Mercurial > emacs
comparison lisp/gnus/nnmail.el @ 85712:a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-911
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 28 Oct 2007 09:18:39 +0000 |
parents | 7bb8a742f977 |
children | 166a6141ae98 880960b70474 |
comparison
equal
deleted
inserted
replaced
85711:b6f5dc84b2e1 | 85712:a3c27999decb |
---|---|
30 (eval-when-compile (require 'cl)) | 30 (eval-when-compile (require 'cl)) |
31 | 31 |
32 (require 'gnus) ; for macro gnus-kill-buffer, at least | 32 (require 'gnus) ; for macro gnus-kill-buffer, at least |
33 (require 'nnheader) | 33 (require 'nnheader) |
34 (require 'message) | 34 (require 'message) |
35 (require 'custom) | |
36 (require 'gnus-util) | 35 (require 'gnus-util) |
37 (require 'mail-source) | 36 (require 'mail-source) |
38 (require 'mm-util) | 37 (require 'mm-util) |
39 | 38 |
40 (eval-and-compile | 39 (eval-and-compile |
296 Eg. | 295 Eg. |
297 | 296 |
298 \(add-hook 'nnmail-read-incoming-hook | 297 \(add-hook 'nnmail-read-incoming-hook |
299 (lambda () | 298 (lambda () |
300 (call-process \"/local/bin/mailsend\" nil nil nil | 299 (call-process \"/local/bin/mailsend\" nil nil nil |
301 \"read\" nnmail-spool-file))) | 300 \"read\" |
301 ;; The incoming mail box file. | |
302 (expand-file-name (user-login-name) | |
303 rmail-spool-directory)))) | |
302 | 304 |
303 If you have xwatch running, this will alert it that mail has been | 305 If you have xwatch running, this will alert it that mail has been |
304 read. | 306 read. |
305 | 307 |
306 If you use `display-time', you could use something like this: | 308 If you use `display-time', you could use something like this: |
410 (editable-list :inline t nnmail-split-fancy)) | 412 (editable-list :inline t nnmail-split-fancy)) |
411 (list :tag "Use all matches (&)" :value (&) | 413 (list :tag "Use all matches (&)" :value (&) |
412 (const :format "" &) | 414 (const :format "" &) |
413 (editable-list :inline t nnmail-split-fancy)) | 415 (editable-list :inline t nnmail-split-fancy)) |
414 (list :tag "Function with fixed arguments (:)" | 416 (list :tag "Function with fixed arguments (:)" |
415 :value (: nil) | 417 :value (:) |
416 (const :format "" :value :) | 418 (const :format "" :value :) |
417 function | 419 function |
418 (editable-list :inline t (sexp :tag "Arg")) | 420 (editable-list :inline t (sexp :tag "Arg")) |
419 ) | 421 ) |
420 (list :tag "Function with split arguments (!)" | 422 (list :tag "Function with split arguments (!)" |
421 :value (! nil) | 423 :value (!) |
422 (const :format "" !) | 424 (const :format "" !) |
423 function | 425 function |
424 (editable-list :inline t nnmail-split-fancy)) | 426 (editable-list :inline t nnmail-split-fancy)) |
425 (list :tag "Field match" | 427 (list :tag "Field match" |
426 (choice :tag "Field" | 428 (choice :tag "Field" |
474 | 476 |
475 FIELD must match a complete field name. VALUE must match a complete | 477 FIELD must match a complete field name. VALUE must match a complete |
476 word according to the `nnmail-split-fancy-syntax-table' syntax table. | 478 word according to the `nnmail-split-fancy-syntax-table' syntax table. |
477 You can use \".*\" in the regexps to match partial field names or words. | 479 You can use \".*\" in the regexps to match partial field names or words. |
478 | 480 |
479 FIELD and VALUE can also be lisp symbols, in that case they are expanded | 481 FIELD and VALUE can also be Lisp symbols, in that case they are expanded |
480 as specified in `nnmail-split-abbrev-alist'. | 482 as specified in `nnmail-split-abbrev-alist'. |
481 | 483 |
482 GROUP can contain \\& and \\N which will substitute from matching | 484 GROUP can contain \\& and \\N which will substitute from matching |
483 \\(\\) patterns in the previous VALUE. | 485 \\(\\) patterns in the previous VALUE. |
484 | 486 |
658 (if (or nnmail-use-long-file-names | 660 (if (or nnmail-use-long-file-names |
659 (file-directory-p (concat dir group))) | 661 (file-directory-p (concat dir group))) |
660 (expand-file-name group dir) | 662 (expand-file-name group dir) |
661 ;; If not, we translate dots into slashes. | 663 ;; If not, we translate dots into slashes. |
662 (expand-file-name | 664 (expand-file-name |
663 (mm-encode-coding-string | 665 (nnheader-replace-chars-in-string group ?. ?/) |
664 (nnheader-replace-chars-in-string group ?. ?/) | |
665 nnmail-pathname-coding-system) | |
666 dir)))) | 666 dir)))) |
667 (or file ""))) | 667 (or file ""))) |
668 | 668 |
669 (defun nnmail-get-active () | 669 (defun nnmail-get-active () |
670 "Returns an assoc of group names and active ranges. | 670 "Returns an assoc of group names and active ranges. |
685 (let ((buffer (current-buffer)) | 685 (let ((buffer (current-buffer)) |
686 group-assoc group max min) | 686 group-assoc group max min) |
687 (while (not (eobp)) | 687 (while (not (eobp)) |
688 (condition-case err | 688 (condition-case err |
689 (progn | 689 (progn |
690 (narrow-to-region (point) (gnus-point-at-eol)) | 690 (narrow-to-region (point) (point-at-eol)) |
691 (setq group (read buffer)) | 691 (setq group (read buffer)) |
692 (unless (stringp group) | 692 (unless (stringp group) |
693 (setq group (symbol-name group))) | 693 (setq group (symbol-name group))) |
694 (if (and (numberp (setq max (read buffer))) | 694 (if (and (numberp (setq max (read buffer))) |
695 (numberp (setq min (read buffer)))) | 695 (numberp (setq min (read buffer)))) |
1045 (save-excursion | 1045 (save-excursion |
1046 (goto-char (point-min)) | 1046 (goto-char (point-min)) |
1047 (nnmail-check-duplication message-id func artnum-func)) | 1047 (nnmail-check-duplication message-id func artnum-func)) |
1048 1)) | 1048 1)) |
1049 | 1049 |
1050 (defvar nnmail-group-names-not-encoded-p nil | |
1051 "Non-nil means group names are not encoded.") | |
1052 | |
1050 (defun nnmail-split-incoming (incoming func &optional exit-func | 1053 (defun nnmail-split-incoming (incoming func &optional exit-func |
1051 group artnum-func) | 1054 group artnum-func) |
1052 "Go through the entire INCOMING file and pick out each individual mail. | 1055 "Go through the entire INCOMING file and pick out each individual mail. |
1053 FUNC will be called with the buffer narrowed to each mail." | 1056 FUNC will be called with the buffer narrowed to each mail." |
1054 (let ( ;; If this is a group-specific split, we bind the split | 1057 (let ( ;; If this is a group-specific split, we bind the split |
1055 ;; methods to just this group. | 1058 ;; methods to just this group. |
1056 (nnmail-split-methods (if (and group | 1059 (nnmail-split-methods (if (and group |
1057 (not nnmail-resplit-incoming)) | 1060 (not nnmail-resplit-incoming)) |
1058 (list (list group "")) | 1061 (list (list group "")) |
1059 nnmail-split-methods))) | 1062 nnmail-split-methods)) |
1063 (nnmail-group-names-not-encoded-p t)) | |
1060 (save-excursion | 1064 (save-excursion |
1061 ;; Insert the incoming file. | 1065 ;; Insert the incoming file. |
1062 (set-buffer (get-buffer-create nnmail-article-buffer)) | 1066 (set-buffer (get-buffer-create nnmail-article-buffer)) |
1063 (erase-buffer) | 1067 (erase-buffer) |
1064 (let ((coding-system-for-read nnmail-incoming-coding-system)) | 1068 (let ((coding-system-for-read nnmail-incoming-coding-system)) |
1123 ;; existence to process. | 1127 ;; existence to process. |
1124 (goto-char (point-min)) | 1128 (goto-char (point-min)) |
1125 (while (not (eobp)) | 1129 (while (not (eobp)) |
1126 (unless (< (move-to-column nnmail-split-header-length-limit) | 1130 (unless (< (move-to-column nnmail-split-header-length-limit) |
1127 nnmail-split-header-length-limit) | 1131 nnmail-split-header-length-limit) |
1128 (delete-region (point) (gnus-point-at-eol))) | 1132 (delete-region (point) (point-at-eol))) |
1129 (forward-line 1)) | 1133 (forward-line 1)) |
1130 ;; Allow washing. | 1134 ;; Allow washing. |
1131 (goto-char (point-min)) | 1135 (goto-char (point-min)) |
1132 (run-hooks 'nnmail-split-hook) | 1136 (run-hooks 'nnmail-split-hook) |
1133 (when (setq nnmail-split-tracing trace) | 1137 (when (setq nnmail-split-tracing trace) |
1245 (when (re-search-backward "^Xref: " nil t) | 1249 (when (re-search-backward "^Xref: " nil t) |
1246 (delete-region (match-beginning 0) | 1250 (delete-region (match-beginning 0) |
1247 (progn (forward-line 1) (point)))) | 1251 (progn (forward-line 1) (point)))) |
1248 (insert (format "Xref: %s" (system-name))) | 1252 (insert (format "Xref: %s" (system-name))) |
1249 (while group-alist | 1253 (while group-alist |
1250 (insert (format " %s:%d" | 1254 (insert (if (mm-multibyte-p) |
1251 (mm-encode-coding-string | 1255 (mm-string-as-multibyte |
1252 (caar group-alist) | 1256 (format " %s:%d" (caar group-alist) (cdar group-alist))) |
1253 nnmail-pathname-coding-system) | 1257 (mm-string-as-unibyte |
1254 (cdar group-alist))) | 1258 (format " %s:%d" (caar group-alist) (cdar group-alist))))) |
1255 (setq group-alist (cdr group-alist))) | 1259 (setq group-alist (cdr group-alist))) |
1256 (insert "\n"))) | 1260 (insert "\n"))) |
1257 | 1261 |
1258 ;;; Message washing functions | 1262 ;;; Message washing functions |
1259 | 1263 |
1283 | 1287 |
1284 (defun nnmail-remove-tabs () | 1288 (defun nnmail-remove-tabs () |
1285 "Translate TAB characters into SPACE characters." | 1289 "Translate TAB characters into SPACE characters." |
1286 (subst-char-in-region (point-min) (point-max) ?\t ? t)) | 1290 (subst-char-in-region (point-min) (point-max) ?\t ? t)) |
1287 | 1291 |
1288 (defun nnmail-fix-eudora-headers () | 1292 (defcustom nnmail-broken-references-mailers |
1289 "Eudora has a broken References line, but an OK In-Reply-To." | 1293 "^X-Mailer:.*\\(Eudora\\|Pegasus\\)" |
1294 "Header line matching mailer producing bogus References lines. | |
1295 See `nnmail-ignore-broken-references'." | |
1296 :group 'nnmail-prepare | |
1297 :version "23.0" ;; No Gnus | |
1298 :type 'regexp) | |
1299 | |
1300 (defun nnmail-ignore-broken-references () | |
1301 "Ignore the References line and use In-Reply-To | |
1302 | |
1303 Eudora has a broken References line, but an OK In-Reply-To." | |
1290 (goto-char (point-min)) | 1304 (goto-char (point-min)) |
1291 (when (re-search-forward "^X-Mailer:.*Eudora" nil t) | 1305 (when (re-search-forward nnmail-broken-references-mailers nil t) |
1292 (goto-char (point-min)) | 1306 (goto-char (point-min)) |
1293 (when (re-search-forward "^References:" nil t) | 1307 (when (re-search-forward "^References:" nil t) |
1294 (beginning-of-line) | 1308 (beginning-of-line) |
1295 (insert "X-Gnus-Broken-Eudora-")) | 1309 (insert "X-Gnus-Broken-Eudora-")) |
1296 (goto-char (point-min)) | 1310 (goto-char (point-min)) |
1297 (when (re-search-forward "^\\(In-Reply-To:[^\n]+\\)\n[ \t]+" nil t) | 1311 (when (re-search-forward "^\\(In-Reply-To:[^\n]+\\)\n[ \t]+" nil t) |
1298 (replace-match "\\1" t)))) | 1312 (replace-match "\\1" t)))) |
1299 | 1313 |
1314 (defalias 'nnmail-fix-eudora-headers 'nnmail-ignore-broken-references) | |
1315 (make-obsolete 'nnmail-fix-eudora-headers 'nnmail-ignore-broken-references) | |
1316 | |
1300 (custom-add-option 'nnmail-prepare-incoming-header-hook | 1317 (custom-add-option 'nnmail-prepare-incoming-header-hook |
1301 'nnmail-fix-eudora-headers) | 1318 'nnmail-ignore-broken-references) |
1302 | 1319 |
1303 ;;; Utility functions | 1320 ;;; Utility functions |
1304 | 1321 |
1305 (defun nnmail-do-request-post (accept-func &optional server) | 1322 (defun nnmail-do-request-post (accept-func &optional server) |
1306 "Utility function to directly post a message to an nnmail-derived group. | 1323 "Utility function to directly post a message to an nnmail-derived group. |
1325 (setq success nil)))))) | 1342 (setq success nil)))))) |
1326 | 1343 |
1327 (defun nnmail-split-fancy () | 1344 (defun nnmail-split-fancy () |
1328 "Fancy splitting method. | 1345 "Fancy splitting method. |
1329 See the documentation for the variable `nnmail-split-fancy' for details." | 1346 See the documentation for the variable `nnmail-split-fancy' for details." |
1330 (let ((syntab (syntax-table))) | 1347 (with-syntax-table nnmail-split-fancy-syntax-table |
1331 (unwind-protect | 1348 (nnmail-split-it nnmail-split-fancy))) |
1332 (progn | |
1333 (set-syntax-table nnmail-split-fancy-syntax-table) | |
1334 (nnmail-split-it nnmail-split-fancy)) | |
1335 (set-syntax-table syntab)))) | |
1336 | 1349 |
1337 (defvar nnmail-split-cache nil) | 1350 (defvar nnmail-split-cache nil) |
1338 ;; Alist of split expressions their equivalent regexps. | 1351 ;; Alist of split expressions their equivalent regexps. |
1339 | 1352 |
1340 (defun nnmail-split-it (split) | 1353 (defun nnmail-split-it (split) |
1642 (when (search-backward id nil t) | 1655 (when (search-backward id nil t) |
1643 (beginning-of-line) | 1656 (beginning-of-line) |
1644 (skip-chars-forward "^\n\r\t") | 1657 (skip-chars-forward "^\n\r\t") |
1645 (unless (looking-at "[\r\n]") | 1658 (unless (looking-at "[\r\n]") |
1646 (forward-char 1) | 1659 (forward-char 1) |
1647 (buffer-substring (point) (gnus-point-at-eol))))))) | 1660 (buffer-substring (point) (point-at-eol))))))) |
1648 | 1661 |
1649 ;; Function for nnmail-split-fancy: look up all references in the | 1662 ;; Function for nnmail-split-fancy: look up all references in the |
1650 ;; cache and if a match is found, return that group. | 1663 ;; cache and if a match is found, return that group. |
1651 (defun nnmail-split-fancy-with-parent () | 1664 (defun nnmail-split-fancy-with-parent () |
1652 "Split this message into the same group as its parent. | 1665 "Split this message into the same group as its parent. |
1670 nnmail-split-fancy-with-parent-ignore-groups))) | 1683 nnmail-split-fancy-with-parent-ignore-groups))) |
1671 (when refstr | 1684 (when refstr |
1672 (setq references (nreverse (gnus-split-references refstr))) | 1685 (setq references (nreverse (gnus-split-references refstr))) |
1673 (unless (gnus-buffer-live-p nnmail-cache-buffer) | 1686 (unless (gnus-buffer-live-p nnmail-cache-buffer) |
1674 (nnmail-cache-open)) | 1687 (nnmail-cache-open)) |
1675 (mapcar (lambda (x) | 1688 (dolist (x references) |
1676 (setq res (or (nnmail-cache-fetch-group x) res)) | 1689 (setq res (or (nnmail-cache-fetch-group x) res)) |
1677 (when (or (member res '("delayed" "drafts" "queue")) | 1690 (when (or (member res '("delayed" "drafts" "queue")) |
1678 (and regexp res (string-match regexp res))) | 1691 (and regexp res (string-match regexp res))) |
1679 (setq res nil))) | 1692 (setq res nil))) |
1680 references) | |
1681 res))) | 1693 res))) |
1682 | 1694 |
1683 (defun nnmail-cache-id-exists-p (id) | 1695 (defun nnmail-cache-id-exists-p (id) |
1684 (when nnmail-treat-duplicates | 1696 (when nnmail-treat-duplicates |
1685 (save-excursion | 1697 (save-excursion |
1900 ;; To or From header | 1912 ;; To or From header |
1901 ((and (equal header 'to-from) | 1913 ((and (equal header 'to-from) |
1902 (or (string-match (cadr regexp-target-pair) from) | 1914 (or (string-match (cadr regexp-target-pair) from) |
1903 (and (string-match (cadr regexp-target-pair) to) | 1915 (and (string-match (cadr regexp-target-pair) to) |
1904 (let ((rmail-dont-reply-to-names | 1916 (let ((rmail-dont-reply-to-names |
1905 message-dont-reply-to-names)) | 1917 (message-dont-reply-to-names))) |
1906 (equal (rmail-dont-reply-to from) ""))))) | 1918 (equal (rmail-dont-reply-to from) ""))))) |
1907 (setq target (format-time-string (caddr regexp-target-pair) date))) | 1919 (setq target (format-time-string (caddr regexp-target-pair) date))) |
1908 ((and (not (equal header 'to-from)) | 1920 ((and (not (equal header 'to-from)) |
1909 (string-match (cadr regexp-target-pair) | 1921 (string-match (cadr regexp-target-pair) |
1910 (or | 1922 (or |
1993 (unless nnmail-split-history | 2005 (unless nnmail-split-history |
1994 (error "No current split history")) | 2006 (error "No current split history")) |
1995 (with-output-to-temp-buffer "*nnmail split history*" | 2007 (with-output-to-temp-buffer "*nnmail split history*" |
1996 (with-current-buffer standard-output | 2008 (with-current-buffer standard-output |
1997 (fundamental-mode)) ; for Emacs 20.4+ | 2009 (fundamental-mode)) ; for Emacs 20.4+ |
1998 (let ((history nnmail-split-history) | 2010 (dolist (elem nnmail-split-history) |
1999 elem) | |
2000 (while (setq elem (pop history)) | |
2001 (princ (mapconcat (lambda (ga) | 2011 (princ (mapconcat (lambda (ga) |
2002 (concat (car ga) ":" (int-to-string (cdr ga)))) | 2012 (concat (car ga) ":" (int-to-string (cdr ga)))) |
2003 elem | 2013 elem |
2004 ", ")) | 2014 ", ")) |
2005 (princ "\n"))))) | 2015 (princ "\n")))) |
2006 | 2016 |
2007 (defun nnmail-purge-split-history (group) | 2017 (defun nnmail-purge-split-history (group) |
2008 "Remove all instances of GROUP from `nnmail-split-history'." | 2018 "Remove all instances of GROUP from `nnmail-split-history'." |
2009 (let ((history nnmail-split-history)) | 2019 (let ((history nnmail-split-history)) |
2010 (while history | 2020 (while history |