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