emacs/lisp/mail/undigest.el

338 lines
12 KiB
EmacsLisp
Raw Normal View History

Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
;;; undigest.el --- digest-cracking support for the RMAIL mail reader -*- lexical-binding:t -*-
1992-05-30 20:24:49 +00:00
;; Copyright (C) 1985-1986, 1994, 1996, 2001-2020 Free Software
2013-01-01 09:11:05 +00:00
;; Foundation, Inc.
1992-07-22 02:58:48 +00:00
;; Maintainer: emacs-devel@gnu.org
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
1989-10-31 15:59:53 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
1989-10-31 15:59:53 +00:00
;; 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
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
1989-10-31 15:59:53 +00:00
1992-07-16 21:47:34 +00:00
;;; Commentary:
;; See Internet RFC 934 and RFC 1153.
;; Also limited support for MIME digest encapsulation.
1992-07-16 21:47:34 +00:00
;;; Code:
1989-10-31 15:59:53 +00:00
Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
(eval-when-compile (require 'cl-lib))
(require 'rmail)
(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.
You may need to customize it for local needs."
:type 'regexp
:group 'rmail-headers)
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)
"List of digest parsing functions, first tried first.
2002-12-16 16:22:41 +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 ; FIXME always true
2002-12-16 16:22:41 +00:00
(re-search-forward
(concat
"^Content-type: multipart/digest;"
Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
"\\s-* boundary=\"?\\([^\";\n]+\\)[\";\n]")
head-end t)
2002-12-16 16:22:41 +00:00
(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))
Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
(cl-pushnew (cons (copy-marker start) (copy-marker end t))
result :test #'equal))
2002-12-16 16:22:41 +00:00
;; 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"
Fix several backslash typos in Elisp strings * lisp/calendar/todo-mode.el (todo-files, todo-rename-file) (todo-find-filtered-items-file, todo-reset-nondiary-marker) (todo-reset-done-string, todo-reset-comment-string) (todo-reset-highlight-item): * lisp/erc/erc-networks.el (erc-networks-alist): * lisp/gnus/gnus-art.el (gnus-button-handle-library): * lisp/gnus/gnus-group.el (gnus-read-ephemeral-gmane-group-url): * lisp/gnus/nntp.el (nntp-via-shell-prompt) (nntp-telnet-shell-prompt): * lisp/gnus/spam-report.el (spam-report-gmane-regex): * lisp/image-dired.el (image-dired-rotate-original): (image-dired-get-exif-file-name): * lisp/international/latin1-disp.el (latin1-display-ucs-per-lynx): * lisp/mail/undigest.el (rmail-digest-parse-rfc1153strict): * lisp/mh-e/mh-letter.el (mh-file-is-vcard-p): * lisp/mh-e/mh-mime.el (mh-file-mime-type-substitutions): * lisp/net/shr-color.el (shr-color->hexadecimal): * lisp/org/org-bibtex.el (org-bibtex-fields): * lisp/org/org-docview.el (org-docview-export): * lisp/org/org-entities.el (org-entities): * lisp/org/ox-icalendar.el (org-icalendar-cleanup-string): * lisp/progmodes/cperl-mode.el (cperl-indent-exp): * lisp/progmodes/ebnf2ps.el (ebnf-file-suffix-regexp) (ebnf-style-database): * lisp/progmodes/idlw-help.el (idlwave-do-context-help1): * lisp/progmodes/ruby-mode.el (ruby-imenu-create-index-in-block): * lisp/progmodes/sql.el (sql-product-alist): * lisp/progmodes/verilog-mode.el (verilog-error-regexp-emacs-alist) (verilog-error-font-lock-keywords) (verilog-assignment-operator-re): * lisp/progmodes/vhdl-mode.el (vhdl-compiler-alist): * lisp/textmodes/reftex-parse.el (reftex-parse-from-file): * lisp/vc/add-log.el (change-log-version-number-regexp-list): Fix typo by replacing ‘\’ with ‘\\’ in a string literal. For example, to get the regular expression ‘\.’ use the string literal "\\.", not "\." (which is equivalent to "."). * lisp/emulation/viper-util.el (viper-glob-unix-files): Remove stray ‘\j’ from string. * lisp/gnus/nntp.el (nntp-via-shell-prompt) (nntp-telnet-shell-prompt): Treat > like $ when matching a shell prompt. * lisp/progmodes/make-mode.el (makefile-browse): Properly quote a diagnostic.
2015-09-17 12:28:45 -07:00
"^\n-\\{30\\}\n\nEnd of .* Digest.*\n\\*\\{15,\\}\n+\\'"))
2002-12-16 16:22:41 +00:00
(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"
;; 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))
(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))
Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
(cl-pushnew (cons (copy-marker start) (copy-marker end t))
result :test #'equal))
2002-12-16 16:22:41 +00:00
;; 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))
Avoid add-to-list on local variables * lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
2017-01-04 00:40:45 -05:00
(cl-pushnew (cons (copy-marker start) (copy-marker end t))
result :test #'equal))
2002-12-16 16:22:41 +00:00
;; 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))))
(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)
(set-buffer rmail-buffer)
(let ((buff (current-buffer))
(current rmail-current-message)
(msgbeg (rmail-msgbeg rmail-current-message))
(msgend (rmail-msgend rmail-current-message)))
(if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
(widen)
(let ((error t)
(buffer-read-only nil))
(goto-char msgend)
(let ((msg-copy (buffer-substring-no-properties msgbeg msgend)))
2002-12-16 16:22:41 +00:00
(narrow-to-region (point) (point))
(insert "\n" msg-copy))
(goto-char (point-min))
(unwind-protect
(progn
(let ((fill-prefix "")
(case-fold-search t)
digest-name fun-list sep-list start end)
(setq digest-name (mail-strip-quoted-names
(save-restriction
(search-forward "\n\n" nil 'move)
(narrow-to-region (point-min) (point))
(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
(setq start (caar sep-list)
end (cdar sep-list))
(delete-region start end)
(goto-char start)
(search-forward "\n\n" (caar (cdr sep-list)) 'move)
(save-restriction
(narrow-to-region end (point))
(goto-char (point-min))
(insert "\nFrom rmail@localhost " (current-time-string) "\n")
(save-excursion
(forward-line -1)
(rmail-add-mbox-headers))
(unless (mail-fetch-field "To")
(insert "To: " digest-name "\n")))
(set-marker start nil)
(set-marker end nil)
(setq sep-list (cdr sep-list))))
(setq error nil)
(message "Message successfully undigestified")
(set-buffer buff)
(rmail-swap-buffers-maybe)
(goto-char (point-max))
;; FIXME use rmail-count-new-messages.
(rmail-set-message-counters)
(set-buffer-modified-p t)
(rmail-show-message current)
(rmail-delete-forward)
(if (rmail-summary-exists)
(rmail-select-summary (rmail-update-summary))))
(when error
(delete-region (point-min) (point-max))
(set-buffer buff)
(rmail-show-message current))))))
1996-09-27 00:33:39 +00:00
;;;###autoload
(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. This command is only useful when messages are
forwarded with `rmail-enable-mime-composing' set to nil."
(interactive)
(set-buffer rmail-buffer)
(let ((buff (current-buffer))
(current rmail-current-message)
(beg (rmail-msgbeg rmail-current-message))
(msgend (rmail-msgend rmail-current-message))
(error t))
(unwind-protect
(progn
(if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
(widen)
(goto-char beg)
(search-forward "\n\n" msgend)
(narrow-to-region beg (point))
(let ((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"))
(buffer-read-only nil)
prefix forward-msg end)
(widen)
(narrow-to-region beg msgend)
(cond ((re-search-forward rmail-forward-separator-regex nil t)
(forward-line 1)
(skip-chars-forward "\n")
(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))))
((and (re-search-forward "^\\(> ?\\)[a-zA-Z-]+: .*\n" nil t)
(setq beg (match-beginning 0))
(setq prefix (match-string-no-properties 1))
(goto-char beg)
(looking-at (concat "\\(" prefix ".+\n\\)*"
prefix "Date: ."))
(looking-at (concat "\\(" prefix ".+\n\\)*"
prefix "From: .+\n"
"\\(" prefix ".+\n\\)*"
"\\(> ?\\)?\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 msgend)
;; Insert a fake From line.
;; FIXME we could construct one using the From and Date headers
;; of the forwarded message - is it worth it?
(insert "\n\nFrom rmail@localhost " (current-time-string) "\n")
(setq beg (point)) ; start of header
(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")
(insert forward-msg "\n")
(goto-char beg)
(re-search-forward "\n$" nil 'move) ; end of header
(narrow-to-region beg (point))
(goto-char (point-min))
(while (not (eobp))
(unless (looking-at "^[a-zA-Z-]+: ")
(insert "\t"))
(forward-line))
(widen)
(goto-char beg)
(forward-line -1)
(rmail-add-mbox-headers)) ; marks as unseen
(setq error nil)
(set-buffer buff)
(rmail-swap-buffers-maybe)
(goto-char (point-max))
;; FIXME use rmail-count-new-messages.
(rmail-set-message-counters)
(set-buffer-modified-p t)
(rmail-show-message current)
(if (rmail-summary-exists)
(rmail-select-summary (rmail-update-summary))))
(when error
(set-buffer buff)
(rmail-show-message current)))))
1997-06-22 18:57:55 +00:00
(provide 'undigest)
;; Local Variables:
;; generated-autoload-file: "rmail-loaddefs.el"
;; End:
1992-05-30 20:24:49 +00:00
;;; undigest.el ends here