diff options
-rw-r--r-- | CHANGELOG | 8 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rwxr-xr-x | archivemail.py | 10 | ||||
-rw-r--r-- | archivemail.sgml | 71 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rwxr-xr-x | test_archivemail.py | 452 |
8 files changed, 339 insertions, 213 deletions
@@ -1,4 +1,12 @@ +Version 0.4.4 - 27 April 2002 + * Fixed a bug where the long --suffix option was not working (although the + short option, '-s' was). + * Added time-based format directives to the --suffix option, so that you + can do things like specify --suffix='%B%Y' to create archives named + after the current month and year + * Added some more tests to test_archivemail.py + Version 0.4.3 - 26 April 2002 * Fixed a couple of bugs where I was using python version 2.2 syntax that was giving errors in python v2.0 and v2.1. @@ -1,5 +1,5 @@ -VERSION=0.4.3 +VERSION=0.4.4 VERSION_TAG=v$(subst .,_,$(VERSION)) TARFILE=archivemail-$(VERSION).tar.gz @@ -30,7 +30,7 @@ module, although the zlib module comes with most python installations. If you are compiling your own version of python < version 2.2, make sure you uncomment the 'zlib' moduile in Modules/Setup in the python source directory. -You can check to see if you version of python has the 'zlib' module by +You can check to see if your version of python has the 'zlib' module by trying this: flare:~$ python @@ -1,5 +1,5 @@ -Goals for next minor release (0.4.4): +Goals for next minor release (0.4.5): ------------------------------------- * Think about the best way to specify the names of archives created with possibly an --archive-name option. @@ -9,12 +9,15 @@ Goals for next minor release (0.4.4): Goals for next major release (0.5.0): ------------------------------------- +* Add a --size option to only archive messages greater than a certain byte + size. * Lock any original .gz files - is this necessary? * Check for symlink attacks for tempfiles (although we don't use /var/tmp) Longer Term goals: ------------------ +* Add an option to not cut threads. * Add MMDF mailbox support * Add Babyl mailbox support * Add option to archive depending on mailbox size threshold diff --git a/archivemail.py b/archivemail.py index 7aa2424..30c06f5 100755 --- a/archivemail.py +++ b/archivemail.py @@ -22,7 +22,7 @@ Website: http://archivemail.sourceforge.net/ """ # global administrivia -__version__ = "archivemail v0.4.3" +__version__ = "archivemail v0.4.4" __cvs_id__ = "$Id$" __copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com> This is free software; see the source for copying conditions. There is NO @@ -165,7 +165,7 @@ class Options: opts, args = getopt.getopt(args, '?D:Vd:hno:qs:uv', ["date=", "days=", "delete", "dry-run", "help", "include-flagged", "no-compress", "output-dir=", - "preserve-unread", "quiet", "suffix", "verbose", + "preserve-unread", "quiet", "suffix=", "verbose", "version", "warn-duplicate"]) except getopt.error, msg: user_error(msg) @@ -858,7 +858,11 @@ def archive(mailbox_name): set_signal_handlers() os.umask(077) # saves setting permissions on mailboxes/tempfiles - final_archive_name = mailbox_name + options.archive_suffix + # allow the user to embed time formats such as '%B' in the suffix string + parsed_suffix = time.strftime(options.archive_suffix, + time.localtime(time.time())) + + final_archive_name = mailbox_name + parsed_suffix if options.output_dir: final_archive_name = os.path.join(options.output_dir, os.path.basename(final_archive_name)) diff --git a/archivemail.sgml b/archivemail.sgml index c20f0cd..ad40248 100644 --- a/archivemail.sgml +++ b/archivemail.sgml @@ -125,11 +125,66 @@ read. <Option>-s <Replaceable/NAME/, --suffix=<Replaceable/NAME/</Option> </Term> <ListItem><Para> -Use the suffix <Replaceable/NAME/ to create the filename used for archive -mailboxes. The default is <filename>_archive</filename>. For example, if you +Use the suffix <Replaceable/NAME/ to create the filename used for archives. +The default is <filename>_archive</filename>. For example, if you run <Command/archivemail/ on a mailbox called -<filename>exsouthrock</filename>, any archive mailbox file will be created +<filename>exsouthrock</filename>, the archive will be created with the filename <filename>exsouthrock_archive.gz</filename>. +</Para> + +<Para> +<Replaceable/NAME/ is run through the &python; <application/time.strftime()/ +function, which means that you can specify any of the following special +directives in <Replaceable/NAME/ to make archives named after the current +date: + +<itemizedlist> + <listitem><para><option>%a</option> + Locale's abbreviated weekday name.</para></listitem> + <listitem><para><option>%A</option> + Locale's full weekday name.</para></listitem> + <listitem><para><option>%b</option> + Locale's abbreviated month name.</para></listitem> + <listitem><para><option>%B</option> + Locale's full month name.</para></listitem> + <listitem><para><option>%c</option> + Locale's appropriate date and time representation.</para></listitem> + <listitem><para><option>%d</option> + Day of the month as a decimal number [01,31].</para></listitem> + <listitem><para><option>%H</option> + Hour (24-hour clock) as a decimal number [00,23].</para></listitem> + <listitem><para><option>%I</option> + Hour (12-hour clock) as a decimal number [01,12].</para></listitem> + <listitem><para><option>%j</option> + Day of the year as a decimal number [001,366].</para></listitem> + <listitem><para><option>%m</option> + Month as a decimal number [01,12].</para></listitem> + <listitem><para><option>%M</option> + Minute as a decimal number [00,59].</para></listitem> + <listitem><para><option>%p</option> + Locale's equivalent of either AM or PM.</para></listitem> + <listitem><para><option>%S</option> + Second as a decimal number [00,61]. (1)</para></listitem> + <listitem><para><option>%U</option> + Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.</para></listitem> + <listitem><para><option>%w</option> + Weekday as a decimal number [0(Sunday),6].</para></listitem> + <listitem><para><option>%W</option> + Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.</para></listitem> + <listitem><para><option>%x</option> + Locale's appropriate date representation.</para></listitem> + <listitem><para><option>%X</option> + Locale's appropriate time representation.</para></listitem> + <listitem><para><option>%y</option> + Year without century as a decimal number [00,99].</para></listitem> + <listitem><para><option>%Y</option> + Year with century as a decimal number.</para></listitem> + <listitem><para><option>%Z</option> + Time zone name (or by no characters if no time zone exists).</para></listitem> + <listitem><para><option>%%</option> + A literal "%" character.</para></listitem> +</itemizedlist> + </Para></ListItem> </VarListEntry> @@ -297,6 +352,16 @@ are older than 180 days to a compressed mailbox called </Para> <Para> +To archive all messages in the mailbox <filename>debian-user</filename> that +are older than 180 days to a compressed mailbox called +<filename>debian-user_April_2002.gz</filename> (where the current month and +year is April, 2002) in the current directory: +<screen> +<prompt>bash$ </prompt><userinput>archivemail --suffix '_%B_%Y' debian-user</userinput> +</screen> +</Para> + +<Para> To archive all messages in the mailbox <filename>cm-melb</filename> that are older than the first of January 2002 to a compressed mailbox called <filename>cm-melb_archive.gz</filename> in the current directory: @@ -19,7 +19,7 @@ check_python_version() # define & run this early - 'distutils.core' is new from distutils.core import setup setup(name="archivemail", - version="0.4.3", + version="0.4.4", description="archive and compress old email", license="GNU GPL", url="http://archivemail.sourceforge.net/", diff --git a/test_archivemail.py b/test_archivemail.py index 7ec41aa..d612fe6 100755 --- a/test_archivemail.py +++ b/test_archivemail.py @@ -55,6 +55,7 @@ import copy import fcntl import filecmp import os +import re import shutil import stat import tempfile @@ -252,6 +253,10 @@ class TestOptionDefaults(unittest.TestCase): """we should not archive flagged messages by default""" self.assertEqual(archivemail.options.include_flagged, 0) + def testPreserveUnread(self): + """we should not preserve unread messages by default""" + self.assertEqual(archivemail.options.preserve_unread, 0) + ########## archivemail.is_older_than_days() unit testing ################# class TestIsTooOld(unittest.TestCase): @@ -349,22 +354,31 @@ class TestArchiveMbox(unittest.TestCase): archivemail.options.quiet = 1 def testOld(self): - """archiving an old mailbox should create an exact archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + """archiving an old mailbox""" + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + shutil.copyfile(self.mbox_name, self.copy_name) + if execute == "package": + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --quiet %s" % self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + self.assertEqual(os.path.getsize(self.mbox_name), 0) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive.gz" + assert(os.path.exists(archive_name)) + self.assertEqual(os.system("gzip -d %s" % archive_name), 0) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + self.tearDown() def testOldFromInBody(self): """archiving an old mailbox with 'From ' in the body""" @@ -384,28 +398,6 @@ This is after the ^From line""" assert(os.path.exists(archive_name)) assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) - def testOldSystem(self): - """archiving an old mailbox via system should create an archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - - run = "./archivemail.py --quiet %s" % self.mbox_name - self.assertEqual(os.system(run), 0) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) - def testDateSystem(self): """test that the --date option works as expected""" test_headers = ( @@ -459,117 +451,88 @@ This is after the ^From line""" self.tearDown() def testMixed(self): - """archiving a mixed mailbox should make a mixed-archive""" - self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) - self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_name = tempfile.mktemp() - shutil.copyfile(self.new_mbox, self.mbox_name) - append_file(self.old_mbox, self.mbox_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.new_mbox, self.mbox_name, shallow=0)) - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.old_mbox, shallow=0)) - - def testMixedSystem(self): - """archiving a mixed mailbox via system should make a mixed-archive""" - self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) - self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_name = tempfile.mktemp() - shutil.copyfile(self.new_mbox, self.mbox_name) - append_file(self.old_mbox, self.mbox_name) - run = "./archivemail.py --quiet %s" % self.mbox_name - self.assertEqual(os.system(run), 0) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.new_mbox, self.mbox_name, shallow=0)) - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.old_mbox, shallow=0)) + """archiving a mixed mailbox""" + for execute in ("package", "system"): + self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) + self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_name = tempfile.mktemp() + shutil.copyfile(self.new_mbox, self.mbox_name) + append_file(self.old_mbox, self.mbox_name) + if execute == "package": + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --quiet %s" % self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + assert(filecmp.cmp(self.new_mbox, self.mbox_name, shallow=0)) + archive_name = self.mbox_name + "_archive.gz" + assert(os.path.exists(archive_name)) + self.assertEqual(os.system("gzip -d %s" % archive_name), 0) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.old_mbox, shallow=0)) + self.tearDown() def testNew(self): - """archiving a new mailbox should not create an archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive.gz" - assert(not os.path.exists(archive_name)) + """archiving a new mailbox""" + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + shutil.copyfile(self.mbox_name, self.copy_name) + if execute == "package": + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --quiet %s" % self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive.gz" + assert(not os.path.exists(archive_name)) + self.tearDown() - def testNewSystem(self): - """archiving a new mailbox via system should not create an archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - run = "./archivemail.py --quiet %s" % self.mbox_name - self.assertEqual(os.system(run), 0) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive.gz" - assert(not os.path.exists(archive_name)) def testOldExisting(self): """archiving an old mailbox with an existing archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - archive_name = self.mbox_name + "_archive" - shutil.copyfile(self.mbox_name, self.copy_name) - shutil.copyfile(self.mbox_name, archive_name) # archive has 3 msgs - append_file(self.mbox_name, self.copy_name) # copy now has 6 msgs - self.assertEqual(os.system("gzip %s" % archive_name), 0) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) - - def testOldExistingSystem(self): - """archiving an old mailbox via system with an existing archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - archive_name = self.mbox_name + "_archive" - shutil.copyfile(self.mbox_name, self.copy_name) - shutil.copyfile(self.mbox_name, archive_name) # archive has 3 msgs - append_file(self.mbox_name, self.copy_name) # copy now has 6 msgs - self.assertEqual(os.system("gzip %s" % archive_name), 0) - run = "./archivemail.py --quiet %s" % self.mbox_name - self.assertEqual(os.system(run), 0) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive.gz" - assert(os.path.exists(archive_name)) - self.assertEqual(os.system("gzip -d %s" % archive_name), 0) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + archive_name = self.mbox_name + "_archive" + shutil.copyfile(self.mbox_name, self.copy_name) + shutil.copyfile(self.mbox_name, archive_name) # archive has 3 msgs + append_file(self.mbox_name, self.copy_name) # copy now has 6 msgs + self.assertEqual(os.system("gzip %s" % archive_name), 0) + if execute == "package": + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --quiet %s" % self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + self.assertEqual(os.path.getsize(self.mbox_name), 0) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive.gz" + assert(os.path.exists(archive_name)) + self.assertEqual(os.system("gzip -d %s" % archive_name), 0) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + self.tearDown() def testOldWeirdHeaders(self): - """old mailboxes with weird headers should create an exact archive""" + """archiving old mailboxes with weird headers""" weird_headers = ( { # we should archive even though date < epoch 'From_' : 'sender@dummy.domain Sat Feb 09 02:35:07 1962', @@ -694,7 +657,6 @@ class TestArchiveMboxPreserveStatus(unittest.TestCase): headers={"Status":"RO"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) assert(os.path.exists(self.mbox_name)) self.assertEqual(os.path.getsize(self.mbox_name), 0) @@ -710,7 +672,6 @@ class TestArchiveMboxPreserveStatus(unittest.TestCase): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) assert(os.path.exists(self.mbox_name)) assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) @@ -726,6 +687,50 @@ class TestArchiveMboxPreserveStatus(unittest.TestCase): os.remove(name) +class TestArchiveMboxSuffix(unittest.TestCase): + """make sure the 'suffix' option works""" + def testSuffix(self): + """archiving with specified --suffix arguments""" + for suffix in ("_static_", "_%B_%Y", "-%Y-%m-%d"): + for execute in ("system_long", "system_short", "package"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) + self.copy_name = tempfile.mktemp() + shutil.copyfile(self.mbox_name, self.copy_name) + if execute == "system_long": + run = "./archivemail.py --quiet --suffix='%s' %s" % \ + (suffix, self.mbox_name) + self.assertEqual(os.system(run), 0) + elif execute == "system_short": + run = "./archivemail.py --quiet -s'%s' %s" % \ + (suffix, self.mbox_name) + self.assertEqual(os.system(run), 0) + elif execute == "package": + archivemail.options.archive_suffix = suffix + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + self.assertEqual(os.path.getsize(self.mbox_name), 0) + parsed_suffix = time.strftime(suffix, time.localtime(time.time())) + archive_name = self.mbox_name + parsed_suffix + ".gz" + assert(os.path.exists(archive_name)) + self.assertEqual(os.system("gzip -d %s" % archive_name), 0) + archive_name = re.sub("\.gz$", "", archive_name) + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + os.remove(archive_name) + self.tearDown() + + def tearDown(self): + archivemail.options.quiet = 0 + archivemail.options.archive_suffix = "_archive" + archive = self.mbox_name + "_archive" + for name in (self.mbox_name, self.copy_name, archive, archive + ".gz"): + if os.path.exists(name): + os.remove(name) + + class TestArchiveMboxFlagged(unittest.TestCase): """make sure the 'include_flagged' option works""" def setUp(self): @@ -738,7 +743,6 @@ class TestArchiveMboxFlagged(unittest.TestCase): headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) assert(os.path.exists(self.mbox_name)) assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) @@ -752,7 +756,6 @@ class TestArchiveMboxFlagged(unittest.TestCase): headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) assert(os.path.exists(self.mbox_name)) assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) @@ -766,7 +769,6 @@ class TestArchiveMboxFlagged(unittest.TestCase): headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) assert(os.path.exists(self.mbox_name)) self.assertEqual(os.path.getsize(self.mbox_name), 0) @@ -798,69 +800,113 @@ class TestArchiveMboxUncompressed(unittest.TestCase): archivemail.options.no_compress = 1 def testOld(self): - """archiving an old mailbox uncompressed should create an ok archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) - assert(not os.path.exists(archive_name + ".gz")) + """archiving an old mailbox uncompressed""" + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + shutil.copyfile(self.mbox_name, self.copy_name) + if execute == "package": + archivemail.options.no_compress = 1 + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --no-compress --quiet %s" % \ + self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + self.assertEqual(os.path.getsize(self.mbox_name), 0) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + assert(not os.path.exists(archive_name + ".gz")) + self.tearDown() def testNew(self): - """archiving a new mailbox uncompressed should not create an archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - shutil.copyfile(self.mbox_name, self.copy_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive" - assert(not os.path.exists(archive_name)) - assert(not os.path.exists(archive_name + ".gz")) + """archiving a new mailbox uncompressed""" + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + shutil.copyfile(self.mbox_name, self.copy_name) + if execute == "package": + archivemail.options.no_compress = 1 + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --no-compress --quiet %s" % \ + self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + assert(filecmp.cmp(self.mbox_name, self.copy_name, shallow=0)) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive" + assert(not os.path.exists(archive_name)) + assert(not os.path.exists(archive_name + ".gz")) + self.tearDown() def testMixed(self): - """archiving a mixed mailbox uncompressed should create a mixed archive""" - self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) - self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_name = tempfile.mktemp() - shutil.copyfile(self.new_mbox, self.mbox_name) - append_file(self.old_mbox, self.mbox_name) - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - assert(filecmp.cmp(self.new_mbox, self.mbox_name, shallow=0)) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.old_mbox, shallow=0)) - assert(not os.path.exists(archive_name + ".gz")) + """archiving a mixed mailbox uncompressed""" + for execute in ("package", "system"): + self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) + self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_name = tempfile.mktemp() + shutil.copyfile(self.new_mbox, self.mbox_name) + append_file(self.old_mbox, self.mbox_name) + if execute == "package": + archivemail.options.no_compress = 1 + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --no-compress --quiet %s" % \ + self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + assert(filecmp.cmp(self.new_mbox, self.mbox_name, shallow=0)) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.old_mbox, shallow=0)) + assert(not os.path.exists(archive_name + ".gz")) + self.tearDown() def testOldExists(self): - """archiving an old mailbox without compressing with an existing archive""" - self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) - self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.copy_name = tempfile.mktemp() - archive_name = self.mbox_name + "_archive" - shutil.copyfile(self.mbox_name, self.copy_name) - shutil.copyfile(self.mbox_name, archive_name) # archive has 3 msgs - append_file(self.mbox_name, self.copy_name) # copy now has 6 msgs - archivemail.archive(self.mbox_name) - assert(os.path.exists(self.mbox_name)) - self.assertEqual(os.path.getsize(self.mbox_name), 0) - new_mode = os.stat(self.mbox_name)[stat.ST_MODE] - self.assertEqual(self.mbox_mode, new_mode) - archive_name = self.mbox_name + "_archive" - assert(os.path.exists(archive_name)) - assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) - assert(not os.path.exists(archive_name + ".gz")) + """archiving an old mailbox uncopressed with an existing archive""" + for execute in ("package", "system"): + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) + self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.copy_name = tempfile.mktemp() + archive_name = self.mbox_name + "_archive" + shutil.copyfile(self.mbox_name, self.copy_name) + shutil.copyfile(self.mbox_name, archive_name) # archive has 3 msgs + append_file(self.mbox_name, self.copy_name) # copy now has 6 msgs + if execute == "package": + archivemail.options.no_compress = 1 + archivemail.options.quiet = 1 + archivemail.archive(self.mbox_name) + elif execute == "system": + run = "./archivemail.py --no-compress --quiet %s" % \ + self.mbox_name + self.assertEqual(os.system(run), 0) + else: + sys.exit(1) + assert(os.path.exists(self.mbox_name)) + self.assertEqual(os.path.getsize(self.mbox_name), 0) + new_mode = os.stat(self.mbox_name)[stat.ST_MODE] + self.assertEqual(self.mbox_mode, new_mode) + archive_name = self.mbox_name + "_archive" + assert(os.path.exists(archive_name)) + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0)) + assert(not os.path.exists(archive_name + ".gz")) + self.tearDown() def tearDown(self): archivemail.options.quiet = 0 |