1 ;;; undigest.el --- digest-cracking support for the RMAIL mail reader
3 ;; Copyright (C) 1985, 1986, 1994, 1996 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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.
20 ;; You should have received a copy of the GNU General Public License
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.
27 ;; See Internet RFC 934
34 (defun undigestify-rmail-message ()
35 "Break up a digest message into its constituent messages.
36 Leaves original message, deleted, before the undigestified messages."
39 (let ((buffer-read-only nil
)
40 (msg-string (buffer-substring (rmail-msgbeg rmail-current-message
)
41 (rmail-msgend rmail-current-message
))))
42 (goto-char (rmail-msgend rmail-current-message
))
43 (narrow-to-region (point) (point))
45 (narrow-to-region (point-min) (1- (point-max))))
47 (buffer-read-only nil
))
51 (goto-char (point-min))
52 (delete-region (point-min)
53 (progn (search-forward "\n*** EOOH ***\n")
55 (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
56 (narrow-to-region (point)
58 (let* ((fill-prefix "")
62 (mail-strip-quoted-names
64 (search-forward "\n\n")
66 (narrow-to-region (point-min) (point))
67 (goto-char (point-max))
68 (or (mail-fetch-field "Reply-To")
69 (mail-fetch-field "To")
70 (mail-fetch-field "Apparently-To")
71 (mail-fetch-field "From")))
72 (error "Message is not a digest--bad header")))))
74 (goto-char (point-max))
75 (skip-chars-backward " \t\n")
77 ;; compensate for broken un*x digestifiers. Sigh Sigh.
78 (while (and (> (point) start
) (not found
))
80 (if (looking-at (concat "End of.*Digest.*\n"
81 (regexp-quote "*********") "*"
85 (error "Message is not a digest--no end line"))))
86 (re-search-forward (concat "^" (make-string 55 ?-
) "-*\n*"))
87 (replace-match "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
89 (narrow-to-region (point)
90 (progn (search-forward "\n\n")
92 (if (mail-fetch-field "To") nil
93 (goto-char (point-min))
94 (insert "To: " digest-name
"\n")))
95 (while (re-search-forward
96 (concat "\n\n" (make-string 27 ?-
) "-*\n*")
98 (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n")
100 (if (looking-at "End ")
101 (insert "To: " digest-name
"\n\n")
102 (narrow-to-region (point)
103 (progn (search-forward "\n\n"
106 (if (mail-fetch-field "To")
108 (goto-char (point-min))
109 (insert "To: " digest-name
"\n")))
110 ;; Digestifiers may insert `- ' on lines that start with `-'.
113 (goto-char (point-min))
114 (if (re-search-forward
115 "\n\n----------------------------*\n*"
117 (let ((end (point-marker)))
118 (goto-char (point-min))
119 (while (re-search-forward "^- " end t
)
123 (message "Message successfully undigestified")
124 (let ((n rmail-current-message
))
125 (rmail-forget-messages)
126 (rmail-show-message n
)
127 (rmail-delete-forward)
128 (if (rmail-summary-exists)
129 (rmail-select-summary
130 (rmail-update-summary)))))
132 (narrow-to-region (point-min) (1+ (point-max)))
133 (delete-region (point-min) (point-max))
134 (rmail-show-message rmail-current-message
))))))
137 (defun unforward-rmail-message ()
138 "Extract a forwarded message from the containing message.
139 This puts the forwarded message into a separate rmail message
140 following the containing message."
142 ;; Don't use save-excursion because we don't want to restore point
143 ;; in the case where we do not switch buffers.
144 (let ((obuf (current-buffer)))
147 ;; If we are in a summary buffer, switch to the Rmail buffer.
148 (if (local-variable-p 'rmail-buffer
)
149 (set-buffer rmail-buffer
))
150 (narrow-to-region (rmail-msgbeg rmail-current-message
)
151 (rmail-msgend rmail-current-message
))
152 (goto-char (point-min))
153 (let (beg end
(buffer-read-only nil
) msg-string who-forwarded-it
)
154 (setq who-forwarded-it
(mail-fetch-field "From"))
155 (if (re-search-forward "^----" nil t
)
157 (error "No forwarded message"))
160 (if (re-search-forward "^----" nil t
)
161 (setq end
(match-beginning 0))
162 (error "No terminator for forwarded message"))
164 (setq msg-string
(buffer-substring beg end
))
165 (goto-char (rmail-msgend rmail-current-message
))
166 (narrow-to-region (point) (point))
167 (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
168 (narrow-to-region (point) (point))
169 (insert "Forwarded-by: " who-forwarded-it
"\n")
171 (goto-char (point-min))
173 (if (looking-at "- ")
174 (delete-region (point) (+ 2 (point))))
176 (let ((n rmail-current-message
))
177 (rmail-forget-messages)
178 (rmail-show-message n
)
179 (if (rmail-summary-exists)
180 (rmail-select-summary
181 (rmail-update-summary))))))
184 ;;; undigest.el ends here