Beispiel #1
0
 def fetch(self, label = "INBOX"):
     mbox = ImapMailbox( (self.server, label) )
     uids = mbox.get_all_uids()
     cache = Cache()
     for uid in uids:
         cached = cache.get_header(uid)
         if cached:
         	yield cached
         else:
             msg = cache.set_header(uid, mbox.get_fields(uid, 'SUBJECT FROM DATE'))
             yield msg
Beispiel #2
0
fromboxname = sys.argv[1]
frombox = mailbox.mbox(fromboxname)
frombox.lock()
tobox.lock()


i = 1
print "Processing mbox file %s with %s messages" % (fromboxname, len(frombox))
for message in frombox:
    print "%s" % i
    if message['Message-Id'] is None:
        print "   WARNING: message has no message-id (mesage ID will be added)"
        message.add_header("Message-Id", make_msgid('katamon.mbox2imap') )
    if True:
        try:
            tobox.add(message)
        except ImapNotOkError:
            print "   ERROR: Transaction failed for message %s" % i
            toserver.reconnect()
            tobox = ImapMailbox((toserver, toboxname))
            time.sleep(5)
        time.sleep(1)
        number_in_tobox = len(tobox.get_all_uids())
        #time.sleep(1)
        print "    Added Message, %s in mailbox" % number_in_tobox
    i = i + 1

frombox.close()
tobox.close()
sys.exit(0)
Beispiel #3
0
    record_file.close()
except IOError:
    pass

record_file = open(options.record, 'a')
mailbox = None
try:
    for label in labels:
        if not label in include: continue
        if label in exclude: continue
        if mailbox is None:
            mailbox = ImapMailbox((server, label))
        else:
            mailbox.switch(label)
        if options.search == '':
            uids = mailbox.get_all_uids()
        else:
            uids = mailbox.search(options.search)
        for uid in uids:
            if not record.has_key("%s.%s" % (label, uid)):
                descr = "%s.%s " % (label, uid)
                if options.summary:
                    s = summary(mailbox, uid, printuid=False, printout=False)[0]
                    descr += "\t" + s[3:]
                print descr
except KeyboardInterrupt:
    print ""
except Exception, errormessage:
    if options.raise_exception: raise
    print "Program ended with exception. Run again."
    print errormessage
Beispiel #4
0
tobox = ImapMailbox((toserver, toboxname))
fromboxname = sys.argv[1]
frombox = mailbox.mbox(fromboxname)
frombox.lock()
tobox.lock()

i = 1
print "Processing mbox file %s with %s messages" % (fromboxname, len(frombox))
for message in frombox:
    print "%s" % i
    if message['Message-Id'] is None:
        print "   WARNING: message has no message-id (mesage ID will be added)"
        message.add_header("Message-Id", make_msgid('katamon.mbox2imap'))
    if True:
        try:
            tobox.add(message)
        except ImapNotOkError:
            print "   ERROR: Transaction failed for message %s" % i
            toserver.reconnect()
            tobox = ImapMailbox((toserver, toboxname))
            time.sleep(5)
        time.sleep(1)
        number_in_tobox = len(tobox.get_all_uids())
        #time.sleep(1)
        print "    Added Message, %s in mailbox" % number_in_tobox
    i = i + 1

frombox.close()
tobox.close()
sys.exit(0)