Exemple #1
0
async def sendLink(app, files, email):
    if not isinstance(files, list):
        return web.json_response({'result': False, 'message': '参数files非list'})
    if len(files) <= 0:
        return web.json_response({'result': False, 'message': '未选择要送的文件'})

    # 更新Filelist表中状态01-已发送和文件的md5
    async with app['db'].acquire() as conn:
        cursor = await conn.execute(
            Mail.select().where(Mail.c.uid == app['uid']))
        row = await cursor.fetchone()
        if row is None:
            return web.json_response({'result': False, 'message': '用户发送邮箱未设置'})
        # 生成文件的md5
        urls = []
        for fileid in files:
            filemd5 = hashlib.md5(fileid.encode('utf-8')).hexdigest()
            urls.append('http://%s:%d/download/%s' %
                        (app['host'], app['port'], filemd5))
            await conn.execute(Filelist.update().where(
                Filelist.c.fileid == fileid).values(status='01',
                                                    filemd5=filemd5))
            await api.writeLog(app=app, fileid=fileid, option='02', conn=conn)
        content = '\n'.join(urls)
        password = api.decryptADS(app['config'].mail.seckey, row.password)
        mail = api.sendMail(content, row.subject, row.mail, email, password)
        if mail.get('result'):
            return web.json_response({'result': True, 'message': '发送链接成功'})
        else:
            return web.json_response({
                'result': False,
                'message': mail.get('message')
            })
Exemple #2
0
async def updateMail(app, mail, password, subject):
    auth = api.authSMTP(mail, password)
    if not auth.get('result'):
        return web.json_response({
            'result': False,
            'message': auth.get('message')
        })
    async with app['db'].acquire() as conn:
        ads_pwd = api.encryptADS(app['config'].mail.seckey, password)
        cursor = await conn.execute(
            Mail.select().where(Mail.c.uid == app['uid']))
        row = await cursor.fetchone()
        print(row)
        if row:
            cursor = await conn.execute(Mail.update().where(
                Mail.c.uid == app['uid']).values(mail=mail,
                                                 password=ads_pwd,
                                                 subject=subject))
            if cursor.rowcount == 1:
                return web.json_response({
                    'result': True,
                    'message': '电子邮件更新成功'
                })
            else:
                return web.json_response({
                    'result': False,
                    'message': '电子邮件更新失败'
                })
        else:
            cursor = await conn.execute(Mail.insert(),
                                        uid=app['uid'],
                                        mail=mail,
                                        password=ads_pwd,
                                        subject=subject)
            if cursor.rowcount == 1:
                return web.json_response({
                    'result': True,
                    'message': '电子邮件新增成功'
                })
            else:
                return web.json_response({
                    'result': False,
                    'message': '电子邮件新增失败'
                })
Exemple #3
0
def linkify_ids(env, req, ids):
    if len(ids) == 0 or ids[0] == '':
        return tag.span()
    
    from model import Mail
    data = []
    for id in sorted(ids, key=lambda x: int(x)):
        try:
            mail = Mail(env, id)
            data.append(tag.a('mail:%s'%mail.id,
                               href=req.href.mailarchive(mail.id),
                               class_='ticket',
                               title='%s %s %s' % (mail.get_fromtext(), mail.get_senddate(), mail.subject)))
        except ResourceNotFound:
            data.append('%s'%id)
        data.append(', ')
    if data:
        del data[-1] # Remove the last comma if needed
    return tag.span(*data)
Exemple #4
0
async def getMail(app):
    async with app['db'].acquire() as conn:
        cursor = await conn.execute(
            Mail.select().where(Mail.c.uid == app['uid']))
        row = await cursor.fetchone()
        if row:
            data = {'mail': row.mail, 'password': None, 'subject': row.subject}
            return web.json_response({'result': True, 'row': data})
        else:
            return web.json_response({'result': False})
Exemple #5
0
    def load_emails(self, folder: Folder):
        self._connection.change_mailbox(self._to_utf_7(folder.name))

        date = datetime.now() - timedelta(weeks=2)

        date_criterion = self._create_date_criterion(date)

        ids_on_server = [
            int(id)
            for id in self._connection.listids(sys.maxsize, date_criterion)
        ]

        self._delete_mail_not_on_server(ids_on_server, folder, date)

        local_ids = [
            mail.uid for mail in Mail.select().where(Mail.folder == folder)
        ]

        for id_ in ids_on_server:
            if id_ in local_ids:
                continue
            mail = self._connection.mail(str(id_).encode(), include_raw=True)

            try:
                encoding = self._charset_pattern.search(
                    mail.content_type).group(1)
            except (IndexError, AttributeError):
                encoding = "utf-8"
            raw_mail = email.message_from_string(mail.raw.decode(encoding))
            body, is_html = self._get_body(raw_mail)
            subject = mail.title if mail.title else ''

            mail_instance = Mail.create(uid=id_,
                                        folder=folder,
                                        body=body,
                                        subject=subject,
                                        recipient=mail.to,
                                        sender=mail.from_addr,
                                        datetime=mail.date,
                                        is_html=is_html)

            self._load_attachments(mail_instance, mail)
Exemple #6
0
 def transfer(self):
     UserAccount = int(self.UserAccount)
     try:
         RequestAccount = int(self.Content) #预防用户输入值非法
     except:
         print("[AccountBook]illegal transfer maths")
         self.FuctionTag = "transfer.error"
     else:
         if UserAccount >= RequestAccount:
             self.Transfer = str(int(self.Transfer) + RequestAccount)
             self.UserAccount = str(UserAccount - RequestAccount)
             self.FuctionTag = "transfer.successed"
             y, m, d, h, mi, s, null, null, null = time.localtime(time.time())
             self.orderID = "T0297" + str(y) + str(m) + str(d) + str(h) + str(mi) + str(s)
             print("[Model]AccountBook:Created an orderID")
             maildata = [str(self.orderID), str(time.asctime(time.localtime(time.time()))), str((self.UserName).encode('utf-8')), str(RequestAccount), str(self.Transfer), str(self.UserAccount)]
             #构建消息体:订单号,创建时间,连接用户,请求金额,总请求金额,用户余额
             #调用Mail模块
             Mail.input_mail("dev", "AccountBook.transfer", maildata)
             self.RequestAccount = str(RequestAccount)
         else:
             self.FuctionTag = "transfer.error"
Exemple #7
0
 def _delete_mail_not_on_server(ids_on_server, folder, date):
     Mail.delete().where((Mail.folder == folder)
                         & (Mail.uid.not_in(ids_on_server))
                         & (Mail.datetime >= date)).execute()
 def import_message(self, msg, author, mlid, db):
     mail = Mail(self.env, db=db)
     mail.populate(author, msg, mlid)
     
     self.handleMail(mail)