annotate lisp/rmail/undigest.el @ 142:1856695b1fa9 r20-2b5

Import from CVS: tag r20-2b5
author cvs
date Mon, 13 Aug 2007 09:33:18 +0200
parents 0293115a14e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; undigest.el --- digest-cracking support for the RMAIL mail reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; See Internet RFC 934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (require 'rmail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun undigestify-rmail-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Break up a digest message into its constituent messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Leaves original message, deleted, before the undigestified messages."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (let ((buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (msg-string (buffer-substring (rmail-msgbeg rmail-current-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (rmail-msgend rmail-current-message))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (goto-char (rmail-msgend rmail-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (narrow-to-region (point) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (insert msg-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (narrow-to-region (point-min) (1- (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (let ((error t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (delete-region (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (progn (search-forward "\n*** EOOH ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (let* ((fill-prefix "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (digest-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (mail-strip-quoted-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (or (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (search-forward "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (narrow-to-region (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (or (mail-fetch-field "Reply-To")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (mail-fetch-field "To")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (mail-fetch-field "Apparently-To")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (mail-fetch-field "From")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (error "Message is not a digest--bad header")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (let (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; compensate for broken un*x digestifiers. Sigh Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (while (and (> (point) start) (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (if (looking-at (concat "End of.*Digest.*\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (regexp-quote "*********") "*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "\\(\n------*\\)*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (setq found t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (if (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (error "Message is not a digest--no end line"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (re-search-forward (concat "^" (make-string 55 ?-) "-*\n*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (replace-match "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (progn (search-forward "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (mail-fetch-field "To") nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (insert "To: " digest-name "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (while (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (concat "\n\n" (make-string 27 ?-) "-*\n*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (looking-at "End ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (insert "To: " digest-name "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (progn (search-forward "\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (mail-fetch-field "To")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (insert "To: " digest-name "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; Digestifiers may insert `- ' on lines that start with `-'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; Undo that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "\n\n----------------------------*\n*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (let ((end (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (while (re-search-forward "^- " end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (delete-char -2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (message "Message successfully undigestified")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (let ((n rmail-current-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (rmail-forget-messages)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (rmail-show-message n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (rmail-delete-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (if (rmail-summary-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (rmail-select-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (rmail-update-summary)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (cond (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (narrow-to-region (point-min) (1+ (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (rmail-show-message rmail-current-message))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;; undigest.el ends here