1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
36 (defvar gnus-message-group-art)
37 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
43 ;; This is apparently necessary even though things are autoloaded.
44 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
45 ;; require mailabbrev here.
46 (if (featurep 'xemacs)
47 (require 'mail-abbrevs)
48 (require 'mailabbrev))
55 (defgroup message '((user-mail-address custom-variable)
56 (user-full-name custom-variable))
57 "Mail and news message composing."
58 :link '(custom-manual "(message)Top")
62 (put 'user-mail-address 'custom-type 'string)
63 (put 'user-full-name 'custom-type 'string)
65 (defgroup message-various nil
66 "Various Message Variables."
67 :link '(custom-manual "(message)Various Message Variables")
70 (defgroup message-buffers nil
72 :link '(custom-manual "(message)Message Buffers")
75 (defgroup message-sending nil
77 :link '(custom-manual "(message)Sending Variables")
80 (defgroup message-interface nil
82 :link '(custom-manual "(message)Interface")
85 (defgroup message-forwarding nil
87 :link '(custom-manual "(message)Forwarding")
88 :group 'message-interface)
90 (defgroup message-insertion nil
92 :link '(custom-manual "(message)Insertion")
95 (defgroup message-headers nil
97 :link '(custom-manual "(message)Message Headers")
100 (defgroup message-news nil
101 "Composing News Messages."
104 (defgroup message-mail nil
105 "Composing Mail Messages."
108 (defgroup message-faces nil
109 "Faces used for message composing."
113 (defcustom message-directory "~/Mail/"
114 "*Directory from which all other mail file variables are derived."
115 :group 'message-various
118 (defcustom message-max-buffers 10
119 "*How many buffers to keep before starting to kill them off."
120 :group 'message-buffers
123 (defcustom message-send-rename-function nil
124 "Function called to rename the buffer after sending it."
125 :group 'message-buffers
126 :type '(choice function (const nil)))
128 (defcustom message-fcc-handler-function 'message-output
129 "*A function called to save outgoing articles.
130 This function will be called with the name of the file to store the
131 article in. The default function is `message-output' which saves in Unix
133 :type '(radio (function-item message-output)
134 (function :tag "Other"))
135 :group 'message-sending)
137 (defcustom message-fcc-externalize-attachments nil
138 "If non-nil, attachments are included as external parts in Fcc copies."
141 :group 'message-sending)
143 (defcustom message-courtesy-message
144 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
145 "*This is inserted at the start of a mailed copy of a posted message.
146 If the string contains the format spec \"%s\", the Newsgroups
147 the article has been posted to will be inserted there.
148 If this variable is nil, no such courtesy message will be added."
149 :group 'message-sending
150 :type '(radio string (const nil)))
152 (defcustom message-ignored-bounced-headers
153 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
154 "*Regexp that matches headers to be removed in resent bounced mail."
155 :group 'message-interface
158 (defcustom message-from-style 'default
159 "*Specifies how \"From\" headers look.
161 If nil, they contain just the return address like:
163 If `parens', they look like:
164 king@grassland.com (Elvis Parsley)
165 If `angles', they look like:
166 Elvis Parsley <king@grassland.com>
168 Otherwise, most addresses look like `angles', but they look like
169 `parens' if `angles' would need quoting and `parens' would not."
170 :type '(choice (const :tag "simple" nil)
174 :group 'message-headers)
176 (defcustom message-insert-canlock t
177 "Whether to insert a Cancel-Lock header in news postings."
179 :group 'message-headers
182 (defcustom message-syntax-checks
183 (if message-insert-canlock '((sender . disabled)) nil)
184 ;; Guess this one shouldn't be easy to customize...
185 "*Controls what syntax checks should not be performed on outgoing posts.
186 To disable checking of long signatures, for instance, add
187 `(signature . disabled)' to this list.
189 Don't touch this variable unless you really know what you're doing.
191 Checks include `approved', `continuation-headers', `control-chars',
192 `empty', `existing-newsgroups', `from', `illegible-text',
193 `invisible-text', `long-header-lines', `long-lines', `message-id',
194 `multiple-headers', `new-text', `newsgroups', `quoting-style',
195 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
196 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
197 and `valid-newsgroups'."
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'."
208 :group 'message-headers
209 :link '(custom-manual "(message)Message Headers")
210 :type '(repeat sexp))
212 (defcustom message-draft-headers '(References From Date)
213 "*Headers to be generated when saving a draft message."
216 :group 'message-headers
217 :link '(custom-manual "(message)Message Headers")
218 :type '(repeat sexp))
220 (defcustom message-required-news-headers
221 '(From Newsgroups Subject Date Message-ID
222 (optional . Organization)
223 (optional . User-Agent))
224 "*Headers to be generated or prompted for when posting an article.
225 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
226 Message-ID. Organization, Lines, In-Reply-To, Expires, and
227 User-Agent are optional. If you don't want message to insert some
228 header, remove it from this list."
230 :group 'message-headers
231 :link '(custom-manual "(message)Message Headers")
232 :type '(repeat sexp))
234 (defcustom message-required-mail-headers
235 '(From Subject Date (optional . In-Reply-To) Message-ID
236 (optional . User-Agent))
237 "*Headers to be generated or prompted for when mailing a message.
238 It is recommended that From, Date, To, Subject and Message-ID be
239 included. Organization and User-Agent are optional."
241 :group 'message-headers
242 :link '(custom-manual "(message)Message Headers")
243 :type '(repeat sexp))
245 (defcustom message-deletable-headers '(Message-ID Date Lines)
246 "Headers to be deleted if they already exist and were generated by message previously."
247 :group 'message-headers
248 :link '(custom-manual "(message)Message Headers")
251 (defcustom message-ignored-news-headers
252 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
253 "*Regexp of headers to be removed unconditionally before posting."
255 :group 'message-headers
256 :link '(custom-manual "(message)Message Headers")
257 :type '(repeat :value-to-internal (lambda (widget value)
258 (custom-split-regexp-maybe value))
259 :match (lambda (widget value)
261 (widget-editable-list-match widget value)))
264 (defcustom message-ignored-mail-headers
265 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
266 "*Regexp of headers to be removed unconditionally before mailing."
268 :group 'message-headers
269 :link '(custom-manual "(message)Mail Headers")
272 (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:\\|^X-Payment:\\|^Approved:"
273 "*Header lines matching this regexp will be deleted before posting.
274 It's best to delete old Path and Date headers before posting to avoid
276 :group 'message-interface
277 :link '(custom-manual "(message)Superseding")
278 :type '(repeat :value-to-internal (lambda (widget value)
279 (custom-split-regexp-maybe value))
280 :match (lambda (widget value)
282 (widget-editable-list-match widget value)))
285 (defcustom message-subject-re-regexp
286 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
287 "*Regexp matching \"Re: \" in the subject line."
288 :group 'message-various
289 :link '(custom-manual "(message)Message Headers")
292 ;;; Start of variables adopted from `message-utils.el'.
294 (defcustom message-subject-trailing-was-query 'ask
295 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
296 If nil, leave the subject unchanged. If it is the symbol `ask', query
297 the user what do do. In this case, the subject is matched against
298 `message-subject-trailing-was-ask-regexp'. If
299 `message-subject-trailing-was-query' is t, always strip the trailing
300 old subject. In this case, `message-subject-trailing-was-regexp' is
303 :type '(choice (const :tag "never" nil)
304 (const :tag "always strip" t)
306 :link '(custom-manual "(message)Message Headers")
307 :group 'message-various)
309 (defcustom message-subject-trailing-was-ask-regexp
310 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
311 "*Regexp matching \"(was: <old subject>)\" in the subject line.
313 The function `message-strip-subject-trailing-was' uses this regexp if
314 `message-subject-trailing-was-query' is set to the symbol `ask'. If
315 the variable is t instead of `ask', use
316 `message-subject-trailing-was-regexp' instead.
318 It is okay to create some false positives here, as the user is asked."
320 :group 'message-various
321 :link '(custom-manual "(message)Message Headers")
324 (defcustom message-subject-trailing-was-regexp
325 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
326 "*Regexp matching \"(was: <old subject>)\" in the subject line.
328 If `message-subject-trailing-was-query' is set to t, the subject is
329 matched against `message-subject-trailing-was-regexp' in
330 `message-strip-subject-trailing-was'. You should use a regexp creating very
331 few false positives here."
333 :group 'message-various
334 :link '(custom-manual "(message)Message Headers")
337 ;;; marking inserted text
339 (defcustom message-mark-insert-begin
340 "--8<---------------cut here---------------start------------->8---\n"
341 "How to mark the beginning of some inserted text."
344 :link '(custom-manual "(message)Insertion Variables")
345 :group 'message-various)
347 (defcustom message-mark-insert-end
348 "--8<---------------cut here---------------end--------------->8---\n"
349 "How to mark the end of some inserted text."
352 :link '(custom-manual "(message)Insertion Variables")
353 :group 'message-various)
355 (defcustom message-archive-header "X-No-Archive: Yes\n"
356 "Header to insert when you don't want your article to be archived.
357 Archives \(such as groups.google.com\) respect this header."
360 :link '(custom-manual "(message)Header Commands")
361 :group 'message-various)
363 (defcustom message-archive-note
364 "X-No-Archive: Yes - save http://groups.google.com/"
365 "Note to insert why you wouldn't want this posting archived.
366 If nil, don't insert any text in the body."
368 :type '(radio string (const nil))
369 :link '(custom-manual "(message)Header Commands")
370 :group 'message-various)
372 ;;; Crossposts and Followups
373 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
374 ;; new suggestions by R. Weikusat <rw at another.de>
376 (defvar message-cross-post-old-target nil
377 "Old target for cross-posts or follow-ups.")
378 (make-variable-buffer-local 'message-cross-post-old-target)
380 (defcustom message-cross-post-default t
381 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
382 If nil, `message-cross-post-followup-to' will only do a followup. Note that
383 you can explicitly override this setting by calling
384 `message-cross-post-followup-to' with a prefix."
387 :group 'message-various)
389 (defcustom message-cross-post-note "Crosspost & Followup-To: "
390 "Note to insert before signature to notify of cross-post and follow-up."
393 :group 'message-various)
395 (defcustom message-followup-to-note "Followup-To: "
396 "Note to insert before signature to notify of follow-up only."
399 :group 'message-various)
401 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
402 "Function to use to insert note about Crosspost or Followup-To.
403 The function will be called with four arguments. The function should not only
404 insert a note, but also ensure old notes are deleted. See the documentation
405 for `message-cross-post-insert-note'."
408 :group 'message-various)
410 ;;; End of variables adopted from `message-utils.el'.
412 (defcustom message-signature-separator "^-- *$"
413 "Regexp matching the signature separator."
415 :link '(custom-manual "(message)Various Message Variables")
416 :group 'message-various)
418 (defcustom message-elide-ellipsis "\n[...]\n\n"
419 "*The string which is inserted for elided text."
421 :link '(custom-manual "(message)Various Commands")
422 :group 'message-various)
424 (defcustom message-interactive t
425 "Non-nil means when sending a message wait for and display errors.
426 nil means let mailer mail back a message to report errors."
427 :group 'message-sending
429 :link '(custom-manual "(message)Sending Variables")
432 (defcustom message-generate-new-buffers 'unique
433 "*Say whether to create a new message buffer to compose a message.
434 Valid values include:
437 Generate the buffer name in the Message way (e.g., *mail*, *news*,
438 *mail to whom*, *news on group*, etc.) and continue editing in the
439 existing buffer of that name. If there is no such buffer, it will
443 Create the new buffer with the name generated in the Message way.
446 Similar to `unique' but the buffer name begins with \"*unsent \".
449 Similar to nil but the buffer name is simpler like *mail message*.
452 If this is a function, call that function with three parameters:
453 The type, the To address and the group name (any of these may be nil).
454 The function should return the new buffer name."
455 :group 'message-buffers
456 :link '(custom-manual "(message)Message Buffers")
457 :type '(choice (const nil)
458 (sexp :tag "unique" :format "unique\n" :value unique
459 :match (lambda (widget value) (memq value '(unique t))))
462 (function :format "\n %{%t%}: %v")))
464 (defcustom message-kill-buffer-on-exit nil
465 "*Non-nil means that the message buffer will be killed after sending a message."
466 :group 'message-buffers
467 :link '(custom-manual "(message)Message Buffers")
470 (defcustom message-kill-buffer-query t
471 "*Non-nil means that killing a modified message buffer has to be confirmed.
472 This is used by `message-kill-buffer'."
473 :version "23.0" ;; No Gnus
474 :group 'message-buffers
478 (defvar gnus-local-organization))
479 (defcustom message-user-organization
480 (or (and (boundp 'gnus-local-organization)
481 (stringp gnus-local-organization)
482 gnus-local-organization)
483 (getenv "ORGANIZATION")
485 "*String to be used as an Organization header.
486 If t, use `message-user-organization-file'."
487 :group 'message-headers
488 :type '(choice string
489 (const :tag "consult file" t)))
491 (defcustom message-user-organization-file
493 (dolist (f (list "/etc/organization"
494 "/etc/news/organization"
495 "/usr/lib/news/organization"))
496 (when (file-readable-p f)
499 "*Local news organization file."
501 :link '(custom-manual "(message)News Headers")
502 :group 'message-headers)
504 (defcustom message-make-forward-subject-function
505 #'message-forward-subject-name-subject
506 "*List of functions called to generate subject headers for forwarded messages.
507 The subject generated by the previous function is passed into each
510 The provided functions are:
512 * `message-forward-subject-author-subject' Source of article (author or
513 newsgroup), in brackets followed by the subject
514 * `message-forward-subject-name-subject' Source of article (name of author
515 or newsgroup), in brackets followed by the subject
516 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
518 :group 'message-forwarding
519 :link '(custom-manual "(message)Forwarding")
520 :type '(radio (function-item message-forward-subject-author-subject)
521 (function-item message-forward-subject-fwd)
522 (function-item message-forward-subject-name-subject)
523 (repeat :tag "List of functions" function)))
525 (defcustom message-forward-as-mime t
526 "*Non-nil means forward messages as an inline/rfc822 MIME section.
527 Otherwise, directly inline the old message in the forwarded message."
529 :group 'message-forwarding
530 :link '(custom-manual "(message)Forwarding")
533 (defcustom message-forward-show-mml 'best
534 "*Non-nil means show forwarded messages as MML (decoded from MIME).
535 Otherwise, forwarded messages are unchanged.
536 Can also be the symbol `best' to indicate that MML should be
537 used, except when it is a bad idea to use MML. One example where
538 it is a bad idea is when forwarding a signed or encrypted
539 message, because converting MIME to MML would invalidate the
542 :group 'message-forwarding
543 :type '(choice (const :tag "use MML" t)
544 (const :tag "don't use MML " nil)
545 (const :tag "use MML when appropriate" best)))
547 (defcustom message-forward-before-signature t
548 "*Non-nil means put forwarded message before signature, else after."
549 :group 'message-forwarding
552 (defcustom message-wash-forwarded-subjects nil
553 "*Non-nil means try to remove as much cruft as possible from the subject.
554 Done before generating the new subject of a forward."
555 :group 'message-forwarding
556 :link '(custom-manual "(message)Forwarding")
559 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
560 "*All headers that match this regexp will be deleted when resending a message."
561 :group 'message-interface
562 :link '(custom-manual "(message)Resending")
563 :type '(repeat :value-to-internal (lambda (widget value)
564 (custom-split-regexp-maybe value))
565 :match (lambda (widget value)
567 (widget-editable-list-match widget value)))
570 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
571 "*All headers that match this regexp will be deleted when forwarding a message."
573 :group 'message-forwarding
574 :type '(repeat :value-to-internal (lambda (widget value)
575 (custom-split-regexp-maybe value))
576 :match (lambda (widget value)
578 (widget-editable-list-match widget value)))
581 (defcustom message-ignored-cited-headers "."
582 "*Delete these headers from the messages you yank."
583 :group 'message-insertion
584 :link '(custom-manual "(message)Insertion Variables")
587 (defcustom message-cite-prefix-regexp
588 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
589 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
590 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
591 (let (non-word-constituents)
592 (with-syntax-table text-mode-syntax-table
593 (setq non-word-constituents
595 (if (string-match "\\w" "-") "" "-")
596 (if (string-match "\\w" "_") "" "_")
597 (if (string-match "\\w" ".") "" "."))))
598 (if (equal non-word-constituents "")
599 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
600 (concat "\\([ \t]*\\(\\w\\|["
601 non-word-constituents
602 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
603 "*Regexp matching the longest possible citation prefix on a line."
605 :group 'message-insertion
606 :link '(custom-manual "(message)Insertion Variables")
608 :set (lambda (symbol value)
610 (custom-set-default symbol value)
611 (if (boundp 'gnus-message-cite-prefix-regexp)
612 (setq gnus-message-cite-prefix-regexp
613 (concat "^\\(?:" value "\\)"))))))
615 (defcustom message-cancel-message "I am canceling my own article.\n"
616 "Message to be inserted in the cancel message."
617 :group 'message-interface
618 :link '(custom-manual "(message)Canceling News")
621 ;; Useful to set in site-init.el
622 (defcustom message-send-mail-function
623 (let ((program (if (boundp 'sendmail-program)
628 (string-match "/" program) ;; Skip path
629 (file-executable-p program))
630 'message-send-mail-with-sendmail)
632 (executable-find program))
633 'message-send-mail-with-sendmail)
636 "Function to call to send the current buffer as mail.
637 The headers should be delimited by a line whose contents match the
638 variable `mail-header-separator'.
640 Valid values include `message-send-mail-with-sendmail' (the default),
641 `message-send-mail-with-mh', `message-send-mail-with-qmail',
642 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
644 See also `send-mail-function'."
645 :type '(radio (function-item message-send-mail-with-sendmail)
646 (function-item message-send-mail-with-mh)
647 (function-item message-send-mail-with-qmail)
648 (function-item message-smtpmail-send-it)
649 (function-item smtpmail-send-it)
650 (function-item feedmail-send-it)
651 (function :tag "Other"))
652 :group 'message-sending
653 :link '(custom-manual "(message)Mail Variables")
654 :group 'message-mail)
656 (defcustom message-send-news-function 'message-send-news
657 "Function to call to send the current buffer as news.
658 The headers should be delimited by a line whose contents match the
659 variable `mail-header-separator'."
660 :group 'message-sending
662 :link '(custom-manual "(message)News Variables")
665 (defcustom message-reply-to-function nil
666 "If non-nil, function that should return a list of headers.
667 This function should pick out addresses from the To, Cc, and From headers
668 and respond with new To and Cc headers."
669 :group 'message-interface
670 :link '(custom-manual "(message)Reply")
671 :type '(choice function (const nil)))
673 (defcustom message-wide-reply-to-function nil
674 "If non-nil, function that should return a list of headers.
675 This function should pick out addresses from the To, Cc, and From headers
676 and respond with new To and Cc headers."
677 :group 'message-interface
678 :link '(custom-manual "(message)Wide Reply")
679 :type '(choice function (const nil)))
681 (defcustom message-followup-to-function nil
682 "If non-nil, function that should return a list of headers.
683 This function should pick out addresses from the To, Cc, and From headers
684 and respond with new To and Cc headers."
685 :group 'message-interface
686 :link '(custom-manual "(message)Followup")
687 :type '(choice function (const nil)))
689 (defcustom message-extra-wide-headers nil
690 "If non-nil, a list of additional address headers.
691 These are used when composing a wide reply."
692 :group 'message-sending
693 :type '(repeat string))
695 (defcustom message-use-followup-to 'ask
696 "*Specifies what to do with Followup-To header.
697 If nil, always ignore the header. If it is t, use its value, but
698 query before using the \"poster\" value. If it is the symbol `ask',
699 always query the user whether to use the value. If it is the symbol
700 `use', always use the value."
701 :group 'message-interface
702 :link '(custom-manual "(message)Followup")
703 :type '(choice (const :tag "ignore" nil)
704 (const :tag "use & query" t)
708 (defcustom message-use-mail-followup-to 'use
709 "*Specifies what to do with Mail-Followup-To header.
710 If nil, always ignore the header. If it is the symbol `ask', always
711 query the user whether to use the value. If it is the symbol `use',
712 always use the value."
714 :group 'message-interface
715 :link '(custom-manual "(message)Mailing Lists")
716 :type '(choice (const :tag "ignore" nil)
720 (defcustom message-subscribed-address-functions nil
721 "*Specifies functions for determining list subscription.
722 If nil, do not attempt to determine list subscription with functions.
723 If non-nil, this variable contains a list of functions which return
724 regular expressions to match lists. These functions can be used in
725 conjunction with `message-subscribed-regexps' and
726 `message-subscribed-addresses'."
728 :group 'message-interface
729 :link '(custom-manual "(message)Mailing Lists")
730 :type '(repeat sexp))
732 (defcustom message-subscribed-address-file nil
733 "*A file containing addresses the user is subscribed to.
734 If nil, do not look at any files to determine list subscriptions. If
735 non-nil, each line of this file should be a mailing list address."
737 :group 'message-interface
738 :link '(custom-manual "(message)Mailing Lists")
739 :type '(radio file (const nil)))
741 (defcustom message-subscribed-addresses nil
742 "*Specifies a list of addresses the user is subscribed to.
743 If nil, do not use any predefined list subscriptions. This list of
744 addresses can be used in conjunction with
745 `message-subscribed-address-functions' and `message-subscribed-regexps'."
747 :group 'message-interface
748 :link '(custom-manual "(message)Mailing Lists")
749 :type '(repeat string))
751 (defcustom message-subscribed-regexps nil
752 "*Specifies a list of addresses the user is subscribed to.
753 If nil, do not use any predefined list subscriptions. This list of
754 regular expressions can be used in conjunction with
755 `message-subscribed-address-functions' and `message-subscribed-addresses'."
757 :group 'message-interface
758 :link '(custom-manual "(message)Mailing Lists")
759 :type '(repeat regexp))
761 (defcustom message-allow-no-recipients 'ask
762 "Specifies what to do when there are no recipients other than Gcc/Fcc.
763 If it is the symbol `always', the posting is allowed. If it is the
764 symbol `never', the posting is not allowed. If it is the symbol
765 `ask', you are prompted."
767 :group 'message-interface
768 :link '(custom-manual "(message)Message Headers")
769 :type '(choice (const always)
773 (defcustom message-sendmail-f-is-evil nil
774 "*Non-nil means don't add \"-f username\" to the sendmail command line.
775 Doing so would be even more evil than leaving it out."
776 :group 'message-sending
777 :link '(custom-manual "(message)Mail Variables")
780 (defcustom message-sendmail-envelope-from nil
781 "*Envelope-from when sending mail with sendmail.
782 If this is nil, use `user-mail-address'. If it is the symbol
783 `header', use the From: header of the message."
785 :type '(choice (string :tag "From name")
786 (const :tag "Use From: header from message" header)
787 (const :tag "Use `user-mail-address'" nil))
788 :link '(custom-manual "(message)Mail Variables")
789 :group 'message-sending)
791 (defcustom message-sendmail-extra-arguments nil
792 "Additional arguments to `sendmail-program'."
793 ;; E.g. '("-a" "account") for msmtp
794 :version "23.0" ;; No Gnus
795 :type '(repeat string)
796 ;; :link '(custom-manual "(message)Mail Variables")
797 :group 'message-sending)
799 ;; qmail-related stuff
800 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
801 "Location of the qmail-inject program."
802 :group 'message-sending
803 :link '(custom-manual "(message)Mail Variables")
806 (defcustom message-qmail-inject-args nil
807 "Arguments passed to qmail-inject programs.
808 This should be a list of strings, one string for each argument. It
809 may also be a function.
811 For e.g., if you wish to set the envelope sender address so that bounces
812 go to the right place or to deal with listserv's usage of that address, you
813 might set this variable to '(\"-f\" \"you@some.where\")."
814 :group 'message-sending
815 :link '(custom-manual "(message)Mail Variables")
816 :type '(choice (function)
820 (defvar gnus-post-method)
821 (defvar gnus-select-method))
822 (defcustom message-post-method
823 (cond ((and (boundp 'gnus-post-method)
824 (listp gnus-post-method)
827 ((boundp 'gnus-select-method)
830 "*Method used to post news.
831 Note that when posting from inside Gnus, for instance, this
832 variable isn't used."
834 :group 'message-sending
835 ;; This should be the `gnus-select-method' widget, but that might
836 ;; create a dependence to `gnus.el'.
839 ;; FIXME: This should be a temporary workaround until someone implements a
840 ;; proper solution. If a crash happens while replying, the auto-save file
841 ;; will *not* have a `References:' header if `message-generate-headers-first'
842 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
843 (defcustom message-generate-headers-first '(references)
844 "Which headers should be generated before starting to compose a message.
845 If t, generate all required headers. This can also be a list of headers to
846 generate. The variables `message-required-news-headers' and
847 `message-required-mail-headers' specify which headers to generate.
849 Note that the variable `message-deletable-headers' specifies headers which
850 are to be deleted and then re-generated before sending, so this variable
851 will not have a visible effect for those headers."
852 :group 'message-headers
853 :link '(custom-manual "(message)Message Headers")
854 :type '(choice (const :tag "None" nil)
855 (const :tag "References" '(references))
857 (repeat (sexp :tag "Header"))))
859 (defcustom message-fill-column 72
860 "Column beyond which automatic line-wrapping should happen.
861 Local value for message buffers. If non-nil, also turn on
862 auto-fill in message buffers."
863 :group 'message-various
864 ;; :link '(custom-manual "(message)Message Headers")
865 :type '(choice (const :tag "Don't turn on auto fill" nil)
868 (defcustom message-setup-hook nil
869 "Normal hook, run each time a new outgoing message is initialized.
870 The function `message-setup' runs this hook."
871 :group 'message-various
872 :link '(custom-manual "(message)Various Message Variables")
875 (defcustom message-cancel-hook nil
876 "Hook run when cancelling articles."
877 :group 'message-various
878 :link '(custom-manual "(message)Various Message Variables")
881 (defcustom message-signature-setup-hook nil
882 "Normal hook, run each time a new outgoing message is initialized.
883 It is run after the headers have been inserted and before
884 the signature is inserted."
885 :group 'message-various
886 :link '(custom-manual "(message)Various Message Variables")
889 (defcustom message-mode-hook nil
890 "Hook run in message mode buffers."
891 :group 'message-various
894 (defcustom message-header-hook nil
895 "Hook run in a message mode buffer narrowed to the headers."
896 :group 'message-various
899 (defcustom message-header-setup-hook nil
900 "Hook called narrowed to the headers when setting up a message buffer."
901 :group 'message-various
902 :link '(custom-manual "(message)Various Message Variables")
905 (defcustom message-minibuffer-local-map
906 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
907 (set-keymap-parent map minibuffer-local-map)
909 "Keymap for `message-read-from-minibuffer'."
911 :group 'message-various)
913 (defcustom message-citation-line-function 'message-insert-citation-line
914 "*Function called to insert the \"Whomever writes:\" line.
916 Predefined functions include `message-insert-citation-line' and
917 `message-insert-formated-citation-line' (see the variable
918 `message-citation-line-format').
920 Note that Gnus provides a feature where the reader can click on
921 `writes:' to hide the cited text. If you change this line too much,
922 people who read your message will have to change their Gnus
923 configuration. See the variable `gnus-cite-attribution-suffix'."
925 (function-item :tag "plain" message-insert-citation-line)
926 (function-item :tag "formatted" message-insert-formated-citation-line)
927 (function :tag "Other"))
928 :link '(custom-manual "(message)Insertion Variables")
929 :group 'message-insertion)
931 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:"
932 "Format of the \"Whomever writes:\" line.
934 The string is formatted using `format-spec'. The following
935 constructs are replaced:
937 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
938 %n The mail address, e.g. \"john.doe@example.invalid\".
939 %N The real name if present, e.g.: \"John Doe\", else fall
940 back to the mail address.
941 %F The first name if present, e.g.: \"John\".
942 %L The last name if present, e.g.: \"Doe\".
944 All other format specifiers are passed to `format-time-string'
945 which is called using the date from the article your replying to.
946 Extracting the first (%F) and last name (%L) is done
947 heuristically, so you should always check it yourself.
949 Please also read the note in the documentation of
950 `message-citation-line-function'."
951 :type '(choice (const :tag "Plain" "%f writes:")
952 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
954 :link '(custom-manual "(message)Insertion Variables")
955 :version "23.0" ;; No Gnus
956 :group 'message-insertion)
958 (defcustom message-yank-prefix "> "
959 "*Prefix inserted on the lines of yanked messages.
960 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
961 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
963 :link '(custom-manual "(message)Insertion Variables")
964 :group 'message-insertion)
966 (defcustom message-yank-cited-prefix ">"
967 "*Prefix inserted on cited lines of yanked messages.
968 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
969 See also `message-yank-prefix' and `message-yank-empty-prefix'."
972 :link '(custom-manual "(message)Insertion Variables")
973 :group 'message-insertion)
975 (defcustom message-yank-empty-prefix ">"
976 "*Prefix inserted on empty lines of yanked messages.
977 See also `message-yank-prefix' and `message-yank-cited-prefix'."
980 :link '(custom-manual "(message)Insertion Variables")
981 :group 'message-insertion)
983 (defcustom message-indentation-spaces 3
984 "*Number of spaces to insert at the beginning of each cited line.
985 Used by `message-yank-original' via `message-yank-cite'."
986 :group 'message-insertion
987 :link '(custom-manual "(message)Insertion Variables")
990 (defcustom message-cite-function 'message-cite-original
991 "*Function for citing an original message.
992 Predefined functions include `message-cite-original' and
993 `message-cite-original-without-signature'.
994 Note that these functions use `mail-citation-hook' if that is non-nil."
995 :type '(radio (function-item message-cite-original)
996 (function-item message-cite-original-without-signature)
997 (function-item sc-cite-original)
998 (function :tag "Other"))
999 :link '(custom-manual "(message)Insertion Variables")
1000 :group 'message-insertion)
1002 (defcustom message-indent-citation-function 'message-indent-citation
1003 "*Function for modifying a citation just inserted in the mail buffer.
1004 This can also be a list of functions. Each function can find the
1005 citation between (point) and (mark t). And each function should leave
1006 point and mark around the citation text as modified."
1008 :link '(custom-manual "(message)Insertion Variables")
1009 :group 'message-insertion)
1011 (defcustom message-signature t
1012 "*String to be inserted at the end of the message buffer.
1013 If t, the `message-signature-file' file will be inserted instead.
1014 If a function, the result from the function will be used instead.
1015 If a form, the result from the form will be used instead."
1017 :link '(custom-manual "(message)Insertion Variables")
1018 :group 'message-insertion)
1020 (defcustom message-signature-file "~/.signature"
1021 "*Name of file containing the text inserted at end of message buffer.
1022 Ignored if the named file doesn't exist.
1023 If nil, don't insert a signature.
1024 If a path is specified, the value of `message-signature-directory' is ignored,
1026 :type '(choice file (const :tags "None" nil))
1027 :link '(custom-manual "(message)Insertion Variables")
1028 :group 'message-insertion)
1030 (defcustom message-signature-directory nil
1031 "*Name of directory containing signature files.
1032 Comes in handy if you have many such files, handled via posting styles for
1034 If nil, `message-signature-file' is expected to specify the directory if
1036 :type '(choice string (const :tags "None" nil))
1037 :link '(custom-manual "(message)Insertion Variables")
1038 :group 'message-insertion)
1040 (defcustom message-signature-insert-empty-line t
1041 "*If non-nil, insert an empty line before the signature separator."
1044 :link '(custom-manual "(message)Insertion Variables")
1045 :group 'message-insertion)
1047 (defcustom message-distribution-function nil
1048 "*Function called to return a Distribution header."
1049 :group 'message-news
1050 :group 'message-headers
1051 :link '(custom-manual "(message)News Headers")
1052 :type '(choice function (const nil)))
1054 (defcustom message-expires 14
1055 "Number of days before your article expires."
1056 :group 'message-news
1057 :group 'message-headers
1058 :link '(custom-manual "(message)News Headers")
1061 (defcustom message-user-path nil
1062 "If nil, use the NNTP server name in the Path header.
1063 If stringp, use this; if non-nil, use no host name (user name only)."
1064 :group 'message-news
1065 :group 'message-headers
1066 :link '(custom-manual "(message)News Headers")
1067 :type '(choice (const :tag "nntp" nil)
1068 (string :tag "name")
1069 (sexp :tag "none" :format "%t" t)))
1071 (defvar message-reply-buffer nil)
1072 (defvar message-reply-headers nil
1073 "The headers of the current replied article.
1074 It is a vector of the following headers:
1075 \[number subject from date id references chars lines xref extra].")
1076 (defvar message-newsreader nil)
1077 (defvar message-mailer nil)
1078 (defvar message-sent-message-via nil)
1079 (defvar message-checksum nil)
1080 (defvar message-send-actions nil
1081 "A list of actions to be performed upon successful sending of a message.")
1082 (defvar message-exit-actions nil
1083 "A list of actions to be performed upon exiting after sending a message.")
1084 (defvar message-kill-actions nil
1085 "A list of actions to be performed before killing a message buffer.")
1086 (defvar message-postpone-actions nil
1087 "A list of actions to be performed after postponing a message.")
1089 (define-widget 'message-header-lines 'text
1090 "All header lines must be LFD terminated."
1091 :format "%{%t%}:%n%v"
1092 :valid-regexp "^\\'"
1093 :error "All header lines must be newline terminated")
1095 (defcustom message-default-headers ""
1096 "*A string containing header lines to be inserted in outgoing messages.
1097 It is inserted before you edit the message, so you can edit or delete
1099 :group 'message-headers
1100 :link '(custom-manual "(message)Message Headers")
1101 :type 'message-header-lines)
1103 (defcustom message-default-mail-headers ""
1104 "*A string of header lines to be inserted in outgoing mails."
1105 :group 'message-headers
1106 :group 'message-mail
1107 :link '(custom-manual "(message)Mail Headers")
1108 :type 'message-header-lines)
1110 (defcustom message-default-news-headers ""
1111 "*A string of header lines to be inserted in outgoing news articles."
1112 :group 'message-headers
1113 :group 'message-news
1114 :link '(custom-manual "(message)News Headers")
1115 :type 'message-header-lines)
1117 ;; Note: could use /usr/ucb/mail instead of sendmail;
1118 ;; options -t, and -v if not interactive.
1119 (defcustom message-mailer-swallows-blank-line
1120 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1121 system-configuration)
1122 (file-readable-p "/etc/sendmail.cf")
1123 (let ((buffer (get-buffer-create " *temp*")))
1127 (insert-file-contents "/etc/sendmail.cf")
1128 (goto-char (point-min))
1129 (let ((case-fold-search nil))
1130 (re-search-forward "^OR\\>" nil t)))
1131 (kill-buffer buffer))))
1132 ;; According to RFC822, "The field-name must be composed of printable
1133 ;; ASCII characters (i. e., characters that have decimal values between
1134 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1136 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1137 "*Set this non-nil if the system's mailer runs the header and body together.
1138 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1139 The value should be an expression to test whether the problem will
1141 :group 'message-sending
1142 :link '(custom-manual "(message)Mail Variables")
1146 (define-mail-user-agent 'message-user-agent
1147 'message-mail 'message-send-and-exit
1148 'message-kill-buffer 'message-send-hook)
1150 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1151 "If non-nil, delete the deletable headers before feeding to mh.")
1153 (defvar message-send-method-alist
1154 '((news message-news-p message-send-via-news)
1155 (mail message-mail-p message-send-via-mail))
1156 "Alist of ways to send outgoing messages.
1157 Each element has the form
1159 \(TYPE PREDICATE FUNCTION)
1161 where TYPE is a symbol that names the method; PREDICATE is a function
1162 called without any parameters to determine whether the message is
1163 a message of type TYPE; and FUNCTION is a function to be called if
1164 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1167 (defcustom message-mail-alias-type 'abbrev
1168 "*What alias expansion type to use in Message buffers.
1169 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1170 an electric completion mode. nil switches mail aliases off.
1171 This can also be a list of values."
1173 :link '(custom-manual "(message)Mail Aliases")
1174 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1175 (const :tag "Use ecomplete" ecomplete)
1176 (const :tag "No expansion" nil)))
1178 (defcustom message-self-insert-commands '(self-insert-command)
1179 "List of `self-insert-command's used to trigger ecomplete.
1180 When one of those commands is invoked to enter a character in To or Cc
1181 header, ecomplete will suggest the candidates of recipients (see also
1182 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1183 text and it replaces `self-insert-command' with the other command, e.g.
1184 `egg-self-insert-command', you may want to add it to this list."
1185 :group 'message-various
1186 :type '(repeat function))
1188 (defcustom message-auto-save-directory
1189 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1190 "*Directory where Message auto-saves buffers if Gnus isn't running.
1191 If nil, Message won't auto-save."
1192 :group 'message-buffers
1193 :link '(custom-manual "(message)Various Message Variables")
1194 :type '(choice directory (const :tag "Don't auto-save" nil)))
1196 (defcustom message-default-charset
1197 (and (not (mm-multibyte-p)) 'iso-8859-1)
1198 "Default charset used in non-MULE Emacsen.
1199 If nil, you might be asked to input the charset."
1202 :link '(custom-manual "(message)Various Message Variables")
1205 (defcustom message-dont-reply-to-names
1206 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1207 "*Addresses to prune when doing wide replies.
1208 This can be a regexp or a list of regexps. Also, a value of nil means
1209 exclude your own user name only."
1212 :link '(custom-manual "(message)Wide Reply")
1213 :type '(choice (const :tag "Yourself" nil)
1215 (repeat :tag "Regexp List" regexp)))
1217 (defsubst message-dont-reply-to-names ()
1218 (gnus-orify-regexp message-dont-reply-to-names))
1220 (defvar message-shoot-gnksa-feet nil
1221 "*A list of GNKSA feet you are allowed to shoot.
1222 Gnus gives you all the opportunity you could possibly want for
1223 shooting yourself in the foot. Also, Gnus allows you to shoot the
1224 feet of Good Net-Keeping Seal of Approval. The following are foot
1226 `empty-article' Allow you to post an empty article;
1227 `quoted-text-only' Allow you to post quoted text only;
1228 `multiple-copies' Allow you to post multiple copies;
1229 `cancel-messages' Allow you to cancel or supersede messages from
1230 your other email addresses.")
1232 (defsubst message-gnksa-enable-p (feature)
1233 (or (not (listp message-shoot-gnksa-feet))
1234 (memq feature message-shoot-gnksa-feet)))
1236 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1238 "Regexp of headers to be hidden when composing new messages.
1239 This can also be a list of regexps to match headers. Or a list
1240 starting with `not' and followed by regexps."
1243 :link '(custom-manual "(message)Message Headers")
1245 :format "%{%t%}: %[Value Type%] %v"
1246 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1247 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1248 (regexp :format "%t: %v"))
1249 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1251 (repeat :format "%v%i"
1252 (regexp :format "%t: %v")))))
1254 (defcustom message-cite-articles-with-x-no-archive t
1255 "If non-nil, cite text from articles that has X-No-Archive set."
1259 ;;; Internal variables.
1260 ;;; Well, not really internal.
1262 (defvar message-mode-syntax-table
1263 (let ((table (copy-syntax-table text-mode-syntax-table)))
1264 (modify-syntax-entry ?% ". " table)
1265 (modify-syntax-entry ?> ". " table)
1266 (modify-syntax-entry ?< ". " table)
1268 "Syntax table used while in Message mode.")
1270 (defface message-header-to
1273 (:foreground "green2" :bold t))
1276 (:foreground "MidnightBlue" :bold t))
1278 (:bold t :italic t)))
1279 "Face used for displaying From headers."
1280 :group 'message-faces)
1281 ;; backward-compatibility alias
1282 (put 'message-header-to-face 'face-alias 'message-header-to)
1284 (defface message-header-cc
1287 (:foreground "green4" :bold t))
1290 (:foreground "MidnightBlue"))
1293 "Face used for displaying Cc headers."
1294 :group 'message-faces)
1295 ;; backward-compatibility alias
1296 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1298 (defface message-header-subject
1301 (:foreground "green3"))
1304 (:foreground "navy blue" :bold t))
1307 "Face used for displaying subject headers."
1308 :group 'message-faces)
1309 ;; backward-compatibility alias
1310 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1312 (defface message-header-newsgroups
1315 (:foreground "yellow" :bold t :italic t))
1318 (:foreground "blue4" :bold t :italic t))
1320 (:bold t :italic t)))
1321 "Face used for displaying newsgroups headers."
1322 :group 'message-faces)
1323 ;; backward-compatibility alias
1324 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1326 (defface message-header-other
1329 (:foreground "#b00000"))
1332 (:foreground "steel blue"))
1334 (:bold t :italic t)))
1335 "Face used for displaying newsgroups headers."
1336 :group 'message-faces)
1337 ;; backward-compatibility alias
1338 (put 'message-header-other-face 'face-alias 'message-header-other)
1340 (defface message-header-name
1343 (:foreground "DarkGreen"))
1346 (:foreground "cornflower blue"))
1349 "Face used for displaying header names."
1350 :group 'message-faces)
1351 ;; backward-compatibility alias
1352 (put 'message-header-name-face 'face-alias 'message-header-name)
1354 (defface message-header-xheader
1357 (:foreground "blue"))
1360 (:foreground "blue"))
1363 "Face used for displaying X-Header headers."
1364 :group 'message-faces)
1365 ;; backward-compatibility alias
1366 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1368 (defface message-separator
1371 (:foreground "blue3"))
1374 (:foreground "brown"))
1377 "Face used for displaying the separator."
1378 :group 'message-faces)
1379 ;; backward-compatibility alias
1380 (put 'message-separator-face 'face-alias 'message-separator)
1382 (defface message-cited-text
1385 (:foreground "red"))
1388 (:foreground "red"))
1391 "Face used for displaying cited text names."
1392 :group 'message-faces)
1393 ;; backward-compatibility alias
1394 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1396 (defface message-mml
1399 (:foreground "ForestGreen"))
1402 (:foreground "ForestGreen"))
1405 "Face used for displaying MML."
1406 :group 'message-faces)
1407 ;; backward-compatibility alias
1408 (put 'message-mml-face 'face-alias 'message-mml)
1410 (defun message-font-lock-make-header-matcher (regexp)
1413 (let ((start (point)))
1416 (goto-char (point-min))
1417 (if (re-search-forward
1418 (concat "^" (regexp-quote mail-header-separator) "$")
1420 (setq limit (min limit (match-beginning 0))))
1422 (and (< start limit)
1423 (re-search-forward ,regexp limit t))))))
1424 (if (featurep 'bytecomp)
1428 (defvar message-font-lock-keywords
1429 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1430 `((,(message-font-lock-make-header-matcher
1431 (concat "^\\([Tt]o:\\)" content))
1432 (1 'message-header-name)
1433 (2 'message-header-to nil t))
1434 (,(message-font-lock-make-header-matcher
1435 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1436 (1 'message-header-name)
1437 (2 'message-header-cc nil t))
1438 (,(message-font-lock-make-header-matcher
1439 (concat "^\\([Ss]ubject:\\)" content))
1440 (1 'message-header-name)
1441 (2 'message-header-subject nil t))
1442 (,(message-font-lock-make-header-matcher
1443 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1444 (1 'message-header-name)
1445 (2 'message-header-newsgroups nil t))
1446 (,(message-font-lock-make-header-matcher
1447 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1448 (1 'message-header-name)
1449 (2 'message-header-other nil t))
1450 (,(message-font-lock-make-header-matcher
1451 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1452 (1 'message-header-name)
1453 (2 'message-header-name))
1454 ,@(if (and mail-header-separator
1455 (not (equal mail-header-separator "")))
1456 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1457 1 'message-separator))
1460 (re-search-forward (concat "^\\("
1461 message-cite-prefix-regexp
1464 (0 'message-cited-text))
1465 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1467 "Additional expressions to highlight in Message mode.")
1470 ;; XEmacs does it like this. For Emacs, we have to set the
1471 ;; `font-lock-defaults' buffer-local variable.
1472 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1474 (defvar message-face-alist
1475 '((bold . message-bold-region)
1476 (underline . underline-region)
1477 (default . (lambda (b e)
1478 (message-unbold-region b e)
1479 (ununderline-region b e))))
1480 "Alist of mail and news faces for facemenu.
1481 The cdr of each entry is a function for applying the face to a region.")
1483 (defcustom message-send-hook nil
1484 "Hook run before sending messages.
1485 This hook is run quite early when sending."
1486 :group 'message-various
1487 :options '(ispell-message)
1488 :link '(custom-manual "(message)Various Message Variables")
1491 (defcustom message-send-mail-hook nil
1492 "Hook run before sending mail messages.
1493 This hook is run very late -- just before the message is sent as
1495 :group 'message-various
1496 :link '(custom-manual "(message)Various Message Variables")
1499 (defcustom message-send-news-hook nil
1500 "Hook run before sending news messages.
1501 This hook is run very late -- just before the message is sent as
1503 :group 'message-various
1504 :link '(custom-manual "(message)Various Message Variables")
1507 (defcustom message-sent-hook nil
1508 "Hook run after sending messages."
1509 :group 'message-various
1512 (defvar message-send-coding-system 'binary
1513 "Coding system to encode outgoing mail.")
1515 (defvar message-draft-coding-system
1516 mm-auto-save-coding-system
1517 "*Coding system to compose mail.
1518 If you'd like to make it possible to share draft files between XEmacs
1519 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1520 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1522 (defcustom message-send-mail-partially-limit 1000000
1523 "The limitation of messages sent as message/partial.
1524 The lower bound of message size in characters, beyond which the message
1525 should be sent in several parts. If it is nil, the size is unlimited."
1527 :group 'message-buffers
1528 :link '(custom-manual "(message)Mail Variables")
1529 :type '(choice (const :tag "unlimited" nil)
1532 (defcustom message-alternative-emails nil
1533 "*Regexp matching alternative email addresses.
1534 The first address in the To, Cc or From headers of the original
1535 article matching this variable is used as the From field of
1538 This variable has precedence over posting styles and anything that runs
1539 off `message-setup-hook'."
1540 :group 'message-headers
1541 :link '(custom-manual "(message)Message Headers")
1542 :type '(choice (const :tag "Always use primary" nil)
1545 (defcustom message-hierarchical-addresses nil
1546 "A list of hierarchical mail address definitions.
1548 Inside each entry, the first address is the \"top\" address, and
1549 subsequent addresses are subaddresses; this is used to indicate that
1550 mail sent to the first address will automatically be delivered to the
1551 subaddresses. So if the first address appears in the recipient list
1552 for a message, the subaddresses will be removed (if present) before
1553 the mail is sent. All addresses in this structure should be
1556 :group 'message-headers
1557 :type '(repeat (repeat string)))
1559 (defcustom message-mail-user-agent nil
1560 "Like `mail-user-agent'.
1561 Except if it is nil, use Gnus native MUA; if it is t, use
1564 :type '(radio (const :tag "Gnus native"
1567 (const :tag "`mail-user-agent'"
1570 (function-item :tag "Default Emacs mail"
1572 sendmail-user-agent)
1573 (function-item :tag "Emacs interface to MH"
1576 (function :tag "Other"))
1580 (defcustom message-wide-reply-confirm-recipients nil
1581 "Whether to confirm a wide reply to multiple email recipients.
1582 If this variable is nil, don't ask whether to reply to all recipients.
1583 If this variable is non-nil, pose the question \"Reply to all
1584 recipients?\" before a wide reply to multiple recipients. If the user
1585 answers yes, reply to all recipients as usual. If the user answers
1586 no, only reply back to the author."
1588 :group 'message-headers
1589 :link '(custom-manual "(message)Wide Reply")
1592 (defcustom message-user-fqdn nil
1593 "*Domain part of Message-Ids."
1595 :group 'message-headers
1596 :link '(custom-manual "(message)News Headers")
1597 :type '(radio (const :format "%v " nil)
1598 (string :format "FQDN: %v")))
1600 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1602 (mm-coding-system-p 'utf-8)
1603 (executable-find idna-program)
1604 (string= (idna-to-ascii "räksmörgås")
1605 "xn--rksmrgs-5wao1o")
1607 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1608 GNU Libidn, and in particular the elisp package \"idna.el\" and
1609 the external program \"idn\", must be installed for this
1610 functionality to work."
1612 :group 'message-headers
1613 :link '(custom-manual "(message)IDNA")
1614 :type '(choice (const :tag "Ask" ask)
1615 (const :tag "Never" nil)
1616 (const :tag "Always" t)))
1618 (defcustom message-generate-hashcash (if (executable-find "hashcash") t)
1619 "*Whether to generate X-Hashcash: headers.
1620 If `t', always generate hashcash headers. If `opportunistic',
1621 only generate hashcash headers if it can be done without the user
1622 waiting (i.e., only asynchronously).
1624 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1625 :group 'message-headers
1626 :link '(custom-manual "(message)Mail Headers")
1627 :type '(choice (const :tag "Always" t)
1628 (const :tag "Never" nil)
1629 (const :tag "Opportunistic" opportunistic)))
1631 ;;; Internal variables.
1633 (defvar message-sending-message "Sending...")
1634 (defvar message-buffer-list nil)
1635 (defvar message-this-is-news nil)
1636 (defvar message-this-is-mail nil)
1637 (defvar message-draft-article nil)
1638 (defvar message-mime-part nil)
1639 (defvar message-posting-charset nil)
1640 (defvar message-inserted-headers nil)
1642 ;; Byte-compiler warning
1644 (defvar gnus-active-hashtb)
1645 (defvar gnus-read-active-file))
1647 ;;; Regexp matching the delimiter of messages in UNIX mail format
1648 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1649 ;;; of rmail.el's rmail-unix-mail-delimiter.
1650 (defvar message-unix-mail-delimiter
1651 (let ((time-zone-regexp
1652 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1653 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1659 ;; Many things can happen to an RFC 822 mailbox before it is put into
1660 ;; a `From' line. The leading phrase can be stripped, e.g.
1661 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1662 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1663 ;; can be removed, e.g.
1664 ;; From: joe@y.z (Joe K
1666 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1669 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1670 ;; The mailbox can be removed or be replaced by white space, e.g.
1671 ;; From: "Joe User"{space}{tab}
1673 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1674 ;; where {space} and {tab} represent the Ascii space and tab characters.
1675 ;; We want to match the results of any of these manglings.
1676 ;; The following regexp rejects names whose first characters are
1677 ;; obviously bogus, but after that anything goes.
1678 "\\([^\0-\b\n-\r\^?].*\\)?"
1680 ;; The time the message was sent.
1681 "\\([^\0-\r \^?]+\\) +" ; day of the week
1682 "\\([^\0-\r \^?]+\\) +" ; month
1683 "\\([0-3]?[0-9]\\) +" ; day of month
1684 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1686 ;; Perhaps a time zone, specified by an abbreviation, or by a
1691 " \\([0-9][0-9]+\\) *"
1693 ;; On some systems the time zone can appear after the year, too.
1697 "\\(remote from .*\\)?"
1700 "Regexp matching the delimiter of messages in UNIX mail format.")
1702 (defvar message-unsent-separator
1703 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1704 "^ *---+ +Returned message +---+ *$\\|"
1705 "^Start of returned message$\\|"
1706 "^ *---+ +Original message +---+ *$\\|"
1707 "^ *--+ +begin message +--+ *$\\|"
1708 "^ *---+ +Original message follows +---+ *$\\|"
1709 "^ *---+ +Undelivered message follows +---+ *$\\|"
1710 "^|? *---+ +Message text follows: +---+ *|?$")
1711 "A regexp that matches the separator before the text of a failed message.")
1713 (defvar message-field-fillers
1714 '((To message-fill-field-address)
1715 (Cc message-fill-field-address)
1716 (From message-fill-field-address))
1717 "Alist of header names/filler functions.")
1719 (defvar message-header-format-alist
1734 (References . message-shorten-references)
1736 "Alist used for formatting headers.")
1738 (defvar message-options nil
1739 "Some saved answers when sending message.")
1741 (defvar message-send-mail-real-function nil
1742 "Internal send mail function.")
1744 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1745 "The regexp of bogus system names.")
1747 (defcustom message-valid-fqdn-regexp
1748 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1750 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1751 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1752 "cat\\|com\\|coop\\|edu\\|gov\\|"
1753 "info\\|int\\|jobs\\|"
1754 "mil\\|mobi\\|museum\\|name\\|net\\|"
1755 "org\\|pro\\|travel\\|uucp\\)")
1756 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1757 ;; http://en.wikipedia.org/wiki/GTLD
1758 ;; `in the process of being approved': .asia .post .tel .sex
1759 ;; "dead" nato bitnet uucp
1760 "Regular expression that matches a valid FQDN."
1761 ;; see also: gnus-button-valid-fqdn-regexp
1763 :group 'message-headers
1767 (autoload 'gnus-alive-p "gnus-util")
1768 (autoload 'gnus-delay-article "gnus-delay")
1769 (autoload 'gnus-extract-address-components "gnus-util")
1770 (autoload 'gnus-find-method-for-group "gnus")
1771 (autoload 'gnus-group-decoded-name "gnus-group")
1772 (autoload 'gnus-group-name-charset "gnus-group")
1773 (autoload 'gnus-group-name-decode "gnus-group")
1774 (autoload 'gnus-groups-from-server "gnus")
1775 (autoload 'gnus-make-local-hook "gnus-util")
1776 (autoload 'gnus-open-server "gnus-int")
1777 (autoload 'gnus-output-to-mail "gnus-util")
1778 (autoload 'gnus-output-to-rmail "gnus-util")
1779 (autoload 'gnus-request-post "gnus-int")
1780 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1781 (autoload 'gnus-server-string "gnus")
1782 (autoload 'idna-to-ascii "idna")
1783 (autoload 'message-setup-toolbar "messagexmas")
1784 (autoload 'mh-new-draft-name "mh-comp")
1785 (autoload 'mh-send-letter "mh-comp")
1786 (autoload 'nndraft-request-associate-buffer "nndraft")
1787 (autoload 'nndraft-request-expire-articles "nndraft")
1788 (autoload 'nnvirtual-find-group-art "nnvirtual")
1789 (autoload 'rmail-dont-reply-to "mail-utils")
1790 (autoload 'rmail-msg-is-pruned "rmail")
1791 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1792 (autoload 'rmail-output "rmailout"))
1797 ;;; Utility functions.
1800 (defmacro message-y-or-n-p (question show &rest text)
1801 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1802 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1804 (defmacro message-delete-line (&optional n)
1805 "Delete the current line (and the next N lines)."
1806 `(delete-region (progn (beginning-of-line) (point))
1807 (progn (forward-line ,(or n 1)) (point))))
1809 (defun message-mark-active-p ()
1810 "Non-nil means the mark and region are currently active in this buffer."
1813 (defun message-unquote-tokens (elems)
1814 "Remove double quotes (\") from strings in list ELEMS."
1815 (mapcar (lambda (item)
1816 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1817 (setq item (concat (match-string 1 item)
1818 (match-string 2 item))))
1822 (defun message-tokenize-header (header &optional separator)
1823 "Split HEADER into a list of header elements.
1824 SEPARATOR is a string of characters to be used as separators. \",\"
1825 is used by default."
1828 (let ((regexp (format "[%s]+" (or separator ",")))
1830 beg quoted elems paren)
1832 (mm-enable-multibyte)
1833 (setq beg (point-min))
1835 (goto-char (point-min))
1840 (cond ((and (> (point) beg)
1842 (and (looking-at regexp)
1845 (push (buffer-substring beg (point)) elems)
1846 (setq beg (match-end 0)))
1847 ((eq (char-after) ?\")
1848 (setq quoted (not quoted)))
1849 ((and (eq (char-after) ?\()
1852 ((and (eq (char-after) ?\))
1855 (nreverse elems)))))
1857 (defun message-mail-file-mbox-p (file)
1858 "Say whether FILE looks like a Unix mbox file."
1859 (when (and (file-exists-p file)
1860 (file-readable-p file)
1861 (file-regular-p file))
1863 (nnheader-insert-file-contents file)
1864 (goto-char (point-min))
1865 (looking-at message-unix-mail-delimiter))))
1867 (defun message-fetch-field (header &optional not-all)
1868 "The same as `mail-fetch-field', only remove all newlines.
1869 The buffer is expected to be narrowed to just the header of the message;
1870 see `message-narrow-to-headers-or-head'."
1871 (let* ((inhibit-point-motion-hooks t)
1872 (value (mail-fetch-field header nil (not not-all))))
1874 (while (string-match "\n[\t ]+" value)
1875 (setq value (replace-match " " t t value)))
1878 (defun message-field-value (header &optional not-all)
1879 "The same as `message-fetch-field', only narrow to the headers first."
1882 (message-narrow-to-headers-or-head)
1883 (message-fetch-field header not-all))))
1885 (defun message-narrow-to-field ()
1886 "Narrow the buffer to the header on the current line."
1888 (while (looking-at "[ \t]")
1894 (if (re-search-forward "^[^ \n\t]" nil t)
1897 (goto-char (point-min)))
1899 (defun message-add-header (&rest headers)
1900 "Add the HEADERS to the message header, skipping those already present."
1903 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1904 (error "Invalid header `%s'" (car headers)))
1905 (setq hclean (match-string 1 (car headers)))
1907 (message-narrow-to-headers)
1908 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1909 (goto-char (point-max))
1910 (if (string-match "\n$" (car headers))
1911 (insert (car headers))
1912 (insert (car headers) ?\n)))))
1913 (setq headers (cdr headers))))
1915 (defmacro message-with-reply-buffer (&rest forms)
1916 "Evaluate FORMS in the reply buffer, if it exists."
1917 `(when (and message-reply-buffer
1918 (buffer-name message-reply-buffer))
1920 (set-buffer message-reply-buffer)
1923 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1924 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1926 (defun message-fetch-reply-field (header)
1927 "Fetch field HEADER from the message we're replying to."
1928 (message-with-reply-buffer
1930 (mail-narrow-to-head)
1931 (message-fetch-field header))))
1933 (defun message-strip-list-identifiers (subject)
1934 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1935 (require 'gnus-sum) ; for gnus-list-identifiers
1936 (let ((regexp (if (stringp gnus-list-identifiers)
1937 gnus-list-identifiers
1938 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1939 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1940 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1941 (concat (substring subject 0 (match-beginning 1))
1942 (or (match-string 3 subject)
1943 (match-string 5 subject))
1948 (defun message-strip-subject-re (subject)
1949 "Remove \"Re:\" from subject lines in string SUBJECT."
1950 (if (string-match message-subject-re-regexp subject)
1951 (substring subject (match-end 0))
1954 (defcustom message-replacement-char "."
1955 "Replacement character used instead of unprintable or not decodable chars."
1956 :group 'message-various
1957 :version "22.1" ;; Gnus 5.10.9
1958 :type '(choice string
1962 ;; FIXME: We also should call `message-strip-subject-encoded-words'
1963 ;; when forwarding. Probably in `message-make-forward-subject' and
1964 ;; `message-forward-make-body'.
1966 (defun message-strip-subject-encoded-words (subject)
1967 "Fix non-decodable words in SUBJECT."
1968 ;; Cf. `gnus-simplify-subject-fully'.
1969 (let* ((case-fold-search t)
1970 (replacement-chars (format "[%s%s%s]"
1971 message-replacement-char
1972 message-replacement-char
1973 message-replacement-char))
1974 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
1979 (goto-char (point-min))
1980 (when (re-search-forward enc-word-re nil t)
1981 (setq cs-string (match-string 1)))))
1982 cs-coding q-or-b word-beg word-end)
1983 (if (or (not have-marker) ;; No encoded word found...
1984 ;; ... or double encoding was correct:
1985 (and (stringp cs-string)
1986 (setq cs-string (downcase cs-string))
1987 (mm-coding-system-p (intern cs-string))
1991 Decoded Subject \"%s\"
1992 contains a valid encoded word. Decode again? "
1994 (setq cs-coding (intern cs-string))))))
1998 (goto-char (point-min))
1999 (while (re-search-forward enc-word-re nil t)
2000 (setq cs-string (downcase (match-string 1))
2001 q-or-b (match-string 2)
2002 word-beg (match-beginning 0)
2003 word-end (match-end 0))
2005 (if (mm-coding-system-p (intern cs-string))
2006 (setq cs-coding (intern cs-string))
2008 ;; No double encoded subject? => bogus charset.
2011 (mm-read-coding-system
2013 Decoded Subject \"%s\"
2014 contains an encoded word. The charset `%s' is unknown or invalid.
2015 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2017 subject cs-string message-replacement-char)))
2019 (replace-match (concat "=?" (symbol-name cs-coding)
2022 (goto-char word-beg)
2023 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2026 (if (string-match "\\`Q\\'" q-or-b)
2029 (message "Replacing non-decodable characters with \"%s\"."
2030 message-replacement-char)
2031 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2033 (replace-match message-replacement-char)))
2035 (message "Replacing non-decodable characters with \"%s\"."
2037 (re-search-forward "[^?]+" word-end t)
2038 (replace-match replacement-chars))
2039 (re-search-forward "\\?=")
2040 (replace-match "")))))
2041 (rfc2047-decode-region (point-min) (point-max))
2044 ;;; Start of functions adopted from `message-utils.el'.
2046 (defun message-strip-subject-trailing-was (subject)
2047 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2048 Leading \"Re: \" is not stripped by this function. Use the function
2049 `message-strip-subject-re' for this."
2050 (let* ((query message-subject-trailing-was-query)
2055 message-subject-trailing-was-ask-regexp
2056 message-subject-trailing-was-regexp)
2059 (setq new (substring subject 0 (match-beginning 0))))
2060 (if (or (not found) (eq query nil))
2063 (if (message-y-or-n-p
2064 "Strip `(was: <old subject>)' in subject? " t
2066 "Strip `(was: <old subject>)' in subject "
2067 "and use the new one instead?\n\n"
2068 "Current subject is: \""
2070 "New subject would be: \""
2072 "See the variable `message-subject-trailing-was-query' "
2073 "to get rid of this query."
2078 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2080 (defun message-change-subject (new-subject)
2081 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2082 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2085 (read-from-minibuffer "New subject: ")))
2086 (cond ((and (not (or (null new-subject) ; new subject not empty
2087 (zerop (string-width new-subject))
2088 (string-match "^[ \t]*$" new-subject))))
2092 (message-narrow-to-headers)
2093 (message-fetch-field "Subject"))))
2094 (cond ((not old-subject)
2095 (error "No current subject"))
2098 (regexp-quote new-subject)
2100 old-subject)) ; yes, it really is a new subject
2101 ;; delete eventual Re: prefix
2103 (message-strip-subject-re old-subject))
2104 (message-goto-subject)
2105 (message-delete-line)
2106 (insert (concat "Subject: "
2109 old-subject ")\n")))))))))
2111 (defun message-mark-inserted-region (beg end &optional verbatim)
2112 "Mark some region in the current article with enclosing tags.
2113 See `message-mark-insert-begin' and `message-mark-insert-end'.
2114 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2115 (interactive "r\nP")
2117 ;; add to the end of the region first, otherwise end would be invalid
2119 (insert (if verbatim "#v-\n" message-mark-insert-end))
2121 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2123 (defun message-mark-insert-file (file &optional verbatim)
2124 "Insert FILE at point, marking it with enclosing tags.
2125 See `message-mark-insert-begin' and `message-mark-insert-end'.
2126 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2127 (interactive "fFile to insert: \nP")
2128 ;; reverse insertion to get correct result.
2130 (insert (if verbatim "#v-\n" message-mark-insert-end))
2132 (insert-file-contents file)
2134 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2136 (defun message-add-archive-header ()
2137 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2138 The note can be customized using `message-archive-note'. When called with a
2139 prefix argument, ask for a text to insert. If you don't want the note in the
2140 body, set `message-archive-note' to nil."
2142 (if current-prefix-arg
2143 (setq message-archive-note
2144 (read-from-minibuffer "Reason for No-Archive: "
2145 (cons message-archive-note 0))))
2147 (if (message-goto-signature)
2148 (re-search-backward message-signature-separator))
2149 (when message-archive-note
2150 (insert message-archive-note)
2152 (message-add-header message-archive-header)
2153 (message-sort-headers)))
2155 (defun message-cross-post-followup-to-header (target-group)
2156 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2157 With prefix-argument just set Follow-Up, don't cross-post."
2159 (list ; Completion based on Gnus
2160 (completing-read "Followup To: "
2161 (if (boundp 'gnus-newsrc-alist)
2163 nil nil '("poster" . 0)
2164 (if (boundp 'gnus-group-history)
2165 'gnus-group-history))))
2166 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2167 (message-goto-newsgroups)
2169 ;; if we already did a crosspost before, kill old target
2170 (if (and message-cross-post-old-target
2172 (regexp-quote (concat "," message-cross-post-old-target))
2175 ;; unless (followup is to poster or user explicitly asked not
2176 ;; to cross-post, or target-group is already in Newsgroups)
2177 ;; add target-group to Newsgroups line.
2179 ;; def: cross-post, req:no
2180 (and message-cross-post-default (not current-prefix-arg))
2181 ;; def: no-cross-post, req:yes
2182 (and (not message-cross-post-default) current-prefix-arg))
2183 (not (string-match "poster" target-group))
2184 (not (string-match (regexp-quote target-group)
2185 (message-fetch-field "Newsgroups"))))
2187 (insert (concat "," target-group))))
2188 (end-of-line) ; ensure Followup: comes after Newsgroups:
2189 ;; unless new followup would be identical to Newsgroups line
2190 ;; make a new Followup-To line
2191 (if (not (string-match (concat "^[ \t]*"
2194 (message-fetch-field "Newsgroups")))
2195 (insert (concat "\nFollowup-To: " target-group)))
2196 (setq message-cross-post-old-target target-group))
2198 (defun message-cross-post-insert-note (target-group cross-post in-old
2200 "Insert a in message body note about a set Followup or Crosspost.
2201 If there have been previous notes, delete them. TARGET-GROUP specifies the
2202 group to Followup-To. When CROSS-POST is t, insert note about
2203 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2204 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2205 been made to before the user asked for a Crosspost."
2206 ;; start scanning body for previous uses
2207 (message-goto-signature)
2208 (let ((head (re-search-backward
2209 (concat "^" mail-header-separator)
2210 nil t))) ; just search in body
2211 (message-goto-signature)
2212 (while (re-search-backward
2213 (concat "^" (regexp-quote message-cross-post-note) ".*")
2215 (message-delete-line))
2216 (message-goto-signature)
2217 (while (re-search-backward
2218 (concat "^" (regexp-quote message-followup-to-note) ".*")
2220 (message-delete-line))
2222 (if (message-goto-signature)
2223 (re-search-backward message-signature-separator))
2226 (string-match "^[ \t]*poster[ \t]*$" target-group))
2227 (insert (concat message-followup-to-note target-group "\n"))
2228 (insert (concat message-cross-post-note target-group "\n")))))
2230 (defun message-cross-post-followup-to (target-group)
2231 "Crossposts message and set Followup-To to TARGET-GROUP.
2232 With prefix-argument just set Follow-Up, don't cross-post."
2234 (list ; Completion based on Gnus
2235 (completing-read "Followup To: "
2236 (if (boundp 'gnus-newsrc-alist)
2238 nil nil '("poster" . 0)
2239 (if (boundp 'gnus-group-history)
2240 'gnus-group-history))))
2241 (cond ((not (or (null target-group) ; new subject not empty
2242 (zerop (string-width target-group))
2243 (string-match "^[ \t]*$" target-group)))
2245 (let* ((old-groups (message-fetch-field "Newsgroups"))
2246 (in-old (string-match
2247 (regexp-quote target-group)
2248 (or old-groups ""))))
2249 ;; check whether target exactly matches old Newsgroups
2250 (cond ((not old-groups)
2251 (error "No current newsgroup"))
2255 (regexp-quote target-group)
2258 ;; yes, Newsgroups line must change
2259 (message-cross-post-followup-to-header target-group)
2260 ;; insert note whether we do cross-post or followup-to
2261 (funcall message-cross-post-note-function
2263 (if (or (and message-cross-post-default
2264 (not current-prefix-arg))
2265 (and (not message-cross-post-default)
2266 current-prefix-arg)) t)
2267 in-old old-groups))))))))
2269 ;;; Reduce To: to Cc: or Bcc: header
2271 (defun message-reduce-to-to-cc ()
2272 "Replace contents of To: header with contents of Cc: or Bcc: header."
2275 (save-restriction (message-narrow-to-headers)
2276 (message-fetch-field "cc")))
2278 (if (and (not cc-content)
2281 (message-narrow-to-headers)
2282 (message-fetch-field "bcc"))))
2287 (message-delete-line)
2288 (insert (concat "To: " cc-content "\n"))
2290 (message-narrow-to-headers)
2291 (message-remove-header (if bcc
2295 ;;; End of functions adopted from `message-utils.el'.
2297 (defun message-remove-header (header &optional is-regexp first reverse)
2298 "Remove HEADER in the narrowed buffer.
2299 If IS-REGEXP, HEADER is a regular expression.
2300 If FIRST, only remove the first instance of the header.
2301 Return the number of headers removed."
2302 (goto-char (point-min))
2303 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2305 (case-fold-search t)
2307 (while (and (not (eobp))
2310 (not (looking-at regexp))
2311 (looking-at regexp))
2318 ;; There might be a continuation header, so we have to search
2319 ;; until we find a new non-continuation line.
2322 (if (re-search-forward "^[^ \t]" nil t)
2323 (goto-char (match-beginning 0))
2326 (if (re-search-forward "^[^ \t]" nil t)
2327 (goto-char (match-beginning 0))
2328 (goto-char (point-max)))))
2331 (defun message-remove-first-header (header)
2332 "Remove the first instance of HEADER if there is more than one."
2334 (regexp (concat "^" (regexp-quote header) ":")))
2336 (goto-char (point-min))
2337 (while (re-search-forward regexp nil t)
2340 (message-remove-header header nil t)
2343 (defun message-narrow-to-headers ()
2344 "Narrow the buffer to the head of the message."
2347 (goto-char (point-min))
2348 (if (re-search-forward
2349 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2352 (goto-char (point-min)))
2354 (defun message-narrow-to-head-1 ()
2355 "Like `message-narrow-to-head'. Don't widen."
2357 (goto-char (point-min))
2358 (if (search-forward "\n\n" nil 1)
2361 (goto-char (point-min)))
2363 (defun message-narrow-to-head ()
2364 "Narrow the buffer to the head of the message.
2365 Point is left at the beginning of the narrowed-to region."
2367 (message-narrow-to-head-1))
2369 (defun message-narrow-to-headers-or-head ()
2370 "Narrow the buffer to the head of the message."
2373 (goto-char (point-min))
2376 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2377 (match-beginning 0))
2378 ((search-forward "\n\n" nil t)
2382 (goto-char (point-min)))
2384 (defun message-news-p ()
2385 "Say whether the current buffer contains a news message."
2386 (and (not message-this-is-mail)
2387 (or message-this-is-news
2390 (message-narrow-to-headers)
2391 (and (message-fetch-field "newsgroups")
2392 (not (message-fetch-field "posted-to"))))))))
2394 (defun message-mail-p ()
2395 "Say whether the current buffer contains a mail message."
2396 (and (not message-this-is-news)
2397 (or message-this-is-mail
2400 (message-narrow-to-headers)
2401 (or (message-fetch-field "to")
2402 (message-fetch-field "cc")
2403 (message-fetch-field "bcc")))))))
2405 (defun message-subscribed-p ()
2406 "Say whether we need to insert a MFT header."
2407 (or message-subscribed-regexps
2408 message-subscribed-addresses
2409 message-subscribed-address-file
2410 message-subscribed-address-functions))
2412 (defun message-next-header ()
2413 "Go to the beginning of the next header."
2415 (or (eobp) (forward-char 1))
2416 (not (if (re-search-forward "^[^ \t]" nil t)
2418 (goto-char (point-max)))))
2420 (defun message-sort-headers-1 ()
2421 "Sort the buffer as headers using `message-rank' text props."
2422 (goto-char (point-min))
2425 nil 'message-next-header
2427 (message-next-header)
2431 (or (get-text-property (point) 'message-rank)
2434 (defun message-sort-headers ()
2435 "Sort the headers of the current message according to `message-header-format-alist'."
2439 (let ((max (1+ (length message-header-format-alist)))
2441 (message-narrow-to-headers)
2442 (while (re-search-forward "^[^ \n]+:" nil t)
2444 (match-beginning 0) (1+ (match-beginning 0))
2446 (if (setq rank (length (memq (assq (intern (buffer-substring
2448 (1- (match-end 0))))
2449 message-header-format-alist)
2450 message-header-format-alist)))
2453 (message-sort-headers-1))))
2455 (defun message-kill-address ()
2456 "Kill the address under point."
2458 (let ((start (point)))
2459 (message-skip-to-next-address)
2460 (kill-region start (point))))
2463 (defun message-info (&optional arg)
2464 "Display the Message manual.
2466 Prefixed with one \\[universal-argument], display the Emacs MIME manual.
2467 Prefixed with two \\[universal-argument]'s, display the PGG manual."
2469 (cond ((eq arg 16) (Info-goto-node "(pgg)Top"))
2470 ((eq arg 4) (Info-goto-node "(emacs-mime)Top"))
2471 (t (Info-goto-node "(message)Top"))))
2481 (defvar message-mode-map nil)
2483 (unless message-mode-map
2484 (setq message-mode-map (make-keymap))
2485 (set-keymap-parent message-mode-map text-mode-map)
2486 (define-key message-mode-map "\C-c?" 'describe-mode)
2488 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2489 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2490 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2491 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2492 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2493 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2494 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2495 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2496 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2497 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2498 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2499 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2500 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2501 (define-key message-mode-map "\C-c\C-f\C-i"
2502 'message-insert-or-toggle-importance)
2503 (define-key message-mode-map "\C-c\C-f\C-a"
2504 'message-generate-unsubscribed-mail-followup-to)
2506 ;; modify headers (and insert notes in body)
2507 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2509 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2510 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2511 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2512 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2513 ;; mark inserted text
2514 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2515 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2517 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2518 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2520 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2521 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2522 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2523 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2524 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2526 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2527 (define-key message-mode-map "\C-c\M-n"
2528 'message-insert-disposition-notification-to)
2530 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2531 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2532 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2533 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2534 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2535 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2536 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2537 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2539 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2540 (define-key message-mode-map "\C-c\C-s" 'message-send)
2541 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2542 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2543 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2545 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2546 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2547 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2548 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2549 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2550 (define-key message-mode-map [remap split-line] 'message-split-line)
2552 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2554 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2555 (define-key message-mode-map "\t" 'message-tab)
2556 (define-key message-mode-map "\M-;" 'comment-region)
2558 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2561 message-mode-menu message-mode-map "Message Menu."
2563 ["Yank Original" message-yank-original message-reply-buffer]
2564 ["Fill Yanked Message" message-fill-yanked-message t]
2565 ["Insert Signature" message-insert-signature t]
2566 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2567 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2568 ["Elide Region" message-elide-region
2569 :active (message-mark-active-p)
2570 ,@(if (featurep 'xemacs) nil
2571 '(:help "Replace text in region with an ellipsis"))]
2572 ["Delete Outside Region" message-delete-not-region
2573 :active (message-mark-active-p)
2574 ,@(if (featurep 'xemacs) nil
2575 '(:help "Delete all quoted text outside region"))]
2576 ["Kill To Signature" message-kill-to-signature t]
2577 ["Newline and Reformat" message-newline-and-reformat t]
2578 ["Rename buffer" message-rename-buffer t]
2579 ["Spellcheck" ispell-message
2580 ,@(if (featurep 'xemacs) '(t)
2581 '(:help "Spellcheck this message"))]
2583 ["Insert Region Marked" message-mark-inserted-region
2584 :active (message-mark-active-p)
2585 ,@(if (featurep 'xemacs) nil
2586 '(:help "Mark region with enclosing tags"))]
2587 ["Insert File Marked..." message-mark-insert-file
2588 ,@(if (featurep 'xemacs) '(t)
2589 '(:help "Insert file at point marked with enclosing tags"))]
2591 ["Send Message" message-send-and-exit
2592 ,@(if (featurep 'xemacs) '(t)
2593 '(:help "Send this message"))]
2594 ["Postpone Message" message-dont-send
2595 ,@(if (featurep 'xemacs) '(t)
2596 '(:help "File this draft message and exit"))]
2597 ["Send at Specific Time..." gnus-delay-article
2598 ,@(if (featurep 'xemacs) '(t)
2599 '(:help "Ask, then arrange to send message at that time"))]
2600 ["Kill Message" message-kill-buffer
2601 ,@(if (featurep 'xemacs) '(t)
2602 '(:help "Delete this message without sending"))]
2604 ["Message manual" message-info
2605 ,@(if (featurep 'xemacs) '(t)
2606 '(:help "Display the Message manual"))]))
2609 message-mode-field-menu message-mode-map ""
2611 ["To" message-goto-to t]
2612 ["From" message-goto-from t]
2613 ["Subject" message-goto-subject t]
2614 ["Change subject..." message-change-subject t]
2615 ["Cc" message-goto-cc t]
2616 ["Bcc" message-goto-bcc t]
2617 ["Fcc" message-goto-fcc t]
2618 ["Reply-To" message-goto-reply-to t]
2619 ["Flag As Important" message-insert-importance-high
2620 ,@(if (featurep 'xemacs) '(t)
2621 '(:help "Mark this message as important"))]
2622 ["Flag As Unimportant" message-insert-importance-low
2623 ,@(if (featurep 'xemacs) '(t)
2624 '(:help "Mark this message as unimportant"))]
2626 message-insert-disposition-notification-to
2627 ,@(if (featurep 'xemacs) '(t)
2628 '(:help "Request a receipt notification"))]
2630 ;; (typical) news stuff
2631 ["Summary" message-goto-summary t]
2632 ["Keywords" message-goto-keywords t]
2633 ["Newsgroups" message-goto-newsgroups t]
2634 ["Fetch Newsgroups" message-insert-newsgroups t]
2635 ["Followup-To" message-goto-followup-to t]
2636 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2637 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2638 ["Distribution" message-goto-distribution t]
2639 ["Expires" message-insert-expires t ]
2640 ["X-No-Archive" message-add-archive-header t ]
2642 ;; (typical) mailing-lists stuff
2643 ["Fetch To" message-insert-to
2644 ,@(if (featurep 'xemacs) '(t)
2645 '(:help "Insert a To header that points to the author."))]
2646 ["Fetch To and Cc" message-insert-wide-reply
2647 ,@(if (featurep 'xemacs) '(t)
2649 "Insert To and Cc headers as if you were doing a wide reply."))]
2651 ["Send to list only" message-to-list-only t]
2652 ["Mail-Followup-To" message-goto-mail-followup-to t]
2653 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2654 ,@(if (featurep 'xemacs) '(t)
2655 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2656 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2658 ["Sort Headers" message-sort-headers t]
2659 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2660 ;; We hide `message-hidden-headers' by narrowing the buffer.
2661 ["Show Hidden Headers" widen t]
2662 ["Goto Body" message-goto-body t]
2663 ["Goto Signature" message-goto-signature t]))
2665 (defvar message-tool-bar-map nil)
2668 (defvar facemenu-add-face-function)
2669 (defvar facemenu-remove-face-function))
2671 ;;; Forbidden properties
2673 ;; We use `after-change-functions' to keep special text properties
2674 ;; that interfer with the normal function of message mode out of the
2677 (defcustom message-strip-special-text-properties t
2678 "Strip special properties from the message buffer.
2680 Emacs has a number of special text properties which can break message
2681 composing in various ways. If this option is set, message will strip
2682 these properties from the message composition buffer. However, some
2683 packages requires these properties to be present in order to work.
2684 If you use one of these packages, turn this option off, and hope the
2685 message composition doesn't break too bad."
2687 :group 'message-various
2688 :link '(custom-manual "(message)Various Message Variables")
2691 (defconst message-forbidden-properties
2692 ;; No reason this should be clutter up customize. We make it a
2693 ;; property list (rather than a list of property symbols), to be
2694 ;; directly useful for `remove-text-properties'.
2695 '(field nil read-only nil invisible nil intangible nil
2696 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2697 insert-behind-hooks nil point-entered nil point-left nil)
2698 ;; Other special properties:
2699 ;; category, face, display: probably doesn't do any harm.
2700 ;; fontified: is used by font-lock.
2701 ;; syntax-table, local-map: I dunno.
2702 ;; We need to add XEmacs names to the list.
2703 "Property list of with properties forbidden in message buffers.
2704 The values of the properties are ignored, only the property names are used.")
2706 (defun message-tamago-not-in-use-p (pos)
2707 "Return t when tamago version 4 is not in use at the cursor position.
2708 Tamago version 4 is a popular input method for writing Japanese text.
2709 It uses the properties `intangible', `invisible', `modification-hooks'
2710 and `read-only' when translating ascii or kana text to kanji text.
2711 These properties are essential to work, so we should never strip them."
2712 (not (and (boundp 'egg-modefull-mode)
2713 (symbol-value 'egg-modefull-mode)
2714 (or (memq (get-text-property pos 'intangible)
2715 '(its-part-1 its-part-2))
2716 (get-text-property pos 'egg-end)
2717 (get-text-property pos 'egg-lang)
2718 (get-text-property pos 'egg-start)))))
2720 (defsubst message-mail-alias-type-p (type)
2721 (if (atom message-mail-alias-type)
2722 (eq message-mail-alias-type type)
2723 (memq type message-mail-alias-type)))
2725 (defun message-strip-forbidden-properties (begin end &optional old-length)
2726 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2727 This function is intended to be called from `after-change-functions'.
2728 See also `message-forbidden-properties'."
2729 (when (and (message-mail-alias-type-p 'ecomplete)
2730 (memq this-command message-self-insert-commands))
2731 (message-display-abbrev))
2732 (when (and message-strip-special-text-properties
2733 (message-tamago-not-in-use-p begin))
2734 (let ((buffer-read-only nil)
2735 (inhibit-read-only t))
2736 (remove-text-properties begin end message-forbidden-properties))))
2739 (define-derived-mode message-mode text-mode "Message"
2740 "Major mode for editing mail and news to be sent.
2741 Like Text Mode but with these additional commands:\\<message-mode-map>
2742 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2743 C-c C-d Postpone sending the message C-c C-k Kill the message
2744 C-c C-f move to a header field (and create it if there isn't):
2745 C-c C-f C-t move to To C-c C-f C-s move to Subject
2746 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2747 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2748 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2749 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2750 C-c C-f C-o move to From (\"Originator\")
2751 C-c C-f C-f move to Followup-To
2752 C-c C-f C-m move to Mail-Followup-To
2753 C-c C-f C-e move to Expires
2754 C-c C-f C-i cycle through Importance values
2755 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2756 C-c C-f x crossposting with FollowUp-To header and note in body
2757 C-c C-f t replace To: header with contents of Cc: or Bcc:
2758 C-c C-f a Insert X-No-Archive: header and a note in the body
2759 C-c C-t `message-insert-to' (add a To header to a news followup)
2760 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2761 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2762 C-c C-b `message-goto-body' (move to beginning of message text).
2763 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2764 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2765 C-c C-y `message-yank-original' (insert current message, if any).
2766 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2767 C-c C-e `message-elide-region' (elide the text between point and mark).
2768 C-c C-v `message-delete-not-region' (remove the text outside the region).
2769 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2770 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2771 C-c C-a `mml-attach-file' (attach a file as MIME).
2772 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2773 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2774 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2775 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2776 M-RET `message-newline-and-reformat' (break the line and reformat)."
2777 (setq local-abbrev-table text-mode-abbrev-table)
2778 (set (make-local-variable 'message-reply-buffer) nil)
2779 (set (make-local-variable 'message-inserted-headers) nil)
2780 (set (make-local-variable 'message-send-actions) nil)
2781 (set (make-local-variable 'message-exit-actions) nil)
2782 (set (make-local-variable 'message-kill-actions) nil)
2783 (set (make-local-variable 'message-postpone-actions) nil)
2784 (set (make-local-variable 'message-draft-article) nil)
2785 (setq buffer-offer-save t)
2786 (set (make-local-variable 'facemenu-add-face-function)
2788 (let ((face-fun (cdr (assq face message-face-alist))))
2790 (funcall face-fun (point) end)
2791 (error "Face %s not configured for %s mode" face mode-name)))
2793 (set (make-local-variable 'facemenu-remove-face-function) t)
2794 (set (make-local-variable 'message-reply-headers) nil)
2795 (make-local-variable 'message-newsreader)
2796 (make-local-variable 'message-mailer)
2797 (make-local-variable 'message-post-method)
2798 (set (make-local-variable 'message-sent-message-via) nil)
2799 (set (make-local-variable 'message-checksum) nil)
2800 (set (make-local-variable 'message-mime-part) 0)
2801 (message-setup-fill-variables)
2802 (when message-fill-column
2803 (setq fill-column message-fill-column)
2804 (turn-on-auto-fill))
2805 ;; Allow using comment commands to add/remove quoting.
2806 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2807 (when message-yank-prefix
2808 (set (make-local-variable 'comment-start) message-yank-prefix)
2809 (set (make-local-variable 'comment-start-skip)
2810 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2811 (if (featurep 'xemacs)
2812 (message-setup-toolbar)
2813 (set (make-local-variable 'font-lock-defaults)
2814 '(message-font-lock-keywords t))
2815 (if (boundp 'tool-bar-map)
2816 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2817 (easy-menu-add message-mode-menu message-mode-map)
2818 (easy-menu-add message-mode-field-menu message-mode-map)
2819 (gnus-make-local-hook 'after-change-functions)
2820 ;; Mmmm... Forbidden properties...
2821 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2823 ;; Allow mail alias things.
2825 ((message-mail-alias-type-p 'abbrev)
2826 (if (fboundp 'mail-abbrevs-setup)
2827 (mail-abbrevs-setup)
2828 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2829 (mail-aliases-setup))))
2830 ((message-mail-alias-type-p 'ecomplete)
2832 (unless buffer-file-name
2833 (message-set-auto-save-file-name))
2834 (unless (buffer-base-buffer)
2835 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2836 ;; multibyte is not necessary at all. -- zsh
2837 (mm-enable-multibyte))
2838 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2841 (defun message-setup-fill-variables ()
2842 "Setup message fill variables."
2843 (set (make-local-variable 'fill-paragraph-function)
2844 'message-fill-paragraph)
2845 (make-local-variable 'paragraph-separate)
2846 (make-local-variable 'paragraph-start)
2847 (make-local-variable 'adaptive-fill-regexp)
2848 (unless (boundp 'adaptive-fill-first-line-regexp)
2849 (setq adaptive-fill-first-line-regexp nil))
2850 (make-local-variable 'adaptive-fill-first-line-regexp)
2851 (let ((quote-prefix-regexp
2852 ;; User should change message-cite-prefix-regexp if
2853 ;; message-yank-prefix is set to an abnormal value.
2854 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2855 (setq paragraph-start
2857 (regexp-quote mail-header-separator) "$\\|"
2858 "[ \t]*$\\|" ; blank lines
2859 "-- $\\|" ; signature delimiter
2860 "---+$\\|" ; delimiters for forwarded messages
2861 page-delimiter "$\\|" ; spoiler warnings
2862 ".*wrote:$\\|" ; attribution lines
2863 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2865 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2866 (setq paragraph-separate paragraph-start)
2867 (setq adaptive-fill-regexp
2868 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2869 (setq adaptive-fill-first-line-regexp
2870 (concat quote-prefix-regexp "\\|"
2871 adaptive-fill-first-line-regexp)))
2872 (make-local-variable 'auto-fill-inhibit-regexp)
2873 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2874 (setq auto-fill-inhibit-regexp nil)
2875 (make-local-variable 'normal-auto-fill-function)
2876 (setq normal-auto-fill-function 'message-do-auto-fill)
2877 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2878 ;; In that case, ensure that it uses the right function. The real
2879 ;; solution would be not to use `define-derived-mode', and run
2880 ;; `text-mode-hook' ourself at the end of the mode.
2881 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2882 (when auto-fill-function
2883 (setq auto-fill-function normal-auto-fill-function)))
2888 ;;; Message mode commands
2891 ;;; Movement commands
2893 (defun message-goto-to ()
2894 "Move point to the To header."
2896 (message-position-on-field "To"))
2898 (defun message-goto-from ()
2899 "Move point to the From header."
2901 (message-position-on-field "From"))
2903 (defun message-goto-subject ()
2904 "Move point to the Subject header."
2906 (message-position-on-field "Subject"))
2908 (defun message-goto-cc ()
2909 "Move point to the Cc header."
2911 (message-position-on-field "Cc" "To"))
2913 (defun message-goto-bcc ()
2914 "Move point to the Bcc header."
2916 (message-position-on-field "Bcc" "Cc" "To"))
2918 (defun message-goto-fcc ()
2919 "Move point to the Fcc header."
2921 (message-position-on-field "Fcc" "To" "Newsgroups"))
2923 (defun message-goto-reply-to ()
2924 "Move point to the Reply-To header."
2926 (message-position-on-field "Reply-To" "Subject"))
2928 (defun message-goto-newsgroups ()
2929 "Move point to the Newsgroups header."
2931 (message-position-on-field "Newsgroups"))
2933 (defun message-goto-distribution ()
2934 "Move point to the Distribution header."
2936 (message-position-on-field "Distribution"))
2938 (defun message-goto-followup-to ()
2939 "Move point to the Followup-To header."
2941 (message-position-on-field "Followup-To" "Newsgroups"))
2943 (defun message-goto-mail-followup-to ()
2944 "Move point to the Mail-Followup-To header."
2946 (message-position-on-field "Mail-Followup-To" "To"))
2948 (defun message-goto-keywords ()
2949 "Move point to the Keywords header."
2951 (message-position-on-field "Keywords" "Subject"))
2953 (defun message-goto-summary ()
2954 "Move point to the Summary header."
2956 (message-position-on-field "Summary" "Subject"))
2958 (defun message-goto-body (&optional interactivep)
2959 "Move point to the beginning of the message body."
2960 (interactive (list t))
2961 (when (and interactivep
2962 (looking-at "[ \t]*\n"))
2964 (goto-char (point-min))
2965 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2966 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2968 (defun message-in-body-p ()
2969 "Return t if point is in the message body."
2970 (let ((body (save-excursion (message-goto-body) (point))))
2973 (defun message-goto-eoh ()
2974 "Move point to the end of the headers."
2979 (defun message-goto-signature ()
2980 "Move point to the beginning of the message signature.
2981 If there is no signature in the article, go to the end and
2984 (goto-char (point-min))
2985 (if (re-search-forward message-signature-separator nil t)
2987 (goto-char (point-max))
2990 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2991 "Insert a reasonable MFT header in a post to an unsubscribed list.
2992 When making original posts to a mailing list you are not subscribed to,
2993 you have to type in a MFT header by hand. The contents, usually, are
2994 the addresses of the list and your own address. This function inserts
2995 such a header automatically. It fetches the contents of the To: header
2996 in the current mail buffer, and appends the current `user-mail-address'.
2998 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2999 Cc: header are also put into the MFT."
3004 (message-narrow-to-headers)
3005 (message-remove-header "Mail-Followup-To")
3006 (setq cc (and include-cc (message-fetch-field "Cc")))
3008 (concat (message-fetch-field "To") "," cc)
3009 (message-fetch-field "To"))))
3010 (message-goto-mail-followup-to)
3011 (insert (concat tos ", " user-mail-address))))
3015 (defun message-insert-to (&optional force)
3016 "Insert a To header that points to the author of the article being replied to.
3017 If the original author requested not to be sent mail, don't insert unless the
3018 prefix FORCE is given."
3020 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3021 (dont (and mct (or (equal (downcase mct) "never")
3022 (equal (downcase mct) "nobody"))))
3023 (to (or (message-fetch-reply-field "mail-reply-to")
3024 (message-fetch-reply-field "reply-to")
3025 (message-fetch-reply-field "from"))))
3029 "Ignoring the user request not to have copies sent via mail"
3030 "Complying with the user request not to have copies sent via mail")))
3031 (when (and force (not to))
3032 (error "No mail address in the article"))
3033 (when (and to (or force (not dont)))
3034 (message-carefully-insert-headers (list (cons 'To to))))))
3036 (defun message-insert-wide-reply ()
3037 "Insert To and Cc headers as if you were doing a wide reply."
3039 (let ((headers (message-with-reply-buffer
3040 (message-get-reply-headers t))))
3041 (message-carefully-insert-headers headers)))
3043 (defcustom message-header-synonyms
3046 "List of lists of header synonyms.
3047 E.g., if this list contains a member list with elements `Cc' and `To',
3048 then `message-carefully-insert-headers' will not insert a `To' header
3049 when the message is already `Cc'ed to the recipient."
3051 :group 'message-headers
3052 :link '(custom-manual "(message)Message Headers")
3053 :type '(repeat sexp))
3055 (defun message-carefully-insert-headers (headers)
3056 "Insert the HEADERS, an alist, into the message buffer.
3057 Does not insert the headers when they are already present there
3058 or in the synonym headers, defined by `message-header-synonyms'."
3059 ;; FIXME: Should compare only the address and not the full name. Comparison
3060 ;; should be done case-folded (and with `string=' rather than
3062 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3063 (dolist (header headers)
3064 (let* ((header-name (symbol-name (car header)))
3065 (new-header (cdr header))
3066 (synonyms (loop for synonym in message-header-synonyms
3067 when (memq (car header) synonym) return synonym))
3069 (loop for synonym in synonyms
3070 for old-header = (mail-fetch-field (symbol-name synonym))
3071 when (and old-header (string-match new-header old-header))
3074 (message "already have `%s' in `%s'" new-header old-header)
3075 (when (and (message-position-on-field header-name)
3076 (setq old-header (mail-fetch-field header-name))
3077 (not (string-match "\\` *\\'" old-header)))
3079 (insert new-header)))))
3081 (defun message-widen-reply ()
3082 "Widen the reply to include maximum recipients."
3085 (and message-reply-buffer
3086 (buffer-name message-reply-buffer)
3088 (set-buffer message-reply-buffer)
3089 (message-get-reply-headers t)))))
3092 (message-narrow-to-headers)
3093 (dolist (elem follow-to)
3094 (message-remove-header (symbol-name (car elem)))
3095 (goto-char (point-min))
3096 (insert (symbol-name (car elem)) ": "
3097 (cdr elem) "\n"))))))
3099 (defun message-insert-newsgroups ()
3100 "Insert the Newsgroups header from the article being replied to."
3102 (when (and (message-position-on-field "Newsgroups")
3103 (mail-fetch-field "newsgroups")
3104 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3106 (insert (or (message-fetch-reply-field "newsgroups") "")))
3110 ;;; Various commands
3112 (defun message-delete-not-region (beg end)
3113 "Delete everything in the body of the current message outside of the region."
3118 ;; snarf citation prefix, if appropriate
3119 (unless (eq (point) (progn (beginning-of-line) (point)))
3120 (when (looking-at message-cite-prefix-regexp)
3121 (setq citeprefix (match-string 0))))
3123 (delete-region (point) (if (not (message-goto-signature))
3129 (delete-region beg (progn (message-goto-body)
3133 (insert citeprefix))))
3134 (when (message-goto-signature)
3137 (defun message-kill-to-signature (&optional arg)
3138 "Kill all text up to the signature.
3139 If a numberic argument or prefix arg is given, leave that number
3140 of lines before the signature intact."
3144 (let ((point (point)))
3145 (narrow-to-region point (point-max))
3146 (message-goto-signature)
3148 (if (and arg (numberp arg))
3149 (forward-line (- -1 arg))
3151 (unless (= point (point))
3152 (kill-region point (point))
3156 (defun message-newline-and-reformat (&optional arg not-break)
3157 "Insert four newlines, and then reformat if inside quoted text.
3158 Prefix arg means justify as well."
3159 (interactive (list (if current-prefix-arg 'full)))
3160 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3161 (setq point (point))
3164 (setq bolp (= beg point))
3165 ;; Find first line of the paragraph.
3167 (while (and (not (eobp))
3168 (not (looking-at message-cite-prefix-regexp))
3169 (looking-at paragraph-start))
3172 (when (looking-at message-cite-prefix-regexp)
3173 (setq quoted (match-string 0))
3174 (goto-char (match-end 0))
3175 (looking-at "[ \t]*")
3176 (setq leading-space (match-string 0)))
3180 (< (- point beg) (length quoted)))
3181 ;; break inside the cite prefix.
3187 (while (and (not (eobp))
3188 (not (looking-at paragraph-separate))
3189 (looking-at message-cite-prefix-regexp)
3190 (equal quoted (match-string 0)))
3191 (goto-char (match-end 0))
3192 (looking-at "[ \t]*")
3193 (if (> (length leading-space) (length (match-string 0)))
3194 (setq leading-space (match-string 0)))
3198 (while (and (if (bobp) nil (forward-line -1) t)
3199 (not (looking-at paragraph-start))
3200 (looking-at message-cite-prefix-regexp)
3201 (equal quoted (match-string 0)))
3203 (goto-char (match-end 0))
3204 (looking-at "[ \t]*")
3205 (if (> (length leading-space) (length (match-string 0)))
3206 (setq leading-space (match-string 0)))))
3207 (while (and (not (eobp))
3208 (not (looking-at paragraph-separate))
3209 (not (looking-at message-cite-prefix-regexp)))
3213 (while (and (if (bobp) nil (forward-line -1) t)
3214 (not (looking-at paragraph-start))
3215 (not (looking-at message-cite-prefix-regexp)))
3216 (setq beg (point))))
3219 (narrow-to-region beg end)
3226 (setq point (point))
3227 ;; (newline 2) doesn't mark both newline's as hard, so call
3228 ;; newline twice. -jas
3231 (delete-region (point) (re-search-forward "[ \t]*"))
3232 (when (and quoted (not bolp))
3233 (insert quoted leading-space)))
3236 (let* ((adaptive-fill-regexp
3237 (regexp-quote (concat quoted leading-space)))
3238 (adaptive-fill-first-line-regexp
3239 adaptive-fill-regexp ))
3240 (fill-paragraph arg))
3241 (fill-paragraph arg))
3242 (if point (goto-char point)))))
3244 (defun message-fill-paragraph (&optional arg)
3245 "Message specific function to fill a paragraph.
3246 This function is used as the value of `fill-paragraph-function' in
3247 Message buffers and is not meant to be called directly."
3248 (interactive (list (if current-prefix-arg 'full)))
3249 (if (if (boundp 'filladapt-mode) filladapt-mode)
3251 (if (message-point-in-header-p)
3252 (message-fill-field)
3253 (message-newline-and-reformat arg t))
3256 (defun message-point-in-header-p ()
3257 "Return t if point is in the header."
3259 (not (re-search-backward
3260 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3262 (defun message-do-auto-fill ()
3263 "Like `do-auto-fill', but don't fill in message header."
3264 (unless (message-point-in-header-p)
3267 (defun message-insert-signature (&optional force)
3268 "Insert a signature. See documentation for variable `message-signature'."
3269 (interactive (list 0))
3272 ((and (null message-signature)
3275 (goto-char (point-max))
3276 (not (re-search-backward message-signature-separator nil t))))
3277 ((and (null message-signature)
3280 ((functionp message-signature)
3281 (funcall message-signature))
3282 ((listp message-signature)
3283 (eval message-signature))
3284 (t message-signature)))
3287 (cond ((stringp signature)
3289 ((and (eq t signature) message-signature-file)
3290 (setq signature-file
3291 (if (and message-signature-directory
3292 ;; don't actually use the signature directory
3293 ;; if message-signature-file contains a path.
3294 (not (file-name-directory
3295 message-signature-file)))
3296 (nnheader-concat message-signature-directory
3297 message-signature-file)
3298 message-signature-file))
3299 (file-exists-p signature-file))))
3301 (goto-char (point-max))
3302 ;; Insert the signature.
3305 (when message-signature-insert-empty-line
3308 (if (eq signature t)
3309 (insert-file-contents signature-file)
3311 (goto-char (point-max))
3312 (or (bolp) (insert "\n")))))
3314 (defun message-insert-importance-high ()
3315 "Insert header to mark message as important."
3319 (message-narrow-to-headers)
3320 (message-remove-header "Importance"))
3322 (insert "Importance: high\n")))
3324 (defun message-insert-importance-low ()
3325 "Insert header to mark message as unimportant."
3329 (message-narrow-to-headers)
3330 (message-remove-header "Importance"))
3332 (insert "Importance: low\n")))
3334 (defun message-insert-or-toggle-importance ()
3335 "Insert a \"Importance: high\" header, or cycle through the header values.
3336 The three allowed values according to RFC 1327 are `high', `normal'
3340 (let ((valid '("high" "normal" "low"))
3344 (message-narrow-to-headers)
3345 (when (setq cur (message-fetch-field "Importance"))
3346 (message-remove-header "Importance")
3347 (setq new (cond ((string= cur "high")
3349 ((string= cur "low")
3354 (insert (format "Importance: %s\n" new)))))
3356 (defun message-insert-disposition-notification-to ()
3357 "Request a disposition notification (return receipt) to this message.
3358 Note that this should not be used in newsgroups."
3362 (message-narrow-to-headers)
3363 (message-remove-header "Disposition-Notification-To"))
3365 (insert (format "Disposition-Notification-To: %s\n"
3366 (or (message-field-value "Reply-to")
3367 (message-field-value "From")
3368 (message-make-from))))))
3370 (defun message-elide-region (b e)
3371 "Elide the text in the region.
3372 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3376 (insert message-elide-ellipsis))
3378 (defvar message-caesar-translation-table nil)
3380 (defun message-caesar-region (b e &optional n)
3381 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3384 (min (point) (or (mark t) (point)))
3385 (max (point) (or (mark t) (point)))
3386 (when current-prefix-arg
3387 (prefix-numeric-value current-prefix-arg))))
3389 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3390 (unless (or (zerop n) ; no action needed for a rot of 0
3391 (= b e)) ; no region to rotate
3392 ;; We build the table, if necessary.
3393 (when (or (not message-caesar-translation-table)
3394 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3395 (setq message-caesar-translation-table
3396 (message-make-caesar-translation-table n)))
3397 (translate-region b e message-caesar-translation-table)))
3399 (defun message-make-caesar-translation-table (n)
3400 "Create a rot table with offset N."
3402 (table (make-string 256 0)))
3403 (while (< (incf i) 256)
3406 (substring table 0 ?A)
3407 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3408 (substring table ?A (+ ?A n))
3409 (substring table (+ ?A 26) ?a)
3410 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3411 (substring table ?a (+ ?a n))
3412 (substring table (+ ?a 26) 255))))
3414 (defun message-caesar-buffer-body (&optional rotnum wide)
3415 "Caesar rotate all letters in the current buffer by 13 places.
3416 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3417 With prefix arg, specifies the number of places to rotate each letter forward.
3418 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3419 (interactive (if current-prefix-arg
3420 (list (prefix-numeric-value current-prefix-arg))
3424 (when (and (not wide) (message-goto-body))
3425 (narrow-to-region (point) (point-max)))
3426 (message-caesar-region (point-min) (point-max) rotnum))))
3428 (defun message-pipe-buffer-body (program)
3429 "Pipe the message body in the current buffer through PROGRAM."
3432 (when (message-goto-body)
3433 (narrow-to-region (point) (point-max)))
3434 (shell-command-on-region
3435 (point-min) (point-max) program nil t))))
3437 (defun message-rename-buffer (&optional enter-string)
3438 "Rename the *message* buffer to \"*message* RECIPIENT\".
3439 If the function is run with a prefix, it will ask for a new buffer
3440 name, rather than giving an automatic name."
3441 (interactive "Pbuffer name: ")
3444 (goto-char (point-min))
3445 (narrow-to-region (point)
3446 (search-forward mail-header-separator nil 'end))
3448 (if (message-news-p) (message-fetch-field "Newsgroups")
3449 (message-fetch-field "To"))
3452 (if (string-match "," mail-to)
3453 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3455 (name-default (concat "*message* " mail-trimmed-to))
3456 (name (if enter-string
3457 (read-string "New buffer name: " name-default)
3459 (rename-buffer name t)))))
3461 (defun message-fill-yanked-message (&optional justifyp)
3462 "Fill the paragraphs of a message yanked into this one.
3463 Numeric argument means justify as well."
3466 (goto-char (point-min))
3467 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3468 (let ((fill-prefix message-yank-prefix))
3469 (fill-individual-paragraphs (point) (point-max) justifyp))))
3471 (defun message-indent-citation (&optional start end yank-only)
3472 "Modify text just inserted from a message to be cited.
3473 The inserted text should be the region.
3474 When this function returns, the region is again around the modified text.
3476 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3477 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3478 (unless start (setq start (point)))
3480 ;; Remove unwanted headers.
3481 (when message-ignored-cited-headers
3486 (if (search-forward "\n\n" nil t)
3489 (message-remove-header message-ignored-cited-headers t)
3490 (when (= (point-min) (point-max))
3491 (setq all-removed t))
3492 (goto-char (point-max)))
3496 ;; Delete blank lines at the start of the buffer.
3497 (while (and (point-min)
3500 (message-delete-line))
3501 ;; Delete blank lines at the end of the buffer.
3502 (goto-char (point-max))
3505 (while (and (zerop (forward-line -1))
3507 (message-delete-line)))
3508 ;; Do the indentation.
3509 (if (null message-yank-prefix)
3510 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3513 (while (< (point) (or end (mark t)))
3514 (cond ((looking-at ">")
3515 (insert message-yank-cited-prefix))
3517 (insert message-yank-empty-prefix))
3519 (insert message-yank-prefix)))
3523 (defvar message-cite-reply-above nil
3524 "If non-nil, start own text above the quote.
3526 Note: Top posting is bad netiquette. Don't use it unless you
3527 really must. You probably want to set variable only for specific
3528 groups, e.g. using `gnus-posting-styles':
3530 (eval (set (make-local-variable 'message-cite-reply-above) t))
3532 This variable has no effect in news postings.")
3534 (defun message-yank-original (&optional arg)
3535 "Insert the message being replied to, if any.
3536 Puts point before the text and mark after.
3537 Normally indents each nonblank line ARG spaces (default 3). However,
3538 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3540 This function uses `message-cite-function' to do the actual citing.
3542 Just \\[universal-argument] as argument means don't indent, insert no
3543 prefix, and don't delete any headers."
3545 (let ((modified (buffer-modified-p))
3547 (when (and message-reply-buffer
3548 message-cite-function)
3549 (when message-cite-reply-above
3550 (if (and (not (message-news-p))
3551 (or (eq message-cite-reply-above 'is-evil)
3553 Top posting is bad netiquette. Please don't top post unless you really must.
3554 Really top post? ")))
3557 (buffer-substring (message-goto-body)
3559 (delete-region (message-goto-body) (point-max)))
3560 (set (make-local-variable 'message-cite-reply-above) nil)))
3561 (delete-windows-on message-reply-buffer t)
3562 (push-mark (save-excursion
3563 (insert-buffer-substring message-reply-buffer)
3568 (funcall message-cite-function)
3569 (unless (eq (char-before (mark t)) ?\n)
3571 (goto-char (mark t))
3572 (insert-before-markers ?\n)
3574 (when message-cite-reply-above
3577 (insert (if (bolp) "\n" "\n\n"))
3578 (message-goto-body))
3579 ;; Add a `message-setup-very-last-hook' here?
3580 ;; Add `gnus-article-highlight-citation' here?
3582 (setq message-checksum (message-checksum))))))
3584 (defun message-yank-buffer (buffer)
3585 "Insert BUFFER into the current buffer and quote it."
3586 (interactive "bYank buffer: ")
3587 (let ((message-reply-buffer (get-buffer buffer)))
3588 (save-window-excursion
3589 (message-yank-original))))
3591 (defun message-buffers ()
3592 "Return a list of active message buffers."
3595 (dolist (buffer (buffer-list t))
3597 (when (and (eq major-mode 'message-mode)
3598 (null message-sent-message-via))
3599 (push (buffer-name buffer) buffers))))
3600 (nreverse buffers)))
3602 (eval-when-compile (defvar mail-citation-hook)) ; Compiler directive
3604 (defun message-cite-original-1 (strip-signature)
3605 "Cite an original message.
3606 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3609 This function uses `mail-citation-hook' if that is non-nil."
3610 (if (and (boundp 'mail-citation-hook)
3612 (run-hooks 'mail-citation-hook)
3613 (let* ((start (point))
3617 (when message-indent-citation-function
3618 (if (listp message-indent-citation-function)
3619 message-indent-citation-function
3620 (list message-indent-citation-function))))
3621 ;; This function may be called by `gnus-summary-yank-message' and
3622 ;; may insert a different article from the original. So, we will
3623 ;; modify the value of `message-reply-headers' with that article.
3624 (message-reply-headers
3626 (narrow-to-region start end)
3627 (message-narrow-to-head-1)
3628 (setq x-no-archive (message-fetch-field "x-no-archive"))
3630 (or (message-fetch-field "subject") "none")
3631 (or (message-fetch-field "from") "nobody")
3632 (message-fetch-field "date")
3633 (message-fetch-field "message-id" t)
3634 (message-fetch-field "references")
3636 (mml-quote-region start end)
3637 (when strip-signature
3641 (when (re-search-backward message-signature-separator start t)
3642 ;; Also peel off any blank lines before the signature.
3644 (while (looking-at "^[ \t]*$")
3647 (delete-region (point) end)
3648 (unless (search-backward "\n\n" start t)
3649 ;; Insert a blank line if it is peeled off.
3652 (mapc 'funcall functions)
3653 (when message-citation-line-function
3656 (funcall message-citation-line-function))
3657 (when (and x-no-archive
3658 (not message-cite-articles-with-x-no-archive)
3659 (string-match "yes" x-no-archive))
3661 (delete-region (point) (mark t))
3662 (insert "> [Quoted text removed due to X-No-Archive]\n")
3664 (forward-line -1)))))
3666 (defun message-cite-original ()
3667 "Cite function in the standard Message manner."
3668 (message-cite-original-1 nil))
3670 (defun message-insert-formated-citation-line (&optional from date)
3671 "Function that inserts a formated citation line.
3673 See `message-citation-line-format'."
3674 ;; The optional args are for testing/debugging. They will disappear later.
3676 ;; (with-temp-buffer
3677 ;; (message-insert-formated-citation-line
3678 ;; "John Doe <john.doe@example.invalid>"
3681 (when (or message-reply-headers (and from date))
3683 (setq from (mail-header-from message-reply-headers)))
3684 (let* ((data (condition-case ()
3685 (funcall (if (boundp gnus-extract-address-components)
3686 gnus-extract-address-components
3687 'mail-extract-address-components)
3693 (net (car (cdr data)))
3694 (name-or-net (or (car data)
3695 (car (cdr data)) from))
3699 ;; We need Gnus functionality if the user wants date or time from
3700 ;; the original article:
3701 (when (string-match "%[^fnNFL]" message-citation-line-format)
3702 (autoload 'gnus-date-get-time "gnus-util")
3703 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3706 (when (stringp name)
3707 ;; Guess first name and last name:
3708 (cond ((string-match
3709 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3710 (setq fname (nth 0 (split-string name "[ \t]+"))
3711 lname (nth 1 (split-string name "[ \t]+"))))
3713 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3714 (setq fname (nth 1 (split-string name "[ \t,]+"))
3715 lname (nth 0 (split-string name "[ \t,]+"))))
3717 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3720 ;; The following letters are not used in `format-time-string':
3721 (push ?E lst) (push "<E>" lst)
3722 (push ?F lst) (push fname lst)
3723 ;; We might want to use "" instead of "<X>" later.
3724 (push ?J lst) (push "<J>" lst)
3725 (push ?K lst) (push "<K>" lst)
3726 (push ?L lst) (push lname lst)
3727 (push ?N lst) (push name-or-net lst)
3728 (push ?O lst) (push "<O>" lst)
3729 (push ?P lst) (push "<P>" lst)
3730 (push ?Q lst) (push "<Q>" lst)
3731 (push ?f lst) (push from lst)
3732 (push ?i lst) (push "<i>" lst)
3733 (push ?n lst) (push net lst)
3734 (push ?o lst) (push "<o>" lst)
3735 (push ?q lst) (push "<q>" lst)
3736 (push ?t lst) (push "<t>" lst)
3737 (push ?v lst) (push "<v>" lst)
3738 ;; Delegate the rest to `format-time-string':
3740 (when (and (not (memq i lst))
3745 (push (condition-case nil
3746 (progn (format-time-string (format "%%%c" i)
3752 (spec (apply 'format-spec-make flist)))
3753 (insert (format-spec message-citation-line-format spec)))
3757 (defun message-cite-original-without-signature ()
3758 "Cite function in the standard Message manner.
3759 This function strips off the signature from the original message."
3760 (message-cite-original-1 t))
3762 (defun message-insert-citation-line ()
3763 "Insert a simple citation line."
3764 (when message-reply-headers
3765 (insert (mail-header-from message-reply-headers) " writes:")
3769 (defun message-position-on-field (header &rest afters)
3770 (let ((case-fold-search t))
3773 (goto-char (point-min))
3776 (concat "^" (regexp-quote mail-header-separator) "$"))
3777 (match-beginning 0)))
3778 (goto-char (point-min))
3779 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3781 (re-search-forward "^[^ \t]" nil 'move)
3783 (skip-chars-backward "\n")
3786 (not (re-search-forward
3787 (concat "^" (regexp-quote (car afters)) ":")
3791 (re-search-forward "^[^ \t]" nil 'move)
3792 (beginning-of-line))
3793 (insert header ": \n")
3797 (defun message-remove-signature ()
3798 "Remove the signature from the text between point and mark.
3799 The text will also be indented the normal way."
3801 (let ((start (point))
3803 (if (not (re-search-forward message-signature-separator (mark t) t))
3804 ;; No signature here, so we just indent the cited text.
3805 (message-indent-citation)
3806 ;; Find the last non-empty line.
3808 (while (looking-at "[ \t]*$")
3811 (setq mark (set-marker (make-marker) (point)))
3813 (message-indent-citation)
3814 ;; Enable undoing the deletion.
3816 (delete-region mark (mark t))
3817 (set-marker mark nil)))))
3822 ;;; Sending messages
3825 (defun message-send-and-exit (&optional arg)
3826 "Send message like `message-send', then, if no errors, exit from mail buffer."
3828 (let ((buf (current-buffer))
3829 (actions message-exit-actions))
3830 (when (and (message-send arg)
3832 (if message-kill-buffer-on-exit
3835 (when (eq buf (current-buffer))
3836 (message-bury buf)))
3837 (message-do-actions actions)
3840 (defun message-dont-send ()
3841 "Don't send the message you have been editing.
3842 Instead, just auto-save the buffer and then bury it."
3844 (set-buffer-modified-p t)
3846 (let ((actions message-postpone-actions))
3847 (message-bury (current-buffer))
3848 (message-do-actions actions)))
3850 (defun message-kill-buffer ()
3851 "Kill the current buffer."
3853 (when (or (not (buffer-modified-p))
3854 (not message-kill-buffer-query)
3855 (yes-or-no-p "Message modified; kill anyway? "))
3856 (let ((actions message-kill-actions)
3857 (draft-article message-draft-article)
3858 (auto-save-file-name buffer-auto-save-file-name)
3859 (file-name buffer-file-name)
3860 (modified (buffer-modified-p)))
3861 (setq buffer-file-name nil)
3862 (kill-buffer (current-buffer))
3863 (when (and (or (and auto-save-file-name
3864 (file-exists-p auto-save-file-name))
3866 (file-exists-p file-name)))
3868 ;; If the message buffer has lived in a dedicated window,
3869 ;; `kill-buffer' has killed the frame. Thus the
3870 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3871 ;; that the user can see the question by raising the
3874 (yes-or-no-p (format "Remove the backup file%s? "
3875 (if modified " too" "")))))
3877 (delete-file auto-save-file-name))
3878 (let ((message-draft-article draft-article))
3879 (message-disassociate-draft)))
3880 (message-do-actions actions))))
3882 (defun message-bury (buffer)
3883 "Bury this mail BUFFER."
3884 (let ((newbuf (other-buffer buffer)))
3885 (bury-buffer buffer)
3886 (if (and (window-dedicated-p (selected-window))
3887 (not (null (delq (selected-frame) (visible-frame-list)))))
3888 (delete-frame (selected-frame))
3889 (switch-to-buffer newbuf))))
3891 (defun message-send (&optional arg)
3892 "Send the message in the current buffer.
3893 If `message-interactive' is non-nil, wait for success indication or
3894 error messages, and inform user.
3895 Otherwise any failure is reported in a message back to the user from
3897 The usage of ARG is defined by the instance that called Message.
3898 It should typically alter the sending method in some way or other."
3900 ;; Make it possible to undo the coming changes.
3902 (let ((inhibit-read-only t))
3903 (put-text-property (point-min) (point-max) 'read-only nil))
3904 (message-fix-before-sending)
3905 (run-hooks 'message-send-hook)
3906 (message message-sending-message)
3907 (let ((alist message-send-method-alist)
3909 elem sent dont-barf-on-no-method
3910 (message-options message-options))
3911 (message-options-set-recipient)
3913 (setq elem (pop alist)))
3914 (when (funcall (cadr elem))
3915 (when (and (or (not (memq (car elem)
3916 message-sent-message-via))
3917 (message-fetch-field "supersedes")
3918 (if (or (message-gnksa-enable-p 'multiple-copies)
3919 (not (eq (car elem) 'news)))
3922 "Already sent message via %s; resend? "
3924 (error "Denied posting -- multiple copies")))
3925 (setq success (funcall (caddr elem) arg)))
3929 (let ((fcc (message-fetch-field "Fcc"))
3930 (gcc (message-fetch-field "Gcc")))
3932 (or (eq message-allow-no-recipients 'always)
3933 (and (not (eq message-allow-no-recipients 'never))
3934 (setq dont-barf-on-no-method
3936 (format "No receiver, perform %s anyway? "
3937 (cond ((and fcc gcc) "Fcc and Gcc")
3940 (error "No methods specified to send by"))
3941 (when (or dont-barf-on-no-method
3945 (run-hooks 'message-sent-hook))
3946 (message "Sending...done")
3947 ;; Do ecomplete address snarfing.
3948 (when (message-mail-alias-type-p 'ecomplete)
3949 (message-put-addresses-in-ecomplete))
3950 ;; Mark the buffer as unmodified and delete auto-save.
3951 (set-buffer-modified-p nil)
3952 (delete-auto-save-file-if-necessary t)
3953 (message-disassociate-draft)
3954 ;; Delete other mail buffers and stuff.
3955 (message-do-send-housekeeping)
3956 (message-do-actions message-send-actions)
3960 (defun message-send-via-mail (arg)
3961 "Send the current message via mail."
3962 (message-send-mail arg))
3964 (defun message-send-via-news (arg)
3965 "Send the current message via news."
3966 (funcall message-send-news-function arg))
3968 (defmacro message-check (type &rest forms)
3969 "Eval FORMS if TYPE is to be checked."
3970 `(or (message-check-element ,type)
3974 (put 'message-check 'lisp-indent-function 1)
3975 (put 'message-check 'edebug-form-spec '(form body))
3977 (defun message-text-with-property (prop &optional start end reverse)
3978 "Return a list of start and end positions where the text has PROP.
3979 START and END bound the search, they default to `point-min' and
3980 `point-max' respectively. If REVERSE is non-nil, find text which does
3983 (setq start (point-min)))
3985 (setq end (point-max)))
3989 (setq start (text-property-any start end prop nil)))
3990 (setq next (next-single-property-change start prop nil end))
3991 (push (cons start (or next end)) regions)
3994 (or (get-text-property start prop)
3995 (and (setq start (next-single-property-change
3996 start prop nil end))
3997 (get-text-property start prop))))
3998 (setq next (text-property-any start end prop nil))
3999 (push (cons start (or next end)) regions)
4001 (nreverse regions)))
4003 (defun message-fix-before-sending ()
4004 "Do various things to make the message nice before sending it."
4005 ;; Make sure there's a newline at the end of the message.
4006 (goto-char (point-max))
4009 ;; Make the hidden headers visible.
4011 ;; Sort headers before sending the message.
4012 (message-sort-headers)
4013 ;; Make invisible text visible.
4014 ;; It doesn't seem as if this is useful, since the invisible property
4015 ;; is clobbered by an after-change hook anyhow.
4016 (message-check 'invisible-text
4017 (let ((regions (message-text-with-property 'invisible))
4021 (setq from (caar regions)
4023 regions (cdr regions))
4024 (put-text-property from to 'invisible nil)
4025 (message-overlay-put (message-make-overlay from to)
4027 (unless (yes-or-no-p
4028 "Invisible text found and made visible; continue sending? ")
4029 (error "Invisible text found and made visible")))))
4030 (message-check 'illegible-text
4033 (skip-chars-forward mm-7bit-chars)
4035 (when (let ((char (char-after)))
4036 (or (< (mm-char-int char) 128)
4037 (and (mm-multibyte-p)
4038 (memq (char-charset char)
4039 '(eight-bit-control eight-bit-graphic
4041 (not (get-text-property
4042 (point) 'untranslated-utf-8)))))
4043 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4047 (skip-chars-forward mm-7bit-chars))
4050 (gnus-multiple-choice
4051 "Non-printable characters found. Continue sending?"
4052 `((?d "Remove non-printable characters and send")
4054 "Replace non-printable characters with \"%s\" and send"
4055 message-replacement-char))
4056 (?i "Ignore non-printable characters and send")
4057 (?e "Continue editing"))))
4059 (error "Non-printable characters"))
4061 (skip-chars-forward mm-7bit-chars)
4063 (when (let ((char (char-after)))
4064 (or (< (mm-char-int char) 128)
4065 (and (mm-multibyte-p)
4066 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4067 ;; things like undecable utf-8. Should at least
4068 ;; use find-coding-systems-region.
4069 (memq (char-charset char)
4070 '(eight-bit-control eight-bit-graphic
4072 (not (get-text-property
4073 (point) 'untranslated-utf-8)))))
4075 (message-kill-all-overlays)
4077 (when (eq choice ?r)
4078 (insert message-replacement-char))))
4080 (skip-chars-forward mm-7bit-chars))))))
4082 (defun message-add-action (action &rest types)
4083 "Add ACTION to be performed when doing an exit of type TYPES."
4085 (add-to-list (intern (format "message-%s-actions" (pop types)))
4088 (defun message-delete-action (action &rest types)
4089 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4092 (set (setq var (intern (format "message-%s-actions" (pop types))))
4093 (delq action (symbol-value var))))))
4095 (defun message-do-actions (actions)
4096 "Perform all actions in ACTIONS."
4097 ;; Now perform actions on successful sending.
4098 (dolist (action actions)
4101 ;; A simple function.
4104 ;; Something to be evaled.
4108 (defun message-send-mail-partially ()
4109 "Send mail as message/partial."
4110 ;; replace the header delimiter with a blank line
4111 (goto-char (point-min))
4113 (concat "^" (regexp-quote mail-header-separator) "\n"))
4114 (replace-match "\n")
4115 (run-hooks 'message-send-mail-hook)
4116 (let ((p (goto-char (point-min)))
4117 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4118 (curbuf (current-buffer))
4119 (id (message-make-message-id)) (n 1)
4120 plist total header required-mail-headers)
4122 (if (< (point-max) (+ p message-send-mail-partially-limit))
4123 (goto-char (point-max))
4124 (goto-char (+ p message-send-mail-partially-limit))
4126 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4129 (setq total (length plist))
4130 (push (point-max) plist)
4131 (setq plist (nreverse plist))
4134 (setq p (pop plist))
4137 (copy-to-buffer tembuf p (car plist))
4139 (goto-char (point-min))
4142 (goto-char (point-min))
4143 (narrow-to-region (point) (point))
4146 (setq header (buffer-substring (point-min) (point)))
4147 (goto-char (point-min))
4148 (narrow-to-region (point) (point))
4150 (message-remove-header "Mime-Version")
4151 (message-remove-header "Content-Type")
4152 (message-remove-header "Content-Transfer-Encoding")
4153 (message-remove-header "Message-ID")
4154 (message-remove-header "Lines")
4155 (goto-char (point-max))
4156 (insert "Mime-Version: 1.0\n")
4157 (setq header (buffer-string)))
4158 (goto-char (point-max))
4159 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4162 (let ((mail-header-separator ""))
4163 (when (memq 'Message-ID message-required-mail-headers)
4164 (insert "Message-ID: " (message-make-message-id) "\n"))
4165 (when (memq 'Lines message-required-mail-headers)
4166 (insert "Lines: " (message-make-lines) "\n"))
4167 (message-goto-subject)
4169 (insert (format " (%d/%d)" n total))
4171 (mm-with-unibyte-current-buffer
4172 (funcall (or message-send-mail-real-function
4173 message-send-mail-function))))
4175 (setq p (pop plist))
4177 (kill-buffer tembuf))))
4179 (defun message-send-mail (&optional arg)
4180 (require 'mail-utils)
4181 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4182 (case-fold-search nil)
4183 (news (message-news-p))
4184 (mailbuf (current-buffer))
4185 (message-this-is-mail t)
4186 (message-posting-charset
4187 (if (fboundp 'gnus-setup-posting-charset)
4188 (gnus-setup-posting-charset nil)
4189 message-posting-charset))
4190 (headers message-required-mail-headers))
4191 (when (and message-generate-hashcash
4192 (not (eq message-generate-hashcash 'opportunistic)))
4193 (message "Generating hashcash...")
4194 ;; Wait for calculations already started to finish...
4195 (hashcash-wait-async)
4196 ;; ...and do calculations not already done. mail-add-payment
4197 ;; will leave existing X-Hashcash headers alone.
4199 (message "Generating hashcash...done"))
4201 (message-narrow-to-headers)
4202 ;; Generate the Mail-Followup-To header if the header is not there...
4203 (if (and (message-subscribed-p)
4204 (not (mail-fetch-field "mail-followup-to")))
4207 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4208 message-required-mail-headers))
4209 ;; otherwise, delete the MFT header if the field is empty
4210 (when (equal "" (mail-fetch-field "mail-followup-to"))
4211 (message-remove-header "^Mail-Followup-To:")))
4212 ;; Insert some headers.
4213 (let ((message-deletable-headers
4214 (if news nil message-deletable-headers)))
4215 (message-generate-headers headers))
4216 ;; Check continuation headers.
4217 (message-check 'continuation-headers
4218 (goto-char (point-min))
4219 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4220 (goto-char (match-beginning 0))
4221 (if (y-or-n-p "Fix continuation lines? ")
4224 (unless (y-or-n-p "Send anyway? ")
4225 (error "Failed to send the message")))))
4226 ;; Let the user do all of the above.
4227 (run-hooks 'message-header-hook))
4232 ;; Avoid copying text props (except hard newlines).
4233 (insert (with-current-buffer mailbuf
4234 (mml-buffer-substring-no-properties-except-hard-newlines
4235 (point-min) (point-max))))
4236 ;; Remove some headers.
4237 (message-encode-message-body)
4239 (message-narrow-to-headers)
4240 ;; We (re)generate the Lines header.
4241 (when (memq 'Lines message-required-mail-headers)
4242 (message-generate-headers '(Lines)))
4243 ;; Remove some headers.
4244 (message-remove-header message-ignored-mail-headers t)
4245 (let ((mail-parse-charset message-default-charset))
4246 (mail-encode-encoded-word-buffer)))
4247 (goto-char (point-max))
4248 ;; require one newline at the end.
4249 (or (= (preceding-char) ?\n)
4251 (message-cleanup-headers)
4252 ;; FIXME: we're inserting the courtesy copy after encoding.
4253 ;; This is wrong if the courtesy copy string contains
4254 ;; non-ASCII characters. -- jh
4257 (message-narrow-to-headers)
4259 (or (message-fetch-field "cc")
4260 (message-fetch-field "bcc")
4261 (message-fetch-field "to"))
4262 (let ((content-type (message-fetch-field
4267 (string= "text/plain"
4269 (mail-header-parse-content-type
4273 (message-fetch-field
4274 "content-transfer-encoding")))))))
4275 (message-insert-courtesy-copy))
4276 (if (or (not message-send-mail-partially-limit)
4277 (< (buffer-size) message-send-mail-partially-limit)
4278 (not (message-y-or-n-p
4279 "The message size is too large, split? "
4283 (/ (buffer-size) 1000) "KB, is too large.
4285 Some mail gateways (MTA's) bounce large messages. To avoid the
4286 problem, answer `y', and the message will be split into several
4287 smaller pieces, the size of each is about "
4288 (/ message-send-mail-partially-limit 1000)
4292 However, some mail readers (MUA's) can't read split messages, i.e.,
4293 mails in message/partially format. Answer `n', and the message will be
4296 The size limit is controlled by `message-send-mail-partially-limit'.
4297 If you always want Gnus to send messages in one piece, set
4298 `message-send-mail-partially-limit' to nil.
4300 (mm-with-unibyte-current-buffer
4301 (message "Sending via mail...")
4302 (funcall (or message-send-mail-real-function
4303 message-send-mail-function)))
4304 (message-send-mail-partially)))
4305 (kill-buffer tembuf))
4306 (set-buffer mailbuf)
4307 (push 'mail message-sent-message-via)))
4309 (defun message-send-mail-with-sendmail ()
4310 "Send off the prepared buffer with sendmail."
4311 (let ((errbuf (if message-interactive
4312 (message-generate-new-buffer-clone-locals
4315 resend-to-addresses delimline)
4318 (let ((case-fold-search t))
4320 (message-narrow-to-headers)
4321 (setq resend-to-addresses (message-fetch-field "resent-to")))
4322 ;; Change header-delimiter to be what sendmail expects.
4323 (goto-char (point-min))
4325 (concat "^" (regexp-quote mail-header-separator) "\n"))
4326 (replace-match "\n")
4328 (setq delimline (point-marker))
4329 (run-hooks 'message-send-mail-hook)
4330 ;; Insert an extra newline if we need it to work around
4331 ;; Sun's bug that swallows newlines.
4332 (goto-char (1+ delimline))
4333 (when (eval message-mailer-swallows-blank-line)
4335 (when message-interactive
4336 (with-current-buffer errbuf
4338 (let* ((default-directory "/")
4339 (coding-system-for-write message-send-coding-system)
4341 'call-process-region
4343 (list (point-min) (point-max)
4344 (cond ((boundp 'sendmail-program)
4346 ((file-exists-p "/usr/sbin/sendmail")
4347 "/usr/sbin/sendmail")
4348 ((file-exists-p "/usr/lib/sendmail")
4349 "/usr/lib/sendmail")
4350 ((file-exists-p "/usr/ucblib/sendmail")
4351 "/usr/ucblib/sendmail")
4353 nil errbuf nil "-oi")
4354 message-sendmail-extra-arguments
4355 ;; Always specify who from,
4356 ;; since some systems have broken sendmails.
4357 ;; But some systems are more broken with -f, so
4358 ;; we'll let users override this.
4359 (if (null message-sendmail-f-is-evil)
4360 (list "-f" (message-sendmail-envelope-from)))
4361 ;; These mean "report errors by mail"
4362 ;; and "deliver in background".
4363 (if (null message-interactive) '("-oem" "-odb"))
4364 ;; Get the addresses from the message
4365 ;; unless this is a resend.
4366 ;; We must not do that for a resend
4367 ;; because we would find the original addresses.
4368 ;; For a resend, include the specific addresses.
4369 (if resend-to-addresses
4370 (list resend-to-addresses)
4372 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4373 (error "Sending...failed with exit value %d" cpr)))
4374 (when message-interactive
4377 (goto-char (point-min))
4378 (while (re-search-forward "\n+ *" nil t)
4379 (replace-match "; "))
4380 (if (not (zerop (buffer-size)))
4381 (error "Sending...failed to %s"
4382 (buffer-string))))))
4383 (when (bufferp errbuf)
4384 (kill-buffer errbuf)))))
4386 (defun message-send-mail-with-qmail ()
4387 "Pass the prepared message buffer to qmail-inject.
4388 Refer to the documentation for the variable `message-send-mail-function'
4389 to find out how to use this."
4390 ;; replace the header delimiter with a blank line
4391 (goto-char (point-min))
4393 (concat "^" (regexp-quote mail-header-separator) "\n"))
4394 (replace-match "\n")
4395 (run-hooks 'message-send-mail-hook)
4398 (let ((coding-system-for-write message-send-coding-system))
4400 'call-process-region (point-min) (point-max)
4401 message-qmail-inject-program nil nil nil
4402 ;; qmail-inject's default behaviour is to look for addresses on the
4403 ;; command line; if there're none, it scans the headers.
4404 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4406 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4407 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4408 ;; message from stdin.
4410 ;; qmail also has the advantage of not having been raped by
4411 ;; various vendors, so we don't have to allow for that, either --
4412 ;; compare this with message-send-mail-with-sendmail and weep
4413 ;; for sendmail's lost innocence.
4415 ;; all this is way cool coz it lets us keep the arguments entirely
4416 ;; free for -inject-arguments -- a big win for the user and for us
4417 ;; since we don't have to play that double-guessing game and the user
4418 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4419 (if (functionp message-qmail-inject-args)
4420 (funcall message-qmail-inject-args)
4421 message-qmail-inject-args)))
4422 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4423 ;; we have to look at the retval instead
4425 (100 (error "qmail-inject reported permanent failure"))
4426 (111 (error "qmail-inject reported transient failure"))
4427 ;; should never happen
4428 (t (error "qmail-inject reported unknown failure"))))
4430 (defun message-send-mail-with-mh ()
4431 "Send the prepared message buffer with mh."
4432 (let ((mh-previous-window-config nil)
4433 (name (mh-new-draft-name)))
4434 (setq buffer-file-name name)
4435 ;; MH wants to generate these headers itself.
4436 (when message-mh-deletable-headers
4437 (let ((headers message-mh-deletable-headers))
4439 (goto-char (point-min))
4440 (and (re-search-forward
4441 (concat "^" (symbol-name (car headers)) ": *") nil t)
4442 (message-delete-line))
4444 (run-hooks 'message-send-mail-hook)
4445 ;; Pass it on to mh.
4448 (defun message-smtpmail-send-it ()
4449 "Send the prepared message buffer with `smtpmail-send-it'.
4450 This only differs from `smtpmail-send-it' that this command evaluates
4451 `message-send-mail-hook' just before sending a message. It is useful
4452 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4453 manual for details."
4454 (run-hooks 'message-send-mail-hook)
4457 (defun message-canlock-generate ()
4458 "Return a string that is non-trivial to guess.
4459 Do not use this for anything important, it is cryptographically weak."
4461 (let (sha1-maximum-internal-length)
4462 (sha1 (concat (message-unique-id)
4463 (format "%x%x%x" (random) (random t) (random))
4464 (prin1-to-string (recent-keys))
4465 (prin1-to-string (garbage-collect))))))
4467 (defun message-canlock-password ()
4468 "The password used by message for cancel locks.
4469 This is the value of `canlock-password', if that option is non-nil.
4470 Otherwise, generate and save a value for `canlock-password' first."
4471 (unless canlock-password
4472 (customize-save-variable 'canlock-password (message-canlock-generate))
4473 (setq canlock-password-for-verify canlock-password))
4476 (defun message-insert-canlock ()
4477 (when message-insert-canlock
4478 (message-canlock-password)
4479 (canlock-insert-header)))
4481 (defun message-send-news (&optional arg)
4482 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4483 (case-fold-search nil)
4484 (method (if (functionp message-post-method)
4485 (funcall message-post-method arg)
4486 message-post-method))
4487 (newsgroups-field (save-restriction
4488 (message-narrow-to-headers-or-head)
4489 (message-fetch-field "Newsgroups")))
4490 (followup-field (save-restriction
4491 (message-narrow-to-headers-or-head)
4492 (message-fetch-field "Followup-To")))
4493 ;; BUG: We really need to get the charset for each name in the
4494 ;; Newsgroups and Followup-To lines to allow crossposting
4495 ;; between group namess with incompatible character sets.
4496 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4497 (group-field-charset
4498 (gnus-group-name-charset method newsgroups-field))
4499 (followup-field-charset
4500 (gnus-group-name-charset method (or followup-field "")))
4501 (rfc2047-header-encoding-alist
4502 (append (when group-field-charset
4503 (list (cons "Newsgroups" group-field-charset)))
4504 (when followup-field-charset
4505 (list (cons "Followup-To" followup-field-charset)))
4506 rfc2047-header-encoding-alist))
4507 (messbuf (current-buffer))
4508 (message-syntax-checks
4510 (listp message-syntax-checks))
4511 (cons '(existing-newsgroups . disabled)
4512 message-syntax-checks)
4513 message-syntax-checks))
4514 (message-this-is-news t)
4515 (message-posting-charset
4516 (gnus-setup-posting-charset newsgroups-field))
4518 (if (not (message-check-news-body-syntax))
4521 (message-narrow-to-headers)
4522 ;; Insert some headers.
4523 (message-generate-headers message-required-news-headers)
4524 (message-insert-canlock)
4525 ;; Let the user do all of the above.
4526 (run-hooks 'message-header-hook))
4527 ;; Note: This check will be disabled by the ".*" default value for
4528 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4529 (when (and group-field-charset
4530 (listp message-syntax-checks))
4531 (setq message-syntax-checks
4532 (cons '(valid-newsgroups . disabled)
4533 message-syntax-checks)))
4534 (message-cleanup-headers)
4535 (if (not (let ((message-post-method method))
4536 (message-check-news-syntax)))
4541 (buffer-disable-undo)
4543 ;; Avoid copying text props (except hard newlines).
4545 (with-current-buffer messbuf
4546 (mml-buffer-substring-no-properties-except-hard-newlines
4547 (point-min) (point-max))))
4548 (message-encode-message-body)
4549 ;; Remove some headers.
4551 (message-narrow-to-headers)
4552 ;; We (re)generate the Lines header.
4553 (when (memq 'Lines message-required-mail-headers)
4554 (message-generate-headers '(Lines)))
4555 ;; Remove some headers.
4556 (message-remove-header message-ignored-news-headers t)
4557 (let ((mail-parse-charset message-default-charset))
4558 (mail-encode-encoded-word-buffer)))
4559 (goto-char (point-max))
4560 ;; require one newline at the end.
4561 (or (= (preceding-char) ?\n)
4563 (let ((case-fold-search t))
4564 ;; Remove the delimiter.
4565 (goto-char (point-min))
4567 (concat "^" (regexp-quote mail-header-separator) "\n"))
4568 (replace-match "\n")
4570 (run-hooks 'message-send-news-hook)
4571 (gnus-open-server method)
4572 (message "Sending news via %s..." (gnus-server-string method))
4573 (setq result (let ((mail-header-separator ""))
4574 (gnus-request-post method))))
4575 (kill-buffer tembuf))
4576 (set-buffer messbuf)
4578 (push 'news message-sent-message-via)
4579 (message "Couldn't send message via news: %s"
4580 (nnheader-get-report (car method)))
4584 ;;; Header generation & syntax checking.
4587 (defun message-check-element (type)
4588 "Return non-nil if this TYPE is not to be checked."
4589 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4591 (let ((able (assq type message-syntax-checks)))
4593 (eq (cdr able) 'disabled)))))
4595 (defun message-check-news-syntax ()
4596 "Check the syntax of the message."
4600 ;; We narrow to the headers and check them first.
4603 (message-narrow-to-headers)
4604 (message-check-news-header-syntax))))))
4606 (defun message-check-news-header-syntax ()
4608 ;; Check Newsgroups header.
4609 (message-check 'newsgroups
4610 (let ((group (message-fetch-field "newsgroups")))
4613 (not (string-match "\\`[ \t]*\\'" group)))
4616 "The newsgroups field is empty or missing. Posting is denied.")))))
4617 ;; Check the Subject header.
4618 (message-check 'subject
4619 (let* ((case-fold-search t)
4620 (subject (message-fetch-field "subject")))
4623 (not (string-match "\\`[ \t]*\\'" subject)))
4626 "The subject field is empty or missing. Posting is denied.")))))
4627 ;; Check for commands in Subject.
4628 (message-check 'subject-cmsg
4629 (if (string-match "^cmsg " (message-fetch-field "subject"))
4631 "The control code \"cmsg\" is in the subject. Really post? ")
4633 ;; Check long header lines.
4634 (message-check 'long-header-lines
4635 (let ((start (point))
4639 (while (and (not found)
4640 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4641 (if (> (- (point) (match-beginning 0)) 998)
4643 length (- (point) (match-beginning 0)))
4644 (setq header (match-string-no-properties 1)))
4645 (setq start (match-beginning 0))
4648 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4651 ;; Check for multiple identical headers.
4652 (message-check 'multiple-headers
4654 (while (and (not found)
4655 (re-search-forward "^[^ \t:]+: " nil t))
4657 (or (re-search-forward
4662 (match-beginning 0) (- (match-end 0) 2))))
4667 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4669 ;; Check for Version and Sendsys.
4670 (message-check 'sendsys
4671 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4673 (format "The article contains a %s command. Really post? "
4674 (buffer-substring (match-beginning 0)
4675 (1- (match-end 0)))))
4677 ;; See whether we can shorten Followup-To.
4678 (message-check 'shorten-followup-to
4679 (let ((newsgroups (message-fetch-field "newsgroups"))
4680 (followup-to (message-fetch-field "followup-to"))
4682 (when (and newsgroups
4683 (string-match "," newsgroups)
4688 (setq to (completing-read
4689 "Followups to (default no Followup-To header): "
4692 (message-tokenize-header
4694 (goto-char (point-min))
4695 (insert "Followup-To: " to "\n"))
4697 ;; Check "Shoot me".
4698 (message-check 'shoot
4699 (if (re-search-forward
4700 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4701 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4703 ;; Check for Approved.
4704 (message-check 'approved
4705 (if (re-search-forward "^Approved:" nil t)
4706 (y-or-n-p "The article contains an Approved header. Really post? ")
4708 ;; Check the Message-ID header.
4709 (message-check 'message-id
4710 (let* ((case-fold-search t)
4711 (message-id (message-fetch-field "message-id" t)))
4712 (or (not message-id)
4713 ;; Is there an @ in the ID?
4714 (and (string-match "@" message-id)
4715 ;; Is there a dot in the ID?
4716 (string-match "@[^.]*\\." message-id)
4717 ;; Does the ID end with a dot?
4718 (not (string-match "\\.>" message-id)))
4720 (format "The Message-ID looks strange: \"%s\". Really post? "
4722 ;; Check the Newsgroups & Followup-To headers.
4723 (message-check 'existing-newsgroups
4724 (let* ((case-fold-search t)
4725 (newsgroups (message-fetch-field "newsgroups"))
4726 (followup-to (message-fetch-field "followup-to"))
4727 (groups (message-tokenize-header
4729 (concat newsgroups "," followup-to)
4731 (post-method (if (functionp message-post-method)
4732 (funcall message-post-method)
4733 message-post-method))
4734 ;; KLUDGE to handle nnvirtual groups. Doing this right
4735 ;; would probably involve a new nnoo function.
4736 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4737 (method (if (and (consp post-method)
4738 (eq (car post-method) 'nnvirtual)
4739 gnus-message-group-art)
4740 (let ((group (car (nnvirtual-find-group-art
4741 (car gnus-message-group-art)
4742 (cdr gnus-message-group-art)))))
4743 (gnus-find-method-for-group group))
4747 (gnus-group-name-decode
4748 (gnus-group-real-name n)
4749 (gnus-group-name-charset method n)))
4750 (gnus-groups-from-server method)))
4753 (when (and (not (equal (car groups) "poster"))
4754 (not (member (car groups) known-groups))
4755 (not (member (car groups) errors)))
4756 (push (car groups) errors))
4759 ;; Gnus is not running.
4760 ((or (not (and (boundp 'gnus-active-hashtb)
4761 gnus-active-hashtb))
4762 (not (boundp 'gnus-read-active-file)))
4764 ;; We don't have all the group names.
4765 ((and (or (not gnus-read-active-file)
4766 (eq gnus-read-active-file 'some))
4770 "Really use %s possibly unknown group%s: %s? "
4771 (if (= (length errors) 1) "this" "these")
4772 (if (= (length errors) 1) "" "s")
4773 (mapconcat 'identity errors ", "))))
4774 ;; There were no errors.
4777 ;; There are unknown groups.
4781 "Really post to %s unknown group%s: %s? "
4782 (if (= (length errors) 1) "this" "these")
4783 (if (= (length errors) 1) "" "s")
4784 (mapconcat 'identity errors ", ")))))))
4785 ;; Check continuation headers.
4786 (message-check 'continuation-headers
4787 (goto-char (point-min))
4788 (let ((do-posting t))
4789 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4790 (goto-char (match-beginning 0))
4791 (if (y-or-n-p "Fix continuation lines? ")
4794 (unless (y-or-n-p "Send anyway? ")
4795 (setq do-posting nil))))
4797 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4798 (message-check 'valid-newsgroups
4799 (let ((case-fold-search t)
4800 (headers '("Newsgroups" "Followup-To"))
4802 (while (and headers (not error))
4803 (when (setq header (mail-fetch-field (car headers)))
4807 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4812 (not (string-match "\\.\\'\\|\\.\\." g)))
4813 (message-tokenize-header header ","))))
4820 (format "The %s header looks odd: \"%s\". Really post? "
4821 (car headers) header)))))
4822 (message-check 'repeated-newsgroups
4823 (let ((case-fold-search t)
4824 (headers '("Newsgroups" "Followup-To"))
4825 header error groups group)
4828 (when (setq header (mail-fetch-field (pop headers)))
4829 (setq groups (message-tokenize-header header ","))
4830 (while (setq group (pop groups))
4831 (when (member group groups)
4837 (format "Group %s is repeated in headers. Really post? " error)))))
4838 ;; Check the From header.
4839 (message-check 'from
4840 (let* ((case-fold-search t)
4841 (from (message-fetch-field "from"))
4845 (message "There is no From line. Posting is denied.")
4847 ((or (not (string-match
4849 (setq ad (nth 1 (mail-extract-address-components
4850 from))))) ;larsi@ifi
4851 (string-match "\\.\\." ad) ;larsi@ifi..uio
4852 (string-match "@\\." ad) ;larsi@.ifi.uio
4853 (string-match "\\.$" ad) ;larsi@ifi.uio.
4854 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4855 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4857 "Denied posting -- the From looks strange: \"%s\"." from)
4859 ((let ((addresses (rfc822-addresses from)))
4860 (while (and addresses
4861 (not (eq (string-to-char (car addresses)) ?\()))
4862 (setq addresses (cdr addresses)))
4865 "Denied posting -- bad From address: \"%s\"." from)
4868 ;; Check the Reply-To header.
4869 (message-check 'reply-to
4870 (let* ((case-fold-search t)
4871 (reply-to (message-fetch-field "reply-to"))
4876 ((string-match "," reply-to)
4878 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4880 ((or (not (string-match
4882 (setq ad (nth 1 (mail-extract-address-components
4883 reply-to))))) ;larsi@ifi
4884 (string-match "\\.\\." ad) ;larsi@ifi..uio
4885 (string-match "@\\." ad) ;larsi@.ifi.uio
4886 (string-match "\\.$" ad) ;larsi@ifi.uio.
4887 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4888 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4891 "The Reply-To looks strange: \"%s\". Really post? "
4895 (defun message-check-news-body-syntax ()
4897 ;; Check for long lines.
4898 (message-check 'long-lines
4899 (goto-char (point-min))
4901 (concat "^" (regexp-quote mail-header-separator) "$"))
4905 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4908 (< (- (point) p) 80)))
4909 (zerop (forward-line 1))))
4913 "You have lines longer than 79 characters. Really post? ")))
4914 ;; Check whether the article is empty.
4915 (message-check 'empty
4916 (goto-char (point-min))
4918 (concat "^" (regexp-quote mail-header-separator) "$"))
4921 (goto-char (point-max))
4922 (re-search-backward message-signature-separator nil t)
4924 (or (re-search-backward "[^ \n\t]" b t)
4925 (if (message-gnksa-enable-p 'empty-article)
4926 (y-or-n-p "Empty article. Really post? ")
4927 (message "Denied posting -- Empty article.")
4929 ;; Check for control characters.
4930 (message-check 'control-chars
4931 (if (re-search-forward
4932 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4935 "The article contains control characters. Really post? ")
4937 ;; Check excessive size.
4938 (message-check 'size
4939 (if (> (buffer-size) 60000)
4941 (format "The article is %d octets long. Really post? "
4944 ;; Check whether any new text has been added.
4945 (message-check 'new-text
4947 (not message-checksum)
4948 (not (eq (message-checksum) message-checksum))
4949 (if (message-gnksa-enable-p 'quoted-text-only)
4951 "It looks like no new text has been added. Really post? ")
4952 (message "Denied posting -- no new text has been added.")
4954 ;; Check the length of the signature.
4955 (message-check 'signature
4956 (goto-char (point-max))
4957 (if (> (count-lines (point) (point-max)) 5)
4960 "Your .sig is %d lines; it should be max 4. Really post? "
4961 (1- (count-lines (point) (point-max)))))
4963 ;; Ensure that text follows last quoted portion.
4964 (message-check 'quoting-style
4965 (goto-char (point-max))
4966 (let ((no-problem t))
4967 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4968 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4971 (if (message-gnksa-enable-p 'quoted-text-only)
4972 (y-or-n-p "Your text should follow quoted text. Really post? ")
4974 (goto-char (point-min))
4976 (concat "^" (regexp-quote mail-header-separator) "$"))
4977 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4978 (y-or-n-p "Your text should follow quoted text. Really post? ")
4979 (message "Denied posting -- only quoted text.")
4982 (defun message-checksum ()
4983 "Return a \"checksum\" for the current buffer."
4986 (goto-char (point-min))
4988 (concat "^" (regexp-quote mail-header-separator) "$"))
4990 (when (not (looking-at "[ \t\n]"))
4991 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4996 (defun message-do-fcc ()
4997 "Process Fcc headers in the current buffer."
4998 (let ((case-fold-search t)
4999 (buf (current-buffer))
5001 (mml-externalize-attachments message-fcc-externalize-attachments))
5004 (message-narrow-to-headers)
5005 (setq file (message-fetch-field "fcc" t)))
5007 (set-buffer (get-buffer-create " *message temp*"))
5009 (insert-buffer-substring buf)
5010 (message-encode-message-body)
5012 (message-narrow-to-headers)
5013 (while (setq file (message-fetch-field "fcc" t))
5015 (message-remove-header "fcc" nil t))
5016 (let ((mail-parse-charset message-default-charset)
5017 (rfc2047-header-encoding-alist
5018 (cons '("Newsgroups" . default)
5019 rfc2047-header-encoding-alist)))
5020 (mail-encode-encoded-word-buffer)))
5021 (goto-char (point-min))
5022 (when (re-search-forward
5023 (concat "^" (regexp-quote mail-header-separator) "$")
5025 (replace-match "" t t ))
5026 ;; Process FCC operations.
5028 (setq file (pop list))
5029 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5030 ;; Pipe the article to the program in question.
5031 (call-process-region (point-min) (point-max) shell-file-name
5032 nil nil nil shell-command-switch
5033 (match-string 1 file))
5034 ;; Save the article.
5035 (setq file (expand-file-name file))
5036 (unless (file-exists-p (file-name-directory file))
5037 (make-directory (file-name-directory file) t))
5038 (if (and message-fcc-handler-function
5039 (not (eq message-fcc-handler-function 'rmail-output)))
5040 (funcall message-fcc-handler-function file)
5041 (if (and (file-readable-p file) (mail-file-babyl-p file))
5042 (rmail-output file 1 nil t)
5043 (let ((mail-use-rfc822 t))
5044 (rmail-output file 1 t t))))))
5045 (kill-buffer (current-buffer))))))
5047 (defun message-output (filename)
5048 "Append this article to Unix/babyl mail file FILENAME."
5049 (if (and (file-readable-p filename)
5050 (mail-file-babyl-p filename))
5051 (gnus-output-to-rmail filename t)
5052 (gnus-output-to-mail filename t)))
5054 (defun message-cleanup-headers ()
5055 "Do various automatic cleanups of the headers."
5056 ;; Remove empty lines in the header.
5058 (message-narrow-to-headers)
5059 ;; Remove blank lines.
5060 (while (re-search-forward "^[ \t]*\n" nil t)
5061 (replace-match "" t t))
5063 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5064 ;; spaces to comma and eliminate spaces around commas. Eliminate
5065 ;; embedded line breaks.
5066 (goto-char (point-min))
5067 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5071 (if (re-search-forward "^[^ \t]" nil t)
5075 (goto-char (point-min))
5076 (while (re-search-forward "\n[ \t]+" nil t)
5077 (replace-match " " t t)) ;No line breaks (too confusing)
5078 (goto-char (point-min))
5079 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5080 (replace-match "," t t))
5081 (goto-char (point-min))
5082 ;; Remove trailing commas.
5083 (when (re-search-forward ",+$" nil t)
5084 (replace-match "" t t))))))
5086 (defun message-make-date (&optional now)
5087 "Make a valid data header.
5088 If NOW, use that time instead."
5089 (let ((system-time-locale "C"))
5090 (format-time-string "%a, %d %b %Y %T %z" now)))
5092 (defun message-insert-expires (days)
5093 "Insert the Expires header. Expiry in DAYS days."
5094 (interactive "NExpire article in how many days? ")
5096 (message-position-on-field "Expires" "X-Draft-From")
5097 (insert (message-make-expires-date days))))
5099 (defun message-make-expires-date (days)
5100 "Make date string for the Expires header. Expiry in DAYS days.
5102 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5103 (let* ((cur (decode-time (current-time)))
5104 (nday (+ days (nth 3 cur))))
5105 (setf (nth 3 cur) nday)
5106 (message-make-date (apply 'encode-time cur))))
5108 (defun message-make-message-id ()
5109 "Make a unique Message-ID."
5110 (concat "<" (message-unique-id)
5111 (let ((psubject (save-excursion (message-fetch-field "subject")))
5113 (save-excursion (message-fetch-field "supersedes"))))
5115 (and message-reply-headers
5116 (mail-header-references message-reply-headers)
5117 (mail-header-subject message-reply-headers)
5120 (message-strip-subject-re
5121 (mail-header-subject message-reply-headers))
5122 (message-strip-subject-re psubject))))
5124 (string-match "_-_@" psupersedes)))
5126 "@" (message-make-fqdn) ">"))
5128 (defvar message-unique-id-char nil)
5130 ;; If you ever change this function, make sure the new version
5131 ;; cannot generate IDs that the old version could.
5132 ;; You might for example insert a "." somewhere (not next to another dot
5133 ;; or string boundary), or modify the "fsf" string.
5134 (defun message-unique-id ()
5135 ;; Don't use microseconds from (current-time), they may be unsupported.
5136 ;; Instead we use this randomly inited counter.
5137 (setq message-unique-id-char
5138 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5139 ;; (current-time) returns 16-bit ints,
5140 ;; and 2^16*25 just fits into 4 digits i base 36.
5142 (let ((tm (current-time)))
5144 (if (or (memq system-type '(ms-dos emx vax-vms))
5145 ;; message-number-base36 doesn't handle bigints.
5146 (floatp (user-uid)))
5147 (let ((user (downcase (user-login-name))))
5148 (while (string-match "[^a-z0-9_]" user)
5149 (aset user (match-beginning 0) ?_))
5151 (message-number-base36 (user-uid) -1))
5152 (message-number-base36 (+ (car tm)
5153 (lsh (% message-unique-id-char 25) 16)) 4)
5154 (message-number-base36 (+ (nth 1 tm)
5155 (lsh (/ message-unique-id-char 25) 16)) 4)
5156 ;; Append a given name, because while the generated ID is unique
5157 ;; to this newsreader, other newsreaders might otherwise generate
5158 ;; the same ID via another algorithm.
5161 (defun message-number-base36 (num len)
5166 (concat (message-number-base36 (/ num 36) (1- len))
5167 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5170 (defun message-make-organization ()
5171 "Make an Organization header."
5172 (let* ((organization
5173 (when message-user-organization
5174 (if (functionp message-user-organization)
5175 (funcall message-user-organization)
5176 message-user-organization))))
5178 (mm-enable-multibyte)
5179 (cond ((stringp organization)
5180 (insert organization))
5181 ((and (eq t organization)
5182 message-user-organization-file
5183 (file-exists-p message-user-organization-file))
5184 (insert-file-contents message-user-organization-file)))
5185 (goto-char (point-min))
5186 (while (re-search-forward "[\t\n]+" nil t)
5187 (replace-match "" t t))
5188 (unless (zerop (buffer-size))
5191 (defun message-make-lines ()
5192 "Count the number of lines and return numeric string."
5197 (int-to-string (count-lines (point) (point-max))))))
5199 (defun message-make-references ()
5200 "Return the References header for this message."
5201 (when message-reply-headers
5202 (let ((message-id (mail-header-message-id message-reply-headers))
5203 (references (mail-header-references message-reply-headers))
5205 (if (or references message-id)
5206 (concat (or references "") (and references " ")
5210 (defun message-make-in-reply-to ()
5211 "Return the In-Reply-To header for this message."
5212 (when message-reply-headers
5213 (let ((from (mail-header-from message-reply-headers))
5214 (date (mail-header-date message-reply-headers))
5215 (msg-id (mail-header-message-id message-reply-headers)))
5217 (let ((name (mail-extract-address-components from)))
5219 msg-id (if msg-id " (")
5221 (if (string-match "[^\000-\177]" (car name))
5222 ;; Quote a string containing non-ASCII characters.
5223 ;; It will make the RFC2047 encoder cause an error
5224 ;; if there are special characters.
5225 (let ((default-enable-multibyte-characters t))
5228 (goto-char (point-min))
5229 (while (search-forward "\"" nil t)
5232 (zerop (% (skip-chars-backward "\\\\") 2))
5233 (goto-char (match-beginning 0)))
5236 ;; Those quotes will be removed by the RFC2047 encoder.
5237 (concat "\"" (buffer-string) "\"")))
5241 (if (or (not date) (string= date ""))
5242 "(unknown date)" date)
5243 "\"" (if msg-id ")")))))))
5245 (defun message-make-distribution ()
5246 "Make a Distribution header."
5247 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5248 (cond ((functionp message-distribution-function)
5249 (funcall message-distribution-function))
5250 (t orig-distribution))))
5252 (defun message-make-expires ()
5253 "Return an Expires header based on `message-expires'."
5254 (let ((current (current-time))
5255 (future (* 1.0 message-expires 60 60 24)))
5256 ;; Add the future to current.
5257 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5258 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5259 (message-make-date current)))
5261 (defun message-make-path ()
5263 (let ((login-name (user-login-name)))
5264 (cond ((null message-user-path)
5265 (concat (system-name) "!" login-name))
5266 ((stringp message-user-path)
5267 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5268 (concat message-user-path "!" login-name))
5271 (defun message-make-from (&optional name address )
5272 "Make a From header."
5273 (let* ((style message-from-style)
5274 (login (or address (message-make-address)))
5276 (and (boundp 'user-full-name)
5279 (when (string= fullname "&")
5280 (setq fullname (user-login-name)))
5282 (mm-enable-multibyte)
5285 (equal fullname ""))
5287 ((or (eq style 'angles)
5288 (and (not (eq style 'parens))
5289 ;; Use angles if no quoting is needed, or if parens would
5290 ;; need quoting too.
5291 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5292 (let ((tmp (concat fullname nil)))
5293 (while (string-match "([^()]*)" tmp)
5294 (aset tmp (match-beginning 0) ?-)
5295 (aset tmp (1- (match-end 0)) ?-))
5296 (string-match "[\\()]" tmp)))))
5298 (goto-char (point-min))
5299 ;; Look for a character that cannot appear unquoted
5300 ;; according to RFC 822.
5301 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5302 ;; Quote fullname, escaping specials.
5303 (goto-char (point-min))
5305 (while (re-search-forward "[\"\\]" nil 1)
5306 (replace-match "\\\\\\&" t))
5308 (insert " <" login ">"))
5309 (t ; 'parens or default
5311 (let ((fullname-start (point)))
5313 (goto-char fullname-start)
5314 ;; RFC 822 says \ and nonmatching parentheses
5315 ;; must be escaped in comments.
5316 ;; Escape every instance of ()\ ...
5317 (while (re-search-forward "[()\\]" nil 1)
5318 (replace-match "\\\\\\&" t))
5319 ;; ... then undo escaping of matching parentheses,
5320 ;; including matching nested parentheses.
5321 (goto-char fullname-start)
5322 (while (re-search-forward
5323 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5325 (replace-match "\\1(\\3)" t)
5326 (goto-char fullname-start)))
5330 (defun message-make-sender ()
5331 "Return the \"real\" user address.
5332 This function tries to ignore all user modifications, and
5333 give as trustworthy answer as possible."
5334 (concat (user-login-name) "@" (system-name)))
5336 (defun message-make-address ()
5337 "Make the address of the user."
5338 (or (message-user-mail-address)
5339 (concat (user-login-name) "@" (message-make-domain))))
5341 (defun message-user-mail-address ()
5342 "Return the pertinent part of `user-mail-address'."
5343 (when (and user-mail-address
5344 (string-match "@.*\\." user-mail-address))
5345 (if (string-match " " user-mail-address)
5346 (nth 1 (mail-extract-address-components user-mail-address))
5347 user-mail-address)))
5349 (defun message-sendmail-envelope-from ()
5350 "Return the envelope from."
5351 (cond ((eq message-sendmail-envelope-from 'header)
5352 (nth 1 (mail-extract-address-components
5353 (message-fetch-field "from"))))
5354 ((stringp message-sendmail-envelope-from)
5355 message-sendmail-envelope-from)
5357 (message-make-address))))
5359 (defun message-make-fqdn ()
5360 "Return user's fully qualified domain name."
5361 (let* ((system-name (system-name))
5362 (user-mail (message-user-mail-address))
5365 (string-match "@\\(.*\\)\\'" user-mail))
5366 (match-string 1 user-mail)))
5367 (case-fold-search t))
5369 ((and message-user-fqdn
5370 (stringp message-user-fqdn)
5371 (string-match message-valid-fqdn-regexp message-user-fqdn)
5372 (not (string-match message-bogus-system-names message-user-fqdn)))
5373 ;; `message-user-fqdn' seems to be valid
5375 ((and (string-match message-valid-fqdn-regexp system-name)
5376 (not (string-match message-bogus-system-names system-name)))
5377 ;; `system-name' returned the right result.
5379 ;; Try `mail-host-address'.
5380 ((and (boundp 'mail-host-address)
5381 (stringp mail-host-address)
5382 (string-match message-valid-fqdn-regexp mail-host-address)
5383 (not (string-match message-bogus-system-names mail-host-address)))
5385 ;; We try `user-mail-address' as a backup.
5387 (stringp user-domain)
5388 (string-match message-valid-fqdn-regexp user-domain)
5389 (not (string-match message-bogus-system-names user-domain)))
5391 ;; Default to this bogus thing.
5394 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5396 (defun message-make-host-name ()
5397 "Return the name of the host."
5398 (let ((fqdn (message-make-fqdn)))
5399 (string-match "^[^.]+\\." fqdn)
5400 (substring fqdn 0 (1- (match-end 0)))))
5402 (defun message-make-domain ()
5403 "Return the domain name."
5404 (or mail-host-address
5405 (message-make-fqdn)))
5407 (defun message-to-list-only ()
5408 "Send a message to the list only.
5409 Remove all addresses but the list address from To and Cc headers."
5411 (let ((listaddr (message-make-mail-followup-to t)))
5414 (message-remove-header "to")
5415 (message-remove-header "cc")
5416 (message-position-on-field "To" "X-Draft-From")
5417 (insert listaddr)))))
5419 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5420 "Return the Mail-Followup-To header.
5421 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5422 subscribed address (and not the additional To and Cc header contents)."
5423 (let* ((case-fold-search t)
5424 (to (message-fetch-field "To"))
5425 (cc (message-fetch-field "cc"))
5426 (msg-recipients (concat to (and to cc ", ") cc))
5428 (mapcar 'mail-strip-quoted-names
5429 (message-tokenize-header msg-recipients)))
5431 (if message-subscribed-address-file
5432 (let (begin end item re)
5435 (insert-file-contents message-subscribed-address-file)
5437 (setq begin (point))
5440 (if (bolp) (setq end (1- end)))
5441 (setq item (regexp-quote (buffer-substring begin end)))
5442 (if re (setq re (concat re "\\|" item))
5443 (setq re (concat "\\`\\(" item))))
5444 (and re (list (concat re "\\)\\'"))))))))
5445 (mft-regexps (apply 'append message-subscribed-regexps
5446 (mapcar 'regexp-quote
5447 message-subscribed-addresses)
5450 message-subscribed-address-functions))))
5452 (let ((subscribed-lists nil)
5454 (loop for recipient in recipients
5455 when (loop for regexp in mft-regexps
5456 when (string-match regexp recipient) return t)
5459 (if only-show-subscribed
5461 msg-recipients))))))
5463 (defun message-idna-to-ascii-rhs-1 (header)
5464 "Interactively potentially IDNA encode domain names in HEADER."
5465 (let ((field (message-fetch-field header))
5469 (mm-delete-duplicates
5470 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5473 'car (mail-header-parse-addresses field))))))
5474 (setq ace (downcase (idna-to-ascii rhs)))
5475 (when (and (not (equal rhs ace))
5476 (or (not (eq message-use-idna 'ask))
5477 (y-or-n-p (format "Replace %s with %s in %s:? "
5479 (goto-char (point-min))
5480 (while (re-search-forward (concat "^" header ":") nil t)
5481 (message-narrow-to-field)
5482 (while (search-forward (concat "@" rhs) nil t)
5483 (replace-match (concat "@" ace) t t))
5484 (goto-char (point-max))
5487 (defun message-idna-to-ascii-rhs ()
5488 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5489 See `message-idna-encode'."
5491 (when message-use-idna
5494 (message-narrow-to-head)
5495 (message-idna-to-ascii-rhs-1 "From")
5496 (message-idna-to-ascii-rhs-1 "To")
5497 (message-idna-to-ascii-rhs-1 "Reply-To")
5498 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5499 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5500 (message-idna-to-ascii-rhs-1 "Cc")))))
5502 (defun message-generate-headers (headers)
5503 "Prepare article HEADERS.
5504 Headers already prepared in the buffer are not modified."
5505 (setq headers (append headers message-required-headers))
5507 (message-narrow-to-headers)
5508 (let* ((Date (message-make-date))
5509 (Message-ID (message-make-message-id))
5510 (Organization (message-make-organization))
5511 (From (message-make-from))
5512 (Path (message-make-path))
5515 (In-Reply-To (message-make-in-reply-to))
5516 (References (message-make-references))
5518 (Distribution (message-make-distribution))
5519 (Lines (message-make-lines))
5520 (User-Agent message-newsreader)
5521 (Expires (message-make-expires))
5522 (case-fold-search t)
5524 header value elem header-string)
5525 ;; First we remove any old generated headers.
5526 (let ((headers message-deletable-headers))
5527 (unless (buffer-modified-p)
5528 (setq headers (delq 'Message-ID (copy-sequence headers))))
5530 (goto-char (point-min))
5531 (and (re-search-forward
5532 (concat "^" (symbol-name (car headers)) ": *") nil t)
5533 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5534 (message-delete-line))
5536 ;; Go through all the required headers and see if they are in the
5537 ;; articles already. If they are not, or are empty, they are
5538 ;; inserted automatically - except for Subject, Newsgroups and
5541 (goto-char (point-min))
5542 (setq elem (pop headers))
5544 (if (eq (car elem) 'optional)
5545 (setq header (cdr elem)
5547 (setq header (car elem)))
5549 (setq header-string (if (stringp header)
5551 (symbol-name header)))
5552 (when (or (not (re-search-forward
5554 (regexp-quote (downcase header-string))
5558 ;; The header was found. We insert a space after the
5559 ;; colon, if there is none.
5560 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5561 ;; Find out whether the header is empty.
5562 (looking-at "[ \t]*\n[^ \t]")))
5563 ;; So we find out what value we should insert.
5567 (eq (car elem) 'optional)
5568 (not (member header-string message-inserted-headers)))
5569 ;; This is an optional header. If the cdr of this
5570 ;; is something that is nil, then we do not insert
5572 (setq header (cdr elem))
5573 (or (and (functionp (cdr elem))
5574 (funcall (cdr elem)))
5575 (and (boundp (cdr elem))
5576 (symbol-value (cdr elem)))))
5578 ;; The element is a cons. Either the cdr is a
5579 ;; string to be inserted verbatim, or it is a
5580 ;; function, and we insert the value returned from
5582 (or (and (stringp (cdr elem))
5584 (and (functionp (cdr elem))
5585 (funcall (cdr elem)))))
5586 ((and (boundp header)
5587 (symbol-value header))
5588 ;; The element is a symbol. We insert the value
5589 ;; of this symbol, if any.
5590 (symbol-value header))
5591 ((not (message-check-element
5592 (intern (downcase (symbol-name header)))))
5593 ;; We couldn't generate a value for this header,
5594 ;; so we just ask the user.
5595 (read-from-minibuffer
5596 (format "Empty header for %s; enter value: " header)))))
5597 ;; Finally insert the header.
5599 (not (equal value "")))
5603 ;; This header didn't exist, so we insert it.
5604 (goto-char (point-max))
5606 (cdr (assq header message-header-format-alist))))
5608 (funcall formatter header value)
5609 (insert header-string ": " value))
5610 (goto-char (message-fill-field))
5611 ;; We check whether the value was ended by a
5612 ;; newline. If not, we insert one.
5616 ;; The value of this header was empty, so we clear
5617 ;; totally and insert the new value.
5618 (delete-region (point) (point-at-eol))
5619 ;; If the header is optional, and the header was
5620 ;; empty, we can't insert it anyway.
5622 (push header-string message-inserted-headers)
5624 (message-fill-field)))
5625 ;; Add the deletable property to the headers that require it.
5626 (and (memq header message-deletable-headers)
5627 (progn (beginning-of-line) (looking-at "[^:]+: "))
5628 (add-text-properties
5629 (point) (match-end 0)
5630 '(message-deletable t face italic) (current-buffer)))))))
5631 ;; Insert new Sender if the From is strange.
5632 (let ((from (message-fetch-field "from"))
5633 (sender (message-fetch-field "sender"))
5634 (secure-sender (message-make-sender)))
5636 (not (message-check-element 'sender))
5639 (cadr (mail-extract-address-components from)))
5640 (downcase secure-sender)))
5645 (cadr (mail-extract-address-components sender)))
5646 (downcase secure-sender)))))
5647 (goto-char (point-min))
5648 ;; Rename any old Sender headers to Original-Sender.
5649 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5651 (insert "Original-")
5652 (beginning-of-line))
5653 (when (or (message-news-p)
5654 (string-match "@.+\\.." secure-sender))
5655 (insert "Sender: " secure-sender "\n"))))
5657 (message-idna-to-ascii-rhs))))
5659 (defun message-insert-courtesy-copy ()
5660 "Insert a courtesy message in mail copies of combined messages."
5664 (message-narrow-to-headers)
5665 (when (setq newsgroups (message-fetch-field "newsgroups"))
5666 (goto-char (point-max))
5667 (insert "Posted-To: " newsgroups "\n")))
5669 (when message-courtesy-message
5671 ((string-match "%s" message-courtesy-message)
5672 (insert (format message-courtesy-message newsgroups)))
5674 (insert message-courtesy-message)))))))
5677 ;;; Setting up a message buffer
5680 (defun message-skip-to-next-address ()
5681 (let ((end (save-excursion
5682 (message-next-header)
5685 (when (looking-at ",")
5687 (while (and (not (= (point) end))
5688 (or (not (eq char ?,))
5690 (skip-chars-forward "^,\"" (point-max))
5691 (when (eq (setq char (following-char)) ?\")
5692 (setq quoted (not quoted)))
5693 (unless (= (point) end)
5695 (skip-chars-forward " \t\n")))
5697 (defun message-fill-address (header value)
5698 (insert (capitalize (symbol-name header))
5700 (if (consp value) (car value) value)
5702 (message-fill-field-address))
5704 (defun message-split-line ()
5705 "Split current line, moving portion beyond point vertically down.
5706 If the current line has `message-yank-prefix', insert it on the new line."
5709 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5713 (defun message-insert-header (header value)
5714 (insert (capitalize (symbol-name header))
5716 (if (consp value) (car value) value)))
5718 (defun message-field-name ()
5720 (goto-char (point-min))
5721 (when (looking-at "\\([^:]+\\):")
5722 (intern (capitalize (match-string 1))))))
5724 (defun message-fill-field ()
5727 (message-narrow-to-field)
5728 (let ((field-name (message-field-name)))
5729 (funcall (or (cadr (assq field-name message-field-fillers))
5730 'message-fill-field-general)))
5733 (defun message-fill-field-address ()
5735 (message-skip-to-next-address)
5737 (if (and (> (current-column) 78)
5743 (setq last (1+ (point))))
5744 (setq last (1+ (point)))))))
5746 (defun message-fill-field-general ()
5747 (let ((begin (point))
5750 (while (and (search-forward "\n" nil t)
5752 (replace-match " " t t))
5753 (fill-region-as-paragraph begin (point-max))
5754 ;; Tapdance around looong Message-IDs.
5756 (when (looking-at "[ \t]*$")
5757 (message-delete-line))
5759 (search-forward ":" nil t)
5760 (when (looking-at "\n[ \t]+")
5761 (replace-match " " t t))
5762 (goto-char (point-max))))
5764 (defun message-shorten-1 (list cut surplus)
5765 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5766 (setcdr (nthcdr (- cut 2) list)
5767 (nthcdr (+ (- cut 2) surplus 1) list)))
5769 (defun message-shorten-references (header references)
5770 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5771 When sending via news, also check that the REFERENCES are less
5772 than 988 characters long, and if they are not, trim them until
5780 (goto-char (point-min))
5781 ;; Cons a list of valid references.
5782 (while (re-search-forward "<[^>]+>" nil t)
5783 (push (match-string 0) refs))
5784 (setq refs (nreverse refs)
5785 count (length refs)))
5787 ;; If the list has more than MAXCOUNT elements, trim it by
5788 ;; removing the CUTth element and the required number of
5789 ;; elements that follow.
5790 (when (> count maxcount)
5791 (let ((surplus (- count maxcount)))
5792 (message-shorten-1 refs cut surplus)
5793 (decf count surplus)))
5795 ;; When sending via news, make sure the total folded length will
5796 ;; be less than 998 characters. This is to cater to broken INN
5797 ;; 2.3 which counts the total number of characters in a header
5798 ;; rather than the physical line length of each line, as it should.
5800 ;; This hack should be removed when it's believed than INN 2.3 is
5801 ;; no longer widely used.
5803 ;; At this point the headers have not been generated, thus we use
5804 ;; message-this-is-news directly.
5805 (when message-this-is-news
5808 (message-insert-header
5809 header (mapconcat #'identity refs " "))
5811 (message-shorten-1 refs cut 1)))
5812 ;; Finally, collect the references back into a string and insert
5813 ;; it into the buffer.
5814 (message-insert-header header (mapconcat #'identity refs " "))))
5816 (defun message-position-point ()
5817 "Move point to where the user probably wants to find it."
5818 (message-narrow-to-headers)
5820 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5821 (search-backward ":" )
5824 (if (eq (char-after) ? )
5828 (goto-char (point-max))
5831 (unless (looking-at "$")
5835 (defcustom message-beginning-of-line t
5836 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5837 goes to beginning of header values."
5839 :group 'message-buffers
5840 :link '(custom-manual "(message)Movement")
5843 (defun message-beginning-of-line (&optional n)
5844 "Move point to beginning of header value or to beginning of line.
5845 The prefix argument N is passed directly to `beginning-of-line'.
5847 This command is identical to `beginning-of-line' if point is
5848 outside the message header or if the option `message-beginning-of-line'
5851 If point is in the message header and on a (non-continued) header
5852 line, move point to the beginning of the header value or the beginning of line,
5853 whichever is closer. If point is already at beginning of line, move point to
5854 beginning of header value. Therefore, repeated calls will toggle point
5855 between beginning of field and beginning of line."
5857 (let ((zrs 'zmacs-region-stays))
5858 (when (and (interactive-p) (boundp zrs))
5860 (if (and message-beginning-of-line
5861 (message-point-in-header-p))
5862 (let* ((here (point))
5863 (bol (progn (beginning-of-line n) (point)))
5864 (eol (point-at-eol))
5865 (eoh (re-search-forward ": *" eol t)))
5867 (if (and eoh (or (< eoh here) (= bol here)))
5869 (beginning-of-line n)))
5871 (defun message-buffer-name (type &optional to group)
5872 "Return a new (unique) buffer name based on TYPE and TO."
5874 ;; Generate a new buffer name The Message Way.
5875 ((memq message-generate-new-buffers '(unique t))
5876 (generate-new-buffer-name
5880 (or (car (mail-extract-address-components to))
5883 (if (and group (not (string= group ""))) (concat " on " group) "")
5885 ;; Check whether `message-generate-new-buffers' is a function,
5886 ;; and if so, call it.
5887 ((functionp message-generate-new-buffers)
5888 (funcall message-generate-new-buffers type to group))
5889 ((eq message-generate-new-buffers 'unsent)
5890 (generate-new-buffer-name
5891 (concat "*unsent " type
5894 (or (car (mail-extract-address-components to))
5897 (if (and group (not (string= group ""))) (concat " on " group) "")
5899 ;; Search for the existing message buffer with the specified name.
5901 (let* ((new (if (eq message-generate-new-buffers 'standard)
5902 (generate-new-buffer-name (concat "*" type " message*"))
5903 (let ((message-generate-new-buffers 'unique))
5904 (message-buffer-name type to group))))
5905 (regexp (concat "\\`"
5907 (if (string-match "<[0-9]+>\\'" new)
5908 (substring new 0 (match-beginning 0))
5910 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
5911 (case-fold-search nil))
5918 (when (and (string-match regexp (setq b (buffer-name b)))
5919 (eq (with-current-buffer b major-mode)
5921 (cons (string-to-number (or (match-string 1 b) "1"))
5924 'car-less-than-car)))
5927 (defun message-pop-to-buffer (name)
5928 "Pop to buffer NAME, and warn if it already exists and is modified."
5929 (let ((buffer (get-buffer name)))
5931 (buffer-name buffer))
5932 (let ((window (get-buffer-window buffer 0)))
5934 ;; Raise the frame already displaying the message buffer.
5936 (gnus-select-frame-set-input-focus (window-frame window))
5937 (select-window window))
5938 (set-buffer (pop-to-buffer buffer)))
5939 (when (and (buffer-modified-p)
5942 "Message already being composed; erase? ")
5944 (error "Message being composed")))
5945 (set-buffer (pop-to-buffer name)))
5949 (defun message-do-send-housekeeping ()
5950 "Kill old message buffers."
5951 ;; We might have sent this buffer already. Delete it from the
5953 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5954 (while (and message-max-buffers
5956 (>= (length message-buffer-list) message-max-buffers))
5957 ;; Kill the oldest buffer -- unless it has been changed.
5958 (let ((buffer (pop message-buffer-list)))
5959 (when (and (buffer-name buffer)
5960 (not (buffer-modified-p buffer)))
5961 (kill-buffer buffer))))
5962 ;; Rename the buffer.
5963 (if message-send-rename-function
5964 (funcall message-send-rename-function)
5965 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5967 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5969 (let ((name (match-string 2 (buffer-name)))
5971 (if (not (or (null name)
5972 (string-equal name "mail")
5973 (string-equal name "posting")))
5974 (setq name (concat "*sent " name "*"))
5975 (message-narrow-to-headers)
5976 (setq to (message-fetch-field "to"))
5977 (setq group (message-fetch-field "newsgroups"))
5981 (to (concat "*sent mail to "
5982 (or (car (mail-extract-address-components to))
5984 ((and group (not (string= group "")))
5985 (concat "*sent posting on " group "*"))
5986 (t "*sent mail*"))))
5987 (unless (string-equal name (buffer-name))
5988 (rename-buffer name t)))))
5989 ;; Push the current buffer onto the list.
5990 (when message-max-buffers
5991 (setq message-buffer-list
5992 (nconc message-buffer-list (list (current-buffer))))))
5994 (defun message-mail-user-agent ()
5996 ((not message-mail-user-agent) nil)
5997 ((eq message-mail-user-agent t) mail-user-agent)
5998 (t message-mail-user-agent))))
5999 (if (memq mua '(message-user-agent gnus-user-agent))
6003 (defun message-setup (headers &optional replybuffer actions
6004 continue switch-function)
6005 (let ((mua (message-mail-user-agent))
6006 subject to field yank-action)
6007 (if (not (and message-this-is-mail mua))
6008 (message-setup-1 headers replybuffer actions)
6010 (setq yank-action (list 'insert-buffer replybuffer)))
6011 (setq headers (copy-sequence headers))
6012 (setq field (assq 'Subject headers))
6014 (setq subject (cdr field))
6015 (setq headers (delq field headers)))
6016 (setq field (assq 'To headers))
6018 (setq to (cdr field))
6019 (setq headers (delq field headers)))
6020 (let ((mail-user-agent mua))
6021 (compose-mail to subject
6022 (mapcar (lambda (item)
6024 (format "%s" (car item))
6027 continue switch-function yank-action actions)))))
6029 (defun message-headers-to-generate (headers included-headers excluded-headers)
6030 "Return a list that includes all headers from HEADERS.
6031 If INCLUDED-HEADERS is a list, just include those headers. If it is
6032 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6036 (dolist (header headers)
6037 (setq header-name (cond
6038 ((and (consp header)
6039 (eq (car header) 'optional))
6040 ;; On the form (optional . Header)
6043 ;; On the form (Header . function)
6048 (when (and (not (memq header-name excluded-headers))
6049 (or (eq included-headers t)
6050 (memq header-name included-headers)))
6051 (push header result)))
6054 (defun message-setup-1 (headers &optional replybuffer actions)
6055 (dolist (action actions)
6057 (add-to-list 'message-send-actions
6058 `(apply ',(car action) ',(cdr action)))))
6059 (setq message-reply-buffer replybuffer)
6060 (goto-char (point-min))
6061 ;; Insert all the headers.
6064 (alist message-header-format-alist))
6066 (unless (assq (caar h) message-header-format-alist)
6067 (push (list (caar h)) alist))
6071 (delete-region (point) (progn (forward-line -1) (point)))
6072 (when message-default-headers
6073 (insert message-default-headers)
6074 (or (bolp) (insert ?\n)))
6075 (insert mail-header-separator "\n")
6077 (when (message-news-p)
6078 (when message-default-news-headers
6079 (insert message-default-news-headers)
6080 (or (bolp) (insert ?\n)))
6081 (when message-generate-headers-first
6082 (message-generate-headers
6083 (message-headers-to-generate
6084 (append message-required-news-headers
6085 message-required-headers)
6086 message-generate-headers-first
6087 '(Lines Subject)))))
6088 (when (message-mail-p)
6089 (when message-default-mail-headers
6090 (insert message-default-mail-headers)
6091 (or (bolp) (insert ?\n)))
6092 (when message-generate-headers-first
6093 (message-generate-headers
6094 (message-headers-to-generate
6095 (append message-required-mail-headers
6096 message-required-headers)
6097 message-generate-headers-first
6098 '(Lines Subject)))))
6099 (run-hooks 'message-signature-setup-hook)
6100 (message-insert-signature)
6102 (message-narrow-to-headers)
6103 (run-hooks 'message-header-setup-hook))
6104 (set-buffer-modified-p nil)
6105 (setq buffer-undo-list nil)
6106 (when message-generate-hashcash
6107 ;; Generate hashcash headers for recipients already known
6108 (mail-add-payment-async))
6109 (run-hooks 'message-setup-hook)
6110 ;; Do this last to give it precedence over posting styles, etc.
6111 (when (message-mail-p)
6113 (message-narrow-to-headers)
6114 (if message-alternative-emails
6115 (message-use-alternative-email-as-from))))
6116 (message-position-point)
6119 (defun message-set-auto-save-file-name ()
6120 "Associate the message buffer with a file in the drafts directory."
6121 (when message-auto-save-directory
6122 (unless (file-directory-p
6123 (directory-file-name message-auto-save-directory))
6124 (make-directory message-auto-save-directory t))
6126 (setq message-draft-article
6127 (nndraft-request-associate-buffer "drafts"))
6128 (setq buffer-file-name (expand-file-name
6129 (if (memq system-type
6130 '(ms-dos ms-windows windows-nt
6131 cygwin cygwin32 win32 w32
6135 message-auto-save-directory))
6136 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6137 (clear-visited-file-modtime)
6138 (setq buffer-file-coding-system message-draft-coding-system)))
6140 (defun message-disassociate-draft ()
6141 "Disassociate the message buffer from the drafts directory."
6142 (when message-draft-article
6143 (nndraft-request-expire-articles
6144 (list message-draft-article) "drafts" nil t)))
6146 (defun message-insert-headers ()
6147 "Generate the headers for the article."
6151 (message-narrow-to-headers)
6152 (when (message-news-p)
6153 (message-generate-headers
6156 (copy-sequence message-required-news-headers)))))
6157 (when (message-mail-p)
6158 (message-generate-headers
6161 (copy-sequence message-required-mail-headers))))))))
6166 ;;; Commands for interfacing with message
6170 (defun message-mail (&optional to subject
6171 other-headers continue switch-function
6172 yank-action send-actions)
6173 "Start editing a mail message to be sent.
6174 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6175 to continue editing a message already being composed. SWITCH-FUNCTION
6176 is a function used to switch to and display the mail buffer."
6178 (let ((message-this-is-mail t) replybuffer)
6179 (unless (message-mail-user-agent)
6181 (or switch-function 'message-pop-to-buffer)
6182 ;; Search for the existing message buffer if `continue' is non-nil.
6183 (let ((message-generate-new-buffers
6184 (when (or (not continue)
6185 (eq message-generate-new-buffers 'standard)
6186 (functionp message-generate-new-buffers))
6187 message-generate-new-buffers)))
6188 (message-buffer-name "mail" to))))
6189 ;; FIXME: message-mail should do something if YANK-ACTION is not
6191 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6192 (setq replybuffer (nth 1 yank-action)))
6195 `((To . ,(or to "")) (Subject . ,(or subject "")))
6196 (when other-headers other-headers))
6197 replybuffer send-actions continue switch-function)
6198 ;; FIXME: Should return nil if failure.
6202 (defun message-news (&optional newsgroups subject)
6203 "Start editing a news article to be sent."
6205 (let ((message-this-is-news t))
6206 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6207 (message-setup `((Newsgroups . ,(or newsgroups ""))
6208 (Subject . ,(or subject ""))))))
6210 (defun message-get-reply-headers (wide &optional to-address address-headers)
6211 (let (follow-to mct never-mct to cc author mft recipients extra)
6212 ;; Find all relevant headers we need.
6214 (message-narrow-to-headers-or-head)
6215 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6216 ;; message-header-synonyms.
6217 (setq to (or (message-fetch-field "to")
6218 (and (loop for synonym in message-header-synonyms
6219 when (memq 'Original-To synonym)
6221 (message-fetch-field "original-to")))
6222 cc (message-fetch-field "cc")
6223 extra (when message-extra-wide-headers
6224 (mapconcat 'identity
6225 (mapcar 'message-fetch-field
6226 message-extra-wide-headers)
6228 mct (message-fetch-field "mail-copies-to")
6229 author (or (message-fetch-field "mail-reply-to")
6230 (message-fetch-field "reply-to")
6231 (message-fetch-field "from")
6233 mft (and message-use-mail-followup-to
6234 (message-fetch-field "mail-followup-to"))))
6236 ;; Handle special values of Mail-Copies-To.
6238 (cond ((or (equal (downcase mct) "never")
6239 (equal (downcase mct) "nobody"))
6242 ((or (equal (downcase mct) "always")
6243 (equal (downcase mct) "poster"))
6244 (setq mct author))))
6247 ;; Build (textual) list of new recipient addresses.
6250 (setq recipients (concat ", " author)))
6252 (dolist (header address-headers)
6253 (let ((value (message-fetch-field header)))
6255 (setq recipients (concat recipients ", " value))))))
6257 (string-match "[^ \t,]" mft)
6258 (or (not (eq message-use-mail-followup-to 'ask))
6259 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6260 You should normally obey the Mail-Followup-To: header. In this
6261 article, it has the value of
6265 which directs your response to " (if (string-match "," mft)
6266 "the specified addresses"
6267 "that address only") ".
6269 Most commonly, Mail-Followup-To is used by a mailing list poster to
6270 express that responses should be sent to just the list, and not the
6273 If a message is posted to several mailing lists, Mail-Followup-To may
6274 also be used to direct the following discussion to one list only,
6275 because discussions that are spread over several lists tend to be
6276 fragmented and very difficult to follow.
6278 Also, some source/announcement lists are not intended for discussion;
6279 responses here are directed to other addresses.
6281 You may customize the variable `message-use-mail-followup-to', if you
6282 want to get rid of this query permanently.")))
6283 (setq recipients (concat ", " mft)))
6285 (setq recipients (concat ", " to-address))
6286 ;; If the author explicitly asked for a copy, we don't deny it to them.
6287 (if mct (setq recipients (concat recipients ", " mct))))
6289 (setq recipients (if never-mct "" (concat ", " author)))
6290 (if to (setq recipients (concat recipients ", " to)))
6291 (if cc (setq recipients (concat recipients ", " cc)))
6292 (if extra (setq recipients (concat recipients ", " extra)))
6293 (if mct (setq recipients (concat recipients ", " mct)))))
6294 (if (>= (length recipients) 2)
6295 ;; Strip the leading ", ".
6296 (setq recipients (substring recipients 2)))
6297 ;; Squeeze whitespace.
6298 (while (string-match "[ \t][ \t]+" recipients)
6299 (setq recipients (replace-match " " t t recipients)))
6300 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6301 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6302 (setq recipients (rmail-dont-reply-to recipients)))
6303 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6304 (if (string-equal recipients "")
6305 (setq recipients author))
6306 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6310 (cons (downcase (mail-strip-quoted-names addr)) addr))
6311 (message-tokenize-header recipients)))
6312 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6313 (let ((s recipients))
6315 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6317 ;; Remove hierarchical lists that are contained within each other,
6318 ;; if message-hierarchical-addresses is defined.
6319 (when message-hierarchical-addresses
6320 (let ((plain-addrs (mapcar 'car recipients))
6323 (setq subaddrs (assoc (car plain-addrs)
6324 message-hierarchical-addresses)
6325 plain-addrs (cdr plain-addrs))
6327 (setq subaddrs (cdr subaddrs))
6329 (setq recip (assoc (car subaddrs) recipients)
6330 subaddrs (cdr subaddrs))
6332 (setq recipients (delq recip recipients))))))))
6334 ;; Build the header alist. Allow the user to be asked whether
6335 ;; or not to reply to all recipients in a wide reply.
6336 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6337 (when (and recipients
6338 (or (not message-wide-reply-confirm-recipients)
6339 (y-or-n-p "Reply to all recipients? ")))
6340 (setq recipients (mapconcat
6341 (lambda (addr) (cdr addr)) recipients ", "))
6342 (if (string-match "^ +" recipients)
6343 (setq recipients (substring recipients (match-end 0))))
6344 (push (cons 'Cc recipients) follow-to)))
6347 (defcustom message-simplify-subject-functions
6348 '(message-strip-list-identifiers
6349 message-strip-subject-re
6350 message-strip-subject-trailing-was
6351 message-strip-subject-encoded-words)
6352 "List of functions taking a string argument that simplify subjects.
6353 The functions are applied when replying to a message.
6355 Useful functions to put in this list include:
6356 `message-strip-list-identifiers', `message-strip-subject-re',
6357 `message-strip-subject-trailing-was', and
6358 `message-strip-subject-encoded-words'."
6359 :version "22.1" ;; Gnus 5.10.9
6360 :group 'message-various
6361 :type '(repeat function))
6363 (defun message-simplify-subject (subject &optional functions)
6364 "Return simplified SUBJECT."
6367 (setq functions message-simplify-subject-functions))
6368 (when (and (memq 'message-strip-list-identifiers functions)
6369 gnus-list-identifiers)
6370 (setq subject (message-strip-list-identifiers subject)))
6371 (when (memq 'message-strip-subject-re functions)
6372 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6373 (when (and (memq 'message-strip-subject-trailing-was functions)
6374 message-subject-trailing-was-query)
6375 (setq subject (message-strip-subject-trailing-was subject)))
6376 (when (memq 'message-strip-subject-encoded-words functions)
6377 (setq subject (message-strip-subject-encoded-words subject)))
6381 (defun message-reply (&optional to-address wide)
6382 "Start editing a reply to the article in the current buffer."
6384 (require 'gnus-sum) ; for gnus-list-identifiers
6385 (let ((cur (current-buffer))
6386 from subject date reply-to to cc
6387 references message-id follow-to
6388 (inhibit-point-motion-hooks t)
6389 (message-this-is-mail t)
6392 (message-narrow-to-head-1)
6393 ;; Allow customizations to have their say.
6395 ;; This is a regular reply.
6396 (when (functionp message-reply-to-function)
6398 (setq follow-to (funcall message-reply-to-function))))
6399 ;; This is a followup.
6400 (when (functionp message-wide-reply-to-function)
6403 (funcall message-wide-reply-to-function)))))
6404 (setq message-id (message-fetch-field "message-id" t)
6405 references (message-fetch-field "references")
6406 date (message-fetch-field "date")
6407 from (or (message-fetch-field "from") "nobody")
6408 subject (or (message-fetch-field "subject") "none"))
6410 ;; Strip list identifiers, "Re: ", and "was:"
6411 (setq subject (message-simplify-subject subject))
6413 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6414 (string-match "<[^>]+>" gnus-warning))
6415 (setq message-id (match-string 0 gnus-warning)))
6418 (setq follow-to (message-get-reply-headers wide to-address))))
6420 (unless (message-mail-user-agent)
6421 (message-pop-to-buffer
6422 (message-buffer-name
6423 (if wide "wide reply" "reply") from
6424 (if wide to-address nil))))
6426 (setq message-reply-headers
6427 (vector 0 subject from date message-id references 0 0 ""))
6430 `((Subject . ,subject)
6435 (defun message-wide-reply (&optional to-address)
6436 "Make a \"wide\" reply to the message in the current buffer."
6438 (message-reply to-address t))
6441 (defun message-followup (&optional to-newsgroups)
6442 "Follow up to the message in the current buffer.
6443 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6445 (require 'gnus-sum) ; for gnus-list-identifiers
6446 (let ((cur (current-buffer))
6447 from subject date reply-to mrt mct
6448 references message-id follow-to
6449 (inhibit-point-motion-hooks t)
6450 (message-this-is-news t)
6451 followup-to distribution newsgroups gnus-warning posted-to)
6454 (goto-char (point-min))
6455 (if (search-forward "\n\n" nil t)
6458 (when (functionp message-followup-to-function)
6460 (funcall message-followup-to-function)))
6461 (setq from (message-fetch-field "from")
6462 date (message-fetch-field "date")
6463 subject (or (message-fetch-field "subject") "none")
6464 references (message-fetch-field "references")
6465 message-id (message-fetch-field "message-id" t)
6466 followup-to (message-fetch-field "followup-to")
6467 newsgroups (message-fetch-field "newsgroups")
6468 posted-to (message-fetch-field "posted-to")
6469 reply-to (message-fetch-field "reply-to")
6470 mrt (message-fetch-field "mail-reply-to")
6471 distribution (message-fetch-field "distribution")
6472 mct (message-fetch-field "mail-copies-to"))
6473 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6474 (string-match "<[^>]+>" gnus-warning))
6475 (setq message-id (match-string 0 gnus-warning)))
6476 ;; Remove bogus distribution.
6477 (when (and (stringp distribution)
6478 (let ((case-fold-search t))
6479 (string-match "world" distribution)))
6480 (setq distribution nil))
6481 ;; Strip list identifiers, "Re: ", and "was:"
6482 (setq subject (message-simplify-subject subject))
6485 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6487 (setq message-reply-headers
6488 (vector 0 subject from date message-id references 0 0 ""))
6491 `((Subject . ,subject)
6494 (list (cons 'Newsgroups to-newsgroups)))
6495 (follow-to follow-to)
6496 ((and followup-to message-use-followup-to)
6499 ((equal (downcase followup-to) "poster")
6500 (if (or (eq message-use-followup-to 'use)
6501 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6502 You should normally obey the Followup-To: header.
6504 `Followup-To: poster' sends your response via e-mail instead of news.
6506 A typical situation where `Followup-To: poster' is used is when the poster
6507 does not read the newsgroup, so he wouldn't see any replies sent to it.
6509 You may customize the variable `message-use-followup-to', if you
6510 want to get rid of this query permanently."))
6512 (setq message-this-is-news nil)
6513 (cons 'To (or mrt reply-to from "")))
6514 (cons 'Newsgroups newsgroups)))
6516 (if (or (equal followup-to newsgroups)
6517 (not (eq message-use-followup-to 'ask))
6519 (concat "Obey Followup-To: " followup-to "? ") t "\
6520 You should normally obey the Followup-To: header.
6522 `Followup-To: " followup-to "'
6523 directs your response to " (if (string-match "," followup-to)
6524 "the specified newsgroups"
6525 "that newsgroup only") ".
6527 If a message is posted to several newsgroups, Followup-To is often
6528 used to direct the following discussion to one newsgroup only,
6529 because discussions that are spread over several newsgroup tend to
6530 be fragmented and very difficult to follow.
6532 Also, some source/announcement newsgroups are not intended for discussion;
6533 responses here are directed to other newsgroups.
6535 You may customize the variable `message-use-followup-to', if you
6536 want to get rid of this query permanently."))
6537 (cons 'Newsgroups followup-to)
6538 (cons 'Newsgroups newsgroups))))))
6540 `((Newsgroups . ,posted-to)))
6542 `((Newsgroups . ,newsgroups))))
6543 ,@(and distribution (list (cons 'Distribution distribution)))
6545 (not (or (equal (downcase mct) "never")
6546 (equal (downcase mct) "nobody"))))
6547 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6548 (equal (downcase mct) "poster"))
6549 (or mrt reply-to from "")
6554 (defun message-is-yours-p ()
6555 "Non-nil means current article is yours.
6556 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6557 are yours except those that have Cancel-Lock header not belonging to you.
6558 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6559 regexp to match all of yours addresses."
6560 ;; Canlock-logic as suggested by Per Abrahamsen
6561 ;; <abraham@dina.kvl.dk>
6563 ;; IF article has cancel-lock THEN
6564 ;; IF we can verify it THEN
6567 ;; error: cancellock: article is not yours
6569 ;; Use old rules, comparing sender...
6572 (message-narrow-to-head-1)
6573 (if (message-fetch-field "Cancel-Lock")
6574 (if (null (canlock-verify))
6576 (error "Failed to verify Cancel-lock: This article is not yours"))
6579 (message-gnksa-enable-p 'cancel-messages)
6580 (and (setq sender (message-fetch-field "sender"))
6581 (string-equal (downcase sender)
6582 (downcase (message-make-sender))))
6583 ;; Email address in From field equals to our address
6584 (and (setq from (message-fetch-field "from"))
6586 (downcase (car (mail-header-parse-address from)))
6587 (downcase (car (mail-header-parse-address
6588 (message-make-from))))))
6589 ;; Email address in From field matches
6590 ;; 'message-alternative-emails' regexp
6592 message-alternative-emails
6594 message-alternative-emails
6595 (car (mail-header-parse-address from))))))))))
6598 (defun message-cancel-news (&optional arg)
6599 "Cancel an article you posted.
6600 If ARG, allow editing of the cancellation message."
6602 (unless (message-news-p)
6603 (error "This is not a news article; canceling is impossible"))
6604 (let (from newsgroups message-id distribution buf)
6606 ;; Get header info from original article.
6608 (message-narrow-to-head-1)
6609 (setq from (message-fetch-field "from")
6610 newsgroups (message-fetch-field "newsgroups")
6611 message-id (message-fetch-field "message-id" t)
6612 distribution (message-fetch-field "distribution")))
6613 ;; Make sure that this article was written by the user.
6614 (unless (message-is-yours-p)
6615 (error "This article is not yours"))
6616 (when (yes-or-no-p "Do you really want to cancel this article? ")
6617 ;; Make control message.
6620 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6622 (insert "Newsgroups: " newsgroups "\n"
6624 "Subject: cmsg cancel " message-id "\n"
6625 "Control: cancel " message-id "\n"
6627 (concat "Distribution: " distribution "\n")
6629 mail-header-separator "\n"
6630 message-cancel-message)
6631 (run-hooks 'message-cancel-hook)
6633 (message "Canceling your article...")
6634 (if (let ((message-syntax-checks
6635 'dont-check-for-anything-just-trust-me))
6636 (funcall message-send-news-function))
6637 (message "Canceling your article...done"))
6638 (kill-buffer buf))))))
6641 (defun message-supersede ()
6642 "Start composing a message to supersede the current message.
6643 This is done simply by taking the old article and adding a Supersedes
6644 header line with the old Message-ID."
6646 (let ((cur (current-buffer)))
6647 ;; Check whether the user owns the article that is to be superseded.
6648 (unless (message-is-yours-p)
6649 (error "This article is not yours"))
6650 ;; Get a normal message buffer.
6651 (message-pop-to-buffer (message-buffer-name "supersede"))
6652 (insert-buffer-substring cur)
6654 (message-narrow-to-head-1)
6655 ;; Remove unwanted headers.
6656 (when message-ignored-supersedes-headers
6657 (message-remove-header message-ignored-supersedes-headers t))
6658 (goto-char (point-min))
6659 (if (not (re-search-forward "^Message-ID: " nil t))
6660 (error "No Message-ID in this article")
6661 (replace-match "Supersedes: " t t))
6662 (goto-char (point-max))
6663 (insert mail-header-separator)
6668 (defun message-recover ()
6669 "Reread contents of current buffer from its last auto-save file."
6671 (let ((file-name (make-auto-save-file-name)))
6672 (cond ((save-window-excursion
6673 (if (not (eq system-type 'vax-vms))
6674 (with-output-to-temp-buffer "*Directory*"
6675 (with-current-buffer standard-output
6676 (fundamental-mode)) ; for Emacs 20.4+
6677 (buffer-disable-undo standard-output)
6678 (let ((default-directory "/"))
6680 "ls" nil standard-output nil "-l" file-name))))
6681 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6682 (let ((buffer-read-only nil))
6684 (insert-file-contents file-name nil)))
6685 (t (error "message-recover cancelled")))))
6687 ;;; Washing Subject:
6689 (defun message-wash-subject (subject)
6690 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6691 Previous forwarders, replyers, etc. may add it."
6694 (goto-char (point-min))
6695 ;; strip Re/Fwd stuff off the beginning
6696 (while (re-search-forward
6697 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6700 ;; and gnus-style forwards [foo@bar.com] subject
6701 (goto-char (point-min))
6702 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6706 (goto-char (point-max))
6707 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6710 ;; and finally, any whitespace that was left-over
6711 (goto-char (point-min))
6712 (while (re-search-forward "^[ \t]+" nil t)
6714 (goto-char (point-max))
6715 (while (re-search-backward "[ \t]+$" nil t)
6720 ;;; Forwarding messages.
6722 (defvar message-forward-decoded-p nil
6723 "Non-nil means the original message is decoded.")
6725 (defun message-forward-subject-name-subject (subject)
6726 "Generate a SUBJECT for a forwarded message.
6727 The form is: [Source] Subject, where if the original message was mail,
6728 Source is the name of the sender, and if the original message was
6729 news, Source is the list of newsgroups is was posted to."
6730 (let* ((group (message-fetch-field "newsgroups"))
6731 (from (message-fetch-field "from"))
6734 (gnus-group-decoded-name group)
6736 (car (gnus-extract-address-components from))
6737 (cadr (gnus-extract-address-components from))))
6740 (if message-forward-decoded-p
6742 (mail-decode-encoded-word-string prefix))
6745 (defun message-forward-subject-author-subject (subject)
6746 "Generate a SUBJECT for a forwarded message.
6747 The form is: [Source] Subject, where if the original message was mail,
6748 Source is the sender, and if the original message was news, Source is
6749 the list of newsgroups is was posted to."
6750 (let* ((group (message-fetch-field "newsgroups"))
6753 (gnus-group-decoded-name group)
6754 (or (message-fetch-field "from")
6757 (if message-forward-decoded-p
6759 (mail-decode-encoded-word-string prefix))
6762 (defun message-forward-subject-fwd (subject)
6763 "Generate a SUBJECT for a forwarded message.
6764 The form is: Fwd: Subject, where Subject is the original subject of
6766 (if (string-match "^Fwd: " subject)
6768 (concat "Fwd: " subject)))
6770 (defun message-make-forward-subject ()
6771 "Return a Subject header suitable for the message in the current buffer."
6774 (message-narrow-to-head-1)
6775 (let ((funcs message-make-forward-subject-function)
6776 (subject (message-fetch-field "Subject")))
6779 (if message-forward-decoded-p
6781 (mail-decode-encoded-word-string subject))
6783 (when message-wash-forwarded-subjects
6784 (setq subject (message-wash-subject subject)))
6785 ;; Make sure funcs is a list.
6788 (setq funcs (list funcs)))
6789 ;; Apply funcs in order, passing subject generated by previous
6790 ;; func to the next one.
6791 (dolist (func funcs)
6792 (when (functionp func)
6793 (setq subject (funcall func subject))))
6797 (defvar gnus-article-decoded-p))
6801 (defun message-forward (&optional news digest)
6802 "Forward the current message via mail.
6803 Optional NEWS will use news to forward instead of mail.
6804 Optional DIGEST will use digest to forward."
6806 (let* ((cur (current-buffer))
6807 (message-forward-decoded-p
6808 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6809 gnus-article-decoded-p ;; In an article buffer.
6810 message-forward-decoded-p))
6811 (subject (message-make-forward-subject)))
6813 (message-news nil subject)
6814 (message-mail nil subject))
6815 (message-forward-make-body cur digest)))
6817 (defun message-forward-make-body-plain (forward-buffer)
6819 "\n-------------------- Start of forwarded message --------------------\n")
6820 (let ((b (point)) e)
6823 (mm-disable-multibyte)
6825 (with-current-buffer forward-buffer
6826 (mm-with-unibyte-current-buffer (buffer-string))))
6827 (mm-enable-multibyte)
6829 (goto-char (point-min))
6830 (when (looking-at "From ")
6831 (replace-match "X-From-Line: "))
6835 "\n-------------------- End of forwarded message --------------------\n")
6836 (message-remove-ignored-headers b e)))
6838 (defun message-remove-ignored-headers (b e)
6839 (when message-forward-ignored-headers
6841 (narrow-to-region b e)
6843 (narrow-to-region (point)
6844 (or (search-forward "\n\n" nil t) (point)))
6845 (let ((ignored (if (stringp message-forward-ignored-headers)
6846 (list message-forward-ignored-headers)
6847 message-forward-ignored-headers)))
6848 (dolist (elem ignored)
6849 (message-remove-header elem t))))))
6851 (defun message-forward-make-body-mime (forward-buffer)
6852 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6853 (let ((b (point)) e)
6855 (narrow-to-region (point) (point))
6856 (mml-insert-buffer forward-buffer)
6857 (goto-char (point-min))
6858 (when (looking-at "From ")
6859 (replace-match "X-From-Line: "))
6860 (goto-char (point-max)))
6862 (insert "<#/part>\n")))
6864 (defun message-forward-make-body-mml (forward-buffer)
6865 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6866 (let ((b (point)) e)
6867 (if (not message-forward-decoded-p)
6870 (mm-disable-multibyte)
6872 (with-current-buffer forward-buffer
6873 (mm-with-unibyte-current-buffer (buffer-string))))
6874 (mm-enable-multibyte)
6876 (goto-char (point-min))
6877 (when (looking-at "From ")
6878 (replace-match "X-From-Line: "))
6881 (narrow-to-region (point) (point))
6882 (mml-insert-buffer forward-buffer)
6883 (goto-char (point-min))
6884 (when (looking-at "From ")
6885 (replace-match "X-From-Line: "))
6886 (goto-char (point-max))))
6888 (insert "<#/mml>\n")
6889 (when (and (not message-forward-decoded-p)
6890 message-forward-ignored-headers)
6891 (message-remove-ignored-headers b e))))
6893 (defun message-forward-make-body-digest-plain (forward-buffer)
6895 "\n-------------------- Start of forwarded message --------------------\n")
6896 (let ((b (point)) e)
6897 (mml-insert-buffer forward-buffer)
6900 "\n-------------------- End of forwarded message --------------------\n")))
6902 (defun message-forward-make-body-digest-mime (forward-buffer)
6903 (insert "\n<#multipart type=digest>\n")
6904 (let ((b (point)) e)
6905 (insert-buffer-substring forward-buffer)
6907 (insert "<#/multipart>\n")
6909 (narrow-to-region b e)
6911 (narrow-to-region (point)
6912 (or (search-forward "\n\n" nil t) (point)))
6913 (delete-region (point-min) (point-max)))))
6915 (defun message-forward-make-body-digest (forward-buffer)
6916 (if message-forward-as-mime
6917 (message-forward-make-body-digest-mime forward-buffer)
6918 (message-forward-make-body-digest-plain forward-buffer)))
6921 (autoload 'mm-uu-dissect-text-parts "mm-uu")
6922 (autoload 'mm-uu-dissect "mm-uu"))
6924 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
6925 "Say whether the current buffer contains signed or encrypted message.
6926 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
6927 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
6928 is for the internal use."
6930 (let ((mm-decrypt-option 'never)
6931 (mm-verify-option 'never))
6932 (if (setq handles (mm-dissect-buffer nil t))
6933 (unless dont-emulate-mime
6934 (mm-uu-dissect-text-parts handles))
6935 (unless dont-emulate-mime
6936 (setq handles (mm-uu-dissect))))))
6937 ;; Check text/plain message in which there is a signed or encrypted
6938 ;; body that has been encoded by B or Q.
6939 (unless (or handles dont-emulate-mime)
6940 (let ((cur (current-buffer))
6941 (mm-decrypt-option 'never)
6942 (mm-verify-option 'never))
6944 (insert-buffer-substring cur)
6945 (when (setq handles (mm-dissect-buffer t t))
6947 (bufferp (car handles))
6948 (mm-destroy-parts handles))
6949 (equal (mm-handle-media-type handles) "text/plain"))
6951 (mm-decode-content-transfer-encoding
6952 (mm-handle-encoding handles))
6953 (setq handles (mm-uu-dissect)))
6954 (setq handles nil))))))
6958 (dolist (handle (if (stringp (car handles))
6959 (if (member (car handles)
6960 '("multipart/signed"
6961 "multipart/encrypted"))
6965 (if (stringp (car handle))
6966 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
6968 (when (and (bufferp (car handle))
6969 (equal (mm-handle-media-type handle)
6971 (with-current-buffer (mm-handle-buffer handle)
6972 (when (message-signed-or-encrypted-p dont-emulate-mime)
6973 (throw 'found t)))))))
6974 (mm-destroy-parts handles))))
6977 (defun message-forward-make-body (forward-buffer &optional digest)
6978 ;; Put point where we want it before inserting the forwarded
6980 (if message-forward-before-signature
6982 (goto-char (point-max)))
6984 (message-forward-make-body-digest forward-buffer)
6985 (if message-forward-as-mime
6986 (if (and message-forward-show-mml
6987 (not (and (eq message-forward-show-mml 'best)
6988 ;; Use the raw form in the body if it contains
6989 ;; signed or encrypted message so as not to be
6990 ;; destroyed by re-encoding.
6991 (with-current-buffer forward-buffer
6993 (message-signed-or-encrypted-p)
6995 (message-forward-make-body-mml forward-buffer)
6996 (message-forward-make-body-mime forward-buffer))
6997 (message-forward-make-body-plain forward-buffer)))
6998 (message-position-point))
7001 (defun message-forward-rmail-make-body (forward-buffer)
7002 (save-window-excursion
7003 (set-buffer forward-buffer)
7004 (if (rmail-msg-is-pruned)
7005 (rmail-msg-restore-non-pruned-header)))
7006 (message-forward-make-body forward-buffer))
7008 (eval-when-compile (defvar rmail-enable-mime-composing))
7010 ;; Fixme: Should have defcustom.
7012 (defun message-insinuate-rmail ()
7013 "Let RMAIL use message to forward."
7015 (setq rmail-enable-mime-composing t)
7016 (setq rmail-insert-mime-forwarded-message-function
7017 'message-forward-rmail-make-body))
7020 (defun message-resend (address)
7021 "Resend the current article to ADDRESS."
7023 (list (message-read-from-minibuffer "Resend message to: ")))
7024 (message "Resending message to %s..." address)
7026 (let ((cur (current-buffer))
7028 ;; We first set up a normal mail buffer.
7029 (unless (message-mail-user-agent)
7030 (set-buffer (get-buffer-create " *message resend*"))
7032 (let ((message-this-is-mail t)
7033 message-generate-hashcash
7035 (message-setup `((To . ,address))))
7036 ;; Insert our usual headers.
7037 (message-generate-headers '(From Date To Message-ID))
7038 (message-narrow-to-headers)
7039 ;; Remove X-Draft-From header etc.
7040 (message-remove-header message-ignored-mail-headers t)
7041 ;; Rename them all to "Resent-*".
7042 (goto-char (point-min))
7043 (while (re-search-forward "^[A-Za-z]" nil t)
7048 (delete-region (point) (point-max))
7050 ;; Insert the message to be resent.
7051 (insert-buffer-substring cur)
7052 (goto-char (point-min))
7053 (search-forward "\n\n")
7056 (narrow-to-region beg (point))
7057 (message-remove-header message-ignored-resent-headers t)
7058 (goto-char (point-max)))
7059 (insert mail-header-separator)
7060 ;; Rename all old ("Also-")Resent headers.
7061 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7064 ;; Quote any "From " lines at the beginning.
7066 (when (looking-at "From ")
7067 (replace-match "X-From-Line: "))
7069 (let ((message-inhibit-body-encoding t)
7070 message-required-mail-headers
7071 message-generate-hashcash
7072 rfc2047-encode-encoded-words)
7073 (message-send-mail))
7074 (kill-buffer (current-buffer)))
7075 (message "Resending message to %s...done" address)))
7078 (defun message-bounce ()
7079 "Re-mail the current message.
7080 This only makes sense if the current message is a bounce message that
7081 contains some mail you have written which has been bounced back to
7084 (let ((handles (mm-dissect-buffer t))
7086 (message-pop-to-buffer (message-buffer-name "bounce"))
7087 (if (stringp (car handles))
7088 ;; This is a MIME bounce.
7089 (mm-insert-part (car (last handles)))
7090 ;; This is a non-MIME bounce, so we try to remove things
7092 (mm-insert-part handles)
7094 (goto-char (point-min))
7095 (re-search-forward "\n\n+" nil t)
7096 (setq boundary (point))
7097 ;; We remove everything before the bounced mail.
7098 (if (or (re-search-forward message-unsent-separator nil t)
7100 (search-forward "\n\n" nil 'move)
7101 (re-search-backward "^Return-Path:.*\n" boundary t)))
7104 (delete-region (point-min)
7105 (if (re-search-forward "^[^ \n\t]+:" nil t)
7108 (goto-char boundary)
7109 (when (re-search-backward "^.?From .*\n" nil t)
7110 (delete-region (match-beginning 0) (match-end 0)))))
7113 (message-narrow-to-head-1)
7114 (message-remove-header message-ignored-bounced-headers t)
7115 (goto-char (point-max))
7116 (insert mail-header-separator))
7117 (message-position-point)))
7120 ;;; Interactive entry points for new message buffers.
7124 (defun message-mail-other-window (&optional to subject)
7125 "Like `message-mail' command, but display mail buffer in another window."
7127 (unless (message-mail-user-agent)
7128 (let ((pop-up-windows t)
7129 (special-display-buffer-names nil)
7130 (special-display-regexps nil)
7131 (same-window-buffer-names nil)
7132 (same-window-regexps nil))
7133 (message-pop-to-buffer (message-buffer-name "mail" to))))
7134 (let ((message-this-is-mail t))
7135 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7136 nil nil nil 'switch-to-buffer-other-window)))
7139 (defun message-mail-other-frame (&optional to subject)
7140 "Like `message-mail' command, but display mail buffer in another frame."
7142 (unless (message-mail-user-agent)
7143 (let ((pop-up-frames t)
7144 (special-display-buffer-names nil)
7145 (special-display-regexps nil)
7146 (same-window-buffer-names nil)
7147 (same-window-regexps nil))
7148 (message-pop-to-buffer (message-buffer-name "mail" to))))
7149 (let ((message-this-is-mail t))
7150 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7151 nil nil nil 'switch-to-buffer-other-frame)))
7154 (defun message-news-other-window (&optional newsgroups subject)
7155 "Start editing a news article to be sent."
7157 (let ((pop-up-windows t)
7158 (special-display-buffer-names nil)
7159 (special-display-regexps nil)
7160 (same-window-buffer-names nil)
7161 (same-window-regexps nil))
7162 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7163 (let ((message-this-is-news t))
7164 (message-setup `((Newsgroups . ,(or newsgroups ""))
7165 (Subject . ,(or subject ""))))))
7168 (defun message-news-other-frame (&optional newsgroups subject)
7169 "Start editing a news article to be sent."
7171 (let ((pop-up-frames t)
7172 (special-display-buffer-names nil)
7173 (special-display-regexps nil)
7174 (same-window-buffer-names nil)
7175 (same-window-regexps nil))
7176 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7177 (let ((message-this-is-news t))
7178 (message-setup `((Newsgroups . ,(or newsgroups ""))
7179 (Subject . ,(or subject ""))))))
7183 ;; This code should be moved to underline.el (from which it is stolen).
7186 (defun message-bold-region (start end)
7187 "Bold all nonblank characters in the region.
7188 Works by overstriking characters.
7189 Called from program, takes two arguments START and END
7190 which specify the range to operate on."
7193 (let ((end1 (make-marker)))
7194 (move-marker end1 (max start end))
7195 (goto-char (min start end))
7196 (while (< (point) end1)
7197 (or (looking-at "[_\^@- ]")
7198 (insert (char-after) "\b"))
7199 (forward-char 1)))))
7202 (defun message-unbold-region (start end)
7203 "Remove all boldness (overstruck characters) in the region.
7204 Called from program, takes two arguments START and END
7205 which specify the range to operate on."
7208 (let ((end1 (make-marker)))
7209 (move-marker end1 (max start end))
7210 (goto-char (min start end))
7211 (while (search-forward "\b" end1 t)
7212 (if (eq (char-after) (char-after (- (point) 2)))
7213 (delete-char -2))))))
7215 (defun message-exchange-point-and-mark ()
7216 "Exchange point and mark, but don't activate region if it was inactive."
7218 (message-mark-active-p)
7219 (exchange-point-and-mark))
7220 (setq mark-active nil)))
7222 (defalias 'message-make-overlay 'make-overlay)
7223 (defalias 'message-delete-overlay 'delete-overlay)
7224 (defalias 'message-overlay-put 'overlay-put)
7225 (defun message-kill-all-overlays ()
7226 (if (featurep 'xemacs)
7227 (map-extents (lambda (extent ignore) (delete-extent extent)))
7228 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7230 ;; Support for toolbar
7232 (defvar tool-bar-mode))
7234 ;; Note: The :set function in the `message-tool-bar*' variables will only
7235 ;; affect _new_ message buffers. We might add a function that walks thru all
7236 ;; message-mode buffers and force the update.
7237 (defun message-tool-bar-update (&optional symbol value)
7238 "Update message mode toolbar.
7239 Setter function for custom variables."
7240 (setq-default message-tool-bar-map nil)
7242 ;; When used as ":set" function:
7243 (set-default symbol value)))
7245 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7246 'message-tool-bar-gnome
7247 'message-tool-bar-retro)
7248 "Specifies the message mode tool bar.
7250 It can be either a list or a symbol refering to a list. See
7251 `gmm-tool-bar-from-list' for the format of the list. The
7252 default key map is `message-mode-map'.
7254 Pre-defined symbols include `message-tool-bar-gnome' and
7255 `message-tool-bar-retro'."
7256 :type '(repeat gmm-tool-bar-list-item)
7257 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7258 (const :tag "Retro look" message-tool-bar-retro)
7259 (repeat :tag "User defined list" gmm-tool-bar-item)
7261 :version "23.0" ;; No Gnus
7262 :initialize 'custom-initialize-default
7263 :set 'message-tool-bar-update
7266 (defcustom message-tool-bar-gnome
7267 '((ispell-message "spell" nil
7268 :visible (or (not (boundp 'flyspell-mode))
7269 (not flyspell-mode)))
7270 (flyspell-buffer "spell" t
7271 :visible (and (boundp 'flyspell-mode)
7273 :help "Flyspell whole buffer")
7274 (gmm-ignore "separator")
7275 (message-send-and-exit "mail/send")
7276 (message-dont-send "mail/save-draft")
7277 (message-kill-buffer "close") ;; stock_cancel
7278 (mml-attach-file "attach" mml-mode-map)
7279 (mml-preview "mail/preview" mml-mode-map)
7280 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7281 (message-insert-importance-high "important" nil :visible nil)
7282 (message-insert-importance-low "unimportant" nil :visible nil)
7283 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7284 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7285 (message-info "help" t :help "Message manual"))
7286 "List of items for the message tool bar (GNOME style).
7288 See `gmm-tool-bar-from-list' for details on the format of the list."
7289 :type '(repeat gmm-tool-bar-item)
7290 :version "23.0" ;; No Gnus
7291 :initialize 'custom-initialize-default
7292 :set 'message-tool-bar-update
7295 (defcustom message-tool-bar-retro
7296 '(;; Old Emacs 21 icon for consistency.
7297 (message-send-and-exit "gnus/mail_send")
7298 (message-kill-buffer "close")
7299 (message-dont-send "cancel")
7300 (mml-attach-file "attach" mml-mode-map)
7301 (ispell-message "spell")
7302 (mml-preview "preview" mml-mode-map)
7303 (message-insert-importance-high "gnus/important")
7304 (message-insert-importance-low "gnus/unimportant")
7305 (message-insert-disposition-notification-to "gnus/receipt"))
7306 "List of items for the message tool bar (retro style).
7308 See `gmm-tool-bar-from-list' for details on the format of the list."
7309 :type '(repeat gmm-tool-bar-item)
7310 :version "23.0" ;; No Gnus
7311 :initialize 'custom-initialize-default
7312 :set 'message-tool-bar-update
7315 (defcustom message-tool-bar-zap-list
7316 '(new-file open-file dired kill-buffer write-file
7317 print-buffer customize help)
7318 "List of icon items from the global tool bar.
7319 These items are not displayed on the message mode tool bar.
7321 See `gmm-tool-bar-from-list' for the format of the list."
7322 :type 'gmm-tool-bar-zap-list
7323 :version "23.0" ;; No Gnus
7324 :initialize 'custom-initialize-default
7325 :set 'message-tool-bar-update
7328 (defvar image-load-path)
7330 (defun message-make-tool-bar (&optional force)
7331 "Make a message mode tool bar from `message-tool-bar-list'.
7332 When FORCE, rebuild the tool bar."
7333 (when (and (not (featurep 'xemacs))
7334 (boundp 'tool-bar-mode)
7336 (or (not message-tool-bar-map) force))
7337 (setq message-tool-bar-map
7339 (gmm-image-load-path-for-library "message"
7340 "mail/save-draft.xpm"
7342 (image-load-path (cons (car load-path)
7343 (when (boundp 'image-load-path)
7345 (gmm-tool-bar-from-list message-tool-bar
7346 message-tool-bar-zap-list
7347 'message-mode-map))))
7348 message-tool-bar-map)
7350 ;;; Group name completion.
7352 (defcustom message-newgroups-header-regexp
7353 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7354 "Regexp that match headers that lists groups."
7358 (defcustom message-completion-alist
7359 (list (cons message-newgroups-header-regexp 'message-expand-group)
7360 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7361 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7362 . message-expand-name)
7363 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7364 . message-expand-name))
7365 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7368 :type '(alist :key-type regexp :value-type function))
7370 (defcustom message-expand-name-databases
7372 "List of databases to try for name completion (`message-expand-name').
7373 Each element is a symbol and can be `bbdb' or `eudc'."
7375 :type '(set (const bbdb) (const eudc)))
7377 (defcustom message-tab-body-function nil
7378 "*Function to execute when `message-tab' (TAB) is executed in the body.
7379 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7382 :link '(custom-manual "(message)Various Commands")
7383 :type '(choice (const nil)
7386 (defun message-tab ()
7387 "Complete names according to `message-completion-alist'.
7388 Execute function specified by `message-tab-body-function' when not in
7391 (let ((alist message-completion-alist))
7393 (let ((mail-abbrev-mode-regexp (caar alist)))
7394 (not (mail-abbrev-in-expansion-header-p))))
7395 (setq alist (cdr alist)))
7396 (funcall (or (cdar alist) message-tab-body-function
7397 (lookup-key text-mode-map "\t")
7398 (lookup-key global-map "\t")
7399 'indent-relative))))
7404 (let ((standard-output (current-buffer)))
7405 (eval '(display-completion-list nil "")))
7406 (defalias 'message-display-completion-list 'display-completion-list))
7407 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7408 (defun message-display-completion-list (completions &optional ignore)
7409 "Display the list of completions, COMPLETIONS, using `standard-output'."
7410 (display-completion-list completions)))))
7412 (defun message-expand-group ()
7413 "Expand the group name under point."
7414 (let* ((b (save-excursion
7419 (skip-chars-forward "^:")
7422 (skip-chars-backward "^, \t\n") (point))))
7423 (completion-ignore-case t)
7424 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7426 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7427 (completions (all-completions string hashtb))
7429 (delete-region b (point))
7431 ((= (length completions) 1)
7432 (if (string= (car completions) string)
7435 (message "Only matching group"))
7436 (insert (car completions))))
7437 ((and (setq comp (try-completion string hashtb))
7438 (not (string= comp string)))
7443 (message "No matching groups")
7444 (save-selected-window
7445 (pop-to-buffer "*Completions*")
7446 (buffer-disable-undo)
7447 (let ((buffer-read-only nil))
7449 (let ((standard-output (current-buffer)))
7450 (message-display-completion-list (sort completions 'string<)
7452 (setq buffer-read-only nil)
7453 (goto-char (point-min))
7454 (delete-region (point) (progn (forward-line 3) (point))))))))))
7456 (defun message-expand-name ()
7457 (cond ((and (memq 'eudc message-expand-name-databases)
7458 (boundp 'eudc-protocol)
7460 (eudc-expand-inline))
7461 ((and (memq 'bbdb message-expand-name-databases)
7462 (fboundp 'bbdb-complete-name))
7463 (bbdb-complete-name))
7469 (defun message-talkative-question (ask question show &rest text)
7470 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7471 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7472 The following arguments may contain lists of values."
7474 (setq text (message-flatten-list text)))
7475 (save-window-excursion
7477 (with-output-to-temp-buffer " *MESSAGE information message*"
7478 (set-buffer " *MESSAGE information message*")
7479 (fundamental-mode) ; for Emacs 20.4+
7480 (mapcar 'princ text)
7481 (goto-char (point-min))))
7482 (funcall ask question))
7483 (funcall ask question)))
7485 (defun message-flatten-list (list)
7486 "Return a new, flat list that contains all elements of LIST.
7488 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7491 (apply 'append (mapcar 'message-flatten-list list)))
7495 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7496 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7497 Then clone the local variables and values from the old buffer to the
7498 new one, cloning only the locals having a substring matching the
7500 (let ((oldbuf (current-buffer)))
7502 (set-buffer (generate-new-buffer name))
7503 (message-clone-locals oldbuf varstr)
7506 (defun message-clone-locals (buffer &optional varstr)
7507 "Clone the local variables from BUFFER to the current buffer."
7508 (let ((locals (save-excursion
7510 (buffer-local-variables)))
7511 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7514 (when (and (consp local)
7516 (string-match regexp (symbol-name (car local)))
7518 (string-match varstr (symbol-name (car local)))))
7520 (set (make-local-variable (car local))
7528 (defvar message-inhibit-body-encoding nil)
7530 (defun message-encode-message-body ()
7531 (unless message-inhibit-body-encoding
7532 (let ((mail-parse-charset (or mail-parse-charset
7533 message-default-charset))
7534 (case-fold-search t)
7535 lines content-type-p)
7538 (narrow-to-region (point) (point-max))
7539 (let ((new (mml-generate-mime)))
7541 (delete-region (point-min) (point-max))
7543 (goto-char (point-min))
7544 (if (eq (aref new 0) ?\n)
7546 (search-forward "\n\n")
7547 (setq lines (buffer-substring (point-min) (1- (point))))
7548 (delete-region (point-min) (point))))))
7550 (message-narrow-to-headers-or-head)
7551 (message-remove-header "Mime-Version")
7552 (goto-char (point-max))
7553 (insert "MIME-Version: 1.0\n")
7556 (setq content-type-p
7558 (re-search-backward "^Content-Type:" nil t))))
7560 (message-narrow-to-headers-or-head)
7561 (message-remove-first-header "Content-Type")
7562 (message-remove-first-header "Content-Transfer-Encoding"))
7563 ;; We always make sure that the message has a Content-Type
7564 ;; header. This is because some broken MTAs and MUAs get
7565 ;; awfully confused when confronted with a message with a
7566 ;; MIME-Version header and without a Content-Type header. For
7567 ;; instance, Solaris' /usr/bin/mail.
7568 (unless content-type-p
7569 (goto-char (point-min))
7570 ;; For unknown reason, MIME-Version doesn't exist.
7571 (when (re-search-forward "^MIME-Version:" nil t)
7573 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7575 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7576 "Read from the minibuffer while providing abbrev expansion."
7577 (if (fboundp 'mail-abbrevs-setup)
7578 (let ((mail-abbrev-mode-regexp "")
7579 (minibuffer-setup-hook 'mail-abbrevs-setup)
7580 (minibuffer-local-map message-minibuffer-local-map))
7581 (read-from-minibuffer prompt initial-contents))
7582 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7583 (minibuffer-local-map message-minibuffer-local-map))
7584 (read-string prompt initial-contents))))
7586 (defun message-use-alternative-email-as-from ()
7587 "Set From field of the outgoing message to the first matching
7588 address in `message-alternative-emails', looking at To, Cc and
7589 From headers in the original article."
7590 (require 'mail-utils)
7591 (let* ((fields '("To" "Cc" "From"))
7594 (mail-strip-quoted-names
7595 (mapconcat 'message-fetch-reply-field fields ","))
7599 (if (string-match message-alternative-emails (car emails))
7600 (setq email (car emails)
7603 (unless (or (not email) (equal email user-mail-address))
7604 (message-remove-header "From")
7605 (goto-char (point-max))
7606 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7609 (defun message-options-get (symbol)
7610 (cdr (assq symbol message-options)))
7612 (defun message-options-set (symbol value)
7613 (let ((the-cons (assq symbol message-options)))
7616 (setcdr the-cons value)
7617 (setq message-options (delq the-cons message-options)))
7619 (push (cons symbol value) message-options))))
7622 (defun message-options-set-recipient ()
7624 (message-narrow-to-headers-or-head)
7625 (message-options-set 'message-sender
7626 (mail-strip-quoted-names
7627 (message-fetch-field "from")))
7628 (message-options-set 'message-recipients
7629 (mail-strip-quoted-names
7630 (let ((to (message-fetch-field "to"))
7631 (cc (message-fetch-field "cc"))
7632 (bcc (message-fetch-field "bcc")))
7635 (if (and to cc) ", ")
7637 (if (and (or to cc) bcc) ", ")
7640 (defun message-hide-headers ()
7641 "Hide headers based on the `message-hidden-headers' variable."
7642 (let ((regexps (if (stringp message-hidden-headers)
7643 (list message-hidden-headers)
7644 message-hidden-headers))
7645 (inhibit-point-motion-hooks t)
7646 (after-change-functions nil)
7651 (message-narrow-to-headers)
7652 (goto-char (point-min))
7654 (if (not (message-hide-header-p regexps))
7655 (message-next-header)
7656 (let ((begin (point))
7658 (message-next-header)
7659 (setq header (buffer-substring begin (point))
7660 header-len (- (point) begin))
7661 (delete-region begin (point))
7662 (goto-char (1+ end-of-headers))
7664 (setq end-of-headers
7665 (+ end-of-headers header-len))))))))
7666 (narrow-to-region (1+ end-of-headers) (point-max))))
7668 (defun message-hide-header-p (regexps)
7671 (when (eq (car regexps) 'not)
7674 (dolist (regexp regexps)
7675 (setq result (or result (looking-at regexp))))
7680 (defun message-put-addresses-in-ecomplete ()
7681 (dolist (header '("to" "cc" "from" "reply-to"))
7682 (let ((value (message-field-value header)))
7683 (dolist (string (mail-header-parse-addresses value 'raw))
7685 (gnus-replace-in-string
7686 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
7687 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
7691 (defun message-display-abbrev (&optional choose)
7692 "Display the next possible abbrev for the text before point."
7693 (interactive (list t))
7694 (when (and (member (char-after (point-at-bol)) '(?C ?T ? ))
7695 (message-point-in-header-p)
7698 (message-narrow-to-field)
7699 (goto-char (point-min))
7700 (looking-at "To\\|Cc"))))
7701 (let* ((end (point))
7702 (start (save-excursion
7703 (and (re-search-backward "[\n\t ]" nil t)
7705 (word (when start (buffer-substring start end)))
7706 (match (when (and word
7707 (not (zerop (length word))))
7708 (ecomplete-display-matches 'mail word choose))))
7709 (when (and choose match)
7710 (delete-region start end)
7713 (when (featurep 'xemacs)
7714 (require 'messagexmas)
7715 (message-xmas-redefine))
7719 (run-hooks 'message-load-hook)
7722 ;; coding: iso-8859-1
7725 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
7726 ;;; message.el ends here