[PATCH] Inform when maxage/startdate is in the future

Łukasz Żarnowiecki dolohow at outlook.com
Thu May 5 18:32:50 BST 2016


Sometimes it might happen that you put wrong date and you except emails
to be fetched, but they are not and you do not have an idea why.

By raising exception the user will see a proper message telling that he
used the wrong date for maxage/startdate property.

If someone wants to set a future date intentionally might as well sync
in the future.

Signed-off-by: Łukasz Żarnowiecki <dolohow at outlook.com>
---
 offlineimap/folder/Base.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 14b0867..f284142 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -335,6 +335,10 @@ class BaseFolder(object):
                 raise OfflineImapError("maxage led to year %d. "
                     "Abort syncing."% date[0],
                     OfflineImapError.ERROR.MESSAGE)
+            if (time.mktime(date) - time.mktime(time.localtime())) > 0:
+                raise OfflineImapError("maxage led to future date %s. "
+                    "Abort syncing."% maxagestr,
+                    OfflineImapError.ERROR.MESSAGE)
             return date
         except ValueError:
             raise OfflineImapError("invalid maxage value %s"% maxagestr,
@@ -356,6 +360,10 @@ class BaseFolder(object):
                 raise OfflineImapError("startdate led to year %d. "
                     "Abort syncing."% date[0],
                     OfflineImapError.ERROR.MESSAGE)
+            if (time.mktime(date) - time.mktime(time.localtime())) > 0:
+                raise OfflineImapError("startdate led to future date %s. "
+                    "Abort syncing."% datestr,
+                    OfflineImapError.ERROR.MESSAGE)
             return date
         except ValueError:
             raise OfflineImapError("invalid startdate value %s",
-- 
2.8.2





More information about the OfflineIMAP-project mailing list