1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
33 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
42 ;; This is apparently necessary even though things are autoloaded.
43 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
44 ;; require mailabbrev here.
45 (if (featurep 'xemacs
)
46 (require 'mail-abbrevs
)
47 (require 'mailabbrev
))
53 (autoload 'mailclient-send-it
"mailclient") ;; Emacs 22 or contrib/
55 (defvar gnus-message-group-art
)
56 (defvar gnus-list-identifiers
) ; gnus-sum is required where necessary
57 (defvar rmail-enable-mime-composing
)
59 (defgroup message
'((user-mail-address custom-variable
)
60 (user-full-name custom-variable
))
61 "Mail and news message composing."
62 :link
'(custom-manual "(message)Top")
66 (put 'user-mail-address
'custom-type
'string
)
67 (put 'user-full-name
'custom-type
'string
)
69 (defgroup message-various nil
70 "Various Message Variables."
71 :link
'(custom-manual "(message)Various Message Variables")
74 (defgroup message-buffers nil
76 :link
'(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link
'(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link
'(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link
'(custom-manual "(message)Forwarding")
92 :group
'message-interface
)
94 (defgroup message-insertion nil
96 :link
'(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link
'(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages."
108 (defgroup message-mail nil
109 "Composing Mail Messages."
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defcustom message-directory
"~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group
'message-various
122 (defcustom message-max-buffers
10
123 "*How many buffers to keep before starting to kill them off."
124 :group
'message-buffers
127 (defcustom message-send-rename-function nil
128 "Function called to rename the buffer after sending it."
129 :group
'message-buffers
130 :type
'(choice function
(const nil
)))
132 (defcustom message-fcc-handler-function
'message-output
133 "*A function called to save outgoing articles.
134 This function will be called with the name of the file to store the
135 article in. The default function is `message-output' which saves in Unix
137 :type
'(radio (function-item message-output
)
138 (function :tag
"Other"))
139 :group
'message-sending
)
141 (defcustom message-fcc-externalize-attachments nil
142 "If non-nil, attachments are included as external parts in Fcc copies."
145 :group
'message-sending
)
147 (defcustom message-courtesy-message
148 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
149 "*This is inserted at the start of a mailed copy of a posted message.
150 If the string contains the format spec \"%s\", the Newsgroups
151 the article has been posted to will be inserted there.
152 If this variable is nil, no such courtesy message will be added."
153 :group
'message-sending
154 :type
'(radio string
(const nil
)))
156 (defcustom message-ignored-bounced-headers
157 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
158 "*Regexp that matches headers to be removed in resent bounced mail."
159 :group
'message-interface
162 (defcustom message-from-style
'default
163 "*Specifies how \"From\" headers look.
165 If nil, they contain just the return address like:
167 If `parens', they look like:
168 king@grassland.com (Elvis Parsley)
169 If `angles', they look like:
170 Elvis Parsley <king@grassland.com>
172 Otherwise, most addresses look like `angles', but they look like
173 `parens' if `angles' would need quoting and `parens' would not."
174 :type
'(choice (const :tag
"simple" nil
)
178 :group
'message-headers
)
180 (defcustom message-insert-canlock t
181 "Whether to insert a Cancel-Lock header in news postings."
183 :group
'message-headers
186 (defcustom message-syntax-checks
187 (if message-insert-canlock
'((sender . disabled
)) nil
)
188 ;; Guess this one shouldn't be easy to customize...
189 "*Controls what syntax checks should not be performed on outgoing posts.
190 To disable checking of long signatures, for instance, add
191 `(signature . disabled)' to this list.
193 Don't touch this variable unless you really know what you're doing.
195 Checks include `approved', `bogus-recipient', `continuation-headers',
196 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
197 `invisible-text', `long-header-lines', `long-lines', `message-id',
198 `multiple-headers', `new-text', `newsgroups', `quoting-style',
199 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
200 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
201 and `valid-newsgroups'."
203 :type
'(repeat sexp
)) ; Fixme: improve this
205 (defcustom message-required-headers
'((optional . References
)
207 "*Headers to be generated or prompted for when sending a message.
208 Also see `message-required-news-headers' and
209 `message-required-mail-headers'."
212 :group
'message-headers
213 :link
'(custom-manual "(message)Message Headers")
214 :type
'(repeat sexp
))
216 (defcustom message-draft-headers
'(References From Date
)
217 "*Headers to be generated when saving a draft message."
220 :group
'message-headers
221 :link
'(custom-manual "(message)Message Headers")
222 :type
'(repeat sexp
))
224 (defcustom message-required-news-headers
225 '(From Newsgroups Subject Date Message-ID
226 (optional . Organization
)
227 (optional . User-Agent
))
228 "*Headers to be generated or prompted for when posting an article.
229 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
230 Message-ID. Organization, Lines, In-Reply-To, Expires, and
231 User-Agent are optional. If you don't want message to insert some
232 header, remove it from this list."
234 :group
'message-headers
235 :link
'(custom-manual "(message)Message Headers")
236 :type
'(repeat sexp
))
238 (defcustom message-required-mail-headers
239 '(From Subject Date
(optional . In-Reply-To
) Message-ID
240 (optional . User-Agent
))
241 "*Headers to be generated or prompted for when mailing a message.
242 It is recommended that From, Date, To, Subject and Message-ID be
243 included. Organization and User-Agent are optional."
245 :group
'message-headers
246 :link
'(custom-manual "(message)Message Headers")
247 :type
'(repeat sexp
))
249 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
250 "Headers to be deleted if they already exist and were generated by message previously."
251 :group
'message-headers
252 :link
'(custom-manual "(message)Message Headers")
255 (defcustom message-ignored-news-headers
256 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
257 "*Regexp of headers to be removed unconditionally before posting."
259 :group
'message-headers
260 :link
'(custom-manual "(message)Message Headers")
261 :type
'(repeat :value-to-internal
(lambda (widget value
)
262 (custom-split-regexp-maybe value
))
263 :match
(lambda (widget value
)
265 (widget-editable-list-match widget value
)))
268 (defcustom message-ignored-mail-headers
269 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
270 "*Regexp of headers to be removed unconditionally before mailing."
272 :group
'message-headers
273 :link
'(custom-manual "(message)Mail Headers")
276 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:"
277 "*Header lines matching this regexp will be deleted before posting.
278 It's best to delete old Path and Date headers before posting to avoid
280 :group
'message-interface
281 :link
'(custom-manual "(message)Superseding")
282 :type
'(repeat :value-to-internal
(lambda (widget value
)
283 (custom-split-regexp-maybe value
))
284 :match
(lambda (widget value
)
286 (widget-editable-list-match widget value
)))
289 (defcustom message-subject-re-regexp
290 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
291 "*Regexp matching \"Re: \" in the subject line."
292 :group
'message-various
293 :link
'(custom-manual "(message)Message Headers")
296 ;;; Start of variables adopted from `message-utils.el'.
298 (defcustom message-subject-trailing-was-query
'ask
299 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
300 If nil, leave the subject unchanged. If it is the symbol `ask', query
301 the user what do do. In this case, the subject is matched against
302 `message-subject-trailing-was-ask-regexp'. If
303 `message-subject-trailing-was-query' is t, always strip the trailing
304 old subject. In this case, `message-subject-trailing-was-regexp' is
307 :type
'(choice (const :tag
"never" nil
)
308 (const :tag
"always strip" t
)
310 :link
'(custom-manual "(message)Message Headers")
311 :group
'message-various
)
313 (defcustom message-subject-trailing-was-ask-regexp
314 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
315 "*Regexp matching \"(was: <old subject>)\" in the subject line.
317 The function `message-strip-subject-trailing-was' uses this regexp if
318 `message-subject-trailing-was-query' is set to the symbol `ask'. If
319 the variable is t instead of `ask', use
320 `message-subject-trailing-was-regexp' instead.
322 It is okay to create some false positives here, as the user is asked."
324 :group
'message-various
325 :link
'(custom-manual "(message)Message Headers")
328 (defcustom message-subject-trailing-was-regexp
329 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
330 "*Regexp matching \"(was: <old subject>)\" in the subject line.
332 If `message-subject-trailing-was-query' is set to t, the subject is
333 matched against `message-subject-trailing-was-regexp' in
334 `message-strip-subject-trailing-was'. You should use a regexp creating very
335 few false positives here."
337 :group
'message-various
338 :link
'(custom-manual "(message)Message Headers")
341 ;;; marking inserted text
343 (defcustom message-mark-insert-begin
344 "--8<---------------cut here---------------start------------->8---\n"
345 "How to mark the beginning of some inserted text."
348 :link
'(custom-manual "(message)Insertion Variables")
349 :group
'message-various
)
351 (defcustom message-mark-insert-end
352 "--8<---------------cut here---------------end--------------->8---\n"
353 "How to mark the end of some inserted text."
356 :link
'(custom-manual "(message)Insertion Variables")
357 :group
'message-various
)
359 (defcustom message-archive-header
"X-No-Archive: Yes\n"
360 "Header to insert when you don't want your article to be archived.
361 Archives \(such as groups.google.com\) respect this header."
364 :link
'(custom-manual "(message)Header Commands")
365 :group
'message-various
)
367 (defcustom message-archive-note
368 "X-No-Archive: Yes - save http://groups.google.com/"
369 "Note to insert why you wouldn't want this posting archived.
370 If nil, don't insert any text in the body."
372 :type
'(radio string
(const nil
))
373 :link
'(custom-manual "(message)Header Commands")
374 :group
'message-various
)
376 ;;; Crossposts and Followups
377 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
378 ;; new suggestions by R. Weikusat <rw at another.de>
380 (defvar message-cross-post-old-target nil
381 "Old target for cross-posts or follow-ups.")
382 (make-variable-buffer-local 'message-cross-post-old-target
)
384 (defcustom message-cross-post-default t
385 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
386 If nil, `message-cross-post-followup-to' will only do a followup. Note that
387 you can explicitly override this setting by calling
388 `message-cross-post-followup-to' with a prefix."
391 :group
'message-various
)
393 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
394 "Note to insert before signature to notify of cross-post and follow-up."
397 :group
'message-various
)
399 (defcustom message-followup-to-note
"Followup-To: "
400 "Note to insert before signature to notify of follow-up only."
403 :group
'message-various
)
405 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
406 "Function to use to insert note about Crosspost or Followup-To.
407 The function will be called with four arguments. The function should not only
408 insert a note, but also ensure old notes are deleted. See the documentation
409 for `message-cross-post-insert-note'."
412 :group
'message-various
)
414 ;;; End of variables adopted from `message-utils.el'.
416 (defcustom message-signature-separator
"^-- $"
417 "Regexp matching the signature separator.
418 This variable is used to strip off the signature from quoted text
419 when `message-cite-function' is
420 `message-cite-original-without-signature'. Most useful values
421 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
423 :type
'(choice (const :tag
"strict" "^-- $")
424 (const :tag
"loose" "^-- *$")
426 :version
"22.3" ;; Gnus 5.10.12 (changed default)
427 :link
'(custom-manual "(message)Various Message Variables")
428 :group
'message-various
)
430 (defcustom message-elide-ellipsis
"\n[...]\n\n"
431 "*The string which is inserted for elided text."
433 :link
'(custom-manual "(message)Various Commands")
434 :group
'message-various
)
436 (defcustom message-interactive t
437 "Non-nil means when sending a message wait for and display errors.
438 nil means let mailer mail back a message to report errors."
439 :group
'message-sending
441 :link
'(custom-manual "(message)Sending Variables")
444 (defcustom message-generate-new-buffers
'unique
445 "*Say whether to create a new message buffer to compose a message.
446 Valid values include:
449 Generate the buffer name in the Message way (e.g., *mail*, *news*,
450 *mail to whom*, *news on group*, etc.) and continue editing in the
451 existing buffer of that name. If there is no such buffer, it will
455 Create the new buffer with the name generated in the Message way.
458 Similar to `unique' but the buffer name begins with \"*unsent \".
461 Similar to nil but the buffer name is simpler like *mail message*.
464 If this is a function, call that function with three parameters:
465 The type, the To address and the group name (any of these may be nil).
466 The function should return the new buffer name."
467 :group
'message-buffers
468 :link
'(custom-manual "(message)Message Buffers")
469 :type
'(choice (const nil
)
470 (sexp :tag
"unique" :format
"unique\n" :value unique
471 :match
(lambda (widget value
) (memq value
'(unique t
))))
474 (function :format
"\n %{%t%}: %v")))
476 (defcustom message-kill-buffer-on-exit nil
477 "*Non-nil means that the message buffer will be killed after sending a message."
478 :group
'message-buffers
479 :link
'(custom-manual "(message)Message Buffers")
482 (defcustom message-kill-buffer-query t
483 "*Non-nil means that killing a modified message buffer has to be confirmed.
484 This is used by `message-kill-buffer'."
485 :version
"23.1" ;; No Gnus
486 :group
'message-buffers
489 (defvar gnus-local-organization
)
490 (defcustom message-user-organization
491 (or (and (boundp 'gnus-local-organization
)
492 (stringp gnus-local-organization
)
493 gnus-local-organization
)
494 (getenv "ORGANIZATION")
496 "*String to be used as an Organization header.
497 If t, use `message-user-organization-file'."
498 :group
'message-headers
499 :type
'(choice string
500 (const :tag
"consult file" t
)))
502 (defcustom message-user-organization-file
504 (dolist (f (list "/etc/organization"
505 "/etc/news/organization"
506 "/usr/lib/news/organization"))
507 (when (file-readable-p f
)
510 "*Local news organization file."
512 :link
'(custom-manual "(message)News Headers")
513 :group
'message-headers
)
515 (defcustom message-make-forward-subject-function
516 #'message-forward-subject-name-subject
517 "*List of functions called to generate subject headers for forwarded messages.
518 The subject generated by the previous function is passed into each
521 The provided functions are:
523 * `message-forward-subject-author-subject' Source of article (author or
524 newsgroup), in brackets followed by the subject
525 * `message-forward-subject-name-subject' Source of article (name of author
526 or newsgroup), in brackets followed by the subject
527 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
529 :group
'message-forwarding
530 :link
'(custom-manual "(message)Forwarding")
531 :type
'(radio (function-item message-forward-subject-author-subject
)
532 (function-item message-forward-subject-fwd
)
533 (function-item message-forward-subject-name-subject
)
534 (repeat :tag
"List of functions" function
)))
536 (defcustom message-forward-as-mime t
537 "*Non-nil means forward messages as an inline/rfc822 MIME section.
538 Otherwise, directly inline the old message in the forwarded message."
540 :group
'message-forwarding
541 :link
'(custom-manual "(message)Forwarding")
544 (defcustom message-forward-show-mml
'best
545 "*Non-nil means show forwarded messages as MML (decoded from MIME).
546 Otherwise, forwarded messages are unchanged.
547 Can also be the symbol `best' to indicate that MML should be
548 used, except when it is a bad idea to use MML. One example where
549 it is a bad idea is when forwarding a signed or encrypted
550 message, because converting MIME to MML would invalidate the
553 :group
'message-forwarding
554 :type
'(choice (const :tag
"use MML" t
)
555 (const :tag
"don't use MML " nil
)
556 (const :tag
"use MML when appropriate" best
)))
558 (defcustom message-forward-before-signature t
559 "*Non-nil means put forwarded message before signature, else after."
560 :group
'message-forwarding
563 (defcustom message-wash-forwarded-subjects nil
564 "*Non-nil means try to remove as much cruft as possible from the subject.
565 Done before generating the new subject of a forward."
566 :group
'message-forwarding
567 :link
'(custom-manual "(message)Forwarding")
570 (defcustom message-ignored-resent-headers
571 ;; `Delivered-To' needs to be removed because some mailers use it to
572 ;; detect loops, so if you resend a message to an address that ultimately
573 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
574 ;; case you may be removed from the list on the grounds that mail to you
575 ;; bounced with a "mailing loop" error).
576 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
577 "*All headers that match this regexp will be deleted when resending a message."
578 :group
'message-interface
579 :link
'(custom-manual "(message)Resending")
580 :type
'(repeat :value-to-internal
(lambda (widget value
)
581 (custom-split-regexp-maybe value
))
582 :match
(lambda (widget value
)
584 (widget-editable-list-match widget value
)))
587 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
588 "*All headers that match this regexp will be deleted when forwarding a message."
590 :group
'message-forwarding
591 :type
'(repeat :value-to-internal
(lambda (widget value
)
592 (custom-split-regexp-maybe value
))
593 :match
(lambda (widget value
)
595 (widget-editable-list-match widget value
)))
598 (defcustom message-ignored-cited-headers
"."
599 "*Delete these headers from the messages you yank."
600 :group
'message-insertion
601 :link
'(custom-manual "(message)Insertion Variables")
604 (defcustom message-cite-prefix-regexp
605 (if (string-match "[[:digit:]]" "1")
606 ;; Support POSIX? XEmacs 21.5.27 doesn't.
607 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+"
608 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
609 (let (non-word-constituents)
610 (with-syntax-table text-mode-syntax-table
611 (setq non-word-constituents
613 (if (string-match "\\w" "_") "" "_")
614 (if (string-match "\\w" ".") "" "."))))
615 (if (equal non-word-constituents
"")
616 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
617 (concat "\\([ \t]*\\(\\w\\|["
618 non-word-constituents
619 "]\\)+>+\\|[ \t]*[]>|}]\\)+"))))
620 "*Regexp matching the longest possible citation prefix on a line."
622 :group
'message-insertion
623 :link
'(custom-manual "(message)Insertion Variables")
625 :set
(lambda (symbol value
)
627 (custom-set-default symbol value
)
628 (if (boundp 'gnus-message-cite-prefix-regexp
)
629 (setq gnus-message-cite-prefix-regexp
630 (concat "^\\(?:" value
"\\)"))))))
632 (defcustom message-cancel-message
"I am canceling my own article.\n"
633 "Message to be inserted in the cancel message."
634 :group
'message-interface
635 :link
'(custom-manual "(message)Canceling News")
638 (defvar smtpmail-default-smtp-server
)
640 (defun message-send-mail-function ()
641 "Return suitable value for the variable `message-send-mail-function'."
642 (cond ((and (require 'sendmail
)
643 (boundp 'sendmail-program
)
645 (executable-find sendmail-program
))
646 'message-send-mail-with-sendmail
)
647 ((and (locate-library "smtpmail")
649 smtpmail-default-smtp-server
)
650 'message-smtpmail-send-it
)
651 ((locate-library "mailclient")
652 'message-send-mail-with-mailclient
)
655 (error "Don't know how to send mail. Please customize `message-send-mail-function'")))))
657 ;; Useful to set in site-init.el
658 (defcustom message-send-mail-function
(message-send-mail-function)
659 "Function to call to send the current buffer as mail.
660 The headers should be delimited by a line whose contents match the
661 variable `mail-header-separator'.
663 Valid values include `message-send-mail-with-sendmail'
664 `message-send-mail-with-mh', `message-send-mail-with-qmail',
665 `message-smtpmail-send-it', `smtpmail-send-it',
666 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
667 default is system dependent and determined by the function
668 `message-send-mail-function'.
670 See also `send-mail-function'."
671 :type
'(radio (function-item message-send-mail-with-sendmail
)
672 (function-item message-send-mail-with-mh
)
673 (function-item message-send-mail-with-qmail
)
674 (function-item message-smtpmail-send-it
)
675 (function-item smtpmail-send-it
)
676 (function-item feedmail-send-it
)
677 (function-item message-send-mail-with-mailclient
678 :tag
"Use Mailclient package")
679 (function :tag
"Other"))
680 :group
'message-sending
681 :version
"23.1" ;; No Gnus
682 :initialize
'custom-initialize-default
683 :link
'(custom-manual "(message)Mail Variables")
684 :group
'message-mail
)
686 (defcustom message-send-news-function
'message-send-news
687 "Function to call to send the current buffer as news.
688 The headers should be delimited by a line whose contents match the
689 variable `mail-header-separator'."
690 :group
'message-sending
692 :link
'(custom-manual "(message)News Variables")
695 (defcustom message-reply-to-function nil
696 "If non-nil, function that should return a list of headers.
697 This function should pick out addresses from the To, Cc, and From headers
698 and respond with new To and Cc headers."
699 :group
'message-interface
700 :link
'(custom-manual "(message)Reply")
701 :type
'(choice function
(const nil
)))
703 (defcustom message-wide-reply-to-function nil
704 "If non-nil, function that should return a list of headers.
705 This function should pick out addresses from the To, Cc, and From headers
706 and respond with new To and Cc headers."
707 :group
'message-interface
708 :link
'(custom-manual "(message)Wide Reply")
709 :type
'(choice function
(const nil
)))
711 (defcustom message-followup-to-function nil
712 "If non-nil, function that should return a list of headers.
713 This function should pick out addresses from the To, Cc, and From headers
714 and respond with new To and Cc headers."
715 :group
'message-interface
716 :link
'(custom-manual "(message)Followup")
717 :type
'(choice function
(const nil
)))
719 (defcustom message-extra-wide-headers nil
720 "If non-nil, a list of additional address headers.
721 These are used when composing a wide reply."
722 :group
'message-sending
723 :type
'(repeat string
))
725 (defcustom message-use-followup-to
'ask
726 "*Specifies what to do with Followup-To header.
727 If nil, always ignore the header. If it is t, use its value, but
728 query before using the \"poster\" value. If it is the symbol `ask',
729 always query the user whether to use the value. If it is the symbol
730 `use', always use the value."
731 :group
'message-interface
732 :link
'(custom-manual "(message)Followup")
733 :type
'(choice (const :tag
"ignore" nil
)
734 (const :tag
"use & query" t
)
738 (defcustom message-use-mail-followup-to
'use
739 "*Specifies what to do with Mail-Followup-To header.
740 If nil, always ignore the header. If it is the symbol `ask', always
741 query the user whether to use the value. If it is the symbol `use',
742 always use the value."
744 :group
'message-interface
745 :link
'(custom-manual "(message)Mailing Lists")
746 :type
'(choice (const :tag
"ignore" nil
)
750 (defcustom message-subscribed-address-functions nil
751 "*Specifies functions for determining list subscription.
752 If nil, do not attempt to determine list subscription with functions.
753 If non-nil, this variable contains a list of functions which return
754 regular expressions to match lists. These functions can be used in
755 conjunction with `message-subscribed-regexps' and
756 `message-subscribed-addresses'."
758 :group
'message-interface
759 :link
'(custom-manual "(message)Mailing Lists")
760 :type
'(repeat sexp
))
762 (defcustom message-subscribed-address-file nil
763 "*A file containing addresses the user is subscribed to.
764 If nil, do not look at any files to determine list subscriptions. If
765 non-nil, each line of this file should be a mailing list address."
767 :group
'message-interface
768 :link
'(custom-manual "(message)Mailing Lists")
769 :type
'(radio file
(const nil
)))
771 (defcustom message-subscribed-addresses nil
772 "*Specifies a list of addresses the user is subscribed to.
773 If nil, do not use any predefined list subscriptions. This list of
774 addresses can be used in conjunction with
775 `message-subscribed-address-functions' and `message-subscribed-regexps'."
777 :group
'message-interface
778 :link
'(custom-manual "(message)Mailing Lists")
779 :type
'(repeat string
))
781 (defcustom message-subscribed-regexps nil
782 "*Specifies a list of addresses the user is subscribed to.
783 If nil, do not use any predefined list subscriptions. This list of
784 regular expressions can be used in conjunction with
785 `message-subscribed-address-functions' and `message-subscribed-addresses'."
787 :group
'message-interface
788 :link
'(custom-manual "(message)Mailing Lists")
789 :type
'(repeat regexp
))
791 (defcustom message-allow-no-recipients
'ask
792 "Specifies what to do when there are no recipients other than Gcc/Fcc.
793 If it is the symbol `always', the posting is allowed. If it is the
794 symbol `never', the posting is not allowed. If it is the symbol
795 `ask', you are prompted."
797 :group
'message-interface
798 :link
'(custom-manual "(message)Message Headers")
799 :type
'(choice (const always
)
803 (defcustom message-sendmail-f-is-evil nil
804 "*Non-nil means don't add \"-f username\" to the sendmail command line.
805 Doing so would be even more evil than leaving it out."
806 :group
'message-sending
807 :link
'(custom-manual "(message)Mail Variables")
810 (defcustom message-sendmail-envelope-from nil
811 "*Envelope-from when sending mail with sendmail.
812 If this is nil, use `user-mail-address'. If it is the symbol
813 `header', use the From: header of the message."
815 :type
'(choice (string :tag
"From name")
816 (const :tag
"Use From: header from message" header
)
817 (const :tag
"Use `user-mail-address'" nil
))
818 :link
'(custom-manual "(message)Mail Variables")
819 :group
'message-sending
)
821 (defcustom message-sendmail-extra-arguments nil
822 "Additional arguments to `sendmail-program'."
823 ;; E.g. '("-a" "account") for msmtp
824 :version
"23.1" ;; No Gnus
825 :type
'(repeat string
)
826 ;; :link '(custom-manual "(message)Mail Variables")
827 :group
'message-sending
)
829 ;; qmail-related stuff
830 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
831 "Location of the qmail-inject program."
832 :group
'message-sending
833 :link
'(custom-manual "(message)Mail Variables")
836 (defcustom message-qmail-inject-args nil
837 "Arguments passed to qmail-inject programs.
838 This should be a list of strings, one string for each argument. It
839 may also be a function.
841 For e.g., if you wish to set the envelope sender address so that bounces
842 go to the right place or to deal with listserv's usage of that address, you
843 might set this variable to '(\"-f\" \"you@some.where\")."
844 :group
'message-sending
845 :link
'(custom-manual "(message)Mail Variables")
846 :type
'(choice (function)
849 (defvar gnus-post-method
)
850 (defvar gnus-select-method
)
851 (defcustom message-post-method
852 (cond ((and (boundp 'gnus-post-method
)
853 (listp gnus-post-method
)
856 ((boundp 'gnus-select-method
)
859 "*Method used to post news.
860 Note that when posting from inside Gnus, for instance, this
861 variable isn't used."
863 :group
'message-sending
864 ;; This should be the `gnus-select-method' widget, but that might
865 ;; create a dependence to `gnus.el'.
868 ;; FIXME: This should be a temporary workaround until someone implements a
869 ;; proper solution. If a crash happens while replying, the auto-save file
870 ;; will *not* have a `References:' header if `message-generate-headers-first'
871 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
872 (defcustom message-generate-headers-first
'(references)
873 "Which headers should be generated before starting to compose a message.
874 If t, generate all required headers. This can also be a list of headers to
875 generate. The variables `message-required-news-headers' and
876 `message-required-mail-headers' specify which headers to generate.
878 Note that the variable `message-deletable-headers' specifies headers which
879 are to be deleted and then re-generated before sending, so this variable
880 will not have a visible effect for those headers."
881 :group
'message-headers
882 :link
'(custom-manual "(message)Message Headers")
883 :type
'(choice (const :tag
"None" nil
)
884 (const :tag
"References" '(references))
886 (repeat (sexp :tag
"Header"))))
888 (defcustom message-fill-column
72
889 "Column beyond which automatic line-wrapping should happen.
890 Local value for message buffers. If non-nil, also turn on
891 auto-fill in message buffers."
892 :group
'message-various
893 ;; :link '(custom-manual "(message)Message Headers")
894 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
897 (defcustom message-setup-hook nil
898 "Normal hook, run each time a new outgoing message is initialized.
899 The function `message-setup' runs this hook."
900 :group
'message-various
901 :link
'(custom-manual "(message)Various Message Variables")
904 (defcustom message-cancel-hook nil
905 "Hook run when cancelling articles."
906 :group
'message-various
907 :link
'(custom-manual "(message)Various Message Variables")
910 (defcustom message-signature-setup-hook nil
911 "Normal hook, run each time a new outgoing message is initialized.
912 It is run after the headers have been inserted and before
913 the signature is inserted."
914 :group
'message-various
915 :link
'(custom-manual "(message)Various Message Variables")
918 (defcustom message-mode-hook nil
919 "Hook run in message mode buffers."
920 :group
'message-various
923 (defcustom message-header-hook nil
924 "Hook run in a message mode buffer narrowed to the headers."
925 :group
'message-various
928 (defcustom message-header-setup-hook nil
929 "Hook called narrowed to the headers when setting up a message buffer."
930 :group
'message-various
931 :link
'(custom-manual "(message)Various Message Variables")
934 (defcustom message-minibuffer-local-map
935 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
936 (set-keymap-parent map minibuffer-local-map
)
938 "Keymap for `message-read-from-minibuffer'."
940 :group
'message-various
)
942 (defcustom message-citation-line-function
'message-insert-citation-line
943 "*Function called to insert the \"Whomever writes:\" line.
945 Predefined functions include `message-insert-citation-line' and
946 `message-insert-formatted-citation-line' (see the variable
947 `message-citation-line-format').
949 Note that Gnus provides a feature where the reader can click on
950 `writes:' to hide the cited text. If you change this line too much,
951 people who read your message will have to change their Gnus
952 configuration. See the variable `gnus-cite-attribution-suffix'."
954 (function-item :tag
"plain" message-insert-citation-line
)
955 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
956 (function :tag
"Other"))
957 :link
'(custom-manual "(message)Insertion Variables")
958 :group
'message-insertion
)
960 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
961 "Format of the \"Whomever writes:\" line.
963 The string is formatted using `format-spec'. The following
964 constructs are replaced:
966 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
967 %n The mail address, e.g. \"john.doe@example.invalid\".
968 %N The real name if present, e.g.: \"John Doe\", else fall
969 back to the mail address.
970 %F The first name if present, e.g.: \"John\".
971 %L The last name if present, e.g.: \"Doe\".
973 All other format specifiers are passed to `format-time-string'
974 which is called using the date from the article your replying to.
975 Extracting the first (%F) and last name (%L) is done
976 heuristically, so you should always check it yourself.
978 Please also read the note in the documentation of
979 `message-citation-line-function'."
980 :type
'(choice (const :tag
"Plain" "%f writes:")
981 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
983 :link
'(custom-manual "(message)Insertion Variables")
984 :version
"23.1" ;; No Gnus
985 :group
'message-insertion
)
987 (defcustom message-yank-prefix
"> "
988 "*Prefix inserted on the lines of yanked messages.
989 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
990 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
992 :link
'(custom-manual "(message)Insertion Variables")
993 :group
'message-insertion
)
995 (defcustom message-yank-cited-prefix
">"
996 "*Prefix inserted on cited lines of yanked messages.
997 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
998 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1001 :link
'(custom-manual "(message)Insertion Variables")
1002 :group
'message-insertion
)
1004 (defcustom message-yank-empty-prefix
">"
1005 "*Prefix inserted on empty lines of yanked messages.
1006 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1009 :link
'(custom-manual "(message)Insertion Variables")
1010 :group
'message-insertion
)
1012 (defcustom message-indentation-spaces
3
1013 "*Number of spaces to insert at the beginning of each cited line.
1014 Used by `message-yank-original' via `message-yank-cite'."
1015 :group
'message-insertion
1016 :link
'(custom-manual "(message)Insertion Variables")
1020 (defcustom message-cite-function
'message-cite-original-without-signature
1021 "*Function for citing an original message.
1022 Predefined functions include `message-cite-original' and
1023 `message-cite-original-without-signature'.
1024 Note that these functions use `mail-citation-hook' if that is non-nil."
1025 :type
'(radio (function-item message-cite-original
)
1026 (function-item message-cite-original-without-signature
)
1027 (function-item sc-cite-original
)
1028 (function :tag
"Other"))
1029 :link
'(custom-manual "(message)Insertion Variables")
1030 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1031 :group
'message-insertion
)
1033 (defcustom message-indent-citation-function
'message-indent-citation
1034 "*Function for modifying a citation just inserted in the mail buffer.
1035 This can also be a list of functions. Each function can find the
1036 citation between (point) and (mark t). And each function should leave
1037 point and mark around the citation text as modified."
1039 :link
'(custom-manual "(message)Insertion Variables")
1040 :group
'message-insertion
)
1042 (defcustom message-signature t
1043 "*String to be inserted at the end of the message buffer.
1044 If t, the `message-signature-file' file will be inserted instead.
1045 If a function, the result from the function will be used instead.
1046 If a form, the result from the form will be used instead."
1048 :link
'(custom-manual "(message)Insertion Variables")
1049 :group
'message-insertion
)
1051 (defcustom message-signature-file
"~/.signature"
1052 "*Name of file containing the text inserted at end of message buffer.
1053 Ignored if the named file doesn't exist.
1054 If nil, don't insert a signature.
1055 If a path is specified, the value of `message-signature-directory' is ignored,
1057 :type
'(choice file
(const :tags
"None" nil
))
1058 :link
'(custom-manual "(message)Insertion Variables")
1059 :group
'message-insertion
)
1061 (defcustom message-signature-directory nil
1062 "*Name of directory containing signature files.
1063 Comes in handy if you have many such files, handled via posting styles for
1065 If nil, `message-signature-file' is expected to specify the directory if
1067 :type
'(choice string
(const :tags
"None" nil
))
1068 :link
'(custom-manual "(message)Insertion Variables")
1069 :group
'message-insertion
)
1071 (defcustom message-signature-insert-empty-line t
1072 "*If non-nil, insert an empty line before the signature separator."
1075 :link
'(custom-manual "(message)Insertion Variables")
1076 :group
'message-insertion
)
1078 (defcustom message-distribution-function nil
1079 "*Function called to return a Distribution header."
1080 :group
'message-news
1081 :group
'message-headers
1082 :link
'(custom-manual "(message)News Headers")
1083 :type
'(choice function
(const nil
)))
1085 (defcustom message-expires
14
1086 "Number of days before your article expires."
1087 :group
'message-news
1088 :group
'message-headers
1089 :link
'(custom-manual "(message)News Headers")
1092 (defcustom message-user-path nil
1093 "If nil, use the NNTP server name in the Path header.
1094 If stringp, use this; if non-nil, use no host name (user name only)."
1095 :group
'message-news
1096 :group
'message-headers
1097 :link
'(custom-manual "(message)News Headers")
1098 :type
'(choice (const :tag
"nntp" nil
)
1099 (string :tag
"name")
1100 (sexp :tag
"none" :format
"%t" t
)))
1102 (defvar message-reply-buffer nil
)
1103 (defvar message-reply-headers nil
1104 "The headers of the current replied article.
1105 It is a vector of the following headers:
1106 \[number subject from date id references chars lines xref extra].")
1107 (defvar message-newsreader nil
)
1108 (defvar message-mailer nil
)
1109 (defvar message-sent-message-via nil
)
1110 (defvar message-checksum nil
)
1111 (defvar message-send-actions nil
1112 "A list of actions to be performed upon successful sending of a message.")
1113 (defvar message-exit-actions nil
1114 "A list of actions to be performed upon exiting after sending a message.")
1115 (defvar message-kill-actions nil
1116 "A list of actions to be performed before killing a message buffer.")
1117 (defvar message-postpone-actions nil
1118 "A list of actions to be performed after postponing a message.")
1120 (define-widget 'message-header-lines
'text
1121 "All header lines must be LFD terminated."
1122 :format
"%{%t%}:%n%v"
1123 :valid-regexp
"^\\'"
1124 :error
"All header lines must be newline terminated")
1126 (defcustom message-default-headers
""
1127 "*A string containing header lines to be inserted in outgoing messages.
1128 It is inserted before you edit the message, so you can edit or delete
1130 :group
'message-headers
1131 :link
'(custom-manual "(message)Message Headers")
1132 :type
'message-header-lines
)
1134 (defcustom message-default-mail-headers
""
1135 "*A string of header lines to be inserted in outgoing mails."
1136 :group
'message-headers
1137 :group
'message-mail
1138 :link
'(custom-manual "(message)Mail Headers")
1139 :type
'message-header-lines
)
1141 (defcustom message-default-news-headers
""
1142 "*A string of header lines to be inserted in outgoing news articles."
1143 :group
'message-headers
1144 :group
'message-news
1145 :link
'(custom-manual "(message)News Headers")
1146 :type
'message-header-lines
)
1148 ;; Note: could use /usr/ucb/mail instead of sendmail;
1149 ;; options -t, and -v if not interactive.
1150 (defcustom message-mailer-swallows-blank-line
1151 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1152 system-configuration
)
1153 (file-readable-p "/etc/sendmail.cf")
1154 (let ((buffer (get-buffer-create " *temp*")))
1156 (with-current-buffer buffer
1157 (insert-file-contents "/etc/sendmail.cf")
1158 (goto-char (point-min))
1159 (let ((case-fold-search nil
))
1160 (re-search-forward "^OR\\>" nil t
)))
1161 (kill-buffer buffer
))))
1162 ;; According to RFC822, "The field-name must be composed of printable
1163 ;; ASCII characters (i. e., characters that have decimal values between
1164 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1166 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1167 "*Set this non-nil if the system's mailer runs the header and body together.
1168 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1169 The value should be an expression to test whether the problem will
1171 :group
'message-sending
1172 :link
'(custom-manual "(message)Mail Variables")
1176 (define-mail-user-agent 'message-user-agent
1177 'message-mail
'message-send-and-exit
1178 'message-kill-buffer
'message-send-hook
)
1180 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1181 "If non-nil, delete the deletable headers before feeding to mh.")
1183 (defvar message-send-method-alist
1184 '((news message-news-p message-send-via-news
)
1185 (mail message-mail-p message-send-via-mail
))
1186 "Alist of ways to send outgoing messages.
1187 Each element has the form
1189 \(TYPE PREDICATE FUNCTION)
1191 where TYPE is a symbol that names the method; PREDICATE is a function
1192 called without any parameters to determine whether the message is
1193 a message of type TYPE; and FUNCTION is a function to be called if
1194 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1197 (defcustom message-mail-alias-type
'abbrev
1198 "*What alias expansion type to use in Message buffers.
1199 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1200 an electric completion mode. nil switches mail aliases off.
1201 This can also be a list of values."
1203 :link
'(custom-manual "(message)Mail Aliases")
1204 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1205 (const :tag
"Use ecomplete" ecomplete
)
1206 (const :tag
"No expansion" nil
)))
1208 (defcustom message-self-insert-commands
'(self-insert-command)
1209 "List of `self-insert-command's used to trigger ecomplete.
1210 When one of those commands is invoked to enter a character in To or Cc
1211 header, ecomplete will suggest the candidates of recipients (see also
1212 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1213 text and it replaces `self-insert-command' with the other command, e.g.
1214 `egg-self-insert-command', you may want to add it to this list."
1215 :group
'message-various
1216 :type
'(repeat function
))
1218 (defcustom message-auto-save-directory
1219 (file-name-as-directory (nnheader-concat message-directory
"drafts"))
1220 "*Directory where Message auto-saves buffers if Gnus isn't running.
1221 If nil, Message won't auto-save."
1222 :group
'message-buffers
1223 :link
'(custom-manual "(message)Various Message Variables")
1224 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1226 (defcustom message-default-charset
1227 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1228 "Default charset used in non-MULE Emacsen.
1229 If nil, you might be asked to input the charset."
1232 :link
'(custom-manual "(message)Various Message Variables")
1235 (defcustom message-dont-reply-to-names
1236 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1237 "*Addresses to prune when doing wide replies.
1238 This can be a regexp or a list of regexps. Also, a value of nil means
1239 exclude your own user name only."
1242 :link
'(custom-manual "(message)Wide Reply")
1243 :type
'(choice (const :tag
"Yourself" nil
)
1245 (repeat :tag
"Regexp List" regexp
)))
1247 (defsubst message-dont-reply-to-names
()
1248 (gmm-regexp-concat message-dont-reply-to-names
))
1250 (defvar message-shoot-gnksa-feet nil
1251 "*A list of GNKSA feet you are allowed to shoot.
1252 Gnus gives you all the opportunity you could possibly want for
1253 shooting yourself in the foot. Also, Gnus allows you to shoot the
1254 feet of Good Net-Keeping Seal of Approval. The following are foot
1256 `empty-article' Allow you to post an empty article;
1257 `quoted-text-only' Allow you to post quoted text only;
1258 `multiple-copies' Allow you to post multiple copies;
1259 `cancel-messages' Allow you to cancel or supersede messages from
1260 your other email addresses.")
1262 (defsubst message-gnksa-enable-p
(feature)
1263 (or (not (listp message-shoot-gnksa-feet
))
1264 (memq feature message-shoot-gnksa-feet
)))
1266 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1268 "Regexp of headers to be hidden when composing new messages.
1269 This can also be a list of regexps to match headers. Or a list
1270 starting with `not' and followed by regexps."
1273 :link
'(custom-manual "(message)Message Headers")
1275 :format
"%{%t%}: %[Value Type%] %v"
1276 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1277 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1278 (regexp :format
"%t: %v"))
1279 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1281 (repeat :format
"%v%i"
1282 (regexp :format
"%t: %v")))))
1284 (defcustom message-cite-articles-with-x-no-archive t
1285 "If non-nil, cite text from articles that has X-No-Archive set."
1289 ;;; Internal variables.
1290 ;;; Well, not really internal.
1292 (defvar message-mode-syntax-table
1293 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1294 (modify-syntax-entry ?%
". " table
)
1295 (modify-syntax-entry ?
> ". " table
)
1296 (modify-syntax-entry ?
< ". " table
)
1298 "Syntax table used while in Message mode.")
1300 (defface message-header-to
1303 (:foreground
"DarkOliveGreen1" :bold t
))
1306 (:foreground
"MidnightBlue" :bold t
))
1308 (:bold t
:italic t
)))
1309 "Face used for displaying From headers."
1310 :group
'message-faces
)
1311 ;; backward-compatibility alias
1312 (put 'message-header-to-face
'face-alias
'message-header-to
)
1314 (defface message-header-cc
1317 (:foreground
"chartreuse1" :bold t
))
1320 (:foreground
"MidnightBlue"))
1323 "Face used for displaying Cc headers."
1324 :group
'message-faces
)
1325 ;; backward-compatibility alias
1326 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1328 (defface message-header-subject
1331 (:foreground
"OliveDrab1"))
1334 (:foreground
"navy blue" :bold t
))
1337 "Face used for displaying subject headers."
1338 :group
'message-faces
)
1339 ;; backward-compatibility alias
1340 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1342 (defface message-header-newsgroups
1345 (:foreground
"yellow" :bold t
:italic t
))
1348 (:foreground
"blue4" :bold t
:italic t
))
1350 (:bold t
:italic t
)))
1351 "Face used for displaying newsgroups headers."
1352 :group
'message-faces
)
1353 ;; backward-compatibility alias
1354 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1356 (defface message-header-other
1359 (:foreground
"VioletRed1"))
1362 (:foreground
"steel blue"))
1364 (:bold t
:italic t
)))
1365 "Face used for displaying newsgroups headers."
1366 :group
'message-faces
)
1367 ;; backward-compatibility alias
1368 (put 'message-header-other-face
'face-alias
'message-header-other
)
1370 (defface message-header-name
1373 (:foreground
"green"))
1376 (:foreground
"cornflower blue"))
1379 "Face used for displaying header names."
1380 :group
'message-faces
)
1381 ;; backward-compatibility alias
1382 (put 'message-header-name-face
'face-alias
'message-header-name
)
1384 (defface message-header-xheader
1387 (:foreground
"DeepSkyBlue1"))
1390 (:foreground
"blue"))
1393 "Face used for displaying X-Header headers."
1394 :group
'message-faces
)
1395 ;; backward-compatibility alias
1396 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1398 (defface message-separator
1401 (:foreground
"LightSkyBlue1"))
1404 (:foreground
"brown"))
1407 "Face used for displaying the separator."
1408 :group
'message-faces
)
1409 ;; backward-compatibility alias
1410 (put 'message-separator-face
'face-alias
'message-separator
)
1412 (defface message-cited-text
1415 (:foreground
"LightPink1"))
1418 (:foreground
"red"))
1421 "Face used for displaying cited text names."
1422 :group
'message-faces
)
1423 ;; backward-compatibility alias
1424 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1426 (defface message-mml
1429 (:foreground
"MediumSpringGreen"))
1432 (:foreground
"ForestGreen"))
1435 "Face used for displaying MML."
1436 :group
'message-faces
)
1437 ;; backward-compatibility alias
1438 (put 'message-mml-face
'face-alias
'message-mml
)
1440 (defun message-font-lock-make-header-matcher (regexp)
1443 (let ((start (point)))
1446 (goto-char (point-min))
1447 (if (re-search-forward
1448 (concat "^" (regexp-quote mail-header-separator
) "$")
1450 (setq limit
(min limit
(match-beginning 0))))
1452 (and (< start limit
)
1453 (re-search-forward ,regexp limit t
))))))
1454 (if (featurep 'bytecomp
)
1458 (defvar message-font-lock-keywords
1459 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1460 `((,(message-font-lock-make-header-matcher
1461 (concat "^\\([Tt]o:\\)" content
))
1462 (1 'message-header-name
)
1463 (2 'message-header-to nil t
))
1464 (,(message-font-lock-make-header-matcher
1465 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1466 (1 'message-header-name
)
1467 (2 'message-header-cc nil t
))
1468 (,(message-font-lock-make-header-matcher
1469 (concat "^\\([Ss]ubject:\\)" content
))
1470 (1 'message-header-name
)
1471 (2 'message-header-subject nil t
))
1472 (,(message-font-lock-make-header-matcher
1473 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1474 (1 'message-header-name
)
1475 (2 'message-header-newsgroups nil t
))
1476 (,(message-font-lock-make-header-matcher
1477 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1478 (1 'message-header-name
)
1479 (2 'message-header-xheader
))
1480 (,(message-font-lock-make-header-matcher
1481 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1482 (1 'message-header-name
)
1483 (2 'message-header-other nil t
))
1484 ,@(if (and mail-header-separator
1485 (not (equal mail-header-separator
"")))
1486 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1487 1 'message-separator
))
1490 (re-search-forward (concat "^\\("
1491 message-cite-prefix-regexp
1494 (0 'message-cited-text
))
1495 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1497 "Additional expressions to highlight in Message mode.")
1500 ;; XEmacs does it like this. For Emacs, we have to set the
1501 ;; `font-lock-defaults' buffer-local variable.
1502 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1504 (defvar message-face-alist
1505 '((bold . message-bold-region
)
1506 (underline . underline-region
)
1507 (default .
(lambda (b e
)
1508 (message-unbold-region b e
)
1509 (ununderline-region b e
))))
1510 "Alist of mail and news faces for facemenu.
1511 The cdr of each entry is a function for applying the face to a region.")
1513 (defcustom message-send-hook nil
1514 "Hook run before sending messages.
1515 This hook is run quite early when sending."
1516 :group
'message-various
1517 :options
'(ispell-message)
1518 :link
'(custom-manual "(message)Various Message Variables")
1521 (defcustom message-send-mail-hook nil
1522 "Hook run before sending mail messages.
1523 This hook is run very late -- just before the message is sent as
1525 :group
'message-various
1526 :link
'(custom-manual "(message)Various Message Variables")
1529 (defcustom message-send-news-hook nil
1530 "Hook run before sending news messages.
1531 This hook is run very late -- just before the message is sent as
1533 :group
'message-various
1534 :link
'(custom-manual "(message)Various Message Variables")
1537 (defcustom message-sent-hook nil
1538 "Hook run after sending messages."
1539 :group
'message-various
1542 (defvar message-send-coding-system
'binary
1543 "Coding system to encode outgoing mail.")
1545 (defvar message-draft-coding-system
1546 mm-auto-save-coding-system
1547 "*Coding system to compose mail.
1548 If you'd like to make it possible to share draft files between XEmacs
1549 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1550 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1552 (defcustom message-send-mail-partially-limit
1000000
1553 "The limitation of messages sent as message/partial.
1554 The lower bound of message size in characters, beyond which the message
1555 should be sent in several parts. If it is nil, the size is unlimited."
1557 :group
'message-buffers
1558 :link
'(custom-manual "(message)Mail Variables")
1559 :type
'(choice (const :tag
"unlimited" nil
)
1562 (defcustom message-alternative-emails nil
1563 "*Regexp matching alternative email addresses.
1564 The first address in the To, Cc or From headers of the original
1565 article matching this variable is used as the From field of
1568 This variable has precedence over posting styles and anything that runs
1569 off `message-setup-hook'."
1570 :group
'message-headers
1571 :link
'(custom-manual "(message)Message Headers")
1572 :type
'(choice (const :tag
"Always use primary" nil
)
1575 (defcustom message-hierarchical-addresses nil
1576 "A list of hierarchical mail address definitions.
1578 Inside each entry, the first address is the \"top\" address, and
1579 subsequent addresses are subaddresses; this is used to indicate that
1580 mail sent to the first address will automatically be delivered to the
1581 subaddresses. So if the first address appears in the recipient list
1582 for a message, the subaddresses will be removed (if present) before
1583 the mail is sent. All addresses in this structure should be
1586 :group
'message-headers
1587 :type
'(repeat (repeat string
)))
1589 (defcustom message-mail-user-agent nil
1590 "Like `mail-user-agent'.
1591 Except if it is nil, use Gnus native MUA; if it is t, use
1594 :type
'(radio (const :tag
"Gnus native"
1597 (const :tag
"`mail-user-agent'"
1600 (function-item :tag
"Default Emacs mail"
1602 sendmail-user-agent
)
1603 (function-item :tag
"Emacs interface to MH"
1606 (function :tag
"Other"))
1610 (defcustom message-wide-reply-confirm-recipients nil
1611 "Whether to confirm a wide reply to multiple email recipients.
1612 If this variable is nil, don't ask whether to reply to all recipients.
1613 If this variable is non-nil, pose the question \"Reply to all
1614 recipients?\" before a wide reply to multiple recipients. If the user
1615 answers yes, reply to all recipients as usual. If the user answers
1616 no, only reply back to the author."
1618 :group
'message-headers
1619 :link
'(custom-manual "(message)Wide Reply")
1622 (defcustom message-user-fqdn nil
1623 "*Domain part of Message-Ids."
1625 :group
'message-headers
1626 :link
'(custom-manual "(message)News Headers")
1627 :type
'(radio (const :format
"%v " nil
)
1628 (string :format
"FQDN: %v")))
1630 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1632 (mm-coding-system-p 'utf-8
)
1633 (executable-find idna-program
)
1634 (string= (idna-to-ascii "räksmörgås")
1635 "xn--rksmrgs-5wao1o")
1637 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1638 GNU Libidn, and in particular the elisp package \"idna.el\" and
1639 the external program \"idn\", must be installed for this
1640 functionality to work."
1642 :group
'message-headers
1643 :link
'(custom-manual "(message)IDNA")
1644 :type
'(choice (const :tag
"Ask" ask
)
1645 (const :tag
"Never" nil
)
1646 (const :tag
"Always" t
)))
1648 (defcustom message-generate-hashcash
(if (executable-find "hashcash") t
)
1649 "*Whether to generate X-Hashcash: headers.
1650 If t, always generate hashcash headers. If `opportunistic',
1651 only generate hashcash headers if it can be done without the user
1652 waiting (i.e., only asynchronously).
1654 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1655 :group
'message-headers
1656 :link
'(custom-manual "(message)Mail Headers")
1657 :type
'(choice (const :tag
"Always" t
)
1658 (const :tag
"Never" nil
)
1659 (const :tag
"Opportunistic" opportunistic
)))
1661 ;;; Internal variables.
1663 (defvar message-sending-message
"Sending...")
1664 (defvar message-buffer-list nil
)
1665 (defvar message-this-is-news nil
)
1666 (defvar message-this-is-mail nil
)
1667 (defvar message-draft-article nil
)
1668 (defvar message-mime-part nil
)
1669 (defvar message-posting-charset nil
)
1670 (defvar message-inserted-headers nil
)
1672 ;; Byte-compiler warning
1673 (defvar gnus-active-hashtb
)
1674 (defvar gnus-read-active-file
)
1676 ;;; Regexp matching the delimiter of messages in UNIX mail format
1677 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1678 ;;; of rmail.el's rmail-unix-mail-delimiter.
1679 (defvar message-unix-mail-delimiter
1680 (let ((time-zone-regexp
1681 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1682 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1688 ;; Many things can happen to an RFC 822 mailbox before it is put into
1689 ;; a `From' line. The leading phrase can be stripped, e.g.
1690 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1691 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1692 ;; can be removed, e.g.
1693 ;; From: joe@y.z (Joe K
1695 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1698 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1699 ;; The mailbox can be removed or be replaced by white space, e.g.
1700 ;; From: "Joe User"{space}{tab}
1702 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1703 ;; where {space} and {tab} represent the Ascii space and tab characters.
1704 ;; We want to match the results of any of these manglings.
1705 ;; The following regexp rejects names whose first characters are
1706 ;; obviously bogus, but after that anything goes.
1707 "\\([^\0-\b\n-\r\^?].*\\)?"
1709 ;; The time the message was sent.
1710 "\\([^\0-\r \^?]+\\) +" ; day of the week
1711 "\\([^\0-\r \^?]+\\) +" ; month
1712 "\\([0-3]?[0-9]\\) +" ; day of month
1713 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1715 ;; Perhaps a time zone, specified by an abbreviation, or by a
1720 " \\([0-9][0-9]+\\) *"
1722 ;; On some systems the time zone can appear after the year, too.
1726 "\\(remote from .*\\)?"
1729 "Regexp matching the delimiter of messages in UNIX mail format.")
1731 (defvar message-unsent-separator
1732 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1733 "^ *---+ +Returned message +---+ *$\\|"
1734 "^Start of returned message$\\|"
1735 "^ *---+ +Original message +---+ *$\\|"
1736 "^ *--+ +begin message +--+ *$\\|"
1737 "^ *---+ +Original message follows +---+ *$\\|"
1738 "^ *---+ +Undelivered message follows +---+ *$\\|"
1739 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1740 "^|? *---+ +Message text follows: +---+ *|?$")
1741 "A regexp that matches the separator before the text of a failed message.")
1743 (defvar message-field-fillers
1744 '((To message-fill-field-address
)
1745 (Cc message-fill-field-address
)
1746 (From message-fill-field-address
))
1747 "Alist of header names/filler functions.")
1749 (defvar message-header-format-alist
1764 (References . message-shorten-references
)
1766 "Alist used for formatting headers.")
1768 (defvar message-options nil
1769 "Some saved answers when sending message.")
1771 (defvar message-send-mail-real-function nil
1772 "Internal send mail function.")
1774 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1775 "The regexp of bogus system names.")
1777 (defcustom message-valid-fqdn-regexp
1778 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1780 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1781 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1782 "cat\\|com\\|coop\\|edu\\|gov\\|"
1783 "info\\|int\\|jobs\\|"
1784 "mil\\|mobi\\|museum\\|name\\|net\\|"
1785 "org\\|pro\\|travel\\|uucp\\)")
1786 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1787 ;; http://en.wikipedia.org/wiki/GTLD
1788 ;; `in the process of being approved': .asia .post .tel .sex
1789 ;; "dead" nato bitnet uucp
1790 "Regular expression that matches a valid FQDN."
1791 ;; see also: gnus-button-valid-fqdn-regexp
1793 :group
'message-headers
1797 (autoload 'gnus-alive-p
"gnus-util")
1798 (autoload 'gnus-delay-article
"gnus-delay")
1799 (autoload 'gnus-extract-address-components
"gnus-util")
1800 (autoload 'gnus-find-method-for-group
"gnus")
1801 (autoload 'gnus-group-decoded-name
"gnus-group")
1802 (autoload 'gnus-group-name-charset
"gnus-group")
1803 (autoload 'gnus-group-name-decode
"gnus-group")
1804 (autoload 'gnus-groups-from-server
"gnus")
1805 (autoload 'gnus-make-local-hook
"gnus-util")
1806 (autoload 'gnus-open-server
"gnus-int")
1807 (autoload 'gnus-output-to-mail
"gnus-util")
1808 (autoload 'gnus-output-to-rmail
"gnus-util")
1809 (autoload 'gnus-request-post
"gnus-int")
1810 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1811 (autoload 'gnus-server-string
"gnus")
1812 (autoload 'idna-to-ascii
"idna")
1813 (autoload 'message-setup-toolbar
"messagexmas")
1814 (autoload 'mh-new-draft-name
"mh-comp")
1815 (autoload 'mh-send-letter
"mh-comp")
1816 (autoload 'nndraft-request-associate-buffer
"nndraft")
1817 (autoload 'nndraft-request-expire-articles
"nndraft")
1818 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1819 (autoload 'rmail-dont-reply-to
"mail-utils")
1820 (autoload 'rmail-msg-is-pruned
"rmail")
1821 (autoload 'rmail-msg-restore-non-pruned-header
"rmail")
1822 (autoload 'rmail-output
"rmailout"))
1827 ;;; Utility functions.
1830 (defmacro message-y-or-n-p
(question show
&rest text
)
1831 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1832 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1834 (defmacro message-delete-line
(&optional n
)
1835 "Delete the current line (and the next N lines)."
1836 `(delete-region (progn (beginning-of-line) (point))
1837 (progn (forward-line ,(or n
1)) (point))))
1839 (defun message-mark-active-p ()
1840 "Non-nil means the mark and region are currently active in this buffer."
1843 (defun message-unquote-tokens (elems)
1844 "Remove double quotes (\") from strings in list ELEMS."
1845 (mapcar (lambda (item)
1846 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1847 (setq item
(concat (match-string 1 item
)
1848 (match-string 2 item
))))
1852 (defun message-tokenize-header (header &optional separator
)
1853 "Split HEADER into a list of header elements.
1854 SEPARATOR is a string of characters to be used as separators. \",\"
1855 is used by default."
1858 (let ((regexp (format "[%s]+" (or separator
",")))
1860 beg quoted elems paren
)
1862 (mm-enable-multibyte)
1863 (setq beg
(point-min))
1865 (goto-char (point-min))
1870 (cond ((and (> (point) beg
)
1872 (and (looking-at regexp
)
1875 (push (buffer-substring beg
(point)) elems
)
1876 (setq beg
(match-end 0)))
1877 ((eq (char-after) ?
\")
1878 (setq quoted
(not quoted
)))
1879 ((and (eq (char-after) ?\
()
1882 ((and (eq (char-after) ?\
))
1885 (nreverse elems
)))))
1887 (defun message-mail-file-mbox-p (file)
1888 "Say whether FILE looks like a Unix mbox file."
1889 (when (and (file-exists-p file
)
1890 (file-readable-p file
)
1891 (file-regular-p file
))
1893 (nnheader-insert-file-contents file
)
1894 (goto-char (point-min))
1895 (looking-at message-unix-mail-delimiter
))))
1897 (defun message-fetch-field (header &optional not-all
)
1898 "The same as `mail-fetch-field', only remove all newlines.
1899 The buffer is expected to be narrowed to just the header of the message;
1900 see `message-narrow-to-headers-or-head'."
1901 (let* ((inhibit-point-motion-hooks t
)
1902 (value (mail-fetch-field header nil
(not not-all
))))
1904 (while (string-match "\n[\t ]+" value
)
1905 (setq value
(replace-match " " t t value
)))
1908 (defun message-field-value (header &optional not-all
)
1909 "The same as `message-fetch-field', only narrow to the headers first."
1912 (message-narrow-to-headers-or-head)
1913 (message-fetch-field header not-all
))))
1915 (defun message-narrow-to-field ()
1916 "Narrow the buffer to the header on the current line."
1918 (while (looking-at "[ \t]")
1924 (if (re-search-forward "^[^ \n\t]" nil t
)
1927 (goto-char (point-min)))
1929 (defun message-add-header (&rest headers
)
1930 "Add the HEADERS to the message header, skipping those already present."
1933 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1934 (error "Invalid header `%s'" (car headers
)))
1935 (setq hclean
(match-string 1 (car headers
)))
1937 (message-narrow-to-headers)
1938 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1939 (goto-char (point-max))
1940 (if (string-match "\n$" (car headers
))
1941 (insert (car headers
))
1942 (insert (car headers
) ?
\n)))))
1943 (setq headers
(cdr headers
))))
1945 (defmacro message-with-reply-buffer
(&rest forms
)
1946 "Evaluate FORMS in the reply buffer, if it exists."
1947 `(when (and message-reply-buffer
1948 (buffer-name message-reply-buffer
))
1949 (with-current-buffer message-reply-buffer
1952 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1953 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1955 (defun message-fetch-reply-field (header)
1956 "Fetch field HEADER from the message we're replying to."
1957 (message-with-reply-buffer
1959 (mail-narrow-to-head)
1960 (message-fetch-field header
))))
1962 (defun message-strip-list-identifiers (subject)
1963 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1964 (require 'gnus-sum
) ; for gnus-list-identifiers
1965 (let ((regexp (if (stringp gnus-list-identifiers
)
1966 gnus-list-identifiers
1967 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1968 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1969 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1970 (concat (substring subject
0 (match-beginning 1))
1971 (or (match-string 3 subject
)
1972 (match-string 5 subject
))
1977 (defun message-strip-subject-re (subject)
1978 "Remove \"Re:\" from subject lines in string SUBJECT."
1979 (if (string-match message-subject-re-regexp subject
)
1980 (substring subject
(match-end 0))
1983 (defcustom message-replacement-char
"."
1984 "Replacement character used instead of unprintable or not decodable chars."
1985 :group
'message-various
1986 :version
"22.1" ;; Gnus 5.10.9
1987 :type
'(choice string
1991 ;; FIXME: We also should call `message-strip-subject-encoded-words'
1992 ;; when forwarding. Probably in `message-make-forward-subject' and
1993 ;; `message-forward-make-body'.
1995 (defun message-strip-subject-encoded-words (subject)
1996 "Fix non-decodable words in SUBJECT."
1997 ;; Cf. `gnus-simplify-subject-fully'.
1998 (let* ((case-fold-search t
)
1999 (replacement-chars (format "[%s%s%s]"
2000 message-replacement-char
2001 message-replacement-char
2002 message-replacement-char
))
2003 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2008 (goto-char (point-min))
2009 (when (re-search-forward enc-word-re nil t
)
2010 (setq cs-string
(match-string 1)))))
2011 cs-coding q-or-b word-beg word-end
)
2012 (if (or (not have-marker
) ;; No encoded word found...
2013 ;; ... or double encoding was correct:
2014 (and (stringp cs-string
)
2015 (setq cs-string
(downcase cs-string
))
2016 (mm-coding-system-p (intern cs-string
))
2020 Decoded Subject \"%s\"
2021 contains a valid encoded word. Decode again? "
2023 (setq cs-coding
(intern cs-string
))))))
2027 (goto-char (point-min))
2028 (while (re-search-forward enc-word-re nil t
)
2029 (setq cs-string
(downcase (match-string 1))
2030 q-or-b
(match-string 2)
2031 word-beg
(match-beginning 0)
2032 word-end
(match-end 0))
2034 (if (mm-coding-system-p (intern cs-string
))
2035 (setq cs-coding
(intern cs-string
))
2037 ;; No double encoded subject? => bogus charset.
2040 (mm-read-coding-system
2042 Decoded Subject \"%s\"
2043 contains an encoded word. The charset `%s' is unknown or invalid.
2044 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2046 subject cs-string message-replacement-char
)))
2048 (replace-match (concat "=?" (symbol-name cs-coding
)
2051 (goto-char word-beg
)
2052 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2055 (if (string-match "\\`Q\\'" q-or-b
)
2058 (message "Replacing non-decodable characters with \"%s\"."
2059 message-replacement-char
)
2060 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2062 (replace-match message-replacement-char
)))
2064 (message "Replacing non-decodable characters with \"%s\"."
2066 (re-search-forward "[^?]+" word-end t
)
2067 (replace-match replacement-chars
))
2068 (re-search-forward "\\?=")
2069 (replace-match "")))))
2070 (rfc2047-decode-region (point-min) (point-max))
2073 ;;; Start of functions adopted from `message-utils.el'.
2075 (defun message-strip-subject-trailing-was (subject)
2076 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2077 Leading \"Re: \" is not stripped by this function. Use the function
2078 `message-strip-subject-re' for this."
2079 (let* ((query message-subject-trailing-was-query
)
2084 message-subject-trailing-was-ask-regexp
2085 message-subject-trailing-was-regexp
)
2088 (setq new
(substring subject
0 (match-beginning 0))))
2089 (if (or (not found
) (eq query nil
))
2092 (if (message-y-or-n-p
2093 "Strip `(was: <old subject>)' in subject? " t
2095 "Strip `(was: <old subject>)' in subject "
2096 "and use the new one instead?\n\n"
2097 "Current subject is: \""
2099 "New subject would be: \""
2101 "See the variable `message-subject-trailing-was-query' "
2102 "to get rid of this query."
2107 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2109 (defun message-change-subject (new-subject)
2110 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2111 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2114 (read-from-minibuffer "New subject: ")))
2115 (cond ((and (not (or (null new-subject
) ; new subject not empty
2116 (zerop (string-width new-subject
))
2117 (string-match "^[ \t]*$" new-subject
))))
2121 (message-narrow-to-headers)
2122 (message-fetch-field "Subject"))))
2123 (cond ((not old-subject
)
2124 (error "No current subject"))
2127 (regexp-quote new-subject
)
2129 old-subject
)) ; yes, it really is a new subject
2130 ;; delete eventual Re: prefix
2132 (message-strip-subject-re old-subject
))
2133 (message-goto-subject)
2134 (message-delete-line)
2135 (insert (concat "Subject: "
2138 old-subject
")\n")))))))))
2140 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2141 "Mark some region in the current article with enclosing tags.
2142 See `message-mark-insert-begin' and `message-mark-insert-end'.
2143 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2144 (interactive "r\nP")
2146 ;; add to the end of the region first, otherwise end would be invalid
2148 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2150 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2152 (defun message-mark-insert-file (file &optional verbatim
)
2153 "Insert FILE at point, marking it with enclosing tags.
2154 See `message-mark-insert-begin' and `message-mark-insert-end'.
2155 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2156 (interactive "fFile to insert: \nP")
2157 ;; reverse insertion to get correct result.
2159 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2161 (insert-file-contents file
)
2163 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2165 (defun message-add-archive-header ()
2166 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2167 The note can be customized using `message-archive-note'. When called with a
2168 prefix argument, ask for a text to insert. If you don't want the note in the
2169 body, set `message-archive-note' to nil."
2171 (if current-prefix-arg
2172 (setq message-archive-note
2173 (read-from-minibuffer "Reason for No-Archive: "
2174 (cons message-archive-note
0))))
2176 (if (message-goto-signature)
2177 (re-search-backward message-signature-separator
))
2178 (when message-archive-note
2179 (insert message-archive-note
)
2181 (message-add-header message-archive-header
)
2182 (message-sort-headers)))
2184 (defun message-cross-post-followup-to-header (target-group)
2185 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2186 With prefix-argument just set Follow-Up, don't cross-post."
2188 (list ; Completion based on Gnus
2189 (completing-read "Followup To: "
2190 (if (boundp 'gnus-newsrc-alist
)
2192 nil nil
'("poster" .
0)
2193 (if (boundp 'gnus-group-history
)
2194 'gnus-group-history
))))
2195 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2196 (message-goto-newsgroups)
2198 ;; if we already did a crosspost before, kill old target
2199 (if (and message-cross-post-old-target
2201 (regexp-quote (concat "," message-cross-post-old-target
))
2204 ;; unless (followup is to poster or user explicitly asked not
2205 ;; to cross-post, or target-group is already in Newsgroups)
2206 ;; add target-group to Newsgroups line.
2208 ;; def: cross-post, req:no
2209 (and message-cross-post-default
(not current-prefix-arg
))
2210 ;; def: no-cross-post, req:yes
2211 (and (not message-cross-post-default
) current-prefix-arg
))
2212 (not (string-match "poster" target-group
))
2213 (not (string-match (regexp-quote target-group
)
2214 (message-fetch-field "Newsgroups"))))
2216 (insert (concat "," target-group
))))
2217 (end-of-line) ; ensure Followup: comes after Newsgroups:
2218 ;; unless new followup would be identical to Newsgroups line
2219 ;; make a new Followup-To line
2220 (if (not (string-match (concat "^[ \t]*"
2223 (message-fetch-field "Newsgroups")))
2224 (insert (concat "\nFollowup-To: " target-group
)))
2225 (setq message-cross-post-old-target target-group
))
2227 (defun message-cross-post-insert-note (target-group cross-post in-old
2229 "Insert a in message body note about a set Followup or Crosspost.
2230 If there have been previous notes, delete them. TARGET-GROUP specifies the
2231 group to Followup-To. When CROSS-POST is t, insert note about
2232 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2233 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2234 been made to before the user asked for a Crosspost."
2235 ;; start scanning body for previous uses
2236 (message-goto-signature)
2237 (let ((head (re-search-backward
2238 (concat "^" mail-header-separator
)
2239 nil t
))) ; just search in body
2240 (message-goto-signature)
2241 (while (re-search-backward
2242 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2244 (message-delete-line))
2245 (message-goto-signature)
2246 (while (re-search-backward
2247 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2249 (message-delete-line))
2251 (if (message-goto-signature)
2252 (re-search-backward message-signature-separator
))
2255 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2256 (insert (concat message-followup-to-note target-group
"\n"))
2257 (insert (concat message-cross-post-note target-group
"\n")))))
2259 (defun message-cross-post-followup-to (target-group)
2260 "Crossposts message and set Followup-To to TARGET-GROUP.
2261 With prefix-argument just set Follow-Up, don't cross-post."
2263 (list ; Completion based on Gnus
2264 (completing-read "Followup To: "
2265 (if (boundp 'gnus-newsrc-alist
)
2267 nil nil
'("poster" .
0)
2268 (if (boundp 'gnus-group-history
)
2269 'gnus-group-history
))))
2270 (cond ((not (or (null target-group
) ; new subject not empty
2271 (zerop (string-width target-group
))
2272 (string-match "^[ \t]*$" target-group
)))
2274 (let* ((old-groups (message-fetch-field "Newsgroups"))
2275 (in-old (string-match
2276 (regexp-quote target-group
)
2277 (or old-groups
""))))
2278 ;; check whether target exactly matches old Newsgroups
2279 (cond ((not old-groups
)
2280 (error "No current newsgroup"))
2284 (regexp-quote target-group
)
2287 ;; yes, Newsgroups line must change
2288 (message-cross-post-followup-to-header target-group
)
2289 ;; insert note whether we do cross-post or followup-to
2290 (funcall message-cross-post-note-function
2292 (if (or (and message-cross-post-default
2293 (not current-prefix-arg
))
2294 (and (not message-cross-post-default
)
2295 current-prefix-arg
)) t
)
2296 in-old old-groups
))))))))
2298 ;;; Reduce To: to Cc: or Bcc: header
2300 (defun message-reduce-to-to-cc ()
2301 "Replace contents of To: header with contents of Cc: or Bcc: header."
2304 (save-restriction (message-narrow-to-headers)
2305 (message-fetch-field "cc")))
2307 (if (and (not cc-content
)
2310 (message-narrow-to-headers)
2311 (message-fetch-field "bcc"))))
2316 (message-delete-line)
2317 (insert (concat "To: " cc-content
"\n"))
2319 (message-narrow-to-headers)
2320 (message-remove-header (if bcc
2324 ;;; End of functions adopted from `message-utils.el'.
2326 (defun message-remove-header (header &optional is-regexp first reverse
)
2327 "Remove HEADER in the narrowed buffer.
2328 If IS-REGEXP, HEADER is a regular expression.
2329 If FIRST, only remove the first instance of the header.
2330 Return the number of headers removed."
2331 (goto-char (point-min))
2332 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2334 (case-fold-search t
)
2336 (while (and (not (eobp))
2339 (not (looking-at regexp
))
2340 (looking-at regexp
))
2347 ;; There might be a continuation header, so we have to search
2348 ;; until we find a new non-continuation line.
2351 (if (re-search-forward "^[^ \t]" nil t
)
2352 (goto-char (match-beginning 0))
2355 (if (re-search-forward "^[^ \t]" nil t
)
2356 (goto-char (match-beginning 0))
2357 (goto-char (point-max)))))
2360 (defun message-remove-first-header (header)
2361 "Remove the first instance of HEADER if there is more than one."
2363 (regexp (concat "^" (regexp-quote header
) ":")))
2365 (goto-char (point-min))
2366 (while (re-search-forward regexp nil t
)
2369 (message-remove-header header nil t
)
2372 (defun message-narrow-to-headers ()
2373 "Narrow the buffer to the head of the message."
2376 (goto-char (point-min))
2377 (if (re-search-forward
2378 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2381 (goto-char (point-min)))
2383 (defun message-narrow-to-head-1 ()
2384 "Like `message-narrow-to-head'. Don't widen."
2386 (goto-char (point-min))
2387 (if (search-forward "\n\n" nil
1)
2390 (goto-char (point-min)))
2392 (defun message-narrow-to-head ()
2393 "Narrow the buffer to the head of the message.
2394 Point is left at the beginning of the narrowed-to region."
2396 (message-narrow-to-head-1))
2398 (defun message-narrow-to-headers-or-head ()
2399 "Narrow the buffer to the head of the message."
2402 (goto-char (point-min))
2403 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2404 (regexp-quote mail-header-separator
)
2407 (or (match-end 1) (match-beginning 2))
2409 (goto-char (point-min)))
2411 (defun message-news-p ()
2412 "Say whether the current buffer contains a news message."
2413 (and (not message-this-is-mail
)
2414 (or message-this-is-news
2417 (message-narrow-to-headers)
2418 (and (message-fetch-field "newsgroups")
2419 (not (message-fetch-field "posted-to"))))))))
2421 (defun message-mail-p ()
2422 "Say whether the current buffer contains a mail message."
2423 (and (not message-this-is-news
)
2424 (or message-this-is-mail
2427 (message-narrow-to-headers)
2428 (or (message-fetch-field "to")
2429 (message-fetch-field "cc")
2430 (message-fetch-field "bcc")))))))
2432 (defun message-subscribed-p ()
2433 "Say whether we need to insert a MFT header."
2434 (or message-subscribed-regexps
2435 message-subscribed-addresses
2436 message-subscribed-address-file
2437 message-subscribed-address-functions
))
2439 (defun message-next-header ()
2440 "Go to the beginning of the next header."
2442 (or (eobp) (forward-char 1))
2443 (not (if (re-search-forward "^[^ \t]" nil t
)
2445 (goto-char (point-max)))))
2447 (defun message-sort-headers-1 ()
2448 "Sort the buffer as headers using `message-rank' text props."
2449 (goto-char (point-min))
2452 nil
'message-next-header
2454 (message-next-header)
2458 (or (get-text-property (point) 'message-rank
)
2461 (defun message-sort-headers ()
2462 "Sort the headers of the current message according to `message-header-format-alist'."
2466 (let ((max (1+ (length message-header-format-alist
)))
2468 (message-narrow-to-headers)
2469 (while (re-search-forward "^[^ \n]+:" nil t
)
2471 (match-beginning 0) (1+ (match-beginning 0))
2473 (if (setq rank
(length (memq (assq (intern (buffer-substring
2475 (1- (match-end 0))))
2476 message-header-format-alist
)
2477 message-header-format-alist
)))
2480 (message-sort-headers-1))))
2482 (defun message-kill-address ()
2483 "Kill the address under point."
2485 (let ((start (point)))
2486 (message-skip-to-next-address)
2487 (kill-region start
(point))))
2490 (autoload 'Info-goto-node
"info")
2491 (defvar mml2015-use
)
2493 (defun message-info (&optional arg
)
2494 "Display the Message manual.
2496 Prefixed with one \\[universal-argument], display the Emacs MIME
2497 manual. With two \\[universal-argument]'s, display the EasyPG or
2498 PGG manual, depending on the value of `mml2015-use'."
2500 ;; Why not `info', which is in loaddefs.el?
2501 (Info-goto-node (format "(%s)Top"
2505 ((eq arg
4) 'emacs-mime
)
2506 ;; `booleanp' only available in Emacs 22+
2507 ((and (not (memq arg
'(nil t
)))
2521 (defvar message-mode-map nil
)
2523 (unless message-mode-map
2524 (setq message-mode-map
(make-keymap))
2525 (set-keymap-parent message-mode-map text-mode-map
)
2526 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2528 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2529 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2530 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2531 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2532 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2533 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2534 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2535 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2536 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2537 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2538 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2539 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2540 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2541 (define-key message-mode-map
"\C-c\C-f\C-i"
2542 'message-insert-or-toggle-importance
)
2543 (define-key message-mode-map
"\C-c\C-f\C-a"
2544 'message-generate-unsubscribed-mail-followup-to
)
2546 ;; modify headers (and insert notes in body)
2547 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2549 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2550 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2551 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2552 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2553 ;; mark inserted text
2554 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2555 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2557 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2558 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2560 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2561 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2562 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2563 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2564 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2566 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2567 (define-key message-mode-map
"\C-c\M-n"
2568 'message-insert-disposition-notification-to
)
2570 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2571 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2572 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2573 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2574 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2575 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2576 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2577 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2579 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2580 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2581 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2582 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2583 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2585 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2586 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2587 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2588 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2589 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2590 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2592 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2594 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2595 (define-key message-mode-map
"\t" 'message-tab
)
2596 (define-key message-mode-map
"\M-;" 'comment-region
)
2598 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2601 message-mode-menu message-mode-map
"Message Menu."
2603 ["Yank Original" message-yank-original message-reply-buffer
]
2604 ["Fill Yanked Message" message-fill-yanked-message t
]
2605 ["Insert Signature" message-insert-signature t
]
2606 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2607 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2608 ["Elide Region" message-elide-region
2609 :active
(message-mark-active-p)
2610 ,@(if (featurep 'xemacs
) nil
2611 '(:help
"Replace text in region with an ellipsis"))]
2612 ["Delete Outside Region" message-delete-not-region
2613 :active
(message-mark-active-p)
2614 ,@(if (featurep 'xemacs
) nil
2615 '(:help
"Delete all quoted text outside region"))]
2616 ["Kill To Signature" message-kill-to-signature t
]
2617 ["Newline and Reformat" message-newline-and-reformat t
]
2618 ["Rename buffer" message-rename-buffer t
]
2619 ["Spellcheck" ispell-message
2620 ,@(if (featurep 'xemacs
) '(t)
2621 '(:help
"Spellcheck this message"))]
2623 ["Insert Region Marked" message-mark-inserted-region
2624 :active
(message-mark-active-p)
2625 ,@(if (featurep 'xemacs
) nil
2626 '(:help
"Mark region with enclosing tags"))]
2627 ["Insert File Marked..." message-mark-insert-file
2628 ,@(if (featurep 'xemacs
) '(t)
2629 '(:help
"Insert file at point marked with enclosing tags"))]
2631 ["Send Message" message-send-and-exit
2632 ,@(if (featurep 'xemacs
) '(t)
2633 '(:help
"Send this message"))]
2634 ["Postpone Message" message-dont-send
2635 ,@(if (featurep 'xemacs
) '(t)
2636 '(:help
"File this draft message and exit"))]
2637 ["Send at Specific Time..." gnus-delay-article
2638 ,@(if (featurep 'xemacs
) '(t)
2639 '(:help
"Ask, then arrange to send message at that time"))]
2640 ["Kill Message" message-kill-buffer
2641 ,@(if (featurep 'xemacs
) '(t)
2642 '(:help
"Delete this message without sending"))]
2644 ["Message manual" message-info
2645 ,@(if (featurep 'xemacs
) '(t)
2646 '(:help
"Display the Message manual"))]))
2649 message-mode-field-menu message-mode-map
""
2651 ["To" message-goto-to t
]
2652 ["From" message-goto-from t
]
2653 ["Subject" message-goto-subject t
]
2654 ["Change subject..." message-change-subject t
]
2655 ["Cc" message-goto-cc t
]
2656 ["Bcc" message-goto-bcc t
]
2657 ["Fcc" message-goto-fcc t
]
2658 ["Reply-To" message-goto-reply-to t
]
2659 ["Flag As Important" message-insert-importance-high
2660 ,@(if (featurep 'xemacs
) '(t)
2661 '(:help
"Mark this message as important"))]
2662 ["Flag As Unimportant" message-insert-importance-low
2663 ,@(if (featurep 'xemacs
) '(t)
2664 '(:help
"Mark this message as unimportant"))]
2666 message-insert-disposition-notification-to
2667 ,@(if (featurep 'xemacs
) '(t)
2668 '(:help
"Request a receipt notification"))]
2670 ;; (typical) news stuff
2671 ["Summary" message-goto-summary t
]
2672 ["Keywords" message-goto-keywords t
]
2673 ["Newsgroups" message-goto-newsgroups t
]
2674 ["Fetch Newsgroups" message-insert-newsgroups t
]
2675 ["Followup-To" message-goto-followup-to t
]
2676 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2677 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2678 ["Distribution" message-goto-distribution t
]
2679 ["Expires" message-insert-expires t
]
2680 ["X-No-Archive" message-add-archive-header t
]
2682 ;; (typical) mailing-lists stuff
2683 ["Fetch To" message-insert-to
2684 ,@(if (featurep 'xemacs
) '(t)
2685 '(:help
"Insert a To header that points to the author."))]
2686 ["Fetch To and Cc" message-insert-wide-reply
2687 ,@(if (featurep 'xemacs
) '(t)
2689 "Insert To and Cc headers as if you were doing a wide reply."))]
2691 ["Send to list only" message-to-list-only t
]
2692 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2693 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2694 ,@(if (featurep 'xemacs
) '(t)
2695 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2696 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2698 ["Sort Headers" message-sort-headers t
]
2699 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2700 ;; We hide `message-hidden-headers' by narrowing the buffer.
2701 ["Show Hidden Headers" widen t
]
2702 ["Goto Body" message-goto-body t
]
2703 ["Goto Signature" message-goto-signature t
]))
2705 (defvar message-tool-bar-map nil
)
2707 (defvar facemenu-add-face-function
)
2708 (defvar facemenu-remove-face-function
)
2710 ;;; Forbidden properties
2712 ;; We use `after-change-functions' to keep special text properties
2713 ;; that interfer with the normal function of message mode out of the
2716 (defcustom message-strip-special-text-properties t
2717 "Strip special properties from the message buffer.
2719 Emacs has a number of special text properties which can break message
2720 composing in various ways. If this option is set, message will strip
2721 these properties from the message composition buffer. However, some
2722 packages requires these properties to be present in order to work.
2723 If you use one of these packages, turn this option off, and hope the
2724 message composition doesn't break too bad."
2726 :group
'message-various
2727 :link
'(custom-manual "(message)Various Message Variables")
2730 (defconst message-forbidden-properties
2731 ;; No reason this should be clutter up customize. We make it a
2732 ;; property list (rather than a list of property symbols), to be
2733 ;; directly useful for `remove-text-properties'.
2734 '(field nil read-only nil invisible nil intangible nil
2735 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2736 insert-behind-hooks nil point-entered nil point-left nil
)
2737 ;; Other special properties:
2738 ;; category, face, display: probably doesn't do any harm.
2739 ;; fontified: is used by font-lock.
2740 ;; syntax-table, local-map: I dunno.
2741 ;; We need to add XEmacs names to the list.
2742 "Property list of with properties forbidden in message buffers.
2743 The values of the properties are ignored, only the property names are used.")
2745 (defun message-tamago-not-in-use-p (pos)
2746 "Return t when tamago version 4 is not in use at the cursor position.
2747 Tamago version 4 is a popular input method for writing Japanese text.
2748 It uses the properties `intangible', `invisible', `modification-hooks'
2749 and `read-only' when translating ascii or kana text to kanji text.
2750 These properties are essential to work, so we should never strip them."
2751 (not (and (boundp 'egg-modefull-mode
)
2752 (symbol-value 'egg-modefull-mode
)
2753 (or (memq (get-text-property pos
'intangible
)
2754 '(its-part-1 its-part-2
))
2755 (get-text-property pos
'egg-end
)
2756 (get-text-property pos
'egg-lang
)
2757 (get-text-property pos
'egg-start
)))))
2759 (defsubst message-mail-alias-type-p
(type)
2760 (if (atom message-mail-alias-type
)
2761 (eq message-mail-alias-type type
)
2762 (memq type message-mail-alias-type
)))
2764 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2765 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2766 This function is intended to be called from `after-change-functions'.
2767 See also `message-forbidden-properties'."
2768 (when (and (message-mail-alias-type-p 'ecomplete
)
2769 (memq this-command message-self-insert-commands
))
2770 (message-display-abbrev))
2771 (when (and message-strip-special-text-properties
2772 (message-tamago-not-in-use-p begin
))
2773 (let ((buffer-read-only nil
)
2774 (inhibit-read-only t
))
2775 (remove-text-properties begin end message-forbidden-properties
))))
2778 (define-derived-mode message-mode text-mode
"Message"
2779 "Major mode for editing mail and news to be sent.
2780 Like Text Mode but with these additional commands:\\<message-mode-map>
2781 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2782 C-c C-d Postpone sending the message C-c C-k Kill the message
2783 C-c C-f move to a header field (and create it if there isn't):
2784 C-c C-f C-t move to To C-c C-f C-s move to Subject
2785 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2786 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2787 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2788 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2789 C-c C-f C-o move to From (\"Originator\")
2790 C-c C-f C-f move to Followup-To
2791 C-c C-f C-m move to Mail-Followup-To
2792 C-c C-f C-e move to Expires
2793 C-c C-f C-i cycle through Importance values
2794 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2795 C-c C-f x crossposting with FollowUp-To header and note in body
2796 C-c C-f t replace To: header with contents of Cc: or Bcc:
2797 C-c C-f a Insert X-No-Archive: header and a note in the body
2798 C-c C-t `message-insert-to' (add a To header to a news followup)
2799 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2800 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2801 C-c C-b `message-goto-body' (move to beginning of message text).
2802 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2803 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2804 C-c C-y `message-yank-original' (insert current message, if any).
2805 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2806 C-c C-e `message-elide-region' (elide the text between point and mark).
2807 C-c C-v `message-delete-not-region' (remove the text outside the region).
2808 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2809 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2810 C-c C-a `mml-attach-file' (attach a file as MIME).
2811 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2812 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2813 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2814 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2815 M-RET `message-newline-and-reformat' (break the line and reformat)."
2816 (setq local-abbrev-table text-mode-abbrev-table
)
2817 (set (make-local-variable 'message-reply-buffer
) nil
)
2818 (set (make-local-variable 'message-inserted-headers
) nil
)
2819 (set (make-local-variable 'message-send-actions
) nil
)
2820 (set (make-local-variable 'message-exit-actions
) nil
)
2821 (set (make-local-variable 'message-kill-actions
) nil
)
2822 (set (make-local-variable 'message-postpone-actions
) nil
)
2823 (set (make-local-variable 'message-draft-article
) nil
)
2824 (setq buffer-offer-save t
)
2825 (set (make-local-variable 'facemenu-add-face-function
)
2827 (let ((face-fun (cdr (assq face message-face-alist
))))
2829 (funcall face-fun
(point) end
)
2830 (error "Face %s not configured for %s mode" face mode-name
)))
2832 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2833 (set (make-local-variable 'message-reply-headers
) nil
)
2834 (make-local-variable 'message-newsreader
)
2835 (make-local-variable 'message-mailer
)
2836 (make-local-variable 'message-post-method
)
2837 (set (make-local-variable 'message-sent-message-via
) nil
)
2838 (set (make-local-variable 'message-checksum
) nil
)
2839 (set (make-local-variable 'message-mime-part
) 0)
2840 (message-setup-fill-variables)
2841 (when message-fill-column
2842 (setq fill-column message-fill-column
)
2843 (turn-on-auto-fill))
2844 ;; Allow using comment commands to add/remove quoting.
2845 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2846 (when message-yank-prefix
2847 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2848 (set (make-local-variable 'comment-start-skip
)
2849 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2850 (if (featurep 'xemacs
)
2851 (message-setup-toolbar)
2852 (set (make-local-variable 'font-lock-defaults
)
2853 '(message-font-lock-keywords t
))
2854 (if (boundp 'tool-bar-map
)
2855 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2856 (easy-menu-add message-mode-menu message-mode-map
)
2857 (easy-menu-add message-mode-field-menu message-mode-map
)
2858 (gnus-make-local-hook 'after-change-functions
)
2859 ;; Mmmm... Forbidden properties...
2860 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2862 ;; Allow mail alias things.
2864 ((message-mail-alias-type-p 'abbrev
)
2865 (if (fboundp 'mail-abbrevs-setup
)
2866 (mail-abbrevs-setup)
2867 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2868 (mail-aliases-setup))))
2869 ((message-mail-alias-type-p 'ecomplete
)
2871 (unless buffer-file-name
2872 (message-set-auto-save-file-name))
2873 (unless (buffer-base-buffer)
2874 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2875 ;; multibyte is not necessary at all. -- zsh
2876 (mm-enable-multibyte))
2877 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2880 (defun message-setup-fill-variables ()
2881 "Setup message fill variables."
2882 (set (make-local-variable 'fill-paragraph-function
)
2883 'message-fill-paragraph
)
2884 (make-local-variable 'paragraph-separate
)
2885 (make-local-variable 'paragraph-start
)
2886 (make-local-variable 'adaptive-fill-regexp
)
2887 (unless (boundp 'adaptive-fill-first-line-regexp
)
2888 (setq adaptive-fill-first-line-regexp nil
))
2889 (make-local-variable 'adaptive-fill-first-line-regexp
)
2890 (let ((quote-prefix-regexp
2891 ;; User should change message-cite-prefix-regexp if
2892 ;; message-yank-prefix is set to an abnormal value.
2893 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2894 (setq paragraph-start
2896 (regexp-quote mail-header-separator
) "$\\|"
2897 "[ \t]*$\\|" ; blank lines
2898 "-- $\\|" ; signature delimiter
2899 "---+$\\|" ; delimiters for forwarded messages
2900 page-delimiter
"$\\|" ; spoiler warnings
2901 ".*wrote:$\\|" ; attribution lines
2902 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2904 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2905 (setq paragraph-separate paragraph-start
)
2906 (setq adaptive-fill-regexp
2907 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2908 (setq adaptive-fill-first-line-regexp
2909 (concat quote-prefix-regexp
"\\|"
2910 adaptive-fill-first-line-regexp
)))
2911 (make-local-variable 'auto-fill-inhibit-regexp
)
2912 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2913 (setq auto-fill-inhibit-regexp nil
)
2914 (make-local-variable 'normal-auto-fill-function
)
2915 (setq normal-auto-fill-function
'message-do-auto-fill
)
2916 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2917 ;; In that case, ensure that it uses the right function. The real
2918 ;; solution would be not to use `define-derived-mode', and run
2919 ;; `text-mode-hook' ourself at the end of the mode.
2920 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2921 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2922 ;; now careful to run parent hooks after the body. --Stef
2923 (when auto-fill-function
2924 (setq auto-fill-function normal-auto-fill-function
)))
2929 ;;; Message mode commands
2932 ;;; Movement commands
2934 (defun message-goto-to ()
2935 "Move point to the To header."
2937 (message-position-on-field "To"))
2939 (defun message-goto-from ()
2940 "Move point to the From header."
2942 (message-position-on-field "From"))
2944 (defun message-goto-subject ()
2945 "Move point to the Subject header."
2947 (message-position-on-field "Subject"))
2949 (defun message-goto-cc ()
2950 "Move point to the Cc header."
2952 (message-position-on-field "Cc" "To"))
2954 (defun message-goto-bcc ()
2955 "Move point to the Bcc header."
2957 (message-position-on-field "Bcc" "Cc" "To"))
2959 (defun message-goto-fcc ()
2960 "Move point to the Fcc header."
2962 (message-position-on-field "Fcc" "To" "Newsgroups"))
2964 (defun message-goto-reply-to ()
2965 "Move point to the Reply-To header."
2967 (message-position-on-field "Reply-To" "Subject"))
2969 (defun message-goto-newsgroups ()
2970 "Move point to the Newsgroups header."
2972 (message-position-on-field "Newsgroups"))
2974 (defun message-goto-distribution ()
2975 "Move point to the Distribution header."
2977 (message-position-on-field "Distribution"))
2979 (defun message-goto-followup-to ()
2980 "Move point to the Followup-To header."
2982 (message-position-on-field "Followup-To" "Newsgroups"))
2984 (defun message-goto-mail-followup-to ()
2985 "Move point to the Mail-Followup-To header."
2987 (message-position-on-field "Mail-Followup-To" "To"))
2989 (defun message-goto-keywords ()
2990 "Move point to the Keywords header."
2992 (message-position-on-field "Keywords" "Subject"))
2994 (defun message-goto-summary ()
2995 "Move point to the Summary header."
2997 (message-position-on-field "Summary" "Subject"))
2999 (defun message-goto-body (&optional interactivep
)
3000 "Move point to the beginning of the message body."
3001 (interactive (list t
))
3002 (when (and interactivep
3003 (looking-at "[ \t]*\n"))
3005 (goto-char (point-min))
3006 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3007 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3009 (defun message-in-body-p ()
3010 "Return t if point is in the message body."
3011 (let ((body (save-excursion (message-goto-body) (point))))
3014 (defun message-goto-eoh ()
3015 "Move point to the end of the headers."
3020 (defun message-goto-signature ()
3021 "Move point to the beginning of the message signature.
3022 If there is no signature in the article, go to the end and
3025 (goto-char (point-min))
3026 (if (re-search-forward message-signature-separator nil t
)
3028 (goto-char (point-max))
3031 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3032 "Insert a reasonable MFT header in a post to an unsubscribed list.
3033 When making original posts to a mailing list you are not subscribed to,
3034 you have to type in a MFT header by hand. The contents, usually, are
3035 the addresses of the list and your own address. This function inserts
3036 such a header automatically. It fetches the contents of the To: header
3037 in the current mail buffer, and appends the current `user-mail-address'.
3039 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3040 Cc: header are also put into the MFT."
3045 (message-narrow-to-headers)
3046 (message-remove-header "Mail-Followup-To")
3047 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3049 (concat (message-fetch-field "To") "," cc
)
3050 (message-fetch-field "To"))))
3051 (message-goto-mail-followup-to)
3052 (insert (concat tos
", " user-mail-address
))))
3056 (defun message-insert-to (&optional force
)
3057 "Insert a To header that points to the author of the article being replied to.
3058 If the original author requested not to be sent mail, don't insert unless the
3059 prefix FORCE is given."
3061 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3062 (dont (and mct
(or (equal (downcase mct
) "never")
3063 (equal (downcase mct
) "nobody"))))
3064 (to (or (message-fetch-reply-field "mail-reply-to")
3065 (message-fetch-reply-field "reply-to")
3066 (message-fetch-reply-field "from"))))
3070 "Ignoring the user request not to have copies sent via mail"
3071 "Complying with the user request not to have copies sent via mail")))
3072 (when (and force
(not to
))
3073 (error "No mail address in the article"))
3074 (when (and to
(or force
(not dont
)))
3075 (message-carefully-insert-headers (list (cons 'To to
))))))
3077 (defun message-insert-wide-reply ()
3078 "Insert To and Cc headers as if you were doing a wide reply."
3080 (let ((headers (message-with-reply-buffer
3081 (message-get-reply-headers t
))))
3082 (message-carefully-insert-headers headers
)))
3084 (defcustom message-header-synonyms
3087 "List of lists of header synonyms.
3088 E.g., if this list contains a member list with elements `Cc' and `To',
3089 then `message-carefully-insert-headers' will not insert a `To' header
3090 when the message is already `Cc'ed to the recipient."
3092 :group
'message-headers
3093 :link
'(custom-manual "(message)Message Headers")
3094 :type
'(repeat sexp
))
3096 (defun message-carefully-insert-headers (headers)
3097 "Insert the HEADERS, an alist, into the message buffer.
3098 Does not insert the headers when they are already present there
3099 or in the synonym headers, defined by `message-header-synonyms'."
3100 ;; FIXME: Should compare only the address and not the full name. Comparison
3101 ;; should be done case-folded (and with `string=' rather than
3103 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3104 (dolist (header headers
)
3105 (let* ((header-name (symbol-name (car header
)))
3106 (new-header (cdr header
))
3107 (synonyms (loop for synonym in message-header-synonyms
3108 when
(memq (car header
) synonym
) return synonym
))
3110 (loop for synonym in synonyms
3111 for old-header
= (mail-fetch-field (symbol-name synonym
))
3112 when
(and old-header
(string-match new-header old-header
))
3115 (message "already have `%s' in `%s'" new-header old-header
)
3116 (when (and (message-position-on-field header-name
)
3117 (setq old-header
(mail-fetch-field header-name
))
3118 (not (string-match "\\` *\\'" old-header
)))
3120 (insert new-header
)))))
3122 (defun message-widen-reply ()
3123 "Widen the reply to include maximum recipients."
3126 (and message-reply-buffer
3127 (buffer-name message-reply-buffer
)
3128 (with-current-buffer message-reply-buffer
3129 (message-get-reply-headers t
)))))
3132 (message-narrow-to-headers)
3133 (dolist (elem follow-to
)
3134 (message-remove-header (symbol-name (car elem
)))
3135 (goto-char (point-min))
3136 (insert (symbol-name (car elem
)) ": "
3137 (cdr elem
) "\n"))))))
3139 (defun message-insert-newsgroups ()
3140 "Insert the Newsgroups header from the article being replied to."
3142 (when (and (message-position-on-field "Newsgroups")
3143 (mail-fetch-field "newsgroups")
3144 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3146 (insert (or (message-fetch-reply-field "newsgroups") "")))
3150 ;;; Various commands
3152 (defun message-delete-not-region (beg end
)
3153 "Delete everything in the body of the current message outside of the region."
3158 ;; snarf citation prefix, if appropriate
3159 (unless (eq (point) (progn (beginning-of-line) (point)))
3160 (when (looking-at message-cite-prefix-regexp
)
3161 (setq citeprefix
(match-string 0))))
3163 (delete-region (point) (if (not (message-goto-signature))
3169 (delete-region beg
(progn (message-goto-body)
3173 (insert citeprefix
))))
3174 (when (message-goto-signature)
3177 (defun message-kill-to-signature (&optional arg
)
3178 "Kill all text up to the signature.
3179 If a numberic argument or prefix arg is given, leave that number
3180 of lines before the signature intact."
3184 (let ((point (point)))
3185 (narrow-to-region point
(point-max))
3186 (message-goto-signature)
3188 (if (and arg
(numberp arg
))
3189 (forward-line (- -
1 arg
))
3191 (unless (= point
(point))
3192 (kill-region point
(point))
3196 (defun message-newline-and-reformat (&optional arg not-break
)
3197 "Insert four newlines, and then reformat if inside quoted text.
3198 Prefix arg means justify as well."
3199 (interactive (list (if current-prefix-arg
'full
)))
3200 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3201 (setq point
(point))
3204 (setq bolp
(= beg point
))
3205 ;; Find first line of the paragraph.
3207 (while (and (not (eobp))
3208 (not (looking-at message-cite-prefix-regexp
))
3209 (looking-at paragraph-start
))
3212 (when (looking-at message-cite-prefix-regexp
)
3213 (setq quoted
(match-string 0))
3214 (goto-char (match-end 0))
3215 (looking-at "[ \t]*")
3216 (setq leading-space
(match-string 0)))
3220 (< (- point beg
) (length quoted
)))
3221 ;; break inside the cite prefix.
3227 (while (and (not (eobp))
3228 (not (looking-at paragraph-separate
))
3229 (looking-at message-cite-prefix-regexp
)
3230 (equal quoted
(match-string 0)))
3231 (goto-char (match-end 0))
3232 (looking-at "[ \t]*")
3233 (if (> (length leading-space
) (length (match-string 0)))
3234 (setq leading-space
(match-string 0)))
3238 (while (and (if (bobp) nil
(forward-line -
1) t
)
3239 (not (looking-at paragraph-start
))
3240 (looking-at message-cite-prefix-regexp
)
3241 (equal quoted
(match-string 0)))
3243 (goto-char (match-end 0))
3244 (looking-at "[ \t]*")
3245 (if (> (length leading-space
) (length (match-string 0)))
3246 (setq leading-space
(match-string 0)))))
3247 (while (and (not (eobp))
3248 (not (looking-at paragraph-separate
))
3249 (not (looking-at message-cite-prefix-regexp
)))
3253 (while (and (if (bobp) nil
(forward-line -
1) t
)
3254 (not (looking-at paragraph-start
))
3255 (not (looking-at message-cite-prefix-regexp
)))
3256 (setq beg
(point))))
3259 (narrow-to-region beg end
)
3266 (setq point
(point))
3267 ;; (newline 2) doesn't mark both newline's as hard, so call
3268 ;; newline twice. -jas
3271 (delete-region (point) (re-search-forward "[ \t]*"))
3272 (when (and quoted
(not bolp
))
3273 (insert quoted leading-space
)))
3276 (let* ((adaptive-fill-regexp
3277 (regexp-quote (concat quoted leading-space
)))
3278 (adaptive-fill-first-line-regexp
3279 adaptive-fill-regexp
))
3280 (fill-paragraph arg
))
3281 (fill-paragraph arg
))
3282 (if point
(goto-char point
)))))
3284 (defun message-fill-paragraph (&optional arg
)
3285 "Message specific function to fill a paragraph.
3286 This function is used as the value of `fill-paragraph-function' in
3287 Message buffers and is not meant to be called directly."
3288 (interactive (list (if current-prefix-arg
'full
)))
3289 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3291 (if (message-point-in-header-p)
3292 (message-fill-field)
3293 (message-newline-and-reformat arg t
))
3296 (defun message-point-in-header-p ()
3297 "Return t if point is in the header."
3299 (not (re-search-backward
3300 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3302 (defun message-do-auto-fill ()
3303 "Like `do-auto-fill', but don't fill in message header."
3304 (unless (message-point-in-header-p)
3307 (defun message-insert-signature (&optional force
)
3308 "Insert a signature. See documentation for variable `message-signature'."
3309 (interactive (list 0))
3312 ((and (null message-signature
)
3315 (goto-char (point-max))
3316 (not (re-search-backward message-signature-separator nil t
))))
3317 ((and (null message-signature
)
3320 ((functionp message-signature
)
3321 (funcall message-signature
))
3322 ((listp message-signature
)
3323 (eval message-signature
))
3324 (t message-signature
)))
3327 (cond ((stringp signature
)
3329 ((and (eq t signature
) message-signature-file
)
3330 (setq signature-file
3331 (if (and message-signature-directory
3332 ;; don't actually use the signature directory
3333 ;; if message-signature-file contains a path.
3334 (not (file-name-directory
3335 message-signature-file
)))
3336 (nnheader-concat message-signature-directory
3337 message-signature-file
)
3338 message-signature-file
))
3339 (file-exists-p signature-file
))))
3341 (goto-char (point-max))
3342 ;; Insert the signature.
3345 (when message-signature-insert-empty-line
3348 (if (eq signature t
)
3349 (insert-file-contents signature-file
)
3351 (goto-char (point-max))
3352 (or (bolp) (insert "\n")))))
3354 (defun message-insert-importance-high ()
3355 "Insert header to mark message as important."
3359 (message-narrow-to-headers)
3360 (message-remove-header "Importance"))
3362 (insert "Importance: high\n")))
3364 (defun message-insert-importance-low ()
3365 "Insert header to mark message as unimportant."
3369 (message-narrow-to-headers)
3370 (message-remove-header "Importance"))
3372 (insert "Importance: low\n")))
3374 (defun message-insert-or-toggle-importance ()
3375 "Insert a \"Importance: high\" header, or cycle through the header values.
3376 The three allowed values according to RFC 1327 are `high', `normal'
3383 (message-narrow-to-headers)
3384 (when (setq cur
(message-fetch-field "Importance"))
3385 (message-remove-header "Importance")
3386 (setq new
(cond ((string= cur
"high")
3388 ((string= cur
"low")
3393 (insert (format "Importance: %s\n" new
)))))
3395 (defun message-insert-disposition-notification-to ()
3396 "Request a disposition notification (return receipt) to this message.
3397 Note that this should not be used in newsgroups."
3401 (message-narrow-to-headers)
3402 (message-remove-header "Disposition-Notification-To"))
3404 (insert (format "Disposition-Notification-To: %s\n"
3405 (or (message-field-value "Reply-to")
3406 (message-field-value "From")
3407 (message-make-from))))))
3409 (defun message-elide-region (b e
)
3410 "Elide the text in the region.
3411 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3415 (insert message-elide-ellipsis
))
3417 (defvar message-caesar-translation-table nil
)
3419 (defun message-caesar-region (b e
&optional n
)
3420 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3423 (min (point) (or (mark t
) (point)))
3424 (max (point) (or (mark t
) (point)))
3425 (when current-prefix-arg
3426 (prefix-numeric-value current-prefix-arg
))))
3428 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3429 (unless (or (zerop n
) ; no action needed for a rot of 0
3430 (= b e
)) ; no region to rotate
3431 ;; We build the table, if necessary.
3432 (when (or (not message-caesar-translation-table
)
3433 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3434 (setq message-caesar-translation-table
3435 (message-make-caesar-translation-table n
)))
3436 (translate-region b e message-caesar-translation-table
)))
3438 (defun message-make-caesar-translation-table (n)
3439 "Create a rot table with offset N."
3441 (table (make-string 256 0)))
3442 (while (< (incf i
) 256)
3445 (substring table
0 ?A
)
3446 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3447 (substring table ?A
(+ ?A n
))
3448 (substring table
(+ ?A
26) ?a
)
3449 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3450 (substring table ?a
(+ ?a n
))
3451 (substring table
(+ ?a
26) 255))))
3453 (defun message-caesar-buffer-body (&optional rotnum wide
)
3454 "Caesar rotate all letters in the current buffer by 13 places.
3455 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3456 With prefix arg, specifies the number of places to rotate each letter forward.
3457 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3458 (interactive (if current-prefix-arg
3459 (list (prefix-numeric-value current-prefix-arg
))
3463 (when (and (not wide
) (message-goto-body))
3464 (narrow-to-region (point) (point-max)))
3465 (message-caesar-region (point-min) (point-max) rotnum
))))
3467 (defun message-pipe-buffer-body (program)
3468 "Pipe the message body in the current buffer through PROGRAM."
3471 (when (message-goto-body)
3472 (narrow-to-region (point) (point-max)))
3473 (shell-command-on-region
3474 (point-min) (point-max) program nil t
))))
3476 (defun message-rename-buffer (&optional enter-string
)
3477 "Rename the *message* buffer to \"*message* RECIPIENT\".
3478 If the function is run with a prefix, it will ask for a new buffer
3479 name, rather than giving an automatic name."
3480 (interactive "Pbuffer name: ")
3483 (goto-char (point-min))
3484 (narrow-to-region (point)
3485 (search-forward mail-header-separator nil
'end
))
3487 (if (message-news-p) (message-fetch-field "Newsgroups")
3488 (message-fetch-field "To"))
3491 (if (string-match "," mail-to
)
3492 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3494 (name-default (concat "*message* " mail-trimmed-to
))
3495 (name (if enter-string
3496 (read-string "New buffer name: " name-default
)
3498 (rename-buffer name t
)))))
3500 (defun message-fill-yanked-message (&optional justifyp
)
3501 "Fill the paragraphs of a message yanked into this one.
3502 Numeric argument means justify as well."
3505 (goto-char (point-min))
3506 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3507 (let ((fill-prefix message-yank-prefix
))
3508 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3510 (defun message-indent-citation (&optional start end yank-only
)
3511 "Modify text just inserted from a message to be cited.
3512 The inserted text should be the region.
3513 When this function returns, the region is again around the modified text.
3515 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3516 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3517 (unless start
(setq start
(point)))
3519 ;; Remove unwanted headers.
3520 (when message-ignored-cited-headers
3525 (if (search-forward "\n\n" nil t
)
3528 (message-remove-header message-ignored-cited-headers t
)
3529 (when (= (point-min) (point-max))
3530 (setq all-removed t
))
3531 (goto-char (point-max)))
3535 ;; Delete blank lines at the start of the buffer.
3536 (while (and (point-min)
3539 (message-delete-line))
3540 ;; Delete blank lines at the end of the buffer.
3541 (goto-char (point-max))
3544 (while (and (zerop (forward-line -
1))
3546 (message-delete-line)))
3547 ;; Do the indentation.
3548 (if (null message-yank-prefix
)
3549 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3552 (while (< (point) (or end
(mark t
)))
3553 (cond ((looking-at ">")
3554 (insert message-yank-cited-prefix
))
3556 (insert message-yank-empty-prefix
))
3558 (insert message-yank-prefix
)))
3562 (defun message-remove-blank-cited-lines (&optional remove
)
3563 "Remove cited lines containing only blanks.
3564 If REMOVE is non-nil, remove newlines, too.
3566 To use this automatically, you may add this function to
3567 `gnus-message-setup-hook'."
3572 (when (boundp 'message-yank-cited-prefix
)
3573 (concat message-yank-cited-prefix
"\\|"))
3577 (gnus-message 8 "removing `%s'" citexp
)
3580 (while (re-search-forward citexp nil t
)
3581 (replace-match (if remove
"" "\n"))))))
3583 (defvar message-cite-reply-above nil
3584 "If non-nil, start own text above the quote.
3586 Note: Top posting is bad netiquette. Don't use it unless you
3587 really must. You probably want to set variable only for specific
3588 groups, e.g. using `gnus-posting-styles':
3590 (eval (set (make-local-variable 'message-cite-reply-above) t))
3592 This variable has no effect in news postings.")
3594 (defun message-yank-original (&optional arg
)
3595 "Insert the message being replied to, if any.
3596 Puts point before the text and mark after.
3597 Normally indents each nonblank line ARG spaces (default 3). However,
3598 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3600 This function uses `message-cite-function' to do the actual citing.
3602 Just \\[universal-argument] as argument means don't indent, insert no
3603 prefix, and don't delete any headers."
3605 (let ((modified (buffer-modified-p))
3607 (when (and message-reply-buffer
3608 message-cite-function
)
3609 (when message-cite-reply-above
3610 (if (and (not (message-news-p))
3611 (or (eq message-cite-reply-above
'is-evil
)
3613 Top posting is bad netiquette. Please don't top post unless you really must.
3614 Really top post? ")))
3617 (buffer-substring (message-goto-body)
3619 (delete-region (message-goto-body) (point-max)))
3620 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3621 (delete-windows-on message-reply-buffer t
)
3622 (push-mark (save-excursion
3623 (insert-buffer-substring message-reply-buffer
)
3628 (funcall message-cite-function
)
3629 (unless (eq (char-before (mark t
)) ?
\n)
3631 (goto-char (mark t
))
3632 (insert-before-markers ?
\n)
3634 (when message-cite-reply-above
3637 (insert (if (bolp) "\n" "\n\n"))
3638 (message-goto-body))
3639 ;; Add a `message-setup-very-last-hook' here?
3640 ;; Add `gnus-article-highlight-citation' here?
3642 (setq message-checksum
(message-checksum))))))
3644 (defun message-yank-buffer (buffer)
3645 "Insert BUFFER into the current buffer and quote it."
3646 (interactive "bYank buffer: ")
3647 (let ((message-reply-buffer (get-buffer buffer
)))
3648 (save-window-excursion
3649 (message-yank-original))))
3651 (defun message-buffers ()
3652 "Return a list of active message buffers."
3654 (save-current-buffer
3655 (dolist (buffer (buffer-list t
))
3657 (when (and (eq major-mode
'message-mode
)
3658 (null message-sent-message-via
))
3659 (push (buffer-name buffer
) buffers
))))
3660 (nreverse buffers
)))
3662 (defun message-cite-original-1 (strip-signature)
3663 "Cite an original message.
3664 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3667 This function uses `mail-citation-hook' if that is non-nil."
3668 (if (and (boundp 'mail-citation-hook
)
3670 (run-hooks 'mail-citation-hook
)
3671 (let* ((start (point))
3675 (when message-indent-citation-function
3676 (if (listp message-indent-citation-function
)
3677 message-indent-citation-function
3678 (list message-indent-citation-function
))))
3679 ;; This function may be called by `gnus-summary-yank-message' and
3680 ;; may insert a different article from the original. So, we will
3681 ;; modify the value of `message-reply-headers' with that article.
3682 (message-reply-headers
3684 (narrow-to-region start end
)
3685 (message-narrow-to-head-1)
3686 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3688 (or (message-fetch-field "subject") "none")
3689 (or (message-fetch-field "from") "nobody")
3690 (message-fetch-field "date")
3691 (message-fetch-field "message-id" t
)
3692 (message-fetch-field "references")
3694 (mml-quote-region start end
)
3695 (when strip-signature
3699 (when (re-search-backward message-signature-separator start t
)
3700 ;; Also peel off any blank lines before the signature.
3702 (while (looking-at "^[ \t]*$")
3705 (delete-region (point) end
)
3706 (unless (search-backward "\n\n" start t
)
3707 ;; Insert a blank line if it is peeled off.
3710 (mapc 'funcall functions
)
3711 (when message-citation-line-function
3714 (funcall message-citation-line-function
))
3715 (when (and x-no-archive
3716 (not message-cite-articles-with-x-no-archive
)
3717 (string-match "yes" x-no-archive
))
3719 (delete-region (point) (mark t
))
3720 (insert "> [Quoted text removed due to X-No-Archive]\n")
3722 (forward-line -
1)))))
3724 (defun message-cite-original ()
3725 "Cite function in the standard Message manner."
3726 (message-cite-original-1 nil
))
3728 (defvar gnus-extract-address-components
)
3730 (autoload 'format-spec
"format-spec")
3732 (defun message-insert-formatted-citation-line (&optional from date
)
3733 "Function that inserts a formatted citation line.
3735 See `message-citation-line-format'."
3736 ;; The optional args are for testing/debugging. They will disappear later.
3738 ;; (with-temp-buffer
3739 ;; (message-insert-formatted-citation-line
3740 ;; "John Doe <john.doe@example.invalid>"
3743 (when (or message-reply-headers
(and from date
))
3745 (setq from
(mail-header-from message-reply-headers
)))
3746 (let* ((data (condition-case ()
3747 (funcall (if (boundp gnus-extract-address-components
)
3748 gnus-extract-address-components
3749 'mail-extract-address-components
)
3755 (net (car (cdr data
)))
3756 (name-or-net (or (car data
)
3757 (car (cdr data
)) from
))
3761 ;; We need Gnus functionality if the user wants date or time from
3762 ;; the original article:
3763 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3764 (autoload 'gnus-date-get-time
"gnus-util")
3765 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3768 (when (stringp name
)
3769 ;; Guess first name and last name:
3770 (cond ((string-match
3771 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3772 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3773 lname
(nth 1 (split-string name
"[ \t]+"))))
3775 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3776 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3777 lname
(nth 0 (split-string name
"[ \t,]+"))))
3779 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3782 ;; The following letters are not used in `format-time-string':
3783 (push ?E lst
) (push "<E>" lst
)
3784 (push ?F lst
) (push fname lst
)
3785 ;; We might want to use "" instead of "<X>" later.
3786 (push ?J lst
) (push "<J>" lst
)
3787 (push ?K lst
) (push "<K>" lst
)
3788 (push ?L lst
) (push lname lst
)
3789 (push ?N lst
) (push name-or-net lst
)
3790 (push ?O lst
) (push "<O>" lst
)
3791 (push ?P lst
) (push "<P>" lst
)
3792 (push ?Q lst
) (push "<Q>" lst
)
3793 (push ?f lst
) (push from lst
)
3794 (push ?i lst
) (push "<i>" lst
)
3795 (push ?n lst
) (push net lst
)
3796 (push ?o lst
) (push "<o>" lst
)
3797 (push ?q lst
) (push "<q>" lst
)
3798 (push ?t lst
) (push "<t>" lst
)
3799 (push ?v lst
) (push "<v>" lst
)
3800 ;; Delegate the rest to `format-time-string':
3802 (when (and (not (memq i lst
))
3807 (push (condition-case nil
3808 (progn (format-time-string (format "%%%c" i
)
3814 (spec (apply 'format-spec-make flist
)))
3815 (insert (format-spec message-citation-line-format spec
)))
3818 (defun message-cite-original-without-signature ()
3819 "Cite function in the standard Message manner.
3820 This function strips off the signature from the original message."
3821 (message-cite-original-1 t
))
3823 (defun message-insert-citation-line ()
3824 "Insert a simple citation line."
3825 (when message-reply-headers
3826 (insert (mail-header-from message-reply-headers
) " writes:")
3830 (defun message-position-on-field (header &rest afters
)
3831 (let ((case-fold-search t
))
3834 (goto-char (point-min))
3837 (concat "^" (regexp-quote mail-header-separator
) "$"))
3838 (match-beginning 0)))
3839 (goto-char (point-min))
3840 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3842 (re-search-forward "^[^ \t]" nil
'move
)
3844 (skip-chars-backward "\n")
3847 (not (re-search-forward
3848 (concat "^" (regexp-quote (car afters
)) ":")
3852 (re-search-forward "^[^ \t]" nil
'move
)
3853 (beginning-of-line))
3854 (insert header
": \n")
3858 (defun message-remove-signature ()
3859 "Remove the signature from the text between point and mark.
3860 The text will also be indented the normal way."
3862 (let ((start (point))
3864 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3865 ;; No signature here, so we just indent the cited text.
3866 (message-indent-citation)
3867 ;; Find the last non-empty line.
3869 (while (looking-at "[ \t]*$")
3872 (setq mark
(set-marker (make-marker) (point)))
3874 (message-indent-citation)
3875 ;; Enable undoing the deletion.
3877 (delete-region mark
(mark t
))
3878 (set-marker mark nil
)))))
3883 ;;; Sending messages
3886 (defun message-send-and-exit (&optional arg
)
3887 "Send message like `message-send', then, if no errors, exit from mail buffer."
3889 (let ((buf (current-buffer))
3890 (actions message-exit-actions
))
3891 (when (and (message-send arg
)
3893 (if message-kill-buffer-on-exit
3896 (when (eq buf
(current-buffer))
3897 (message-bury buf
)))
3898 (message-do-actions actions
)
3901 (defun message-dont-send ()
3902 "Don't send the message you have been editing.
3903 Instead, just auto-save the buffer and then bury it."
3905 (set-buffer-modified-p t
)
3907 (let ((actions message-postpone-actions
))
3908 (message-bury (current-buffer))
3909 (message-do-actions actions
)))
3911 (defun message-kill-buffer ()
3912 "Kill the current buffer."
3914 (when (or (not (buffer-modified-p))
3915 (not message-kill-buffer-query
)
3916 (yes-or-no-p "Message modified; kill anyway? "))
3917 (let ((actions message-kill-actions
)
3918 (draft-article message-draft-article
)
3919 (auto-save-file-name buffer-auto-save-file-name
)
3920 (file-name buffer-file-name
)
3921 (modified (buffer-modified-p)))
3922 (setq buffer-file-name nil
)
3923 (kill-buffer (current-buffer))
3924 (when (and (or (and auto-save-file-name
3925 (file-exists-p auto-save-file-name
))
3927 (file-exists-p file-name
)))
3929 ;; If the message buffer has lived in a dedicated window,
3930 ;; `kill-buffer' has killed the frame. Thus the
3931 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3932 ;; that the user can see the question by raising the
3935 (yes-or-no-p (format "Remove the backup file%s? "
3936 (if modified
" too" "")))))
3938 (delete-file auto-save-file-name
))
3939 (let ((message-draft-article draft-article
))
3940 (message-disassociate-draft)))
3941 (message-do-actions actions
))))
3943 (defun message-bury (buffer)
3944 "Bury this mail BUFFER."
3945 (let ((newbuf (other-buffer buffer
)))
3946 (bury-buffer buffer
)
3947 (if (and (window-dedicated-p (selected-window))
3948 (not (null (delq (selected-frame) (visible-frame-list)))))
3949 (delete-frame (selected-frame))
3950 (switch-to-buffer newbuf
))))
3952 (defun message-send (&optional arg
)
3953 "Send the message in the current buffer.
3954 If `message-interactive' is non-nil, wait for success indication or
3955 error messages, and inform user.
3956 Otherwise any failure is reported in a message back to the user from
3958 The usage of ARG is defined by the instance that called Message.
3959 It should typically alter the sending method in some way or other."
3961 ;; Make it possible to undo the coming changes.
3963 (let ((inhibit-read-only t
))
3964 (put-text-property (point-min) (point-max) 'read-only nil
))
3965 (message-fix-before-sending)
3966 (run-hooks 'message-send-hook
)
3967 (message message-sending-message
)
3968 (let ((alist message-send-method-alist
)
3970 elem sent dont-barf-on-no-method
3971 (message-options message-options
))
3972 (message-options-set-recipient)
3974 (setq elem
(pop alist
)))
3975 (when (funcall (cadr elem
))
3976 (when (and (or (not (memq (car elem
)
3977 message-sent-message-via
))
3978 (message-fetch-field "supersedes")
3979 (if (or (message-gnksa-enable-p 'multiple-copies
)
3980 (not (eq (car elem
) 'news
)))
3983 "Already sent message via %s; resend? "
3985 (error "Denied posting -- multiple copies")))
3986 (setq success
(funcall (caddr elem
) arg
)))
3990 (let ((fcc (message-fetch-field "Fcc"))
3991 (gcc (message-fetch-field "Gcc")))
3993 (or (eq message-allow-no-recipients
'always
)
3994 (and (not (eq message-allow-no-recipients
'never
))
3995 (setq dont-barf-on-no-method
3997 (format "No receiver, perform %s anyway? "
3998 (cond ((and fcc gcc
) "Fcc and Gcc")
4001 (error "No methods specified to send by"))
4002 (when (or dont-barf-on-no-method
4006 (run-hooks 'message-sent-hook
))
4007 (message "Sending...done")
4008 ;; Do ecomplete address snarfing.
4009 (when (message-mail-alias-type-p 'ecomplete
)
4010 (message-put-addresses-in-ecomplete))
4011 ;; Mark the buffer as unmodified and delete auto-save.
4012 (set-buffer-modified-p nil
)
4013 (delete-auto-save-file-if-necessary t
)
4014 (message-disassociate-draft)
4015 ;; Delete other mail buffers and stuff.
4016 (message-do-send-housekeeping)
4017 (message-do-actions message-send-actions
)
4021 (defun message-send-via-mail (arg)
4022 "Send the current message via mail."
4023 (message-send-mail arg
))
4025 (defun message-send-via-news (arg)
4026 "Send the current message via news."
4027 (funcall message-send-news-function arg
))
4029 (defmacro message-check
(type &rest forms
)
4030 "Eval FORMS if TYPE is to be checked."
4031 `(or (message-check-element ,type
)
4035 (put 'message-check
'lisp-indent-function
1)
4036 (put 'message-check
'edebug-form-spec
'(form body
))
4038 (defun message-text-with-property (prop &optional start end reverse
)
4039 "Return a list of start and end positions where the text has PROP.
4040 START and END bound the search, they default to `point-min' and
4041 `point-max' respectively. If REVERSE is non-nil, find text which does
4044 (setq start
(point-min)))
4046 (setq end
(point-max)))
4050 (setq start
(text-property-any start end prop nil
)))
4051 (setq next
(next-single-property-change start prop nil end
))
4052 (push (cons start
(or next end
)) regions
)
4055 (or (get-text-property start prop
)
4056 (and (setq start
(next-single-property-change
4057 start prop nil end
))
4058 (get-text-property start prop
))))
4059 (setq next
(text-property-any start end prop nil
))
4060 (push (cons start
(or next end
)) regions
)
4062 (nreverse regions
)))
4064 (defcustom message-bogus-address-regexp nil
;; "noreply\\|nospam\\|invalid"
4065 "Regexp of potentially bogus mail addresses."
4066 :version
"23.1" ;; No Gnus
4067 :group
'message-headers
4070 (defun message-fix-before-sending ()
4071 "Do various things to make the message nice before sending it."
4072 ;; Make sure there's a newline at the end of the message.
4073 (goto-char (point-max))
4076 ;; Make the hidden headers visible.
4078 ;; Sort headers before sending the message.
4079 (message-sort-headers)
4080 ;; Make invisible text visible.
4081 ;; It doesn't seem as if this is useful, since the invisible property
4082 ;; is clobbered by an after-change hook anyhow.
4083 (message-check 'invisible-text
4084 (let ((regions (message-text-with-property 'invisible
))
4088 (setq from
(caar regions
)
4090 regions
(cdr regions
))
4091 (put-text-property from to
'invisible nil
)
4092 (message-overlay-put (message-make-overlay from to
)
4094 (unless (yes-or-no-p
4095 "Invisible text found and made visible; continue sending? ")
4096 (error "Invisible text found and made visible")))))
4097 (message-check 'illegible-text
4098 (let (char found choice
)
4101 (skip-chars-forward mm-7bit-chars
)
4102 (when (get-text-property (point) 'no-illegible-text
)
4103 ;; There is a signed or encrypted raw message part
4104 ;; that is considered to be safe.
4105 (goto-char (or (next-single-property-change
4106 (point) 'no-illegible-text
)
4108 (setq char
(char-after)))
4109 (when (or (< (mm-char-int char
) 128)
4110 (and (mm-multibyte-p)
4111 (memq (char-charset char
)
4112 '(eight-bit-control eight-bit-graphic
4114 (not (get-text-property
4115 (point) 'untranslated-utf-8
))))
4116 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4122 (gnus-multiple-choice
4123 "Non-printable characters found. Continue sending?"
4124 `((?d
"Remove non-printable characters and send")
4126 "Replace non-printable characters with \"%s\" and send"
4127 message-replacement-char
))
4128 (?i
"Ignore non-printable characters and send")
4129 (?e
"Continue editing"))))
4131 (error "Non-printable characters"))
4133 (skip-chars-forward mm-7bit-chars
)
4135 (when (let ((char (char-after)))
4136 (or (< (mm-char-int char
) 128)
4137 (and (mm-multibyte-p)
4138 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4139 ;; things like undecable utf-8. Should at least
4140 ;; use find-coding-systems-region.
4141 (memq (char-charset char
)
4142 '(eight-bit-control eight-bit-graphic
4144 (not (get-text-property
4145 (point) 'untranslated-utf-8
)))))
4147 (message-kill-all-overlays)
4149 (when (eq choice ?r
)
4150 (insert message-replacement-char
))))
4152 (skip-chars-forward mm-7bit-chars
)))))
4153 (message-check 'bogus-recipient
4154 ;; Warn before composing or sending a mail to an invalid address.
4155 (message-check-recipients)))
4157 (defun message-bogus-recipient-p (recipients)
4158 "Check if a mail address in RECIPIENTS looks bogus.
4160 RECIPIENTS is a mail header. Return a list of potentially bogus
4161 addresses. If none is found, return nil.
4163 An addresses might be bogus if the domain part is not fully
4164 qualified, see `message-valid-fqdn-regexp', or if it matches
4165 `message-bogus-address-regexp'."
4166 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4168 (mapc (lambda (address)
4169 (setq address
(cadr address
))
4173 (not (string-match "@" address
))
4176 message-valid-fqdn-regexp
"\\)\\'") address
)))
4177 (and (stringp message-bogus-address-regexp
)
4178 (string-match message-bogus-address-regexp address
)))
4179 (push address found
)))
4181 (mail-extract-address-components recipients t
))
4184 (defun message-check-recipients ()
4185 "Warn before composing or sending a mail to an invalid address.
4187 This function could be useful in `message-setup-hook'."
4190 (message-narrow-to-headers)
4191 (dolist (hdr '("To" "Cc" "Bcc"))
4192 (let ((addr (message-fetch-field hdr
)))
4193 (when (stringp addr
)
4194 (dolist (bog (message-bogus-recipient-p addr
))
4198 "Address `%s' might be bogus. Continue? " bog
)))
4199 (error "Bogus address."))))))))
4201 (defun message-add-action (action &rest types
)
4202 "Add ACTION to be performed when doing an exit of type TYPES."
4204 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4207 (defun message-delete-action (action &rest types
)
4208 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4211 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4212 (delq action
(symbol-value var
))))))
4214 (defun message-do-actions (actions)
4215 "Perform all actions in ACTIONS."
4216 ;; Now perform actions on successful sending.
4217 (dolist (action actions
)
4220 ;; A simple function.
4223 ;; Something to be evaled.
4227 (defun message-send-mail-partially ()
4228 "Send mail as message/partial."
4229 ;; replace the header delimiter with a blank line
4230 (goto-char (point-min))
4232 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4233 (replace-match "\n")
4234 (run-hooks 'message-send-mail-hook
)
4235 (let ((p (goto-char (point-min)))
4236 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4237 (curbuf (current-buffer))
4238 (id (message-make-message-id)) (n 1)
4239 plist total header required-mail-headers
)
4241 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4242 (goto-char (point-max))
4243 (goto-char (+ p message-send-mail-partially-limit
))
4245 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4248 (setq total
(length plist
))
4249 (push (point-max) plist
)
4250 (setq plist
(nreverse plist
))
4253 (setq p
(pop plist
))
4256 (copy-to-buffer tembuf p
(car plist
))
4258 (goto-char (point-min))
4261 (goto-char (point-min))
4262 (narrow-to-region (point) (point))
4265 (setq header
(buffer-substring (point-min) (point)))
4266 (goto-char (point-min))
4267 (narrow-to-region (point) (point))
4269 (message-remove-header "Mime-Version")
4270 (message-remove-header "Content-Type")
4271 (message-remove-header "Content-Transfer-Encoding")
4272 (message-remove-header "Message-ID")
4273 (message-remove-header "Lines")
4274 (goto-char (point-max))
4275 (insert "Mime-Version: 1.0\n")
4276 (setq header
(buffer-string)))
4277 (goto-char (point-max))
4278 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4281 (let ((mail-header-separator ""))
4282 (when (memq 'Message-ID message-required-mail-headers
)
4283 (insert "Message-ID: " (message-make-message-id) "\n"))
4284 (when (memq 'Lines message-required-mail-headers
)
4285 (insert "Lines: " (message-make-lines) "\n"))
4286 (message-goto-subject)
4288 (insert (format " (%d/%d)" n total
))
4290 (mm-with-unibyte-current-buffer
4291 (funcall (or message-send-mail-real-function
4292 message-send-mail-function
))))
4294 (setq p
(pop plist
))
4296 (kill-buffer tembuf
))))
4298 (defun message-send-mail (&optional arg
)
4299 (require 'mail-utils
)
4300 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4301 (case-fold-search nil
)
4302 (news (message-news-p))
4303 (mailbuf (current-buffer))
4304 (message-this-is-mail t
)
4305 (message-posting-charset
4306 (if (fboundp 'gnus-setup-posting-charset
)
4307 (gnus-setup-posting-charset nil
)
4308 message-posting-charset
))
4309 (headers message-required-mail-headers
))
4310 (when (and message-generate-hashcash
4311 (not (eq message-generate-hashcash
'opportunistic
)))
4312 (message "Generating hashcash...")
4313 ;; Wait for calculations already started to finish...
4314 (hashcash-wait-async)
4315 ;; ...and do calculations not already done. mail-add-payment
4316 ;; will leave existing X-Hashcash headers alone.
4318 (message "Generating hashcash...done"))
4320 (message-narrow-to-headers)
4321 ;; Generate the Mail-Followup-To header if the header is not there...
4322 (if (and (message-subscribed-p)
4323 (not (mail-fetch-field "mail-followup-to")))
4326 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4327 message-required-mail-headers
))
4328 ;; otherwise, delete the MFT header if the field is empty
4329 (when (equal "" (mail-fetch-field "mail-followup-to"))
4330 (message-remove-header "^Mail-Followup-To:")))
4331 ;; Insert some headers.
4332 (let ((message-deletable-headers
4333 (if news nil message-deletable-headers
)))
4334 (message-generate-headers headers
))
4335 ;; Check continuation headers.
4336 (message-check 'continuation-headers
4337 (goto-char (point-min))
4338 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4339 (goto-char (match-beginning 0))
4340 (if (y-or-n-p "Fix continuation lines? ")
4343 (unless (y-or-n-p "Send anyway? ")
4344 (error "Failed to send the message")))))
4345 ;; Let the user do all of the above.
4346 (run-hooks 'message-header-hook
))
4348 (with-current-buffer tembuf
4350 ;; Avoid copying text props (except hard newlines).
4351 (insert (with-current-buffer mailbuf
4352 (mml-buffer-substring-no-properties-except-hard-newlines
4353 (point-min) (point-max))))
4354 ;; Remove some headers.
4355 (message-encode-message-body)
4357 (message-narrow-to-headers)
4358 ;; We (re)generate the Lines header.
4359 (when (memq 'Lines message-required-mail-headers
)
4360 (message-generate-headers '(Lines)))
4361 ;; Remove some headers.
4362 (message-remove-header message-ignored-mail-headers t
)
4363 (let ((mail-parse-charset message-default-charset
))
4364 (mail-encode-encoded-word-buffer)))
4365 (goto-char (point-max))
4366 ;; require one newline at the end.
4367 (or (= (preceding-char) ?
\n)
4369 (message-cleanup-headers)
4370 ;; FIXME: we're inserting the courtesy copy after encoding.
4371 ;; This is wrong if the courtesy copy string contains
4372 ;; non-ASCII characters. -- jh
4375 (message-narrow-to-headers)
4377 (or (message-fetch-field "cc")
4378 (message-fetch-field "bcc")
4379 (message-fetch-field "to"))
4380 (let ((content-type (message-fetch-field
4385 (string= "text/plain"
4387 (mail-header-parse-content-type
4391 (message-fetch-field
4392 "content-transfer-encoding")))))))
4393 (message-insert-courtesy-copy))
4394 (if (or (not message-send-mail-partially-limit
)
4395 (< (buffer-size) message-send-mail-partially-limit
)
4396 (not (message-y-or-n-p
4397 "The message size is too large, split? "
4401 (/ (buffer-size) 1000) "KB, is too large.
4403 Some mail gateways (MTA's) bounce large messages. To avoid the
4404 problem, answer `y', and the message will be split into several
4405 smaller pieces, the size of each is about "
4406 (/ message-send-mail-partially-limit
1000)
4410 However, some mail readers (MUA's) can't read split messages, i.e.,
4411 mails in message/partially format. Answer `n', and the message will be
4414 The size limit is controlled by `message-send-mail-partially-limit'.
4415 If you always want Gnus to send messages in one piece, set
4416 `message-send-mail-partially-limit' to nil.
4418 (mm-with-unibyte-current-buffer
4419 (message "Sending via mail...")
4420 (funcall (or message-send-mail-real-function
4421 message-send-mail-function
)))
4422 (message-send-mail-partially)))
4423 (kill-buffer tembuf
))
4424 (set-buffer mailbuf
)
4425 (push 'mail message-sent-message-via
)))
4427 (defun message-send-mail-with-sendmail ()
4428 "Send off the prepared buffer with sendmail."
4429 (let ((errbuf (if message-interactive
4430 (message-generate-new-buffer-clone-locals
4433 resend-to-addresses delimline
)
4436 (let ((case-fold-search t
))
4438 (message-narrow-to-headers)
4439 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4440 ;; Change header-delimiter to be what sendmail expects.
4441 (goto-char (point-min))
4443 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4444 (replace-match "\n")
4446 (setq delimline
(point-marker))
4447 (run-hooks 'message-send-mail-hook
)
4448 ;; Insert an extra newline if we need it to work around
4449 ;; Sun's bug that swallows newlines.
4450 (goto-char (1+ delimline
))
4451 (when (eval message-mailer-swallows-blank-line
)
4453 (when message-interactive
4454 (with-current-buffer errbuf
4456 (let* ((default-directory "/")
4457 (coding-system-for-write message-send-coding-system
)
4459 'call-process-region
4461 (list (point-min) (point-max)
4462 (cond ((boundp 'sendmail-program
)
4464 ((file-exists-p "/usr/sbin/sendmail")
4465 "/usr/sbin/sendmail")
4466 ((file-exists-p "/usr/lib/sendmail")
4467 "/usr/lib/sendmail")
4468 ((file-exists-p "/usr/ucblib/sendmail")
4469 "/usr/ucblib/sendmail")
4471 nil errbuf nil
"-oi")
4472 message-sendmail-extra-arguments
4473 ;; Always specify who from,
4474 ;; since some systems have broken sendmails.
4475 ;; But some systems are more broken with -f, so
4476 ;; we'll let users override this.
4477 (if (null message-sendmail-f-is-evil
)
4478 (list "-f" (message-sendmail-envelope-from)))
4479 ;; These mean "report errors by mail"
4480 ;; and "deliver in background".
4481 (if (null message-interactive
) '("-oem" "-odb"))
4482 ;; Get the addresses from the message
4483 ;; unless this is a resend.
4484 ;; We must not do that for a resend
4485 ;; because we would find the original addresses.
4486 ;; For a resend, include the specific addresses.
4487 (if resend-to-addresses
4488 (list resend-to-addresses
)
4490 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4491 (error "Sending...failed with exit value %d" cpr
)))
4492 (when message-interactive
4493 (with-current-buffer errbuf
4494 (goto-char (point-min))
4495 (while (re-search-forward "\n+ *" nil t
)
4496 (replace-match "; "))
4497 (if (not (zerop (buffer-size)))
4498 (error "Sending...failed to %s"
4499 (buffer-string))))))
4500 (when (bufferp errbuf
)
4501 (kill-buffer errbuf
)))))
4503 (defun message-send-mail-with-qmail ()
4504 "Pass the prepared message buffer to qmail-inject.
4505 Refer to the documentation for the variable `message-send-mail-function'
4506 to find out how to use this."
4507 ;; replace the header delimiter with a blank line
4508 (goto-char (point-min))
4510 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4511 (replace-match "\n")
4512 (run-hooks 'message-send-mail-hook
)
4515 (let ((coding-system-for-write message-send-coding-system
))
4517 'call-process-region
(point-min) (point-max)
4518 message-qmail-inject-program nil nil nil
4519 ;; qmail-inject's default behaviour is to look for addresses on the
4520 ;; command line; if there're none, it scans the headers.
4521 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4523 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4524 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4525 ;; message from stdin.
4527 ;; qmail also has the advantage of not having been raped by
4528 ;; various vendors, so we don't have to allow for that, either --
4529 ;; compare this with message-send-mail-with-sendmail and weep
4530 ;; for sendmail's lost innocence.
4532 ;; all this is way cool coz it lets us keep the arguments entirely
4533 ;; free for -inject-arguments -- a big win for the user and for us
4534 ;; since we don't have to play that double-guessing game and the user
4535 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4536 (if (functionp message-qmail-inject-args
)
4537 (funcall message-qmail-inject-args
)
4538 message-qmail-inject-args
)))
4539 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4540 ;; we have to look at the retval instead
4542 (100 (error "qmail-inject reported permanent failure"))
4543 (111 (error "qmail-inject reported transient failure"))
4544 ;; should never happen
4545 (t (error "qmail-inject reported unknown failure"))))
4547 (defun message-send-mail-with-mh ()
4548 "Send the prepared message buffer with mh."
4549 (let ((mh-previous-window-config nil
)
4550 (name (mh-new-draft-name)))
4551 (setq buffer-file-name name
)
4552 ;; MH wants to generate these headers itself.
4553 (when message-mh-deletable-headers
4554 (let ((headers message-mh-deletable-headers
))
4556 (goto-char (point-min))
4557 (and (re-search-forward
4558 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4559 (message-delete-line))
4561 (run-hooks 'message-send-mail-hook
)
4562 ;; Pass it on to mh.
4565 (defun message-smtpmail-send-it ()
4566 "Send the prepared message buffer with `smtpmail-send-it'.
4567 This only differs from `smtpmail-send-it' that this command evaluates
4568 `message-send-mail-hook' just before sending a message. It is useful
4569 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4570 manual for details."
4571 (run-hooks 'message-send-mail-hook
)
4574 (defun message-send-mail-with-mailclient ()
4575 "Send the prepared message buffer with `mailclient-send-it'.
4576 This only differs from `smtpmail-send-it' that this command evaluates
4577 `message-send-mail-hook' just before sending a message."
4578 (run-hooks 'message-send-mail-hook
)
4579 (mailclient-send-it))
4581 (defun message-canlock-generate ()
4582 "Return a string that is non-trivial to guess.
4583 Do not use this for anything important, it is cryptographically weak."
4585 (let (sha1-maximum-internal-length)
4586 (sha1 (concat (message-unique-id)
4587 (format "%x%x%x" (random) (random t
) (random))
4588 (prin1-to-string (recent-keys))
4589 (prin1-to-string (garbage-collect))))))
4591 (defun message-canlock-password ()
4592 "The password used by message for cancel locks.
4593 This is the value of `canlock-password', if that option is non-nil.
4594 Otherwise, generate and save a value for `canlock-password' first."
4595 (unless canlock-password
4596 (customize-save-variable 'canlock-password
(message-canlock-generate))
4597 (setq canlock-password-for-verify canlock-password
))
4600 (defun message-insert-canlock ()
4601 (when message-insert-canlock
4602 (message-canlock-password)
4603 (canlock-insert-header)))
4605 (defun message-send-news (&optional arg
)
4606 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4607 (case-fold-search nil
)
4608 (method (if (functionp message-post-method
)
4609 (funcall message-post-method arg
)
4610 message-post-method
))
4611 (newsgroups-field (save-restriction
4612 (message-narrow-to-headers-or-head)
4613 (message-fetch-field "Newsgroups")))
4614 (followup-field (save-restriction
4615 (message-narrow-to-headers-or-head)
4616 (message-fetch-field "Followup-To")))
4617 ;; BUG: We really need to get the charset for each name in the
4618 ;; Newsgroups and Followup-To lines to allow crossposting
4619 ;; between group namess with incompatible character sets.
4620 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4621 (group-field-charset
4622 (gnus-group-name-charset method newsgroups-field
))
4623 (followup-field-charset
4624 (gnus-group-name-charset method
(or followup-field
"")))
4625 (rfc2047-header-encoding-alist
4626 (append (when group-field-charset
4627 (list (cons "Newsgroups" group-field-charset
)))
4628 (when followup-field-charset
4629 (list (cons "Followup-To" followup-field-charset
)))
4630 rfc2047-header-encoding-alist
))
4631 (messbuf (current-buffer))
4632 (message-syntax-checks
4634 (listp message-syntax-checks
))
4635 (cons '(existing-newsgroups . disabled
)
4636 message-syntax-checks
)
4637 message-syntax-checks
))
4638 (message-this-is-news t
)
4639 (message-posting-charset
4640 (gnus-setup-posting-charset newsgroups-field
))
4642 (if (not (message-check-news-body-syntax))
4645 (message-narrow-to-headers)
4646 ;; Insert some headers.
4647 (message-generate-headers message-required-news-headers
)
4648 (message-insert-canlock)
4649 ;; Let the user do all of the above.
4650 (run-hooks 'message-header-hook
))
4651 ;; Note: This check will be disabled by the ".*" default value for
4652 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4653 (when (and group-field-charset
4654 (listp message-syntax-checks
))
4655 (setq message-syntax-checks
4656 (cons '(valid-newsgroups . disabled
)
4657 message-syntax-checks
)))
4658 (message-cleanup-headers)
4659 (if (not (let ((message-post-method method
))
4660 (message-check-news-syntax)))
4663 (with-current-buffer tembuf
4664 (buffer-disable-undo)
4666 ;; Avoid copying text props (except hard newlines).
4668 (with-current-buffer messbuf
4669 (mml-buffer-substring-no-properties-except-hard-newlines
4670 (point-min) (point-max))))
4671 (message-encode-message-body)
4672 ;; Remove some headers.
4674 (message-narrow-to-headers)
4675 ;; We (re)generate the Lines header.
4676 (when (memq 'Lines message-required-mail-headers
)
4677 (message-generate-headers '(Lines)))
4678 ;; Remove some headers.
4679 (message-remove-header message-ignored-news-headers t
)
4680 (let ((mail-parse-charset message-default-charset
))
4681 (mail-encode-encoded-word-buffer)))
4682 (goto-char (point-max))
4683 ;; require one newline at the end.
4684 (or (= (preceding-char) ?
\n)
4686 (let ((case-fold-search t
))
4687 ;; Remove the delimiter.
4688 (goto-char (point-min))
4690 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4691 (replace-match "\n")
4693 (run-hooks 'message-send-news-hook
)
4694 (gnus-open-server method
)
4695 (message "Sending news via %s..." (gnus-server-string method
))
4696 (setq result
(let ((mail-header-separator ""))
4697 (gnus-request-post method
))))
4698 (kill-buffer tembuf
))
4699 (set-buffer messbuf
)
4701 (push 'news message-sent-message-via
)
4702 (message "Couldn't send message via news: %s"
4703 (nnheader-get-report (car method
)))
4707 ;;; Header generation & syntax checking.
4710 (defun message-check-element (type)
4711 "Return non-nil if this TYPE is not to be checked."
4712 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4714 (let ((able (assq type message-syntax-checks
)))
4716 (eq (cdr able
) 'disabled
)))))
4718 (defun message-check-news-syntax ()
4719 "Check the syntax of the message."
4723 ;; We narrow to the headers and check them first.
4726 (message-narrow-to-headers)
4727 (message-check-news-header-syntax))))))
4729 (defun message-check-news-header-syntax ()
4731 ;; Check Newsgroups header.
4732 (message-check 'newsgroups
4733 (let ((group (message-fetch-field "newsgroups")))
4736 (not (string-match "\\`[ \t]*\\'" group
)))
4739 "The newsgroups field is empty or missing. Posting is denied.")))))
4740 ;; Check the Subject header.
4741 (message-check 'subject
4742 (let* ((case-fold-search t
)
4743 (subject (message-fetch-field "subject")))
4746 (not (string-match "\\`[ \t]*\\'" subject
)))
4749 "The subject field is empty or missing. Posting is denied.")))))
4750 ;; Check for commands in Subject.
4751 (message-check 'subject-cmsg
4752 (if (string-match "^cmsg " (message-fetch-field "subject"))
4754 "The control code \"cmsg\" is in the subject. Really post? ")
4756 ;; Check long header lines.
4757 (message-check 'long-header-lines
4758 (let ((start (point))
4762 (while (and (not found
)
4763 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4764 (if (> (- (point) (match-beginning 0)) 998)
4766 length
(- (point) (match-beginning 0)))
4767 (setq header
(match-string-no-properties 1)))
4768 (setq start
(match-beginning 0))
4771 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4774 ;; Check for multiple identical headers.
4775 (message-check 'multiple-headers
4777 (while (and (not found
)
4778 (re-search-forward "^[^ \t:]+: " nil t
))
4780 (or (re-search-forward
4785 (match-beginning 0) (- (match-end 0) 2))))
4790 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4792 ;; Check for Version and Sendsys.
4793 (message-check 'sendsys
4794 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4796 (format "The article contains a %s command. Really post? "
4797 (buffer-substring (match-beginning 0)
4798 (1- (match-end 0)))))
4800 ;; See whether we can shorten Followup-To.
4801 (message-check 'shorten-followup-to
4802 (let ((newsgroups (message-fetch-field "newsgroups"))
4803 (followup-to (message-fetch-field "followup-to"))
4805 (when (and newsgroups
4806 (string-match "," newsgroups
)
4811 (setq to
(completing-read
4812 "Followups to (default no Followup-To header): "
4815 (message-tokenize-header
4817 (goto-char (point-min))
4818 (insert "Followup-To: " to
"\n"))
4820 ;; Check "Shoot me".
4821 (message-check 'shoot
4822 (if (re-search-forward
4823 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4824 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4826 ;; Check for Approved.
4827 (message-check 'approved
4828 (if (re-search-forward "^Approved:" nil t
)
4829 (y-or-n-p "The article contains an Approved header. Really post? ")
4831 ;; Check the Message-ID header.
4832 (message-check 'message-id
4833 (let* ((case-fold-search t
)
4834 (message-id (message-fetch-field "message-id" t
)))
4835 (or (not message-id
)
4836 ;; Is there an @ in the ID?
4837 (and (string-match "@" message-id
)
4838 ;; Is there a dot in the ID?
4839 (string-match "@[^.]*\\." message-id
)
4840 ;; Does the ID end with a dot?
4841 (not (string-match "\\.>" message-id
)))
4843 (format "The Message-ID looks strange: \"%s\". Really post? "
4845 ;; Check the Newsgroups & Followup-To headers.
4846 (message-check 'existing-newsgroups
4847 (let* ((case-fold-search t
)
4848 (newsgroups (message-fetch-field "newsgroups"))
4849 (followup-to (message-fetch-field "followup-to"))
4850 (groups (message-tokenize-header
4852 (concat newsgroups
"," followup-to
)
4854 (post-method (if (functionp message-post-method
)
4855 (funcall message-post-method
)
4856 message-post-method
))
4857 ;; KLUDGE to handle nnvirtual groups. Doing this right
4858 ;; would probably involve a new nnoo function.
4859 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4860 (method (if (and (consp post-method
)
4861 (eq (car post-method
) 'nnvirtual
)
4862 gnus-message-group-art
)
4863 (let ((group (car (nnvirtual-find-group-art
4864 (car gnus-message-group-art
)
4865 (cdr gnus-message-group-art
)))))
4866 (gnus-find-method-for-group group
))
4870 (gnus-group-name-decode
4871 (gnus-group-real-name n
)
4872 (gnus-group-name-charset method n
)))
4873 (gnus-groups-from-server method
)))
4876 (when (and (not (equal (car groups
) "poster"))
4877 (not (member (car groups
) known-groups
))
4878 (not (member (car groups
) errors
)))
4879 (push (car groups
) errors
))
4882 ;; Gnus is not running.
4883 ((or (not (and (boundp 'gnus-active-hashtb
)
4884 gnus-active-hashtb
))
4885 (not (boundp 'gnus-read-active-file
)))
4887 ;; We don't have all the group names.
4888 ((and (or (not gnus-read-active-file
)
4889 (eq gnus-read-active-file
'some
))
4893 "Really use %s possibly unknown group%s: %s? "
4894 (if (= (length errors
) 1) "this" "these")
4895 (if (= (length errors
) 1) "" "s")
4896 (mapconcat 'identity errors
", "))))
4897 ;; There were no errors.
4900 ;; There are unknown groups.
4904 "Really post to %s unknown group%s: %s? "
4905 (if (= (length errors
) 1) "this" "these")
4906 (if (= (length errors
) 1) "" "s")
4907 (mapconcat 'identity errors
", ")))))))
4908 ;; Check continuation headers.
4909 (message-check 'continuation-headers
4910 (goto-char (point-min))
4911 (let ((do-posting t
))
4912 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4913 (goto-char (match-beginning 0))
4914 (if (y-or-n-p "Fix continuation lines? ")
4917 (unless (y-or-n-p "Send anyway? ")
4918 (setq do-posting nil
))))
4920 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4921 (message-check 'valid-newsgroups
4922 (let ((case-fold-search t
)
4923 (headers '("Newsgroups" "Followup-To"))
4925 (while (and headers
(not error
))
4926 (when (setq header
(mail-fetch-field (car headers
)))
4930 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4935 (not (string-match "\\.\\'\\|\\.\\." g
)))
4936 (message-tokenize-header header
","))))
4943 (format "The %s header looks odd: \"%s\". Really post? "
4944 (car headers
) header
)))))
4945 (message-check 'repeated-newsgroups
4946 (let ((case-fold-search t
)
4947 (headers '("Newsgroups" "Followup-To"))
4948 header error groups group
)
4951 (when (setq header
(mail-fetch-field (pop headers
)))
4952 (setq groups
(message-tokenize-header header
","))
4953 (while (setq group
(pop groups
))
4954 (when (member group groups
)
4960 (format "Group %s is repeated in headers. Really post? " error
)))))
4961 ;; Check the From header.
4962 (message-check 'from
4963 (let* ((case-fold-search t
)
4964 (from (message-fetch-field "from"))
4968 (message "There is no From line. Posting is denied.")
4970 ((or (not (string-match
4972 (setq ad
(nth 1 (mail-extract-address-components
4973 from
))))) ;larsi@ifi
4974 (string-match "\\.\\." ad
) ;larsi@ifi..uio
4975 (string-match "@\\." ad
) ;larsi@.ifi.uio
4976 (string-match "\\.$" ad
) ;larsi@ifi.uio.
4977 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
4978 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
4980 "Denied posting -- the From looks strange: \"%s\"." from
)
4982 ((let ((addresses (rfc822-addresses from
)))
4983 (while (and addresses
4984 (not (eq (string-to-char (car addresses
)) ?\
()))
4985 (setq addresses
(cdr addresses
)))
4988 "Denied posting -- bad From address: \"%s\"." from
)
4991 ;; Check the Reply-To header.
4992 (message-check 'reply-to
4993 (let* ((case-fold-search t
)
4994 (reply-to (message-fetch-field "reply-to"))
4999 ((string-match "," reply-to
)
5001 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5003 ((or (not (string-match
5005 (setq ad
(nth 1 (mail-extract-address-components
5006 reply-to
))))) ;larsi@ifi
5007 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5008 (string-match "@\\." ad
) ;larsi@.ifi.uio
5009 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5010 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5011 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5014 "The Reply-To looks strange: \"%s\". Really post? "
5018 (defun message-check-news-body-syntax ()
5020 ;; Check for long lines.
5021 (message-check 'long-lines
5022 (goto-char (point-min))
5024 (concat "^" (regexp-quote mail-header-separator
) "$"))
5028 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5031 (< (- (point) p
) 80)))
5032 (zerop (forward-line 1))))
5036 "You have lines longer than 79 characters. Really post? ")))
5037 ;; Check whether the article is empty.
5038 (message-check 'empty
5039 (goto-char (point-min))
5041 (concat "^" (regexp-quote mail-header-separator
) "$"))
5044 (goto-char (point-max))
5045 (re-search-backward message-signature-separator nil t
)
5047 (or (re-search-backward "[^ \n\t]" b t
)
5048 (if (message-gnksa-enable-p 'empty-article
)
5049 (y-or-n-p "Empty article. Really post? ")
5050 (message "Denied posting -- Empty article.")
5052 ;; Check for control characters.
5053 (message-check 'control-chars
5054 (if (re-search-forward
5055 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5058 "The article contains control characters. Really post? ")
5060 ;; Check excessive size.
5061 (message-check 'size
5062 (if (> (buffer-size) 60000)
5064 (format "The article is %d octets long. Really post? "
5067 ;; Check whether any new text has been added.
5068 (message-check 'new-text
5070 (not message-checksum
)
5071 (not (eq (message-checksum) message-checksum
))
5072 (if (message-gnksa-enable-p 'quoted-text-only
)
5074 "It looks like no new text has been added. Really post? ")
5075 (message "Denied posting -- no new text has been added.")
5077 ;; Check the length of the signature.
5078 (message-check 'signature
5079 (goto-char (point-max))
5080 (if (not (re-search-backward message-signature-separator nil t
))
5082 (if (>= (count-lines (1+ (point-at-eol)) (point-max)) 5)
5083 (if (message-gnksa-enable-p 'signature
)
5085 (format "Signature is excessively long (%d lines). Really post? "
5086 (count-lines (1+ (point-at-eol)) (point-max))))
5087 (message "Denied posting -- Excessive signature.")
5090 ;; Ensure that text follows last quoted portion.
5091 (message-check 'quoting-style
5092 (goto-char (point-max))
5093 (let ((no-problem t
))
5094 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5095 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5098 (if (message-gnksa-enable-p 'quoted-text-only
)
5099 (y-or-n-p "Your text should follow quoted text. Really post? ")
5101 (goto-char (point-min))
5103 (concat "^" (regexp-quote mail-header-separator
) "$"))
5104 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5105 (y-or-n-p "Your text should follow quoted text. Really post? ")
5106 (message "Denied posting -- only quoted text.")
5109 (defun message-checksum ()
5110 "Return a \"checksum\" for the current buffer."
5113 (goto-char (point-min))
5115 (concat "^" (regexp-quote mail-header-separator
) "$"))
5117 (when (not (looking-at "[ \t\n]"))
5118 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5123 (defun message-do-fcc ()
5124 "Process Fcc headers in the current buffer."
5125 (let ((case-fold-search t
)
5126 (buf (current-buffer))
5128 (mml-externalize-attachments message-fcc-externalize-attachments
))
5131 (message-narrow-to-headers)
5132 (setq file
(message-fetch-field "fcc" t
)))
5134 (set-buffer (get-buffer-create " *message temp*"))
5136 (insert-buffer-substring buf
)
5137 (message-encode-message-body)
5139 (message-narrow-to-headers)
5140 (while (setq file
(message-fetch-field "fcc" t
))
5142 (message-remove-header "fcc" nil t
))
5143 (let ((mail-parse-charset message-default-charset
)
5144 (rfc2047-header-encoding-alist
5145 (cons '("Newsgroups" . default
)
5146 rfc2047-header-encoding-alist
)))
5147 (mail-encode-encoded-word-buffer)))
5148 (goto-char (point-min))
5149 (when (re-search-forward
5150 (concat "^" (regexp-quote mail-header-separator
) "$")
5152 (replace-match "" t t
))
5153 ;; Process FCC operations.
5155 (setq file
(pop list
))
5156 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5157 ;; Pipe the article to the program in question.
5158 (call-process-region (point-min) (point-max) shell-file-name
5159 nil nil nil shell-command-switch
5160 (match-string 1 file
))
5161 ;; Save the article.
5162 (setq file
(expand-file-name file
))
5163 (unless (file-exists-p (file-name-directory file
))
5164 (make-directory (file-name-directory file
) t
))
5165 (if (and message-fcc-handler-function
5166 (not (eq message-fcc-handler-function
'rmail-output
)))
5167 (funcall message-fcc-handler-function file
)
5168 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5169 (rmail-output file
1 nil t
)
5170 (let ((mail-use-rfc822 t
))
5171 (rmail-output file
1 t t
))))))
5172 (kill-buffer (current-buffer))))))
5174 (defun message-output (filename)
5175 "Append this article to Unix/babyl mail file FILENAME."
5176 (if (and (file-readable-p filename
)
5177 (mail-file-babyl-p filename
))
5178 (gnus-output-to-rmail filename t
)
5179 (gnus-output-to-mail filename t
)))
5181 (defun message-cleanup-headers ()
5182 "Do various automatic cleanups of the headers."
5183 ;; Remove empty lines in the header.
5185 (message-narrow-to-headers)
5186 ;; Remove blank lines.
5187 (while (re-search-forward "^[ \t]*\n" nil t
)
5188 (replace-match "" t t
))
5190 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5191 ;; spaces to comma and eliminate spaces around commas. Eliminate
5192 ;; embedded line breaks.
5193 (goto-char (point-min))
5194 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5198 (if (re-search-forward "^[^ \t]" nil t
)
5202 (goto-char (point-min))
5203 (while (re-search-forward "\n[ \t]+" nil t
)
5204 (replace-match " " t t
)) ;No line breaks (too confusing)
5205 (goto-char (point-min))
5206 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5207 (replace-match "," t t
))
5208 (goto-char (point-min))
5209 ;; Remove trailing commas.
5210 (when (re-search-forward ",+$" nil t
)
5211 (replace-match "" t t
))))))
5213 (defun message-make-date (&optional now
)
5214 "Make a valid data header.
5215 If NOW, use that time instead."
5216 (let ((system-time-locale "C"))
5217 (format-time-string "%a, %d %b %Y %T %z" now
)))
5219 (defun message-insert-expires (days)
5220 "Insert the Expires header. Expiry in DAYS days."
5221 (interactive "NExpire article in how many days? ")
5223 (message-position-on-field "Expires" "X-Draft-From")
5224 (insert (message-make-expires-date days
))))
5226 (defun message-make-expires-date (days)
5227 "Make date string for the Expires header. Expiry in DAYS days.
5229 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5230 (let* ((cur (decode-time (current-time)))
5231 (nday (+ days
(nth 3 cur
))))
5232 (setf (nth 3 cur
) nday
)
5233 (message-make-date (apply 'encode-time cur
))))
5235 (defun message-make-message-id ()
5236 "Make a unique Message-ID."
5237 (concat "<" (message-unique-id)
5238 (let ((psubject (save-excursion (message-fetch-field "subject")))
5240 (save-excursion (message-fetch-field "supersedes"))))
5242 (and message-reply-headers
5243 (mail-header-references message-reply-headers
)
5244 (mail-header-subject message-reply-headers
)
5247 (message-strip-subject-re
5248 (mail-header-subject message-reply-headers
))
5249 (message-strip-subject-re psubject
))))
5251 (string-match "_-_@" psupersedes
)))
5253 "@" (message-make-fqdn) ">"))
5255 (defvar message-unique-id-char nil
)
5257 ;; If you ever change this function, make sure the new version
5258 ;; cannot generate IDs that the old version could.
5259 ;; You might for example insert a "." somewhere (not next to another dot
5260 ;; or string boundary), or modify the "fsf" string.
5261 (defun message-unique-id ()
5262 ;; Don't use microseconds from (current-time), they may be unsupported.
5263 ;; Instead we use this randomly inited counter.
5264 (setq message-unique-id-char
5265 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5266 ;; (current-time) returns 16-bit ints,
5267 ;; and 2^16*25 just fits into 4 digits i base 36.
5269 (let ((tm (current-time)))
5271 (if (or (memq system-type
'(ms-dos emx vax-vms
))
5272 ;; message-number-base36 doesn't handle bigints.
5273 (floatp (user-uid)))
5274 (let ((user (downcase (user-login-name))))
5275 (while (string-match "[^a-z0-9_]" user
)
5276 (aset user
(match-beginning 0) ?_
))
5278 (message-number-base36 (user-uid) -
1))
5279 (message-number-base36 (+ (car tm
)
5280 (lsh (% message-unique-id-char
25) 16)) 4)
5281 (message-number-base36 (+ (nth 1 tm
)
5282 (lsh (/ message-unique-id-char
25) 16)) 4)
5283 ;; Append a given name, because while the generated ID is unique
5284 ;; to this newsreader, other newsreaders might otherwise generate
5285 ;; the same ID via another algorithm.
5288 (defun message-number-base36 (num len
)
5293 (concat (message-number-base36 (/ num
36) (1- len
))
5294 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5297 (defun message-make-organization ()
5298 "Make an Organization header."
5299 (let* ((organization
5300 (when message-user-organization
5301 (if (functionp message-user-organization
)
5302 (funcall message-user-organization
)
5303 message-user-organization
))))
5305 (mm-enable-multibyte)
5306 (cond ((stringp organization
)
5307 (insert organization
))
5308 ((and (eq t organization
)
5309 message-user-organization-file
5310 (file-exists-p message-user-organization-file
))
5311 (insert-file-contents message-user-organization-file
)))
5312 (goto-char (point-min))
5313 (while (re-search-forward "[\t\n]+" nil t
)
5314 (replace-match "" t t
))
5315 (unless (zerop (buffer-size))
5318 (defun message-make-lines ()
5319 "Count the number of lines and return numeric string."
5324 (int-to-string (count-lines (point) (point-max))))))
5326 (defun message-make-references ()
5327 "Return the References header for this message."
5328 (when message-reply-headers
5329 (let ((message-id (mail-header-message-id message-reply-headers
))
5330 (references (mail-header-references message-reply-headers
)))
5331 (if (or references message-id
)
5332 (concat (or references
"") (and references
" ")
5336 (defun message-make-in-reply-to ()
5337 "Return the In-Reply-To header for this message."
5338 (when message-reply-headers
5339 (let ((from (mail-header-from message-reply-headers
))
5340 (date (mail-header-date message-reply-headers
))
5341 (msg-id (mail-header-message-id message-reply-headers
)))
5343 (let ((name (mail-extract-address-components from
)))
5345 msg-id
(if msg-id
" (")
5347 (if (string-match "[^\000-\177]" (car name
))
5348 ;; Quote a string containing non-ASCII characters.
5349 ;; It will make the RFC2047 encoder cause an error
5350 ;; if there are special characters.
5351 (mm-with-multibyte-buffer
5353 (goto-char (point-min))
5354 (while (search-forward "\"" nil t
)
5357 (zerop (%
(skip-chars-backward "\\\\") 2))
5358 (goto-char (match-beginning 0)))
5361 ;; Those quotes will be removed by the RFC2047 encoder.
5362 (concat "\"" (buffer-string) "\""))
5366 (if (or (not date
) (string= date
""))
5367 "(unknown date)" date
)
5368 "\"" (if msg-id
")")))))))
5370 (defun message-make-distribution ()
5371 "Make a Distribution header."
5372 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5373 (cond ((functionp message-distribution-function
)
5374 (funcall message-distribution-function
))
5375 (t orig-distribution
))))
5377 (defun message-make-expires ()
5378 "Return an Expires header based on `message-expires'."
5379 (let ((current (current-time))
5380 (future (* 1.0 message-expires
60 60 24)))
5381 ;; Add the future to current.
5382 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5383 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5384 (message-make-date current
)))
5386 (defun message-make-path ()
5388 (let ((login-name (user-login-name)))
5389 (cond ((null message-user-path
)
5390 (concat (system-name) "!" login-name
))
5391 ((stringp message-user-path
)
5392 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5393 (concat message-user-path
"!" login-name
))
5396 (defun message-make-from (&optional name address
)
5397 "Make a From header."
5398 (let* ((style message-from-style
)
5399 (login (or address
(message-make-address)))
5401 (and (boundp 'user-full-name
)
5404 (when (string= fullname
"&")
5405 (setq fullname
(user-login-name)))
5407 (mm-enable-multibyte)
5410 (equal fullname
""))
5412 ((or (eq style
'angles
)
5413 (and (not (eq style
'parens
))
5414 ;; Use angles if no quoting is needed, or if parens would
5415 ;; need quoting too.
5416 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5417 (let ((tmp (concat fullname nil
)))
5418 (while (string-match "([^()]*)" tmp
)
5419 (aset tmp
(match-beginning 0) ?-
)
5420 (aset tmp
(1- (match-end 0)) ?-
))
5421 (string-match "[\\()]" tmp
)))))
5423 (goto-char (point-min))
5424 ;; Look for a character that cannot appear unquoted
5425 ;; according to RFC 822.
5426 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5427 ;; Quote fullname, escaping specials.
5428 (goto-char (point-min))
5430 (while (re-search-forward "[\"\\]" nil
1)
5431 (replace-match "\\\\\\&" t
))
5433 (insert " <" login
">"))
5434 (t ; 'parens or default
5436 (let ((fullname-start (point)))
5438 (goto-char fullname-start
)
5439 ;; RFC 822 says \ and nonmatching parentheses
5440 ;; must be escaped in comments.
5441 ;; Escape every instance of ()\ ...
5442 (while (re-search-forward "[()\\]" nil
1)
5443 (replace-match "\\\\\\&" t
))
5444 ;; ... then undo escaping of matching parentheses,
5445 ;; including matching nested parentheses.
5446 (goto-char fullname-start
)
5447 (while (re-search-forward
5448 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5450 (replace-match "\\1(\\3)" t
)
5451 (goto-char fullname-start
)))
5455 (defun message-make-sender ()
5456 "Return the \"real\" user address.
5457 This function tries to ignore all user modifications, and
5458 give as trustworthy answer as possible."
5459 (concat (user-login-name) "@" (system-name)))
5461 (defun message-make-address ()
5462 "Make the address of the user."
5463 (or (message-user-mail-address)
5464 (concat (user-login-name) "@" (message-make-domain))))
5466 (defun message-user-mail-address ()
5467 "Return the pertinent part of `user-mail-address'."
5468 (when (and user-mail-address
5469 (string-match "@.*\\." user-mail-address
))
5470 (if (string-match " " user-mail-address
)
5471 (nth 1 (mail-extract-address-components user-mail-address
))
5472 user-mail-address
)))
5474 (defun message-sendmail-envelope-from ()
5475 "Return the envelope from."
5476 (cond ((eq message-sendmail-envelope-from
'header
)
5477 (nth 1 (mail-extract-address-components
5478 (message-fetch-field "from"))))
5479 ((stringp message-sendmail-envelope-from
)
5480 message-sendmail-envelope-from
)
5482 (message-make-address))))
5484 (defun message-make-fqdn ()
5485 "Return user's fully qualified domain name."
5486 (let* ((system-name (system-name))
5487 (user-mail (message-user-mail-address))
5490 (string-match "@\\(.*\\)\\'" user-mail
))
5491 (match-string 1 user-mail
)))
5492 (case-fold-search t
))
5494 ((and message-user-fqdn
5495 (stringp message-user-fqdn
)
5496 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5497 (not (string-match message-bogus-system-names message-user-fqdn
)))
5498 ;; `message-user-fqdn' seems to be valid
5500 ((and (string-match message-valid-fqdn-regexp system-name
)
5501 (not (string-match message-bogus-system-names system-name
)))
5502 ;; `system-name' returned the right result.
5504 ;; Try `mail-host-address'.
5505 ((and (boundp 'mail-host-address
)
5506 (stringp mail-host-address
)
5507 (string-match message-valid-fqdn-regexp mail-host-address
)
5508 (not (string-match message-bogus-system-names mail-host-address
)))
5510 ;; We try `user-mail-address' as a backup.
5512 (stringp user-domain
)
5513 (string-match message-valid-fqdn-regexp user-domain
)
5514 (not (string-match message-bogus-system-names user-domain
)))
5516 ;; Default to this bogus thing.
5519 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5521 (defun message-make-host-name ()
5522 "Return the name of the host."
5523 (let ((fqdn (message-make-fqdn)))
5524 (string-match "^[^.]+\\." fqdn
)
5525 (substring fqdn
0 (1- (match-end 0)))))
5527 (defun message-make-domain ()
5528 "Return the domain name."
5529 (or mail-host-address
5530 (message-make-fqdn)))
5532 (defun message-to-list-only ()
5533 "Send a message to the list only.
5534 Remove all addresses but the list address from To and Cc headers."
5536 (let ((listaddr (message-make-mail-followup-to t
)))
5539 (message-remove-header "to")
5540 (message-remove-header "cc")
5541 (message-position-on-field "To" "X-Draft-From")
5542 (insert listaddr
)))))
5544 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5545 "Return the Mail-Followup-To header.
5546 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5547 subscribed address (and not the additional To and Cc header contents)."
5548 (let* ((case-fold-search t
)
5549 (to (message-fetch-field "To"))
5550 (cc (message-fetch-field "cc"))
5551 (msg-recipients (concat to
(and to cc
", ") cc
))
5553 (mapcar 'mail-strip-quoted-names
5554 (message-tokenize-header msg-recipients
)))
5556 (if message-subscribed-address-file
5557 (let (begin end item re
)
5560 (insert-file-contents message-subscribed-address-file
)
5562 (setq begin
(point))
5565 (if (bolp) (setq end
(1- end
)))
5566 (setq item
(regexp-quote (buffer-substring begin end
)))
5567 (if re
(setq re
(concat re
"\\|" item
))
5568 (setq re
(concat "\\`\\(" item
))))
5569 (and re
(list (concat re
"\\)\\'"))))))))
5570 (mft-regexps (apply 'append message-subscribed-regexps
5571 (mapcar 'regexp-quote
5572 message-subscribed-addresses
)
5575 message-subscribed-address-functions
))))
5578 (loop for recipient in recipients
5579 when
(loop for regexp in mft-regexps
5580 when
(string-match regexp recipient
) return t
)
5583 (if only-show-subscribed
5585 msg-recipients
))))))
5587 (defun message-idna-to-ascii-rhs-1 (header)
5588 "Interactively potentially IDNA encode domain names in HEADER."
5589 (let ((field (message-fetch-field header
))
5593 (mm-delete-duplicates
5594 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5597 'car
(mail-header-parse-addresses field
))))))
5598 (setq ace
(if (string-match "\\`[[:ascii:]]+\\'" rhs
)
5600 (downcase (idna-to-ascii rhs
))))
5601 (when (and (not (equal rhs ace
))
5602 (or (not (eq message-use-idna
'ask
))
5603 (y-or-n-p (format "Replace %s with %s in %s:? "
5605 (goto-char (point-min))
5606 (while (re-search-forward (concat "^" header
":") nil t
)
5607 (message-narrow-to-field)
5608 (while (search-forward (concat "@" rhs
) nil t
)
5609 (replace-match (concat "@" ace
) t t
))
5610 (goto-char (point-max))
5613 (defun message-idna-to-ascii-rhs ()
5614 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5615 See `message-idna-encode'."
5617 (when message-use-idna
5620 (message-narrow-to-head)
5621 (message-idna-to-ascii-rhs-1 "From")
5622 (message-idna-to-ascii-rhs-1 "To")
5623 (message-idna-to-ascii-rhs-1 "Reply-To")
5624 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5625 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5626 (message-idna-to-ascii-rhs-1 "Cc")))))
5628 (defun message-generate-headers (headers)
5629 "Prepare article HEADERS.
5630 Headers already prepared in the buffer are not modified."
5631 (setq headers
(append headers message-required-headers
))
5633 (message-narrow-to-headers)
5634 (let* ((Date (message-make-date))
5635 (Message-ID (message-make-message-id))
5636 (Organization (message-make-organization))
5637 (From (message-make-from))
5638 (Path (message-make-path))
5641 (In-Reply-To (message-make-in-reply-to))
5642 (References (message-make-references))
5644 (Distribution (message-make-distribution))
5645 (Lines (message-make-lines))
5646 (User-Agent message-newsreader
)
5647 (Expires (message-make-expires))
5648 (case-fold-search t
)
5650 header value elem header-string
)
5651 ;; First we remove any old generated headers.
5652 (let ((headers message-deletable-headers
))
5653 (unless (buffer-modified-p)
5654 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5656 (goto-char (point-min))
5657 (and (re-search-forward
5658 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5659 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5660 (message-delete-line))
5662 ;; Go through all the required headers and see if they are in the
5663 ;; articles already. If they are not, or are empty, they are
5664 ;; inserted automatically - except for Subject, Newsgroups and
5667 (goto-char (point-min))
5668 (setq elem
(pop headers
))
5670 (if (eq (car elem
) 'optional
)
5671 (setq header
(cdr elem
)
5673 (setq header
(car elem
)))
5675 (setq header-string
(if (stringp header
)
5677 (symbol-name header
)))
5678 (when (or (not (re-search-forward
5680 (regexp-quote (downcase header-string
))
5684 ;; The header was found. We insert a space after the
5685 ;; colon, if there is none.
5686 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5687 ;; Find out whether the header is empty.
5688 (looking-at "[ \t]*\n[^ \t]")))
5689 ;; So we find out what value we should insert.
5693 (eq (car elem
) 'optional
)
5694 (not (member header-string message-inserted-headers
)))
5695 ;; This is an optional header. If the cdr of this
5696 ;; is something that is nil, then we do not insert
5698 (setq header
(cdr elem
))
5699 (or (and (functionp (cdr elem
))
5700 (funcall (cdr elem
)))
5701 (and (boundp (cdr elem
))
5702 (symbol-value (cdr elem
)))))
5704 ;; The element is a cons. Either the cdr is a
5705 ;; string to be inserted verbatim, or it is a
5706 ;; function, and we insert the value returned from
5708 (or (and (stringp (cdr elem
))
5710 (and (functionp (cdr elem
))
5711 (funcall (cdr elem
)))))
5712 ((and (boundp header
)
5713 (symbol-value header
))
5714 ;; The element is a symbol. We insert the value
5715 ;; of this symbol, if any.
5716 (symbol-value header
))
5717 ((not (message-check-element
5718 (intern (downcase (symbol-name header
)))))
5719 ;; We couldn't generate a value for this header,
5720 ;; so we just ask the user.
5721 (read-from-minibuffer
5722 (format "Empty header for %s; enter value: " header
)))))
5723 ;; Finally insert the header.
5725 (not (equal value
"")))
5729 ;; This header didn't exist, so we insert it.
5730 (goto-char (point-max))
5732 (cdr (assq header message-header-format-alist
))))
5734 (funcall formatter header value
)
5735 (insert header-string
": " value
))
5736 (goto-char (message-fill-field))
5737 ;; We check whether the value was ended by a
5738 ;; newline. If not, we insert one.
5742 ;; The value of this header was empty, so we clear
5743 ;; totally and insert the new value.
5744 (delete-region (point) (point-at-eol))
5745 ;; If the header is optional, and the header was
5746 ;; empty, we can't insert it anyway.
5748 (push header-string message-inserted-headers
)
5750 (message-fill-field)))
5751 ;; Add the deletable property to the headers that require it.
5752 (and (memq header message-deletable-headers
)
5753 (progn (beginning-of-line) (looking-at "[^:]+: "))
5754 (add-text-properties
5755 (point) (match-end 0)
5756 '(message-deletable t face italic
) (current-buffer)))))))
5757 ;; Insert new Sender if the From is strange.
5758 (let ((from (message-fetch-field "from"))
5759 (sender (message-fetch-field "sender"))
5760 (secure-sender (message-make-sender)))
5762 (not (message-check-element 'sender
))
5765 (cadr (mail-extract-address-components from
)))
5766 (downcase secure-sender
)))
5771 (cadr (mail-extract-address-components sender
)))
5772 (downcase secure-sender
)))))
5773 (goto-char (point-min))
5774 ;; Rename any old Sender headers to Original-Sender.
5775 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5777 (insert "Original-")
5778 (beginning-of-line))
5779 (when (or (message-news-p)
5780 (string-match "@.+\\.." secure-sender
))
5781 (insert "Sender: " secure-sender
"\n"))))
5783 (message-idna-to-ascii-rhs))))
5785 (defun message-insert-courtesy-copy ()
5786 "Insert a courtesy message in mail copies of combined messages."
5790 (message-narrow-to-headers)
5791 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5792 (goto-char (point-max))
5793 (insert "Posted-To: " newsgroups
"\n")))
5795 (when message-courtesy-message
5797 ((string-match "%s" message-courtesy-message
)
5798 (insert (format message-courtesy-message newsgroups
)))
5800 (insert message-courtesy-message
)))))))
5803 ;;; Setting up a message buffer
5806 (defun message-skip-to-next-address ()
5807 (let ((end (save-excursion
5808 (message-next-header)
5811 (when (looking-at ",")
5813 (while (and (not (= (point) end
))
5814 (or (not (eq char ?
,))
5816 (skip-chars-forward "^,\"" (point-max))
5817 (when (eq (setq char
(following-char)) ?
\")
5818 (setq quoted
(not quoted
)))
5819 (unless (= (point) end
)
5821 (skip-chars-forward " \t\n")))
5823 (defun message-fill-address (header value
)
5824 (insert (capitalize (symbol-name header
))
5826 (if (consp value
) (car value
) value
)
5828 (message-fill-field-address))
5830 (defun message-split-line ()
5831 "Split current line, moving portion beyond point vertically down.
5832 If the current line has `message-yank-prefix', insert it on the new line."
5835 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5839 (defun message-insert-header (header value
)
5840 (insert (capitalize (symbol-name header
))
5842 (if (consp value
) (car value
) value
)))
5844 (defun message-field-name ()
5846 (goto-char (point-min))
5847 (when (looking-at "\\([^:]+\\):")
5848 (intern (capitalize (match-string 1))))))
5850 (defun message-fill-field ()
5853 (message-narrow-to-field)
5854 (let ((field-name (message-field-name)))
5855 (funcall (or (cadr (assq field-name message-field-fillers
))
5856 'message-fill-field-general
)))
5859 (defun message-fill-field-address ()
5861 (message-skip-to-next-address)
5863 (if (and (> (current-column) 78)
5869 (setq last
(1+ (point))))
5870 (setq last
(1+ (point)))))))
5872 (defun message-fill-field-general ()
5873 (let ((begin (point))
5876 (while (and (search-forward "\n" nil t
)
5878 (replace-match " " t t
))
5879 (fill-region-as-paragraph begin
(point-max))
5880 ;; Tapdance around looong Message-IDs.
5882 (when (looking-at "[ \t]*$")
5883 (message-delete-line))
5885 (search-forward ":" nil t
)
5886 (when (looking-at "\n[ \t]+")
5887 (replace-match " " t t
))
5888 (goto-char (point-max))))
5890 (defun message-shorten-1 (list cut surplus
)
5891 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5892 (setcdr (nthcdr (- cut
2) list
)
5893 (nthcdr (+ (- cut
2) surplus
1) list
)))
5895 (defun message-shorten-references (header references
)
5896 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5897 When sending via news, also check that the REFERENCES are less
5898 than 988 characters long, and if they are not, trim them until
5906 (goto-char (point-min))
5907 ;; Cons a list of valid references. GNKSA says we must not include MIDs
5908 ;; with whitespace or missing brackets (7.a "Does not propagate broken
5909 ;; Message-IDs in original References").
5910 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
5911 (push (match-string 0) refs
))
5912 (setq refs
(nreverse refs
)
5913 count
(length refs
)))
5915 ;; If the list has more than MAXCOUNT elements, trim it by
5916 ;; removing the CUTth element and the required number of
5917 ;; elements that follow.
5918 (when (> count maxcount
)
5919 (let ((surplus (- count maxcount
)))
5920 (message-shorten-1 refs cut surplus
)
5921 (decf count surplus
)))
5923 ;; When sending via news, make sure the total folded length will
5924 ;; be less than 998 characters. This is to cater to broken INN
5925 ;; 2.3 which counts the total number of characters in a header
5926 ;; rather than the physical line length of each line, as it should.
5928 ;; This hack should be removed when it's believed than INN 2.3 is
5929 ;; no longer widely used.
5931 ;; At this point the headers have not been generated, thus we use
5932 ;; message-this-is-news directly.
5933 (when message-this-is-news
5936 (message-insert-header
5937 header
(mapconcat #'identity refs
" "))
5939 (message-shorten-1 refs cut
1)))
5940 ;; Finally, collect the references back into a string and insert
5941 ;; it into the buffer.
5942 (message-insert-header header
(mapconcat #'identity refs
" "))))
5944 (defun message-position-point ()
5945 "Move point to where the user probably wants to find it."
5946 (message-narrow-to-headers)
5948 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
5949 (search-backward ":" )
5952 (if (eq (char-after) ?
)
5956 (goto-char (point-max))
5959 (unless (looking-at "$")
5963 (defcustom message-beginning-of-line t
5964 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5965 goes to beginning of header values."
5967 :group
'message-buffers
5968 :link
'(custom-manual "(message)Movement")
5971 (defun message-beginning-of-line (&optional n
)
5972 "Move point to beginning of header value or to beginning of line.
5973 The prefix argument N is passed directly to `beginning-of-line'.
5975 This command is identical to `beginning-of-line' if point is
5976 outside the message header or if the option `message-beginning-of-line'
5979 If point is in the message header and on a (non-continued) header
5980 line, move point to the beginning of the header value or the beginning of line,
5981 whichever is closer. If point is already at beginning of line, move point to
5982 beginning of header value. Therefore, repeated calls will toggle point
5983 between beginning of field and beginning of line."
5985 (let ((zrs 'zmacs-region-stays
))
5986 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
5988 (if (and message-beginning-of-line
5989 (message-point-in-header-p))
5990 (let* ((here (point))
5991 (bol (progn (beginning-of-line n
) (point)))
5992 (eol (point-at-eol))
5993 (eoh (re-search-forward ": *" eol t
)))
5995 (if (and eoh
(or (< eoh here
) (= bol here
)))
5997 (beginning-of-line n
)))
5999 (defun message-buffer-name (type &optional to group
)
6000 "Return a new (unique) buffer name based on TYPE and TO."
6002 ;; Generate a new buffer name The Message Way.
6003 ((memq message-generate-new-buffers
'(unique t
))
6004 (generate-new-buffer-name
6008 (or (car (mail-extract-address-components to
))
6011 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6013 ;; Check whether `message-generate-new-buffers' is a function,
6014 ;; and if so, call it.
6015 ((functionp message-generate-new-buffers
)
6016 (funcall message-generate-new-buffers type to group
))
6017 ((eq message-generate-new-buffers
'unsent
)
6018 (generate-new-buffer-name
6019 (concat "*unsent " type
6022 (or (car (mail-extract-address-components to
))
6025 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6027 ;; Search for the existing message buffer with the specified name.
6029 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6030 (generate-new-buffer-name (concat "*" type
" message*"))
6031 (let ((message-generate-new-buffers 'unique
))
6032 (message-buffer-name type to group
))))
6033 (regexp (concat "\\`"
6035 (if (string-match "<[0-9]+>\\'" new
)
6036 (substring new
0 (match-beginning 0))
6038 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6039 (case-fold-search nil
))
6046 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6047 (eq (with-current-buffer b major-mode
)
6049 (cons (string-to-number (or (match-string 1 b
) "1"))
6052 'car-less-than-car
)))
6055 (defun message-pop-to-buffer (name &optional switch-function
)
6056 "Pop to buffer NAME, and warn if it already exists and is modified."
6057 (let ((buffer (get-buffer name
)))
6059 (buffer-name buffer
))
6060 (let ((window (get-buffer-window buffer
0)))
6062 ;; Raise the frame already displaying the message buffer.
6064 (gnus-select-frame-set-input-focus (window-frame window
))
6065 (select-window window
))
6066 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6067 (set-buffer buffer
))
6068 (when (and (buffer-modified-p)
6071 "Message already being composed; erase? ")
6073 (error "Message being composed")))
6074 (funcall (or switch-function
'pop-to-buffer
) name
)
6079 (defun message-do-send-housekeeping ()
6080 "Kill old message buffers."
6081 ;; We might have sent this buffer already. Delete it from the
6083 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6084 (while (and message-max-buffers
6086 (>= (length message-buffer-list
) message-max-buffers
))
6087 ;; Kill the oldest buffer -- unless it has been changed.
6088 (let ((buffer (pop message-buffer-list
)))
6089 (when (and (buffer-name buffer
)
6090 (not (buffer-modified-p buffer
)))
6091 (kill-buffer buffer
))))
6092 ;; Rename the buffer.
6093 (if message-send-rename-function
6094 (funcall message-send-rename-function
)
6095 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6097 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6099 (let ((name (match-string 2 (buffer-name)))
6101 (if (not (or (null name
)
6102 (string-equal name
"mail")
6103 (string-equal name
"posting")))
6104 (setq name
(concat "*sent " name
"*"))
6105 (message-narrow-to-headers)
6106 (setq to
(message-fetch-field "to"))
6107 (setq group
(message-fetch-field "newsgroups"))
6111 (to (concat "*sent mail to "
6112 (or (car (mail-extract-address-components to
))
6114 ((and group
(not (string= group
"")))
6115 (concat "*sent posting on " group
"*"))
6116 (t "*sent mail*"))))
6117 (unless (string-equal name
(buffer-name))
6118 (rename-buffer name t
)))))
6119 ;; Push the current buffer onto the list.
6120 (when message-max-buffers
6121 (setq message-buffer-list
6122 (nconc message-buffer-list
(list (current-buffer))))))
6124 (defun message-mail-user-agent ()
6126 ((not message-mail-user-agent
) nil
)
6127 ((eq message-mail-user-agent t
) mail-user-agent
)
6128 (t message-mail-user-agent
))))
6129 (if (memq mua
'(message-user-agent gnus-user-agent
))
6133 (defun message-setup (headers &optional replybuffer actions
6134 continue switch-function
)
6135 (let ((mua (message-mail-user-agent))
6136 subject to field yank-action
)
6137 (if (not (and message-this-is-mail mua
))
6138 (message-setup-1 headers replybuffer actions
)
6140 (setq yank-action
(list 'insert-buffer replybuffer
)))
6141 (setq headers
(copy-sequence headers
))
6142 (setq field
(assq 'Subject headers
))
6144 (setq subject
(cdr field
))
6145 (setq headers
(delq field headers
)))
6146 (setq field
(assq 'To headers
))
6148 (setq to
(cdr field
))
6149 (setq headers
(delq field headers
)))
6150 (let ((mail-user-agent mua
))
6151 (compose-mail to subject
6152 (mapcar (lambda (item)
6154 (format "%s" (car item
))
6157 continue switch-function yank-action actions
)))))
6159 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6160 "Return a list that includes all headers from HEADERS.
6161 If INCLUDED-HEADERS is a list, just include those headers. If it is
6162 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6166 (dolist (header headers
)
6167 (setq header-name
(cond
6168 ((and (consp header
)
6169 (eq (car header
) 'optional
))
6170 ;; On the form (optional . Header)
6173 ;; On the form (Header . function)
6178 (when (and (not (memq header-name excluded-headers
))
6179 (or (eq included-headers t
)
6180 (memq header-name included-headers
)))
6181 (push header result
)))
6184 (defun message-setup-1 (headers &optional replybuffer actions
)
6185 (dolist (action actions
)
6187 (add-to-list 'message-send-actions
6188 `(apply ',(car action
) ',(cdr action
)))))
6189 (setq message-reply-buffer replybuffer
)
6190 (goto-char (point-min))
6191 ;; Insert all the headers.
6194 (alist message-header-format-alist
))
6196 (unless (assq (caar h
) message-header-format-alist
)
6197 (push (list (caar h
)) alist
))
6201 (delete-region (point) (progn (forward-line -
1) (point)))
6202 (when message-default-headers
6203 (insert message-default-headers
)
6204 (or (bolp) (insert ?
\n)))
6205 (insert mail-header-separator
"\n")
6207 (when (message-news-p)
6208 (when message-default-news-headers
6209 (insert message-default-news-headers
)
6210 (or (bolp) (insert ?
\n)))
6211 (when message-generate-headers-first
6212 (message-generate-headers
6213 (message-headers-to-generate
6214 (append message-required-news-headers
6215 message-required-headers
)
6216 message-generate-headers-first
6217 '(Lines Subject
)))))
6218 (when (message-mail-p)
6219 (when message-default-mail-headers
6220 (insert message-default-mail-headers
)
6221 (or (bolp) (insert ?
\n)))
6222 (when message-generate-headers-first
6223 (message-generate-headers
6224 (message-headers-to-generate
6225 (append message-required-mail-headers
6226 message-required-headers
)
6227 message-generate-headers-first
6228 '(Lines Subject
)))))
6229 (run-hooks 'message-signature-setup-hook
)
6230 (message-insert-signature)
6232 (message-narrow-to-headers)
6233 (run-hooks 'message-header-setup-hook
))
6234 (setq buffer-undo-list nil
)
6235 (when message-generate-hashcash
6236 ;; Generate hashcash headers for recipients already known
6237 (mail-add-payment-async))
6238 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6240 (run-hooks 'message-setup-hook
)
6241 ;; Do this last to give it precedence over posting styles, etc.
6242 (when (message-mail-p)
6244 (message-narrow-to-headers)
6245 (if message-alternative-emails
6246 (message-use-alternative-email-as-from))))
6247 (message-position-point)
6248 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6249 (set-buffer-modified-p nil
)
6252 (defun message-set-auto-save-file-name ()
6253 "Associate the message buffer with a file in the drafts directory."
6254 (when message-auto-save-directory
6255 (unless (file-directory-p
6256 (directory-file-name message-auto-save-directory
))
6257 (make-directory message-auto-save-directory t
))
6259 (setq message-draft-article
6260 (nndraft-request-associate-buffer "drafts"))
6261 (setq buffer-file-name
(expand-file-name
6262 (if (memq system-type
6263 '(ms-dos ms-windows windows-nt
6264 cygwin cygwin32 win32 w32
6268 message-auto-save-directory
))
6269 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6270 (clear-visited-file-modtime)
6271 (setq buffer-file-coding-system message-draft-coding-system
)))
6273 (defun message-disassociate-draft ()
6274 "Disassociate the message buffer from the drafts directory."
6275 (when message-draft-article
6276 (nndraft-request-expire-articles
6277 (list message-draft-article
) "nndraft:drafts" nil t
)))
6279 (defun message-insert-headers ()
6280 "Generate the headers for the article."
6284 (message-narrow-to-headers)
6285 (when (message-news-p)
6286 (message-generate-headers
6289 (copy-sequence message-required-news-headers
)))))
6290 (when (message-mail-p)
6291 (message-generate-headers
6294 (copy-sequence message-required-mail-headers
))))))))
6299 ;;; Commands for interfacing with message
6303 (defun message-mail (&optional to subject
6304 other-headers continue switch-function
6305 yank-action send-actions
)
6306 "Start editing a mail message to be sent.
6307 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6308 to continue editing a message already being composed. SWITCH-FUNCTION
6309 is a function used to switch to and display the mail buffer."
6311 (let ((message-this-is-mail t
) replybuffer
)
6312 (unless (message-mail-user-agent)
6313 (message-pop-to-buffer
6314 ;; Search for the existing message buffer if `continue' is non-nil.
6315 (let ((message-generate-new-buffers
6316 (when (or (not continue
)
6317 (eq message-generate-new-buffers
'standard
)
6318 (functionp message-generate-new-buffers
))
6319 message-generate-new-buffers
)))
6320 (message-buffer-name "mail" to
))
6322 ;; FIXME: message-mail should do something if YANK-ACTION is not
6324 (and (consp yank-action
) (eq (car yank-action
) 'insert-buffer
)
6325 (setq replybuffer
(nth 1 yank-action
)))
6328 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6329 (when other-headers other-headers
))
6330 replybuffer send-actions continue switch-function
)
6331 ;; FIXME: Should return nil if failure.
6335 (defun message-news (&optional newsgroups subject
)
6336 "Start editing a news article to be sent."
6338 (let ((message-this-is-news t
))
6339 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6340 (message-setup `((Newsgroups .
,(or newsgroups
""))
6341 (Subject .
,(or subject
""))))))
6343 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6344 "Discard mail address in full names.
6345 When the full name in reply headers contains the mail
6346 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6347 ADDRCELL is a cons cell where the car is the mail address and the
6348 cdr is the complete address (full name and mail address)."
6349 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6350 (regexp-quote (car addrcell
)))
6352 (cons (car addrcell
) (car addrcell
))
6355 (defcustom message-alter-recipients-function nil
6356 "Function called to allow alteration of reply header structures.
6357 It is called in `message-get-reply-headers' for each recipient.
6358 The function is called with one parameter, a cons cell ..."
6359 :type
'(choice (const :tag
"None" nil
)
6360 (const :tag
"Discard bogus full name"
6361 message-alter-recipients-discard-bogus-full-name
)
6363 :version
"23.1" ;; No Gnus
6364 :group
'message-headers
)
6366 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6367 (let (follow-to mct never-mct to cc author mft recipients extra
)
6368 ;; Find all relevant headers we need.
6370 (message-narrow-to-headers-or-head)
6371 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6372 ;; message-header-synonyms.
6373 (setq to
(or (message-fetch-field "to")
6374 (and (loop for synonym in message-header-synonyms
6375 when
(memq 'Original-To synonym
)
6377 (message-fetch-field "original-to")))
6378 cc
(message-fetch-field "cc")
6379 extra
(when message-extra-wide-headers
6380 (mapconcat 'identity
6381 (mapcar 'message-fetch-field
6382 message-extra-wide-headers
)
6384 mct
(message-fetch-field "mail-copies-to")
6385 author
(or (message-fetch-field "mail-reply-to")
6386 (message-fetch-field "reply-to")
6387 (message-fetch-field "from")
6389 mft
(and message-use-mail-followup-to
6390 (message-fetch-field "mail-followup-to"))))
6392 ;; Handle special values of Mail-Copies-To.
6394 (cond ((or (equal (downcase mct
) "never")
6395 (equal (downcase mct
) "nobody"))
6398 ((or (equal (downcase mct
) "always")
6399 (equal (downcase mct
) "poster"))
6400 (setq mct author
))))
6403 ;; Build (textual) list of new recipient addresses.
6406 (setq recipients
(concat ", " author
)))
6408 (dolist (header address-headers
)
6409 (let ((value (message-fetch-field header
)))
6411 (setq recipients
(concat recipients
", " value
))))))
6413 (string-match "[^ \t,]" mft
)
6414 (or (not (eq message-use-mail-followup-to
'ask
))
6415 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6416 You should normally obey the Mail-Followup-To: header. In this
6417 article, it has the value of
6421 which directs your response to " (if (string-match "," mft
)
6422 "the specified addresses"
6423 "that address only") ".
6425 Most commonly, Mail-Followup-To is used by a mailing list poster to
6426 express that responses should be sent to just the list, and not the
6429 If a message is posted to several mailing lists, Mail-Followup-To may
6430 also be used to direct the following discussion to one list only,
6431 because discussions that are spread over several lists tend to be
6432 fragmented and very difficult to follow.
6434 Also, some source/announcement lists are not intended for discussion;
6435 responses here are directed to other addresses.
6437 You may customize the variable `message-use-mail-followup-to', if you
6438 want to get rid of this query permanently.")))
6439 (setq recipients
(concat ", " mft
)))
6441 (setq recipients
(concat ", " to-address
))
6442 ;; If the author explicitly asked for a copy, we don't deny it to them.
6443 (if mct
(setq recipients
(concat recipients
", " mct
))))
6445 (setq recipients
(if never-mct
"" (concat ", " author
)))
6446 (if to
(setq recipients
(concat recipients
", " to
)))
6447 (if cc
(setq recipients
(concat recipients
", " cc
)))
6448 (if extra
(setq recipients
(concat recipients
", " extra
)))
6449 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6450 (if (>= (length recipients
) 2)
6451 ;; Strip the leading ", ".
6452 (setq recipients
(substring recipients
2)))
6453 ;; Squeeze whitespace.
6454 (while (string-match "[ \t][ \t]+" recipients
)
6455 (setq recipients
(replace-match " " t t recipients
)))
6456 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6457 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6458 (setq recipients
(rmail-dont-reply-to recipients
)))
6459 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6460 (if (string-equal recipients
"")
6461 (setq recipients author
))
6462 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6466 (if message-alter-recipients-function
6467 (funcall message-alter-recipients-function
6468 (cons (downcase (mail-strip-quoted-names addr
))
6470 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6471 (message-tokenize-header recipients
)))
6472 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6473 (let ((s recipients
))
6475 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6477 ;; Remove hierarchical lists that are contained within each other,
6478 ;; if message-hierarchical-addresses is defined.
6479 (when message-hierarchical-addresses
6480 (let ((plain-addrs (mapcar 'car recipients
))
6483 (setq subaddrs
(assoc (car plain-addrs
)
6484 message-hierarchical-addresses
)
6485 plain-addrs
(cdr plain-addrs
))
6487 (setq subaddrs
(cdr subaddrs
))
6489 (setq recip
(assoc (car subaddrs
) recipients
)
6490 subaddrs
(cdr subaddrs
))
6492 (setq recipients
(delq recip recipients
))))))))
6494 ;; Build the header alist. Allow the user to be asked whether
6495 ;; or not to reply to all recipients in a wide reply.
6496 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6497 (when (and recipients
6498 (or (not message-wide-reply-confirm-recipients
)
6499 (y-or-n-p "Reply to all recipients? ")))
6500 (setq recipients
(mapconcat
6501 (lambda (addr) (cdr addr
)) recipients
", "))
6502 (if (string-match "^ +" recipients
)
6503 (setq recipients
(substring recipients
(match-end 0))))
6504 (push (cons 'Cc recipients
) follow-to
)))
6507 (defcustom message-simplify-subject-functions
6508 '(message-strip-list-identifiers
6509 message-strip-subject-re
6510 message-strip-subject-trailing-was
6511 message-strip-subject-encoded-words
)
6512 "List of functions taking a string argument that simplify subjects.
6513 The functions are applied when replying to a message.
6515 Useful functions to put in this list include:
6516 `message-strip-list-identifiers', `message-strip-subject-re',
6517 `message-strip-subject-trailing-was', and
6518 `message-strip-subject-encoded-words'."
6519 :version
"22.1" ;; Gnus 5.10.9
6520 :group
'message-various
6521 :type
'(repeat function
))
6523 (defun message-simplify-subject (subject &optional functions
)
6524 "Return simplified SUBJECT."
6527 (setq functions message-simplify-subject-functions
))
6528 (when (and (memq 'message-strip-list-identifiers functions
)
6529 gnus-list-identifiers
)
6530 (setq subject
(message-strip-list-identifiers subject
)))
6531 (when (memq 'message-strip-subject-re functions
)
6532 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6533 (when (and (memq 'message-strip-subject-trailing-was functions
)
6534 message-subject-trailing-was-query
)
6535 (setq subject
(message-strip-subject-trailing-was subject
)))
6536 (when (memq 'message-strip-subject-encoded-words functions
)
6537 (setq subject
(message-strip-subject-encoded-words subject
)))
6541 (defun message-reply (&optional to-address wide
)
6542 "Start editing a reply to the article in the current buffer."
6544 (require 'gnus-sum
) ; for gnus-list-identifiers
6545 (let ((cur (current-buffer))
6546 from subject date reply-to to cc
6547 references message-id follow-to
6548 (inhibit-point-motion-hooks t
)
6549 (message-this-is-mail t
)
6552 (message-narrow-to-head-1)
6553 ;; Allow customizations to have their say.
6555 ;; This is a regular reply.
6556 (when (functionp message-reply-to-function
)
6558 (setq follow-to
(funcall message-reply-to-function
))))
6559 ;; This is a followup.
6560 (when (functionp message-wide-reply-to-function
)
6563 (funcall message-wide-reply-to-function
)))))
6564 (setq message-id
(message-fetch-field "message-id" t
)
6565 references
(message-fetch-field "references")
6566 date
(message-fetch-field "date")
6567 from
(or (message-fetch-field "from") "nobody")
6568 subject
(or (message-fetch-field "subject") "none"))
6570 ;; Strip list identifiers, "Re: ", and "was:"
6571 (setq subject
(message-simplify-subject subject
))
6573 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6574 (string-match "<[^>]+>" gnus-warning
))
6575 (setq message-id
(match-string 0 gnus-warning
)))
6578 (setq follow-to
(message-get-reply-headers wide to-address
))))
6580 (unless (message-mail-user-agent)
6581 (message-pop-to-buffer
6582 (message-buffer-name
6583 (if wide
"wide reply" "reply") from
6584 (if wide to-address nil
))))
6586 (setq message-reply-headers
6587 (vector 0 subject from date message-id references
0 0 ""))
6590 `((Subject .
,subject
)
6595 (defun message-wide-reply (&optional to-address
)
6596 "Make a \"wide\" reply to the message in the current buffer."
6598 (message-reply to-address t
))
6601 (defun message-followup (&optional to-newsgroups
)
6602 "Follow up to the message in the current buffer.
6603 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6605 (require 'gnus-sum
) ; for gnus-list-identifiers
6606 (let ((cur (current-buffer))
6607 from subject date reply-to mrt mct
6608 references message-id follow-to
6609 (inhibit-point-motion-hooks t
)
6610 (message-this-is-news t
)
6611 followup-to distribution newsgroups gnus-warning posted-to
)
6614 (goto-char (point-min))
6615 (if (search-forward "\n\n" nil t
)
6618 (when (functionp message-followup-to-function
)
6620 (funcall message-followup-to-function
)))
6621 (setq from
(message-fetch-field "from")
6622 date
(message-fetch-field "date")
6623 subject
(or (message-fetch-field "subject") "none")
6624 references
(message-fetch-field "references")
6625 message-id
(message-fetch-field "message-id" t
)
6626 followup-to
(message-fetch-field "followup-to")
6627 newsgroups
(message-fetch-field "newsgroups")
6628 posted-to
(message-fetch-field "posted-to")
6629 reply-to
(message-fetch-field "reply-to")
6630 mrt
(message-fetch-field "mail-reply-to")
6631 distribution
(message-fetch-field "distribution")
6632 mct
(message-fetch-field "mail-copies-to"))
6633 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6634 (string-match "<[^>]+>" gnus-warning
))
6635 (setq message-id
(match-string 0 gnus-warning
)))
6636 ;; Remove bogus distribution.
6637 (when (and (stringp distribution
)
6638 (let ((case-fold-search t
))
6639 (string-match "world" distribution
)))
6640 (setq distribution nil
))
6641 ;; Strip list identifiers, "Re: ", and "was:"
6642 (setq subject
(message-simplify-subject subject
))
6645 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6647 (setq message-reply-headers
6648 (vector 0 subject from date message-id references
0 0 ""))
6651 `((Subject .
,subject
)
6654 (list (cons 'Newsgroups to-newsgroups
)))
6655 (follow-to follow-to
)
6656 ((and followup-to message-use-followup-to
)
6659 ((equal (downcase followup-to
) "poster")
6660 (if (or (eq message-use-followup-to
'use
)
6661 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6662 You should normally obey the Followup-To: header.
6664 `Followup-To: poster' sends your response via e-mail instead of news.
6666 A typical situation where `Followup-To: poster' is used is when the poster
6667 does not read the newsgroup, so he wouldn't see any replies sent to it.
6669 You may customize the variable `message-use-followup-to', if you
6670 want to get rid of this query permanently."))
6672 (setq message-this-is-news nil
)
6673 (cons 'To
(or mrt reply-to from
"")))
6674 (cons 'Newsgroups newsgroups
)))
6676 (if (or (equal followup-to newsgroups
)
6677 (not (eq message-use-followup-to
'ask
))
6679 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6680 You should normally obey the Followup-To: header.
6682 `Followup-To: " followup-to
"'
6683 directs your response to " (if (string-match "," followup-to
)
6684 "the specified newsgroups"
6685 "that newsgroup only") ".
6687 If a message is posted to several newsgroups, Followup-To is often
6688 used to direct the following discussion to one newsgroup only,
6689 because discussions that are spread over several newsgroup tend to
6690 be fragmented and very difficult to follow.
6692 Also, some source/announcement newsgroups are not intended for discussion;
6693 responses here are directed to other newsgroups.
6695 You may customize the variable `message-use-followup-to', if you
6696 want to get rid of this query permanently."))
6697 (cons 'Newsgroups followup-to
)
6698 (cons 'Newsgroups newsgroups
))))))
6700 `((Newsgroups .
,posted-to
)))
6702 `((Newsgroups .
,newsgroups
))))
6703 ,@(and distribution
(list (cons 'Distribution distribution
)))
6705 (not (or (equal (downcase mct
) "never")
6706 (equal (downcase mct
) "nobody"))))
6707 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6708 (equal (downcase mct
) "poster"))
6709 (or mrt reply-to from
"")
6714 (defun message-is-yours-p ()
6715 "Non-nil means current article is yours.
6716 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6717 are yours except those that have Cancel-Lock header not belonging to you.
6718 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6719 regexp to match all of yours addresses."
6720 ;; Canlock-logic as suggested by Per Abrahamsen
6721 ;; <abraham@dina.kvl.dk>
6723 ;; IF article has cancel-lock THEN
6724 ;; IF we can verify it THEN
6727 ;; error: cancellock: article is not yours
6729 ;; Use old rules, comparing sender...
6732 (message-narrow-to-head-1)
6733 (if (message-fetch-field "Cancel-Lock")
6734 (if (null (canlock-verify))
6736 (error "Failed to verify Cancel-lock: This article is not yours"))
6739 (message-gnksa-enable-p 'cancel-messages
)
6740 (and (setq sender
(message-fetch-field "sender"))
6741 (string-equal (downcase sender
)
6742 (downcase (message-make-sender))))
6743 ;; Email address in From field equals to our address
6744 (and (setq from
(message-fetch-field "from"))
6746 (downcase (car (mail-header-parse-address from
)))
6747 (downcase (car (mail-header-parse-address
6748 (message-make-from))))))
6749 ;; Email address in From field matches
6750 ;; 'message-alternative-emails' regexp
6752 message-alternative-emails
6754 message-alternative-emails
6755 (car (mail-header-parse-address from
))))))))))
6758 (defun message-cancel-news (&optional arg
)
6759 "Cancel an article you posted.
6760 If ARG, allow editing of the cancellation message."
6762 (unless (message-news-p)
6763 (error "This is not a news article; canceling is impossible"))
6764 (let (from newsgroups message-id distribution buf
)
6766 ;; Get header info from original article.
6768 (message-narrow-to-head-1)
6769 (setq from
(message-fetch-field "from")
6770 newsgroups
(message-fetch-field "newsgroups")
6771 message-id
(message-fetch-field "message-id" t
)
6772 distribution
(message-fetch-field "distribution")))
6773 ;; Make sure that this article was written by the user.
6774 (unless (message-is-yours-p)
6775 (error "This article is not yours"))
6776 (when (yes-or-no-p "Do you really want to cancel this article? ")
6777 ;; Make control message.
6780 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6782 (insert "Newsgroups: " newsgroups
"\n"
6784 "Subject: cmsg cancel " message-id
"\n"
6785 "Control: cancel " message-id
"\n"
6787 (concat "Distribution: " distribution
"\n")
6789 mail-header-separator
"\n"
6790 message-cancel-message
)
6791 (run-hooks 'message-cancel-hook
)
6793 (message "Canceling your article...")
6794 (if (let ((message-syntax-checks
6795 'dont-check-for-anything-just-trust-me
))
6796 (funcall message-send-news-function
))
6797 (message "Canceling your article...done"))
6798 (kill-buffer buf
))))))
6801 (defun message-supersede ()
6802 "Start composing a message to supersede the current message.
6803 This is done simply by taking the old article and adding a Supersedes
6804 header line with the old Message-ID."
6806 (let ((cur (current-buffer)))
6807 ;; Check whether the user owns the article that is to be superseded.
6808 (unless (message-is-yours-p)
6809 (error "This article is not yours"))
6810 ;; Get a normal message buffer.
6811 (message-pop-to-buffer (message-buffer-name "supersede"))
6812 (insert-buffer-substring cur
)
6814 (message-narrow-to-head-1)
6815 ;; Remove unwanted headers.
6816 (when message-ignored-supersedes-headers
6817 (message-remove-header message-ignored-supersedes-headers t
))
6818 (goto-char (point-min))
6819 (if (not (re-search-forward "^Message-ID: " nil t
))
6820 (error "No Message-ID in this article")
6821 (replace-match "Supersedes: " t t
))
6822 (goto-char (point-max))
6823 (insert mail-header-separator
)
6828 (defun message-recover ()
6829 "Reread contents of current buffer from its last auto-save file."
6831 (let ((file-name (make-auto-save-file-name)))
6832 (cond ((save-window-excursion
6833 (if (not (eq system-type
'vax-vms
))
6834 (with-output-to-temp-buffer "*Directory*"
6835 (with-current-buffer standard-output
6836 (fundamental-mode)) ; for Emacs 20.4+
6837 (buffer-disable-undo standard-output
)
6838 (let ((default-directory "/"))
6840 "ls" nil standard-output nil
"-l" file-name
))))
6841 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
6842 (let ((buffer-read-only nil
))
6844 (insert-file-contents file-name nil
)))
6845 (t (error "message-recover cancelled")))))
6847 ;;; Washing Subject:
6849 (defun message-wash-subject (subject)
6850 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6851 Previous forwarders, replyers, etc. may add it."
6854 (goto-char (point-min))
6855 ;; strip Re/Fwd stuff off the beginning
6856 (while (re-search-forward
6857 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
6860 ;; and gnus-style forwards [foo@bar.com] subject
6861 (goto-char (point-min))
6862 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
6866 (goto-char (point-max))
6867 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
6870 ;; and finally, any whitespace that was left-over
6871 (goto-char (point-min))
6872 (while (re-search-forward "^[ \t]+" nil t
)
6874 (goto-char (point-max))
6875 (while (re-search-backward "[ \t]+$" nil t
)
6880 ;;; Forwarding messages.
6882 (defvar message-forward-decoded-p nil
6883 "Non-nil means the original message is decoded.")
6885 (defun message-forward-subject-name-subject (subject)
6886 "Generate a SUBJECT for a forwarded message.
6887 The form is: [Source] Subject, where if the original message was mail,
6888 Source is the name of the sender, and if the original message was
6889 news, Source is the list of newsgroups is was posted to."
6890 (let* ((group (message-fetch-field "newsgroups"))
6891 (from (message-fetch-field "from"))
6894 (gnus-group-decoded-name group
)
6896 (car (gnus-extract-address-components from
))
6897 (cadr (gnus-extract-address-components from
))))
6900 (if message-forward-decoded-p
6902 (mail-decode-encoded-word-string prefix
))
6905 (defun message-forward-subject-author-subject (subject)
6906 "Generate a SUBJECT for a forwarded message.
6907 The form is: [Source] Subject, where if the original message was mail,
6908 Source is the sender, and if the original message was news, Source is
6909 the list of newsgroups is was posted to."
6910 (let* ((group (message-fetch-field "newsgroups"))
6913 (gnus-group-decoded-name group
)
6914 (or (message-fetch-field "from")
6917 (if message-forward-decoded-p
6919 (mail-decode-encoded-word-string prefix
))
6922 (defun message-forward-subject-fwd (subject)
6923 "Generate a SUBJECT for a forwarded message.
6924 The form is: Fwd: Subject, where Subject is the original subject of
6926 (if (string-match "^Fwd: " subject
)
6928 (concat "Fwd: " subject
)))
6930 (defun message-make-forward-subject ()
6931 "Return a Subject header suitable for the message in the current buffer."
6934 (message-narrow-to-head-1)
6935 (let ((funcs message-make-forward-subject-function
)
6936 (subject (message-fetch-field "Subject")))
6939 (if message-forward-decoded-p
6941 (mail-decode-encoded-word-string subject
))
6943 (when message-wash-forwarded-subjects
6944 (setq subject
(message-wash-subject subject
)))
6945 ;; Make sure funcs is a list.
6948 (setq funcs
(list funcs
)))
6949 ;; Apply funcs in order, passing subject generated by previous
6950 ;; func to the next one.
6951 (dolist (func funcs
)
6952 (when (functionp func
)
6953 (setq subject
(funcall func subject
))))
6956 (defvar gnus-article-decoded-p
)
6960 (defun message-forward (&optional news digest
)
6961 "Forward the current message via mail.
6962 Optional NEWS will use news to forward instead of mail.
6963 Optional DIGEST will use digest to forward."
6965 (let* ((cur (current-buffer))
6966 (message-forward-decoded-p
6967 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
6968 gnus-article-decoded-p
;; In an article buffer.
6969 message-forward-decoded-p
))
6970 (subject (message-make-forward-subject)))
6972 (message-news nil subject
)
6973 (message-mail nil subject
))
6974 (message-forward-make-body cur digest
)))
6976 (defun message-forward-make-body-plain (forward-buffer)
6978 "\n-------------------- Start of forwarded message --------------------\n")
6979 (let ((b (point)) e
)
6982 (mm-disable-multibyte)
6984 (with-current-buffer forward-buffer
6985 (mm-with-unibyte-current-buffer (buffer-string))))
6986 (mm-enable-multibyte)
6988 (goto-char (point-min))
6989 (when (looking-at "From ")
6990 (replace-match "X-From-Line: "))
6994 "\n-------------------- End of forwarded message --------------------\n")
6995 (message-remove-ignored-headers b e
)))
6997 (defun message-remove-ignored-headers (b e
)
6998 (when message-forward-ignored-headers
7000 (narrow-to-region b e
)
7002 (narrow-to-region (point)
7003 (or (search-forward "\n\n" nil t
) (point)))
7004 (let ((ignored (if (stringp message-forward-ignored-headers
)
7005 (list message-forward-ignored-headers
)
7006 message-forward-ignored-headers
)))
7007 (dolist (elem ignored
)
7008 (message-remove-header elem t
))))))
7010 (defun message-forward-make-body-mime (forward-buffer)
7012 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7014 (narrow-to-region (point) (point))
7015 (mml-insert-buffer forward-buffer
)
7016 (goto-char (point-min))
7017 (when (looking-at "From ")
7018 (replace-match "X-From-Line: "))
7019 (goto-char (point-max)))
7020 (insert "<#/part>\n")
7021 ;; Consider there is no illegible text.
7022 (add-text-properties
7024 `(no-illegible-text t rear-nonsticky t start-open t
))))
7026 (defun message-forward-make-body-mml (forward-buffer)
7027 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7028 (let ((b (point)) e
)
7029 (if (not message-forward-decoded-p
)
7032 (mm-disable-multibyte)
7034 (with-current-buffer forward-buffer
7035 (mm-with-unibyte-current-buffer (buffer-string))))
7036 (mm-enable-multibyte)
7038 (goto-char (point-min))
7039 (when (looking-at "From ")
7040 (replace-match "X-From-Line: "))
7043 (narrow-to-region (point) (point))
7044 (mml-insert-buffer forward-buffer
)
7045 (goto-char (point-min))
7046 (when (looking-at "From ")
7047 (replace-match "X-From-Line: "))
7048 (goto-char (point-max))))
7050 (insert "<#/mml>\n")
7051 (when (and (not message-forward-decoded-p
)
7052 message-forward-ignored-headers
)
7053 (message-remove-ignored-headers b e
))))
7055 (defun message-forward-make-body-digest-plain (forward-buffer)
7057 "\n-------------------- Start of forwarded message --------------------\n")
7058 (let ((b (point)) e
)
7059 (mml-insert-buffer forward-buffer
)
7062 "\n-------------------- End of forwarded message --------------------\n")))
7064 (defun message-forward-make-body-digest-mime (forward-buffer)
7065 (insert "\n<#multipart type=digest>\n")
7066 (let ((b (point)) e
)
7067 (insert-buffer-substring forward-buffer
)
7069 (insert "<#/multipart>\n")
7071 (narrow-to-region b e
)
7073 (narrow-to-region (point)
7074 (or (search-forward "\n\n" nil t
) (point)))
7075 (delete-region (point-min) (point-max)))))
7077 (defun message-forward-make-body-digest (forward-buffer)
7078 (if message-forward-as-mime
7079 (message-forward-make-body-digest-mime forward-buffer
)
7080 (message-forward-make-body-digest-plain forward-buffer
)))
7083 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7084 (autoload 'mm-uu-dissect
"mm-uu"))
7086 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7087 "Say whether the current buffer contains signed or encrypted message.
7088 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7089 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7090 is for the internal use."
7092 (let ((mm-decrypt-option 'never
)
7093 (mm-verify-option 'never
))
7094 (if (setq handles
(mm-dissect-buffer nil t
))
7095 (unless dont-emulate-mime
7096 (mm-uu-dissect-text-parts handles
))
7097 (unless dont-emulate-mime
7098 (setq handles
(mm-uu-dissect))))))
7099 ;; Check text/plain message in which there is a signed or encrypted
7100 ;; body that has been encoded by B or Q.
7101 (unless (or handles dont-emulate-mime
)
7102 (let ((cur (current-buffer))
7103 (mm-decrypt-option 'never
)
7104 (mm-verify-option 'never
))
7106 (insert-buffer-substring cur
)
7107 (when (setq handles
(mm-dissect-buffer t t
))
7109 (bufferp (car handles
))
7110 (mm-destroy-parts handles
))
7111 (equal (mm-handle-media-type handles
) "text/plain"))
7113 (mm-decode-content-transfer-encoding
7114 (mm-handle-encoding handles
))
7115 (setq handles
(mm-uu-dissect)))
7116 (setq handles nil
))))))
7120 (dolist (handle (if (stringp (car handles
))
7121 (if (member (car handles
)
7122 '("multipart/signed"
7123 "multipart/encrypted"))
7127 (if (stringp (car handle
))
7128 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7130 (when (and (bufferp (car handle
))
7131 (equal (mm-handle-media-type handle
)
7133 (with-current-buffer (mm-handle-buffer handle
)
7134 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7135 (throw 'found t
)))))))
7136 (mm-destroy-parts handles
))))
7139 (defun message-forward-make-body (forward-buffer &optional digest
)
7140 ;; Put point where we want it before inserting the forwarded
7142 (if message-forward-before-signature
7144 (goto-char (point-max)))
7146 (message-forward-make-body-digest forward-buffer
)
7147 (if message-forward-as-mime
7148 (if (and message-forward-show-mml
7149 (not (and (eq message-forward-show-mml
'best
)
7150 ;; Use the raw form in the body if it contains
7151 ;; signed or encrypted message so as not to be
7152 ;; destroyed by re-encoding.
7153 (with-current-buffer forward-buffer
7155 (message-signed-or-encrypted-p)
7157 (message-forward-make-body-mml forward-buffer
)
7158 (message-forward-make-body-mime forward-buffer
))
7159 (message-forward-make-body-plain forward-buffer
)))
7160 (message-position-point))
7163 (defun message-forward-rmail-make-body (forward-buffer)
7164 (save-window-excursion
7165 (set-buffer forward-buffer
)
7166 (if (rmail-msg-is-pruned)
7167 (rmail-msg-restore-non-pruned-header)))
7168 (message-forward-make-body forward-buffer
))
7170 ;; Fixme: Should have defcustom.
7172 (defun message-insinuate-rmail ()
7173 "Let RMAIL use message to forward."
7175 (setq rmail-enable-mime-composing t
)
7176 (setq rmail-insert-mime-forwarded-message-function
7177 'message-forward-rmail-make-body
))
7180 (defun message-resend (address)
7181 "Resend the current article to ADDRESS."
7183 (list (message-read-from-minibuffer "Resend message to: ")))
7184 (message "Resending message to %s..." address
)
7186 (let ((cur (current-buffer))
7188 ;; We first set up a normal mail buffer.
7189 (unless (message-mail-user-agent)
7190 (set-buffer (get-buffer-create " *message resend*"))
7192 (let ((message-this-is-mail t
)
7193 message-generate-hashcash
7195 (message-setup `((To .
,address
))))
7196 ;; Insert our usual headers.
7197 (message-generate-headers '(From Date To Message-ID
))
7198 (message-narrow-to-headers)
7199 ;; Remove X-Draft-From header etc.
7200 (message-remove-header message-ignored-mail-headers t
)
7201 ;; Rename them all to "Resent-*".
7202 (goto-char (point-min))
7203 (while (re-search-forward "^[A-Za-z]" nil t
)
7208 (delete-region (point) (point-max))
7210 ;; Insert the message to be resent.
7211 (insert-buffer-substring cur
)
7212 (goto-char (point-min))
7213 (search-forward "\n\n")
7216 (narrow-to-region beg
(point))
7217 (message-remove-header message-ignored-resent-headers t
)
7218 (goto-char (point-max)))
7219 (insert mail-header-separator
)
7220 ;; Rename all old ("Also-")Resent headers.
7221 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7224 ;; Quote any "From " lines at the beginning.
7226 (when (looking-at "From ")
7227 (replace-match "X-From-Line: "))
7229 (let ((message-inhibit-body-encoding t
)
7230 message-required-mail-headers
7231 message-generate-hashcash
7232 rfc2047-encode-encoded-words
)
7233 (message-send-mail))
7234 (kill-buffer (current-buffer)))
7235 (message "Resending message to %s...done" address
)))
7238 (defun message-bounce ()
7239 "Re-mail the current message.
7240 This only makes sense if the current message is a bounce message that
7241 contains some mail you have written which has been bounced back to
7244 (let ((handles (mm-dissect-buffer t
))
7246 (message-pop-to-buffer (message-buffer-name "bounce"))
7247 (if (stringp (car handles
))
7248 ;; This is a MIME bounce.
7249 (mm-insert-part (car (last handles
)))
7250 ;; This is a non-MIME bounce, so we try to remove things
7252 (mm-insert-part handles
)
7254 (goto-char (point-min))
7255 (re-search-forward "\n\n+" nil t
)
7256 (setq boundary
(point))
7257 ;; We remove everything before the bounced mail.
7258 (if (or (re-search-forward message-unsent-separator nil t
)
7260 (search-forward "\n\n" nil
'move
)
7261 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7264 (delete-region (point-min)
7265 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7268 (goto-char boundary
)
7269 (when (re-search-backward "^.?From .*\n" nil t
)
7270 (delete-region (match-beginning 0) (match-end 0)))))
7273 (message-narrow-to-head-1)
7274 (message-remove-header message-ignored-bounced-headers t
)
7275 (goto-char (point-max))
7276 (insert mail-header-separator
))
7277 (message-position-point)))
7280 ;;; Interactive entry points for new message buffers.
7284 (defun message-mail-other-window (&optional to subject
)
7285 "Like `message-mail' command, but display mail buffer in another window."
7287 (unless (message-mail-user-agent)
7288 (let ((pop-up-windows t
)
7289 (special-display-buffer-names nil
)
7290 (special-display-regexps nil
)
7291 (same-window-buffer-names nil
)
7292 (same-window-regexps nil
))
7293 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7294 (let ((message-this-is-mail t
))
7295 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7296 nil nil nil
'switch-to-buffer-other-window
)))
7299 (defun message-mail-other-frame (&optional to subject
)
7300 "Like `message-mail' command, but display mail buffer in another frame."
7302 (unless (message-mail-user-agent)
7303 (let ((pop-up-frames t
)
7304 (special-display-buffer-names nil
)
7305 (special-display-regexps nil
)
7306 (same-window-buffer-names nil
)
7307 (same-window-regexps nil
))
7308 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7309 (let ((message-this-is-mail t
))
7310 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7311 nil nil nil
'switch-to-buffer-other-frame
)))
7314 (defun message-news-other-window (&optional newsgroups subject
)
7315 "Start editing a news article to be sent."
7317 (let ((pop-up-windows t
)
7318 (special-display-buffer-names nil
)
7319 (special-display-regexps nil
)
7320 (same-window-buffer-names nil
)
7321 (same-window-regexps nil
))
7322 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7323 (let ((message-this-is-news t
))
7324 (message-setup `((Newsgroups .
,(or newsgroups
""))
7325 (Subject .
,(or subject
""))))))
7328 (defun message-news-other-frame (&optional newsgroups subject
)
7329 "Start editing a news article to be sent."
7331 (let ((pop-up-frames t
)
7332 (special-display-buffer-names nil
)
7333 (special-display-regexps nil
)
7334 (same-window-buffer-names nil
)
7335 (same-window-regexps nil
))
7336 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7337 (let ((message-this-is-news t
))
7338 (message-setup `((Newsgroups .
,(or newsgroups
""))
7339 (Subject .
,(or subject
""))))))
7343 ;; This code should be moved to underline.el (from which it is stolen).
7346 (defun message-bold-region (start end
)
7347 "Bold all nonblank characters in the region.
7348 Works by overstriking characters.
7349 Called from program, takes two arguments START and END
7350 which specify the range to operate on."
7353 (let ((end1 (make-marker)))
7354 (move-marker end1
(max start end
))
7355 (goto-char (min start end
))
7356 (while (< (point) end1
)
7357 (or (looking-at "[_\^@- ]")
7358 (insert (char-after) "\b"))
7359 (forward-char 1)))))
7362 (defun message-unbold-region (start end
)
7363 "Remove all boldness (overstruck characters) in the region.
7364 Called from program, takes two arguments START and END
7365 which specify the range to operate on."
7368 (let ((end1 (make-marker)))
7369 (move-marker end1
(max start end
))
7370 (goto-char (min start end
))
7371 (while (search-forward "\b" end1 t
)
7372 (if (eq (char-after) (char-after (- (point) 2)))
7373 (delete-char -
2))))))
7375 (defun message-exchange-point-and-mark ()
7376 "Exchange point and mark, but don't activate region if it was inactive."
7378 (message-mark-active-p)
7379 (exchange-point-and-mark))
7380 (setq mark-active nil
)))
7382 (defalias 'message-make-overlay
'make-overlay
)
7383 (defalias 'message-delete-overlay
'delete-overlay
)
7384 (defalias 'message-overlay-put
'overlay-put
)
7385 (defun message-kill-all-overlays ()
7386 (if (featurep 'xemacs
)
7387 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7388 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7390 ;; Support for toolbar
7391 (defvar tool-bar-mode
)
7393 ;; Note: The :set function in the `message-tool-bar*' variables will only
7394 ;; affect _new_ message buffers. We might add a function that walks thru all
7395 ;; message-mode buffers and force the update.
7396 (defun message-tool-bar-update (&optional symbol value
)
7397 "Update message mode toolbar.
7398 Setter function for custom variables."
7399 (setq-default message-tool-bar-map nil
)
7401 ;; When used as ":set" function:
7402 (set-default symbol value
)))
7404 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7405 'message-tool-bar-gnome
7406 'message-tool-bar-retro
)
7407 "Specifies the message mode tool bar.
7409 It can be either a list or a symbol refering to a list. See
7410 `gmm-tool-bar-from-list' for the format of the list. The
7411 default key map is `message-mode-map'.
7413 Pre-defined symbols include `message-tool-bar-gnome' and
7414 `message-tool-bar-retro'."
7415 :type
'(repeat gmm-tool-bar-list-item
)
7416 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7417 (const :tag
"Retro look" message-tool-bar-retro
)
7418 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7420 :version
"23.1" ;; No Gnus
7421 :initialize
'custom-initialize-default
7422 :set
'message-tool-bar-update
7425 (defcustom message-tool-bar-gnome
7426 '((ispell-message "spell" nil
7427 :visible
(or (not (boundp 'flyspell-mode
))
7428 (not flyspell-mode
)))
7429 (flyspell-buffer "spell" t
7430 :visible
(and (boundp 'flyspell-mode
)
7432 :help
"Flyspell whole buffer")
7433 (gmm-ignore "separator")
7434 (message-send-and-exit "mail/send")
7435 (message-dont-send "mail/save-draft")
7436 (message-kill-buffer "close") ;; stock_cancel
7437 (mml-attach-file "attach" mml-mode-map
)
7438 (mml-preview "mail/preview" mml-mode-map
)
7439 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7440 (message-insert-importance-high "important" nil
:visible nil
)
7441 (message-insert-importance-low "unimportant" nil
:visible nil
)
7442 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7443 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7444 (message-info "help" t
:help
"Message manual"))
7445 "List of items for the message tool bar (GNOME style).
7447 See `gmm-tool-bar-from-list' for details on the format of the list."
7448 :type
'(repeat gmm-tool-bar-item
)
7449 :version
"23.1" ;; No Gnus
7450 :initialize
'custom-initialize-default
7451 :set
'message-tool-bar-update
7454 (defcustom message-tool-bar-retro
7455 '(;; Old Emacs 21 icon for consistency.
7456 (message-send-and-exit "gnus/mail-send")
7457 (message-kill-buffer "close")
7458 (message-dont-send "cancel")
7459 (mml-attach-file "attach" mml-mode-map
)
7460 (ispell-message "spell")
7461 (mml-preview "preview" mml-mode-map
)
7462 (message-insert-importance-high "gnus/important")
7463 (message-insert-importance-low "gnus/unimportant")
7464 (message-insert-disposition-notification-to "gnus/receipt"))
7465 "List of items for the message tool bar (retro style).
7467 See `gmm-tool-bar-from-list' for details on the format of the list."
7468 :type
'(repeat gmm-tool-bar-item
)
7469 :version
"23.1" ;; No Gnus
7470 :initialize
'custom-initialize-default
7471 :set
'message-tool-bar-update
7474 (defcustom message-tool-bar-zap-list
7475 '(new-file open-file dired kill-buffer write-file
7476 print-buffer customize help
)
7477 "List of icon items from the global tool bar.
7478 These items are not displayed on the message mode tool bar.
7480 See `gmm-tool-bar-from-list' for the format of the list."
7481 :type
'gmm-tool-bar-zap-list
7482 :version
"23.1" ;; No Gnus
7483 :initialize
'custom-initialize-default
7484 :set
'message-tool-bar-update
7487 (defvar image-load-path
)
7489 (defun message-make-tool-bar (&optional force
)
7490 "Make a message mode tool bar from `message-tool-bar-list'.
7491 When FORCE, rebuild the tool bar."
7492 (when (and (not (featurep 'xemacs
))
7493 (boundp 'tool-bar-mode
)
7495 (or (not message-tool-bar-map
) force
))
7496 (setq message-tool-bar-map
7498 (gmm-image-load-path-for-library "message"
7499 "mail/save-draft.xpm"
7501 (image-load-path (cons (car load-path
)
7502 (when (boundp 'image-load-path
)
7504 (gmm-tool-bar-from-list message-tool-bar
7505 message-tool-bar-zap-list
7506 'message-mode-map
))))
7507 message-tool-bar-map
)
7509 ;;; Group name completion.
7511 (defcustom message-newgroups-header-regexp
7512 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7513 "Regexp that match headers that lists groups."
7517 (defcustom message-completion-alist
7518 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7519 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7520 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7521 . message-expand-name
)
7522 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7523 . message-expand-name
))
7524 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7527 :type
'(alist :key-type regexp
:value-type function
))
7529 (defcustom message-expand-name-databases
7531 "List of databases to try for name completion (`message-expand-name').
7532 Each element is a symbol and can be `bbdb' or `eudc'."
7534 :type
'(set (const bbdb
) (const eudc
)))
7536 (defcustom message-tab-body-function nil
7537 "*Function to execute when `message-tab' (TAB) is executed in the body.
7538 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7541 :link
'(custom-manual "(message)Various Commands")
7542 :type
'(choice (const nil
)
7545 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7547 (defun message-tab ()
7548 "Complete names according to `message-completion-alist'.
7549 Execute function specified by `message-tab-body-function' when not in
7552 (let ((alist message-completion-alist
))
7554 (let ((mail-abbrev-mode-regexp (caar alist
)))
7555 (not (mail-abbrev-in-expansion-header-p))))
7556 (setq alist
(cdr alist
)))
7557 (funcall (or (cdar alist
) message-tab-body-function
7558 (lookup-key text-mode-map
"\t")
7559 (lookup-key global-map
"\t")
7560 'indent-relative
))))
7565 (let ((standard-output (current-buffer)))
7566 (eval '(display-completion-list nil
"")))
7567 (defalias 'message-display-completion-list
'display-completion-list
))
7568 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7569 (defun message-display-completion-list (completions &optional ignore
)
7570 "Display the list of completions, COMPLETIONS, using `standard-output'."
7571 (display-completion-list completions
)))))
7573 (defun message-expand-group ()
7574 "Expand the group name under point."
7575 (let* ((b (save-excursion
7580 (skip-chars-forward "^:")
7583 (skip-chars-backward "^, \t\n") (point))))
7584 (completion-ignore-case t
)
7585 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
7587 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
7588 (completions (all-completions string hashtb
))
7590 (delete-region b
(point))
7592 ((= (length completions
) 1)
7593 (if (string= (car completions
) string
)
7596 (message "Only matching group"))
7597 (insert (car completions
))))
7598 ((and (setq comp
(try-completion string hashtb
))
7599 (not (string= comp string
)))
7604 (message "No matching groups")
7605 (save-selected-window
7606 (pop-to-buffer "*Completions*")
7607 (buffer-disable-undo)
7608 (let ((buffer-read-only nil
))
7610 (let ((standard-output (current-buffer)))
7611 (message-display-completion-list (sort completions
'string
<)
7613 (setq buffer-read-only nil
)
7614 (goto-char (point-min))
7615 (delete-region (point) (progn (forward-line 3) (point))))))))))
7617 (defun message-expand-name ()
7618 (cond ((and (memq 'eudc message-expand-name-databases
)
7619 (boundp 'eudc-protocol
)
7621 (eudc-expand-inline))
7622 ((and (memq 'bbdb message-expand-name-databases
)
7623 (fboundp 'bbdb-complete-name
))
7624 (bbdb-complete-name))
7630 (defun message-talkative-question (ask question show
&rest text
)
7631 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7632 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7633 The following arguments may contain lists of values."
7635 (setq text
(message-flatten-list text
)))
7636 (save-window-excursion
7637 (with-output-to-temp-buffer " *MESSAGE information message*"
7638 (with-current-buffer " *MESSAGE information message*"
7639 (fundamental-mode) ; for Emacs 20.4+
7641 (goto-char (point-min))))
7642 (funcall ask question
))
7643 (funcall ask question
)))
7645 (defun message-flatten-list (list)
7646 "Return a new, flat list that contains all elements of LIST.
7648 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7651 (apply 'append
(mapcar 'message-flatten-list list
)))
7655 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7656 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7657 Then clone the local variables and values from the old buffer to the
7658 new one, cloning only the locals having a substring matching the
7660 (let ((oldbuf (current-buffer)))
7661 (with-current-buffer (generate-new-buffer name
)
7662 (message-clone-locals oldbuf varstr
)
7665 (defun message-clone-locals (buffer &optional varstr
)
7666 "Clone the local variables from BUFFER to the current buffer."
7667 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7668 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7671 (when (and (consp local
)
7673 (string-match regexp
(symbol-name (car local
)))
7675 (string-match varstr
(symbol-name (car local
)))))
7677 (set (make-local-variable (car local
))
7685 (defvar message-inhibit-body-encoding nil
)
7687 (defun message-encode-message-body ()
7688 (unless message-inhibit-body-encoding
7689 (let ((mail-parse-charset (or mail-parse-charset
7690 message-default-charset
))
7691 (case-fold-search t
)
7692 lines content-type-p
)
7695 (narrow-to-region (point) (point-max))
7696 (let ((new (mml-generate-mime)))
7698 (delete-region (point-min) (point-max))
7700 (goto-char (point-min))
7701 (if (eq (aref new
0) ?
\n)
7703 (search-forward "\n\n")
7704 (setq lines
(buffer-substring (point-min) (1- (point))))
7705 (delete-region (point-min) (point))))))
7707 (message-narrow-to-headers-or-head)
7708 (message-remove-header "Mime-Version")
7709 (goto-char (point-max))
7710 (insert "MIME-Version: 1.0\n")
7713 (setq content-type-p
7715 (re-search-backward "^Content-Type:" nil t
))))
7717 (message-narrow-to-headers-or-head)
7718 (message-remove-first-header "Content-Type")
7719 (message-remove-first-header "Content-Transfer-Encoding"))
7720 ;; We always make sure that the message has a Content-Type
7721 ;; header. This is because some broken MTAs and MUAs get
7722 ;; awfully confused when confronted with a message with a
7723 ;; MIME-Version header and without a Content-Type header. For
7724 ;; instance, Solaris' /usr/bin/mail.
7725 (unless content-type-p
7726 (goto-char (point-min))
7727 ;; For unknown reason, MIME-Version doesn't exist.
7728 (when (re-search-forward "^MIME-Version:" nil t
)
7730 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7732 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7733 "Read from the minibuffer while providing abbrev expansion."
7734 (if (fboundp 'mail-abbrevs-setup
)
7735 (let ((mail-abbrev-mode-regexp "")
7736 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7737 (minibuffer-local-map message-minibuffer-local-map
))
7738 (read-from-minibuffer prompt initial-contents
))
7739 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7740 (minibuffer-local-map message-minibuffer-local-map
))
7741 (read-string prompt initial-contents
))))
7743 (defun message-use-alternative-email-as-from ()
7744 "Set From field of the outgoing message to the first matching
7745 address in `message-alternative-emails', looking at To, Cc and
7746 From headers in the original article."
7747 (require 'mail-utils
)
7748 (let* ((fields '("To" "Cc" "From"))
7751 (mail-strip-quoted-names
7752 (mapconcat 'message-fetch-reply-field fields
","))
7756 (if (string-match message-alternative-emails
(car emails
))
7757 (setq email
(car emails
)
7760 (unless (or (not email
) (equal email user-mail-address
))
7761 (message-remove-header "From")
7762 (goto-char (point-max))
7763 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
7766 (defun message-options-get (symbol)
7767 (cdr (assq symbol message-options
)))
7769 (defun message-options-set (symbol value
)
7770 (let ((the-cons (assq symbol message-options
)))
7773 (setcdr the-cons value
)
7774 (setq message-options
(delq the-cons message-options
)))
7776 (push (cons symbol value
) message-options
))))
7779 (defun message-options-set-recipient ()
7781 (message-narrow-to-headers-or-head)
7782 (message-options-set 'message-sender
7783 (mail-strip-quoted-names
7784 (message-fetch-field "from")))
7785 (message-options-set 'message-recipients
7786 (mail-strip-quoted-names
7787 (let ((to (message-fetch-field "to"))
7788 (cc (message-fetch-field "cc"))
7789 (bcc (message-fetch-field "bcc")))
7792 (if (and to cc
) ", ")
7794 (if (and (or to cc
) bcc
) ", ")
7797 (defun message-hide-headers ()
7798 "Hide headers based on the `message-hidden-headers' variable."
7799 (let ((regexps (if (stringp message-hidden-headers
)
7800 (list message-hidden-headers
)
7801 message-hidden-headers
))
7802 (inhibit-point-motion-hooks t
)
7803 (after-change-functions nil
)
7804 (end-of-headers (point-min)))
7808 (message-narrow-to-headers)
7809 (goto-char (point-min))
7811 (if (not (message-hide-header-p regexps
))
7812 (message-next-header)
7813 (let ((begin (point))
7815 (message-next-header)
7816 (setq header
(buffer-substring begin
(point))
7817 header-len
(- (point) begin
))
7818 (delete-region begin
(point))
7819 (goto-char end-of-headers
)
7821 (setq end-of-headers
7822 (+ end-of-headers header-len
))))))))
7823 (narrow-to-region end-of-headers
(point-max))))
7825 (defun message-hide-header-p (regexps)
7828 (when (eq (car regexps
) 'not
)
7831 (dolist (regexp regexps
)
7832 (setq result
(or result
(looking-at regexp
))))
7837 (defun message-put-addresses-in-ecomplete ()
7838 (dolist (header '("to" "cc" "from" "reply-to"))
7839 (let ((value (message-field-value header
)))
7840 (dolist (string (mail-header-parse-addresses value
'raw
))
7842 (gnus-replace-in-string
7843 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
7844 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
7848 (defun message-display-abbrev (&optional choose
)
7849 "Display the next possible abbrev for the text before point."
7850 (interactive (list t
))
7851 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
7852 (message-point-in-header-p)
7855 (while (and (memq (char-after) '(?
\t ?
))
7856 (zerop (forward-line -
1))))
7857 (looking-at "To:\\|Cc:")))
7858 (let* ((end (point))
7859 (start (save-excursion
7860 (and (re-search-backward "[\n\t ]" nil t
)
7862 (word (when start
(buffer-substring start end
)))
7863 (match (when (and word
7864 (not (zerop (length word
))))
7865 (ecomplete-display-matches 'mail word choose
))))
7866 (when (and choose match
)
7867 (delete-region start end
)
7870 ;; To send pre-formatted letters like the example below, you can use
7871 ;; `message-send-form-letter':
7872 ;; --8<---------------cut here---------------start------------->8---
7873 ;; To: alice@invalid.invalid
7874 ;; Subject: Verification of your contact information
7875 ;; From: Contact verification <admin@foo.invalid>
7876 ;; --text follows this line--
7878 ;; please verify that your contact information is still valid:
7879 ;; Alice A, A avenue 11, 1111 A town, Austria
7880 ;; ----------next form letter message follows this line----------
7881 ;; To: bob@invalid.invalid
7882 ;; Subject: Verification of your contact information
7883 ;; From: Contact verification <admin@foo.invalid>
7884 ;; --text follows this line--
7886 ;; please verify that your contact information is still valid:
7887 ;; Bob, B street 22, 22222 Be town, Belgium
7888 ;; ----------next form letter message follows this line----------
7889 ;; To: charlie@invalid.invalid
7890 ;; Subject: Verification of your contact information
7891 ;; From: Contact verification <admin@foo.invalid>
7892 ;; --text follows this line--
7894 ;; please verify that your contact information is still valid:
7895 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
7896 ;; --8<---------------cut here---------------end--------------->8---
7898 ;; FIXME: What is the most common term (circular letter, form letter, serial
7899 ;; letter, standard letter) for such kind of letter? See also
7900 ;; <http://en.wikipedia.org/wiki/Form_letter>
7902 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
7903 ;; `message-form-letter-separator', i.e. highlight each message like a single
7906 (defcustom message-form-letter-separator
7907 "\n----------next form letter message follows this line----------\n"
7908 "Separator for `message-send-form-letter'."
7909 ;; :group 'message-form-letter
7910 :group
'message-various
7911 :version
"23.1" ;; No Gnus
7914 (defcustom message-send-form-letter-delay
1
7915 "Delay in seconds when sending a message with `message-send-form-letter'.
7916 Only used when `message-send-form-letter' is called with non-nil
7918 ;; :group 'message-form-letter
7919 :group
'message-various
7920 :version
"23.1" ;; No Gnus
7923 (defun message-send-form-letter (&optional force
)
7924 "Sent all form letter messages from current buffer.
7925 Unless FORCE, prompt before sending.
7927 The messages are separated by `message-form-letter-separator'.
7928 Header and body are separated by `mail-header-separator'."
7930 (let ((sent 0) (skipped 0)
7934 (goto-char (point-min))
7937 end
(if (search-forward message-form-letter-separator nil t
)
7938 (- (point) (length message-form-letter-separator
) -
1)
7942 (buffer-substring-no-properties start end
))
7943 (setq buff
(generate-new-buffer "*mail - form letter*"))
7944 (with-current-buffer buff
7947 (setq to
(message-fetch-field "To"))
7948 (switch-to-buffer buff
)
7950 (sit-for message-send-form-letter-delay
))
7952 (y-or-n-p (format "Send message to `%s'? " to
)))
7954 (setq sent
(1+ sent
))
7955 (message-send-and-exit))
7956 (message (format "Message to `%s' skipped." to
))
7957 (setq skipped
(1+ skipped
)))
7958 (when (buffer-live-p buff
)
7959 (kill-buffer buff
))))
7960 (message "%s message(s) sent, %s skipped." sent skipped
)))
7962 (defun message-replace-header (header new-value
&optional after force
)
7963 "Remove HEADER and insert the NEW-VALUE.
7964 If AFTER, insert after this header. If FORCE, insert new field
7965 even if NEW-VALUE is empty."
7966 ;; Similar to `nnheader-replace-header' but for message buffers.
7969 (message-narrow-to-headers)
7970 (message-remove-header header
))
7971 (when (or force
(> (length new-value
) 0))
7973 (message-position-on-field header after
)
7974 (message-position-on-field header
))
7975 (insert new-value
))))
7977 (defcustom message-recipients-without-full-name
7978 (list "ding@gnus.org"
7980 "emacs-devel@gnu.org"
7981 "emacs-pretest-bug@gnu.org"
7982 "bug-gnu-emacs@gnu.org")
7983 "Mail addresses that have no full name.
7984 Used in `message-simplify-recipients'."
7985 ;; Maybe the addresses could be extracted from
7986 ;; `gnus-parameter-to-list-alist'?
7987 :type
'(choice (const :tag
"None" nil
)
7989 :version
"23.1" ;; No Gnus
7990 :group
'message-headers
)
7992 (defun message-simplify-recipients ()
7994 (dolist (hdr '("Cc" "To"))
7995 (message-replace-header
7999 (if (and message-recipients-without-full-name
8001 (regexp-opt message-recipients-without-full-name
)
8005 (message-make-from (car addrcomp
) (cadr addrcomp
))
8007 (when (message-fetch-field hdr
)
8008 (mail-extract-address-components
8009 (message-fetch-field hdr
) t
))
8012 (when (featurep 'xemacs
)
8013 (require 'messagexmas
)
8014 (message-xmas-redefine))
8018 (run-hooks 'message-load-hook
)
8021 ;; coding: iso-8859-1
8024 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
8025 ;;; message.el ends here