Commit | Line | Data |
---|---|---|
d501f516 ER |
1 | ;;; undigest.el --- digest-cracking support for the RMAIL mail reader |
2 | ||
9596811a | 3 | ;; Copyright (C) 1985, 1986, 1994, 1996 Free Software Foundation, Inc. |
58142744 | 4 | |
e5167999 | 5 | ;; Maintainer: FSF |
d7b4d18f | 6 | ;; Keywords: mail |
e5167999 | 7 | |
0d20f9a0 JB |
8 | ;; This file is part of GNU Emacs. |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
0d20f9a0 JB |
13 | ;; any later version. |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
0d20f9a0 | 24 | |
e5167999 ER |
25 | ;;; Commentary: |
26 | ||
27 | ;; See Internet RFC 934 | |
28 | ||
29 | ;;; Code: | |
0d20f9a0 | 30 | |
4fe9b563 KH |
31 | (require 'rmail) |
32 | ||
5ea4b65b RS |
33 | (defcustom rmail-digest-end-regexps |
34 | (list (concat "End of.*Digest.*\n" | |
35 | (regexp-quote "*********") "*" | |
36 | "\\(\n------*\\)*") | |
37 | (concat "End of.*\n" | |
38 | (regexp-quote "*") "*")) | |
39 | "*Regexps matching the end of a digest message." | |
51ee83ac | 40 | :group 'rmail |
5ea4b65b | 41 | :type '(repeat regexp)) |
51ee83ac | 42 | |
372a91d7 | 43 | ;;;###autoload |
0d20f9a0 JB |
44 | (defun undigestify-rmail-message () |
45 | "Break up a digest message into its constituent messages. | |
46 | Leaves original message, deleted, before the undigestified messages." | |
47 | (interactive) | |
add0c454 RS |
48 | (with-current-buffer rmail-buffer |
49 | (widen) | |
50 | (let ((buffer-read-only nil) | |
51 | (msg-string (buffer-substring (rmail-msgbeg rmail-current-message) | |
52 | (rmail-msgend rmail-current-message)))) | |
53 | (goto-char (rmail-msgend rmail-current-message)) | |
54 | (narrow-to-region (point) (point)) | |
55 | (insert msg-string) | |
56 | (narrow-to-region (point-min) (1- (point-max)))) | |
57 | (let ((error t) | |
58 | (buffer-read-only nil)) | |
59 | (unwind-protect | |
60 | (progn | |
61 | (save-restriction | |
62 | (goto-char (point-min)) | |
63 | (delete-region (point-min) | |
64 | (progn (search-forward "\n*** EOOH ***\n") | |
65 | (point))) | |
66 | (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
67 | (narrow-to-region (point) | |
68 | (point-max)) | |
69 | (let* ((fill-prefix "") | |
70 | (case-fold-search t) | |
71 | start | |
72 | (digest-name | |
73 | (mail-strip-quoted-names | |
74 | (or (save-restriction | |
75 | (search-forward "\n\n") | |
76 | (setq start (point)) | |
77 | (narrow-to-region (point-min) (point)) | |
78 | (goto-char (point-max)) | |
79 | (or (mail-fetch-field "Reply-To") | |
80 | (mail-fetch-field "To") | |
81 | (mail-fetch-field "Apparently-To") | |
82 | (mail-fetch-field "From"))) | |
83 | (error "Message is not a digest--bad header"))))) | |
84 | (save-excursion | |
5ea4b65b RS |
85 | (let (found |
86 | (regexps rmail-digest-end-regexps)) | |
87 | (while (and regexps (not found)) | |
88 | (goto-char (point-max)) | |
89 | (skip-chars-backward " \t\n") | |
90 | ;; compensate for broken un*x digestifiers. Sigh Sigh. | |
91 | (while (and (> (point) start) (not found)) | |
92 | (forward-line -1) | |
93 | (if (looking-at (car regexps)) | |
94 | (setq found t)) | |
7588f68a | 95 | (setq regexps (cdr regexps)))) |
5ea4b65b RS |
96 | (unless found |
97 | (error "Message is not a digest--no end line")))) | |
add0c454 RS |
98 | (re-search-forward (concat "^" (make-string 55 ?-) "-*\n*")) |
99 | (replace-match "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
0d20f9a0 | 100 | (save-restriction |
add0c454 RS |
101 | (narrow-to-region (point) |
102 | (progn (search-forward "\n\n") | |
103 | (point))) | |
104 | (if (mail-fetch-field "To") nil | |
0d20f9a0 | 105 | (goto-char (point-min)) |
369718f8 | 106 | (insert "To: " digest-name "\n"))) |
add0c454 RS |
107 | (while (re-search-forward |
108 | (concat "\n\n" (make-string 27 ?-) "-*\n*") | |
109 | nil t) | |
110 | (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
111 | (save-restriction | |
112 | (if (looking-at "End ") | |
113 | (insert "To: " digest-name "\n\n") | |
114 | (narrow-to-region (point) | |
115 | (progn (search-forward "\n\n" | |
116 | nil 'move) | |
117 | (point)))) | |
118 | (if (mail-fetch-field "To") | |
119 | nil | |
120 | (goto-char (point-min)) | |
121 | (insert "To: " digest-name "\n"))) | |
122 | ;; Digestifiers may insert `- ' on lines that start with `-'. | |
123 | ;; Undo that. | |
124 | (save-excursion | |
125 | (goto-char (point-min)) | |
126 | (if (re-search-forward | |
127 | "\n\n----------------------------*\n*" | |
128 | nil t) | |
129 | (let ((end (point-marker))) | |
130 | (goto-char (point-min)) | |
131 | (while (re-search-forward "^- " end t) | |
132 | (delete-char -2))))) | |
133 | ))) | |
134 | (setq error nil) | |
135 | (message "Message successfully undigestified") | |
136 | (let ((n rmail-current-message)) | |
137 | (rmail-forget-messages) | |
138 | (rmail-show-message n) | |
139 | (rmail-delete-forward) | |
140 | (if (rmail-summary-exists) | |
141 | (rmail-select-summary | |
142 | (rmail-update-summary))))) | |
143 | (cond (error | |
144 | (narrow-to-region (point-min) (1+ (point-max))) | |
145 | (delete-region (point-min) (point-max)) | |
146 | (rmail-show-message rmail-current-message))))))) | |
0d20f9a0 | 147 | |
372a91d7 | 148 | ;;;###autoload |
9f606031 KH |
149 | (defun unforward-rmail-message () |
150 | "Extract a forwarded message from the containing message. | |
151 | This puts the forwarded message into a separate rmail message | |
152 | following the containing message." | |
153 | (interactive) | |
add0c454 RS |
154 | ;; If we are in a summary buffer, switch to the Rmail buffer. |
155 | (with-current-buffer rmail-buffer | |
156 | (narrow-to-region (rmail-msgbeg rmail-current-message) | |
157 | (rmail-msgend rmail-current-message)) | |
158 | (goto-char (point-min)) | |
159 | (let (beg end (buffer-read-only nil) msg-string who-forwarded-it) | |
160 | (setq who-forwarded-it (mail-fetch-field "From")) | |
161 | (if (re-search-forward "^----" nil t) | |
162 | nil | |
163 | (error "No forwarded message")) | |
164 | (forward-line 1) | |
165 | (setq beg (point)) | |
166 | (if (re-search-forward "^----" nil t) | |
167 | (setq end (match-beginning 0)) | |
168 | (error "No terminator for forwarded message")) | |
169 | (widen) | |
170 | (setq msg-string (buffer-substring beg end)) | |
171 | (goto-char (rmail-msgend rmail-current-message)) | |
172 | (narrow-to-region (point) (point)) | |
173 | (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
174 | (narrow-to-region (point) (point)) | |
175 | (insert "Forwarded-by: " who-forwarded-it "\n") | |
176 | (insert msg-string) | |
177 | (goto-char (point-min)) | |
178 | (while (not (eobp)) | |
179 | (if (looking-at "- ") | |
180 | (delete-region (point) (+ 2 (point)))) | |
181 | (forward-line 1)) | |
182 | (let ((n rmail-current-message)) | |
183 | (rmail-forget-messages) | |
184 | (rmail-show-message n) | |
185 | (if (rmail-summary-exists) | |
186 | (rmail-select-summary | |
187 | (rmail-update-summary))))))) | |
9f606031 | 188 | |
896546cd RS |
189 | (provide 'undigest) |
190 | ||
d501f516 | 191 | ;;; undigest.el ends here |