1992-05-30 20:24:49 +00:00
|
|
|
|
;;; undigest.el --- digest-cracking support for the RMAIL mail reader
|
|
|
|
|
|
2006-12-09 04:06:06 +00:00
|
|
|
|
;; Copyright (C) 1985, 1986, 1994, 1996, 2001, 2002, 2003, 2004,
|
2008-01-07 02:00:47 +00:00
|
|
|
|
;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
1992-07-22 02:58:48 +00:00
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;; Maintainer: FSF
|
1992-07-17 20:24:00 +00:00
|
|
|
|
;; Keywords: mail
|
1992-07-16 21:47:34 +00:00
|
|
|
|
|
1989-10-31 15:59:53 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2007-07-25 04:27:24 +00:00
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
1989-10-31 15:59:53 +00:00
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 17:55:18 +00:00
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2002-12-16 16:22:41 +00:00
|
|
|
|
;; See Internet RFC 934 and RFC 1153
|
2002-12-16 17:05:59 +00:00
|
|
|
|
;; Also limited support for MIME digest encapsulation
|
1992-07-16 21:47:34 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
1994-04-23 02:31:52 +00:00
|
|
|
|
(require 'rmail)
|
|
|
|
|
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(defconst rmail-mail-separator
|
|
|
|
|
"\^_\^L\n0, unseen,,\n*** EOOH ***\n"
|
|
|
|
|
"String for separating messages in an rmail file.")
|
|
|
|
|
|
2003-01-31 14:01:20 +00:00
|
|
|
|
(defcustom rmail-forward-separator-regex
|
|
|
|
|
"^----.*\\([Ff]orwarded\\|[Oo]riginal\\).*[Mm]essage"
|
|
|
|
|
"*Regexp to match the string that introduces forwarded messages.
|
|
|
|
|
This is not a header, but a string contained in the body of the message.
|
2005-06-10 00:44:05 +00:00
|
|
|
|
You may need to customize it for local needs."
|
2003-01-31 14:01:20 +00:00
|
|
|
|
:type 'regexp
|
|
|
|
|
:group 'rmail-headers)
|
|
|
|
|
|
2002-12-20 12:46:44 +00:00
|
|
|
|
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(defconst rmail-digest-methods
|
|
|
|
|
'(rmail-digest-parse-mime
|
|
|
|
|
rmail-digest-parse-rfc1153strict
|
|
|
|
|
rmail-digest-parse-rfc1153sloppy
|
|
|
|
|
rmail-digest-parse-rfc934)
|
2002-12-20 12:46:44 +00:00
|
|
|
|
"List of digest parsing functions, first tried first.
|
2002-12-16 16:22:41 +00:00
|
|
|
|
|
2002-12-20 12:46:44 +00:00
|
|
|
|
These functions operate on the current narrowing, and take no argument.
|
|
|
|
|
A function returns nil if it cannot parse the digest. If it can, it
|
2002-12-16 16:22:41 +00:00
|
|
|
|
returns a list of cons pairs containing the start and end positions of
|
|
|
|
|
each undigestified message as markers.")
|
|
|
|
|
|
|
|
|
|
(defun rmail-digest-parse-mime ()
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (let ((head-end (progn (search-forward "\n\n" nil t) (point))))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(and head-end
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(concat
|
|
|
|
|
"^Content-type: multipart/digest;"
|
|
|
|
|
"\\s-* boundary=\"?\\([^\";\n]+\\)[\";\n]") head-end t)
|
|
|
|
|
(search-forward (match-string 1) nil t)))
|
|
|
|
|
;; Ok, prolog separator found
|
|
|
|
|
(let ((start (make-marker))
|
|
|
|
|
(end (make-marker))
|
|
|
|
|
(separator (concat "\n--" (match-string 0) "\n\n"))
|
|
|
|
|
result)
|
|
|
|
|
(while (search-forward separator nil t)
|
|
|
|
|
(move-marker start (match-beginning 0))
|
|
|
|
|
(move-marker end (match-end 0))
|
|
|
|
|
(add-to-list 'result (cons (copy-marker start) (copy-marker end t))))
|
|
|
|
|
;; Return the list of marker pairs
|
|
|
|
|
(nreverse result))))
|
|
|
|
|
|
|
|
|
|
(defun rmail-digest-parse-rfc1153strict ()
|
|
|
|
|
"Parse following strictly the method defined in RFC 1153.
|
|
|
|
|
See rmail-digest-methods."
|
|
|
|
|
(rmail-digest-rfc1153
|
|
|
|
|
"^-\\{70\\}\n\n"
|
|
|
|
|
"^\n-\\{30\\}\n\n"
|
|
|
|
|
"^\n-\\{30\\}\n\nEnd of .* Digest.*\n\\*\\{15,\\}\n+\'"))
|
|
|
|
|
|
|
|
|
|
(defun rmail-digest-parse-rfc1153sloppy ()
|
|
|
|
|
"Parse using the method defined in RFC 1153, allowing for some sloppiness.
|
|
|
|
|
See rmail-digest-methods."
|
|
|
|
|
(rmail-digest-rfc1153
|
|
|
|
|
"^-\\{55,\\}\n\n"
|
|
|
|
|
"^\n-\\{27,\\}\n\n"
|
2007-08-15 03:09:28 +00:00
|
|
|
|
;; GNU Mailman knowingly (see comment at line 353 of ToDigest.py in
|
|
|
|
|
;; Mailman source) produces non-conformant rfc 1153 digests, in that
|
|
|
|
|
;; the trailer contains a "digest footer" like this:
|
|
|
|
|
;; _______________________________________________
|
|
|
|
|
;; <one or more lines of list blurb>
|
|
|
|
|
;;
|
|
|
|
|
;; End of Foo Digest...
|
|
|
|
|
;; **************************************
|
|
|
|
|
"^\nEnd of"))
|
2002-12-16 16:22:41 +00:00
|
|
|
|
|
|
|
|
|
(defun rmail-digest-rfc1153 (prolog-sep message-sep trailer-sep)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (re-search-forward prolog-sep nil t)
|
|
|
|
|
;; Ok, prolog separator found
|
|
|
|
|
(let ((start (make-marker))
|
|
|
|
|
(end (make-marker))
|
|
|
|
|
separator result)
|
|
|
|
|
(move-marker start (match-beginning 0))
|
|
|
|
|
(move-marker end (match-end 0))
|
2007-08-15 03:09:28 +00:00
|
|
|
|
(setq result (list (cons (copy-marker start) (copy-marker end t))))
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(when (re-search-forward message-sep nil t)
|
|
|
|
|
;; Ok, at least one message separator found
|
|
|
|
|
(setq separator (match-string 0))
|
|
|
|
|
(when (re-search-forward trailer-sep nil t)
|
|
|
|
|
;; Wonderful, we found a trailer, too. Now, go on splitting
|
|
|
|
|
;; the digest into separate rmail messages
|
|
|
|
|
(goto-char (cdar result))
|
|
|
|
|
(while (search-forward separator nil t)
|
|
|
|
|
(move-marker start (match-beginning 0))
|
|
|
|
|
(move-marker end (match-end 0))
|
|
|
|
|
(add-to-list 'result
|
|
|
|
|
(cons (copy-marker start) (copy-marker end t))))
|
|
|
|
|
;; Undo masking of separators inside digestified messages
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward
|
|
|
|
|
(replace-regexp-in-string "\n-" "\n " separator) nil t)
|
|
|
|
|
(replace-match separator))
|
|
|
|
|
;; Return the list of marker pairs
|
|
|
|
|
(nreverse result))))))
|
|
|
|
|
|
|
|
|
|
(defun rmail-digest-parse-rfc934 ()
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (re-search-forward "^\n?-[^ ].*\n\n?" nil t)
|
|
|
|
|
;; Message separator found
|
|
|
|
|
(let ((start (make-marker))
|
|
|
|
|
(end (make-marker))
|
|
|
|
|
(separator (match-string 0))
|
|
|
|
|
result)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward separator nil t)
|
|
|
|
|
(move-marker start (match-beginning 0))
|
|
|
|
|
(move-marker end (match-end 0))
|
|
|
|
|
(add-to-list 'result (cons (copy-marker start) (copy-marker end t))))
|
|
|
|
|
;; Undo masking of separators inside digestified messages
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward "\n- -" nil t)
|
|
|
|
|
(replace-match "\n-"))
|
|
|
|
|
;; Return the list of marker pairs
|
|
|
|
|
(nreverse result))))
|
|
|
|
|
|
2007-11-25 16:48:31 +00:00
|
|
|
|
(declare-function rmail-update-summary "rmailsum" (&rest ignore))
|
|
|
|
|
|
1996-09-27 00:33:39 +00:00
|
|
|
|
;;;###autoload
|
1989-10-31 15:59:53 +00:00
|
|
|
|
(defun undigestify-rmail-message ()
|
|
|
|
|
"Break up a digest message into its constituent messages.
|
|
|
|
|
Leaves original message, deleted, before the undigestified messages."
|
|
|
|
|
(interactive)
|
1997-12-26 10:48:47 +00:00
|
|
|
|
(with-current-buffer rmail-buffer
|
|
|
|
|
(widen)
|
|
|
|
|
(let ((error t)
|
|
|
|
|
(buffer-read-only nil))
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(goto-char (rmail-msgend rmail-current-message))
|
|
|
|
|
(let ((msg-copy (buffer-substring (rmail-msgbeg rmail-current-message)
|
|
|
|
|
(rmail-msgend rmail-current-message))))
|
|
|
|
|
(narrow-to-region (point) (point))
|
|
|
|
|
(insert msg-copy))
|
|
|
|
|
(narrow-to-region (point-min) (1- (point-max)))
|
1997-12-26 10:48:47 +00:00
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn
|
|
|
|
|
(save-restriction
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(delete-region (point-min)
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(progn (search-forward "\n*** EOOH ***\n" nil t)
|
1997-12-26 10:48:47 +00:00
|
|
|
|
(point)))
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(insert "\n" rmail-mail-separator)
|
1997-12-26 10:48:47 +00:00
|
|
|
|
(narrow-to-region (point)
|
|
|
|
|
(point-max))
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(let ((fill-prefix "")
|
|
|
|
|
(case-fold-search t)
|
|
|
|
|
digest-name type start end separator fun-list sep-list)
|
|
|
|
|
(setq digest-name (mail-strip-quoted-names
|
|
|
|
|
(save-restriction
|
|
|
|
|
(search-forward "\n\n" nil 'move)
|
|
|
|
|
(setq start (point))
|
|
|
|
|
(narrow-to-region (point-min) start)
|
|
|
|
|
(or (mail-fetch-field "Reply-To")
|
|
|
|
|
(mail-fetch-field "To")
|
|
|
|
|
(mail-fetch-field "Apparently-To")
|
|
|
|
|
(mail-fetch-field "From")))))
|
|
|
|
|
(unless digest-name
|
|
|
|
|
(error "Message is not a digest--bad header"))
|
|
|
|
|
|
|
|
|
|
(setq fun-list rmail-digest-methods)
|
|
|
|
|
(while (and fun-list
|
|
|
|
|
(null (setq sep-list (funcall (car fun-list)))))
|
|
|
|
|
(setq fun-list (cdr fun-list)))
|
|
|
|
|
(unless sep-list
|
|
|
|
|
(error "Message is not a digest--no messages found"))
|
|
|
|
|
|
|
|
|
|
;;; Split the digest into separate rmail messages
|
|
|
|
|
(while sep-list
|
|
|
|
|
(let ((start (caar sep-list))
|
|
|
|
|
(end (cdar sep-list)))
|
|
|
|
|
(delete-region start end)
|
|
|
|
|
(goto-char start)
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(insert rmail-mail-separator)
|
2002-12-16 16:22:41 +00:00
|
|
|
|
(search-forward "\n\n" (caar (cdr sep-list)) 'move)
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region end (point))
|
|
|
|
|
(unless (mail-fetch-field "To")
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(insert "To: " digest-name "\n")))
|
|
|
|
|
(set-marker start nil)
|
|
|
|
|
(set-marker end nil))
|
|
|
|
|
(setq sep-list (cdr sep-list)))))
|
|
|
|
|
|
1997-12-26 10:48:47 +00:00
|
|
|
|
(setq error nil)
|
|
|
|
|
(message "Message successfully undigestified")
|
|
|
|
|
(let ((n rmail-current-message))
|
|
|
|
|
(rmail-forget-messages)
|
|
|
|
|
(rmail-show-message n)
|
|
|
|
|
(rmail-delete-forward)
|
|
|
|
|
(if (rmail-summary-exists)
|
|
|
|
|
(rmail-select-summary
|
|
|
|
|
(rmail-update-summary)))))
|
|
|
|
|
(cond (error
|
|
|
|
|
(narrow-to-region (point-min) (1+ (point-max)))
|
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
|
(rmail-show-message rmail-current-message)))))))
|
2002-12-20 12:46:44 +00:00
|
|
|
|
|
1996-09-27 00:33:39 +00:00
|
|
|
|
;;;###autoload
|
1996-02-21 21:28:05 +00:00
|
|
|
|
(defun unforward-rmail-message ()
|
|
|
|
|
"Extract a forwarded message from the containing message.
|
|
|
|
|
This puts the forwarded message into a separate rmail message
|
|
|
|
|
following the containing message."
|
|
|
|
|
(interactive)
|
1997-12-26 10:48:47 +00:00
|
|
|
|
;; If we are in a summary buffer, switch to the Rmail buffer.
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(unwind-protect
|
|
|
|
|
(with-current-buffer rmail-buffer
|
|
|
|
|
(goto-char (point-min))
|
2003-02-20 08:56:08 +00:00
|
|
|
|
(narrow-to-region (point)
|
|
|
|
|
(save-excursion (search-forward "\n\n") (point)))
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(let ((buffer-read-only nil)
|
2003-02-20 08:56:08 +00:00
|
|
|
|
(old-fwd-from (mail-fetch-field "Forwarded-From" nil nil t))
|
|
|
|
|
(old-fwd-date (mail-fetch-field "Forwarded-Date" nil nil t))
|
|
|
|
|
(fwd-from (mail-fetch-field "From"))
|
|
|
|
|
(fwd-date (mail-fetch-field "Date"))
|
2003-01-08 10:13:57 +00:00
|
|
|
|
beg end prefix forward-msg)
|
2003-02-20 08:56:08 +00:00
|
|
|
|
(narrow-to-region (rmail-msgbeg rmail-current-message)
|
|
|
|
|
(rmail-msgend rmail-current-message))
|
|
|
|
|
(goto-char (point-min))
|
2003-01-31 14:01:20 +00:00
|
|
|
|
(cond ((re-search-forward rmail-forward-separator-regex nil t)
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(forward-line 1)
|
2003-01-07 14:34:44 +00:00
|
|
|
|
(skip-chars-forward "\n")
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(setq beg (point))
|
|
|
|
|
(setq end (if (re-search-forward "^----.*[^- \t\n]" nil t)
|
|
|
|
|
(match-beginning 0) (point-max)))
|
|
|
|
|
(setq forward-msg
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"^- -" "-" (buffer-substring beg end))))
|
2002-12-23 22:51:38 +00:00
|
|
|
|
((and (re-search-forward "^\\(> ?\\)[a-zA-Z-]+: .*\n" nil t)
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(setq beg (match-beginning 0))
|
2003-01-08 09:11:23 +00:00
|
|
|
|
(setq prefix (match-string-no-properties 1))
|
2002-12-23 22:51:38 +00:00
|
|
|
|
(goto-char beg)
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(looking-at (concat "\\(" prefix ".+\n\\)*"
|
2003-01-08 09:11:23 +00:00
|
|
|
|
prefix "Date: ."))
|
2002-12-23 22:51:38 +00:00
|
|
|
|
(looking-at (concat "\\(" prefix ".+\n\\)*"
|
|
|
|
|
prefix "From: .+\n"
|
|
|
|
|
"\\(" prefix ".+\n\\)*"
|
2002-12-20 12:46:44 +00:00
|
|
|
|
"\\(> ?\\)?\n" prefix)))
|
|
|
|
|
(re-search-forward "^[^>\n]" nil 'move)
|
|
|
|
|
(backward-char)
|
|
|
|
|
(skip-chars-backward " \t\n")
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(setq end (point))
|
|
|
|
|
(setq forward-msg
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
(if (string= prefix ">") "^>" "> ?")
|
|
|
|
|
"" (buffer-substring beg end))))
|
|
|
|
|
(t
|
|
|
|
|
(error "No forwarded message found")))
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (rmail-msgend rmail-current-message))
|
|
|
|
|
(narrow-to-region (point) (point))
|
|
|
|
|
(insert rmail-mail-separator)
|
|
|
|
|
(narrow-to-region (point) (point))
|
2003-02-20 08:56:08 +00:00
|
|
|
|
(while old-fwd-from
|
|
|
|
|
(insert "Forwarded-From: " (car old-fwd-from) "\n")
|
|
|
|
|
(insert "Forwarded-Date: " (car old-fwd-date) "\n")
|
|
|
|
|
(setq old-fwd-from (cdr old-fwd-from))
|
|
|
|
|
(setq old-fwd-date (cdr old-fwd-date)))
|
|
|
|
|
(insert "Forwarded-From: " fwd-from "\n")
|
|
|
|
|
(insert "Forwarded-Date: " fwd-date "\n")
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(insert forward-msg)
|
|
|
|
|
(save-restriction
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(re-search-forward "\n$" nil 'move)
|
|
|
|
|
(narrow-to-region (point-min) (point))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(unless (looking-at "^[a-zA-Z-]+: ")
|
|
|
|
|
(insert "\t"))
|
|
|
|
|
(forward-line)))
|
|
|
|
|
(goto-char (point-min))))
|
2003-01-08 10:13:57 +00:00
|
|
|
|
(let ((n rmail-current-message))
|
|
|
|
|
(rmail-forget-messages)
|
|
|
|
|
(rmail-show-message n))
|
2002-12-20 12:46:44 +00:00
|
|
|
|
(if (rmail-summary-exists)
|
|
|
|
|
(rmail-select-summary
|
|
|
|
|
(rmail-update-summary)))))
|
|
|
|
|
|
1996-02-21 21:28:05 +00:00
|
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
|
(provide 'undigest)
|
|
|
|
|
|
2008-04-10 14:10:46 +00:00
|
|
|
|
;; arch-tag: 3a28b9fb-c1f5-43ef-9278-285f3e4b874d
|
1992-05-30 20:24:49 +00:00
|
|
|
|
;;; undigest.el ends here
|