Update of /cvsroot/spambayes/spambayes/utilities
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5565/utilities
Modified Files:
export_apple_mail.py
Log Message:
Add a few options: showing help, excluding accounts/mailboxes, quiet.
Index: export_apple_mail.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/utilities/export_apple_mail.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** export_apple_mail.py 3 Jan 2006 02:47:24 -0000 1.1
--- export_apple_mail.py 4 Jan 2006 04:31:38 -0000 1.2
***************
*** 1,12 ****
#!/usr/bin/env python
! """export_apple_mail.py
!
! Converts Apple Mail's emlx files to plain text files usable
by SpamBayes's testtools.
! Adding some way to display help would be good. For now, read
! this file and run the script with the path to the user's
! ~/Library/Mail directory.
(Tested on Windows XP remotely accessing the Mac filesystem.
--- 1,21 ----
#!/usr/bin/env python
! """Convert Apple Mail's emlx files to plain text files usable
by SpamBayes's testtools.
! Usage: %(program)s [options] path
!
! Where:
! -h
! Show usage and exit.
! -e mailbox
! Name of mailbox or account to exclude. Drafts and
! Sent Messages are always excluded.
! -q
! Don't print status indicators.
! -o section:option:value
! Set [section, option] in the options database to value.
!
! "path" should be the path to the user's ~/Library/Mail directory.
(Tested on Windows XP remotely accessing the Mac filesystem.
***************
*** 18,24 ****
--- 27,42 ----
import os
import sys
+ import getopt
from spambayes.Options import options
+ def usage(code, msg=''):
+ """Print usage message and sys.exit(code)."""
+ if msg:
+ print >> sys.stderr, msg
+ print >> sys.stderr
+ print >> sys.stderr, __doc__ % globals()
+ sys.exit(code)
+
def emlx_to_rfc2822(in_fn, out_fn):
"""Convert an individual file in Apple Mail's emlx format
***************
*** 37,41 ****
plist = fin.read()
! def export(mail_dir):
"""Scans through the specified directory, which should be
the Apple Mail user's ~\Library\Mail folder, converting
--- 55,59 ----
plist = fin.read()
! def export(mail_dir, exclude, quiet):
"""Scans through the specified directory, which should be
the Apple Mail user's ~\Library\Mail folder, converting
***************
*** 60,68 ****
dirname = os.path.join(mail_dir, dirname)
if os.path.isdir(dirname):
! export_directory(mail_dir, dirname)
! print
! def export_directory(parent, dirname):
! if parent == "Junk.mbox":
# All of these should be spam. Make sure that you
# check for false positives first!
--- 78,86 ----
dirname = os.path.join(mail_dir, dirname)
if os.path.isdir(dirname):
! export_directory(mail_dir, dirname, exclude, quiet)
! def export_directory(parent, dirname, exclude, quiet):
! base_parent = os.path.splitext(os.path.basename(parent))[0]
! if base_parent == "Junk":
# All of these should be spam. Make sure that you
# check for false positives first!
***************
*** 70,75 ****
os.path.dirname(options["TestDriver", "spam_directories"]),
"reservoir")
! elif parent == "Sent Messages.mbox" or parent == "Drafts.mbox":
! # We don't do anything with outgoing mail.
return
else:
--- 88,92 ----
os.path.dirname(options["TestDriver", "spam_directories"]),
"reservoir")
! elif base_parent in exclude:
return
else:
***************
*** 82,86 ****
path = os.path.join(dirname, path)
if os.path.isdir(path):
! export_directory(dirname, path)
else:
fn, ext = os.path.splitext(path)
--- 99,103 ----
path = os.path.join(dirname, path)
if os.path.isdir(path):
! export_directory(dirname, path, exclude, quiet)
else:
fn, ext = os.path.splitext(path)
***************
*** 90,95 ****
os.path.basename(fn) + ".txt")
emlx_to_rfc2822(in_fn, out_fn)
! sys.stdout.write('.')
if __name__ == "__main__":
! export(sys.argv[1])
--- 107,138 ----
os.path.basename(fn) + ".txt")
emlx_to_rfc2822(in_fn, out_fn)
! if not quiet:
! sys.stdout.write('.')
! if not quiet:
! print
!
! def main():
! try:
! opts, args = getopt.getopt(sys.argv[1:], 'hqe:o:')
! except getopt.error, msg:
! usage(1, msg)
!
! quiet = False
! # We don't do anything with outgoing mail.
! exclude = ["Sent Messages", "Drafts"]
! for opt, arg in opts:
! if opt == '-h':
! usage(0)
! elif opt == '-e':
! exclude.append(arg)
! elif opt == '-q':
! quiet = True
! elif opt in ('-o', '--option'):
! options.set_from_cmdline(arg, sys.stderr)
!
! if len(args) != 1:
! usage(1, "Must specify exactly one path.")
! export(args[0], exclude, quiet)
if __name__ == "__main__":
! main()
_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins