Bug 6210 - Support timestamp and modulo (%) in conditionals, e.g. if (time < 1253806618)
Summary: Support timestamp and modulo (%) in conditionals, e.g. if (time < 1253806618)
Status: RESOLVED WONTFIX
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Rules (show other bugs)
Version: unspecified
Hardware: Other All
: P5 enhancement
Target Milestone: Undefined
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-24 09:42 UTC by Adam Katz
Modified: 2019-08-09 15:24 UTC (History)
2 users (show)



Attachment Type Modified Status Actions Submitter/CLA Status

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Katz 2009-09-24 09:42:24 UTC
Please allow if() to deal with time, date, and time of day, and add the modulo (%) operator to the acceptable arithmetic operators.  This is specifically useful for rulesets that need to expire, like my bug 6114.

(from the perldoc for Mail::SpamAssassin::Conf)
> The conditional accepts a limited subset of perl for security --
> just enough to perform basic arithmetic comparisons.  The following
> input is accepted:
>
> numbers, whitespace, arithmetic operations and grouping
>       ( ) - + * / _ . , < = > ! ~ 0-9 whitespace
> version
> plugin(Name::Of::Plugin)

(Uh, note that it doesn't mention || and && are acceptable...)

I just want to add one arithmetic operator and three simple variables to that.  Modulo and the first variable are trivial because they already exists in perl.  The others should be all-but trivial.  Formatted like the perldoc:

time
    The UNIX time, seconds since 1970-01-01 00:00:00 UTC
date
    The date in the form CCYYMMDDhhmm.ss (local time),
    so 200901021533.04 is 2009 January 2 3:33:04 PM.
weektime
    Seconds since Sunday 00:00:00 (local time), H*3600+M*60+S,
    so 223021 = Tuesday at 13:57:01 (1:57:01p).
    You can get the time of day (in seconds) with (weektime % 86400).
    You can get the day of week with ( (weektime - weektime % 86400) / 86400).


Examples:

  if (time < 1257698474)  # before 45 days from now (`date -d '45 days' +%s`)
    ...
  endif
  # or by the math; y2k + 10y + 3 leap-days = 2010/1/1 00:00:00 UTC
  if (time < (946684800+((365*10+3)*24*60*60)) )
    ...
  endif
  if (date < 201001010000) # before 2010-01-01 00:00:00 EDT
    ....
  endif
  # work week check ( is sunday or is saturday or is before 8a or is after 6p )
  if (weektime < 86400 || weektime > 86400 * 6 
      || weektime % 86400 < 28800 || 64800 < weektime % 86400)
    ...
  endif
Comment 1 Michael Parker 2009-09-24 09:49:32 UTC
The conditionals are only used when parsing the rules at startup time, what will the behavior be for a long running process?
Comment 2 Henrik Krohns 2019-07-31 13:02:33 UTC
Closing old stale bug. I don't think it's worth bloating code for, as said it would be very hard to evaluate everything runtime, atleast if syntax won't cut it.
Comment 3 Henrik Krohns 2019-08-09 15:24:55 UTC
*** Bug 7436 has been marked as a duplicate of this bug. ***