1 # Description: add, document and test --prefix option for archive name
2 # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=247340
3 # Author: Serafeim Zanikolas <serzan@hellug.gr>
4 # Last-Update: 2009-02-22
5 Index: archivemail/archivemail
6 ===================================================================
7 --- archivemail.orig/archivemail 2008-08-15 21:40:17.000000000 +0100
8 +++ archivemail/archivemail 2008-08-15 21:40:17.000000000 +0100
12 """Class to store runtime options, including defaults"""
13 + archive_prefix = None
14 archive_suffix = "_archive"
21 - opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uv',
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=",
27 "filter-append=", "pwfile=", "dont-mangle",
28 "preserve-unread", "quiet", "size=", "suffix=",
29 - "verbose", "version", "warn-duplicate", "copy"])
30 + "verbose", "version", "warn-duplicate", "copy",
32 except getopt.error, msg:
37 if o in ('-q', '--quiet'):
39 + if o in ('-p', '--prefix'):
40 + self.archive_prefix = a
41 if o in ('-s', '--suffix'):
42 self.archive_suffix = a
43 if o in ('-S', '--size'):
45 -o, --output-dir=DIR directory to store archives (default: same as original)
46 -P, --pwfile=FILE file to read imap password from (default: None)
47 -F, --filter-append=STRING append arbitrary string to the IMAP filter string
48 + -p, --prefix=NAME prefix for archive filename (default: none)
49 -s, --suffix=NAME suffix for archive filename (default: '%s')
50 --archive-name=NAME specify whole archive filename, overrides prefix
52 @@ -1124,8 +1129,11 @@
53 final_archive_name = mailbox_name.split('/')[-1] + parsed_suffix
55 final_archive_name = mailbox_name + parsed_suffix
56 + if options.archive_prefix:
57 + final_archive_name = os.path.join(os.path.dirname(final_archive_name),\
58 + options.archive_prefix + os.path.basename(final_archive_name))
59 if options.archive_name:
60 - final_archive_name = options.archive_name
61 + final_archive_name = options.archive_name
62 if options.output_dir:
63 final_archive_name = os.path.join(options.output_dir,
64 os.path.basename(final_archive_name))
65 Index: archivemail/test_archivemail.py
66 ===================================================================
67 --- archivemail.orig/test_archivemail.py 2008-08-15 21:40:17.000000000 +0100
68 +++ archivemail/test_archivemail.py 2008-08-15 21:40:17.000000000 +0100
70 archivemail.options.archive_suffix = "_archive"
71 super(TestArchiveMboxSuffix, self).tearDown()
73 +class TestArchiveMboxPrefix(TestCaseInTempdir):
74 + """make sure the 'prefix' option works"""
76 + super(TestArchiveMboxPrefix, self).setUp()
77 + archivemail.options.quiet = 1
79 + def testPrefix(self):
80 + """archiving with specified --prefix arguments"""
81 + for prefix in ["blah-"]:
82 + for execute in ("system_long", "system_short", "package"):
85 + self.mbox_name = make_mbox(messages=3,
86 + hours_old=(24 * (days_old_max+1)))
87 + self.copy_name = tempfile.mkstemp()[1]
88 + shutil.copyfile(self.mbox_name, self.copy_name)
89 + if execute == "system_long":
90 + run = "./archivemail.py --quiet --prefix='%s' %s" % \
91 + (prefix, self.mbox_name)
92 + self.assertEqual(os.system(run), 0)
93 + elif execute == "system_short":
94 + run = "./archivemail.py --quiet -p'%s' %s" % \
95 + (prefix, self.mbox_name)
96 + self.assertEqual(os.system(run), 0)
97 + elif execute == "package":
98 + archivemail.options.archive_prefix = prefix
99 + archivemail.archive(self.mbox_name)
102 + assert(os.path.exists(self.mbox_name))
103 + self.assertEqual(os.path.getsize(self.mbox_name), 0)
105 + archive_name = os.path.join(os.path.dirname(self.mbox_name),\
106 + prefix + os.path.basename(self.mbox_name) +\
108 + assert(os.path.exists(archive_name))
109 + self.assertEqual(os.system("gzip -d %s" % archive_name), 0)
110 + archive_name = re.sub("\.gz$", "", archive_name)
111 + assert(os.path.exists(archive_name))
112 + assert(filecmp.cmp(archive_name, self.copy_name, shallow=0))
113 + os.remove(archive_name)
116 + def tearDown(self):
117 + archivemail.options.quiet = 0
118 + archivemail.options.archive_prefix = None
119 + super(TestArchiveMboxPrefix, self).tearDown()
122 class TestArchiveDryRun(TestCaseInTempdir):
123 """make sure the 'dry-run' option works"""
124 Index: archivemail/archivemail.sgml
125 ===================================================================
126 --- archivemail.orig/archivemail.sgml 2008-08-15 21:38:49.000000000 +0100
127 +++ archivemail/archivemail.sgml 2008-08-15 21:40:34.000000000 +0100
132 + <Option>-p <Replaceable/NAME/, --prefix=<Replaceable/NAME/</Option>
134 +<ListItem><Para>Prefix <Replaceable/NAME/ to the archive name.
140 <Option>-s <Replaceable/NAME/, --suffix=<Replaceable/NAME/</Option>