Пример #1
0
    def parse_args(self, args=None, values=None):
        """
        parse_args(args : [string] = sys.argv[1:],
                   values : Values = None)
        -> (values : Values, args : [string])

        Parse the command-line options found in 'args' (default:
        sys.argv[1:]).  Any errors result in a call to 'error()', which
        by default prints the usage message to stderr and calls
        sys.exit() with an error message.  On success returns a pair
        (values, args) where 'values' is an Values instance (with all
        your option values) and 'args' is the list of arguments left
        over after parsing options.
        """
        result = OptionParser.parse_args(self, args, values)
        if self.values.profile is None:
            self.exit(status=1,
                      msg="You did not provide a profile, and the "
                      "PROC_IMAP_PROFILE environment variable is not set.\n")
        else:
            try:
                self.values.profile = MailboxFactory(self.values.profile)
            except:
                raise
        return result
Пример #2
0
#!/usr/bin/env python
"""
    This example shows how to restore a backup created by backup_mailbox.py"
"""
from ProcImap.ImapMailbox import ImapMailbox
from ProcImap.ImapMessage import ImapMessage
from ProcImap.Utils.MailboxFactory import MailboxFactory
from mailbox import mbox
import sys

# usage: restore_mailbox.py backupmbox imapmailbox

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

for message in backupsource:
    if message.has_key("X-ProcImap-Imapflags"):
        message.flags_from_string(message["X-ProcImap-Imapflags"])
        del message["X-ProcImap-Imapflags"]
    if message.has_key("X-ProcImap-ImapInternalDate"):
        message. internaldate_from_string(message["X-ProcImap-ImapInternalDate"])
        del message["X-ProcImap-ImapInternalDate"]
    mailbox.add(message)

mailbox.close()
backupsource.close()
sys.exit(0)
Пример #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)
Пример #4
0
#!/usr/bin/env python
"""
    This example shows how to read mail on an imap server.
"""
import sys

from ProcImap.Utils.MailboxFactory import MailboxFactory
from ProcImap.Utils.Server import summary, display

mailboxes = MailboxFactory('/home/goerz/.procimap/mailboxes.cfg')
mailbox = mailboxes["Physik"]


def help():
    """ Print help message """
    print "\nEnter message number to read the message"
    print "Enter 'd #', with # being a message number to delete a message"
    print "Press enter to quit\n"


unseen = mailbox.get_unseen_uids()
if len(unseen) == 0:
    print "No unread messages"
    sys.exit(0)
else:
    if '--check' in sys.argv:
        sys.stdout.write("%s unread message" % len(unseen))
        if len(unseen) > 1:
            sys.stdout.write("s\n")
        else:
            sys.stdout.write("\n")
Пример #5
0
from ProcImap.Utils.MailboxFactory import MailboxFactory
from ProcImap.Utils.Processing import AddressListFile
from time import time
import sys
import os
import subprocess
import re
import email

if sys.version_info > (3, 0):
    import pickle
else:
    import cPickle as pickle

try:
    inbox = MailboxFactory("/Users/goerz/.procimap/mailboxes.cfg")['Gmail']
    prioritylist = AddressListFile("/Users/goerz/.procimap/priority.lst")
    notifylist = AddressListFile("/Users/goerz/.procimap/notify.lst")
    picklefile = "/Users/goerz/.procimap/notify.pickle"
    imageslist = "/Users/goerz/.procimap/pictures.txt"

    notifytimeout = 3600

    unread_mails = {}

    unseen = inbox.get_unseen_uids()
except:
    sys.exit(0)


def get_icon(address):
Пример #6
0
from ProcImap.Utils.MailboxFactory import MailboxFactory
from ProcImap.Utils.Processing import AddressListFile
from time import time
import sys
import os
import subprocess
import re
import email

if sys.version_info > (3, 0):
    import pickle
else:
    import cPickle as pickle

try:
    inbox = MailboxFactory("/Users/goerz/.procimap/mailboxes.cfg")['Gmail']
    prioritylist = AddressListFile("/Users/goerz/.procimap/priority.lst")
    notifylist = AddressListFile("/Users/goerz/.procimap/notify.lst")
    picklefile = "/Users/goerz/.procimap/notify.pickle"
    imageslist = "/Users/goerz/.procimap/pictures.txt"

    notifytimeout = 3600

    unread_mails = {}

    unseen = inbox.get_unseen_uids()
except:
    sys.exit(0)

def get_icon(address):
    images_fh = open(imageslist)
Пример #7
0
 def __init__(self, config = "/home/adam/.climap/conf", server = "Gmail"):
     factory = MailboxFactory(config)
     self.server = factory.get_server(server)
     self.labels = self.server.list()
     log.debug("ImapClient connected")