annotate lisp/mail/pmailout.el @ 100404:e5f10d15806c

(pmail-output-to-babyl-file): Rewrite, assuming mbox internal format. (pmail-convert-to-babyl-format, pmail-nuke-pinhead-header): New functions, moved from pmail.el.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 13 Dec 2008 14:19:56 +0000
parents 241987bb5332
children 413e7b650cf7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
1 ;;; pmailout.el --- "PMAIL" mail reader for Emacs: output message to a file
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
2
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
3 ;; Copyright (C) 1985, 1987, 1993, 1994, 2001, 2002, 2003, 2004,
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
5
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
6 ;; Maintainer: FSF
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
7 ;; Keywords: mail
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
8
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
10
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
14 ;; (at your option) any later version.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
15
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
20
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
23
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
24 ;;; Commentary:
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
25
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
26 ;;; Code:
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
27
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
28 (require 'pmail)
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
29 (provide 'pmailout)
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
30
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
31 ;;;###autoload
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
32 (defcustom pmail-output-file-alist nil
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
33 "*Alist matching regexps to suggested output Pmail files.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
34 This is a list of elements of the form (REGEXP . NAME-EXP).
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35 The suggestion is taken if REGEXP matches anywhere in the message buffer.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36 NAME-EXP may be a string constant giving the file name to use,
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
37 or more generally it may be any kind of expression that returns
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
38 a file name as a string."
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39 :type '(repeat (cons regexp
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
40 (choice :value ""
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41 (string :tag "File Name")
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 sexp)))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43 :group 'pmail-output)
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
44
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
45 (defun pmail-output-read-pmail-file-name ()
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
46 "Read the file name to use for `pmail-output-to-babyl-file'.
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
47 Set `pmail-default-pmail-file' to this name as well as returning it."
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
48 (let ((default-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
49 (let (answer tail)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
50 (setq tail pmail-output-file-alist)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
51 ;; Suggest a file based on a pattern match.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
52 (while (and tail (not answer))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
53 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
54 (set-buffer pmail-buffer)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
55 (goto-char (point-min))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
56 (if (re-search-forward (car (car tail)) nil t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
57 (setq answer (eval (cdr (car tail)))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
58 (setq tail (cdr tail))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
59 ;; If no suggestions, use same file as last time.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
60 (expand-file-name (or answer pmail-default-pmail-file)))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
61 (let ((read-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
62 (expand-file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
63 (read-file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
64 (concat "Output message to Pmail file (default "
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
65 (file-name-nondirectory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
66 "): ")
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
67 (file-name-directory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
68 (abbreviate-file-name default-file))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
69 (file-name-directory default-file))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
70 ;; If the user enters just a directory,
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
71 ;; use the name within that directory chosen by the default.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
72 (setq pmail-default-pmail-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
73 (if (file-directory-p read-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
74 (expand-file-name (file-name-nondirectory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
75 read-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
76 read-file)))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
77
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
78 (defun pmail-output-read-file-name ()
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
79 "Read the file name to use for `pmail-output'.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
80 Set `pmail-default-file' to this name as well as returning it."
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
81 (let ((default-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
82 (let (answer tail)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
83 (setq tail pmail-output-file-alist)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
84 ;; Suggest a file based on a pattern match.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
85 (while (and tail (not answer))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
86 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
87 (goto-char (point-min))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
88 (if (re-search-forward (car (car tail)) nil t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
89 (setq answer (eval (cdr (car tail)))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
90 (setq tail (cdr tail))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
91 ;; If no suggestion, use same file as last time.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
92 (or answer pmail-default-file))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
93 (let ((read-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
94 (expand-file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
95 (read-file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
96 (concat "Output message to Unix mail file (default "
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
97 (file-name-nondirectory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
98 "): ")
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
99 (file-name-directory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
100 (abbreviate-file-name default-file))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
101 (file-name-directory default-file))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
102 (setq pmail-default-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
103 (if (file-directory-p read-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
104 (expand-file-name (file-name-nondirectory default-file)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
105 read-file)
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106 (expand-file-name
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
107 (or read-file (file-name-nondirectory default-file))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
108 (file-name-directory default-file)))))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
110 (declare-function pmail-update-summary "pmailsum" (&rest ignore))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 ;;; There are functions elsewhere in Emacs that use this function;
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113 ;;; look at them before you change the calling method.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114 ;;;###autoload
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
115 (defun pmail-output-to-babyl-file (file-name &optional count stay)
100339
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
116 "Append the current message to a Babyl file named FILE-NAME.
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117 If the file does not exist, ask if it should be created.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118 If file is being visited, the message is appended to the Emacs
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119 buffer visiting that file.
100339
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
120 If the file exists and is not a Babyl file, the message is
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121 appended in inbox format, the same way `pmail-output' does it.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123 The default file name comes from `pmail-default-pmail-file',
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
124 which is updated to the name you use in this command.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 A prefix argument COUNT says to output that many consecutive messages,
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 starting with the current one. Deleted messages are skipped and don't count.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129 If the optional argument STAY is non-nil, then leave the last filed
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 message up instead of moving forward to the next non-deleted message."
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
131 (interactive
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
132 (list (pmail-output-read-pmail-file-name)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
133 (prefix-numeric-value current-prefix-arg)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
134 (or count (setq count 1))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
135 (setq file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
136 (expand-file-name file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
137 (file-name-directory pmail-default-pmail-file)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
138 (if (and (file-readable-p file-name) (not (mail-file-babyl-p file-name)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
139 (pmail-output file-name count)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
140 (pmail-maybe-set-message-counters)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
141 (setq file-name (abbreviate-file-name file-name))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
142 (or (find-buffer-visiting file-name)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
143 (file-exists-p file-name)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
144 (if (yes-or-no-p
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
145 (concat "\"" file-name "\" does not exist, create it? "))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
146 (let ((file-buffer (create-file-buffer file-name)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
147 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
148 (set-buffer file-buffer)
100339
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
149 (let ((buffer-read-only nil))
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
150 (insert "BABYL OPTIONS: -*- pmail -*-
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
151 Version: 5
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
152 Labels:
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
153 Note: This is the header of an pmail file.
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
154 Note: If you are seeing it in pmail,
1afe9b0dcf0e (pmail-output-to-pmail-file): Don't call
Chong Yidong <cyd@stupidchicken.com>
parents: 100223
diff changeset
155 Note: it means the file has no messages in it.\n\^_"))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
156 (let ((require-final-newline nil)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
157 (coding-system-for-write
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
158 (or pmail-file-coding-system
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
159 'emacs-mule-unix)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
160 (write-region (point-min) (point-max) file-name t 1)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
161 (kill-buffer file-buffer))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
162 (error "Output file does not exist")))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
163 (while (> count 0)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
164 (let (redelete)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
165 (unwind-protect
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
166 (progn
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
167 (set-buffer pmail-buffer)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
168 ;; Temporarily turn off Deleted attribute.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
169 ;; Do this outside the save-restriction, since it would
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
170 ;; shift the place in the buffer where the visible text starts.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
171 (if (pmail-message-deleted-p pmail-current-message)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
172 (progn (setq redelete t)
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
173 (pmail-set-attribute pmail-deleted-attr-index nil)))
100404
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
174 (let ((coding-system-for-write
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
175 (or pmail-file-coding-system
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
176 'emacs-mule-unix))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
177 cur beg end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
178 (pmail-swap-buffers-maybe)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
179 (setq cur (current-buffer))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
180 (save-restriction
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
181 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
182 (widen)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
183 (setq beg (pmail-msgbeg pmail-current-message)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
184 end (pmail-msgend pmail-current-message))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
185 ;; Output to a file.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
186 (set-buffer (get-buffer-create " pmail-out-temp"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
187 (insert-buffer-substring cur beg end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
188 (if pmail-fields-not-to-output
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
189 (pmail-delete-unwanted-fields))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
190 ;; Convert to Babyl format.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
191 (pmail-convert-to-babyl-format)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
192 (append-to-file (point-min) (point-max) file-name)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
193 (set-buffer cur)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
194 (kill-buffer (get-buffer " pmail-out-temp")))))
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
195 (pmail-set-attribute pmail-filed-attr-index t))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
196 (if redelete (pmail-set-attribute pmail-deleted-attr-index t))))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
197 (setq count (1- count))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
198 (if pmail-delete-after-output
100404
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
199 (unless (if (and (= count 0) stay)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
200 (pmail-delete-message)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
201 (pmail-delete-forward))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
202 (setq count 0))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
203 (if (> count 0)
100404
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
204 (unless (if (not stay)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
205 (pmail-next-undeleted-message 1))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
206 (setq count 0))))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
207 (pmail-show-message))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
208
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
209 (defalias 'pmail-output-to-pmail-file 'pmail-output-to-babyl-file)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
210
100404
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
211 (defun pmail-convert-to-babyl-format ()
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
212 (let ((count 0) start
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
213 (case-fold-search nil)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
214 (buffer-undo-list t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
215 (goto-char (point-min))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
216 (save-restriction
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
217 (while (not (eobp))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
218 (setq start (point))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
219 (unless (looking-at "^From ")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
220 (error "Invalid mbox message"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
221 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
222 (pmail-nuke-pinhead-header)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
223 ;; If this message has a Content-Length field,
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
224 ;; skip to the end of the contents.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
225 (let* ((header-end (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
226 (and (re-search-forward "\n\n" nil t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
227 (1- (point)))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
228 (case-fold-search t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
229 (quoted-printable-header-field-end
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
230 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
231 (re-search-forward
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
232 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
233 header-end t)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
234 (base64-header-field-end
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
235 (and
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
236 ;; Don't decode non-text data.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
237 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
238 (re-search-forward
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
239 "^content-type:\\(\n?[\t ]\\)\\(text\\|message\\)/"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
240 header-end t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
241 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
242 (re-search-forward
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
243 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
244 header-end t))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
245 (size
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
246 ;; Get the numeric value from the Content-Length field.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
247 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
248 ;; Back up to end of prev line,
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
249 ;; in case the Content-Length field comes first.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
250 (forward-char -1)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
251 (and (search-forward "\ncontent-length: "
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
252 header-end t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
253 (let ((beg (point))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
254 (eol (progn (end-of-line) (point))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
255 (string-to-number (buffer-substring beg eol)))))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
256 (and size
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
257 (if (and (natnump size)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
258 (<= (+ header-end size) (point-max))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
259 ;; Make sure this would put us at a position
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
260 ;; that we could continue from.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
261 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
262 (goto-char (+ header-end size))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
263 (skip-chars-forward "\n")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
264 (or (eobp)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
265 (and (looking-at "BABYL OPTIONS:")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
266 (search-forward "\n\^_" nil t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
267 (and (looking-at "\^L")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
268 (search-forward "\n\^_" nil t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
269 (let ((case-fold-search t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
270 (looking-at pmail-mmdf-delim1))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
271 (looking-at "From "))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
272 (goto-char (+ header-end size))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
273 (message "Ignoring invalid Content-Length field")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
274 (sit-for 1 0 t)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
275 (if (let ((case-fold-search nil))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
276 (re-search-forward
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
277 (concat "^[\^_]?\\("
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
278 pmail-unix-mail-delimiter
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
279 "\\|"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
280 pmail-mmdf-delim1 "\\|"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
281 "^BABYL OPTIONS:\\|"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
282 "\^L\n[01],\\)") nil t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
283 (goto-char (match-beginning 1))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
284 (goto-char (point-max)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
285 (setq count (1+ count))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
286 (if quoted-printable-header-field-end
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
287 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
288 (unless (mail-unquote-printable-region
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
289 header-end (point) nil t t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
290 (message "Malformed MIME quoted-printable message"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
291 ;; Change "quoted-printable" to "8bit",
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
292 ;; to reflect the decoding we just did.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
293 (goto-char quoted-printable-header-field-end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
294 (delete-region (point) (search-backward ":"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
295 (insert ": 8bit")))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
296 (if base64-header-field-end
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
297 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
298 (when (condition-case nil
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
299 (progn
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
300 (base64-decode-region
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
301 (1+ header-end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
302 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
303 ;; Prevent base64-decode-region
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
304 ;; from removing newline characters.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
305 (skip-chars-backward "\n\t ")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
306 (point)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
307 t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
308 (error nil))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
309 ;; Change "base64" to "8bit", to reflect the
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
310 ;; decoding we just did.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
311 (goto-char base64-header-field-end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
312 (delete-region (point) (search-backward ":"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
313 (insert ": 8bit")))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
314 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
315 (save-restriction
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
316 (narrow-to-region start (point))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
317 (goto-char (point-min))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
318 (while (search-forward "\n\^_" nil t) ; single char
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
319 (replace-match "\n^_")))) ; 2 chars: "^" and "_"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
320 ;; This is for malformed messages that don't end in newline.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
321 ;; There shouldn't be any, but some users say occasionally
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
322 ;; there are some.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
323 (or (bolp) (newline))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
324 (insert ?\^_)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
325 (setq last-coding-system-used nil)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
326 (or pmail-enable-mime
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
327 (not pmail-enable-multibyte)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
328 (let ((mime-charset
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
329 (if (and pmail-decode-mime-charset
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
330 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
331 (goto-char start)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
332 (search-forward "\n\n" nil t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
333 (let ((case-fold-search t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
334 (re-search-backward
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
335 pmail-mime-charset-pattern
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
336 start t))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
337 (intern (downcase (match-string 1))))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
338 (pmail-decode-region start (point) mime-charset)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
339 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
340 (goto-char start)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
341 (forward-line 3)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
342 (insert "X-Coding-System: "
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
343 (symbol-name last-coding-system-used)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
344 "\n"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
345 (narrow-to-region (point) (point-max))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
346 (and (= 0 (% count 10))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
347 (message "Converting to Babyl format...%d" count))))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
348
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
349 ;; Delete the "From ..." line, creating various other headers with
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
350 ;; information from it if they don't already exist. Now puts the
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
351 ;; original line into a mail-from: header line for debugging and for
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
352 ;; use by the pmail-output function.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
353 (defun pmail-nuke-pinhead-header ()
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
354 (save-excursion
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
355 (save-restriction
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
356 (let ((start (point))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
357 (end (progn
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
358 (condition-case ()
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
359 (search-forward "\n\n")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
360 (error
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
361 (goto-char (point-max))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
362 (insert "\n\n")))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
363 (point)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
364 has-from has-date)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
365 (narrow-to-region start end)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
366 (let ((case-fold-search t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
367 (goto-char start)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
368 (setq has-from (search-forward "\nFrom:" nil t))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
369 (goto-char start)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
370 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
371 (goto-char start))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
372 (let ((case-fold-search nil))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
373 (if (re-search-forward (concat "^" pmail-unix-mail-delimiter) nil t)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
374 (replace-match
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
375 (concat
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
376 "Mail-from: \\&"
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
377 ;; Keep and reformat the date if we don't
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
378 ;; have a Date: field.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
379 (if has-date
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
380 ""
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
381 (concat
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
382 "Date: \\2, \\4 \\3 \\9 \\5 "
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
383
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
384 ;; The timezone could be matched by group 7 or group 10.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
385 ;; If neither of them matched, assume EST, since only
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
386 ;; Easterners would be so sloppy.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
387 ;; It's a shame the substitution can't use "\\10".
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
388 (cond
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
389 ((/= (match-beginning 7) (match-end 7)) "\\7")
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
390 ((/= (match-beginning 10) (match-end 10))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
391 (buffer-substring (match-beginning 10)
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
392 (match-end 10)))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
393 (t "EST"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
394 "\n"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
395 ;; Keep and reformat the sender if we don't
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
396 ;; have a From: field.
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
397 (if has-from
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
398 ""
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
399 "From: \\1\n"))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
400 t)))))))
e5f10d15806c (pmail-output-to-babyl-file): Rewrite, assuming mbox
Chong Yidong <cyd@stupidchicken.com>
parents: 100377
diff changeset
401
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
402 ;;;###autoload
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
403 (defcustom pmail-fields-not-to-output nil
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
404 "*Regexp describing fields to exclude when outputting a message to a file."
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
405 :type '(choice (const :tag "None" nil)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
406 regexp)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
407 :group 'pmail-output)
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
408
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
409 ;; Delete from the buffer header fields we don't want output.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
410 ;; NOT-PMAIL if t means this buffer does not have the full header
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
411 ;; and *** EOOH *** that a message in an Pmail file has.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
412 (defun pmail-delete-unwanted-fields (&optional not-pmail)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
413 (if pmail-fields-not-to-output
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
414 (save-excursion
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
415 (goto-char (point-min))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
416 ;; Find the end of the header.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
417 (if (and (or not-pmail (search-forward "\n*** EOOH ***\n" nil t))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
418 (search-forward "\n\n" nil t))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
419 (let ((end (point-marker)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
420 (goto-char (point-min))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
421 (while (re-search-forward pmail-fields-not-to-output end t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
422 (beginning-of-line)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
423 (delete-region (point)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
424 (progn (forward-line 1) (point)))))))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
425
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
426 ;;; There are functions elsewhere in Emacs that use this function;
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
427 ;;; look at them before you change the calling method.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
428 ;;;###autoload
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
429 (defun pmail-output (file-name &optional count noattribute from-gnus)
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
430 "Append this message to system-inbox-format mail file named FILE-NAME.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
431 A prefix argument COUNT says to output that many consecutive messages,
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
432 starting with the current one. Deleted messages are skipped and don't count.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
433 When called from lisp code, COUNT may be omitted and defaults to 1.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
434
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
435 If the pruned message header is shown on the current message, then
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
436 messages will be appended with pruned headers; otherwise, messages
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
437 will be appended with their original headers.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
438
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
439 The default file name comes from `pmail-default-file',
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
440 which is updated to the name you use in this command.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
441
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
442 The optional third argument NOATTRIBUTE, if non-nil, says not
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
443 to set the `filed' attribute, and not to display a message.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
444
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
445 The optional fourth argument FROM-GNUS is set when called from GNUS."
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
446 (interactive
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
447 (list (pmail-output-read-file-name)
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
448 (prefix-numeric-value current-prefix-arg)))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
449 (or count (setq count 1))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
450 (setq file-name
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
451 (expand-file-name file-name
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
452 (and pmail-default-file
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
453 (file-name-directory pmail-default-file))))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
454 (if (and (file-readable-p file-name) (mail-file-babyl-p file-name))
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
455 (pmail-output-to-babyl-file file-name count)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
456 (set-buffer pmail-buffer)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
457 (let ((orig-count count)
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
458 (pmailbuf pmail-buffer)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
459 (case-fold-search t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
460 (tembuf (get-buffer-create " pmail-output"))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
461 header-beginning
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
462 mail-from mime-version content-type)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
463 (while (> count 0)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
464 ;; Preserve the Mail-From and MIME-Version fields
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
465 ;; even if they have been pruned.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
466 (or from-gnus
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
467 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
468 (save-restriction
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
469 (goto-char (if pmail-buffers-swapped-p
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
470 (point-min)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
471 (pmail-msgbeg pmail-current-message)))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
472 (setq header-beginning (point))
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
473 (search-forward "\n\n" nil 'move)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
474 (narrow-to-region header-beginning (point))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
475 (setq mail-from (mail-fetch-field "Mail-From"))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
476 (unless pmail-enable-mime
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
477 (setq mime-version (mail-fetch-field "MIME-Version")
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
478 content-type (mail-fetch-field "Content-type"))))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
479 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
480 (set-buffer tembuf)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
481 (erase-buffer)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
482 (insert-buffer-substring pmailbuf)
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
483 (save-excursion
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
484 (goto-char (min (point-min) (- (point-max) 2)))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
485 (unless (looking-at "\n\n")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
486 (goto-char (point-max))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
487 (insert "\n\n")))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
488 (when pmail-enable-mime
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
489 (goto-char (point-min))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
490 (forward-line 2)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
491 (delete-region (point-min) (point))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
492 (search-forward "\n\n")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
493 (delete-region (match-beginning 0)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
494 (if (search-forward "\n\n")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
495 (1- (match-end 0))))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
496 (setq buffer-file-coding-system (or pmail-file-coding-system
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
497 'raw-text)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
498 (pmail-delete-unwanted-fields t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
499 (or (bolp) (insert "\n"))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
500 (goto-char (point-min))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
501 (if mail-from
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
502 (insert mail-from "\n")
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
503 (insert "From "
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
504 (mail-strip-quoted-names
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
505 (save-excursion
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
506 (save-restriction
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
507 (goto-char (point-min))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
508 (narrow-to-region
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
509 (point)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
510 (or (search-forward "\n\n" nil)
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
511 (point-max)))
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
512 (or (mail-fetch-field "from")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
513 (mail-fetch-field "really-from")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
514 (mail-fetch-field "sender")
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
515 "unknown"))))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
516 " " (current-time-string) "\n"))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
517 (when mime-version
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
518 (insert "MIME-Version: " mime-version)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
519 ;; Some malformed MIME messages set content-type to nil.
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
520 (when content-type
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
521 (insert "\nContent-type: " content-type "\n")))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
522 ;; ``Quote'' "\nFrom " as "\n>From "
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
523 ;; (note that this isn't really quoting, as there is no requirement
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
524 ;; that "\n[>]+From " be quoted in the same transparent way.)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
525 (let ((case-fold-search nil))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
526 (while (search-forward "\nFrom " nil t)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
527 (forward-char -5)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
528 (insert ?>)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
529 (write-region (point-min) (point-max) file-name t
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
530 (if noattribute 'nomsg)))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
531 (or noattribute
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
532 (if (equal major-mode 'pmail-mode)
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
533 (pmail-set-attribute pmail-filed-attr-index t)))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
534 (setq count (1- count))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
535 (or from-gnus
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
536 (let ((next-message-p
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
537 (if pmail-delete-after-output
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
538 (pmail-delete-forward)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
539 (if (> count 0)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
540 (pmail-next-undeleted-message 1))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
541 (num-appended (- orig-count count)))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
542 (if (and (> count 0) (not next-message-p))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
543 (progn
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
544 (error "%s"
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
545 (save-excursion
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
546 (set-buffer pmailbuf)
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
547 (format "Only %d message%s appended" num-appended
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
548 (if (= num-appended 1) "" "s"))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
549 (setq count 0))))))
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
550 (kill-buffer tembuf))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
551
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
552 ;;;###autoload
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
553 (defun pmail-output-body-to-file (file-name)
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
554 "Write this message body to the file FILE-NAME.
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
555 FILE-NAME defaults, interactively, from the Subject field of the message."
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
556 (interactive
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
557 (let ((default-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
558 (or (mail-fetch-field "Subject")
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
559 pmail-default-body-file)))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
560 (list (setq pmail-default-body-file
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
561 (read-file-name
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
562 "Output message body to file: "
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
563 (and default-file (file-name-directory default-file))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
564 default-file
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
565 nil default-file)))))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
566 (setq file-name
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
567 (expand-file-name file-name
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
568 (and pmail-default-body-file
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
569 (file-name-directory pmail-default-body-file))))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
570 (save-excursion
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
571 (goto-char (point-min))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
572 (search-forward "\n\n")
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
573 (and (file-exists-p file-name)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
574 (not (y-or-n-p (format "File %s exists; overwrite? " file-name)))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
575 (error "Operation aborted"))
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
576 (write-region (point) (point-max) file-name)
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
577 (if (equal major-mode 'pmail-mode)
100377
241987bb5332 (pmail-output): Rewrite to handle mbox format.
Chong Yidong <cyd@stupidchicken.com>
parents: 100339
diff changeset
578 (pmail-set-attribute pmail-stored-attr-index t)))
100223
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
579 (if pmail-delete-after-output
ecb3dba6e932 Sync with rmailout.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 98019
diff changeset
580 (pmail-delete-forward)))
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
581
98019
72564311fb7b Add local variable setting for change-log-default-name.
Glenn Morris <rgm@gnu.org>
parents: 97967
diff changeset
582 ;; Local Variables:
72564311fb7b Add local variable setting for change-log-default-name.
Glenn Morris <rgm@gnu.org>
parents: 97967
diff changeset
583 ;; change-log-default-name: "ChangeLog.pmail"
72564311fb7b Add local variable setting for change-log-default-name.
Glenn Morris <rgm@gnu.org>
parents: 97967
diff changeset
584 ;; End:
72564311fb7b Add local variable setting for change-log-default-name.
Glenn Morris <rgm@gnu.org>
parents: 97967
diff changeset
585
97533
ec1125c7ac26 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 97532
diff changeset
586 ;; arch-tag: 4059abf0-f249-4be4-8e0d-602d370d01d1
97528
184bb2071e3f mail/: Add new (temporary) libaries for which to test Rmail/mbox such
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
587 ;;; pmailout.el ends here