[imapfilter-devel] Filtering by date in IMAPFilter
Luigi Iotti
luigi at iotti.biz
Sun Mar 7 15:32:27 EET 2004
I was looking for a tool that moves pre-2003 e-mail messages in a different
IMAP folder. IMAPFilter seems to be the right tool, but I found that with
the 'older' mask I can only use a number of days (so the demarcation between
old-new messages varies as days pass), not a fixed date in time (for
example, 01-Jan-2004).
I am not a programmer at all, but having a look inside the source (for what
I can understand) it seems that IMAP talks about BEFORE 'date' and SINCE
'date', so having the feature that I need seems fairly easy.
I tried to write a patch that does the job. It seems to work for me, so I
include it here. There was only the need for creating some new 'mask' types
that simply pass a command to the IMAP server. The new masks take a string
argument, which must be a date as defined in the IMAP RFC (for example,
05-Jan-2003 ).
Surely, things could be improved, for example parsing the string to verify
it is really a date. But this would be too difficult for me, so I simply
took the date as a sting, like in the 'subject' mask.
Hope this can be useful to someone.
Luigi Iotti
The patch:
diff -uarN imapfilter-0.9.6.orig/filter.c imapfilter-0.9.6/filter.c
--- imapfilter-0.9.6.orig/filter.c 2004-02-08 22:45:01.000000000 +0100
+++ imapfilter-0.9.6/filter.c 2004-03-27 14:18:28.000000000 +0100
@@ -281,7 +281,7 @@
break;
case MASK_MATCH_2:
- /* Mask is BCC, BODY, CC, FROM, SUBJECT, TEXT, TO. */
+ /* Mask is BCC, BODY, CC, FROM, SUBJECT, TEXT, TO, BEFORE,
ON, SINCE, SENTBEFORE, SENTON, SENTSINCE. */
*(bp++) = ' ';
diff -uarN imapfilter-0.9.6.orig/imapfilterrc.5
imapfilter-0.9.6/imapfilterrc.5
--- imapfilter-0.9.6.orig/imapfilterrc.5 2004-02-08
22:45:01.000000000 +0100
+++ imapfilter-0.9.6/imapfilterrc.5 2004-03-27 14:15:38.000000000 +0100
@@ -155,6 +155,10 @@
in the envelope structure's
.Dq Bcc
field.
+.It Cm before Ar string
+Messages whose internal date (disregarding time and timezone) is earlier
than the specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
.It Cm body Ar string
Messages that contain the specified
.Ar string
@@ -205,6 +209,10 @@
Messages whose internal date is older than the specified
.Ar number
of days.
+.It Cm on Ar string
+Messages whose internal date (disregarding time and timezone) is within the
specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
.It Cm recent
Messages that have
.Qq recently
@@ -212,6 +220,22 @@
first, to have been notified about the messages).
.It Cm seen
Messages that have been read.
+.It Cm sentbefore Ar string
+Messages whose RFC-2822 date: header (disregarding time and timezone) is
earlier than the specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
+.It Cm senton Ar string
+Messages whose RFC-2822 date: header (disregarding time and timezone) is
within the specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
+.It Cm sentsince Ar string
+Messages whose RFC-2822 date: header (disregarding time and timezone) is
within or later than the specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
+.It Cm since Ar string
+Messages whose internal date (disregarding time and timezone) is within or
later than the specified
+.Ar string
+; string should specify a date in RFC3501 format (Ex. 03-Jan-1969)
.It Cm smaller Ar number
Messages with size smaller than the specified
.Ar number
diff -uarN imapfilter-0.9.6.orig/parse.c imapfilter-0.9.6/parse.c
--- imapfilter-0.9.6.orig/parse.c 2004-02-08 22:45:01.000000000 +0100
+++ imapfilter-0.9.6/parse.c 2004-03-27 14:17:14.000000000 +0100
@@ -121,7 +121,8 @@
"^[[:blank:]]*(MASK[[:blank:]])?[[:blank:]]*(OR[[:blank:]]|"
"AND[[:blank:]])?[[:blank:]]*(NOT[[:blank:]])?[[:blank:]]*"
- "(BCC|BODY|CC|FROM|SUBJECT|TEXT|TO)[[:blank:]]+"
+ "(BCC|BODY|CC|FROM|SUBJECT|TEXT|TO|"
+ "BEFORE|ON|SINCE|SENTBEFORE|SENTON|SENTSINCE)[[:blank:]]+"
"(\"[[:print:]]*\"|[[:graph:]]+)[[:blank:]]*\n$",
"^[[:blank:]]*(MASK[[:blank:]])?[[:blank:]]*(OR[[:blank:]]|"
More information about the Imapfilter-devel
mailing list