Re: [exim] Limit ingress outdated mails

Pàgina inicial
Delete this message
Reply to this message
Autor: Chris Lightfoot
Data:  
A: Dave Evans
CC: exim-users
Assumpte: Re: [exim] Limit ingress outdated mails
On Sat, May 27, 2006 at 11:28:54AM +0100, Dave Evans wrote:
> On Fri, May 26, 2006 at 08:46:21AM +0200, Balzi Andrea wrote:
> > I am trying to create a filter for the mail with older or greater date
> > than 7 days.
> > I am trying in the documentation of version 4.6 something that can help
> > me. Someone can gives a suggestion to me?
>
> Is it taboo on this list to point out that it can be done by using the ${perl}
> or ${run} expansions? e.g. Using Perl, the Mail::Field module might come in
> handy, or maybe the underlying Date::Parse module. It should be possible to
> construct a function such that
>
> date_age($date_header, $default)
>
> returns the age (in days, or seconds, or whatever you prefer) of $date_header
> compared to now, or $default if $date_header could not be parsed. You could
> then use a simple arithmetic comparison in the "data" ACL.


suppose that you have $h_date and you are confident that
it is a valid rfc[2]822 date (you can test that using a
regular expression which you can trivially construct).

You can then form an ISO-8601 date for the message like
this:

    ${substr_13_4:$h_date}${sg{${sg{${sg{${sg{${sg{${sg{${sg{${sg{${sg{${sg{${sg{${sg{$substr_9_3:$h_date}{Jan}{01}}}{Feb}{02}}}{Mar}{03}}}{Apr}{04}}}{May}{05}}}{Jun}{06}}}{Jul}{07}}}{Aug}{08}}}{Sep}{09}}}{Oct}{10}}}{Nov}{11}}}{Dec}{12}}${substr_5_2:$h_date}


Once you have the dates in ISO-8601 format it is trivial
to convert them to Julian day numbers by a further
application of ${substr...} and ${eval10...}; the algorithm
is as given here:
    http://en.wikipedia.org/wiki/Julian_day#Calculation
and its implementation in Exim is as follows, given a
notional ISO date DATE:


    ${eval10:
        ${substr_6_2:DATE}
            + (153 * (${substr_2_2:DATE} + 12 * (14 - ${substr_2_2:DATE}) / 12 - 3) + 2) / 5
            + 365 * ${substr_0_4:DATE}
            + ${substr_0_4:DATE} / 4
            - ${substr_0_4:DATE} / 100
            + ${substr_0_4:DATE} / 400
            - 32045}}


The ISO-8601 value for the current date is of course
${substr_0_8:$tod_zulu}.

Once you have two Julian day numbers it is trivial to test
whether one is within seven days of the other (this is
just an arithmetic test).

I am sure you will agree that this is much neater than the
perl solution. Perl is also notoriously unreadable, so
this version will be more maintainable.

--
``Large increases in cost with questionable increases in performance
can be tolerated only in racehorses and fancy women.'' (Lord Kelvin)