From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/40778 Path: main.gmane.org!not-for-mail From: Nevin Kapur Newsgroups: gmane.emacs.gnus.general Subject: [PATCH] Expiry based on headers Date: Sat, 08 Dec 2001 11:42:44 -0500 Sender: owner-ding@hpc.uh.edu Message-ID: NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1035176275 2689 80.91.224.250 (21 Oct 2002 04:57:55 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 04:57:55 +0000 (UTC) Return-Path: Original-Received: (qmail 775 invoked from network); 8 Dec 2001 16:48:38 -0000 Original-Received: from malifon.math.uh.edu (mail@129.7.128.13) by mastaler.com with SMTP; 8 Dec 2001 16:48:38 -0000 Original-Received: from sina.hpc.uh.edu ([129.7.128.10] ident=lists) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 16CkZ5-000831-00; Sat, 08 Dec 2001 10:43:03 -0600 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Sat, 08 Dec 2001 10:42:49 -0600 (CST) Original-Received: from sclp3.sclp.com (qmailr@sclp3.sclp.com [209.196.61.66]) by sina.hpc.uh.edu (8.9.3/8.9.3) with SMTP id KAA20306 for ; Sat, 8 Dec 2001 10:42:37 -0600 (CST) Original-Received: (qmail 700 invoked by alias); 8 Dec 2001 16:42:45 -0000 Original-Received: (qmail 695 invoked from network); 8 Dec 2001 16:42:45 -0000 Original-Received: from fermat.mts.jhu.edu (128.220.17.18) by gnus.org with SMTP; 8 Dec 2001 16:42:45 -0000 Original-Received: (from nevin@localhost) by fermat.mts.jhu.edu (8.11.6/8.11.6) id fB8GgiC15032; Sat, 8 Dec 2001 11:42:44 -0500 X-Authentication-Warning: fermat.mts.jhu.edu: nevin set sender to nevin@jhu.edu using -f Original-To: Ding X-Face: H~?ZI_L2!bGIrH^iC0e8t85[S`lwpP_/-sOvkGnN[\)[S";}xM3[Ib!ljz-80yK9SIf9sz6/DcY?yKUq1=-&XdrLjA^wK1 Mail-Copies-To: never Original-Lines: 117 User-Agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Civil Service, i686-pc-linux) Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:40778 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:40778 Recently, I've seen a few requests for a function that will expire articles based on their headers. I've been using such a function for a while. I am proposing it for inclusion into Gnus. ChangeLog: 2001-12-08 Nevin Kapur * nnmail.el (nnmail-fancy-expiry-targets): New variable. (nnmail-fancy-expiry-target): Use it. Index: lisp/nnmail.el =================================================================== RCS file: /usr/local/cvsroot/gnus/lisp/nnmail.el,v retrieving revision 6.27 diff -u -r6.27 nnmail.el --- lisp/nnmail.el 2001/09/26 17:55:05 6.27 +++ lisp/nnmail.el 2001/12/08 16:33:42 @@ -190,6 +190,16 @@ (function :format "%v" nnmail-) string)) +;; Need to make this a defcustom +(defvar nnmail-fancy-expiry-targets nil + "A list of (\"header\" \"regexp\" \"target\" \"date format\"). If +`nnmail-expiry-target' is set to `nnmail-fancy-expiry-target' and the +header matches the regexp, the message will be expired to the target +group with the date in the specified format, appended. If no date +format is specified the %Y is assumed. In the special cases that +header is from, the regexp will match the from or to header. See +the manual for examples.") + (defcustom nnmail-cache-accepted-message-ids nil "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache. If non-nil, also update the cache when copy or move articles." @@ -1699,6 +1709,38 @@ (setq target (funcall target group))) (unless (eq target 'delete) (gnus-request-accept-article target nil nil t)))) + +(defun nnmail-fancy-expiry-target (group) + "Returns a target expiry group depending on the last match in nnmail-fancy-expiry-targets." + (if (or (string= group "drafts") (string= group "queue")) + 'delete + (let* (header + (case-fold-search nil) + (from (or (message-fetch-field "from") "")) + (to (or (message-fetch-field "to") "")) + (date (date-to-time + (or (message-fetch-field "date") (current-time-string)))) + (target 'delete)) + ;; Note that last match will be returned. + (dolist (regexp-target-pair nnmail-fancy-expiry-targets target) + (setq header (car regexp-target-pair)) + (cond + ;; If the header is "from" or "to" match either field + ((and (or (string-match header "from") (string-match header "to")) + (or (string-match (cadr regexp-target-pair) from) + (and (string-match message-dont-reply-to-names from) + (string-match (cadr regexp-target-pair) to)))) + (setq target (concat (caddr regexp-target-pair) + "-" + (format-time-string + (or (cadddr regexp-target-pair) "%Y") date)))) + ((string-match (cadr regexp-target-pair) (message-fetch-field header)) + (setq target (concat (caddr regexp-target-pair) + "-" + (format-time-string + (or (cadddr regexp-target-pair) "%Y") + date))))))))) + (defun nnmail-check-syntax () "Check (and modify) the syntax of the message in the current buffer." Here is the manual entry: Index: texi/gnus.texi =================================================================== RCS file: /usr/local/cvsroot/gnus/texi/gnus.texi,v retrieving revision 6.189 diff -u -r6.189 gnus.texi --- texi/gnus.texi 2001/12/05 10:15:25 6.189 +++ texi/gnus.texi 2001/12/08 16:37:14 @@ -13073,6 +13073,26 @@ (setq nnmail-expiry-target "nnml:expired") @end lisp +Gnus provides a function @code{nnmail-fancy-expiry-target} which will +expire mail to groups according to the variable +@code{nnmail-fancy-expiry-targets}. Here's an example: + +@lisp + (setq nnmail-expiry-target 'nnmail-fancy-expiry-target + nnmail-fancy-expiry-targets + '(("from" ".*" "nnfolder:Archive" "%Y-%b") + ("subject" "IMPORTANT" "nnfolder:IMPORTANT") + ("from" "boss" "nnfolder:Work"))) +@end lisp + +With this setup, any mail that has @code{IMPORTANT} in its Subject +header and was sent in the year @code{YYYY}, will get expired to the +group @code{nnfolder:IMPORTANT-YYYY}. If its From or To header contains +the string @code{boss}, it will get expired to +@code{nnfolder:Work-YYYY}. All other mail will get expired to +@code{nnfolder:Archive-YYYY-MMM}. + + @vindex nnmail-keep-last-article If @code{nnmail-keep-last-article} is non-@code{nil}, Gnus will never -- Nevin