From: Olivier Matz Date: Wed, 30 Nov 2016 10:28:30 +0000 (+0100) Subject: XXX tmp: add reldate X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c8221c7f65ef987e73cff4cc910b3e85dd2fca1a;p=imapami.git XXX tmp: add reldate --- diff --git a/imapami/conditions.py b/imapami/conditions.py index 6b45510..f674bd5 100644 --- a/imapami/conditions.py +++ b/imapami/conditions.py @@ -31,6 +31,7 @@ import imapami.utils import logging import re +import time _all_conditions = {} @@ -310,16 +311,35 @@ class ImapamiCondSentBefore(ImapamiCond): be filtered by the IMAP server. Arguments: - sent-before: - The reference date. The format is day-month-year, with: + date: [optional] + The absolute date. The format is day-month-year, with: day = 2 digits, month = 3 letter string (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec), year = 4 digits. + If date is specified, reldate must not be set. + reldate: [optional] + The relative date. The format is a integer followed by a + letter ('y' year, 'm' month, 'w' week, 'd' days). + If reldate is specified, date must not be set. Example: sent-before: {date: 28-Oct-2015} + sent-before: {reldate: 1m} """ name = "sent-before" - def __init__(self, date): + def __init__(self, **kwargs): + date = kwargs.get("date", None) + reldate = kwargs.get("reldate", None) + if date is not None and reldate is not None: + raise ValueError("cannot set date and reldate at the same time") + if date is None and reldate is None: + raise ValueError("no date specified") + if reldate: + t = time.time() + t -= int(reldate) * 3600 * 24 # XXX + t = time.gmtime(t) + month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec"][t.tm_mon] + date = "%d-%s-%d" %(t.tm_mday, month, t.tm_year) ImapamiCond.__init__(self, criteria=set(['SENTBEFORE "%s"' % date])) register(ImapamiCondSentBefore) @@ -332,7 +352,7 @@ class ImapamiCondSentOn(ImapamiCond): be filtered by the IMAP server. Arguments: - sent-on: + date: The reference date. The format is day-month-year, with: day = 2 digits, month = 3 letter string (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec), year = 4 digits. @@ -354,7 +374,7 @@ class ImapamiCondSentSince(ImapamiCond): be filtered by the IMAP server. Arguments: - sent-since: + date: The reference date. The format is day-month-year, with: day = 2 digits, month = 3 letter string (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec), year = 4 digits.