]> code.delx.au - gnu-emacs/blob - lisp/mail/undigest.el
(webjump-to-javaapi): Function deleted.
[gnu-emacs] / lisp / mail / undigest.el
1 ;;; undigest.el --- digest-cracking support for the RMAIL mail reader
2
3 ;; Copyright (C) 1985, 1986, 1994, 1996 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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
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.
24
25 ;;; Commentary:
26
27 ;; See Internet RFC 934
28
29 ;;; Code:
30
31 (require 'rmail)
32
33 ;;;###autoload
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)
38 (widen)
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))
44 (insert msg-string)
45 (narrow-to-region (point-min) (1- (point-max))))
46 (let ((error t)
47 (buffer-read-only nil))
48 (unwind-protect
49 (progn
50 (save-restriction
51 (goto-char (point-min))
52 (delete-region (point-min)
53 (progn (search-forward "\n*** EOOH ***\n")
54 (point)))
55 (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
56 (narrow-to-region (point)
57 (point-max))
58 (let* ((fill-prefix "")
59 (case-fold-search t)
60 start
61 (digest-name
62 (mail-strip-quoted-names
63 (or (save-restriction
64 (search-forward "\n\n")
65 (setq start (point))
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")))))
73 (save-excursion
74 (goto-char (point-max))
75 (skip-chars-backward " \t\n")
76 (let (found)
77 ;; compensate for broken un*x digestifiers. Sigh Sigh.
78 (while (and (> (point) start) (not found))
79 (forward-line -1)
80 (if (looking-at (concat "End of.*Digest.*\n"
81 (regexp-quote "*********") "*"
82 "\\(\n------*\\)*"))
83 (setq found t)))
84 (if (not found)
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")
88 (save-restriction
89 (narrow-to-region (point)
90 (progn (search-forward "\n\n")
91 (point)))
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*")
97 nil t)
98 (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n")
99 (save-restriction
100 (if (looking-at "End ")
101 (insert "To: " digest-name "\n\n")
102 (narrow-to-region (point)
103 (progn (search-forward "\n\n"
104 nil 'move)
105 (point))))
106 (if (mail-fetch-field "To")
107 nil
108 (goto-char (point-min))
109 (insert "To: " digest-name "\n")))
110 ;; Digestifiers may insert `- ' on lines that start with `-'.
111 ;; Undo that.
112 (save-excursion
113 (goto-char (point-min))
114 (if (re-search-forward
115 "\n\n----------------------------*\n*"
116 nil t)
117 (let ((end (point-marker)))
118 (goto-char (point-min))
119 (while (re-search-forward "^- " end t)
120 (delete-char -2)))))
121 )))
122 (setq error nil)
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)))))
131 (cond (error
132 (narrow-to-region (point-min) (1+ (point-max)))
133 (delete-region (point-min) (point-max))
134 (rmail-show-message rmail-current-message))))))
135
136 ;;;###autoload
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."
141 (interactive)
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)))
145 (unwind-protect
146 (progn
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)
156 nil
157 (error "No forwarded message"))
158 (forward-line 1)
159 (setq beg (point))
160 (if (re-search-forward "^----" nil t)
161 (setq end (match-beginning 0))
162 (error "No terminator for forwarded message"))
163 (widen)
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")
170 (insert msg-string)
171 (goto-char (point-min))
172 (while (not (eobp))
173 (if (looking-at "- ")
174 (delete-region (point) (+ 2 (point))))
175 (forward-line 1))
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))))))
182 (set-buffer obuf))))
183
184 ;;; undigest.el ends here