*** empty log message ***
[bpt/emacs.git] / lisp / mail / undigest.el
CommitLineData
d501f516
ER
1;;; undigest.el --- digest-cracking support for the RMAIL mail reader
2
e5167999
ER
3;; Maintainer: FSF
4;; Last-Modified: 14 Jul 1992
d7b4d18f 5;; Keywords: mail
e5167999 6
0d20f9a0
JB
7;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
0d20f9a0
JB
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to
23;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
e5167999
ER
25;;; Commentary:
26
27;; See Internet RFC 934
28
29;;; Code:
0d20f9a0
JB
30
31(defun undigestify-rmail-message ()
32 "Break up a digest message into its constituent messages.
33Leaves original message, deleted, before the undigestified messages."
34 (interactive)
35 (widen)
36 (let ((buffer-read-only nil)
37 (msg-string (buffer-substring (rmail-msgbeg rmail-current-message)
38 (rmail-msgend rmail-current-message))))
39 (goto-char (rmail-msgend rmail-current-message))
40 (narrow-to-region (point) (point))
41 (insert msg-string)
42 (narrow-to-region (point-min) (1- (point-max))))
43 (let ((error t)
44 (buffer-read-only nil))
45 (unwind-protect
46 (progn
47 (save-restriction
48 (goto-char (point-min))
49 (delete-region (point-min)
50 (progn (search-forward "\n*** EOOH ***\n")
51 (point)))
52 (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
53 (narrow-to-region (point)
54 (point-max))
55 (let* ((fill-prefix "")
56 (case-fold-search t)
57 (digest-name
58 (mail-strip-quoted-names
59 (or (save-restriction
60 (search-forward "\n\n")
61 (narrow-to-region (point-min) (point))
62 (goto-char (point-max))
63 (or (mail-fetch-field "Reply-To")
64 (mail-fetch-field "To")
65 (mail-fetch-field "Apparently-To")
66 (mail-fetch-field "From")))
67 (error "Message is not a digest")))))
68 (save-excursion
69 (goto-char (point-max))
70 (skip-chars-backward " \t\n")
71 (let ((count 10) found)
72 ;; compensate for broken un*x digestifiers. Sigh Sigh.
73 (while (and (> count 0) (not found))
74 (forward-line -1)
75 (setq count (1- count))
76 (if (looking-at (concat "End of.*Digest.*\n"
77 (regexp-quote "*********") "*"
78 "\\(\n------*\\)*"))
79 (setq found t)))
80 (if (not found) (error "Message is not a digest"))))
81 (re-search-forward (concat "^" (make-string 55 ?-) "-*\n*"))
82 (replace-match "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
83 (save-restriction
84 (narrow-to-region (point)
85 (progn (search-forward "\n\n")
86 (point)))
87 (if (mail-fetch-field "To") nil
88 (goto-char (point-min))
89 (insert "To: " digest-name "\n")))
90 (while (re-search-forward
91 (concat "\n\n" (make-string 27 ?-) "-*\n*")
92 nil t)
93 (replace-match "\n\n\^_\^L\n0, unseen,,\n*** EOOH ***\n")
94 (save-restriction
95 (if (looking-at "End ")
96 (insert "To: " digest-name "\n\n")
97 (narrow-to-region (point)
98 (progn (search-forward "\n\n"
99 nil 'move)
100 (point))))
101 (if (mail-fetch-field "To") nil
102 (goto-char (point-min))
103 (insert "To: " digest-name "\n"))))))
104 (setq error nil)
105 (message "Message successfully undigestified")
106 (let ((n rmail-current-message))
107 (rmail-forget-messages)
108 (rmail-show-message n)
109 (rmail-delete-forward)))
110 (cond (error
111 (narrow-to-region (point-min) (1+ (point-max)))
112 (delete-region (point-min) (point-max))
113 (rmail-show-message rmail-current-message))))))
114
d501f516 115;;; undigest.el ends here