1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
47 (require 'canlock-om))
51 ;; This is apparently necessary even though things are autoloaded.
52 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
53 ;; require mailabbrev here.
54 (if (featurep 'xemacs)
55 (require 'mail-abbrevs)
56 (require 'mailabbrev))
58 (eval-when-compile (require 'static))
60 ;; Avoid byte-compile warnings.
67 (autoload 'sha1 "sha1-el")
68 (autoload 'customize-save-variable "cus-edit"));; for Mule 2.
70 (defgroup message '((user-mail-address custom-variable)
71 (user-full-name custom-variable))
72 "Mail and news message composing."
73 :link '(custom-manual "(message)Top")
77 (put 'user-mail-address 'custom-type 'string)
78 (put 'user-full-name 'custom-type 'string)
80 (defgroup message-various nil
81 "Various Message Variables"
82 :link '(custom-manual "(message)Various Message Variables")
85 (defgroup message-buffers nil
87 :link '(custom-manual "(message)Message Buffers")
90 (defgroup message-sending nil
92 :link '(custom-manual "(message)Sending Variables")
95 (defgroup message-interface nil
97 :link '(custom-manual "(message)Interface")
100 (defgroup message-forwarding nil
102 :link '(custom-manual "(message)Forwarding")
103 :group 'message-interface)
105 (defgroup message-insertion nil
107 :link '(custom-manual "(message)Insertion")
110 (defgroup message-headers nil
112 :link '(custom-manual "(message)Message Headers")
115 (defgroup message-news nil
116 "Composing News Messages"
119 (defgroup message-mail nil
120 "Composing Mail Messages"
123 (defgroup message-faces nil
124 "Faces used for message composing."
128 (defgroup message-frames nil
132 (defcustom message-directory "~/Mail/"
133 "*Directory from which all other mail file variables are derived."
134 :group 'message-various
137 (defcustom message-max-buffers 10
138 "*How many buffers to keep before starting to kill them off."
139 :group 'message-buffers
142 (defcustom message-send-rename-function nil
143 "Function called to rename the buffer after sending it."
144 :group 'message-buffers
145 :type '(choice function (const nil)))
147 (defcustom message-fcc-handler-function 'message-output
148 "*A function called to save outgoing articles.
149 This function will be called with the name of the file to store the
150 article in. The default function is `message-output' which saves in Unix
152 :type '(radio (function-item message-output)
153 (function :tag "Other"))
154 :group 'message-sending)
156 (defcustom message-encode-function 'message-maybe-encode
157 "*A function called to encode messages."
158 :group 'message-sending
161 (defcustom message-8bit-encoding-list '(8bit binary)
162 "*8bit encoding type in Content-Transfer-Encoding field."
163 :group 'message-sending
164 :type '(repeat (symbol :tag "Type")))
166 (defcustom message-fcc-externalize-attachments nil
167 "If non-nil, attachments are included as external parts in Fcc copies."
169 :group 'message-sending)
171 (defcustom message-courtesy-message
172 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
173 "*This is inserted at the start of a mailed copy of a posted message.
174 If the string contains the format spec \"%s\", the Newsgroups
175 the article has been posted to will be inserted there.
176 If this variable is nil, no such courtesy message will be added."
177 :group 'message-sending
180 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
181 "*Regexp that matches headers to be removed in resent bounced mail."
182 :group 'message-interface
185 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
186 "Function to setup a re-sending bounced message."
187 :group 'message-sending
191 (defcustom message-from-style 'default
192 "*Specifies how \"From\" headers look.
194 If nil, they contain just the return address like:
196 If `parens', they look like:
197 king@grassland.com (Elvis Parsley)
198 If `angles', they look like:
199 Elvis Parsley <king@grassland.com>
201 Otherwise, most addresses look like `angles', but they look like
202 `parens' if `angles' would need quoting and `parens' would not."
203 :type '(choice (const :tag "simple" nil)
207 :group 'message-headers)
209 (defcustom message-insert-canlock t
210 "Whether to insert a Cancel-Lock header in news postings."
212 :group 'message-headers
215 (defcustom message-syntax-checks
216 (if message-insert-canlock '((sender . disabled)) nil)
217 ;; Guess this one shouldn't be easy to customize...
218 "*Controls what syntax checks should not be performed on outgoing posts.
219 To disable checking of long signatures, for instance, add
220 `(signature . disabled)' to this list.
222 Don't touch this variable unless you really know what you're doing.
224 Checks include `subject-cmsg', `multiple-headers', `sendsys',
225 `message-id', `from', `long-lines', `control-chars', `size',
226 `new-text', `quoting-style', `redirected-followup', `signature',
227 `approved', `sender', `empty', `empty-headers', `message-id', `from',
228 `subject', `shorten-followup-to', `existing-newsgroups',
229 `buffer-file-name', `unchanged', `newsgroups', `reply-to'."
231 :type '(repeat sexp)) ; Fixme: improve this
233 (defcustom message-required-news-headers
234 '(From Newsgroups Subject Date Message-ID
235 (optional . Organization) Lines
236 (optional . User-Agent))
237 "*Headers to be generated or prompted for when posting an article.
238 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
239 Message-ID. Organization, Lines, In-Reply-To, Expires, and
240 User-Agent are optional. If don't you want message to insert some
241 header, remove it from this list."
243 :group 'message-headers
244 :type '(repeat sexp))
246 (defcustom message-required-mail-headers
247 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
248 (optional . User-Agent))
249 "*Headers to be generated or prompted for when mailing a message.
250 It is recommended that From, Date, To, Subject and Message-ID be
251 included. Organization, Lines and User-Agent are optional."
253 :group 'message-headers
254 :type '(repeat sexp))
256 (defcustom message-deletable-headers '(Message-ID Date Lines)
257 "Headers to be deleted if they already exist and were generated by message previously."
258 :group 'message-headers
261 (defcustom message-ignored-news-headers
262 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
263 "*Regexp of headers to be removed unconditionally before posting."
265 :group 'message-headers
268 (defcustom message-ignored-mail-headers
269 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
270 "*Regexp of headers to be removed unconditionally before mailing."
272 :group 'message-headers
275 (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:"
276 "*Header lines matching this regexp will be deleted before posting.
277 It's best to delete old Path and Date headers before posting to avoid
279 :group 'message-interface
282 (defcustom message-supersede-setup-function
283 'message-supersede-setup-for-mime-edit
284 "Function to setup a supersede message."
285 :group 'message-sending
288 (defcustom message-subject-re-regexp
289 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
290 "*Regexp matching \"Re: \" in the subject line."
291 :group 'message-various
294 ;;; Some sender agents encode the whole subject including leading "Re: ".
295 ;;; And if followup agent does not decode it for some reason (e.g. unknown
296 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
297 ;;; result will contain multiple "Re: "'s.
298 (defcustom message-subject-encoded-re-regexp
302 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
305 "[Bb]" (regexp-quote "?") ; B encoding
306 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
308 "[Uc][km]U6" ; [Rr][Ee]:
310 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
312 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
315 "[Qb]" (regexp-quote "?") ; Q encoding
316 "\\(_\\|=09\\|=20\\)*"
317 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
320 "*Regexp matching \"Re: \" in the subject line.
321 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
323 :group 'message-various
326 (defcustom message-use-subject-re t
327 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
328 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
329 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
330 :group 'message-various
331 :type '(choice (const :tag "off" nil)
336 (defcustom message-signature-separator "^-- *$"
337 "Regexp matching the signature separator."
339 :group 'message-various)
341 (defcustom message-signature-separator-for-insertion "-- \n"
342 "*Signature separator. This value will be inserted as signature separator
343 when composing message. Default value is \"-- \\n\". Notice: Changing this
344 value may go against RFC-1036 and draft-ietf-usefor-article-05.txt. "
346 :group 'message-insertion)
348 (defcustom message-elide-ellipsis "\n[...]\n\n"
349 "*The string which is inserted for elided text."
351 :group 'message-various)
353 (defcustom message-interactive t
354 "Non-nil means when sending a message wait for and display errors.
355 nil means let mailer mail back a message to report errors."
356 :group 'message-sending
360 (defcustom message-generate-new-buffers 'unique
361 "*Non-nil means create a new message buffer whenever `message-setup' is called.
362 If this is a function, call that function with three parameters: The type,
363 the to address and the group name. (Any of these may be nil.) The function
364 should return the new buffer name."
365 :group 'message-buffers
366 :type '(choice (const :tag "off" nil)
367 (const :tag "unique" unique)
368 (const :tag "unsent" unsent)
371 (defcustom message-kill-buffer-on-exit nil
372 "*Non-nil means that the message buffer will be killed after sending a message."
373 :group 'message-buffers
376 (defcustom message-kill-buffer-query-function 'yes-or-no-p
377 "*Function used to prompt user whether to kill the message buffer. If
378 it is t, the buffer will be killed unconditionally."
379 :type '(radio (function-item yes-or-no-p)
380 (function-item y-or-n-p)
381 (function-item nnheader-Y-or-n-p)
382 (function :tag "Other" t))
383 :group 'message-buffers)
385 (defcustom message-kill-buffer-and-remove-file t
386 "*Non-nil means that the associated file will be removed before
387 removing the message buffer. However, it is treated as nil when the
388 command `message-mimic-kill-buffer' is used."
389 :group 'message-buffers
393 (defvar gnus-local-organization))
394 (defcustom message-user-organization
395 (or (and (boundp 'gnus-local-organization)
396 (stringp gnus-local-organization)
397 gnus-local-organization)
398 (getenv "ORGANIZATION")
400 "*String to be used as an Organization header.
401 If t, use `message-user-organization-file'."
402 :group 'message-headers
403 :type '(choice string
404 (const :tag "consult file" t)))
407 (defcustom message-user-organization-file "/usr/lib/news/organization"
408 "*Local news organization file."
410 :group 'message-headers)
412 (defcustom message-forward-start-separator
413 (concat (mime-make-tag "message" "rfc822") "\n")
414 "*Delimiter inserted before forwarded messages."
415 :group 'message-forwarding
418 (defcustom message-forward-end-separator
419 (concat (mime-make-tag "text" "plain") "\n")
420 "*Delimiter inserted after forwarded messages."
421 :group 'message-forwarding
424 (defcustom message-included-forward-headers
425 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-\\|^MIME-Version:"
426 "*Regexp matching headers to be included in forwarded messages."
427 :group 'message-forwarding
430 (defcustom message-make-forward-subject-function
431 'message-forward-subject-author-subject
432 "*List of functions called to generate subject headers for forwarded messages.
433 The subject generated by the previous function is passed into each
436 The provided functions are:
438 * `message-forward-subject-author-subject' (Source of article (author or
439 newsgroup)), in brackets followed by the subject
440 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
442 :group 'message-forwarding
443 :type '(radio (function-item message-forward-subject-author-subject)
444 (function-item message-forward-subject-fwd)
445 (repeat :tag "List of functions" function)))
447 (defcustom message-forward-as-mime t
448 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
450 :group 'message-forwarding
453 (defcustom message-forward-show-mml t
454 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
456 :group 'message-forwarding
459 (defcustom message-forward-before-signature t
460 "*If non-nil, put forwarded message before signature, else after."
461 :group 'message-forwarding
464 (defcustom message-wash-forwarded-subjects nil
465 "*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."
466 :group 'message-forwarding
469 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
470 "*All headers that match this regexp will be deleted when resending a message."
471 :group 'message-interface
474 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
475 "*All headers that match this regexp will be deleted when forwarding a message."
477 :group 'message-forwarding
478 :type '(choice (const :tag "None" nil)
481 (defcustom message-ignored-cited-headers "."
482 "*Delete these headers from the messages you yank."
483 :group 'message-insertion
486 (defcustom message-cite-prefix-regexp
487 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
488 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
489 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
490 (let ((old-table (syntax-table))
491 non-word-constituents)
492 (set-syntax-table text-mode-syntax-table)
493 (setq non-word-constituents
495 (if (string-match "\\w" "-") "" "-")
496 (if (string-match "\\w" "_") "" "_")
497 (if (string-match "\\w" ".") "" ".")))
498 (set-syntax-table old-table)
499 (if (equal non-word-constituents "")
500 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
501 (concat "\\([ \t]*\\(\\w\\|["
502 non-word-constituents
503 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
504 "*Regexp matching the longest possible citation prefix on a line."
505 :group 'message-insertion
508 (defcustom message-cancel-message "I am canceling my own article.\n"
509 "Message to be inserted in the cancel message."
510 :group 'message-interface
513 ;; Useful to set in site-init.el
515 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
516 "Function to call to send the current buffer as mail.
517 The headers should be delimited by a line whose contents match the
518 variable `mail-header-separator'.
520 Valid values include `message-send-mail-with-sendmail' (the default),
521 `message-send-mail-with-mh', `message-send-mail-with-qmail',
522 `message-send-mail-with-smtp', `smtpmail-send-it' and `feedmail-send-it'.
524 See also `send-mail-function'."
525 :type '(radio (function-item message-send-mail-with-sendmail)
526 (function-item message-send-mail-with-mh)
527 (function-item message-send-mail-with-qmail)
528 (function-item message-send-mail-with-smtp)
529 (function-item smtpmail-send-it)
530 (function-item feedmail-send-it)
531 (function :tag "Other"))
532 :group 'message-sending
533 :group 'message-mail)
535 ;; 1997-09-29 by MORIOKA Tomohiko
536 (defcustom message-send-news-function 'message-send-news-with-gnus
537 "Function to call to send the current buffer as news.
538 The headers should be delimited by a line whose contents match the
539 variable `mail-header-separator'."
540 :group 'message-sending
544 (defcustom message-reply-to-function nil
545 "If non-nil, function that should return a list of headers.
546 This function should pick out addresses from the To, Cc, and From headers
547 and respond with new To and Cc headers."
548 :group 'message-interface
549 :type '(choice function (const nil)))
551 (defcustom message-wide-reply-to-function nil
552 "If non-nil, function that should return a list of headers.
553 This function should pick out addresses from the To, Cc, and From headers
554 and respond with new To and Cc headers."
555 :group 'message-interface
556 :type '(choice function (const nil)))
558 (defcustom message-followup-to-function nil
559 "If non-nil, function that should return a list of headers.
560 This function should pick out addresses from the To, Cc, and From headers
561 and respond with new To and Cc headers."
562 :group 'message-interface
563 :type '(choice function (const nil)))
565 (defcustom message-use-followup-to 'ask
566 "*Specifies what to do with Followup-To header.
567 If nil, always ignore the header. If it is t, use its value, but
568 query before using the \"poster\" value. If it is the symbol `ask',
569 always query the user whether to use the value. If it is the symbol
570 `use', always use the value."
571 :group 'message-interface
572 :type '(choice (const :tag "ignore" nil)
573 (const :tag "use & query" t)
574 (const :tag "maybe" t)
575 (const :tag "always" use)
576 (const :tag "ask" ask)))
578 (defcustom message-use-mail-copies-to 'ask
579 "*Specifies what to do with Mail-Copies-To header.
580 If nil, always ignore the header. If it is t, use its value, but
581 query before using the value other than \"always\" or \"never\".
582 If it is the symbol `ask', always query the user whether to use
583 the value. If it is the symbol `use', always use the value."
584 :group 'message-interface
585 :type '(choice (const :tag "ignore" nil)
586 (const :tag "maybe" t)
587 (const :tag "always" use)
588 (const :tag "ask" ask)))
590 ;;; XXX: 'ask and 'use are not implemented yet.
591 (defcustom message-use-mail-reply-to 'ask
592 "*Specifies what to do with Mail-Reply-To/Reply-To header.
593 If nil, always ignore the header. If it is t or the symbol `use', use
594 its value. If it is the symbol `ask', always query the user whether to
595 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
597 :group 'message-interface
598 :type '(choice (const :tag "ignore" nil)
599 (const :tag "maybe" t)
600 (const :tag "always" use)
601 (const :tag "ask" ask)))
603 (defcustom message-use-mail-followup-to 'use
604 "*Specifies what to do with Mail-Followup-To header.
605 If nil, always ignore the header. If it is the symbol `ask', always
606 query the user whether to use the value. If it is t or the symbol
607 `use', always use the value."
608 :group 'message-interface
609 :type '(choice (const :tag "ignore" nil)
610 (const :tag "maybe" t)
611 (const :tag "always" use)
612 (const :tag "ask" ask)))
614 (defcustom message-subscribed-address-functions nil
615 "*Specifies functions for determining list subscription.
616 If nil, do not attempt to determine list subscribtion with functions.
617 If non-nil, this variable contains a list of functions which return
618 regular expressions to match lists. These functions can be used in
619 conjunction with `message-subscribed-regexps' and
620 `message-subscribed-addresses'."
621 :group 'message-interface
622 :type '(repeat sexp))
624 (defcustom message-subscribed-address-file nil
625 "*A file containing addresses the user is subscribed to.
626 If nil, do not look at any files to determine list subscriptions. If
627 non-nil, each line of this file should be a mailing list address."
628 :group 'message-interface
631 (defcustom message-subscribed-addresses nil
632 "*Specifies a list of addresses the user is subscribed to.
633 If nil, do not use any predefined list subscriptions. This list of
634 addresses can be used in conjuction with
635 `message-subscribed-address-functions' and `message-subscribed-regexps'."
636 :group 'message-interface
637 :type '(repeat string))
639 (defcustom message-subscribed-regexps nil
640 "*Specifies a list of addresses the user is subscribed to.
641 If nil, do not use any predefined list subscriptions. This list of
642 regular expressions can be used in conjuction with
643 `message-subscribed-address-functions' and `message-subscribed-addresses'."
644 :group 'message-interface
645 :type '(repeat regexp))
647 (defcustom message-allow-no-recipients 'ask
648 "Specifies what to do when there are no recipients other than Gcc/Fcc.
649 If it is the symbol `always', the posting is allowed. If it is the
650 symbol `never', the posting is not allowed. If it is the symbol
651 `ask', you are prompted."
652 :group 'message-interface
653 :type '(choice (const always)
657 (defcustom message-sendmail-f-is-evil nil
658 "*Non-nil means don't add \"-f username\" to the sendmail command line.
659 Doing so would be even more evil than leaving it out."
660 :group 'message-sending
663 ;; qmail-related stuff
664 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
665 "Location of the qmail-inject program."
666 :group 'message-sending
669 (defcustom message-qmail-inject-args nil
670 "Arguments passed to qmail-inject programs.
671 This should be a list of strings, one string for each argument. It
672 may also be a function.
674 For e.g., if you wish to set the envelope sender address so that bounces
675 go to the right place or to deal with listserv's usage of that address, you
676 might set this variable to '(\"-f\" \"you@some.where\")."
677 :group 'message-sending
678 :type '(choice (function)
681 (defvar message-cater-to-broken-inn t
682 "Non-nil means Gnus should not fold the `References' header.
683 Folding `References' makes ancient versions of INN create incorrect
687 (defvar gnus-post-method)
688 (defvar gnus-select-method))
689 (defcustom message-post-method
690 (cond ((and (boundp 'gnus-post-method)
691 (listp gnus-post-method)
694 ((boundp 'gnus-select-method)
697 "*Method used to post news.
698 Note that when posting from inside Gnus, for instance, this
699 variable isn't used."
701 :group 'message-sending
702 ;; This should be the `gnus-select-method' widget, but that might
703 ;; create a dependence to `gnus.el'.
706 (defcustom message-generate-headers-first nil
707 "*If non-nil, generate all required headers before composing.
708 The variables `message-required-news-headers' and
709 `message-required-mail-headers' specify which headers to generate.
711 Note that the variable `message-deletable-headers' specifies headers which
712 are to be deleted and then re-generated before sending, so this variable
713 will not have a visible effect for those headers."
714 :group 'message-headers
717 (defcustom message-setup-hook '(turn-on-mime-edit)
718 "Normal hook, run each time a new outgoing message is initialized.
719 The function `message-setup' runs this hook."
720 :group 'message-various
723 (defcustom message-cancel-hook nil
724 "Hook run when cancelling articles."
725 :group 'message-various
728 (defcustom message-signature-setup-hook nil
729 "Normal hook, run each time a new outgoing message is initialized.
730 It is run after the headers have been inserted and before
731 the signature is inserted."
732 :group 'message-various
735 (defcustom message-bounce-setup-hook nil
736 "Normal hook, run each time a re-sending bounced message is initialized.
737 The function `message-bounce' runs this hook."
738 :group 'message-various
741 (defcustom message-supersede-setup-hook nil
742 "Normal hook, run each time a supersede message is initialized.
743 The function `message-supersede' runs this hook."
744 :group 'message-various
747 (defcustom message-mode-hook nil
748 "Hook run in message mode buffers."
749 :group 'message-various
752 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
753 "Hook run in a message mode buffer narrowed to the headers."
754 :group 'message-various
757 (defcustom message-header-setup-hook nil
758 "Hook called narrowed to the headers when setting up a message buffer."
759 :group 'message-various
762 (defcustom message-minibuffer-local-map
763 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
764 (set-keymap-parent map minibuffer-local-map)
766 "Keymap for `message-read-from-minibuffer'.")
769 (defcustom message-citation-line-function 'message-insert-citation-line
770 "*Function called to insert the \"Whomever writes:\" line.
772 Note that Gnus provides a feature where the reader can click on
773 `writes:' to hide the cited text. If you change this line too much,
774 people who read your message will have to change their Gnus
775 configuration. See the variable `gnus-cite-attribution-suffix'."
777 :group 'message-insertion)
780 (defcustom message-yank-prefix "> "
781 "*Prefix inserted on the lines of yanked messages.
782 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
783 See also `message-yank-cited-prefix'."
785 :group 'message-insertion)
787 (defcustom message-yank-add-new-references t
788 "Non-nil means new IDs will be added to \"References\" field when an
789 article is yanked by the command `message-yank-original' interactively.
790 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
791 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
792 \"Message-ID\" fields are used."
793 :type '(radio (const :tag "Do not add anything" nil)
794 (const :tag "From Message-Id, References and In-Reply-To fields" t)
795 (const :tag "From only Message-Id field." message-id-only))
796 :group 'message-insertion)
798 (defcustom message-list-references-add-position nil
799 "Integer value means position for adding to \"References\" field when
800 an article is yanked by the command `message-yank-original' interactively."
801 :type '(radio (const :tag "Add to last" nil)
802 (integer :tag "Position from last ID"))
803 :group 'message-insertion)
805 (defcustom message-yank-cited-prefix ">"
806 "*Prefix inserted on cited or empty lines of yanked messages.
807 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
808 See also `message-yank-prefix'."
810 :group 'message-insertion)
812 (defcustom message-indentation-spaces 3
813 "*Number of spaces to insert at the beginning of each cited line.
814 Used by `message-yank-original' via `message-yank-cite'."
815 :group 'message-insertion
819 (defcustom message-cite-function 'message-cite-original
820 "*Function for citing an original message.
821 Predefined functions include `message-cite-original' and
822 `message-cite-original-without-signature'.
823 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
824 :type '(radio (function-item message-cite-original)
825 (function-item message-cite-original-without-signature)
826 (function-item mu-cite-original)
827 (function-item sc-cite-original)
828 (function :tag "Other"))
829 :group 'message-insertion)
832 (defcustom message-suspend-font-lock-when-citing nil
833 "Non-nil means suspend font-lock'ing while citing an original message.
834 Some lazy demand-driven fontification tools (or Emacs itself) have a
835 bug that they often miss a buffer to be fontified. It will mostly
836 occur when Emacs prompts user for any inputs in the minibuffer.
837 Setting this option to non-nil may help you to avoid unpleasant errors
838 even if it is an add-hoc expedient."
840 :group 'message-insertion)
843 (defcustom message-indent-citation-function 'message-indent-citation
844 "*Function for modifying a citation just inserted in the mail buffer.
845 This can also be a list of functions. Each function can find the
846 citation between (point) and (mark t). And each function should leave
847 point and mark around the citation text as modified."
849 :group 'message-insertion)
852 (defcustom message-signature t
853 "*String to be inserted at the end of the message buffer.
854 If t, the `message-signature-file' file will be inserted instead.
855 If a function, the result from the function will be used instead.
856 If a form, the result from the form will be used instead."
858 :group 'message-insertion)
861 (defcustom message-signature-file "~/.signature"
862 "*Name of file containing the text inserted at end of message buffer.
863 Ignored if the named file doesn't exist.
864 If nil, don't insert a signature."
865 :type '(choice file (const :tags "None" nil))
866 :group 'message-insertion)
868 (defcustom message-distribution-function nil
869 "*Function called to return a Distribution header."
871 :group 'message-headers
872 :type '(choice function (const nil)))
874 (defcustom message-expires 14
875 "Number of days before your article expires."
877 :group 'message-headers
878 :link '(custom-manual "(message)News Headers")
881 (defcustom message-user-path nil
882 "If nil, use the NNTP server name in the Path header.
883 If stringp, use this; if non-nil, use no host name (user name only)."
885 :group 'message-headers
886 :link '(custom-manual "(message)News Headers")
887 :type '(choice (const :tag "nntp" nil)
889 (sexp :tag "none" :format "%t" t)))
891 (defvar message-reply-buffer nil)
892 (defvar message-reply-headers nil
893 "The headers of the current replied article.
894 It is a vector of the following headers:
895 \[number subject from date id references chars lines xref extra].")
896 (defvar message-sent-message-via nil)
897 (defvar message-checksum nil)
898 (defvar message-send-actions nil
899 "A list of actions to be performed upon successful sending of a message.")
900 (defvar message-exit-actions nil
901 "A list of actions to be performed upon exiting after sending a message.")
902 (defvar message-kill-actions nil
903 "A list of actions to be performed before killing a message buffer.")
904 (defvar message-postpone-actions nil
905 "A list of actions to be performed after postponing a message.")
906 (defvar message-original-frame nil)
907 (defvar message-parameter-alist nil)
908 (defvar message-startup-parameter-alist nil)
910 (define-widget 'message-header-lines 'text
911 "All header lines must be LFD terminated."
912 :format "%{%t%}:%n%v"
914 :error "All header lines must be newline terminated")
916 (defcustom message-default-headers ""
917 "*A string containing header lines to be inserted in outgoing messages.
918 It is inserted before you edit the message, so you can edit or delete
920 :group 'message-headers
921 :type 'message-header-lines)
923 (defcustom message-default-mail-headers ""
924 "*A string of header lines to be inserted in outgoing mails."
925 :group 'message-headers
927 :type 'message-header-lines)
929 (defcustom message-default-news-headers ""
930 "*A string of header lines to be inserted in outgoing news articles."
931 :group 'message-headers
933 :type 'message-header-lines)
935 ;; Note: could use /usr/ucb/mail instead of sendmail;
936 ;; options -t, and -v if not interactive.
937 (defcustom message-mailer-swallows-blank-line
938 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
939 system-configuration)
940 (file-readable-p "/etc/sendmail.cf")
941 (let ((buffer (get-buffer-create " *temp*")))
945 (insert-file-contents "/etc/sendmail.cf")
946 (goto-char (point-min))
947 (let ((case-fold-search nil))
948 (re-search-forward "^OR\\>" nil t)))
949 (kill-buffer buffer))))
950 ;; According to RFC822, "The field-name must be composed of printable
951 ;; ASCII characters (i. e., characters that have decimal values between
952 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
954 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
955 "*Set this non-nil if the system's mailer runs the header and body together.
956 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
957 The value should be an expression to test whether the problem will
959 :group 'message-sending
962 ;;; XXX: This symbol is overloaded! See below.
963 (defvar message-user-agent nil
964 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
966 (static-when (boundp 'MULE)
967 (require 'reporter));; `define-mail-user-agent' is here.
970 (define-mail-user-agent 'message-user-agent
971 'message-mail 'message-send-and-exit
972 'message-kill-buffer 'message-send-hook)
974 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
975 "If non-nil, delete the deletable headers before feeding to mh.")
977 (defvar message-send-method-alist
978 '((news message-news-p message-send-via-news)
979 (mail message-mail-p message-send-via-mail))
980 "Alist of ways to send outgoing messages.
981 Each element has the form
983 \(TYPE PREDICATE FUNCTION)
985 where TYPE is a symbol that names the method; PREDICATE is a function
986 called without any parameters to determine whether the message is
987 a message of type TYPE; and FUNCTION is a function to be called if
988 PREDICATE returns non-nil. FUNCTION is called with one parameter --
991 (defcustom message-mail-alias-type 'abbrev
992 "*What alias expansion type to use in Message buffers.
993 The default is `abbrev', which uses mailabbrev. nil switches
996 :link '(custom-manual "(message)Mail Aliases")
997 :type '(choice (const :tag "Use Mailabbrev" abbrev)
998 (const :tag "No expansion" nil)))
1000 (defcustom message-auto-save-directory
1001 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1002 "*Directory where Message auto-saves buffers if Gnus isn't running.
1003 If nil, Message won't auto-save."
1004 :group 'message-buffers
1005 :type '(choice directory (const :tag "Don't auto-save" nil)))
1007 (defcustom message-default-charset
1008 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
1009 "Default charset used in non-MULE XEmacsen."
1014 (defcustom message-dont-reply-to-names
1015 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1016 "*A regexp specifying addresses to prune when doing wide replies.
1017 A value of nil means exclude your own user name only."
1020 :type '(choice (const :tag "Yourself" nil)
1023 (defvar message-shoot-gnksa-feet nil
1024 "*A list of GNKSA feet you are allowed to shoot.
1025 Gnus gives you all the opportunity you could possibly want for
1026 shooting yourself in the foot. Also, Gnus allows you to shoot the
1027 feet of Good Net-Keeping Seal of Approval. The following are foot
1029 `empty-article' Allow you to post an empty article;
1030 `quoted-text-only' Allow you to post quoted text only;
1031 `multiple-copies' Allow you to post multiple copies;
1032 `cancel-messages' Allow you to cancel or supersede messages from
1033 your other email addresses.")
1035 (defsubst message-gnksa-enable-p (feature)
1036 (or (not (listp message-shoot-gnksa-feet))
1037 (memq feature message-shoot-gnksa-feet)))
1039 ;;; Internal variables.
1040 ;;; Well, not really internal.
1042 (defvar message-mode-syntax-table
1043 (let ((table (copy-syntax-table text-mode-syntax-table)))
1044 (modify-syntax-entry ?% ". " table)
1045 (modify-syntax-entry ?> ". " table)
1046 (modify-syntax-entry ?< ". " table)
1048 "Syntax table used while in Message mode.")
1050 (defface message-header-to-face
1053 (:foreground "green2" :bold t))
1056 (:foreground "MidnightBlue" :bold t))
1058 (:bold t :italic t)))
1059 "Face used for displaying From headers."
1060 :group 'message-faces)
1062 (defface message-header-cc-face
1065 (:foreground "green4" :bold t))
1068 (:foreground "MidnightBlue"))
1071 "Face used for displaying Cc headers."
1072 :group 'message-faces)
1074 (defface message-header-subject-face
1077 (:foreground "green3"))
1080 (:foreground "navy blue" :bold t))
1083 "Face used for displaying subject headers."
1084 :group 'message-faces)
1086 (defface message-header-newsgroups-face
1089 (:foreground "yellow" :bold t :italic t))
1092 (:foreground "blue4" :bold t :italic t))
1094 (:bold t :italic t)))
1095 "Face used for displaying newsgroups headers."
1096 :group 'message-faces)
1098 (defface message-header-other-face
1101 (:foreground "#b00000"))
1104 (:foreground "steel blue"))
1106 (:bold t :italic t)))
1107 "Face used for displaying newsgroups headers."
1108 :group 'message-faces)
1110 (defface message-header-name-face
1113 (:foreground "DarkGreen"))
1116 (:foreground "cornflower blue"))
1119 "Face used for displaying header names."
1120 :group 'message-faces)
1122 (defface message-header-xheader-face
1125 (:foreground "blue"))
1128 (:foreground "blue"))
1131 "Face used for displaying X-Header headers."
1132 :group 'message-faces)
1134 (defface message-separator-face
1137 (:foreground "blue3"))
1140 (:foreground "brown"))
1143 "Face used for displaying the separator."
1144 :group 'message-faces)
1146 (defface message-cited-text-face
1149 (:foreground "red"))
1152 (:foreground "red"))
1155 "Face used for displaying cited text names."
1156 :group 'message-faces)
1158 (defface message-mml-face
1161 (:foreground "ForestGreen"))
1164 (:foreground "ForestGreen"))
1167 "Face used for displaying MML."
1168 :group 'message-faces)
1170 (defun message-font-lock-make-header-matcher (regexp)
1173 (let ((start (point)))
1176 (goto-char (point-min))
1177 (if (re-search-forward
1178 (concat "^" (regexp-quote mail-header-separator) "$")
1180 (setq limit (min limit (match-beginning 0))))
1182 (and (< start limit)
1183 (re-search-forward ,regexp limit t))))))
1184 (if (featurep 'bytecomp)
1188 (defvar message-font-lock-keywords
1189 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1190 `((,(message-font-lock-make-header-matcher
1191 (concat "^\\([Tt]o:\\)" content))
1192 (1 'message-header-name-face)
1193 (2 'message-header-to-face nil t))
1194 (,(message-font-lock-make-header-matcher
1195 (concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1196 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1197 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1198 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content))
1199 (1 'message-header-name-face)
1200 (2 'message-header-cc-face nil t))
1201 (,(message-font-lock-make-header-matcher
1202 (concat "^\\([Ss]ubject:\\)" content))
1203 (1 'message-header-name-face)
1204 (2 'message-header-subject-face nil t))
1205 (,(message-font-lock-make-header-matcher
1206 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1207 (1 'message-header-name-face)
1208 (2 'message-header-newsgroups-face nil t))
1209 (,(message-font-lock-make-header-matcher
1210 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1211 (1 'message-header-name-face)
1212 (2 'message-header-other-face nil t))
1213 (,(message-font-lock-make-header-matcher
1214 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1215 (1 'message-header-name-face)
1216 (2 'message-header-name-face))
1217 ,@(if (and mail-header-separator
1218 (not (equal mail-header-separator "")))
1219 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1220 1 'message-separator-face))
1223 (re-search-forward (concat "^\\("
1224 message-cite-prefix-regexp
1227 (0 'message-cited-text-face))
1228 (,mime-edit-tag-regexp
1229 (0 'message-mml-face))))
1230 "Additional expressions to highlight in Message mode.")
1232 ;; XEmacs does it like this. For Emacs, we have to set the
1233 ;; `font-lock-defaults' buffer-local variable.
1234 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1236 (defvar message-face-alist
1237 '((bold . bold-region)
1238 (underline . underline-region)
1239 (default . (lambda (b e)
1241 (ununderline-region b e))))
1242 "Alist of mail and news faces for facemenu.
1243 The cdr of ech entry is a function for applying the face to a region.")
1245 (defcustom message-send-hook nil
1246 "Hook run before sending messages."
1247 :group 'message-various
1248 :options '(ispell-message)
1251 (defcustom message-send-mail-hook nil
1252 "Hook run before sending mail messages."
1253 :group 'message-various
1256 (defcustom message-send-news-hook nil
1257 "Hook run before sending news messages."
1258 :group 'message-various
1261 (defcustom message-sent-hook nil
1262 "Hook run after sending messages."
1263 :group 'message-various
1266 (defcustom message-use-multi-frames nil
1267 "Make new frame when sending messages."
1268 :group 'message-frames
1271 (defcustom message-delete-frame-on-exit nil
1272 "Delete frame after sending messages."
1273 :group 'message-frames
1274 :type '(choice (const :tag "off" nil)
1275 (const :tag "always" t)
1276 (const :tag "ask" ask)))
1278 (defvar message-draft-coding-system
1279 nnheader-auto-save-coding-system
1280 "Coding system to compose mail.")
1282 (defcustom message-send-mail-partially-limit 1000000
1283 "The limitation of messages sent as message/partial.
1284 The lower bound of message size in characters, beyond which the message
1285 should be sent in several parts. If it is nil, the size is unlimited."
1287 :group 'message-buffers
1288 :type '(choice (const :tag "unlimited" nil)
1291 (defcustom message-alternative-emails nil
1292 "A regexp to match the alternative email addresses.
1293 The first matched address (not primary one) is used in the From field."
1294 :group 'message-headers
1295 :type '(choice (const :tag "Always use primary" nil)
1298 (defcustom message-hierarchical-addresses nil
1299 "A list of hierarchical mail address definitions.
1301 Inside each entry, the first address is the \"top\" address, and
1302 subsequent addresses are subaddresses; this is used to indicate that
1303 mail sent to the first address will automatically be delivered to the
1304 subaddresses. So if the first address appears in the recipient list
1305 for a message, the subaddresses will be removed (if present) before
1306 the mail is sent. All addresses in this structure should be
1308 :group 'message-headers
1309 :type '(repeat (repeat string)))
1311 (defcustom message-mail-user-agent nil
1312 "Like `mail-user-agent'.
1313 Except if it is nil, use Gnus native MUA; if it is t, use
1315 :type '(radio (const :tag "Gnus native"
1318 (const :tag "`mail-user-agent'"
1321 (function-item :tag "Default Emacs mail"
1323 sendmail-user-agent)
1324 (function-item :tag "Emacs interface to MH"
1327 (function :tag "Other"))
1331 (defcustom message-wide-reply-confirm-recipients nil
1332 "Whether to confirm a wide reply to multiple email recipients.
1333 If this variable is nil, don't ask whether to reply to all recipients.
1334 If this variable is non-nil, pose the question \"Reply to all
1335 recipients?\" before a wide reply to multiple recipients. If the user
1336 answers yes, reply to all recipients as usual. If the user answers
1337 no, only reply back to the author."
1339 :group 'message-headers
1342 ;;; Internal variables.
1344 (defvar message-sending-message "Sending...")
1345 (defvar message-buffer-list nil)
1346 (defvar message-this-is-news nil)
1347 (defvar message-this-is-mail nil)
1348 (defvar message-draft-article nil)
1349 (defvar message-mime-part nil)
1350 (defvar message-posting-charset nil)
1352 ;; Byte-compiler warning
1354 (defvar gnus-active-hashtb)
1355 (defvar gnus-read-active-file))
1357 ;;; Regexp matching the delimiter of messages in UNIX mail format
1358 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1359 ;;; of rmail.el's rmail-unix-mail-delimiter.
1360 (defvar message-unix-mail-delimiter
1361 (let ((time-zone-regexp
1362 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1363 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1369 ;; Many things can happen to an RFC 822 mailbox before it is put into
1370 ;; a `From' line. The leading phrase can be stripped, e.g.
1371 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1372 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1373 ;; can be removed, e.g.
1374 ;; From: joe@y.z (Joe K
1376 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1379 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1380 ;; The mailbox can be removed or be replaced by white space, e.g.
1381 ;; From: "Joe User"{space}{tab}
1383 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1384 ;; where {space} and {tab} represent the Ascii space and tab characters.
1385 ;; We want to match the results of any of these manglings.
1386 ;; The following regexp rejects names whose first characters are
1387 ;; obviously bogus, but after that anything goes.
1388 "\\([^\0-\b\n-\r\^?].*\\)? "
1390 ;; The time the message was sent.
1391 "\\([^\0-\r \^?]+\\) +" ; day of the week
1392 "\\([^\0-\r \^?]+\\) +" ; month
1393 "\\([0-3]?[0-9]\\) +" ; day of month
1394 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1396 ;; Perhaps a time zone, specified by an abbreviation, or by a
1401 " \\([0-9][0-9]+\\) *"
1403 ;; On some systems the time zone can appear after the year, too.
1407 "\\(remote from .*\\)?"
1410 "Regexp matching the delimiter of messages in UNIX mail format.")
1412 (defvar message-unsent-separator
1413 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1414 "^ *---+ +Returned message +---+ *$\\|"
1415 "^Start of returned message$\\|"
1416 "^ *---+ +Original message +---+ *$\\|"
1417 "^ *--+ +begin message +--+ *$\\|"
1418 "^ *---+ +Original message follows +---+ *$\\|"
1419 "^ *---+ +Undelivered message follows +---+ *$\\|"
1420 "^|? *---+ +Message text follows: +---+ *|?$")
1421 "A regexp that matches the separator before the text of a failed message.")
1423 (defvar message-header-format-alist
1425 (To . message-fill-address)
1426 (Cc . message-fill-address)
1437 (References . message-shorten-references)
1439 "Alist used for formatting headers.")
1441 (defvar message-options nil
1442 "Some saved answers when sending message.")
1444 (defvar message-send-mail-real-function nil
1445 "Internal send mail function.")
1447 (defvar message-bogus-system-names "^localhost\\."
1448 "The regexp of bogus system names.")
1451 (autoload 'message-setup-toolbar "messagexmas")
1452 (autoload 'mh-new-draft-name "mh-comp")
1453 (autoload 'mh-send-letter "mh-comp")
1454 (autoload 'gnus-point-at-eol "gnus-util")
1455 (autoload 'gnus-point-at-bol "gnus-util")
1456 (autoload 'gnus-output-to-rmail "gnus-util")
1457 (autoload 'gnus-output-to-mail "gnus-util")
1458 (autoload 'nndraft-request-associate-buffer "nndraft")
1459 (autoload 'nndraft-request-expire-articles "nndraft")
1460 (autoload 'gnus-open-server "gnus-int")
1461 (autoload 'gnus-request-post "gnus-int")
1462 (autoload 'gnus-copy-article-buffer "gnus-msg")
1463 (autoload 'gnus-alive-p "gnus-util")
1464 (autoload 'gnus-server-string "gnus")
1465 (autoload 'gnus-group-name-charset "gnus-group")
1466 (autoload 'gnus-group-name-decode "gnus-group")
1467 (autoload 'gnus-groups-from-server "gnus")
1468 (autoload 'rmail-output "rmailout")
1469 (autoload 'mu-cite-original "mu-cite"))
1474 ;;; Utility functions.
1476 (defun message-eval-parameter (parameter)
1478 (if (symbolp parameter)
1479 (if (functionp parameter)
1485 (defsubst message-get-parameter (key &optional alist)
1487 (setq alist message-parameter-alist))
1488 (cdr (assq key alist)))
1490 (defmacro message-get-parameter-with-eval (key &optional alist)
1491 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1493 (defmacro message-y-or-n-p (question show &rest text)
1494 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1495 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1497 (defmacro message-delete-line (&optional n)
1498 "Delete the current line (and the next N lines)."
1499 `(delete-region (progn (beginning-of-line) (point))
1500 (progn (forward-line ,(or n 1)) (point))))
1502 (defun message-unquote-tokens (elems)
1503 "Remove double quotes (\") from strings in list ELEMS."
1504 (mapcar (lambda (item)
1505 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1506 (setq item (concat (match-string 1 item)
1507 (match-string 2 item))))
1511 (defun message-tokenize-header (header &optional separator)
1512 "Split HEADER into a list of header elements.
1513 SEPARATOR is a string of characters to be used as separators. \",\"
1514 is used by default."
1517 (let ((regexp (format "[%s]+" (or separator ",")))
1522 (message-set-work-buffer)
1524 (goto-char (point-min))
1529 (cond ((and (> (point) beg)
1531 (and (looking-at regexp)
1534 (push (buffer-substring beg (point)) elems)
1535 (setq beg (match-end 0)))
1536 ((eq (char-after) ?\")
1537 (setq quoted (not quoted)))
1538 ((and (eq (char-after) ?\()
1541 ((and (eq (char-after) ?\))
1544 (nreverse elems)))))
1546 (defun message-mail-file-mbox-p (file)
1547 "Say whether FILE looks like a Unix mbox file."
1548 (when (and (file-exists-p file)
1549 (file-readable-p file)
1550 (file-regular-p file))
1552 (nnheader-insert-file-contents file)
1553 (goto-char (point-min))
1554 (looking-at message-unix-mail-delimiter))))
1556 (defun message-fetch-field (header &optional not-all)
1557 "The same as `mail-fetch-field', only remove all newlines."
1558 (let* ((inhibit-point-motion-hooks t)
1559 (case-fold-search t)
1560 (value (mail-fetch-field header nil (not not-all))))
1562 (while (string-match "\n[\t ]+" value)
1563 (setq value (replace-match " " t t value)))
1564 (set-text-properties 0 (length value) nil value)
1567 (defun message-narrow-to-field ()
1568 "Narrow the buffer to the header on the current line."
1574 (if (re-search-forward "^[^ \n\t]" nil t)
1579 (goto-char (point-min)))
1581 (defun message-add-header (&rest headers)
1582 "Add the HEADERS to the message header, skipping those already present."
1585 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1586 (error "Invalid header `%s'" (car headers)))
1587 (setq hclean (match-string 1 (car headers)))
1589 (message-narrow-to-headers)
1590 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1591 (goto-char (point-max))
1592 (if (string-match "\n$" (car headers))
1593 (insert (car headers))
1594 (insert (car headers) ?\n)))))
1595 (setq headers (cdr headers))))
1598 (defun message-fetch-reply-field (header)
1599 "Fetch field HEADER from the message we're replying to."
1600 (let ((buffer (message-eval-parameter message-reply-buffer)))
1602 (buffer-name buffer))
1605 (message-fetch-field header)))))
1607 (defun message-set-work-buffer ()
1608 (if (get-buffer " *message work*")
1610 (set-buffer " *message work*")
1612 (set-buffer (get-buffer-create " *message work*"))
1613 (kill-all-local-variables)))
1615 (defun message-functionp (form)
1616 "Return non-nil if FORM is funcallable."
1617 (or (and (symbolp form) (fboundp form))
1618 (and (listp form) (eq (car form) 'lambda))
1619 (byte-code-function-p form)))
1621 (defun message-strip-list-identifiers (subject)
1622 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1623 (require 'gnus-sum) ; for gnus-list-identifiers
1624 (let ((regexp (if (stringp gnus-list-identifiers)
1625 gnus-list-identifiers
1626 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1627 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1628 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1629 (concat (substring subject 0 (match-beginning 1))
1630 (or (match-string 3 subject)
1631 (match-string 5 subject))
1636 (defun message-strip-subject-re (subject)
1637 "Remove \"Re:\" from subject lines in string SUBJECT."
1638 (if (string-match message-subject-re-regexp subject)
1639 (substring subject (match-end 0))
1642 (defun message-remove-header (header &optional is-regexp first reverse)
1643 "Remove HEADER in the narrowed buffer.
1644 If IS-REGEXP, HEADER is a regular expression.
1645 If FIRST, only remove the first instance of the header.
1646 Return the number of headers removed."
1647 (goto-char (point-min))
1648 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1650 (case-fold-search t)
1652 (while (and (not (eobp))
1655 (not (looking-at regexp))
1656 (looking-at regexp))
1663 ;; There might be a continuation header, so we have to search
1664 ;; until we find a new non-continuation line.
1667 (if (re-search-forward "^[^ \t]" nil t)
1668 (goto-char (match-beginning 0))
1671 (if (re-search-forward "^[^ \t]" nil t)
1672 (goto-char (match-beginning 0))
1673 (goto-char (point-max)))))
1676 (defun message-remove-first-header (header)
1677 "Remove the first instance of HEADER if there is more than one."
1679 (regexp (concat "^" (regexp-quote header) ":")))
1681 (goto-char (point-min))
1682 (while (re-search-forward regexp nil t)
1685 (message-remove-header header nil t)
1688 (defun message-narrow-to-headers ()
1689 "Narrow the buffer to the head of the message."
1692 (goto-char (point-min))
1693 (if (re-search-forward
1694 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1697 (goto-char (point-min)))
1699 (defun message-narrow-to-head-1 ()
1700 "Like `message-narrow-to-head'. Don't widen."
1702 (goto-char (point-min))
1703 (if (search-forward "\n\n" nil 1)
1706 (goto-char (point-min)))
1708 (defun message-narrow-to-head ()
1709 "Narrow the buffer to the head of the message.
1710 Point is left at the beginning of the narrowed-to region."
1712 (message-narrow-to-head-1))
1714 (defun message-narrow-to-headers-or-head ()
1715 "Narrow the buffer to the head of the message."
1718 (goto-char (point-min))
1721 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1722 (match-beginning 0))
1723 ((search-forward "\n\n" nil t)
1727 (goto-char (point-min)))
1729 (defun message-news-p ()
1730 "Say whether the current buffer contains a news message."
1731 (and (not message-this-is-mail)
1732 (or message-this-is-news
1735 (message-narrow-to-headers)
1736 (and (message-fetch-field "newsgroups")
1737 (not (message-fetch-field "posted-to"))))))))
1739 (defun message-mail-p ()
1740 "Say whether the current buffer contains a mail message."
1741 (and (not message-this-is-news)
1742 (or message-this-is-mail
1745 (message-narrow-to-headers)
1746 (or (message-fetch-field "to")
1747 (message-fetch-field "cc")
1748 (message-fetch-field "bcc")))))))
1750 (defun message-next-header ()
1751 "Go to the beginning of the next header."
1753 (or (eobp) (forward-char 1))
1754 (not (if (re-search-forward "^[^ \t]" nil t)
1756 (goto-char (point-max)))))
1758 (defun message-sort-headers-1 ()
1759 "Sort the buffer as headers using `message-rank' text props."
1760 (goto-char (point-min))
1763 nil 'message-next-header
1765 (message-next-header)
1769 (or (get-text-property (point) 'message-rank)
1772 (defun message-sort-headers ()
1773 "Sort the headers of the current message according to `message-header-format-alist'."
1777 (let ((max (1+ (length message-header-format-alist)))
1779 (message-narrow-to-headers)
1780 (while (re-search-forward "^[^ \n]+:" nil t)
1782 (match-beginning 0) (1+ (match-beginning 0))
1784 (if (setq rank (length (memq (assq (intern (buffer-substring
1786 (1- (match-end 0))))
1787 message-header-format-alist)
1788 message-header-format-alist)))
1791 (message-sort-headers-1))))
1801 (defvar message-mode-map nil)
1803 (unless message-mode-map
1804 (setq message-mode-map (make-keymap))
1805 (set-keymap-parent message-mode-map text-mode-map)
1806 (define-key message-mode-map "\C-c?" 'describe-mode)
1808 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1809 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
1810 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1811 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1812 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1813 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1814 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1815 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1816 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1817 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1818 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1819 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1820 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1821 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1822 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1823 (define-key message-mode-map "\C-c\C-f\C-i" 'message-insert-or-toggle-importance)
1824 (define-key message-mode-map "\C-c\C-f\C-a" 'message-gen-unsubscribed-mft)
1825 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1826 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1827 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1829 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1830 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1831 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
1833 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
1834 (define-key message-mode-map "\C-c\M-n" 'message-insert-disposition-notification-to)
1836 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1837 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1838 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1839 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1840 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1841 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1842 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1843 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1845 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1846 (define-key message-mode-map "\C-c\C-s" 'message-send)
1847 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1848 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1849 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
1851 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1852 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1853 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1854 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1855 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1857 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
1858 (define-key message-mode-map "\t" 'message-tab)
1859 (define-key message-mode-map "\M-;" 'comment-region)
1861 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1864 message-mode-menu message-mode-map "Message Menu."
1866 ["Sort Headers" message-sort-headers t]
1867 ["Yank Original" message-yank-original t]
1868 ["Fill Yanked Message" message-fill-yanked-message t]
1869 ["Insert Signature" message-insert-signature t]
1870 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1871 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1872 ["Elide Region" message-elide-region (mark t)]
1873 ["Delete Outside Region" message-delete-not-region (mark t)]
1874 ["Kill To Signature" message-kill-to-signature t]
1875 ["Newline and Reformat" message-newline-and-reformat t]
1876 ["Rename buffer" message-rename-buffer t]
1877 ["Flag As Important" message-insert-importance-high
1878 ,@(if (featurep 'xemacs) '(t)
1879 '(:help "Mark this message as important"))]
1880 ["Flag As Unimportant" message-insert-importance-low
1881 ,@(if (featurep 'xemacs) '(t)
1882 '(:help "Mark this message as unimportant"))]
1884 message-insert-disposition-notification-to
1885 ,@(if (featurep 'xemacs) '(t)
1886 '(:help "Request a Disposition Notification of this article"))]
1887 ["Spellcheck" ispell-message
1888 ,@(if (featurep 'xemacs) '(t)
1889 '(:help "Spellcheck this message"))]
1890 ["Attach file as MIME" mime-edit-insert-file
1891 ,@(if (featurep 'xemacs) '(t)
1892 '(:help "Attach a file at point"))]
1894 ["Send Message" message-send-and-exit
1895 ,@(if (featurep 'xemacs) '(t)
1896 '(:help "Send this message"))]
1897 ["Postpone Message" message-dont-send
1898 ,@(if (featurep 'xemacs) '(t)
1899 '(:help "File this draft message and exit"))]
1900 ["Send at Specific Time" gnus-delay-article
1901 ,@(if (featurep 'xemacs) '(t)
1902 '(:help "Ask, then arrange to send message at that time"))]
1903 ["Kill Message" message-kill-buffer
1904 ,@(if (featurep 'xemacs) '(t)
1905 '(:help "Delete this message without sending"))]))
1908 message-mode-field-menu message-mode-map ""
1910 ["Fetch To" message-insert-to t]
1911 ["Fetch Newsgroups" message-insert-newsgroups t]
1913 ["To" message-goto-to t]
1914 ["From" message-goto-from t]
1915 ["Subject" message-goto-subject t]
1916 ["Cc" message-goto-cc t]
1917 ["Reply-To" message-goto-reply-to t]
1918 ["Mail-Reply-To" message-goto-mail-reply-to t]
1919 ["Mail-Followup-To" message-goto-mail-followup-to t]
1920 ["Mail-Copies-To" message-goto-mail-copies-to t]
1921 ["Summary" message-goto-summary t]
1922 ["Keywords" message-goto-keywords t]
1923 ["Newsgroups" message-goto-newsgroups t]
1924 ["Followup-To" message-goto-followup-to t]
1925 ["Mail-Followup-To" message-goto-mail-followup-to t]
1926 ["Distribution" message-goto-distribution t]
1927 ["Body" message-goto-body t]
1928 ["Signature" message-goto-signature t]))
1930 (defvar message-tool-bar-map nil)
1933 (defvar facemenu-add-face-function)
1934 (defvar facemenu-remove-face-function))
1936 ;;; Forbidden properties
1938 ;; We use `after-change-functions' to keep special text properties
1939 ;; that interfer with the normal function of message mode out of the
1942 (defcustom message-strip-special-text-properties t
1943 "Strip special properties from the message buffer.
1945 Emacs has a number of special text properties which can break message
1946 composing in various ways. If this option is set, message will strip
1947 these properties from the message composition buffer. However, some
1948 packages requires these properties to be present in order to work.
1949 If you use one of these packages, turn this option off, and hope the
1950 message composition doesn't break too bad."
1951 :group 'message-various
1954 (defconst message-forbidden-properties
1955 ;; No reason this should be clutter up customize. We make it a
1956 ;; property list (rather than a list of property symbols), to be
1957 ;; directly useful for `remove-text-properties'.
1958 '(field nil read-only nil intangible nil invisible nil
1959 mouse-face nil modification-hooks nil insert-in-front-hooks nil
1960 insert-behind-hooks nil point-entered nil point-left nil)
1961 ;; Other special properties:
1962 ;; category, face, display: probably doesn't do any harm.
1963 ;; fontified: is used by font-lock.
1964 ;; syntax-table, local-map: I dunno.
1965 ;; We need to add XEmacs names to the list.
1966 "Property list of with properties.forbidden in message buffers.
1967 The values of the properties are ignored, only the property names are used.")
1969 (defun message-tamago-not-in-use-p (pos)
1970 "Return t when tamago version 4 is not in use at the cursor position.
1971 Tamago version 4 is a popular input method for writing Japanese text.
1972 It uses the properties `intangible', `invisible', `modification-hooks'
1973 and `read-only' when translating ascii or kana text to kanji text.
1974 These properties are essential to work, so we should never strip them."
1975 (not (and (boundp 'egg-modefull-mode)
1976 (symbol-value 'egg-modefull-mode)
1977 (or (memq (get-text-property pos 'intangible)
1978 '(its-part-1 its-part-2))
1979 (get-text-property pos 'egg-end)
1980 (get-text-property pos 'egg-lang)
1981 (get-text-property pos 'egg-start)))))
1983 (defun message-strip-forbidden-properties (begin end &optional old-length)
1984 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
1985 This function is intended to be called from `after-change-functions'.
1986 See also `message-forbidden-properties'."
1987 (when (and message-strip-special-text-properties
1988 (message-tamago-not-in-use-p begin)
1989 ;; Check whether the invisible MIME part is not inserted.
1990 (not (text-property-any begin end 'mime-edit-invisible t)))
1991 (remove-text-properties begin end message-forbidden-properties)))
1994 (define-derived-mode message-mode text-mode "Message"
1995 "Major mode for editing mail and news to be sent.
1996 Like Text Mode but with these additional commands:\\<message-mode-map>
1997 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1998 C-c C-d Postpone sending the message C-c C-k Kill the message
1999 C-c C-f move to a header field (and create it if there isn't):
2000 C-c C-f C-t move to To C-c C-f C-s move to Subject
2001 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2002 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2003 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2004 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2005 C-c C-f C-o move to From (\"Originator\")
2006 C-c C-f C-f move to Followup-To
2007 C-c C-f C-m move to Mail-Followup-To
2008 C-c C-f C-i cycle through Importance values
2009 C-c C-f c move to Mail-Copies-To
2010 C-c C-t `message-insert-to' (add a To header to a news followup)
2011 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2012 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2013 C-c C-b `message-goto-body' (move to beginning of message text).
2014 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2015 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2016 C-c C-y `message-yank-original' (insert current message, if any).
2017 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2018 C-c C-e `message-elide-region' (elide the text between point and mark).
2019 C-c C-v `message-delete-not-region' (remove the text outside the region).
2020 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2021 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2022 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2023 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2024 M-RET `message-newline-and-reformat' (break the line and reformat)."
2025 (setq local-abbrev-table text-mode-abbrev-table)
2026 (set (make-local-variable 'message-reply-buffer) nil)
2027 (make-local-variable 'message-send-actions)
2028 (make-local-variable 'message-exit-actions)
2029 (make-local-variable 'message-kill-actions)
2030 (make-local-variable 'message-postpone-actions)
2031 (make-local-variable 'message-draft-article)
2032 (setq buffer-offer-save t)
2033 (set (make-local-variable 'facemenu-add-face-function)
2035 (let ((face-fun (cdr (assq face message-face-alist))))
2037 (funcall face-fun (point) end)
2038 (error "Face %s not configured for %s mode" face mode-name)))
2040 (set (make-local-variable 'facemenu-remove-face-function) t)
2041 (set (make-local-variable 'message-reply-headers) nil)
2042 (make-local-variable 'message-user-agent)
2043 (make-local-variable 'message-post-method)
2044 (set (make-local-variable 'message-sent-message-via) nil)
2045 (set (make-local-variable 'message-checksum) nil)
2046 (make-local-variable 'message-parameter-alist)
2047 (setq message-parameter-alist
2048 (copy-sequence message-startup-parameter-alist))
2049 (message-setup-fill-variables)
2050 ;; Allow using comment commands to add/remove quoting.
2051 (set (make-local-variable 'comment-start) message-yank-prefix)
2052 (if (featurep 'xemacs)
2053 (message-setup-toolbar)
2054 (set (make-local-variable 'font-lock-defaults)
2055 '(message-font-lock-keywords t))
2056 (if (boundp 'tool-bar-map)
2057 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2058 (easy-menu-add message-mode-menu message-mode-map)
2059 (easy-menu-add message-mode-field-menu message-mode-map)
2060 ;; make-local-hook is harmless though obsolete in Emacs 21.
2061 ;; Emacs 20 and XEmacs need make-local-hook.
2062 (make-local-hook 'after-change-functions)
2063 ;; Mmmm... Forbidden properties...
2064 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2066 ;; Allow mail alias things.
2067 (when (eq message-mail-alias-type 'abbrev)
2068 (if (fboundp 'mail-abbrevs-setup)
2069 (mail-abbrevs-setup)
2070 (mail-aliases-setup)))
2071 (unless buffer-file-name
2072 (message-set-auto-save-file-name))
2073 (set (make-local-variable 'indent-tabs-mode) nil)) ;No tabs for indentation.
2075 (defun message-setup-fill-variables ()
2076 "Setup message fill variables."
2077 (set (make-local-variable 'fill-paragraph-function)
2078 'message-fill-paragraph)
2079 (make-local-variable 'paragraph-separate)
2080 (make-local-variable 'paragraph-start)
2081 (make-local-variable 'adaptive-fill-regexp)
2082 (unless (boundp 'adaptive-fill-first-line-regexp)
2083 (setq adaptive-fill-first-line-regexp nil))
2084 (make-local-variable 'adaptive-fill-first-line-regexp)
2085 (let ((quote-prefix-regexp
2086 ;; User should change message-cite-prefix-regexp if
2087 ;; message-yank-prefix is set to an abnormal value.
2088 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2089 (setq paragraph-start
2091 (regexp-quote mail-header-separator) "$\\|"
2092 "[ \t]*$\\|" ; blank lines
2093 "-- $\\|" ; signature delimiter
2094 "---+$\\|" ; delimiters for forwarded messages
2095 page-delimiter "$\\|" ; spoiler warnings
2096 ".*wrote:$\\|" ; attribution lines
2097 quote-prefix-regexp "$")) ; empty lines in quoted text
2098 (setq paragraph-separate paragraph-start)
2099 (setq adaptive-fill-regexp
2100 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2101 (setq adaptive-fill-first-line-regexp
2102 (concat quote-prefix-regexp "\\|"
2103 adaptive-fill-first-line-regexp)))
2104 (make-local-variable 'auto-fill-inhibit-regexp)
2105 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2106 (setq auto-fill-inhibit-regexp nil)
2107 (make-local-variable 'normal-auto-fill-function)
2108 (setq normal-auto-fill-function 'message-do-auto-fill)
2109 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2110 ;; In that case, ensure that it uses the right function. The real
2111 ;; solution would be not to use `define-derived-mode', and run
2112 ;; `text-mode-hook' ourself at the end of the mode.
2113 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2114 (when auto-fill-function
2115 (setq auto-fill-function normal-auto-fill-function)))
2120 ;;; Message mode commands
2123 ;;; Movement commands
2125 (defun message-goto-to ()
2126 "Move point to the To header."
2128 (message-position-on-field "To"))
2130 (defun message-goto-from ()
2131 "Move point to the From header."
2133 (message-position-on-field "From"))
2135 (defun message-goto-subject ()
2136 "Move point to the Subject header."
2138 (message-position-on-field "Subject"))
2140 (defun message-goto-cc ()
2141 "Move point to the Cc header."
2143 (message-position-on-field "Cc" "To"))
2145 (defun message-goto-bcc ()
2146 "Move point to the Bcc header."
2148 (message-position-on-field "Bcc" "Cc" "To"))
2150 (defun message-goto-fcc ()
2151 "Move point to the Fcc header."
2153 (message-position-on-field "Fcc" "To" "Newsgroups"))
2155 (defun message-goto-reply-to ()
2156 "Move point to the Reply-To header."
2158 (message-position-on-field "Reply-To" "Subject"))
2160 (defun message-goto-mail-reply-to ()
2161 "Move point to the Mail-Reply-To header."
2163 (message-position-on-field "Mail-Reply-To" "Subject"))
2165 (defun message-goto-mail-copies-to ()
2166 "Move point to the Mail-Copies-To header. If the header is newly created,
2167 a string \"never\" is inserted in default."
2169 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2173 (defun message-goto-newsgroups ()
2174 "Move point to the Newsgroups header."
2176 (message-position-on-field "Newsgroups"))
2178 (defun message-goto-distribution ()
2179 "Move point to the Distribution header."
2181 (message-position-on-field "Distribution"))
2183 (defun message-goto-followup-to ()
2184 "Move point to the Followup-To header."
2186 (message-position-on-field "Followup-To" "Newsgroups"))
2188 (defun message-goto-mail-followup-to ()
2189 "Move point to the Mail-Followup-To header. If the header is newly created
2190 and To field contains only one address, the address is inserted in default."
2192 (unless (message-position-on-field "Mail-Followup-To" "Subject")
2193 (let ((start (point))
2196 (message-narrow-to-headers)
2197 (setq addresses (split-string (mail-strip-quoted-names
2198 (or (std11-fetch-field "to") ""))
2200 (when (eq 1 (length addresses))
2202 (insert (car addresses))
2203 (goto-char start))))))
2205 (defun message-goto-keywords ()
2206 "Move point to the Keywords header."
2208 (message-position-on-field "Keywords" "Subject"))
2210 (defun message-goto-summary ()
2211 "Move point to the Summary header."
2213 (message-position-on-field "Summary" "Subject"))
2215 (defun message-goto-body (&optional interactivep)
2216 "Move point to the beginning of the message body."
2217 (interactive (list t))
2218 (when (and interactivep
2219 (looking-at "[ \t]*\n"))
2221 (goto-char (point-min))
2222 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2223 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2225 (defun message-goto-eoh ()
2226 "Move point to the end of the headers."
2231 (defun message-goto-signature ()
2232 "Move point to the beginning of the message signature.
2233 If there is no signature in the article, go to the end and
2236 (goto-char (point-min))
2237 (if (re-search-forward message-signature-separator nil t)
2239 (goto-char (point-max))
2242 (defun message-gen-unsubscribed-mft (&optional include-cc)
2243 "Insert a reasonable MFT header in a post to an unsubscribed list.
2244 When making original posts to a mailing list you are not subscribed to,
2245 you have to type in a MFT header by hand. The contents, usually, are
2246 the addresses of the list and your own address. This function inserts
2247 such a header automatically. It fetches the contents of the To: header
2248 in the current mail buffer, and appends the current user-mail-address.
2250 If the optional argument `include-cc' is non-nil, the addresses in the
2251 Cc: header are also put into the MFT."
2254 (message-remove-header "Mail-Followup-To")
2255 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2257 (concat (message-fetch-field "To") "," cc)
2258 (message-fetch-field "To"))))
2259 (message-goto-mail-followup-to)
2260 (insert (concat tos ", " user-mail-address))))
2264 (defun message-insert-to (&optional force)
2265 "Insert a To header that points to the author of the article being replied to.
2266 If the original author requested not to be sent mail, the function signals
2268 With the prefix argument FORCE, insert the header anyway."
2270 (let ((co (message-fetch-reply-field "mail-copies-to")))
2271 (when (and (null force)
2273 (or (equal (downcase co) "never")
2274 (equal (downcase co) "nobody")))
2275 (error "The user has requested not to have copies sent via mail")))
2276 (when (and (message-position-on-field "To")
2277 (mail-fetch-field "to")
2278 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2280 (insert (or (message-fetch-reply-field "mail-reply-to")
2281 (message-fetch-reply-field "reply-to")
2282 (message-fetch-reply-field "from") "")))
2284 (defun message-widen-reply ()
2285 "Widen the reply to include maximum recipients."
2288 (and message-reply-buffer
2289 (buffer-name message-reply-buffer)
2291 (set-buffer message-reply-buffer)
2292 (message-get-reply-headers t)))))
2295 (message-narrow-to-headers)
2296 (dolist (elem follow-to)
2297 (message-remove-header (symbol-name (car elem)))
2298 (goto-char (point-min))
2299 (insert (symbol-name (car elem)) ": "
2300 (cdr elem) "\n"))))))
2302 (defun message-insert-newsgroups ()
2303 "Insert the Newsgroups header from the article being replied to."
2305 (when (and (message-position-on-field "Newsgroups")
2306 (mail-fetch-field "newsgroups")
2307 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2309 (insert (or (message-fetch-reply-field "newsgroups") "")))
2313 ;;; Various commands
2315 (defun message-delete-not-region (beg end)
2316 "Delete everything in the body of the current message outside of the region."
2321 ;; snarf citation prefix, if appropriate
2322 (unless (eq (point) (progn (beginning-of-line) (point)))
2323 (when (looking-at message-cite-prefix-regexp)
2324 (setq citeprefix (match-string 0))))
2326 (delete-region (point) (if (not (message-goto-signature))
2332 (delete-region beg (progn (message-goto-body)
2336 (insert citeprefix))))
2337 (when (message-goto-signature)
2340 (defun message-kill-to-signature ()
2341 "Deletes all text up to the signature."
2343 (let ((point (point)))
2344 (message-goto-signature)
2347 (kill-region point (point))
2351 (defun message-newline-and-reformat (&optional arg not-break)
2352 "Insert four newlines, and then reformat if inside quoted text.
2353 Prefix arg means justify as well."
2354 (interactive (list (if current-prefix-arg 'full)))
2355 (let (quoted point beg end leading-space bolp)
2356 (setq point (point))
2359 (setq bolp (= beg point))
2360 ;; Find first line of the paragraph.
2362 (while (and (not (eobp))
2363 (not (looking-at message-cite-prefix-regexp))
2364 (looking-at paragraph-start))
2367 (when (looking-at message-cite-prefix-regexp)
2368 (setq quoted (match-string 0))
2369 (goto-char (match-end 0))
2370 (looking-at "[ \t]*")
2371 (setq leading-space (match-string 0)))
2375 (< (- point beg) (length quoted)))
2376 ;; break inside the cite prefix.
2382 (while (and (not (eobp))
2383 (not (looking-at paragraph-separate))
2384 (looking-at message-cite-prefix-regexp)
2385 (equal quoted (match-string 0)))
2386 (goto-char (match-end 0))
2387 (looking-at "[ \t]*")
2388 (if (> (length leading-space) (length (match-string 0)))
2389 (setq leading-space (match-string 0)))
2393 (while (and (if (bobp) nil (forward-line -1) t)
2394 (not (looking-at paragraph-start))
2395 (looking-at message-cite-prefix-regexp)
2396 (equal quoted (match-string 0)))
2398 (goto-char (match-end 0))
2399 (looking-at "[ \t]*")
2400 (if (> (length leading-space) (length (match-string 0)))
2401 (setq leading-space (match-string 0)))))
2402 (while (and (not (eobp))
2403 (not (looking-at paragraph-separate))
2404 (not (looking-at message-cite-prefix-regexp)))
2408 (while (and (if (bobp) nil (forward-line -1) t)
2409 (not (looking-at paragraph-start))
2410 (not (looking-at message-cite-prefix-regexp)))
2411 (setq beg (point))))
2414 (narrow-to-region beg end)
2421 (setq point (point))
2422 ;; (newline 2) doesn't mark both newline's as hard, so call
2423 ;; newline twice. -jas
2426 (delete-region (point) (re-search-forward "[ \t]*"))
2427 (when (and quoted (not bolp))
2428 (insert quoted leading-space)))
2430 (let* ((adaptive-fill-regexp
2431 (regexp-quote (concat quoted leading-space)))
2432 (adaptive-fill-first-line-regexp
2433 adaptive-fill-regexp ))
2434 (fill-paragraph arg))
2435 (fill-paragraph arg))
2436 (if point (goto-char point)))))
2438 (defun message-fill-paragraph (&optional arg)
2439 "Like `fill-paragraph'."
2440 (interactive (list (if current-prefix-arg 'full)))
2441 (if (and (boundp 'filladapt-mode) filladapt-mode)
2443 (message-newline-and-reformat arg t)
2446 ;; Is it better to use `mail-header-end'?
2447 (defun message-point-in-header-p ()
2448 "Return t if point is in the header."
2451 (goto-char (point-min))
2452 (not (re-search-forward
2453 (concat "^" (regexp-quote mail-header-separator) "\n")
2456 (defun message-do-auto-fill ()
2457 "Like `do-auto-fill', but don't fill in message header."
2458 (unless (message-point-in-header-p)
2461 (defun message-insert-signature (&optional force)
2462 "Insert a signature. See documentation for variable `message-signature'."
2463 (interactive (list 0))
2466 ((and (null message-signature)
2469 (goto-char (point-max))
2470 (not (re-search-backward message-signature-separator nil t))))
2471 ((and (null message-signature)
2474 ((message-functionp message-signature)
2475 (funcall message-signature))
2476 ((listp message-signature)
2477 (eval message-signature))
2478 (t message-signature)))
2480 (cond ((stringp signature)
2482 ((and (eq t signature)
2483 message-signature-file
2484 (file-exists-p message-signature-file))
2487 (goto-char (point-max))
2488 ;; Insert the signature.
2491 (insert "\n" message-signature-separator-for-insertion)
2494 (if (eq signature t)
2495 (insert-file-contents message-signature-file)
2497 (goto-char (point-max))
2498 (or (bolp) (insert "\n")))))
2500 (defun message-insert-importance-high ()
2501 "Insert header to mark message as important."
2504 (message-remove-header "Importance")
2506 (insert "Importance: high\n")))
2508 (defun message-insert-importance-low ()
2509 "Insert header to mark message as unimportant."
2512 (message-remove-header "Importance")
2514 (insert "Importance: low\n")))
2516 (defun message-insert-or-toggle-importance ()
2517 "Insert a \"Importance: high\" header, or cycle through the header values.
2518 The three allowed values according to RFC 1327 are `high', `normal'
2522 (let ((valid '("high" "normal" "low"))
2525 (when (setq cur (message-fetch-field "Importance"))
2526 (message-remove-header "Importance")
2527 (setq new (cond ((string= cur "high")
2529 ((string= cur "low")
2534 (insert (format "Importance: %s\n" new)))))
2536 (defun message-insert-disposition-notification-to ()
2537 "Request a disposition notification (return receipt) to this message.
2538 Note that this should not be used in newsgroups."
2541 (message-remove-header "Disposition-Notification-To")
2543 (insert (format "Disposition-Notification-To: %s\n"
2544 (or (message-fetch-field "From") (message-make-from))))))
2546 (defun message-elide-region (b e)
2547 "Elide the text in the region.
2548 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2552 (insert message-elide-ellipsis))
2554 (defvar message-caesar-translation-table nil)
2556 (defun message-caesar-region (b e &optional n)
2557 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2560 (min (point) (or (mark t) (point)))
2561 (max (point) (or (mark t) (point)))
2562 (when current-prefix-arg
2563 (prefix-numeric-value current-prefix-arg))))
2565 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2566 (unless (or (zerop n) ; no action needed for a rot of 0
2567 (= b e)) ; no region to rotate
2568 ;; We build the table, if necessary.
2569 (when (or (not message-caesar-translation-table)
2570 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2571 (setq message-caesar-translation-table
2572 (message-make-caesar-translation-table n)))
2573 (translate-region b e message-caesar-translation-table)))
2575 (defun message-make-caesar-translation-table (n)
2576 "Create a rot table with offset N."
2578 (table (make-string 256 0)))
2579 (while (< (incf i) 256)
2582 (substring table 0 ?A)
2583 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2584 (substring table ?A (+ ?A n))
2585 (substring table (+ ?A 26) ?a)
2586 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2587 (substring table ?a (+ ?a n))
2588 (substring table (+ ?a 26) 255))))
2590 (defun message-caesar-buffer-body (&optional rotnum)
2591 "Caesar rotate all letters in the current buffer by 13 places.
2592 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2593 With prefix arg, specifies the number of places to rotate each letter forward.
2594 Mail and USENET news headers are not rotated."
2595 (interactive (if current-prefix-arg
2596 (list (prefix-numeric-value current-prefix-arg))
2600 (when (message-goto-body)
2601 (narrow-to-region (point) (point-max)))
2602 (message-caesar-region (point-min) (point-max) rotnum))))
2604 (defun message-pipe-buffer-body (program)
2605 "Pipe the message body in the current buffer through PROGRAM."
2608 (when (message-goto-body)
2609 (narrow-to-region (point) (point-max)))
2610 (shell-command-on-region
2611 (point-min) (point-max) program nil t))))
2613 (defun message-rename-buffer (&optional enter-string)
2614 "Rename the *message* buffer to \"*message* RECIPIENT\".
2615 If the function is run with a prefix, it will ask for a new buffer
2616 name, rather than giving an automatic name."
2617 (interactive "Pbuffer name: ")
2620 (goto-char (point-min))
2621 (narrow-to-region (point)
2622 (search-forward mail-header-separator nil 'end))
2624 (if (message-news-p) (message-fetch-field "Newsgroups")
2625 (message-fetch-field "To"))
2628 (if (string-match "," mail-to)
2629 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2631 (name-default (concat "*message* " mail-trimmed-to))
2632 (name (if enter-string
2633 (read-string "New buffer name: " name-default)
2635 (rename-buffer name t)))))
2637 (defun message-fill-yanked-message (&optional justifyp)
2638 "Fill the paragraphs of a message yanked into this one.
2639 Numeric argument means justify as well."
2642 (goto-char (point-min))
2643 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2644 (let ((fill-prefix message-yank-prefix))
2645 (fill-individual-paragraphs (point) (point-max) justifyp))))
2647 (defun message-indent-citation ()
2648 "Modify text just inserted from a message to be cited.
2649 The inserted text should be the region.
2650 When this function returns, the region is again around the modified text.
2652 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2653 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2654 (let ((start (point)))
2655 ;; Remove unwanted headers.
2656 (when message-ignored-cited-headers
2661 (if (search-forward "\n\n" nil t)
2664 (message-remove-header message-ignored-cited-headers t)
2665 (when (= (point-min) (point-max))
2666 (setq all-removed t))
2667 (goto-char (point-max)))
2671 ;; Delete blank lines at the start of the buffer.
2672 (while (and (point-min)
2675 (message-delete-line))
2676 ;; Delete blank lines at the end of the buffer.
2677 (goto-char (point-max))
2680 (while (and (zerop (forward-line -1))
2682 (message-delete-line))
2683 ;; Do the indentation.
2684 (if (null message-yank-prefix)
2685 (indent-rigidly start (mark t) message-indentation-spaces)
2688 (while (< (point) (mark t))
2689 (if (or (looking-at ">") (looking-at "^$"))
2690 (insert message-yank-cited-prefix)
2691 (insert message-yank-prefix))
2695 (defun message-list-references (refs-list &rest refs-strs)
2696 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2698 (let (refs ref id saved-id)
2699 (when (and refs-list
2700 (integerp message-list-references-add-position))
2701 (let ((pos message-list-references-add-position))
2702 (while (and refs-list
2704 (push (pop refs-list) saved-id)
2705 (setq pos (1- pos)))))
2707 (when (setq refs (pop refs-strs))
2708 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2710 (when (eq (car (setq ref (pop refs))) 'msg-id)
2711 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2712 (or (member id refs-list)
2713 (member id saved-id)
2714 (push id refs-list))))))
2716 (push (pop saved-id) refs-list))
2719 (defvar gnus-article-copy)
2720 (defun message-yank-original (&optional arg)
2721 "Insert the message being replied to, if any.
2722 Puts point before the text and mark after.
2723 Normally indents each nonblank line ARG spaces (default 3). However,
2724 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2726 This function uses `message-cite-function' to do the actual citing.
2728 Just \\[universal-argument] as argument means don't indent, insert no
2729 prefix, and don't delete any headers.
2731 In addition, if `message-yank-add-new-references' is non-nil and this
2732 command is called interactively, new IDs from the yanked article will
2733 be added to \"References\" field.
2734 \(See also `message-yank-add-new-references'.)"
2736 (let ((modified (buffer-modified-p))
2737 (buffer (message-eval-parameter message-reply-buffer))
2740 message-cite-function)
2741 (delete-windows-on buffer t)
2742 (insert-buffer buffer) ; mark will be set at the end of article.
2746 ;; Add new IDs to References field.
2747 (when (and message-yank-add-new-references (interactive-p))
2750 (message-narrow-to-headers)
2751 (setq refs (message-list-references
2753 (message-fetch-field "References")))
2755 (narrow-to-region start end)
2756 (std11-narrow-to-header)
2757 (when (setq refs (message-list-references
2759 (unless (eq message-yank-add-new-references
2761 (or (message-fetch-field "References")
2762 (message-fetch-field "In-Reply-To")))
2763 (message-fetch-field "Message-ID")))
2765 (message-narrow-to-headers)
2766 (goto-char (point-min))
2767 (let ((case-fold-search t))
2768 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2770 (goto-char (point-max))))
2772 (list (or (assq 'References message-header-format-alist)
2773 '(References . message-fill-references)))
2774 (list (cons 'References
2775 (mapconcat 'identity (nreverse refs) " "))))
2776 (backward-delete-char 1)))))
2779 (if (and message-suspend-font-lock-when-citing
2780 (boundp 'font-lock-mode)
2781 (symbol-value 'font-lock-mode))
2786 (funcall message-cite-function))
2788 (funcall message-cite-function)))
2789 (message-exchange-point-and-mark)
2793 (setq message-checksum (message-checksum))))))
2795 (defun message-yank-buffer (buffer)
2796 "Insert BUFFER into the current buffer and quote it."
2797 (interactive "bYank buffer: ")
2798 (let ((message-reply-buffer buffer))
2799 (save-window-excursion
2800 (message-yank-original))))
2802 (defun message-buffers ()
2803 "Return a list of active message buffers."
2806 (dolist (buffer (buffer-list t))
2808 (when (and (eq major-mode 'message-mode)
2809 (null message-sent-message-via))
2810 (push (buffer-name buffer) buffers))))
2811 (nreverse buffers)))
2813 (defun message-cite-original-without-signature ()
2814 "Cite function in the standard Message manner."
2815 (let ((start (point))
2818 (when message-indent-citation-function
2819 (if (listp message-indent-citation-function)
2820 message-indent-citation-function
2821 (list message-indent-citation-function))))
2822 (message-reply-headers (or message-reply-headers
2823 (make-mail-header))))
2824 (mail-header-set-from message-reply-headers
2828 (if (search-forward "\n\n" nil t)
2831 (or (message-fetch-field "from")
2836 (when (re-search-backward message-signature-separator start t)
2837 ;; Also peel off any blank lines before the signature.
2839 (while (looking-at "^[ \t]*$")
2842 (delete-region (point) end)
2843 (unless (search-backward "\n\n" start t)
2844 ;; Insert a blank line if it is peeled off.
2848 (funcall (pop functions)))
2849 (when message-citation-line-function
2852 (funcall message-citation-line-function))))
2854 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2855 (defun message-cite-original ()
2856 "Cite function in the standard Message manner."
2857 (if (and (boundp 'mail-citation-hook)
2859 (run-hooks 'mail-citation-hook)
2860 (let ((start (point))
2863 (when message-indent-citation-function
2864 (if (listp message-indent-citation-function)
2865 message-indent-citation-function
2866 (list message-indent-citation-function))))
2867 (message-reply-headers (or message-reply-headers
2868 (make-mail-header))))
2869 (mail-header-set-from message-reply-headers
2873 (if (search-forward "\n\n" nil t)
2876 (or (message-fetch-field "from")
2880 (funcall (pop functions)))
2881 (when message-citation-line-function
2884 (funcall message-citation-line-function)))))
2886 (defun message-insert-citation-line ()
2887 "Insert a simple citation line."
2888 (when message-reply-headers
2889 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2891 (defun message-position-on-field (header &rest afters)
2892 (let ((case-fold-search t))
2895 (goto-char (point-min))
2898 (concat "^" (regexp-quote mail-header-separator) "$"))
2899 (match-beginning 0)))
2900 (goto-char (point-min))
2901 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2903 (re-search-forward "^[^ \t]" nil 'move)
2905 (skip-chars-backward "\n")
2908 (not (re-search-forward
2909 (concat "^" (regexp-quote (car afters)) ":")
2913 (re-search-forward "^[^ \t]" nil 'move)
2914 (beginning-of-line))
2915 (insert header ": \n")
2919 (defun message-remove-signature ()
2920 "Remove the signature from the text between point and mark.
2921 The text will also be indented the normal way."
2923 (let ((start (point))
2925 (if (not (re-search-forward message-signature-separator (mark t) t))
2926 ;; No signature here, so we just indent the cited text.
2927 (message-indent-citation)
2928 ;; Find the last non-empty line.
2930 (while (looking-at "[ \t]*$")
2933 (setq mark (set-marker (make-marker) (point)))
2935 (message-indent-citation)
2936 ;; Enable undoing the deletion.
2938 (delete-region mark (mark t))
2939 (set-marker mark nil)))))
2944 ;;; Sending messages
2947 ;; Avoid byte-compile warning.
2948 (defvar message-encoding-buffer nil)
2949 (defvar message-edit-buffer nil)
2950 (defvar message-mime-mode nil)
2952 (defun message-send-and-exit (&optional arg)
2953 "Send message like `message-send', then, if no errors, exit from mail buffer."
2955 (let ((buf (current-buffer))
2956 (actions message-exit-actions)
2957 (frame (selected-frame))
2958 (org-frame message-original-frame))
2959 (when (and (message-send arg)
2961 (if message-kill-buffer-on-exit
2964 (when (eq buf (current-buffer))
2965 (message-bury buf)))
2966 (message-do-actions actions)
2967 (message-delete-frame frame org-frame)
2970 (defun message-dont-send ()
2971 "Don't send the message you have been editing.
2972 Instead, just auto-save the buffer and then bury it."
2974 (set-buffer-modified-p t)
2976 (let ((actions message-postpone-actions)
2977 (frame (selected-frame))
2978 (org-frame message-original-frame))
2979 (message-bury (current-buffer))
2980 (message-do-actions actions)
2981 (message-delete-frame frame org-frame)))
2983 (defun message-kill-buffer ()
2984 "Kill the current buffer."
2986 (when (or (not (buffer-modified-p))
2987 (eq t message-kill-buffer-query-function)
2988 (funcall message-kill-buffer-query-function
2989 "The buffer modified; kill anyway? "))
2990 (let ((actions message-kill-actions)
2991 (draft-article message-draft-article)
2992 (auto-save-file-name buffer-auto-save-file-name)
2993 (file-name buffer-file-name)
2994 (modified (buffer-modified-p))
2995 (frame (selected-frame))
2996 (org-frame message-original-frame))
2997 (setq buffer-file-name nil)
2998 (kill-buffer (current-buffer))
2999 (when (and message-kill-buffer-and-remove-file
3000 (or (and auto-save-file-name
3001 (file-exists-p auto-save-file-name))
3003 (file-exists-p file-name)))
3004 (yes-or-no-p (format "Remove the backup file%s? "
3005 (if modified " too" ""))))
3007 (delete-file auto-save-file-name))
3008 (let ((message-draft-article draft-article))
3009 (message-disassociate-draft)))
3010 (message-do-actions actions)
3011 (message-delete-frame frame org-frame)))
3014 (defun message-mimic-kill-buffer ()
3015 "Kill the current buffer with query. This is an imitation for
3016 `kill-buffer', but it will delete a message frame."
3018 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
3020 message-kill-buffer-and-remove-file)
3021 (when (or (not bufname)
3022 (string-equal bufname "")
3023 (string-equal bufname (buffer-name)))
3024 (message-kill-buffer))))
3026 (defun message-delete-frame (frame org-frame)
3027 "Delete frame for editing message."
3028 (when (and (or (static-if (featurep 'xemacs)
3029 (device-on-window-system-p)
3031 (>= emacs-major-version 20))
3032 (or (and (eq message-delete-frame-on-exit t)
3033 (select-frame frame)
3034 (or (eq frame org-frame)
3036 (y-or-n-p "Delete this frame?")
3038 (and (eq message-delete-frame-on-exit 'ask)
3039 (select-frame frame)
3041 (y-or-n-p "Delete this frame?")
3043 (delete-frame frame)))
3045 (defun message-bury (buffer)
3046 "Bury this mail BUFFER."
3047 (let ((newbuf (other-buffer buffer)))
3048 (bury-buffer buffer)
3049 (if (and (fboundp 'frame-parameters)
3050 (cdr (assq 'dedicated (frame-parameters)))
3051 (not (null (delq (selected-frame) (visible-frame-list)))))
3052 (delete-frame (selected-frame))
3053 (switch-to-buffer newbuf))))
3055 (defun message-send (&optional arg)
3056 "Send the message in the current buffer.
3057 If `message-interactive' is non-nil, wait for success indication or
3058 error messages, and inform user.
3059 Otherwise any failure is reported in a message back to the user from
3061 The usage of ARG is defined by the instance that called Message.
3062 It should typically alter the sending method in some way or other."
3065 (when (or (buffer-modified-p)
3066 (message-check-element 'unchanged)
3067 (y-or-n-p "No changes in the buffer; really send? "))
3068 ;; Make it possible to undo the coming changes.
3070 (let ((inhibit-read-only t))
3071 (put-text-property (point-min) (point-max) 'read-only nil))
3072 (run-hooks 'message-send-hook)
3073 (message-fix-before-sending)
3074 (message message-sending-message)
3075 (let ((message-encoding-buffer
3076 (message-generate-new-buffer-clone-locals " message encoding"))
3077 (message-edit-buffer (current-buffer))
3078 (message-mime-mode mime-edit-mode-flag)
3079 (alist message-send-method-alist)
3081 elem sent dont-barf-on-no-method
3082 (message-options message-options))
3085 (message-options-set-recipient)
3087 (set-buffer message-encoding-buffer)
3089 ;; ;; Avoid copying text props (except hard newlines).
3090 ;; T-gnus change: copy all text props from the editing buffer
3091 ;; into the encoding buffer.
3092 (insert-buffer-substring message-edit-buffer)
3093 (funcall message-encode-function)
3095 (setq elem (pop alist)))
3096 (when (funcall (cadr elem))
3098 (or (not (memq (car elem)
3099 message-sent-message-via))
3100 (if (or (message-gnksa-enable-p 'multiple-copies)
3101 (not (eq (car elem) 'news)))
3104 "Already sent message via %s; resend? "
3106 (error "Denied posting -- multiple copies")))
3107 (setq success (funcall (caddr elem) arg)))
3113 (let ((fcc (message-fetch-field "Fcc"))
3114 (gcc (message-fetch-field "Gcc")))
3117 (eq message-allow-no-recipients 'always)
3118 (and (not (eq message-allow-no-recipients 'never))
3119 (setq dont-barf-on-no-method
3121 (format "No receiver, perform %s anyway? "
3122 (cond ((and fcc gcc) "Fcc and Gcc")
3125 (error "No methods specified to send by"))
3126 (when (or dont-barf-on-no-method
3130 (run-hooks 'message-sent-hook))
3131 (message "Sending...done")
3132 ;; Mark the buffer as unmodified and delete auto-save.
3133 (set-buffer-modified-p nil)
3134 (delete-auto-save-file-if-necessary t)
3135 (message-disassociate-draft)
3136 ;; Delete other mail buffers and stuff.
3137 (message-do-send-housekeeping)
3138 (message-do-actions message-send-actions)
3141 (kill-buffer message-encoding-buffer)))))
3143 (defun message-send-via-mail (arg)
3144 "Send the current message via mail."
3145 (message-send-mail arg))
3147 (defun message-send-via-news (arg)
3148 "Send the current message via news."
3149 (message-send-news arg))
3151 (defmacro message-check (type &rest forms)
3152 "Eval FORMS if TYPE is to be checked."
3153 `(or (message-check-element ,type)
3157 (put 'message-check 'lisp-indent-function 1)
3158 (put 'message-check 'edebug-form-spec '(form body))
3160 ;; Advise the function `invisible-region'.
3161 (let (current-load-list)
3163 `(defadvice invisible-region (around add-mime-edit-invisible (start end)
3165 "Advised by T-gnus Message.
3166 Add the text property `mime-edit-invisible' to an invisible text when
3167 the buffer's major mode is `message-mode'. The added property will be
3168 used to distinguish whether the invisible text is a MIME part or not."
3169 ,(if (featurep 'xemacs)
3170 '(if (eq ?\n (char-after start))
3171 (setq start (1+ start)))
3172 '(if (eq ?\n (char-after (1- end)))
3173 (setq end (1- end))))
3174 (setq ad-return-value
3175 (if (eq 'message-mode major-mode)
3176 (add-text-properties start end
3177 '(invisible t mime-edit-invisible t))
3178 (put-text-property start end 'invisible t))))))
3180 (defun message-text-with-property (prop)
3181 "Return a list of all points where the text has PROP."
3183 (point (point-min)))
3185 (while (< point (point-max))
3186 (when (get-text-property point prop)
3187 (push point points))
3191 (defun message-fix-before-sending ()
3192 "Do various things to make the message nice before sending it."
3193 ;; Make sure there's a newline at the end of the message.
3195 (goto-char (point-max))
3198 ;; Delete all invisible text except for the mime parts which might
3199 ;; be inserted by the MIME-Edit.
3200 (message-check 'invisible-text
3203 mime-from mime-to hidden-start)
3204 (while (setq from (text-property-any to (point-max) 'invisible t))
3205 (setq to (or (text-property-not-all from (point-max) 'invisible t)
3208 (while (setq mime-from (text-property-any mime-to to
3209 'mime-edit-invisible t))
3210 (when (> mime-from mime-to)
3211 (setq hidden-start (or hidden-start mime-to))
3212 (put-text-property mime-to mime-from 'invisible nil))
3213 (setq mime-to (or (text-property-not-all mime-from to
3214 'mime-edit-invisible t)
3216 (when (< mime-to to)
3217 (setq hidden-start (or hidden-start mime-to))
3218 (put-text-property mime-to to 'invisible nil)))
3220 (goto-char hidden-start)
3221 (set-window-start (selected-window) (gnus-point-at-bol))
3222 (unless (yes-or-no-p
3223 "Invisible text found and made visible; continue posting? ")
3224 (error "Invisible text found and made visible")))))
3225 (message-check 'illegible-text
3226 (let ((mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f\x1b")
3229 (skip-chars-forward mm-7bit-chars)
3231 (when (let ((char (char-after)))
3232 (or (< (mm-char-int char) 128)
3233 (and (mm-multibyte-p)
3234 (memq (char-charset char)
3235 '(eight-bit-control eight-bit-graphic
3237 (add-text-properties (point) (1+ (point)) '(highlight t))
3240 (skip-chars-forward mm-7bit-chars))
3243 (gnus-multiple-choice
3244 "Illegible text found. Continue posting? "
3245 '((?d "Remove and continue posting")
3246 (?r "Replace with dots and continue posting")
3247 (?i "Ignore and continue posting")
3248 (?e "Continue editing"))))
3250 (error "Illegible text found"))
3252 (skip-chars-forward mm-7bit-chars)
3254 (when (let ((char (char-after)))
3255 (or (< (mm-char-int char) 128)
3256 (and (mm-multibyte-p)
3257 (memq (char-charset char)
3258 '(eight-bit-control eight-bit-graphic
3261 (remove-text-properties (point) (1+ (point)) '(highlight t))
3266 (skip-chars-forward mm-7bit-chars))))))
3268 (defun message-add-action (action &rest types)
3269 "Add ACTION to be performed when doing an exit of type TYPES."
3271 (add-to-list (intern (format "message-%s-actions" (pop types)))
3274 (defun message-delete-action (action &rest types)
3275 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3278 (set (setq var (intern (format "message-%s-actions" (pop types))))
3279 (delq action (symbol-value var))))))
3281 (defun message-do-actions (actions)
3282 "Perform all actions in ACTIONS."
3283 ;; Now perform actions on successful sending.
3287 ;; A simple function.
3288 ((message-functionp (car actions))
3289 (funcall (car actions)))
3290 ;; Something to be evaled.
3292 (eval (car actions)))))
3295 (defsubst message-maybe-split-and-send-mail ()
3296 "Split a message if necessary, and send it via mail.
3297 Returns nil if sending succeeded, returns any string if sending failed.
3298 This sub function is for exclusive use of `message-send-mail'."
3299 (let ((mime-edit-split-ignored-field-regexp
3300 mime-edit-split-ignored-field-regexp)
3301 (case-fold-search t)
3303 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3304 (setq mime-edit-split-ignored-field-regexp
3305 (concat (substring mime-edit-split-ignored-field-regexp
3306 0 (match-beginning 0))
3307 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3308 "_so_don't_rape_it!"
3309 (substring mime-edit-split-ignored-field-regexp
3313 (catch 'message-sending-mail-failure
3314 (mime-edit-maybe-split-and-send
3319 (std11-narrow-to-header mail-header-separator)
3320 (goto-char (point-min))
3321 (when (re-search-forward "^Message-ID:" nil t)
3322 (delete-region (match-end 0) (std11-field-end))
3323 (insert " " (message-make-message-id))))
3325 (funcall (or message-send-mail-real-function
3326 message-send-mail-function))
3328 (throw 'message-sending-mail-failure err))))))
3332 (funcall (or message-send-mail-real-function
3333 message-send-mail-function))
3337 (if (eq 'error (car failure))
3339 (prin1-to-string failure)))))
3341 (defun message-send-mail-partially ()
3342 "Send mail as message/partial."
3343 ;; replace the header delimiter with a blank line
3344 (goto-char (point-min))
3346 (concat "^" (regexp-quote mail-header-separator) "\n"))
3347 (replace-match "\n")
3348 (run-hooks 'message-send-mail-hook)
3349 (let ((p (goto-char (point-min)))
3350 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3351 (curbuf (current-buffer))
3352 (id (message-make-message-id)) (n 1)
3353 plist total header required-mail-headers)
3355 (if (< (point-max) (+ p message-send-mail-partially-limit))
3356 (goto-char (point-max))
3357 (goto-char (+ p message-send-mail-partially-limit))
3359 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3362 (setq total (length plist))
3363 (push (point-max) plist)
3364 (setq plist (nreverse plist))
3367 (setq p (pop plist))
3370 (copy-to-buffer tembuf p (car plist))
3372 (goto-char (point-min))
3375 (goto-char (point-min))
3376 (narrow-to-region (point) (point))
3379 (setq header (buffer-substring (point-min) (point)))
3380 (goto-char (point-min))
3381 (narrow-to-region (point) (point))
3383 (message-remove-header "Mime-Version")
3384 (message-remove-header "Content-Type")
3385 (message-remove-header "Content-Transfer-Encoding")
3386 (message-remove-header "Message-ID")
3387 (message-remove-header "Lines")
3388 (goto-char (point-max))
3389 (insert "Mime-Version: 1.0\n")
3390 (setq header (buffer-substring (point-min) (point-max))))
3391 (goto-char (point-max))
3392 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3395 (let ((mail-header-separator ""))
3396 (when (memq 'Message-ID message-required-mail-headers)
3397 (insert "Message-ID: " (message-make-message-id) "\n"))
3398 (when (memq 'Lines message-required-mail-headers)
3399 (insert "Lines: " (message-make-lines) "\n"))
3400 (message-goto-subject)
3402 (insert (format " (%d/%d)" n total))
3404 (mm-with-unibyte-current-buffer
3405 (funcall (or message-send-mail-real-function
3406 message-send-mail-function))))
3408 (setq p (pop plist))
3410 (kill-buffer tembuf))))
3412 (defun message-send-mail (&optional arg)
3413 (require 'mail-utils)
3414 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3415 (case-fold-search nil)
3416 (news (message-news-p))
3417 (message-this-is-mail t)
3418 (headers message-required-mail-headers)
3421 (message-narrow-to-headers)
3422 ;; Generate the Mail-Followup-To header if the header is not there...
3423 (if (and (or message-subscribed-regexps
3424 message-subscribed-addresses
3425 message-subscribed-address-file
3426 message-subscribed-address-functions)
3427 (not (mail-fetch-field "mail-followup-to")))
3430 (cons "Mail-Followup-To" (message-make-mft))
3431 message-required-mail-headers))
3432 ;; otherwise, delete the MFT header if the field is empty
3433 (when (equal "" (mail-fetch-field "mail-followup-to"))
3434 (message-remove-header "^Mail-Followup-To:")))
3435 ;; Insert some headers.
3436 (let ((message-deletable-headers
3437 (if news nil message-deletable-headers)))
3438 (message-generate-headers headers))
3439 ;; Let the user do all of the above.
3440 (run-hooks 'message-header-hook))
3441 (if (not (message-check-mail-syntax))
3449 ;; ;; Avoid copying text props (except hard newlines).
3450 ;; T-gnus change: copy all text props from the editing buffer
3451 ;; into the encoding buffer.
3452 (insert-buffer-substring message-encoding-buffer)
3453 ;; Remove some headers.
3455 (message-narrow-to-headers)
3456 ;; We Semi-gnus people have no use for it.
3457 ;; ;; We (re)generate the Lines header.
3458 ;; (when (memq 'Lines message-required-mail-headers)
3459 ;; (message-generate-headers '(Lines)))
3460 (message-remove-header message-ignored-mail-headers t))
3461 (goto-char (point-max))
3462 ;; require one newline at the end.
3463 (or (= (preceding-char) ?\n)
3467 (message-narrow-to-headers)
3469 (or (message-fetch-field "cc")
3470 (message-fetch-field "to"))
3471 (let ((ct (mime-read-Content-Type)))
3473 (and (eq 'text (cdr (assq 'type ct)))
3474 (eq 'plain (cdr (assq 'subtype ct))))))))
3475 (message-insert-courtesy-copy))
3476 (setq failure (message-maybe-split-and-send-mail)))
3477 (kill-buffer tembuf))
3478 (set-buffer message-edit-buffer)
3481 (message "Couldn't send message via mail: %s" failure)
3483 (push 'mail message-sent-message-via)))))
3485 (defun message-send-mail-with-sendmail ()
3486 "Send off the prepared buffer with sendmail."
3487 (let ((errbuf (if message-interactive
3488 (message-generate-new-buffer-clone-locals
3491 resend-to-addresses delimline)
3494 (let ((case-fold-search t))
3496 (message-narrow-to-headers)
3497 (setq resend-to-addresses (message-fetch-field "resent-to")))
3498 ;; Change header-delimiter to be what sendmail expects.
3499 (goto-char (point-min))
3501 (concat "^" (regexp-quote mail-header-separator) "\n"))
3502 (replace-match "\n")
3504 (setq delimline (point-marker))
3505 (run-hooks 'message-send-mail-hook)
3506 ;; Insert an extra newline if we need it to work around
3507 ;; Sun's bug that swallows newlines.
3508 (goto-char (1+ delimline))
3509 (when (eval message-mailer-swallows-blank-line)
3511 (when message-interactive
3515 (let* ((default-directory "/")
3516 (cpr (as-binary-process
3518 'call-process-region
3520 (list (point-min) (point-max)
3521 (if (boundp 'sendmail-program)
3523 "/usr/lib/sendmail")
3524 nil errbuf nil "-oi")
3525 ;; Always specify who from,
3526 ;; since some systems have broken sendmails.
3527 ;; But some systems are more broken with -f, so
3528 ;; we'll let users override this.
3529 (if (null message-sendmail-f-is-evil)
3530 (list "-f" (message-make-address)))
3531 ;; These mean "report errors by mail"
3532 ;; and "deliver in background".
3533 (if (null message-interactive) '("-oem" "-odb"))
3534 ;; Get the addresses from the message
3535 ;; unless this is a resend.
3536 ;; We must not do that for a resend
3537 ;; because we would find the original addresses.
3538 ;; For a resend, include the specific addresses.
3539 (if resend-to-addresses
3540 (list resend-to-addresses)
3542 (unless (or (null cpr) (zerop cpr))
3543 (error "Sending...failed with exit value %d" cpr)))
3544 (when message-interactive
3547 (goto-char (point-min))
3548 (while (re-search-forward "\n\n* *" nil t)
3549 (replace-match "; "))
3550 (if (not (zerop (buffer-size)))
3551 (error "Sending...failed to %s"
3552 (buffer-substring (point-min) (point-max)))))))
3553 (when (bufferp errbuf)
3554 (kill-buffer errbuf)))))
3556 (defun message-send-mail-with-qmail ()
3557 "Pass the prepared message buffer to qmail-inject.
3558 Refer to the documentation for the variable `message-send-mail-function'
3559 to find out how to use this."
3560 ;; replace the header delimiter with a blank line
3561 (goto-char (point-min))
3563 (concat "^" (regexp-quote mail-header-separator) "\n"))
3564 (replace-match "\n")
3566 (run-hooks 'message-send-mail-hook)
3571 'call-process-region 1 (point-max) message-qmail-inject-program
3573 ;; qmail-inject's default behaviour is to look for addresses on the
3574 ;; command line; if there're none, it scans the headers.
3575 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3577 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3578 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3579 ;; message from stdin.
3581 ;; qmail also has the advantage of not having been raped by
3582 ;; various vendors, so we don't have to allow for that, either --
3583 ;; compare this with message-send-mail-with-sendmail and weep
3584 ;; for sendmail's lost innocence.
3586 ;; all this is way cool coz it lets us keep the arguments entirely
3587 ;; free for -inject-arguments -- a big win for the user and for us
3588 ;; since we don't have to play that double-guessing game and the user
3589 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3590 (if (functionp message-qmail-inject-args)
3591 (funcall message-qmail-inject-args)
3592 message-qmail-inject-args)))
3593 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3594 ;; we have to look at the retval instead
3596 (100 (error "qmail-inject reported permanent failure"))
3597 (111 (error "qmail-inject reported transient failure"))
3598 ;; should never happen
3599 (t (error "qmail-inject reported unknown failure"))))
3601 (defun message-send-mail-with-mh ()
3602 "Send the prepared message buffer with mh."
3603 (let ((mh-previous-window-config nil)
3604 (name (mh-new-draft-name)))
3605 (setq buffer-file-name name)
3606 ;; MH wants to generate these headers itself.
3607 (when message-mh-deletable-headers
3608 (let ((headers message-mh-deletable-headers))
3610 (goto-char (point-min))
3611 (and (re-search-forward
3612 (concat "^" (symbol-name (car headers)) ": *") nil t)
3613 (message-delete-line))
3615 (run-hooks 'message-send-mail-hook)
3616 ;; Pass it on to mh.
3619 (defun message-send-mail-with-smtp ()
3620 "Send off the prepared buffer with SMTP."
3621 (require 'smtp) ; XXX
3622 (let ((case-fold-search t)
3625 (message-narrow-to-headers)
3627 ;; XXX: Should be replaced by better one.
3628 (smtp-deduce-address-list (current-buffer)
3629 (point-min) (point-max)))
3630 ;; Remove BCC lines.
3631 (message-remove-header "bcc"))
3632 ;; replace the header delimiter with a blank line.
3633 (goto-char (point-min))
3635 (concat "^" (regexp-quote mail-header-separator) "\n"))
3636 (replace-match "\n")
3638 (run-hooks 'message-send-mail-hook)
3640 (static-if (fboundp 'smtp-send-buffer)
3641 (smtp-send-buffer user-mail-address recipients
3643 (let ((result (smtp-via-smtp user-mail-address recipients
3645 (unless (eq result t)
3646 (error "Sending failed; %s" result))))
3647 (error "Sending failed; no recipients"))))
3649 (defsubst message-maybe-split-and-send-news (method)
3650 "Split a message if necessary, and send it via news.
3651 Returns nil if sending succeeded, returns t if sending failed.
3652 This sub function is for exclusive use of `message-send-news'."
3653 (let ((mime-edit-split-ignored-field-regexp
3654 mime-edit-split-ignored-field-regexp)
3655 (case-fold-search t))
3656 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3657 (setq mime-edit-split-ignored-field-regexp
3658 (concat (substring mime-edit-split-ignored-field-regexp
3659 0 (match-beginning 0))
3660 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3661 "_so_don't_rape_it!"
3662 (substring mime-edit-split-ignored-field-regexp
3665 (catch 'message-sending-news-failure
3666 (mime-edit-maybe-split-and-send
3671 (std11-narrow-to-header mail-header-separator)
3672 (goto-char (point-min))
3673 (when (re-search-forward "^Message-ID:" nil t)
3674 (delete-region (match-end 0) (std11-field-end))
3675 (insert " " (message-make-message-id))))
3676 (unless (funcall message-send-news-function method)
3677 (throw 'message-sending-news-failure t)))))
3679 (not (funcall message-send-news-function method)))))
3681 (defun message-canlock-generate ()
3682 "Return a string that is non-trival to guess.
3683 Do not use this for anything important, it is cryptographically weak."
3684 (sha1 (concat (message-unique-id)
3685 (format "%x%x%x" (random) (random t) (random))
3686 (prin1-to-string (recent-keys))
3687 (prin1-to-string (garbage-collect)))))
3689 (defun message-canlock-password ()
3690 "The password used by message for cancel locks.
3691 This is the value of `canlock-password', if that option is non-nil.
3692 Otherwise, generate and save a value for `canlock-password' first."
3693 (unless canlock-password
3694 (customize-save-variable 'canlock-password (message-canlock-generate))
3695 (setq canlock-password-for-verify canlock-password))
3698 (defun message-insert-canlock ()
3699 (when message-insert-canlock
3700 (message-canlock-password)
3701 (canlock-insert-header)))
3703 (defun message-send-news (&optional arg)
3704 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3705 (case-fold-search nil)
3706 (method (if (message-functionp message-post-method)
3707 (funcall message-post-method arg)
3708 message-post-method))
3709 (newsgroups-field (save-restriction
3710 (message-narrow-to-headers-or-head)
3711 (message-fetch-field "Newsgroups")))
3712 (followup-field (save-restriction
3713 (message-narrow-to-headers-or-head)
3714 (message-fetch-field "Followup-To")))
3715 ;; BUG: We really need to get the charset for each name in the
3716 ;; Newsgroups and Followup-To lines to allow crossposting
3717 ;; between group namess with incompatible character sets.
3718 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3719 (group-field-charset
3720 (gnus-group-name-charset method newsgroups-field))
3721 (followup-field-charset
3722 (gnus-group-name-charset method (or followup-field "")))
3723 (mime-field-encoding-method-alist
3724 (append (when group-field-charset
3725 (list (cons "Newsgroups" group-field-charset)))
3726 (when followup-field-charset
3727 (list (cons "Followup-To" followup-field-charset)))
3728 mime-field-encoding-method-alist))
3729 (message-syntax-checks
3731 (listp message-syntax-checks))
3732 (cons '(existing-newsgroups . disabled)
3733 message-syntax-checks)
3734 message-syntax-checks))
3735 (message-this-is-news t)
3738 (message-narrow-to-headers)
3739 ;; Insert some headers.
3740 (message-generate-headers message-required-news-headers)
3741 (message-insert-canlock)
3742 ;; Let the user do all of the above.
3743 (run-hooks 'message-header-hook))
3744 ;; Note: This check will be disabled by the ".*" default value for
3745 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
3746 (when (and group-field-charset
3747 (listp message-syntax-checks))
3748 (setq message-syntax-checks
3749 (cons '(valid-newsgroups . disabled)
3750 message-syntax-checks)))
3751 (message-cleanup-headers)
3752 (if (not (let ((message-post-method method))
3753 (message-check-news-syntax)))
3758 (buffer-disable-undo)
3760 (insert-buffer-substring message-encoding-buffer)
3761 ;; Remove some headers.
3763 (message-narrow-to-headers)
3764 ;; We Semi-gnus people have no use for it.
3765 ;; ;; We (re)generate the Lines header.
3766 ;; (when (memq 'Lines message-required-mail-headers)
3767 ;; (message-generate-headers '(Lines)))
3768 ;; Remove some headers.
3769 (message-remove-header message-ignored-news-headers t))
3770 (goto-char (point-max))
3771 ;; require one newline at the end.
3772 (or (= (preceding-char) ?\n)
3774 (setq result (message-maybe-split-and-send-news method)))
3775 (kill-buffer tembuf))
3776 (set-buffer message-edit-buffer)
3779 (message "Couldn't send message via news: %s"
3780 (nnheader-get-report (car method)))
3782 (push 'news message-sent-message-via)))))
3784 ;; 1997-09-29 by MORIOKA Tomohiko
3785 (defun message-send-news-with-gnus (method)
3786 (let ((case-fold-search t))
3787 ;; Remove the delimiter.
3788 (goto-char (point-min))
3790 (concat "^" (regexp-quote mail-header-separator) "\n"))
3791 (replace-match "\n")
3793 (run-hooks 'message-send-news-hook)
3794 (gnus-open-server method)
3795 (message "Sending news via %s..." (gnus-server-string method))
3796 (gnus-request-post method)
3800 ;;; Header generation & syntax checking.
3803 (defun message-check-element (type)
3804 "Return non-nil if this TYPE is not to be checked."
3805 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3807 (let ((able (assq type message-syntax-checks)))
3809 (eq (cdr able) 'disabled)))))
3811 (defun message-check-news-syntax ()
3812 "Check the syntax of the message."
3817 ;; We narrow to the headers and check them first.
3820 (message-narrow-to-headers)
3821 (message-check-news-header-syntax)))
3824 (set-buffer message-edit-buffer)
3825 (message-check-news-body-syntax))))))
3827 (defun message-check-news-header-syntax ()
3829 ;; Check Newsgroups header.
3830 (message-check 'newsgroups
3831 (let ((group (message-fetch-field "newsgroups")))
3834 (not (string-match "\\`[ \t]*\\'" group)))
3837 "The newsgroups field is empty or missing. Posting is denied.")))))
3838 ;; Check the Subject header.
3839 (message-check 'subject
3840 (let* ((case-fold-search t)
3841 (subject (message-fetch-field "subject")))
3844 (not (string-match "\\`[ \t]*\\'" subject)))
3847 "The subject field is empty or missing. Posting is denied.")))))
3848 ;; Check for commands in Subject.
3849 (message-check 'subject-cmsg
3850 (if (string-match "^cmsg " (message-fetch-field "subject"))
3852 "The control code \"cmsg\" is in the subject. Really post? ")
3854 ;; Check for multiple identical headers.
3855 (message-check 'multiple-headers
3857 (while (and (not found)
3858 (re-search-forward "^[^ \t:]+: " nil t))
3860 (or (re-search-forward
3865 (match-beginning 0) (- (match-end 0) 2))))
3870 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3872 ;; Check for Version and Sendsys.
3873 (message-check 'sendsys
3874 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3876 (format "The article contains a %s command. Really post? "
3877 (buffer-substring (match-beginning 0)
3878 (1- (match-end 0)))))
3880 ;; See whether we can shorten Followup-To.
3881 (message-check 'shorten-followup-to
3882 (let ((newsgroups (message-fetch-field "newsgroups"))
3883 (followup-to (message-fetch-field "followup-to"))
3885 (when (and newsgroups
3886 (string-match "," newsgroups)
3891 (setq to (completing-read
3892 "Followups to (default: no Followup-To header) "
3893 (mapcar (lambda (g) (list g))
3895 (message-tokenize-header
3897 (goto-char (point-min))
3898 (insert "Followup-To: " to "\n"))
3900 ;; Check "Shoot me".
3901 (message-check 'shoot
3902 (if (re-search-forward
3903 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3904 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3906 ;; Check for Approved.
3907 (message-check 'approved
3908 (if (re-search-forward "^Approved:" nil t)
3909 (y-or-n-p "The article contains an Approved header. Really post? ")
3911 ;; Check the Message-ID header.
3912 (message-check 'message-id
3913 (let* ((case-fold-search t)
3914 (message-id (message-fetch-field "message-id" t)))
3915 (or (not message-id)
3916 ;; Is there an @ in the ID?
3917 (and (string-match "@" message-id)
3918 ;; Is there a dot in the ID?
3919 (string-match "@[^.]*\\." message-id)
3920 ;; Does the ID end with a dot?
3921 (not (string-match "\\.>" message-id)))
3923 (format "The Message-ID looks strange: \"%s\". Really post? "
3925 ;; Check the Newsgroups & Followup-To headers.
3926 (message-check 'existing-newsgroups
3927 (let* ((case-fold-search t)
3928 (newsgroups (message-fetch-field "newsgroups"))
3929 (followup-to (message-fetch-field "followup-to"))
3930 (groups (message-tokenize-header
3932 (concat newsgroups "," followup-to)
3934 (post-method (if (message-functionp message-post-method)
3935 (funcall message-post-method)
3936 message-post-method))
3937 ;; KLUDGE to handle nnvirtual groups. Doing this right
3938 ;; would probably involve a new nnoo function.
3939 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
3940 (method (if (and (consp post-method)
3941 (eq (car post-method) 'nnvirtual)
3942 gnus-message-group-art)
3943 (let ((group (car (nnvirtual-find-group-art
3944 (car gnus-message-group-art)
3945 (cdr gnus-message-group-art)))))
3946 (gnus-find-method-for-group group))
3950 (gnus-group-name-decode
3951 (gnus-group-real-name n)
3952 (gnus-group-name-charset method n)))
3953 (gnus-groups-from-server method)))
3956 (unless (or (equal (car groups) "poster")
3957 (member (car groups) known-groups))
3958 (push (car groups) errors))
3961 ;; Gnus is not running.
3962 ((or (not (and (boundp 'gnus-active-hashtb)
3963 gnus-active-hashtb))
3964 (not (boundp 'gnus-read-active-file)))
3966 ;; We don't have all the group names.
3967 ((and (or (not gnus-read-active-file)
3968 (eq gnus-read-active-file 'some))
3972 "Really post to %s possibly unknown group%s: %s? "
3973 (if (= (length errors) 1) "this" "these")
3974 (if (= (length errors) 1) "" "s")
3975 (mapconcat 'identity errors ", "))))
3976 ;; There were no errors.
3979 ;; There are unknown groups.
3983 "Really post to %s unknown group%s: %s? "
3984 (if (= (length errors) 1) "this" "these")
3985 (if (= (length errors) 1) "" "s")
3986 (mapconcat 'identity errors ", ")))))))
3987 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3988 (message-check 'valid-newsgroups
3989 (let ((case-fold-search t)
3990 (headers '("Newsgroups" "Followup-To"))
3992 (while (and headers (not error))
3993 (when (setq header (mail-fetch-field (car headers)))
3997 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4002 (not (string-match "\\.\\'\\|\\.\\." g)))
4003 (message-tokenize-header header ","))))
4010 (format "The %s header looks odd: \"%s\". Really post? "
4011 (car headers) header)))))
4012 (message-check 'repeated-newsgroups
4013 (let ((case-fold-search t)
4014 (headers '("Newsgroups" "Followup-To"))
4015 header error groups group)
4018 (when (setq header (mail-fetch-field (pop headers)))
4019 (setq groups (message-tokenize-header header ","))
4020 (while (setq group (pop groups))
4021 (when (member group groups)
4027 (format "Group %s is repeated in headers. Really post? " error)))))
4028 ;; Check the From header.
4029 (message-check 'from
4030 (let* ((case-fold-search t)
4031 (from (message-fetch-field "from"))
4035 (message "There is no From line. Posting is denied.")
4037 ((or (not (string-match
4039 (setq ad (nth 1 (mail-extract-address-components
4040 from))))) ;larsi@ifi
4041 (string-match "\\.\\." ad) ;larsi@ifi..uio
4042 (string-match "@\\." ad) ;larsi@.ifi.uio
4043 (string-match "\\.$" ad) ;larsi@ifi.uio.
4044 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4045 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4047 "Denied posting -- the From looks strange: \"%s\"." from)
4049 ((let ((addresses (rfc822-addresses from)))
4050 (while (and addresses
4051 (not (eq (string-to-char (car addresses)) ?\()))
4052 (setq addresses (cdr addresses)))
4055 "Denied posting -- bad From address: \"%s\"." from)
4058 ;; Check the Reply-To header.
4059 (message-check 'reply-to
4060 (let* ((case-fold-search t)
4061 (reply-to (message-fetch-field "reply-to"))
4066 ((string-match "," reply-to)
4068 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4070 ((or (not (string-match
4072 (setq ad (nth 1 (mail-extract-address-components
4073 reply-to))))) ;larsi@ifi
4074 (string-match "\\.\\." ad) ;larsi@ifi..uio
4075 (string-match "@\\." ad) ;larsi@.ifi.uio
4076 (string-match "\\.$" ad) ;larsi@ifi.uio.
4077 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4078 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4081 "The Reply-To looks strange: \"%s\". Really post? "
4085 (defun message-check-news-body-syntax ()
4087 ;; Check for long lines.
4088 (message-check 'long-lines
4089 (goto-char (point-min))
4091 (concat "^" (regexp-quote mail-header-separator) "$"))
4095 mime-edit-tag-regexp)
4098 (< (- (point) p) 80)))
4099 (zerop (forward-line 1))))
4103 "You have lines longer than 79 characters. Really post? ")))
4104 ;; Check whether the article is empty.
4105 (message-check 'empty
4106 (goto-char (point-min))
4108 (concat "^" (regexp-quote mail-header-separator) "$"))
4111 (goto-char (point-max))
4112 (re-search-backward message-signature-separator nil t)
4114 (or (re-search-backward "[^ \n\t]" b t)
4115 (if (message-gnksa-enable-p 'empty-article)
4116 (y-or-n-p "Empty article. Really post? ")
4117 (message "Denied posting -- Empty article.")
4119 ;; Check for control characters.
4120 (message-check 'control-chars
4121 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4123 "The article contains control characters. Really post? ")
4125 ;; Check 8bit characters.
4126 (message-check '8bit
4127 (message-check-8bit))
4128 ;; Check excessive size.
4129 (message-check 'size
4130 (if (> (buffer-size) 60000)
4132 (format "The article is %d octets long. Really post? "
4135 ;; Check whether any new text has been added.
4136 (message-check 'new-text
4138 (not message-checksum)
4139 (not (eq (message-checksum) message-checksum))
4140 (if (message-gnksa-enable-p 'quoted-text-only)
4142 "It looks like no new text has been added. Really post? ")
4143 (message "Denied posting -- no new text has been added.")
4145 ;; Check the length of the signature.
4146 (message-check 'signature
4147 (goto-char (point-max))
4148 (if (> (count-lines (point) (point-max)) 5)
4151 "Your .sig is %d lines; it should be max 4. Really post? "
4152 (1- (count-lines (point) (point-max)))))
4154 ;; Ensure that text follows last quoted portion.
4155 (message-check 'quoting-style
4156 (goto-char (point-max))
4157 (let ((no-problem t))
4158 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4159 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4162 (if (message-gnksa-enable-p 'quoted-text-only)
4163 (y-or-n-p "Your text should follow quoted text. Really post? ")
4165 (goto-char (point-min))
4167 (concat "^" (regexp-quote mail-header-separator) "$"))
4168 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4169 (y-or-n-p "Your text should follow quoted text. Really post? ")
4170 (message "Denied posting -- only quoted text.")
4173 (defun message-check-mail-syntax ()
4174 "Check the syntax of the message."
4179 ;; We narrow to the headers and check them first.
4182 (message-narrow-to-headers)
4183 (message-check-mail-header-syntax)))
4186 (set-buffer message-edit-buffer)
4187 (message-check-mail-body-syntax))))))
4189 (defun message-check-mail-header-syntax ()
4192 (defun message-check-mail-body-syntax ()
4194 ;; Check 8bit characters.
4195 (message-check '8bit
4196 (message-check-8bit)
4199 (defun message-check-8bit ()
4200 "Check the article contains 8bit characters."
4202 (set-buffer message-encoding-buffer)
4203 (message-narrow-to-headers)
4204 (let* ((case-fold-search t)
4205 (field-value (message-fetch-field "content-transfer-encoding")))
4206 (if (and field-value
4207 (member (downcase field-value) message-8bit-encoding-list))
4210 (set-buffer (get-buffer-create " message syntax"))
4212 (goto-char (point-min))
4213 (set-buffer-multibyte nil)
4214 (insert-buffer-substring message-encoding-buffer)
4215 (goto-char (point-min))
4216 (if (re-search-forward "[^\x00-\x7f]" nil t)
4218 "The article contains 8bit characters. Really post? ")
4221 (defun message-checksum ()
4222 "Return a \"checksum\" for the current buffer."
4225 (goto-char (point-min))
4227 (concat "^" (regexp-quote mail-header-separator) "$"))
4229 (when (not (looking-at "[ \t\n]"))
4230 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4235 (defun message-do-fcc ()
4236 "Process Fcc headers in the current buffer."
4237 (let ((case-fold-search t)
4238 (coding-system-for-write 'raw-text)
4239 (output-coding-system 'raw-text)
4241 (mml-externalize-attachments message-fcc-externalize-attachments))
4244 (message-narrow-to-headers)
4245 (setq file (message-fetch-field "fcc" t)))
4247 (set-buffer (get-buffer-create " *message temp*"))
4249 (insert-buffer-substring message-encoding-buffer)
4251 (message-narrow-to-headers)
4252 (while (setq file (message-fetch-field "fcc"))
4254 (message-remove-header "fcc" nil t)))
4255 (goto-char (point-min))
4256 (when (re-search-forward
4257 (concat "^" (regexp-quote mail-header-separator) "$")
4259 (replace-match "" t t))
4260 ;; Process FCC operations.
4262 (setq file (pop list))
4263 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4264 ;; Pipe the article to the program in question.
4265 (call-process-region (point-min) (point-max) shell-file-name
4266 nil nil nil shell-command-switch
4267 (match-string 1 file))
4268 ;; Save the article.
4269 (setq file (expand-file-name file))
4270 (unless (file-exists-p (file-name-directory file))
4271 (make-directory (file-name-directory file) t))
4272 (if (and message-fcc-handler-function
4273 (not (eq message-fcc-handler-function 'rmail-output)))
4274 (funcall message-fcc-handler-function file)
4275 (if (and (file-readable-p file) (mail-file-babyl-p file))
4276 (rmail-output file 1 nil t)
4277 (let ((mail-use-rfc822 t))
4278 (rmail-output file 1 t t))))))
4279 (kill-buffer (current-buffer))))))
4281 (defun message-output (filename)
4282 "Append this article to Unix/babyl mail file FILENAME."
4283 (if (and (file-readable-p filename)
4284 (mail-file-babyl-p filename))
4285 (gnus-output-to-rmail filename t)
4286 (gnus-output-to-mail filename t)))
4288 (defun message-cleanup-headers ()
4289 "Do various automatic cleanups of the headers."
4290 ;; Remove empty lines in the header.
4292 (message-narrow-to-headers)
4293 ;; Remove blank lines.
4294 (while (re-search-forward "^[ \t]*\n" nil t)
4295 (replace-match "" t t))
4297 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4298 ;; spaces to comma and eliminate spaces around commas. Eliminate
4299 ;; embedded line breaks.
4300 (goto-char (point-min))
4301 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4305 (if (re-search-forward "^[^ \t]" nil t)
4309 (goto-char (point-min))
4310 (while (re-search-forward "\n[ \t]+" nil t)
4311 (replace-match " " t t)) ;No line breaks (too confusing)
4312 (goto-char (point-min))
4313 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4314 (replace-match "," t t))
4315 (goto-char (point-min))
4316 ;; Remove trailing commas.
4317 (when (re-search-forward ",+$" nil t)
4318 (replace-match "" t t))))))
4320 (defun message-make-date (&optional now)
4321 "Make a valid data header.
4322 If NOW, use that time instead."
4323 (let* ((now (or now (current-time)))
4324 (zone (nth 8 (decode-time now)))
4328 (setq zone (- zone)))
4330 ;; The day name of the %a spec is locale-specific. Pfff.
4331 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4332 parse-time-weekdays))))
4333 (format-time-string "%d" now)
4334 ;; The month name of the %b spec is locale-specific. Pfff.
4336 (capitalize (car (rassoc (nth 4 (decode-time now))
4337 parse-time-months))))
4338 (format-time-string "%Y %H:%M:%S " now)
4339 ;; We do all of this because XEmacs doesn't have the %z spec.
4340 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4342 (defun message-make-followup-subject (subject)
4343 "Make a followup Subject."
4345 ((and (eq message-use-subject-re 'guess)
4346 (string-match message-subject-encoded-re-regexp subject))
4348 (message-use-subject-re
4349 (concat "Re: " (message-strip-subject-re subject)))
4352 (defun message-make-message-id ()
4353 "Make a unique Message-ID."
4354 (concat "<" (message-unique-id)
4355 (let ((psubject (save-excursion (message-fetch-field "subject")))
4357 (save-excursion (message-fetch-field "supersedes"))))
4359 (and message-reply-headers
4360 (mail-header-references message-reply-headers)
4361 (mail-header-subject message-reply-headers)
4364 (message-strip-subject-re
4365 (mail-header-subject message-reply-headers))
4366 (message-strip-subject-re psubject))))
4368 (string-match "_-_@" psupersedes)))
4370 "@" (message-make-fqdn) ">"))
4372 (defvar message-unique-id-char nil)
4374 ;; If you ever change this function, make sure the new version
4375 ;; cannot generate IDs that the old version could.
4376 ;; You might for example insert a "." somewhere (not next to another dot
4377 ;; or string boundary), or modify the "fsf" string.
4378 (defun message-unique-id ()
4379 ;; Don't use microseconds from (current-time), they may be unsupported.
4380 ;; Instead we use this randomly inited counter.
4381 (setq message-unique-id-char
4382 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4383 ;; (current-time) returns 16-bit ints,
4384 ;; and 2^16*25 just fits into 4 digits i base 36.
4386 (let ((tm (current-time)))
4388 (if (memq system-type '(ms-dos emx vax-vms))
4389 (let ((user (downcase (user-login-name))))
4390 (while (string-match "[^a-z0-9_]" user)
4391 (aset user (match-beginning 0) ?_))
4393 (message-number-base36 (user-uid) -1))
4394 (message-number-base36 (+ (car tm)
4395 (lsh (% message-unique-id-char 25) 16)) 4)
4396 (message-number-base36 (+ (nth 1 tm)
4397 (lsh (/ message-unique-id-char 25) 16)) 4)
4398 ;; Append the newsreader name, because while the generated
4399 ;; ID is unique to this newsreader, other newsreaders might
4400 ;; otherwise generate the same ID via another algorithm.
4403 (defun message-number-base36 (num len)
4408 (concat (message-number-base36 (/ num 36) (1- len))
4409 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4412 (defun message-make-organization ()
4413 "Make an Organization header."
4414 (let* ((organization
4415 (when message-user-organization
4416 (if (message-functionp message-user-organization)
4417 (funcall message-user-organization)
4418 message-user-organization))))
4420 (message-set-work-buffer)
4421 (cond ((stringp organization)
4422 (insert organization))
4423 ((and (eq t organization)
4424 message-user-organization-file
4425 (file-exists-p message-user-organization-file))
4426 (insert-file-contents message-user-organization-file)))
4427 (goto-char (point-min))
4428 (while (re-search-forward "[\t\n]+" nil t)
4429 (replace-match "" t t))
4430 (unless (zerop (buffer-size))
4433 (defun message-make-lines ()
4434 "Count the number of lines and return numeric string."
4439 (int-to-string (count-lines (point) (point-max))))))
4441 (defun message-make-in-reply-to ()
4442 "Return the In-Reply-To header for this message."
4443 (when message-reply-headers
4444 (let ((from (mail-header-from message-reply-headers))
4445 (date (mail-header-date message-reply-headers))
4446 (msg-id (mail-header-message-id message-reply-headers)))
4450 (let ((pair (std11-extract-address-components from)))
4452 (or (car pair) (cadr pair))
4454 (if (or (not date) (string= date ""))
4455 "(unknown date)" date)
4458 (defun message-make-distribution ()
4459 "Make a Distribution header."
4460 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4461 (cond ((message-functionp message-distribution-function)
4462 (funcall message-distribution-function))
4463 (t orig-distribution))))
4465 (defun message-make-expires ()
4466 "Return an Expires header based on `message-expires'."
4467 (let ((current (current-time))
4468 (future (* 1.0 message-expires 60 60 24)))
4469 ;; Add the future to current.
4470 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4471 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4472 (message-make-date current)))
4474 (defun message-make-path ()
4476 (let ((login-name (user-login-name)))
4477 (cond ((null message-user-path)
4478 (concat (system-name) "!" login-name))
4479 ((stringp message-user-path)
4480 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4481 (concat message-user-path "!" login-name))
4484 (defun message-make-from ()
4485 "Make a From header."
4486 (let* ((style message-from-style)
4487 (login (message-make-address))
4489 (or (and (boundp 'user-full-name)
4492 (when (string= fullname "&")
4493 (setq fullname (user-login-name)))
4495 (message-set-work-buffer)
4498 (equal fullname ""))
4500 ((or (eq style 'angles)
4501 (and (not (eq style 'parens))
4502 ;; Use angles if no quoting is needed, or if parens would
4503 ;; need quoting too.
4504 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4505 (let ((tmp (concat fullname nil)))
4506 (while (string-match "([^()]*)" tmp)
4507 (aset tmp (match-beginning 0) ?-)
4508 (aset tmp (1- (match-end 0)) ?-))
4509 (string-match "[\\()]" tmp)))))
4511 (insert " <" login ">"))
4512 (t ; 'parens or default
4514 (let ((fullname-start (point)))
4516 (goto-char fullname-start)
4517 ;; RFC 822 says \ and nonmatching parentheses
4518 ;; must be escaped in comments.
4519 ;; Escape every instance of ()\ ...
4520 (while (re-search-forward "[()\\]" nil 1)
4521 (replace-match "\\\\\\&" t))
4522 ;; ... then undo escaping of matching parentheses,
4523 ;; including matching nested parentheses.
4524 (goto-char fullname-start)
4525 (while (re-search-forward
4526 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4528 (replace-match "\\1(\\3)" t)
4529 (goto-char fullname-start)))
4533 (defun message-make-sender ()
4534 "Return the \"real\" user address.
4535 This function tries to ignore all user modifications, and
4536 give as trustworthy answer as possible."
4537 (concat (user-login-name) "@" (system-name)))
4539 (defun message-make-address ()
4540 "Make the address of the user."
4541 (or (message-user-mail-address)
4542 (concat (user-login-name) "@" (message-make-domain))))
4544 (defun message-user-mail-address ()
4545 "Return the pertinent part of `user-mail-address'."
4546 (when user-mail-address
4547 (if (string-match " " user-mail-address)
4548 (nth 1 (std11-extract-address-components user-mail-address))
4549 user-mail-address)))
4551 (defun message-make-fqdn ()
4552 "Return user's fully qualified domain name."
4553 (let ((system-name (system-name))
4554 (user-mail (message-user-mail-address)))
4556 ((and (string-match "[^.]\\.[^.]" system-name)
4557 (not (string-match message-bogus-system-names system-name)))
4558 ;; `system-name' returned the right result.
4560 ;; Try `mail-host-address'.
4561 ((and (boundp 'mail-host-address)
4562 (stringp mail-host-address)
4563 (string-match "\\." mail-host-address))
4565 ;; We try `user-mail-address' as a backup.
4567 (string-match "\\." user-mail)
4568 (string-match "@\\(.*\\)\\'" user-mail))
4569 (match-string 1 user-mail))
4570 ;; Default to this bogus thing.
4572 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
4574 (defun message-make-host-name ()
4575 "Return the name of the host."
4576 (let ((fqdn (message-make-fqdn)))
4577 (string-match "^[^.]+\\." fqdn)
4578 (substring fqdn 0 (1- (match-end 0)))))
4580 (defun message-make-domain ()
4581 "Return the domain name."
4582 (or mail-host-address
4583 (message-make-fqdn)))
4585 (defun message-to-list-only ()
4587 (let ((listaddr (message-make-mft t)))
4590 (message-remove-header "to")
4591 (message-remove-header "cc")
4592 (message-position-on-field "To" "X-Draft-From")
4593 (insert listaddr)))))
4595 (defun message-make-mft (&optional only-show-subscribed)
4596 "Return the Mail-Followup-To header. If passed the optional
4597 argument `only-show-subscribed' only return the subscribed address (and
4598 not the additional To and Cc header contents)."
4599 (let* ((case-fold-search t)
4600 (to (message-fetch-field "To"))
4601 (cc (message-fetch-field "cc"))
4602 (msg-recipients (concat to (and to cc ", ") cc))
4604 (mapcar 'mail-strip-quoted-names
4605 (message-tokenize-header msg-recipients)))
4607 (if message-subscribed-address-file
4608 (let (begin end item re)
4611 (insert-file-contents message-subscribed-address-file)
4613 (setq begin (point))
4616 (if (bolp) (setq end (1- end)))
4617 (setq item (regexp-quote (buffer-substring begin end)))
4618 (if re (setq re (concat re "\\|" item))
4619 (setq re (concat "\\`\\(" item))))
4620 (and re (list (concat re "\\)\\'"))))))))
4621 (mft-regexps (apply 'append message-subscribed-regexps
4622 (mapcar 'regexp-quote
4623 message-subscribed-addresses)
4626 message-subscribed-address-functions))))
4628 (let ((subscribed-lists nil)
4630 (loop for recipient in recipients
4631 when (loop for regexp in mft-regexps
4632 when (string-match regexp recipient) return t)
4635 (if only-show-subscribed
4637 msg-recipients))))))
4639 ;; Dummy to avoid byte-compile warning.
4640 (defvar mule-version)
4641 (defvar emacs-beta-version)
4642 (defvar xemacs-codename)
4643 (defvar gnus-inviolable-extended-version)
4645 (defun message-make-user-agent ()
4646 "Return user-agent info if the value `message-user-agent' is non-nil. If the
4647 \"User-Agent\" field has already exist, it's value will be added in the return
4649 (when message-user-agent
4651 (goto-char (point-min))
4652 (let ((case-fold-search t)
4653 user-agent start p end)
4654 (if (re-search-forward
4655 (concat "^User-Agent:[\t ]*\\("
4656 (regexp-quote gnus-product-name)
4657 "/[0-9.]+\\([ \t\r\n]*([^)]+)\\)*\\)?[\t ]*")
4660 (setq start (match-beginning 0)
4662 end (std11-field-end)
4663 user-agent (buffer-substring-no-properties p end))
4664 (delete-region start (1+ end))
4665 (concat message-user-agent " " user-agent))
4666 message-user-agent)))))
4668 (defun message-generate-headers (headers)
4669 "Prepare article HEADERS.
4670 Headers already prepared in the buffer are not modified."
4672 (message-narrow-to-headers)
4673 (let* ((Date (message-make-date))
4674 (Message-ID (message-make-message-id))
4675 (Organization (message-make-organization))
4676 (From (message-make-from))
4677 (Path (message-make-path))
4680 (In-Reply-To (message-make-in-reply-to))
4682 (Distribution (message-make-distribution))
4683 (Lines (message-make-lines))
4684 (User-Agent (message-make-user-agent))
4685 (Expires (message-make-expires))
4686 (case-fold-search t)
4688 ;; First we remove any old generated headers.
4689 (let ((headers message-deletable-headers))
4690 (unless (buffer-modified-p)
4691 (setq headers (delq 'Message-ID (copy-sequence headers))))
4693 (goto-char (point-min))
4694 (and (re-search-forward
4695 (concat "^" (symbol-name (car headers)) ": *") nil t)
4696 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4697 (message-delete-line))
4699 ;; Go through all the required headers and see if they are in the
4700 ;; articles already. If they are not, or are empty, they are
4701 ;; inserted automatically - except for Subject, Newsgroups and
4704 (goto-char (point-min))
4705 (setq elem (pop headers))
4707 (if (eq (car elem) 'optional)
4708 (setq header (cdr elem))
4709 (setq header (car elem)))
4711 (when (or (not (re-search-forward
4715 (if (stringp header)
4717 (symbol-name header))))
4721 ;; The header was found. We insert a space after the
4722 ;; colon, if there is none.
4723 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4724 ;; Find out whether the header is empty...
4725 (looking-at "[ \t]*\n[^ \t]")))
4726 ;; So we find out what value we should insert.
4729 ((and (consp elem) (eq (car elem) 'optional))
4730 ;; This is an optional header. If the cdr of this
4731 ;; is something that is nil, then we do not insert
4733 (setq header (cdr elem))
4734 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4735 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4737 ;; The element is a cons. Either the cdr is a
4738 ;; string to be inserted verbatim, or it is a
4739 ;; function, and we insert the value returned from
4741 (or (and (stringp (cdr elem)) (cdr elem))
4742 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4743 ((and (boundp header) (symbol-value header))
4744 ;; The element is a symbol. We insert the value
4745 ;; of this symbol, if any.
4746 (symbol-value header))
4747 ((not (message-check-element header))
4748 ;; We couldn't generate a value for this header,
4749 ;; so we just ask the user.
4750 (read-from-minibuffer
4751 (format "Empty header for %s; enter value: " header)))))
4752 ;; Finally insert the header.
4754 (not (equal value "")))
4758 ;; This header didn't exist, so we insert it.
4759 (goto-char (point-max))
4760 (insert (if (stringp header) header (symbol-name header))
4762 ;; We check whether the value was ended by a
4763 ;; newline. If now, we insert one.
4767 ;; The value of this header was empty, so we clear
4768 ;; totally and insert the new value.
4769 (delete-region (point) (gnus-point-at-eol))
4773 ;; Add the deletable property to the headers that require it.
4774 (and (memq header message-deletable-headers)
4775 (progn (beginning-of-line) (looking-at "[^:]+: "))
4776 (add-text-properties
4777 (point) (match-end 0)
4778 '(message-deletable t face italic) (current-buffer)))))))
4779 ;; Insert new Sender if the From is strange.
4780 (let ((from (message-fetch-field "from"))
4781 (sender (message-fetch-field "sender"))
4782 (secure-sender (message-make-sender)))
4784 (not (message-check-element 'sender))
4787 (cadr (std11-extract-address-components from)))
4788 (downcase secure-sender)))
4793 (cadr (std11-extract-address-components sender)))
4794 (downcase secure-sender)))))
4795 (goto-char (point-min))
4796 ;; Rename any old Sender headers to Original-Sender.
4797 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4799 (insert "Original-")
4800 (beginning-of-line))
4801 (when (or (message-news-p)
4802 (string-match "@.+\\.." secure-sender))
4803 (insert "Sender: " secure-sender "\n")))))))
4805 (defun message-insert-courtesy-copy ()
4806 "Insert a courtesy message in mail copies of combined messages."
4810 (message-narrow-to-headers)
4811 (when (setq newsgroups (message-fetch-field "newsgroups"))
4812 (goto-char (point-max))
4813 (insert "Posted-To: " newsgroups "\n")))
4815 (when message-courtesy-message
4817 ((string-match "%s" message-courtesy-message)
4818 (insert (format message-courtesy-message newsgroups)))
4820 (insert message-courtesy-message)))))))
4823 ;;; Setting up a message buffer
4826 (defun message-fill-address (header value)
4828 (narrow-to-region (point) (point))
4829 (insert (capitalize (symbol-name header))
4831 (if (consp value) (car value) value)
4833 (narrow-to-region (point-min) (1- (point-max)))
4835 (goto-char (point-min))
4837 (skip-chars-forward "^,\"" (point-max))
4838 (if (or (eq (char-after) ?,)
4841 (if (and (> (current-column) 78)
4845 (looking-at "[ \t]*")
4846 (replace-match "\n " t t)))
4847 (setq last (1+ (point))))
4848 (setq quoted (not quoted)))
4851 (goto-char (point-max))
4855 (defun message-fill-references (header value)
4856 (insert (capitalize (symbol-name header))
4858 (std11-fill-msg-id-list-string
4859 (if (consp value) (car value) value))
4862 (defun message-fill-header (header value)
4863 (let ((begin (point))
4866 (insert (capitalize (symbol-name header))
4868 (if (consp value) (car value) value)
4871 (narrow-to-region begin (point))
4872 (fill-region-as-paragraph begin (point))
4873 ;; Tapdance around looong Message-IDs.
4875 (when (looking-at "[ \t]*$")
4876 (message-delete-line))
4878 (re-search-forward ":" nil t)
4879 (when (looking-at "\n[ \t]+")
4880 (replace-match " " t t))
4881 (goto-char (point-max)))))
4883 (defun message-shorten-1 (list cut surplus)
4884 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4885 (setcdr (nthcdr (- cut 2) list)
4886 (nthcdr (+ (- cut 2) surplus 1) list)))
4888 (defun message-shorten-references (header references)
4889 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
4890 If folding is disallowed, also check that the REFERENCES are less
4891 than 988 characters long, and if they are not, trim them until they are."
4898 (goto-char (point-min))
4899 ;; Cons a list of valid references.
4900 (while (re-search-forward "<[^>]+>" nil t)
4901 (push (match-string 0) refs))
4902 (setq refs (nreverse refs)
4903 count (length refs)))
4905 ;; If the list has more than MAXCOUNT elements, trim it by
4906 ;; removing the CUTth element and the required number of
4907 ;; elements that follow.
4908 (when (> count maxcount)
4909 (let ((surplus (- count maxcount)))
4910 (message-shorten-1 refs cut surplus)
4911 (decf count surplus)))
4913 ;; If folding is disallowed, make sure the total length (including
4914 ;; the spaces between) will be less than MAXSIZE characters.
4916 ;; Only disallow folding for News messages. At this point the headers
4917 ;; have not been generated, thus we use message-this-is-news directly.
4918 (when (and message-this-is-news message-cater-to-broken-inn)
4920 (totalsize (+ (apply #'+ (mapcar #'length refs))
4923 (ptr (nthcdr (1- cut) refs)))
4924 ;; Decide how many elements to cut off...
4925 (while (> totalsize maxsize)
4926 (decf totalsize (1+ (length (car ptr))))
4928 (setq ptr (cdr ptr)))
4931 (message-shorten-1 refs cut surplus))))
4933 ;; Finally, collect the references back into a string and insert
4934 ;; it into the buffer.
4935 (let ((refstring (mapconcat #'identity refs " ")))
4936 (if (and message-this-is-news message-cater-to-broken-inn)
4937 (insert (capitalize (symbol-name header)) ": "
4939 (message-fill-header header refstring)))))
4941 (defun message-position-point ()
4942 "Move point to where the user probably wants to find it."
4943 (message-narrow-to-headers)
4945 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4946 (search-backward ":" )
4949 (if (eq (char-after) ? )
4953 (goto-char (point-max))
4956 (unless (looking-at "$")
4960 (defun message-beginning-of-line (&optional n)
4961 "Move point to beginning of header value or to beginning of line."
4963 (let ((zrs 'zmacs-region-stays))
4964 (when (and (interactive-p) (boundp zrs))
4966 (if (message-point-in-header-p)
4967 (let* ((here (point))
4968 (bol (progn (beginning-of-line n) (point)))
4969 (eol (gnus-point-at-eol))
4970 (eoh (re-search-forward ": *" eol t)))
4971 (if (or (not eoh) (equal here eoh))
4974 (beginning-of-line n)))
4976 (defun message-buffer-name (type &optional to group)
4977 "Return a new (unique) buffer name based on TYPE and TO."
4979 ;; Generate a new buffer name The Message Way.
4980 ((eq message-generate-new-buffers 'unique)
4981 (generate-new-buffer-name
4985 (or (car (std11-extract-address-components to))
4988 (if (and group (not (string= group ""))) (concat " on " group) "")
4990 ;; Check whether `message-generate-new-buffers' is a function,
4991 ;; and if so, call it.
4992 ((message-functionp message-generate-new-buffers)
4993 (funcall message-generate-new-buffers type to group))
4994 ((eq message-generate-new-buffers 'unsent)
4995 (generate-new-buffer-name
4996 (concat "*unsent " type
4999 (or (car (mail-extract-address-components to))
5002 (if (and group (not (string= group ""))) (concat " on " group) "")
5004 ;; Use standard name.
5006 (format "*%s message*" type))))
5008 (defmacro message-pop-to-buffer-1 (buffer)
5010 (let (special-display-buffer-names
5011 special-display-regexps
5012 same-window-buffer-names
5013 same-window-regexps)
5014 (pop-to-buffer ,buffer))
5015 (pop-to-buffer ,buffer)))
5017 (defun message-pop-to-buffer (name)
5018 "Pop to buffer NAME, and warn if it already exists and is modified."
5019 (let ((buffer (get-buffer name))
5020 (pop-up-frames (and (or (static-if (featurep 'xemacs)
5021 (device-on-window-system-p)
5023 (>= emacs-major-version 20))
5024 message-use-multi-frames)))
5026 (buffer-name buffer))
5028 (message-pop-to-buffer-1 buffer)
5029 (when (and (buffer-modified-p)
5031 "Message already being composed; erase? ")))
5032 (error "Message being composed")))
5033 (message-pop-to-buffer-1 name))
5037 (set (make-local-variable 'message-original-frame) (selected-frame)))))
5039 (defun message-do-send-housekeeping ()
5040 "Kill old message buffers."
5041 ;; We might have sent this buffer already. Delete it from the
5043 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5044 (while (and message-max-buffers
5046 (>= (length message-buffer-list) message-max-buffers))
5047 ;; Kill the oldest buffer -- unless it has been changed.
5048 (let ((buffer (pop message-buffer-list)))
5049 (when (and (buffer-name buffer)
5050 (not (buffer-modified-p buffer)))
5051 (kill-buffer buffer))))
5052 ;; Rename the buffer.
5053 (if message-send-rename-function
5054 (funcall message-send-rename-function)
5055 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5057 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5059 (let ((name (match-string 2 (buffer-name)))
5061 (if (not (or (null name)
5062 (string-equal name "mail")
5063 (string-equal name "posting")))
5064 (setq name (concat "*sent " name "*"))
5065 (message-narrow-to-headers)
5066 (setq to (message-fetch-field "to"))
5067 (setq group (message-fetch-field "newsgroups"))
5071 (to (concat "*sent mail to "
5072 (or (car (mail-extract-address-components to))
5074 ((and group (not (string= group "")))
5075 (concat "*sent posting on " group "*"))
5076 (t "*sent mail*"))))
5077 (unless (string-equal name (buffer-name))
5078 (rename-buffer name t)))))
5079 ;; Push the current buffer onto the list.
5080 (when message-max-buffers
5081 (setq message-buffer-list
5082 (nconc message-buffer-list (list (current-buffer))))))
5084 (defun message-mail-user-agent ()
5086 ((not message-mail-user-agent) nil)
5087 ((eq message-mail-user-agent t) mail-user-agent)
5088 (t message-mail-user-agent))))
5089 (if (memq mua '(message-user-agent gnus-user-agent))
5093 (defun message-setup (headers &optional replybuffer actions switch-function)
5094 (let ((mua (message-mail-user-agent))
5095 subject to field yank-action)
5096 (if (not (and message-this-is-mail mua))
5097 (message-setup-1 headers replybuffer actions)
5099 (setq yank-action (list 'insert-buffer replybuffer)))
5100 (setq headers (copy-sequence headers))
5101 (setq field (assq 'Subject headers))
5103 (setq subject (cdr field))
5104 (setq headers (delq field headers)))
5105 (setq field (assq 'To headers))
5107 (setq to (cdr field))
5108 (setq headers (delq field headers)))
5109 (let ((mail-user-agent mua))
5110 (compose-mail to subject
5111 (mapcar (lambda (item)
5113 (format "%s" (car item))
5116 nil switch-function yank-action actions)))))
5118 (defun message-setup-1 (headers &optional replybuffer actions)
5119 (dolist (action actions)
5121 (add-to-list 'message-send-actions
5122 `(apply ',(car action) ',(cdr action)))))
5123 (setq message-reply-buffer
5124 (or (message-get-parameter 'reply-buffer)
5126 (goto-char (point-min))
5127 ;; Insert all the headers.
5130 (alist message-header-format-alist))
5132 (unless (assq (caar h) message-header-format-alist)
5133 (push (list (caar h)) alist))
5137 (delete-region (point) (progn (forward-line -1) (point)))
5138 (when message-default-headers
5139 (insert message-default-headers)
5140 (or (bolp) (insert ?\n)))
5144 (insert mail-header-separator "\n")
5148 (when (message-news-p)
5149 (when message-default-news-headers
5150 (insert message-default-news-headers)
5151 (or (bolp) (insert ?\n)))
5152 (when message-generate-headers-first
5153 (message-generate-headers
5156 (copy-sequence message-required-news-headers))))))
5157 (when (message-mail-p)
5158 (when message-default-mail-headers
5159 (insert message-default-mail-headers)
5160 (or (bolp) (insert ?\n)))
5161 (when message-generate-headers-first
5162 (message-generate-headers
5165 (copy-sequence message-required-mail-headers))))))
5166 (run-hooks 'message-signature-setup-hook)
5167 (message-insert-signature)
5169 (message-narrow-to-headers)
5170 (if message-alternative-emails
5171 (message-use-alternative-email-as-from))
5172 (run-hooks 'message-header-setup-hook))
5173 (set-buffer-modified-p nil)
5174 (setq buffer-undo-list nil)
5175 (run-hooks 'message-setup-hook)
5176 (message-position-point)
5179 (defun message-set-auto-save-file-name ()
5180 "Associate the message buffer with a file in the drafts directory."
5181 (when message-auto-save-directory
5182 (unless (file-directory-p
5183 (directory-file-name message-auto-save-directory))
5184 (gnus-make-directory message-auto-save-directory))
5186 (setq message-draft-article
5187 (nndraft-request-associate-buffer "drafts"))
5188 (setq buffer-file-name (expand-file-name
5189 (if (memq system-type
5190 '(ms-dos ms-windows windows-nt
5195 message-auto-save-directory))
5196 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5197 (clear-visited-file-modtime)
5198 (static-if (boundp 'MULE)
5199 (set-file-coding-system message-draft-coding-system)
5200 (setq buffer-file-coding-system message-draft-coding-system))))
5202 (defun message-disassociate-draft ()
5203 "Disassociate the message buffer from the drafts directory."
5204 (when message-draft-article
5205 (nndraft-request-expire-articles
5206 (list message-draft-article) "drafts" nil t)))
5208 (defun message-insert-headers ()
5209 "Generate the headers for the article."
5213 (message-narrow-to-headers)
5214 (when (message-news-p)
5215 (message-generate-headers
5218 (copy-sequence message-required-news-headers)))))
5219 (when (message-mail-p)
5220 (message-generate-headers
5223 (copy-sequence message-required-mail-headers))))))))
5228 ;;; Commands for interfacing with message
5232 (defun message-mail (&optional to subject
5233 other-headers continue switch-function
5234 yank-action send-actions)
5235 "Start editing a mail message to be sent.
5236 OTHER-HEADERS is an alist of header/value pairs."
5238 (let ((message-this-is-mail t) replybuffer)
5239 (unless (message-mail-user-agent)
5240 (message-pop-to-buffer (message-buffer-name "mail" to)))
5241 ;; FIXME: message-mail should do something if YANK-ACTION is not
5243 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5244 (setq replybuffer (nth 1 yank-action)))
5247 `((To . ,(or to "")) (Subject . ,(or subject "")))
5248 (when other-headers other-headers))
5249 replybuffer send-actions)
5250 ;; FIXME: Should return nil if failure.
5254 (defun message-news (&optional newsgroups subject)
5255 "Start editing a news article to be sent."
5257 (let ((message-this-is-news t))
5258 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5259 (message-setup `((Newsgroups . ,(or newsgroups ""))
5260 (Subject . ,(or subject ""))))))
5262 (defun message-get-reply-headers (wide &optional to-address)
5263 (let (follow-to mct never-mct to cc author mft recipients)
5264 ;; Find all relevant headers we need.
5265 (let ((mrt (when message-use-mail-reply-to
5266 (message-fetch-field "mail-reply-to")))
5267 (reply-to (message-fetch-field "reply-to")))
5268 (setq to (message-fetch-field "to")
5269 cc (message-fetch-field "cc")
5270 mct (when message-use-mail-copies-to
5271 (message-fetch-field "mail-copies-to"))
5274 (message-fetch-field "from")
5276 mft (when (and (not (or to-address mrt reply-to))
5277 message-use-mail-followup-to)
5278 (message-fetch-field "mail-followup-to"))))
5281 ;; Handle special values of Mail-Copies-To.
5283 (cond ((or (equal (downcase mct) "never")
5284 (equal (downcase mct) "nobody"))
5285 (when (or (not (eq message-use-mail-copies-to 'ask))
5287 (concat "Obey Mail-Copies-To: never? ") t "\
5288 You should normally obey the Mail-Copies-To: header.
5290 `Mail-Copies-To: " mct "'
5291 directs you not to send your response to the author."))
5294 ((or (equal (downcase mct) "always")
5295 (equal (downcase mct) "poster"))
5296 (if (or (not (eq message-use-mail-copies-to 'ask))
5298 (concat "Obey Mail-Copies-To: always? ") t "\
5299 You should normally obey the Mail-Copies-To: header.
5301 `Mail-Copies-To: " mct "'
5302 sends a copy of your response to the author."))
5305 ((and (eq message-use-mail-copies-to 'ask)
5306 (not (message-y-or-n-p
5307 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5308 You should normally obey the Mail-Copies-To: header.
5310 `Mail-Copies-To: " mct "'
5311 sends a copy of your response to " (if (string-match "," mct)
5312 "the specified addresses"
5313 "that address") ".")))
5316 ;; Build (textual) list of new recipient addresses.
5319 (setq recipients (concat ", " author)))
5321 (string-match "[^ \t,]" mft)
5322 (or (not (eq message-use-mail-followup-to 'ask))
5323 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5324 You should normally obey the Mail-Followup-To: header. In this
5325 article, it has the value of
5329 which directs your response to " (if (string-match "," mft)
5330 "the specified addresses"
5331 "that address only") ".
5333 Most commonly, Mail-Followup-To is used by a mailing list poster to
5334 express that responses should be sent to just the list, and not the
5337 If a message is posted to several mailing lists, Mail-Followup-To may
5338 also be used to direct the following discussion to one list only,
5339 because discussions that are spread over several lists tend to be
5340 fragmented and very difficult to follow.
5342 Also, some source/announcement lists are not intended for discussion;
5343 responses here are directed to other addresses.")))
5344 (setq recipients (concat ", " mft)))
5346 (setq recipients (concat ", " to-address))
5347 ;; If the author explicitly asked for a copy, we don't deny it to them.
5348 (if mct (setq recipients (concat recipients ", " mct))))
5350 (setq recipients (if never-mct "" (concat ", " author)))
5351 (if to (setq recipients (concat recipients ", " to)))
5352 (if cc (setq recipients (concat recipients ", " cc)))
5353 (if mct (setq recipients (concat recipients ", " mct)))))
5354 (if (>= (length recipients) 2)
5355 ;; Strip the leading ", ".
5356 (setq recipients (substring recipients 2)))
5357 ;; Squeeze whitespace.
5358 (while (string-match "[ \t][ \t]+" recipients)
5359 (setq recipients (replace-match " " t t recipients)))
5360 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5361 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5362 (setq recipients (rmail-dont-reply-to recipients)))
5363 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5364 (if (string-equal recipients "")
5365 (setq recipients author))
5366 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5370 (cons (downcase (mail-strip-quoted-names addr)) addr))
5371 (message-tokenize-header recipients)))
5372 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5373 (let ((s recipients))
5375 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5377 ;; Remove hierarchical lists that are contained within each other,
5378 ;; if message-hierarchical-addresses is defined.
5379 (when message-hierarchical-addresses
5380 (let ((plain-addrs (mapcar 'car recipients))
5383 (setq subaddrs (assoc (car plain-addrs)
5384 message-hierarchical-addresses)
5385 plain-addrs (cdr plain-addrs))
5387 (setq subaddrs (cdr subaddrs))
5389 (setq recip (assoc (car subaddrs) recipients)
5390 subaddrs (cdr subaddrs))
5392 (setq recipients (delq recip recipients))))))))
5394 ;; Build the header alist. Allow the user to be asked whether
5395 ;; or not to reply to all recipients in a wide reply.
5396 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5397 (when (and recipients
5398 (or (not message-wide-reply-confirm-recipients)
5399 (y-or-n-p "Reply to all recipients? ")))
5400 (setq recipients (mapconcat
5401 (lambda (addr) (cdr addr)) recipients ", "))
5402 (if (string-match "^ +" recipients)
5403 (setq recipients (substring recipients (match-end 0))))
5404 (push (cons 'Cc recipients) follow-to)))
5408 (defun message-reply (&optional to-address wide)
5409 "Start editing a reply to the article in the current buffer."
5411 (require 'gnus-sum) ; for gnus-list-identifiers
5412 (let ((cur (current-buffer))
5414 references message-id follow-to
5415 (inhibit-point-motion-hooks t)
5416 (message-this-is-mail t)
5417 gnus-warning in-reply-to)
5419 (message-narrow-to-head-1)
5420 ;; Allow customizations to have their say.
5422 ;; This is a regular reply.
5423 (when (message-functionp message-reply-to-function)
5425 (setq follow-to (funcall message-reply-to-function))))
5426 ;; This is a followup.
5427 (when (message-functionp message-wide-reply-to-function)
5430 (funcall message-wide-reply-to-function)))))
5431 (setq message-id (message-fetch-field "message-id" t)
5432 references (message-fetch-field "references")
5433 date (message-fetch-field "date")
5434 from (message-fetch-field "from")
5435 subject (or (message-fetch-field "subject") "none"))
5436 (when gnus-list-identifiers
5437 (setq subject (message-strip-list-identifiers subject)))
5438 (setq subject (message-make-followup-subject subject))
5440 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5441 (string-match "<[^>]+>" gnus-warning))
5442 (setq message-id (match-string 0 gnus-warning)))
5445 (setq follow-to (message-get-reply-headers wide to-address)))
5447 ;; Get the references from "In-Reply-To" field if there were
5448 ;; no references and "In-Reply-To" field looks promising.
5450 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
5451 (string-match "<[^>]+>" in-reply-to))
5452 (setq references (match-string 0 in-reply-to)))))
5454 (unless (message-mail-user-agent)
5455 (message-pop-to-buffer
5456 (message-buffer-name
5457 (if wide "wide reply" "reply") from
5458 (if wide to-address nil))))
5460 (setq message-reply-headers
5461 (make-full-mail-header-from-decoded-header
5462 0 subject from date message-id references 0 0 ""))
5465 `((Subject . ,subject)
5467 ,@(if (or references message-id)
5468 `((References . ,(concat (or references "") (and references " ")
5469 (or message-id ""))))
5474 (defun message-wide-reply (&optional to-address)
5475 "Make a \"wide\" reply to the message in the current buffer."
5477 (message-reply to-address t))
5480 (defun message-followup (&optional to-newsgroups)
5481 "Follow up to the message in the current buffer.
5482 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5484 (require 'gnus-sum) ; for gnus-list-identifiers
5485 (let ((cur (current-buffer))
5486 from subject date reply-to mrt mct mft
5487 references message-id follow-to
5488 (inhibit-point-motion-hooks t)
5489 (message-this-is-news t)
5490 followup-to distribution newsgroups gnus-warning posted-to)
5492 (message-narrow-to-head)
5493 (when (message-functionp message-followup-to-function)
5495 (funcall message-followup-to-function)))
5496 (setq from (message-fetch-field "from")
5497 date (message-fetch-field "date")
5498 subject (or (message-fetch-field "subject") "none")
5499 references (message-fetch-field "references")
5500 message-id (message-fetch-field "message-id" t)
5501 followup-to (message-fetch-field "followup-to")
5502 newsgroups (message-fetch-field "newsgroups")
5503 posted-to (message-fetch-field "posted-to")
5504 reply-to (message-fetch-field "reply-to")
5505 mrt (when message-use-mail-reply-to
5506 (message-fetch-field "mail-reply-to"))
5507 distribution (message-fetch-field "distribution")
5508 mct (when message-use-mail-copies-to
5509 (message-fetch-field "mail-copies-to"))
5510 mft (when message-use-mail-followup-to
5511 (message-fetch-field "mail-followup-to")))
5512 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5513 (string-match "<[^>]+>" gnus-warning))
5514 (setq message-id (match-string 0 gnus-warning)))
5515 ;; Remove bogus distribution.
5516 (when (and (stringp distribution)
5517 (let ((case-fold-search t))
5518 (string-match "world" distribution)))
5519 (setq distribution nil))
5520 (if gnus-list-identifiers
5521 (setq subject (message-strip-list-identifiers subject)))
5522 (setq subject (message-make-followup-subject subject))
5525 ;; Handle special values of Mail-Copies-To.
5528 ((and (or (equal (downcase mct) "never")
5529 (equal (downcase mct) "nobody")))
5531 ((and (or (equal (downcase mct) "always")
5532 (equal (downcase mct) "poster")))
5533 (if (or (not (eq message-use-mail-copies-to 'ask))
5535 (concat "Obey Mail-Copies-To: always? ") t "\
5536 You should normally obey the Mail-Copies-To: header.
5538 `Mail-Copies-To: " mct "'
5539 sends a copy of your response to the author."))
5540 (setq mct (or mrt reply-to from))
5542 ((and (eq message-use-mail-copies-to 'ask)
5545 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
5546 You should normally obey the Mail-Copies-To: header.
5548 `Mail-Copies-To: " mct "'
5549 sends a copy of your response to " (if (string-match "," mct)
5550 "the specified addresses"
5551 "that address") ".")))
5556 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
5557 ;; Handle Followup-To.
5560 ((equal (downcase followup-to) "poster")
5561 (if (or (and followup-to (eq message-use-followup-to 'use))
5562 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5563 You should normally obey the Followup-To: header.
5565 `Followup-To: poster'
5566 sends your response via e-mail instead of news.
5568 A typical situation where `Followup-To: poster' is used is when the author
5569 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5570 (setq message-this-is-news nil
5572 follow-to (list (cons 'To (or mrt reply-to from ""))))
5573 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
5575 (if (or (equal followup-to newsgroups)
5576 (not (and followup-to (eq message-use-followup-to 'ask)))
5578 (concat "Obey Followup-To: " followup-to "? ") t "\
5579 You should normally obey the Followup-To: header.
5581 `Followup-To: " followup-to "'
5582 directs your response to " (if (string-match "," followup-to)
5583 "the specified newsgroups"
5584 "that newsgroup only") ".
5586 If a message is posted to several newsgroups, Followup-To is often
5587 used to direct the following discussion to one newsgroup only,
5588 because discussions that are spread over several newsgroup tend to
5589 be fragmented and very difficult to follow.
5591 Also, some source/announcement newsgroups are not intended for discussion;
5592 responses here are directed to other newsgroups."))
5593 (setq follow-to (list (cons 'Newsgroups followup-to)))
5594 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
5595 ;; Handle Mail-Followup-To, followup via e-mail.
5597 (or (not (eq message-use-mail-followup-to 'ask))
5599 (concat "Obey Mail-Followup-To: " mft "? ") t "\
5600 You should normally obey the Mail-Followup-To: header.
5602 `Mail-Followup-To: " mft "'
5603 directs your response to " (if (string-match "," mft)
5604 "the specified addresses"
5605 "that address only") " instead of news.
5607 A typical situation where Mail-Followup-To is used is when the author thinks
5608 that further discussion should take place only in "
5609 (if (string-match "," mft)
5610 "the specified mailing lists"
5611 "that mailing list") ".")))
5612 (setq message-this-is-news nil
5614 follow-to (list (cons 'To mft))))
5615 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
5617 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
5619 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5622 `((Subject . ,subject)
5624 ,@(and mct (list (cons 'Cc mct)))
5625 ,@(and distribution (list (cons 'Distribution distribution)))
5626 ,@(if (or references message-id)
5627 `((References . ,(concat (or references "") (and references " ")
5628 (or message-id ""))))))
5631 (setq message-reply-headers
5632 (make-full-mail-header-from-decoded-header
5633 0 subject from date message-id references 0 0 ""))))
5636 (defun message-cancel-news (&optional arg)
5637 "Cancel an article you posted.
5638 If ARG, allow editing of the cancellation message."
5640 (unless (message-news-p)
5641 (error "This is not a news article; canceling is impossible"))
5642 (let (from newsgroups message-id distribution buf sender)
5644 ;; Get header info from original article.
5646 (message-narrow-to-head-1)
5647 (setq from (message-fetch-field "from")
5648 sender (message-fetch-field "sender")
5649 newsgroups (message-fetch-field "newsgroups")
5650 message-id (message-fetch-field "message-id" t)
5651 distribution (message-fetch-field "distribution")))
5652 ;; Make sure that this article was written by the user.
5654 ;; Canlock-logic as suggested by Per Abrahamsen
5655 ;; <abraham@dina.kvl.dk>
5657 ;; IF article has cancel-lock THEN
5658 ;; IF we can verify it THEN
5661 ;; error: cancellock: article is not yours
5663 ;; Use old rules, comparing sender...
5664 (if (message-fetch-field "Cancel-Lock")
5665 (if (null (canlock-verify))
5667 (error "Failed to verify Cancel-lock: This article is not yours"))
5669 (message-gnksa-enable-p 'cancel-messages)
5673 (downcase (message-make-sender))))
5675 (downcase (cadr (std11-extract-address-components from)))
5676 (downcase (cadr (std11-extract-address-components
5677 (message-make-from))))))
5678 (error "This article is not yours"))
5679 (when (yes-or-no-p "Do you really want to cancel this article? ")
5680 ;; Make control message.
5683 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5685 (insert "Newsgroups: " newsgroups "\n"
5687 "Subject: cmsg cancel " message-id "\n"
5688 "Control: cancel " message-id "\n"
5690 (concat "Distribution: " distribution "\n")
5692 mail-header-separator "\n"
5693 message-cancel-message)
5694 (run-hooks 'message-cancel-hook)
5696 (message "Canceling your article...")
5697 (if (let ((message-syntax-checks
5698 'dont-check-for-anything-just-trust-me)
5699 (message-encoding-buffer (current-buffer))
5700 (message-edit-buffer (current-buffer)))
5701 (message-send-news))
5702 (message "Canceling your article...done"))
5703 (kill-buffer buf))))))
5705 (defun message-supersede-setup-for-mime-edit ()
5706 (set (make-local-variable 'message-setup-hook) nil)
5710 (defun message-supersede ()
5711 "Start composing a message to supersede the current message.
5712 This is done simply by taking the old article and adding a Supersedes
5713 header line with the old Message-ID."
5715 (let ((cur (current-buffer))
5716 (sender (message-fetch-field "sender"))
5717 (from (message-fetch-field "from")))
5718 ;; Check whether the user owns the article that is to be superseded.
5720 ;; Canlock-logic as suggested by Per Abrahamsen
5721 ;; <abraham@dina.kvl.dk>
5723 ;; IF article has cancel-lock THEN
5724 ;; IF we can verify it THEN
5727 ;; error: cancellock: article is not yours
5729 ;; Use old rules, comparing sender...
5730 (if (message-fetch-field "Cancel-Lock")
5731 (if (null (canlock-verify))
5733 (error "Failed to verify Cancel-lock: This article is not yours"))
5735 (message-gnksa-enable-p 'cancel-messages)
5739 (downcase (message-make-sender))))
5741 (downcase (cadr (std11-extract-address-components from)))
5742 (downcase (cadr (std11-extract-address-components
5743 (message-make-from))))))
5744 (error "This article is not yours"))
5745 ;; Get a normal message buffer.
5746 (message-pop-to-buffer (message-buffer-name "supersede"))
5747 (insert-buffer-substring cur)
5748 (message-narrow-to-head-1)
5749 ;; Remove unwanted headers.
5750 (when message-ignored-supersedes-headers
5751 (message-remove-header message-ignored-supersedes-headers t))
5752 (goto-char (point-min))
5753 (if (not (re-search-forward "^Message-ID: " nil t))
5754 (error "No Message-ID in this article")
5755 (replace-match "Supersedes: " t t))
5756 (goto-char (point-max))
5757 (insert mail-header-separator)
5759 (when message-supersede-setup-function
5760 (funcall message-supersede-setup-function))
5761 (run-hooks 'message-supersede-setup-hook)
5762 (goto-char (point-min))
5763 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
5766 (defun message-recover ()
5767 "Reread contents of current buffer from its last auto-save file."
5769 (let ((file-name (make-auto-save-file-name)))
5770 (cond ((save-window-excursion
5771 (if (not (eq system-type 'vax-vms))
5772 (with-output-to-temp-buffer "*Directory*"
5773 (with-current-buffer standard-output
5774 (fundamental-mode)) ; for Emacs 20.4+
5775 (buffer-disable-undo standard-output)
5776 (let ((default-directory "/"))
5778 "ls" nil standard-output nil "-l" file-name))))
5779 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5780 (let ((buffer-read-only nil))
5782 (insert-file-contents file-name nil)))
5783 (t (error "message-recover cancelled")))))
5785 ;;; Washing Subject:
5787 (defun message-wash-subject (subject)
5788 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5789 Previous forwarders, replyers, etc. may add it."
5792 (goto-char (point-min))
5793 ;; strip Re/Fwd stuff off the beginning
5794 (while (re-search-forward
5795 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5798 ;; and gnus-style forwards [foo@bar.com] subject
5799 (goto-char (point-min))
5800 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5804 (goto-char (point-max))
5805 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5808 ;; and finally, any whitespace that was left-over
5809 (goto-char (point-min))
5810 (while (re-search-forward "^[ \t]+" nil t)
5812 (goto-char (point-max))
5813 (while (re-search-backward "[ \t]+$" nil t)
5818 ;;; Forwarding messages.
5820 (defvar message-forward-decoded-p nil
5821 "Non-nil means the original message is decoded.")
5823 (defun message-forward-subject-author-subject (subject)
5824 "Generate a SUBJECT for a forwarded message.
5825 The form is: [Source] Subject, where if the original message was mail,
5826 Source is the sender, and if the original message was news, Source is
5827 the list of newsgroups is was posted to."
5829 (let ((prefix (message-fetch-field "newsgroups")))
5831 (and (setq prefix (message-fetch-field "from"))
5832 (nnheader-decode-from prefix))
5836 (defun message-forward-subject-fwd (subject)
5837 "Generate a SUBJECT for a forwarded message.
5838 The form is: Fwd: Subject, where Subject is the original subject of
5840 (concat "Fwd: " subject))
5842 (defun message-make-forward-subject ()
5843 "Return a Subject header suitable for the message in the current buffer."
5846 (message-narrow-to-head-1)
5847 (let ((funcs message-make-forward-subject-function)
5848 (subject (message-fetch-field "Subject")))
5851 (if message-forward-decoded-p
5853 (nnheader-decode-subject subject))
5855 (if message-wash-forwarded-subjects
5856 (setq subject (message-wash-subject subject)))
5857 ;; Make sure funcs is a list.
5860 (setq funcs (list funcs)))
5861 ;; Apply funcs in order, passing subject generated by previous
5862 ;; func to the next one.
5864 (when (message-functionp (car funcs))
5865 (setq subject (funcall (car funcs) subject)))
5866 (setq funcs (cdr funcs)))
5870 (defun message-forward (&optional news)
5871 "Forward the current message via mail.
5872 Optional NEWS will use news to forward instead of mail."
5874 (let ((cur (current-buffer))
5875 (subject (message-make-forward-subject)))
5877 (message-news nil subject)
5878 (message-mail nil subject))
5879 (message-forward-make-body cur)))
5882 (defun message-forward-make-body (forward-buffer)
5883 ;; Put point where we want it before inserting the forwarded
5885 ;; Note that this function definition for T-gnus is totally different
5886 ;; from the original Gnus."
5887 (if message-forward-before-signature
5889 (goto-char (point-max)))
5890 ;; Make sure we're at the start of the line.
5893 ;; Narrow to the area we are to insert.
5894 (narrow-to-region (point) (point))
5895 ;; Insert the separators and the forwarded buffer.
5896 (insert message-forward-start-separator)
5897 (let ((art-beg (point)))
5898 (insert-buffer-substring forward-buffer)
5899 (goto-char (point-max))
5900 (insert message-forward-end-separator)
5901 (set-text-properties (point-min) (point-max) nil)
5902 ;; Remove all unwanted headers.
5904 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5907 (goto-char (point-min))
5908 (message-remove-header message-included-forward-headers t nil t)
5910 (message-position-point)))
5913 (defun message-forward-rmail-make-body (forward-buffer)
5914 (save-window-excursion
5915 (set-buffer forward-buffer)
5916 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
5917 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
5918 (if (rmail-msg-is-pruned)
5919 (rmail-msg-restore-non-pruned-header)))
5920 (message-forward-make-body forward-buffer))
5923 (defun message-insinuate-rmail ()
5924 "Let RMAIL uses message to forward."
5926 (setq rmail-enable-mime-composing t)
5927 (setq rmail-insert-mime-forwarded-message-function
5928 'message-forward-rmail-make-body))
5931 (defun message-resend (address)
5932 "Resend the current article to ADDRESS."
5934 (list (message-read-from-minibuffer "Resend message to: ")))
5935 (message "Resending message to %s..." address)
5937 (let ((cur (current-buffer))
5939 ;; We first set up a normal mail buffer.
5940 (unless (message-mail-user-agent)
5941 (set-buffer (get-buffer-create " *message resend*"))
5943 (let ((message-this-is-mail t)
5944 ;; avoid to turn-on-mime-edit
5946 (message-setup `((To . ,address)))))
5947 ;; Insert our usual headers.
5948 (message-generate-headers '(From Date To))
5949 (message-narrow-to-headers)
5950 ;; Rename them all to "Resent-*".
5951 (while (re-search-forward "^[A-Za-z]" nil t)
5956 (delete-region (point) (point-max))
5958 ;; Insert the message to be resent.
5959 (insert-buffer-substring cur)
5960 (goto-char (point-min))
5961 (search-forward "\n\n")
5964 (narrow-to-region beg (point))
5965 (message-remove-header message-ignored-resent-headers t)
5966 (goto-char (point-max)))
5967 (insert mail-header-separator)
5968 ;; Rename all old ("Also-")Resent headers.
5969 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5972 ;; Quote any "From " lines at the beginning.
5974 (when (looking-at "From ")
5975 (replace-match "X-From-Line: "))
5977 (let ((message-encoding-buffer (current-buffer))
5978 (message-edit-buffer (current-buffer))
5979 message-required-mail-headers)
5980 (message-send-mail))
5981 (kill-buffer (current-buffer)))
5982 (message "Resending message to %s...done" address)))
5984 (defun message-bounce-setup-for-mime-edit ()
5985 (set (make-local-variable 'message-setup-hook) nil)
5989 (defun message-bounce ()
5990 "Re-mail the current message.
5991 This only makes sense if the current message is a bounce message that
5992 contains some mail you have written which has been bounced back to
5995 (let ((cur (current-buffer))
5997 (message-pop-to-buffer (message-buffer-name "bounce"))
5998 (insert-buffer-substring cur)
6000 (message-narrow-to-head)
6001 (if (and (message-fetch-field "MIME-Version")
6002 (setq boundary (message-fetch-field "Content-Type")))
6003 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
6004 (setq boundary (concat (match-string 1 boundary) " *\n"
6005 "Content-Type: message/rfc822"))
6006 (setq boundary nil)))
6008 (goto-char (point-min))
6009 (search-forward "\n\n" nil t)
6010 (if (or (and boundary
6011 (re-search-forward boundary nil t)
6013 (and (re-search-forward message-unsent-separator nil t)
6015 (re-search-forward "^Return-Path:.*\n" nil t))
6016 ;; We remove everything before the bounced mail.
6019 (if (re-search-forward "^[^ \n\t]+:" nil t)
6022 (when (re-search-backward "^.?From .*\n" nil t)
6023 (delete-region (match-beginning 0) (match-end 0))))
6025 (message-narrow-to-head-1)
6026 (message-remove-header message-ignored-bounced-headers t)
6027 (goto-char (point-max))
6028 (insert mail-header-separator))
6029 (when message-bounce-setup-function
6030 (funcall message-bounce-setup-function))
6031 (run-hooks 'message-bounce-setup-hook)
6032 (message-position-point)))
6035 ;;; Interactive entry points for new message buffers.
6039 (defun message-mail-other-window (&optional to subject)
6040 "Like `message-mail' command, but display mail buffer in another window."
6042 (unless (message-mail-user-agent)
6043 (let ((pop-up-windows t)
6044 (special-display-buffer-names nil)
6045 (special-display-regexps nil)
6046 (same-window-buffer-names nil)
6047 (same-window-regexps nil))
6048 (message-pop-to-buffer (message-buffer-name "mail" to))))
6049 (let ((message-this-is-mail t))
6050 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6051 nil nil 'switch-to-buffer-other-window)))
6054 (defun message-mail-other-frame (&optional to subject)
6055 "Like `message-mail' command, but display mail buffer in another frame."
6057 (unless (message-mail-user-agent)
6058 (let ((pop-up-frames t)
6059 (special-display-buffer-names nil)
6060 (special-display-regexps nil)
6061 (same-window-buffer-names nil)
6062 (same-window-regexps nil))
6063 (message-pop-to-buffer (message-buffer-name "mail" to))))
6064 (let ((message-this-is-mail t))
6065 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6066 nil nil 'switch-to-buffer-other-frame)))
6069 (defun message-news-other-window (&optional newsgroups subject)
6070 "Start editing a news article to be sent."
6072 (let ((pop-up-windows t)
6073 (special-display-buffer-names nil)
6074 (special-display-regexps nil)
6075 (same-window-buffer-names nil)
6076 (same-window-regexps nil))
6077 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6078 (let ((message-this-is-news t))
6079 (message-setup `((Newsgroups . ,(or newsgroups ""))
6080 (Subject . ,(or subject ""))))))
6083 (defun message-news-other-frame (&optional newsgroups subject)
6084 "Start editing a news article to be sent."
6086 (let ((pop-up-frames t)
6087 (special-display-buffer-names nil)
6088 (special-display-regexps nil)
6089 (same-window-buffer-names nil)
6090 (same-window-regexps nil))
6091 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6092 (let ((message-this-is-news t))
6093 (message-setup `((Newsgroups . ,(or newsgroups ""))
6094 (Subject . ,(or subject ""))))))
6098 ;; This code should be moved to underline.el (from which it is stolen).
6101 (defun bold-region (start end)
6102 "Bold all nonblank characters in the region.
6103 Works by overstriking characters.
6104 Called from program, takes two arguments START and END
6105 which specify the range to operate on."
6108 (let ((end1 (make-marker)))
6109 (move-marker end1 (max start end))
6110 (goto-char (min start end))
6111 (while (< (point) end1)
6112 (or (looking-at "[_\^@- ]")
6113 (insert (char-after) "\b"))
6114 (forward-char 1)))))
6117 (defun unbold-region (start end)
6118 "Remove all boldness (overstruck characters) in the region.
6119 Called from program, takes two arguments START and END
6120 which specify the range to operate on."
6123 (let ((end1 (make-marker)))
6124 (move-marker end1 (max start end))
6125 (goto-char (min start end))
6126 (while (re-search-forward "\b" end1 t)
6127 (if (eq (char-after) (char-after (- (point) 2)))
6128 (delete-char -2))))))
6130 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6132 ;; Support for toolbar
6134 (defvar tool-bar-map)
6135 (defvar tool-bar-mode))
6137 (defun message-tool-bar-map ()
6138 (or message-tool-bar-map
6139 (setq message-tool-bar-map
6141 (condition-case nil (require 'tool-bar) (error nil))
6142 (fboundp 'tool-bar-add-item-from-menu)
6144 (let ((tool-bar-map (copy-keymap tool-bar-map))
6145 (load-path (mm-image-load-path)))
6146 ;; Zap some items which aren't so relevant and take
6148 (dolist (key '(print-buffer kill-buffer save-buffer
6149 write-file dired open-file))
6150 (define-key tool-bar-map (vector key) nil))
6151 (tool-bar-add-item-from-menu
6152 'message-send-and-exit "mail_send" message-mode-map)
6153 (tool-bar-add-item-from-menu
6154 'message-kill-buffer "close" message-mode-map)
6155 (tool-bar-add-item-from-menu
6156 'message-dont-send "cancel" message-mode-map)
6157 (tool-bar-add-item-from-menu
6158 'mime-edit-insert-file "attach" message-mode-map)
6159 (tool-bar-add-item-from-menu
6160 'ispell-message "spell" message-mode-map)
6161 (tool-bar-add-item-from-menu
6162 'message-insert-importance-high "important"
6164 (tool-bar-add-item-from-menu
6165 'message-insert-importance-low "unimportant"
6167 (tool-bar-add-item-from-menu
6168 'message-insert-disposition-notification-to "receipt"
6172 ;;; Group name completion.
6174 (defcustom message-newgroups-header-regexp
6175 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6176 "Regexp that match headers that lists groups."
6180 (defcustom message-completion-alist
6181 (list (cons message-newgroups-header-regexp 'message-expand-group)
6182 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name))
6183 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6185 :type '(alist :key-type regexp :value-type function))
6187 (defcustom message-expand-name-function
6188 (if (fboundp 'bbdb-complete-name)
6190 (if (fboundp 'lsdb-complete-name)
6193 "*A function called to expand addresses in field body."
6197 (defcustom message-tab-body-function nil
6198 "*Function to execute when `message-tab' (TAB) is executed in the body.
6199 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6203 (defun message-tab ()
6204 "Complete names according to `message-completion-alist'.
6205 Execute function specified by `message-tab-body-function' when not in
6208 (let ((alist message-completion-alist))
6210 (let ((mail-abbrev-mode-regexp (caar alist)))
6211 (not (mail-abbrev-in-expansion-header-p))))
6212 (setq alist (cdr alist)))
6213 (funcall (or (cdar alist) message-tab-body-function
6214 (lookup-key text-mode-map "\t")
6215 (lookup-key global-map "\t")
6216 'indent-relative))))
6218 (defun message-expand-group ()
6219 "Expand the group name under point."
6220 (let* ((b (save-excursion
6225 (skip-chars-forward "^:")
6228 (skip-chars-backward "^, \t\n") (point))))
6229 (completion-ignore-case t)
6230 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6232 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6233 (completions (all-completions string hashtb))
6235 (delete-region b (point))
6237 ((= (length completions) 1)
6238 (if (string= (car completions) string)
6241 (message "Only matching group"))
6242 (insert (car completions))))
6243 ((and (setq comp (try-completion string hashtb))
6244 (not (string= comp string)))
6249 (message "No matching groups")
6250 (save-selected-window
6251 (pop-to-buffer "*Completions*")
6252 (buffer-disable-undo)
6253 (let ((buffer-read-only nil))
6255 (let ((standard-output (current-buffer)))
6256 (display-completion-list (sort completions 'string<)))
6257 (goto-char (point-min))
6258 (delete-region (point) (progn (forward-line 3) (point))))))))))
6260 (defun message-expand-name ()
6261 (funcall message-expand-name-function))
6265 (defun message-talkative-question (ask question show &rest text)
6266 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6267 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6268 The following arguments may contain lists of values."
6270 (setq text (message-flatten-list text)))
6271 (save-window-excursion
6273 (with-output-to-temp-buffer " *MESSAGE information message*"
6274 (set-buffer " *MESSAGE information message*")
6275 (fundamental-mode) ; for Emacs 20.4+
6276 (mapcar 'princ text)
6277 (goto-char (point-min))))
6278 (funcall ask question))
6279 (funcall ask question)))
6281 (defun message-flatten-list (list)
6282 "Return a new, flat list that contains all elements of LIST.
6284 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6287 (apply 'append (mapcar 'message-flatten-list list)))
6291 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6292 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6293 Then clone the local variables and values from the old buffer to the
6294 new one, cloning only the locals having a substring matching the
6296 (let ((oldbuf (current-buffer)))
6298 (set-buffer (generate-new-buffer name))
6299 (message-clone-locals oldbuf varstr)
6302 (defun message-clone-locals (buffer &optional varstr)
6303 "Clone the local variables from BUFFER to the current buffer."
6304 (let ((locals (save-excursion
6306 (buffer-local-variables)))
6308 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
6311 (when (and (consp local)
6313 (string-match regexp (symbol-name (car local)))
6315 (string-match varstr (symbol-name (car local)))))
6317 (set (make-local-variable (car local))
6322 ;;; @ for MIME Edit mode
6325 (defun message-maybe-encode ()
6326 (when message-mime-mode
6327 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
6328 (let ((pgp-processing (with-current-buffer message-edit-buffer
6329 mime-edit-pgp-processing)))
6330 (setq mime-edit-pgp-processing pgp-processing))
6331 (run-hooks 'mime-edit-translate-hook)
6332 (if (catch 'mime-edit-error
6334 (mime-edit-pgp-enclose-buffer)
6335 (mime-edit-translate-body)))
6336 (error "Translation error!"))
6337 (run-hooks 'mime-edit-exit-hook)))
6339 (defun message-mime-insert-article (&optional full-headers)
6341 (let ((message-cite-function 'mime-edit-inserted-message-filter)
6342 (message-reply-buffer
6343 (message-get-parameter-with-eval 'original-buffer))
6345 (message-yank-original nil)
6347 (narrow-to-region (goto-char start)
6348 (if (search-forward "\n\n" nil t)
6351 (goto-char (point-min))
6352 (let ((message-included-forward-headers
6353 (if full-headers "" message-included-forward-headers)))
6354 (message-remove-header message-included-forward-headers t nil t))
6357 (set-alist 'mime-edit-message-inserter-alist
6358 'message-mode (function message-mime-insert-article))
6360 ;;; Miscellaneous functions
6362 ;; stolen (and renamed) from nnheader.el
6363 (static-if (fboundp 'subst-char-in-string)
6364 (defsubst message-replace-chars-in-string (string from to)
6365 (subst-char-in-string from to string))
6366 (defun message-replace-chars-in-string (string from to)
6367 "Replace characters in STRING from FROM to TO."
6368 (let ((string (substring string 0)) ;Copy string.
6369 (len (length string))
6371 ;; Replace all occurrences of FROM with TO.
6373 (when (= (aref string idx) from)
6374 (aset string idx to))
6375 (setq idx (1+ idx)))
6382 (defvar message-inhibit-body-encoding t)
6384 (defun message-encode-message-body ()
6385 (unless message-inhibit-body-encoding
6386 (let ((mail-parse-charset (or mail-parse-charset
6387 message-default-charset))
6388 (case-fold-search t)
6389 lines content-type-p)
6392 (narrow-to-region (point) (point-max))
6393 (let ((new (mml-generate-mime)))
6395 (delete-region (point-min) (point-max))
6397 (goto-char (point-min))
6398 (if (eq (aref new 0) ?\n)
6400 (search-forward "\n\n")
6401 (setq lines (buffer-substring (point-min) (1- (point))))
6402 (delete-region (point-min) (point))))))
6404 (message-narrow-to-headers-or-head)
6405 (message-remove-header "Mime-Version")
6406 (goto-char (point-max))
6407 (insert "MIME-Version: 1.0\n")
6410 (setq content-type-p
6412 (re-search-backward "^Content-Type:" nil t))))
6414 (message-narrow-to-headers-or-head)
6415 (message-remove-first-header "Content-Type")
6416 (message-remove-first-header "Content-Transfer-Encoding"))
6417 ;; We always make sure that the message has a Content-Type
6418 ;; header. This is because some broken MTAs and MUAs get
6419 ;; awfully confused when confronted with a message with a
6420 ;; MIME-Version header and without a Content-Type header. For
6421 ;; instance, Solaris' /usr/bin/mail.
6422 (unless content-type-p
6423 (goto-char (point-min))
6424 ;; For unknown reason, MIME-Version doesn't exist.
6425 (when (re-search-forward "^MIME-Version:" nil t)
6427 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6429 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6430 "Read from the minibuffer while providing abbrev expansion."
6431 (if (fboundp 'mail-abbrevs-setup)
6432 (let ((mail-abbrev-mode-regexp "")
6433 (minibuffer-setup-hook 'mail-abbrevs-setup)
6434 (minibuffer-local-map message-minibuffer-local-map))
6435 (read-from-minibuffer prompt initial-contents))
6436 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6437 (minibuffer-local-map message-minibuffer-local-map))
6438 (read-string prompt initial-contents))))
6440 (defun message-use-alternative-email-as-from ()
6441 (require 'mail-utils)
6442 (let* ((fields '("To" "Cc"))
6445 (mail-strip-quoted-names
6446 (mapconcat 'message-fetch-reply-field fields ","))
6450 (if (string-match message-alternative-emails (car emails))
6451 (setq email (car emails)
6454 (unless (or (not email) (equal email user-mail-address))
6455 (goto-char (point-max))
6456 (insert "From: " email "\n"))))
6458 (defun message-options-get (symbol)
6459 (cdr (assq symbol message-options)))
6461 (defun message-options-set (symbol value)
6462 (let ((the-cons (assq symbol message-options)))
6465 (setcdr the-cons value)
6466 (setq message-options (delq the-cons message-options)))
6468 (push (cons symbol value) message-options))))
6471 (defun message-options-set-recipient ()
6473 (message-narrow-to-headers-or-head)
6474 (message-options-set 'message-sender
6475 (mail-strip-quoted-names
6476 (message-fetch-field "from")))
6477 (message-options-set 'message-recipients
6478 (mail-strip-quoted-names
6479 (let ((to (message-fetch-field "to"))
6480 (cc (message-fetch-field "cc"))
6481 (bcc (message-fetch-field "bcc")))
6484 (if (and to cc) ", ")
6486 (if (and (or to cc) bcc) ", ")
6489 (when (featurep 'xemacs)
6490 (require 'messagexmas)
6491 (message-xmas-redefine))
6495 (run-hooks 'message-load-hook)
6498 ;; coding: iso-8859-1
6501 ;;; message.el ends here