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 | ||
372a91d7 | 33 | ;;;###autoload |
0d20f9a0 JB |
34 | (defun undigestify-rmail-message () |
35 | "Break up a digest message into its constituent messages. | |
36 | Leaves original message, deleted, before the undigestified messages." | |
37 | (interactive) | |
add0c454 RS |
38 | (with-current-buffer rmail-buffer |
39 | (widen) | |
40 | (let ((buffer-read-only nil) | |
41 | (msg-string (buffer-substring (rmail-msgbeg rmail-current-message) | |
42 | (rmail-msgend rmail-current-message)))) | |
43 | (goto-char (rmail-msgend rmail-current-message)) | |
44 | (narrow-to-region (point) (point)) | |
45 | (insert msg-string) | |
46 | (narrow-to-region (point-min) (1- (point-max)))) | |
47 | (let ((error t) | |
48 | (buffer-read-only nil)) | |
49 | (unwind-protect | |
50 | (progn | |
51 | (save-restriction | |
52 | (goto-char (point-min)) | |
53 | (delete-region (point-min) | |
54 | (progn (search-forward "\n*** EOOH ***\n") | |
55 | (point))) | |
56 | (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
57 | (narrow-to-region (point) | |
58 | (point-max)) | |
59 | (let* ((fill-prefix "") | |
60 | (case-fold-search t) | |
61 | start | |
62 | (digest-name | |
63 | (mail-strip-quoted-names | |
64 | (or (save-restriction | |
65 | (search-forward "\n\n") | |
66 | (setq start (point)) | |
67 | (narrow-to-region (point-min) (point)) | |
68 | (goto-char (point-max)) | |
69 | (or (mail-fetch-field "Reply-To") | |
70 | (mail-fetch-field "To") | |
71 | (mail-fetch-field "Apparently-To") | |
72 | (mail-fetch-field "From"))) | |
73 | (error "Message is not a digest--bad header"))))) | |
74 | (save-excursion | |
75 | (goto-char (point-max)) | |
76 | (skip-chars-backward " \t\n") | |
77 | (let (found) | |
78 | ;; compensate for broken un*x digestifiers. Sigh Sigh. | |
79 | (while (and (> (point) start) (not found)) | |
80 | (forward-line -1) | |
81 | (if (looking-at (concat "End of.*Digest.*\n" | |
82 | (regexp-quote "*********") "*" | |
83 | "\\(\n------*\\)*")) | |
84 | (setq found t))) | |
85 | (if (not found) | |
86 | (error "Message is not a digest--no end line")))) | |
87 | (re-search-forward (concat "^" (make-string 55 ?-) "-*\n*")) | |
88 | (replace-match "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
0d20f9a0 | 89 | (save-restriction |
add0c454 RS |
90 | (narrow-to-region (point) |
91 | (progn (search-forward "\n\n") | |
92 | (point))) | |
93 | (if (mail-fetch-field "To") nil | |
0d20f9a0 | 94 | (goto-char (point-min)) |
369718f8 | 95 | (insert "To: " digest-name "\n"))) |
add0c454 RS |
96 | (while (re-search-forward |
97 | (concat "\n\n" (make-string 27 ?-) "-*\n*") | |
98 | nil t) | |
99 | (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
100 | (save-restriction | |
101 | (if (looking-at "End ") | |
102 | (insert "To: " digest-name "\n\n") | |
103 | (narrow-to-region (point) | |
104 | (progn (search-forward "\n\n" | |
105 | nil 'move) | |
106 | (point)))) | |
107 | (if (mail-fetch-field "To") | |
108 | nil | |
109 | (goto-char (point-min)) | |
110 | (insert "To: " digest-name "\n"))) | |
111 | ;; Digestifiers may insert `- ' on lines that start with `-'. | |
112 | ;; Undo that. | |
113 | (save-excursion | |
114 | (goto-char (point-min)) | |
115 | (if (re-search-forward | |
116 | "\n\n----------------------------*\n*" | |
117 | nil t) | |
118 | (let ((end (point-marker))) | |
119 | (goto-char (point-min)) | |
120 | (while (re-search-forward "^- " end t) | |
121 | (delete-char -2))))) | |
122 | ))) | |
123 | (setq error nil) | |
124 | (message "Message successfully undigestified") | |
125 | (let ((n rmail-current-message)) | |
126 | (rmail-forget-messages) | |
127 | (rmail-show-message n) | |
128 | (rmail-delete-forward) | |
129 | (if (rmail-summary-exists) | |
130 | (rmail-select-summary | |
131 | (rmail-update-summary))))) | |
132 | (cond (error | |
133 | (narrow-to-region (point-min) (1+ (point-max))) | |
134 | (delete-region (point-min) (point-max)) | |
135 | (rmail-show-message rmail-current-message))))))) | |
0d20f9a0 | 136 | |
372a91d7 | 137 | ;;;###autoload |
9f606031 KH |
138 | (defun unforward-rmail-message () |
139 | "Extract a forwarded message from the containing message. | |
140 | This puts the forwarded message into a separate rmail message | |
141 | following the containing message." | |
142 | (interactive) | |
add0c454 RS |
143 | ;; If we are in a summary buffer, switch to the Rmail buffer. |
144 | (with-current-buffer rmail-buffer | |
145 | (narrow-to-region (rmail-msgbeg rmail-current-message) | |
146 | (rmail-msgend rmail-current-message)) | |
147 | (goto-char (point-min)) | |
148 | (let (beg end (buffer-read-only nil) msg-string who-forwarded-it) | |
149 | (setq who-forwarded-it (mail-fetch-field "From")) | |
150 | (if (re-search-forward "^----" nil t) | |
151 | nil | |
152 | (error "No forwarded message")) | |
153 | (forward-line 1) | |
154 | (setq beg (point)) | |
155 | (if (re-search-forward "^----" nil t) | |
156 | (setq end (match-beginning 0)) | |
157 | (error "No terminator for forwarded message")) | |
158 | (widen) | |
159 | (setq msg-string (buffer-substring beg end)) | |
160 | (goto-char (rmail-msgend rmail-current-message)) | |
161 | (narrow-to-region (point) (point)) | |
162 | (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n") | |
163 | (narrow-to-region (point) (point)) | |
164 | (insert "Forwarded-by: " who-forwarded-it "\n") | |
165 | (insert msg-string) | |
166 | (goto-char (point-min)) | |
167 | (while (not (eobp)) | |
168 | (if (looking-at "- ") | |
169 | (delete-region (point) (+ 2 (point)))) | |
170 | (forward-line 1)) | |
171 | (let ((n rmail-current-message)) | |
172 | (rmail-forget-messages) | |
173 | (rmail-show-message n) | |
174 | (if (rmail-summary-exists) | |
175 | (rmail-select-summary | |
176 | (rmail-update-summary))))))) | |
9f606031 | 177 | |
896546cd RS |
178 | (provide 'undigest) |
179 | ||
d501f516 | 180 | ;;; undigest.el ends here |