Exemplo n.º 1
0
    def OnActivate(self, evt):
        #loginfo('event:', evt)
        loginfo('OnActivate: %s' % self.tree.GetItemText(evt.GetItem()))
        self.lastitem = evt.GetItem()
        row = self.tree.GetItemData(evt.GetItem()).GetData()
        #loginfo('active row:', row)
        if not row:
            logerr('not found row.')
            return
        if not row.has_key('id'):
            loginfo('is category.')
            return
        #mid, name, mbox = s
        mid  = row['id']
        name = row['user']
        mbox = row['box']

        info = mailparse.decode_mail(row['filepath'])
        
        htmldata = info['html']
        plaindata = info['plain']
        #if htmldata:
        #    self.parent.listcnt.set_text(htmldata)
        #elif plaindata:
        #    self.parent.listcnt.set_text(plaindata.replace('\r\n', '<br>').replace('\n', '<br>'))
        self.parent.listcnt.set_text_auto(htmldata, plaindata)

        attachctl = self.parent.attachctl
        attachctl.clear()
        
        #row['attach'] = simplejson.loads(row['attach'])

        for item in row['attach']:
            filename = os.path.join(config.cf.datadir, name, row['mailbox'], row['filename'].strip(os.sep))
            homename = os.path.join(config.cf.datadir, name)
            attachdata = {'file':filename, 'home':homename, 'attach':item[0]}
            loginfo('attachdata:', attachdata)
            attachctl.add_file(item[0], attachdata)

        if row['status'] == 'noread':
            #row['status'] = 'read' 
            item = evt.GetItem()
            itemdata = self.tree.GetItemData(item).GetData()
            #loginfo('noread itemdata:', itemdata)
            self.draw_category_text(item, 'read')
            self.tree.SetItemBold(item, False)
        
            sql = "update mailinfo set status='read' where id=" + str(itemdata['id'])
            loginfo('read:', sql)
            db = dbope.openuser(config.cf, name)
            db.execute(sql)
            db.close()

        self.SetFocus()
Exemplo n.º 2
0
 def display(self):
     conn = dbope.openuser(config.cf, self.user)
     try:
         for x in self.display_sqls:
             mcount = conn.query(x[1], False)[0][0]
             msize  = conn.query(x[2], False)[0][0]
             if msize is None:
                 msize = 0
             x[3].SetValue(u'信件%d封 大小%.2fM' % (mcount, float(msize)/1024/1024)) 
     finally:
         conn.close()
Exemplo n.º 3
0
    def change_box(self, info, newbox='trash'):
        id = info['id']
        mailbox = info['mailbox'] 
        if newbox == 'recv':
            basepath = os.path.basename(info['filename'])
            datestr = info['ctime'][:6]
            hashstr = '%02d' % (hash(basepath) % 10)
            newfilename = os.path.join(datestr, hashstr, basepath)
        else:
            newfilename = os.path.basename(info['filename'])

        loginfo('change box from:', mailbox, ' to:', newbox)
        if mailbox == 'trash': 
            sql = "delete from mailinfo where id=%s" % (str(id))
        else:
            sql = "update mailinfo set mailbox='%s',filename='%s' where id=%s" % (newbox, newfilename, str(id))
        loginfo('delete:', sql)
        
        username = info['user']
        db = dbope.openuser(config.cf, username)
        db.execute(sql)
        db.close()
        
        if info.has_key('item'):
            loginfo('info item:', info['item'])
            item = info['item']
        else:
            loginfo('not found item in info')
            item = self.lastitem
        loginfo('item: ', item)
        self.remove_item(item)
        self.parent.load_db_one(username, id)
        
        if mailbox == 'trash':
            os.remove(info['filepath']) 
        else:
            newfile = os.path.join(config.cf.datadir, username, newbox, newfilename)
            loginfo('newfile:', newfile)
            os.rename(info['filepath'], newfile)
Exemplo n.º 4
0
def mail_import(user, boxnode, filename):
    hashdir_count = 10
    info = mailparse.decode_mail(filename)

    attachs = []
    for x in info["attach"]:
        attachs.append("::".join(x))
    attachstr = "||".join(attachs)

    att = 0
    if len(info["attach"]) > 0:
        att = 1
    if boxnode["boxname"].find("/") == -1:
        mailbox = config.cf.mailbox_map_cn2en[boxnode["boxname"]]
    else:
        return
    info["mailbox"] = mailbox
    info["ctime"] = "datetime()"
    info["user"] = user

    fname = uuid.uuid1().urn[9:]
    hashdir = "%02d" % (hash(fname) % hashdir_count)
    timepath = "%d%02d" % time.localtime()[:2]
    newdir = os.path.join(config.cf.datadir, user, mailbox, timepath, hashdir)
    if not os.path.isdir(newdir):
        os.makedirs(newdir)
    newfilename = os.sep + os.path.join(timepath, hashdir, "%d." % (int(time.time())) + fname + ".eml")
    dstfile = os.path.join(newdir, "%d." % (int(time.time())) + fname + ".eml")

    info["filename"] = newfilename
    subject = info["subject"].replace("'", "''")
    attach = attachstr.replace("'", "''")

    sql = (
        "insert into mailinfo(filename,subject,mailfrom,mailto,size,ctime,date,attach,mailbox,status) values "
        "('%s','%s','%s','%s',%d,%s,'%s','%s','%s','noread')"
        % (
            newfilename,
            subject,
            info["from"],
            ",".join(info["to"]),
            info["size"],
            info["ctime"],
            info["date"],
            attach,
            info["mailbox"],
        )
    )
    conn = dbope.openuser(config.cf, user)
    conn.execute(sql)
    conn.close()
    shutil.copyfile(filename, dstfile)
    info["box"] = "/%s/%s" % (user, info["mailbox"])
    info["status"] = "noread"
    info["filepath"] = os.path.join(config.cf.datadir, user, info["mailbox"], info["filename"].lstrip(os.sep))
    item = [
        info["from"],
        att,
        info["subject"],
        1,
        info["date"],
        str(info["size"] / 1024 + 1) + " K",
        wx.TreeItemData(info),
    ]
    panel = boxnode["panel"]
    panel.add_mail(item)