From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/60201 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Arne_J=C3=B8rgensen?= Newsgroups: gmane.emacs.gnus.general Subject: Generate Procmail recipes from Gnus Date: Tue, 26 Apr 2005 14:07:19 +0200 Organization: Arne Joergensen -- http://arnested.dk/ Message-ID: <87mzrlrbbc.fsf@arnested.dk> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1114517347 13119 80.91.229.2 (26 Apr 2005 12:09:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 26 Apr 2005 12:09:07 +0000 (UTC) Original-X-From: ding-owner+M8729@lists.math.uh.edu Tue Apr 26 14:09:05 2005 Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DQOrX-0002Mo-Iw for ding-account@gmane.org; Tue, 26 Apr 2005 14:08:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu ident=lists) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 1DQOrl-0005Vs-00; Tue, 26 Apr 2005 07:08:37 -0500 Original-Received: from util2.math.uh.edu ([129.7.128.23]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1DQOra-0005Vk-00 for ding@lists.math.uh.edu; Tue, 26 Apr 2005 07:08:26 -0500 Original-Received: from quimby.gnus.org ([80.91.224.244]) by util2.math.uh.edu with esmtp (Exim 4.30) id 1DQOrW-0003G4-Od for ding@lists.math.uh.edu; Tue, 26 Apr 2005 07:08:22 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1DQOrV-0004i0-00 for ; Tue, 26 Apr 2005 14:08:21 +0200 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DQOlX-00015Z-3U for ding@gnus.org; Tue, 26 Apr 2005 14:02:11 +0200 Original-Received: from 213.237.94.152 ([213.237.94.152]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 Apr 2005 14:02:11 +0200 Original-Received: from arne by 213.237.94.152 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 26 Apr 2005 14:02:11 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: ding@gnus.org Original-Lines: 258 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 213.237.94.152 X-Face: 5t,7/Y$&<1A_t.$vC2{pWZ{m@3_06;kcm]no{hgEL/}Uz(>XV6cl4}xO\v?-h3%>znNaZtq `~rf,GY1T%r=a.zH`hOb(-]'x)nI088Z&|e;V^h;/TShou User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:894r8RyvJl2hd2rIG28w9CdGp/c= X-Spam-Score: -4.9 (----) Precedence: bulk Original-Sender: ding-owner@lists.math.uh.edu Xref: news.gmane.org gmane.emacs.gnus.general:60201 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:60201 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Heavily inspired, and even more based on, gnus-sieve.el I created a way to generate Procmail recipes from inside Gnus. This way you can add an `procmail' entry to your group parameters like (procmail . "^Sender:.*arne@arnested.dk") and have it turned into recipes like :0 * ^Sender:.*arne@arnested.dk ~/Maildir/mail.junk/ or (procmail "^From:.*larsi" "^Subject:.*gnus") to :0 * ^From:.*larsi * ^Subject:.*gnus ~/maildir/mail.important/ You will still have to know how to write a Procmail condition, but you can keep them together with your group parameters and the recipes will adjust themselves to changing group names. The format of the action line (the destination of the mail) is decided by `gnus-procmail-action' (a format string or a function). Feedback appreciated. Kind regards, -- Arne Jørgensen --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=gnus-prcml.el Content-Transfer-Encoding: quoted-printable Content-Description: lisp/gnus-prcml.el ;;; gnus-prcml.el --- Utilities to manage procmail scripts for Gnus ;; Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. ;; Author: NAGY Andras , ;; Simon Josefsson , ;; Arne J=1B,Ax=1B(Brgensen ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Gnus glue to generate Procmail recipes from Gnus Group Parameters. ;; It is inspired by and heavily based on gnus-sieve.el ;;; Code: (require 'gnus) (require 'gnus-sum) (require 'format-spec) ;; Variables (defgroup gnus-procmail nil "Manage procmail recipes in Gnus." :group 'gnus) (defcustom gnus-procmail-file "~/.procmailrc" "Path to your Procmail script." :type 'file :group 'gnus-procmail) (defcustom gnus-procmail-region-start "\n## Begin Gnus Procmail Script\n" "Line indicating the start of the autogenerated region in your Procmail script." :type 'string :group 'gnus-procmail) (defcustom gnus-procmail-region-end "\n## End Gnus Procmail Script\n" "Line indicating the end of the autogenerated region in your Procmail script." :type 'string :group 'gnus-procmail) (defcustom gnus-procmail-select-method nil "Which select method we generate the Procmail script for. For example: \"nnimap:mailbox\"" :group 'gnus-procmail) (defcustom gnus-procmail-crosspost t "Whether the generated Procmail script should do crossposting." :type 'boolean :group 'gnus-procmail) (defcustom gnus-procmail-action nil "Determine how the groupname is turned into an action line. If this variable is nil the action line will be identical to the groupname. Another possibility is to let it be a string where %s is substituted with the group name, i.e. \"~/Maildir/%s/\" or \"| dmail +%s\" The possibilty is for it to be a function (of your choice and probably also definition) taking the group name as an argument an returnikng the action line as a string." :type '(choice (const :tag "Group name" nil) (string :tag "Format string" :value "%s") (function :tag "Function")) :group 'gnus-procmail) ;;;###autoload (defun gnus-procmail-update () "Update the Procmail script in gnus-procmail-file, by replacing the region between gnus-procmail-region-start and gnus-procmail-region-end with \(gnus-procmail-script gnus-procmail-select-method gnus-procmail-crosspost\). See the documentation for these variables and functions for details." (interactive) (save-window-excursion (gnus-procmail-generate) (save-buffer))) ;;;###autoload (defun gnus-procmail-generate () "Generate the Procmail script in gnus-procmail-file, by replacing the region between gnus-procmail-region-start and gnus-procmail-region-end with \(gnus-procmail-script gnus-procmail-select-method gnus-procmail-crosspost\). See the documentation for these variables and functions for details." (interactive) (find-file gnus-procmail-file) (goto-char (point-min)) (if (re-search-forward (regexp-quote gnus-procmail-region-start) nil t) (delete-region (match-beginning 0) (or (re-search-forward (regexp-quote gnus-procmail-region-end) nil t) (point)))) (insert gnus-procmail-region-start (gnus-procmail-script gnus-procmail-select-method gnus-procmail-crosspos= t) gnus-procmail-region-end)) (defun gnus-procmail-guess-rule-for-article () "Guess a procmail recipe based on RFC822 article in buffer. Return nil if no recipe could be guessed." (when (message-fetch-field "sender") `(procmail . ,(concat "^Sender:.*" (message-fetch-field "sender"))))) ;;;###autoload (defun gnus-procmail-article-add-rule () "Guess and add a procmail recipe to the group parameters." (interactive) (gnus-summary-select-article nil 'force) (with-current-buffer gnus-original-article-buffer (let ((rule (gnus-procmail-guess-rule-for-article)) (info (gnus-get-info gnus-newsgroup-name))) (if (null rule) (error "Could not guess recipe for article.") (gnus-info-set-params info (cons rule (gnus-info-params info))) (message "Added recipe in group %s for article: %s" gnus-newsgroup-name rule))))) ;; Internals (defun gnus-procmail-test (test) "Convert an elisp test to a Procmail condition. For example: \(procmail . \"^TO_my@address.com\"\) =3D> * ^TO_my@address.com \(procmail \"^From:.*larsi\" \"^Subject:.*gnus\"\) =3D>=20 * ^From:.*larsi * ^Subject:.*gnus" (if (listp test) (mapconcat 'gnus-procmail-test test "\n") (concat "* " test))) (defun gnus-procmail-script (&optional method crosspost) "Generate a Procmail script based on groups with select method METHOD \(or all groups if nil\). Only groups having a `procmail' parameter are considered. This parameter should contain an elisp test \(see the documentation of gnus-procmail-test for details\). For each such group, a Procmail recipe is generated, having the test(s) as the condition(s) and an action line based on the group name (see `gnus-procmail-action'). If CROSSPOST is t, each recipe will have a \"c\" flag (:0 c) at the beginning of the recipe. For example: If the INBOX.list.procmail group has the (procmail \"^Sender:.*procmail-admin@extundo.com\") group parameter, (gnus-procmail-script) results in: :0 * ^Sender:.*procmail-admin@extundo.com INBOX.list.procmail This is returned as a string." (let* ((newsrc (cdr gnus-newsrc-alist)) script) (dolist (info newsrc) (when (or (not method) (gnus-server-equal method (gnus-info-method info))) (let* ((group (gnus-info-group info)) (spec (gnus-group-find-parameter group 'procmail t))) (when spec (push (concat ":0" (if crosspost " c\n" "\n") (gnus-procmail-test spec) "\n" (if (stringp gnus-procmail-action) (format gnus-procmail-action (gnus-group-real-name group)) (if (functionp gnus-procmail-action) (apply gnus-procmail-action (list (gnus-group-real-name group))) (gnus-group-real-name group))) "\n") script))))) (mapconcat 'identity script "\n"))) (provide 'gnus-prcml) ;;; gnus-prcml.el ends here --=-=-=--