diff options
author | Nikolaus Schulz <microschulz@web.de> | 2010-07-30 23:26:22 +0200 |
---|---|---|
committer | Nikolaus Schulz <microschulz@web.de> | 2010-07-31 20:49:03 +0200 |
commit | b6bc92c34f255054a7fd2128a024a5ae26cd1026 (patch) | |
tree | ac3268c8f698f38d866ce164ad3c3d62b86a678c /archivemail | |
parent | f22fe4decd9a70a2eb826ecdd14f9d1bb3b4e394 (diff) | |
download | archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.tar.gz archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.tar.bz2 archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.zip |
New option --archive-prefix, alias -p
Technically, this works just like the --suffix option. This commit also
updates the manpage accordingly.
Currently, the prefix is not checked for slashes, so it could contain path
components. (The same applies for the suffix, btw). Since the expanded
string is prepended to the archive base name, this can be used to dynamically
configure the archive directory, depending on the archive cutoff date. I'm
not sure if this can be considered a reasonable feature, though.
Diffstat (limited to 'archivemail')
-rwxr-xr-x | archivemail | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/archivemail b/archivemail index 52ec06b..0ace88a 100755 --- a/archivemail +++ b/archivemail @@ -171,6 +171,7 @@ class StaleFiles: class Options: """Class to store runtime options, including defaults""" + archive_prefix = None archive_suffix = "_archive" days_old_max = 180 date_old_max = None @@ -209,12 +210,12 @@ class Options: """ try: - opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uv', + opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:p:uv', ["date=", "days=", "delete", "dry-run", "help", "include-flagged", "no-compress", "output-dir=", "filter-append=", "pwfile=", "dont-mangle", "preserve-unread", "quiet", "size=", "suffix=", - "verbose", "debug-imap=", "version", + "prefix=", "verbose", "debug-imap=", "version", "warn-duplicate", "copy", "all"]) except getopt.error, msg: user_error(msg) @@ -257,6 +258,8 @@ class Options: self.quiet = True if o in ('-s', '--suffix'): self.archive_suffix = a + if o in ('-p', '--prefix'): + self.archive_prefix = a if o in ('-S', '--size'): self.min_size = string.atoi(a) if o in ('-u', '--preserve-unread'): @@ -642,6 +645,7 @@ Options are as follows: -o, --output-dir=DIR directory to store archives (default: same as original) -P, --pwfile=FILE file to read imap password from (default: None) -F, --filter-append=STRING append arbitrary string to the IMAP filter string + -p, --prefix=NAME prefix for archive filename (default: none) -s, --suffix=NAME suffix for archive filename (default: '%s') -S, --size=NUM only archive messages NUM bytes or larger -n, --dry-run don't write to anything - just show what would be done @@ -1626,21 +1630,25 @@ def commit_archive(archive, final_archive_name): def make_archive_name(mailbox_name): """Derive archive name and (relative) path from the mailbox name.""" - # allow the user to embed time formats such as '%B' in the suffix string + # allow the user to embed time formats such as '%B' in the prefix or suffix string if options.date_old_max == None: - parsed_suffix_time = time.time() - options.days_old_max*24*60*60 + tm = time.localtime(time.time() - options.days_old_max*24*60*60) else: - parsed_suffix_time = options.date_old_max - parsed_suffix = time.strftime(options.archive_suffix, - time.localtime(parsed_suffix_time)) - + tm = time.localtime(options.date_old_max) + prefix = suffix = "" + if options.archive_prefix: + prefix = time.strftime(options.archive_prefix, tm) + if options.archive_suffix: + suffix = time.strftime(options.archive_suffix, tm) if re.match(r'imaps?://', mailbox_name.lower()): - mailbox_name = mailbox_name.rsplit('/', 1)[-1] - final_archive_name = mailbox_name + parsed_suffix + archive_dir = "" + archive_base = mailbox_name.rsplit('/', 1)[-1] + else: + archive_dir, archive_base = os.path.split(mailbox_name) if options.output_dir: - final_archive_name = os.path.join(options.output_dir, - os.path.basename(final_archive_name)) - return final_archive_name + archive_dir = options.output_dir + archive_name = os.path.join(archive_dir, prefix + archive_base + suffix) + return archive_name def check_sane_destdir(dir): """Do a very primitive check if the given directory looks like a reasonable |