Gnus development mailing list
 help / color / mirror / Atom feed
* new variable nnmail-fancy-expiry-target-with-arrival-time?
@ 2003-10-31 15:28 Adrian Lanz
  2004-01-02 22:08 ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Lanz @ 2003-10-31 15:28 UTC (permalink / raw)


Here a propsal for a small addition to the expiry rules applied with
nnmail-fancy-expiry-target: The idea is to allow fancy splitting
articles into expiry groups not parsing the Date field but the
X-Gnus-Article-Number field for a valid time/date. This functionality
only applies when expiring articles kept in the nnfolder mail back end
(and does nothing [harmful] for other mail back ends).

One (my) reason to add this new functionality, was that I get
sometimes messages with illegal (for instance "internationization" of
month an day names) or (actually quite often) wrong Date fields (a
date/time entry somewhere in the future or in the past or simply a
missing date/time entry), especially in spam messages. These messages
either block the summary-exit process with an error message (see the
FIXME comments in the below function) or create stupid/unwanted/wrong
archive (expiry) group names, if I use a TARGET like "mail-%Y-%b" for
storing (archiving) mail messages by year-month.

I propose a simple boolean type variable
nnmail-fancy-expiry-target-with-arrival-time defined in nnmail.el
(feel free to find a better name!), which is documented below, and a
minor change in the nnmail-fancy-expiry-target function (it is only a
change in the definition of the local variable date, and a comment
concerning the missing fix for invalid Date header entry).

If the functionality is considered to be useful for more people, it
would be nice to see it implemented in the CVS version for testing,
Adrian.

PS: Not very programers like, here the proposed changes (please
correct wording...):

+++ Changes in the documentation (texinfo) +++
Under "Expiring Mail" and just after the nnmail-fancy-expiry-targets
example:

[...]
   With this setup, any mail that has `IMPORTANT' in its Subject header
and was sent in the year `YYYY' and month `MMM', will get expired to
the group `nnfolder:IMPORTANT.YYYY.MMM'.  If its From or To header
contains the string `boss', it will get expired to `nnfolder:Work'.
All other mail will get expired to `nnfolder:Archive-YYYY'.
++ BEGIN NEW ++
   If you expire articles from a nnfolder back end, you can set
`nnmail-fancy-expiry-target-with-arrival-time' to t (default is
nil). Then, year and month in the above example would be read from the
articles' nnfolder inserted X-Gnus-Article-Number header field instead
of the articles' original Date field, and articles will get expired in
chronological year-month groups using the (always correct, well at
least valid) articles' date and time of arrival in your nnfolder group
rather than the (sometimes wrong and/or invalid) articles' date of
sending. Invalid and/or simply wrong time/date values in the original
Date field are particularly known for spam mail.
++ END NEW ++
   If `nnmail-keep-last-article' is non-`nil', Gnus will never expire
the final article in a mail newsgroup.  This is to make life easier for
procmail users.
[...]

+++ Changes in nnmail.el +++
++ new variable ++

(defcustom nnmail-fancy-expiry-target-with-arrival-time nil
  "`nnmail-fancy-expiry-target' determines the expiry group of an
article by invoking `format-time-string' on the target given in
variable `nnmail-fancy-expiry-targets'.

Now, if this variable is t (default is nil) and the articles'
X-Gnus-Article-Number header field exist, `format-time-string'
extracts date/time from the articles' X-Gnus-Article-Number header
field (if missing the current date/time is used). The
X-Gnus-Article-Number header field is automatically inserted by the
nnfolder mail back end. It includes a date/time string indicating
arrival of the article in the current nnfolder group. This variable
has no effect under other mail back ends.

If this variable is not t, `format-time-string' extracts the date/time
from the articles' Date header field (if missing the current date/time
is used).

If you set this variable to t and use format strings in
`nnmail-fancy-expiry-targets', `nnmail-fancy-expiry-target' expires
articles into expiry groups named chronologically by the articles'
date/time of arrival in the nnfolder groups. This variable is
particularly useful, if you expire articles with invalid, wrong or
missing Date header fields (mainly spam)."
  :group 'nnmail-expire
  :type 'boolean)

++ changed function ++
(defun nnmail-fancy-expiry-target (group)
  "Returns a target expiry group determined by `nnmail-fancy-expiry-targets'."
  (let* (header
	 (case-fold-search nil)
	 (from (or (message-fetch-field "from") ""))
	 (to (or (message-fetch-field "to") ""))
	 (date (date-to-time
		(if nnmail-fancy-expiry-target-with-arrival-time
		    (or (message-fetch-field "x-gnus-article-number") (current-time-string))
		  (or (message-fetch-field "date") (current-time-string)))))
	 (target 'delete))
    (dolist (regexp-target-pair (reverse nnmail-fancy-expiry-targets) target)
      (setq header (car regexp-target-pair))
      (cond
       ;; If the header is to-from then match against the
       ;; To or From header
       ((and (equal header 'to-from)
	     (or (string-match (cadr regexp-target-pair) from)
		 (and (string-match message-dont-reply-to-names from)
		      (string-match (cadr regexp-target-pair) to))))
	;;; fixme: below, format-time-string returns an error for illegal
	;;; fixme: date strings like, e.g. Mit 12 Mai 2003 12:34:23
	;;; fixme: We would like to return a proper error message
        ;;; fixme: or apply the current date/time if an illegal date?
	(setq target (format-time-string (caddr regexp-target-pair) date)))
       ((and (not (equal header 'to-from))
	     (string-match (cadr regexp-target-pair)
			   (or
			    (message-fetch-field header)
			    "")))
	(setq target
	      (format-time-string (caddr regexp-target-pair) date)))))))



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: new variable nnmail-fancy-expiry-target-with-arrival-time?
  2003-10-31 15:28 new variable nnmail-fancy-expiry-target-with-arrival-time? Adrian Lanz
@ 2004-01-02 22:08 ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Magne Ingebrigtsen @ 2004-01-02 22:08 UTC (permalink / raw)


Adrian Lanz <lanz@fowi.ethz.ch> writes:

> Here a propsal for a small addition to the expiry rules applied with
> nnmail-fancy-expiry-target: The idea is to allow fancy splitting
> articles into expiry groups not parsing the Date field but the
> X-Gnus-Article-Number field for a valid time/date. This functionality
> only applies when expiring articles kept in the nnfolder mail back end
> (and does nothing [harmful] for other mail back ends).

[...]

> If the functionality is considered to be useful for more people, it
> would be nice to see it implemented in the CVS version for testing,
> Adrian.

It seems like a useful idea.  If you could send a patch, that'd be
nice... 

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-01-02 22:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-31 15:28 new variable nnmail-fancy-expiry-target-with-arrival-time? Adrian Lanz
2004-01-02 22:08 ` Lars Magne Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).