mirror of
https://git.code.sf.net/p/archivemail/code
synced 2025-02-21 23:06:56 +00:00
Made sure that we don't archive messages flagged important unless we are
given the --include-flagged option.
This commit is contained in:
parent
fd61a98c46
commit
80b2b99194
1 changed files with 37 additions and 10 deletions
|
@ -22,7 +22,7 @@ Website: http://archivemail.sourceforge.net/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# global administrivia
|
# global administrivia
|
||||||
__version__ = "archivemail v0.4.0"
|
__version__ = "archivemail v0.4.1"
|
||||||
__cvs_id__ = "$Id$"
|
__cvs_id__ = "$Id$"
|
||||||
__copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com>
|
__copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com>
|
||||||
This is free software; see the source for copying conditions. There is NO
|
This is free software; see the source for copying conditions. There is NO
|
||||||
|
@ -135,6 +135,7 @@ class Options:
|
||||||
days_old_max = 180
|
days_old_max = 180
|
||||||
delete_old_mail = 0
|
delete_old_mail = 0
|
||||||
dry_run = 0
|
dry_run = 0
|
||||||
|
include_flagged = 0
|
||||||
lockfile_attempts = 5
|
lockfile_attempts = 5
|
||||||
lockfile_extension = ".lock"
|
lockfile_extension = ".lock"
|
||||||
lockfile_sleep = 1
|
lockfile_sleep = 1
|
||||||
|
@ -162,8 +163,9 @@ class Options:
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(args, '?Vd:hno:qs:uv',
|
opts, args = getopt.getopt(args, '?Vd:hno:qs:uv',
|
||||||
["days=", "delete", "dry-run", "help",
|
["days=", "delete", "dry-run", "help",
|
||||||
"preserve-unread", "no-compress", "output-dir=",
|
"include-flagged", "no-compress",
|
||||||
"quiet", "suffix", "verbose", "version",
|
"output-dir=", "preserve-unread", "quiet",
|
||||||
|
"suffix", "verbose", "version",
|
||||||
"warn-duplicate"])
|
"warn-duplicate"])
|
||||||
except getopt.error, msg:
|
except getopt.error, msg:
|
||||||
user_error(msg)
|
user_error(msg)
|
||||||
|
@ -171,14 +173,12 @@ class Options:
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '--delete':
|
if o == '--delete':
|
||||||
self.delete_old_mail = 1
|
self.delete_old_mail = 1
|
||||||
if o in ('-u', '--preserve-unread'):
|
if o == '--include-flagged':
|
||||||
self.preserve_unread = 1
|
self.include_flagged = 1
|
||||||
if o == '--no-compress':
|
if o == '--no-compress':
|
||||||
self.no_compress = 1
|
self.no_compress = 1
|
||||||
if o == '--warn-duplicate':
|
if o == '--warn-duplicate':
|
||||||
self.warn_duplicates = 1
|
self.warn_duplicates = 1
|
||||||
if o in ('-n', '--dry-run'):
|
|
||||||
self.dry_run = 1
|
|
||||||
if o in ('-d', '--days'):
|
if o in ('-d', '--days'):
|
||||||
self.days_old_max = string.atoi(a)
|
self.days_old_max = string.atoi(a)
|
||||||
if o in ('-o', '--output-dir'):
|
if o in ('-o', '--output-dir'):
|
||||||
|
@ -186,12 +186,16 @@ class Options:
|
||||||
if o in ('-h', '-?', '--help'):
|
if o in ('-h', '-?', '--help'):
|
||||||
print usage
|
print usage
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
if o in ('-n', '--dry-run'):
|
||||||
|
self.dry_run = 1
|
||||||
if o in ('-q', '--quiet'):
|
if o in ('-q', '--quiet'):
|
||||||
self.quiet = 1
|
self.quiet = 1
|
||||||
if o in ('-v', '--verbose'):
|
|
||||||
self.verbose = 1
|
|
||||||
if o in ('-s', '--suffix'):
|
if o in ('-s', '--suffix'):
|
||||||
self.archive_suffix = a
|
self.archive_suffix = a
|
||||||
|
if o in ('-u', '--preserve-unread'):
|
||||||
|
self.preserve_unread = 1
|
||||||
|
if o in ('-v', '--verbose'):
|
||||||
|
self.verbose = 1
|
||||||
if o in ('-V', '--version'):
|
if o in ('-V', '--version'):
|
||||||
print __version__ + "\n\n" + __copyright__
|
print __version__ + "\n\n" + __copyright__
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -522,6 +526,7 @@ Options are as follows:
|
||||||
-n, --dry-run don't write to anything - just show what would be done
|
-n, --dry-run don't write to anything - just show what would be done
|
||||||
-u, --preserve-unread never archive unread messages
|
-u, --preserve-unread never archive unread messages
|
||||||
--delete delete rather than archive old mail (use with caution!)
|
--delete delete rather than archive old mail (use with caution!)
|
||||||
|
--include-flagged messages flagged important can also be archived
|
||||||
--no-compress do not compress archives with gzip
|
--no-compress do not compress archives with gzip
|
||||||
--warn-duplicate warn about duplicate Message-IDs in the same mailbox
|
--warn-duplicate warn about duplicate Message-IDs in the same mailbox
|
||||||
-v, --verbose report lots of extra debugging information
|
-v, --verbose report lots of extra debugging information
|
||||||
|
@ -649,11 +654,31 @@ def guess_delivery_time(message):
|
||||||
return time_message
|
return time_message
|
||||||
|
|
||||||
|
|
||||||
|
def is_flagged(message):
|
||||||
|
"""return true if the message is flagged important, false otherwise"""
|
||||||
|
# MH and mbox mailboxes use the 'X-Status' header to indicate importance
|
||||||
|
x_status = message.get('X-Status')
|
||||||
|
if x_status and re.search('F', x_status):
|
||||||
|
vprint("message is important (X-Status header='%s')" % x_status)
|
||||||
|
return 1
|
||||||
|
file_name = None
|
||||||
|
try:
|
||||||
|
file_name = message.fp.name
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
# maildir mailboxes use the filename suffix to indicate flagged status
|
||||||
|
if file_name and re.search(":2,.*F.*$", file_name):
|
||||||
|
vprint("message is important (filename info has 'F')")
|
||||||
|
return 1
|
||||||
|
vprint("message is not flagged important")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def is_unread(message):
|
def is_unread(message):
|
||||||
"""return true if the message is unread, false otherwise"""
|
"""return true if the message is unread, false otherwise"""
|
||||||
# MH and mbox mailboxes use the 'Status' header to indicate read status
|
# MH and mbox mailboxes use the 'Status' header to indicate read status
|
||||||
status = message.get('Status')
|
status = message.get('Status')
|
||||||
if (status == 'RO') or (status == 'OR'):
|
if status and re.search('R', status):
|
||||||
vprint("message has been read (status header='%s')" % status)
|
vprint("message has been read (status header='%s')" % status)
|
||||||
return 0
|
return 0
|
||||||
file_name = None
|
file_name = None
|
||||||
|
@ -676,6 +701,8 @@ def should_archive(message):
|
||||||
# I could probably do this in one if statement, but then I wouldn't
|
# I could probably do this in one if statement, but then I wouldn't
|
||||||
# understand it.
|
# understand it.
|
||||||
if old:
|
if old:
|
||||||
|
if not options.include_flagged and is_flagged(message):
|
||||||
|
return 0
|
||||||
if options.preserve_unread:
|
if options.preserve_unread:
|
||||||
if is_unread(message):
|
if is_unread(message):
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue