1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
35 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
39 ;; This is apparently necessary even though things are autoloaded:
40 (if (featurep 'xemacs)
41 (require 'mail-abbrevs))
46 (autoload 'sha1 "sha1-el"))
48 (defgroup message '((user-mail-address custom-variable)
49 (user-full-name custom-variable))
50 "Mail and news message composing."
51 :link '(custom-manual "(message)Top")
55 (put 'user-mail-address 'custom-type 'string)
56 (put 'user-full-name 'custom-type 'string)
58 (defgroup message-various nil
59 "Various Message Variables"
60 :link '(custom-manual "(message)Various Message Variables")
63 (defgroup message-buffers nil
65 :link '(custom-manual "(message)Message Buffers")
68 (defgroup message-sending nil
70 :link '(custom-manual "(message)Sending Variables")
73 (defgroup message-interface nil
75 :link '(custom-manual "(message)Interface")
78 (defgroup message-forwarding nil
80 :link '(custom-manual "(message)Forwarding")
81 :group 'message-interface)
83 (defgroup message-insertion nil
85 :link '(custom-manual "(message)Insertion")
88 (defgroup message-headers nil
90 :link '(custom-manual "(message)Message Headers")
93 (defgroup message-news nil
94 "Composing News Messages"
97 (defgroup message-mail nil
98 "Composing Mail Messages"
101 (defgroup message-faces nil
102 "Faces used for message composing."
106 (defcustom message-directory "~/Mail/"
107 "*Directory from which all other mail file variables are derived."
108 :group 'message-various
111 (defcustom message-max-buffers 10
112 "*How many buffers to keep before starting to kill them off."
113 :group 'message-buffers
116 (defcustom message-send-rename-function nil
117 "Function called to rename the buffer after sending it."
118 :group 'message-buffers
119 :type '(choice function (const nil)))
121 (defcustom message-fcc-handler-function 'message-output
122 "*A function called to save outgoing articles.
123 This function will be called with the name of the file to store the
124 article in. The default function is `message-output' which saves in Unix
126 :type '(radio (function-item message-output)
127 (function :tag "Other"))
128 :group 'message-sending)
130 (defcustom message-courtesy-message
131 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
132 "*This is inserted at the start of a mailed copy of a posted message.
133 If the string contains the format spec \"%s\", the Newsgroups
134 the article has been posted to will be inserted there.
135 If this variable is nil, no such courtesy message will be added."
136 :group 'message-sending
139 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
140 "*Regexp that matches headers to be removed in resent bounced mail."
141 :group 'message-interface
145 (defcustom message-from-style 'default
146 "*Specifies how \"From\" headers look.
148 If nil, they contain just the return address like:
150 If `parens', they look like:
151 king@grassland.com (Elvis Parsley)
152 If `angles', they look like:
153 Elvis Parsley <king@grassland.com>
155 Otherwise, most addresses look like `angles', but they look like
156 `parens' if `angles' would need quoting and `parens' would not."
157 :type '(choice (const :tag "simple" nil)
161 :group 'message-headers)
163 (defcustom message-syntax-checks nil
164 ;; Guess this one shouldn't be easy to customize...
165 "*Controls what syntax checks should not be performed on outgoing posts.
166 To disable checking of long signatures, for instance, add
167 `(signature . disabled)' to this list.
169 Don't touch this variable unless you really know what you're doing.
171 Checks include `subject-cmsg', `multiple-headers', `sendsys',
172 `message-id', `from', `long-lines', `control-chars', `size',
173 `new-text', `quoting-style', `redirected-followup', `signature',
174 `approved', `sender', `empty', `empty-headers', `message-id', `from',
175 `subject', `shorten-followup-to', `existing-newsgroups',
176 `buffer-file-name', `unchanged', `newsgroups', `reply-to'."
178 :type '(repeat sexp)) ; Fixme: improve this
180 (defcustom message-required-news-headers
181 '(From Newsgroups Subject Date Message-ID
182 (optional . Organization) Lines
183 (optional . User-Agent))
184 "*Headers to be generated or prompted for when posting an article.
185 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
186 Message-ID. Organization, Lines, In-Reply-To, Expires, and
187 User-Agent are optional. If don't you want message to insert some
188 header, remove it from this list."
190 :group 'message-headers
191 :type '(repeat sexp))
193 (defcustom message-required-mail-headers
194 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
195 (optional . User-Agent))
196 "*Headers to be generated or prompted for when mailing a message.
197 It is recommended that From, Date, To, Subject and Message-ID be
198 included. Organization, Lines and User-Agent are optional."
200 :group 'message-headers
201 :type '(repeat sexp))
203 (defcustom message-deletable-headers '(Message-ID Date Lines)
204 "Headers to be deleted if they already exist and were generated by message previously."
205 :group 'message-headers
208 (defcustom message-ignored-news-headers
209 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:"
210 "*Regexp of headers to be removed unconditionally before posting."
212 :group 'message-headers
215 (defcustom message-ignored-mail-headers
216 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:"
217 "*Regexp of headers to be removed unconditionally before mailing."
219 :group 'message-headers
222 (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:\\|^Cancel-Lock:\\|^Cancel-Key:"
223 "*Header lines matching this regexp will be deleted before posting.
224 It's best to delete old Path and Date headers before posting to avoid
226 :group 'message-interface
229 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
230 "*Regexp matching \"Re: \" in the subject line."
231 :group 'message-various
235 (defcustom message-signature-separator "^-- *$"
236 "Regexp matching the signature separator."
238 :group 'message-various)
240 (defcustom message-elide-ellipsis "\n[...]\n\n"
241 "*The string which is inserted for elided text."
243 :group 'message-various)
245 (defcustom message-interactive nil
246 "Non-nil means when sending a message wait for and display errors.
247 nil means let mailer mail back a message to report errors."
248 :group 'message-sending
252 (defcustom message-generate-new-buffers 'unique
253 "*Non-nil means create a new message buffer whenever `message-setup' is called.
254 If this is a function, call that function with three parameters: The type,
255 the to address and the group name. (Any of these may be nil.) The function
256 should return the new buffer name."
257 :group 'message-buffers
258 :type '(choice (const :tag "off" nil)
259 (const :tag "unique" unique)
260 (const :tag "unsent" unsent)
263 (defcustom message-kill-buffer-on-exit nil
264 "*Non-nil means that the message buffer will be killed after sending a message."
265 :group 'message-buffers
269 (defvar gnus-local-organization))
270 (defcustom message-user-organization
271 (or (and (boundp 'gnus-local-organization)
272 (stringp gnus-local-organization)
273 gnus-local-organization)
274 (getenv "ORGANIZATION")
276 "*String to be used as an Organization header.
277 If t, use `message-user-organization-file'."
278 :group 'message-headers
279 :type '(choice string
280 (const :tag "consult file" t)))
283 (defcustom message-user-organization-file "/usr/lib/news/organization"
284 "*Local news organization file."
286 :group 'message-headers)
288 (defcustom message-make-forward-subject-function
289 'message-forward-subject-author-subject
290 "*List of functions called to generate subject headers for forwarded messages.
291 The subject generated by the previous function is passed into each
294 The provided functions are:
296 * `message-forward-subject-author-subject' (Source of article (author or
297 newsgroup)), in brackets followed by the subject
298 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
300 :group 'message-forwarding
301 :type '(radio (function-item message-forward-subject-author-subject)
302 (function-item message-forward-subject-fwd)
303 (repeat :tag "List of functions" function)))
305 (defcustom message-forward-as-mime t
306 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
308 :group 'message-forwarding
311 (defcustom message-forward-show-mml t
312 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
314 :group 'message-forwarding
317 (defcustom message-forward-before-signature t
318 "*If non-nil, put forwarded message before signature, else after."
319 :group 'message-forwarding
322 (defcustom message-wash-forwarded-subjects nil
323 "*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."
324 :group 'message-forwarding
327 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
328 "*All headers that match this regexp will be deleted when resending a message."
329 :group 'message-interface
332 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
333 "*All headers that match this regexp will be deleted when forwarding a message."
335 :group 'message-forwarding
336 :type '(choice (const :tag "None" nil)
339 (defcustom message-ignored-cited-headers "."
340 "*Delete these headers from the messages you yank."
341 :group 'message-insertion
344 (defcustom message-cite-prefix-regexp
345 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
346 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>»|:}+]\\)+"
347 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
348 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+")
349 "*Regexp matching the longest possible citation prefix on a line."
350 :group 'message-insertion
353 (defcustom message-cancel-message "I am canceling my own article.\n"
354 "Message to be inserted in the cancel message."
355 :group 'message-interface
358 ;; Useful to set in site-init.el
360 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
361 "Function to call to send the current buffer as mail.
362 The headers should be delimited by a line whose contents match the
363 variable `mail-header-separator'.
365 Valid values include `message-send-mail-with-sendmail' (the default),
366 `message-send-mail-with-mh', `message-send-mail-with-qmail',
367 `smtpmail-send-it' and `feedmail-send-it'.
369 See also `send-mail-function'."
370 :type '(radio (function-item message-send-mail-with-sendmail)
371 (function-item message-send-mail-with-mh)
372 (function-item message-send-mail-with-qmail)
373 (function-item smtpmail-send-it)
374 (function-item feedmail-send-it)
375 (function :tag "Other"))
376 :group 'message-sending
377 :group 'message-mail)
379 (defcustom message-send-news-function 'message-send-news
380 "Function to call to send the current buffer as news.
381 The headers should be delimited by a line whose contents match the
382 variable `mail-header-separator'."
383 :group 'message-sending
387 (defcustom message-reply-to-function nil
388 "If non-nil, function that should return a list of headers.
389 This function should pick out addresses from the To, Cc, and From headers
390 and respond with new To and Cc headers."
391 :group 'message-interface
392 :type '(choice function (const nil)))
394 (defcustom message-wide-reply-to-function nil
395 "If non-nil, function that should return a list of headers.
396 This function should pick out addresses from the To, Cc, and From headers
397 and respond with new To and Cc headers."
398 :group 'message-interface
399 :type '(choice function (const nil)))
401 (defcustom message-followup-to-function nil
402 "If non-nil, function that should return a list of headers.
403 This function should pick out addresses from the To, Cc, and From headers
404 and respond with new To and Cc headers."
405 :group 'message-interface
406 :type '(choice function (const nil)))
408 (defcustom message-use-followup-to 'ask
409 "*Specifies what to do with Followup-To header.
410 If nil, always ignore the header. If it is t, use its value, but
411 query before using the \"poster\" value. If it is the symbol `ask',
412 always query the user whether to use the value. If it is the symbol
413 `use', always use the value."
414 :group 'message-interface
415 :type '(choice (const :tag "ignore" nil)
416 (const :tag "use & query" t)
420 (defcustom message-use-mail-followup-to 'use
421 "*Specifies what to do with Mail-Followup-To header.
422 If nil, always ignore the header. If it is the symbol `ask', always
423 query the user whether to use the value. If it is the symbol `use',
424 always use the value."
425 :group 'message-interface
426 :type '(choice (const :tag "ignore" nil)
430 (defcustom message-subscribed-address-functions nil
431 "*Specifies functions for determining list subscription.
432 If nil, do not attempt to determine list subscribtion with functions.
433 If non-nil, this variable contains a list of functions which return
434 regular expressions to match lists. These functions can be used in
435 conjunction with `message-subscribed-regexps' and
436 `message-subscribed-addresses'."
437 :group 'message-interface
438 :type '(repeat sexp))
440 (defcustom message-subscribed-address-file nil
441 "*A file containing addresses the user is subscribed to.
442 If nil, do not look at any files to determine list subscriptions. If
443 non-nil, each line of this file should be a mailing list address."
444 :group 'message-interface
447 (defcustom message-subscribed-addresses nil
448 "*Specifies a list of addresses the user is subscribed to.
449 If nil, do not use any predefined list subscriptions. This list of
450 addresses can be used in conjuction with
451 `message-subscribed-address-functions' and `message-subscribed-regexps'."
452 :group 'message-interface
453 :type '(repeat string))
455 (defcustom message-subscribed-regexps nil
456 "*Specifies a list of addresses the user is subscribed to.
457 If nil, do not use any predefined list subscriptions. This list of
458 regular expressions can be used in conjuction with
459 `message-subscribed-address-functions' and `message-subscribed-addresses'."
460 :group 'message-interface
461 :type '(repeat regexp))
463 (defcustom message-allow-no-recipients 'ask
464 "Specifies what to do when there are no recipients other than Gcc/Fcc.
465 If it is the symbol `always', the posting is allowed. If it is the
466 symbol `never', the posting is not allowed. If it is the symbol
467 `ask', you are prompted."
468 :group 'message-interface
469 :type '(choice (const always)
473 (defcustom message-sendmail-f-is-evil nil
474 "*Non-nil means don't add \"-f username\" to the sendmail command line.
475 Doing so would be even more evil than leaving it out."
476 :group 'message-sending
479 ;; qmail-related stuff
480 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
481 "Location of the qmail-inject program."
482 :group 'message-sending
485 (defcustom message-qmail-inject-args nil
486 "Arguments passed to qmail-inject programs.
487 This should be a list of strings, one string for each argument.
489 For e.g., if you wish to set the envelope sender address so that bounces
490 go to the right place or to deal with listserv's usage of that address, you
491 might set this variable to '(\"-f\" \"you@some.where\")."
492 :group 'message-sending
493 :type '(repeat string))
495 (defvar message-cater-to-broken-inn t
496 "Non-nil means Gnus should not fold the `References' header.
497 Folding `References' makes ancient versions of INN create incorrect
501 (defvar gnus-post-method)
502 (defvar gnus-select-method))
503 (defcustom message-post-method
504 (cond ((and (boundp 'gnus-post-method)
505 (listp gnus-post-method)
508 ((boundp 'gnus-select-method)
511 "*Method used to post news.
512 Note that when posting from inside Gnus, for instance, this
513 variable isn't used."
515 :group 'message-sending
516 ;; This should be the `gnus-select-method' widget, but that might
517 ;; create a dependence to `gnus.el'.
520 (defcustom message-generate-headers-first nil
521 "*If non-nil, generate all required headers before composing.
522 The variables `message-required-news-headers' and
523 `message-required-mail-headers' specify which headers to generate.
525 Note that the variable `message-deletable-headers' specifies headers which
526 are to be deleted and then re-generated before sending, so this variable
527 will not have a visible effect for those headers."
528 :group 'message-headers
531 (defcustom message-setup-hook nil
532 "Normal hook, run each time a new outgoing message is initialized.
533 The function `message-setup' runs this hook."
534 :group 'message-various
537 (defcustom message-cancel-hook nil
538 "Hook run when cancelling articles."
539 :group 'message-various
542 (defcustom message-signature-setup-hook nil
543 "Normal hook, run each time a new outgoing message is initialized.
544 It is run after the headers have been inserted and before
545 the signature is inserted."
546 :group 'message-various
549 (defcustom message-mode-hook nil
550 "Hook run in message mode buffers."
551 :group 'message-various
554 (defcustom message-header-hook nil
555 "Hook run in a message mode buffer narrowed to the headers."
556 :group 'message-various
559 (defcustom message-header-setup-hook nil
560 "Hook called narrowed to the headers when setting up a message buffer."
561 :group 'message-various
564 (defcustom message-minibuffer-local-map
565 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
566 (set-keymap-parent map minibuffer-local-map)
568 "Keymap for `message-read-from-minibuffer'.")
571 (defcustom message-citation-line-function 'message-insert-citation-line
572 "*Function called to insert the \"Whomever writes:\" line.
574 Note that Gnus provides a feature where the reader can click on
575 `writes:' to hide the cited text. If you change this line too much,
576 people who read your message will have to change their Gnus
577 configuration. See the variable `gnus-cite-attribution-suffix'."
579 :group 'message-insertion)
582 (defcustom message-yank-prefix "> "
583 "*Prefix inserted on the lines of yanked messages.
584 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
585 See also `message-yank-cited-prefix'."
587 :group 'message-insertion)
589 (defcustom message-yank-cited-prefix ">"
590 "*Prefix inserted on cited or empty lines of yanked messages.
591 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
592 See also `message-yank-prefix'."
594 :group 'message-insertion)
596 (defcustom message-indentation-spaces 3
597 "*Number of spaces to insert at the beginning of each cited line.
598 Used by `message-yank-original' via `message-yank-cite'."
599 :group 'message-insertion
603 (defcustom message-cite-function 'message-cite-original
604 "*Function for citing an original message.
605 Predefined functions include `message-cite-original' and
606 `message-cite-original-without-signature'.
607 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
608 :type '(radio (function-item message-cite-original)
609 (function-item message-cite-original-without-signature)
610 (function-item sc-cite-original)
611 (function :tag "Other"))
612 :group 'message-insertion)
615 (defcustom message-indent-citation-function 'message-indent-citation
616 "*Function for modifying a citation just inserted in the mail buffer.
617 This can also be a list of functions. Each function can find the
618 citation between (point) and (mark t). And each function should leave
619 point and mark around the citation text as modified."
621 :group 'message-insertion)
623 (defvar message-abbrevs-loaded nil)
626 (defcustom message-signature t
627 "*String to be inserted at the end of the message buffer.
628 If t, the `message-signature-file' file will be inserted instead.
629 If a function, the result from the function will be used instead.
630 If a form, the result from the form will be used instead."
632 :group 'message-insertion)
635 (defcustom message-signature-file "~/.signature"
636 "*Name of file containing the text inserted at end of message buffer.
637 Ignored if the named file doesn't exist.
638 If nil, don't insert a signature."
639 :type '(choice file (const :tags "None" nil))
640 :group 'message-insertion)
642 (defcustom message-distribution-function nil
643 "*Function called to return a Distribution header."
645 :group 'message-headers
646 :type '(choice function (const nil)))
648 (defcustom message-expires 14
649 "Number of days before your article expires."
651 :group 'message-headers
652 :link '(custom-manual "(message)News Headers")
655 (defcustom message-user-path nil
656 "If nil, use the NNTP server name in the Path header.
657 If stringp, use this; if non-nil, use no host name (user name only)."
659 :group 'message-headers
660 :link '(custom-manual "(message)News Headers")
661 :type '(choice (const :tag "nntp" nil)
663 (sexp :tag "none" :format "%t" t)))
665 (defvar message-reply-buffer nil)
666 (defvar message-reply-headers nil)
667 (defvar message-newsreader nil)
668 (defvar message-mailer nil)
669 (defvar message-sent-message-via nil)
670 (defvar message-checksum nil)
671 (defvar message-send-actions nil
672 "A list of actions to be performed upon successful sending of a message.")
673 (defvar message-exit-actions nil
674 "A list of actions to be performed upon exiting after sending a message.")
675 (defvar message-kill-actions nil
676 "A list of actions to be performed before killing a message buffer.")
677 (defvar message-postpone-actions nil
678 "A list of actions to be performed after postponing a message.")
680 (define-widget 'message-header-lines 'text
681 "All header lines must be LFD terminated."
682 :format "%{%t%}:%n%v"
684 :error "All header lines must be newline terminated")
686 (defcustom message-default-headers ""
687 "*A string containing header lines to be inserted in outgoing messages.
688 It is inserted before you edit the message, so you can edit or delete
690 :group 'message-headers
691 :type 'message-header-lines)
693 (defcustom message-default-mail-headers ""
694 "*A string of header lines to be inserted in outgoing mails."
695 :group 'message-headers
697 :type 'message-header-lines)
699 (defcustom message-default-news-headers ""
700 "*A string of header lines to be inserted in outgoing news articles."
701 :group 'message-headers
703 :type 'message-header-lines)
705 ;; Note: could use /usr/ucb/mail instead of sendmail;
706 ;; options -t, and -v if not interactive.
707 (defcustom message-mailer-swallows-blank-line
708 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
709 system-configuration)
710 (file-readable-p "/etc/sendmail.cf")
711 (let ((buffer (get-buffer-create " *temp*")))
715 (insert-file-contents "/etc/sendmail.cf")
716 (goto-char (point-min))
717 (let ((case-fold-search nil))
718 (re-search-forward "^OR\\>" nil t)))
719 (kill-buffer buffer))))
720 ;; According to RFC822, "The field-name must be composed of printable
721 ;; ASCII characters (i. e., characters that have decimal values between
722 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
724 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
725 "*Set this non-nil if the system's mailer runs the header and body together.
726 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
727 The value should be an expression to test whether the problem will
729 :group 'message-sending
733 (define-mail-user-agent 'message-user-agent
734 'message-mail 'message-send-and-exit
735 'message-kill-buffer 'message-send-hook)
737 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
738 "If non-nil, delete the deletable headers before feeding to mh.")
740 (defvar message-send-method-alist
741 '((news message-news-p message-send-via-news)
742 (mail message-mail-p message-send-via-mail))
743 "Alist of ways to send outgoing messages.
744 Each element has the form
746 \(TYPE PREDICATE FUNCTION)
748 where TYPE is a symbol that names the method; PREDICATE is a function
749 called without any parameters to determine whether the message is
750 a message of type TYPE; and FUNCTION is a function to be called if
751 PREDICATE returns non-nil. FUNCTION is called with one parameter --
754 (defcustom message-mail-alias-type 'abbrev
755 "*What alias expansion type to use in Message buffers.
756 The default is `abbrev', which uses mailabbrev. nil switches
759 :link '(custom-manual "(message)Mail Aliases")
760 :type '(choice (const :tag "Use Mailabbrev" abbrev)
761 (const :tag "No expansion" nil)))
763 (defcustom message-auto-save-directory
764 (file-name-as-directory (nnheader-concat message-directory "drafts"))
765 "*Directory where Message auto-saves buffers if Gnus isn't running.
766 If nil, Message won't auto-save."
767 :group 'message-buffers
768 :type '(choice directory (const :tag "Don't auto-save" nil)))
770 (defcustom message-buffer-naming-style 'unique
771 "*The way new message buffers are named.
772 Valid valued are `unique' and `unsent'."
774 :group 'message-buffers
775 :type '(choice (const :tag "unique" unique)
776 (const :tag "unsent" unsent)))
778 (defcustom message-default-charset
779 (and (not (mm-multibyte-p)) 'iso-8859-1)
780 "Default charset used in non-MULE Emacsen.
781 If nil, you might be asked to input the charset."
786 (defcustom message-dont-reply-to-names
787 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
788 "*A regexp specifying addresses to prune when doing wide replies.
789 A value of nil means exclude your own user name only."
792 :type '(choice (const :tag "Yourself" nil)
795 (defvar message-shoot-gnksa-feet nil
796 "*A list of GNKSA feet you are allowed to shoot.
797 Gnus gives you all the opportunity you could possibly want for
798 shooting yourself in the foot. Also, Gnus allows you to shoot the
799 feet of Good Net-Keeping Seal of Approval. The following are foot
801 `empty-article' Allow you to post an empty article;
802 `quoted-text-only' Allow you to post quoted text only;
803 `multiple-copies' Allow you to post multiple copies.")
804 ;; `cancel-messages' Allow you to cancel or supersede others' messages.
806 (defsubst message-gnksa-enable-p (feature)
807 (or (not (listp message-shoot-gnksa-feet))
808 (memq feature message-shoot-gnksa-feet)))
810 ;;; Internal variables.
811 ;;; Well, not really internal.
813 (defvar message-mode-syntax-table
814 (let ((table (copy-syntax-table text-mode-syntax-table)))
815 (modify-syntax-entry ?% ". " table)
816 (modify-syntax-entry ?> ". " table)
817 (modify-syntax-entry ?< ". " table)
819 "Syntax table used while in Message mode.")
821 (defface message-header-to-face
824 (:foreground "green2" :bold t))
827 (:foreground "MidnightBlue" :bold t))
829 (:bold t :italic t)))
830 "Face used for displaying From headers."
831 :group 'message-faces)
833 (defface message-header-cc-face
836 (:foreground "green4" :bold t))
839 (:foreground "MidnightBlue"))
842 "Face used for displaying Cc headers."
843 :group 'message-faces)
845 (defface message-header-subject-face
848 (:foreground "green3"))
851 (:foreground "navy blue" :bold t))
854 "Face used for displaying subject headers."
855 :group 'message-faces)
857 (defface message-header-newsgroups-face
860 (:foreground "yellow" :bold t :italic t))
863 (:foreground "blue4" :bold t :italic t))
865 (:bold t :italic t)))
866 "Face used for displaying newsgroups headers."
867 :group 'message-faces)
869 (defface message-header-other-face
872 (:foreground "#b00000"))
875 (:foreground "steel blue"))
877 (:bold t :italic t)))
878 "Face used for displaying newsgroups headers."
879 :group 'message-faces)
881 (defface message-header-name-face
884 (:foreground "DarkGreen"))
887 (:foreground "cornflower blue"))
890 "Face used for displaying header names."
891 :group 'message-faces)
893 (defface message-header-xheader-face
896 (:foreground "blue"))
899 (:foreground "blue"))
902 "Face used for displaying X-Header headers."
903 :group 'message-faces)
905 (defface message-separator-face
908 (:foreground "blue3"))
911 (:foreground "brown"))
914 "Face used for displaying the separator."
915 :group 'message-faces)
917 (defface message-cited-text-face
926 "Face used for displaying cited text names."
927 :group 'message-faces)
929 (defface message-mml-face
932 (:foreground "ForestGreen"))
935 (:foreground "ForestGreen"))
938 "Face used for displaying MML."
939 :group 'message-faces)
941 (defvar message-font-lock-keywords
942 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
943 `((,(concat "^\\([Tt]o:\\)" content)
944 (1 'message-header-name-face)
945 (2 'message-header-to-face nil t))
946 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
947 (1 'message-header-name-face)
948 (2 'message-header-cc-face nil t))
949 (,(concat "^\\([Ss]ubject:\\)" content)
950 (1 'message-header-name-face)
951 (2 'message-header-subject-face nil t))
952 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
953 (1 'message-header-name-face)
954 (2 'message-header-newsgroups-face nil t))
955 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
956 (1 'message-header-name-face)
957 (2 'message-header-other-face nil t))
958 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
959 (1 'message-header-name-face)
960 (2 'message-header-name-face))
961 ,@(if (and mail-header-separator
962 (not (equal mail-header-separator "")))
963 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
964 1 'message-separator-face))
966 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
967 (0 'message-cited-text-face))
968 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
969 (0 'message-mml-face))))
970 "Additional expressions to highlight in Message mode.")
972 ;; XEmacs does it like this. For Emacs, we have to set the
973 ;; `font-lock-defaults' buffer-local variable.
974 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
976 (defvar message-face-alist
977 '((bold . bold-region)
978 (underline . underline-region)
979 (default . (lambda (b e)
981 (ununderline-region b e))))
982 "Alist of mail and news faces for facemenu.
983 The cdr of ech entry is a function for applying the face to a region.")
985 (defcustom message-send-hook nil
986 "Hook run before sending messages."
987 :group 'message-various
988 :options '(ispell-message)
991 (defcustom message-send-mail-hook nil
992 "Hook run before sending mail messages."
993 :group 'message-various
996 (defcustom message-send-news-hook nil
997 "Hook run before sending news messages."
998 :group 'message-various
1001 (defcustom message-sent-hook nil
1002 "Hook run after sending messages."
1003 :group 'message-various
1006 (defvar message-send-coding-system 'binary
1007 "Coding system to encode outgoing mail.")
1009 (defvar message-draft-coding-system
1010 mm-auto-save-coding-system
1011 "Coding system to compose mail.")
1013 (defcustom message-send-mail-partially-limit 1000000
1014 "The limitation of messages sent as message/partial.
1015 The lower bound of message size in characters, beyond which the message
1016 should be sent in several parts. If it is nil, the size is unlimited."
1018 :group 'message-buffers
1019 :type '(choice (const :tag "unlimited" nil)
1022 (defcustom message-alternative-emails nil
1023 "A regexp to match the alternative email addresses.
1024 The first matched address (not primary one) is used in the From field."
1025 :group 'message-headers
1026 :type '(choice (const :tag "Always use primary" nil)
1029 (defcustom message-mail-user-agent nil
1030 "Like `mail-user-agent'.
1031 Except if it is nil, use Gnus native MUA; if it is t, use
1033 :type '(radio (const :tag "Gnus native"
1036 (const :tag "`mail-user-agent'"
1039 (function-item :tag "Default Emacs mail"
1041 sendmail-user-agent)
1042 (function-item :tag "Emacs interface to MH"
1045 (function :tag "Other"))
1049 (defcustom message-wide-reply-confirm-recipients nil
1050 "Whether to confirm a wide reply to multiple email recipients.
1051 If this variable is nil, don't ask whether to reply to all recipients.
1052 If this variable is non-nil, pose the question \"Reply to all
1053 recipients?\" before a wide reply to multiple recipients. If the user
1054 answers yes, reply to all recipients as usual. If the user answers
1055 no, only reply back to the author."
1056 :group 'message-headers
1059 (defcustom message-insert-canlock t
1060 "Whether to insert a Cancel-Lock header in news postings."
1061 :group 'message-headers
1064 ;;; Internal variables.
1066 (defvar message-sending-message "Sending...")
1067 (defvar message-buffer-list nil)
1068 (defvar message-this-is-news nil)
1069 (defvar message-this-is-mail nil)
1070 (defvar message-draft-article nil)
1071 (defvar message-mime-part nil)
1072 (defvar message-posting-charset nil)
1074 ;; Byte-compiler warning
1076 (defvar gnus-active-hashtb)
1077 (defvar gnus-read-active-file))
1079 ;;; Regexp matching the delimiter of messages in UNIX mail format
1080 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1081 ;;; of rmail.el's rmail-unix-mail-delimiter.
1082 (defvar message-unix-mail-delimiter
1083 (let ((time-zone-regexp
1084 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1085 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1091 ;; Many things can happen to an RFC 822 mailbox before it is put into
1092 ;; a `From' line. The leading phrase can be stripped, e.g.
1093 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1094 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1095 ;; can be removed, e.g.
1096 ;; From: joe@y.z (Joe K
1098 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1101 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1102 ;; The mailbox can be removed or be replaced by white space, e.g.
1103 ;; From: "Joe User"{space}{tab}
1105 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1106 ;; where {space} and {tab} represent the Ascii space and tab characters.
1107 ;; We want to match the results of any of these manglings.
1108 ;; The following regexp rejects names whose first characters are
1109 ;; obviously bogus, but after that anything goes.
1110 "\\([^\0-\b\n-\r\^?].*\\)? "
1112 ;; The time the message was sent.
1113 "\\([^\0-\r \^?]+\\) +" ; day of the week
1114 "\\([^\0-\r \^?]+\\) +" ; month
1115 "\\([0-3]?[0-9]\\) +" ; day of month
1116 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1118 ;; Perhaps a time zone, specified by an abbreviation, or by a
1123 " \\([0-9][0-9]+\\) *"
1125 ;; On some systems the time zone can appear after the year, too.
1129 "\\(remote from .*\\)?"
1132 "Regexp matching the delimiter of messages in UNIX mail format.")
1134 (defvar message-unsent-separator
1135 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1136 "^ *---+ +Returned message +---+ *$\\|"
1137 "^Start of returned message$\\|"
1138 "^ *---+ +Original message +---+ *$\\|"
1139 "^ *--+ +begin message +--+ *$\\|"
1140 "^ *---+ +Original message follows +---+ *$\\|"
1141 "^ *---+ +Undelivered message follows +---+ *$\\|"
1142 "^|? *---+ +Message text follows: +---+ *|?$")
1143 "A regexp that matches the separator before the text of a failed message.")
1145 (defvar message-header-format-alist
1147 (To . message-fill-address)
1148 (Cc . message-fill-address)
1159 (References . message-shorten-references)
1161 "Alist used for formatting headers.")
1163 (defvar message-options nil
1164 "Some saved answers when sending message.")
1166 (defvar message-send-mail-real-function nil
1167 "Internal send mail function.")
1169 (defvar message-bogus-system-names "^localhost\\."
1170 "The regexp of bogus system names.")
1173 (autoload 'message-setup-toolbar "messagexmas")
1174 (autoload 'mh-new-draft-name "mh-comp")
1175 (autoload 'mh-send-letter "mh-comp")
1176 (autoload 'gnus-point-at-eol "gnus-util")
1177 (autoload 'gnus-point-at-bol "gnus-util")
1178 (autoload 'gnus-output-to-rmail "gnus-util")
1179 (autoload 'gnus-output-to-mail "gnus-util")
1180 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1181 (autoload 'nndraft-request-associate-buffer "nndraft")
1182 (autoload 'nndraft-request-expire-articles "nndraft")
1183 (autoload 'gnus-open-server "gnus-int")
1184 (autoload 'gnus-request-post "gnus-int")
1185 (autoload 'gnus-alive-p "gnus-util")
1186 (autoload 'gnus-server-string "gnus")
1187 (autoload 'gnus-group-name-charset "gnus-group")
1188 (autoload 'gnus-group-name-decode "gnus-group")
1189 (autoload 'gnus-groups-from-server "gnus")
1190 (autoload 'rmail-output "rmailout"))
1195 ;;; Utility functions.
1198 (defmacro message-y-or-n-p (question show &rest text)
1199 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1200 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1202 (defmacro message-delete-line (&optional n)
1203 "Delete the current line (and the next N lines)."
1204 `(delete-region (progn (beginning-of-line) (point))
1205 (progn (forward-line ,(or n 1)) (point))))
1207 (defun message-unquote-tokens (elems)
1208 "Remove double quotes (\") from strings in list ELEMS."
1209 (mapcar (lambda (item)
1210 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1211 (setq item (concat (match-string 1 item)
1212 (match-string 2 item))))
1216 (defun message-tokenize-header (header &optional separator)
1217 "Split HEADER into a list of header elements.
1218 SEPARATOR is a string of characters to be used as separators. \",\"
1219 is used by default."
1222 (let ((regexp (format "[%s]+" (or separator ",")))
1227 (message-set-work-buffer)
1229 (goto-char (point-min))
1234 (cond ((and (> (point) beg)
1236 (and (looking-at regexp)
1239 (push (buffer-substring beg (point)) elems)
1240 (setq beg (match-end 0)))
1241 ((eq (char-after) ?\")
1242 (setq quoted (not quoted)))
1243 ((and (eq (char-after) ?\()
1246 ((and (eq (char-after) ?\))
1249 (nreverse elems)))))
1251 (defun message-mail-file-mbox-p (file)
1252 "Say whether FILE looks like a Unix mbox file."
1253 (when (and (file-exists-p file)
1254 (file-readable-p file)
1255 (file-regular-p file))
1257 (nnheader-insert-file-contents file)
1258 (goto-char (point-min))
1259 (looking-at message-unix-mail-delimiter))))
1261 (defun message-fetch-field (header &optional not-all)
1262 "The same as `mail-fetch-field', only remove all newlines."
1263 (let* ((inhibit-point-motion-hooks t)
1264 (case-fold-search t)
1265 (value (mail-fetch-field header nil (not not-all))))
1267 (while (string-match "\n[\t ]+" value)
1268 (setq value (replace-match " " t t value)))
1269 (set-text-properties 0 (length value) nil value)
1272 (defun message-narrow-to-field ()
1273 "Narrow the buffer to the header on the current line."
1279 (if (re-search-forward "^[^ \n\t]" nil t)
1284 (goto-char (point-min)))
1286 (defun message-add-header (&rest headers)
1287 "Add the HEADERS to the message header, skipping those already present."
1290 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1291 (error "Invalid header `%s'" (car headers)))
1292 (setq hclean (match-string 1 (car headers)))
1294 (message-narrow-to-headers)
1295 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1296 (goto-char (point-max))
1297 (if (string-match "\n$" (car headers))
1298 (insert (car headers))
1299 (insert (car headers) ?\n)))))
1300 (setq headers (cdr headers))))
1303 (defun message-fetch-reply-field (header)
1304 "Fetch field HEADER from the message we're replying to."
1305 (when (and message-reply-buffer
1306 (buffer-name message-reply-buffer))
1308 (set-buffer message-reply-buffer)
1309 (message-fetch-field header))))
1311 (defun message-set-work-buffer ()
1312 (if (get-buffer " *message work*")
1314 (set-buffer " *message work*")
1316 (set-buffer (get-buffer-create " *message work*"))
1317 (kill-all-local-variables)
1318 (mm-enable-multibyte)))
1320 (defun message-functionp (form)
1321 "Return non-nil if FORM is funcallable."
1322 (or (and (symbolp form) (fboundp form))
1323 (and (listp form) (eq (car form) 'lambda))
1324 (byte-code-function-p form)))
1326 (defun message-strip-list-identifiers (subject)
1327 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1328 (require 'gnus-sum) ; for gnus-list-identifiers
1329 (let ((regexp (if (stringp gnus-list-identifiers)
1330 gnus-list-identifiers
1331 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1332 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1333 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1334 (concat (substring subject 0 (match-beginning 1))
1335 (or (match-string 3 subject)
1336 (match-string 5 subject))
1341 (defun message-strip-subject-re (subject)
1342 "Remove \"Re:\" from subject lines in string SUBJECT."
1343 (if (string-match message-subject-re-regexp subject)
1344 (substring subject (match-end 0))
1347 (defun message-remove-header (header &optional is-regexp first reverse)
1348 "Remove HEADER in the narrowed buffer.
1349 If IS-REGEXP, HEADER is a regular expression.
1350 If FIRST, only remove the first instance of the header.
1351 Return the number of headers removed."
1352 (goto-char (point-min))
1353 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1355 (case-fold-search t)
1357 (while (and (not (eobp))
1360 (not (looking-at regexp))
1361 (looking-at regexp))
1368 ;; There might be a continuation header, so we have to search
1369 ;; until we find a new non-continuation line.
1372 (if (re-search-forward "^[^ \t]" nil t)
1373 (goto-char (match-beginning 0))
1376 (if (re-search-forward "^[^ \t]" nil t)
1377 (goto-char (match-beginning 0))
1378 (goto-char (point-max)))))
1381 (defun message-remove-first-header (header)
1382 "Remove the first instance of HEADER if there is more than one."
1384 (regexp (concat "^" (regexp-quote header) ":")))
1386 (goto-char (point-min))
1387 (while (re-search-forward regexp nil t)
1390 (message-remove-header header nil t)
1393 (defun message-narrow-to-headers ()
1394 "Narrow the buffer to the head of the message."
1397 (goto-char (point-min))
1398 (if (re-search-forward
1399 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1402 (goto-char (point-min)))
1404 (defun message-narrow-to-head-1 ()
1405 "Like `message-narrow-to-head'. Don't widen."
1407 (goto-char (point-min))
1408 (if (search-forward "\n\n" nil 1)
1411 (goto-char (point-min)))
1413 (defun message-narrow-to-head ()
1414 "Narrow the buffer to the head of the message.
1415 Point is left at the beginning of the narrowed-to region."
1417 (message-narrow-to-head-1))
1419 (defun message-narrow-to-headers-or-head ()
1420 "Narrow the buffer to the head of the message."
1423 (goto-char (point-min))
1426 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1427 (match-beginning 0))
1428 ((search-forward "\n\n" nil t)
1432 (goto-char (point-min)))
1434 (defun message-news-p ()
1435 "Say whether the current buffer contains a news message."
1436 (and (not message-this-is-mail)
1437 (or message-this-is-news
1440 (message-narrow-to-headers)
1441 (and (message-fetch-field "newsgroups")
1442 (not (message-fetch-field "posted-to"))))))))
1444 (defun message-mail-p ()
1445 "Say whether the current buffer contains a mail message."
1446 (and (not message-this-is-news)
1447 (or message-this-is-mail
1450 (message-narrow-to-headers)
1451 (or (message-fetch-field "to")
1452 (message-fetch-field "cc")
1453 (message-fetch-field "bcc")))))))
1455 (defun message-next-header ()
1456 "Go to the beginning of the next header."
1458 (or (eobp) (forward-char 1))
1459 (not (if (re-search-forward "^[^ \t]" nil t)
1461 (goto-char (point-max)))))
1463 (defun message-sort-headers-1 ()
1464 "Sort the buffer as headers using `message-rank' text props."
1465 (goto-char (point-min))
1468 nil 'message-next-header
1470 (message-next-header)
1474 (or (get-text-property (point) 'message-rank)
1477 (defun message-sort-headers ()
1478 "Sort the headers of the current message according to `message-header-format-alist'."
1482 (let ((max (1+ (length message-header-format-alist)))
1484 (message-narrow-to-headers)
1485 (while (re-search-forward "^[^ \n]+:" nil t)
1487 (match-beginning 0) (1+ (match-beginning 0))
1489 (if (setq rank (length (memq (assq (intern (buffer-substring
1491 (1- (match-end 0))))
1492 message-header-format-alist)
1493 message-header-format-alist)))
1496 (message-sort-headers-1))))
1506 (defvar message-mode-map nil)
1508 (unless message-mode-map
1509 (setq message-mode-map (make-keymap))
1510 (set-keymap-parent message-mode-map text-mode-map)
1511 (define-key message-mode-map "\C-c?" 'describe-mode)
1513 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1514 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1515 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1516 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1517 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1518 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1519 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1520 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1521 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1522 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1523 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1524 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1525 (define-key message-mode-map "\C-c\C-f\C-i" 'message-insert-or-toggle-importance)
1526 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1527 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1529 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1530 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1532 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1533 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1534 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1535 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1536 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1537 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1538 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1539 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1541 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1542 (define-key message-mode-map "\C-c\C-s" 'message-send)
1543 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1544 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1545 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
1547 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1548 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1549 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1550 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1551 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1553 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1555 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
1556 (define-key message-mode-map "\t" 'message-tab)
1557 (define-key message-mode-map "\M-;" 'comment-region))
1560 message-mode-menu message-mode-map "Message Menu."
1562 ["Sort Headers" message-sort-headers t]
1563 ["Yank Original" message-yank-original t]
1564 ["Fill Yanked Message" message-fill-yanked-message t]
1565 ["Insert Signature" message-insert-signature t]
1566 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1567 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1568 ["Elide Region" message-elide-region (mark t)]
1569 ["Delete Outside Region" message-delete-not-region (mark t)]
1570 ["Kill To Signature" message-kill-to-signature t]
1571 ["Newline and Reformat" message-newline-and-reformat t]
1572 ["Rename buffer" message-rename-buffer t]
1573 ["Flag as important" message-insert-importance-high
1574 ,@(if (featurep 'xemacs) '(t)
1575 '(:help "Mark this message as important"))]
1576 ["Flag as unimportant" message-insert-importance-low
1577 ,@(if (featurep 'xemacs) '(t)
1578 '(:help "Mark this message as unimportant"))]
1579 ["Spellcheck" ispell-message
1580 ,@(if (featurep 'xemacs) '(t)
1581 '(:help "Spellcheck this message"))]
1583 ["Send Message" message-send-and-exit
1584 ,@(if (featurep 'xemacs) '(t)
1585 '(:help "Send this message"))]
1586 ["Postpone Message" message-dont-send
1587 ,@(if (featurep 'xemacs) '(t)
1588 '(:help "File this draft message and exit"))]
1589 ["Send at Specific Time" gnus-delay-article
1590 ,@(if (featurep 'xemacs) '(t)
1591 '(:help "Ask, then arrange to send message at that time"))]
1592 ["Kill Message" message-kill-buffer
1593 ,@(if (featurep 'xemacs) '(t)
1594 '(:help "Delete this message without sending"))]))
1597 message-mode-field-menu message-mode-map ""
1599 ["Fetch To" message-insert-to t]
1600 ["Fetch Newsgroups" message-insert-newsgroups t]
1602 ["To" message-goto-to t]
1603 ["Subject" message-goto-subject t]
1604 ["Cc" message-goto-cc t]
1605 ["Reply-To" message-goto-reply-to t]
1606 ["Summary" message-goto-summary t]
1607 ["Keywords" message-goto-keywords t]
1608 ["Newsgroups" message-goto-newsgroups t]
1609 ["Followup-To" message-goto-followup-to t]
1610 ["Mail-Followup-To" message-goto-mail-followup-to t]
1611 ["Distribution" message-goto-distribution t]
1612 ["Body" message-goto-body t]
1613 ["Signature" message-goto-signature t]))
1615 (defvar message-tool-bar-map nil)
1618 (defvar facemenu-add-face-function)
1619 (defvar facemenu-remove-face-function))
1621 ;;; Forbidden properties
1623 ;; We use `after-change-functions' to keep special text properties
1624 ;; that interfer with the normal function of message mode out of the
1627 (defcustom message-strip-special-text-properties t
1628 "Strip special properties from the message buffer.
1630 Emacs has a number of special text properties which can break message
1631 composing in various ways. If this option is set, message will strip
1632 these properties from the message composition buffer. However, some
1633 packages requires these properties to be present in order to work.
1634 If you use one of these packages, turn this option off, and hope the
1635 message composition doesn't break too bad."
1636 :group 'message-various
1639 (defconst message-forbidden-properties
1640 ;; No reason this should be clutter up customize. We make it a
1641 ;; property list (rather than a list of property symbols), to be
1642 ;; directly useful for `remove-text-properties'.
1643 '(field nil read-only nil intangible nil invisible nil
1644 mouse-face nil modification-hooks nil insert-in-front-hooks nil
1645 insert-behind-hooks nil point-entered nil point-left nil)
1646 ;; Other special properties:
1647 ;; category, face, display: probably doesn't do any harm.
1648 ;; fontified: is used by font-lock.
1649 ;; syntax-table, local-map: I dunno.
1650 ;; We need to add XEmacs names to the list.
1651 "Property list of with properties.forbidden in message buffers.
1652 The values of the properties are ignored, only the property names are used.")
1654 (defun message-tamago-not-in-use-p (pos)
1655 "Return t when tamago version 4 is not in use at the cursor position.
1656 Tamago version 4 is a popular input method for writing Japanese text.
1657 It uses the properties `intangible', `invisible', `modification-hooks'
1658 and `read-only' when translating ascii or kana text to kanji text.
1659 These properties are essential to work, so we should never strip them."
1660 (not (and (boundp 'egg-modefull-mode)
1661 (symbol-value 'egg-modefull-mode)
1662 (or (memq (get-text-property pos 'intangible)
1663 '(its-part-1 its-part-2))
1664 (get-text-property pos 'egg-end)
1665 (get-text-property pos 'egg-lang)
1666 (get-text-property pos 'egg-start)))))
1668 (defun message-strip-forbidden-properties (begin end &optional old-length)
1669 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
1670 This function is intended to be called from `after-change-functions'.
1671 See also `message-forbidden-properties'."
1672 (when (and message-strip-special-text-properties
1673 (message-tamago-not-in-use-p begin))
1674 (remove-text-properties begin end message-forbidden-properties)))
1677 (define-derived-mode message-mode text-mode "Message"
1678 "Major mode for editing mail and news to be sent.
1679 Like Text Mode but with these additional commands:\\<message-mode-map>
1680 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1681 C-c C-d Postpone sending the message C-c C-k Kill the message
1682 C-c C-f move to a header field (and create it if there isn't):
1683 C-c C-f C-t move to To C-c C-f C-s move to Subject
1684 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1685 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1686 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1687 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1688 C-c C-f C-f move to Followup-To
1689 C-c C-f C-m move to Mail-Followup-To
1690 C-c C-t `message-insert-to' (add a To header to a news followup)
1691 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1692 C-c C-b `message-goto-body' (move to beginning of message text).
1693 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1694 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1695 C-c C-y `message-yank-original' (insert current message, if any).
1696 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1697 C-c C-e `message-elide-region' (elide the text between point and mark).
1698 C-c C-v `message-delete-not-region' (remove the text outside the region).
1699 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1700 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1701 C-c C-a `mml-attach-file' (attach a file as MIME).
1702 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance)
1703 M-RET `message-newline-and-reformat' (break the line and reformat)."
1704 (set (make-local-variable 'message-reply-buffer) nil)
1705 (make-local-variable 'message-send-actions)
1706 (make-local-variable 'message-exit-actions)
1707 (make-local-variable 'message-kill-actions)
1708 (make-local-variable 'message-postpone-actions)
1709 (make-local-variable 'message-draft-article)
1710 (setq buffer-offer-save t)
1711 (set (make-local-variable 'facemenu-add-face-function)
1713 (let ((face-fun (cdr (assq face message-face-alist))))
1715 (funcall face-fun (point) end)
1716 (error "Face %s not configured for %s mode" face mode-name)))
1718 (set (make-local-variable 'facemenu-remove-face-function) t)
1719 (set (make-local-variable 'message-reply-headers) nil)
1720 (make-local-variable 'message-newsreader)
1721 (make-local-variable 'message-mailer)
1722 (make-local-variable 'message-post-method)
1723 (set (make-local-variable 'message-sent-message-via) nil)
1724 (set (make-local-variable 'message-checksum) nil)
1725 (set (make-local-variable 'message-mime-part) 0)
1726 (message-setup-fill-variables)
1727 ;; Allow using comment commands to add/remove quoting.
1728 (set (make-local-variable 'comment-start) message-yank-prefix)
1729 (if (featurep 'xemacs)
1730 (message-setup-toolbar)
1731 (set (make-local-variable 'font-lock-defaults)
1732 '(message-font-lock-keywords t))
1733 (if (boundp 'tool-bar-map)
1734 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1735 (easy-menu-add message-mode-menu message-mode-map)
1736 (easy-menu-add message-mode-field-menu message-mode-map)
1737 ;; make-local-hook is harmless though obsolete in Emacs 21.
1738 ;; Emacs 20 and XEmacs need make-local-hook.
1739 (make-local-hook 'after-change-functions)
1740 ;; Mmmm... Forbidden properties...
1741 (add-hook 'after-change-functions 'message-strip-forbidden-properties
1743 ;; Allow mail alias things.
1744 (when (eq message-mail-alias-type 'abbrev)
1745 (if (fboundp 'mail-abbrevs-setup)
1746 (mail-abbrevs-setup)
1747 (mail-aliases-setup)))
1748 (message-set-auto-save-file-name)
1749 (mm-enable-multibyte)
1750 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
1753 (defun message-setup-fill-variables ()
1754 "Setup message fill variables."
1755 (set (make-local-variable 'fill-paragraph-function)
1756 'message-fill-paragraph)
1757 (make-local-variable 'paragraph-separate)
1758 (make-local-variable 'paragraph-start)
1759 (make-local-variable 'adaptive-fill-regexp)
1760 (unless (boundp 'adaptive-fill-first-line-regexp)
1761 (setq adaptive-fill-first-line-regexp nil))
1762 (make-local-variable 'adaptive-fill-first-line-regexp)
1763 (let ((quote-prefix-regexp
1764 ;; User should change message-cite-prefix-regexp if
1765 ;; message-yank-prefix is set to an abnormal value.
1766 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
1767 (setq paragraph-start
1769 (regexp-quote mail-header-separator) "$\\|"
1770 "[ \t]*$\\|" ; blank lines
1771 "-- $\\|" ; signature delimiter
1772 "---+$\\|" ; delimiters for forwarded messages
1773 page-delimiter "$\\|" ; spoiler warnings
1774 ".*wrote:$\\|" ; attribution lines
1775 quote-prefix-regexp "$")) ; empty lines in quoted text
1776 (setq paragraph-separate paragraph-start)
1777 (setq adaptive-fill-regexp
1778 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1779 (setq adaptive-fill-first-line-regexp
1780 (concat quote-prefix-regexp "\\|"
1781 adaptive-fill-first-line-regexp)))
1782 (make-local-variable 'auto-fill-inhibit-regexp)
1783 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1784 (setq auto-fill-inhibit-regexp nil)
1785 (make-local-variable 'normal-auto-fill-function)
1786 (setq normal-auto-fill-function 'message-do-auto-fill)
1787 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
1788 ;; In that case, ensure that it uses the right function. The real
1789 ;; solution would be not to use `define-derived-mode', and run
1790 ;; `text-mode-hook' ourself at the end of the mode.
1791 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
1792 (when auto-fill-function
1793 (setq auto-fill-function normal-auto-fill-function)))
1798 ;;; Message mode commands
1801 ;;; Movement commands
1803 (defun message-goto-to ()
1804 "Move point to the To header."
1806 (message-position-on-field "To"))
1808 (defun message-goto-subject ()
1809 "Move point to the Subject header."
1811 (message-position-on-field "Subject"))
1813 (defun message-goto-cc ()
1814 "Move point to the Cc header."
1816 (message-position-on-field "Cc" "To"))
1818 (defun message-goto-bcc ()
1819 "Move point to the Bcc header."
1821 (message-position-on-field "Bcc" "Cc" "To"))
1823 (defun message-goto-fcc ()
1824 "Move point to the Fcc header."
1826 (message-position-on-field "Fcc" "To" "Newsgroups"))
1828 (defun message-goto-reply-to ()
1829 "Move point to the Reply-To header."
1831 (message-position-on-field "Reply-To" "Subject"))
1833 (defun message-goto-newsgroups ()
1834 "Move point to the Newsgroups header."
1836 (message-position-on-field "Newsgroups"))
1838 (defun message-goto-distribution ()
1839 "Move point to the Distribution header."
1841 (message-position-on-field "Distribution"))
1843 (defun message-goto-followup-to ()
1844 "Move point to the Followup-To header."
1846 (message-position-on-field "Followup-To" "Newsgroups"))
1848 (defun message-goto-mail-followup-to ()
1849 "Move point to the Mail-Followup-To header."
1851 (message-position-on-field "Mail-Followup-To" "From"))
1853 (defun message-goto-keywords ()
1854 "Move point to the Keywords header."
1856 (message-position-on-field "Keywords" "Subject"))
1858 (defun message-goto-summary ()
1859 "Move point to the Summary header."
1861 (message-position-on-field "Summary" "Subject"))
1863 (defun message-goto-body (&optional interactivep)
1864 "Move point to the beginning of the message body."
1865 (interactive (list t))
1866 (when (and interactivep
1867 (looking-at "[ \t]*\n"))
1869 (goto-char (point-min))
1870 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1871 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
1873 (defun message-goto-eoh ()
1874 "Move point to the end of the headers."
1879 (defun message-goto-signature ()
1880 "Move point to the beginning of the message signature.
1881 If there is no signature in the article, go to the end and
1884 (goto-char (point-min))
1885 (if (re-search-forward message-signature-separator nil t)
1887 (goto-char (point-max))
1892 (defun message-insert-to (&optional force)
1893 "Insert a To header that points to the author of the article being replied to.
1894 If the original author requested not to be sent mail, the function signals
1896 With the prefix argument FORCE, insert the header anyway."
1898 (let ((co (message-fetch-reply-field "mail-copies-to")))
1899 (when (and (null force)
1901 (or (equal (downcase co) "never")
1902 (equal (downcase co) "nobody")))
1903 (error "The user has requested not to have copies sent via mail")))
1904 (when (and (message-position-on-field "To")
1905 (mail-fetch-field "to")
1906 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1908 (insert (or (message-fetch-reply-field "mail-reply-to")
1909 (message-fetch-reply-field "reply-to")
1910 (message-fetch-reply-field "from") "")))
1912 (defun message-widen-reply ()
1913 "Widen the reply to include maximum recipients."
1916 (and message-reply-buffer
1917 (buffer-name message-reply-buffer)
1919 (set-buffer message-reply-buffer)
1920 (message-get-reply-headers t)))))
1923 (message-narrow-to-headers)
1924 (dolist (elem follow-to)
1925 (message-remove-header (symbol-name (car elem)))
1926 (goto-char (point-min))
1927 (insert (symbol-name (car elem)) ": "
1928 (cdr elem) "\n"))))))
1930 (defun message-insert-newsgroups ()
1931 "Insert the Newsgroups header from the article being replied to."
1933 (when (and (message-position-on-field "Newsgroups")
1934 (mail-fetch-field "newsgroups")
1935 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1937 (insert (or (message-fetch-reply-field "newsgroups") "")))
1941 ;;; Various commands
1943 (defun message-delete-not-region (beg end)
1944 "Delete everything in the body of the current message outside of the region."
1949 ;; snarf citation prefix, if appropriate
1950 (unless (eq (point) (progn (beginning-of-line) (point)))
1951 (when (looking-at message-cite-prefix-regexp)
1952 (setq citeprefix (match-string 0))))
1954 (delete-region (point) (if (not (message-goto-signature))
1960 (delete-region beg (progn (message-goto-body)
1964 (insert citeprefix))))
1965 (when (message-goto-signature)
1968 (defun message-kill-to-signature ()
1969 "Deletes all text up to the signature."
1971 (let ((point (point)))
1972 (message-goto-signature)
1975 (kill-region point (point))
1979 (defun message-newline-and-reformat (&optional arg not-break)
1980 "Insert four newlines, and then reformat if inside quoted text.
1981 Prefix arg means justify as well."
1982 (interactive (list (if current-prefix-arg 'full)))
1983 (let (quoted point beg end leading-space bolp)
1984 (setq point (point))
1987 (setq bolp (= beg point))
1988 ;; Find first line of the paragraph.
1990 (while (and (not (eobp))
1991 (not (looking-at message-cite-prefix-regexp))
1992 (looking-at paragraph-start))
1995 (when (looking-at message-cite-prefix-regexp)
1996 (setq quoted (match-string 0))
1997 (goto-char (match-end 0))
1998 (looking-at "[ \t]*")
1999 (setq leading-space (match-string 0)))
2003 (< (- point beg) (length quoted)))
2004 ;; break inside the cite prefix.
2010 (while (and (not (eobp))
2011 (not (looking-at paragraph-separate))
2012 (looking-at message-cite-prefix-regexp)
2013 (equal quoted (match-string 0)))
2014 (goto-char (match-end 0))
2015 (looking-at "[ \t]*")
2016 (if (> (length leading-space) (length (match-string 0)))
2017 (setq leading-space (match-string 0)))
2021 (while (and (if (bobp) nil (forward-line -1) t)
2022 (not (looking-at paragraph-start))
2023 (looking-at message-cite-prefix-regexp)
2024 (equal quoted (match-string 0)))
2026 (goto-char (match-end 0))
2027 (looking-at "[ \t]*")
2028 (if (> (length leading-space) (length (match-string 0)))
2029 (setq leading-space (match-string 0)))))
2030 (while (and (not (eobp))
2031 (not (looking-at paragraph-separate))
2032 (not (looking-at message-cite-prefix-regexp)))
2036 (while (and (if (bobp) nil (forward-line -1) t)
2037 (not (looking-at paragraph-start))
2038 (not (looking-at message-cite-prefix-regexp)))
2039 (setq beg (point))))
2042 (narrow-to-region beg end)
2048 (setq point (point))
2050 (delete-region (point) (re-search-forward "[ \t]*"))
2051 (when (and quoted (not bolp))
2052 (insert quoted leading-space)))
2054 (let* ((adaptive-fill-regexp
2055 (regexp-quote (concat quoted leading-space)))
2056 (adaptive-fill-first-line-regexp
2057 adaptive-fill-regexp ))
2058 (fill-paragraph arg))
2059 (fill-paragraph arg))
2060 (if point (goto-char point)))))
2062 (defun message-fill-paragraph (&optional arg)
2063 "Like `fill-paragraph'."
2064 (interactive (list (if current-prefix-arg 'full)))
2065 (if (and (boundp 'filladapt-mode) filladapt-mode)
2067 (message-newline-and-reformat arg t)
2070 ;; Is it better to use `mail-header-end'?
2071 (defun message-point-in-header-p ()
2072 "Return t if point is in the header."
2075 (goto-char (point-min))
2076 (not (re-search-forward
2077 (concat "^" (regexp-quote mail-header-separator) "\n")
2080 (defun message-do-auto-fill ()
2081 "Like `do-auto-fill', but don't fill in message header."
2082 (unless (message-point-in-header-p)
2085 (defun message-insert-signature (&optional force)
2086 "Insert a signature. See documentation for variable `message-signature'."
2087 (interactive (list 0))
2090 ((and (null message-signature)
2093 (goto-char (point-max))
2094 (not (re-search-backward message-signature-separator nil t))))
2095 ((and (null message-signature)
2098 ((message-functionp message-signature)
2099 (funcall message-signature))
2100 ((listp message-signature)
2101 (eval message-signature))
2102 (t message-signature)))
2104 (cond ((stringp signature)
2106 ((and (eq t signature)
2107 message-signature-file
2108 (file-exists-p message-signature-file))
2111 (goto-char (point-max))
2112 ;; Insert the signature.
2116 (if (eq signature t)
2117 (insert-file-contents message-signature-file)
2119 (goto-char (point-max))
2120 (or (bolp) (insert "\n")))))
2122 (defun message-insert-importance-high ()
2123 "Insert header to mark message as important."
2126 (message-remove-header "Importance")
2128 (insert "Importance: high\n")))
2130 (defun message-insert-importance-low ()
2131 "Insert header to mark message as unimportant."
2134 (message-remove-header "Importance")
2136 (insert "Importance: low\n")))
2138 (defun message-insert-or-toggle-importance ()
2139 "Insert a \"Importance: high\" header, or cycle through the header values.
2140 The three allowed values according to RFC 1327 are `high', `normal'
2144 (let ((valid '("high" "normal" "low"))
2147 (when (setq cur (message-fetch-field "Importance"))
2148 (message-remove-header "Importance")
2149 (setq new (cond ((string= cur "high")
2151 ((string= cur "low")
2156 (insert (format "Importance: %s\n" new)))))
2158 (defun message-elide-region (b e)
2159 "Elide the text in the region.
2160 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2164 (insert message-elide-ellipsis))
2166 (defvar message-caesar-translation-table nil)
2168 (defun message-caesar-region (b e &optional n)
2169 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2172 (min (point) (or (mark t) (point)))
2173 (max (point) (or (mark t) (point)))
2174 (when current-prefix-arg
2175 (prefix-numeric-value current-prefix-arg))))
2177 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2178 (unless (or (zerop n) ; no action needed for a rot of 0
2179 (= b e)) ; no region to rotate
2180 ;; We build the table, if necessary.
2181 (when (or (not message-caesar-translation-table)
2182 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2183 (setq message-caesar-translation-table
2184 (message-make-caesar-translation-table n)))
2185 (translate-region b e message-caesar-translation-table)))
2187 (defun message-make-caesar-translation-table (n)
2188 "Create a rot table with offset N."
2190 (table (make-string 256 0)))
2191 (while (< (incf i) 256)
2194 (substring table 0 ?A)
2195 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2196 (substring table ?A (+ ?A n))
2197 (substring table (+ ?A 26) ?a)
2198 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2199 (substring table ?a (+ ?a n))
2200 (substring table (+ ?a 26) 255))))
2202 (defun message-caesar-buffer-body (&optional rotnum)
2203 "Caesar rotate all letters in the current buffer by 13 places.
2204 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2205 With prefix arg, specifies the number of places to rotate each letter forward.
2206 Mail and USENET news headers are not rotated."
2207 (interactive (if current-prefix-arg
2208 (list (prefix-numeric-value current-prefix-arg))
2212 (when (message-goto-body)
2213 (narrow-to-region (point) (point-max)))
2214 (message-caesar-region (point-min) (point-max) rotnum))))
2216 (defun message-pipe-buffer-body (program)
2217 "Pipe the message body in the current buffer through PROGRAM."
2220 (when (message-goto-body)
2221 (narrow-to-region (point) (point-max)))
2222 (shell-command-on-region
2223 (point-min) (point-max) program nil t))))
2225 (defun message-rename-buffer (&optional enter-string)
2226 "Rename the *message* buffer to \"*message* RECIPIENT\".
2227 If the function is run with a prefix, it will ask for a new buffer
2228 name, rather than giving an automatic name."
2229 (interactive "Pbuffer name: ")
2232 (goto-char (point-min))
2233 (narrow-to-region (point)
2234 (search-forward mail-header-separator nil 'end))
2236 (if (message-news-p) (message-fetch-field "Newsgroups")
2237 (message-fetch-field "To"))
2240 (if (string-match "," mail-to)
2241 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2243 (name-default (concat "*message* " mail-trimmed-to))
2244 (name (if enter-string
2245 (read-string "New buffer name: " name-default)
2247 (rename-buffer name t)))))
2249 (defun message-fill-yanked-message (&optional justifyp)
2250 "Fill the paragraphs of a message yanked into this one.
2251 Numeric argument means justify as well."
2254 (goto-char (point-min))
2255 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2256 (let ((fill-prefix message-yank-prefix))
2257 (fill-individual-paragraphs (point) (point-max) justifyp))))
2259 (defun message-indent-citation ()
2260 "Modify text just inserted from a message to be cited.
2261 The inserted text should be the region.
2262 When this function returns, the region is again around the modified text.
2264 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2265 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2266 (let ((start (point)))
2267 ;; Remove unwanted headers.
2268 (when message-ignored-cited-headers
2273 (if (search-forward "\n\n" nil t)
2276 (message-remove-header message-ignored-cited-headers t)
2277 (when (= (point-min) (point-max))
2278 (setq all-removed t))
2279 (goto-char (point-max)))
2283 ;; Delete blank lines at the start of the buffer.
2284 (while (and (point-min)
2287 (message-delete-line))
2288 ;; Delete blank lines at the end of the buffer.
2289 (goto-char (point-max))
2292 (while (and (zerop (forward-line -1))
2294 (message-delete-line))
2295 ;; Do the indentation.
2296 (if (null message-yank-prefix)
2297 (indent-rigidly start (mark t) message-indentation-spaces)
2300 (while (< (point) (mark t))
2301 (if (or (looking-at ">") (looking-at "^$"))
2302 (insert message-yank-cited-prefix)
2303 (insert message-yank-prefix))
2307 (defun message-yank-original (&optional arg)
2308 "Insert the message being replied to, if any.
2309 Puts point before the text and mark after.
2310 Normally indents each nonblank line ARG spaces (default 3). However,
2311 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2313 This function uses `message-cite-function' to do the actual citing.
2315 Just \\[universal-argument] as argument means don't indent, insert no
2316 prefix, and don't delete any headers."
2318 (let ((modified (buffer-modified-p)))
2319 (when (and message-reply-buffer
2320 message-cite-function)
2321 (delete-windows-on message-reply-buffer t)
2322 (insert-buffer message-reply-buffer)
2324 (funcall message-cite-function))
2325 (message-exchange-point-and-mark)
2329 (setq message-checksum (message-checksum))))))
2331 (defun message-yank-buffer (buffer)
2332 "Insert BUFFER into the current buffer and quote it."
2333 (interactive "bYank buffer: ")
2334 (let ((message-reply-buffer buffer))
2335 (save-window-excursion
2336 (message-yank-original))))
2338 (defun message-buffers ()
2339 "Return a list of active message buffers."
2342 (dolist (buffer (buffer-list t))
2344 (when (and (eq major-mode 'message-mode)
2345 (null message-sent-message-via))
2346 (push (buffer-name buffer) buffers))))
2347 (nreverse buffers)))
2349 (defun message-cite-original-without-signature ()
2350 "Cite function in the standard Message manner."
2351 (let ((start (point))
2354 (when message-indent-citation-function
2355 (if (listp message-indent-citation-function)
2356 message-indent-citation-function
2357 (list message-indent-citation-function)))))
2358 (mml-quote-region start end)
2362 (when (re-search-backward message-signature-separator start t)
2363 ;; Also peel off any blank lines before the signature.
2365 (while (looking-at "^[ \t]*$")
2368 (delete-region (point) end)
2369 (unless (search-backward "\n\n" start t)
2370 ;; Insert a blank line if it is peeled off.
2374 (funcall (pop functions)))
2375 (when message-citation-line-function
2378 (funcall message-citation-line-function))))
2380 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2381 (defun message-cite-original ()
2382 "Cite function in the standard Message manner."
2383 (if (and (boundp 'mail-citation-hook)
2385 (run-hooks 'mail-citation-hook)
2386 (let ((start (point))
2389 (when message-indent-citation-function
2390 (if (listp message-indent-citation-function)
2391 message-indent-citation-function
2392 (list message-indent-citation-function)))))
2393 (mml-quote-region start end)
2396 (funcall (pop functions)))
2397 (when message-citation-line-function
2400 (funcall message-citation-line-function)))))
2402 (defun message-insert-citation-line ()
2403 "Insert a simple citation line."
2404 (when message-reply-headers
2405 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2407 (defun message-position-on-field (header &rest afters)
2408 (let ((case-fold-search t))
2411 (goto-char (point-min))
2414 (concat "^" (regexp-quote mail-header-separator) "$"))
2415 (match-beginning 0)))
2416 (goto-char (point-min))
2417 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2419 (re-search-forward "^[^ \t]" nil 'move)
2421 (skip-chars-backward "\n")
2424 (not (re-search-forward
2425 (concat "^" (regexp-quote (car afters)) ":")
2429 (re-search-forward "^[^ \t]" nil 'move)
2430 (beginning-of-line))
2431 (insert header ": \n")
2435 (defun message-remove-signature ()
2436 "Remove the signature from the text between point and mark.
2437 The text will also be indented the normal way."
2439 (let ((start (point))
2441 (if (not (re-search-forward message-signature-separator (mark t) t))
2442 ;; No signature here, so we just indent the cited text.
2443 (message-indent-citation)
2444 ;; Find the last non-empty line.
2446 (while (looking-at "[ \t]*$")
2449 (setq mark (set-marker (make-marker) (point)))
2451 (message-indent-citation)
2452 ;; Enable undoing the deletion.
2454 (delete-region mark (mark t))
2455 (set-marker mark nil)))))
2460 ;;; Sending messages
2463 (defun message-send-and-exit (&optional arg)
2464 "Send message like `message-send', then, if no errors, exit from mail buffer."
2466 (let ((buf (current-buffer))
2467 (actions message-exit-actions))
2468 (when (and (message-send arg)
2470 (if message-kill-buffer-on-exit
2473 (when (eq buf (current-buffer))
2474 (message-bury buf)))
2475 (message-do-actions actions)
2478 (defun message-dont-send ()
2479 "Don't send the message you have been editing."
2481 (set-buffer-modified-p t)
2483 (let ((actions message-postpone-actions))
2484 (message-bury (current-buffer))
2485 (message-do-actions actions)))
2487 (defun message-kill-buffer ()
2488 "Kill the current buffer."
2490 (when (or (not (buffer-modified-p))
2491 (yes-or-no-p "Message modified; kill anyway? "))
2492 (let ((actions message-kill-actions)
2493 (draft-article message-draft-article)
2494 (auto-save-file-name buffer-auto-save-file-name)
2495 (file-name buffer-file-name)
2496 (modified (buffer-modified-p)))
2497 (setq buffer-file-name nil)
2498 (kill-buffer (current-buffer))
2499 (when (and (or (and auto-save-file-name
2500 (file-exists-p auto-save-file-name))
2502 (file-exists-p file-name)))
2503 (yes-or-no-p (format "Remove the backup file%s? "
2504 (if modified " too" ""))))
2506 (delete-file auto-save-file-name))
2507 (let ((message-draft-article draft-article))
2508 (message-disassociate-draft)))
2509 (message-do-actions actions))))
2511 (defun message-bury (buffer)
2512 "Bury this mail BUFFER."
2513 (let ((newbuf (other-buffer buffer)))
2514 (bury-buffer buffer)
2515 (if (and (fboundp 'frame-parameters)
2516 (cdr (assq 'dedicated (frame-parameters)))
2517 (not (null (delq (selected-frame) (visible-frame-list)))))
2518 (delete-frame (selected-frame))
2519 (switch-to-buffer newbuf))))
2521 (defun message-send (&optional arg)
2522 "Send the message in the current buffer.
2523 If `message-interactive' is non-nil, wait for success indication or
2524 error messages, and inform user.
2525 Otherwise any failure is reported in a message back to the user from
2527 The usage of ARG is defined by the instance that called Message.
2528 It should typically alter the sending method in some way or other."
2530 ;; Make it possible to undo the coming changes.
2532 (let ((inhibit-read-only t))
2533 (put-text-property (point-min) (point-max) 'read-only nil))
2534 (message-fix-before-sending)
2535 (run-hooks 'message-send-hook)
2536 (message message-sending-message)
2537 (let ((alist message-send-method-alist)
2539 elem sent dont-barf-on-no-method
2540 (message-options message-options))
2541 (message-options-set-recipient)
2543 (setq elem (pop alist)))
2544 (when (funcall (cadr elem))
2545 (when (and (or (not (memq (car elem)
2546 message-sent-message-via))
2547 (if (or (message-gnksa-enable-p 'multiple-copies)
2548 (not (eq (car elem) 'news)))
2551 "Already sent message via %s; resend? "
2553 (error "Denied posting -- multiple copies")))
2554 (setq success (funcall (caddr elem) arg)))
2556 (unless (or sent (not success)
2557 (let ((fcc (message-fetch-field "Fcc"))
2558 (gcc (message-fetch-field "Gcc")))
2560 (or (eq message-allow-no-recipients 'always)
2561 (and (not (eq message-allow-no-recipients 'never))
2562 (setq dont-barf-on-no-method
2564 (format "No receiver, perform %s anyway? "
2565 (cond ((and fcc gcc) "Fcc and Gcc")
2568 (error "No methods specified to send by"))
2569 (when (or dont-barf-on-no-method
2573 (run-hooks 'message-sent-hook))
2574 (message "Sending...done")
2575 ;; Mark the buffer as unmodified and delete auto-save.
2576 (set-buffer-modified-p nil)
2577 (delete-auto-save-file-if-necessary t)
2578 (message-disassociate-draft)
2579 ;; Delete other mail buffers and stuff.
2580 (message-do-send-housekeeping)
2581 (message-do-actions message-send-actions)
2585 (defun message-send-via-mail (arg)
2586 "Send the current message via mail."
2587 (message-send-mail arg))
2589 (defun message-send-via-news (arg)
2590 "Send the current message via news."
2591 (funcall message-send-news-function arg))
2593 (defmacro message-check (type &rest forms)
2594 "Eval FORMS if TYPE is to be checked."
2595 `(or (message-check-element ,type)
2599 (put 'message-check 'lisp-indent-function 1)
2600 (put 'message-check 'edebug-form-spec '(form body))
2602 (defun message-fix-before-sending ()
2603 "Do various things to make the message nice before sending it."
2604 ;; Make sure there's a newline at the end of the message.
2605 (goto-char (point-max))
2608 ;; Delete all invisible text.
2609 (message-check 'invisible-text
2610 (when (text-property-any (point-min) (point-max) 'invisible t)
2611 (put-text-property (point-min) (point-max) 'invisible nil)
2612 (unless (yes-or-no-p
2613 "Invisible text found and made visible; continue posting? ")
2614 (error "Invisible text found and made visible")))))
2616 (defun message-add-action (action &rest types)
2617 "Add ACTION to be performed when doing an exit of type TYPES."
2620 (set (setq var (intern (format "message-%s-actions" (pop types))))
2621 (nconc (symbol-value var) (list action))))))
2623 (defun message-do-actions (actions)
2624 "Perform all actions in ACTIONS."
2625 ;; Now perform actions on successful sending.
2629 ;; A simple function.
2630 ((message-functionp (car actions))
2631 (funcall (car actions)))
2632 ;; Something to be evaled.
2634 (eval (car actions)))))
2637 (defun message-send-mail-partially ()
2638 "Send mail as message/partial."
2639 ;; replace the header delimiter with a blank line
2640 (goto-char (point-min))
2642 (concat "^" (regexp-quote mail-header-separator) "\n"))
2643 (replace-match "\n")
2644 (run-hooks 'message-send-mail-hook)
2645 (let ((p (goto-char (point-min)))
2646 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2647 (curbuf (current-buffer))
2648 (id (message-make-message-id)) (n 1)
2649 plist total header required-mail-headers)
2651 (if (< (point-max) (+ p message-send-mail-partially-limit))
2652 (goto-char (point-max))
2653 (goto-char (+ p message-send-mail-partially-limit))
2655 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2658 (setq total (length plist))
2659 (push (point-max) plist)
2660 (setq plist (nreverse plist))
2663 (setq p (pop plist))
2666 (copy-to-buffer tembuf p (car plist))
2668 (goto-char (point-min))
2671 (goto-char (point-min))
2672 (narrow-to-region (point) (point))
2675 (setq header (buffer-substring (point-min) (point)))
2676 (goto-char (point-min))
2677 (narrow-to-region (point) (point))
2679 (message-remove-header "Mime-Version")
2680 (message-remove-header "Content-Type")
2681 (message-remove-header "Content-Transfer-Encoding")
2682 (message-remove-header "Message-ID")
2683 (message-remove-header "Lines")
2684 (goto-char (point-max))
2685 (insert "Mime-Version: 1.0\n")
2686 (setq header (buffer-substring (point-min) (point-max))))
2687 (goto-char (point-max))
2688 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
2691 (let ((mail-header-separator ""))
2692 (when (memq 'Message-ID message-required-mail-headers)
2693 (insert "Message-ID: " (message-make-message-id) "\n"))
2694 (when (memq 'Lines message-required-mail-headers)
2695 (insert "Lines: " (message-make-lines) "\n"))
2696 (message-goto-subject)
2698 (insert (format " (%d/%d)" n total))
2700 (mm-with-unibyte-current-buffer
2701 (funcall (or message-send-mail-real-function
2702 message-send-mail-function))))
2704 (setq p (pop plist))
2706 (kill-buffer tembuf))))
2708 (defun message-send-mail (&optional arg)
2709 (require 'mail-utils)
2710 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2711 (case-fold-search nil)
2712 (news (message-news-p))
2713 (mailbuf (current-buffer))
2714 (message-this-is-mail t)
2715 (message-posting-charset
2716 (if (fboundp 'gnus-setup-posting-charset)
2717 (gnus-setup-posting-charset nil)
2718 message-posting-charset))
2719 (headers message-required-mail-headers))
2721 (message-narrow-to-headers)
2722 ;; Generate the Mail-Followup-To header if the header is not there...
2723 (if (and (or message-subscribed-regexps
2724 message-subscribed-addresses
2725 message-subscribed-address-file
2726 message-subscribed-address-functions)
2727 (not (mail-fetch-field "mail-followup-to")))
2730 (cons "Mail-Followup-To" (message-make-mft))
2731 message-required-mail-headers))
2732 ;; otherwise, delete the MFT header if the field is empty
2733 (when (equal "" (mail-fetch-field "mail-followup-to"))
2734 (message-remove-header "^Mail-Followup-To:")))
2735 ;; Insert some headers.
2736 (let ((message-deletable-headers
2737 (if news nil message-deletable-headers)))
2738 (message-generate-headers headers))
2739 ;; Let the user do all of the above.
2740 (run-hooks 'message-header-hook))
2745 ;; Avoid copying text props.
2746 (insert (with-current-buffer mailbuf
2747 (buffer-substring-no-properties (point-min) (point-max))))
2748 ;; Remove some headers.
2749 (message-encode-message-body)
2751 (message-narrow-to-headers)
2752 ;; We (re)generate the Lines header.
2753 (when (memq 'Lines message-required-mail-headers)
2754 (message-generate-headers '(Lines)))
2755 ;; Remove some headers.
2756 (message-remove-header message-ignored-mail-headers t)
2757 (let ((mail-parse-charset message-default-charset))
2758 (mail-encode-encoded-word-buffer)))
2759 (goto-char (point-max))
2760 ;; require one newline at the end.
2761 (or (= (preceding-char) ?\n)
2765 (message-narrow-to-headers)
2767 (or (message-fetch-field "cc")
2768 (message-fetch-field "to"))
2769 (let ((content-type (message-fetch-field "content-type")))
2772 (string= "text/plain"
2774 (mail-header-parse-content-type
2776 (message-insert-courtesy-copy))
2777 (if (or (not message-send-mail-partially-limit)
2778 (< (point-max) message-send-mail-partially-limit)
2779 (not (y-or-n-p "Message exceeds message-send-mail-partially-limit, send in parts? ")))
2780 (mm-with-unibyte-current-buffer
2781 (message "Sending via mail...")
2782 (funcall (or message-send-mail-real-function
2783 message-send-mail-function)))
2784 (message-send-mail-partially)))
2785 (kill-buffer tembuf))
2786 (set-buffer mailbuf)
2787 (push 'mail message-sent-message-via)))
2789 (defun message-send-mail-with-sendmail ()
2790 "Send off the prepared buffer with sendmail."
2791 (let ((errbuf (if message-interactive
2792 (message-generate-new-buffer-clone-locals
2795 resend-to-addresses delimline)
2796 (let ((case-fold-search t))
2798 (message-narrow-to-headers)
2799 (setq resend-to-addresses (message-fetch-field "resent-to")))
2800 ;; Change header-delimiter to be what sendmail expects.
2801 (goto-char (point-min))
2803 (concat "^" (regexp-quote mail-header-separator) "\n"))
2804 (replace-match "\n")
2806 (setq delimline (point-marker))
2807 (run-hooks 'message-send-mail-hook)
2808 ;; Insert an extra newline if we need it to work around
2809 ;; Sun's bug that swallows newlines.
2810 (goto-char (1+ delimline))
2811 (when (eval message-mailer-swallows-blank-line)
2813 (when message-interactive
2817 (let ((default-directory "/")
2818 (coding-system-for-write message-send-coding-system))
2819 (apply 'call-process-region
2820 (append (list (point-min) (point-max)
2821 (if (boundp 'sendmail-program)
2823 "/usr/lib/sendmail")
2824 nil errbuf nil "-oi")
2825 ;; Always specify who from,
2826 ;; since some systems have broken sendmails.
2827 ;; But some systems are more broken with -f, so
2828 ;; we'll let users override this.
2829 (if (null message-sendmail-f-is-evil)
2830 (list "-f" (message-make-address)))
2831 ;; These mean "report errors by mail"
2832 ;; and "deliver in background".
2833 (if (null message-interactive) '("-oem" "-odb"))
2834 ;; Get the addresses from the message
2835 ;; unless this is a resend.
2836 ;; We must not do that for a resend
2837 ;; because we would find the original addresses.
2838 ;; For a resend, include the specific addresses.
2839 (if resend-to-addresses
2840 (list resend-to-addresses)
2842 (when message-interactive
2845 (goto-char (point-min))
2846 (while (re-search-forward "\n\n* *" nil t)
2847 (replace-match "; "))
2848 (if (not (zerop (buffer-size)))
2849 (error "Sending...failed to %s"
2850 (buffer-substring (point-min) (point-max)))))
2851 (when (bufferp errbuf)
2852 (kill-buffer errbuf)))))
2854 (defun message-send-mail-with-qmail ()
2855 "Pass the prepared message buffer to qmail-inject.
2856 Refer to the documentation for the variable `message-send-mail-function'
2857 to find out how to use this."
2858 ;; replace the header delimiter with a blank line
2859 (goto-char (point-min))
2861 (concat "^" (regexp-quote mail-header-separator) "\n"))
2862 (replace-match "\n")
2863 (run-hooks 'message-send-mail-hook)
2866 (let ((coding-system-for-write message-send-coding-system))
2868 'call-process-region 1 (point-max) message-qmail-inject-program
2870 ;; qmail-inject's default behaviour is to look for addresses on the
2871 ;; command line; if there're none, it scans the headers.
2872 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2874 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2875 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2876 ;; message from stdin.
2878 ;; qmail also has the advantage of not having been raped by
2879 ;; various vendors, so we don't have to allow for that, either --
2880 ;; compare this with message-send-mail-with-sendmail and weep
2881 ;; for sendmail's lost innocence.
2883 ;; all this is way cool coz it lets us keep the arguments entirely
2884 ;; free for -inject-arguments -- a big win for the user and for us
2885 ;; since we don't have to play that double-guessing game and the user
2886 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2887 message-qmail-inject-args))
2888 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2889 ;; we have to look at the retval instead
2891 (100 (error "qmail-inject reported permanent failure"))
2892 (111 (error "qmail-inject reported transient failure"))
2893 ;; should never happen
2894 (t (error "qmail-inject reported unknown failure"))))
2896 (defun message-send-mail-with-mh ()
2897 "Send the prepared message buffer with mh."
2898 (let ((mh-previous-window-config nil)
2899 (name (mh-new-draft-name)))
2900 (setq buffer-file-name name)
2901 ;; MH wants to generate these headers itself.
2902 (when message-mh-deletable-headers
2903 (let ((headers message-mh-deletable-headers))
2905 (goto-char (point-min))
2906 (and (re-search-forward
2907 (concat "^" (symbol-name (car headers)) ": *") nil t)
2908 (message-delete-line))
2910 (run-hooks 'message-send-mail-hook)
2911 ;; Pass it on to mh.
2914 (defun message-canlock-generate ()
2915 "Return a string that is non-trival to guess.
2916 Do not use this for anything important, it is cryptographically weak."
2917 (sha1 (concat (message-unique-id)
2918 (format "%x%x%x" (random) (random t) (random))
2919 (prin1-to-string (recent-keys))
2920 (prin1-to-string (garbage-collect)))))
2922 (defun message-canlock-password ()
2923 "The password used by message for cancel locks.
2924 This is the value of `canlock-password', if that option is non-nil.
2925 Otherwise, generate and save a value for `canlock-password' first."
2926 (unless canlock-password
2927 (customize-save-variable 'canlock-password (message-canlock-generate)))
2930 (defun message-insert-canlock ()
2931 (when message-insert-canlock
2932 (message-canlock-password)
2933 (canlock-insert-header)))
2935 (defun message-send-news (&optional arg)
2936 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2937 (case-fold-search nil)
2938 (method (if (message-functionp message-post-method)
2939 (funcall message-post-method arg)
2940 message-post-method))
2941 (newsgroups-field (save-restriction
2942 (message-narrow-to-headers-or-head)
2943 (message-fetch-field "Newsgroups")))
2944 (followup-field (save-restriction
2945 (message-narrow-to-headers-or-head)
2946 (message-fetch-field "Followup-To")))
2947 ;; BUG: We really need to get the charset for each name in the
2948 ;; Newsgroups and Followup-To lines to allow crossposting
2949 ;; between group namess with incompatible character sets.
2950 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
2951 (group-field-charset
2952 (gnus-group-name-charset method newsgroups-field))
2953 (followup-field-charset
2954 (gnus-group-name-charset method (or followup-field "")))
2955 (rfc2047-header-encoding-alist
2956 (append (when group-field-charset
2957 (list (cons "Newsgroups" group-field-charset)))
2958 (when followup-field-charset
2959 (list (cons "Followup-To" followup-field-charset)))
2960 rfc2047-header-encoding-alist))
2961 (messbuf (current-buffer))
2962 (message-syntax-checks
2964 (listp message-syntax-checks))
2965 (cons '(existing-newsgroups . disabled)
2966 message-syntax-checks)
2967 message-syntax-checks))
2968 (message-this-is-news t)
2969 (message-posting-charset
2970 (gnus-setup-posting-charset newsgroups-field))
2972 (if (not (message-check-news-body-syntax))
2975 (message-narrow-to-headers)
2976 ;; Insert some headers.
2977 (message-generate-headers message-required-news-headers)
2978 (message-insert-canlock)
2979 ;; Let the user do all of the above.
2980 (run-hooks 'message-header-hook))
2981 ;; Note: This check will be disabled by the ".*" default value for
2982 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
2983 (when (and group-field-charset
2984 (listp message-syntax-checks))
2985 (setq message-syntax-checks
2986 (cons '(valid-newsgroups . disabled)
2987 message-syntax-checks)))
2988 (message-cleanup-headers)
2989 (if (not (let ((message-post-method method))
2990 (message-check-news-syntax)))
2995 (buffer-disable-undo)
2997 ;; Avoid copying text props.
2998 (insert (with-current-buffer messbuf
2999 (buffer-substring-no-properties
3000 (point-min) (point-max))))
3001 (message-encode-message-body)
3002 ;; Remove some headers.
3004 (message-narrow-to-headers)
3005 ;; We (re)generate the Lines header.
3006 (when (memq 'Lines message-required-mail-headers)
3007 (message-generate-headers '(Lines)))
3008 ;; Remove some headers.
3009 (message-remove-header message-ignored-news-headers t)
3010 (let ((mail-parse-charset message-default-charset))
3011 (mail-encode-encoded-word-buffer)))
3012 (goto-char (point-max))
3013 ;; require one newline at the end.
3014 (or (= (preceding-char) ?\n)
3016 (let ((case-fold-search t))
3017 ;; Remove the delimiter.
3018 (goto-char (point-min))
3020 (concat "^" (regexp-quote mail-header-separator) "\n"))
3021 (replace-match "\n")
3023 (run-hooks 'message-send-news-hook)
3024 (gnus-open-server method)
3025 (message "Sending news with %s..." (gnus-server-string method))
3026 (setq result (let ((mail-header-separator ""))
3027 (gnus-request-post method))))
3028 (kill-buffer tembuf))
3029 (set-buffer messbuf)
3031 (push 'news message-sent-message-via)
3032 (message "Couldn't send message via news: %s"
3033 (nnheader-get-report (car method)))
3037 ;;; Header generation & syntax checking.
3040 (defun message-check-element (type)
3041 "Return non-nil if this TYPE is not to be checked."
3042 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3044 (let ((able (assq type message-syntax-checks)))
3046 (eq (cdr able) 'disabled)))))
3048 (defun message-check-news-syntax ()
3049 "Check the syntax of the message."
3053 ;; We narrow to the headers and check them first.
3056 (message-narrow-to-headers)
3057 (message-check-news-header-syntax))))))
3059 (defun message-check-news-header-syntax ()
3061 ;; Check Newsgroups header.
3062 (message-check 'newsgroups
3063 (let ((group (message-fetch-field "newsgroups")))
3066 (not (string-match "\\`[ \t]*\\'" group)))
3069 "The newsgroups field is empty or missing. Posting is denied.")))))
3070 ;; Check the Subject header.
3071 (message-check 'subject
3072 (let* ((case-fold-search t)
3073 (subject (message-fetch-field "subject")))
3076 (not (string-match "\\`[ \t]*\\'" subject)))
3079 "The subject field is empty or missing. Posting is denied.")))))
3080 ;; Check for commands in Subject.
3081 (message-check 'subject-cmsg
3082 (if (string-match "^cmsg " (message-fetch-field "subject"))
3084 "The control code \"cmsg\" is in the subject. Really post? ")
3086 ;; Check for multiple identical headers.
3087 (message-check 'multiple-headers
3089 (while (and (not found)
3090 (re-search-forward "^[^ \t:]+: " nil t))
3092 (or (re-search-forward
3097 (match-beginning 0) (- (match-end 0) 2))))
3102 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3104 ;; Check for Version and Sendsys.
3105 (message-check 'sendsys
3106 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3108 (format "The article contains a %s command. Really post? "
3109 (buffer-substring (match-beginning 0)
3110 (1- (match-end 0)))))
3112 ;; See whether we can shorten Followup-To.
3113 (message-check 'shorten-followup-to
3114 (let ((newsgroups (message-fetch-field "newsgroups"))
3115 (followup-to (message-fetch-field "followup-to"))
3117 (when (and newsgroups
3118 (string-match "," newsgroups)
3123 (setq to (completing-read
3124 "Followups to: (default all groups) "
3125 (mapcar (lambda (g) (list g))
3127 (message-tokenize-header
3129 (goto-char (point-min))
3130 (insert "Followup-To: " to "\n"))
3132 ;; Check "Shoot me".
3133 (message-check 'shoot
3134 (if (re-search-forward
3135 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3136 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3138 ;; Check for Approved.
3139 (message-check 'approved
3140 (if (re-search-forward "^Approved:" nil t)
3141 (y-or-n-p "The article contains an Approved header. Really post? ")
3143 ;; Check the Message-ID header.
3144 (message-check 'message-id
3145 (let* ((case-fold-search t)
3146 (message-id (message-fetch-field "message-id" t)))
3147 (or (not message-id)
3148 ;; Is there an @ in the ID?
3149 (and (string-match "@" message-id)
3150 ;; Is there a dot in the ID?
3151 (string-match "@[^.]*\\." message-id)
3152 ;; Does the ID end with a dot?
3153 (not (string-match "\\.>" message-id)))
3155 (format "The Message-ID looks strange: \"%s\". Really post? "
3157 ;; Check the Newsgroups & Followup-To headers.
3158 (message-check 'existing-newsgroups
3159 (let* ((case-fold-search t)
3160 (newsgroups (message-fetch-field "newsgroups"))
3161 (followup-to (message-fetch-field "followup-to"))
3162 (groups (message-tokenize-header
3164 (concat newsgroups "," followup-to)
3166 (post-method (if (message-functionp message-post-method)
3167 (funcall message-post-method)
3168 message-post-method))
3169 ;; KLUDGE to handle nnvirtual groups. Doing this right
3170 ;; would probably involve a new nnoo function.
3171 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
3172 (method (if (and (consp post-method)
3173 (eq (car post-method) 'nnvirtual)
3174 gnus-message-group-art)
3175 (let ((group (car (nnvirtual-find-group-art
3176 (car gnus-message-group-art)
3177 (cdr gnus-message-group-art)))))
3178 (gnus-find-method-for-group group))
3182 (gnus-group-name-decode
3183 (gnus-group-real-name n)
3184 (gnus-group-name-charset method n)))
3185 (gnus-groups-from-server method)))
3188 (unless (or (equal (car groups) "poster")
3189 (member (car groups) known-groups))
3190 (push (car groups) errors))
3193 ;; Gnus is not running.
3194 ((or (not (and (boundp 'gnus-active-hashtb)
3195 gnus-active-hashtb))
3196 (not (boundp 'gnus-read-active-file)))
3198 ;; We don't have all the group names.
3199 ((and (or (not gnus-read-active-file)
3200 (eq gnus-read-active-file 'some))
3204 "Really post to %s possibly unknown group%s: %s? "
3205 (if (= (length errors) 1) "this" "these")
3206 (if (= (length errors) 1) "" "s")
3207 (mapconcat 'identity errors ", "))))
3208 ;; There were no errors.
3211 ;; There are unknown groups.
3215 "Really post to %s unknown group%s: %s? "
3216 (if (= (length errors) 1) "this" "these")
3217 (if (= (length errors) 1) "" "s")
3218 (mapconcat 'identity errors ", ")))))))
3219 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3220 (message-check 'valid-newsgroups
3221 (let ((case-fold-search t)
3222 (headers '("Newsgroups" "Followup-To"))
3224 (while (and headers (not error))
3225 (when (setq header (mail-fetch-field (car headers)))
3229 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3234 (not (string-match "\\.\\'\\|\\.\\." g)))
3235 (message-tokenize-header header ","))))
3242 (format "The %s header looks odd: \"%s\". Really post? "
3243 (car headers) header)))))
3244 (message-check 'repeated-newsgroups
3245 (let ((case-fold-search t)
3246 (headers '("Newsgroups" "Followup-To"))
3247 header error groups group)
3250 (when (setq header (mail-fetch-field (pop headers)))
3251 (setq groups (message-tokenize-header header ","))
3252 (while (setq group (pop groups))
3253 (when (member group groups)
3259 (format "Group %s is repeated in headers. Really post? " error)))))
3260 ;; Check the From header.
3261 (message-check 'from
3262 (let* ((case-fold-search t)
3263 (from (message-fetch-field "from"))
3267 (message "There is no From line. Posting is denied.")
3269 ((or (not (string-match
3271 (setq ad (nth 1 (mail-extract-address-components
3272 from))))) ;larsi@ifi
3273 (string-match "\\.\\." ad) ;larsi@ifi..uio
3274 (string-match "@\\." ad) ;larsi@.ifi.uio
3275 (string-match "\\.$" ad) ;larsi@ifi.uio.
3276 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3277 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3279 "Denied posting -- the From looks strange: \"%s\"." from)
3281 ((let ((addresses (rfc822-addresses from)))
3282 (while (and addresses
3283 (not (eq (string-to-char (car addresses)) ?\()))
3284 (setq addresses (cdr addresses)))
3287 "Denied posting -- bad From address: \"%s\"." from)
3290 ;; Check the Reply-To header.
3291 (message-check 'reply-to
3292 (let* ((case-fold-search t)
3293 (reply-to (message-fetch-field "reply-to"))
3298 ((string-match "," reply-to)
3300 (format "Multiple Reply-To addresses: \"%s\". Really post? "
3302 ((or (not (string-match
3304 (setq ad (nth 1 (mail-extract-address-components
3305 reply-to))))) ;larsi@ifi
3306 (string-match "\\.\\." ad) ;larsi@ifi..uio
3307 (string-match "@\\." ad) ;larsi@.ifi.uio
3308 (string-match "\\.$" ad) ;larsi@ifi.uio.
3309 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3310 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
3313 "The Reply-To looks strange: \"%s\". Really post? "
3317 (defun message-check-news-body-syntax ()
3319 ;; Check for long lines.
3320 (message-check 'long-lines
3321 (goto-char (point-min))
3323 (concat "^" (regexp-quote mail-header-separator) "$"))
3327 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
3330 (< (- (point) p) 80)))
3331 (zerop (forward-line 1))))
3335 "You have lines longer than 79 characters. Really post? ")))
3336 ;; Check whether the article is empty.
3337 (message-check 'empty
3338 (goto-char (point-min))
3340 (concat "^" (regexp-quote mail-header-separator) "$"))
3343 (goto-char (point-max))
3344 (re-search-backward message-signature-separator nil t)
3346 (or (re-search-backward "[^ \n\t]" b t)
3347 (if (message-gnksa-enable-p 'empty-article)
3348 (y-or-n-p "Empty article. Really post? ")
3349 (message "Denied posting -- Empty article.")
3351 ;; Check for control characters.
3352 (message-check 'control-chars
3353 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3355 "The article contains control characters. Really post? ")
3357 ;; Check excessive size.
3358 (message-check 'size
3359 (if (> (buffer-size) 60000)
3361 (format "The article is %d octets long. Really post? "
3364 ;; Check whether any new text has been added.
3365 (message-check 'new-text
3367 (not message-checksum)
3368 (not (eq (message-checksum) message-checksum))
3369 (if (message-gnksa-enable-p 'quoted-text-only)
3371 "It looks like no new text has been added. Really post? ")
3372 (message "Denied posting -- no new text has been added.")
3374 ;; Check the length of the signature.
3375 (message-check 'signature
3376 (goto-char (point-max))
3377 (if (> (count-lines (point) (point-max)) 5)
3380 "Your .sig is %d lines; it should be max 4. Really post? "
3381 (1- (count-lines (point) (point-max)))))
3383 ;; Ensure that text follows last quoted portion.
3384 (message-check 'quoting-style
3385 (goto-char (point-max))
3386 (let ((no-problem t))
3387 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3388 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3391 (if (message-gnksa-enable-p 'quoted-text-only)
3392 (y-or-n-p "Your text should follow quoted text. Really post? ")
3394 (goto-char (point-min))
3396 (concat "^" (regexp-quote mail-header-separator) "$"))
3397 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3398 (y-or-n-p "Your text should follow quoted text. Really post? ")
3399 (message "Denied posting -- only quoted text.")
3402 (defun message-checksum ()
3403 "Return a \"checksum\" for the current buffer."
3406 (goto-char (point-min))
3408 (concat "^" (regexp-quote mail-header-separator) "$"))
3410 (when (not (looking-at "[ \t\n]"))
3411 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3416 (defun message-do-fcc ()
3417 "Process Fcc headers in the current buffer."
3418 (let ((case-fold-search t)
3419 (buf (current-buffer))
3423 (message-narrow-to-headers)
3424 (setq file (message-fetch-field "fcc" t)))
3426 (set-buffer (get-buffer-create " *message temp*"))
3428 (insert-buffer-substring buf)
3429 (message-encode-message-body)
3431 (message-narrow-to-headers)
3432 (while (setq file (message-fetch-field "fcc" t))
3434 (message-remove-header "fcc" nil t))
3435 (let ((mail-parse-charset message-default-charset)
3436 (rfc2047-header-encoding-alist
3437 (cons '("Newsgroups" . default)
3438 rfc2047-header-encoding-alist)))
3439 (mail-encode-encoded-word-buffer)))
3440 (goto-char (point-min))
3441 (when (re-search-forward
3442 (concat "^" (regexp-quote mail-header-separator) "$")
3444 (replace-match "" t t ))
3445 ;; Process FCC operations.
3447 (setq file (pop list))
3448 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3449 ;; Pipe the article to the program in question.
3450 (call-process-region (point-min) (point-max) shell-file-name
3451 nil nil nil shell-command-switch
3452 (match-string 1 file))
3453 ;; Save the article.
3454 (setq file (expand-file-name file))
3455 (unless (file-exists-p (file-name-directory file))
3456 (make-directory (file-name-directory file) t))
3457 (if (and message-fcc-handler-function
3458 (not (eq message-fcc-handler-function 'rmail-output)))
3459 (funcall message-fcc-handler-function file)
3460 (if (and (file-readable-p file) (mail-file-babyl-p file))
3461 (rmail-output file 1 nil t)
3462 (let ((mail-use-rfc822 t))
3463 (rmail-output file 1 t t))))))
3464 (kill-buffer (current-buffer))))))
3466 (defun message-output (filename)
3467 "Append this article to Unix/babyl mail file FILENAME."
3468 (if (and (file-readable-p filename)
3469 (mail-file-babyl-p filename))
3470 (gnus-output-to-rmail filename t)
3471 (gnus-output-to-mail filename t)))
3473 (defun message-cleanup-headers ()
3474 "Do various automatic cleanups of the headers."
3475 ;; Remove empty lines in the header.
3477 (message-narrow-to-headers)
3478 ;; Remove blank lines.
3479 (while (re-search-forward "^[ \t]*\n" nil t)
3480 (replace-match "" t t))
3482 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3483 ;; spaces to comma and eliminate spaces around commas. Eliminate
3484 ;; embedded line breaks.
3485 (goto-char (point-min))
3486 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3490 (if (re-search-forward "^[^ \t]" nil t)
3494 (goto-char (point-min))
3495 (while (re-search-forward "\n[ \t]+" nil t)
3496 (replace-match " " t t)) ;No line breaks (too confusing)
3497 (goto-char (point-min))
3498 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3499 (replace-match "," t t))
3500 (goto-char (point-min))
3501 ;; Remove trailing commas.
3502 (when (re-search-forward ",+$" nil t)
3503 (replace-match "" t t))))))
3505 (defun message-make-date (&optional now)
3506 "Make a valid data header.
3507 If NOW, use that time instead."
3508 (let* ((now (or now (current-time)))
3509 (zone (nth 8 (decode-time now)))
3513 (setq zone (- zone)))
3515 ;; The day name of the %a spec is locale-specific. Pfff.
3516 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
3517 parse-time-weekdays))))
3518 (format-time-string "%d" now)
3519 ;; The month name of the %b spec is locale-specific. Pfff.
3521 (capitalize (car (rassoc (nth 4 (decode-time now))
3522 parse-time-months))))
3523 (format-time-string "%Y %H:%M:%S " now)
3524 ;; We do all of this because XEmacs doesn't have the %z spec.
3525 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3527 (defun message-make-message-id ()
3528 "Make a unique Message-ID."
3529 (concat "<" (message-unique-id)
3530 (let ((psubject (save-excursion (message-fetch-field "subject")))
3532 (save-excursion (message-fetch-field "supersedes"))))
3534 (and message-reply-headers
3535 (mail-header-references message-reply-headers)
3536 (mail-header-subject message-reply-headers)
3539 (message-strip-subject-re
3540 (mail-header-subject message-reply-headers))
3541 (message-strip-subject-re psubject))))
3543 (string-match "_-_@" psupersedes)))
3545 "@" (message-make-fqdn) ">"))
3547 (defvar message-unique-id-char nil)
3549 ;; If you ever change this function, make sure the new version
3550 ;; cannot generate IDs that the old version could.
3551 ;; You might for example insert a "." somewhere (not next to another dot
3552 ;; or string boundary), or modify the "fsf" string.
3553 (defun message-unique-id ()
3554 ;; Don't use microseconds from (current-time), they may be unsupported.
3555 ;; Instead we use this randomly inited counter.
3556 (setq message-unique-id-char
3557 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3558 ;; (current-time) returns 16-bit ints,
3559 ;; and 2^16*25 just fits into 4 digits i base 36.
3561 (let ((tm (current-time)))
3563 (if (memq system-type '(ms-dos emx vax-vms))
3564 (let ((user (downcase (user-login-name))))
3565 (while (string-match "[^a-z0-9_]" user)
3566 (aset user (match-beginning 0) ?_))
3568 (message-number-base36 (user-uid) -1))
3569 (message-number-base36 (+ (car tm)
3570 (lsh (% message-unique-id-char 25) 16)) 4)
3571 (message-number-base36 (+ (nth 1 tm)
3572 (lsh (/ message-unique-id-char 25) 16)) 4)
3573 ;; Append the newsreader name, because while the generated
3574 ;; ID is unique to this newsreader, other newsreaders might
3575 ;; otherwise generate the same ID via another algorithm.
3578 (defun message-number-base36 (num len)
3583 (concat (message-number-base36 (/ num 36) (1- len))
3584 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3587 (defun message-make-organization ()
3588 "Make an Organization header."
3589 (let* ((organization
3590 (when message-user-organization
3591 (if (message-functionp message-user-organization)
3592 (funcall message-user-organization)
3593 message-user-organization))))
3595 (message-set-work-buffer)
3596 (cond ((stringp organization)
3597 (insert organization))
3598 ((and (eq t organization)
3599 message-user-organization-file
3600 (file-exists-p message-user-organization-file))
3601 (insert-file-contents message-user-organization-file)))
3602 (goto-char (point-min))
3603 (while (re-search-forward "[\t\n]+" nil t)
3604 (replace-match "" t t))
3605 (unless (zerop (buffer-size))
3608 (defun message-make-lines ()
3609 "Count the number of lines and return numeric string."
3614 (int-to-string (count-lines (point) (point-max))))))
3616 (defun message-make-in-reply-to ()
3617 "Return the In-Reply-To header for this message."
3618 (when message-reply-headers
3619 (let ((from (mail-header-from message-reply-headers))
3620 (date (mail-header-date message-reply-headers))
3621 (msg-id (mail-header-message-id message-reply-headers)))
3624 (string-match " *at \\| *@ \\| *(\\| *<" from)))
3625 (concat msg-id (if msg-id " (")
3627 (not (zerop stop-pos)))
3628 (substring from 0 stop-pos) from)
3630 (if (or (not date) (string= date ""))
3631 "(unknown date)" date)
3632 "\"" (if msg-id ")")))))))
3634 (defun message-make-distribution ()
3635 "Make a Distribution header."
3636 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3637 (cond ((message-functionp message-distribution-function)
3638 (funcall message-distribution-function))
3639 (t orig-distribution))))
3641 (defun message-make-expires ()
3642 "Return an Expires header based on `message-expires'."
3643 (let ((current (current-time))
3644 (future (* 1.0 message-expires 60 60 24)))
3645 ;; Add the future to current.
3646 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3647 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3648 (message-make-date current)))
3650 (defun message-make-path ()
3652 (let ((login-name (user-login-name)))
3653 (cond ((null message-user-path)
3654 (concat (system-name) "!" login-name))
3655 ((stringp message-user-path)
3656 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3657 (concat message-user-path "!" login-name))
3660 (defun message-make-from ()
3661 "Make a From header."
3662 (let* ((style message-from-style)
3663 (login (message-make-address))
3665 (or (and (boundp 'user-full-name)
3668 (when (string= fullname "&")
3669 (setq fullname (user-login-name)))
3671 (message-set-work-buffer)
3674 (equal fullname ""))
3676 ((or (eq style 'angles)
3677 (and (not (eq style 'parens))
3678 ;; Use angles if no quoting is needed, or if parens would
3679 ;; need quoting too.
3680 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3681 (let ((tmp (concat fullname nil)))
3682 (while (string-match "([^()]*)" tmp)
3683 (aset tmp (match-beginning 0) ?-)
3684 (aset tmp (1- (match-end 0)) ?-))
3685 (string-match "[\\()]" tmp)))))
3687 (goto-char (point-min))
3688 ;; Look for a character that cannot appear unquoted
3689 ;; according to RFC 822.
3690 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3691 ;; Quote fullname, escaping specials.
3692 (goto-char (point-min))
3694 (while (re-search-forward "[\"\\]" nil 1)
3695 (replace-match "\\\\\\&" t))
3697 (insert " <" login ">"))
3698 (t ; 'parens or default
3700 (let ((fullname-start (point)))
3702 (goto-char fullname-start)
3703 ;; RFC 822 says \ and nonmatching parentheses
3704 ;; must be escaped in comments.
3705 ;; Escape every instance of ()\ ...
3706 (while (re-search-forward "[()\\]" nil 1)
3707 (replace-match "\\\\\\&" t))
3708 ;; ... then undo escaping of matching parentheses,
3709 ;; including matching nested parentheses.
3710 (goto-char fullname-start)
3711 (while (re-search-forward
3712 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3714 (replace-match "\\1(\\3)" t)
3715 (goto-char fullname-start)))
3719 (defun message-make-sender ()
3720 "Return the \"real\" user address.
3721 This function tries to ignore all user modifications, and
3722 give as trustworthy answer as possible."
3723 (concat (user-login-name) "@" (system-name)))
3725 (defun message-make-address ()
3726 "Make the address of the user."
3727 (or (message-user-mail-address)
3728 (concat (user-login-name) "@" (message-make-domain))))
3730 (defun message-user-mail-address ()
3731 "Return the pertinent part of `user-mail-address'."
3732 (when user-mail-address
3733 (if (string-match " " user-mail-address)
3734 (nth 1 (mail-extract-address-components user-mail-address))
3735 user-mail-address)))
3737 (defun message-make-fqdn ()
3738 "Return user's fully qualified domain name."
3739 (let ((system-name (system-name))
3740 (user-mail (message-user-mail-address)))
3742 ((and (string-match "[^.]\\.[^.]" system-name)
3743 (not (string-match message-bogus-system-names system-name)))
3744 ;; `system-name' returned the right result.
3746 ;; Try `mail-host-address'.
3747 ((and (boundp 'mail-host-address)
3748 (stringp mail-host-address)
3749 (string-match "\\." mail-host-address))
3751 ;; We try `user-mail-address' as a backup.
3753 (string-match "\\." user-mail)
3754 (string-match "@\\(.*\\)\\'" user-mail))
3755 (match-string 1 user-mail))
3756 ;; Default to this bogus thing.
3758 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3760 (defun message-make-host-name ()
3761 "Return the name of the host."
3762 (let ((fqdn (message-make-fqdn)))
3763 (string-match "^[^.]+\\." fqdn)
3764 (substring fqdn 0 (1- (match-end 0)))))
3766 (defun message-make-domain ()
3767 "Return the domain name."
3768 (or mail-host-address
3769 (message-make-fqdn)))
3771 (defun message-make-mft ()
3772 "Return the Mail-Followup-To header."
3773 (let* ((msg-recipients (message-options-get 'message-recipients))
3775 (mapcar 'mail-strip-quoted-names
3776 (message-tokenize-header msg-recipients)))
3778 (if message-subscribed-address-file
3779 (let (begin end item re)
3782 (insert-file-contents message-subscribed-address-file)
3784 (setq begin (point))
3787 (if (bolp) (setq end (1- end)))
3788 (setq item (regexp-quote (buffer-substring begin end)))
3789 (if re (setq re (concat re "\\|" item))
3790 (setq re (concat "\\`\\(" item))))
3791 (and re (list (concat re "\\)\\'"))))))))
3792 (mft-regexps (apply 'append message-subscribed-regexps
3793 (mapcar 'regexp-quote
3794 message-subscribed-addresses)
3797 message-subscribed-address-functions))))
3799 (when (eval (apply 'append '(or)
3801 (function (lambda (regexp)
3803 (function (lambda (recipient)
3804 `(string-match ,regexp
3810 (defun message-generate-headers (headers)
3811 "Prepare article HEADERS.
3812 Headers already prepared in the buffer are not modified."
3814 (message-narrow-to-headers)
3815 (let* ((Date (message-make-date))
3816 (Message-ID (message-make-message-id))
3817 (Organization (message-make-organization))
3818 (From (message-make-from))
3819 (Path (message-make-path))
3822 (In-Reply-To (message-make-in-reply-to))
3824 (Distribution (message-make-distribution))
3825 (Lines (message-make-lines))
3826 (User-Agent message-newsreader)
3827 (Expires (message-make-expires))
3828 (case-fold-search t)
3830 ;; First we remove any old generated headers.
3831 (let ((headers message-deletable-headers))
3832 (unless (buffer-modified-p)
3833 (setq headers (delq 'Message-ID (copy-sequence headers))))
3835 (goto-char (point-min))
3836 (and (re-search-forward
3837 (concat "^" (symbol-name (car headers)) ": *") nil t)
3838 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3839 (message-delete-line))
3841 ;; Go through all the required headers and see if they are in the
3842 ;; articles already. If they are not, or are empty, they are
3843 ;; inserted automatically - except for Subject, Newsgroups and
3846 (goto-char (point-min))
3847 (setq elem (pop headers))
3849 (if (eq (car elem) 'optional)
3850 (setq header (cdr elem))
3851 (setq header (car elem)))
3853 (when (or (not (re-search-forward
3857 (if (stringp header)
3859 (symbol-name header))))
3863 ;; The header was found. We insert a space after the
3864 ;; colon, if there is none.
3865 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3866 ;; Find out whether the header is empty...
3867 (looking-at "[ \t]*\n[^ \t]")))
3868 ;; So we find out what value we should insert.
3871 ((and (consp elem) (eq (car elem) 'optional))
3872 ;; This is an optional header. If the cdr of this
3873 ;; is something that is nil, then we do not insert
3875 (setq header (cdr elem))
3876 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3877 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3879 ;; The element is a cons. Either the cdr is a
3880 ;; string to be inserted verbatim, or it is a
3881 ;; function, and we insert the value returned from
3883 (or (and (stringp (cdr elem)) (cdr elem))
3884 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3885 ((and (boundp header) (symbol-value header))
3886 ;; The element is a symbol. We insert the value
3887 ;; of this symbol, if any.
3888 (symbol-value header))
3889 ((not (message-check-element header))
3890 ;; We couldn't generate a value for this header,
3891 ;; so we just ask the user.
3892 (read-from-minibuffer
3893 (format "Empty header for %s; enter value: " header)))))
3894 ;; Finally insert the header.
3896 (not (equal value "")))
3900 ;; This header didn't exist, so we insert it.
3901 (goto-char (point-max))
3902 (insert (if (stringp header) header (symbol-name header))
3905 ;; The value of this header was empty, so we clear
3906 ;; totally and insert the new value.
3907 (delete-region (point) (gnus-point-at-eol))
3909 ;; Add the deletable property to the headers that require it.
3910 (and (memq header message-deletable-headers)
3911 (progn (beginning-of-line) (looking-at "[^:]+: "))
3912 (add-text-properties
3913 (point) (match-end 0)
3914 '(message-deletable t face italic) (current-buffer)))))))
3915 ;; Insert new Sender if the From is strange.
3916 (let ((from (message-fetch-field "from"))
3917 (sender (message-fetch-field "sender"))
3918 (secure-sender (message-make-sender)))
3920 (not (message-check-element 'sender))
3923 (cadr (mail-extract-address-components from)))
3924 (downcase secure-sender)))
3929 (cadr (mail-extract-address-components sender)))
3930 (downcase secure-sender)))))
3931 (goto-char (point-min))
3932 ;; Rename any old Sender headers to Original-Sender.
3933 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3935 (insert "Original-")
3936 (beginning-of-line))
3937 (when (or (message-news-p)
3938 (string-match "@.+\\.." secure-sender))
3939 (insert "Sender: " secure-sender "\n")))))))
3941 (defun message-insert-courtesy-copy ()
3942 "Insert a courtesy message in mail copies of combined messages."
3946 (message-narrow-to-headers)
3947 (when (setq newsgroups (message-fetch-field "newsgroups"))
3948 (goto-char (point-max))
3949 (insert "Posted-To: " newsgroups "\n")))
3951 (when message-courtesy-message
3953 ((string-match "%s" message-courtesy-message)
3954 (insert (format message-courtesy-message newsgroups)))
3956 (insert message-courtesy-message)))))))
3959 ;;; Setting up a message buffer
3962 (defun message-fill-address (header value)
3964 (narrow-to-region (point) (point))
3965 (insert (capitalize (symbol-name header))
3967 (if (consp value) (car value) value)
3969 (narrow-to-region (point-min) (1- (point-max)))
3971 (goto-char (point-min))
3973 (skip-chars-forward "^,\"" (point-max))
3974 (if (or (eq (char-after) ?,)
3977 (if (and (> (current-column) 78)
3983 (setq last (1+ (point))))
3984 (setq last (1+ (point)))))
3985 (setq quoted (not quoted)))
3988 (goto-char (point-max))
3992 (defun message-fill-header (header value)
3993 (let ((begin (point))
3996 (insert (capitalize (symbol-name header))
3998 (if (consp value) (car value) value)
4001 (narrow-to-region begin (point))
4002 (fill-region-as-paragraph begin (point))
4003 ;; Tapdance around looong Message-IDs.
4005 (when (looking-at "[ \t]*$")
4006 (message-delete-line))
4008 (re-search-forward ":" nil t)
4009 (when (looking-at "\n[ \t]+")
4010 (replace-match " " t t))
4011 (goto-char (point-max)))))
4013 (defun message-shorten-1 (list cut surplus)
4014 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4015 (setcdr (nthcdr (- cut 2) list)
4016 (nthcdr (+ (- cut 2) surplus 1) list)))
4018 (defun message-shorten-references (header references)
4019 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
4020 If folding is disallowed, also check that the REFERENCES are less
4021 than 988 characters long, and if they are not, trim them until they are."
4028 (goto-char (point-min))
4029 ;; Cons a list of valid references.
4030 (while (re-search-forward "<[^>]+>" nil t)
4031 (push (match-string 0) refs))
4032 (setq refs (nreverse refs)
4033 count (length refs)))
4035 ;; If the list has more than MAXCOUNT elements, trim it by
4036 ;; removing the CUTth element and the required number of
4037 ;; elements that follow.
4038 (when (> count maxcount)
4039 (let ((surplus (- count maxcount)))
4040 (message-shorten-1 refs cut surplus)
4041 (decf count surplus)))
4043 ;; If folding is disallowed, make sure the total length (including
4044 ;; the spaces between) will be less than MAXSIZE characters.
4046 ;; Only disallow folding for News messages. At this point the headers
4047 ;; have not been generated, thus we use message-this-is-news directly.
4048 (when (and message-this-is-news message-cater-to-broken-inn)
4050 (totalsize (+ (apply #'+ (mapcar #'length refs))
4053 (ptr (nthcdr (1- cut) refs)))
4054 ;; Decide how many elements to cut off...
4055 (while (> totalsize maxsize)
4056 (decf totalsize (1+ (length (car ptr))))
4058 (setq ptr (cdr ptr)))
4061 (message-shorten-1 refs cut surplus))))
4063 ;; Finally, collect the references back into a string and insert
4064 ;; it into the buffer.
4065 (let ((refstring (mapconcat #'identity refs " ")))
4066 (if (and message-this-is-news message-cater-to-broken-inn)
4067 (insert (capitalize (symbol-name header)) ": "
4069 (message-fill-header header refstring)))))
4071 (defun message-position-point ()
4072 "Move point to where the user probably wants to find it."
4073 (message-narrow-to-headers)
4075 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4076 (search-backward ":" )
4079 (if (eq (char-after) ? )
4083 (goto-char (point-max))
4086 (unless (looking-at "$")
4090 (defun message-beginning-of-line (&optional n)
4091 "Move point to beginning of header value or to beginning of line."
4093 (if (message-point-in-header-p)
4094 (let* ((here (point))
4095 (bol (progn (beginning-of-line n) (point)))
4096 (eol (gnus-point-at-eol))
4097 (eoh (re-search-forward ": *" eol t)))
4098 (if (or (not eoh) (equal here eoh))
4101 (beginning-of-line n)))
4103 (defun message-buffer-name (type &optional to group)
4104 "Return a new (unique) buffer name based on TYPE and TO."
4106 ;; Generate a new buffer name The Message Way.
4107 ((eq message-generate-new-buffers 'unique)
4108 (generate-new-buffer-name
4112 (or (car (mail-extract-address-components to))
4115 (if (and group (not (string= group ""))) (concat " on " group) "")
4117 ;; Check whether `message-generate-new-buffers' is a function,
4118 ;; and if so, call it.
4119 ((message-functionp message-generate-new-buffers)
4120 (funcall message-generate-new-buffers type to group))
4121 ((eq message-generate-new-buffers 'unsent)
4122 (generate-new-buffer-name
4123 (concat "*unsent " type
4126 (or (car (mail-extract-address-components to))
4129 (if (and group (not (string= group ""))) (concat " on " group) "")
4131 ;; Use standard name.
4133 (format "*%s message*" type))))
4135 (defun message-pop-to-buffer (name)
4136 "Pop to buffer NAME, and warn if it already exists and is modified."
4137 (let ((buffer (get-buffer name)))
4139 (buffer-name buffer))
4141 (set-buffer (pop-to-buffer buffer))
4142 (when (and (buffer-modified-p)
4144 "Message already being composed; erase? ")))
4145 (error "Message being composed")))
4146 (set-buffer (pop-to-buffer name)))
4150 (defun message-do-send-housekeeping ()
4151 "Kill old message buffers."
4152 ;; We might have sent this buffer already. Delete it from the
4154 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4155 (while (and message-max-buffers
4157 (>= (length message-buffer-list) message-max-buffers))
4158 ;; Kill the oldest buffer -- unless it has been changed.
4159 (let ((buffer (pop message-buffer-list)))
4160 (when (and (buffer-name buffer)
4161 (not (buffer-modified-p buffer)))
4162 (kill-buffer buffer))))
4163 ;; Rename the buffer.
4164 (if message-send-rename-function
4165 (funcall message-send-rename-function)
4166 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
4168 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
4170 (let ((name (match-string 2 (buffer-name)))
4172 (if (not (or (null name)
4173 (string-equal name "mail")
4174 (string-equal name "news")))
4175 (setq name (concat "*sent " name "*"))
4176 (message-narrow-to-headers)
4177 (setq to (message-fetch-field "to"))
4178 (setq group (message-fetch-field "newsgroups"))
4182 (to (concat "*sent mail to "
4183 (or (car (mail-extract-address-components to))
4185 ((and group (not (string= group "")))
4186 (concat "*sent news on " group "*"))
4187 (t "*sent mail*"))))
4188 (unless (string-equal name (buffer-name))
4189 (rename-buffer name t)))))
4190 ;; Push the current buffer onto the list.
4191 (when message-max-buffers
4192 (setq message-buffer-list
4193 (nconc message-buffer-list (list (current-buffer))))))
4195 (defun message-mail-user-agent ()
4197 ((not message-mail-user-agent) nil)
4198 ((eq message-mail-user-agent t) mail-user-agent)
4199 (t message-mail-user-agent))))
4200 (if (memq mua '(message-user-agent gnus-user-agent))
4204 (defun message-setup (headers &optional replybuffer actions switch-function)
4205 (let ((mua (message-mail-user-agent))
4206 subject to field yank-action)
4207 (if (not (and message-this-is-mail mua))
4208 (message-setup-1 headers replybuffer actions)
4210 (setq yank-action (list 'insert-buffer replybuffer)))
4211 (setq headers (copy-sequence headers))
4212 (setq field (assq 'Subject headers))
4214 (setq subject (cdr field))
4215 (setq headers (delq field headers)))
4216 (setq field (assq 'To headers))
4218 (setq to (cdr field))
4219 (setq headers (delq field headers)))
4220 (let ((mail-user-agent mua))
4221 (compose-mail to subject
4222 (mapcar (lambda (item)
4224 (format "%s" (car item))
4227 nil switch-function yank-action actions)))))
4229 (defun message-setup-1 (headers &optional replybuffer actions)
4230 (dolist (action actions)
4232 (add-to-list 'message-send-actions
4233 `(apply ',(car action) ',(cdr action)))))
4234 (setq message-reply-buffer replybuffer)
4235 (goto-char (point-min))
4236 ;; Insert all the headers.
4239 (alist message-header-format-alist))
4241 (unless (assq (caar h) message-header-format-alist)
4242 (push (list (caar h)) alist))
4246 (delete-region (point) (progn (forward-line -1) (point)))
4247 (when message-default-headers
4248 (insert message-default-headers)
4249 (or (bolp) (insert ?\n)))
4253 (insert mail-header-separator "\n")
4257 (when (message-news-p)
4258 (when message-default-news-headers
4259 (insert message-default-news-headers)
4260 (or (bolp) (insert ?\n)))
4261 (when message-generate-headers-first
4262 (message-generate-headers
4265 (copy-sequence message-required-news-headers))))))
4266 (when (message-mail-p)
4267 (when message-default-mail-headers
4268 (insert message-default-mail-headers)
4269 (or (bolp) (insert ?\n)))
4270 (when message-generate-headers-first
4271 (message-generate-headers
4274 (copy-sequence message-required-mail-headers))))))
4275 (run-hooks 'message-signature-setup-hook)
4276 (message-insert-signature)
4278 (message-narrow-to-headers)
4279 (if message-alternative-emails
4280 (message-use-alternative-email-as-from))
4281 (run-hooks 'message-header-setup-hook))
4282 (set-buffer-modified-p nil)
4283 (setq buffer-undo-list nil)
4284 (run-hooks 'message-setup-hook)
4285 (message-position-point)
4288 (defun message-set-auto-save-file-name ()
4289 "Associate the message buffer with a file in the drafts directory."
4290 (when message-auto-save-directory
4291 (unless (file-directory-p
4292 (directory-file-name message-auto-save-directory))
4293 (gnus-make-directory message-auto-save-directory))
4295 (setq message-draft-article
4296 (nndraft-request-associate-buffer "drafts"))
4297 (setq buffer-file-name (expand-file-name
4298 (if (memq system-type
4299 '(ms-dos ms-windows windows-nt
4304 message-auto-save-directory))
4305 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4306 (clear-visited-file-modtime)
4307 (setq buffer-file-coding-system message-draft-coding-system)))
4309 (defun message-disassociate-draft ()
4310 "Disassociate the message buffer from the drafts directory."
4311 (when message-draft-article
4312 (nndraft-request-expire-articles
4313 (list message-draft-article) "drafts" nil t)))
4315 (defun message-insert-headers ()
4316 "Generate the headers for the article."
4320 (message-narrow-to-headers)
4321 (when (message-news-p)
4322 (message-generate-headers
4325 (copy-sequence message-required-news-headers)))))
4326 (when (message-mail-p)
4327 (message-generate-headers
4330 (copy-sequence message-required-mail-headers))))))))
4335 ;;; Commands for interfacing with message
4339 (defun message-mail (&optional to subject
4340 other-headers continue switch-function
4341 yank-action send-actions)
4342 "Start editing a mail message to be sent.
4343 OTHER-HEADERS is an alist of header/value pairs."
4345 (let ((message-this-is-mail t) replybuffer)
4346 (unless (message-mail-user-agent)
4347 (message-pop-to-buffer (message-buffer-name "mail" to)))
4348 ;; FIXME: message-mail should do something if YANK-ACTION is not
4350 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
4351 (setq replybuffer (nth 1 yank-action)))
4354 `((To . ,(or to "")) (Subject . ,(or subject "")))
4355 (when other-headers other-headers))
4356 replybuffer send-actions)
4357 ;; FIXME: Should return nil if failure.
4361 (defun message-news (&optional newsgroups subject)
4362 "Start editing a news article to be sent."
4364 (let ((message-this-is-news t))
4365 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4366 (message-setup `((Newsgroups . ,(or newsgroups ""))
4367 (Subject . ,(or subject ""))))))
4369 (defun message-get-reply-headers (wide &optional to-address)
4370 (let (follow-to mct never-mct to cc author mft recipients)
4371 ;; Find all relevant headers we need.
4372 (setq to (message-fetch-field "to")
4373 cc (message-fetch-field "cc")
4374 mct (message-fetch-field "mail-copies-to")
4375 author (or (message-fetch-field "mail-reply-to")
4376 (message-fetch-field "reply-to")
4377 (message-fetch-field "from")
4379 mft (and message-use-mail-followup-to
4380 (message-fetch-field "mail-followup-to")))
4382 ;; Handle special values of Mail-Copies-To.
4384 (cond ((or (equal (downcase mct) "never")
4385 (equal (downcase mct) "nobody"))
4388 ((or (equal (downcase mct) "always")
4389 (equal (downcase mct) "poster"))
4390 (setq mct author))))
4393 ;; Build (textual) list of new recipient addresses.
4396 (setq recipients (concat ", " author)))
4398 (string-match "[^ \t,]" mft)
4399 (or (not (eq message-use-mail-followup-to 'ask))
4400 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4401 You should normally obey the Mail-Followup-To: header. In this
4402 article, it has the value of
4406 which directs your response to " (if (string-match "," mft)
4407 "the specified addresses"
4408 "that address only") ".
4410 Most commonly, Mail-Followup-To is used by a mailing list poster to
4411 express that responses should be sent to just the list, and not the
4414 If a message is posted to several mailing lists, Mail-Followup-To may
4415 also be used to direct the following discussion to one list only,
4416 because discussions that are spread over several lists tend to be
4417 fragmented and very difficult to follow.
4419 Also, some source/announcement lists are not intended for discussion;
4420 responses here are directed to other addresses.")))
4421 (setq recipients (concat ", " mft)))
4423 (setq recipients (concat ", " to-address))
4424 ;; If the author explicitly asked for a copy, we don't deny it to them.
4425 (if mct (setq recipients (concat recipients ", " mct))))
4427 (setq recipients (if never-mct "" (concat ", " author)))
4428 (if to (setq recipients (concat recipients ", " to)))
4429 (if cc (setq recipients (concat recipients ", " cc)))
4430 (if mct (setq recipients (concat recipients ", " mct)))))
4431 (if (>= (length recipients) 2)
4432 ;; Strip the leading ", ".
4433 (setq recipients (substring recipients 2)))
4434 ;; Squeeze whitespace.
4435 (while (string-match "[ \t][ \t]+" recipients)
4436 (setq recipients (replace-match " " t t recipients)))
4437 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4438 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4439 (setq recipients (rmail-dont-reply-to recipients)))
4440 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4441 (if (string-equal recipients "")
4442 (setq recipients author))
4443 ;; Convert string to a list of (("foo@bar" . "Name <foo@bar>") ...).
4447 (cons (mail-strip-quoted-names addr) addr))
4448 (message-tokenize-header recipients)))
4449 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
4450 (let ((s recipients))
4452 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
4453 ;; Build the header alist. Allow the user to be asked whether
4454 ;; or not to reply to all recipients in a wide reply.
4455 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
4456 (when (and recipients
4457 (or (not message-wide-reply-confirm-recipients)
4458 (y-or-n-p "Reply to all recipients? ")))
4459 (setq recipients (mapconcat
4460 (lambda (addr) (cdr addr)) recipients ", "))
4461 (if (string-match "^ +" recipients)
4462 (setq recipients (substring recipients (match-end 0))))
4463 (push (cons 'Cc recipients) follow-to)))
4467 (defun message-reply (&optional to-address wide)
4468 "Start editing a reply to the article in the current buffer."
4470 (require 'gnus-sum) ; for gnus-list-identifiers
4471 (let ((cur (current-buffer))
4472 from subject date reply-to to cc
4473 references message-id follow-to
4474 (inhibit-point-motion-hooks t)
4475 (message-this-is-mail t)
4478 (message-narrow-to-head-1)
4479 ;; Allow customizations to have their say.
4481 ;; This is a regular reply.
4482 (when (message-functionp message-reply-to-function)
4484 (setq follow-to (funcall message-reply-to-function))))
4485 ;; This is a followup.
4486 (when (message-functionp message-wide-reply-to-function)
4489 (funcall message-wide-reply-to-function)))))
4490 (setq message-id (message-fetch-field "message-id" t)
4491 references (message-fetch-field "references")
4492 date (message-fetch-field "date")
4493 from (message-fetch-field "from")
4494 subject (or (message-fetch-field "subject") "none"))
4495 (when gnus-list-identifiers
4496 (setq subject (message-strip-list-identifiers subject)))
4497 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4499 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4500 (string-match "<[^>]+>" gnus-warning))
4501 (setq message-id (match-string 0 gnus-warning)))
4504 (setq follow-to (message-get-reply-headers wide to-address))))
4506 (unless (message-mail-user-agent)
4507 (message-pop-to-buffer
4508 (message-buffer-name
4509 (if wide "wide reply" "reply") from
4510 (if wide to-address nil))))
4512 (setq message-reply-headers
4513 (vector 0 subject from date message-id references 0 0 ""))
4516 `((Subject . ,subject)
4518 ,@(if (or references message-id)
4519 `((References . ,(concat (or references "") (and references " ")
4520 (or message-id ""))))
4525 (defun message-wide-reply (&optional to-address)
4526 "Make a \"wide\" reply to the message in the current buffer."
4528 (message-reply to-address t))
4531 (defun message-followup (&optional to-newsgroups)
4532 "Follow up to the message in the current buffer.
4533 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4535 (require 'gnus-sum) ; for gnus-list-identifiers
4536 (let ((cur (current-buffer))
4537 from subject date reply-to mrt mct
4538 references message-id follow-to
4539 (inhibit-point-motion-hooks t)
4540 (message-this-is-news t)
4541 followup-to distribution newsgroups gnus-warning posted-to)
4544 (goto-char (point-min))
4545 (if (search-forward "\n\n" nil t)
4548 (when (message-functionp message-followup-to-function)
4550 (funcall message-followup-to-function)))
4551 (setq from (message-fetch-field "from")
4552 date (message-fetch-field "date")
4553 subject (or (message-fetch-field "subject") "none")
4554 references (message-fetch-field "references")
4555 message-id (message-fetch-field "message-id" t)
4556 followup-to (message-fetch-field "followup-to")
4557 newsgroups (message-fetch-field "newsgroups")
4558 posted-to (message-fetch-field "posted-to")
4559 reply-to (message-fetch-field "reply-to")
4560 mrt (message-fetch-field "mail-reply-to")
4561 distribution (message-fetch-field "distribution")
4562 mct (message-fetch-field "mail-copies-to"))
4563 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4564 (string-match "<[^>]+>" gnus-warning))
4565 (setq message-id (match-string 0 gnus-warning)))
4566 ;; Remove bogus distribution.
4567 (when (and (stringp distribution)
4568 (let ((case-fold-search t))
4569 (string-match "world" distribution)))
4570 (setq distribution nil))
4571 (if gnus-list-identifiers
4572 (setq subject (message-strip-list-identifiers subject)))
4573 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4576 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4579 `((Subject . ,subject)
4582 (list (cons 'Newsgroups to-newsgroups)))
4583 (follow-to follow-to)
4584 ((and followup-to message-use-followup-to)
4587 ((equal (downcase followup-to) "poster")
4588 (if (or (eq message-use-followup-to 'use)
4589 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4590 You should normally obey the Followup-To: header.
4592 `Followup-To: poster' sends your response via e-mail instead of news.
4594 A typical situation where `Followup-To: poster' is used is when the poster
4595 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4597 (setq message-this-is-news nil)
4598 (cons 'To (or mrt reply-to from "")))
4599 (cons 'Newsgroups newsgroups)))
4601 (if (or (equal followup-to newsgroups)
4602 (not (eq message-use-followup-to 'ask))
4604 (concat "Obey Followup-To: " followup-to "? ") t "\
4605 You should normally obey the Followup-To: header.
4607 `Followup-To: " followup-to "'
4608 directs your response to " (if (string-match "," followup-to)
4609 "the specified newsgroups"
4610 "that newsgroup only") ".
4612 If a message is posted to several newsgroups, Followup-To is often
4613 used to direct the following discussion to one newsgroup only,
4614 because discussions that are spread over several newsgroup tend to
4615 be fragmented and very difficult to follow.
4617 Also, some source/announcement newsgroups are not intended for discussion;
4618 responses here are directed to other newsgroups."))
4619 (cons 'Newsgroups followup-to)
4620 (cons 'Newsgroups newsgroups))))))
4622 `((Newsgroups . ,posted-to)))
4624 `((Newsgroups . ,newsgroups))))
4625 ,@(and distribution (list (cons 'Distribution distribution)))
4626 ,@(if (or references message-id)
4627 `((References . ,(concat (or references "") (and references " ")
4628 (or message-id "")))))
4630 (not (or (equal (downcase mct) "never")
4631 (equal (downcase mct) "nobody"))))
4632 (list (cons 'Cc (if (or (equal (downcase mct) "always")
4633 (equal (downcase mct) "poster"))
4634 (or mrt reply-to from "")
4639 (setq message-reply-headers
4640 (vector 0 subject from date message-id references 0 0 ""))))
4644 (defun message-cancel-news (&optional arg)
4645 "Cancel an article you posted.
4646 If ARG, allow editing of the cancellation message."
4648 (unless (message-news-p)
4649 (error "This is not a news article; canceling is impossible"))
4650 (let (from newsgroups message-id distribution buf sender)
4652 ;; Get header info from original article.
4654 (message-narrow-to-head-1)
4655 (setq from (message-fetch-field "from")
4656 sender (message-fetch-field "sender")
4657 newsgroups (message-fetch-field "newsgroups")
4658 message-id (message-fetch-field "message-id" t)
4659 distribution (message-fetch-field "distribution")))
4660 ;; Make sure that this article was written by the user.
4662 ;; Canlock-logic as suggested by Per Abrahamsen
4663 ;; <abraham@dina.kvl.dk>
4665 ;; IF article has cancel-lock THEN
4666 ;; IF we can verify it THEN
4669 ;; error: cancellock: article is not yours
4671 ;; Use old rules, comparing sender...
4672 (if (message-fetch-field "Cancel-Lock")
4673 (if (null (canlock-verify))
4675 (error "Failed to verify Cancel-lock: This article is not yours"))
4677 (message-gnksa-enable-p 'cancel-messages)
4681 (downcase (message-make-sender))))
4683 (downcase (cadr (mail-extract-address-components from)))
4684 (downcase (cadr (mail-extract-address-components
4685 (message-make-from))))))
4686 (error "This article is not yours"))
4687 (when (yes-or-no-p "Do you really want to cancel this article? ")
4688 ;; Make control message.
4691 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4693 (insert "Newsgroups: " newsgroups "\n"
4695 "Subject: cmsg cancel " message-id "\n"
4696 "Control: cancel " message-id "\n"
4698 (concat "Distribution: " distribution "\n")
4700 mail-header-separator "\n"
4701 message-cancel-message)
4702 (run-hooks 'message-cancel-hook)
4704 (message "Canceling your article...")
4705 (if (let ((message-syntax-checks
4706 'dont-check-for-anything-just-trust-me))
4707 (funcall message-send-news-function))
4708 (message "Canceling your article...done"))
4709 (kill-buffer buf))))))
4712 (defun message-supersede ()
4713 "Start composing a message to supersede the current message.
4714 This is done simply by taking the old article and adding a Supersedes
4715 header line with the old Message-ID."
4717 (let ((cur (current-buffer))
4718 (sender (message-fetch-field "sender"))
4719 (from (message-fetch-field "from")))
4720 ;; Check whether the user owns the article that is to be superseded.
4722 ;; Canlock-logic as suggested by Per Abrahamsen
4723 ;; <abraham@dina.kvl.dk>
4725 ;; IF article has cancel-lock THEN
4726 ;; IF we can verify it THEN
4729 ;; error: cancellock: article is not yours
4731 ;; Use old rules, comparing sender...
4732 (if (message-fetch-field "Cancel-Lock")
4733 (if (null (canlock-verify))
4735 (error "Failed to verify Cancel-lock: This article is not yours"))
4737 (message-gnksa-enable-p 'cancel-messages)
4741 (downcase (message-make-sender))))
4743 (downcase (cadr (mail-extract-address-components from)))
4744 (downcase (cadr (mail-extract-address-components
4745 (message-make-from))))))
4746 (error "This article is not yours"))
4747 ;; Get a normal message buffer.
4748 (message-pop-to-buffer (message-buffer-name "supersede"))
4749 (insert-buffer-substring cur)
4751 (message-narrow-to-head-1)
4752 ;; Remove unwanted headers.
4753 (when message-ignored-supersedes-headers
4754 (message-remove-header message-ignored-supersedes-headers t))
4755 (goto-char (point-min))
4756 (if (not (re-search-forward "^Message-ID: " nil t))
4757 (error "No Message-ID in this article")
4758 (replace-match "Supersedes: " t t))
4759 (goto-char (point-max))
4760 (insert mail-header-separator)
4765 (defun message-recover ()
4766 "Reread contents of current buffer from its last auto-save file."
4768 (let ((file-name (make-auto-save-file-name)))
4769 (cond ((save-window-excursion
4770 (if (not (eq system-type 'vax-vms))
4771 (with-output-to-temp-buffer "*Directory*"
4772 (with-current-buffer standard-output
4773 (fundamental-mode)) ; for Emacs 20.4+
4774 (buffer-disable-undo standard-output)
4775 (let ((default-directory "/"))
4777 "ls" nil standard-output nil "-l" file-name))))
4778 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4779 (let ((buffer-read-only nil))
4781 (insert-file-contents file-name nil)))
4782 (t (error "message-recover cancelled")))))
4784 ;;; Washing Subject:
4786 (defun message-wash-subject (subject)
4787 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
4788 Previous forwarders, replyers, etc. may add it."
4791 (goto-char (point-min))
4792 ;; strip Re/Fwd stuff off the beginning
4793 (while (re-search-forward
4794 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4797 ;; and gnus-style forwards [foo@bar.com] subject
4798 (goto-char (point-min))
4799 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4803 (goto-char (point-max))
4804 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4807 ;; and finally, any whitespace that was left-over
4808 (goto-char (point-min))
4809 (while (re-search-forward "^[ \t]+" nil t)
4811 (goto-char (point-max))
4812 (while (re-search-backward "[ \t]+$" nil t)
4817 ;;; Forwarding messages.
4819 (defvar message-forward-decoded-p nil
4820 "Non-nil means the original message is decoded.")
4822 (defun message-forward-subject-author-subject (subject)
4823 "Generate a SUBJECT for a forwarded message.
4824 The form is: [Source] Subject, where if the original message was mail,
4825 Source is the sender, and if the original message was news, Source is
4826 the list of newsgroups is was posted to."
4829 (or (message-fetch-field "newsgroups")
4830 (message-fetch-field "from")
4832 (if message-forward-decoded-p
4834 (mail-decode-encoded-word-string prefix)))
4837 (defun message-forward-subject-fwd (subject)
4838 "Generate a SUBJECT for a forwarded message.
4839 The form is: Fwd: Subject, where Subject is the original subject of
4841 (concat "Fwd: " subject))
4843 (defun message-make-forward-subject ()
4844 "Return a Subject header suitable for the message in the current buffer."
4847 (message-narrow-to-head-1)
4848 (let ((funcs message-make-forward-subject-function)
4849 (subject (message-fetch-field "Subject")))
4852 (if message-forward-decoded-p
4854 (mail-decode-encoded-word-string subject))
4856 (if message-wash-forwarded-subjects
4857 (setq subject (message-wash-subject subject)))
4858 ;; Make sure funcs is a list.
4861 (setq funcs (list funcs)))
4862 ;; Apply funcs in order, passing subject generated by previous
4863 ;; func to the next one.
4865 (when (message-functionp (car funcs))
4866 (setq subject (funcall (car funcs) subject)))
4867 (setq funcs (cdr funcs)))
4871 (defvar gnus-article-decoded-p))
4875 (defun message-forward (&optional news digest)
4876 "Forward the current message via mail.
4877 Optional NEWS will use news to forward instead of mail.
4878 Optional DIGEST will use digest to forward."
4880 (let* ((cur (current-buffer))
4881 (message-forward-decoded-p
4882 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
4883 gnus-article-decoded-p ;; In an article buffer.
4884 message-forward-decoded-p))
4885 (subject (message-make-forward-subject)))
4887 (message-news nil subject)
4888 (message-mail nil subject))
4889 (message-forward-make-body cur digest)))
4892 (defun message-forward-make-body (forward-buffer &optional digest)
4893 ;; Put point where we want it before inserting the forwarded
4895 (if message-forward-before-signature
4897 (goto-char (point-max)))
4898 (if message-forward-as-mime
4900 (insert "\n<#multipart type=digest>\n")
4901 (if message-forward-show-mml
4902 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4903 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4904 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4905 (let ((b (point)) e)
4907 (if message-forward-as-mime
4908 (insert-buffer-substring forward-buffer)
4909 (mml-insert-buffer forward-buffer))
4910 (if (and message-forward-show-mml
4911 (not message-forward-decoded-p))
4914 (mm-disable-multibyte-mule4) ;; Must copy buffer in unibyte mode
4916 (with-current-buffer forward-buffer
4917 (mm-string-as-unibyte (buffer-string))))
4918 (mm-enable-multibyte-mule4)
4920 (goto-char (point-min))
4921 (when (looking-at "From ")
4922 (replace-match "X-From-Line: "))
4925 (narrow-to-region (point) (point))
4926 (mml-insert-buffer forward-buffer)
4927 (goto-char (point-min))
4928 (when (looking-at "From ")
4929 (replace-match "X-From-Line: "))
4930 (goto-char (point-max)))))
4932 (if message-forward-as-mime
4934 (insert "<#/multipart>\n")
4935 (if message-forward-show-mml
4936 (insert "<#/mml>\n")
4937 (insert "<#/part>\n")))
4938 (insert "\n-------------------- End of forwarded message --------------------\n"))
4939 (if (and digest message-forward-as-mime)
4941 (narrow-to-region b e)
4943 (narrow-to-region (point)
4944 (or (search-forward "\n\n" nil t) (point)))
4945 (delete-region (point-min) (point-max)))
4946 (when (and (not current-prefix-arg)
4947 message-forward-ignored-headers)
4949 (narrow-to-region b e)
4951 (narrow-to-region (point)
4952 (or (search-forward "\n\n" nil t) (point)))
4953 (message-remove-header message-forward-ignored-headers t)))))
4954 (message-position-point))
4957 (defun message-forward-rmail-make-body (forward-buffer)
4958 (save-window-excursion
4959 (set-buffer forward-buffer)
4960 (let (rmail-enable-mime)
4961 (rmail-toggle-header 0)))
4962 (message-forward-make-body forward-buffer))
4965 (defun message-insinuate-rmail ()
4966 "Let RMAIL uses message to forward."
4968 (setq rmail-enable-mime-composing t)
4969 (setq rmail-insert-mime-forwarded-message-function
4970 'message-forward-rmail-make-body))
4973 (defun message-resend (address)
4974 "Resend the current article to ADDRESS."
4976 (list (message-read-from-minibuffer "Resend message to: ")))
4977 (message "Resending message to %s..." address)
4979 (let ((cur (current-buffer))
4981 ;; We first set up a normal mail buffer.
4982 (unless (message-mail-user-agent)
4983 (set-buffer (get-buffer-create " *message resend*"))
4985 (let ((message-this-is-mail t))
4986 (message-setup `((To . ,address))))
4987 ;; Insert our usual headers.
4988 (message-generate-headers '(From Date To))
4989 (message-narrow-to-headers)
4990 ;; Rename them all to "Resent-*".
4991 (while (re-search-forward "^[A-Za-z]" nil t)
4996 (delete-region (point) (point-max))
4998 ;; Insert the message to be resent.
4999 (insert-buffer-substring cur)
5000 (goto-char (point-min))
5001 (search-forward "\n\n")
5004 (narrow-to-region beg (point))
5005 (message-remove-header message-ignored-resent-headers t)
5006 (goto-char (point-max)))
5007 (insert mail-header-separator)
5008 ;; Rename all old ("Also-")Resent headers.
5009 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5012 ;; Quote any "From " lines at the beginning.
5014 (when (looking-at "From ")
5015 (replace-match "X-From-Line: "))
5017 (let ((message-inhibit-body-encoding t)
5018 message-required-mail-headers)
5019 (message-send-mail))
5020 (kill-buffer (current-buffer)))
5021 (message "Resending message to %s...done" address)))
5024 (defun message-bounce ()
5025 "Re-mail the current message.
5026 This only makes sense if the current message is a bounce message that
5027 contains some mail you have written which has been bounced back to
5030 (let ((handles (mm-dissect-buffer t))
5032 (message-pop-to-buffer (message-buffer-name "bounce"))
5033 (if (stringp (car handles))
5034 ;; This is a MIME bounce.
5035 (mm-insert-part (car (last handles)))
5036 ;; This is a non-MIME bounce, so we try to remove things
5038 (mm-insert-part handles)
5040 (goto-char (point-min))
5041 (search-forward "\n\n" nil t)
5042 (if (or (and (re-search-forward message-unsent-separator nil t)
5044 (re-search-forward "^Return-Path:.*\n" nil t))
5045 ;; We remove everything before the bounced mail.
5048 (if (re-search-forward "^[^ \n\t]+:" nil t)
5051 (when (re-search-backward "^.?From .*\n" nil t)
5052 (delete-region (match-beginning 0) (match-end 0)))))
5053 (mm-enable-multibyte)
5056 (message-narrow-to-head-1)
5057 (message-remove-header message-ignored-bounced-headers t)
5058 (goto-char (point-max))
5059 (insert mail-header-separator))
5060 (message-position-point)))
5063 ;;; Interactive entry points for new message buffers.
5067 (defun message-mail-other-window (&optional to subject)
5068 "Like `message-mail' command, but display mail buffer in another window."
5070 (unless (message-mail-user-agent)
5071 (let ((pop-up-windows t)
5072 (special-display-buffer-names nil)
5073 (special-display-regexps nil)
5074 (same-window-buffer-names nil)
5075 (same-window-regexps nil))
5076 (message-pop-to-buffer (message-buffer-name "mail" to))))
5077 (let ((message-this-is-mail t))
5078 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5079 nil nil 'switch-to-buffer-other-window)))
5082 (defun message-mail-other-frame (&optional to subject)
5083 "Like `message-mail' command, but display mail buffer in another frame."
5085 (unless (message-mail-user-agent)
5086 (let ((pop-up-frames t)
5087 (special-display-buffer-names nil)
5088 (special-display-regexps nil)
5089 (same-window-buffer-names nil)
5090 (same-window-regexps nil))
5091 (message-pop-to-buffer (message-buffer-name "mail" to))))
5092 (let ((message-this-is-mail t))
5093 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5094 nil nil 'switch-to-buffer-other-frame)))
5097 (defun message-news-other-window (&optional newsgroups subject)
5098 "Start editing a news article to be sent."
5100 (let ((pop-up-windows t)
5101 (special-display-buffer-names nil)
5102 (special-display-regexps nil)
5103 (same-window-buffer-names nil)
5104 (same-window-regexps nil))
5105 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5106 (let ((message-this-is-news t))
5107 (message-setup `((Newsgroups . ,(or newsgroups ""))
5108 (Subject . ,(or subject ""))))))
5111 (defun message-news-other-frame (&optional newsgroups subject)
5112 "Start editing a news article to be sent."
5114 (let ((pop-up-frames t)
5115 (special-display-buffer-names nil)
5116 (special-display-regexps nil)
5117 (same-window-buffer-names nil)
5118 (same-window-regexps nil))
5119 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5120 (let ((message-this-is-news t))
5121 (message-setup `((Newsgroups . ,(or newsgroups ""))
5122 (Subject . ,(or subject ""))))))
5126 ;; This code should be moved to underline.el (from which it is stolen).
5129 (defun bold-region (start end)
5130 "Bold all nonblank characters in the region.
5131 Works by overstriking characters.
5132 Called from program, takes two arguments START and END
5133 which specify the range to operate on."
5136 (let ((end1 (make-marker)))
5137 (move-marker end1 (max start end))
5138 (goto-char (min start end))
5139 (while (< (point) end1)
5140 (or (looking-at "[_\^@- ]")
5141 (insert (char-after) "\b"))
5142 (forward-char 1)))))
5145 (defun unbold-region (start end)
5146 "Remove all boldness (overstruck characters) in the region.
5147 Called from program, takes two arguments START and END
5148 which specify the range to operate on."
5151 (let ((end1 (make-marker)))
5152 (move-marker end1 (max start end))
5153 (goto-char (min start end))
5154 (while (re-search-forward "\b" end1 t)
5155 (if (eq (char-after) (char-after (- (point) 2)))
5156 (delete-char -2))))))
5158 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5160 ;; Support for toolbar
5162 (defvar tool-bar-map)
5163 (defvar tool-bar-mode))
5165 (defun message-tool-bar-map ()
5166 (or message-tool-bar-map
5167 (setq message-tool-bar-map
5168 (and (fboundp 'tool-bar-add-item-from-menu)
5170 (let ((tool-bar-map (copy-keymap tool-bar-map))
5171 (load-path (mm-image-load-path)))
5172 ;; Zap some items which aren't so relevant and take
5174 (dolist (key '(print-buffer kill-buffer save-buffer
5175 write-file dired open-file))
5176 (define-key tool-bar-map (vector key) nil))
5177 (tool-bar-add-item-from-menu
5178 'message-send-and-exit "mail_send" message-mode-map)
5179 (tool-bar-add-item-from-menu
5180 'message-kill-buffer "close" message-mode-map)
5181 (tool-bar-add-item-from-menu
5182 'message-dont-send "cancel" message-mode-map)
5183 (tool-bar-add-item-from-menu
5184 'mml-attach-file "attach" mml-mode-map)
5185 (tool-bar-add-item-from-menu
5186 'ispell-message "spell" message-mode-map)
5187 (tool-bar-add-item-from-menu
5188 'message-insert-importance-high "important"
5190 (tool-bar-add-item-from-menu
5191 'message-insert-importance-low "unimportant"
5195 ;;; Group name completion.
5197 (defcustom message-newgroups-header-regexp
5198 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5199 "Regexp that match headers that lists groups."
5203 (defcustom message-completion-alist
5204 (list (cons message-newgroups-header-regexp 'message-expand-group)
5205 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name))
5206 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
5208 :type '(alist :key-type regexp :value-type function))
5210 (defcustom message-tab-body-function nil
5211 "*Function to execute when `message-tab' (TAB) is executed in the body.
5212 If nil, the function bound in `text-mode-map' or `global-map' is executed."
5216 (defun message-tab ()
5217 "Complete names according to `message-completion-alist'.
5218 Execute function specified by `message-tab-body-function' when not in
5221 (let ((alist message-completion-alist))
5223 (let ((mail-abbrev-mode-regexp (caar alist)))
5224 (not (mail-abbrev-in-expansion-header-p))))
5225 (setq alist (cdr alist)))
5226 (funcall (or (cdar alist) message-tab-body-function
5227 (lookup-key text-mode-map "\t")
5228 (lookup-key global-map "\t")
5229 'indent-relative))))
5231 (defun message-expand-group ()
5232 "Expand the group name under point."
5233 (let* ((b (save-excursion
5238 (skip-chars-forward "^:")
5241 (skip-chars-backward "^, \t\n") (point))))
5242 (completion-ignore-case t)
5243 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5245 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5246 (completions (all-completions string hashtb))
5248 (delete-region b (point))
5250 ((= (length completions) 1)
5251 (if (string= (car completions) string)
5254 (message "Only matching group"))
5255 (insert (car completions))))
5256 ((and (setq comp (try-completion string hashtb))
5257 (not (string= comp string)))
5262 (message "No matching groups")
5263 (save-selected-window
5264 (pop-to-buffer "*Completions*")
5265 (buffer-disable-undo)
5266 (let ((buffer-read-only nil))
5268 (let ((standard-output (current-buffer)))
5269 (display-completion-list (sort completions 'string<)))
5270 (goto-char (point-min))
5271 (delete-region (point) (progn (forward-line 3) (point))))))))))
5273 (defun message-expand-name ()
5274 (if (fboundp 'bbdb-complete-name)
5275 (bbdb-complete-name)
5280 (defun message-talkative-question (ask question show &rest text)
5281 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5282 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5283 The following arguments may contain lists of values."
5285 (setq text (message-flatten-list text)))
5286 (save-window-excursion
5288 (with-output-to-temp-buffer " *MESSAGE information message*"
5289 (set-buffer " *MESSAGE information message*")
5290 (fundamental-mode) ; for Emacs 20.4+
5291 (mapcar 'princ text)
5292 (goto-char (point-min))))
5293 (funcall ask question))
5294 (funcall ask question)))
5296 (defun message-flatten-list (list)
5297 "Return a new, flat list that contains all elements of LIST.
5299 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5302 (apply 'append (mapcar 'message-flatten-list list)))
5306 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5307 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
5308 Then clone the local variables and values from the old buffer to the
5309 new one, cloning only the locals having a substring matching the
5311 (let ((oldbuf (current-buffer)))
5313 (set-buffer (generate-new-buffer name))
5314 (message-clone-locals oldbuf varstr)
5317 (defun message-clone-locals (buffer &optional varstr)
5318 "Clone the local variables from BUFFER to the current buffer."
5319 (let ((locals (save-excursion
5321 (buffer-local-variables)))
5322 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
5325 (when (and (consp local)
5327 (string-match regexp (symbol-name (car local)))
5329 (string-match varstr (symbol-name (car local)))))
5331 (set (make-local-variable (car local))
5335 ;;; Miscellaneous functions
5337 (defsubst message-replace-chars-in-string (string from to)
5338 (mm-subst-char-in-string from to string))
5344 (defvar message-inhibit-body-encoding nil)
5346 (defun message-encode-message-body ()
5347 (unless message-inhibit-body-encoding
5348 (let ((mail-parse-charset (or mail-parse-charset
5349 message-default-charset))
5350 (case-fold-search t)
5351 lines content-type-p)
5354 (narrow-to-region (point) (point-max))
5355 (let ((new (mml-generate-mime)))
5357 (delete-region (point-min) (point-max))
5359 (goto-char (point-min))
5360 (if (eq (aref new 0) ?\n)
5362 (search-forward "\n\n")
5363 (setq lines (buffer-substring (point-min) (1- (point))))
5364 (delete-region (point-min) (point))))))
5366 (message-narrow-to-headers-or-head)
5367 (message-remove-header "Mime-Version")
5368 (goto-char (point-max))
5369 (insert "MIME-Version: 1.0\n")
5372 (setq content-type-p
5374 (re-search-backward "^Content-Type:" nil t))))
5376 (message-narrow-to-headers-or-head)
5377 (message-remove-first-header "Content-Type")
5378 (message-remove-first-header "Content-Transfer-Encoding"))
5379 ;; We always make sure that the message has a Content-Type header.
5380 ;; This is because some broken MTAs and MUAs get awfully confused
5381 ;; when confronted with a message with a MIME-Version header and
5382 ;; without a Content-Type header. For instance, Solaris'
5384 (unless content-type-p
5385 (goto-char (point-min))
5386 ;; For unknown reason, MIME-Version doesn't exist.
5387 (when (re-search-forward "^MIME-Version:" nil t)
5389 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
5391 (defun message-read-from-minibuffer (prompt)
5392 "Read from the minibuffer while providing abbrev expansion."
5393 (if (fboundp 'mail-abbrevs-setup)
5394 (let ((mail-abbrev-mode-regexp "")
5395 (minibuffer-setup-hook 'mail-abbrevs-setup)
5396 (minibuffer-local-map message-minibuffer-local-map))
5397 (read-from-minibuffer prompt))
5398 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
5399 (minibuffer-local-map message-minibuffer-local-map))
5400 (read-string prompt))))
5402 (defun message-use-alternative-email-as-from ()
5403 (require 'mail-utils)
5404 (let* ((fields '("To" "Cc"))
5407 (mail-strip-quoted-names
5408 (mapconcat 'message-fetch-reply-field fields ","))
5412 (if (string-match message-alternative-emails (car emails))
5413 (setq email (car emails)
5416 (unless (or (not email) (equal email user-mail-address))
5417 (goto-char (point-max))
5418 (insert "From: " email "\n"))))
5420 (defun message-options-get (symbol)
5421 (cdr (assq symbol message-options)))
5423 (defun message-options-set (symbol value)
5424 (let ((the-cons (assq symbol message-options)))
5427 (setcdr the-cons value)
5428 (setq message-options (delq the-cons message-options)))
5430 (push (cons symbol value) message-options))))
5433 (defun message-options-set-recipient ()
5435 (message-narrow-to-headers-or-head)
5436 (message-options-set 'message-sender
5437 (mail-strip-quoted-names
5438 (message-fetch-field "from")))
5439 (message-options-set 'message-recipients
5440 (mail-strip-quoted-names
5441 (let ((to (message-fetch-field "to"))
5442 (cc (message-fetch-field "cc"))
5443 (bcc (message-fetch-field "bcc")))
5446 (if (and to cc) ", ")
5448 (if (and (or to cc) bcc) ", ")
5451 (when (featurep 'xemacs)
5452 (require 'messagexmas)
5453 (message-xmas-redefine))
5457 (run-hooks 'message-load-hook)
5460 ;; coding: iso-8859-1
5463 ;;; message.el ends here