(gnus-configure-windows): switch-to-buffer -> set-buffer.
[emacs.git] / lisp / gnus / message.el
blobf0c4d34e3a96df24fba808edc408a6c25cd8787e
1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
31 ;;; Code:
33 (eval-when-compile
34 (require 'cl)
35 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
36 (require 'mailheader)
37 (require 'nnheader)
38 ;; This is apparently necessary even though things are autoloaded:
39 (if (featurep 'xemacs)
40 (require 'mail-abbrevs))
41 (require 'mail-parse)
42 (require 'mml)
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
48 :group 'mail
49 :group 'news)
51 (put 'user-mail-address 'custom-type 'string)
52 (put 'user-full-name 'custom-type 'string)
54 (defgroup message-various nil
55 "Various Message Variables"
56 :link '(custom-manual "(message)Various Message Variables")
57 :group 'message)
59 (defgroup message-buffers nil
60 "Message Buffers"
61 :link '(custom-manual "(message)Message Buffers")
62 :group 'message)
64 (defgroup message-sending nil
65 "Message Sending"
66 :link '(custom-manual "(message)Sending Variables")
67 :group 'message)
69 (defgroup message-interface nil
70 "Message Interface"
71 :link '(custom-manual "(message)Interface")
72 :group 'message)
74 (defgroup message-forwarding nil
75 "Message Forwarding"
76 :link '(custom-manual "(message)Forwarding")
77 :group 'message-interface)
79 (defgroup message-insertion nil
80 "Message Insertion"
81 :link '(custom-manual "(message)Insertion")
82 :group 'message)
84 (defgroup message-headers nil
85 "Message Headers"
86 :link '(custom-manual "(message)Message Headers")
87 :group 'message)
89 (defgroup message-news nil
90 "Composing News Messages"
91 :group 'message)
93 (defgroup message-mail nil
94 "Composing Mail Messages"
95 :group 'message)
97 (defgroup message-faces nil
98 "Faces used for message composing."
99 :group 'message
100 :group 'faces)
102 (defcustom message-directory "~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group 'message-various
105 :type 'directory)
107 (defcustom message-max-buffers 10
108 "*How many buffers to keep before starting to kill them off."
109 :group 'message-buffers
110 :type 'integer)
112 (defcustom message-send-rename-function nil
113 "Function called to rename the buffer after sending it."
114 :group 'message-buffers
115 :type 'function)
117 (defcustom message-fcc-handler-function 'message-output
118 "*A function called to save outgoing articles.
119 This function will be called with the name of the file to store the
120 article in. The default function is `message-output' which saves in Unix
121 mailbox format."
122 :type '(radio (function-item message-output)
123 (function :tag "Other"))
124 :group 'message-sending)
126 (defcustom message-courtesy-message
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
128 "*This is inserted at the start of a mailed copy of a posted message.
129 If the string contains the format spec \"%s\", the Newsgroups
130 the article has been posted to will be inserted there.
131 If this variable is nil, no such courtesy message will be added."
132 :group 'message-sending
133 :type 'string)
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
136 "*Regexp that matches headers to be removed in resent bounced mail."
137 :group 'message-interface
138 :type 'regexp)
140 ;;;###autoload
141 (defcustom message-from-style 'default
142 "*Specifies how \"From\" headers look.
144 If `nil', they contain just the return address like:
145 king@grassland.com
146 If `parens', they look like:
147 king@grassland.com (Elvis Parsley)
148 If `angles', they look like:
149 Elvis Parsley <king@grassland.com>
151 Otherwise, most addresses look like `angles', but they look like
152 `parens' if `angles' would need quoting and `parens' would not."
153 :type '(choice (const :tag "simple" nil)
154 (const parens)
155 (const angles)
156 (const default))
157 :group 'message-headers)
159 (defcustom message-syntax-checks nil
160 ;; Guess this one shouldn't be easy to customize...
161 "*Controls what syntax checks should not be performed on outgoing posts.
162 To disable checking of long signatures, for instance, add
163 `(signature . disabled)' to this list.
165 Don't touch this variable unless you really know what you're doing.
167 Checks include subject-cmsg multiple-headers sendsys message-id from
168 long-lines control-chars size new-text quoting-style
169 redirected-followup signature approved sender empty empty-headers
170 message-id from subject shorten-followup-to existing-newsgroups
171 buffer-file-name unchanged newsgroups."
172 :group 'message-news
173 :type '(repeat sexp))
175 (defcustom message-required-news-headers
176 '(From Newsgroups Subject Date Message-ID
177 (optional . Organization) Lines
178 (optional . User-Agent))
179 "*Headers to be generated or prompted for when posting an article.
180 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
181 Message-ID. Organization, Lines, In-Reply-To, Expires, and
182 User-Agent are optional. If don't you want message to insert some
183 header, remove it from this list."
184 :group 'message-news
185 :group 'message-headers
186 :type '(repeat sexp))
188 (defcustom message-required-mail-headers
189 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
190 (optional . User-Agent))
191 "*Headers to be generated or prompted for when mailing a message.
192 RFC822 required that From, Date, To, Subject and Message-ID be
193 included. Organization, Lines and User-Agent are optional."
194 :group 'message-mail
195 :group 'message-headers
196 :type '(repeat sexp))
198 (defcustom message-deletable-headers '(Message-ID Date Lines)
199 "Headers to be deleted if they already exist and were generated by message previously."
200 :group 'message-headers
201 :type 'sexp)
203 (defcustom message-ignored-news-headers
204 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
205 "*Regexp of headers to be removed unconditionally before posting."
206 :group 'message-news
207 :group 'message-headers
208 :type 'regexp)
210 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
211 "*Regexp of headers to be removed unconditionally before mailing."
212 :group 'message-mail
213 :group 'message-headers
214 :type 'regexp)
216 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
217 "*Header lines matching this regexp will be deleted before posting.
218 It's best to delete old Path and Date headers before posting to avoid
219 any confusion."
220 :group 'message-interface
221 :type 'regexp)
223 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
224 "*Regexp matching \"Re: \" in the subject line."
225 :group 'message-various
226 :type 'regexp)
228 ;;;###autoload
229 (defcustom message-signature-separator "^-- *$"
230 "Regexp matching the signature separator."
231 :type 'regexp
232 :group 'message-various)
234 (defcustom message-elide-ellipsis "\n[...]\n\n"
235 "*The string which is inserted for elided text."
236 :type 'string
237 :group 'message-various)
239 (defcustom message-interactive nil
240 "Non-nil means when sending a message wait for and display errors.
241 nil means let mailer mail back a message to report errors."
242 :group 'message-sending
243 :group 'message-mail
244 :type 'boolean)
246 (defcustom message-generate-new-buffers 'unique
247 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
248 If this is a function, call that function with three parameters: The type,
249 the to address and the group name. (Any of these may be nil.) The function
250 should return the new buffer name."
251 :group 'message-buffers
252 :type '(choice (const :tag "off" nil)
253 (const :tag "unique" unique)
254 (const :tag "unsent" unsent)
255 (function fun)))
257 (defcustom message-kill-buffer-on-exit nil
258 "*Non-nil means that the message buffer will be killed after sending a message."
259 :group 'message-buffers
260 :type 'boolean)
262 (eval-when-compile
263 (defvar gnus-local-organization))
264 (defcustom message-user-organization
265 (or (and (boundp 'gnus-local-organization)
266 (stringp gnus-local-organization)
267 gnus-local-organization)
268 (getenv "ORGANIZATION")
270 "*String to be used as an Organization header.
271 If t, use `message-user-organization-file'."
272 :group 'message-headers
273 :type '(choice string
274 (const :tag "consult file" t)))
276 ;;;###autoload
277 (defcustom message-user-organization-file "/usr/lib/news/organization"
278 "*Local news organization file."
279 :type 'file
280 :group 'message-headers)
282 (defcustom message-make-forward-subject-function
283 'message-forward-subject-author-subject
284 "*A list of functions that are called to generate a subject header for forwarded messages.
285 The subject generated by the previous function is passed into each
286 successive function.
288 The provided functions are:
290 * message-forward-subject-author-subject (Source of article (author or
291 newsgroup)), in brackets followed by the subject
292 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
293 to it."
294 :group 'message-forwarding
295 :type '(radio (function-item message-forward-subject-author-subject)
296 (function-item message-forward-subject-fwd)))
298 (defcustom message-forward-as-mime t
299 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
300 :version "21.1"
301 :group 'message-forwarding
302 :type 'boolean)
304 (defcustom message-forward-show-mml t
305 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
306 :group 'message-forwarding
307 :type 'boolean)
309 (defcustom message-forward-before-signature t
310 "*If non-nil, put forwarded message before signature, else after."
311 :group 'message-forwarding
312 :type 'boolean)
314 (defcustom message-wash-forwarded-subjects nil
315 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
316 :group 'message-forwarding
317 :type 'boolean)
319 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
320 "*All headers that match this regexp will be deleted when resending a message."
321 :group 'message-interface
322 :type 'regexp)
324 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
325 "*All headers that match this regexp will be deleted when forwarding a message."
326 :version "21.1"
327 :group 'message-forwarding
328 :type '(choice (const :tag "None" nil)
329 regexp))
331 (defcustom message-ignored-cited-headers "."
332 "*Delete these headers from the messages you yank."
333 :group 'message-insertion
334 :type 'regexp)
336 (defcustom message-cancel-message "I am canceling my own article.\n"
337 "Message to be inserted in the cancel message."
338 :group 'message-interface
339 :type 'string)
341 ;; Useful to set in site-init.el
342 ;;;###autoload
343 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
344 "Function to call to send the current buffer as mail.
345 The headers should be delimited by a line whose contents match the
346 variable `mail-header-separator'.
348 Valid values include `message-send-mail-with-sendmail' (the default),
349 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
350 `smtpmail-send-it'."
351 :type '(radio (function-item message-send-mail-with-sendmail)
352 (function-item message-send-mail-with-mh)
353 (function-item message-send-mail-with-qmail)
354 (function-item smtpmail-send-it)
355 (function :tag "Other"))
356 :group 'message-sending
357 :group 'message-mail)
359 (defcustom message-send-news-function 'message-send-news
360 "Function to call to send the current buffer as news.
361 The headers should be delimited by a line whose contents match the
362 variable `mail-header-separator'."
363 :group 'message-sending
364 :group 'message-news
365 :type 'function)
367 (defcustom message-reply-to-function nil
368 "Function that should return a list of headers.
369 This function should pick out addresses from the To, Cc, and From headers
370 and respond with new To and Cc headers."
371 :group 'message-interface
372 :type 'function)
374 (defcustom message-wide-reply-to-function nil
375 "Function that should return a list of headers.
376 This function should pick out addresses from the To, Cc, and From headers
377 and respond with new To and Cc headers."
378 :group 'message-interface
379 :type 'function)
381 (defcustom message-followup-to-function nil
382 "Function that should return a list of headers.
383 This function should pick out addresses from the To, Cc, and From headers
384 and respond with new To and Cc headers."
385 :group 'message-interface
386 :type 'function)
388 (defcustom message-use-followup-to 'ask
389 "*Specifies what to do with Followup-To header.
390 If nil, always ignore the header. If it is t, use its value, but
391 query before using the \"poster\" value. If it is the symbol `ask',
392 always query the user whether to use the value. If it is the symbol
393 `use', always use the value."
394 :group 'message-interface
395 :type '(choice (const :tag "ignore" nil)
396 (const use)
397 (const ask)))
399 (defcustom message-sendmail-f-is-evil nil
400 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
401 Doing so would be even more evil than leaving it out."
402 :group 'message-sending
403 :type 'boolean)
405 ;; qmail-related stuff
406 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
407 "Location of the qmail-inject program."
408 :group 'message-sending
409 :type 'file)
411 (defcustom message-qmail-inject-args nil
412 "Arguments passed to qmail-inject programs.
413 This should be a list of strings, one string for each argument.
415 For e.g., if you wish to set the envelope sender address so that bounces
416 go to the right place or to deal with listserv's usage of that address, you
417 might set this variable to '(\"-f\" \"you@some.where\")."
418 :group 'message-sending
419 :type '(repeat string))
421 (defvar message-cater-to-broken-inn t
422 "Non-nil means Gnus should not fold the `References' header.
423 Folding `References' makes ancient versions of INN create incorrect
424 NOV lines.")
426 (eval-when-compile
427 (defvar gnus-post-method)
428 (defvar gnus-select-method))
429 (defcustom message-post-method
430 (cond ((and (boundp 'gnus-post-method)
431 (listp gnus-post-method)
432 gnus-post-method)
433 gnus-post-method)
434 ((boundp 'gnus-select-method)
435 gnus-select-method)
436 (t '(nnspool "")))
437 "*Method used to post news.
438 Note that when posting from inside Gnus, for instance, this
439 variable isn't used."
440 :group 'message-news
441 :group 'message-sending
442 ;; This should be the `gnus-select-method' widget, but that might
443 ;; create a dependence to `gnus.el'.
444 :type 'sexp)
446 (defcustom message-generate-headers-first nil
447 "*If non-nil, generate all possible headers before composing."
448 :group 'message-headers
449 :type 'boolean)
451 (defcustom message-setup-hook nil
452 "Normal hook, run each time a new outgoing message is initialized.
453 The function `message-setup' runs this hook."
454 :group 'message-various
455 :type 'hook)
457 (defcustom message-cancel-hook nil
458 "Hook run when cancelling articles."
459 :group 'message-various
460 :type 'hook)
462 (defcustom message-signature-setup-hook nil
463 "Normal hook, run each time a new outgoing message is initialized.
464 It is run after the headers have been inserted and before
465 the signature is inserted."
466 :group 'message-various
467 :type 'hook)
469 (defcustom message-mode-hook nil
470 "Hook run in message mode buffers."
471 :group 'message-various
472 :type 'hook)
474 (defcustom message-header-hook nil
475 "Hook run in a message mode buffer narrowed to the headers."
476 :group 'message-various
477 :type 'hook)
479 (defcustom message-header-setup-hook nil
480 "Hook called narrowed to the headers when setting up a message buffer."
481 :group 'message-various
482 :type 'hook)
484 ;;;###autoload
485 (defcustom message-citation-line-function 'message-insert-citation-line
486 "*Function called to insert the \"Whomever writes:\" line."
487 :type 'function
488 :group 'message-insertion)
490 ;;;###autoload
491 (defcustom message-yank-prefix "> "
492 "*Prefix inserted on the lines of yanked messages."
493 :type 'string
494 :group 'message-insertion)
496 (defcustom message-indentation-spaces 3
497 "*Number of spaces to insert at the beginning of each cited line.
498 Used by `message-yank-original' via `message-yank-cite'."
499 :group 'message-insertion
500 :type 'integer)
502 ;;;###autoload
503 (defcustom message-cite-function 'message-cite-original
504 "*Function for citing an original message.
505 Predefined functions include `message-cite-original' and
506 `message-cite-original-without-signature'.
507 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
508 :type '(radio (function-item message-cite-original)
509 (function-item message-cite-original-without-signature)
510 (function-item sc-cite-original)
511 (function :tag "Other"))
512 :group 'message-insertion)
514 ;;;###autoload
515 (defcustom message-indent-citation-function 'message-indent-citation
516 "*Function for modifying a citation just inserted in the mail buffer.
517 This can also be a list of functions. Each function can find the
518 citation between (point) and (mark t). And each function should leave
519 point and mark around the citation text as modified."
520 :type 'function
521 :group 'message-insertion)
523 (defvar message-abbrevs-loaded nil)
525 ;;;###autoload
526 (defcustom message-signature t
527 "*String to be inserted at the end of the message buffer.
528 If t, the `message-signature-file' file will be inserted instead.
529 If a function, the result from the function will be used instead.
530 If a form, the result from the form will be used instead."
531 :type 'sexp
532 :group 'message-insertion)
534 ;;;###autoload
535 (defcustom message-signature-file "~/.signature"
536 "*File containing the text inserted at end of message buffer."
537 :type 'file
538 :group 'message-insertion)
540 (defcustom message-distribution-function nil
541 "*Function called to return a Distribution header."
542 :group 'message-news
543 :group 'message-headers
544 :type 'function)
546 (defcustom message-expires 14
547 "Number of days before your article expires."
548 :group 'message-news
549 :group 'message-headers
550 :link '(custom-manual "(message)News Headers")
551 :type 'integer)
553 (defcustom message-user-path nil
554 "If nil, use the NNTP server name in the Path header.
555 If stringp, use this; if non-nil, use no host name (user name only)."
556 :group 'message-news
557 :group 'message-headers
558 :link '(custom-manual "(message)News Headers")
559 :type '(choice (const :tag "nntp" nil)
560 (string :tag "name")
561 (sexp :tag "none" :format "%t" t)))
563 (defvar message-reply-buffer nil)
564 (defvar message-reply-headers nil)
565 (defvar message-newsreader nil)
566 (defvar message-mailer nil)
567 (defvar message-sent-message-via nil)
568 (defvar message-checksum nil)
569 (defvar message-send-actions nil
570 "A list of actions to be performed upon successful sending of a message.")
571 (defvar message-exit-actions nil
572 "A list of actions to be performed upon exiting after sending a message.")
573 (defvar message-kill-actions nil
574 "A list of actions to be performed before killing a message buffer.")
575 (defvar message-postpone-actions nil
576 "A list of actions to be performed after postponing a message.")
578 (define-widget 'message-header-lines 'text
579 "All header lines must be LFD terminated."
580 :format "%t:%n%v"
581 :valid-regexp "^\\'"
582 :error "All header lines must be newline terminated")
584 (defcustom message-default-headers ""
585 "*A string containing header lines to be inserted in outgoing messages.
586 It is inserted before you edit the message, so you can edit or delete
587 these lines."
588 :group 'message-headers
589 :type 'message-header-lines)
591 (defcustom message-default-mail-headers ""
592 "*A string of header lines to be inserted in outgoing mails."
593 :group 'message-headers
594 :group 'message-mail
595 :type 'message-header-lines)
597 (defcustom message-default-news-headers ""
598 "*A string of header lines to be inserted in outgoing news articles."
599 :group 'message-headers
600 :group 'message-news
601 :type 'message-header-lines)
603 ;; Note: could use /usr/ucb/mail instead of sendmail;
604 ;; options -t, and -v if not interactive.
605 (defcustom message-mailer-swallows-blank-line
606 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
607 system-configuration)
608 (file-readable-p "/etc/sendmail.cf")
609 (let ((buffer (get-buffer-create " *temp*")))
610 (unwind-protect
611 (save-excursion
612 (set-buffer buffer)
613 (insert-file-contents "/etc/sendmail.cf")
614 (goto-char (point-min))
615 (let ((case-fold-search nil))
616 (re-search-forward "^OR\\>" nil t)))
617 (kill-buffer buffer))))
618 ;; According to RFC822, "The field-name must be composed of printable
619 ;; ASCII characters (i. e., characters that have decimal values between
620 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
621 ;; space, or colon.
622 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
623 "*Set this non-nil if the system's mailer runs the header and body together.
624 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
625 The value should be an expression to test whether the problem will
626 actually occur."
627 :group 'message-sending
628 :type 'sexp)
630 ;;;###autoload
631 (define-mail-user-agent 'message-user-agent
632 'message-mail 'message-send-and-exit
633 'message-kill-buffer 'message-send-hook)
635 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
636 "If non-nil, delete the deletable headers before feeding to mh.")
638 (defvar message-send-method-alist
639 '((news message-news-p message-send-via-news)
640 (mail message-mail-p message-send-via-mail))
641 "Alist of ways to send outgoing messages.
642 Each element has the form
644 \(TYPE PREDICATE FUNCTION)
646 where TYPE is a symbol that names the method; PREDICATE is a function
647 called without any parameters to determine whether the message is
648 a message of type TYPE; and FUNCTION is a function to be called if
649 PREDICATE returns non-nil. FUNCTION is called with one parameter --
650 the prefix.")
652 (defvar message-mail-alias-type 'abbrev
653 "*What alias expansion type to use in Message buffers.
654 The default is `abbrev', which uses mailabbrev. nil switches
655 mail aliases off.")
657 (defcustom message-auto-save-directory
658 (nnheader-concat message-directory "drafts/")
659 "*Directory where Message auto-saves buffers if Gnus isn't running.
660 If nil, Message won't auto-save."
661 :group 'message-buffers
662 :type 'directory)
664 (defcustom message-buffer-naming-style 'unique
665 "*The way new message buffers are named.
666 Valid valued are `unique' and `unsent'."
667 :version "21.1"
668 :group 'message-buffers
669 :type '(choice (const :tag "unique" unique)
670 (const :tag "unsent" unsent)))
672 (defcustom message-default-charset
673 (and (not (mm-multibyte-p)) 'iso-8859-1)
674 "Default charset used in non-MULE Emacsen.
675 If nil, you might be asked to input the charset."
676 :version "21.1"
677 :group 'message
678 :type 'symbol)
680 (defcustom message-dont-reply-to-names
681 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
682 "*A regexp specifying names to prune when doing wide replies.
683 A value of nil means exclude your own name only."
684 :version "21.1"
685 :group 'message
686 :type '(choice (const :tag "Yourself" nil)
687 regexp))
689 ;;; Internal variables.
690 ;;; Well, not really internal.
692 (defvar message-mode-syntax-table
693 (let ((table (copy-syntax-table text-mode-syntax-table)))
694 (modify-syntax-entry ?% ". " table)
695 (modify-syntax-entry ?> ". " table)
696 (modify-syntax-entry ?< ". " table)
697 table)
698 "Syntax table used while in Message mode.")
700 (defvar message-mode-abbrev-table text-mode-abbrev-table
701 "Abbrev table used in Message mode buffers.
702 Defaults to `text-mode-abbrev-table'.")
703 (defgroup message-headers nil
704 "Message headers."
705 :link '(custom-manual "(message)Variables")
706 :group 'message)
708 (defface message-header-to-face
709 '((((class color)
710 (background dark))
711 (:foreground "green2" :bold t))
712 (((class color)
713 (background light))
714 (:foreground "MidnightBlue" :bold t))
716 (:bold t :italic t)))
717 "Face used for displaying From headers."
718 :group 'message-faces)
720 (defface message-header-cc-face
721 '((((class color)
722 (background dark))
723 (:foreground "green4" :bold t))
724 (((class color)
725 (background light))
726 (:foreground "MidnightBlue"))
728 (:bold t)))
729 "Face used for displaying Cc headers."
730 :group 'message-faces)
732 (defface message-header-subject-face
733 '((((class color)
734 (background dark))
735 (:foreground "green3"))
736 (((class color)
737 (background light))
738 (:foreground "navy blue" :bold t))
740 (:bold t)))
741 "Face used for displaying subject headers."
742 :group 'message-faces)
744 (defface message-header-newsgroups-face
745 '((((class color)
746 (background dark))
747 (:foreground "yellow" :bold t :italic t))
748 (((class color)
749 (background light))
750 (:foreground "blue4" :bold t :italic t))
752 (:bold t :italic t)))
753 "Face used for displaying newsgroups headers."
754 :group 'message-faces)
756 (defface message-header-other-face
757 '((((class color)
758 (background dark))
759 (:foreground "#b00000"))
760 (((class color)
761 (background light))
762 (:foreground "steel blue"))
764 (:bold t :italic t)))
765 "Face used for displaying newsgroups headers."
766 :group 'message-faces)
768 (defface message-header-name-face
769 '((((class color)
770 (background dark))
771 (:foreground "DarkGreen"))
772 (((class color)
773 (background light))
774 (:foreground "cornflower blue"))
776 (:bold t)))
777 "Face used for displaying header names."
778 :group 'message-faces)
780 (defface message-header-xheader-face
781 '((((class color)
782 (background dark))
783 (:foreground "blue"))
784 (((class color)
785 (background light))
786 (:foreground "blue"))
788 (:bold t)))
789 "Face used for displaying X-Header headers."
790 :group 'message-faces)
792 (defface message-separator-face
793 '((((class color)
794 (background dark))
795 (:foreground "blue3"))
796 (((class color)
797 (background light))
798 (:foreground "brown"))
800 (:bold t)))
801 "Face used for displaying the separator."
802 :group 'message-faces)
804 (defface message-cited-text-face
805 '((((class color)
806 (background dark))
807 (:foreground "red"))
808 (((class color)
809 (background light))
810 (:foreground "red"))
812 (:bold t)))
813 "Face used for displaying cited text names."
814 :group 'message-faces)
816 (defface message-mml-face
817 '((((class color)
818 (background dark))
819 (:foreground "ForestGreen"))
820 (((class color)
821 (background light))
822 (:foreground "ForestGreen"))
824 (:bold t)))
825 "Face used for displaying MML."
826 :group 'message-faces)
828 (defvar message-font-lock-keywords
829 (let* ((cite-prefix "[:alpha:]")
830 (cite-suffix (concat cite-prefix "0-9_.@-"))
831 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
832 `((,(concat "^\\([Tt]o:\\)" content)
833 (1 'message-header-name-face)
834 (2 'message-header-to-face nil t))
835 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
836 (1 'message-header-name-face)
837 (2 'message-header-cc-face nil t))
838 (,(concat "^\\([Ss]ubject:\\)" content)
839 (1 'message-header-name-face)
840 (2 'message-header-subject-face nil t))
841 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
842 (1 'message-header-name-face)
843 (2 'message-header-newsgroups-face nil t))
844 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
845 (1 'message-header-name-face)
846 (2 'message-header-other-face nil t))
847 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
848 (1 'message-header-name-face)
849 (2 'message-header-name-face))
850 ,@(if (and mail-header-separator
851 (not (equal mail-header-separator "")))
852 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
853 1 'message-separator-face))
854 nil)
855 (,(concat "^[ \t]*"
856 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
857 "[:>|}].*")
858 (0 'message-cited-text-face))
859 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
860 (0 'message-mml-face))))
861 "Additional expressions to highlight in Message mode.")
863 ;; XEmacs does it like this. For Emacs, we have to set the
864 ;; `font-lock-defaults' buffer-local variable.
865 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
867 (defvar message-face-alist
868 '((bold . bold-region)
869 (underline . underline-region)
870 (default . (lambda (b e)
871 (unbold-region b e)
872 (ununderline-region b e))))
873 "Alist of mail and news faces for facemenu.
874 The cdr of ech entry is a function for applying the face to a region.")
876 (defcustom message-send-hook nil
877 "Hook run before sending messages."
878 :group 'message-various
879 :options '(ispell-message)
880 :type 'hook)
882 (defcustom message-send-mail-hook nil
883 "Hook run before sending mail messages."
884 :group 'message-various
885 :type 'hook)
887 (defcustom message-send-news-hook nil
888 "Hook run before sending news messages."
889 :group 'message-various
890 :type 'hook)
892 (defcustom message-sent-hook nil
893 "Hook run after sending messages."
894 :group 'message-various
895 :type 'hook)
897 (defvar message-send-coding-system 'binary
898 "Coding system to encode outgoing mail.")
900 (defvar message-draft-coding-system
901 mm-auto-save-coding-system
902 "Coding system to compose mail.")
904 (defcustom message-send-mail-partially-limit 1000000
905 "The limitation of messages sent as message/partial.
906 The lower bound of message size in characters, beyond which the message
907 should be sent in several parts. If it is nil, the size is unlimited."
908 :version "21.1"
909 :group 'message-buffers
910 :type '(choice (const :tag "unlimited" nil)
911 (integer 1000000)))
913 (defcustom message-alternative-emails nil
914 "A regexp to match the alternative email addresses.
915 The first matched address (not primary one) is used in the From field."
916 :group 'message-headers
917 :type '(choice (const :tag "Always use primary" nil)
918 regexp))
920 ;;; Internal variables.
922 (defvar message-sending-message "Sending...")
923 (defvar message-buffer-list nil)
924 (defvar message-this-is-news nil)
925 (defvar message-this-is-mail nil)
926 (defvar message-draft-article nil)
927 (defvar message-mime-part nil)
928 (defvar message-posting-charset nil)
930 ;; Byte-compiler warning
931 (eval-when-compile
932 (defvar gnus-active-hashtb)
933 (defvar gnus-read-active-file))
935 ;;; Regexp matching the delimiter of messages in UNIX mail format
936 ;;; (UNIX From lines), minus the initial ^. It should be a copy
937 ;;; of rmail.el's rmail-unix-mail-delimiter.
938 (defvar message-unix-mail-delimiter
939 (let ((time-zone-regexp
940 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
941 "\\|[-+]?[0-9][0-9][0-9][0-9]"
942 "\\|"
943 "\\) *")))
944 (concat
945 "From "
947 ;; Many things can happen to an RFC 822 mailbox before it is put into
948 ;; a `From' line. The leading phrase can be stripped, e.g.
949 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
950 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
951 ;; can be removed, e.g.
952 ;; From: joe@y.z (Joe K
953 ;; User)
954 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
955 ;; From: Joe User
956 ;; <joe@y.z>
957 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
958 ;; The mailbox can be removed or be replaced by white space, e.g.
959 ;; From: "Joe User"{space}{tab}
960 ;; <joe@y.z>
961 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
962 ;; where {space} and {tab} represent the Ascii space and tab characters.
963 ;; We want to match the results of any of these manglings.
964 ;; The following regexp rejects names whose first characters are
965 ;; obviously bogus, but after that anything goes.
966 "\\([^\0-\b\n-\r\^?].*\\)? "
968 ;; The time the message was sent.
969 "\\([^\0-\r \^?]+\\) +" ; day of the week
970 "\\([^\0-\r \^?]+\\) +" ; month
971 "\\([0-3]?[0-9]\\) +" ; day of month
972 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
974 ;; Perhaps a time zone, specified by an abbreviation, or by a
975 ;; numeric offset.
976 time-zone-regexp
978 ;; The year.
979 " \\([0-9][0-9]+\\) *"
981 ;; On some systems the time zone can appear after the year, too.
982 time-zone-regexp
984 ;; Old uucp cruft.
985 "\\(remote from .*\\)?"
987 "\n"))
988 "Regexp matching the delimiter of messages in UNIX mail format.")
990 (defvar message-unsent-separator
991 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
992 "^ *---+ +Returned message +---+ *$\\|"
993 "^Start of returned message$\\|"
994 "^ *---+ +Original message +---+ *$\\|"
995 "^ *--+ +begin message +--+ *$\\|"
996 "^ *---+ +Original message follows +---+ *$\\|"
997 "^ *---+ +Undelivered message follows +---+ *$\\|"
998 "^|? *---+ +Message text follows: +---+ *|?$")
999 "A regexp that matches the separator before the text of a failed message.")
1001 (defvar message-header-format-alist
1002 `((Newsgroups)
1003 (To . message-fill-address)
1004 (Cc . message-fill-address)
1005 (Subject)
1006 (In-Reply-To)
1007 (Fcc)
1008 (Bcc)
1009 (Date)
1010 (Organization)
1011 (Distribution)
1012 (Lines)
1013 (Expires)
1014 (Message-ID)
1015 (References . message-shorten-references)
1016 (User-Agent))
1017 "Alist used for formatting headers.")
1019 (eval-and-compile
1020 (autoload 'message-setup-toolbar "messagexmas")
1021 (autoload 'mh-new-draft-name "mh-comp")
1022 (autoload 'mh-send-letter "mh-comp")
1023 (autoload 'gnus-point-at-eol "gnus-util")
1024 (autoload 'gnus-point-at-bol "gnus-util")
1025 (autoload 'gnus-output-to-rmail "gnus-util")
1026 (autoload 'gnus-output-to-mail "gnus-util")
1027 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1028 (autoload 'nndraft-request-associate-buffer "nndraft")
1029 (autoload 'nndraft-request-expire-articles "nndraft")
1030 (autoload 'gnus-open-server "gnus-int")
1031 (autoload 'gnus-request-post "gnus-int")
1032 (autoload 'gnus-alive-p "gnus-util")
1033 (autoload 'gnus-group-name-charset "gnus-group")
1034 (autoload 'rmail-output "rmail"))
1039 ;;; Utility functions.
1042 (defmacro message-y-or-n-p (question show &rest text)
1043 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1044 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1046 ;; Delete the current line (and the next N lines.);
1047 (defmacro message-delete-line (&optional n)
1048 `(delete-region (progn (beginning-of-line) (point))
1049 (progn (forward-line ,(or n 1)) (point))))
1051 (defun message-unquote-tokens (elems)
1052 "Remove double quotes (\") from strings in list."
1053 (mapcar (lambda (item)
1054 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1055 (setq item (concat (match-string 1 item)
1056 (match-string 2 item))))
1057 item)
1058 elems))
1060 (defun message-tokenize-header (header &optional separator)
1061 "Split HEADER into a list of header elements.
1062 SEPARATOR is a string of characters to be used as separators. \",\"
1063 is used by default."
1064 (if (not header)
1066 (let ((regexp (format "[%s]+" (or separator ",")))
1067 (beg 1)
1068 (first t)
1069 quoted elems paren)
1070 (save-excursion
1071 (message-set-work-buffer)
1072 (insert header)
1073 (goto-char (point-min))
1074 (while (not (eobp))
1075 (if first
1076 (setq first nil)
1077 (forward-char 1))
1078 (cond ((and (> (point) beg)
1079 (or (eobp)
1080 (and (looking-at regexp)
1081 (not quoted)
1082 (not paren))))
1083 (push (buffer-substring beg (point)) elems)
1084 (setq beg (match-end 0)))
1085 ((eq (char-after) ?\")
1086 (setq quoted (not quoted)))
1087 ((and (eq (char-after) ?\()
1088 (not quoted))
1089 (setq paren t))
1090 ((and (eq (char-after) ?\))
1091 (not quoted))
1092 (setq paren nil))))
1093 (nreverse elems)))))
1095 (defun message-mail-file-mbox-p (file)
1096 "Say whether FILE looks like a Unix mbox file."
1097 (when (and (file-exists-p file)
1098 (file-readable-p file)
1099 (file-regular-p file))
1100 (with-temp-buffer
1101 (nnheader-insert-file-contents file)
1102 (goto-char (point-min))
1103 (looking-at message-unix-mail-delimiter))))
1105 (defun message-fetch-field (header &optional not-all)
1106 "The same as `mail-fetch-field', only remove all newlines."
1107 (let* ((inhibit-point-motion-hooks t)
1108 (case-fold-search t)
1109 (value (mail-fetch-field header nil (not not-all))))
1110 (when value
1111 (while (string-match "\n[\t ]+" value)
1112 (setq value (replace-match " " t t value)))
1113 (set-text-properties 0 (length value) nil value)
1114 value)))
1116 (defun message-narrow-to-field ()
1117 "Narrow the buffer to the header on the current line."
1118 (beginning-of-line)
1119 (narrow-to-region
1120 (point)
1121 (progn
1122 (forward-line 1)
1123 (if (re-search-forward "^[^ \n\t]" nil t)
1124 (progn
1125 (beginning-of-line)
1126 (point))
1127 (point-max))))
1128 (goto-char (point-min)))
1130 (defun message-add-header (&rest headers)
1131 "Add the HEADERS to the message header, skipping those already present."
1132 (while headers
1133 (let (hclean)
1134 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1135 (error "Invalid header `%s'" (car headers)))
1136 (setq hclean (match-string 1 (car headers)))
1137 (save-restriction
1138 (message-narrow-to-headers)
1139 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1140 (insert (car headers) ?\n))))
1141 (setq headers (cdr headers))))
1144 (defun message-fetch-reply-field (header)
1145 "Fetch FIELD from the message we're replying to."
1146 (when (and message-reply-buffer
1147 (buffer-name message-reply-buffer))
1148 (save-excursion
1149 (set-buffer message-reply-buffer)
1150 (message-fetch-field header))))
1152 (defun message-set-work-buffer ()
1153 (if (get-buffer " *message work*")
1154 (progn
1155 (set-buffer " *message work*")
1156 (erase-buffer))
1157 (set-buffer (get-buffer-create " *message work*"))
1158 (kill-all-local-variables)
1159 (mm-enable-multibyte)))
1161 (defun message-functionp (form)
1162 "Return non-nil if FORM is funcallable."
1163 (or (and (symbolp form) (fboundp form))
1164 (and (listp form) (eq (car form) 'lambda))
1165 (byte-code-function-p form)))
1167 (defun message-strip-list-identifiers (subject)
1168 "Remove list identifiers in `gnus-list-identifiers'."
1169 (require 'gnus-sum) ; for gnus-list-identifiers
1170 (let ((regexp (if (stringp gnus-list-identifiers)
1171 gnus-list-identifiers
1172 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1173 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1174 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1175 (concat (substring subject 0 (match-beginning 1))
1176 (or (match-string 3 subject)
1177 (match-string 5 subject))
1178 (substring subject
1179 (match-end 1)))
1180 subject)))
1182 (defun message-strip-subject-re (subject)
1183 "Remove \"Re:\" from subject lines."
1184 (if (string-match message-subject-re-regexp subject)
1185 (substring subject (match-end 0))
1186 subject))
1188 (defun message-remove-header (header &optional is-regexp first reverse)
1189 "Remove HEADER in the narrowed buffer.
1190 If REGEXP, HEADER is a regular expression.
1191 If FIRST, only remove the first instance of the header.
1192 Return the number of headers removed."
1193 (goto-char (point-min))
1194 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1195 (number 0)
1196 (case-fold-search t)
1197 last)
1198 (while (and (not (eobp))
1199 (not last))
1200 (if (if reverse
1201 (not (looking-at regexp))
1202 (looking-at regexp))
1203 (progn
1204 (incf number)
1205 (when first
1206 (setq last t))
1207 (delete-region
1208 (point)
1209 ;; There might be a continuation header, so we have to search
1210 ;; until we find a new non-continuation line.
1211 (progn
1212 (forward-line 1)
1213 (if (re-search-forward "^[^ \t]" nil t)
1214 (goto-char (match-beginning 0))
1215 (point-max)))))
1216 (forward-line 1)
1217 (if (re-search-forward "^[^ \t]" nil t)
1218 (goto-char (match-beginning 0))
1219 (goto-char (point-max)))))
1220 number))
1222 (defun message-remove-first-header (header)
1223 "Remove the first instance of HEADER if there is more than one."
1224 (let ((count 0)
1225 (regexp (concat "^" (regexp-quote header) ":")))
1226 (save-excursion
1227 (goto-char (point-min))
1228 (while (re-search-forward regexp nil t)
1229 (incf count)))
1230 (while (> count 1)
1231 (message-remove-header header nil t)
1232 (decf count))))
1234 (defun message-narrow-to-headers ()
1235 "Narrow the buffer to the head of the message."
1236 (widen)
1237 (narrow-to-region
1238 (goto-char (point-min))
1239 (if (re-search-forward
1240 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1241 (match-beginning 0)
1242 (point-max)))
1243 (goto-char (point-min)))
1245 (defun message-narrow-to-head ()
1246 "Narrow the buffer to the head of the message.
1247 Point is left at the beginning of the narrowed-to region."
1248 (widen)
1249 (narrow-to-region
1250 (goto-char (point-min))
1251 (if (search-forward "\n\n" nil 1)
1252 (1- (point))
1253 (point-max)))
1254 (goto-char (point-min)))
1256 (defun message-narrow-to-headers-or-head ()
1257 "Narrow the buffer to the head of the message."
1258 (widen)
1259 (narrow-to-region
1260 (goto-char (point-min))
1261 (cond
1262 ((re-search-forward
1263 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1264 (match-beginning 0))
1265 ((search-forward "\n\n" nil t)
1266 (1- (point)))
1268 (point-max))))
1269 (goto-char (point-min)))
1271 (defun message-news-p ()
1272 "Say whether the current buffer contains a news message."
1273 (and (not message-this-is-mail)
1274 (or message-this-is-news
1275 (save-excursion
1276 (save-restriction
1277 (message-narrow-to-headers)
1278 (and (message-fetch-field "newsgroups")
1279 (not (message-fetch-field "posted-to"))))))))
1281 (defun message-mail-p ()
1282 "Say whether the current buffer contains a mail message."
1283 (and (not message-this-is-news)
1284 (or message-this-is-mail
1285 (save-excursion
1286 (save-restriction
1287 (message-narrow-to-headers)
1288 (or (message-fetch-field "to")
1289 (message-fetch-field "cc")
1290 (message-fetch-field "bcc")))))))
1292 (defun message-next-header ()
1293 "Go to the beginning of the next header."
1294 (beginning-of-line)
1295 (or (eobp) (forward-char 1))
1296 (not (if (re-search-forward "^[^ \t]" nil t)
1297 (beginning-of-line)
1298 (goto-char (point-max)))))
1300 (defun message-sort-headers-1 ()
1301 "Sort the buffer as headers using `message-rank' text props."
1302 (goto-char (point-min))
1303 (require 'sort)
1304 (sort-subr
1305 nil 'message-next-header
1306 (lambda ()
1307 (message-next-header)
1308 (unless (bobp)
1309 (forward-char -1)))
1310 (lambda ()
1311 (or (get-text-property (point) 'message-rank)
1312 10000))))
1314 (defun message-sort-headers ()
1315 "Sort the headers of the current message according to `message-header-format-alist'."
1316 (interactive)
1317 (save-excursion
1318 (save-restriction
1319 (let ((max (1+ (length message-header-format-alist)))
1320 rank)
1321 (message-narrow-to-headers)
1322 (while (re-search-forward "^[^ \n]+:" nil t)
1323 (put-text-property
1324 (match-beginning 0) (1+ (match-beginning 0))
1325 'message-rank
1326 (if (setq rank (length (memq (assq (intern (buffer-substring
1327 (match-beginning 0)
1328 (1- (match-end 0))))
1329 message-header-format-alist)
1330 message-header-format-alist)))
1331 (- max rank)
1332 (1+ max)))))
1333 (message-sort-headers-1))))
1338 ;;; Message mode
1341 ;;; Set up keymap.
1343 (defvar message-mode-map nil)
1345 (unless message-mode-map
1346 (setq message-mode-map (make-keymap))
1347 (set-keymap-parent message-mode-map text-mode-map)
1348 (define-key message-mode-map "\C-c?" 'describe-mode)
1350 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1351 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1352 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1353 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1354 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1355 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1356 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1357 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1358 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1359 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1360 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1361 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1362 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1364 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1365 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1367 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1368 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1369 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1370 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1371 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1372 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1373 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1374 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1376 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1377 (define-key message-mode-map "\C-c\C-s" 'message-send)
1378 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1379 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1381 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1382 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1383 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1384 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1386 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1388 (define-key message-mode-map "\t" 'message-tab))
1390 (easy-menu-define
1391 message-mode-menu message-mode-map "Message Menu."
1392 '("Message"
1393 ["Sort Headers" message-sort-headers t]
1394 ["Yank Original" message-yank-original t]
1395 ["Fill Yanked Message" message-fill-yanked-message t]
1396 ["Insert Signature" message-insert-signature t]
1397 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1398 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1399 ["Elide Region" message-elide-region (mark t)]
1400 ["Delete Outside Region" message-delete-not-region (mark t)]
1401 ["Kill To Signature" message-kill-to-signature t]
1402 ["Newline and Reformat" message-newline-and-reformat t]
1403 ["Rename buffer" message-rename-buffer t]
1404 ["Spellcheck" ispell-message
1405 :help "Spellcheck this message"]
1406 ["Attach file as MIME" mml-attach-file
1407 :help "Attach a file at point"]
1408 "----"
1409 ["Send Message" message-send-and-exit
1410 :help "Send this message"]
1411 ["Abort Message" message-dont-send
1412 :help "File this draft message and exit"]
1413 ["Kill Message" message-kill-buffer
1414 :help "Delete this message without sending"]))
1416 (easy-menu-define
1417 message-mode-field-menu message-mode-map ""
1418 '("Field"
1419 ["Fetch To" message-insert-to t]
1420 ["Fetch Newsgroups" message-insert-newsgroups t]
1421 "----"
1422 ["To" message-goto-to t]
1423 ["Subject" message-goto-subject t]
1424 ["Cc" message-goto-cc t]
1425 ["Reply-To" message-goto-reply-to t]
1426 ["Summary" message-goto-summary t]
1427 ["Keywords" message-goto-keywords t]
1428 ["Newsgroups" message-goto-newsgroups t]
1429 ["Followup-To" message-goto-followup-to t]
1430 ["Distribution" message-goto-distribution t]
1431 ["Body" message-goto-body t]
1432 ["Signature" message-goto-signature t]))
1434 (eval-when-compile
1435 (defvar facemenu-add-face-function)
1436 (defvar facemenu-remove-face-function))
1438 ;;;###autoload
1439 (defun message-mode ()
1440 "Major mode for editing mail and news to be sent.
1441 Like Text Mode but with these additional commands:
1442 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1443 C-c C-d Pospone sending the message C-c C-k Kill the message
1444 C-c C-f move to a header field (and create it if there isn't):
1445 C-c C-f C-t move to To C-c C-f C-s move to Subject
1446 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1447 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1448 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1449 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1450 C-c C-f C-f move to Followup-To
1451 C-c C-t message-insert-to (add a To header to a news followup)
1452 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1453 C-c C-b message-goto-body (move to beginning of message text).
1454 C-c C-i message-goto-signature (move to the beginning of the signature).
1455 C-c C-w message-insert-signature (insert `message-signature-file' file).
1456 C-c C-y message-yank-original (insert current message, if any).
1457 C-c C-q message-fill-yanked-message (fill what was yanked).
1458 C-c C-e message-elide-region (elide the text between point and mark).
1459 C-c C-v message-delete-not-region (remove the text outside the region).
1460 C-c C-z message-kill-to-signature (kill the text up to the signature).
1461 C-c C-r message-caesar-buffer-body (rot13 the message body).
1462 C-c C-a mml-attach-file (attach a file as MIME).
1463 M-RET message-newline-and-reformat (break the line and reformat)."
1464 (interactive)
1465 (if (local-variable-p 'mml-buffer-list (current-buffer))
1466 (mml-destroy-buffers))
1467 (kill-all-local-variables)
1468 (set (make-local-variable 'message-reply-buffer) nil)
1469 (make-local-variable 'message-send-actions)
1470 (make-local-variable 'message-exit-actions)
1471 (make-local-variable 'message-kill-actions)
1472 (make-local-variable 'message-postpone-actions)
1473 (make-local-variable 'message-draft-article)
1474 (make-local-hook 'kill-buffer-hook)
1475 (set-syntax-table message-mode-syntax-table)
1476 (use-local-map message-mode-map)
1477 (setq local-abbrev-table message-mode-abbrev-table)
1478 (setq major-mode 'message-mode)
1479 (setq mode-name "Message")
1480 (setq buffer-offer-save t)
1481 (make-local-variable 'facemenu-add-face-function)
1482 (make-local-variable 'facemenu-remove-face-function)
1483 (setq facemenu-add-face-function
1484 (lambda (face end)
1485 (let ((face-fun (cdr (assq face message-face-alist))))
1486 (if face-fun
1487 (funcall face-fun (point) end)
1488 (error "Face %s not configured for %s mode" face mode-name)))
1490 facemenu-remove-face-function t)
1491 (make-local-variable 'message-reply-headers)
1492 (setq message-reply-headers nil)
1493 (make-local-variable 'message-newsreader)
1494 (make-local-variable 'message-mailer)
1495 (make-local-variable 'message-post-method)
1496 (set (make-local-variable 'message-sent-message-via) nil)
1497 (set (make-local-variable 'message-checksum) nil)
1498 (set (make-local-variable 'message-mime-part) 0)
1499 (message-setup-fill-variables)
1500 ;;(when (fboundp 'mail-hist-define-keys)
1501 ;; (mail-hist-define-keys))
1502 (if (featurep 'xemacs)
1503 (message-setup-toolbar)
1504 (set (make-local-variable 'font-lock-defaults)
1505 '(message-font-lock-keywords t))
1506 (if (boundp 'message-tool-bar-map)
1507 (set (make-local-variable 'tool-bar-map) message-tool-bar-map)))
1508 (easy-menu-add message-mode-menu message-mode-map)
1509 (easy-menu-add message-mode-field-menu message-mode-map)
1510 ;; Allow mail alias things.
1511 (when (eq message-mail-alias-type 'abbrev)
1512 (if (fboundp 'mail-abbrevs-setup)
1513 (mail-abbrevs-setup)
1514 (mail-aliases-setup)))
1515 (message-set-auto-save-file-name)
1516 (mm-enable-multibyte)
1517 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1518 (setq indent-tabs-mode nil)
1519 (mml-mode)
1520 (run-hooks 'text-mode-hook 'message-mode-hook))
1522 (defun message-setup-fill-variables ()
1523 "Setup message fill variables."
1524 (make-local-variable 'paragraph-separate)
1525 (make-local-variable 'paragraph-start)
1526 (make-local-variable 'adaptive-fill-regexp)
1527 (unless (boundp 'adaptive-fill-first-line-regexp)
1528 (setq adaptive-fill-first-line-regexp nil))
1529 (make-local-variable 'adaptive-fill-first-line-regexp)
1530 (make-local-variable 'auto-fill-inhibit-regexp)
1531 (let ((quote-prefix-regexp
1532 (concat
1533 "[ \t]*" ; possible initial space
1534 "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
1535 "\\w+>\\|" ; supercite-style prefix
1536 "[|:>]" ; standard prefix
1537 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1538 (setq paragraph-start
1539 (concat
1540 (regexp-quote mail-header-separator) "$\\|"
1541 "[ \t]*$\\|" ; blank lines
1542 "-- $\\|" ; signature delimiter
1543 "---+$\\|" ; delimiters for forwarded messages
1544 page-delimiter "$\\|" ; spoiler warnings
1545 ".*wrote:$\\|" ; attribution lines
1546 quote-prefix-regexp "$")) ; empty lines in quoted text
1547 (setq paragraph-separate paragraph-start)
1548 (setq adaptive-fill-regexp
1549 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1550 (setq adaptive-fill-first-line-regexp
1551 (concat quote-prefix-regexp "\\|"
1552 adaptive-fill-first-line-regexp))
1553 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1558 ;;; Message mode commands
1561 ;;; Movement commands
1563 (defun message-goto-to ()
1564 "Move point to the To header."
1565 (interactive)
1566 (message-position-on-field "To"))
1568 (defun message-goto-subject ()
1569 "Move point to the Subject header."
1570 (interactive)
1571 (message-position-on-field "Subject"))
1573 (defun message-goto-cc ()
1574 "Move point to the Cc header."
1575 (interactive)
1576 (message-position-on-field "Cc" "To"))
1578 (defun message-goto-bcc ()
1579 "Move point to the Bcc header."
1580 (interactive)
1581 (message-position-on-field "Bcc" "Cc" "To"))
1583 (defun message-goto-fcc ()
1584 "Move point to the Fcc header."
1585 (interactive)
1586 (message-position-on-field "Fcc" "To" "Newsgroups"))
1588 (defun message-goto-reply-to ()
1589 "Move point to the Reply-To header."
1590 (interactive)
1591 (message-position-on-field "Reply-To" "Subject"))
1593 (defun message-goto-newsgroups ()
1594 "Move point to the Newsgroups header."
1595 (interactive)
1596 (message-position-on-field "Newsgroups"))
1598 (defun message-goto-distribution ()
1599 "Move point to the Distribution header."
1600 (interactive)
1601 (message-position-on-field "Distribution"))
1603 (defun message-goto-followup-to ()
1604 "Move point to the Followup-To header."
1605 (interactive)
1606 (message-position-on-field "Followup-To" "Newsgroups"))
1608 (defun message-goto-keywords ()
1609 "Move point to the Keywords header."
1610 (interactive)
1611 (message-position-on-field "Keywords" "Subject"))
1613 (defun message-goto-summary ()
1614 "Move point to the Summary header."
1615 (interactive)
1616 (message-position-on-field "Summary" "Subject"))
1618 (defun message-goto-body ()
1619 "Move point to the beginning of the message body."
1620 (interactive)
1621 (if (looking-at "[ \t]*\n") (expand-abbrev))
1622 (goto-char (point-min))
1623 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1624 (search-forward "\n\n" nil t)))
1626 (defun message-goto-eoh ()
1627 "Move point to the end of the headers."
1628 (interactive)
1629 (message-goto-body)
1630 (forward-line -1))
1632 (defun message-goto-signature ()
1633 "Move point to the beginning of the message signature.
1634 If there is no signature in the article, go to the end and
1635 return nil."
1636 (interactive)
1637 (goto-char (point-min))
1638 (if (re-search-forward message-signature-separator nil t)
1639 (forward-line 1)
1640 (goto-char (point-max))
1641 nil))
1645 (defun message-insert-to (&optional force)
1646 "Insert a To header that points to the author of the article being replied to.
1647 If the original author requested not to be sent mail, the function signals
1648 an error.
1649 With the prefix argument FORCE, insert the header anyway."
1650 (interactive "P")
1651 (let ((co (message-fetch-reply-field "mail-copies-to")))
1652 (when (and (null force)
1654 (or (equal (downcase co) "never")
1655 (equal (downcase co) "nobody")))
1656 (error "The user has requested not to have copies sent via mail")))
1657 (when (and (message-position-on-field "To")
1658 (mail-fetch-field "to")
1659 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1660 (insert ", "))
1661 (insert (or (message-fetch-reply-field "reply-to")
1662 (message-fetch-reply-field "from") "")))
1664 (defun message-widen-reply ()
1665 "Widen the reply to include maximum recipients."
1666 (interactive)
1667 (let ((follow-to
1668 (and message-reply-buffer
1669 (buffer-name message-reply-buffer)
1670 (save-excursion
1671 (set-buffer message-reply-buffer)
1672 (message-get-reply-headers t)))))
1673 (save-excursion
1674 (save-restriction
1675 (message-narrow-to-headers)
1676 (dolist (elem follow-to)
1677 (message-remove-header (symbol-name (car elem)))
1678 (goto-char (point-min))
1679 (insert (symbol-name (car elem)) ": "
1680 (cdr elem) "\n"))))))
1682 (defun message-insert-newsgroups ()
1683 "Insert the Newsgroups header from the article being replied to."
1684 (interactive)
1685 (when (and (message-position-on-field "Newsgroups")
1686 (mail-fetch-field "newsgroups")
1687 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1688 (insert ","))
1689 (insert (or (message-fetch-reply-field "newsgroups") "")))
1693 ;;; Various commands
1695 (defun message-delete-not-region (beg end)
1696 "Delete everything in the body of the current message that is outside of the region."
1697 (interactive "r")
1698 (save-excursion
1699 (goto-char end)
1700 (delete-region (point) (if (not (message-goto-signature))
1701 (point)
1702 (forward-line -2)
1703 (point)))
1704 (insert "\n")
1705 (goto-char beg)
1706 (delete-region beg (progn (message-goto-body)
1707 (forward-line 2)
1708 (point))))
1709 (when (message-goto-signature)
1710 (forward-line -2)))
1712 (defun message-kill-to-signature ()
1713 "Deletes all text up to the signature."
1714 (interactive)
1715 (let ((point (point)))
1716 (message-goto-signature)
1717 (unless (eobp)
1718 (forward-line -2))
1719 (kill-region point (point))
1720 (unless (bolp)
1721 (insert "\n"))))
1723 (defun message-newline-and-reformat ()
1724 "Insert four newlines, and then reformat if inside quoted text."
1725 (interactive)
1726 ;; The Latin-1 angle quote looks pretty dubious. -- fx
1727 (let ((prefix "[]>»|:}+ \t]*")
1728 (supercite-thing "[-._[:alnum:]]*[>]+[ \t]*")
1729 quoted point)
1730 (unless (bolp)
1731 (save-excursion
1732 (beginning-of-line)
1733 (when (looking-at (concat prefix
1734 supercite-thing))
1735 (setq quoted (match-string 0))))
1736 (insert "\n"))
1737 (setq point (point))
1738 (insert "\n\n\n")
1739 (delete-region (point) (re-search-forward "[ \t]*"))
1740 (when quoted
1741 (insert quoted))
1742 (fill-paragraph nil)
1743 (goto-char point)
1744 (forward-line 1)))
1746 (defun message-insert-signature (&optional force)
1747 "Insert a signature. See documentation for the `message-signature' variable."
1748 (interactive (list 0))
1749 (let* ((signature
1750 (cond
1751 ((and (null message-signature)
1752 (eq force 0))
1753 (save-excursion
1754 (goto-char (point-max))
1755 (not (re-search-backward message-signature-separator nil t))))
1756 ((and (null message-signature)
1757 force)
1759 ((message-functionp message-signature)
1760 (funcall message-signature))
1761 ((listp message-signature)
1762 (eval message-signature))
1763 (t message-signature)))
1764 (signature
1765 (cond ((stringp signature)
1766 signature)
1767 ((and (eq t signature)
1768 message-signature-file
1769 (file-exists-p message-signature-file))
1770 signature))))
1771 (when signature
1772 (goto-char (point-max))
1773 ;; Insert the signature.
1774 (unless (bolp)
1775 (insert "\n"))
1776 (insert "\n-- \n")
1777 (if (eq signature t)
1778 (insert-file-contents message-signature-file)
1779 (insert signature))
1780 (goto-char (point-max))
1781 (or (bolp) (insert "\n")))))
1783 (defun message-elide-region (b e)
1784 "Elide the text between point and mark.
1785 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1786 text was killed."
1787 (interactive "r")
1788 (kill-region b e)
1789 (insert message-elide-ellipsis))
1791 (defvar message-caesar-translation-table nil)
1793 (defun message-caesar-region (b e &optional n)
1794 "Caesar rotation of region by N, default 13, for decrypting netnews."
1795 (interactive
1796 (list
1797 (min (point) (or (mark t) (point)))
1798 (max (point) (or (mark t) (point)))
1799 (when current-prefix-arg
1800 (prefix-numeric-value current-prefix-arg))))
1802 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1803 (unless (or (zerop n) ; no action needed for a rot of 0
1804 (= b e)) ; no region to rotate
1805 ;; We build the table, if necessary.
1806 (when (or (not message-caesar-translation-table)
1807 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1808 (setq message-caesar-translation-table
1809 (message-make-caesar-translation-table n)))
1810 (translate-region b e message-caesar-translation-table)))
1812 (defun message-make-caesar-translation-table (n)
1813 "Create a rot table with offset N."
1814 (let ((i -1)
1815 (table (make-string 256 0)))
1816 (while (< (incf i) 256)
1817 (aset table i i))
1818 (concat
1819 (substring table 0 ?A)
1820 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1821 (substring table ?A (+ ?A n))
1822 (substring table (+ ?A 26) ?a)
1823 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1824 (substring table ?a (+ ?a n))
1825 (substring table (+ ?a 26) 255))))
1827 (defun message-caesar-buffer-body (&optional rotnum)
1828 "Caesar rotates all letters in the current buffer by 13 places.
1829 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1830 With prefix arg, specifies the number of places to rotate each letter forward.
1831 Mail and USENET news headers are not rotated."
1832 (interactive (if current-prefix-arg
1833 (list (prefix-numeric-value current-prefix-arg))
1834 (list nil)))
1835 (save-excursion
1836 (save-restriction
1837 (when (message-goto-body)
1838 (narrow-to-region (point) (point-max)))
1839 (message-caesar-region (point-min) (point-max) rotnum))))
1841 (defun message-pipe-buffer-body (program)
1842 "Pipe the message body in the current buffer through PROGRAM."
1843 (save-excursion
1844 (save-restriction
1845 (when (message-goto-body)
1846 (narrow-to-region (point) (point-max)))
1847 (shell-command-on-region
1848 (point-min) (point-max) program nil t))))
1850 (defun message-rename-buffer (&optional enter-string)
1851 "Rename the *message* buffer to \"*message* RECIPIENT\".
1852 If the function is run with a prefix, it will ask for a new buffer
1853 name, rather than giving an automatic name."
1854 (interactive "Pbuffer name: ")
1855 (save-excursion
1856 (save-restriction
1857 (goto-char (point-min))
1858 (narrow-to-region (point)
1859 (search-forward mail-header-separator nil 'end))
1860 (let* ((mail-to (or
1861 (if (message-news-p) (message-fetch-field "Newsgroups")
1862 (message-fetch-field "To"))
1863 ""))
1864 (mail-trimmed-to
1865 (if (string-match "," mail-to)
1866 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1867 mail-to))
1868 (name-default (concat "*message* " mail-trimmed-to))
1869 (name (if enter-string
1870 (read-string "New buffer name: " name-default)
1871 name-default)))
1872 (rename-buffer name t)))))
1874 (defun message-fill-yanked-message (&optional justifyp)
1875 "Fill the paragraphs of a message yanked into this one.
1876 Numeric argument means justify as well."
1877 (interactive "P")
1878 (save-excursion
1879 (goto-char (point-min))
1880 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1881 (let ((fill-prefix message-yank-prefix))
1882 (fill-individual-paragraphs (point) (point-max) justifyp))))
1884 (defun message-indent-citation ()
1885 "Modify text just inserted from a message to be cited.
1886 The inserted text should be the region.
1887 When this function returns, the region is again around the modified text.
1889 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1890 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1891 (let ((start (point)))
1892 ;; Remove unwanted headers.
1893 (when message-ignored-cited-headers
1894 (let (all-removed)
1895 (save-restriction
1896 (narrow-to-region
1897 (goto-char start)
1898 (if (search-forward "\n\n" nil t)
1899 (1- (point))
1900 (point)))
1901 (message-remove-header message-ignored-cited-headers t)
1902 (when (= (point-min) (point-max))
1903 (setq all-removed t))
1904 (goto-char (point-max)))
1905 (if all-removed
1906 (goto-char start)
1907 (forward-line 1))))
1908 ;; Delete blank lines at the start of the buffer.
1909 (while (and (point-min)
1910 (eolp)
1911 (not (eobp)))
1912 (message-delete-line))
1913 ;; Delete blank lines at the end of the buffer.
1914 (goto-char (point-max))
1915 (unless (eolp)
1916 (insert "\n"))
1917 (while (and (zerop (forward-line -1))
1918 (looking-at "$"))
1919 (message-delete-line))
1920 ;; Do the indentation.
1921 (if (null message-yank-prefix)
1922 (indent-rigidly start (mark t) message-indentation-spaces)
1923 (save-excursion
1924 (goto-char start)
1925 (while (< (point) (mark t))
1926 (insert message-yank-prefix)
1927 (forward-line 1))))
1928 (goto-char start)))
1930 (defun message-yank-original (&optional arg)
1931 "Insert the message being replied to, if any.
1932 Puts point before the text and mark after.
1933 Normally indents each nonblank line ARG spaces (default 3). However,
1934 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1936 This function uses `message-cite-function' to do the actual citing.
1938 Just \\[universal-argument] as argument means don't indent, insert no
1939 prefix, and don't delete any headers."
1940 (interactive "P")
1941 (let ((modified (buffer-modified-p)))
1942 (when (and message-reply-buffer
1943 message-cite-function)
1944 (delete-windows-on message-reply-buffer t)
1945 (insert-buffer message-reply-buffer)
1946 (funcall message-cite-function)
1947 (message-exchange-point-and-mark)
1948 (unless (bolp)
1949 (insert ?\n))
1950 (unless modified
1951 (setq message-checksum (message-checksum))))))
1953 (defun message-yank-buffer (buffer)
1954 "Insert BUFFER into the current buffer and quote it."
1955 (interactive "bYank buffer: ")
1956 (let ((message-reply-buffer buffer))
1957 (save-window-excursion
1958 (message-yank-original))))
1960 (defun message-buffers ()
1961 "Return a list of active message buffers."
1962 (let (buffers)
1963 (save-excursion
1964 (dolist (buffer (buffer-list t))
1965 (set-buffer buffer)
1966 (when (and (eq major-mode 'message-mode)
1967 (null message-sent-message-via))
1968 (push (buffer-name buffer) buffers))))
1969 (nreverse buffers)))
1971 (defun message-cite-original-without-signature ()
1972 "Cite function in the standard Message manner."
1973 (let ((start (point))
1974 (end (mark t))
1975 (functions
1976 (when message-indent-citation-function
1977 (if (listp message-indent-citation-function)
1978 message-indent-citation-function
1979 (list message-indent-citation-function)))))
1980 (mml-quote-region start end)
1981 ;; Allow undoing.
1982 (undo-boundary)
1983 (goto-char end)
1984 (when (re-search-backward message-signature-separator start t)
1985 ;; Also peel off any blank lines before the signature.
1986 (forward-line -1)
1987 (while (looking-at "^[ \t]*$")
1988 (forward-line -1))
1989 (forward-line 1)
1990 (delete-region (point) end))
1991 (goto-char start)
1992 (while functions
1993 (funcall (pop functions)))
1994 (when message-citation-line-function
1995 (unless (bolp)
1996 (insert "\n"))
1997 (funcall message-citation-line-function))))
1999 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2000 (defun message-cite-original ()
2001 "Cite function in the standard Message manner."
2002 (if (and (boundp 'mail-citation-hook)
2003 mail-citation-hook)
2004 (run-hooks 'mail-citation-hook)
2005 (let ((start (point))
2006 (end (mark t))
2007 (functions
2008 (when message-indent-citation-function
2009 (if (listp message-indent-citation-function)
2010 message-indent-citation-function
2011 (list message-indent-citation-function)))))
2012 (mml-quote-region start end)
2013 (goto-char start)
2014 (while functions
2015 (funcall (pop functions)))
2016 (when message-citation-line-function
2017 (unless (bolp)
2018 (insert "\n"))
2019 (funcall message-citation-line-function)))))
2021 (defun message-insert-citation-line ()
2022 "Function that inserts a simple citation line."
2023 (when message-reply-headers
2024 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2026 (defun message-position-on-field (header &rest afters)
2027 (let ((case-fold-search t))
2028 (save-restriction
2029 (narrow-to-region
2030 (goto-char (point-min))
2031 (progn
2032 (re-search-forward
2033 (concat "^" (regexp-quote mail-header-separator) "$"))
2034 (match-beginning 0)))
2035 (goto-char (point-min))
2036 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2037 (progn
2038 (re-search-forward "^[^ \t]" nil 'move)
2039 (beginning-of-line)
2040 (skip-chars-backward "\n")
2042 (while (and afters
2043 (not (re-search-forward
2044 (concat "^" (regexp-quote (car afters)) ":")
2045 nil t)))
2046 (pop afters))
2047 (when afters
2048 (re-search-forward "^[^ \t]" nil 'move)
2049 (beginning-of-line))
2050 (insert header ": \n")
2051 (forward-char -1)
2052 nil))))
2054 (defun message-remove-signature ()
2055 "Remove the signature from the text between point and mark.
2056 The text will also be indented the normal way."
2057 (save-excursion
2058 (let ((start (point))
2059 mark)
2060 (if (not (re-search-forward message-signature-separator (mark t) t))
2061 ;; No signature here, so we just indent the cited text.
2062 (message-indent-citation)
2063 ;; Find the last non-empty line.
2064 (forward-line -1)
2065 (while (looking-at "[ \t]*$")
2066 (forward-line -1))
2067 (forward-line 1)
2068 (setq mark (set-marker (make-marker) (point)))
2069 (goto-char start)
2070 (message-indent-citation)
2071 ;; Enable undoing the deletion.
2072 (undo-boundary)
2073 (delete-region mark (mark t))
2074 (set-marker mark nil)))))
2079 ;;; Sending messages
2082 (defun message-send-and-exit (&optional arg)
2083 "Send message like `message-send', then, if no errors, exit from mail buffer."
2084 (interactive "P")
2085 (let ((buf (current-buffer))
2086 (actions message-exit-actions))
2087 (when (and (message-send arg)
2088 (buffer-name buf))
2089 (if message-kill-buffer-on-exit
2090 (kill-buffer buf)
2091 (bury-buffer buf)
2092 (when (eq buf (current-buffer))
2093 (message-bury buf)))
2094 (message-do-actions actions)
2095 t)))
2097 (defun message-dont-send ()
2098 "Don't send the message you have been editing."
2099 (interactive)
2100 (set-buffer-modified-p t)
2101 (save-buffer)
2102 (let ((actions message-postpone-actions))
2103 (message-bury (current-buffer))
2104 (message-do-actions actions)))
2106 (defun message-kill-buffer ()
2107 "Kill the current buffer."
2108 (interactive)
2109 (when (or (not (buffer-modified-p))
2110 (yes-or-no-p "Message modified; kill anyway? "))
2111 (let ((actions message-kill-actions))
2112 (setq buffer-file-name nil)
2113 (kill-buffer (current-buffer))
2114 (message-do-actions actions))))
2116 (defun message-bury (buffer)
2117 "Bury this mail buffer."
2118 (let ((newbuf (other-buffer buffer)))
2119 (bury-buffer buffer)
2120 (if (and (fboundp 'frame-parameters)
2121 (cdr (assq 'dedicated (frame-parameters)))
2122 (not (null (delq (selected-frame) (visible-frame-list)))))
2123 (delete-frame (selected-frame))
2124 (switch-to-buffer newbuf))))
2126 (defun message-send (&optional arg)
2127 "Send the message in the current buffer.
2128 If `message-interactive' is non-nil, wait for success indication or
2129 error messages, and inform user.
2130 Otherwise any failure is reported in a message back to the user from
2131 the mailer.
2132 The usage of ARG is defined by the instance that called Message.
2133 It should typically alter the sending method in some way or other."
2134 (interactive "P")
2135 ;; Make it possible to undo the coming changes.
2136 (undo-boundary)
2137 (let ((inhibit-read-only t))
2138 (put-text-property (point-min) (point-max) 'read-only nil))
2139 (message-fix-before-sending)
2140 (run-hooks 'message-send-hook)
2141 (message message-sending-message)
2142 (let ((alist message-send-method-alist)
2143 (success t)
2144 elem sent)
2145 (while (and success
2146 (setq elem (pop alist)))
2147 (when (funcall (cadr elem))
2148 (when (and (or (not (memq (car elem)
2149 message-sent-message-via))
2150 (y-or-n-p
2151 (format
2152 "Already sent message via %s; resend? "
2153 (car elem))))
2154 (setq success (funcall (caddr elem) arg)))
2155 (setq sent t))))
2156 (unless (or sent (not success))
2157 (error "No methods specified to send by"))
2158 (when (and success sent)
2159 (message-do-fcc)
2160 (save-excursion
2161 (run-hooks 'message-sent-hook))
2162 (message "Sending...done")
2163 ;; Mark the buffer as unmodified and delete auto-save.
2164 (set-buffer-modified-p nil)
2165 (delete-auto-save-file-if-necessary t)
2166 (message-disassociate-draft)
2167 ;; Delete other mail buffers and stuff.
2168 (message-do-send-housekeeping)
2169 (message-do-actions message-send-actions)
2170 ;; Return success.
2171 t)))
2173 (defun message-send-via-mail (arg)
2174 "Send the current message via mail."
2175 (message-send-mail arg))
2177 (defun message-send-via-news (arg)
2178 "Send the current message via news."
2179 (funcall message-send-news-function arg))
2181 (defmacro message-check (type &rest forms)
2182 "Eval FORMS if TYPE is to be checked."
2183 `(or (message-check-element ,type)
2184 (save-excursion
2185 ,@forms)))
2187 (put 'message-check 'lisp-indent-function 1)
2188 (put 'message-check 'edebug-form-spec '(form body))
2190 (defun message-fix-before-sending ()
2191 "Do various things to make the message nice before sending it."
2192 ;; Make sure there's a newline at the end of the message.
2193 (goto-char (point-max))
2194 (unless (bolp)
2195 (insert "\n"))
2196 ;; Delete all invisible text.
2197 (message-check 'invisible-text
2198 (when (text-property-any (point-min) (point-max) 'invisible t)
2199 (put-text-property (point-min) (point-max) 'invisible nil)
2200 (unless (yes-or-no-p
2201 "Invisible text found and made visible; continue posting? ")
2202 (error "Invisible text found and made visible")))))
2204 (defun message-add-action (action &rest types)
2205 "Add ACTION to be performed when doing an exit of type TYPES."
2206 (let (var)
2207 (while types
2208 (set (setq var (intern (format "message-%s-actions" (pop types))))
2209 (nconc (symbol-value var) (list action))))))
2211 (defun message-do-actions (actions)
2212 "Perform all actions in ACTIONS."
2213 ;; Now perform actions on successful sending.
2214 (while actions
2215 (ignore-errors
2216 (cond
2217 ;; A simple function.
2218 ((message-functionp (car actions))
2219 (funcall (car actions)))
2220 ;; Something to be evaled.
2222 (eval (car actions)))))
2223 (pop actions)))
2225 (defun message-send-mail-partially ()
2226 "Sendmail as message/partial."
2227 ;; replace the header delimiter with a blank line
2228 (goto-char (point-min))
2229 (re-search-forward
2230 (concat "^" (regexp-quote mail-header-separator) "\n"))
2231 (replace-match "\n")
2232 (run-hooks 'message-send-mail-hook)
2233 (let ((p (goto-char (point-min)))
2234 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2235 (curbuf (current-buffer))
2236 (id (message-make-message-id)) (n 1)
2237 plist total header required-mail-headers)
2238 (while (not (eobp))
2239 (if (< (point-max) (+ p message-send-mail-partially-limit))
2240 (goto-char (point-max))
2241 (goto-char (+ p message-send-mail-partially-limit))
2242 (beginning-of-line)
2243 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2244 (push p plist)
2245 (setq p (point)))
2246 (setq total (length plist))
2247 (push (point-max) plist)
2248 (setq plist (nreverse plist))
2249 (unwind-protect
2250 (save-excursion
2251 (setq p (pop plist))
2252 (while plist
2253 (set-buffer curbuf)
2254 (copy-to-buffer tembuf p (car plist))
2255 (set-buffer tembuf)
2256 (goto-char (point-min))
2257 (if header
2258 (progn
2259 (goto-char (point-min))
2260 (narrow-to-region (point) (point))
2261 (insert header))
2262 (message-goto-eoh)
2263 (setq header (buffer-substring (point-min) (point)))
2264 (goto-char (point-min))
2265 (narrow-to-region (point) (point))
2266 (insert header)
2267 (message-remove-header "Mime-Version")
2268 (message-remove-header "Content-Type")
2269 (message-remove-header "Content-Transfer-Encoding")
2270 (message-remove-header "Message-ID")
2271 (message-remove-header "Lines")
2272 (goto-char (point-max))
2273 (insert "Mime-Version: 1.0\n")
2274 (setq header (buffer-substring (point-min) (point-max))))
2275 (goto-char (point-max))
2276 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2277 id n total))
2278 (let ((mail-header-separator ""))
2279 (when (memq 'Message-ID message-required-mail-headers)
2280 (insert "Message-ID: " (message-make-message-id) "\n"))
2281 (when (memq 'Lines message-required-mail-headers)
2282 (let ((mail-header-separator ""))
2283 (insert "Lines: " (message-make-lines) "\n")))
2284 (message-goto-subject)
2285 (end-of-line)
2286 (insert (format " (%d/%d)" n total))
2287 (goto-char (point-max))
2288 (insert "\n")
2289 (widen)
2290 (mm-with-unibyte-current-buffer
2291 (funcall message-send-mail-function)))
2292 (setq n (+ n 1))
2293 (setq p (pop plist))
2294 (erase-buffer)))
2295 (kill-buffer tembuf))))
2297 (defun message-send-mail (&optional arg)
2298 (require 'mail-utils)
2299 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2300 (case-fold-search nil)
2301 (news (message-news-p))
2302 (mailbuf (current-buffer))
2303 (message-this-is-mail t)
2304 (message-posting-charset
2305 (if (fboundp 'gnus-setup-posting-charset)
2306 (gnus-setup-posting-charset nil)
2307 message-posting-charset)))
2308 (save-restriction
2309 (message-narrow-to-headers)
2310 ;; Insert some headers.
2311 (let ((message-deletable-headers
2312 (if news nil message-deletable-headers)))
2313 (message-generate-headers message-required-mail-headers))
2314 ;; Let the user do all of the above.
2315 (run-hooks 'message-header-hook))
2316 (unwind-protect
2317 (save-excursion
2318 (set-buffer tembuf)
2319 (erase-buffer)
2320 ;; Avoid copying text props.
2321 (insert (format
2322 "%s" (save-excursion
2323 (set-buffer mailbuf)
2324 (buffer-string))))
2325 ;; Remove some headers.
2326 (message-encode-message-body)
2327 (save-restriction
2328 (message-narrow-to-headers)
2329 ;; We (re)generate the Lines header.
2330 (when (memq 'Lines message-required-mail-headers)
2331 (message-generate-headers '(Lines)))
2332 ;; Remove some headers.
2333 (message-remove-header message-ignored-mail-headers t)
2334 (let ((mail-parse-charset message-default-charset))
2335 (mail-encode-encoded-word-buffer)))
2336 (goto-char (point-max))
2337 ;; require one newline at the end.
2338 (or (= (preceding-char) ?\n)
2339 (insert ?\n))
2340 (when
2341 (save-restriction
2342 (message-narrow-to-headers)
2343 (and news
2344 (or (message-fetch-field "cc")
2345 (message-fetch-field "to"))
2346 (string= "text/plain"
2347 (car
2348 (mail-header-parse-content-type
2349 (message-fetch-field "content-type"))))))
2350 (message-insert-courtesy-copy))
2351 (if (or (not message-send-mail-partially-limit)
2352 (< (point-max) message-send-mail-partially-limit)
2353 (not (y-or-n-p "The message size is too large, should it be sent partially?")))
2354 (mm-with-unibyte-current-buffer
2355 (funcall message-send-mail-function))
2356 (message-send-mail-partially)))
2357 (kill-buffer tembuf))
2358 (set-buffer mailbuf)
2359 (push 'mail message-sent-message-via)))
2361 (defun message-send-mail-with-sendmail ()
2362 "Send off the prepared buffer with sendmail."
2363 (let ((errbuf (if message-interactive
2364 (message-generate-new-buffer-clone-locals
2365 " sendmail errors")
2367 resend-to-addresses delimline)
2368 (let ((case-fold-search t))
2369 (save-restriction
2370 (message-narrow-to-headers)
2371 (setq resend-to-addresses (message-fetch-field "resent-to")))
2372 ;; Change header-delimiter to be what sendmail expects.
2373 (goto-char (point-min))
2374 (re-search-forward
2375 (concat "^" (regexp-quote mail-header-separator) "\n"))
2376 (replace-match "\n")
2377 (backward-char 1)
2378 (setq delimline (point-marker))
2379 (run-hooks 'message-send-mail-hook)
2380 ;; Insert an extra newline if we need it to work around
2381 ;; Sun's bug that swallows newlines.
2382 (goto-char (1+ delimline))
2383 (when (eval message-mailer-swallows-blank-line)
2384 (newline))
2385 (when message-interactive
2386 (save-excursion
2387 (set-buffer errbuf)
2388 (erase-buffer))))
2389 (let ((default-directory "/")
2390 (coding-system-for-write message-send-coding-system))
2391 (apply 'call-process-region
2392 (append (list (point-min) (point-max)
2393 (if (boundp 'sendmail-program)
2394 sendmail-program
2395 "/usr/lib/sendmail")
2396 nil errbuf nil "-oi")
2397 ;; Always specify who from,
2398 ;; since some systems have broken sendmails.
2399 ;; But some systems are more broken with -f, so
2400 ;; we'll let users override this.
2401 (if (null message-sendmail-f-is-evil)
2402 (list "-f" (message-make-address)))
2403 ;; These mean "report errors by mail"
2404 ;; and "deliver in background".
2405 (if (null message-interactive) '("-oem" "-odb"))
2406 ;; Get the addresses from the message
2407 ;; unless this is a resend.
2408 ;; We must not do that for a resend
2409 ;; because we would find the original addresses.
2410 ;; For a resend, include the specific addresses.
2411 (if resend-to-addresses
2412 (list resend-to-addresses)
2413 '("-t")))))
2414 (when message-interactive
2415 (save-excursion
2416 (set-buffer errbuf)
2417 (goto-char (point-min))
2418 (while (re-search-forward "\n\n* *" nil t)
2419 (replace-match "; "))
2420 (if (not (zerop (buffer-size)))
2421 (error "Sending...failed to %s"
2422 (buffer-substring (point-min) (point-max)))))
2423 (when (bufferp errbuf)
2424 (kill-buffer errbuf)))))
2426 (defun message-send-mail-with-qmail ()
2427 "Pass the prepared message buffer to qmail-inject.
2428 Refer to the documentation for the variable `message-send-mail-function'
2429 to find out how to use this."
2430 ;; replace the header delimiter with a blank line
2431 (goto-char (point-min))
2432 (re-search-forward
2433 (concat "^" (regexp-quote mail-header-separator) "\n"))
2434 (replace-match "\n")
2435 (run-hooks 'message-send-mail-hook)
2436 ;; send the message
2437 (case
2438 (let ((coding-system-for-write message-send-coding-system))
2439 (apply
2440 'call-process-region 1 (point-max) message-qmail-inject-program
2441 nil nil nil
2442 ;; qmail-inject's default behaviour is to look for addresses on the
2443 ;; command line; if there're none, it scans the headers.
2444 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2446 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2447 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2448 ;; message from stdin.
2450 ;; qmail also has the advantage of not having been raped by
2451 ;; various vendors, so we don't have to allow for that, either --
2452 ;; compare this with message-send-mail-with-sendmail and weep
2453 ;; for sendmail's lost innocence.
2455 ;; all this is way cool coz it lets us keep the arguments entirely
2456 ;; free for -inject-arguments -- a big win for the user and for us
2457 ;; since we don't have to play that double-guessing game and the user
2458 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2459 message-qmail-inject-args))
2460 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2461 ;; we have to look at the retval instead
2462 (0 nil)
2463 (1 (error "qmail-inject reported permanent failure"))
2464 (111 (error "qmail-inject reported transient failure"))
2465 ;; should never happen
2466 (t (error "qmail-inject reported unknown failure"))))
2468 (defun message-send-mail-with-mh ()
2469 "Send the prepared message buffer with mh."
2470 (let ((mh-previous-window-config nil)
2471 (name (mh-new-draft-name)))
2472 (setq buffer-file-name name)
2473 ;; MH wants to generate these headers itself.
2474 (when message-mh-deletable-headers
2475 (let ((headers message-mh-deletable-headers))
2476 (while headers
2477 (goto-char (point-min))
2478 (and (re-search-forward
2479 (concat "^" (symbol-name (car headers)) ": *") nil t)
2480 (message-delete-line))
2481 (pop headers))))
2482 (run-hooks 'message-send-mail-hook)
2483 ;; Pass it on to mh.
2484 (mh-send-letter)))
2486 (defun message-send-news (&optional arg)
2487 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2488 (case-fold-search nil)
2489 (method (if (message-functionp message-post-method)
2490 (funcall message-post-method arg)
2491 message-post-method))
2492 (group-name-charset (gnus-group-name-charset method ""))
2493 (rfc2047-header-encoding-alist
2494 (if group-name-charset
2495 (cons (cons "Newsgroups" group-name-charset)
2496 rfc2047-header-encoding-alist)
2497 rfc2047-header-encoding-alist))
2498 (messbuf (current-buffer))
2499 (message-syntax-checks
2500 (if arg
2501 (cons '(existing-newsgroups . disabled)
2502 message-syntax-checks)
2503 message-syntax-checks))
2504 (message-this-is-news t)
2505 (message-posting-charset (gnus-setup-posting-charset
2506 (save-restriction
2507 (message-narrow-to-headers-or-head)
2508 (message-fetch-field "Newsgroups"))))
2509 result)
2510 (if (not (message-check-news-body-syntax))
2512 (save-restriction
2513 (message-narrow-to-headers)
2514 ;; Insert some headers.
2515 (message-generate-headers message-required-news-headers)
2516 ;; Let the user do all of the above.
2517 (run-hooks 'message-header-hook))
2518 (if group-name-charset
2519 (setq message-syntax-checks
2520 (cons '(valid-newsgroups . disabled)
2521 message-syntax-checks)))
2522 (message-cleanup-headers)
2523 (if (not (message-check-news-syntax))
2525 (unwind-protect
2526 (save-excursion
2527 (set-buffer tembuf)
2528 (buffer-disable-undo)
2529 (erase-buffer)
2530 ;; Avoid copying text props.
2531 (insert (format
2532 "%s" (save-excursion
2533 (set-buffer messbuf)
2534 (buffer-string))))
2535 (message-encode-message-body)
2536 ;; Remove some headers.
2537 (save-restriction
2538 (message-narrow-to-headers)
2539 ;; We (re)generate the Lines header.
2540 (when (memq 'Lines message-required-mail-headers)
2541 (message-generate-headers '(Lines)))
2542 ;; Remove some headers.
2543 (message-remove-header message-ignored-news-headers t)
2544 (let ((mail-parse-charset message-default-charset))
2545 (mail-encode-encoded-word-buffer)))
2546 (goto-char (point-max))
2547 ;; require one newline at the end.
2548 (or (= (preceding-char) ?\n)
2549 (insert ?\n))
2550 (let ((case-fold-search t))
2551 ;; Remove the delimiter.
2552 (goto-char (point-min))
2553 (re-search-forward
2554 (concat "^" (regexp-quote mail-header-separator) "\n"))
2555 (replace-match "\n")
2556 (backward-char 1))
2557 (run-hooks 'message-send-news-hook)
2558 (gnus-open-server method)
2559 (setq result (let ((mail-header-separator ""))
2560 (gnus-request-post method))))
2561 (kill-buffer tembuf))
2562 (set-buffer messbuf)
2563 (if result
2564 (push 'news message-sent-message-via)
2565 (message "Couldn't send message via news: %s"
2566 (nnheader-get-report (car method)))
2567 nil)))))
2570 ;;; Header generation & syntax checking.
2573 (defun message-check-element (type)
2574 "Returns non-nil if this type is not to be checked."
2575 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2577 (let ((able (assq type message-syntax-checks)))
2578 (and (consp able)
2579 (eq (cdr able) 'disabled)))))
2581 (defun message-check-news-syntax ()
2582 "Check the syntax of the message."
2583 (save-excursion
2584 (save-restriction
2585 (widen)
2586 ;; We narrow to the headers and check them first.
2587 (save-excursion
2588 (save-restriction
2589 (message-narrow-to-headers)
2590 (message-check-news-header-syntax))))))
2592 (defun message-check-news-header-syntax ()
2593 (and
2594 ;; Check Newsgroups header.
2595 (message-check 'newsgroups
2596 (let ((group (message-fetch-field "newsgroups")))
2598 (and group
2599 (not (string-match "\\`[ \t]*\\'" group)))
2600 (ignore
2601 (message
2602 "The newsgroups field is empty or missing. Posting is denied.")))))
2603 ;; Check the Subject header.
2604 (message-check 'subject
2605 (let* ((case-fold-search t)
2606 (subject (message-fetch-field "subject")))
2608 (and subject
2609 (not (string-match "\\`[ \t]*\\'" subject)))
2610 (ignore
2611 (message
2612 "The subject field is empty or missing. Posting is denied.")))))
2613 ;; Check for commands in Subject.
2614 (message-check 'subject-cmsg
2615 (if (string-match "^cmsg " (message-fetch-field "subject"))
2616 (y-or-n-p
2617 "The control code \"cmsg\" is in the subject. Really post? ")
2619 ;; Check for multiple identical headers.
2620 (message-check 'multiple-headers
2621 (let (found)
2622 (while (and (not found)
2623 (re-search-forward "^[^ \t:]+: " nil t))
2624 (save-excursion
2625 (or (re-search-forward
2626 (concat "^"
2627 (regexp-quote
2628 (setq found
2629 (buffer-substring
2630 (match-beginning 0) (- (match-end 0) 2))))
2631 ":")
2632 nil t)
2633 (setq found nil))))
2634 (if found
2635 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2636 t)))
2637 ;; Check for Version and Sendsys.
2638 (message-check 'sendsys
2639 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2640 (y-or-n-p
2641 (format "The article contains a %s command. Really post? "
2642 (buffer-substring (match-beginning 0)
2643 (1- (match-end 0)))))
2645 ;; See whether we can shorten Followup-To.
2646 (message-check 'shorten-followup-to
2647 (let ((newsgroups (message-fetch-field "newsgroups"))
2648 (followup-to (message-fetch-field "followup-to"))
2650 (when (and newsgroups
2651 (string-match "," newsgroups)
2652 (not followup-to)
2653 (not
2654 (zerop
2655 (length
2656 (setq to (completing-read
2657 "Followups to: (default all groups) "
2658 (mapcar (lambda (g) (list g))
2659 (cons "poster"
2660 (message-tokenize-header
2661 newsgroups)))))))))
2662 (goto-char (point-min))
2663 (insert "Followup-To: " to "\n"))
2665 ;; Check "Shoot me".
2666 (message-check 'shoot
2667 (if (re-search-forward
2668 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2669 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2671 ;; Check for Approved.
2672 (message-check 'approved
2673 (if (re-search-forward "^Approved:" nil t)
2674 (y-or-n-p "The article contains an Approved header. Really post? ")
2676 ;; Check the Message-ID header.
2677 (message-check 'message-id
2678 (let* ((case-fold-search t)
2679 (message-id (message-fetch-field "message-id" t)))
2680 (or (not message-id)
2681 ;; Is there an @ in the ID?
2682 (and (string-match "@" message-id)
2683 ;; Is there a dot in the ID?
2684 (string-match "@[^.]*\\." message-id)
2685 ;; Does the ID end with a dot?
2686 (not (string-match "\\.>" message-id)))
2687 (y-or-n-p
2688 (format "The Message-ID looks strange: \"%s\". Really post? "
2689 message-id)))))
2690 ;; Check the Newsgroups & Followup-To headers.
2691 (message-check 'existing-newsgroups
2692 (let* ((case-fold-search t)
2693 (newsgroups (message-fetch-field "newsgroups"))
2694 (followup-to (message-fetch-field "followup-to"))
2695 (groups (message-tokenize-header
2696 (if followup-to
2697 (concat newsgroups "," followup-to)
2698 newsgroups)))
2699 (hashtb (and (boundp 'gnus-active-hashtb)
2700 gnus-active-hashtb))
2701 errors)
2702 (if (or (not hashtb)
2703 (not (boundp 'gnus-read-active-file))
2704 (not gnus-read-active-file)
2705 (eq gnus-read-active-file 'some))
2707 (while groups
2708 (when (and (not (boundp (intern (car groups) hashtb)))
2709 (not (equal (car groups) "poster")))
2710 (push (car groups) errors))
2711 (pop groups))
2712 (if (not errors)
2714 (y-or-n-p
2715 (format
2716 "Really post to %s unknown group%s: %s "
2717 (if (= (length errors) 1) "this" "these")
2718 (if (= (length errors) 1) "" "s")
2719 (mapconcat 'identity errors ", ")))))))
2720 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2721 (message-check 'valid-newsgroups
2722 (let ((case-fold-search t)
2723 (headers '("Newsgroups" "Followup-To"))
2724 header error)
2725 (while (and headers (not error))
2726 (when (setq header (mail-fetch-field (car headers)))
2727 (if (or
2728 (not
2729 (string-match
2730 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2731 header))
2732 (memq
2733 nil (mapcar
2734 (lambda (g)
2735 (not (string-match "\\.\\'\\|\\.\\." g)))
2736 (message-tokenize-header header ","))))
2737 (setq error t)))
2738 (unless error
2739 (pop headers)))
2740 (if (not error)
2742 (y-or-n-p
2743 (format "The %s header looks odd: \"%s\". Really post? "
2744 (car headers) header)))))
2745 (message-check 'repeated-newsgroups
2746 (let ((case-fold-search t)
2747 (headers '("Newsgroups" "Followup-To"))
2748 header error groups group)
2749 (while (and headers
2750 (not error))
2751 (when (setq header (mail-fetch-field (pop headers)))
2752 (setq groups (message-tokenize-header header ","))
2753 (while (setq group (pop groups))
2754 (when (member group groups)
2755 (setq error group
2756 groups nil)))))
2757 (if (not error)
2759 (y-or-n-p
2760 (format "Group %s is repeated in headers. Really post? " error)))))
2761 ;; Check the From header.
2762 (message-check 'from
2763 (let* ((case-fold-search t)
2764 (from (message-fetch-field "from"))
2766 (cond
2767 ((not from)
2768 (message "There is no From line. Posting is denied.")
2769 nil)
2770 ((or (not (string-match
2771 "@[^\\.]*\\."
2772 (setq ad (nth 1 (mail-extract-address-components
2773 from))))) ;larsi@ifi
2774 (string-match "\\.\\." ad) ;larsi@ifi..uio
2775 (string-match "@\\." ad) ;larsi@.ifi.uio
2776 (string-match "\\.$" ad) ;larsi@ifi.uio.
2777 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2778 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2779 (message
2780 "Denied posting -- the From looks strange: \"%s\"." from)
2781 nil)
2782 (t t))))))
2784 (defun message-check-news-body-syntax ()
2785 (and
2786 ;; Check for long lines.
2787 (message-check 'long-lines
2788 (goto-char (point-min))
2789 (re-search-forward
2790 (concat "^" (regexp-quote mail-header-separator) "$"))
2791 (while (and
2792 (progn
2793 (end-of-line)
2794 (< (current-column) 80))
2795 (zerop (forward-line 1))))
2796 (or (bolp)
2797 (eobp)
2798 (y-or-n-p
2799 "You have lines longer than 79 characters. Really post? ")))
2800 ;; Check whether the article is empty.
2801 (message-check 'empty
2802 (goto-char (point-min))
2803 (re-search-forward
2804 (concat "^" (regexp-quote mail-header-separator) "$"))
2805 (forward-line 1)
2806 (let ((b (point)))
2807 (goto-char (point-max))
2808 (re-search-backward message-signature-separator nil t)
2809 (beginning-of-line)
2810 (or (re-search-backward "[^ \n\t]" b t)
2811 (y-or-n-p "Empty article. Really post? "))))
2812 ;; Check for control characters.
2813 (message-check 'control-chars
2814 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2815 (y-or-n-p
2816 "The article contains control characters. Really post? ")
2818 ;; Check excessive size.
2819 (message-check 'size
2820 (if (> (buffer-size) 60000)
2821 (y-or-n-p
2822 (format "The article is %d octets long. Really post? "
2823 (buffer-size)))
2825 ;; Check whether any new text has been added.
2826 (message-check 'new-text
2828 (not message-checksum)
2829 (not (eq (message-checksum) message-checksum))
2830 (y-or-n-p
2831 "It looks like no new text has been added. Really post? ")))
2832 ;; Check the length of the signature.
2833 (message-check 'signature
2834 (goto-char (point-max))
2835 (if (> (count-lines (point) (point-max)) 5)
2836 (y-or-n-p
2837 (format
2838 "Your .sig is %d lines; it should be max 4. Really post? "
2839 (1- (count-lines (point) (point-max)))))
2841 ;; Ensure that text follows last quoted portion.
2842 (message-check 'quoting-style
2843 (goto-char (point-max))
2844 (let ((no-problem t))
2845 (when (search-backward-regexp "^>[^\n]*\n>" nil t)
2846 (setq no-problem nil)
2847 (while (not (eobp))
2848 (when (and (not (eolp)) (looking-at "[^> \t]"))
2849 (setq no-problem t))
2850 (forward-line)))
2851 (if no-problem
2853 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
2855 (defun message-checksum ()
2856 "Return a \"checksum\" for the current buffer."
2857 (let ((sum 0))
2858 (save-excursion
2859 (goto-char (point-min))
2860 (re-search-forward
2861 (concat "^" (regexp-quote mail-header-separator) "$"))
2862 (while (not (eobp))
2863 (when (not (looking-at "[ \t\n]"))
2864 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2865 (char-after))))
2866 (forward-char 1)))
2867 sum))
2869 (defun message-do-fcc ()
2870 "Process Fcc headers in the current buffer."
2871 (let ((case-fold-search t)
2872 (buf (current-buffer))
2873 list file)
2874 (save-excursion
2875 (set-buffer (get-buffer-create " *message temp*"))
2876 (erase-buffer)
2877 (insert-buffer-substring buf)
2878 (save-restriction
2879 (message-narrow-to-headers)
2880 (while (setq file (message-fetch-field "fcc"))
2881 (push file list)
2882 (message-remove-header "fcc" nil t)))
2883 (message-encode-message-body)
2884 (save-restriction
2885 (message-narrow-to-headers)
2886 (let ((mail-parse-charset message-default-charset)
2887 (rfc2047-header-encoding-alist
2888 (cons '("Newsgroups" . default)
2889 rfc2047-header-encoding-alist)))
2890 (mail-encode-encoded-word-buffer)))
2891 (goto-char (point-min))
2892 (when (re-search-forward
2893 (concat "^" (regexp-quote mail-header-separator) "$")
2894 nil t)
2895 (replace-match "" t t ))
2896 ;; Process FCC operations.
2897 (while list
2898 (setq file (pop list))
2899 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2900 ;; Pipe the article to the program in question.
2901 (call-process-region (point-min) (point-max) shell-file-name
2902 nil nil nil shell-command-switch
2903 (match-string 1 file))
2904 ;; Save the article.
2905 (setq file (expand-file-name file))
2906 (unless (file-exists-p (file-name-directory file))
2907 (make-directory (file-name-directory file) t))
2908 (if (and message-fcc-handler-function
2909 (not (eq message-fcc-handler-function 'rmail-output)))
2910 (funcall message-fcc-handler-function file)
2911 (if (and (file-readable-p file) (mail-file-babyl-p file))
2912 (rmail-output file 1 nil t)
2913 (let ((mail-use-rfc822 t))
2914 (rmail-output file 1 t t))))))
2915 (kill-buffer (current-buffer)))))
2917 (defun message-output (filename)
2918 "Append this article to Unix/babyl mail file.."
2919 (if (and (file-readable-p filename)
2920 (mail-file-babyl-p filename))
2921 (gnus-output-to-rmail filename t)
2922 (gnus-output-to-mail filename t)))
2924 (defun message-cleanup-headers ()
2925 "Do various automatic cleanups of the headers."
2926 ;; Remove empty lines in the header.
2927 (save-restriction
2928 (message-narrow-to-headers)
2929 ;; Remove blank lines.
2930 (while (re-search-forward "^[ \t]*\n" nil t)
2931 (replace-match "" t t))
2933 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2934 ;; spaces to comma and eliminate spaces around commas. Eliminate
2935 ;; embedded line breaks.
2936 (goto-char (point-min))
2937 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2938 (save-restriction
2939 (narrow-to-region
2940 (point)
2941 (if (re-search-forward "^[^ \t]" nil t)
2942 (match-beginning 0)
2943 (forward-line 1)
2944 (point)))
2945 (goto-char (point-min))
2946 (while (re-search-forward "\n[ \t]+" nil t)
2947 (replace-match " " t t)) ;No line breaks (too confusing)
2948 (goto-char (point-min))
2949 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2950 (replace-match "," t t))
2951 (goto-char (point-min))
2952 ;; Remove trailing commas.
2953 (when (re-search-forward ",+$" nil t)
2954 (replace-match "" t t))))))
2956 (defun message-make-date (&optional now)
2957 "Make a valid data header.
2958 If NOW, use that time instead."
2959 (let* ((now (or now (current-time)))
2960 (zone (nth 8 (decode-time now)))
2961 (sign "+"))
2962 (when (< zone 0)
2963 (setq sign "-")
2964 (setq zone (- zone)))
2965 (concat
2966 (format-time-string "%d" now)
2967 ;; The month name of the %b spec is locale-specific. Pfff.
2968 (format " %s "
2969 (capitalize (car (rassoc (nth 4 (decode-time now))
2970 parse-time-months))))
2971 (format-time-string "%Y %H:%M:%S " now)
2972 ;; We do all of this because XEmacs doesn't have the %z spec.
2973 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
2975 (defun message-make-message-id ()
2976 "Make a unique Message-ID."
2977 (concat "<" (message-unique-id)
2978 (let ((psubject (save-excursion (message-fetch-field "subject")))
2979 (psupersedes
2980 (save-excursion (message-fetch-field "supersedes"))))
2981 (if (or
2982 (and message-reply-headers
2983 (mail-header-references message-reply-headers)
2984 (mail-header-subject message-reply-headers)
2985 psubject
2986 (mail-header-subject message-reply-headers)
2987 (not (string=
2988 (message-strip-subject-re
2989 (mail-header-subject message-reply-headers))
2990 (message-strip-subject-re psubject))))
2991 (and psupersedes
2992 (string-match "_-_@" psupersedes)))
2993 "_-_" ""))
2994 "@" (message-make-fqdn) ">"))
2996 (defvar message-unique-id-char nil)
2998 ;; If you ever change this function, make sure the new version
2999 ;; cannot generate IDs that the old version could.
3000 ;; You might for example insert a "." somewhere (not next to another dot
3001 ;; or string boundary), or modify the "fsf" string.
3002 (defun message-unique-id ()
3003 ;; Don't use microseconds from (current-time), they may be unsupported.
3004 ;; Instead we use this randomly inited counter.
3005 (setq message-unique-id-char
3006 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3007 ;; (current-time) returns 16-bit ints,
3008 ;; and 2^16*25 just fits into 4 digits i base 36.
3009 (* 25 25)))
3010 (let ((tm (current-time)))
3011 (concat
3012 (if (memq system-type '(ms-dos emx vax-vms))
3013 (let ((user (downcase (user-login-name))))
3014 (while (string-match "[^a-z0-9_]" user)
3015 (aset user (match-beginning 0) ?_))
3016 user)
3017 (message-number-base36 (user-uid) -1))
3018 (message-number-base36 (+ (car tm)
3019 (lsh (% message-unique-id-char 25) 16)) 4)
3020 (message-number-base36 (+ (nth 1 tm)
3021 (lsh (/ message-unique-id-char 25) 16)) 4)
3022 ;; Append the newsreader name, because while the generated
3023 ;; ID is unique to this newsreader, other newsreaders might
3024 ;; otherwise generate the same ID via another algorithm.
3025 ".fsf")))
3027 (defun message-number-base36 (num len)
3028 (if (if (< len 0)
3029 (<= num 0)
3030 (= len 0))
3032 (concat (message-number-base36 (/ num 36) (1- len))
3033 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3034 (% num 36))))))
3036 (defun message-make-organization ()
3037 "Make an Organization header."
3038 (let* ((organization
3039 (when message-user-organization
3040 (if (message-functionp message-user-organization)
3041 (funcall message-user-organization)
3042 message-user-organization))))
3043 (save-excursion
3044 (message-set-work-buffer)
3045 (cond ((stringp organization)
3046 (insert organization))
3047 ((and (eq t organization)
3048 message-user-organization-file
3049 (file-exists-p message-user-organization-file))
3050 (insert-file-contents message-user-organization-file)))
3051 (goto-char (point-min))
3052 (while (re-search-forward "[\t\n]+" nil t)
3053 (replace-match "" t t))
3054 (unless (zerop (buffer-size))
3055 (buffer-string)))))
3057 (defun message-make-lines ()
3058 "Count the number of lines and return numeric string."
3059 (save-excursion
3060 (save-restriction
3061 (widen)
3062 (goto-char (point-min))
3063 (re-search-forward
3064 (concat "^" (regexp-quote mail-header-separator) "$"))
3065 (forward-line 1)
3066 (int-to-string (count-lines (point) (point-max))))))
3068 (defun message-make-in-reply-to ()
3069 "Return the In-Reply-To header for this message."
3070 (when message-reply-headers
3071 (mail-header-message-id message-reply-headers)))
3073 (defun message-make-distribution ()
3074 "Make a Distribution header."
3075 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3076 (cond ((message-functionp message-distribution-function)
3077 (funcall message-distribution-function))
3078 (t orig-distribution))))
3080 (defun message-make-expires ()
3081 "Return an Expires header based on `message-expires'."
3082 (let ((current (current-time))
3083 (future (* 1.0 message-expires 60 60 24)))
3084 ;; Add the future to current.
3085 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3086 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3087 (message-make-date current)))
3089 (defun message-make-path ()
3090 "Return uucp path."
3091 (let ((login-name (user-login-name)))
3092 (cond ((null message-user-path)
3093 (concat (system-name) "!" login-name))
3094 ((stringp message-user-path)
3095 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3096 (concat message-user-path "!" login-name))
3097 (t login-name))))
3099 (defun message-make-from ()
3100 "Make a From header."
3101 (let* ((style message-from-style)
3102 (login (message-make-address))
3103 (fullname
3104 (or (and (boundp 'user-full-name)
3105 user-full-name)
3106 (user-full-name))))
3107 (when (string= fullname "&")
3108 (setq fullname (user-login-name)))
3109 (save-excursion
3110 (message-set-work-buffer)
3111 (cond
3112 ((or (null style)
3113 (equal fullname ""))
3114 (insert login))
3115 ((or (eq style 'angles)
3116 (and (not (eq style 'parens))
3117 ;; Use angles if no quoting is needed, or if parens would
3118 ;; need quoting too.
3119 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3120 (let ((tmp (concat fullname nil)))
3121 (while (string-match "([^()]*)" tmp)
3122 (aset tmp (match-beginning 0) ?-)
3123 (aset tmp (1- (match-end 0)) ?-))
3124 (string-match "[\\()]" tmp)))))
3125 (insert fullname)
3126 (goto-char (point-min))
3127 ;; Look for a character that cannot appear unquoted
3128 ;; according to RFC 822.
3129 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3130 ;; Quote fullname, escaping specials.
3131 (goto-char (point-min))
3132 (insert "\"")
3133 (while (re-search-forward "[\"\\]" nil 1)
3134 (replace-match "\\\\\\&" t))
3135 (insert "\""))
3136 (insert " <" login ">"))
3137 (t ; 'parens or default
3138 (insert login " (")
3139 (let ((fullname-start (point)))
3140 (insert fullname)
3141 (goto-char fullname-start)
3142 ;; RFC 822 says \ and nonmatching parentheses
3143 ;; must be escaped in comments.
3144 ;; Escape every instance of ()\ ...
3145 (while (re-search-forward "[()\\]" nil 1)
3146 (replace-match "\\\\\\&" t))
3147 ;; ... then undo escaping of matching parentheses,
3148 ;; including matching nested parentheses.
3149 (goto-char fullname-start)
3150 (while (re-search-forward
3151 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3152 nil 1)
3153 (replace-match "\\1(\\3)" t)
3154 (goto-char fullname-start)))
3155 (insert ")")))
3156 (buffer-string))))
3158 (defun message-make-sender ()
3159 "Return the \"real\" user address.
3160 This function tries to ignore all user modifications, and
3161 give as trustworthy answer as possible."
3162 (concat (user-login-name) "@" (system-name)))
3164 (defun message-make-address ()
3165 "Make the address of the user."
3166 (or (message-user-mail-address)
3167 (concat (user-login-name) "@" (message-make-domain))))
3169 (defun message-user-mail-address ()
3170 "Return the pertinent part of `user-mail-address'."
3171 (when user-mail-address
3172 (if (string-match " " user-mail-address)
3173 (nth 1 (mail-extract-address-components user-mail-address))
3174 user-mail-address)))
3176 (defun message-make-fqdn ()
3177 "Return user's fully qualified domain name."
3178 (let ((system-name (system-name))
3179 (user-mail (message-user-mail-address)))
3180 (cond
3181 ((string-match "[^.]\\.[^.]" system-name)
3182 ;; `system-name' returned the right result.
3183 system-name)
3184 ;; Try `mail-host-address'.
3185 ((and (boundp 'mail-host-address)
3186 (stringp mail-host-address)
3187 (string-match "\\." mail-host-address))
3188 mail-host-address)
3189 ;; We try `user-mail-address' as a backup.
3190 ((and user-mail
3191 (string-match "\\." user-mail)
3192 (string-match "@\\(.*\\)\\'" user-mail))
3193 (match-string 1 user-mail))
3194 ;; Default to this bogus thing.
3196 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3198 (defun message-make-host-name ()
3199 "Return the name of the host."
3200 (let ((fqdn (message-make-fqdn)))
3201 (string-match "^[^.]+\\." fqdn)
3202 (substring fqdn 0 (1- (match-end 0)))))
3204 (defun message-make-domain ()
3205 "Return the domain name."
3206 (or mail-host-address
3207 (message-make-fqdn)))
3209 (defun message-generate-headers (headers)
3210 "Prepare article HEADERS.
3211 Headers already prepared in the buffer are not modified."
3212 (save-restriction
3213 (message-narrow-to-headers)
3214 (let* ((Date (message-make-date))
3215 (Message-ID (message-make-message-id))
3216 (Organization (message-make-organization))
3217 (From (message-make-from))
3218 (Path (message-make-path))
3219 (Subject nil)
3220 (Newsgroups nil)
3221 (In-Reply-To (message-make-in-reply-to))
3222 (To nil)
3223 (Distribution (message-make-distribution))
3224 (Lines (message-make-lines))
3225 (User-Agent message-newsreader)
3226 (Expires (message-make-expires))
3227 (case-fold-search t)
3228 header value elem)
3229 ;; First we remove any old generated headers.
3230 (let ((headers message-deletable-headers))
3231 (unless (buffer-modified-p)
3232 (setq headers (delq 'Message-ID (copy-sequence headers))))
3233 (while headers
3234 (goto-char (point-min))
3235 (and (re-search-forward
3236 (concat "^" (symbol-name (car headers)) ": *") nil t)
3237 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3238 (message-delete-line))
3239 (pop headers)))
3240 ;; Go through all the required headers and see if they are in the
3241 ;; articles already. If they are not, or are empty, they are
3242 ;; inserted automatically - except for Subject, Newsgroups and
3243 ;; Distribution.
3244 (while headers
3245 (goto-char (point-min))
3246 (setq elem (pop headers))
3247 (if (consp elem)
3248 (if (eq (car elem) 'optional)
3249 (setq header (cdr elem))
3250 (setq header (car elem)))
3251 (setq header elem))
3252 (when (or (not (re-search-forward
3253 (concat "^"
3254 (regexp-quote
3255 (downcase
3256 (if (stringp header)
3257 header
3258 (symbol-name header))))
3259 ":")
3260 nil t))
3261 (progn
3262 ;; The header was found. We insert a space after the
3263 ;; colon, if there is none.
3264 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3265 ;; Find out whether the header is empty...
3266 (looking-at "[ \t]*\n[^ \t]")))
3267 ;; So we find out what value we should insert.
3268 (setq value
3269 (cond
3270 ((and (consp elem) (eq (car elem) 'optional))
3271 ;; This is an optional header. If the cdr of this
3272 ;; is something that is nil, then we do not insert
3273 ;; this header.
3274 (setq header (cdr elem))
3275 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3276 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3277 ((consp elem)
3278 ;; The element is a cons. Either the cdr is a
3279 ;; string to be inserted verbatim, or it is a
3280 ;; function, and we insert the value returned from
3281 ;; this function.
3282 (or (and (stringp (cdr elem)) (cdr elem))
3283 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3284 ((and (boundp header) (symbol-value header))
3285 ;; The element is a symbol. We insert the value
3286 ;; of this symbol, if any.
3287 (symbol-value header))
3288 ((not (message-check-element header))
3289 ;; We couldn't generate a value for this header,
3290 ;; so we just ask the user.
3291 (read-from-minibuffer
3292 (format "Empty header for %s; enter value: " header)))))
3293 ;; Finally insert the header.
3294 (when (and value
3295 (not (equal value "")))
3296 (save-excursion
3297 (if (bolp)
3298 (progn
3299 ;; This header didn't exist, so we insert it.
3300 (goto-char (point-max))
3301 (insert (if (stringp header) header (symbol-name header))
3302 ": " value "\n")
3303 (forward-line -1))
3304 ;; The value of this header was empty, so we clear
3305 ;; totally and insert the new value.
3306 (delete-region (point) (gnus-point-at-eol))
3307 (insert value))
3308 ;; Add the deletable property to the headers that require it.
3309 (and (memq header message-deletable-headers)
3310 (progn (beginning-of-line) (looking-at "[^:]+: "))
3311 (add-text-properties
3312 (point) (match-end 0)
3313 '(message-deletable t face italic) (current-buffer)))))))
3314 ;; Insert new Sender if the From is strange.
3315 (let ((from (message-fetch-field "from"))
3316 (sender (message-fetch-field "sender"))
3317 (secure-sender (message-make-sender)))
3318 (when (and from
3319 (not (message-check-element 'sender))
3320 (not (string=
3321 (downcase
3322 (cadr (mail-extract-address-components from)))
3323 (downcase secure-sender)))
3324 (or (null sender)
3325 (not
3326 (string=
3327 (downcase
3328 (cadr (mail-extract-address-components sender)))
3329 (downcase secure-sender)))))
3330 (goto-char (point-min))
3331 ;; Rename any old Sender headers to Original-Sender.
3332 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3333 (beginning-of-line)
3334 (insert "Original-")
3335 (beginning-of-line))
3336 (when (or (message-news-p)
3337 (string-match "@.+\\.." secure-sender))
3338 (insert "Sender: " secure-sender "\n")))))))
3340 (defun message-insert-courtesy-copy ()
3341 "Insert a courtesy message in mail copies of combined messages."
3342 (let (newsgroups)
3343 (save-excursion
3344 (save-restriction
3345 (message-narrow-to-headers)
3346 (when (setq newsgroups (message-fetch-field "newsgroups"))
3347 (goto-char (point-max))
3348 (insert "Posted-To: " newsgroups "\n")))
3349 (forward-line 1)
3350 (when message-courtesy-message
3351 (cond
3352 ((string-match "%s" message-courtesy-message)
3353 (insert (format message-courtesy-message newsgroups)))
3355 (insert message-courtesy-message)))))))
3358 ;;; Setting up a message buffer
3361 (defun message-fill-address (header value)
3362 (save-restriction
3363 (narrow-to-region (point) (point))
3364 (insert (capitalize (symbol-name header))
3365 ": "
3366 (if (consp value) (car value) value)
3367 "\n")
3368 (narrow-to-region (point-min) (1- (point-max)))
3369 (let (quoted last)
3370 (goto-char (point-min))
3371 (while (not (eobp))
3372 (skip-chars-forward "^,\"" (point-max))
3373 (if (or (eq (char-after) ?,)
3374 (eobp))
3375 (when (not quoted)
3376 (if (and (> (current-column) 78)
3377 last)
3378 (progn
3379 (save-excursion
3380 (goto-char last)
3381 (insert "\n\t"))
3382 (setq last (1+ (point))))
3383 (setq last (1+ (point)))))
3384 (setq quoted (not quoted)))
3385 (unless (eobp)
3386 (forward-char 1))))
3387 (goto-char (point-max))
3388 (widen)
3389 (forward-line 1)))
3391 (defun message-fill-header (header value)
3392 (let ((begin (point))
3393 (fill-column 78)
3394 (fill-prefix "\t"))
3395 (insert (capitalize (symbol-name header))
3396 ": "
3397 (if (consp value) (car value) value)
3398 "\n")
3399 (save-restriction
3400 (narrow-to-region begin (point))
3401 (fill-region-as-paragraph begin (point))
3402 ;; Tapdance around looong Message-IDs.
3403 (forward-line -1)
3404 (when (looking-at "[ \t]*$")
3405 (message-delete-line))
3406 (goto-char begin)
3407 (re-search-forward ":" nil t)
3408 (when (looking-at "\n[ \t]+")
3409 (replace-match " " t t))
3410 (goto-char (point-max)))))
3412 (defun message-shorten-1 (list cut surplus)
3413 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3414 (setcdr (nthcdr (- cut 2) list)
3415 (nthcdr (+ (- cut 2) surplus 1) list)))
3417 (defun message-shorten-references (header references)
3418 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3419 If folding is disallowed, also check that the REFERENCES are less
3420 than 988 characters long, and if they are not, trim them until they are."
3421 (let ((maxcount 31)
3422 (count 0)
3423 (cut 6)
3424 refs)
3425 (with-temp-buffer
3426 (insert references)
3427 (goto-char (point-min))
3428 ;; Cons a list of valid references.
3429 (while (re-search-forward "<[^>]+>" nil t)
3430 (push (match-string 0) refs))
3431 (setq refs (nreverse refs)
3432 count (length refs)))
3434 ;; If the list has more than MAXCOUNT elements, trim it by
3435 ;; removing the CUTth element and the required number of
3436 ;; elements that follow.
3437 (when (> count maxcount)
3438 (let ((surplus (- count maxcount)))
3439 (message-shorten-1 refs cut surplus)
3440 (decf count surplus)))
3442 ;; If folding is disallowed, make sure the total length (including
3443 ;; the spaces between) will be less than MAXSIZE characters.
3445 ;; Only disallow folding for News messages. At this point the headers
3446 ;; have not been generated, thus we use message-this-is-news directly.
3447 (when (and message-this-is-news message-cater-to-broken-inn)
3448 (let ((maxsize 988)
3449 (totalsize (+ (apply #'+ (mapcar #'length refs))
3450 (1- count)))
3451 (surplus 0)
3452 (ptr (nthcdr (1- cut) refs)))
3453 ;; Decide how many elements to cut off...
3454 (while (> totalsize maxsize)
3455 (decf totalsize (1+ (length (car ptr))))
3456 (incf surplus)
3457 (setq ptr (cdr ptr)))
3458 ;; ...and do it.
3459 (when (> surplus 0)
3460 (message-shorten-1 refs cut surplus))))
3462 ;; Finally, collect the references back into a string and insert
3463 ;; it into the buffer.
3464 (let ((refstring (mapconcat #'identity refs " ")))
3465 (if (and message-this-is-news message-cater-to-broken-inn)
3466 (insert (capitalize (symbol-name header)) ": "
3467 refstring "\n")
3468 (message-fill-header header refstring)))))
3470 (defun message-position-point ()
3471 "Move point to where the user probably wants to find it."
3472 (message-narrow-to-headers)
3473 (cond
3474 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3475 (search-backward ":" )
3476 (widen)
3477 (forward-char 1)
3478 (if (eq (char-after) ? )
3479 (forward-char 1)
3480 (insert " ")))
3482 (goto-char (point-max))
3483 (widen)
3484 (forward-line 1)
3485 (unless (looking-at "$")
3486 (forward-line 2)))
3487 (sit-for 0)))
3489 (defun message-buffer-name (type &optional to group)
3490 "Return a new (unique) buffer name based on TYPE and TO."
3491 (cond
3492 ;; Generate a new buffer name The Message Way.
3493 ((eq message-generate-new-buffers 'unique)
3494 (generate-new-buffer-name
3495 (concat "*" type
3496 (if to
3497 (concat " to "
3498 (or (car (mail-extract-address-components to))
3499 to) "")
3501 (if (and group (not (string= group ""))) (concat " on " group) "")
3502 "*")))
3503 ;; Check whether `message-generate-new-buffers' is a function,
3504 ;; and if so, call it.
3505 ((message-functionp message-generate-new-buffers)
3506 (funcall message-generate-new-buffers type to group))
3507 ((eq message-generate-new-buffers 'unsent)
3508 (generate-new-buffer-name
3509 (concat "*unsent " type
3510 (if to
3511 (concat " to "
3512 (or (car (mail-extract-address-components to))
3513 to) "")
3515 (if (and group (not (string= group ""))) (concat " on " group) "")
3516 "*")))
3517 ;; Use standard name.
3519 (format "*%s message*" type))))
3521 (defun message-pop-to-buffer (name)
3522 "Pop to buffer NAME, and warn if it already exists and is modified."
3523 (let ((buffer (get-buffer name)))
3524 (if (and buffer
3525 (buffer-name buffer))
3526 (progn
3527 (set-buffer (pop-to-buffer buffer))
3528 (when (and (buffer-modified-p)
3529 (not (y-or-n-p
3530 "Message already being composed; erase? ")))
3531 (error "Message being composed")))
3532 (set-buffer (pop-to-buffer name)))
3533 (erase-buffer)
3534 (message-mode)))
3536 (defun message-do-send-housekeeping ()
3537 "Kill old message buffers."
3538 ;; We might have sent this buffer already. Delete it from the
3539 ;; list of buffers.
3540 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3541 (while (and message-max-buffers
3542 message-buffer-list
3543 (>= (length message-buffer-list) message-max-buffers))
3544 ;; Kill the oldest buffer -- unless it has been changed.
3545 (let ((buffer (pop message-buffer-list)))
3546 (when (and (buffer-name buffer)
3547 (not (buffer-modified-p buffer)))
3548 (kill-buffer buffer))))
3549 ;; Rename the buffer.
3550 (if message-send-rename-function
3551 (funcall message-send-rename-function)
3552 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3553 (rename-buffer
3554 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3555 ;; Push the current buffer onto the list.
3556 (when message-max-buffers
3557 (setq message-buffer-list
3558 (nconc message-buffer-list (list (current-buffer))))))
3560 (eval-when-compile (defvar mc-modes-alist))
3561 (defun message-setup (headers &optional replybuffer actions)
3562 (when (and (boundp 'mc-modes-alist)
3563 (not (assq 'message-mode mc-modes-alist)))
3564 (push '(message-mode (encrypt . mc-encrypt-message)
3565 (sign . mc-sign-message))
3566 mc-modes-alist))
3567 (when actions
3568 (setq message-send-actions actions))
3569 (setq message-reply-buffer replybuffer)
3570 (goto-char (point-min))
3571 ;; Insert all the headers.
3572 (mail-header-format
3573 (let ((h headers)
3574 (alist message-header-format-alist))
3575 (while h
3576 (unless (assq (caar h) message-header-format-alist)
3577 (push (list (caar h)) alist))
3578 (pop h))
3579 alist)
3580 headers)
3581 (delete-region (point) (progn (forward-line -1) (point)))
3582 (when message-default-headers
3583 (insert message-default-headers)
3584 (or (bolp) (insert ?\n)))
3585 (put-text-property
3586 (point)
3587 (progn
3588 (insert mail-header-separator "\n")
3589 (1- (point)))
3590 'read-only nil)
3591 (forward-line -1)
3592 (when (message-news-p)
3593 (when message-default-news-headers
3594 (insert message-default-news-headers)
3595 (or (bolp) (insert ?\n)))
3596 (when message-generate-headers-first
3597 (message-generate-headers
3598 (delq 'Lines
3599 (delq 'Subject
3600 (copy-sequence message-required-news-headers))))))
3601 (when (message-mail-p)
3602 (when message-default-mail-headers
3603 (insert message-default-mail-headers)
3604 (or (bolp) (insert ?\n)))
3605 (when message-generate-headers-first
3606 (message-generate-headers
3607 (delq 'Lines
3608 (delq 'Subject
3609 (copy-sequence message-required-mail-headers))))))
3610 (run-hooks 'message-signature-setup-hook)
3611 (message-insert-signature)
3612 (save-restriction
3613 (message-narrow-to-headers)
3614 (if message-alternative-emails
3615 (message-use-alternative-email-as-from))
3616 (run-hooks 'message-header-setup-hook))
3617 (set-buffer-modified-p nil)
3618 (setq buffer-undo-list nil)
3619 (run-hooks 'message-setup-hook)
3620 (message-position-point)
3621 (undo-boundary))
3623 (defun message-set-auto-save-file-name ()
3624 "Associate the message buffer with a file in the drafts directory."
3625 (when message-auto-save-directory
3626 (if (gnus-alive-p)
3627 (setq message-draft-article
3628 (nndraft-request-associate-buffer "drafts"))
3629 (setq buffer-file-name (expand-file-name "*message*"
3630 message-auto-save-directory))
3631 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3632 (clear-visited-file-modtime)
3633 (setq buffer-file-coding-system message-draft-coding-system)))
3635 (defun message-disassociate-draft ()
3636 "Disassociate the message buffer from the drafts directory."
3637 (when message-draft-article
3638 (nndraft-request-expire-articles
3639 (list message-draft-article) "drafts" nil t)))
3641 (defun message-insert-headers ()
3642 "Generate the headers for the article."
3643 (interactive)
3644 (save-excursion
3645 (save-restriction
3646 (message-narrow-to-headers)
3647 (when (message-news-p)
3648 (message-generate-headers
3649 (delq 'Lines
3650 (delq 'Subject
3651 (copy-sequence message-required-news-headers)))))
3652 (when (message-mail-p)
3653 (message-generate-headers
3654 (delq 'Lines
3655 (delq 'Subject
3656 (copy-sequence message-required-mail-headers))))))))
3661 ;;; Commands for interfacing with message
3664 ;;;###autoload
3665 (defun message-mail (&optional to subject
3666 other-headers continue switch-function
3667 yank-action send-actions)
3668 "Start editing a mail message to be sent.
3669 OTHER-HEADERS is an alist of header/value pairs."
3670 (interactive)
3671 (let ((message-this-is-mail t))
3672 (message-pop-to-buffer (message-buffer-name "mail" to))
3673 (message-setup
3674 (nconc
3675 `((To . ,(or to "")) (Subject . ,(or subject "")))
3676 (when other-headers other-headers)))))
3678 ;;;###autoload
3679 (defun message-news (&optional newsgroups subject)
3680 "Start editing a news article to be sent."
3681 (interactive)
3682 (let ((message-this-is-news t))
3683 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3684 (message-setup `((Newsgroups . ,(or newsgroups ""))
3685 (Subject . ,(or subject ""))))))
3687 (defun message-get-reply-headers (wide &optional to-address)
3688 (let (follow-to mct never-mct from to cc reply-to ccalist)
3689 ;; Find all relevant headers we need.
3690 (setq from (message-fetch-field "from")
3691 to (message-fetch-field "to")
3692 cc (message-fetch-field "cc")
3693 mct (message-fetch-field "mail-copies-to")
3694 reply-to (message-fetch-field "reply-to"))
3696 ;; Handle special values of Mail-Copies-To.
3697 (when mct
3698 (cond ((or (equal (downcase mct) "never")
3699 (equal (downcase mct) "nobody"))
3700 (setq never-mct t)
3701 (setq mct nil))
3702 ((or (equal (downcase mct) "always")
3703 (equal (downcase mct) "poster"))
3704 (setq mct (or reply-to from)))))
3706 (if (or (not wide)
3707 to-address)
3708 (progn
3709 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3710 (when (and wide mct)
3711 (push (cons 'Cc mct) follow-to)))
3712 (let (ccalist)
3713 (save-excursion
3714 (message-set-work-buffer)
3715 (unless never-mct
3716 (insert (or reply-to from "")))
3717 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3718 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3719 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3720 (goto-char (point-min))
3721 (while (re-search-forward "[ \t]+" nil t)
3722 (replace-match " " t t))
3723 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3724 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
3725 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3726 (erase-buffer))))
3727 (goto-char (point-min))
3728 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3729 (when (eobp)
3730 (insert (or reply-to from "")))
3731 (setq ccalist
3732 (mapcar
3733 (lambda (addr)
3734 (cons (mail-strip-quoted-names addr) addr))
3735 (message-tokenize-header (buffer-string))))
3736 (let ((s ccalist))
3737 (while s
3738 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3739 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3740 (when ccalist
3741 (let ((ccs (cons 'Cc (mapconcat
3742 (lambda (addr) (cdr addr)) ccalist ", "))))
3743 (when (string-match "^ +" (cdr ccs))
3744 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3745 (push ccs follow-to)))))
3746 follow-to))
3749 ;;;###autoload
3750 (defun message-reply (&optional to-address wide)
3751 "Start editing a reply to the article in the current buffer."
3752 (interactive)
3753 (require 'gnus-sum) ; for gnus-list-identifiers
3754 (let ((cur (current-buffer))
3755 from subject date reply-to to cc
3756 references message-id follow-to
3757 (inhibit-point-motion-hooks t)
3758 (message-this-is-mail t)
3759 gnus-warning)
3760 (save-restriction
3761 (message-narrow-to-head)
3762 ;; Allow customizations to have their say.
3763 (if (not wide)
3764 ;; This is a regular reply.
3765 (if (message-functionp message-reply-to-function)
3766 (setq follow-to (funcall message-reply-to-function)))
3767 ;; This is a followup.
3768 (if (message-functionp message-wide-reply-to-function)
3769 (save-excursion
3770 (setq follow-to
3771 (funcall message-wide-reply-to-function)))))
3772 (setq message-id (message-fetch-field "message-id" t)
3773 references (message-fetch-field "references")
3774 date (message-fetch-field "date")
3775 from (message-fetch-field "from")
3776 subject (or (message-fetch-field "subject") "none"))
3777 (if gnus-list-identifiers
3778 (setq subject (message-strip-list-identifiers subject)))
3779 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3781 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3782 (string-match "<[^>]+>" gnus-warning))
3783 (setq message-id (match-string 0 gnus-warning)))
3785 (unless follow-to
3786 (setq follow-to (message-get-reply-headers wide to-address))))
3788 (message-pop-to-buffer
3789 (message-buffer-name
3790 (if wide "wide reply" "reply") from
3791 (if wide to-address nil)))
3793 (setq message-reply-headers
3794 (vector 0 subject from date message-id references 0 0 ""))
3796 (message-setup
3797 `((Subject . ,subject)
3798 ,@follow-to
3799 ,@(if (or references message-id)
3800 `((References . ,(concat (or references "") (and references " ")
3801 (or message-id ""))))
3802 nil))
3803 cur)))
3805 ;;;###autoload
3806 (defun message-wide-reply (&optional to-address)
3807 "Make a \"wide\" reply to the message in the current buffer."
3808 (interactive)
3809 (message-reply to-address t))
3811 ;;;###autoload
3812 (defun message-followup (&optional to-newsgroups)
3813 "Follow up to the message in the current buffer.
3814 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3815 (interactive)
3816 (require 'gnus-sum) ; for gnus-list-identifiers
3817 (let ((cur (current-buffer))
3818 from subject date reply-to mct
3819 references message-id follow-to
3820 (inhibit-point-motion-hooks t)
3821 (message-this-is-news t)
3822 followup-to distribution newsgroups gnus-warning posted-to)
3823 (save-restriction
3824 (narrow-to-region
3825 (goto-char (point-min))
3826 (if (search-forward "\n\n" nil t)
3827 (1- (point))
3828 (point-max)))
3829 (when (message-functionp message-followup-to-function)
3830 (setq follow-to
3831 (funcall message-followup-to-function)))
3832 (setq from (message-fetch-field "from")
3833 date (message-fetch-field "date")
3834 subject (or (message-fetch-field "subject") "none")
3835 references (message-fetch-field "references")
3836 message-id (message-fetch-field "message-id" t)
3837 followup-to (message-fetch-field "followup-to")
3838 newsgroups (message-fetch-field "newsgroups")
3839 posted-to (message-fetch-field "posted-to")
3840 reply-to (message-fetch-field "reply-to")
3841 distribution (message-fetch-field "distribution")
3842 mct (message-fetch-field "mail-copies-to"))
3843 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3844 (string-match "<[^>]+>" gnus-warning))
3845 (setq message-id (match-string 0 gnus-warning)))
3846 ;; Remove bogus distribution.
3847 (when (and (stringp distribution)
3848 (let ((case-fold-search t))
3849 (string-match "world" distribution)))
3850 (setq distribution nil))
3851 (if gnus-list-identifiers
3852 (setq subject (message-strip-list-identifiers subject)))
3853 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3854 (widen))
3856 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3858 (message-setup
3859 `((Subject . ,subject)
3860 ,@(cond
3861 (to-newsgroups
3862 (list (cons 'Newsgroups to-newsgroups)))
3863 (follow-to follow-to)
3864 ((and followup-to message-use-followup-to)
3865 (list
3866 (cond
3867 ((equal (downcase followup-to) "poster")
3868 (if (or (eq message-use-followup-to 'use)
3869 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3870 You should normally obey the Followup-To: header.
3872 `Followup-To: poster' sends your response via e-mail instead of news.
3874 A typical situation where `Followup-To: poster' is used is when the poster
3875 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3876 (progn
3877 (setq message-this-is-news nil)
3878 (cons 'To (or reply-to from "")))
3879 (cons 'Newsgroups newsgroups)))
3881 (if (or (equal followup-to newsgroups)
3882 (not (eq message-use-followup-to 'ask))
3883 (message-y-or-n-p
3884 (concat "Obey Followup-To: " followup-to "? ") t "\
3885 You should normally obey the Followup-To: header.
3887 `Followup-To: " followup-to "'
3888 directs your response to " (if (string-match "," followup-to)
3889 "the specified newsgroups"
3890 "that newsgroup only") ".
3892 If a message is posted to several newsgroups, Followup-To is often
3893 used to direct the following discussion to one newsgroup only,
3894 because discussions that are spread over several newsgroup tend to
3895 be fragmented and very difficult to follow.
3897 Also, some source/announcement newsgroups are not indented for discussion;
3898 responses here are directed to other newsgroups."))
3899 (cons 'Newsgroups followup-to)
3900 (cons 'Newsgroups newsgroups))))))
3901 (posted-to
3902 `((Newsgroups . ,posted-to)))
3904 `((Newsgroups . ,newsgroups))))
3905 ,@(and distribution (list (cons 'Distribution distribution)))
3906 ,@(if (or references message-id)
3907 `((References . ,(concat (or references "") (and references " ")
3908 (or message-id "")))))
3909 ,@(when (and mct
3910 (not (or (equal (downcase mct) "never")
3911 (equal (downcase mct) "nobody"))))
3912 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3913 (equal (downcase mct) "poster"))
3914 (or reply-to from "")
3915 mct)))))
3917 cur)
3919 (setq message-reply-headers
3920 (vector 0 subject from date message-id references 0 0 ""))))
3923 ;;;###autoload
3924 (defun message-cancel-news (&optional arg)
3925 "Cancel an article you posted.
3926 If ARG, allow editing of the cancellation message."
3927 (interactive "P")
3928 (unless (message-news-p)
3929 (error "This is not a news article; canceling is impossible"))
3930 (when (yes-or-no-p "Do you really want to cancel this article? ")
3931 (let (from newsgroups message-id distribution buf sender)
3932 (save-excursion
3933 ;; Get header info from original article.
3934 (save-restriction
3935 (message-narrow-to-head)
3936 (setq from (message-fetch-field "from")
3937 sender (message-fetch-field "sender")
3938 newsgroups (message-fetch-field "newsgroups")
3939 message-id (message-fetch-field "message-id" t)
3940 distribution (message-fetch-field "distribution")))
3941 ;; Make sure that this article was written by the user.
3942 (unless (or (and sender
3943 (string-equal
3944 (downcase sender)
3945 (downcase (message-make-sender))))
3946 (string-equal
3947 (downcase (cadr (mail-extract-address-components from)))
3948 (downcase (cadr (mail-extract-address-components
3949 (message-make-from))))))
3950 (error "This article is not yours"))
3951 ;; Make control message.
3952 (if arg
3953 (message-news)
3954 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
3955 (erase-buffer)
3956 (insert "Newsgroups: " newsgroups "\n"
3957 "From: " from "\n"
3958 "Subject: cmsg cancel " message-id "\n"
3959 "Control: cancel " message-id "\n"
3960 (if distribution
3961 (concat "Distribution: " distribution "\n")
3963 mail-header-separator "\n"
3964 message-cancel-message)
3965 (run-hooks 'message-cancel-hook)
3966 (unless arg
3967 (message "Canceling your article...")
3968 (if (let ((message-syntax-checks
3969 'dont-check-for-anything-just-trust-me))
3970 (funcall message-send-news-function))
3971 (message "Canceling your article...done"))
3972 (kill-buffer buf))))))
3974 ;;;###autoload
3975 (defun message-supersede ()
3976 "Start composing a message to supersede the current message.
3977 This is done simply by taking the old article and adding a Supersedes
3978 header line with the old Message-ID."
3979 (interactive)
3980 (let ((cur (current-buffer))
3981 (sender (message-fetch-field "sender"))
3982 (from (message-fetch-field "from")))
3983 ;; Check whether the user owns the article that is to be superseded.
3984 (unless (or (and sender
3985 (string-equal
3986 (downcase sender)
3987 (downcase (message-make-sender))))
3988 (string-equal
3989 (downcase (cadr (mail-extract-address-components from)))
3990 (downcase (cadr (mail-extract-address-components
3991 (message-make-from))))))
3992 (error "This article is not yours"))
3993 ;; Get a normal message buffer.
3994 (message-pop-to-buffer (message-buffer-name "supersede"))
3995 (insert-buffer-substring cur)
3996 (mime-to-mml)
3997 (message-narrow-to-head)
3998 ;; Remove unwanted headers.
3999 (when message-ignored-supersedes-headers
4000 (message-remove-header message-ignored-supersedes-headers t))
4001 (goto-char (point-min))
4002 (if (not (re-search-forward "^Message-ID: " nil t))
4003 (error "No Message-ID in this article")
4004 (replace-match "Supersedes: " t t))
4005 (goto-char (point-max))
4006 (insert mail-header-separator)
4007 (widen)
4008 (forward-line 1)))
4010 ;;;###autoload
4011 (defun message-recover ()
4012 "Reread contents of current buffer from its last auto-save file."
4013 (interactive)
4014 (let ((file-name (make-auto-save-file-name)))
4015 (cond ((save-window-excursion
4016 (if (not (eq system-type 'vax-vms))
4017 (with-output-to-temp-buffer "*Directory*"
4018 (with-current-buffer standard-output
4019 (fundamental-mode)) ; for Emacs 20.4+
4020 (buffer-disable-undo standard-output)
4021 (let ((default-directory "/"))
4022 (call-process
4023 "ls" nil standard-output nil "-l" file-name))))
4024 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4025 (let ((buffer-read-only nil))
4026 (erase-buffer)
4027 (insert-file-contents file-name nil)))
4028 (t (error "message-recover cancelled")))))
4030 ;;; Washing Subject:
4032 (defun message-wash-subject (subject)
4033 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4034 (with-temp-buffer
4035 (insert-string subject)
4036 (goto-char (point-min))
4037 ;; strip Re/Fwd stuff off the beginning
4038 (while (re-search-forward
4039 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4040 (replace-match ""))
4042 ;; and gnus-style forwards [foo@bar.com] subject
4043 (goto-char (point-min))
4044 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4045 (replace-match ""))
4047 ;; and off the end
4048 (goto-char (point-max))
4049 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4050 (replace-match ""))
4052 ;; and finally, any whitespace that was left-over
4053 (goto-char (point-min))
4054 (while (re-search-forward "^[ \t]+" nil t)
4055 (replace-match ""))
4056 (goto-char (point-max))
4057 (while (re-search-backward "[ \t]+$" nil t)
4058 (replace-match ""))
4060 (buffer-string)))
4062 ;;; Forwarding messages.
4064 (defun message-forward-subject-author-subject (subject)
4065 "Generate a subject for a forwarded message.
4066 The form is: [Source] Subject, where if the original message was mail,
4067 Source is the sender, and if the original message was news, Source is
4068 the list of newsgroups is was posted to."
4069 (concat "["
4070 (or (message-fetch-field
4071 (if (message-news-p) "newsgroups" "from"))
4072 "(nowhere)")
4073 "] " subject))
4075 (defun message-forward-subject-fwd (subject)
4076 "Generate a subject for a forwarded message.
4077 The form is: Fwd: Subject, where Subject is the original subject of
4078 the message."
4079 (concat "Fwd: " subject))
4081 (defun message-make-forward-subject ()
4082 "Return a Subject header suitable for the message in the current buffer."
4083 (save-excursion
4084 (save-restriction
4085 (current-buffer)
4086 (message-narrow-to-head)
4087 (let ((funcs message-make-forward-subject-function)
4088 (subject (if message-wash-forwarded-subjects
4089 (message-wash-subject
4090 (or (message-fetch-field "Subject") ""))
4091 (or (message-fetch-field "Subject") ""))))
4092 ;; Make sure funcs is a list.
4093 (and funcs
4094 (not (listp funcs))
4095 (setq funcs (list funcs)))
4096 ;; Apply funcs in order, passing subject generated by previous
4097 ;; func to the next one.
4098 (while funcs
4099 (when (message-functionp (car funcs))
4100 (setq subject (funcall (car funcs) subject)))
4101 (setq funcs (cdr funcs)))
4102 subject))))
4104 ;;;###autoload
4105 (defun message-forward (&optional news digest)
4106 "Forward the current message via mail.
4107 Optional NEWS will use news to forward instead of mail.
4108 Optional DIGEST will use digest to forward."
4109 (interactive "P")
4110 (let* ((cur (current-buffer))
4111 (subject (if message-forward-show-mml
4112 (message-make-forward-subject)
4113 (mail-decode-encoded-word-string
4114 (message-make-forward-subject))))
4115 art-beg)
4116 (if news
4117 (message-news nil subject)
4118 (message-mail nil subject))
4119 ;; Put point where we want it before inserting the forwarded
4120 ;; message.
4121 (if message-forward-before-signature
4122 (message-goto-body)
4123 (goto-char (point-max)))
4124 (if message-forward-as-mime
4125 (if digest
4126 (insert "\n<#multipart type=digest>\n")
4127 (if message-forward-show-mml
4128 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4129 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4130 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4131 (let ((b (point)) e)
4132 (if digest
4133 (if message-forward-as-mime
4134 (insert-buffer-substring cur)
4135 (mml-insert-buffer cur))
4136 (if message-forward-show-mml
4137 (insert-buffer-substring cur)
4138 (mml-insert-buffer cur)))
4139 (setq e (point))
4140 (if message-forward-as-mime
4141 (if digest
4142 (insert "<#/multipart>\n")
4143 (if message-forward-show-mml
4144 (insert "<#/mml>\n")
4145 (insert "<#/part>\n")))
4146 (insert "\n-------------------- End of forwarded message --------------------\n"))
4147 (if (and digest message-forward-as-mime)
4148 (save-restriction
4149 (narrow-to-region b e)
4150 (goto-char b)
4151 (narrow-to-region (point)
4152 (or (search-forward "\n\n" nil t) (point)))
4153 (delete-region (point-min) (point-max)))
4154 (when (and (not current-prefix-arg)
4155 message-forward-ignored-headers)
4156 (save-restriction
4157 (narrow-to-region b e)
4158 (goto-char b)
4159 (narrow-to-region (point)
4160 (or (search-forward "\n\n" nil t) (point)))
4161 (message-remove-header message-forward-ignored-headers t)))))
4162 (message-position-point)))
4164 ;;;###autoload
4165 (defun message-resend (address)
4166 "Resend the current article to ADDRESS."
4167 (interactive
4168 (list (message-read-from-minibuffer "Resend message to: ")))
4169 (message "Resending message to %s..." address)
4170 (save-excursion
4171 (let ((cur (current-buffer))
4172 beg)
4173 ;; We first set up a normal mail buffer.
4174 (set-buffer (get-buffer-create " *message resend*"))
4175 (erase-buffer)
4176 (message-setup `((To . ,address)))
4177 ;; Insert our usual headers.
4178 (message-generate-headers '(From Date To))
4179 (message-narrow-to-headers)
4180 ;; Rename them all to "Resent-*".
4181 (while (re-search-forward "^[A-Za-z]" nil t)
4182 (forward-char -1)
4183 (insert "Resent-"))
4184 (widen)
4185 (forward-line)
4186 (delete-region (point) (point-max))
4187 (setq beg (point))
4188 ;; Insert the message to be resent.
4189 (insert-buffer-substring cur)
4190 (goto-char (point-min))
4191 (search-forward "\n\n")
4192 (forward-char -1)
4193 (save-restriction
4194 (narrow-to-region beg (point))
4195 (message-remove-header message-ignored-resent-headers t)
4196 (goto-char (point-max)))
4197 (insert mail-header-separator)
4198 ;; Rename all old ("Also-")Resent headers.
4199 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4200 (beginning-of-line)
4201 (insert "Also-"))
4202 ;; Quote any "From " lines at the beginning.
4203 (goto-char beg)
4204 (when (looking-at "From ")
4205 (replace-match "X-From-Line: "))
4206 ;; Send it.
4207 (let ((message-inhibit-body-encoding t)
4208 message-required-mail-headers)
4209 (message-send-mail))
4210 (kill-buffer (current-buffer)))
4211 (message "Resending message to %s...done" address)))
4213 ;;;###autoload
4214 (defun message-bounce ()
4215 "Re-mail the current message.
4216 This only makes sense if the current message is a bounce message that
4217 contains some mail you have written which has been bounced back to
4218 you."
4219 (interactive)
4220 (let ((handles (mm-dissect-buffer t))
4221 boundary)
4222 (message-pop-to-buffer (message-buffer-name "bounce"))
4223 (if (stringp (car handles))
4224 ;; This is a MIME bounce.
4225 (mm-insert-part (car (last handles)))
4226 ;; This is a non-MIME bounce, so we try to remove things
4227 ;; manually.
4228 (mm-insert-part handles)
4229 (undo-boundary)
4230 (goto-char (point-min))
4231 (search-forward "\n\n" nil t)
4232 (or (and (re-search-forward message-unsent-separator nil t)
4233 (forward-line 1))
4234 (re-search-forward "^Return-Path:.*\n" nil t))
4235 ;; We remove everything before the bounced mail.
4236 (delete-region
4237 (point-min)
4238 (if (re-search-forward "^[^ \n\t]+:" nil t)
4239 (match-beginning 0)
4240 (point))))
4241 (mm-enable-multibyte)
4242 (mime-to-mml)
4243 (save-restriction
4244 (message-narrow-to-head)
4245 (message-remove-header message-ignored-bounced-headers t)
4246 (goto-char (point-max))
4247 (insert mail-header-separator))
4248 (message-position-point)))
4251 ;;; Interactive entry points for new message buffers.
4254 ;;;###autoload
4255 (defun message-mail-other-window (&optional to subject)
4256 "Like `message-mail' command, but display mail buffer in another window."
4257 (interactive)
4258 (let ((pop-up-windows t)
4259 (special-display-buffer-names nil)
4260 (special-display-regexps nil)
4261 (same-window-buffer-names nil)
4262 (same-window-regexps nil))
4263 (message-pop-to-buffer (message-buffer-name "mail" to)))
4264 (let ((message-this-is-mail t))
4265 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4267 ;;;###autoload
4268 (defun message-mail-other-frame (&optional to subject)
4269 "Like `message-mail' command, but display mail buffer in another frame."
4270 (interactive)
4271 (let ((pop-up-frames t)
4272 (special-display-buffer-names nil)
4273 (special-display-regexps nil)
4274 (same-window-buffer-names nil)
4275 (same-window-regexps nil))
4276 (message-pop-to-buffer (message-buffer-name "mail" to)))
4277 (let ((message-this-is-mail t))
4278 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4280 ;;;###autoload
4281 (defun message-news-other-window (&optional newsgroups subject)
4282 "Start editing a news article to be sent."
4283 (interactive)
4284 (let ((pop-up-windows t)
4285 (special-display-buffer-names nil)
4286 (special-display-regexps nil)
4287 (same-window-buffer-names nil)
4288 (same-window-regexps nil))
4289 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4290 (let ((message-this-is-news t))
4291 (message-setup `((Newsgroups . ,(or newsgroups ""))
4292 (Subject . ,(or subject ""))))))
4294 ;;;###autoload
4295 (defun message-news-other-frame (&optional newsgroups subject)
4296 "Start editing a news article to be sent."
4297 (interactive)
4298 (let ((pop-up-frames t)
4299 (special-display-buffer-names nil)
4300 (special-display-regexps nil)
4301 (same-window-buffer-names nil)
4302 (same-window-regexps nil))
4303 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4304 (let ((message-this-is-news t))
4305 (message-setup `((Newsgroups . ,(or newsgroups ""))
4306 (Subject . ,(or subject ""))))))
4308 ;;; underline.el
4310 ;; This code should be moved to underline.el (from which it is stolen).
4312 ;;;###autoload
4313 (defun bold-region (start end)
4314 "Bold all nonblank characters in the region.
4315 Works by overstriking characters.
4316 Called from program, takes two arguments START and END
4317 which specify the range to operate on."
4318 (interactive "r")
4319 (save-excursion
4320 (let ((end1 (make-marker)))
4321 (move-marker end1 (max start end))
4322 (goto-char (min start end))
4323 (while (< (point) end1)
4324 (or (looking-at "[_\^@- ]")
4325 (insert (char-after) "\b"))
4326 (forward-char 1)))))
4328 ;;;###autoload
4329 (defun unbold-region (start end)
4330 "Remove all boldness (overstruck characters) in the region.
4331 Called from program, takes two arguments START and END
4332 which specify the range to operate on."
4333 (interactive "r")
4334 (save-excursion
4335 (let ((end1 (make-marker)))
4336 (move-marker end1 (max start end))
4337 (goto-char (min start end))
4338 (while (re-search-forward "\b" end1 t)
4339 (if (eq (char-after) (char-after (- (point) 2)))
4340 (delete-char -2))))))
4342 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4344 ;; Support for toolbar
4345 (eval-when-compile (defvar tool-bar-map))
4346 (if (featurep 'xemacs)
4347 (require 'messagexmas)
4348 (when (and (fboundp 'tool-bar-add-item-from-menu)
4349 tool-bar-mode)
4350 (defvar message-tool-bar-map
4351 (let ((tool-bar-map (copy-keymap tool-bar-map)))
4352 ;; Zap some items which aren't so relevant and take up space.
4353 (dolist (key '(print-buffer kill-buffer save-buffer write-file
4354 dired open-file))
4355 (define-key tool-bar-map (vector key) nil))
4357 (tool-bar-add-item-from-menu
4358 'message-send-and-exit "mail_send" message-mode-map)
4359 (tool-bar-add-item-from-menu
4360 'message-kill-buffer "close" message-mode-map)
4361 (tool-bar-add-item-from-menu
4362 'message-dont-send "cancel" message-mode-map)
4363 (tool-bar-add-item-from-menu
4364 'mml-attach-file "attach" message-mode-map)
4365 (tool-bar-add-item-from-menu
4366 'ispell-message "spell" message-mode-map)
4367 tool-bar-map))))
4369 ;;; Group name completion.
4371 (defvar message-newgroups-header-regexp
4372 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4373 "Regexp that match headers that lists groups.")
4375 (defun message-tab ()
4376 "Expand group names in Newsgroups and Followup-To headers.
4377 Do a `tab-to-tab-stop' if not in those headers."
4378 (interactive)
4379 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4380 (mail-abbrev-in-expansion-header-p))
4381 (message-expand-group)
4382 (tab-to-tab-stop)))
4384 (defun message-expand-group ()
4385 "Expand the group name under point."
4386 (let* ((b (save-excursion
4387 (save-restriction
4388 (narrow-to-region
4389 (save-excursion
4390 (beginning-of-line)
4391 (skip-chars-forward "^:")
4392 (1+ (point)))
4393 (point))
4394 (skip-chars-backward "^, \t\n") (point))))
4395 (completion-ignore-case t)
4396 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4397 (point))))
4398 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4399 (completions (all-completions string hashtb))
4400 comp)
4401 (delete-region b (point))
4402 (cond
4403 ((= (length completions) 1)
4404 (if (string= (car completions) string)
4405 (progn
4406 (insert string)
4407 (message "Only matching group"))
4408 (insert (car completions))))
4409 ((and (setq comp (try-completion string hashtb))
4410 (not (string= comp string)))
4411 (insert comp))
4413 (insert string)
4414 (if (not comp)
4415 (message "No matching groups")
4416 (save-selected-window
4417 (pop-to-buffer "*Completions*")
4418 (buffer-disable-undo)
4419 (let ((buffer-read-only nil))
4420 (erase-buffer)
4421 (let ((standard-output (current-buffer)))
4422 (display-completion-list (sort completions 'string<)))
4423 (goto-char (point-min))
4424 (delete-region (point) (progn (forward-line 3) (point))))))))))
4426 ;;; Help stuff.
4428 (defun message-talkative-question (ask question show &rest text)
4429 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4430 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4431 The following arguments may contain lists of values."
4432 (if (and show
4433 (setq text (message-flatten-list text)))
4434 (save-window-excursion
4435 (save-excursion
4436 (with-output-to-temp-buffer " *MESSAGE information message*"
4437 (set-buffer " *MESSAGE information message*")
4438 (fundamental-mode) ; for Emacs 20.4+
4439 (mapcar 'princ text)
4440 (goto-char (point-min))))
4441 (funcall ask question))
4442 (funcall ask question)))
4444 (defun message-flatten-list (list)
4445 "Return a new, flat list that contains all elements of LIST.
4447 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4448 => (1 2 3 4 5 6 7)"
4449 (cond ((consp list)
4450 (apply 'append (mapcar 'message-flatten-list list)))
4451 (list
4452 (list list))))
4454 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4455 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4456 Then clone the local variables and values from the old buffer to the
4457 new one, cloning only the locals having a substring matching the
4458 regexp varstr."
4459 (let ((oldbuf (current-buffer)))
4460 (save-excursion
4461 (set-buffer (generate-new-buffer name))
4462 (message-clone-locals oldbuf varstr)
4463 (current-buffer))))
4465 (defun message-clone-locals (buffer &optional varstr)
4466 "Clone the local variables from BUFFER to the current buffer."
4467 (let ((locals (save-excursion
4468 (set-buffer buffer)
4469 (buffer-local-variables)))
4470 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4471 (mapcar
4472 (lambda (local)
4473 (when (and (consp local)
4474 (car local)
4475 (string-match regexp (symbol-name (car local)))
4476 (or (null varstr)
4477 (string-match varstr (symbol-name (car local)))))
4478 (ignore-errors
4479 (set (make-local-variable (car local))
4480 (cdr local)))))
4481 locals)))
4483 ;;; Miscellaneous functions
4485 ;; stolen (and renamed) from nnheader.el
4486 (if (fboundp 'subst-char-in-string)
4487 (defsubst message-replace-chars-in-string (string from to)
4488 (subst-char-in-string from to string))
4489 (defun message-replace-chars-in-string (string from to)
4490 "Replace characters in STRING from FROM to TO."
4491 (let ((string (substring string 0)) ;Copy string.
4492 (len (length string))
4493 (idx 0))
4494 ;; Replace all occurrences of FROM with TO.
4495 (while (< idx len)
4496 (when (= (aref string idx) from)
4497 (aset string idx to))
4498 (setq idx (1+ idx)))
4499 string)))
4502 ;;; MIME functions
4505 (defvar message-inhibit-body-encoding nil)
4507 (defun message-encode-message-body ()
4508 (unless message-inhibit-body-encoding
4509 (let ((mail-parse-charset (or mail-parse-charset
4510 message-default-charset))
4511 (case-fold-search t)
4512 lines content-type-p)
4513 (message-goto-body)
4514 (save-restriction
4515 (narrow-to-region (point) (point-max))
4516 (let ((new (mml-generate-mime)))
4517 (when new
4518 (delete-region (point-min) (point-max))
4519 (insert new)
4520 (goto-char (point-min))
4521 (if (eq (aref new 0) ?\n)
4522 (delete-char 1)
4523 (search-forward "\n\n")
4524 (setq lines (buffer-substring (point-min) (1- (point))))
4525 (delete-region (point-min) (point))))))
4526 (save-restriction
4527 (message-narrow-to-headers-or-head)
4528 (message-remove-header "Mime-Version")
4529 (goto-char (point-max))
4530 (insert "MIME-Version: 1.0\n")
4531 (when lines
4532 (insert lines))
4533 (setq content-type-p
4534 (re-search-backward "^Content-Type:" nil t)))
4535 (save-restriction
4536 (message-narrow-to-headers-or-head)
4537 (message-remove-first-header "Content-Type")
4538 (message-remove-first-header "Content-Transfer-Encoding"))
4539 ;; We always make sure that the message has a Content-Type header.
4540 ;; This is because some broken MTAs and MUAs get awfully confused
4541 ;; when confronted with a message with a MIME-Version header and
4542 ;; without a Content-Type header. For instance, Solaris'
4543 ;; /usr/bin/mail.
4544 (unless content-type-p
4545 (goto-char (point-min))
4546 (re-search-forward "^MIME-Version:")
4547 (forward-line 1)
4548 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4550 (defun message-read-from-minibuffer (prompt)
4551 "Read from the minibuffer while providing abbrev expansion."
4552 (if (fboundp 'mail-abbrevs-setup)
4553 (let ((mail-abbrev-mode-regexp "")
4554 (minibuffer-setup-hook 'mail-abbrevs-setup))
4555 (read-from-minibuffer prompt))
4556 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
4557 (read-string prompt))))
4559 (defun message-use-alternative-email-as-from ()
4560 (require 'mail-utils)
4561 (let* ((fields '("To" "Cc"))
4562 (emails
4563 (split-string
4564 (mail-strip-quoted-names
4565 (mapconcat 'message-fetch-reply-field fields ","))
4566 "[ \f\t\n\r\v,]+"))
4567 email)
4568 (while emails
4569 (if (string-match message-alternative-emails (car emails))
4570 (setq email (car emails)
4571 emails nil))
4572 (pop emails))
4573 (unless (or (not email) (equal email user-mail-address))
4574 (goto-char (point-max))
4575 (insert "From: " email "\n"))))
4577 (provide 'message)
4579 (run-hooks 'message-load-hook)
4581 ;; Local Variables:
4582 ;; coding: iso-8859-1
4583 ;; End:
4585 ;;; message.el ends here