1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-22 15:56:27 +00:00

Renamed variable 'filter' to prevent conflicts with the builtin function.

This commit is contained in:
Nikolaus Schulz 2006-11-01 00:40:26 +00:00
parent e9a11944f1
commit 86f1fec50d

View file

@ -1021,7 +1021,7 @@ def is_older_than_days(time_message, max_days):
def build_imap_filter(invert = False): def build_imap_filter(invert = False):
"""Return an imap filter string""" """Return an imap filter string"""
filter = [] imap_filter = []
old = 0 old = 0
if options.date_old_max == None: if options.date_old_max == None:
time_now = time.time() time_now = time.time()
@ -1030,24 +1030,24 @@ def build_imap_filter(invert = False):
else: else:
time_old = time.gmtime(options.date_old_max) time_old = time.gmtime(options.date_old_max)
time_str = time.strftime('%d-%b-%Y', time_old) time_str = time.strftime('%d-%b-%Y', time_old)
filter.append("BEFORE %s" % time_str) imap_filter.append("BEFORE %s" % time_str)
if not options.include_flagged: if not options.include_flagged:
filter.append("UNFLAGGED") imap_filter.append("UNFLAGGED")
if options.min_size: if options.min_size:
filter.append("LARGER %d" % options.min_size) imap_filter.append("LARGER %d" % options.min_size)
if options.preserve_unread: if options.preserve_unread:
filter.append("SEEN") imap_filter.append("SEEN")
if options.filter_append: if options.filter_append:
filter.append(options.filter_append) imap_filter.append(options.filter_append)
if not invert: if not invert:
return '(' + string.join(filter, ' ') + ')' return '(' + string.join(imap_filter, ' ') + ')'
filter = map(lambda x: 'NOT ' + x, filter) imap_filter = map(lambda x: 'NOT ' + x, imap_filter)
if len(filter) == 1: if len(imap_filter) == 1:
return '(' + filter[0] + ')' return '(' + imap_filter[0] + ')'
return reduce(lambda x,y: '(OR ' + x + ' ' + y + ')', filter) return reduce(lambda x,y: '(OR ' + x + ' ' + y + ')', imap_filter)
############### mailbox operations ############### ############### mailbox operations ###############
@ -1302,10 +1302,10 @@ def _archive_imap(mailbox_name, final_archive_name):
archive = None archive = None
stats = Stats(mailbox_name, final_archive_name) stats = Stats(mailbox_name, final_archive_name)
imap_str = mailbox_name[mailbox_name.find('://') + 3:] imap_str = mailbox_name[mailbox_name.find('://') + 3:]
filter = build_imap_filter() imap_filter = build_imap_filter()
inverse_filter = build_imap_filter(invert=True) inverse_imap_filter = build_imap_filter(invert=True)
vprint("imap filter: '%s'" % filter) vprint("imap filter: '%s'" % imap_filter)
vprint("inverse imap filter: '%s'" % inverse_filter) vprint("inverse imap filter: '%s'" % inverse_imap_filter)
try: try:
imap_username, imap_str = imap_str.split('@', 1) imap_username, imap_str = imap_str.split('@', 1)
imap_server, imap_folder = imap_str.split('/', 1) imap_server, imap_folder = imap_str.split('/', 1)
@ -1338,7 +1338,7 @@ def _archive_imap(mailbox_name, final_archive_name):
vprint("selected imap folder %s" % imap_folder) vprint("selected imap folder %s" % imap_folder)
vprint("folder has %s message(s)" % response[0]) vprint("folder has %s message(s)" % response[0])
result, response = imap_srv.search(None, inverse_filter) result, response = imap_srv.search(None, inverse_imap_filter)
if result != 'OK': unexpected_error("imap search failed") if result != 'OK': unexpected_error("imap search failed")
# response is a list with a single item, listing message ids # response is a list with a single item, listing message ids
# like ['1 2 3 1016'] # like ['1 2 3 1016']
@ -1356,7 +1356,7 @@ def _archive_imap(mailbox_name, final_archive_name):
msg_size = int(x.split()[2][:-1]) msg_size = int(x.split()[2][:-1])
stats.another_message(msg_size) stats.another_message(msg_size)
result, response = imap_srv.search(None, filter) result, response = imap_srv.search(None, imap_filter)
if result != 'OK': unexpected_error("imap search failed") if result != 'OK': unexpected_error("imap search failed")
message_list = response[0].split() message_list = response[0].split()
vprint("%d messages are matching filter" % len(message_list)) vprint("%d messages are matching filter" % len(message_list))