1 # Description: add, document and test --all option
2 # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470675
3 # Author: Serafeim Zanikolas <serzan@hellug.gr>
4 # Last-Update: 2009-02-22
5 Index: archivemail/archivemail
6 ===================================================================
7 --- archivemail.orig/archivemail 2008-09-06 15:11:32.000000000 +0100
8 +++ archivemail/archivemail 2008-09-06 15:14:23.000000000 +0100
16 lockfile_extension = ".lock"
21 - opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uvp:',
22 + opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uvp:',
23 ["date=", "days=", "delete", "dry-run", "help",
24 "include-flagged", "no-compress", "output-dir=",
26 "filter-append=", "pwfile=", "dont-mangle",
27 "preserve-unread", "quiet", "size=", "suffix=",
28 "verbose", "version", "warn-duplicate", "copy",
31 except getopt.error, msg:
35 if self.copy_old_mail:
36 user_error("found conflicting options --copy and --delete")
37 self.delete_old_mail = 1
39 + self.archive_all = 1
40 if o == '--include-flagged':
41 self.include_flagged = 1
42 if o == '--no-compress':
44 if o in ('-V', '--version'):
45 print __version__ + "\n\n" + __copyright__
47 + if self.archive_all and archive_by:
48 + user_error("--all must not be used with other " +
49 + "filtering options")
52 def sanity_check(self):
54 mailbox compressed with gzip.
56 Options are as follows:
57 + --all archive all messages (not to be used along with other
58 + filter switches; use with caution)
59 -d, --days=NUM archive messages older than NUM days (default: %d)
60 -D, --date=DATE archive messages older than DATE
61 -o, --output-dir=DIR directory to store archives (default: same as original)
64 def should_archive(message):
65 """Return true if we should archive the message, false otherwise"""
66 + if options.archive_all:
69 time_message = guess_delivery_time(message)
70 if options.date_old_max == None:
71 Index: archivemail/archivemail.sgml
72 ===================================================================
73 --- archivemail.orig/archivemail.sgml 2008-09-06 15:11:32.000000000 +0100
74 +++ archivemail/archivemail.sgml 2008-09-06 15:16:25.000000000 +0100
79 + <Option>--all</Option>
82 +Archive _all_ messages. Not to be combined with other filter switches.
88 <Option>-d <Replaceable/NUM/, --days=<Replaceable/NUM/</Option>
90 <ListItem><Para>Archive messages older than <Replaceable/NUM/ days.
91 Index: archivemail/test_archivemail.py
92 ===================================================================
93 --- archivemail.orig/test_archivemail.py 2008-09-06 15:13:17.000000000 +0100
94 +++ archivemail/test_archivemail.py 2008-09-06 19:58:49.000000000 +0100
96 super(TestArchiveDryRun, self).tearDown()
99 +class TestArchiveAll(TestCaseInTempdir):
100 + """make sure the 'all' option works"""
102 + super(TestArchiveAll, self).setUp()
103 + archivemail.options.quiet = 1
105 + def testValidUse(self):
106 + """test that it works when used without any other archive_by option"""
107 + for execute in ("package", "system_long"):
109 + self.mbox_name = make_mbox(messages=3, hours_old=(24 * 12))
110 + self.mbox = archivemail.Mbox(self.mbox_name)
111 + if execute == "package":
112 + archivemail.options.archive_all = 1
113 + archivemail.archive(self.mbox_name)
114 + elif execute == "system_long":
115 + run = "./archivemail.py --all --quiet "\
116 + + "%s 2>&1 >/dev/null" % self.mbox_name
117 + self.assertEqual(os.system(run), 0)
120 + assert(os.path.exists(self.mbox_name))
121 + self.assertTrue(self.mbox.is_empty())
124 + def testInvalidUses(self):
125 + """test that it gives up with invoked with either -d or -D"""
126 + for arg in ["-d 30", "--days=30",\
127 + "-D 2008-07-30", "--date=2008-07-30"]:
128 + run = ("./archivemail.py --all %s --quiet "\
129 + + "whatever >/dev/null 2>&1") % arg
130 + self.assertEqual(os.system(run), 256)
132 + def tearDown(self):
133 + archivemail.options.archive_all = 0
134 + archivemail.options.quiet = 0
135 + super(TestArchiveAll, self).tearDown()
137 class TestArchiveDays(TestCaseInTempdir):
138 """make sure the 'days' option works"""