def create_mailbox( mailbox_name, format=None ): """Creates and returns a Python mailbox object that can be used to write mail messages into. If format is not None, it can be one of mbox, maildir, mmdf, mh, babyl, to control the type of mailbox created. """ try: if not format or format=='mbox': newmailbox = mbox( mailbox_name ) elif format=='maildir': newmailbox = Maildir( mailbox_name ) elif format=='mmdf': newmailbox = MMDF( mailbox_name ) elif format=='mh': newmailbox = MH( mailbox_name ) elif format=='babyl': newmailbox = Babyl( mailbox_name ) except IOError, ( errno, strerror ): newmailbox = None return EudoraLog.fatal( P + ': cannot open "' + mailbox_name + '", ' + strerror )
def create_mailbox(mailbox_name, format=None): """Creates and returns a Python mailbox object that can be used to write mail messages into. If format is not None, it can be one of mbox, maildir, mmdf, mh, babyl, to control the type of mailbox created. """ try: if not format or format == 'mbox': newmailbox = mbox(mailbox_name) elif format == 'maildir': newmailbox = Maildir(mailbox_name) elif format == 'mmdf': newmailbox = MMDF(mailbox_name) elif format == 'mh': newmailbox = MH(mailbox_name) elif format == 'babyl': newmailbox = Babyl(mailbox_name) except IOError, (errno, strerror): newmailbox = None return EudoraLog.fatal(P + ': cannot open "' + mailbox_name + '", ' + strerror)
def convert(mbx, embedded_dir=None, opts=None): """ Start at the Eudora specific pattern "^From ???@???" and keep gathering all headers. When an empty line is found, emit the headers. Replace ???@??? with the e-mail address in "From: " (if found), or else use "Sender: " or else "Return-Path: " or else use the magic address "*****@*****.**" for later analysis (easily greppable). Also add a "Date: " if missing (mostly for outbound mail sent by yourself) which is extracted from the Eudora "From ???@??? ..." line, but is reformatted, because Eudora has the order in the datum items wrong. Eudora uses: dayname-abbr monthname-abbr monthnumber-nn time-hh:mm:ss year-yyyy whereas it should be: dayname-abbr monthnumber-nn monthname-abbr year-yyyy time-hh:mm:ss Example: Thu 03 Jan 2002 11:42:42 (24 characters) """ global attachments_listed, attachments_found, attachments_missing, attachments_dirs global paths_found, paths_missing, message_count global re_initial_whitespace global toc_info, replies, target global edir attachments_listed = 0 attachments_found = 0 attachments_missing = 0 edir = embedded_dir print "Converting %s" % (mbx, ) if not mbx: EudoraLog.fatal(P + ': usage: Eudora2Mbox.py eudora-mailbox-file.mbx') return 0 attachments_dirs = [] target = '' format = None if opts: for f, v in opts: if f == '-a': attachments_dirs = v.split(':') elif f == '-f': format = v.strip().lower() elif f == '-t': target = v EudoraLog.log = EudoraLog.Log(mbx) try: INPUT = open(mbx, 'r') except IOError, (errno, strerror): INPUT = None return EudoraLog.fatal(P + ': cannot open "' + mbx + '", ' + strerror)
print msg_str if EudoraLog.verbose >= 0: print EudoraLog.log.summary() # Finish up. Close failures usually indicate filesystem full. if newmailbox: newmailbox.close() if INPUT: try: INPUT.close() except IOError: return EudoraLog.fatal(P + ': cannot close "' + mbx + '"') return 0 def create_mailbox(mailbox_name, format=None): """Creates and returns a Python mailbox object that can be used to write mail messages into. If format is not None, it can be one of mbox, maildir, mmdf, mh, babyl, to control the type of mailbox created. """ try: if not format or format == 'mbox': newmailbox = mbox(mailbox_name)
def convert( mbx, embedded_dir = None, opts = None ): """ Start at the Eudora specific pattern "^From ???@???" and keep gathering all headers. When an empty line is found, emit the headers. Replace ???@??? with the e-mail address in "From: " (if found), or else use "Sender: " or else "Return-Path: " or else use the magic address "*****@*****.**" for later analysis (easily greppable). Also add a "Date: " if missing (mostly for outbound mail sent by yourself) which is extracted from the Eudora "From ???@??? ..." line, but is reformatted, because Eudora has the order in the datum items wrong. Eudora uses: dayname-abbr monthname-abbr monthnumber-nn time-hh:mm:ss year-yyyy whereas it should be: dayname-abbr monthnumber-nn monthname-abbr year-yyyy time-hh:mm:ss Example: Thu 03 Jan 2002 11:42:42 (24 characters) """ global attachments_listed, attachments_found, attachments_missing, attachments_dirs global paths_found, paths_missing, message_count global re_initial_whitespace global toc_info, replies, target global edir attachments_listed = 0 attachments_found = 0 attachments_missing = 0 edir = embedded_dir print "Converting %s" % (mbx,) if not mbx: EudoraLog.fatal( P + ': usage: Eudora2Mbox.py eudora-mailbox-file.mbx' ) return 0 attachments_dirs = [] target = '' format = None if opts: for f, v in opts: if f == '-a': attachments_dirs = v.split(':') elif f == '-f': format = v.strip().lower() elif f == '-t': target = v EudoraLog.log = EudoraLog.Log( mbx ) try: INPUT = open( mbx, 'r' ) except IOError, ( errno, strerror ): INPUT = None return EudoraLog.fatal( P + ': cannot open "' + mbx + '", ' + strerror )
print msg_str if EudoraLog.verbose >= 0: print EudoraLog.log.summary() # Finish up. Close failures usually indicate filesystem full. if newmailbox: newmailbox.close() if INPUT: try: INPUT.close() except IOError: return EudoraLog.fatal( P + ': cannot close "' + mbx + '"' ) return 0 def create_mailbox( mailbox_name, format=None ): """Creates and returns a Python mailbox object that can be used to write mail messages into. If format is not None, it can be one of mbox, maildir, mmdf, mh, babyl, to control the type of mailbox created. """ try: if not format or format=='mbox': newmailbox = mbox( mailbox_name ) elif format=='maildir':