newerthan #1

Merged
mwtkrayer merged 6 commits from newerthan into master 2020-05-22 11:55:05 +00:00
1 changed files with 45 additions and 0 deletions
Showing only changes of commit 54604011b3 - Show all commits

View File

@ -1012,11 +1012,17 @@ def should_archive(message):
old = is_older_than_days(time_message, options.days_old_max)
else:
old = is_older_than_time(time_message, options.date_old_max)
if options.date_old_min == None:
new = is_younger_than_days(time_message, options.days_old_min)
else:
new = is_younger_than_time(time_message, options.date_old_min)
# I could probably do this in one if statement, but then I wouldn't
# understand it.
if not old:
return False
if not new:
return False
if not options.include_flagged and is_flagged(message):
return False
if options.min_size and is_smaller(message, options.min_size):
@ -1065,6 +1071,45 @@ def is_older_than_days(time_message, max_days):
return True
return False
def is_younger_than_time(time_message, min_time):
"""Return true if a message is newer than the specified time,
false otherwise.
Arguments:
time_message -- the delivery date of the message measured in seconds
since the epoch
min_time -- minimum time allowed for message
"""
days_old = (min_time - time_message) / 24 / 60 / 60
if time_message >= min_time:
vprint("message is %.2f days newer than the specified date" % days_old)
return True
vprint("message is %.2f days older than the specified date" % \
abs(days_old))
return False
def is_younger_than_days(time_message, min_days):
"""Return true if a message is newer than the specified number of days,
false otherwise.
Arguments:
time_message -- the delivery date of the message measured in seconds
since the epoch
min_days -- minimum number of days before message is considered old
"""
time_now = time.time()
if time_message > time_now:
vprint("warning: message has date in the future")
return False
secs_old_min = (min_days * 24 * 60 * 60)
days_old = (time_now - time_message) / 24 / 60 / 60
vprint("message is %.2f days old" % days_old)
if ((time_message + secs_old_min) >= time_now):
return True
return False
def build_imap_filter():
"""Return an imap filter string"""