*** empty log message ***
[gnus] / lisp / nnmail.el
index d9cd825..e761868 100644 (file)
@@ -1,7 +1,7 @@
 ;;; nnmail.el --- mail support functions for the Gnus mail backends
-;; Copyright (C) 1995,96 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news, mail
 
 ;; This file is part of GNU Emacs.
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 (require 'nnheader)
 (require 'timezone)
 (require 'message)
-(eval-when-compile (require 'cl))
+(require 'custom)
+
+(eval-and-compile
+  (autoload 'gnus-error "gnus-util")
+  (autoload 'gnus-buffer-live-p "gnus-util")
+  (autoload 'gnus-encode-coding-string "gnus-ems"))
+
+(defgroup nnmail nil
+  "Reading mail with Gnus."
+  :group 'gnus)
+
+(defgroup nnmail-retrieve nil
+  "Retrieving new mail."
+  :group 'nnmail)
+
+(defgroup nnmail-prepare nil
+  "Preparing (or mangling) new mail after retrival."
+  :group 'nnmail)
+
+(defgroup nnmail-duplicate nil
+  "Handling of duplicate mail messages."
+  :group 'nnmail)
+
+(defgroup nnmail-split nil
+  "Organizing the incomming mail in folders."
+  :group 'nnmail)
+
+(defgroup nnmail-files nil
+  "Mail files."
+  :group 'gnus-files
+  :group 'nnmail)
+
+(defgroup nnmail-expire nil
+  "Expiring old mail."
+  :group 'nnmail)
 
-(defvar nnmail-split-methods
+(defgroup nnmail-procmail nil
+  "Interfacing with procmail and other mail agents."
+  :group 'nnmail)
+
+(defgroup nnmail-various nil
+  "Various mail options."
+  :group 'nnmail)
+
+(defcustom nnmail-split-methods
   '(("mail.misc" ""))
   "*Incoming mail will be split according to this variable.
 
@@ -56,35 +100,54 @@ mail belongs in that group.
 
 The last element should always have \"\" as the regexp.
 
-This variable can also have a function as its value.")
+This variable can also have a function as its value."
+  :group 'nnmail-split
+  :type '(choice (repeat :tag "Alist" (group (string :tag "Name") regexp))
+                (function-item nnmail-split-fancy)
+                (function :tag "Other")))
 
 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
-(defvar nnmail-crosspost t
-  "*If non-nil, do crossposting if several split methods match the mail.
-If nil, the first match found will be used.")
+(defcustom nnmail-crosspost t
+  "If non-nil, do crossposting if several split methods match the mail.
+If nil, the first match found will be used."
+  :group 'nnmail-split
+  :type 'boolean)
 
 ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit).
-(defvar nnmail-keep-last-article nil
-  "*If non-nil, nnmail will never delete the last expired article in a directory.  
+(defcustom nnmail-keep-last-article nil
+  "If non-nil, nnmail will never delete/move a group's last article.
+It can be marked expirable, so it will be deleted when it is no longer last.
+
 You may need to set this variable if other programs are putting
-new mail into folder numbers that Gnus has marked as expired.")
+new mail into folder numbers that Gnus has marked as expired."
+  :group 'nnmail-procmail
+  :group 'nnmail-various
+  :type 'boolean)
 
-(defvar nnmail-use-long-file-names nil
-  "*If non-nil the mail backends will use long file and directory names.
+(defcustom nnmail-use-long-file-names nil
+  "If non-nil the mail backends will use long file and directory names.
 If nil, groups like \"mail.misc\" will end up in directories like
-\"mail/misc/\".")
+\"mail/misc/\"."
+  :group 'nnmail-files
+  :type 'boolean)
 
-(defvar nnmail-default-file-modes 384
-  "Set the mode bits of all new mail files to this integer.")
+(defcustom nnmail-default-file-modes 384
+  "Set the mode bits of all new mail files to this integer."
+  :group 'nnmail-files
+  :type 'integer)
 
-(defvar nnmail-expiry-wait 7
+(defcustom nnmail-expiry-wait 7
   "*Expirable articles that are older than this will be expired.
 This variable can either be a number (which will be interpreted as a
 number of days) -- this doesn't have to be an integer.  This variable
-can also be `immediate' and `never'.")
-
-(defvar nnmail-expiry-wait-function nil
-  "*Variable that holds function to specify how old articles should be before they are expired.
+can also be `immediate' and `never'."
+  :group 'nnmail-expire
+  :type '(choice (const immediate)
+                (integer :tag "days")
+                (const never)))
+
+(defcustom nnmail-expiry-wait-function nil
+  "Variable that holds function to specify how old articles should be before they are expired.
   The function will be called with the name of the group that the
 expiry is to be performed in, and it should return an integer that
 says how many days an article can be stored before it is considered
@@ -92,74 +155,117 @@ says how many days an article can be stored before it is considered
 
 Eg.:
 
-(setq nnmail-expiry-wait-function
+\(setq nnmail-expiry-wait-function
       (lambda (newsgroup)
         (cond ((string-match \"private\" newsgroup) 31)
               ((string-match \"junk\" newsgroup) 1)
              ((string-match \"important\" newsgroup) 'never)
-             (t 7))))")
+             (t 7))))"
+  :group 'nnmail-expire
+  :type '(choice (const :tag "nnmail-expiry-wait" nil)
+                (function :format "%v" nnmail-)))
+
+(defcustom nnmail-cache-accepted-message-ids nil
+  "If non-nil, put Message-IDs of Gcc'd articles into the duplicate cache."
+  :group 'nnmail
+  :type 'boolean)
 
-(defvar nnmail-spool-file 
+(defcustom nnmail-spool-file
   (or (getenv "MAIL")
       (concat "/usr/spool/mail/" (user-login-name)))
-  "Where the mail backends will look for incoming mail.
+  "*Where the mail backends will look for incoming mail.
 This variable is \"/usr/spool/mail/$user\" by default.
 If this variable is nil, no mail backends will read incoming mail.
 If this variable is a list, all files mentioned in this list will be
-used as incoming mailboxes.")
-
-(defvar nnmail-crash-box "~/.gnus-crash-box"
-  "*File where Gnus will store mail while processing it.")
-
-(defvar nnmail-use-procmail nil
+used as incoming mailboxes.
+If this variable is a directory (i. e., it's name ends with a \"/\"),
+treat all files in that directory as incoming spool files."
+  :group 'nnmail-files
+  :type 'file)
+
+(defcustom nnmail-crash-box "~/.gnus-crash-box"
+  "File where Gnus will store mail while processing it."
+  :group 'nnmail-files
+  :type 'file)
+
+(defcustom nnmail-use-procmail nil
   "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files.
-The file(s) in `nnmail-spool-file' will also be read.")
+The file(s) in `nnmail-spool-file' will also be read."
+  :group 'nnmail-procmail
+  :type 'boolean)
 
-(defvar nnmail-procmail-directory "~/incoming/"
+(defcustom nnmail-procmail-directory "~/incoming/"
   "*When using procmail (and the like), incoming mail is put in this directory.
-The Gnus mail backends will read the mail from this directory.")
+The Gnus mail backends will read the mail from this directory."
+  :group 'nnmail-procmail
+  :type 'directory)
 
-(defvar nnmail-procmail-suffix "\\.spool"
+(defcustom nnmail-procmail-suffix "\\.spool"
   "*Suffix of files created by procmail (and the like).
 This variable might be a suffix-regexp to match the suffixes of
-several files - eg. \".spool[0-9]*\".")
-
-(defvar nnmail-resplit-incoming nil
-  "*If non-nil, re-split incoming procmail sorted mail.")
-
-(defvar nnmail-delete-file-function 'delete-file
-  "Function called to delete files in some mail backends.")
-
-(defvar nnmail-crosspost-link-function 'add-name-to-file
-  "Function called to create a copy of a file.
+several files - eg. \".spool[0-9]*\"."
+  :group 'nnmail-procmail
+  :type 'regexp)
+
+(defcustom nnmail-resplit-incoming nil
+  "*If non-nil, re-split incoming procmail sorted mail."
+  :group 'nnmail-procmail
+  :type 'boolean)
+
+(defcustom nnmail-delete-file-function 'delete-file
+  "Function called to delete files in some mail backends."
+  :group 'nnmail-files
+  :type 'function)
+
+(defcustom nnmail-crosspost-link-function
+  (if (string-match "windows-nt\\|emx" (symbol-name system-type))
+      'copy-file
+    'add-name-to-file)
+  "*Function called to create a copy of a file.
 This is `add-name-to-file' by default, which means that crossposts
 will use hard links.  If your file system doesn't allow hard
-links, you could set this variable to `copy-file' instead.")
+links, you could set this variable to `copy-file' instead."
+  :group 'nnmail-files
+  :type '(radio (function-item add-name-to-file)
+               (function-item copy-file)
+               (function :tag "Other")))
 
-(defvar nnmail-movemail-program "movemail"
+(defcustom nnmail-movemail-program "movemail"
   "*A command to be executed to move mail from the inbox.
-The default is \"movemail\".")
-
-(defvar nnmail-pop-password-required nil
-  "*Non-nil if a password is required when reading mail using POP.")
-
-(defvar nnmail-read-incoming-hook nil
+The default is \"movemail\".
+
+This can also be a function.  In that case, the function will be
+called with two parameters -- the name of the INBOX file, and the file
+to be moved to."
+  :group 'nnmail-files
+  :group 'nnmail-retrieve
+  :type 'string)
+
+(defcustom nnmail-pop-password-required nil
+  "*Non-nil if a password is required when reading mail using POP."
+  :group 'nnmail-retrieve
+  :type 'boolean)
+
+(defcustom nnmail-read-incoming-hook
+  (if (eq system-type 'windows-nt)
+      '(nnheader-ms-strip-cr)
+    nil)
   "*Hook that will be run after the incoming mail has been transferred.
 The incoming mail is moved from `nnmail-spool-file' (which normally is
 something like \"/usr/spool/mail/$user\") to the user's home
-directory. This hook is called after the incoming mail box has been
+directory.  This hook is called after the incoming mail box has been
 emptied, and can be used to call any mail box programs you have
 running (\"xwatch\", etc.)
 
 Eg.
 
-\(add-hook 'nnmail-read-incoming-hook 
-          (lambda () 
-            (start-process \"mailsend\" nil 
+\(add-hook 'nnmail-read-incoming-hook
+          (lambda ()
+            (start-process \"mailsend\" nil
                            \"/local/bin/mailsend\" \"read\" \"mbox\")))
 
 If you have xwatch running, this will alert it that mail has been
-read.  
+read.
 
 If you use `display-time', you could use something like this:
 
@@ -167,37 +273,77 @@ If you use `display-time', you could use something like this:
          (lambda ()
            ;; Update the displayed time, since that will clear out
            ;; the flag that says you have mail.
-           (if (eq (process-status \"display-time\") 'run)
-               (display-time-filter display-time-process \"\"))))") 
-
-(when (eq system-type 'windows-nt)
-  (add-hook 'nnmail-prepare-incoming-hook 'nnheader-ms-strip-cr))
+           (when (eq (process-status \"display-time\") 'run)
+             (display-time-filter display-time-process \"\"))))"
+  :group 'nnmail-prepare
+  :type 'hook)
 
 ;; Suggested by Erik Selberg <speed@cs.washington.edu>.
-(defvar nnmail-prepare-incoming-hook nil
-  "*Hook called before treating incoming mail.
-The hook is run in a buffer with all the new, incoming mail.")
-
-(defvar nnmail-pre-get-new-mail-hook nil
-  "Hook called just before starting to handle new incoming mail.")
-
-(defvar nnmail-post-get-new-mail-hook nil
-  "Hook called just after finishing handling new incoming mail.")
+(defcustom nnmail-prepare-incoming-hook nil
+  "Hook called before treating incoming mail.
+The hook is run in a buffer with all the new, incoming mail."
+  :group 'nnmail-prepare
+  :type 'hook)
+
+(defcustom nnmail-prepare-incoming-header-hook nil
+  "Hook called narrowed to the headers of each message.
+This can be used to remove excessive spaces (and stuff like
+that) from the headers before splitting and saving the messages."
+  :group 'nnmail-prepare
+  :type 'hook)
+
+(defcustom nnmail-prepare-incoming-message-hook nil
+  "Hook called narrowed to each message."
+  :group 'nnmail-prepare
+  :type 'hook)
+
+(defcustom nnmail-list-identifiers nil
+  "Regexp that matches list identifiers to be removed.
+This can also be a list of regexps."
+  :group 'nnmail-prepare
+  :type '(choice (const :tag "none" nil)
+                (regexp :value ".*")
+                (repeat :value (".*") regexp)))
+
+(defcustom nnmail-pre-get-new-mail-hook nil
+  "Hook called just before starting to handle new incoming mail."
+  :group 'nnmail-retrieve
+  :type 'hook)
+
+(defcustom nnmail-post-get-new-mail-hook nil
+  "Hook called just after finishing handling new incoming mail."
+  :group 'nnmail-retrieve
+  :type 'hook)
+
+(defcustom nnmail-split-hook nil
+  "Hook called before deciding where to split an article.
+The functions in this hook are free to modify the buffer
+contents in any way they choose -- the buffer contents are
+discarded after running the split process."
+  :group 'nnmail-split
+  :type 'hook)
 
 ;; Suggested by Mejia Pablo J <pjm9806@usl.edu>.
-(defvar nnmail-tmp-directory nil
-  "*If non-nil, use this directory for temporary storage when reading incoming mail.")
-
-(defvar nnmail-large-newsgroup 50
+(defcustom nnmail-tmp-directory nil
+  "*If non-nil, use this directory for temporary storage.
+Used when reading incoming mail."
+  :group 'nnmail-files
+  :group 'nnmail-retrieve
+  :type '(choice (const :tag "default" nil)
+                (directory :format "%v")))
+
+(defcustom nnmail-large-newsgroup 50
   "*The number of the articles which indicates a large newsgroup.
 If the number of the articles is greater than the value, verbose
-messages will be shown to indicate the current status.")
+messages will be shown to indicate the current status."
+  :group 'nnmail-various
+  :type 'integer)
 
-(defvar nnmail-split-fancy "mail.misc"
-  "*Incoming mail can be split according to this fancy variable.
+(defcustom nnmail-split-fancy "mail.misc"
+  "Incoming mail can be split according to this fancy variable.
 To enable this, set `nnmail-split-methods' to `nnmail-split-fancy'.
 
-The format is this variable is SPLIT, where SPLIT can be one of
+The format of this variable is SPLIT, where SPLIT can be one of
 the following:
 
 GROUP: Mail will be stored in GROUP (a string).
@@ -207,22 +353,29 @@ GROUP: Mail will be stored in GROUP (a string).
 
 \(| SPLIT...): Process each SPLIT expression until one of them matches.
   A SPLIT expression is said to match if it will cause the mail
-  message to be stored in one or more groups.  
+  message to be stored in one or more groups.
 
 \(& SPLIT...): Process each SPLIT expression.
 
+\(: FUNCTION optional args): Call FUNCTION with the optional args, in
+  the buffer containing the message headers.  The return value FUNCTION
+  should be a split, which is then recursively processed.
+
 FIELD must match a complete field name.  VALUE must match a complete
 word according to the `nnmail-split-fancy-syntax-table' syntax table.
-You can use .* in the regexps to match partial field names or words.
+You can use \".*\" in the regexps to match partial field names or words.
 
 FIELD and VALUE can also be lisp symbols, in that case they are expanded
 as specified in `nnmail-split-abbrev-alist'.
 
+GROUP can contain \\& and \\N which will substitute from matching
+\\(\\) patterns in the previous VALUE.
+
 Example:
 
 \(setq nnmail-split-methods 'nnmail-split-fancy
       nnmail-split-fancy
-      ;; Messages from the mailer deamon are not crossposted to any of
+      ;; Messages from the mailer daemon are not crossposted to any of
       ;; the ordinary groups.  Warnings are put in a separate group
       ;; from real errors.
       '(| (\"from\" mail (| (\"subject\" \"warn.*\" \"mail.warning\")
@@ -238,25 +391,43 @@ Example:
             ;; People...
             (any \"larsi@ifi\\\\.uio\\\\.no\" \"people.Lars Magne Ingebrigtsen\"))
          ;; Unmatched mail goes to the catch all group.
-         \"misc.misc\"))")
+         \"misc.misc\"))"
+  :group 'nnmail-split
+  ;; Sigh!
+  :type 'sexp)
 
-(defvar nnmail-split-abbrev-alist
+(defcustom nnmail-split-abbrev-alist