1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
35 (defvar gnus-message-group-art)
36 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (if (featurep 'xemacs)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
50 (autoload 'sha1 "sha1-el")
51 (autoload 'gnus-find-method-for-group "gnus")
52 (autoload 'nnvirtual-find-group-art "nnvirtual"))
54 (defgroup message '((user-mail-address custom-variable)
55 (user-full-name custom-variable))
56 "Mail and news message composing."
57 :link '(custom-manual "(message)Top")
61 (put 'user-mail-address 'custom-type 'string)
62 (put 'user-full-name 'custom-type 'string)
64 (defgroup message-various nil
65 "Various Message Variables"
66 :link '(custom-manual "(message)Various Message Variables")
69 (defgroup message-buffers nil
71 :link '(custom-manual "(message)Message Buffers")
74 (defgroup message-sending nil
76 :link '(custom-manual "(message)Sending Variables")
79 (defgroup message-interface nil
81 :link '(custom-manual "(message)Interface")
84 (defgroup message-forwarding nil
86 :link '(custom-manual "(message)Forwarding")
87 :group 'message-interface)
89 (defgroup message-insertion nil
91 :link '(custom-manual "(message)Insertion")
94 (defgroup message-headers nil
96 :link '(custom-manual "(message)Message Headers")
99 (defgroup message-news nil
100 "Composing News Messages"
103 (defgroup message-mail nil
104 "Composing Mail Messages"
107 (defgroup message-faces nil
108 "Faces used for message composing."
112 (defcustom message-directory "~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group 'message-various
117 (defcustom message-max-buffers 10
118 "*How many buffers to keep before starting to kill them off."
119 :group 'message-buffers
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group 'message-buffers
125 :type '(choice function (const nil)))
127 (defcustom message-fcc-handler-function 'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
132 :type '(radio (function-item message-output)
133 (function :tag "Other"))
134 :group 'message-sending)
136 (defcustom message-fcc-externalize-attachments nil
137 "If non-nil, attachments are included as external parts in Fcc copies."
139 :group 'message-sending)
141 (defcustom message-courtesy-message
142 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
143 "*This is inserted at the start of a mailed copy of a posted message.
144 If the string contains the format spec \"%s\", the Newsgroups
145 the article has been posted to will be inserted there.
146 If this variable is nil, no such courtesy message will be added."
147 :group 'message-sending
150 (defcustom message-ignored-bounced-headers
151 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
152 "*Regexp that matches headers to be removed in resent bounced mail."
153 :group 'message-interface
157 (defcustom message-from-style 'default
158 "*Specifies how \"From\" headers look.
160 If nil, they contain just the return address like:
162 If `parens', they look like:
163 king@grassland.com (Elvis Parsley)
164 If `angles', they look like:
165 Elvis Parsley <king@grassland.com>
167 Otherwise, most addresses look like `angles', but they look like
168 `parens' if `angles' would need quoting and `parens' would not."
169 :type '(choice (const :tag "simple" nil)
173 :group 'message-headers)
175 (defcustom message-insert-canlock t
176 "Whether to insert a Cancel-Lock header in news postings."
178 :group 'message-headers
181 (defcustom message-syntax-checks
182 (if message-insert-canlock '((sender . disabled)) nil)
183 ;; Guess this one shouldn't be easy to customize...
184 "*Controls what syntax checks should not be performed on outgoing posts.
185 To disable checking of long signatures, for instance, add
186 `(signature . disabled)' to this list.
188 Don't touch this variable unless you really know what you're doing.
190 Checks include `subject-cmsg', `multiple-headers', `sendsys',
191 `message-id', `from', `long-lines', `control-chars', `size',
192 `new-text', `quoting-style', `redirected-followup', `signature',
193 `approved', `sender', `empty', `empty-headers', `message-id', `from',
194 `subject', `shorten-followup-to', `existing-newsgroups',
195 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
196 `continuation-headers', `long-header-lines', `invisible-text' and
199 :type '(repeat sexp)) ; Fixme: improve this
201 (defcustom message-required-headers '((optional . References)
203 "*Headers to be generated or prompted for when sending a message.
204 Also see `message-required-news-headers' and
205 `message-required-mail-headers'."
207 :group 'message-headers
208 :type '(repeat sexp))
210 (defcustom message-draft-headers '(References From)
211 "*Headers to be generated when saving a draft message."
213 :group 'message-headers
214 :type '(repeat sexp))
216 (defcustom message-required-news-headers
217 '(From Newsgroups Subject Date Message-ID
218 (optional . Organization)
219 (optional . User-Agent))
220 "*Headers to be generated or prompted for when posting an article.
221 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
222 Message-ID. Organization, Lines, In-Reply-To, Expires, and
223 User-Agent are optional. If don't you want message to insert some
224 header, remove it from this list."
226 :group 'message-headers
227 :type '(repeat sexp))
229 (defcustom message-required-mail-headers
230 '(From Subject Date (optional . In-Reply-To) Message-ID
231 (optional . User-Agent))
232 "*Headers to be generated or prompted for when mailing a message.
233 It is recommended that From, Date, To, Subject and Message-ID be
234 included. Organization and User-Agent are optional."
236 :group 'message-headers
237 :type '(repeat sexp))
239 (defcustom message-deletable-headers '(Message-ID Date Lines)
240 "Headers to be deleted if they already exist and were generated by message previously."
241 :group 'message-headers
244 (defcustom message-ignored-news-headers
245 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
246 "*Regexp of headers to be removed unconditionally before posting."
248 :group 'message-headers
251 (defcustom message-ignored-mail-headers
252 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
253 "*Regexp of headers to be removed unconditionally before mailing."
255 :group 'message-headers
258 (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:\\|^X-Hashcash:"
259 "*Header lines matching this regexp will be deleted before posting.
260 It's best to delete old Path and Date headers before posting to avoid
262 :group 'message-interface
265 (defcustom message-subject-re-regexp
266 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
267 "*Regexp matching \"Re: \" in the subject line."
268 :group 'message-various
271 ;;; Start of variables adopted from `message-utils.el'.
273 (defcustom message-subject-trailing-was-query 'ask
274 ;; should it default to nil or ask?
275 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
276 If nil, leave the subject unchanged. If it is the symbol `ask', query
277 the user what do do. In this case, the subject is matched against
278 `message-subject-trailing-was-ask-regexp'. If
279 `message-subject-trailing-was-query' is t, always strip the trailing
280 old subject. In this case, `message-subject-trailing-was-regexp' is
282 :type '(choice (const :tag "never" nil)
283 (const :tag "always strip" t)
285 :group 'message-various)
287 (defcustom message-subject-trailing-was-ask-regexp
288 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
289 "*Regexp matching \"(was: <old subject>)\" in the subject line.
291 The function `message-strip-subject-trailing-was' uses this regexp if
292 `message-subject-trailing-was-query' is set to the symbol `ask'. If
293 the variable is t instead of `ask', use
294 `message-subject-trailing-was-regexp' instead.
296 It is okay to create some false positives here, as the user is asked."
297 :group 'message-various
300 (defcustom message-subject-trailing-was-regexp
301 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
302 "*Regexp matching \"(was: <old subject>)\" in the subject line.
304 If `message-subject-trailing-was-query' is set to t, the subject is
305 matched against `message-subject-trailing-was-regexp' in
306 `message-strip-subject-trailing-was'. You should use a regexp creating very
307 few false positives here."
308 :group 'message-various
311 ;; Fixme: Why are all these things autoloaded?
313 ;;; marking inserted text
316 (defcustom message-mark-insert-begin
317 "--8<---------------cut here---------------start------------->8---\n"
318 "How to mark the beginning of some inserted text."
320 :group 'message-various)
323 (defcustom message-mark-insert-end
324 "--8<---------------cut here---------------end--------------->8---\n"
325 "How to mark the end of some inserted text."
327 :group 'message-various)
330 (defcustom message-archive-header
331 "X-No-Archive: Yes\n"
332 "Header to insert when you don't want your article to be archived.
333 Archives \(such as groups.googgle.com\) respect this header."
335 :group 'message-various)
338 (defcustom message-archive-note
339 "X-No-Archive: Yes - save http://groups.google.com/"
340 "Note to insert why you wouldn't want this posting archived.
341 If nil, don't insert any text in the body."
343 :group 'message-various)
345 ;;; Crossposts and Followups
346 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
347 ;; new suggestions by R. Weikusat <rw at another.de>
349 (defvar message-cross-post-old-target nil
350 "Old target for cross-posts or follow-ups.")
351 (make-variable-buffer-local 'message-cross-post-old-target)
354 (defcustom message-cross-post-default t
355 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
356 If nil, `message-cross-post-followup-to' will only do a followup. Note that
357 you can explicitly override this setting by calling
358 `message-cross-post-followup-to' with a prefix."
360 :group 'message-various)
363 (defcustom message-cross-post-note
364 "Crosspost & Followup-To: "
365 "Note to insert before signature to notify of cross-post and follow-up."
367 :group 'message-various)
370 (defcustom message-followup-to-note
372 "Note to insert before signature to notify of follow-up only."
374 :group 'message-various)
377 (defcustom message-cross-post-note-function
378 'message-cross-post-insert-note
379 "Function to use to insert note about Crosspost or Followup-To.
380 The function will be called with four arguments. The function should not only
381 insert a note, but also ensure old notes are deleted. See the documentation
382 for `message-cross-post-insert-note'."
384 :group 'message-various)
386 ;;; End of variables adopted from `message-utils.el'.
389 (defcustom message-signature-separator "^-- *$"
390 "Regexp matching the signature separator."
392 :group 'message-various)
394 (defcustom message-elide-ellipsis "\n[...]\n\n"
395 "*The string which is inserted for elided text."
397 :group 'message-various)
399 (defcustom message-interactive t
400 "Non-nil means when sending a message wait for and display errors.
401 nil means let mailer mail back a message to report errors."
402 :group 'message-sending
406 (defcustom message-generate-new-buffers 'unique
407 "*Non-nil means create a new message buffer whenever `message-setup' is called.
408 If this is a function, call that function with three parameters: The type,
409 the to address and the group name. (Any of these may be nil.) The function
410 should return the new buffer name."
411 :group 'message-buffers
412 :type '(choice (const :tag "off" nil)
413 (const :tag "unique" unique)
414 (const :tag "unsent" unsent)
417 (defcustom message-kill-buffer-on-exit nil
418 "*Non-nil means that the message buffer will be killed after sending a message."
419 :group 'message-buffers
423 (defvar gnus-local-organization))
424 (defcustom message-user-organization
425 (or (and (boundp 'gnus-local-organization)
426 (stringp gnus-local-organization)
427 gnus-local-organization)
428 (getenv "ORGANIZATION")
430 "*String to be used as an Organization header.
431 If t, use `message-user-organization-file'."
432 :group 'message-headers
433 :type '(choice string
434 (const :tag "consult file" t)))
437 (defcustom message-user-organization-file "/usr/lib/news/organization"
438 "*Local news organization file."
440 :group 'message-headers)
442 (defcustom message-make-forward-subject-function
443 'message-forward-subject-name-subject
444 "*List of functions called to generate subject headers for forwarded messages.
445 The subject generated by the previous function is passed into each
448 The provided functions are:
450 * `message-forward-subject-author-subject' (Source of article (author or
451 newsgroup)), in brackets followed by the subject
452 * `message-forward-subject-name-subject' (Source of article (name of author
453 or newsgroup)), in brackets followed by the subject
454 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
456 :group 'message-forwarding
457 :type '(radio (function-item message-forward-subject-author-subject)
458 (function-item message-forward-subject-fwd)
459 (repeat :tag "List of functions" function)))
461 (defcustom message-forward-as-mime t
462 "*Non-nil means forward messages as an inline/rfc822 MIME section.
463 Otherwise, directly inline the old message in the forwarded message."
465 :group 'message-forwarding
468 (defcustom message-forward-show-mml t
469 "*Non-nil means show forwarded messages as mml.
470 Otherwise, forwarded messages are unchanged."
472 :group 'message-forwarding
475 (defcustom message-forward-before-signature t
476 "*Non-nil means put forwarded message before signature, else after."
477 :group 'message-forwarding
480 (defcustom message-wash-forwarded-subjects nil
481 "*Non-nil means try to remove as much cruft as possible from the subject.
482 Done before generating the new subject of a forward."
483 :group 'message-forwarding
486 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
487 "*All headers that match this regexp will be deleted when resending a message."
488 :group 'message-interface
491 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
492 "*All headers that match this regexp will be deleted when forwarding a message."
494 :group 'message-forwarding
495 :type '(choice (const :tag "None" nil)
498 (defcustom message-ignored-cited-headers "."
499 "*Delete these headers from the messages you yank."
500 :group 'message-insertion
503 (defcustom message-cite-prefix-regexp
504 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
505 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
506 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
507 (let ((old-table (syntax-table))
508 non-word-constituents)
509 (set-syntax-table text-mode-syntax-table)
510 (setq non-word-constituents
512 (if (string-match "\\w" "-") "" "-")
513 (if (string-match "\\w" "_") "" "_")
514 (if (string-match "\\w" ".") "" ".")))
515 (set-syntax-table old-table)
516 (if (equal non-word-constituents "")
517 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
518 (concat "\\([ \t]*\\(\\w\\|["
519 non-word-constituents
520 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
521 "*Regexp matching the longest possible citation prefix on a line."
522 :group 'message-insertion
525 (defcustom message-cancel-message "I am canceling my own article.\n"
526 "Message to be inserted in the cancel message."
527 :group 'message-interface
530 ;; Useful to set in site-init.el
532 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
533 "Function to call to send the current buffer as mail.
534 The headers should be delimited by a line whose contents match the
535 variable `mail-header-separator'.
537 Valid values include `message-send-mail-with-sendmail' (the default),
538 `message-send-mail-with-mh', `message-send-mail-with-qmail',
539 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
541 See also `send-mail-function'."
542 :type '(radio (function-item message-send-mail-with-sendmail)
543 (function-item message-send-mail-with-mh)
544 (function-item message-send-mail-with-qmail)
545 (function-item message-smtpmail-send-it)
546 (function-item smtpmail-send-it)
547 (function-item feedmail-send-it)
548 (function :tag "Other"))
549 :group 'message-sending
550 :group 'message-mail)
552 (defcustom message-send-news-function 'message-send-news
553 "Function to call to send the current buffer as news.
554 The headers should be delimited by a line whose contents match the
555 variable `mail-header-separator'."
556 :group 'message-sending
560 (defcustom message-reply-to-function nil
561 "If non-nil, function that should return a list of headers.
562 This function should pick out addresses from the To, Cc, and From headers
563 and respond with new To and Cc headers."
564 :group 'message-interface
565 :type '(choice function (const nil)))
567 (defcustom message-wide-reply-to-function nil
568 "If non-nil, function that should return a list of headers.
569 This function should pick out addresses from the To, Cc, and From headers
570 and respond with new To and Cc headers."
571 :group 'message-interface
572 :type '(choice function (const nil)))
574 (defcustom message-followup-to-function nil
575 "If non-nil, function that should return a list of headers.
576 This function should pick out addresses from the To, Cc, and From headers
577 and respond with new To and Cc headers."
578 :group 'message-interface
579 :type '(choice function (const nil)))
581 (defcustom message-use-followup-to 'ask
582 "*Specifies what to do with Followup-To header.
583 If nil, always ignore the header. If it is t, use its value, but
584 query before using the \"poster\" value. If it is the symbol `ask',
585 always query the user whether to use the value. If it is the symbol
586 `use', always use the value."
587 :group 'message-interface
588 :type '(choice (const :tag "ignore" nil)
589 (const :tag "use & query" t)
593 (defcustom message-use-mail-followup-to 'use
594 "*Specifies what to do with Mail-Followup-To header.
595 If nil, always ignore the header. If it is the symbol `ask', always
596 query the user whether to use the value. If it is the symbol `use',
597 always use the value."
598 :group 'message-interface
599 :type '(choice (const :tag "ignore" nil)
603 (defcustom message-subscribed-address-functions nil
604 "*Specifies functions for determining list subscription.
605 If nil, do not attempt to determine list subscribtion with functions.
606 If non-nil, this variable contains a list of functions which return
607 regular expressions to match lists. These functions can be used in
608 conjunction with `message-subscribed-regexps' and
609 `message-subscribed-addresses'."
610 :group 'message-interface
611 :type '(repeat sexp))
613 (defcustom message-subscribed-address-file nil
614 "*A file containing addresses the user is subscribed to.
615 If nil, do not look at any files to determine list subscriptions. If
616 non-nil, each line of this file should be a mailing list address."
617 :group 'message-interface
620 (defcustom message-subscribed-addresses nil
621 "*Specifies a list of addresses the user is subscribed to.
622 If nil, do not use any predefined list subscriptions. This list of
623 addresses can be used in conjuction with
624 `message-subscribed-address-functions' and `message-subscribed-regexps'."
625 :group 'message-interface
626 :type '(repeat string))
628 (defcustom message-subscribed-regexps nil
629 "*Specifies a list of addresses the user is subscribed to.
630 If nil, do not use any predefined list subscriptions. This list of
631 regular expressions can be used in conjuction with
632 `message-subscribed-address-functions' and `message-subscribed-addresses'."
633 :group 'message-interface
634 :type '(repeat regexp))
636 (defcustom message-allow-no-recipients 'ask
637 "Specifies what to do when there are no recipients other than Gcc/Fcc.
638 If it is the symbol `always', the posting is allowed. If it is the
639 symbol `never', the posting is not allowed. If it is the symbol
640 `ask', you are prompted."
641 :group 'message-interface
642 :type '(choice (const always)
646 (defcustom message-sendmail-f-is-evil nil
647 "*Non-nil means don't add \"-f username\" to the sendmail command line.
648 Doing so would be even more evil than leaving it out."
649 :group 'message-sending
652 (defcustom message-sendmail-envelope-from nil
653 "*Envelope-from when sending mail with sendmail.
654 If this is nil, use `user-mail-address'. If it is the symbol
655 `header', use the From: header of the message."
656 :type '(choice (string :tag "From name")
657 (const :tag "Use From: header from message" header)
658 (const :tag "Use `user-mail-address'" nil))
659 :group 'message-sending)
661 ;; qmail-related stuff
662 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
663 "Location of the qmail-inject program."
664 :group 'message-sending
667 (defcustom message-qmail-inject-args nil
668 "Arguments passed to qmail-inject programs.
669 This should be a list of strings, one string for each argument. It
670 may also be a function.
672 For e.g., if you wish to set the envelope sender address so that bounces
673 go to the right place or to deal with listserv's usage of that address, you
674 might set this variable to '(\"-f\" \"you@some.where\")."
675 :group 'message-sending
676 :type '(choice (function)
679 (defvar message-cater-to-broken-inn t
680 "Non-nil means Gnus should not fold the `References' header.
681 Folding `References' makes ancient versions of INN create incorrect
685 (defvar gnus-post-method)
686 (defvar gnus-select-method))
687 (defcustom message-post-method
688 (cond ((and (boundp 'gnus-post-method)
689 (listp gnus-post-method)
692 ((boundp 'gnus-select-method)
695 "*Method used to post news.
696 Note that when posting from inside Gnus, for instance, this
697 variable isn't used."
699 :group 'message-sending
700 ;; This should be the `gnus-select-method' widget, but that might
701 ;; create a dependence to `gnus.el'.
704 ;; FIXME: This should be a temporary workaround until someone implements a
705 ;; proper solution. If a crash happens while replying, the auto-save file
706 ;; will *not* have a `References:' header if `message-generate-headers-first'
707 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
708 (defcustom message-generate-headers-first '(references)
709 "*If non-nil, generate all required headers before composing.
710 The variables `message-required-news-headers' and
711 `message-required-mail-headers' specify which headers to generate.
712 This can also be a list of headers that should be generated before
715 Note that the variable `message-deletable-headers' specifies headers which
716 are to be deleted and then re-generated before sending, so this variable
717 will not have a visible effect for those headers."
718 :group 'message-headers
719 :type '(choice (const :tag "None" nil)
720 (const :tag "References" '(references))
722 (repeat (sexp :tag "Header"))))
724 (defcustom message-setup-hook nil
725 "Normal hook, run each time a new outgoing message is initialized.
726 The function `message-setup' runs this hook."
727 :group 'message-various
730 (defcustom message-cancel-hook nil
731 "Hook run when cancelling articles."
732 :group 'message-various
735 (defcustom message-signature-setup-hook nil
736 "Normal hook, run each time a new outgoing message is initialized.
737 It is run after the headers have been inserted and before
738 the signature is inserted."
739 :group 'message-various
742 (defcustom message-mode-hook nil
743 "Hook run in message mode buffers."
744 :group 'message-various
747 (defcustom message-header-hook nil
748 "Hook run in a message mode buffer narrowed to the headers."
749 :group 'message-various
752 (defcustom message-header-setup-hook nil
753 "Hook called narrowed to the headers when setting up a message buffer."
754 :group 'message-various
757 (defcustom message-minibuffer-local-map
758 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
759 (set-keymap-parent map minibuffer-local-map)
761 "Keymap for `message-read-from-minibuffer'.")
764 (defcustom message-citation-line-function 'message-insert-citation-line
765 "*Function called to insert the \"Whomever writes:\" line.
767 Note that Gnus provides a feature where the reader can click on
768 `writes:' to hide the cited text. If you change this line too much,
769 people who read your message will have to change their Gnus
770 configuration. See the variable `gnus-cite-attribution-suffix'."
772 :group 'message-insertion)
775 (defcustom message-yank-prefix "> "
776 "*Prefix inserted on the lines of yanked messages.
777 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
778 See also `message-yank-cited-prefix'."
780 :group 'message-insertion)
782 (defcustom message-yank-cited-prefix ">"
783 "*Prefix inserted on cited or empty lines of yanked messages.
784 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
785 See also `message-yank-prefix'."
787 :group 'message-insertion)
789 (defcustom message-indentation-spaces 3
790 "*Number of spaces to insert at the beginning of each cited line.
791 Used by `message-yank-original' via `message-yank-cite'."
792 :group 'message-insertion
796 (defcustom message-cite-function 'message-cite-original
797 "*Function for citing an original message.
798 Predefined functions include `message-cite-original' and
799 `message-cite-original-without-signature'.
800 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
801 :type '(radio (function-item message-cite-original)
802 (function-item message-cite-original-without-signature)
803 (function-item sc-cite-original)
804 (function :tag "Other"))
805 :group 'message-insertion)
808 (defcustom message-indent-citation-function 'message-indent-citation
809 "*Function for modifying a citation just inserted in the mail buffer.
810 This can also be a list of functions. Each function can find the
811 citation between (point) and (mark t). And each function should leave
812 point and mark around the citation text as modified."
814 :group 'message-insertion)
817 (defcustom message-signature t
818 "*String to be inserted at the end of the message buffer.
819 If t, the `message-signature-file' file will be inserted instead.
820 If a function, the result from the function will be used instead.
821 If a form, the result from the form will be used instead."
823 :group 'message-insertion)
826 (defcustom message-signature-file "~/.signature"
827 "*Name of file containing the text inserted at end of message buffer.
828 Ignored if the named file doesn't exist.
829 If nil, don't insert a signature."
830 :type '(choice file (const :tags "None" nil))
831 :group 'message-insertion)
834 (defcustom message-signature-insert-empty-line t
835 "*If non-nil, insert an empty line before the signature separator."
837 :group 'message-insertion)
839 (defcustom message-distribution-function nil
840 "*Function called to return a Distribution header."
842 :group 'message-headers
843 :type '(choice function (const nil)))
845 (defcustom message-expires 14
846 "Number of days before your article expires."
848 :group 'message-headers
849 :link '(custom-manual "(message)News Headers")
852 (defcustom message-user-path nil
853 "If nil, use the NNTP server name in the Path header.
854 If stringp, use this; if non-nil, use no host name (user name only)."
856 :group 'message-headers
857 :link '(custom-manual "(message)News Headers")
858 :type '(choice (const :tag "nntp" nil)
860 (sexp :tag "none" :format "%t" t)))
862 (defvar message-reply-buffer nil)
863 (defvar message-reply-headers nil
864 "The headers of the current replied article.
865 It is a vector of the following headers:
866 \[number subject from date id references chars lines xref extra].")
867 (defvar message-newsreader nil)
868 (defvar message-mailer nil)
869 (defvar message-sent-message-via nil)
870 (defvar message-checksum nil)
871 (defvar message-send-actions nil
872 "A list of actions to be performed upon successful sending of a message.")
873 (defvar message-exit-actions nil
874 "A list of actions to be performed upon exiting after sending a message.")
875 (defvar message-kill-actions nil
876 "A list of actions to be performed before killing a message buffer.")
877 (defvar message-postpone-actions nil
878 "A list of actions to be performed after postponing a message.")
880 (define-widget 'message-header-lines 'text
881 "All header lines must be LFD terminated."
882 :format "%{%t%}:%n%v"
884 :error "All header lines must be newline terminated")
886 (defcustom message-default-headers ""
887 "*A string containing header lines to be inserted in outgoing messages.
888 It is inserted before you edit the message, so you can edit or delete
890 :group 'message-headers
891 :type 'message-header-lines)
893 (defcustom message-default-mail-headers ""
894 "*A string of header lines to be inserted in outgoing mails."
895 :group 'message-headers
897 :type 'message-header-lines)
899 (defcustom message-default-news-headers ""
900 "*A string of header lines to be inserted in outgoing news articles."
901 :group 'message-headers
903 :type 'message-header-lines)
905 ;; Note: could use /usr/ucb/mail instead of sendmail;
906 ;; options -t, and -v if not interactive.
907 (defcustom message-mailer-swallows-blank-line
908 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
909 system-configuration)
910 (file-readable-p "/etc/sendmail.cf")
911 (let ((buffer (get-buffer-create " *temp*")))
915 (insert-file-contents "/etc/sendmail.cf")
916 (goto-char (point-min))
917 (let ((case-fold-search nil))
918 (re-search-forward "^OR\\>" nil t)))
919 (kill-buffer buffer))))
920 ;; According to RFC822, "The field-name must be composed of printable
921 ;; ASCII characters (i. e., characters that have decimal values between
922 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
924 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
925 "*Set this non-nil if the system's mailer runs the header and body together.
926 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
927 The value should be an expression to test whether the problem will
929 :group 'message-sending
933 (define-mail-user-agent 'message-user-agent
934 'message-mail 'message-send-and-exit
935 'message-kill-buffer 'message-send-hook)
937 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
938 "If non-nil, delete the deletable headers before feeding to mh.")
940 (defvar message-send-method-alist
941 '((news message-news-p message-send-via-news)
942 (mail message-mail-p message-send-via-mail))
943 "Alist of ways to send outgoing messages.
944 Each element has the form
946 \(TYPE PREDICATE FUNCTION)
948 where TYPE is a symbol that names the method; PREDICATE is a function
949 called without any parameters to determine whether the message is
950 a message of type TYPE; and FUNCTION is a function to be called if
951 PREDICATE returns non-nil. FUNCTION is called with one parameter --
954 (defcustom message-mail-alias-type 'abbrev
955 "*What alias expansion type to use in Message buffers.
956 The default is `abbrev', which uses mailabbrev. nil switches
959 :link '(custom-manual "(message)Mail Aliases")
960 :type '(choice (const :tag "Use Mailabbrev" abbrev)
961 (const :tag "No expansion" nil)))
963 (defcustom message-auto-save-directory
964 (file-name-as-directory (nnheader-concat message-directory "drafts"))
965 "*Directory where Message auto-saves buffers if Gnus isn't running.
966 If nil, Message won't auto-save."
967 :group 'message-buffers
968 :type '(choice directory (const :tag "Don't auto-save" nil)))
970 (defcustom message-default-charset
971 (and (not (mm-multibyte-p)) 'iso-8859-1)
972 "Default charset used in non-MULE Emacsen.
973 If nil, you might be asked to input the charset."
978 (defcustom message-dont-reply-to-names
979 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
980 "*A regexp specifying addresses to prune when doing wide replies.
981 A value of nil means exclude your own user name only."
984 :type '(choice (const :tag "Yourself" nil)
987 (defvar message-shoot-gnksa-feet nil
988 "*A list of GNKSA feet you are allowed to shoot.
989 Gnus gives you all the opportunity you could possibly want for
990 shooting yourself in the foot. Also, Gnus allows you to shoot the
991 feet of Good Net-Keeping Seal of Approval. The following are foot
993 `empty-article' Allow you to post an empty article;
994 `quoted-text-only' Allow you to post quoted text only;
995 `multiple-copies' Allow you to post multiple copies;
996 `cancel-messages' Allow you to cancel or supersede messages from
997 your other email addresses.")
999 (defsubst message-gnksa-enable-p (feature)
1000 (or (not (listp message-shoot-gnksa-feet))
1001 (memq feature message-shoot-gnksa-feet)))
1003 (defcustom message-hidden-headers nil
1004 "Regexp of headers to be hidden when composing new messages.
1005 This can also be a list of regexps to match headers. Or a list
1006 starting with `not' and followed by regexps.."
1008 :type '(repeat regexp))
1010 ;;; Internal variables.
1011 ;;; Well, not really internal.
1013 (defvar message-mode-syntax-table
1014 (let ((table (copy-syntax-table text-mode-syntax-table)))
1015 (modify-syntax-entry ?% ". " table)
1016 (modify-syntax-entry ?> ". " table)
1017 (modify-syntax-entry ?< ". " table)
1019 "Syntax table used while in Message mode.")
1021 (defface message-header-to-face
1024 (:foreground "green2" :bold t))
1027 (:foreground "MidnightBlue" :bold t))
1029 (:bold t :italic t)))
1030 "Face used for displaying From headers."
1031 :group 'message-faces)
1033 (defface message-header-cc-face
1036 (:foreground "green4" :bold t))
1039 (:foreground "MidnightBlue"))
1042 "Face used for displaying Cc headers."
1043 :group 'message-faces)
1045 (defface message-header-subject-face
1048 (:foreground "green3"))
1051 (:foreground "navy blue" :bold t))
1054 "Face used for displaying subject headers."
1055 :group 'message-faces)
1057 (defface message-header-newsgroups-face
1060 (:foreground "yellow" :bold t :italic t))
1063 (:foreground "blue4" :bold t :italic t))
1065 (:bold t :italic t)))
1066 "Face used for displaying newsgroups headers."
1067 :group 'message-faces)
1069 (defface message-header-other-face
1072 (:foreground "#b00000"))
1075 (:foreground "steel blue"))
1077 (:bold t :italic t)))
1078 "Face used for displaying newsgroups headers."
1079 :group 'message-faces)
1081 (defface message-header-name-face
1084 (:foreground "DarkGreen"))
1087 (:foreground "cornflower blue"))
1090 "Face used for displaying header names."
1091 :group 'message-faces)
1093 (defface message-header-xheader-face
1096 (:foreground "blue"))
1099 (:foreground "blue"))
1102 "Face used for displaying X-Header headers."
1103 :group 'message-faces)
1105 (defface message-separator-face
1108 (:foreground "blue3"))
1111 (:foreground "brown"))
1114 "Face used for displaying the separator."
1115 :group 'message-faces)
1117 (defface message-cited-text-face
1120 (:foreground "red"))
1123 (:foreground "red"))
1126 "Face used for displaying cited text names."
1127 :group 'message-faces)
1129 (defface message-mml-face
1132 (:foreground "ForestGreen"))
1135 (:foreground "ForestGreen"))
1138 "Face used for displaying MML."
1139 :group 'message-faces)
1141 (defun message-font-lock-make-header-matcher (regexp)
1144 (let ((start (point)))
1147 (goto-char (point-min))
1148 (if (re-search-forward
1149 (concat "^" (regexp-quote mail-header-separator) "$")
1151 (setq limit (min limit (match-beginning 0))))
1153 (and (< start limit)
1154 (re-search-forward ,regexp limit t))))))
1155 (if (featurep 'bytecomp)
1159 (defvar message-font-lock-keywords
1160 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1161 `((,(message-font-lock-make-header-matcher
1162 (concat "^\\([Tt]o:\\)" content))
1163 (1 'message-header-name-face)
1164 (2 'message-header-to-face nil t))
1165 (,(message-font-lock-make-header-matcher
1166 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1167 (1 'message-header-name-face)
1168 (2 'message-header-cc-face nil t))
1169 (,(message-font-lock-make-header-matcher
1170 (concat "^\\([Ss]ubject:\\)" content))
1171 (1 'message-header-name-face)
1172 (2 'message-header-subject-face nil t))
1173 (,(message-font-lock-make-header-matcher
1174 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1175 (1 'message-header-name-face)
1176 (2 'message-header-newsgroups-face nil t))
1177 (,(message-font-lock-make-header-matcher
1178 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1179 (1 'message-header-name-face)
1180 (2 'message-header-other-face nil t))
1181 (,(message-font-lock-make-header-matcher
1182 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1183 (1 'message-header-name-face)
1184 (2 'message-header-name-face))
1185 ,@(if (and mail-header-separator
1186 (not (equal mail-header-separator "")))
1187 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1188 1 'message-separator-face))
1191 (re-search-forward (concat "^\\("
1192 message-cite-prefix-regexp
1195 (0 'message-cited-text-face))
1196 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1197 (0 'message-mml-face))))
1198 "Additional expressions to highlight in Message mode.")
1201 ;; XEmacs does it like this. For Emacs, we have to set the
1202 ;; `font-lock-defaults' buffer-local variable.
1203 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1205 (defvar message-face-alist
1206 '((bold . bold-region)
1207 (underline . underline-region)
1208 (default . (lambda (b e)
1210 (ununderline-region b e))))
1211 "Alist of mail and news faces for facemenu.
1212 The cdr of each entry is a function for applying the face to a region.")
1214 (defcustom message-send-hook nil
1215 "Hook run before sending messages.
1216 This hook is run quite early when sending."
1217 :group 'message-various
1218 :options '(ispell-message)
1221 (defcustom message-send-mail-hook nil
1222 "Hook run before sending mail messages.
1223 This hook is run very late -- just before the message is sent as
1225 :group 'message-various
1228 (defcustom message-send-news-hook nil
1229 "Hook run before sending news messages.
1230 This hook is run very late -- just before the message is sent as
1232 :group 'message-various
1235 (defcustom message-sent-hook nil
1236 "Hook run after sending messages."
1237 :group 'message-various
1240 (defvar message-send-coding-system 'binary
1241 "Coding system to encode outgoing mail.")
1243 (defvar message-draft-coding-system
1244 mm-auto-save-coding-system
1245 "*Coding system to compose mail.
1246 If you'd like to make it possible to share draft files between XEmacs
1247 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1248 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1250 (defcustom message-send-mail-partially-limit 1000000
1251 "The limitation of messages sent as message/partial.
1252 The lower bound of message size in characters, beyond which the message
1253 should be sent in several parts. If it is nil, the size is unlimited."
1255 :group 'message-buffers
1256 :type '(choice (const :tag "unlimited" nil)
1259 (defcustom message-alternative-emails nil
1260 "A regexp to match the alternative email addresses.
1261 The first matched address (not primary one) is used in the From field."
1262 :group 'message-headers
1263 :type '(choice (const :tag "Always use primary" nil)
1266 (defcustom message-hierarchical-addresses nil
1267 "A list of hierarchical mail address definitions.
1269 Inside each entry, the first address is the \"top\" address, and
1270 subsequent addresses are subaddresses; this is used to indicate that
1271 mail sent to the first address will automatically be delivered to the
1272 subaddresses. So if the first address appears in the recipient list
1273 for a message, the subaddresses will be removed (if present) before
1274 the mail is sent. All addresses in this structure should be
1276 :group 'message-headers
1277 :type '(repeat (repeat string)))
1279 (defcustom message-mail-user-agent nil
1280 "Like `mail-user-agent'.
1281 Except if it is nil, use Gnus native MUA; if it is t, use
1283 :type '(radio (const :tag "Gnus native"
1286 (const :tag "`mail-user-agent'"
1289 (function-item :tag "Default Emacs mail"
1291 sendmail-user-agent)
1292 (function-item :tag "Emacs interface to MH"
1295 (function :tag "Other"))
1299 (defcustom message-wide-reply-confirm-recipients nil
1300 "Whether to confirm a wide reply to multiple email recipients.
1301 If this variable is nil, don't ask whether to reply to all recipients.
1302 If this variable is non-nil, pose the question \"Reply to all
1303 recipients?\" before a wide reply to multiple recipients. If the user
1304 answers yes, reply to all recipients as usual. If the user answers
1305 no, only reply back to the author."
1307 :group 'message-headers
1310 (defcustom message-user-fqdn nil
1311 "*Domain part of Messsage-Ids."
1312 :group 'message-headers
1313 :link '(custom-manual "(message)News Headers")
1316 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1318 (mm-coding-system-p 'utf-8)
1319 (executable-find idna-program)
1321 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1322 :group 'message-headers
1323 :type '(choice (const :tag "Ask" ask)
1324 (const :tag "Never" nil)
1325 (const :tag "Always" t)))
1327 ;;; Internal variables.
1329 (defvar message-sending-message "Sending...")
1330 (defvar message-buffer-list nil)
1331 (defvar message-this-is-news nil)
1332 (defvar message-this-is-mail nil)
1333 (defvar message-draft-article nil)
1334 (defvar message-mime-part nil)
1335 (defvar message-posting-charset nil)
1337 ;; Byte-compiler warning
1339 (defvar gnus-active-hashtb)
1340 (defvar gnus-read-active-file))
1342 ;;; Regexp matching the delimiter of messages in UNIX mail format
1343 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1344 ;;; of rmail.el's rmail-unix-mail-delimiter.
1345 (defvar message-unix-mail-delimiter
1346 (let ((time-zone-regexp
1347 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1348 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1354 ;; Many things can happen to an RFC 822 mailbox before it is put into
1355 ;; a `From' line. The leading phrase can be stripped, e.g.
1356 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1357 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1358 ;; can be removed, e.g.
1359 ;; From: joe@y.z (Joe K
1361 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1364 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1365 ;; The mailbox can be removed or be replaced by white space, e.g.
1366 ;; From: "Joe User"{space}{tab}
1368 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1369 ;; where {space} and {tab} represent the Ascii space and tab characters.
1370 ;; We want to match the results of any of these manglings.
1371 ;; The following regexp rejects names whose first characters are
1372 ;; obviously bogus, but after that anything goes.
1373 "\\([^\0-\b\n-\r\^?].*\\)?"
1375 ;; The time the message was sent.
1376 "\\([^\0-\r \^?]+\\) +" ; day of the week
1377 "\\([^\0-\r \^?]+\\) +" ; month
1378 "\\([0-3]?[0-9]\\) +" ; day of month
1379 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1381 ;; Perhaps a time zone, specified by an abbreviation, or by a
1386 " \\([0-9][0-9]+\\) *"
1388 ;; On some systems the time zone can appear after the year, too.
1392 "\\(remote from .*\\)?"
1395 "Regexp matching the delimiter of messages in UNIX mail format.")
1397 (defvar message-unsent-separator
1398 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1399 "^ *---+ +Returned message +---+ *$\\|"
1400 "^Start of returned message$\\|"
1401 "^ *---+ +Original message +---+ *$\\|"
1402 "^ *--+ +begin message +--+ *$\\|"
1403 "^ *---+ +Original message follows +---+ *$\\|"
1404 "^ *---+ +Undelivered message follows +---+ *$\\|"
1405 "^|? *---+ +Message text follows: +---+ *|?$")
1406 "A regexp that matches the separator before the text of a failed message.")
1408 (defvar message-header-format-alist
1410 (To . message-fill-address)
1411 (Cc . message-fill-address)
1422 (References . message-shorten-references)
1424 "Alist used for formatting headers.")
1426 (defvar message-options nil
1427 "Some saved answers when sending message.")
1429 (defvar message-send-mail-real-function nil
1430 "Internal send mail function.")
1432 (defvar message-bogus-system-names "^localhost\\."
1433 "The regexp of bogus system names.")
1435 (defcustom message-valid-fqdn-regexp
1436 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1438 "\\([a-z][a-z]" ;; two letter country TDLs
1439 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1440 "\\|aero\\|coop\\|info\\|name\\|museum"
1441 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1443 "Regular expression that matches a valid FQDN."
1444 ;; see also: gnus-button-valid-fqdn-regexp
1445 :group 'message-headers
1449 (autoload 'message-setup-toolbar "messagexmas")
1450 (autoload 'mh-new-draft-name "mh-comp")
1451 (autoload 'mh-send-letter "mh-comp")
1452 (autoload 'gnus-point-at-eol "gnus-util")
1453 (autoload 'gnus-point-at-bol "gnus-util")
1454 (autoload 'gnus-output-to-rmail "gnus-util")
1455 (autoload 'gnus-output-to-mail "gnus-util")
1456 (autoload 'nndraft-request-associate-buffer "nndraft")
1457 (autoload 'nndraft-request-expire-articles "nndraft")
1458 (autoload 'gnus-open-server "gnus-int")
1459 (autoload 'gnus-request-post "gnus-int")
1460 (autoload 'gnus-alive-p "gnus-util")
1461 (autoload 'gnus-server-string "gnus")
1462 (autoload 'gnus-group-name-charset "gnus-group")
1463 (autoload 'gnus-group-name-decode "gnus-group")
1464 (autoload 'gnus-groups-from-server "gnus")
1465 (autoload 'rmail-output "rmailout")
1466 (autoload 'gnus-delay-article "gnus-delay")
1467 (autoload 'gnus-make-local-hook "gnus-util"))
1472 ;;; Utility functions.
1475 (defmacro message-y-or-n-p (question show &rest text)
1476 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1477 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1479 (defmacro message-delete-line (&optional n)
1480 "Delete the current line (and the next N lines)."
1481 `(delete-region (progn (beginning-of-line) (point))
1482 (progn (forward-line ,(or n 1)) (point))))
1484 (defun message-mark-active-p ()
1485 "Non-nil means the mark and region are currently active in this buffer."
1488 (defun message-unquote-tokens (elems)
1489 "Remove double quotes (\") from strings in list ELEMS."
1490 (mapcar (lambda (item)
1491 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1492 (setq item (concat (match-string 1 item)
1493 (match-string 2 item))))
1497 (defun message-tokenize-header (header &optional separator)
1498 "Split HEADER into a list of header elements.
1499 SEPARATOR is a string of characters to be used as separators. \",\"
1500 is used by default."
1503 (let ((regexp (format "[%s]+" (or separator ",")))
1508 (mm-enable-multibyte)
1510 (goto-char (point-min))
1515 (cond ((and (> (point) beg)
1517 (and (looking-at regexp)
1520 (push (buffer-substring beg (point)) elems)
1521 (setq beg (match-end 0)))
1522 ((eq (char-after) ?\")
1523 (setq quoted (not quoted)))
1524 ((and (eq (char-after) ?\()
1527 ((and (eq (char-after) ?\))
1530 (nreverse elems)))))
1532 (defun message-mail-file-mbox-p (file)
1533 "Say whether FILE looks like a Unix mbox file."
1534 (when (and (file-exists-p file)
1535 (file-readable-p file)
1536 (file-regular-p file))
1538 (nnheader-insert-file-contents file)
1539 (goto-char (point-min))
1540 (looking-at message-unix-mail-delimiter))))
1542 (defun message-fetch-field (header &optional not-all)
1543 "The same as `mail-fetch-field', only remove all newlines.
1544 The buffer is expected to be narrowed to just the header of the message;
1545 see `message-narrow-to-headers-or-head'."
1546 (let* ((inhibit-point-motion-hooks t)
1547 (case-fold-search t)
1548 (value (mail-fetch-field header nil (not not-all))))
1550 (while (string-match "\n[\t ]+" value)
1551 (setq value (replace-match " " t t value)))
1552 (set-text-properties 0 (length value) nil value)
1555 (defun message-narrow-to-field ()
1556 "Narrow the buffer to the header on the current line."
1562 (if (re-search-forward "^[^ \n\t]" nil t)
1567 (goto-char (point-min)))
1569 (defun message-add-header (&rest headers)
1570 "Add the HEADERS to the message header, skipping those already present."
1573 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1574 (error "Invalid header `%s'" (car headers)))
1575 (setq hclean (match-string 1 (car headers)))
1577 (message-narrow-to-headers)
1578 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1579 (goto-char (point-max))
1580 (if (string-match "\n$" (car headers))
1581 (insert (car headers))
1582 (insert (car headers) ?\n)))))
1583 (setq headers (cdr headers))))
1585 (defmacro message-with-reply-buffer (&rest forms)
1586 "Evaluate FORMS in the reply buffer, if it exists."
1587 `(when (and message-reply-buffer
1588 (buffer-name message-reply-buffer))
1590 (set-buffer message-reply-buffer)
1593 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1594 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1596 (defun message-fetch-reply-field (header)
1597 "Fetch field HEADER from the message we're replying to."
1598 (message-with-reply-buffer
1600 (mail-narrow-to-head)
1601 (message-fetch-field header))))
1603 (defun message-strip-list-identifiers (subject)
1604 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1605 (require 'gnus-sum) ; for gnus-list-identifiers
1606 (let ((regexp (if (stringp gnus-list-identifiers)
1607 gnus-list-identifiers
1608 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1609 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1610 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1611 (concat (substring subject 0 (match-beginning 1))
1612 (or (match-string 3 subject)
1613 (match-string 5 subject))
1618 (defun message-strip-subject-re (subject)
1619 "Remove \"Re:\" from subject lines in string SUBJECT."
1620 (if (string-match message-subject-re-regexp subject)
1621 (substring subject (match-end 0))
1624 ;;; Start of functions adopted from `message-utils.el'.
1626 (defun message-strip-subject-trailing-was (subject)
1627 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1628 Leading \"Re: \" is not stripped by this function. Use the function
1629 `message-strip-subject-re' for this."
1630 (let* ((query message-subject-trailing-was-query)
1635 message-subject-trailing-was-ask-regexp
1636 message-subject-trailing-was-regexp)
1639 (setq new (substring subject 0 (match-beginning 0))))
1640 (if (or (not found) (eq query nil))
1643 (if (message-y-or-n-p
1644 "Strip `(was: <old subject>)' in subject? " t
1646 "Strip `(was: <old subject>)' in subject "
1647 "and use the new one instead?\n\n"
1648 "Current subject is: \""
1650 "New subject would be: \""
1652 "See the variable `message-subject-trailing-was-query' "
1653 "to get rid of this query."
1658 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1661 (defun message-change-subject (new-subject)
1662 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1665 (read-from-minibuffer "New subject: ")))
1666 (cond ((and (not (or (null new-subject) ; new subject not empty
1667 (zerop (string-width new-subject))
1668 (string-match "^[ \t]*$" new-subject))))
1672 (message-narrow-to-headers)
1673 (message-fetch-field "Subject"))))
1674 (cond ((not old-subject)
1675 (error "No current subject"))
1678 (regexp-quote new-subject)
1680 old-subject)) ; yes, it really is a new subject
1681 ;; delete eventual Re: prefix
1683 (message-strip-subject-re old-subject))
1684 (message-goto-subject)
1685 (message-delete-line)
1686 (insert (concat "Subject: "
1689 old-subject ")\n")))))))))
1692 (defun message-mark-inserted-region (beg end)
1693 "Mark some region in the current article with enclosing tags.
1694 See `message-mark-insert-begin' and `message-mark-insert-end'."
1697 ; add to the end of the region first, otherwise end would be invalid
1699 (insert message-mark-insert-end)
1701 (insert message-mark-insert-begin)))
1704 (defun message-mark-insert-file (file)
1705 "Insert FILE at point, marking it with enclosing tags.
1706 See `message-mark-insert-begin' and `message-mark-insert-end'."
1707 (interactive "fFile to insert: ")
1708 ;; reverse insertion to get correct result.
1710 (insert message-mark-insert-end)
1712 (insert-file-contents file)
1714 (insert message-mark-insert-begin)))
1717 (defun message-add-archive-header ()
1718 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1719 The note can be customized using `message-archive-note'. When called with a
1720 prefix argument, ask for a text to insert. If you don't want the note in the
1721 body, set `message-archive-note' to nil."
1723 (if current-prefix-arg
1724 (setq message-archive-note
1725 (read-from-minibuffer "Reason for No-Archive: "
1726 (cons message-archive-note 0))))
1728 (if (message-goto-signature)
1729 (re-search-backward message-signature-separator))
1730 (when message-archive-note
1731 (insert message-archive-note)
1733 (message-add-header message-archive-header)
1734 (message-sort-headers)))
1737 (defun message-cross-post-followup-to-header (target-group)
1738 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1739 With prefix-argument just set Follow-Up, don't cross-post."
1741 (list ; Completion based on Gnus
1742 (completing-read "Followup To: "
1743 (if (boundp 'gnus-newsrc-alist)
1745 nil nil '("poster" . 0)
1746 (if (boundp 'gnus-group-history)
1747 'gnus-group-history))))
1748 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1749 (message-goto-newsgroups)
1751 ;; if we already did a crosspost before, kill old target
1752 (if (and message-cross-post-old-target
1754 (regexp-quote (concat "," message-cross-post-old-target))
1757 ;; unless (followup is to poster or user explicitly asked not
1758 ;; to cross-post, or target-group is already in Newsgroups)
1759 ;; add target-group to Newsgroups line.
1761 ;; def: cross-post, req:no
1762 (and message-cross-post-default (not current-prefix-arg))
1763 ;; def: no-cross-post, req:yes
1764 (and (not message-cross-post-default) current-prefix-arg))
1765 (not (string-match "poster" target-group))
1766 (not (string-match (regexp-quote target-group)
1767 (message-fetch-field "Newsgroups"))))
1769 (insert (concat "," target-group))))
1770 (end-of-line) ; ensure Followup: comes after Newsgroups:
1771 ;; unless new followup would be identical to Newsgroups line
1772 ;; make a new Followup-To line
1773 (if (not (string-match (concat "^[ \t]*"
1776 (message-fetch-field "Newsgroups")))
1777 (insert (concat "\nFollowup-To: " target-group)))
1778 (setq message-cross-post-old-target target-group))
1781 (defun message-cross-post-insert-note (target-group cross-post in-old
1783 "Insert a in message body note about a set Followup or Crosspost.
1784 If there have been previous notes, delete them. TARGET-GROUP specifies the
1785 group to Followup-To. When CROSS-POST is t, insert note about
1786 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1787 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1788 been made to before the user asked for a Crosspost."
1789 ;; start scanning body for previous uses
1790 (message-goto-signature)
1791 (let ((head (re-search-backward
1792 (concat "^" mail-header-separator)
1793 nil t))) ; just search in body
1794 (message-goto-signature)
1795 (while (re-search-backward
1796 (concat "^" (regexp-quote message-cross-post-note) ".*")
1798 (message-delete-line))
1799 (message-goto-signature)
1800 (while (re-search-backward
1801 (concat "^" (regexp-quote message-followup-to-note) ".*")
1803 (message-delete-line))
1805 (if (message-goto-signature)
1806 (re-search-backward message-signature-separator))
1809 (string-match "^[ \t]*poster[ \t]*$" target-group))
1810 (insert (concat message-followup-to-note target-group "\n"))
1811 (insert (concat message-cross-post-note target-group "\n")))))
1814 (defun message-cross-post-followup-to (target-group)
1815 "Crossposts message and set Followup-To to TARGET-GROUP.
1816 With prefix-argument just set Follow-Up, don't cross-post."
1818 (list ; Completion based on Gnus
1819 (completing-read "Followup To: "
1820 (if (boundp 'gnus-newsrc-alist)
1822 nil nil '("poster" . 0)
1823 (if (boundp 'gnus-group-history)
1824 'gnus-group-history))))
1825 (cond ((not (or (null target-group) ; new subject not empty
1826 (zerop (string-width target-group))
1827 (string-match "^[ \t]*$" target-group)))
1829 (let* ((old-groups (message-fetch-field "Newsgroups"))
1830 (in-old (string-match
1831 (regexp-quote target-group)
1832 (or old-groups ""))))
1833 ;; check whether target exactly matches old Newsgroups
1834 (cond ((not old-groups)
1835 (error "No current newsgroup"))
1839 (regexp-quote target-group)
1842 ;; yes, Newsgroups line must change
1843 (message-cross-post-followup-to-header target-group)
1844 ;; insert note whether we do cross-post or followup-to
1845 (funcall message-cross-post-note-function
1847 (if (or (and message-cross-post-default
1848 (not current-prefix-arg))
1849 (and (not message-cross-post-default)
1850 current-prefix-arg)) t)
1851 in-old old-groups))))))))
1853 ;;; Reduce To: to Cc: or Bcc: header
1856 (defun message-reduce-to-to-cc ()
1857 "Replace contents of To: header with contents of Cc: or Bcc: header."
1860 (save-restriction (message-narrow-to-headers)
1861 (message-fetch-field "cc")))
1863 (if (and (not cc-content)
1866 (message-narrow-to-headers)
1867 (message-fetch-field "bcc"))))
1872 (message-delete-line)
1873 (insert (concat "To: " cc-content "\n"))
1875 (message-narrow-to-headers)
1876 (message-remove-header (if bcc
1880 ;;; End of functions adopted from `message-utils.el'.
1882 (defun message-remove-header (header &optional is-regexp first reverse)
1883 "Remove HEADER in the narrowed buffer.
1884 If IS-REGEXP, HEADER is a regular expression.
1885 If FIRST, only remove the first instance of the header.
1886 Return the number of headers removed."
1887 (goto-char (point-min))
1888 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1890 (case-fold-search t)
1892 (while (and (not (eobp))
1895 (not (looking-at regexp))
1896 (looking-at regexp))
1903 ;; There might be a continuation header, so we have to search
1904 ;; until we find a new non-continuation line.
1907 (if (re-search-forward "^[^ \t]" nil t)
1908 (goto-char (match-beginning 0))
1911 (if (re-search-forward "^[^ \t]" nil t)
1912 (goto-char (match-beginning 0))
1913 (goto-char (point-max)))))
1916 (defun message-remove-first-header (header)
1917 "Remove the first instance of HEADER if there is more than one."
1919 (regexp (concat "^" (regexp-quote header) ":")))
1921 (goto-char (point-min))
1922 (while (re-search-forward regexp nil t)
1925 (message-remove-header header nil t)
1928 (defun message-narrow-to-headers ()
1929 "Narrow the buffer to the head of the message."
1932 (goto-char (point-min))
1933 (if (re-search-forward
1934 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1937 (goto-char (point-min)))
1939 (defun message-narrow-to-head-1 ()
1940 "Like `message-narrow-to-head'. Don't widen."
1942 (goto-char (point-min))
1943 (if (search-forward "\n\n" nil 1)
1946 (goto-char (point-min)))
1948 (defun message-narrow-to-head ()
1949 "Narrow the buffer to the head of the message.
1950 Point is left at the beginning of the narrowed-to region."
1952 (message-narrow-to-head-1))
1954 (defun message-narrow-to-headers-or-head ()
1955 "Narrow the buffer to the head of the message."
1958 (goto-char (point-min))
1961 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1962 (match-beginning 0))
1963 ((search-forward "\n\n" nil t)
1967 (goto-char (point-min)))
1969 (defun message-news-p ()
1970 "Say whether the current buffer contains a news message."
1971 (and (not message-this-is-mail)
1972 (or message-this-is-news
1975 (message-narrow-to-headers)
1976 (and (message-fetch-field "newsgroups")
1977 (not (message-fetch-field "posted-to"))))))))
1979 (defun message-mail-p ()
1980 "Say whether the current buffer contains a mail message."
1981 (and (not message-this-is-news)
1982 (or message-this-is-mail
1985 (message-narrow-to-headers)
1986 (or (message-fetch-field "to")
1987 (message-fetch-field "cc")
1988 (message-fetch-field "bcc")))))))
1990 (defun message-subscribed-p ()
1991 "Say whether we need to insert a MFT header."
1992 (or message-subscribed-regexps
1993 message-subscribed-addresses
1994 message-subscribed-address-file
1995 message-subscribed-address-functions))
1997 (defun message-next-header ()
1998 "Go to the beginning of the next header."
2000 (or (eobp) (forward-char 1))
2001 (not (if (re-search-forward "^[^ \t]" nil t)
2003 (goto-char (point-max)))))
2005 (defun message-sort-headers-1 ()
2006 "Sort the buffer as headers using `message-rank' text props."
2007 (goto-char (point-min))
2010 nil 'message-next-header
2012 (message-next-header)
2016 (or (get-text-property (point) 'message-rank)
2019 (defun message-sort-headers ()
2020 "Sort the headers of the current message according to `message-header-format-alist'."
2024 (let ((max (1+ (length message-header-format-alist)))
2026 (message-narrow-to-headers)
2027 (while (re-search-forward "^[^ \n]+:" nil t)
2029 (match-beginning 0) (1+ (match-beginning 0))
2031 (if (setq rank (length (memq (assq (intern (buffer-substring
2033 (1- (match-end 0))))
2034 message-header-format-alist)
2035 message-header-format-alist)))
2038 (message-sort-headers-1))))
2049 (defvar message-mode-map nil)
2051 (unless message-mode-map
2052 (setq message-mode-map (make-keymap))
2053 (set-keymap-parent message-mode-map text-mode-map)
2054 (define-key message-mode-map "\C-c?" 'describe-mode)
2056 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2057 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2058 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2059 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2060 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2061 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2062 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2063 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2064 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2065 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2066 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2067 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2068 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2069 (define-key message-mode-map "\C-c\C-f\C-i"
2070 'message-insert-or-toggle-importance)
2071 (define-key message-mode-map "\C-c\C-f\C-a"
2072 'message-generate-unsubscribed-mail-followup-to)
2074 ;; modify headers (and insert notes in body)
2075 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2077 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2078 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2079 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2080 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2081 ;; mark inserted text
2082 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2083 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2085 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2086 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2088 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2089 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2090 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2091 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2093 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2094 (define-key message-mode-map "\C-c\M-n"
2095 'message-insert-disposition-notification-to)
2097 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2098 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2099 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2100 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2101 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2102 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2103 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2104 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2106 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2107 (define-key message-mode-map "\C-c\C-s" 'message-send)
2108 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2109 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2110 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2112 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2113 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2114 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2115 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2116 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2117 (define-key message-mode-map [remap split-line] 'message-split-line)
2119 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2121 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2122 (define-key message-mode-map "\t" 'message-tab)
2123 (define-key message-mode-map "\M-;" 'comment-region))
2126 message-mode-menu message-mode-map "Message Menu."
2128 ["Yank Original" message-yank-original message-reply-buffer]
2129 ["Fill Yanked Message" message-fill-yanked-message t]
2130 ["Insert Signature" message-insert-signature t]
2131 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2132 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2133 ["Elide Region" message-elide-region
2134 :active (message-mark-active-p)
2135 ,@(if (featurep 'xemacs) nil
2136 '(:help "Replace text in region with an ellipsis"))]
2137 ["Delete Outside Region" message-delete-not-region
2138 :active (message-mark-active-p)
2139 ,@(if (featurep 'xemacs) nil
2140 '(:help "Delete all quoted text outside region"))]
2141 ["Kill To Signature" message-kill-to-signature t]
2142 ["Newline and Reformat" message-newline-and-reformat t]
2143 ["Rename buffer" message-rename-buffer t]
2144 ["Spellcheck" ispell-message
2145 ,@(if (featurep 'xemacs) '(t)
2146 '(:help "Spellcheck this message"))]
2148 ["Insert Region Marked" message-mark-inserted-region
2149 :active (message-mark-active-p)
2150 ,@(if (featurep 'xemacs) nil
2151 '(:help "Mark region with enclosing tags"))]
2152 ["Insert File Marked..." message-mark-insert-file
2153 ,@(if (featurep 'xemacs) '(t)
2154 '(:help "Insert file at point marked with enclosing tags"))]
2156 ["Send Message" message-send-and-exit
2157 ,@(if (featurep 'xemacs) '(t)
2158 '(:help "Send this message"))]
2159 ["Postpone Message" message-dont-send
2160 ,@(if (featurep 'xemacs) '(t)
2161 '(:help "File this draft message and exit"))]
2162 ["Send at Specific Time..." gnus-delay-article
2163 ,@(if (featurep 'xemacs) '(t)
2164 '(:help "Ask, then arrange to send message at that time"))]
2165 ["Kill Message" message-kill-buffer
2166 ,@(if (featurep 'xemacs) '(t)
2167 '(:help "Delete this message without sending"))]))
2170 message-mode-field-menu message-mode-map ""
2172 ["Fetch To" message-insert-to t]
2173 ["Fetch Newsgroups" message-insert-newsgroups t]
2175 ["To" message-goto-to t]
2176 ["From" message-goto-from t]
2177 ["Subject" message-goto-subject t]
2178 ["Change subject..." message-change-subject t]
2179 ["Cc" message-goto-cc t]
2180 ["Bcc" message-goto-bcc t]
2181 ["Fcc" message-goto-fcc t]
2182 ["Reply-To" message-goto-reply-to t]
2183 ["Flag As Important" message-insert-importance-high
2184 ,@(if (featurep 'xemacs) '(t)
2185 '(:help "Mark this message as important"))]
2186 ["Flag As Unimportant" message-insert-importance-low
2187 ,@(if (featurep 'xemacs) '(t)
2188 '(:help "Mark this message as unimportant"))]
2190 message-insert-disposition-notification-to
2191 ,@(if (featurep 'xemacs) '(t)
2192 '(:help "Request a receipt notification"))]
2194 ;; (typical) news stuff
2195 ["Summary" message-goto-summary t]
2196 ["Keywords" message-goto-keywords t]
2197 ["Newsgroups" message-goto-newsgroups t]
2198 ["Followup-To" message-goto-followup-to t]
2199 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2200 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2201 ["Distribution" message-goto-distribution t]
2202 ["X-No-Archive:" message-add-archive-header t ]
2204 ;; (typical) mailing-lists stuff
2205 ["Send to list only" message-to-list-only t]
2206 ["Mail-Followup-To" message-goto-mail-followup-to t]
2207 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2209 ["Sort Headers" message-sort-headers t]
2210 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2211 ["Goto Body" message-goto-body t]
2212 ["Goto Signature" message-goto-signature t]))
2214 (defvar message-tool-bar-map nil)
2217 (defvar facemenu-add-face-function)
2218 (defvar facemenu-remove-face-function))
2220 ;;; Forbidden properties
2222 ;; We use `after-change-functions' to keep special text properties
2223 ;; that interfer with the normal function of message mode out of the
2226 (defcustom message-strip-special-text-properties t
2227 "Strip special properties from the message buffer.
2229 Emacs has a number of special text properties which can break message
2230 composing in various ways. If this option is set, message will strip
2231 these properties from the message composition buffer. However, some
2232 packages requires these properties to be present in order to work.
2233 If you use one of these packages, turn this option off, and hope the
2234 message composition doesn't break too bad."
2235 :group 'message-various
2238 (defconst message-forbidden-properties
2239 ;; No reason this should be clutter up customize. We make it a
2240 ;; property list (rather than a list of property symbols), to be
2241 ;; directly useful for `remove-text-properties'.
2242 '(field nil read-only nil invisible nil intangible nil
2243 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2244 insert-behind-hooks nil point-entered nil point-left nil)
2245 ;; Other special properties:
2246 ;; category, face, display: probably doesn't do any harm.
2247 ;; fontified: is used by font-lock.
2248 ;; syntax-table, local-map: I dunno.
2249 ;; We need to add XEmacs names to the list.
2250 "Property list of with properties.forbidden in message buffers.
2251 The values of the properties are ignored, only the property names are used.")
2253 (defun message-tamago-not-in-use-p (pos)
2254 "Return t when tamago version 4 is not in use at the cursor position.
2255 Tamago version 4 is a popular input method for writing Japanese text.
2256 It uses the properties `intangible', `invisible', `modification-hooks'
2257 and `read-only' when translating ascii or kana text to kanji text.
2258 These properties are essential to work, so we should never strip them."
2259 (not (and (boundp 'egg-modefull-mode)
2260 (symbol-value 'egg-modefull-mode)
2261 (or (memq (get-text-property pos 'intangible)
2262 '(its-part-1 its-part-2))
2263 (get-text-property pos 'egg-end)
2264 (get-text-property pos 'egg-lang)
2265 (get-text-property pos 'egg-start)))))
2267 (defun message-strip-forbidden-properties (begin end &optional old-length)
2268 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2269 This function is intended to be called from `after-change-functions'.
2270 See also `message-forbidden-properties'."
2271 (when (and message-strip-special-text-properties
2272 (message-tamago-not-in-use-p begin))
2273 (while (not (= begin end))
2274 (when (not (get-text-property begin 'message-hidden))
2275 (remove-text-properties begin (1+ begin)
2276 message-forbidden-properties))
2280 (define-derived-mode message-mode text-mode "Message"
2281 "Major mode for editing mail and news to be sent.
2282 Like Text Mode but with these additional commands:\\<message-mode-map>
2283 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2284 C-c C-d Postpone sending the message C-c C-k Kill the message
2285 C-c C-f move to a header field (and create it if there isn't):
2286 C-c C-f C-t move to To C-c C-f C-s move to Subject
2287 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2288 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2289 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2290 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2291 C-c C-f C-o move to From (\"Originator\")
2292 C-c C-f C-f move to Followup-To
2293 C-c C-f C-m move to Mail-Followup-To
2294 C-c C-f C-i cycle through Importance values
2295 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2296 C-c C-f x crossposting with FollowUp-To header and note in body
2297 C-c C-f t replace To: header with contents of Cc: or Bcc:
2298 C-c C-f a Insert X-No-Archive: header and a note in the body
2299 C-c C-t `message-insert-to' (add a To header to a news followup)
2300 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2301 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2302 C-c C-b `message-goto-body' (move to beginning of message text).
2303 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2304 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2305 C-c C-y `message-yank-original' (insert current message, if any).
2306 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2307 C-c C-e `message-elide-region' (elide the text between point and mark).
2308 C-c C-v `message-delete-not-region' (remove the text outside the region).
2309 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2310 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2311 C-c C-a `mml-attach-file' (attach a file as MIME).
2312 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2313 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2314 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2315 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2316 M-RET `message-newline-and-reformat' (break the line and reformat)."
2317 (setq local-abbrev-table text-mode-abbrev-table)
2318 (set (make-local-variable 'message-reply-buffer) nil)
2319 (make-local-variable 'message-send-actions)
2320 (make-local-variable 'message-exit-actions)
2321 (make-local-variable 'message-kill-actions)
2322 (make-local-variable 'message-postpone-actions)
2323 (make-local-variable 'message-draft-article)
2324 (setq buffer-offer-save t)
2325 (set (make-local-variable 'facemenu-add-face-function)
2327 (let ((face-fun (cdr (assq face message-face-alist))))
2329 (funcall face-fun (point) end)
2330 (error "Face %s not configured for %s mode" face mode-name)))
2332 (set (make-local-variable 'facemenu-remove-face-function) t)
2333 (set (make-local-variable 'message-reply-headers) nil)
2334 (make-local-variable 'message-newsreader)
2335 (make-local-variable 'message-mailer)
2336 (make-local-variable 'message-post-method)
2337 (set (make-local-variable 'message-sent-message-via) nil)
2338 (set (make-local-variable 'message-checksum) nil)
2339 (set (make-local-variable 'message-mime-part) 0)
2340 (message-setup-fill-variables)
2342 (make-local-variable 'paragraph-separate)
2343 (format "\\(%s\\)\\|\\(%s\\)"
2345 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2346 ;; Allow using comment commands to add/remove quoting.
2347 (set (make-local-variable 'comment-start) message-yank-prefix)
2348 (if (featurep 'xemacs)
2349 (message-setup-toolbar)
2350 (set (make-local-variable 'font-lock-defaults)
2351 '(message-font-lock-keywords t))
2352 (if (boundp 'tool-bar-map)
2353 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2354 (easy-menu-add message-mode-menu message-mode-map)
2355 (easy-menu-add message-mode-field-menu message-mode-map)
2356 (gnus-make-local-hook 'after-change-functions)
2357 ;; Mmmm... Forbidden properties...
2358 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2360 ;; Allow mail alias things.
2361 (when (eq message-mail-alias-type 'abbrev)
2362 (if (fboundp 'mail-abbrevs-setup)
2363 (mail-abbrevs-setup)
2364 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2365 (mail-aliases-setup))))
2366 (unless buffer-file-name
2367 (message-set-auto-save-file-name))
2368 (unless (buffer-base-buffer)
2369 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2370 ;; multibyte is not necessary at all. -- zsh
2371 (mm-enable-multibyte))
2372 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2375 (defun message-setup-fill-variables ()
2376 "Setup message fill variables."
2377 (set (make-local-variable 'fill-paragraph-function)
2378 'message-fill-paragraph)
2379 (make-local-variable 'paragraph-separate)
2380 (make-local-variable 'paragraph-start)
2381 (make-local-variable 'adaptive-fill-regexp)
2382 (unless (boundp 'adaptive-fill-first-line-regexp)
2383 (setq adaptive-fill-first-line-regexp nil))
2384 (make-local-variable 'adaptive-fill-first-line-regexp)
2385 (let ((quote-prefix-regexp
2386 ;; User should change message-cite-prefix-regexp if
2387 ;; message-yank-prefix is set to an abnormal value.
2388 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2389 (setq paragraph-start
2391 (regexp-quote mail-header-separator) "$\\|"
2392 "[ \t]*$\\|" ; blank lines
2393 "-- $\\|" ; signature delimiter
2394 "---+$\\|" ; delimiters for forwarded messages
2395 page-delimiter "$\\|" ; spoiler warnings
2396 ".*wrote:$\\|" ; attribution lines
2397 quote-prefix-regexp "$")) ; empty lines in quoted text
2398 (setq paragraph-separate paragraph-start)
2399 (setq adaptive-fill-regexp
2400 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2401 (setq adaptive-fill-first-line-regexp
2402 (concat quote-prefix-regexp "\\|"
2403 adaptive-fill-first-line-regexp)))
2404 (make-local-variable 'auto-fill-inhibit-regexp)
2405 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2406 (setq auto-fill-inhibit-regexp nil)
2407 (make-local-variable 'normal-auto-fill-function)
2408 (setq normal-auto-fill-function 'message-do-auto-fill)
2409 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2410 ;; In that case, ensure that it uses the right function. The real
2411 ;; solution would be not to use `define-derived-mode', and run
2412 ;; `text-mode-hook' ourself at the end of the mode.
2413 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2414 (when auto-fill-function
2415 (setq auto-fill-function normal-auto-fill-function)))
2420 ;;; Message mode commands
2423 ;;; Movement commands
2425 (defun message-goto-to ()
2426 "Move point to the To header."
2428 (message-position-on-field "To"))
2430 (defun message-goto-from ()
2431 "Move point to the From header."
2433 (message-position-on-field "From"))
2435 (defun message-goto-subject ()
2436 "Move point to the Subject header."
2438 (message-position-on-field "Subject"))
2440 (defun message-goto-cc ()
2441 "Move point to the Cc header."
2443 (message-position-on-field "Cc" "To"))
2445 (defun message-goto-bcc ()
2446 "Move point to the Bcc header."
2448 (message-position-on-field "Bcc" "Cc" "To"))
2450 (defun message-goto-fcc ()
2451 "Move point to the Fcc header."
2453 (message-position-on-field "Fcc" "To" "Newsgroups"))
2455 (defun message-goto-reply-to ()
2456 "Move point to the Reply-To header."
2458 (message-position-on-field "Reply-To" "Subject"))
2460 (defun message-goto-newsgroups ()
2461 "Move point to the Newsgroups header."
2463 (message-position-on-field "Newsgroups"))
2465 (defun message-goto-distribution ()
2466 "Move point to the Distribution header."
2468 (message-position-on-field "Distribution"))
2470 (defun message-goto-followup-to ()
2471 "Move point to the Followup-To header."
2473 (message-position-on-field "Followup-To" "Newsgroups"))
2475 (defun message-goto-mail-followup-to ()
2476 "Move point to the Mail-Followup-To header."
2478 (message-position-on-field "Mail-Followup-To" "From"))
2480 (defun message-goto-keywords ()
2481 "Move point to the Keywords header."
2483 (message-position-on-field "Keywords" "Subject"))
2485 (defun message-goto-summary ()
2486 "Move point to the Summary header."
2488 (message-position-on-field "Summary" "Subject"))
2490 (defun message-goto-body (&optional interactivep)
2491 "Move point to the beginning of the message body."
2492 (interactive (list t))
2493 (when (and interactivep
2494 (looking-at "[ \t]*\n"))
2496 (goto-char (point-min))
2497 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2498 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2500 (defun message-goto-eoh ()
2501 "Move point to the end of the headers."
2506 (defun message-goto-signature ()
2507 "Move point to the beginning of the message signature.
2508 If there is no signature in the article, go to the end and
2511 (goto-char (point-min))
2512 (if (re-search-forward message-signature-separator nil t)
2514 (goto-char (point-max))
2517 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2518 "Insert a reasonable MFT header in a post to an unsubscribed list.
2519 When making original posts to a mailing list you are not subscribed to,
2520 you have to type in a MFT header by hand. The contents, usually, are
2521 the addresses of the list and your own address. This function inserts
2522 such a header automatically. It fetches the contents of the To: header
2523 in the current mail buffer, and appends the current `user-mail-address'.
2525 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2526 Cc: header are also put into the MFT."
2531 (message-narrow-to-headers)
2532 (message-remove-header "Mail-Followup-To")
2533 (setq cc (and include-cc (message-fetch-field "Cc")))
2535 (concat (message-fetch-field "To") "," cc)
2536 (message-fetch-field "To"))))
2537 (message-goto-mail-followup-to)
2538 (insert (concat tos ", " user-mail-address))))
2542 (defun message-insert-to (&optional force)
2543 "Insert a To header that points to the author of the article being replied to.
2544 If the original author requested not to be sent mail, the function signals
2546 With the prefix argument FORCE, insert the header anyway."
2548 (let ((co (message-fetch-reply-field "mail-copies-to")))
2549 (when (and (null force)
2551 (or (equal (downcase co) "never")
2552 (equal (downcase co) "nobody")))
2553 (error "The user has requested not to have copies sent via mail")))
2554 (message-carefully-insert-headers
2556 (or (message-fetch-reply-field "mail-reply-to")
2557 (message-fetch-reply-field "reply-to")
2558 (message-fetch-reply-field "from")
2561 (defun message-insert-wide-reply ()
2562 "Insert To and Cc headers as if you were doing a wide reply."
2564 (let ((headers (message-with-reply-buffer
2565 (message-get-reply-headers t))))
2566 (message-carefully-insert-headers headers)))
2568 (defun message-carefully-insert-headers (headers)
2569 (dolist (header headers)
2570 (let ((header-name (symbol-name (car header))))
2571 (when (and (message-position-on-field header-name)
2572 (mail-fetch-field header-name)
2573 (not (string-match "\\` *\\'"
2574 (mail-fetch-field header-name))))
2576 (insert (cdr header)))))
2578 (defun message-widen-reply ()
2579 "Widen the reply to include maximum recipients."
2582 (and message-reply-buffer
2583 (buffer-name message-reply-buffer)
2585 (set-buffer message-reply-buffer)
2586 (message-get-reply-headers t)))))
2589 (message-narrow-to-headers)
2590 (dolist (elem follow-to)
2591 (message-remove-header (symbol-name (car elem)))
2592 (goto-char (point-min))
2593 (insert (symbol-name (car elem)) ": "
2594 (cdr elem) "\n"))))))
2596 (defun message-insert-newsgroups ()
2597 "Insert the Newsgroups header from the article being replied to."
2599 (when (and (message-position-on-field "Newsgroups")
2600 (mail-fetch-field "newsgroups")
2601 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2603 (insert (or (message-fetch-reply-field "newsgroups") "")))
2607 ;;; Various commands
2609 (defun message-delete-not-region (beg end)
2610 "Delete everything in the body of the current message outside of the region."
2615 ;; snarf citation prefix, if appropriate
2616 (unless (eq (point) (progn (beginning-of-line) (point)))
2617 (when (looking-at message-cite-prefix-regexp)
2618 (setq citeprefix (match-string 0))))
2620 (delete-region (point) (if (not (message-goto-signature))
2626 (delete-region beg (progn (message-goto-body)
2630 (insert citeprefix))))
2631 (when (message-goto-signature)
2634 (defun message-kill-to-signature ()
2635 "Deletes all text up to the signature."
2637 (let ((point (point)))
2638 (message-goto-signature)
2641 (kill-region point (point))
2645 (defun message-newline-and-reformat (&optional arg not-break)
2646 "Insert four newlines, and then reformat if inside quoted text.
2647 Prefix arg means justify as well."
2648 (interactive (list (if current-prefix-arg 'full)))
2649 (let (quoted point beg end leading-space bolp)
2650 (setq point (point))
2653 (setq bolp (= beg point))
2654 ;; Find first line of the paragraph.
2656 (while (and (not (eobp))
2657 (not (looking-at message-cite-prefix-regexp))
2658 (looking-at paragraph-start))
2661 (when (looking-at message-cite-prefix-regexp)
2662 (setq quoted (match-string 0))
2663 (goto-char (match-end 0))
2664 (looking-at "[ \t]*")
2665 (setq leading-space (match-string 0)))
2669 (< (- point beg) (length quoted)))
2670 ;; break inside the cite prefix.
2676 (while (and (not (eobp))
2677 (not (looking-at paragraph-separate))
2678 (looking-at message-cite-prefix-regexp)
2679 (equal quoted (match-string 0)))
2680 (goto-char (match-end 0))
2681 (looking-at "[ \t]*")
2682 (if (> (length leading-space) (length (match-string 0)))
2683 (setq leading-space (match-string 0)))
2687 (while (and (if (bobp) nil (forward-line -1) t)
2688 (not (looking-at paragraph-start))
2689 (looking-at message-cite-prefix-regexp)
2690 (equal quoted (match-string 0)))
2692 (goto-char (match-end 0))
2693 (looking-at "[ \t]*")
2694 (if (> (length leading-space) (length (match-string 0)))
2695 (setq leading-space (match-string 0)))))
2696 (while (and (not (eobp))
2697 (not (looking-at paragraph-separate))
2698 (not (looking-at message-cite-prefix-regexp)))
2702 (while (and (if (bobp) nil (forward-line -1) t)
2703 (not (looking-at paragraph-start))
2704 (not (looking-at message-cite-prefix-regexp)))
2705 (setq beg (point))))
2708 (narrow-to-region beg end)
2715 (setq point (point))
2716 ;; (newline 2) doesn't mark both newline's as hard, so call
2717 ;; newline twice. -jas
2720 (delete-region (point) (re-search-forward "[ \t]*"))
2721 (when (and quoted (not bolp))
2722 (insert quoted leading-space)))
2725 (let* ((adaptive-fill-regexp
2726 (regexp-quote (concat quoted leading-space)))
2727 (adaptive-fill-first-line-regexp
2728 adaptive-fill-regexp ))
2729 (fill-paragraph arg))
2730 (fill-paragraph arg))
2731 (if point (goto-char point)))))
2733 (defun message-fill-paragraph (&optional arg)
2734 "Like `fill-paragraph'."
2735 (interactive (list (if current-prefix-arg 'full)))
2736 (if (if (boundp 'filladapt-mode) filladapt-mode)
2738 (message-newline-and-reformat arg t)
2741 ;; Is it better to use `mail-header-end'?
2742 (defun message-point-in-header-p ()
2743 "Return t if point is in the header."
2746 (goto-char (point-min))
2747 (not (re-search-forward
2748 (concat "^" (regexp-quote mail-header-separator) "\n")
2751 (defun message-do-auto-fill ()
2752 "Like `do-auto-fill', but don't fill in message header."
2753 (unless (message-point-in-header-p)
2756 (defun message-insert-signature (&optional force)
2757 "Insert a signature. See documentation for variable `message-signature'."
2758 (interactive (list 0))
2761 ((and (null message-signature)
2764 (goto-char (point-max))
2765 (not (re-search-backward message-signature-separator nil t))))
2766 ((and (null message-signature)
2769 ((functionp message-signature)
2770 (funcall message-signature))
2771 ((listp message-signature)
2772 (eval message-signature))
2773 (t message-signature)))
2775 (cond ((stringp signature)
2777 ((and (eq t signature)
2778 message-signature-file
2779 (file-exists-p message-signature-file))
2782 (goto-char (point-max))
2783 ;; Insert the signature.
2786 (when message-signature-insert-empty-line
2789 (if (eq signature t)
2790 (insert-file-contents message-signature-file)
2792 (goto-char (point-max))
2793 (or (bolp) (insert "\n")))))
2795 (defun message-insert-importance-high ()
2796 "Insert header to mark message as important."
2800 (message-narrow-to-headers)
2801 (message-remove-header "Importance"))
2803 (insert "Importance: high\n")))
2805 (defun message-insert-importance-low ()
2806 "Insert header to mark message as unimportant."
2810 (message-narrow-to-headers)
2811 (message-remove-header "Importance"))
2813 (insert "Importance: low\n")))
2815 (defun message-insert-or-toggle-importance ()
2816 "Insert a \"Importance: high\" header, or cycle through the header values.
2817 The three allowed values according to RFC 1327 are `high', `normal'
2821 (let ((valid '("high" "normal" "low"))
2825 (message-narrow-to-headers)
2826 (when (setq cur (message-fetch-field "Importance"))
2827 (message-remove-header "Importance")
2828 (setq new (cond ((string= cur "high")
2830 ((string= cur "low")
2835 (insert (format "Importance: %s\n" new)))))
2837 (defun message-insert-disposition-notification-to ()
2838 "Request a disposition notification (return receipt) to this message.
2839 Note that this should not be used in newsgroups."
2843 (message-narrow-to-headers)
2844 (message-remove-header "Disposition-Notification-To"))
2846 (insert (format "Disposition-Notification-To: %s\n"
2849 (message-narrow-to-headers)
2850 (message-fetch-field "From")))
2851 (message-make-from))))))
2853 (defun message-elide-region (b e)
2854 "Elide the text in the region.
2855 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2859 (insert message-elide-ellipsis))
2861 (defvar message-caesar-translation-table nil)
2863 (defun message-caesar-region (b e &optional n)
2864 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2867 (min (point) (or (mark t) (point)))
2868 (max (point) (or (mark t) (point)))
2869 (when current-prefix-arg
2870 (prefix-numeric-value current-prefix-arg))))
2872 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2873 (unless (or (zerop n) ; no action needed for a rot of 0
2874 (= b e)) ; no region to rotate
2875 ;; We build the table, if necessary.
2876 (when (or (not message-caesar-translation-table)
2877 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2878 (setq message-caesar-translation-table
2879 (message-make-caesar-translation-table n)))
2880 (translate-region b e message-caesar-translation-table)))
2882 (defun message-make-caesar-translation-table (n)
2883 "Create a rot table with offset N."
2885 (table (make-string 256 0)))
2886 (while (< (incf i) 256)
2889 (substring table 0 ?A)
2890 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2891 (substring table ?A (+ ?A n))
2892 (substring table (+ ?A 26) ?a)
2893 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2894 (substring table ?a (+ ?a n))
2895 (substring table (+ ?a 26) 255))))
2897 (defun message-caesar-buffer-body (&optional rotnum)
2898 "Caesar rotate all letters in the current buffer by 13 places.
2899 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2900 With prefix arg, specifies the number of places to rotate each letter forward.
2901 Mail and USENET news headers are not rotated."
2902 (interactive (if current-prefix-arg
2903 (list (prefix-numeric-value current-prefix-arg))
2907 (when (message-goto-body)
2908 (narrow-to-region (point) (point-max)))
2909 (message-caesar-region (point-min) (point-max) rotnum))))
2911 (defun message-pipe-buffer-body (program)
2912 "Pipe the message body in the current buffer through PROGRAM."
2915 (when (message-goto-body)
2916 (narrow-to-region (point) (point-max)))
2917 (shell-command-on-region
2918 (point-min) (point-max) program nil t))))
2920 (defun message-rename-buffer (&optional enter-string)
2921 "Rename the *message* buffer to \"*message* RECIPIENT\".
2922 If the function is run with a prefix, it will ask for a new buffer
2923 name, rather than giving an automatic name."
2924 (interactive "Pbuffer name: ")
2927 (goto-char (point-min))
2928 (narrow-to-region (point)
2929 (search-forward mail-header-separator nil 'end))
2931 (if (message-news-p) (message-fetch-field "Newsgroups")
2932 (message-fetch-field "To"))
2935 (if (string-match "," mail-to)
2936 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2938 (name-default (concat "*message* " mail-trimmed-to))
2939 (name (if enter-string
2940 (read-string "New buffer name: " name-default)
2942 (rename-buffer name t)))))
2944 (defun message-fill-yanked-message (&optional justifyp)
2945 "Fill the paragraphs of a message yanked into this one.
2946 Numeric argument means justify as well."
2949 (goto-char (point-min))
2950 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2951 (let ((fill-prefix message-yank-prefix))
2952 (fill-individual-paragraphs (point) (point-max) justifyp))))
2954 (defun message-indent-citation ()
2955 "Modify text just inserted from a message to be cited.
2956 The inserted text should be the region.
2957 When this function returns, the region is again around the modified text.
2959 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2960 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2961 (let ((start (point)))
2962 ;; Remove unwanted headers.
2963 (when message-ignored-cited-headers
2968 (if (search-forward "\n\n" nil t)
2971 (message-remove-header message-ignored-cited-headers t)
2972 (when (= (point-min) (point-max))
2973 (setq all-removed t))
2974 (goto-char (point-max)))
2978 ;; Delete blank lines at the start of the buffer.
2979 (while (and (point-min)
2982 (message-delete-line))
2983 ;; Delete blank lines at the end of the buffer.
2984 (goto-char (point-max))
2987 (while (and (zerop (forward-line -1))
2989 (message-delete-line))
2990 ;; Do the indentation.
2991 (if (null message-yank-prefix)
2992 (indent-rigidly start (mark t) message-indentation-spaces)
2995 (while (< (point) (mark t))
2996 (if (or (looking-at ">") (looking-at "^$"))
2997 (insert message-yank-cited-prefix)
2998 (insert message-yank-prefix))
3002 (defun message-yank-original (&optional arg)
3003 "Insert the message being replied to, if any.
3004 Puts point before the text and mark after.
3005 Normally indents each nonblank line ARG spaces (default 3). However,
3006 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3008 This function uses `message-cite-function' to do the actual citing.
3010 Just \\[universal-argument] as argument means don't indent, insert no
3011 prefix, and don't delete any headers."
3013 (let ((modified (buffer-modified-p)))
3014 (when (and message-reply-buffer
3015 message-cite-function)
3016 (delete-windows-on message-reply-buffer t)
3017 (insert-buffer message-reply-buffer)
3019 (funcall message-cite-function))
3020 (message-exchange-point-and-mark)
3024 (setq message-checksum (message-checksum))))))
3026 (defun message-yank-buffer (buffer)
3027 "Insert BUFFER into the current buffer and quote it."
3028 (interactive "bYank buffer: ")
3029 (let ((message-reply-buffer buffer))
3030 (save-window-excursion
3031 (message-yank-original))))
3033 (defun message-buffers ()
3034 "Return a list of active message buffers."
3037 (dolist (buffer (buffer-list t))
3039 (when (and (eq major-mode 'message-mode)
3040 (null message-sent-message-via))
3041 (push (buffer-name buffer) buffers))))
3042 (nreverse buffers)))
3044 (defun message-cite-original-without-signature ()
3045 "Cite function in the standard Message manner."
3046 (let ((start (point))
3049 (when message-indent-citation-function
3050 (if (listp message-indent-citation-function)
3051 message-indent-citation-function
3052 (list message-indent-citation-function)))))
3053 (mml-quote-region start end)
3057 (when (re-search-backward message-signature-separator start t)
3058 ;; Also peel off any blank lines before the signature.
3060 (while (looking-at "^[ \t]*$")
3063 (delete-region (point) end)
3064 (unless (search-backward "\n\n" start t)
3065 ;; Insert a blank line if it is peeled off.
3069 (funcall (pop functions)))
3070 (when message-citation-line-function
3073 (funcall message-citation-line-function))))
3075 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3076 (defun message-cite-original ()
3077 "Cite function in the standard Message manner."
3078 (if (and (boundp 'mail-citation-hook)
3080 (run-hooks 'mail-citation-hook)
3081 (let ((start (point))
3084 (when message-indent-citation-function
3085 (if (listp message-indent-citation-function)
3086 message-indent-citation-function
3087 (list message-indent-citation-function)))))
3088 (mml-quote-region start end)
3091 (funcall (pop functions)))
3092 (when message-citation-line-function
3095 (funcall message-citation-line-function)))))
3097 (defun message-insert-citation-line ()
3098 "Insert a simple citation line."
3099 (when message-reply-headers
3100 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3102 (defun message-position-on-field (header &rest afters)
3103 (let ((case-fold-search t))
3106 (goto-char (point-min))
3109 (concat "^" (regexp-quote mail-header-separator) "$"))
3110 (match-beginning 0)))
3111 (goto-char (point-min))
3112 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3114 (re-search-forward "^[^ \t]" nil 'move)
3116 (skip-chars-backward "\n")
3119 (not (re-search-forward
3120 (concat "^" (regexp-quote (car afters)) ":")
3124 (re-search-forward "^[^ \t]" nil 'move)
3125 (beginning-of-line))
3126 (insert header ": \n")
3130 (defun message-remove-signature ()
3131 "Remove the signature from the text between point and mark.
3132 The text will also be indented the normal way."
3134 (let ((start (point))
3136 (if (not (re-search-forward message-signature-separator (mark t) t))
3137 ;; No signature here, so we just indent the cited text.
3138 (message-indent-citation)
3139 ;; Find the last non-empty line.
3141 (while (looking-at "[ \t]*$")
3144 (setq mark (set-marker (make-marker) (point)))
3146 (message-indent-citation)
3147 ;; Enable undoing the deletion.
3149 (delete-region mark (mark t))
3150 (set-marker mark nil)))))
3155 ;;; Sending messages
3158 (defun message-send-and-exit (&optional arg)
3159 "Send message like `message-send', then, if no errors, exit from mail buffer."
3161 (let ((buf (current-buffer))
3162 (actions message-exit-actions))
3163 (when (and (message-send arg)
3165 (if message-kill-buffer-on-exit
3168 (when (eq buf (current-buffer))
3169 (message-bury buf)))
3170 (message-do-actions actions)
3173 (defun message-dont-send ()
3174 "Don't send the message you have been editing.
3175 Instead, just auto-save the buffer and then bury it."
3177 (set-buffer-modified-p t)
3179 (let ((actions message-postpone-actions))
3180 (message-bury (current-buffer))
3181 (message-do-actions actions)))
3183 (defun message-kill-buffer ()
3184 "Kill the current buffer."
3186 (when (or (not (buffer-modified-p))
3187 (yes-or-no-p "Message modified; kill anyway? "))
3188 (let ((actions message-kill-actions)
3189 (draft-article message-draft-article)
3190 (auto-save-file-name buffer-auto-save-file-name)
3191 (file-name buffer-file-name)
3192 (modified (buffer-modified-p)))
3193 (setq buffer-file-name nil)
3194 (kill-buffer (current-buffer))
3195 (when (and (or (and auto-save-file-name
3196 (file-exists-p auto-save-file-name))
3198 (file-exists-p file-name)))
3199 (yes-or-no-p (format "Remove the backup file%s? "
3200 (if modified " too" ""))))
3202 (delete-file auto-save-file-name))
3203 (let ((message-draft-article draft-article))
3204 (message-disassociate-draft)))
3205 (message-do-actions actions))))
3207 (defun message-bury (buffer)
3208 "Bury this mail BUFFER."
3209 (let ((newbuf (other-buffer buffer)))
3210 (bury-buffer buffer)
3211 (if (and (fboundp 'frame-parameters)
3212 (cdr (assq 'dedicated (frame-parameters)))
3213 (not (null (delq (selected-frame) (visible-frame-list)))))
3214 (delete-frame (selected-frame))
3215 (switch-to-buffer newbuf))))
3217 (defun message-send (&optional arg)
3218 "Send the message in the current buffer.
3219 If `message-interactive' is non-nil, wait for success indication or
3220 error messages, and inform user.
3221 Otherwise any failure is reported in a message back to the user from
3223 The usage of ARG is defined by the instance that called Message.
3224 It should typically alter the sending method in some way or other."
3226 ;; Make it possible to undo the coming changes.
3228 (let ((inhibit-read-only t))
3229 (put-text-property (point-min) (point-max) 'read-only nil))
3230 (message-fix-before-sending)
3231 (run-hooks 'message-send-hook)
3232 (message message-sending-message)
3233 (let ((alist message-send-method-alist)
3235 elem sent dont-barf-on-no-method
3236 (message-options message-options))
3237 (message-options-set-recipient)
3239 (setq elem (pop alist)))
3240 (when (funcall (cadr elem))
3241 (when (and (or (not (memq (car elem)
3242 message-sent-message-via))
3243 (not (message-fetch-field "supersedes"))
3244 (if (or (message-gnksa-enable-p 'multiple-copies)
3245 (not (eq (car elem) 'news)))
3248 "Already sent message via %s; resend? "
3250 (error "Denied posting -- multiple copies")))
3251 (setq success (funcall (caddr elem) arg)))
3255 (let ((fcc (message-fetch-field "Fcc"))
3256 (gcc (message-fetch-field "Gcc")))
3258 (or (eq message-allow-no-recipients 'always)
3259 (and (not (eq message-allow-no-recipients 'never))
3260 (setq dont-barf-on-no-method
3262 (format "No receiver, perform %s anyway? "
3263 (cond ((and fcc gcc) "Fcc and Gcc")
3266 (error "No methods specified to send by"))
3267 (when (or dont-barf-on-no-method
3271 (run-hooks 'message-sent-hook))
3272 (message "Sending...done")
3273 ;; Mark the buffer as unmodified and delete auto-save.
3274 (set-buffer-modified-p nil)
3275 (delete-auto-save-file-if-necessary t)
3276 (message-disassociate-draft)
3277 ;; Delete other mail buffers and stuff.
3278 (message-do-send-housekeeping)
3279 (message-do-actions message-send-actions)
3283 (defun message-send-via-mail (arg)
3284 "Send the current message via mail."
3285 (message-send-mail arg))
3287 (defun message-send-via-news (arg)
3288 "Send the current message via news."
3289 (funcall message-send-news-function arg))
3291 (defmacro message-check (type &rest forms)
3292 "Eval FORMS if TYPE is to be checked."
3293 `(or (message-check-element ,type)
3297 (put 'message-check 'lisp-indent-function 1)
3298 (put 'message-check 'edebug-form-spec '(form body))
3300 (defun message-text-with-property (prop)
3301 "Return a list of all points where the text has PROP."
3303 (point (point-min)))
3305 (while (< point (point-max))
3306 (when (get-text-property point prop)
3307 (push point points))
3311 (defun message-fix-before-sending ()
3312 "Do various things to make the message nice before sending it."
3313 ;; Make sure there's a newline at the end of the message.
3314 (goto-char (point-max))
3317 ;; Make the hidden headers visible.
3318 (let ((points (message-text-with-property 'message-hidden)))
3320 (goto-char (car points))
3321 (dolist (point points)
3322 (add-text-properties point (1+ point)
3323 '(invisible nil intangible nil)))))
3324 ;; Make invisible text visible.
3325 ;; It doesn't seem as if this is useful, since the invisible property
3326 ;; is clobbered by an after-change hook anyhow.
3327 (message-check 'invisible-text
3328 (let ((points (message-text-with-property 'invisible)))
3330 (goto-char (car points))
3331 (dolist (point points)
3332 (put-text-property point (1+ point) 'invisible nil)
3333 (message-overlay-put (message-make-overlay point (1+ point))
3335 (unless (yes-or-no-p
3336 "Invisible text found and made visible; continue sending? ")
3337 (error "Invisible text found and made visible")))))
3338 (message-check 'illegible-text
3341 (skip-chars-forward mm-7bit-chars)
3343 (when (let ((char (char-after)))
3344 (or (< (mm-char-int char) 128)
3345 (and (mm-multibyte-p)
3346 (> (length (mm-find-mime-charset-region
3347 (point) (point-max)))
3349 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3353 (skip-chars-forward mm-7bit-chars))
3356 (gnus-multiple-choice
3357 "Non-printable characters found. Continue sending?"
3358 '((?d "Remove non-printable characters and send")
3359 (?r "Replace non-printable characters with dots and send")
3360 (?i "Ignore non-printable characters and send")
3361 (?e "Continue editing"))))
3363 (error "Non-printable characters"))
3365 (skip-chars-forward mm-7bit-chars)
3367 (when (let ((char (char-after)))
3368 (or (< (mm-char-int char) 128)
3369 (and (mm-multibyte-p)
3370 ;; Fixme: Wrong for Emacs 22 and for things
3371 ;; like undecable utf-8. Should at least
3372 ;; use find-coding-systems-region.
3373 (memq (char-charset char)
3374 '(eight-bit-control eight-bit-graphic
3377 (message-kill-all-overlays)
3379 (when (eq choice ?r)
3382 (skip-chars-forward mm-7bit-chars))))))
3384 (defun message-add-action (action &rest types)
3385 "Add ACTION to be performed when doing an exit of type TYPES."
3387 (add-to-list (intern (format "message-%s-actions" (pop types)))
3390 (defun message-delete-action (action &rest types)
3391 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3394 (set (setq var (intern (format "message-%s-actions" (pop types))))
3395 (delq action (symbol-value var))))))
3397 (defun message-do-actions (actions)
3398 "Perform all actions in ACTIONS."
3399 ;; Now perform actions on successful sending.
3403 ;; A simple function.
3404 ((functionp (car actions))
3405 (funcall (car actions)))
3406 ;; Something to be evaled.
3408 (eval (car actions)))))
3411 (defun message-send-mail-partially ()
3412 "Send mail as message/partial."
3413 ;; replace the header delimiter with a blank line
3414 (goto-char (point-min))
3416 (concat "^" (regexp-quote mail-header-separator) "\n"))
3417 (replace-match "\n")
3418 (run-hooks 'message-send-mail-hook)
3419 (let ((p (goto-char (point-min)))
3420 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3421 (curbuf (current-buffer))
3422 (id (message-make-message-id)) (n 1)
3423 plist total header required-mail-headers)
3425 (if (< (point-max) (+ p message-send-mail-partially-limit))
3426 (goto-char (point-max))
3427 (goto-char (+ p message-send-mail-partially-limit))
3429 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3432 (setq total (length plist))
3433 (push (point-max) plist)
3434 (setq plist (nreverse plist))
3437 (setq p (pop plist))
3440 (copy-to-buffer tembuf p (car plist))
3442 (goto-char (point-min))
3445 (goto-char (point-min))
3446 (narrow-to-region (point) (point))
3449 (setq header (buffer-substring (point-min) (point)))
3450 (goto-char (point-min))
3451 (narrow-to-region (point) (point))
3453 (message-remove-header "Mime-Version")
3454 (message-remove-header "Content-Type")
3455 (message-remove-header "Content-Transfer-Encoding")
3456 (message-remove-header "Message-ID")
3457 (message-remove-header "Lines")
3458 (goto-char (point-max))
3459 (insert "Mime-Version: 1.0\n")
3460 (setq header (buffer-string)))
3461 (goto-char (point-max))
3462 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3465 (let ((mail-header-separator ""))
3466 (when (memq 'Message-ID message-required-mail-headers)
3467 (insert "Message-ID: " (message-make-message-id) "\n"))
3468 (when (memq 'Lines message-required-mail-headers)
3469 (insert "Lines: " (message-make-lines) "\n"))
3470 (message-goto-subject)
3472 (insert (format " (%d/%d)" n total))
3474 (mm-with-unibyte-current-buffer
3475 (funcall (or message-send-mail-real-function
3476 message-send-mail-function))))
3478 (setq p (pop plist))
3480 (kill-buffer tembuf))))
3482 (defun message-send-mail (&optional arg)
3483 (require 'mail-utils)
3484 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3485 (case-fold-search nil)
3486 (news (message-news-p))
3487 (mailbuf (current-buffer))
3488 (message-this-is-mail t)
3489 (message-posting-charset
3490 (if (fboundp 'gnus-setup-posting-charset)
3491 (gnus-setup-posting-charset nil)
3492 message-posting-charset))
3493 (headers message-required-mail-headers))
3495 (message-narrow-to-headers)
3496 ;; Generate the Mail-Followup-To header if the header is not there...
3497 (if (and (message-subscribed-p)
3498 (not (mail-fetch-field "mail-followup-to")))
3501 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3502 message-required-mail-headers))
3503 ;; otherwise, delete the MFT header if the field is empty
3504 (when (equal "" (mail-fetch-field "mail-followup-to"))
3505 (message-remove-header "^Mail-Followup-To:")))
3506 ;; Insert some headers.
3507 (let ((message-deletable-headers
3508 (if news nil message-deletable-headers)))
3509 (message-generate-headers headers))
3510 ;; Let the user do all of the above.
3511 (run-hooks 'message-header-hook))
3516 ;; Avoid copying text props (except hard newlines).
3517 (insert (with-current-buffer mailbuf
3518 (mml-buffer-substring-no-properties-except-hard-newlines
3519 (point-min) (point-max))))
3520 ;; Remove some headers.
3521 (message-encode-message-body)
3523 (message-narrow-to-headers)
3524 ;; We (re)generate the Lines header.
3525 (when (memq 'Lines message-required-mail-headers)
3526 (message-generate-headers '(Lines)))
3527 ;; Remove some headers.
3528 (message-remove-header message-ignored-mail-headers t)
3529 (let ((mail-parse-charset message-default-charset))
3530 (mail-encode-encoded-word-buffer)))
3531 (goto-char (point-max))
3532 ;; require one newline at the end.
3533 (or (= (preceding-char) ?\n)
3535 (message-cleanup-headers)
3536 ;; FIXME: we're inserting the courtesy copy after encoding.
3537 ;; This is wrong if the courtesy copy string contains
3538 ;; non-ASCII characters. -- jh
3541 (message-narrow-to-headers)
3543 (or (message-fetch-field "cc")
3544 (message-fetch-field "bcc")
3545 (message-fetch-field "to"))
3546 (let ((content-type (message-fetch-field
3551 (string= "text/plain"
3553 (mail-header-parse-content-type
3557 (message-fetch-field
3558 "content-transfer-encoding")))))))
3559 (message-insert-courtesy-copy))
3560 (if (or (not message-send-mail-partially-limit)
3561 (< (point-max) message-send-mail-partially-limit)
3562 (not (message-y-or-n-p
3563 "The message size is too large, split? "
3567 (/ (point-max) 1000) "KB, is too large.
3569 Some mail gateways (MTA's) bounce large messages. To avoid the
3570 problem, answer `y', and the message will be split into several
3571 smaller pieces, the size of each is about "
3572 (/ message-send-mail-partially-limit 1000)
3576 However, some mail readers (MUA's) can't read split messages, i.e.,
3577 mails in message/partially format. Answer `n', and the message will be
3580 The size limit is controlled by `message-send-mail-partially-limit'.
3581 If you always want Gnus to send messages in one piece, set
3582 `message-send-mail-partially-limit' to nil.
3584 (mm-with-unibyte-current-buffer
3585 (message "Sending via mail...")
3586 (funcall (or message-send-mail-real-function
3587 message-send-mail-function)))
3588 (message-send-mail-partially)))
3589 (kill-buffer tembuf))
3590 (set-buffer mailbuf)
3591 (push 'mail message-sent-message-via)))
3593 (defun message-send-mail-with-sendmail ()
3594 "Send off the prepared buffer with sendmail."
3595 (let ((errbuf (if message-interactive
3596 (message-generate-new-buffer-clone-locals
3599 resend-to-addresses delimline)
3602 (let ((case-fold-search t))
3604 (message-narrow-to-headers)
3605 (setq resend-to-addresses (message-fetch-field "resent-to")))
3606 ;; Change header-delimiter to be what sendmail expects.
3607 (goto-char (point-min))
3609 (concat "^" (regexp-quote mail-header-separator) "\n"))
3610 (replace-match "\n")
3612 (setq delimline (point-marker))
3613 (run-hooks 'message-send-mail-hook)
3614 ;; Insert an extra newline if we need it to work around
3615 ;; Sun's bug that swallows newlines.
3616 (goto-char (1+ delimline))
3617 (when (eval message-mailer-swallows-blank-line)
3619 (when message-interactive
3623 (let* ((default-directory "/")
3624 (coding-system-for-write message-send-coding-system)
3626 'call-process-region
3628 (list (point-min) (point-max)
3629 (if (boundp 'sendmail-program)
3631 "/usr/lib/sendmail")
3632 nil errbuf nil "-oi")
3633 ;; Always specify who from,
3634 ;; since some systems have broken sendmails.
3635 ;; But some systems are more broken with -f, so
3636 ;; we'll let users override this.
3637 (if (null message-sendmail-f-is-evil)
3638 (list "-f" (message-sendmail-envelope-from)))
3639 ;; These mean "report errors by mail"
3640 ;; and "deliver in background".
3641 (if (null message-interactive) '("-oem" "-odb"))
3642 ;; Get the addresses from the message
3643 ;; unless this is a resend.
3644 ;; We must not do that for a resend
3645 ;; because we would find the original addresses.
3646 ;; For a resend, include the specific addresses.
3647 (if resend-to-addresses
3648 (list resend-to-addresses)
3650 (unless (or (null cpr) (zerop cpr))
3651 (error "Sending...failed with exit value %d" cpr)))
3652 (when message-interactive
3655 (goto-char (point-min))
3656 (while (re-search-forward "\n\n* *" nil t)
3657 (replace-match "; "))
3658 (if (not (zerop (buffer-size)))
3659 (error "Sending...failed to %s"
3660 (buffer-string))))))
3661 (when (bufferp errbuf)
3662 (kill-buffer errbuf)))))
3664 (defun message-send-mail-with-qmail ()
3665 "Pass the prepared message buffer to qmail-inject.
3666 Refer to the documentation for the variable `message-send-mail-function'
3667 to find out how to use this."
3668 ;; replace the header delimiter with a blank line
3669 (goto-char (point-min))
3671 (concat "^" (regexp-quote mail-header-separator) "\n"))
3672 (replace-match "\n")
3673 (run-hooks 'message-send-mail-hook)
3676 (let ((coding-system-for-write message-send-coding-system))
3678 'call-process-region 1 (point-max) message-qmail-inject-program
3680 ;; qmail-inject's default behaviour is to look for addresses on the
3681 ;; command line; if there're none, it scans the headers.
3682 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3684 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3685 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3686 ;; message from stdin.
3688 ;; qmail also has the advantage of not having been raped by
3689 ;; various vendors, so we don't have to allow for that, either --
3690 ;; compare this with message-send-mail-with-sendmail and weep
3691 ;; for sendmail's lost innocence.
3693 ;; all this is way cool coz it lets us keep the arguments entirely
3694 ;; free for -inject-arguments -- a big win for the user and for us
3695 ;; since we don't have to play that double-guessing game and the user
3696 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3697 (if (functionp message-qmail-inject-args)
3698 (funcall message-qmail-inject-args)
3699 message-qmail-inject-args)))
3700 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3701 ;; we have to look at the retval instead
3703 (100 (error "qmail-inject reported permanent failure"))
3704 (111 (error "qmail-inject reported transient failure"))
3705 ;; should never happen
3706 (t (error "qmail-inject reported unknown failure"))))
3708 (defun message-send-mail-with-mh ()
3709 "Send the prepared message buffer with mh."
3710 (let ((mh-previous-window-config nil)
3711 (name (mh-new-draft-name)))
3712 (setq buffer-file-name name)
3713 ;; MH wants to generate these headers itself.
3714 (when message-mh-deletable-headers
3715 (let ((headers message-mh-deletable-headers))
3717 (goto-char (point-min))
3718 (and (re-search-forward
3719 (concat "^" (symbol-name (car headers)) ": *") nil t)
3720 (message-delete-line))
3722 (run-hooks 'message-send-mail-hook)
3723 ;; Pass it on to mh.
3726 (defun message-smtpmail-send-it ()
3727 "Send the prepared message buffer with `smtpmail-send-it'.
3728 This only differs from `smtpmail-send-it' that this command evaluates
3729 `message-send-mail-hook' just before sending a message. It is useful
3730 if your ISP requires the POP-before-SMTP authentication. See the
3731 documentation for the function `mail-source-touch-pop'."
3732 (run-hooks 'message-send-mail-hook)
3735 (defun message-canlock-generate ()
3736 "Return a string that is non-trival to guess.
3737 Do not use this for anything important, it is cryptographically weak."
3738 (let (sha1-maximum-internal-length)
3739 (sha1 (concat (message-unique-id)
3740 (format "%x%x%x" (random) (random t) (random))
3741 (prin1-to-string (recent-keys))
3742 (prin1-to-string (garbage-collect))))))
3744 (defun message-canlock-password ()
3745 "The password used by message for cancel locks.
3746 This is the value of `canlock-password', if that option is non-nil.
3747 Otherwise, generate and save a value for `canlock-password' first."
3748 (unless canlock-password
3749 (customize-save-variable 'canlock-password (message-canlock-generate))
3750 (setq canlock-password-for-verify canlock-password))
3753 (defun message-insert-canlock ()
3754 (when message-insert-canlock
3755 (message-canlock-password)
3756 (canlock-insert-header)))
3758 (defun message-send-news (&optional arg)
3759 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3760 (case-fold-search nil)
3761 (method (if (functionp message-post-method)
3762 (funcall message-post-method arg)
3763 message-post-method))
3764 (newsgroups-field (save-restriction
3765 (message-narrow-to-headers-or-head)
3766 (message-fetch-field "Newsgroups")))
3767 (followup-field (save-restriction
3768 (message-narrow-to-headers-or-head)
3769 (message-fetch-field "Followup-To")))
3770 ;; BUG: We really need to get the charset for each name in the
3771 ;; Newsgroups and Followup-To lines to allow crossposting
3772 ;; between group namess with incompatible character sets.
3773 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3774 (group-field-charset
3775 (gnus-group-name-charset method newsgroups-field))
3776 (followup-field-charset
3777 (gnus-group-name-charset method (or followup-field "")))
3778 (rfc2047-header-encoding-alist
3779 (append (when group-field-charset
3780 (list (cons "Newsgroups" group-field-charset)))
3781 (when followup-field-charset
3782 (list (cons "Followup-To" followup-field-charset)))
3783 rfc2047-header-encoding-alist))
3784 (messbuf (current-buffer))
3785 (message-syntax-checks
3787 (listp message-syntax-checks))
3788 (cons '(existing-newsgroups . disabled)
3789 message-syntax-checks)
3790 message-syntax-checks))
3791 (message-this-is-news t)
3792 (message-posting-charset
3793 (gnus-setup-posting-charset newsgroups-field))
3795 (if (not (message-check-news-body-syntax))
3798 (message-narrow-to-headers)
3799 ;; Insert some headers.
3800 (message-generate-headers message-required-news-headers)
3801 (message-insert-canlock)
3802 ;; Let the user do all of the above.
3803 (run-hooks 'message-header-hook))
3804 ;; Note: This check will be disabled by the ".*" default value for
3805 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
3806 (when (and group-field-charset
3807 (listp message-syntax-checks))
3808 (setq message-syntax-checks
3809 (cons '(valid-newsgroups . disabled)
3810 message-syntax-checks)))
3811 (message-cleanup-headers)
3812 (if (not (let ((message-post-method method))
3813 (message-check-news-syntax)))
3818 (buffer-disable-undo)
3820 ;; Avoid copying text props (except hard newlines).
3822 (with-current-buffer messbuf
3823 (mml-buffer-substring-no-properties-except-hard-newlines
3824 (point-min) (point-max))))
3825 (message-encode-message-body)
3826 ;; Remove some headers.
3828 (message-narrow-to-headers)
3829 ;; We (re)generate the Lines header.
3830 (when (memq 'Lines message-required-mail-headers)
3831 (message-generate-headers '(Lines)))
3832 ;; Remove some headers.
3833 (message-remove-header message-ignored-news-headers t)
3834 (let ((mail-parse-charset message-default-charset))
3835 (mail-encode-encoded-word-buffer)))
3836 (goto-char (point-max))
3837 ;; require one newline at the end.
3838 (or (= (preceding-char) ?\n)
3840 (let ((case-fold-search t))
3841 ;; Remove the delimiter.
3842 (goto-char (point-min))
3844 (concat "^" (regexp-quote mail-header-separator) "\n"))
3845 (replace-match "\n")
3847 (run-hooks 'message-send-news-hook)
3848 (gnus-open-server method)
3849 (message "Sending news via %s..." (gnus-server-string method))
3850 (setq result (let ((mail-header-separator ""))
3851 (gnus-request-post method))))
3852 (kill-buffer tembuf))
3853 (set-buffer messbuf)
3855 (push 'news message-sent-message-via)
3856 (message "Couldn't send message via news: %s"
3857 (nnheader-get-report (car method)))
3861 ;;; Header generation & syntax checking.
3864 (defun message-check-element (type)
3865 "Return non-nil if this TYPE is not to be checked."
3866 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3868 (let ((able (assq type message-syntax-checks)))
3870 (eq (cdr able) 'disabled)))))
3872 (defun message-check-news-syntax ()
3873 "Check the syntax of the message."
3877 ;; We narrow to the headers and check them first.
3880 (message-narrow-to-headers)
3881 (message-check-news-header-syntax))))))
3883 (defun message-check-news-header-syntax ()
3885 ;; Check Newsgroups header.
3886 (message-check 'newsgroups
3887 (let ((group (message-fetch-field "newsgroups")))
3890 (not (string-match "\\`[ \t]*\\'" group)))
3893 "The newsgroups field is empty or missing. Posting is denied.")))))
3894 ;; Check the Subject header.
3895 (message-check 'subject
3896 (let* ((case-fold-search t)
3897 (subject (message-fetch-field "subject")))
3900 (not (string-match "\\`[ \t]*\\'" subject)))
3903 "The subject field is empty or missing. Posting is denied.")))))
3904 ;; Check for commands in Subject.
3905 (message-check 'subject-cmsg
3906 (if (string-match "^cmsg " (message-fetch-field "subject"))
3908 "The control code \"cmsg\" is in the subject. Really post? ")
3910 ;; Check long header lines.
3911 (message-check 'long-header-lines
3912 (let ((start (point))
3916 (while (and (not found)
3917 (re-search-forward "^\\([^ \t:]+\\): " nil t))
3918 (if (> (- (point) (match-beginning 0)) 998)
3920 length (- (point) (match-beginning 0)))
3921 (setq header (match-string-no-properties 1)))
3922 (setq start (match-beginning 0))
3925 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
3928 ;; Check for multiple identical headers.
3929 (message-check 'multiple-headers
3931 (while (and (not found)
3932 (re-search-forward "^[^ \t:]+: " nil t))
3934 (or (re-search-forward
3939 (match-beginning 0) (- (match-end 0) 2))))
3944 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3946 ;; Check for Version and Sendsys.
3947 (message-check 'sendsys
3948 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3950 (format "The article contains a %s command. Really post? "
3951 (buffer-substring (match-beginning 0)
3952 (1- (match-end 0)))))
3954 ;; See whether we can shorten Followup-To.
3955 (message-check 'shorten-followup-to
3956 (let ((newsgroups (message-fetch-field "newsgroups"))
3957 (followup-to (message-fetch-field "followup-to"))
3959 (when (and newsgroups
3960 (string-match "," newsgroups)
3965 (setq to (completing-read
3966 "Followups to (default: no Followup-To header) "
3969 (message-tokenize-header
3971 (goto-char (point-min))
3972 (insert "Followup-To: " to "\n"))
3974 ;; Check "Shoot me".
3975 (message-check 'shoot
3976 (if (re-search-forward
3977 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
3978 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3980 ;; Check for Approved.
3981 (message-check 'approved
3982 (if (re-search-forward "^Approved:" nil t)
3983 (y-or-n-p "The article contains an Approved header. Really post? ")
3985 ;; Check the Message-ID header.
3986 (message-check 'message-id
3987 (let* ((case-fold-search t)
3988 (message-id (message-fetch-field "message-id" t)))
3989 (or (not message-id)
3990 ;; Is there an @ in the ID?
3991 (and (string-match "@" message-id)
3992 ;; Is there a dot in the ID?
3993 (string-match "@[^.]*\\." message-id)
3994 ;; Does the ID end with a dot?
3995 (not (string-match "\\.>" message-id)))
3997 (format "The Message-ID looks strange: \"%s\". Really post? "
3999 ;; Check the Newsgroups & Followup-To headers.
4000 (message-check 'existing-newsgroups
4001 (let* ((case-fold-search t)
4002 (newsgroups (message-fetch-field "newsgroups"))
4003 (followup-to (message-fetch-field "followup-to"))
4004 (groups (message-tokenize-header
4006 (concat newsgroups "," followup-to)
4008 (post-method (if (functionp message-post-method)
4009 (funcall message-post-method)
4010 message-post-method))
4011 ;; KLUDGE to handle nnvirtual groups. Doing this right
4012 ;; would probably involve a new nnoo function.
4013 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4014 (method (if (and (consp post-method)
4015 (eq (car post-method) 'nnvirtual)
4016 gnus-message-group-art)
4017 (let ((group (car (nnvirtual-find-group-art
4018 (car gnus-message-group-art)
4019 (cdr gnus-message-group-art)))))
4020 (gnus-find-method-for-group group))
4024 (gnus-group-name-decode
4025 (gnus-group-real-name n)
4026 (gnus-group-name-charset method n)))
4027 (gnus-groups-from-server method)))
4030 (when (and (not (equal (car groups) "poster"))
4031 (not (member (car groups) known-groups))
4032 (not (member (car groups) errors)))
4033 (push (car groups) errors))
4036 ;; Gnus is not running.
4037 ((or (not (and (boundp 'gnus-active-hashtb)
4038 gnus-active-hashtb))
4039 (not (boundp 'gnus-read-active-file)))
4041 ;; We don't have all the group names.
4042 ((and (or (not gnus-read-active-file)
4043 (eq gnus-read-active-file 'some))
4047 "Really use %s possibly unknown group%s: %s? "
4048 (if (= (length errors) 1) "this" "these")
4049 (if (= (length errors) 1) "" "s")
4050 (mapconcat 'identity errors ", "))))
4051 ;; There were no errors.
4054 ;; There are unknown groups.
4058 "Really post to %s unknown group%s: %s? "
4059 (if (= (length errors) 1) "this" "these")
4060 (if (= (length errors) 1) "" "s")
4061 (mapconcat 'identity errors ", ")))))))
4062 ;; Check continuation headers.
4063 (message-check 'continuation-headers
4064 (goto-char (point-min))
4065 (let ((do-posting t))
4066 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4067 (if (y-or-n-p "Fix continuation lines? ")
4069 (goto-char (match-beginning 0))
4071 (unless (y-or-n-p "Send anyway? ")
4072 (setq do-posting nil))))
4074 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4075 (message-check 'valid-newsgroups
4076 (let ((case-fold-search t)
4077 (headers '("Newsgroups" "Followup-To"))
4079 (while (and headers (not error))
4080 (when (setq header (mail-fetch-field (car headers)))
4084 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4089 (not (string-match "\\.\\'\\|\\.\\." g)))
4090 (message-tokenize-header header ","))))
4097 (format "The %s header looks odd: \"%s\". Really post? "
4098 (car headers) header)))))
4099 (message-check 'repeated-newsgroups
4100 (let ((case-fold-search t)
4101 (headers '("Newsgroups" "Followup-To"))
4102 header error groups group)
4105 (when (setq header (mail-fetch-field (pop headers)))
4106 (setq groups (message-tokenize-header header ","))
4107 (while (setq group (pop groups))
4108 (when (member group groups)
4114 (format "Group %s is repeated in headers. Really post? " error)))))
4115 ;; Check the From header.
4116 (message-check 'from
4117 (let* ((case-fold-search t)
4118 (from (message-fetch-field "from"))
4122 (message "There is no From line. Posting is denied.")
4124 ((or (not (string-match
4126 (setq ad (nth 1 (mail-extract-address-components
4127 from))))) ;larsi@ifi
4128 (string-match "\\.\\." ad) ;larsi@ifi..uio
4129 (string-match "@\\." ad) ;larsi@.ifi.uio
4130 (string-match "\\.$" ad) ;larsi@ifi.uio.
4131 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4132 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4134 "Denied posting -- the From looks strange: \"%s\"." from)
4136 ((let ((addresses (rfc822-addresses from)))
4137 (while (and addresses
4138 (not (eq (string-to-char (car addresses)) ?\()))
4139 (setq addresses (cdr addresses)))
4142 "Denied posting -- bad From address: \"%s\"." from)
4145 ;; Check the Reply-To header.
4146 (message-check 'reply-to
4147 (let* ((case-fold-search t)
4148 (reply-to (message-fetch-field "reply-to"))
4153 ((string-match "," reply-to)
4155 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4157 ((or (not (string-match
4159 (setq ad (nth 1 (mail-extract-address-components
4160 reply-to))))) ;larsi@ifi
4161 (string-match "\\.\\." ad) ;larsi@ifi..uio
4162 (string-match "@\\." ad) ;larsi@.ifi.uio
4163 (string-match "\\.$" ad) ;larsi@ifi.uio.
4164 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4165 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4168 "The Reply-To looks strange: \"%s\". Really post? "
4172 (defun message-check-news-body-syntax ()
4174 ;; Check for long lines.
4175 (message-check 'long-lines
4176 (goto-char (point-min))
4178 (concat "^" (regexp-quote mail-header-separator) "$"))
4182 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4185 (< (- (point) p) 80)))
4186 (zerop (forward-line 1))))
4190 "You have lines longer than 79 characters. Really post? ")))
4191 ;; Check whether the article is empty.
4192 (message-check 'empty
4193 (goto-char (point-min))
4195 (concat "^" (regexp-quote mail-header-separator) "$"))
4198 (goto-char (point-max))
4199 (re-search-backward message-signature-separator nil t)
4201 (or (re-search-backward "[^ \n\t]" b t)
4202 (if (message-gnksa-enable-p 'empty-article)
4203 (y-or-n-p "Empty article. Really post? ")
4204 (message "Denied posting -- Empty article.")
4206 ;; Check for control characters.
4207 (message-check 'control-chars
4208 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4210 "The article contains control characters. Really post? ")
4212 ;; Check excessive size.
4213 (message-check 'size
4214 (if (> (buffer-size) 60000)
4216 (format "The article is %d octets long. Really post? "
4219 ;; Check whether any new text has been added.
4220 (message-check 'new-text
4222 (not message-checksum)
4223 (not (eq (message-checksum) message-checksum))
4224 (if (message-gnksa-enable-p 'quoted-text-only)
4226 "It looks like no new text has been added. Really post? ")
4227 (message "Denied posting -- no new text has been added.")
4229 ;; Check the length of the signature.
4230 (message-check 'signature
4231 (goto-char (point-max))
4232 (if (> (count-lines (point) (point-max)) 5)
4235 "Your .sig is %d lines; it should be max 4. Really post? "
4236 (1- (count-lines (point) (point-max)))))
4238 ;; Ensure that text follows last quoted portion.
4239 (message-check 'quoting-style
4240 (goto-char (point-max))
4241 (let ((no-problem t))
4242 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4243 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4246 (if (message-gnksa-enable-p 'quoted-text-only)
4247 (y-or-n-p "Your text should follow quoted text. Really post? ")
4249 (goto-char (point-min))
4251 (concat "^" (regexp-quote mail-header-separator) "$"))
4252 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4253 (y-or-n-p "Your text should follow quoted text. Really post? ")
4254 (message "Denied posting -- only quoted text.")
4257 (defun message-checksum ()
4258 "Return a \"checksum\" for the current buffer."
4261 (goto-char (point-min))
4263 (concat "^" (regexp-quote mail-header-separator) "$"))
4265 (when (not (looking-at "[ \t\n]"))
4266 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4271 (defun message-do-fcc ()
4272 "Process Fcc headers in the current buffer."
4273 (let ((case-fold-search t)
4274 (buf (current-buffer))
4276 (mml-externalize-attachments message-fcc-externalize-attachments))
4279 (message-narrow-to-headers)
4280 (setq file (message-fetch-field "fcc" t)))
4282 (set-buffer (get-buffer-create " *message temp*"))
4284 (insert-buffer-substring buf)
4285 (message-encode-message-body)
4287 (message-narrow-to-headers)
4288 (while (setq file (message-fetch-field "fcc" t))
4290 (message-remove-header "fcc" nil t))
4291 (let ((mail-parse-charset message-default-charset)
4292 (rfc2047-header-encoding-alist
4293 (cons '("Newsgroups" . default)
4294 rfc2047-header-encoding-alist)))
4295 (mail-encode-encoded-word-buffer)))
4296 (goto-char (point-min))
4297 (when (re-search-forward
4298 (concat "^" (regexp-quote mail-header-separator) "$")
4300 (replace-match "" t t ))
4301 ;; Process FCC operations.
4303 (setq file (pop list))
4304 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4305 ;; Pipe the article to the program in question.
4306 (call-process-region (point-min) (point-max) shell-file-name
4307 nil nil nil shell-command-switch
4308 (match-string 1 file))
4309 ;; Save the article.
4310 (setq file (expand-file-name file))
4311 (unless (file-exists-p (file-name-directory file))
4312 (make-directory (file-name-directory file) t))
4313 (if (and message-fcc-handler-function
4314 (not (eq message-fcc-handler-function 'rmail-output)))
4315 (funcall message-fcc-handler-function file)
4316 (if (and (file-readable-p file) (mail-file-babyl-p file))
4317 (rmail-output file 1 nil t)
4318 (let ((mail-use-rfc822 t))
4319 (rmail-output file 1 t t))))))
4320 (kill-buffer (current-buffer))))))
4322 (defun message-output (filename)
4323 "Append this article to Unix/babyl mail file FILENAME."
4324 (if (and (file-readable-p filename)
4325 (mail-file-babyl-p filename))
4326 (gnus-output-to-rmail filename t)
4327 (gnus-output-to-mail filename t)))
4329 (defun message-cleanup-headers ()
4330 "Do various automatic cleanups of the headers."
4331 ;; Remove empty lines in the header.
4333 (message-narrow-to-headers)
4334 ;; Remove blank lines.
4335 (while (re-search-forward "^[ \t]*\n" nil t)
4336 (replace-match "" t t))
4338 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4339 ;; spaces to comma and eliminate spaces around commas. Eliminate
4340 ;; embedded line breaks.
4341 (goto-char (point-min))
4342 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4346 (if (re-search-forward "^[^ \t]" nil t)
4350 (goto-char (point-min))
4351 (while (re-search-forward "\n[ \t]+" nil t)
4352 (replace-match " " t t)) ;No line breaks (too confusing)
4353 (goto-char (point-min))
4354 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4355 (replace-match "," t t))
4356 (goto-char (point-min))
4357 ;; Remove trailing commas.
4358 (when (re-search-forward ",+$" nil t)
4359 (replace-match "" t t))))))
4361 (defun message-make-date (&optional now)
4362 "Make a valid data header.
4363 If NOW, use that time instead."
4364 (let* ((now (or now (current-time)))
4365 (zone (nth 8 (decode-time now)))
4369 (setq zone (- zone)))
4371 ;; The day name of the %a spec is locale-specific. Pfff.
4372 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4373 parse-time-weekdays))))
4374 (format-time-string "%d" now)
4375 ;; The month name of the %b spec is locale-specific. Pfff.
4377 (capitalize (car (rassoc (nth 4 (decode-time now))
4378 parse-time-months))))
4379 (format-time-string "%Y %H:%M:%S " now)
4380 ;; We do all of this because XEmacs doesn't have the %z spec.
4381 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4383 (defun message-make-message-id ()
4384 "Make a unique Message-ID."
4385 (concat "<" (message-unique-id)
4386 (let ((psubject (save-excursion (message-fetch-field "subject")))
4388 (save-excursion (message-fetch-field "supersedes"))))
4390 (and message-reply-headers
4391 (mail-header-references message-reply-headers)
4392 (mail-header-subject message-reply-headers)
4395 (message-strip-subject-re
4396 (mail-header-subject message-reply-headers))
4397 (message-strip-subject-re psubject))))
4399 (string-match "_-_@" psupersedes)))
4401 "@" (message-make-fqdn) ">"))
4403 (defvar message-unique-id-char nil)
4405 ;; If you ever change this function, make sure the new version
4406 ;; cannot generate IDs that the old version could.
4407 ;; You might for example insert a "." somewhere (not next to another dot
4408 ;; or string boundary), or modify the "fsf" string.
4409 (defun message-unique-id ()
4410 ;; Don't use microseconds from (current-time), they may be unsupported.
4411 ;; Instead we use this randomly inited counter.
4412 (setq message-unique-id-char
4413 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4414 ;; (current-time) returns 16-bit ints,
4415 ;; and 2^16*25 just fits into 4 digits i base 36.
4417 (let ((tm (current-time)))
4419 (if (memq system-type '(ms-dos emx vax-vms))
4420 (let ((user (downcase (user-login-name))))
4421 (while (string-match "[^a-z0-9_]" user)
4422 (aset user (match-beginning 0) ?_))
4424 (message-number-base36 (user-uid) -1))
4425 (message-number-base36 (+ (car tm)
4426 (lsh (% message-unique-id-char 25) 16)) 4)
4427 (message-number-base36 (+ (nth 1 tm)
4428 (lsh (/ message-unique-id-char 25) 16)) 4)
4429 ;; Append a given name, because while the generated ID is unique
4430 ;; to this newsreader, other newsreaders might otherwise generate
4431 ;; the same ID via another algorithm.
4434 (defun message-number-base36 (num len)
4439 (concat (message-number-base36 (/ num 36) (1- len))
4440 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4443 (defun message-make-organization ()
4444 "Make an Organization header."
4445 (let* ((organization
4446 (when message-user-organization
4447 (if (functionp message-user-organization)
4448 (funcall message-user-organization)
4449 message-user-organization))))
4451 (mm-enable-multibyte)
4452 (cond ((stringp organization)
4453 (insert organization))
4454 ((and (eq t organization)
4455 message-user-organization-file
4456 (file-exists-p message-user-organization-file))
4457 (insert-file-contents message-user-organization-file)))
4458 (goto-char (point-min))
4459 (while (re-search-forward "[\t\n]+" nil t)
4460 (replace-match "" t t))
4461 (unless (zerop (buffer-size))
4464 (defun message-make-lines ()
4465 "Count the number of lines and return numeric string."
4470 (int-to-string (count-lines (point) (point-max))))))
4472 (defun message-make-references ()
4473 "Return the References header for this message."
4474 (when message-reply-headers
4475 (let ((message-id (mail-header-message-id message-reply-headers))
4476 (references (mail-header-references message-reply-headers))
4478 (if (or references message-id)
4479 (concat (or references "") (and references " ")
4483 (defun message-make-in-reply-to ()
4484 "Return the In-Reply-To header for this message."
4485 (when message-reply-headers
4486 (let ((from (mail-header-from message-reply-headers))
4487 (date (mail-header-date message-reply-headers))
4488 (msg-id (mail-header-message-id message-reply-headers)))
4490 (let ((name (mail-extract-address-components from)))
4491 (concat msg-id (if msg-id " (")
4495 (if (or (not date) (string= date ""))
4496 "(unknown date)" date)
4497 "\"" (if msg-id ")")))))))
4499 (defun message-make-distribution ()
4500 "Make a Distribution header."
4501 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4502 (cond ((functionp message-distribution-function)
4503 (funcall message-distribution-function))
4504 (t orig-distribution))))
4506 (defun message-make-expires ()
4507 "Return an Expires header based on `message-expires'."
4508 (let ((current (current-time))
4509 (future (* 1.0 message-expires 60 60 24)))
4510 ;; Add the future to current.
4511 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4512 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4513 (message-make-date current)))
4515 (defun message-make-path ()
4517 (let ((login-name (user-login-name)))
4518 (cond ((null message-user-path)
4519 (concat (system-name) "!" login-name))
4520 ((stringp message-user-path)
4521 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4522 (concat message-user-path "!" login-name))
4525 (defun message-make-from ()
4526 "Make a From header."
4527 (let* ((style message-from-style)
4528 (login (message-make-address))
4530 (or (and (boundp 'user-full-name)
4533 (when (string= fullname "&")
4534 (setq fullname (user-login-name)))
4536 (mm-enable-multibyte)
4539 (equal fullname ""))
4541 ((or (eq style 'angles)
4542 (and (not (eq style 'parens))
4543 ;; Use angles if no quoting is needed, or if parens would
4544 ;; need quoting too.
4545 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4546 (let ((tmp (concat fullname nil)))
4547 (while (string-match "([^()]*)" tmp)
4548 (aset tmp (match-beginning 0) ?-)
4549 (aset tmp (1- (match-end 0)) ?-))
4550 (string-match "[\\()]" tmp)))))
4552 (insert " <" login ">"))
4553 (t ; 'parens or default
4555 (let ((fullname-start (point)))
4557 (goto-char fullname-start)
4558 ;; RFC 822 says \ and nonmatching parentheses
4559 ;; must be escaped in comments.
4560 ;; Escape every instance of ()\ ...
4561 (while (re-search-forward "[()\\]" nil 1)
4562 (replace-match "\\\\\\&" t))
4563 ;; ... then undo escaping of matching parentheses,
4564 ;; including matching nested parentheses.
4565 (goto-char fullname-start)
4566 (while (re-search-forward
4567 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4569 (replace-match "\\1(\\3)" t)
4570 (goto-char fullname-start)))
4574 (defun message-make-sender ()
4575 "Return the \"real\" user address.
4576 This function tries to ignore all user modifications, and
4577 give as trustworthy answer as possible."
4578 (concat (user-login-name) "@" (system-name)))
4580 (defun message-make-address ()
4581 "Make the address of the user."
4582 (or (message-user-mail-address)
4583 (concat (user-login-name) "@" (message-make-domain))))
4585 (defun message-user-mail-address ()
4586 "Return the pertinent part of `user-mail-address'."
4587 (when (and user-mail-address
4588 (string-match "@.*\\." user-mail-address))
4589 (if (string-match " " user-mail-address)
4590 (nth 1 (mail-extract-address-components user-mail-address))
4591 user-mail-address)))
4593 (defun message-sendmail-envelope-from ()
4594 "Return the envelope from."
4595 (cond ((eq message-sendmail-envelope-from 'header)
4596 (nth 1 (mail-extract-address-components
4597 (message-fetch-field "from"))))
4598 ((stringp message-sendmail-envelope-from)
4599 message-sendmail-envelope-from)
4601 (message-make-address))))
4603 (defun message-make-fqdn ()
4604 "Return user's fully qualified domain name."
4605 (let* ((system-name (system-name))
4606 (user-mail (message-user-mail-address))
4609 (string-match "@\\(.*\\)\\'" user-mail))
4610 (match-string 1 user-mail))))
4612 ((and message-user-fqdn
4613 (stringp message-user-fqdn)
4614 (string-match message-valid-fqdn-regexp message-user-fqdn)
4615 (not (string-match message-bogus-system-names message-user-fqdn)))
4617 ;; `message-user-fqdn' seems to be valid
4618 ((and (string-match message-valid-fqdn-regexp system-name)
4619 (not (string-match message-bogus-system-names system-name)))
4620 ;; `system-name' returned the right result.
4622 ;; Try `mail-host-address'.
4623 ((and (boundp 'mail-host-address)
4624 (stringp mail-host-address)
4625 (string-match message-valid-fqdn-regexp mail-host-address)
4626 (not (string-match message-bogus-system-names mail-host-address)))
4628 ;; We try `user-mail-address' as a backup.
4630 (stringp user-domain)
4631 (string-match message-valid-fqdn-regexp user-domain)
4632 (not (string-match message-bogus-system-names user-domain)))
4634 ;; Default to this bogus thing.
4637 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4639 (defun message-make-host-name ()
4640 "Return the name of the host."
4641 (let ((fqdn (message-make-fqdn)))
4642 (string-match "^[^.]+\\." fqdn)
4643 (substring fqdn 0 (1- (match-end 0)))))
4645 (defun message-make-domain ()
4646 "Return the domain name."
4647 (or mail-host-address
4648 (message-make-fqdn)))
4650 (defun message-to-list-only ()
4651 "Send a message to the list only.
4652 Remove all addresses but the list address from To and Cc headers."
4654 (let ((listaddr (message-make-mail-followup-to t)))
4657 (message-remove-header "to")
4658 (message-remove-header "cc")
4659 (message-position-on-field "To" "X-Draft-From")
4660 (insert listaddr)))))
4662 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4663 "Return the Mail-Followup-To header.
4664 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4665 subscribed address (and not the additional To and Cc header contents)."
4666 (let* ((case-fold-search t)
4667 (to (message-fetch-field "To"))
4668 (cc (message-fetch-field "cc"))
4669 (msg-recipients (concat to (and to cc ", ") cc))
4671 (mapcar 'mail-strip-quoted-names
4672 (message-tokenize-header msg-recipients)))
4674 (if message-subscribed-address-file
4675 (let (begin end item re)
4678 (insert-file-contents message-subscribed-address-file)
4680 (setq begin (point))
4683 (if (bolp) (setq end (1- end)))
4684 (setq item (regexp-quote (buffer-substring begin end)))
4685 (if re (setq re (concat re "\\|" item))
4686 (setq re (concat "\\`\\(" item))))
4687 (and re (list (concat re "\\)\\'"))))))))
4688 (mft-regexps (apply 'append message-subscribed-regexps
4689 (mapcar 'regexp-quote
4690 message-subscribed-addresses)
4693 message-subscribed-address-functions))))
4695 (let ((subscribed-lists nil)
4697 (loop for recipient in recipients
4698 when (loop for regexp in mft-regexps
4699 when (string-match regexp recipient) return t)
4702 (if only-show-subscribed
4704 msg-recipients))))))
4706 (defun message-idna-inside-rhs-p ()
4707 "Return t iff point is inside a RHS (heuristically).
4708 Only works properly if header contains mailbox-list or address-list.
4709 I.e., calling it on a Subject: header is useless."
4711 (narrow-to-region (save-excursion (or (re-search-backward "^[^ \t]" nil t)
4713 (save-excursion (or (re-search-forward "^[^ \t]" nil t)
4715 (if (re-search-backward "[\\\n\r\t ]"
4716 (save-excursion (search-backward "@" nil t)) t)
4717 ;; whitespace between @ and point
4719 (let ((dquote 1) (paren 1))
4720 (while (save-excursion (re-search-backward "[^\\]\"" nil t dquote))
4722 (while (save-excursion (re-search-backward "[^\\]\(" nil t paren))
4724 (and (= (% dquote 2) 1) (= (% paren 2) 1))))))
4726 (autoload 'idna-to-ascii "idna")
4728 (defun message-idna-to-ascii-rhs-1 (header)
4729 "Interactively potentially IDNA encode domain names in HEADER."
4730 (let (rhs ace start startpos endpos ovl)
4731 (goto-char (point-min))
4732 (while (re-search-forward (concat "^" header) nil t)
4733 (while (re-search-forward "@\\([^ \t\r\n>]+\\)"
4735 (re-search-forward "^[^ \t]" nil t))
4738 (setq rhs (match-string-no-properties 1)
4739 startpos (match-beginning 1)
4740 endpos (match-end 1))
4741 (when (save-match-data
4742 (and (message-idna-inside-rhs-p)
4743 (setq ace (idna-to-ascii rhs))
4744 (not (string= rhs ace))
4745 (if (eq message-use-idna 'ask)
4748 (setq ovl (message-make-overlay startpos
4750 (message-overlay-put ovl 'face 'highlight)
4752 (format "Replace with `%s'? " ace)))
4754 (message-delete-overlay ovl))
4756 (replace-match (concat "@" ace)))))))
4758 (defun message-idna-to-ascii-rhs ()
4759 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4760 See `message-idna-encode'."
4762 (when message-use-idna
4765 (message-narrow-to-head)
4766 (message-idna-to-ascii-rhs-1 "From")
4767 (message-idna-to-ascii-rhs-1 "To")
4768 (message-idna-to-ascii-rhs-1 "Cc")))))
4770 (defun message-generate-headers (headers)
4771 "Prepare article HEADERS.
4772 Headers already prepared in the buffer are not modified."
4773 (setq headers (append headers message-required-headers))
4775 (message-narrow-to-headers)
4776 (let* ((Date (message-make-date))
4777 (Message-ID (message-make-message-id))
4778 (Organization (message-make-organization))
4779 (From (message-make-from))
4780 (Path (message-make-path))
4783 (In-Reply-To (message-make-in-reply-to))
4784 (References (message-make-references))
4786 (Distribution (message-make-distribution))
4787 (Lines (message-make-lines))
4788 (User-Agent message-newsreader)
4789 (Expires (message-make-expires))
4790 (case-fold-search t)
4793 ;; First we remove any old generated headers.
4794 (let ((headers message-deletable-headers))
4795 (unless (buffer-modified-p)
4796 (setq headers (delq 'Message-ID (copy-sequence headers))))
4798 (goto-char (point-min))
4799 (and (re-search-forward
4800 (concat "^" (symbol-name (car headers)) ": *") nil t)
4801 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4802 (message-delete-line))
4804 ;; Go through all the required headers and see if they are in the
4805 ;; articles already. If they are not, or are empty, they are
4806 ;; inserted automatically - except for Subject, Newsgroups and
4809 (goto-char (point-min))
4810 (setq elem (pop headers))
4812 (if (eq (car elem) 'optional)
4813 (setq header (cdr elem)
4815 (setq header (car elem)))
4817 (when (or (not (re-search-forward
4821 (if (stringp header)
4823 (symbol-name header))))
4827 ;; The header was found. We insert a space after the
4828 ;; colon, if there is none.
4829 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4830 ;; Find out whether the header is empty.
4831 (looking-at "[ \t]*\n[^ \t]")))
4832 ;; So we find out what value we should insert.
4836 (eq (car elem) 'optional))
4837 ;; This is an optional header. If the cdr of this
4838 ;; is something that is nil, then we do not insert
4840 (setq header (cdr elem))
4841 (or (and (functionp (cdr elem))
4842 (funcall (cdr elem)))
4843 (and (boundp (cdr elem))
4844 (symbol-value (cdr elem)))))
4846 ;; The element is a cons. Either the cdr is a
4847 ;; string to be inserted verbatim, or it is a
4848 ;; function, and we insert the value returned from
4850 (or (and (stringp (cdr elem))
4852 (and (functionp (cdr elem))
4853 (funcall (cdr elem)))))
4854 ((and (boundp header)
4855 (symbol-value header))
4856 ;; The element is a symbol. We insert the value
4857 ;; of this symbol, if any.
4858 (symbol-value header))
4859 ((not (message-check-element header))
4860 ;; We couldn't generate a value for this header,
4861 ;; so we just ask the user.
4862 (read-from-minibuffer
4863 (format "Empty header for %s; enter value: " header)))))
4864 ;; Finally insert the header.
4866 (not (equal value "")))
4870 ;; This header didn't exist, so we insert it.
4871 (goto-char (point-max))
4873 (cdr (assq header message-header-format-alist))))
4875 (funcall formatter header value)
4876 (insert (if (stringp header)
4877 header (symbol-name header))
4879 ;; We check whether the value was ended by a
4880 ;; newline. If now, we insert one.
4884 ;; The value of this header was empty, so we clear
4885 ;; totally and insert the new value.
4886 (delete-region (point) (gnus-point-at-eol))
4887 ;; If the header is optional, and the header was
4888 ;; empty, we con't insert it anyway.
4891 ;; Add the deletable property to the headers that require it.
4892 (and (memq header message-deletable-headers)
4893 (progn (beginning-of-line) (looking-at "[^:]+: "))
4894 (add-text-properties
4895 (point) (match-end 0)
4896 '(message-deletable t face italic) (current-buffer)))))))
4897 ;; Insert new Sender if the From is strange.
4898 (let ((from (message-fetch-field "from"))
4899 (sender (message-fetch-field "sender"))
4900 (secure-sender (message-make-sender)))
4902 (not (message-check-element 'sender))
4905 (cadr (mail-extract-address-components from)))
4906 (downcase secure-sender)))
4911 (cadr (mail-extract-address-components sender)))
4912 (downcase secure-sender)))))
4913 (goto-char (point-min))
4914 ;; Rename any old Sender headers to Original-Sender.
4915 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4917 (insert "Original-")
4918 (beginning-of-line))
4919 (when (or (message-news-p)
4920 (string-match "@.+\\.." secure-sender))
4921 (insert "Sender: " secure-sender "\n"))))
4923 (message-idna-to-ascii-rhs))))
4925 (defun message-insert-courtesy-copy ()
4926 "Insert a courtesy message in mail copies of combined messages."
4930 (message-narrow-to-headers)
4931 (when (setq newsgroups (message-fetch-field "newsgroups"))
4932 (goto-char (point-max))
4933 (insert "Posted-To: " newsgroups "\n")))
4935 (when message-courtesy-message
4937 ((string-match "%s" message-courtesy-message)
4938 (insert (format message-courtesy-message newsgroups)))
4940 (insert message-courtesy-message)))))))
4943 ;;; Setting up a message buffer
4946 (defun message-fill-address (header value)
4948 (narrow-to-region (point) (point))
4949 (insert (capitalize (symbol-name header))
4951 (if (consp value) (car value) value)
4953 (narrow-to-region (point-min) (1- (point-max)))
4955 (goto-char (point-min))
4957 (skip-chars-forward "^,\"" (point-max))
4958 (if (or (eq (char-after) ?,)
4961 (if (and (> (current-column) 78)
4967 (setq last (1+ (point))))
4968 (setq last (1+ (point)))))
4969 (setq quoted (not quoted)))
4972 (goto-char (point-max))
4976 (defun message-split-line ()
4977 "Split current line, moving portion beyond point vertically down.
4978 If the current line has `message-yank-prefix', insert it on the new line."
4981 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
4986 (defun message-fill-header (header value)
4987 (let ((begin (point))
4990 (insert (capitalize (symbol-name header))
4992 (if (consp value) (car value) value)
4995 (narrow-to-region begin (point))
4996 (fill-region-as-paragraph begin (point))
4997 ;; Tapdance around looong Message-IDs.
4999 (when (looking-at "[ \t]*$")
5000 (message-delete-line))
5002 (re-search-forward ":" nil t)
5003 (when (looking-at "\n[ \t]+")
5004 (replace-match " " t t))
5005 (goto-char (point-max)))))
5007 (defun message-shorten-1 (list cut surplus)
5008 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5009 (setcdr (nthcdr (- cut 2) list)
5010 (nthcdr (+ (- cut 2) surplus 1) list)))
5012 (defun message-shorten-references (header references)
5013 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5014 If folding is disallowed, also check that the REFERENCES are less
5015 than 988 characters long, and if they are not, trim them until they are."
5022 (goto-char (point-min))
5023 ;; Cons a list of valid references.
5024 (while (re-search-forward "<[^>]+>" nil t)
5025 (push (match-string 0) refs))
5026 (setq refs (nreverse refs)
5027 count (length refs)))
5029 ;; If the list has more than MAXCOUNT elements, trim it by
5030 ;; removing the CUTth element and the required number of
5031 ;; elements that follow.
5032 (when (> count maxcount)
5033 (let ((surplus (- count maxcount)))
5034 (message-shorten-1 refs cut surplus)
5035 (decf count surplus)))
5037 ;; If folding is disallowed, make sure the total length (including
5038 ;; the spaces between) will be less than MAXSIZE characters.
5040 ;; Only disallow folding for News messages. At this point the headers
5041 ;; have not been generated, thus we use message-this-is-news directly.
5042 (when (and message-this-is-news message-cater-to-broken-inn)
5044 (totalsize (+ (apply #'+ (mapcar #'length refs))
5047 (ptr (nthcdr (1- cut) refs)))
5048 ;; Decide how many elements to cut off...
5049 (while (> totalsize maxsize)
5050 (decf totalsize (1+ (length (car ptr))))
5052 (setq ptr (cdr ptr)))
5055 (message-shorten-1 refs cut surplus))))
5057 ;; Finally, collect the references back into a string and insert
5058 ;; it into the buffer.
5059 (let ((refstring (mapconcat #'identity refs " ")))
5060 (if (and message-this-is-news message-cater-to-broken-inn)
5061 (insert (capitalize (symbol-name header)) ": "
5063 (message-fill-header header refstring)))))
5065 (defun message-position-point ()
5066 "Move point to where the user probably wants to find it."
5067 (message-narrow-to-headers)
5069 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5070 (search-backward ":" )
5073 (if (eq (char-after) ? )
5077 (goto-char (point-max))
5080 (unless (looking-at "$")
5084 (defcustom message-beginning-of-line t
5085 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5086 goes to beginning of header values."
5087 :group 'message-buffers
5090 (defun message-beginning-of-line (&optional n)
5091 "Move point to beginning of header value or to beginning of line.
5092 The prefix argument N is passed directly to `beginning-of-line'.
5094 This command is identical to `beginning-of-line' if point is
5095 outside the message header or if the option `message-beginning-of-line'
5098 If point is in the message header and on a (non-continued) header
5099 line, move point to the beginning of the header value. If point
5100 is already there, move point to beginning of line. Therefore,
5101 repeated calls will toggle point between beginning of field and
5104 (let ((zrs 'zmacs-region-stays))
5105 (when (and (interactive-p) (boundp zrs))
5107 (if (and message-beginning-of-line
5108 (message-point-in-header-p))
5109 (let* ((here (point))
5110 (bol (progn (beginning-of-line n) (point)))
5111 (eol (gnus-point-at-eol))
5112 (eoh (re-search-forward ": *" eol t)))
5113 (if (or (not eoh) (equal here eoh))
5116 (beginning-of-line n)))
5118 (defun message-buffer-name (type &optional to group)
5119 "Return a new (unique) buffer name based on TYPE and TO."
5121 ;; Generate a new buffer name The Message Way.
5122 ((eq message-generate-new-buffers 'unique)
5123 (generate-new-buffer-name
5127 (or (car (mail-extract-address-components to))
5130 (if (and group (not (string= group ""))) (concat " on " group) "")
5132 ;; Check whether `message-generate-new-buffers' is a function,
5133 ;; and if so, call it.
5134 ((functionp message-generate-new-buffers)
5135 (funcall message-generate-new-buffers type to group))
5136 ((eq message-generate-new-buffers 'unsent)
5137 (generate-new-buffer-name
5138 (concat "*unsent " type
5141 (or (car (mail-extract-address-components to))
5144 (if (and group (not (string= group ""))) (concat " on " group) "")
5146 ;; Use standard name.
5148 (format "*%s message*" type))))
5150 (defun message-pop-to-buffer (name)
5151 "Pop to buffer NAME, and warn if it already exists and is modified."
5152 (let ((buffer (get-buffer name)))
5154 (buffer-name buffer))
5156 (set-buffer (pop-to-buffer buffer))
5157 (when (and (buffer-modified-p)
5159 "Message already being composed; erase? ")))
5160 (error "Message being composed")))
5161 (set-buffer (pop-to-buffer name)))
5165 (defun message-do-send-housekeeping ()
5166 "Kill old message buffers."
5167 ;; We might have sent this buffer already. Delete it from the
5169 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5170 (while (and message-max-buffers
5172 (>= (length message-buffer-list) message-max-buffers))
5173 ;; Kill the oldest buffer -- unless it has been changed.
5174 (let ((buffer (pop message-buffer-list)))
5175 (when (and (buffer-name buffer)
5176 (not (buffer-modified-p buffer)))
5177 (kill-buffer buffer))))
5178 ;; Rename the buffer.
5179 (if message-send-rename-function
5180 (funcall message-send-rename-function)
5181 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5183 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5185 (let ((name (match-string 2 (buffer-name)))
5187 (if (not (or (null name)
5188 (string-equal name "mail")
5189 (string-equal name "posting")))
5190 (setq name (concat "*sent " name "*"))
5191 (message-narrow-to-headers)
5192 (setq to (message-fetch-field "to"))
5193 (setq group (message-fetch-field "newsgroups"))
5197 (to (concat "*sent mail to "
5198 (or (car (mail-extract-address-components to))
5200 ((and group (not (string= group "")))
5201 (concat "*sent posting on " group "*"))
5202 (t "*sent mail*"))))
5203 (unless (string-equal name (buffer-name))
5204 (rename-buffer name t)))))
5205 ;; Push the current buffer onto the list.
5206 (when message-max-buffers
5207 (setq message-buffer-list
5208 (nconc message-buffer-list (list (current-buffer))))))
5210 (defun message-mail-user-agent ()
5212 ((not message-mail-user-agent) nil)
5213 ((eq message-mail-user-agent t) mail-user-agent)
5214 (t message-mail-user-agent))))
5215 (if (memq mua '(message-user-agent gnus-user-agent))
5219 (defun message-setup (headers &optional replybuffer actions switch-function)
5220 (let ((mua (message-mail-user-agent))
5221 subject to field yank-action)
5222 (if (not (and message-this-is-mail mua))
5223 (message-setup-1 headers replybuffer actions)
5225 (setq yank-action (list 'insert-buffer replybuffer)))
5226 (setq headers (copy-sequence headers))
5227 (setq field (assq 'Subject headers))
5229 (setq subject (cdr field))
5230 (setq headers (delq field headers)))
5231 (setq field (assq 'To headers))
5233 (setq to (cdr field))
5234 (setq headers (delq field headers)))
5235 (let ((mail-user-agent mua))
5236 (compose-mail to subject
5237 (mapcar (lambda (item)
5239 (format "%s" (car item))
5242 nil switch-function yank-action actions)))))
5244 (defun message-headers-to-generate (headers included-headers excluded-headers)
5245 "Return a list that includes all headers from HEADERS.
5246 If INCLUDED-HEADERS is a list, just include those headers. If if is
5247 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5251 (dolist (header headers)
5252 (setq header-name (cond
5253 ((and (consp header)
5254 (eq (car header) 'optional))
5255 ;; On the form (optional . Header)
5258 ;; On the form (Header . function)
5263 (when (and (not (memq header-name excluded-headers))
5264 (or (eq included-headers t)
5265 (memq header-name included-headers)))
5266 (push header result)))
5269 (defun message-setup-1 (headers &optional replybuffer actions)
5270 (dolist (action actions)
5272 (add-to-list 'message-send-actions
5273 `(apply ',(car action) ',(cdr action)))))
5274 (setq message-reply-buffer replybuffer)
5275 (goto-char (point-min))
5276 ;; Insert all the headers.
5279 (alist message-header-format-alist))
5281 (unless (assq (caar h) message-header-format-alist)
5282 (push (list (caar h)) alist))
5286 (delete-region (point) (progn (forward-line -1) (point)))
5287 (when message-default-headers
5288 (insert message-default-headers)
5289 (or (bolp) (insert ?\n)))
5293 (insert mail-header-separator "\n")
5297 (when (message-news-p)
5298 (when message-default-news-headers
5299 (insert message-default-news-headers)
5300 (or (bolp) (insert ?\n)))
5301 (when message-generate-headers-first
5302 (message-generate-headers
5303 (message-headers-to-generate
5304 (append message-required-news-headers
5305 message-required-headers)
5306 message-generate-headers-first
5307 '(Lines Subject)))))
5308 (when (message-mail-p)
5309 (when message-default-mail-headers
5310 (insert message-default-mail-headers)
5311 (or (bolp) (insert ?\n)))
5313 (message-narrow-to-headers)
5314 (if message-alternative-emails
5315 (message-use-alternative-email-as-from)))
5316 (when message-generate-headers-first
5317 (message-generate-headers
5318 (message-headers-to-generate
5319 (append message-required-mail-headers
5320 message-required-headers)
5321 message-generate-headers-first
5322 '(Lines Subject)))))
5323 (run-hooks 'message-signature-setup-hook)
5324 (message-insert-signature)
5326 (message-narrow-to-headers)
5327 (run-hooks 'message-header-setup-hook))
5328 (set-buffer-modified-p nil)
5329 (setq buffer-undo-list nil)
5330 (run-hooks 'message-setup-hook)
5331 (message-position-point)
5334 (defun message-set-auto-save-file-name ()
5335 "Associate the message buffer with a file in the drafts directory."
5336 (when message-auto-save-directory
5337 (unless (file-directory-p
5338 (directory-file-name message-auto-save-directory))
5339 (make-directory message-auto-save-directory t))
5341 (setq message-draft-article
5342 (nndraft-request-associate-buffer "drafts"))
5343 (setq buffer-file-name (expand-file-name
5344 (if (memq system-type
5345 '(ms-dos ms-windows windows-nt
5346 cygwin cygwin32 win32 w32
5350 message-auto-save-directory))
5351 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5352 (clear-visited-file-modtime)
5353 (setq buffer-file-coding-system message-draft-coding-system)))
5355 (defun message-disassociate-draft ()
5356 "Disassociate the message buffer from the drafts directory."
5357 (when message-draft-article
5358 (nndraft-request-expire-articles
5359 (list message-draft-article) "drafts" nil t)))
5361 (defun message-insert-headers ()
5362 "Generate the headers for the article."
5366 (message-narrow-to-headers)
5367 (when (message-news-p)
5368 (message-generate-headers
5371 (copy-sequence message-required-news-headers)))))
5372 (when (message-mail-p)
5373 (message-generate-headers
5376 (copy-sequence message-required-mail-headers))))))))
5381 ;;; Commands for interfacing with message
5385 (defun message-mail (&optional to subject
5386 other-headers continue switch-function
5387 yank-action send-actions)
5388 "Start editing a mail message to be sent.
5389 OTHER-HEADERS is an alist of header/value pairs."
5391 (let ((message-this-is-mail t) replybuffer)
5392 (unless (message-mail-user-agent)
5393 (message-pop-to-buffer (message-buffer-name "mail" to)))
5394 ;; FIXME: message-mail should do something if YANK-ACTION is not
5396 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5397 (setq replybuffer (nth 1 yank-action)))
5400 `((To . ,(or to "")) (Subject . ,(or subject "")))
5401 (when other-headers other-headers))
5402 replybuffer send-actions)
5403 ;; FIXME: Should return nil if failure.
5407 (defun message-news (&optional newsgroups subject)
5408 "Start editing a news article to be sent."
5410 (let ((message-this-is-news t))
5411 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5412 (message-setup `((Newsgroups . ,(or newsgroups ""))
5413 (Subject . ,(or subject ""))))))
5415 (defun message-get-reply-headers (wide &optional to-address address-headers)
5416 (let (follow-to mct never-mct to cc author mft recipients)
5417 ;; Find all relevant headers we need.
5418 (setq to (message-fetch-field "to")
5419 cc (message-fetch-field "cc")
5420 mct (message-fetch-field "mail-copies-to")
5421 author (or (message-fetch-field "mail-reply-to")
5422 (message-fetch-field "reply-to")
5423 (message-fetch-field "from")
5425 mft (and message-use-mail-followup-to
5426 (message-fetch-field "mail-followup-to")))
5428 ;; Handle special values of Mail-Copies-To.
5430 (cond ((or (equal (downcase mct) "never")
5431 (equal (downcase mct) "nobody"))
5434 ((or (equal (downcase mct) "always")
5435 (equal (downcase mct) "poster"))
5436 (setq mct author))))
5439 ;; Build (textual) list of new recipient addresses.
5442 (setq recipients (concat ", " author)))
5444 (dolist (header address-headers)
5445 (let ((value (message-fetch-field header)))
5447 (setq recipients (concat recipients ", " value))))))
5449 (string-match "[^ \t,]" mft)
5450 (or (not (eq message-use-mail-followup-to 'ask))
5451 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5452 You should normally obey the Mail-Followup-To: header. In this
5453 article, it has the value of
5457 which directs your response to " (if (string-match "," mft)
5458 "the specified addresses"
5459 "that address only") ".
5461 Most commonly, Mail-Followup-To is used by a mailing list poster to
5462 express that responses should be sent to just the list, and not the
5465 If a message is posted to several mailing lists, Mail-Followup-To may
5466 also be used to direct the following discussion to one list only,
5467 because discussions that are spread over several lists tend to be
5468 fragmented and very difficult to follow.
5470 Also, some source/announcement lists are not intended for discussion;
5471 responses here are directed to other addresses.")))
5472 (setq recipients (concat ", " mft)))
5474 (setq recipients (concat ", " to-address))
5475 ;; If the author explicitly asked for a copy, we don't deny it to them.
5476 (if mct (setq recipients (concat recipients ", " mct))))
5478 (setq recipients (if never-mct "" (concat ", " author)))
5479 (if to (setq recipients (concat recipients ", " to)))
5480 (if cc (setq recipients (concat recipients ", " cc)))
5481 (if mct (setq recipients (concat recipients ", " mct)))))
5482 (if (>= (length recipients) 2)
5483 ;; Strip the leading ", ".
5484 (setq recipients (substring recipients 2)))
5485 ;; Squeeze whitespace.
5486 (while (string-match "[ \t][ \t]+" recipients)
5487 (setq recipients (replace-match " " t t recipients)))
5488 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5489 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5490 (setq recipients (rmail-dont-reply-to recipients)))
5491 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5492 (if (string-equal recipients "")
5493 (setq recipients author))
5494 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5498 (cons (downcase (mail-strip-quoted-names addr)) addr))
5499 (message-tokenize-header recipients)))
5500 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5501 (let ((s recipients))
5503 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5505 ;; Remove hierarchical lists that are contained within each other,
5506 ;; if message-hierarchical-addresses is defined.
5507 (when message-hierarchical-addresses
5508 (let ((plain-addrs (mapcar 'car recipients))
5511 (setq subaddrs (assoc (car plain-addrs)
5512 message-hierarchical-addresses)
5513 plain-addrs (cdr plain-addrs))
5515 (setq subaddrs (cdr subaddrs))
5517 (setq recip (assoc (car subaddrs) recipients)
5518 subaddrs (cdr subaddrs))
5520 (setq recipients (delq recip recipients))))))))
5522 ;; Build the header alist. Allow the user to be asked whether
5523 ;; or not to reply to all recipients in a wide reply.
5524 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5525 (when (and recipients
5526 (or (not message-wide-reply-confirm-recipients)
5527 (y-or-n-p "Reply to all recipients? ")))
5528 (setq recipients (mapconcat
5529 (lambda (addr) (cdr addr)) recipients ", "))
5530 (if (string-match "^ +" recipients)
5531 (setq recipients (substring recipients (match-end 0))))
5532 (push (cons 'Cc recipients) follow-to)))
5536 (defun message-reply (&optional to-address wide)
5537 "Start editing a reply to the article in the current buffer."
5539 (require 'gnus-sum) ; for gnus-list-identifiers
5540 (let ((cur (current-buffer))
5541 from subject date reply-to to cc
5542 references message-id follow-to
5543 (inhibit-point-motion-hooks t)
5544 (message-this-is-mail t)
5547 (message-narrow-to-head-1)
5548 ;; Allow customizations to have their say.
5550 ;; This is a regular reply.
5551 (when (functionp message-reply-to-function)
5553 (setq follow-to (funcall message-reply-to-function))))
5554 ;; This is a followup.
5555 (when (functionp message-wide-reply-to-function)
5558 (funcall message-wide-reply-to-function)))))
5559 (setq message-id (message-fetch-field "message-id" t)
5560 references (message-fetch-field "references")
5561 date (message-fetch-field "date")
5562 from (message-fetch-field "from")
5563 subject (or (message-fetch-field "subject") "none"))
5564 (when gnus-list-identifiers
5565 (setq subject (message-strip-list-identifiers subject)))
5566 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5567 (when message-subject-trailing-was-query
5568 (setq subject (message-strip-subject-trailing-was subject)))
5570 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5571 (string-match "<[^>]+>" gnus-warning))
5572 (setq message-id (match-string 0 gnus-warning)))
5575 (setq follow-to (message-get-reply-headers wide to-address))))
5577 (unless (message-mail-user-agent)
5578 (message-pop-to-buffer
5579 (message-buffer-name
5580 (if wide "wide reply" "reply") from
5581 (if wide to-address nil))))
5583 (setq message-reply-headers
5584 (vector 0 subject from date message-id references 0 0 ""))
5587 `((Subject . ,subject)
5592 (defun message-wide-reply (&optional to-address)
5593 "Make a \"wide\" reply to the message in the current buffer."
5595 (message-reply to-address t))
5598 (defun message-followup (&optional to-newsgroups)
5599 "Follow up to the message in the current buffer.
5600 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5602 (require 'gnus-sum) ; for gnus-list-identifiers
5603 (let ((cur (current-buffer))
5604 from subject date reply-to mrt mct
5605 references message-id follow-to
5606 (inhibit-point-motion-hooks t)
5607 (message-this-is-news t)
5608 followup-to distribution newsgroups gnus-warning posted-to)
5611 (goto-char (point-min))
5612 (if (search-forward "\n\n" nil t)
5615 (when (functionp message-followup-to-function)
5617 (funcall message-followup-to-function)))
5618 (setq from (message-fetch-field "from")
5619 date (message-fetch-field "date")
5620 subject (or (message-fetch-field "subject") "none")
5621 references (message-fetch-field "references")
5622 message-id (message-fetch-field "message-id" t)
5623 followup-to (message-fetch-field "followup-to")
5624 newsgroups (message-fetch-field "newsgroups")
5625 posted-to (message-fetch-field "posted-to")
5626 reply-to (message-fetch-field "reply-to")
5627 mrt (message-fetch-field "mail-reply-to")
5628 distribution (message-fetch-field "distribution")
5629 mct (message-fetch-field "mail-copies-to"))
5630 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5631 (string-match "<[^>]+>" gnus-warning))
5632 (setq message-id (match-string 0 gnus-warning)))
5633 ;; Remove bogus distribution.
5634 (when (and (stringp distribution)
5635 (let ((case-fold-search t))
5636 (string-match "world" distribution)))
5637 (setq distribution nil))
5638 (if gnus-list-identifiers
5639 (setq subject (message-strip-list-identifiers subject)))
5640 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5641 (when message-subject-trailing-was-query
5642 (setq subject (message-strip-subject-trailing-was subject)))
5645 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5647 (setq message-reply-headers
5648 (vector 0 subject from date message-id references 0 0 ""))
5651 `((Subject . ,subject)
5654 (list (cons 'Newsgroups to-newsgroups)))
5655 (follow-to follow-to)
5656 ((and followup-to message-use-followup-to)
5659 ((equal (downcase followup-to) "poster")
5660 (if (or (eq message-use-followup-to 'use)
5661 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5662 You should normally obey the Followup-To: header.
5664 `Followup-To: poster' sends your response via e-mail instead of news.
5666 A typical situation where `Followup-To: poster' is used is when the poster
5667 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5669 (setq message-this-is-news nil)
5670 (cons 'To (or mrt reply-to from "")))
5671 (cons 'Newsgroups newsgroups)))
5673 (if (or (equal followup-to newsgroups)
5674 (not (eq message-use-followup-to 'ask))
5676 (concat "Obey Followup-To: " followup-to "? ") t "\
5677 You should normally obey the Followup-To: header.
5679 `Followup-To: " followup-to "'
5680 directs your response to " (if (string-match "," followup-to)
5681 "the specified newsgroups"
5682 "that newsgroup only") ".
5684 If a message is posted to several newsgroups, Followup-To is often
5685 used to direct the following discussion to one newsgroup only,
5686 because discussions that are spread over several newsgroup tend to
5687 be fragmented and very difficult to follow.
5689 Also, some source/announcement newsgroups are not intended for discussion;
5690 responses here are directed to other newsgroups."))
5691 (cons 'Newsgroups followup-to)
5692 (cons 'Newsgroups newsgroups))))))
5694 `((Newsgroups . ,posted-to)))
5696 `((Newsgroups . ,newsgroups))))
5697 ,@(and distribution (list (cons 'Distribution distribution)))
5699 (not (or (equal (downcase mct) "never")
5700 (equal (downcase mct) "nobody"))))
5701 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5702 (equal (downcase mct) "poster"))
5703 (or mrt reply-to from "")
5709 ;; Must be dynamically bound for message-is-yours-p.
5713 (defun message-is-yours-p ()
5714 "Non-nil means current article is yours.
5715 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
5716 are yours except those that have Cancel-Lock header not belonging to you.
5717 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
5718 regexp to match all of yours addresses."
5719 ;; Canlock-logic as suggested by Per Abrahamsen
5720 ;; <abraham@dina.kvl.dk>
5722 ;; IF article has cancel-lock THEN
5723 ;; IF we can verify it THEN
5726 ;; error: cancellock: article is not yours
5728 ;; Use old rules, comparing sender...
5731 (message-narrow-to-head-1)
5732 (if (message-fetch-field "Cancel-Lock")
5733 (if (null (canlock-verify))
5735 (error "Failed to verify Cancel-lock: This article is not yours"))
5738 (message-gnksa-enable-p 'cancel-messages)
5739 (and (setq sender (message-fetch-field "sender"))
5740 (string-equal (downcase sender)
5741 (downcase (message-make-sender))))
5742 ;; Email address in From field equals to our address
5743 (and (setq from (message-fetch-field "from"))
5745 (downcase (cadr (mail-extract-address-components from)))
5746 (downcase (cadr (mail-extract-address-components
5747 (message-make-from))))))
5748 ;; Email address in From field matches
5749 ;; 'message-alternative-emails' regexp
5751 message-alternative-emails
5753 message-alternative-emails
5754 (cadr (mail-extract-address-components from))))))))))
5757 (defun message-cancel-news (&optional arg)
5758 "Cancel an article you posted.
5759 If ARG, allow editing of the cancellation message."
5761 (unless (message-news-p)
5762 (error "This is not a news article; canceling is impossible"))
5763 (let (from newsgroups message-id distribution buf)
5765 ;; Get header info from original article.
5767 (message-narrow-to-head-1)
5768 (setq from (message-fetch-field "from")
5769 newsgroups (message-fetch-field "newsgroups")
5770 message-id (message-fetch-field "message-id" t)
5771 distribution (message-fetch-field "distribution")))
5772 ;; Make sure that this article was written by the user.
5773 (unless (message-is-yours-p)
5774 (error "This article is not yours"))
5775 (when (yes-or-no-p "Do you really want to cancel this article? ")
5776 ;; Make control message.
5779 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5781 (insert "Newsgroups: " newsgroups "\n"
5783 "Subject: cmsg cancel " message-id "\n"
5784 "Control: cancel " message-id "\n"
5786 (concat "Distribution: " distribution "\n")
5788 mail-header-separator "\n"
5789 message-cancel-message)
5790 (run-hooks 'message-cancel-hook)
5792 (message "Canceling your article...")
5793 (if (let ((message-syntax-checks
5794 'dont-check-for-anything-just-trust-me))
5795 (funcall message-send-news-function))
5796 (message "Canceling your article...done"))
5797 (kill-buffer buf))))))
5800 (defun message-supersede ()
5801 "Start composing a message to supersede the current message.
5802 This is done simply by taking the old article and adding a Supersedes
5803 header line with the old Message-ID."
5805 (let ((cur (current-buffer)))
5806 ;; Check whether the user owns the article that is to be superseded.
5807 (unless (message-is-yours-p)
5808 (error "This article is not yours"))
5809 ;; Get a normal message buffer.
5810 (message-pop-to-buffer (message-buffer-name "supersede"))
5811 (insert-buffer-substring cur)
5813 (message-narrow-to-head-1)
5814 ;; Remove unwanted headers.
5815 (when message-ignored-supersedes-headers
5816 (message-remove-header message-ignored-supersedes-headers t))
5817 (goto-char (point-min))
5818 (if (not (re-search-forward "^Message-ID: " nil t))
5819 (error "No Message-ID in this article")
5820 (replace-match "Supersedes: " t t))
5821 (goto-char (point-max))
5822 (insert mail-header-separator)
5827 (defun message-recover ()
5828 "Reread contents of current buffer from its last auto-save file."
5830 (let ((file-name (make-auto-save-file-name)))
5831 (cond ((save-window-excursion
5832 (if (not (eq system-type 'vax-vms))
5833 (with-output-to-temp-buffer "*Directory*"
5834 (with-current-buffer standard-output
5835 (fundamental-mode)) ; for Emacs 20.4+
5836 (buffer-disable-undo standard-output)
5837 (let ((default-directory "/"))
5839 "ls" nil standard-output nil "-l" file-name))))
5840 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5841 (let ((buffer-read-only nil))
5843 (insert-file-contents file-name nil)))
5844 (t (error "message-recover cancelled")))))
5846 ;;; Washing Subject:
5848 (defun message-wash-subject (subject)
5849 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5850 Previous forwarders, replyers, etc. may add it."
5853 (goto-char (point-min))
5854 ;; strip Re/Fwd stuff off the beginning
5855 (while (re-search-forward
5856 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5859 ;; and gnus-style forwards [foo@bar.com] subject
5860 (goto-char (point-min))
5861 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5865 (goto-char (point-max))
5866 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5869 ;; and finally, any whitespace that was left-over
5870 (goto-char (point-min))
5871 (while (re-search-forward "^[ \t]+" nil t)
5873 (goto-char (point-max))
5874 (while (re-search-backward "[ \t]+$" nil t)
5879 ;;; Forwarding messages.
5881 (defvar message-forward-decoded-p nil
5882 "Non-nil means the original message is decoded.")
5884 (defun message-forward-subject-author-subject (subject)
5885 "Generate a SUBJECT for a forwarded message.
5886 The form is: [Source] Subject, where if the original message was mail,
5887 Source is the sender, and if the original message was news, Source is
5888 the list of newsgroups is was posted to."
5891 (or (message-fetch-field "newsgroups")
5892 (message-fetch-field "from")
5894 (if message-forward-decoded-p
5896 (mail-decode-encoded-word-string prefix)))
5899 (defun message-forward-subject-name-subject (subject)
5900 "Generate a SUBJECT for a forwarded message.
5901 The form is: [Source] Subject, where if the original message was mail,
5902 Source is the name of the sender, and if the original message was
5903 news, Source is the list of newsgroups is was posted to."
5906 (or (message-fetch-field "newsgroups")
5907 (let ((from (message-fetch-field "from")))
5909 (cdr (mail-header-parse-address from))))
5911 (if message-forward-decoded-p
5913 (mail-decode-encoded-word-string prefix)))
5916 (defun message-forward-subject-fwd (subject)
5917 "Generate a SUBJECT for a forwarded message.
5918 The form is: Fwd: Subject, where Subject is the original subject of
5920 (concat "Fwd: " subject))
5922 (defun message-make-forward-subject ()
5923 "Return a Subject header suitable for the message in the current buffer."
5926 (message-narrow-to-head-1)
5927 (let ((funcs message-make-forward-subject-function)
5928 (subject (message-fetch-field "Subject")))
5931 (if message-forward-decoded-p
5933 (mail-decode-encoded-word-string subject))
5935 (if message-wash-forwarded-subjects
5936 (setq subject (message-wash-subject subject)))
5937 ;; Make sure funcs is a list.
5940 (setq funcs (list funcs)))
5941 ;; Apply funcs in order, passing subject generated by previous
5942 ;; func to the next one.
5944 (when (functionp (car funcs))
5945 (setq subject (funcall (car funcs) subject)))
5946 (setq funcs (cdr funcs)))
5950 (defvar gnus-article-decoded-p))
5954 (defun message-forward (&optional news digest)
5955 "Forward the current message via mail.
5956 Optional NEWS will use news to forward instead of mail.
5957 Optional DIGEST will use digest to forward."
5959 (let* ((cur (current-buffer))
5960 (message-forward-decoded-p
5961 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
5962 gnus-article-decoded-p ;; In an article buffer.
5963 message-forward-decoded-p))
5964 (subject (message-make-forward-subject)))
5966 (message-news nil subject)
5967 (message-mail nil subject))
5968 (message-forward-make-body cur digest)))
5971 (defun message-forward-make-body (forward-buffer &optional digest)
5972 ;; Put point where we want it before inserting the forwarded
5974 (if message-forward-before-signature
5976 (goto-char (point-max)))
5977 (if message-forward-as-mime
5979 (insert "\n<#multipart type=digest>\n")
5980 (if message-forward-show-mml
5981 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
5982 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
5983 (insert "\n-------------------- Start of forwarded message --------------------\n"))
5984 (let ((b (point)) e)
5986 (if message-forward-as-mime
5987 (insert-buffer-substring forward-buffer)
5988 (mml-insert-buffer forward-buffer))
5989 (if (and message-forward-show-mml
5990 (not message-forward-decoded-p))
5993 (mm-disable-multibyte)
5995 (with-current-buffer forward-buffer
5996 (mm-with-unibyte-current-buffer (buffer-string))))
5997 (mm-enable-multibyte)
5999 (goto-char (point-min))
6000 (when (looking-at "From ")
6001 (replace-match "X-From-Line: "))
6004 (narrow-to-region (point) (point))
6005 (mml-insert-buffer forward-buffer)
6006 (goto-char (point-min))
6007 (when (looking-at "From ")
6008 (replace-match "X-From-Line: "))
6009 (goto-char (point-max)))))
6011 (if message-forward-as-mime
6013 (insert "<#/multipart>\n")
6014 (if message-forward-show-mml
6015 (insert "<#/mml>\n")
6016 (insert "<#/part>\n")))
6017 (insert "\n-------------------- End of forwarded message --------------------\n"))
6018 (if (and digest message-forward-as-mime)
6020 (narrow-to-region b e)
6022 (narrow-to-region (point)
6023 (or (search-forward "\n\n" nil t) (point)))
6024 (delete-region (point-min) (point-max)))
6025 (when (and (not current-prefix-arg)
6026 message-forward-ignored-headers
6027 ;; don't remove CTE, X-Gnus etc when doing "raw" forward:
6028 message-forward-show-mml)
6030 (narrow-to-region b e)
6032 (narrow-to-region (point)
6033 (or (search-forward "\n\n" nil t) (point)))
6034 (message-remove-header message-forward-ignored-headers t)))))
6035 (message-position-point))
6038 (defun message-forward-rmail-make-body (forward-buffer)
6039 (save-window-excursion
6040 (set-buffer forward-buffer)
6041 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6042 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6043 (if (rmail-msg-is-pruned)
6044 (rmail-msg-restore-non-pruned-header)))
6045 (message-forward-make-body forward-buffer))
6047 (eval-when-compile (defvar rmail-enable-mime-composing))
6049 ;; Fixme: Should have defcustom.
6051 (defun message-insinuate-rmail ()
6052 "Let RMAIL use message to forward."
6054 (setq rmail-enable-mime-composing t)
6055 (setq rmail-insert-mime-forwarded-message-function
6056 'message-forward-rmail-make-body))
6059 (defun message-resend (address)
6060 "Resend the current article to ADDRESS."
6062 (list (message-read-from-minibuffer "Resend message to: ")))
6063 (message "Resending message to %s..." address)
6065 (let ((cur (current-buffer))
6067 ;; We first set up a normal mail buffer.
6068 (unless (message-mail-user-agent)
6069 (set-buffer (get-buffer-create " *message resend*"))
6071 (let ((message-this-is-mail t)
6073 (message-setup `((To . ,address))))
6074 ;; Insert our usual headers.
6075 (message-generate-headers '(From Date To))
6076 (message-narrow-to-headers)
6077 ;; Remove X-Draft-From header etc.
6078 (message-remove-header message-ignored-mail-headers t)
6079 ;; Rename them all to "Resent-*".
6080 (goto-char (point-min))
6081 (while (re-search-forward "^[A-Za-z]" nil t)
6086 (delete-region (point) (point-max))
6088 ;; Insert the message to be resent.
6089 (insert-buffer-substring cur)
6090 (goto-char (point-min))
6091 (search-forward "\n\n")
6094 (narrow-to-region beg (point))
6095 (message-remove-header message-ignored-resent-headers t)
6096 (goto-char (point-max)))
6097 (insert mail-header-separator)
6098 ;; Rename all old ("Also-")Resent headers.
6099 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6102 ;; Quote any "From " lines at the beginning.
6104 (when (looking-at "From ")
6105 (replace-match "X-From-Line: "))
6107 (let ((message-inhibit-body-encoding t)
6108 message-required-mail-headers)
6109 (message-send-mail))
6110 (kill-buffer (current-buffer)))
6111 (message "Resending message to %s...done" address)))
6114 (defun message-bounce ()
6115 "Re-mail the current message.
6116 This only makes sense if the current message is a bounce message that
6117 contains some mail you have written which has been bounced back to
6120 (let ((handles (mm-dissect-buffer t))
6122 (message-pop-to-buffer (message-buffer-name "bounce"))
6123 (if (stringp (car handles))
6124 ;; This is a MIME bounce.
6125 (mm-insert-part (car (last handles)))
6126 ;; This is a non-MIME bounce, so we try to remove things
6128 (mm-insert-part handles)
6130 (goto-char (point-min))
6131 (search-forward "\n\n" nil t)
6132 (if (or (and (re-search-forward message-unsent-separator nil t)
6134 (re-search-forward "^Return-Path:.*\n" nil t))
6135 ;; We remove everything before the bounced mail.
6138 (if (re-search-forward "^[^ \n\t]+:" nil t)
6141 (when (re-search-backward "^.?From .*\n" nil t)
6142 (delete-region (match-beginning 0) (match-end 0)))))
6143 (mm-enable-multibyte)
6146 (message-narrow-to-head-1)
6147 (message-remove-header message-ignored-bounced-headers t)
6148 (goto-char (point-max))
6149 (insert mail-header-separator))
6150 (message-position-point)))
6153 ;;; Interactive entry points for new message buffers.
6157 (defun message-mail-other-window (&optional to subject)
6158 "Like `message-mail' command, but display mail buffer in another window."
6160 (unless (message-mail-user-agent)
6161 (let ((pop-up-windows t)
6162 (special-display-buffer-names nil)
6163 (special-display-regexps nil)
6164 (same-window-buffer-names nil)
6165 (same-window-regexps nil))
6166 (message-pop-to-buffer (message-buffer-name "mail" to))))
6167 (let ((message-this-is-mail t))
6168 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6169 nil nil 'switch-to-buffer-other-window)))
6172 (defun message-mail-other-frame (&optional to subject)
6173 "Like `message-mail' command, but display mail buffer in another frame."
6175 (unless (message-mail-user-agent)
6176 (let ((pop-up-frames t)
6177 (special-display-buffer-names nil)
6178 (special-display-regexps nil)
6179 (same-window-buffer-names nil)
6180 (same-window-regexps nil))
6181 (message-pop-to-buffer (message-buffer-name "mail" to))))
6182 (let ((message-this-is-mail t))
6183 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6184 nil nil 'switch-to-buffer-other-frame)))
6187 (defun message-news-other-window (&optional newsgroups subject)
6188 "Start editing a news article to be sent."
6190 (let ((pop-up-windows t)
6191 (special-display-buffer-names nil)
6192 (special-display-regexps nil)
6193 (same-window-buffer-names nil)
6194 (same-window-regexps nil))
6195 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6196 (let ((message-this-is-news t))
6197 (message-setup `((Newsgroups . ,(or newsgroups ""))
6198 (Subject . ,(or subject ""))))))
6201 (defun message-news-other-frame (&optional newsgroups subject)
6202 "Start editing a news article to be sent."
6204 (let ((pop-up-frames t)
6205 (special-display-buffer-names nil)
6206 (special-display-regexps nil)
6207 (same-window-buffer-names nil)
6208 (same-window-regexps nil))
6209 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6210 (let ((message-this-is-news t))
6211 (message-setup `((Newsgroups . ,(or newsgroups ""))
6212 (Subject . ,(or subject ""))))))
6216 ;; This code should be moved to underline.el (from which it is stolen).
6219 (defun bold-region (start end)
6220 "Bold all nonblank characters in the region.
6221 Works by overstriking characters.
6222 Called from program, takes two arguments START and END
6223 which specify the range to operate on."
6226 (let ((end1 (make-marker)))
6227 (move-marker end1 (max start end))
6228 (goto-char (min start end))
6229 (while (< (point) end1)
6230 (or (looking-at "[_\^@- ]")
6231 (insert (char-after) "\b"))
6232 (forward-char 1)))))
6235 (defun unbold-region (start end)
6236 "Remove all boldness (overstruck characters) in the region.
6237 Called from program, takes two arguments START and END
6238 which specify the range to operate on."
6241 (let ((end1 (make-marker)))
6242 (move-marker end1 (max start end))
6243 (goto-char (min start end))
6244 (while (re-search-forward "\b" end1 t)
6245 (if (eq (char-after) (char-after (- (point) 2)))
6246 (delete-char -2))))))
6248 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6249 (defalias 'message-make-overlay 'make-overlay)
6250 (defalias 'message-delete-overlay 'delete-overlay)
6251 (defalias 'message-overlay-put 'overlay-put)
6252 (defun message-kill-all-overlays ()
6253 (if (featurep 'xemacs)
6254 (map-extents (lambda (extent ignore) (delete-extent extent)))
6255 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6257 ;; Support for toolbar
6259 (defvar tool-bar-map)
6260 (defvar tool-bar-mode))
6262 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6263 ;; We need to make tool bar entries in local keymaps with
6264 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6265 (if (fboundp 'tool-bar-local-item-from-menu)
6266 ;; This is for Emacs 21.3
6267 (tool-bar-local-item-from-menu command icon in-map from-map props)
6268 (tool-bar-add-item-from-menu command icon from-map props)))
6270 (defun message-tool-bar-map ()
6271 (or message-tool-bar-map
6272 (setq message-tool-bar-map
6274 (condition-case nil (require 'tool-bar) (error nil))
6275 (fboundp 'tool-bar-add-item-from-menu)
6277 (let ((tool-bar-map (copy-keymap tool-bar-map))
6278 (load-path (mm-image-load-path)))
6279 ;; Zap some items which aren't so relevant and take
6281 (dolist (key '(print-buffer kill-buffer save-buffer
6282 write-file dired open-file))
6283 (define-key tool-bar-map (vector key) nil))
6284 (message-tool-bar-local-item-from-menu
6285 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6286 (message-tool-bar-local-item-from-menu
6287 'message-kill-buffer "close" tool-bar-map message-mode-map)
6288 (message-tool-bar-local-item-from-menu
6289 'message-dont-send "cancel" tool-bar-map message-mode-map)
6290 (message-tool-bar-local-item-from-menu
6291 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6292 (message-tool-bar-local-item-from-menu
6293 'ispell-message "spell" tool-bar-map message-mode-map)
6294 (message-tool-bar-local-item-from-menu
6295 'mml-preview "preview"
6296 tool-bar-map mml-mode-map)
6297 (message-tool-bar-local-item-from-menu
6298 'message-insert-importance-high "important"
6299 tool-bar-map message-mode-map)
6300 (message-tool-bar-local-item-from-menu
6301 'message-insert-importance-low "unimportant"
6302 tool-bar-map message-mode-map)
6303 (message-tool-bar-local-item-from-menu
6304 'message-insert-disposition-notification-to "receipt"
6305 tool-bar-map message-mode-map)
6308 ;;; Group name completion.
6310 (defcustom message-newgroups-header-regexp
6311 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6312 "Regexp that match headers that lists groups."
6316 (defcustom message-completion-alist
6317 (list (cons message-newgroups-header-regexp 'message-expand-group)
6318 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6319 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6320 . message-expand-name)
6321 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6322 . message-expand-name))
6323 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6325 :type '(alist :key-type regexp :value-type function))
6327 (defcustom message-tab-body-function nil
6328 "*Function to execute when `message-tab' (TAB) is executed in the body.
6329 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6333 (defun message-tab ()
6334 "Complete names according to `message-completion-alist'.
6335 Execute function specified by `message-tab-body-function' when not in
6338 (let ((alist message-completion-alist))
6340 (let ((mail-abbrev-mode-regexp (caar alist)))
6341 (not (mail-abbrev-in-expansion-header-p))))
6342 (setq alist (cdr alist)))
6343 (funcall (or (cdar alist) message-tab-body-function
6344 (lookup-key text-mode-map "\t")
6345 (lookup-key global-map "\t")
6346 'indent-relative))))
6348 (defun message-expand-group ()
6349 "Expand the group name under point."
6350 (let* ((b (save-excursion
6355 (skip-chars-forward "^:")
6358 (skip-chars-backward "^, \t\n") (point))))
6359 (completion-ignore-case t)
6360 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6362 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6363 (completions (all-completions string hashtb))
6365 (delete-region b (point))
6367 ((= (length completions) 1)
6368 (if (string= (car completions) string)
6371 (message "Only matching group"))
6372 (insert (car completions))))
6373 ((and (setq comp (try-completion string hashtb))
6374 (not (string= comp string)))
6379 (message "No matching groups")
6380 (save-selected-window
6381 (pop-to-buffer "*Completions*")
6382 (buffer-disable-undo)
6383 (let ((buffer-read-only nil))
6385 (let ((standard-output (current-buffer)))
6386 (display-completion-list (sort completions 'string<)))
6387 (goto-char (point-min))
6388 (delete-region (point) (progn (forward-line 3) (point))))))))))
6390 (defun message-expand-name ()
6391 (if (fboundp 'bbdb-complete-name)
6392 (bbdb-complete-name)
6397 (defun message-talkative-question (ask question show &rest text)
6398 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6399 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6400 The following arguments may contain lists of values."
6402 (setq text (message-flatten-list text)))
6403 (save-window-excursion
6405 (with-output-to-temp-buffer " *MESSAGE information message*"
6406 (set-buffer " *MESSAGE information message*")
6407 (fundamental-mode) ; for Emacs 20.4+
6408 (mapcar 'princ text)
6409 (goto-char (point-min))))
6410 (funcall ask question))
6411 (funcall ask question)))
6413 (defun message-flatten-list (list)
6414 "Return a new, flat list that contains all elements of LIST.
6416 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6419 (apply 'append (mapcar 'message-flatten-list list)))
6423 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6424 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6425 Then clone the local variables and values from the old buffer to the
6426 new one, cloning only the locals having a substring matching the
6428 (let ((oldbuf (current-buffer)))
6430 (set-buffer (generate-new-buffer name))
6431 (message-clone-locals oldbuf varstr)
6434 (defun message-clone-locals (buffer &optional varstr)
6435 "Clone the local variables from BUFFER to the current buffer."
6436 (let ((locals (save-excursion
6438 (buffer-local-variables)))
6439 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
6442 (when (and (consp local)
6444 (string-match regexp (symbol-name (car local)))
6446 (string-match varstr (symbol-name (car local)))))
6448 (set (make-local-variable (car local))
6456 (defvar message-inhibit-body-encoding nil)
6458 (defun message-encode-message-body ()
6459 (unless message-inhibit-body-encoding
6460 (let ((mail-parse-charset (or mail-parse-charset
6461 message-default-charset))
6462 (case-fold-search t)
6463 lines content-type-p)
6466 (narrow-to-region (point) (point-max))
6467 (let ((new (mml-generate-mime)))
6469 (delete-region (point-min) (point-max))
6471 (goto-char (point-min))
6472 (if (eq (aref new 0) ?\n)
6474 (search-forward "\n\n")
6475 (setq lines (buffer-substring (point-min) (1- (point))))
6476 (delete-region (point-min) (point))))))
6478 (message-narrow-to-headers-or-head)
6479 (message-remove-header "Mime-Version")
6480 (goto-char (point-max))
6481 (insert "MIME-Version: 1.0\n")
6484 (setq content-type-p
6486 (re-search-backward "^Content-Type:" nil t))))
6488 (message-narrow-to-headers-or-head)
6489 (message-remove-first-header "Content-Type")
6490 (message-remove-first-header "Content-Transfer-Encoding"))
6491 ;; We always make sure that the message has a Content-Type
6492 ;; header. This is because some broken MTAs and MUAs get
6493 ;; awfully confused when confronted with a message with a
6494 ;; MIME-Version header and without a Content-Type header. For
6495 ;; instance, Solaris' /usr/bin/mail.
6496 (unless content-type-p
6497 (goto-char (point-min))
6498 ;; For unknown reason, MIME-Version doesn't exist.
6499 (when (re-search-forward "^MIME-Version:" nil t)
6501 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6503 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6504 "Read from the minibuffer while providing abbrev expansion."
6505 (if (fboundp 'mail-abbrevs-setup)
6506 (let ((mail-abbrev-mode-regexp "")
6507 (minibuffer-setup-hook 'mail-abbrevs-setup)
6508 (minibuffer-local-map message-minibuffer-local-map))
6509 (read-from-minibuffer prompt initial-contents))
6510 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6511 (minibuffer-local-map message-minibuffer-local-map))
6512 (read-string prompt initial-contents))))
6514 (defun message-use-alternative-email-as-from ()
6515 (require 'mail-utils)
6516 (let* ((fields '("To" "Cc"))
6519 (mail-strip-quoted-names
6520 (mapconcat 'message-fetch-reply-field fields ","))
6524 (if (string-match message-alternative-emails (car emails))
6525 (setq email (car emails)
6528 (unless (or (not email) (equal email user-mail-address))
6529 (goto-char (point-max))
6530 (insert "From: " email "\n"))))
6532 (defun message-options-get (symbol)
6533 (cdr (assq symbol message-options)))
6535 (defun message-options-set (symbol value)
6536 (let ((the-cons (assq symbol message-options)))
6539 (setcdr the-cons value)
6540 (setq message-options (delq the-cons message-options)))
6542 (push (cons symbol value) message-options))))
6545 (defun message-options-set-recipient ()
6547 (message-narrow-to-headers-or-head)
6548 (message-options-set 'message-sender
6549 (mail-strip-quoted-names
6550 (message-fetch-field "from")))
6551 (message-options-set 'message-recipients
6552 (mail-strip-quoted-names
6553 (let ((to (message-fetch-field "to"))
6554 (cc (message-fetch-field "cc"))
6555 (bcc (message-fetch-field "bcc")))
6558 (if (and to cc) ", ")
6560 (if (and (or to cc) bcc) ", ")
6563 (defun message-hide-headers ()
6564 "Hide headers based on the `message-hidden-headers' variable."
6565 (let ((regexps (if (stringp message-hidden-headers)
6566 (list message-hidden-headers)
6567 message-hidden-headers))
6568 (inhibit-point-motion-hooks t)
6569 (after-change-functions nil))
6573 (message-narrow-to-headers)
6574 (goto-char (point-min))
6576 (if (not (message-hide-header-p regexps))
6577 (message-next-header)
6578 (let ((begin (point)))
6579 (message-next-header)
6580 (add-text-properties
6582 '(invisible t message-hidden t))))))))))
6584 (defun message-hide-header-p (regexps)
6587 (when (eq (car regexps) 'not)
6590 (dolist (regexp regexps)
6591 (setq result (or result (looking-at regexp))))
6596 (when (featurep 'xemacs)
6597 (require 'messagexmas)
6598 (message-xmas-redefine))
6602 (run-hooks 'message-load-hook)
6605 ;; coding: iso-8859-1
6608 ;;; message.el ends here