Beispiel #1
0
    print >> sys.stderr, "You must use a backup mailbox"
    sys.exit(1)

if 'imap.gmail.com' in mailbox_server.servername:
    if options.cachefile is None:
        print >> sys.stdout, "Gmail Mailboxes require a cache"
        sys.exit(1)
    else:
        cache = GmailCache(mailbox_server)
        cache.load(options.cachefile)
        cache.autosave = options.cachefile
        cache.update()


for mailbox_name in args[2:]:
    mailbox =  ImapMailbox((mailbox_server.clone(), mailbox_name))
    print("\n\nProcessing mailbox %s" % mailbox.name)
    encrypted = mailbox.search('UNDELETED HEADER Content-Type encrypted')
    for uid in encrypted:
        print("    Decrypting UID %s" % uid)
        message = mailbox[uid]
        labels = [mailbox_name] # all the mailboxes the mail appears (for gmail)
        if options.backup is not None:
            print("        Backing up the original (encrypted) message")
            backupbox.add(message)
        print("        Deleting the original (encrypted) message")
        if is_gmail_box(mailbox):
            labels = cache.get_labels("%s.%s" % (mailbox_name, uid))
            delete(mailbox, uid)
        else:
            mailbox.discard(uid)
Beispiel #2
0
if len(sys.argv) < 3:
    print "Usage: mbox2imap.py <mboxpath> <imapfolder>"
    print "To change the imap server, edit the script"
    sys.exit(2)

# Variables

toserver = ImapServer("imap.gmail.com",
                      "*****@*****.**",
                      "secret",
                      ssl=True)
toboxname = sys.argv[2]

# Processing

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)
Beispiel #3
0
#!/usr/bin/env python
"""
    This example shows how to create a backup of an IMAP mailbox into an mbox folders.
    The IMAP attributes are stored in each message in special header fields"
"""
from ProcImap.ImapMailbox import ImapMailbox
from ProcImap.Utils.MailboxFactory import MailboxFactory
from mailbox import mbox
import sys

# usage: backup_mailbox.py imapmailbox backupmbox

mailboxes = MailboxFactory('/home/goerz/.procimap/mailboxes.cfg')
server = mailboxes.get_server('Gmail')
mailbox = ImapMailbox((server, sys.argv[1]))
backuptarget = mbox(sys.argv[2])

backuptarget.lock()

for message in mailbox:
    message.add_header("X-ProcImap-Imapflags", message.flagstring())
    message.add_header("X-ProcImap-ImapInternalDate",
                       message.internaldatestring())
    backuptarget.add(message)

mailbox.close()
backuptarget.close()
sys.exit(0)
Beispiel #4
0
        print "subject:",header['subject'],"copied to archive"
        print ""
        return header
    

    def fullprocess(self,message):
        """Only called if header.fullprocess=True"""
        return

if __name__=="__main__":
    from ProcImap import imaplib2
    from ProcImap.Utils import log
    import os
    password = open( os.getenv("HOME")+"/.me").read().strip()
    while True:
        try:
            s = ImapServer("mail.me.com","simsong",password)
            mbx = ImapMailbox(path=(s,"INBOX"))
            mbx.trash = 'Trash'                 # specify a trash box
            print "calling ImapWatcher"
            w = ImapWatcher(mbx)
            w.run()
        except:
            log("caught exception")
            pass