Add 7z archive format support (bug#5475).
[emacs.git] / lisp / gnus / message.el
blob7a96d2480b431ce80cbfd64d80c9261043d67774
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, 2009, 2010 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/>.
24 ;;; Commentary:
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.
30 ;;; Code:
32 (eval-and-compile
33 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
34 (eval-when-compile
35 (require 'cl))
37 (require 'mailheader)
38 (require 'gmm-utils)
39 (require 'mail-utils)
40 ;; Only for the trivial macros mail-header-from, mail-header-date
41 ;; mail-header-references, mail-header-subject, mail-header-id
42 (eval-when-compile (require 'nnheader))
43 ;; This is apparently necessary even though things are autoloaded.
44 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
45 ;; require mailabbrev here.
46 (if (featurep 'xemacs)
47 (require 'mail-abbrevs)
48 (require 'mailabbrev))
49 (require 'mail-parse)
50 (require 'mml)
51 (require 'rfc822)
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")
63 :group 'mail
64 :group 'news)
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")
72 :group 'message)
74 (defgroup message-buffers nil
75 "Message Buffers."
76 :link '(custom-manual "(message)Message Buffers")
77 :group 'message)
79 (defgroup message-sending nil
80 "Message Sending."
81 :link '(custom-manual "(message)Sending Variables")
82 :group 'message)
84 (defgroup message-interface nil
85 "Message Interface."
86 :link '(custom-manual "(message)Interface")
87 :group 'message)
89 (defgroup message-forwarding nil
90 "Message Forwarding."
91 :link '(custom-manual "(message)Forwarding")
92 :group 'message-interface)
94 (defgroup message-insertion nil
95 "Message Insertion."
96 :link '(custom-manual "(message)Insertion")
97 :group 'message)
99 (defgroup message-headers nil
100 "Message Headers."
101 :link '(custom-manual "(message)Message Headers")
102 :group 'message)
104 (defgroup message-news nil
105 "Composing News Messages."
106 :group 'message)
108 (defgroup message-mail nil
109 "Composing Mail Messages."
110 :group 'message)
112 (defgroup message-faces nil
113 "Faces used for message composing."
114 :group 'message
115 :group 'faces)
117 (defcustom message-directory "~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group 'message-various
120 :type 'directory)
122 (defcustom message-max-buffers 10
123 "*How many buffers to keep before starting to kill them off."
124 :group 'message-buffers
125 :type 'integer)
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
136 mailbox format."
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."
143 :version "22.1"
144 :type 'boolean
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
160 :type 'regexp)
162 (defcustom message-from-style mail-from-style
163 ;; Default to the value of `mail-from-style', available in all Emacsen
164 ;; that Gnus supports.
165 "*Specifies how \"From\" headers look.
167 If nil, they contain just the return address like:
168 king@grassland.com
169 If `parens', they look like:
170 king@grassland.com (Elvis Parsley)
171 If `angles', they look like:
172 Elvis Parsley <king@grassland.com>
174 Otherwise, most addresses look like `angles', but they look like
175 `parens' if `angles' would need quoting and `parens' would not."
176 :version "23.2"
177 :type '(choice (const :tag "simple" nil)
178 (const parens)
179 (const angles)
180 (const default))
181 :group 'message-headers)
183 (defcustom message-insert-canlock t
184 "Whether to insert a Cancel-Lock header in news postings."
185 :version "22.1"
186 :group 'message-headers
187 :type 'boolean)
189 (defcustom message-syntax-checks
190 (if message-insert-canlock '((sender . disabled)) nil)
191 ;; Guess this one shouldn't be easy to customize...
192 "*Controls what syntax checks should not be performed on outgoing posts.
193 To disable checking of long signatures, for instance, add
194 `(signature . disabled)' to this list.
196 Don't touch this variable unless you really know what you're doing.
198 Checks include `approved', `bogus-recipient', `continuation-headers',
199 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
200 `invisible-text', `long-header-lines', `long-lines', `message-id',
201 `multiple-headers', `new-text', `newsgroups', `quoting-style',
202 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
203 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
204 and `valid-newsgroups'."
205 :group 'message-news
206 :type '(repeat sexp)) ; Fixme: improve this
208 (defcustom message-required-headers '((optional . References)
209 From)
210 "*Headers to be generated or prompted for when sending a message.
211 Also see `message-required-news-headers' and
212 `message-required-mail-headers'."
213 :version "22.1"
214 :group 'message-news
215 :group 'message-headers
216 :link '(custom-manual "(message)Message Headers")
217 :type '(repeat sexp))
219 (defcustom message-draft-headers '(References From Date)
220 "*Headers to be generated when saving a draft message."
221 :version "22.1"
222 :group 'message-news
223 :group 'message-headers
224 :link '(custom-manual "(message)Message Headers")
225 :type '(repeat sexp))
227 (defcustom message-required-news-headers
228 '(From Newsgroups Subject Date Message-ID
229 (optional . Organization)
230 (optional . User-Agent))
231 "*Headers to be generated or prompted for when posting an article.
232 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
233 Message-ID. Organization, Lines, In-Reply-To, Expires, and
234 User-Agent are optional. If you don't want message to insert some
235 header, remove it from this list."
236 :group 'message-news
237 :group 'message-headers
238 :link '(custom-manual "(message)Message Headers")
239 :type '(repeat sexp))
241 (defcustom message-required-mail-headers
242 '(From Subject Date (optional . In-Reply-To) Message-ID
243 (optional . User-Agent))
244 "*Headers to be generated or prompted for when mailing a message.
245 It is recommended that From, Date, To, Subject and Message-ID be
246 included. Organization and User-Agent are optional."
247 :group 'message-mail
248 :group 'message-headers
249 :link '(custom-manual "(message)Message Headers")
250 :type '(repeat sexp))
252 (defcustom message-deletable-headers '(Message-ID Date Lines)
253 "Headers to be deleted if they already exist and were generated by message previously."
254 :group 'message-headers
255 :link '(custom-manual "(message)Message Headers")
256 :type 'sexp)
258 (defcustom message-ignored-news-headers
259 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
260 "*Regexp of headers to be removed unconditionally before posting."
261 :group 'message-news
262 :group 'message-headers
263 :link '(custom-manual "(message)Message Headers")
264 :type '(repeat :value-to-internal (lambda (widget value)
265 (custom-split-regexp-maybe value))
266 :match (lambda (widget value)
267 (or (stringp value)
268 (widget-editable-list-match widget value)))
269 regexp))
271 (defcustom message-ignored-mail-headers
272 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
273 "*Regexp of headers to be removed unconditionally before mailing."
274 :group 'message-mail
275 :group 'message-headers
276 :link '(custom-manual "(message)Mail Headers")
277 :type 'regexp)
279 (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:"
280 "*Header lines matching this regexp will be deleted before posting.
281 It's best to delete old Path and Date headers before posting to avoid
282 any confusion."
283 :group 'message-interface
284 :link '(custom-manual "(message)Superseding")
285 :type '(repeat :value-to-internal (lambda (widget value)
286 (custom-split-regexp-maybe value))
287 :match (lambda (widget value)
288 (or (stringp value)
289 (widget-editable-list-match widget value)))
290 regexp))
292 (defcustom message-subject-re-regexp
293 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
294 "*Regexp matching \"Re: \" in the subject line."
295 :group 'message-various
296 :link '(custom-manual "(message)Message Headers")
297 :type 'regexp)
299 ;;; Start of variables adopted from `message-utils.el'.
301 (defcustom message-subject-trailing-was-query 'ask
302 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
303 If nil, leave the subject unchanged. If it is the symbol `ask', query
304 the user what do do. In this case, the subject is matched against
305 `message-subject-trailing-was-ask-regexp'. If
306 `message-subject-trailing-was-query' is t, always strip the trailing
307 old subject. In this case, `message-subject-trailing-was-regexp' is
308 used."
309 :version "22.1"
310 :type '(choice (const :tag "never" nil)
311 (const :tag "always strip" t)
312 (const ask))
313 :link '(custom-manual "(message)Message Headers")
314 :group 'message-various)
316 (defcustom message-subject-trailing-was-ask-regexp
317 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
318 "*Regexp matching \"(was: <old subject>)\" in the subject line.
320 The function `message-strip-subject-trailing-was' uses this regexp if
321 `message-subject-trailing-was-query' is set to the symbol `ask'. If
322 the variable is t instead of `ask', use
323 `message-subject-trailing-was-regexp' instead.
325 It is okay to create some false positives here, as the user is asked."
326 :version "22.1"
327 :group 'message-various
328 :link '(custom-manual "(message)Message Headers")
329 :type 'regexp)
331 (defcustom message-subject-trailing-was-regexp
332 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
333 "*Regexp matching \"(was: <old subject>)\" in the subject line.
335 If `message-subject-trailing-was-query' is set to t, the subject is
336 matched against `message-subject-trailing-was-regexp' in
337 `message-strip-subject-trailing-was'. You should use a regexp creating very
338 few false positives here."
339 :version "22.1"
340 :group 'message-various
341 :link '(custom-manual "(message)Message Headers")
342 :type 'regexp)
344 ;;; marking inserted text
346 (defcustom message-mark-insert-begin
347 "--8<---------------cut here---------------start------------->8---\n"
348 "How to mark the beginning of some inserted text."
349 :version "22.1"
350 :type 'string
351 :link '(custom-manual "(message)Insertion Variables")
352 :group 'message-various)
354 (defcustom message-mark-insert-end
355 "--8<---------------cut here---------------end--------------->8---\n"
356 "How to mark the end of some inserted text."
357 :version "22.1"
358 :type 'string
359 :link '(custom-manual "(message)Insertion Variables")
360 :group 'message-various)
362 (defcustom message-archive-header "X-No-Archive: Yes\n"
363 "Header to insert when you don't want your article to be archived.
364 Archives \(such as groups.google.com\) respect this header."
365 :version "22.1"
366 :type 'string
367 :link '(custom-manual "(message)Header Commands")
368 :group 'message-various)
370 (defcustom message-archive-note
371 "X-No-Archive: Yes - save http://groups.google.com/"
372 "Note to insert why you wouldn't want this posting archived.
373 If nil, don't insert any text in the body."
374 :version "22.1"
375 :type '(radio string (const nil))
376 :link '(custom-manual "(message)Header Commands")
377 :group 'message-various)
379 ;;; Crossposts and Followups
380 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
381 ;; new suggestions by R. Weikusat <rw at another.de>
383 (defvar message-cross-post-old-target nil
384 "Old target for cross-posts or follow-ups.")
385 (make-variable-buffer-local 'message-cross-post-old-target)
387 (defcustom message-cross-post-default t
388 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
389 If nil, `message-cross-post-followup-to' will only do a followup. Note that
390 you can explicitly override this setting by calling
391 `message-cross-post-followup-to' with a prefix."
392 :version "22.1"
393 :type 'boolean
394 :group 'message-various)
396 (defcustom message-cross-post-note "Crosspost & Followup-To: "
397 "Note to insert before signature to notify of cross-post and follow-up."
398 :version "22.1"
399 :type 'string
400 :group 'message-various)
402 (defcustom message-followup-to-note "Followup-To: "
403 "Note to insert before signature to notify of follow-up only."
404 :version "22.1"
405 :type 'string
406 :group 'message-various)
408 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
409 "Function to use to insert note about Crosspost or Followup-To.
410 The function will be called with four arguments. The function should not only
411 insert a note, but also ensure old notes are deleted. See the documentation
412 for `message-cross-post-insert-note'."
413 :version "22.1"
414 :type 'function
415 :group 'message-various)
417 ;;; End of variables adopted from `message-utils.el'.
419 (defcustom message-signature-separator "^-- $"
420 "Regexp matching the signature separator.
421 This variable is used to strip off the signature from quoted text
422 when `message-cite-function' is
423 `message-cite-original-without-signature'. Most useful values
424 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
425 whitespace)."
426 :type '(choice (const :tag "strict" "^-- $")
427 (const :tag "loose" "^-- *$")
428 regexp)
429 :version "22.3" ;; Gnus 5.10.12 (changed default)
430 :link '(custom-manual "(message)Various Message Variables")
431 :group 'message-various)
433 (defcustom message-elide-ellipsis "\n[...]\n\n"
434 "*The string which is inserted for elided text."
435 :type 'string
436 :link '(custom-manual "(message)Various Commands")
437 :group 'message-various)
439 (defcustom message-interactive mail-interactive
440 ;; Default to the value of `mail-interactive', available in all Emacsen
441 ;; that Gnus supports.
442 "Non-nil means when sending a message wait for and display errors.
443 A value of nil means let mailer mail back a message to report errors."
444 :version "23.2"
445 :group 'message-sending
446 :group 'message-mail
447 :link '(custom-manual "(message)Sending Variables")
448 :type 'boolean)
450 (defcustom message-confirm-send nil
451 "When non-nil, ask for confirmation when sending a message."
452 :group 'message-sending
453 :group 'message-mail
454 :version "23.1" ;; No Gnus
455 :link '(custom-manual "(message)Sending Variables")
456 :type 'boolean)
458 (defcustom message-generate-new-buffers 'unique
459 "*Say whether to create a new message buffer to compose a message.
460 Valid values include:
463 Generate the buffer name in the Message way (e.g., *mail*, *news*,
464 *mail to whom*, *news on group*, etc.) and continue editing in the
465 existing buffer of that name. If there is no such buffer, it will
466 be newly created.
468 `unique' or t
469 Create the new buffer with the name generated in the Message way.
471 `unsent'
472 Similar to `unique' but the buffer name begins with \"*unsent \".
474 `standard'
475 Similar to nil but the buffer name is simpler like *mail message*.
477 function
478 If this is a function, call that function with three parameters:
479 The type, the To address and the group name (any of these may be nil).
480 The function should return the new buffer name."
481 :group 'message-buffers
482 :link '(custom-manual "(message)Message Buffers")
483 :type '(choice (const nil)
484 (sexp :tag "unique" :format "unique\n" :value unique
485 :match (lambda (widget value) (memq value '(unique t))))
486 (const unsent)
487 (const standard)
488 (function :format "\n %{%t%}: %v")))
490 (defcustom message-kill-buffer-on-exit nil
491 "*Non-nil means that the message buffer will be killed after sending a message."
492 :group 'message-buffers
493 :link '(custom-manual "(message)Message Buffers")
494 :type 'boolean)
496 (defcustom message-kill-buffer-query t
497 "*Non-nil means that killing a modified message buffer has to be confirmed.
498 This is used by `message-kill-buffer'."
499 :version "23.1" ;; No Gnus
500 :group 'message-buffers
501 :type 'boolean)
503 (defvar gnus-local-organization)
504 (defcustom message-user-organization
505 (or (and (boundp 'gnus-local-organization)
506 (stringp gnus-local-organization)
507 gnus-local-organization)
508 (getenv "ORGANIZATION")
510 "*String to be used as an Organization header.
511 If t, use `message-user-organization-file'."
512 :group 'message-headers
513 :type '(choice string
514 (const :tag "consult file" t)))
516 (defcustom message-user-organization-file
517 (let (orgfile)
518 (dolist (f (list "/etc/organization"
519 "/etc/news/organization"
520 "/usr/lib/news/organization"))
521 (when (file-readable-p f)
522 (setq orgfile f)))
523 orgfile)
524 "*Local news organization file."
525 :type 'file
526 :link '(custom-manual "(message)News Headers")
527 :group 'message-headers)
529 (defcustom message-make-forward-subject-function
530 #'message-forward-subject-name-subject
531 "*List of functions called to generate subject headers for forwarded messages.
532 The subject generated by the previous function is passed into each
533 successive function.
535 The provided functions are:
537 * `message-forward-subject-author-subject' Source of article (author or
538 newsgroup), in brackets followed by the subject
539 * `message-forward-subject-name-subject' Source of article (name of author
540 or newsgroup), in brackets followed by the subject
541 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
542 to it."
543 :group 'message-forwarding
544 :link '(custom-manual "(message)Forwarding")
545 :type '(radio (function-item message-forward-subject-author-subject)
546 (function-item message-forward-subject-fwd)
547 (function-item message-forward-subject-name-subject)
548 (repeat :tag "List of functions" function)))
550 (defcustom message-forward-as-mime t
551 "*Non-nil means forward messages as an inline/rfc822 MIME section.
552 Otherwise, directly inline the old message in the forwarded message."
553 :version "21.1"
554 :group 'message-forwarding
555 :link '(custom-manual "(message)Forwarding")
556 :type 'boolean)
558 (defcustom message-forward-show-mml 'best
559 "*Non-nil means show forwarded messages as MML (decoded from MIME).
560 Otherwise, forwarded messages are unchanged.
561 Can also be the symbol `best' to indicate that MML should be
562 used, except when it is a bad idea to use MML. One example where
563 it is a bad idea is when forwarding a signed or encrypted
564 message, because converting MIME to MML would invalidate the
565 digital signature."
566 :version "21.1"
567 :group 'message-forwarding
568 :type '(choice (const :tag "use MML" t)
569 (const :tag "don't use MML " nil)
570 (const :tag "use MML when appropriate" best)))
572 (defcustom message-forward-before-signature t
573 "*Non-nil means put forwarded message before signature, else after."
574 :group 'message-forwarding
575 :type 'boolean)
577 (defcustom message-wash-forwarded-subjects nil
578 "*Non-nil means try to remove as much cruft as possible from the subject.
579 Done before generating the new subject of a forward."
580 :group 'message-forwarding
581 :link '(custom-manual "(message)Forwarding")
582 :type 'boolean)
584 (defcustom message-ignored-resent-headers
585 ;; `Delivered-To' needs to be removed because some mailers use it to
586 ;; detect loops, so if you resend a message to an address that ultimately
587 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
588 ;; case you may be removed from the list on the grounds that mail to you
589 ;; bounced with a "mailing loop" error).
590 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
591 "*All headers that match this regexp will be deleted when resending a message."
592 :group 'message-interface
593 :link '(custom-manual "(message)Resending")
594 :type '(repeat :value-to-internal (lambda (widget value)
595 (custom-split-regexp-maybe value))
596 :match (lambda (widget value)
597 (or (stringp value)
598 (widget-editable-list-match widget value)))
599 regexp))
601 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
602 "*All headers that match this regexp will be deleted when forwarding a message."
603 :version "21.1"
604 :group 'message-forwarding
605 :type '(repeat :value-to-internal (lambda (widget value)
606 (custom-split-regexp-maybe value))
607 :match (lambda (widget value)
608 (or (stringp value)
609 (widget-editable-list-match widget value)))
610 regexp))
612 (defcustom message-ignored-cited-headers "."
613 "*Delete these headers from the messages you yank."
614 :group 'message-insertion
615 :link '(custom-manual "(message)Insertion Variables")
616 :type 'regexp)
618 (defcustom message-cite-prefix-regexp
619 ;; Default to the value of `mail-citation-prefix-regexp' if available.
620 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
621 ;; unless sendmail.el is loaded.
622 (cond ((boundp 'mail-citation-prefix-regexp)
623 mail-citation-prefix-regexp)
624 ((string-match "[[:digit:]]" "1")
625 ;; Support POSIX? XEmacs 21.5.27 doesn't.
626 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+")
628 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
629 (let (non-word-constituents)
630 (with-syntax-table text-mode-syntax-table
631 (setq non-word-constituents
632 (concat
633 (if (string-match "\\w" "_") "" "_")
634 (if (string-match "\\w" ".") "" "."))))
635 (if (equal non-word-constituents "")
636 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
637 (concat "\\([ \t]*\\(\\w\\|["
638 non-word-constituents
639 "]\\)+>+\\|[ \t]*[]>|}]\\)+")))))
640 "*Regexp matching the longest possible citation prefix on a line."
641 :version "23.2"
642 :group 'message-insertion
643 :link '(custom-manual "(message)Insertion Variables")
644 :type 'regexp
645 :set (lambda (symbol value)
646 (prog1
647 (custom-set-default symbol value)
648 (if (boundp 'gnus-message-cite-prefix-regexp)
649 (setq gnus-message-cite-prefix-regexp
650 (concat "^\\(?:" value "\\)"))))))
652 (defcustom message-cancel-message "I am canceling my own article.\n"
653 "Message to be inserted in the cancel message."
654 :group 'message-interface
655 :link '(custom-manual "(message)Canceling News")
656 :type 'string)
658 (defun message-send-mail-function ()
659 "Return suitable value for the variable `message-send-mail-function'."
660 (cond ((and (require 'sendmail)
661 (boundp 'sendmail-program)
662 sendmail-program
663 (executable-find sendmail-program))
664 'message-send-mail-with-sendmail)
665 ((and (locate-library "smtpmail")
666 (boundp 'smtpmail-default-smtp-server)
667 smtpmail-default-smtp-server)
668 'message-smtpmail-send-it)
669 ((locate-library "mailclient")
670 'message-send-mail-with-mailclient)
672 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
674 ;; Useful to set in site-init.el
675 (defcustom message-send-mail-function
676 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
677 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
678 ((eq send-mail-function 'mailclient-send-it)
679 'message-send-mail-with-mailclient)
680 (t (message-send-mail-function)))
681 "Function to call to send the current buffer as mail.
682 The headers should be delimited by a line whose contents match the
683 variable `mail-header-separator'.
685 Valid values include `message-send-mail-with-sendmail'
686 `message-send-mail-with-mh', `message-send-mail-with-qmail',
687 `message-smtpmail-send-it', `smtpmail-send-it',
688 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
689 default is system dependent and determined by the function
690 `message-send-mail-function'.
692 See also `send-mail-function'."
693 :type '(radio (function-item message-send-mail-with-sendmail)
694 (function-item message-send-mail-with-mh)
695 (function-item message-send-mail-with-qmail)
696 (function-item message-smtpmail-send-it)
697 (function-item smtpmail-send-it)
698 (function-item feedmail-send-it)
699 (function-item message-send-mail-with-mailclient
700 :tag "Use Mailclient package")
701 (function :tag "Other"))
702 :group 'message-sending
703 :version "23.2"
704 :initialize 'custom-initialize-default
705 :link '(custom-manual "(message)Mail Variables")
706 :group 'message-mail)
708 (defcustom message-send-news-function 'message-send-news
709 "Function to call to send the current buffer as news.
710 The headers should be delimited by a line whose contents match the
711 variable `mail-header-separator'."
712 :group 'message-sending
713 :group 'message-news
714 :link '(custom-manual "(message)News Variables")
715 :type 'function)
717 (defcustom message-reply-to-function nil
718 "If non-nil, function that should return a list of headers.
719 This function should pick out addresses from the To, Cc, and From headers
720 and respond with new To and Cc headers."
721 :group 'message-interface
722 :link '(custom-manual "(message)Reply")
723 :type '(choice function (const nil)))
725 (defcustom message-wide-reply-to-function nil
726 "If non-nil, function that should return a list of headers.
727 This function should pick out addresses from the To, Cc, and From headers
728 and respond with new To and Cc headers."
729 :group 'message-interface
730 :link '(custom-manual "(message)Wide Reply")
731 :type '(choice function (const nil)))
733 (defcustom message-followup-to-function nil
734 "If non-nil, function that should return a list of headers.
735 This function should pick out addresses from the To, Cc, and From headers
736 and respond with new To and Cc headers."
737 :group 'message-interface
738 :link '(custom-manual "(message)Followup")
739 :type '(choice function (const nil)))
741 (defcustom message-extra-wide-headers nil
742 "If non-nil, a list of additional address headers.
743 These are used when composing a wide reply."
744 :group 'message-sending
745 :type '(repeat string))
747 (defcustom message-use-followup-to 'ask
748 "*Specifies what to do with Followup-To header.
749 If nil, always ignore the header. If it is t, use its value, but
750 query before using the \"poster\" value. If it is the symbol `ask',
751 always query the user whether to use the value. If it is the symbol
752 `use', always use the value."
753 :group 'message-interface
754 :link '(custom-manual "(message)Followup")
755 :type '(choice (const :tag "ignore" nil)
756 (const :tag "use & query" t)
757 (const use)
758 (const ask)))
760 (defcustom message-use-mail-followup-to 'use
761 "*Specifies what to do with Mail-Followup-To header.
762 If nil, always ignore the header. If it is the symbol `ask', always
763 query the user whether to use the value. If it is the symbol `use',
764 always use the value."
765 :version "22.1"
766 :group 'message-interface
767 :link '(custom-manual "(message)Mailing Lists")
768 :type '(choice (const :tag "ignore" nil)
769 (const use)
770 (const ask)))
772 (defcustom message-subscribed-address-functions nil
773 "*Specifies functions for determining list subscription.
774 If nil, do not attempt to determine list subscription with functions.
775 If non-nil, this variable contains a list of functions which return
776 regular expressions to match lists. These functions can be used in
777 conjunction with `message-subscribed-regexps' and
778 `message-subscribed-addresses'."
779 :version "22.1"
780 :group 'message-interface
781 :link '(custom-manual "(message)Mailing Lists")
782 :type '(repeat sexp))
784 (defcustom message-subscribed-address-file nil
785 "*A file containing addresses the user is subscribed to.
786 If nil, do not look at any files to determine list subscriptions. If
787 non-nil, each line of this file should be a mailing list address."
788 :version "22.1"
789 :group 'message-interface
790 :link '(custom-manual "(message)Mailing Lists")
791 :type '(radio file (const nil)))
793 (defcustom message-subscribed-addresses nil
794 "*Specifies a list of addresses the user is subscribed to.
795 If nil, do not use any predefined list subscriptions. This list of
796 addresses can be used in conjunction with
797 `message-subscribed-address-functions' and `message-subscribed-regexps'."
798 :version "22.1"
799 :group 'message-interface
800 :link '(custom-manual "(message)Mailing Lists")
801 :type '(repeat string))
803 (defcustom message-subscribed-regexps nil
804 "*Specifies a list of addresses the user is subscribed to.
805 If nil, do not use any predefined list subscriptions. This list of
806 regular expressions can be used in conjunction with
807 `message-subscribed-address-functions' and `message-subscribed-addresses'."
808 :version "22.1"
809 :group 'message-interface
810 :link '(custom-manual "(message)Mailing Lists")
811 :type '(repeat regexp))
813 (defcustom message-allow-no-recipients 'ask
814 "Specifies what to do when there are no recipients other than Gcc/Fcc.
815 If it is the symbol `always', the posting is allowed. If it is the
816 symbol `never', the posting is not allowed. If it is the symbol
817 `ask', you are prompted."
818 :version "22.1"
819 :group 'message-interface
820 :link '(custom-manual "(message)Message Headers")
821 :type '(choice (const always)
822 (const never)
823 (const ask)))
825 (defcustom message-sendmail-f-is-evil nil
826 "*Non-nil means don't add \"-f username\" to the sendmail command line.
827 Doing so would be even more evil than leaving it out."
828 :group 'message-sending
829 :link '(custom-manual "(message)Mail Variables")
830 :type 'boolean)
832 (defcustom message-sendmail-envelope-from
833 ;; Default to the value of `mail-envelope-from' if available.
834 ;; Note: as for Emacsen that Gnus supports, except for SXEmacs, it is
835 ;; unavailable unless sendmail.el is loaded.
836 (if (boundp 'mail-envelope-from) mail-envelope-from)
837 "*Envelope-from when sending mail with sendmail.
838 If this is nil, use `user-mail-address'. If it is the symbol
839 `header', use the From: header of the message."
840 :version "23.2"
841 :type '(choice (string :tag "From name")
842 (const :tag "Use From: header from message" header)
843 (const :tag "Use `user-mail-address'" nil))
844 :link '(custom-manual "(message)Mail Variables")
845 :group 'message-sending)
847 (defcustom message-sendmail-extra-arguments nil
848 "Additional arguments to `sendmail-program'."
849 ;; E.g. '("-a" "account") for msmtp
850 :version "23.1" ;; No Gnus
851 :type '(repeat string)
852 ;; :link '(custom-manual "(message)Mail Variables")
853 :group 'message-sending)
855 ;; qmail-related stuff
856 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
857 "Location of the qmail-inject program."
858 :group 'message-sending
859 :link '(custom-manual "(message)Mail Variables")
860 :type 'file)
862 (defcustom message-qmail-inject-args nil
863 "Arguments passed to qmail-inject programs.
864 This should be a list of strings, one string for each argument.
865 It may also be a function.
867 For e.g., if you wish to set the envelope sender address so that bounces
868 go to the right place or to deal with listserv's usage of that address, you
869 might set this variable to '(\"-f\" \"you@some.where\")."
870 :group 'message-sending
871 :link '(custom-manual "(message)Mail Variables")
872 :type '(choice (function)
873 (repeat string)))
875 (defvar gnus-post-method)
876 (defvar gnus-select-method)
877 (defcustom message-post-method
878 (cond ((and (boundp 'gnus-post-method)
879 (listp gnus-post-method)
880 gnus-post-method)
881 gnus-post-method)
882 ((boundp 'gnus-select-method)
883 gnus-select-method)
884 (t '(nnspool "")))
885 "*Method used to post news.
886 Note that when posting from inside Gnus, for instance, this
887 variable isn't used."
888 :group 'message-news
889 :group 'message-sending
890 ;; This should be the `gnus-select-method' widget, but that might
891 ;; create a dependence to `gnus.el'.
892 :type 'sexp)
894 ;; FIXME: This should be a temporary workaround until someone implements a
895 ;; proper solution. If a crash happens while replying, the auto-save file
896 ;; will *not* have a `References:' header if `message-generate-headers-first'
897 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
898 (defcustom message-generate-headers-first '(references)
899 "Which headers should be generated before starting to compose a message.
900 If t, generate all required headers. This can also be a list of headers to
901 generate. The variables `message-required-news-headers' and
902 `message-required-mail-headers' specify which headers to generate.
904 Note that the variable `message-deletable-headers' specifies headers which
905 are to be deleted and then re-generated before sending, so this variable
906 will not have a visible effect for those headers."
907 :group 'message-headers
908 :link '(custom-manual "(message)Message Headers")
909 :type '(choice (const :tag "None" nil)
910 (const :tag "References" '(references))
911 (const :tag "All" t)
912 (repeat (sexp :tag "Header"))))
914 (defcustom message-fill-column 72
915 "Column beyond which automatic line-wrapping should happen.
916 Local value for message buffers. If non-nil, also turn on
917 auto-fill in message buffers."
918 :group 'message-various
919 ;; :link '(custom-manual "(message)Message Headers")
920 :type '(choice (const :tag "Don't turn on auto fill" nil)
921 (integer)))
923 (defcustom message-setup-hook nil
924 "Normal hook, run each time a new outgoing message is initialized.
925 The function `message-setup' runs this hook."
926 :group 'message-various
927 :link '(custom-manual "(message)Various Message Variables")
928 :type 'hook)
930 (defcustom message-cancel-hook nil
931 "Hook run when cancelling articles."
932 :group 'message-various
933 :link '(custom-manual "(message)Various Message Variables")
934 :type 'hook)
936 (defcustom message-signature-setup-hook nil
937 "Normal hook, run each time a new outgoing message is initialized.
938 It is run after the headers have been inserted and before
939 the signature is inserted."
940 :group 'message-various
941 :link '(custom-manual "(message)Various Message Variables")
942 :type 'hook)
944 (defcustom message-mode-hook nil
945 "Hook run in message mode buffers."
946 :group 'message-various
947 :type 'hook)
949 (defcustom message-header-hook nil
950 "Hook run in a message mode buffer narrowed to the headers."
951 :group 'message-various
952 :type 'hook)
954 (defcustom message-header-setup-hook nil
955 "Hook called narrowed to the headers when setting up a message buffer."
956 :group 'message-various
957 :link '(custom-manual "(message)Various Message Variables")
958 :type 'hook)
960 (defcustom message-minibuffer-local-map
961 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
962 (set-keymap-parent map minibuffer-local-map)
963 map)
964 "Keymap for `message-read-from-minibuffer'."
965 :version "22.1"
966 :group 'message-various)
968 (defcustom message-citation-line-function 'message-insert-citation-line
969 "*Function called to insert the \"Whomever writes:\" line.
971 Predefined functions include `message-insert-citation-line' and
972 `message-insert-formatted-citation-line' (see the variable
973 `message-citation-line-format').
975 Note that Gnus provides a feature where the reader can click on
976 `writes:' to hide the cited text. If you change this line too much,
977 people who read your message will have to change their Gnus
978 configuration. See the variable `gnus-cite-attribution-suffix'."
979 :type '(choice
980 (function-item :tag "plain" message-insert-citation-line)
981 (function-item :tag "formatted" message-insert-formatted-citation-line)
982 (function :tag "Other"))
983 :link '(custom-manual "(message)Insertion Variables")
984 :group 'message-insertion)
986 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
987 "Format of the \"Whomever writes:\" line.
989 The string is formatted using `format-spec'. The following
990 constructs are replaced:
992 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
993 %n The mail address, e.g. \"john.doe@example.invalid\".
994 %N The real name if present, e.g.: \"John Doe\", else fall
995 back to the mail address.
996 %F The first name if present, e.g.: \"John\".
997 %L The last name if present, e.g.: \"Doe\".
999 All other format specifiers are passed to `format-time-string'
1000 which is called using the date from the article your replying to.
1001 Extracting the first (%F) and last name (%L) is done
1002 heuristically, so you should always check it yourself.
1004 Please also read the note in the documentation of
1005 `message-citation-line-function'."
1006 :type '(choice (const :tag "Plain" "%f writes:")
1007 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1008 string)
1009 :link '(custom-manual "(message)Insertion Variables")
1010 :version "23.1" ;; No Gnus
1011 :group 'message-insertion)
1013 (defcustom message-yank-prefix
1014 ;; Default to the value of `mail-yank-prefix' if available.
1015 ;; Note: as for Emacs 21, it is unavailable unless sendmail.el is loaded.
1016 (if (boundp 'mail-yank-prefix) mail-yank-prefix "> ")
1017 "*Prefix inserted on the lines of yanked messages.
1018 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1019 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1020 :version "23.2"
1021 :type 'string
1022 :link '(custom-manual "(message)Insertion Variables")
1023 :group 'message-insertion)
1025 (defcustom message-yank-cited-prefix ">"
1026 "*Prefix inserted on cited lines of yanked messages.
1027 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1028 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1029 :version "22.1"
1030 :type 'string
1031 :link '(custom-manual "(message)Insertion Variables")
1032 :group 'message-insertion)
1034 (defcustom message-yank-empty-prefix ">"
1035 "*Prefix inserted on empty lines of yanked messages.
1036 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1037 :version "22.1"
1038 :type 'string
1039 :link '(custom-manual "(message)Insertion Variables")
1040 :group 'message-insertion)
1042 (defcustom message-indentation-spaces
1043 ;; Default to the value of `mail-indentation-spaces' if available.
1044 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1045 ;; unless sendmail.el is loaded.
1046 (if (boundp 'mail-indentation-spaces) mail-indentation-spaces 3)
1047 "*Number of spaces to insert at the beginning of each cited line.
1048 Used by `message-yank-original' via `message-yank-cite'."
1049 :version "23.2"
1050 :group 'message-insertion
1051 :link '(custom-manual "(message)Insertion Variables")
1052 :type 'integer)
1054 (defcustom message-cite-function 'message-cite-original-without-signature
1055 "*Function for citing an original message.
1056 Predefined functions include `message-cite-original' and
1057 `message-cite-original-without-signature'.
1058 Note that these functions use `mail-citation-hook' if that is non-nil."
1059 :type '(radio (function-item message-cite-original)
1060 (function-item message-cite-original-without-signature)
1061 (function-item sc-cite-original)
1062 (function :tag "Other"))
1063 :link '(custom-manual "(message)Insertion Variables")
1064 :version "22.3" ;; Gnus 5.10.12 (changed default)
1065 :group 'message-insertion)
1067 (defcustom message-indent-citation-function 'message-indent-citation
1068 "*Function for modifying a citation just inserted in the mail buffer.
1069 This can also be a list of functions. Each function can find the
1070 citation between (point) and (mark t). And each function should leave
1071 point and mark around the citation text as modified."
1072 :type 'function
1073 :link '(custom-manual "(message)Insertion Variables")
1074 :group 'message-insertion)
1076 (defcustom message-signature mail-signature
1077 ;; Default to the value of `mail-signature', available in all Emacsen
1078 ;; that Gnus supports.
1079 "*String to be inserted at the end of the message buffer.
1080 If t, the `message-signature-file' file will be inserted instead.
1081 If a function, the result from the function will be used instead.
1082 If a form, the result from the form will be used instead."
1083 :version "23.2"
1084 :type 'sexp
1085 :link '(custom-manual "(message)Insertion Variables")
1086 :group 'message-insertion)
1088 (defcustom message-signature-file
1089 ;; Default to the value of `mail-signature-file' if available.
1090 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1091 ;; unless sendmail.el is loaded.
1092 (if (boundp 'mail-signature-file) mail-signature-file "~/.signature")
1093 "*Name of file containing the text inserted at end of message buffer.
1094 Ignored if the named file doesn't exist.
1095 If nil, don't insert a signature.
1096 If a path is specified, the value of `message-signature-directory' is ignored,
1097 even if set."
1098 :version "23.2"
1099 :type '(choice file (const :tags "None" nil))
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1103 (defcustom message-signature-directory nil
1104 "*Name of directory containing signature files.
1105 Comes in handy if you have many such files, handled via posting styles for
1106 instance.
1107 If nil, `message-signature-file' is expected to specify the directory if
1108 needed."
1109 :type '(choice string (const :tags "None" nil))
1110 :link '(custom-manual "(message)Insertion Variables")
1111 :group 'message-insertion)
1113 (defcustom message-signature-insert-empty-line t
1114 "*If non-nil, insert an empty line before the signature separator."
1115 :version "22.1"
1116 :type 'boolean
1117 :link '(custom-manual "(message)Insertion Variables")
1118 :group 'message-insertion)
1120 (defcustom message-distribution-function nil
1121 "*Function called to return a Distribution header."
1122 :group 'message-news
1123 :group 'message-headers
1124 :link '(custom-manual "(message)News Headers")
1125 :type '(choice function (const nil)))
1127 (defcustom message-expires 14
1128 "Number of days before your article expires."
1129 :group 'message-news
1130 :group 'message-headers
1131 :link '(custom-manual "(message)News Headers")
1132 :type 'integer)
1134 (defcustom message-user-path nil
1135 "If nil, use the NNTP server name in the Path header.
1136 If stringp, use this; if non-nil, use no host name (user name only)."
1137 :group 'message-news
1138 :group 'message-headers
1139 :link '(custom-manual "(message)News Headers")
1140 :type '(choice (const :tag "nntp" nil)
1141 (string :tag "name")
1142 (sexp :tag "none" :format "%t" t)))
1144 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1145 ;; for yanking the original buffer.
1146 (defvar message-reply-buffer nil)
1147 (defvar message-reply-headers nil
1148 "The headers of the current replied article.
1149 It is a vector of the following headers:
1150 \[number subject from date id references chars lines xref extra].")
1151 (defvar message-newsreader nil)
1152 (defvar message-mailer nil)
1153 (defvar message-sent-message-via nil)
1154 (defvar message-checksum nil)
1155 (defvar message-send-actions nil
1156 "A list of actions to be performed upon successful sending of a message.")
1157 (defvar message-exit-actions nil
1158 "A list of actions to be performed upon exiting after sending a message.")
1159 (defvar message-kill-actions nil
1160 "A list of actions to be performed before killing a message buffer.")
1161 (defvar message-postpone-actions nil
1162 "A list of actions to be performed after postponing a message.")
1164 (define-widget 'message-header-lines 'text
1165 "All header lines must be LFD terminated."
1166 :format "%{%t%}:%n%v"
1167 :valid-regexp "^\\'"
1168 :error "All header lines must be newline terminated")
1170 (defcustom message-default-headers ""
1171 "*A string containing header lines to be inserted in outgoing messages.
1172 It is inserted before you edit the message, so you can edit or delete
1173 these lines."
1174 :version "23.2"
1175 :group 'message-headers
1176 :link '(custom-manual "(message)Message Headers")
1177 :type 'message-header-lines)
1179 (defcustom message-default-mail-headers
1180 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1181 (concat (if (and (boundp 'mail-default-reply-to)
1182 (stringp mail-default-reply-to))
1183 (format "Reply-to: %s\n" mail-default-reply-to))
1184 (if (and (boundp 'mail-self-blind)
1185 mail-self-blind)
1186 (format "BCC: %s\n" user-mail-address))
1187 (if (and (boundp 'mail-archive-file-name)
1188 (stringp mail-archive-file-name))
1189 (format "FCC: %s\n" mail-archive-file-name))
1190 ;; Use the value of `mail-default-headers' if available.
1191 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is
1192 ;; unavailable unless sendmail.el is loaded.
1193 (if (boundp 'mail-default-headers)
1194 mail-default-headers))
1195 "*A string of header lines to be inserted in outgoing mails."
1196 :version "23.2"
1197 :group 'message-headers
1198 :group 'message-mail
1199 :link '(custom-manual "(message)Mail Headers")
1200 :type 'message-header-lines)
1202 (defcustom message-default-news-headers ""
1203 "*A string of header lines to be inserted in outgoing news articles."
1204 :group 'message-headers
1205 :group 'message-news
1206 :link '(custom-manual "(message)News Headers")
1207 :type 'message-header-lines)
1209 ;; Note: could use /usr/ucb/mail instead of sendmail;
1210 ;; options -t, and -v if not interactive.
1211 (defcustom message-mailer-swallows-blank-line
1212 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1213 system-configuration)
1214 (file-readable-p "/etc/sendmail.cf")
1215 (let ((buffer (get-buffer-create " *temp*")))
1216 (unwind-protect
1217 (with-current-buffer buffer
1218 (insert-file-contents "/etc/sendmail.cf")
1219 (goto-char (point-min))
1220 (let ((case-fold-search nil))
1221 (re-search-forward "^OR\\>" nil t)))
1222 (kill-buffer buffer))))
1223 ;; According to RFC822, "The field-name must be composed of printable
1224 ;; ASCII characters (i. e., characters that have decimal values between
1225 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1226 ;; space, or colon.
1227 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1228 "*Set this non-nil if the system's mailer runs the header and body together.
1229 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1230 The value should be an expression to test whether the problem will
1231 actually occur."
1232 :group 'message-sending
1233 :link '(custom-manual "(message)Mail Variables")
1234 :type 'sexp)
1236 ;;;###autoload
1237 (define-mail-user-agent 'message-user-agent
1238 'message-mail 'message-send-and-exit
1239 'message-kill-buffer 'message-send-hook)
1241 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1242 "If non-nil, delete the deletable headers before feeding to mh.")
1244 (defvar message-send-method-alist
1245 '((news message-news-p message-send-via-news)
1246 (mail message-mail-p message-send-via-mail))
1247 "Alist of ways to send outgoing messages.
1248 Each element has the form
1250 \(TYPE PREDICATE FUNCTION)
1252 where TYPE is a symbol that names the method; PREDICATE is a function
1253 called without any parameters to determine whether the message is
1254 a message of type TYPE; and FUNCTION is a function to be called if
1255 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1256 the prefix.")
1258 (defcustom message-mail-alias-type 'abbrev
1259 "*What alias expansion type to use in Message buffers.
1260 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1261 an electric completion mode. nil switches mail aliases off.
1262 This can also be a list of values."
1263 :group 'message
1264 :link '(custom-manual "(message)Mail Aliases")
1265 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1266 (const :tag "Use ecomplete" ecomplete)
1267 (const :tag "No expansion" nil)))
1269 (defcustom message-self-insert-commands '(self-insert-command)
1270 "List of `self-insert-command's used to trigger ecomplete.
1271 When one of those commands is invoked to enter a character in To or Cc
1272 header, ecomplete will suggest the candidates of recipients (see also
1273 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1274 text and it replaces `self-insert-command' with the other command, e.g.
1275 `egg-self-insert-command', you may want to add it to this list."
1276 :group 'message-various
1277 :type '(repeat function))
1279 (defcustom message-auto-save-directory
1280 (file-name-as-directory (expand-file-name "drafts" message-directory))
1281 "*Directory where Message auto-saves buffers if Gnus isn't running.
1282 If nil, Message won't auto-save."
1283 :group 'message-buffers
1284 :link '(custom-manual "(message)Various Message Variables")
1285 :type '(choice directory (const :tag "Don't auto-save" nil)))
1287 (defcustom message-default-charset
1288 (and (not (mm-multibyte-p)) 'iso-8859-1)
1289 "Default charset used in non-MULE Emacsen.
1290 If nil, you might be asked to input the charset."
1291 :version "21.1"
1292 :group 'message
1293 :link '(custom-manual "(message)Various Message Variables")
1294 :type 'symbol)
1296 (defcustom message-dont-reply-to-names
1297 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1298 "*Addresses to prune when doing wide replies.
1299 This can be a regexp or a list of regexps. Also, a value of nil means
1300 exclude your own user name only."
1301 :version "21.1"
1302 :group 'message
1303 :link '(custom-manual "(message)Wide Reply")
1304 :type '(choice (const :tag "Yourself" nil)
1305 regexp
1306 (repeat :tag "Regexp List" regexp)))
1308 (defsubst message-dont-reply-to-names ()
1309 (gmm-regexp-concat message-dont-reply-to-names))
1311 (defvar message-shoot-gnksa-feet nil
1312 "*A list of GNKSA feet you are allowed to shoot.
1313 Gnus gives you all the opportunity you could possibly want for
1314 shooting yourself in the foot. Also, Gnus allows you to shoot the
1315 feet of Good Net-Keeping Seal of Approval. The following are foot
1316 candidates:
1317 `empty-article' Allow you to post an empty article;
1318 `quoted-text-only' Allow you to post quoted text only;
1319 `multiple-copies' Allow you to post multiple copies;
1320 `cancel-messages' Allow you to cancel or supersede messages from
1321 your other email addresses.")
1323 (defsubst message-gnksa-enable-p (feature)
1324 (or (not (listp message-shoot-gnksa-feet))
1325 (memq feature message-shoot-gnksa-feet)))
1327 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1328 "^X-Draft-From:")
1329 "Regexp of headers to be hidden when composing new messages.
1330 This can also be a list of regexps to match headers. Or a list
1331 starting with `not' and followed by regexps."
1332 :version "22.1"
1333 :group 'message
1334 :link '(custom-manual "(message)Message Headers")
1335 :type '(choice
1336 :format "%{%t%}: %[Value Type%] %v"
1337 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1338 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1339 (regexp :format "%t: %v"))
1340 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1341 (const not)
1342 (repeat :format "%v%i"
1343 (regexp :format "%t: %v")))))
1345 (defcustom message-cite-articles-with-x-no-archive t
1346 "If non-nil, cite text from articles that has X-No-Archive set."
1347 :group 'message
1348 :type 'boolean)
1350 ;;; Internal variables.
1351 ;;; Well, not really internal.
1353 (defvar message-mode-syntax-table
1354 (let ((table (copy-syntax-table text-mode-syntax-table)))
1355 (modify-syntax-entry ?% ". " table)
1356 (modify-syntax-entry ?> ". " table)
1357 (modify-syntax-entry ?< ". " table)
1358 table)
1359 "Syntax table used while in Message mode.")
1361 (defface message-header-to
1362 '((((class color)
1363 (background dark))
1364 (:foreground "DarkOliveGreen1" :bold t))
1365 (((class color)
1366 (background light))
1367 (:foreground "MidnightBlue" :bold t))
1369 (:bold t :italic t)))
1370 "Face used for displaying From headers."
1371 :group 'message-faces)
1372 ;; backward-compatibility alias
1373 (put 'message-header-to-face 'face-alias 'message-header-to)
1374 (put 'message-header-to-face 'obsolete-face "22.1")
1376 (defface message-header-cc
1377 '((((class color)
1378 (background dark))
1379 (:foreground "chartreuse1" :bold t))
1380 (((class color)
1381 (background light))
1382 (:foreground "MidnightBlue"))
1384 (:bold t)))
1385 "Face used for displaying Cc headers."
1386 :group 'message-faces)
1387 ;; backward-compatibility alias
1388 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1389 (put 'message-header-cc-face 'obsolete-face "22.1")
1391 (defface message-header-subject
1392 '((((class color)
1393 (background dark))
1394 (:foreground "OliveDrab1"))
1395 (((class color)
1396 (background light))
1397 (:foreground "navy blue" :bold t))
1399 (:bold t)))
1400 "Face used for displaying subject headers."
1401 :group 'message-faces)
1402 ;; backward-compatibility alias
1403 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1404 (put 'message-header-subject-face 'obsolete-face "22.1")
1406 (defface message-header-newsgroups
1407 '((((class color)
1408 (background dark))
1409 (:foreground "yellow" :bold t :italic t))
1410 (((class color)
1411 (background light))
1412 (:foreground "blue4" :bold t :italic t))
1414 (:bold t :italic t)))
1415 "Face used for displaying newsgroups headers."
1416 :group 'message-faces)
1417 ;; backward-compatibility alias
1418 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1419 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1421 (defface message-header-other
1422 '((((class color)
1423 (background dark))
1424 (:foreground "VioletRed1"))
1425 (((class color)
1426 (background light))
1427 (:foreground "steel blue"))
1429 (:bold t :italic t)))
1430 "Face used for displaying newsgroups headers."
1431 :group 'message-faces)
1432 ;; backward-compatibility alias
1433 (put 'message-header-other-face 'face-alias 'message-header-other)
1434 (put 'message-header-other-face 'obsolete-face "22.1")
1436 (defface message-header-name
1437 '((((class color)
1438 (background dark))
1439 (:foreground "green"))
1440 (((class color)
1441 (background light))
1442 (:foreground "cornflower blue"))
1444 (:bold t)))
1445 "Face used for displaying header names."
1446 :group 'message-faces)
1447 ;; backward-compatibility alias
1448 (put 'message-header-name-face 'face-alias 'message-header-name)
1449 (put 'message-header-name-face 'obsolete-face "22.1")
1451 (defface message-header-xheader
1452 '((((class color)
1453 (background dark))
1454 (:foreground "DeepSkyBlue1"))
1455 (((class color)
1456 (background light))
1457 (:foreground "blue"))
1459 (:bold t)))
1460 "Face used for displaying X-Header headers."
1461 :group 'message-faces)
1462 ;; backward-compatibility alias
1463 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1464 (put 'message-header-xheader-face 'obsolete-face "22.1")
1466 (defface message-separator
1467 '((((class color)
1468 (background dark))
1469 (:foreground "LightSkyBlue1"))
1470 (((class color)
1471 (background light))
1472 (:foreground "brown"))
1474 (:bold t)))
1475 "Face used for displaying the separator."
1476 :group 'message-faces)
1477 ;; backward-compatibility alias
1478 (put 'message-separator-face 'face-alias 'message-separator)
1479 (put 'message-separator-face 'obsolete-face "22.1")
1481 (defface message-cited-text
1482 '((((class color)
1483 (background dark))
1484 (:foreground "LightPink1"))
1485 (((class color)
1486 (background light))
1487 (:foreground "red"))
1489 (:bold t)))
1490 "Face used for displaying cited text names."
1491 :group 'message-faces)
1492 ;; backward-compatibility alias
1493 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1494 (put 'message-cited-text-face 'obsolete-face "22.1")
1496 (defface message-mml
1497 '((((class color)
1498 (background dark))
1499 (:foreground "MediumSpringGreen"))
1500 (((class color)
1501 (background light))
1502 (:foreground "ForestGreen"))
1504 (:bold t)))
1505 "Face used for displaying MML."
1506 :group 'message-faces)
1507 ;; backward-compatibility alias
1508 (put 'message-mml-face 'face-alias 'message-mml)
1509 (put 'message-mml-face 'obsolete-face "22.1")
1511 (defun message-font-lock-make-header-matcher (regexp)
1512 (let ((form
1513 `(lambda (limit)
1514 (let ((start (point)))
1515 (save-restriction
1516 (widen)
1517 (goto-char (point-min))
1518 (if (re-search-forward
1519 (concat "^" (regexp-quote mail-header-separator) "$")
1520 nil t)
1521 (setq limit (min limit (match-beginning 0))))
1522 (goto-char start))
1523 (and (< start limit)
1524 (re-search-forward ,regexp limit t))))))
1525 (if (featurep 'bytecomp)
1526 (byte-compile form)
1527 form)))
1529 (defvar message-font-lock-keywords
1530 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1531 `((,(message-font-lock-make-header-matcher
1532 (concat "^\\([Tt]o:\\)" content))
1533 (1 'message-header-name)
1534 (2 'message-header-to nil t))
1535 (,(message-font-lock-make-header-matcher
1536 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1537 (1 'message-header-name)
1538 (2 'message-header-cc nil t))
1539 (,(message-font-lock-make-header-matcher
1540 (concat "^\\([Ss]ubject:\\)" content))
1541 (1 'message-header-name)
1542 (2 'message-header-subject nil t))
1543 (,(message-font-lock-make-header-matcher
1544 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1545 (1 'message-header-name)
1546 (2 'message-header-newsgroups nil t))
1547 (,(message-font-lock-make-header-matcher
1548 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1549 (1 'message-header-name)
1550 (2 'message-header-xheader))
1551 (,(message-font-lock-make-header-matcher
1552 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1553 (1 'message-header-name)
1554 (2 'message-header-other nil t))
1555 ,@(if (and mail-header-separator
1556 (not (equal mail-header-separator "")))
1557 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1558 1 'message-separator))
1559 nil)
1560 ((lambda (limit)
1561 (re-search-forward (concat "^\\("
1562 message-cite-prefix-regexp
1563 "\\).*")
1564 limit t))
1565 (0 'message-cited-text))
1566 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1567 (0 'message-mml))))
1568 "Additional expressions to highlight in Message mode.")
1571 ;; XEmacs does it like this. For Emacs, we have to set the
1572 ;; `font-lock-defaults' buffer-local variable.
1573 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1575 (defvar message-face-alist
1576 '((bold . message-bold-region)
1577 (underline . underline-region)
1578 (default . (lambda (b e)
1579 (message-unbold-region b e)
1580 (ununderline-region b e))))
1581 "Alist of mail and news faces for facemenu.
1582 The cdr of each entry is a function for applying the face to a region.")
1584 (defcustom message-send-hook nil
1585 "Hook run before sending messages.
1586 This hook is run quite early when sending."
1587 :group 'message-various
1588 :options '(ispell-message)
1589 :link '(custom-manual "(message)Various Message Variables")
1590 :type 'hook)
1592 (defcustom message-send-mail-hook nil
1593 "Hook run before sending mail messages.
1594 This hook is run very late -- just before the message is sent as
1595 mail."
1596 :group 'message-various
1597 :link '(custom-manual "(message)Various Message Variables")
1598 :type 'hook)
1600 (defcustom message-send-news-hook nil
1601 "Hook run before sending news messages.
1602 This hook is run very late -- just before the message is sent as
1603 news."
1604 :group 'message-various
1605 :link '(custom-manual "(message)Various Message Variables")
1606 :type 'hook)
1608 (defcustom message-sent-hook nil
1609 "Hook run after sending messages."
1610 :group 'message-various
1611 :type 'hook)
1613 (defvar message-send-coding-system 'binary
1614 "Coding system to encode outgoing mail.")
1616 (defvar message-draft-coding-system
1617 mm-auto-save-coding-system
1618 "*Coding system to compose mail.
1619 If you'd like to make it possible to share draft files between XEmacs
1620 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1621 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1623 (defcustom message-send-mail-partially-limit 1000000
1624 "The limitation of messages sent as message/partial.
1625 The lower bound of message size in characters, beyond which the message
1626 should be sent in several parts. If it is nil, the size is unlimited."
1627 :version "21.1"
1628 :group 'message-buffers
1629 :link '(custom-manual "(message)Mail Variables")
1630 :type '(choice (const :tag "unlimited" nil)
1631 (integer 1000000)))
1633 (defcustom message-alternative-emails nil
1634 "*Regexp matching alternative email addresses.
1635 The first address in the To, Cc or From headers of the original
1636 article matching this variable is used as the From field of
1637 outgoing messages.
1639 This variable has precedence over posting styles and anything that runs
1640 off `message-setup-hook'."
1641 :group 'message-headers
1642 :link '(custom-manual "(message)Message Headers")
1643 :type '(choice (const :tag "Always use primary" nil)
1644 regexp))
1646 (defcustom message-hierarchical-addresses nil
1647 "A list of hierarchical mail address definitions.
1649 Inside each entry, the first address is the \"top\" address, and
1650 subsequent addresses are subaddresses; this is used to indicate that
1651 mail sent to the first address will automatically be delivered to the
1652 subaddresses. So if the first address appears in the recipient list
1653 for a message, the subaddresses will be removed (if present) before
1654 the mail is sent. All addresses in this structure should be
1655 downcased."
1656 :version "22.1"
1657 :group 'message-headers
1658 :type '(repeat (repeat string)))
1660 (defcustom message-mail-user-agent nil
1661 "Like `mail-user-agent'.
1662 Except if it is nil, use Gnus native MUA; if it is t, use
1663 `mail-user-agent'."
1664 :version "22.1"
1665 :type '(radio (const :tag "Gnus native"
1666 :format "%t\n"
1667 nil)
1668 (const :tag "`mail-user-agent'"
1669 :format "%t\n"
1671 (function-item :tag "Default Emacs mail"
1672 :format "%t\n"
1673 sendmail-user-agent)
1674 (function-item :tag "Emacs interface to MH"
1675 :format "%t\n"
1676 mh-e-user-agent)
1677 (function :tag "Other"))
1678 :version "21.1"
1679 :group 'message)
1681 (defcustom message-wide-reply-confirm-recipients nil
1682 "Whether to confirm a wide reply to multiple email recipients.
1683 If this variable is nil, don't ask whether to reply to all recipients.
1684 If this variable is non-nil, pose the question \"Reply to all
1685 recipients?\" before a wide reply to multiple recipients. If the user
1686 answers yes, reply to all recipients as usual. If the user answers
1687 no, only reply back to the author."
1688 :version "22.1"
1689 :group 'message-headers
1690 :link '(custom-manual "(message)Wide Reply")
1691 :type 'boolean)
1693 (defcustom message-user-fqdn nil
1694 "*Domain part of Message-Ids."
1695 :version "22.1"
1696 :group 'message-headers
1697 :link '(custom-manual "(message)News Headers")
1698 :type '(radio (const :format "%v " nil)
1699 (string :format "FQDN: %v")))
1701 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1702 (file-error))
1703 (mm-coding-system-p 'utf-8)
1704 (executable-find idna-program)
1705 (string= (idna-to-ascii "räksmörgås")
1706 "xn--rksmrgs-5wao1o")
1708 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1709 GNU Libidn, and in particular the elisp package \"idna.el\" and
1710 the external program \"idn\", must be installed for this
1711 functionality to work."
1712 :version "22.1"
1713 :group 'message-headers
1714 :link '(custom-manual "(message)IDNA")
1715 :type '(choice (const :tag "Ask" ask)
1716 (const :tag "Never" nil)
1717 (const :tag "Always" t)))
1719 (defcustom message-generate-hashcash (if (executable-find "hashcash") t)
1720 "*Whether to generate X-Hashcash: headers.
1721 If t, always generate hashcash headers. If `opportunistic',
1722 only generate hashcash headers if it can be done without the user
1723 waiting (i.e., only asynchronously).
1725 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1726 :group 'message-headers
1727 :link '(custom-manual "(message)Mail Headers")
1728 :type '(choice (const :tag "Always" t)
1729 (const :tag "Never" nil)
1730 (const :tag "Opportunistic" opportunistic)))
1732 ;;; Internal variables.
1734 (defvar message-sending-message "Sending...")
1735 (defvar message-buffer-list nil)
1736 (defvar message-this-is-news nil)
1737 (defvar message-this-is-mail nil)
1738 (defvar message-draft-article nil)
1739 (defvar message-mime-part nil)
1740 (defvar message-posting-charset nil)
1741 (defvar message-inserted-headers nil)
1743 ;; Byte-compiler warning
1744 (defvar gnus-active-hashtb)
1745 (defvar gnus-read-active-file)
1747 ;;; Regexp matching the delimiter of messages in UNIX mail format
1748 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1749 ;;; of rmail.el's rmail-unix-mail-delimiter.
1750 (defvar message-unix-mail-delimiter
1751 (let ((time-zone-regexp
1752 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1753 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1754 "\\|"
1755 "\\) *")))
1756 (concat
1757 "From "
1759 ;; Many things can happen to an RFC 822 mailbox before it is put into
1760 ;; a `From' line. The leading phrase can be stripped, e.g.
1761 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1762 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1763 ;; can be removed, e.g.
1764 ;; From: joe@y.z (Joe K
1765 ;; User)
1766 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1767 ;; From: Joe User
1768 ;; <joe@y.z>
1769 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1770 ;; The mailbox can be removed or be replaced by white space, e.g.
1771 ;; From: "Joe User"{space}{tab}
1772 ;; <joe@y.z>
1773 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1774 ;; where {space} and {tab} represent the Ascii space and tab characters.
1775 ;; We want to match the results of any of these manglings.
1776 ;; The following regexp rejects names whose first characters are
1777 ;; obviously bogus, but after that anything goes.
1778 "\\([^\0-\b\n-\r\^?].*\\)?"
1780 ;; The time the message was sent.
1781 "\\([^\0-\r \^?]+\\) +" ; day of the week
1782 "\\([^\0-\r \^?]+\\) +" ; month
1783 "\\([0-3]?[0-9]\\) +" ; day of month
1784 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1786 ;; Perhaps a time zone, specified by an abbreviation, or by a
1787 ;; numeric offset.
1788 time-zone-regexp
1790 ;; The year.
1791 " \\([0-9][0-9]+\\) *"
1793 ;; On some systems the time zone can appear after the year, too.
1794 time-zone-regexp
1796 ;; Old uucp cruft.
1797 "\\(remote from .*\\)?"
1799 "\n"))
1800 "Regexp matching the delimiter of messages in UNIX mail format.")
1802 (defvar message-unsent-separator
1803 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1804 "^ *---+ +Returned message +---+ *$\\|"
1805 "^Start of returned message$\\|"
1806 "^ *---+ +Original message +---+ *$\\|"
1807 "^ *--+ +begin message +--+ *$\\|"
1808 "^ *---+ +Original message follows +---+ *$\\|"
1809 "^ *---+ +Undelivered message follows +---+ *$\\|"
1810 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1811 "^|? *---+ +Message text follows: +---+ *|?$")
1812 "A regexp that matches the separator before the text of a failed message.")
1814 (defvar message-field-fillers
1815 '((To message-fill-field-address)
1816 (Cc message-fill-field-address)
1817 (From message-fill-field-address))
1818 "Alist of header names/filler functions.")
1820 (defvar message-header-format-alist
1821 `((From)
1822 (Newsgroups)
1823 (To)
1824 (Cc)
1825 (Subject)
1826 (In-Reply-To)
1827 (Fcc)
1828 (Bcc)
1829 (Date)
1830 (Organization)
1831 (Distribution)
1832 (Lines)
1833 (Expires)
1834 (Message-ID)
1835 (References . message-shorten-references)
1836 (User-Agent))
1837 "Alist used for formatting headers.")
1839 (defvar message-options nil
1840 "Some saved answers when sending message.")
1842 (defvar message-send-mail-real-function nil
1843 "Internal send mail function.")
1845 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1846 "The regexp of bogus system names.")
1848 (defcustom message-valid-fqdn-regexp
1849 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1850 ;; valid TLDs:
1851 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1852 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1853 "cat\\|com\\|coop\\|edu\\|gov\\|"
1854 "info\\|int\\|jobs\\|"
1855 "mil\\|mobi\\|museum\\|name\\|net\\|"
1856 "org\\|pro\\|travel\\|uucp\\)")
1857 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1858 ;; http://en.wikipedia.org/wiki/GTLD
1859 ;; `in the process of being approved': .asia .post .tel .sex
1860 ;; "dead" nato bitnet uucp
1861 "Regular expression that matches a valid FQDN."
1862 ;; see also: gnus-button-valid-fqdn-regexp
1863 :version "22.1"
1864 :group 'message-headers
1865 :type 'regexp)
1867 (autoload 'gnus-alive-p "gnus-util")
1868 (autoload 'gnus-delay-article "gnus-delay")
1869 (autoload 'gnus-extract-address-components "gnus-util")
1870 (autoload 'gnus-find-method-for-group "gnus")
1871 (autoload 'gnus-group-decoded-name "gnus-group")
1872 (autoload 'gnus-group-name-charset "gnus-group")
1873 (autoload 'gnus-group-name-decode "gnus-group")
1874 (autoload 'gnus-groups-from-server "gnus")
1875 (autoload 'gnus-make-local-hook "gnus-util")
1876 (autoload 'gnus-open-server "gnus-int")
1877 (autoload 'gnus-output-to-mail "gnus-util")
1878 (autoload 'gnus-output-to-rmail "gnus-util")
1879 (autoload 'gnus-request-post "gnus-int")
1880 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1881 (autoload 'gnus-server-string "gnus")
1882 (autoload 'idna-to-ascii "idna")
1883 (autoload 'message-setup-toolbar "messagexmas")
1884 (autoload 'mh-new-draft-name "mh-comp")
1885 (autoload 'mh-send-letter "mh-comp")
1886 (autoload 'nndraft-request-associate-buffer "nndraft")
1887 (autoload 'nndraft-request-expire-articles "nndraft")
1888 (autoload 'nnvirtual-find-group-art "nnvirtual")
1889 (autoload 'rmail-dont-reply-to "mail-utils")
1890 (autoload 'rmail-msg-is-pruned "rmail")
1891 (autoload 'rmail-output "rmailout")
1896 ;;; Utility functions.
1899 (defmacro message-y-or-n-p (question show &rest text)
1900 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1901 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1903 (defmacro message-delete-line (&optional n)
1904 "Delete the current line (and the next N lines)."
1905 `(delete-region (progn (beginning-of-line) (point))
1906 (progn (forward-line ,(or n 1)) (point))))
1908 (defun message-mark-active-p ()
1909 "Non-nil means the mark and region are currently active in this buffer."
1910 mark-active)
1912 (defun message-unquote-tokens (elems)
1913 "Remove double quotes (\") from strings in list ELEMS."
1914 (mapcar (lambda (item)
1915 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1916 (setq item (concat (match-string 1 item)
1917 (match-string 2 item))))
1918 item)
1919 elems))
1921 (defun message-tokenize-header (header &optional separator)
1922 "Split HEADER into a list of header elements.
1923 SEPARATOR is a string of characters to be used as separators. \",\"
1924 is used by default."
1925 (if (not header)
1927 (let ((regexp (format "[%s]+" (or separator ",")))
1928 (first t)
1929 beg quoted elems paren)
1930 (with-temp-buffer
1931 (mm-enable-multibyte)
1932 (setq beg (point-min))
1933 (insert header)
1934 (goto-char (point-min))
1935 (while (not (eobp))
1936 (if first
1937 (setq first nil)
1938 (forward-char 1))
1939 (cond ((and (> (point) beg)
1940 (or (eobp)
1941 (and (looking-at regexp)
1942 (not quoted)
1943 (not paren))))
1944 (push (buffer-substring beg (point)) elems)
1945 (setq beg (match-end 0)))
1946 ((eq (char-after) ?\")
1947 (setq quoted (not quoted)))
1948 ((and (eq (char-after) ?\()
1949 (not quoted))
1950 (setq paren t))
1951 ((and (eq (char-after) ?\))
1952 (not quoted))
1953 (setq paren nil))))
1954 (nreverse elems)))))
1956 (autoload 'nnheader-insert-file-contents "nnheader")
1958 (defun message-mail-file-mbox-p (file)
1959 "Say whether FILE looks like a Unix mbox file."
1960 (when (and (file-exists-p file)
1961 (file-readable-p file)
1962 (file-regular-p file))
1963 (with-temp-buffer
1964 (nnheader-insert-file-contents file)
1965 (goto-char (point-min))
1966 (looking-at message-unix-mail-delimiter))))
1968 (defun message-fetch-field (header &optional not-all)
1969 "The same as `mail-fetch-field', only remove all newlines.
1970 The buffer is expected to be narrowed to just the header of the message;
1971 see `message-narrow-to-headers-or-head'."
1972 (let* ((inhibit-point-motion-hooks t)
1973 (value (mail-fetch-field header nil (not not-all))))
1974 (when value
1975 (while (string-match "\n[\t ]+" value)
1976 (setq value (replace-match " " t t value)))
1977 value)))
1979 (defun message-field-value (header &optional not-all)
1980 "The same as `message-fetch-field', only narrow to the headers first."
1981 (save-excursion
1982 (save-restriction
1983 (message-narrow-to-headers-or-head)
1984 (message-fetch-field header not-all))))
1986 (defun message-narrow-to-field ()
1987 "Narrow the buffer to the header on the current line."
1988 (beginning-of-line)
1989 (while (looking-at "[ \t]")
1990 (forward-line -1))
1991 (narrow-to-region
1992 (point)
1993 (progn
1994 (forward-line 1)
1995 (if (re-search-forward "^[^ \n\t]" nil t)
1996 (point-at-bol)
1997 (point-max))))
1998 (goto-char (point-min)))
2000 (defun message-add-header (&rest headers)
2001 "Add the HEADERS to the message header, skipping those already present."
2002 (while headers
2003 (let (hclean)
2004 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2005 (error "Invalid header `%s'" (car headers)))
2006 (setq hclean (match-string 1 (car headers)))
2007 (save-restriction
2008 (message-narrow-to-headers)
2009 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2010 (goto-char (point-max))
2011 (if (string-match "\n$" (car headers))
2012 (insert (car headers))
2013 (insert (car headers) ?\n)))))
2014 (setq headers (cdr headers))))
2016 (defmacro message-with-reply-buffer (&rest forms)
2017 "Evaluate FORMS in the reply buffer, if it exists."
2018 `(when (and (bufferp message-reply-buffer)
2019 (buffer-name message-reply-buffer))
2020 (with-current-buffer message-reply-buffer
2021 ,@forms)))
2023 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2024 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2026 (defun message-fetch-reply-field (header)
2027 "Fetch field HEADER from the message we're replying to."
2028 (message-with-reply-buffer
2029 (save-restriction
2030 (mail-narrow-to-head)
2031 (message-fetch-field header))))
2033 (defun message-strip-list-identifiers (subject)
2034 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2035 (require 'gnus-sum) ; for gnus-list-identifiers
2036 (let ((regexp (if (stringp gnus-list-identifiers)
2037 gnus-list-identifiers
2038 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2039 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2040 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2041 (concat (substring subject 0 (match-beginning 1))
2042 (or (match-string 3 subject)
2043 (match-string 5 subject))
2044 (substring subject
2045 (match-end 1)))
2046 subject)))
2048 (defun message-strip-subject-re (subject)
2049 "Remove \"Re:\" from subject lines in string SUBJECT."
2050 (if (string-match message-subject-re-regexp subject)
2051 (substring subject (match-end 0))
2052 subject))
2054 (defcustom message-replacement-char "."
2055 "Replacement character used instead of unprintable or not decodable chars."
2056 :group 'message-various
2057 :version "22.1" ;; Gnus 5.10.9
2058 :type '(choice string
2059 (const ".")
2060 (const "?")))
2062 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2063 ;; when forwarding. Probably in `message-make-forward-subject' and
2064 ;; `message-forward-make-body'.
2066 (defun message-strip-subject-encoded-words (subject)
2067 "Fix non-decodable words in SUBJECT."
2068 ;; Cf. `gnus-simplify-subject-fully'.
2069 (let* ((case-fold-search t)
2070 (replacement-chars (format "[%s%s%s]"
2071 message-replacement-char
2072 message-replacement-char
2073 message-replacement-char))
2074 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2075 cs-string
2076 (have-marker
2077 (with-temp-buffer
2078 (insert subject)
2079 (goto-char (point-min))
2080 (when (re-search-forward enc-word-re nil t)
2081 (setq cs-string (match-string 1)))))
2082 cs-coding q-or-b word-beg word-end)
2083 (if (or (not have-marker) ;; No encoded word found...
2084 ;; ... or double encoding was correct:
2085 (and (stringp cs-string)
2086 (setq cs-string (downcase cs-string))
2087 (mm-coding-system-p (intern cs-string))
2088 (not (prog1
2089 (y-or-n-p
2090 (format "\
2091 Decoded Subject \"%s\"
2092 contains a valid encoded word. Decode again? "
2093 subject))
2094 (setq cs-coding (intern cs-string))))))
2095 subject
2096 (with-temp-buffer
2097 (insert subject)
2098 (goto-char (point-min))
2099 (while (re-search-forward enc-word-re nil t)
2100 (setq cs-string (downcase (match-string 1))
2101 q-or-b (match-string 2)
2102 word-beg (match-beginning 0)
2103 word-end (match-end 0))
2104 (setq cs-coding
2105 (if (mm-coding-system-p (intern cs-string))
2106 (setq cs-coding (intern cs-string))
2107 nil))
2108 ;; No double encoded subject? => bogus charset.
2109 (unless cs-coding
2110 (setq cs-coding
2111 (mm-read-coding-system
2112 (format "\
2113 Decoded Subject \"%s\"
2114 contains an encoded word. The charset `%s' is unknown or invalid.
2115 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2116 charset: "
2117 subject cs-string message-replacement-char)))
2118 (if cs-coding
2119 (replace-match (concat "=?" (symbol-name cs-coding)
2120 "?\\2?\\3\\4\\5"))
2121 (save-excursion
2122 (goto-char word-beg)
2123 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2124 (replace-match "")
2125 ;; QP or base64
2126 (if (string-match "\\`Q\\'" q-or-b)
2127 ;; QP
2128 (progn
2129 (message "Replacing non-decodable characters with \"%s\"."
2130 message-replacement-char)
2131 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2132 word-end t)
2133 (replace-match message-replacement-char)))
2134 ;; base64
2135 (message "Replacing non-decodable characters with \"%s\"."
2136 replacement-chars)
2137 (re-search-forward "[^?]+" word-end t)
2138 (replace-match replacement-chars))
2139 (re-search-forward "\\?=")
2140 (replace-match "")))))
2141 (rfc2047-decode-region (point-min) (point-max))
2142 (buffer-string)))))
2144 ;;; Start of functions adopted from `message-utils.el'.
2146 (defun message-strip-subject-trailing-was (subject)
2147 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2148 Leading \"Re: \" is not stripped by this function. Use the function
2149 `message-strip-subject-re' for this."
2150 (let* ((query message-subject-trailing-was-query)
2151 (new) (found))
2152 (setq found
2153 (string-match
2154 (if (eq query 'ask)
2155 message-subject-trailing-was-ask-regexp
2156 message-subject-trailing-was-regexp)
2157 subject))
2158 (if found
2159 (setq new (substring subject 0 (match-beginning 0))))
2160 (if (or (not found) (eq query nil))
2161 subject
2162 (if (eq query 'ask)
2163 (if (message-y-or-n-p
2164 "Strip `(was: <old subject>)' in subject? " t
2165 (concat
2166 "Strip `(was: <old subject>)' in subject "
2167 "and use the new one instead?\n\n"
2168 "Current subject is: \""
2169 subject "\"\n\n"
2170 "New subject would be: \""
2171 new "\"\n\n"
2172 "See the variable `message-subject-trailing-was-query' "
2173 "to get rid of this query."
2175 new subject)
2176 new))))
2178 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2180 (defun message-change-subject (new-subject)
2181 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2182 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2183 (interactive
2184 (list
2185 (read-from-minibuffer "New subject: ")))
2186 (cond ((and (not (or (null new-subject) ; new subject not empty
2187 (zerop (string-width new-subject))
2188 (string-match "^[ \t]*$" new-subject))))
2189 (save-excursion
2190 (let ((old-subject
2191 (save-restriction
2192 (message-narrow-to-headers)
2193 (message-fetch-field "Subject"))))
2194 (cond ((not old-subject)
2195 (error "No current subject"))
2196 ((not (string-match
2197 (concat "^[ \t]*"
2198 (regexp-quote new-subject)
2199 " \t]*$")
2200 old-subject)) ; yes, it really is a new subject
2201 ;; delete eventual Re: prefix
2202 (setq old-subject
2203 (message-strip-subject-re old-subject))
2204 (message-goto-subject)
2205 (message-delete-line)
2206 (insert (concat "Subject: "
2207 new-subject
2208 " (was: "
2209 old-subject ")\n")))))))))
2211 (defun message-mark-inserted-region (beg end &optional verbatim)
2212 "Mark some region in the current article with enclosing tags.
2213 See `message-mark-insert-begin' and `message-mark-insert-end'.
2214 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2215 (interactive "r\nP")
2216 (save-excursion
2217 ;; add to the end of the region first, otherwise end would be invalid
2218 (goto-char end)
2219 (insert (if verbatim "#v-\n" message-mark-insert-end))
2220 (goto-char beg)
2221 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2223 (defun message-mark-insert-file (file &optional verbatim)
2224 "Insert FILE at point, marking it with enclosing tags.
2225 See `message-mark-insert-begin' and `message-mark-insert-end'.
2226 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2227 (interactive "fFile to insert: \nP")
2228 ;; reverse insertion to get correct result.
2229 (let ((p (point)))
2230 (insert (if verbatim "#v-\n" message-mark-insert-end))
2231 (goto-char p)
2232 (insert-file-contents file)
2233 (goto-char p)
2234 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2236 (defun message-add-archive-header ()
2237 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2238 The note can be customized using `message-archive-note'. When called with a
2239 prefix argument, ask for a text to insert. If you don't want the note in the
2240 body, set `message-archive-note' to nil."
2241 (interactive)
2242 (if current-prefix-arg
2243 (setq message-archive-note
2244 (read-from-minibuffer "Reason for No-Archive: "
2245 (cons message-archive-note 0))))
2246 (save-excursion
2247 (if (message-goto-signature)
2248 (re-search-backward message-signature-separator))
2249 (when message-archive-note
2250 (insert message-archive-note)
2251 (newline))
2252 (message-add-header message-archive-header)
2253 (message-sort-headers)))
2255 (defun message-cross-post-followup-to-header (target-group)
2256 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2257 With prefix-argument just set Follow-Up, don't cross-post."
2258 (interactive
2259 (list ; Completion based on Gnus
2260 (completing-read "Followup To: "
2261 (if (boundp 'gnus-newsrc-alist)
2262 gnus-newsrc-alist)
2263 nil nil '("poster" . 0)
2264 (if (boundp 'gnus-group-history)
2265 'gnus-group-history))))
2266 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2267 (message-goto-newsgroups)
2268 (beginning-of-line)
2269 ;; if we already did a crosspost before, kill old target
2270 (if (and message-cross-post-old-target
2271 (re-search-forward
2272 (regexp-quote (concat "," message-cross-post-old-target))
2273 nil t))
2274 (replace-match ""))
2275 ;; unless (followup is to poster or user explicitly asked not
2276 ;; to cross-post, or target-group is already in Newsgroups)
2277 ;; add target-group to Newsgroups line.
2278 (cond ((and (or
2279 ;; def: cross-post, req:no
2280 (and message-cross-post-default (not current-prefix-arg))
2281 ;; def: no-cross-post, req:yes
2282 (and (not message-cross-post-default) current-prefix-arg))
2283 (not (string-match "poster" target-group))
2284 (not (string-match (regexp-quote target-group)
2285 (message-fetch-field "Newsgroups"))))
2286 (end-of-line)
2287 (insert (concat "," target-group))))
2288 (end-of-line) ; ensure Followup: comes after Newsgroups:
2289 ;; unless new followup would be identical to Newsgroups line
2290 ;; make a new Followup-To line
2291 (if (not (string-match (concat "^[ \t]*"
2292 target-group
2293 "[ \t]*$")
2294 (message-fetch-field "Newsgroups")))
2295 (insert (concat "\nFollowup-To: " target-group)))
2296 (setq message-cross-post-old-target target-group))
2298 (defun message-cross-post-insert-note (target-group cross-post in-old
2299 old-groups)
2300 "Insert a in message body note about a set Followup or Crosspost.
2301 If there have been previous notes, delete them. TARGET-GROUP specifies the
2302 group to Followup-To. When CROSS-POST is t, insert note about
2303 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2304 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2305 been made to before the user asked for a Crosspost."
2306 ;; start scanning body for previous uses
2307 (message-goto-signature)
2308 (let ((head (re-search-backward
2309 (concat "^" mail-header-separator)
2310 nil t))) ; just search in body
2311 (message-goto-signature)
2312 (while (re-search-backward
2313 (concat "^" (regexp-quote message-cross-post-note) ".*")
2314 head t)
2315 (message-delete-line))
2316 (message-goto-signature)
2317 (while (re-search-backward
2318 (concat "^" (regexp-quote message-followup-to-note) ".*")
2319 head t)
2320 (message-delete-line))
2321 ;; insert new note
2322 (if (message-goto-signature)
2323 (re-search-backward message-signature-separator))
2324 (if (or in-old
2325 (not cross-post)
2326 (string-match "^[ \t]*poster[ \t]*$" target-group))
2327 (insert (concat message-followup-to-note target-group "\n"))
2328 (insert (concat message-cross-post-note target-group "\n")))))
2330 (defun message-cross-post-followup-to (target-group)
2331 "Crossposts message and set Followup-To to TARGET-GROUP.
2332 With prefix-argument just set Follow-Up, don't cross-post."
2333 (interactive
2334 (list ; Completion based on Gnus
2335 (completing-read "Followup To: "
2336 (if (boundp 'gnus-newsrc-alist)
2337 gnus-newsrc-alist)
2338 nil nil '("poster" . 0)
2339 (if (boundp 'gnus-group-history)
2340 'gnus-group-history))))
2341 (cond ((not (or (null target-group) ; new subject not empty
2342 (zerop (string-width target-group))
2343 (string-match "^[ \t]*$" target-group)))
2344 (save-excursion
2345 (let* ((old-groups (message-fetch-field "Newsgroups"))
2346 (in-old (string-match
2347 (regexp-quote target-group)
2348 (or old-groups ""))))
2349 ;; check whether target exactly matches old Newsgroups
2350 (cond ((not old-groups)
2351 (error "No current newsgroup"))
2352 ((or (not in-old)
2353 (not (string-match
2354 (concat "^[ \t]*"
2355 (regexp-quote target-group)
2356 "[ \t]*$")
2357 old-groups)))
2358 ;; yes, Newsgroups line must change
2359 (message-cross-post-followup-to-header target-group)
2360 ;; insert note whether we do cross-post or followup-to
2361 (funcall message-cross-post-note-function
2362 target-group
2363 (if (or (and message-cross-post-default
2364 (not current-prefix-arg))
2365 (and (not message-cross-post-default)
2366 current-prefix-arg)) t)
2367 in-old old-groups))))))))
2369 ;;; Reduce To: to Cc: or Bcc: header
2371 (defun message-reduce-to-to-cc ()
2372 "Replace contents of To: header with contents of Cc: or Bcc: header."
2373 (interactive)
2374 (let ((cc-content
2375 (save-restriction (message-narrow-to-headers)
2376 (message-fetch-field "cc")))
2377 (bcc nil))
2378 (if (and (not cc-content)
2379 (setq cc-content
2380 (save-restriction
2381 (message-narrow-to-headers)
2382 (message-fetch-field "bcc"))))
2383 (setq bcc t))
2384 (cond (cc-content
2385 (save-excursion
2386 (message-goto-to)
2387 (message-delete-line)
2388 (insert (concat "To: " cc-content "\n"))
2389 (save-restriction
2390 (message-narrow-to-headers)
2391 (message-remove-header (if bcc
2392 "bcc"
2393 "cc"))))))))
2395 ;;; End of functions adopted from `message-utils.el'.
2397 (defun message-remove-header (header &optional is-regexp first reverse)
2398 "Remove HEADER in the narrowed buffer.
2399 If IS-REGEXP, HEADER is a regular expression.
2400 If FIRST, only remove the first instance of the header.
2401 Return the number of headers removed."
2402 (goto-char (point-min))
2403 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2404 (number 0)
2405 (case-fold-search t)
2406 last)
2407 (while (and (not (eobp))
2408 (not last))
2409 (if (if reverse
2410 (not (looking-at regexp))
2411 (looking-at regexp))
2412 (progn
2413 (incf number)
2414 (when first
2415 (setq last t))
2416 (delete-region
2417 (point)
2418 ;; There might be a continuation header, so we have to search
2419 ;; until we find a new non-continuation line.
2420 (progn
2421 (forward-line 1)
2422 (if (re-search-forward "^[^ \t]" nil t)
2423 (goto-char (match-beginning 0))
2424 (point-max)))))
2425 (forward-line 1)
2426 (if (re-search-forward "^[^ \t]" nil t)
2427 (goto-char (match-beginning 0))
2428 (goto-char (point-max)))))
2429 number))
2431 (defun message-remove-first-header (header)
2432 "Remove the first instance of HEADER if there is more than one."
2433 (let ((count 0)
2434 (regexp (concat "^" (regexp-quote header) ":")))
2435 (save-excursion
2436 (goto-char (point-min))
2437 (while (re-search-forward regexp nil t)
2438 (incf count)))
2439 (while (> count 1)
2440 (message-remove-header header nil t)
2441 (decf count))))
2443 (defun message-narrow-to-headers ()
2444 "Narrow the buffer to the head of the message."
2445 (widen)
2446 (narrow-to-region
2447 (goto-char (point-min))
2448 (if (re-search-forward
2449 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2450 (match-beginning 0)
2451 (point-max)))
2452 (goto-char (point-min)))
2454 (defun message-narrow-to-head-1 ()
2455 "Like `message-narrow-to-head'. Don't widen."
2456 (narrow-to-region
2457 (goto-char (point-min))
2458 (if (search-forward "\n\n" nil 1)
2459 (1- (point))
2460 (point-max)))
2461 (goto-char (point-min)))
2463 ;; FIXME: clarify diffference: message-narrow-to-head,
2464 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2465 (defun message-narrow-to-head ()
2466 "Narrow the buffer to the head of the message.
2467 Point is left at the beginning of the narrowed-to region."
2468 (widen)
2469 (message-narrow-to-head-1))
2471 (defun message-narrow-to-headers-or-head ()
2472 "Narrow the buffer to the head of the message."
2473 (widen)
2474 (narrow-to-region
2475 (goto-char (point-min))
2476 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2477 (regexp-quote mail-header-separator)
2478 "\n\\)")
2479 nil t)
2480 (or (match-end 1) (match-beginning 2))
2481 (point-max)))
2482 (goto-char (point-min)))
2484 (defun message-news-p ()
2485 "Say whether the current buffer contains a news message."
2486 (and (not message-this-is-mail)
2487 (or message-this-is-news
2488 (save-excursion
2489 (save-restriction
2490 (message-narrow-to-headers)
2491 (and (message-fetch-field "newsgroups")
2492 (not (message-fetch-field "posted-to"))))))))
2494 (defun message-mail-p ()
2495 "Say whether the current buffer contains a mail message."
2496 (and (not message-this-is-news)
2497 (or message-this-is-mail
2498 (save-excursion
2499 (save-restriction
2500 (message-narrow-to-headers)
2501 (or (message-fetch-field "to")
2502 (message-fetch-field "cc")
2503 (message-fetch-field "bcc")))))))
2505 (defun message-subscribed-p ()
2506 "Say whether we need to insert a MFT header."
2507 (or message-subscribed-regexps
2508 message-subscribed-addresses
2509 message-subscribed-address-file
2510 message-subscribed-address-functions))
2512 (defun message-next-header ()
2513 "Go to the beginning of the next header."
2514 (beginning-of-line)
2515 (or (eobp) (forward-char 1))
2516 (not (if (re-search-forward "^[^ \t]" nil t)
2517 (beginning-of-line)
2518 (goto-char (point-max)))))
2520 (defun message-sort-headers-1 ()
2521 "Sort the buffer as headers using `message-rank' text props."
2522 (goto-char (point-min))
2523 (require 'sort)
2524 (sort-subr
2525 nil 'message-next-header
2526 (lambda ()
2527 (message-next-header)
2528 (unless (bobp)
2529 (forward-char -1)))
2530 (lambda ()
2531 (or (get-text-property (point) 'message-rank)
2532 10000))))
2534 (defun message-sort-headers ()
2535 "Sort the headers of the current message according to `message-header-format-alist'."
2536 (interactive)
2537 (save-excursion
2538 (save-restriction
2539 (let ((max (1+ (length message-header-format-alist)))
2540 rank)
2541 (message-narrow-to-headers)
2542 (while (re-search-forward "^[^ \n]+:" nil t)
2543 (put-text-property
2544 (match-beginning 0) (1+ (match-beginning 0))
2545 'message-rank
2546 (if (setq rank (length (memq (assq (intern (buffer-substring
2547 (match-beginning 0)
2548 (1- (match-end 0))))
2549 message-header-format-alist)
2550 message-header-format-alist)))
2551 (- max rank)
2552 (1+ max)))))
2553 (message-sort-headers-1))))
2555 (defun message-kill-address ()
2556 "Kill the address under point."
2557 (interactive)
2558 (let ((start (point)))
2559 (message-skip-to-next-address)
2560 (kill-region start (point))))
2563 (autoload 'Info-goto-node "info")
2564 (defvar mml2015-use)
2566 (defun message-info (&optional arg)
2567 "Display the Message manual.
2569 Prefixed with one \\[universal-argument], display the Emacs MIME
2570 manual. With two \\[universal-argument]'s, display the EasyPG or
2571 PGG manual, depending on the value of `mml2015-use'."
2572 (interactive "p")
2573 ;; Don't use `info' because support for `(filename)nodename' is not
2574 ;; available in XEmacs < 21.5.12.
2575 (Info-goto-node (format "(%s)Top"
2576 (cond ((eq arg 16)
2577 (require 'mml2015)
2578 mml2015-use)
2579 ((eq arg 4) 'emacs-mime)
2580 ;; `booleanp' only available in Emacs 22+
2581 ((and (not (memq arg '(nil t)))
2582 (symbolp arg))
2583 arg)
2585 'message)))))
2590 ;;; Message mode
2593 ;;; Set up keymap.
2595 (defvar message-mode-map nil)
2597 (unless message-mode-map
2598 (setq message-mode-map (make-keymap))
2599 (set-keymap-parent message-mode-map text-mode-map)
2600 (define-key message-mode-map "\C-c?" 'describe-mode)
2602 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2603 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2604 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2605 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2606 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2607 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2608 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2609 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2610 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2611 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2612 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2613 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2614 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2615 (define-key message-mode-map "\C-c\C-f\C-i"
2616 'message-insert-or-toggle-importance)
2617 (define-key message-mode-map "\C-c\C-f\C-a"
2618 'message-generate-unsubscribed-mail-followup-to)
2620 ;; modify headers (and insert notes in body)
2621 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2623 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2624 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2625 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2626 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2627 ;; mark inserted text
2628 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2629 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2631 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2632 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2634 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2635 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2636 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2637 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2638 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2640 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2641 (define-key message-mode-map "\C-c\M-n"
2642 'message-insert-disposition-notification-to)
2644 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2645 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2646 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2647 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2648 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2649 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2650 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2651 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2653 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2654 (define-key message-mode-map "\C-c\C-s" 'message-send)
2655 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2656 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2657 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2659 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2660 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2661 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2662 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2663 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2664 (define-key message-mode-map [remap split-line] 'message-split-line)
2666 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2668 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2669 (define-key message-mode-map "\t" 'message-tab)
2670 (define-key message-mode-map "\M-;" 'comment-region)
2672 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2674 (easy-menu-define
2675 message-mode-menu message-mode-map "Message Menu."
2676 `("Message"
2677 ["Yank Original" message-yank-original message-reply-buffer]
2678 ["Fill Yanked Message" message-fill-yanked-message t]
2679 ["Insert Signature" message-insert-signature t]
2680 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2681 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2682 ["Elide Region" message-elide-region
2683 :active (message-mark-active-p)
2684 ,@(if (featurep 'xemacs) nil
2685 '(:help "Replace text in region with an ellipsis"))]
2686 ["Delete Outside Region" message-delete-not-region
2687 :active (message-mark-active-p)
2688 ,@(if (featurep 'xemacs) nil
2689 '(:help "Delete all quoted text outside region"))]
2690 ["Kill To Signature" message-kill-to-signature t]
2691 ["Newline and Reformat" message-newline-and-reformat t]
2692 ["Rename buffer" message-rename-buffer t]
2693 ["Spellcheck" ispell-message
2694 ,@(if (featurep 'xemacs) '(t)
2695 '(:help "Spellcheck this message"))]
2696 "----"
2697 ["Insert Region Marked" message-mark-inserted-region
2698 :active (message-mark-active-p)
2699 ,@(if (featurep 'xemacs) nil
2700 '(:help "Mark region with enclosing tags"))]
2701 ["Insert File Marked..." message-mark-insert-file
2702 ,@(if (featurep 'xemacs) '(t)
2703 '(:help "Insert file at point marked with enclosing tags"))]
2704 "----"
2705 ["Send Message" message-send-and-exit
2706 ,@(if (featurep 'xemacs) '(t)
2707 '(:help "Send this message"))]
2708 ["Postpone Message" message-dont-send
2709 ,@(if (featurep 'xemacs) '(t)
2710 '(:help "File this draft message and exit"))]
2711 ["Send at Specific Time..." gnus-delay-article
2712 ,@(if (featurep 'xemacs) '(t)
2713 '(:help "Ask, then arrange to send message at that time"))]
2714 ["Kill Message" message-kill-buffer
2715 ,@(if (featurep 'xemacs) '(t)
2716 '(:help "Delete this message without sending"))]
2717 "----"
2718 ["Message manual" message-info
2719 ,@(if (featurep 'xemacs) '(t)
2720 '(:help "Display the Message manual"))]))
2722 (easy-menu-define
2723 message-mode-field-menu message-mode-map ""
2724 `("Field"
2725 ["To" message-goto-to t]
2726 ["From" message-goto-from t]
2727 ["Subject" message-goto-subject t]
2728 ["Change subject..." message-change-subject t]
2729 ["Cc" message-goto-cc t]
2730 ["Bcc" message-goto-bcc t]
2731 ["Fcc" message-goto-fcc t]
2732 ["Reply-To" message-goto-reply-to t]
2733 ["Flag As Important" message-insert-importance-high
2734 ,@(if (featurep 'xemacs) '(t)
2735 '(:help "Mark this message as important"))]
2736 ["Flag As Unimportant" message-insert-importance-low
2737 ,@(if (featurep 'xemacs) '(t)
2738 '(:help "Mark this message as unimportant"))]
2739 ["Request Receipt"
2740 message-insert-disposition-notification-to
2741 ,@(if (featurep 'xemacs) '(t)
2742 '(:help "Request a receipt notification"))]
2743 "----"
2744 ;; (typical) news stuff
2745 ["Summary" message-goto-summary t]
2746 ["Keywords" message-goto-keywords t]
2747 ["Newsgroups" message-goto-newsgroups t]
2748 ["Fetch Newsgroups" message-insert-newsgroups t]
2749 ["Followup-To" message-goto-followup-to t]
2750 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2751 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2752 ["Distribution" message-goto-distribution t]
2753 ["Expires" message-insert-expires t ]
2754 ["X-No-Archive" message-add-archive-header t ]
2755 "----"
2756 ;; (typical) mailing-lists stuff
2757 ["Fetch To" message-insert-to
2758 ,@(if (featurep 'xemacs) '(t)
2759 '(:help "Insert a To header that points to the author."))]
2760 ["Fetch To and Cc" message-insert-wide-reply
2761 ,@(if (featurep 'xemacs) '(t)
2762 '(:help
2763 "Insert To and Cc headers as if you were doing a wide reply."))]
2764 "----"
2765 ["Send to list only" message-to-list-only t]
2766 ["Mail-Followup-To" message-goto-mail-followup-to t]
2767 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2768 ,@(if (featurep 'xemacs) '(t)
2769 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2770 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2771 "----"
2772 ["Sort Headers" message-sort-headers t]
2773 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2774 ;; We hide `message-hidden-headers' by narrowing the buffer.
2775 ["Show Hidden Headers" widen t]
2776 ["Goto Body" message-goto-body t]
2777 ["Goto Signature" message-goto-signature t]))
2779 (defvar message-tool-bar-map nil)
2781 (defvar facemenu-add-face-function)
2782 (defvar facemenu-remove-face-function)
2784 ;;; Forbidden properties
2786 ;; We use `after-change-functions' to keep special text properties
2787 ;; that interfere with the normal function of message mode out of the
2788 ;; buffer.
2790 (defcustom message-strip-special-text-properties t
2791 "Strip special properties from the message buffer.
2793 Emacs has a number of special text properties which can break message
2794 composing in various ways. If this option is set, message will strip
2795 these properties from the message composition buffer. However, some
2796 packages requires these properties to be present in order to work.
2797 If you use one of these packages, turn this option off, and hope the
2798 message composition doesn't break too bad."
2799 :version "22.1"
2800 :group 'message-various
2801 :link '(custom-manual "(message)Various Message Variables")
2802 :type 'boolean)
2804 (defconst message-forbidden-properties
2805 ;; No reason this should be clutter up customize. We make it a
2806 ;; property list (rather than a list of property symbols), to be
2807 ;; directly useful for `remove-text-properties'.
2808 '(field nil read-only nil invisible nil intangible nil
2809 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2810 insert-behind-hooks nil point-entered nil point-left nil)
2811 ;; Other special properties:
2812 ;; category, face, display: probably doesn't do any harm.
2813 ;; fontified: is used by font-lock.
2814 ;; syntax-table, local-map: I dunno.
2815 ;; We need to add XEmacs names to the list.
2816 "Property list of with properties forbidden in message buffers.
2817 The values of the properties are ignored, only the property names are used.")
2819 (defun message-tamago-not-in-use-p (pos)
2820 "Return t when tamago version 4 is not in use at the cursor position.
2821 Tamago version 4 is a popular input method for writing Japanese text.
2822 It uses the properties `intangible', `invisible', `modification-hooks'
2823 and `read-only' when translating ascii or kana text to kanji text.
2824 These properties are essential to work, so we should never strip them."
2825 (not (and (boundp 'egg-modefull-mode)
2826 (symbol-value 'egg-modefull-mode)
2827 (or (memq (get-text-property pos 'intangible)
2828 '(its-part-1 its-part-2))
2829 (get-text-property pos 'egg-end)
2830 (get-text-property pos 'egg-lang)
2831 (get-text-property pos 'egg-start)))))
2833 (defsubst message-mail-alias-type-p (type)
2834 (if (atom message-mail-alias-type)
2835 (eq message-mail-alias-type type)
2836 (memq type message-mail-alias-type)))
2838 (defun message-strip-forbidden-properties (begin end &optional old-length)
2839 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2840 This function is intended to be called from `after-change-functions'.
2841 See also `message-forbidden-properties'."
2842 (when (and (message-mail-alias-type-p 'ecomplete)
2843 (memq this-command message-self-insert-commands))
2844 (message-display-abbrev))
2845 (when (and message-strip-special-text-properties
2846 (message-tamago-not-in-use-p begin))
2847 (let ((buffer-read-only nil)
2848 (inhibit-read-only t))
2849 (remove-text-properties begin end message-forbidden-properties))))
2851 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2853 ;;;###autoload
2854 (define-derived-mode message-mode text-mode "Message"
2855 "Major mode for editing mail and news to be sent.
2856 Like Text Mode but with these additional commands:\\<message-mode-map>
2857 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2858 C-c C-d Postpone sending the message C-c C-k Kill the message
2859 C-c C-f move to a header field (and create it if there isn't):
2860 C-c C-f C-t move to To C-c C-f C-s move to Subject
2861 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2862 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2863 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2864 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2865 C-c C-f C-o move to From (\"Originator\")
2866 C-c C-f C-f move to Followup-To
2867 C-c C-f C-m move to Mail-Followup-To
2868 C-c C-f C-e move to Expires
2869 C-c C-f C-i cycle through Importance values
2870 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2871 C-c C-f x crossposting with FollowUp-To header and note in body
2872 C-c C-f t replace To: header with contents of Cc: or Bcc:
2873 C-c C-f a Insert X-No-Archive: header and a note in the body
2874 C-c C-t `message-insert-to' (add a To header to a news followup)
2875 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2876 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2877 C-c C-b `message-goto-body' (move to beginning of message text).
2878 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2879 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2880 C-c C-y `message-yank-original' (insert current message, if any).
2881 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2882 C-c C-e `message-elide-region' (elide the text between point and mark).
2883 C-c C-v `message-delete-not-region' (remove the text outside the region).
2884 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2885 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2886 C-c C-a `mml-attach-file' (attach a file as MIME).
2887 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2888 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2889 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2890 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2891 M-RET `message-newline-and-reformat' (break the line and reformat)."
2892 (setq local-abbrev-table text-mode-abbrev-table)
2893 (set (make-local-variable 'message-reply-buffer) nil)
2894 (set (make-local-variable 'message-inserted-headers) nil)
2895 (set (make-local-variable 'message-send-actions) nil)
2896 (set (make-local-variable 'message-exit-actions) nil)
2897 (set (make-local-variable 'message-kill-actions) nil)
2898 (set (make-local-variable 'message-postpone-actions) nil)
2899 (set (make-local-variable 'message-draft-article) nil)
2900 (setq buffer-offer-save t)
2901 (set (make-local-variable 'facemenu-add-face-function)
2902 (lambda (face end)
2903 (let ((face-fun (cdr (assq face message-face-alist))))
2904 (if face-fun
2905 (funcall face-fun (point) end)
2906 (error "Face %s not configured for %s mode" face mode-name)))
2907 ""))
2908 (set (make-local-variable 'facemenu-remove-face-function) t)
2909 (set (make-local-variable 'message-reply-headers) nil)
2910 (make-local-variable 'message-newsreader)
2911 (make-local-variable 'message-mailer)
2912 (make-local-variable 'message-post-method)
2913 (set (make-local-variable 'message-sent-message-via) nil)
2914 (set (make-local-variable 'message-checksum) nil)
2915 (set (make-local-variable 'message-mime-part) 0)
2916 (message-setup-fill-variables)
2917 (when message-fill-column
2918 (setq fill-column message-fill-column)
2919 (turn-on-auto-fill))
2920 ;; Allow using comment commands to add/remove quoting.
2921 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2922 (when message-yank-prefix
2923 (set (make-local-variable 'comment-start) message-yank-prefix)
2924 (set (make-local-variable 'comment-start-skip)
2925 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2926 (if (featurep 'xemacs)
2927 (message-setup-toolbar)
2928 (set (make-local-variable 'font-lock-defaults)
2929 '(message-font-lock-keywords t))
2930 (if (boundp 'tool-bar-map)
2931 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2932 (easy-menu-add message-mode-menu message-mode-map)
2933 (easy-menu-add message-mode-field-menu message-mode-map)
2934 (gnus-make-local-hook 'after-change-functions)
2935 ;; Mmmm... Forbidden properties...
2936 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2937 nil 'local)
2938 ;; Allow mail alias things.
2939 (cond
2940 ((message-mail-alias-type-p 'abbrev)
2941 (if (fboundp 'mail-abbrevs-setup)
2942 (mail-abbrevs-setup)
2943 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2944 (mail-aliases-setup))))
2945 ((message-mail-alias-type-p 'ecomplete)
2946 (ecomplete-setup)))
2947 (unless buffer-file-name
2948 (message-set-auto-save-file-name))
2949 (unless (buffer-base-buffer)
2950 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2951 ;; multibyte is not necessary at all. -- zsh
2952 (mm-enable-multibyte))
2953 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2954 (mml-mode))
2956 (defun message-setup-fill-variables ()
2957 "Setup message fill variables."
2958 (set (make-local-variable 'fill-paragraph-function)
2959 'message-fill-paragraph)
2960 (make-local-variable 'paragraph-separate)
2961 (make-local-variable 'paragraph-start)
2962 (make-local-variable 'adaptive-fill-regexp)
2963 (unless (boundp 'adaptive-fill-first-line-regexp)
2964 (setq adaptive-fill-first-line-regexp nil))
2965 (make-local-variable 'adaptive-fill-first-line-regexp)
2966 (let ((quote-prefix-regexp
2967 ;; User should change message-cite-prefix-regexp if
2968 ;; message-yank-prefix is set to an abnormal value.
2969 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2970 (setq paragraph-start
2971 (concat
2972 (regexp-quote mail-header-separator) "$\\|"
2973 "[ \t]*$\\|" ; blank lines
2974 "-- $\\|" ; signature delimiter
2975 "---+$\\|" ; delimiters for forwarded messages
2976 page-delimiter "$\\|" ; spoiler warnings
2977 ".*wrote:$\\|" ; attribution lines
2978 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2979 ; mml tags
2980 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2981 (setq paragraph-separate paragraph-start)
2982 (setq adaptive-fill-regexp
2983 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2984 (setq adaptive-fill-first-line-regexp
2985 (concat quote-prefix-regexp "\\|"
2986 adaptive-fill-first-line-regexp)))
2987 (make-local-variable 'auto-fill-inhibit-regexp)
2988 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2989 (setq auto-fill-inhibit-regexp nil)
2990 (make-local-variable 'normal-auto-fill-function)
2991 (setq normal-auto-fill-function 'message-do-auto-fill)
2992 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2993 ;; In that case, ensure that it uses the right function. The real
2994 ;; solution would be not to use `define-derived-mode', and run
2995 ;; `text-mode-hook' ourself at the end of the mode.
2996 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2997 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2998 ;; now careful to run parent hooks after the body. --Stef
2999 (when auto-fill-function
3000 (setq auto-fill-function normal-auto-fill-function)))
3005 ;;; Message mode commands
3008 ;;; Movement commands
3010 (defun message-goto-to ()
3011 "Move point to the To header."
3012 (interactive)
3013 (message-position-on-field "To"))
3015 (defun message-goto-from ()
3016 "Move point to the From header."
3017 (interactive)
3018 (message-position-on-field "From"))
3020 (defun message-goto-subject ()
3021 "Move point to the Subject header."
3022 (interactive)
3023 (message-position-on-field "Subject"))
3025 (defun message-goto-cc ()
3026 "Move point to the Cc header."
3027 (interactive)
3028 (message-position-on-field "Cc" "To"))
3030 (defun message-goto-bcc ()
3031 "Move point to the Bcc header."
3032 (interactive)
3033 (message-position-on-field "Bcc" "Cc" "To"))
3035 (defun message-goto-fcc ()
3036 "Move point to the Fcc header."
3037 (interactive)
3038 (message-position-on-field "Fcc" "To" "Newsgroups"))
3040 (defun message-goto-reply-to ()
3041 "Move point to the Reply-To header."
3042 (interactive)
3043 (message-position-on-field "Reply-To" "Subject"))
3045 (defun message-goto-newsgroups ()
3046 "Move point to the Newsgroups header."
3047 (interactive)
3048 (message-position-on-field "Newsgroups"))
3050 (defun message-goto-distribution ()
3051 "Move point to the Distribution header."
3052 (interactive)
3053 (message-position-on-field "Distribution"))
3055 (defun message-goto-followup-to ()
3056 "Move point to the Followup-To header."
3057 (interactive)
3058 (message-position-on-field "Followup-To" "Newsgroups"))
3060 (defun message-goto-mail-followup-to ()
3061 "Move point to the Mail-Followup-To header."
3062 (interactive)
3063 (message-position-on-field "Mail-Followup-To" "To"))
3065 (defun message-goto-keywords ()
3066 "Move point to the Keywords header."
3067 (interactive)
3068 (message-position-on-field "Keywords" "Subject"))
3070 (defun message-goto-summary ()
3071 "Move point to the Summary header."
3072 (interactive)
3073 (message-position-on-field "Summary" "Subject"))
3075 (defun message-goto-body (&optional interactivep)
3076 "Move point to the beginning of the message body."
3077 (interactive (list t))
3078 (when (and interactivep
3079 (looking-at "[ \t]*\n"))
3080 (expand-abbrev))
3081 (goto-char (point-min))
3082 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3083 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3085 (defun message-in-body-p ()
3086 "Return t if point is in the message body."
3087 (let ((body (save-excursion (message-goto-body) (point))))
3088 (>= (point) body)))
3090 (defun message-goto-eoh ()
3091 "Move point to the end of the headers."
3092 (interactive)
3093 (message-goto-body)
3094 (forward-line -1))
3096 (defun message-goto-signature ()
3097 "Move point to the beginning of the message signature.
3098 If there is no signature in the article, go to the end and
3099 return nil."
3100 (interactive)
3101 (goto-char (point-min))
3102 (if (re-search-forward message-signature-separator nil t)
3103 (forward-line 1)
3104 (goto-char (point-max))
3105 nil))
3107 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3108 "Insert a reasonable MFT header in a post to an unsubscribed list.
3109 When making original posts to a mailing list you are not subscribed to,
3110 you have to type in a MFT header by hand. The contents, usually, are
3111 the addresses of the list and your own address. This function inserts
3112 such a header automatically. It fetches the contents of the To: header
3113 in the current mail buffer, and appends the current `user-mail-address'.
3115 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3116 Cc: header are also put into the MFT."
3118 (interactive "P")
3119 (let* (cc tos)
3120 (save-restriction
3121 (message-narrow-to-headers)
3122 (message-remove-header "Mail-Followup-To")
3123 (setq cc (and include-cc (message-fetch-field "Cc")))
3124 (setq tos (if cc
3125 (concat (message-fetch-field "To") "," cc)
3126 (message-fetch-field "To"))))
3127 (message-goto-mail-followup-to)
3128 (insert (concat tos ", " user-mail-address))))
3132 (defun message-insert-to (&optional force)
3133 "Insert a To header that points to the author of the article being replied to.
3134 If the original author requested not to be sent mail, don't insert unless the
3135 prefix FORCE is given."
3136 (interactive "P")
3137 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3138 (dont (and mct (or (equal (downcase mct) "never")
3139 (equal (downcase mct) "nobody"))))
3140 (to (or (message-fetch-reply-field "mail-reply-to")
3141 (message-fetch-reply-field "reply-to")
3142 (message-fetch-reply-field "from"))))
3143 (when (and dont to)
3144 (message
3145 (if force
3146 "Ignoring the user request not to have copies sent via mail"
3147 "Complying with the user request not to have copies sent via mail")))
3148 (when (and force (not to))
3149 (error "No mail address in the article"))
3150 (when (and to (or force (not dont)))
3151 (message-carefully-insert-headers (list (cons 'To to))))))
3153 (defun message-insert-wide-reply ()
3154 "Insert To and Cc headers as if you were doing a wide reply."
3155 (interactive)
3156 (let ((headers (message-with-reply-buffer
3157 (message-get-reply-headers t))))
3158 (message-carefully-insert-headers headers)))
3160 (defcustom message-header-synonyms
3161 '((To Cc Bcc)
3162 (Original-To))
3163 "List of lists of header synonyms.
3164 E.g., if this list contains a member list with elements `Cc' and `To',
3165 then `message-carefully-insert-headers' will not insert a `To' header
3166 when the message is already `Cc'ed to the recipient."
3167 :version "22.1"
3168 :group 'message-headers
3169 :link '(custom-manual "(message)Message Headers")
3170 :type '(repeat sexp))
3172 (defun message-carefully-insert-headers (headers)
3173 "Insert the HEADERS, an alist, into the message buffer.
3174 Does not insert the headers when they are already present there
3175 or in the synonym headers, defined by `message-header-synonyms'."
3176 ;; FIXME: Should compare only the address and not the full name. Comparison
3177 ;; should be done case-folded (and with `string=' rather than
3178 ;; `string-match').
3179 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3180 (dolist (header headers)
3181 (let* ((header-name (symbol-name (car header)))
3182 (new-header (cdr header))
3183 (synonyms (loop for synonym in message-header-synonyms
3184 when (memq (car header) synonym) return synonym))
3185 (old-header
3186 (loop for synonym in synonyms
3187 for old-header = (mail-fetch-field (symbol-name synonym))
3188 when (and old-header (string-match new-header old-header))
3189 return synonym)))
3190 (if old-header
3191 (message "already have `%s' in `%s'" new-header old-header)
3192 (when (and (message-position-on-field header-name)
3193 (setq old-header (mail-fetch-field header-name))
3194 (not (string-match "\\` *\\'" old-header)))
3195 (insert ", "))
3196 (insert new-header)))))
3198 (defun message-widen-reply ()
3199 "Widen the reply to include maximum recipients."
3200 (interactive)
3201 (let ((follow-to
3202 (and (bufferp message-reply-buffer)
3203 (buffer-name message-reply-buffer)
3204 (with-current-buffer message-reply-buffer
3205 (message-get-reply-headers t)))))
3206 (save-excursion
3207 (save-restriction
3208 (message-narrow-to-headers)
3209 (dolist (elem follow-to)
3210 (message-remove-header (symbol-name (car elem)))
3211 (goto-char (point-min))
3212 (insert (symbol-name (car elem)) ": "
3213 (cdr elem) "\n"))))))
3215 (defun message-insert-newsgroups ()
3216 "Insert the Newsgroups header from the article being replied to."
3217 (interactive)
3218 (when (and (message-position-on-field "Newsgroups")
3219 (mail-fetch-field "newsgroups")
3220 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3221 (insert ","))
3222 (insert (or (message-fetch-reply-field "newsgroups") "")))
3226 ;;; Various commands
3228 (defun message-delete-not-region (beg end)
3229 "Delete everything in the body of the current message outside of the region."
3230 (interactive "r")
3231 (let (citeprefix)
3232 (save-excursion
3233 (goto-char beg)
3234 ;; snarf citation prefix, if appropriate
3235 (unless (eq (point) (progn (beginning-of-line) (point)))
3236 (when (looking-at message-cite-prefix-regexp)
3237 (setq citeprefix (match-string 0))))
3238 (goto-char end)
3239 (delete-region (point) (if (not (message-goto-signature))
3240 (point)
3241 (forward-line -2)
3242 (point)))
3243 (insert "\n")
3244 (goto-char beg)
3245 (delete-region beg (progn (message-goto-body)
3246 (forward-line 2)
3247 (point)))
3248 (when citeprefix
3249 (insert citeprefix))))
3250 (when (message-goto-signature)
3251 (forward-line -2)))
3253 (defun message-kill-to-signature (&optional arg)
3254 "Kill all text up to the signature.
3255 If a numeric argument or prefix arg is given, leave that number
3256 of lines before the signature intact."
3257 (interactive "P")
3258 (save-excursion
3259 (save-restriction
3260 (let ((point (point)))
3261 (narrow-to-region point (point-max))
3262 (message-goto-signature)
3263 (unless (eobp)
3264 (if (and arg (numberp arg))
3265 (forward-line (- -1 arg))
3266 (end-of-line -1)))
3267 (unless (= point (point))
3268 (kill-region point (point))
3269 (unless (bolp)
3270 (insert "\n")))))))
3272 (defun message-newline-and-reformat (&optional arg not-break)
3273 "Insert four newlines, and then reformat if inside quoted text.
3274 Prefix arg means justify as well."
3275 (interactive (list (if current-prefix-arg 'full)))
3276 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3277 (setq point (point))
3278 (beginning-of-line)
3279 (setq beg (point))
3280 (setq bolp (= beg point))
3281 ;; Find first line of the paragraph.
3282 (if not-break
3283 (while (and (not (eobp))
3284 (not (looking-at message-cite-prefix-regexp))
3285 (looking-at paragraph-start))
3286 (forward-line 1)))
3287 ;; Find the prefix
3288 (when (looking-at message-cite-prefix-regexp)
3289 (setq quoted (match-string 0))
3290 (goto-char (match-end 0))
3291 (looking-at "[ \t]*")
3292 (setq leading-space (match-string 0)))
3293 (if (and quoted
3294 (not not-break)
3295 (not bolp)
3296 (< (- point beg) (length quoted)))
3297 ;; break inside the cite prefix.
3298 (setq quoted nil
3299 end nil))
3300 (if quoted
3301 (progn
3302 (forward-line 1)
3303 (while (and (not (eobp))
3304 (not (looking-at paragraph-separate))
3305 (looking-at message-cite-prefix-regexp)
3306 (equal quoted (match-string 0)))
3307 (goto-char (match-end 0))
3308 (looking-at "[ \t]*")
3309 (if (> (length leading-space) (length (match-string 0)))
3310 (setq leading-space (match-string 0)))
3311 (forward-line 1))
3312 (setq end (point))
3313 (goto-char beg)
3314 (while (and (if (bobp) nil (forward-line -1) t)
3315 (not (looking-at paragraph-start))
3316 (looking-at message-cite-prefix-regexp)
3317 (equal quoted (match-string 0)))
3318 (setq beg (point))
3319 (goto-char (match-end 0))
3320 (looking-at "[ \t]*")
3321 (if (> (length leading-space) (length (match-string 0)))
3322 (setq leading-space (match-string 0)))))
3323 (while (and (not (eobp))
3324 (not (looking-at paragraph-separate))
3325 (not (looking-at message-cite-prefix-regexp)))
3326 (forward-line 1))
3327 (setq end (point))
3328 (goto-char beg)
3329 (while (and (if (bobp) nil (forward-line -1) t)
3330 (not (looking-at paragraph-start))
3331 (not (looking-at message-cite-prefix-regexp)))
3332 (setq beg (point))))
3333 (goto-char point)
3334 (save-restriction
3335 (narrow-to-region beg end)
3336 (if not-break
3337 (setq point nil)
3338 (if bolp
3339 (newline)
3340 (newline)
3341 (newline))
3342 (setq point (point))
3343 ;; (newline 2) doesn't mark both newline's as hard, so call
3344 ;; newline twice. -jas
3345 (newline)
3346 (newline)
3347 (delete-region (point) (re-search-forward "[ \t]*"))
3348 (when (and quoted (not bolp))
3349 (insert quoted leading-space)))
3350 (undo-boundary)
3351 (if quoted
3352 (let* ((adaptive-fill-regexp
3353 (regexp-quote (concat quoted leading-space)))
3354 (adaptive-fill-first-line-regexp
3355 adaptive-fill-regexp ))
3356 (fill-paragraph arg))
3357 (fill-paragraph arg))
3358 (if point (goto-char point)))))
3360 (defun message-fill-paragraph (&optional arg)
3361 "Message specific function to fill a paragraph.
3362 This function is used as the value of `fill-paragraph-function' in
3363 Message buffers and is not meant to be called directly."
3364 (interactive (list (if current-prefix-arg 'full)))
3365 (if (if (boundp 'filladapt-mode) filladapt-mode)
3367 (if (message-point-in-header-p)
3368 (message-fill-field)
3369 (message-newline-and-reformat arg t))
3372 (defun message-point-in-header-p ()
3373 "Return t if point is in the header."
3374 (save-excursion
3375 (not (re-search-backward
3376 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3378 (defun message-do-auto-fill ()
3379 "Like `do-auto-fill', but don't fill in message header."
3380 (unless (message-point-in-header-p)
3381 (do-auto-fill)))
3383 (defun message-insert-signature (&optional force)
3384 "Insert a signature. See documentation for variable `message-signature'."
3385 (interactive (list 0))
3386 (let* ((signature
3387 (cond
3388 ((and (null message-signature)
3389 (eq force 0))
3390 (save-excursion
3391 (goto-char (point-max))
3392 (not (re-search-backward message-signature-separator nil t))))
3393 ((and (null message-signature)
3394 force)
3396 ((functionp message-signature)
3397 (funcall message-signature))
3398 ((listp message-signature)
3399 (eval message-signature))
3400 (t message-signature)))
3401 signature-file)
3402 (setq signature
3403 (cond ((stringp signature)
3404 signature)
3405 ((and (eq t signature) message-signature-file)
3406 (setq signature-file
3407 (if (and message-signature-directory
3408 ;; don't actually use the signature directory
3409 ;; if message-signature-file contains a path.
3410 (not (file-name-directory
3411 message-signature-file)))
3412 (expand-file-name message-signature-file
3413 message-signature-directory)
3414 message-signature-file))
3415 (file-exists-p signature-file))))
3416 (when signature
3417 (goto-char (point-max))
3418 ;; Insert the signature.
3419 (unless (bolp)
3420 (insert "\n"))
3421 (when message-signature-insert-empty-line
3422 (insert "\n"))
3423 (insert "-- \n")
3424 (if (eq signature t)
3425 (insert-file-contents signature-file)
3426 (insert signature))
3427 (goto-char (point-max))
3428 (or (bolp) (insert "\n")))))
3430 (defun message-insert-importance-high ()
3431 "Insert header to mark message as important."
3432 (interactive)
3433 (save-excursion
3434 (save-restriction
3435 (message-narrow-to-headers)
3436 (message-remove-header "Importance"))
3437 (message-goto-eoh)
3438 (insert "Importance: high\n")))
3440 (defun message-insert-importance-low ()
3441 "Insert header to mark message as unimportant."
3442 (interactive)
3443 (save-excursion
3444 (save-restriction
3445 (message-narrow-to-headers)
3446 (message-remove-header "Importance"))
3447 (message-goto-eoh)
3448 (insert "Importance: low\n")))
3450 (defun message-insert-or-toggle-importance ()
3451 "Insert a \"Importance: high\" header, or cycle through the header values.
3452 The three allowed values according to RFC 1327 are `high', `normal'
3453 and `low'."
3454 (interactive)
3455 (save-excursion
3456 (let ((new "high")
3457 cur)
3458 (save-restriction
3459 (message-narrow-to-headers)
3460 (when (setq cur (message-fetch-field "Importance"))
3461 (message-remove-header "Importance")
3462 (setq new (cond ((string= cur "high")
3463 "low")
3464 ((string= cur "low")
3465 "normal")
3467 "high")))))
3468 (message-goto-eoh)
3469 (insert (format "Importance: %s\n" new)))))
3471 (defun message-insert-disposition-notification-to ()
3472 "Request a disposition notification (return receipt) to this message.
3473 Note that this should not be used in newsgroups."
3474 (interactive)
3475 (save-excursion
3476 (save-restriction
3477 (message-narrow-to-headers)
3478 (message-remove-header "Disposition-Notification-To"))
3479 (message-goto-eoh)
3480 (insert (format "Disposition-Notification-To: %s\n"
3481 (or (message-field-value "Reply-to")
3482 (message-field-value "From")
3483 (message-make-from))))))
3485 (defun message-elide-region (b e)
3486 "Elide the text in the region.
3487 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3488 text was killed."
3489 (interactive "r")
3490 (kill-region b e)
3491 (insert message-elide-ellipsis))
3493 (defvar message-caesar-translation-table nil)
3495 (defun message-caesar-region (b e &optional n)
3496 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3497 (interactive
3498 (list
3499 (min (point) (or (mark t) (point)))
3500 (max (point) (or (mark t) (point)))
3501 (when current-prefix-arg
3502 (prefix-numeric-value current-prefix-arg))))
3504 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3505 (unless (or (zerop n) ; no action needed for a rot of 0
3506 (= b e)) ; no region to rotate
3507 ;; We build the table, if necessary.
3508 (when (or (not message-caesar-translation-table)
3509 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3510 (setq message-caesar-translation-table
3511 (message-make-caesar-translation-table n)))
3512 (translate-region b e message-caesar-translation-table)))
3514 (defun message-make-caesar-translation-table (n)
3515 "Create a rot table with offset N."
3516 (let ((i -1)
3517 (table (make-string 256 0)))
3518 (while (< (incf i) 256)
3519 (aset table i i))
3520 (concat
3521 (substring table 0 ?A)
3522 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3523 (substring table ?A (+ ?A n))
3524 (substring table (+ ?A 26) ?a)
3525 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3526 (substring table ?a (+ ?a n))
3527 (substring table (+ ?a 26) 255))))
3529 (defun message-caesar-buffer-body (&optional rotnum wide)
3530 "Caesar rotate all letters in the current buffer by 13 places.
3531 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3532 With prefix arg, specifies the number of places to rotate each letter forward.
3533 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3534 (interactive (if current-prefix-arg
3535 (list (prefix-numeric-value current-prefix-arg))
3536 (list nil)))
3537 (save-excursion
3538 (save-restriction
3539 (when (and (not wide) (message-goto-body))
3540 (narrow-to-region (point) (point-max)))
3541 (message-caesar-region (point-min) (point-max) rotnum))))
3543 (defun message-pipe-buffer-body (program)
3544 "Pipe the message body in the current buffer through PROGRAM."
3545 (save-excursion
3546 (save-restriction
3547 (when (message-goto-body)
3548 (narrow-to-region (point) (point-max)))
3549 (shell-command-on-region
3550 (point-min) (point-max) program nil t))))
3552 (defun message-rename-buffer (&optional enter-string)
3553 "Rename the *message* buffer to \"*message* RECIPIENT\".
3554 If the function is run with a prefix, it will ask for a new buffer
3555 name, rather than giving an automatic name."
3556 (interactive "Pbuffer name: ")
3557 (save-excursion
3558 (save-restriction
3559 (goto-char (point-min))
3560 (narrow-to-region (point)
3561 (search-forward mail-header-separator nil 'end))
3562 (let* ((mail-to (or
3563 (if (message-news-p) (message-fetch-field "Newsgroups")
3564 (message-fetch-field "To"))
3565 ""))
3566 (mail-trimmed-to
3567 (if (string-match "," mail-to)
3568 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3569 mail-to))
3570 (name-default (concat "*message* " mail-trimmed-to))
3571 (name (if enter-string
3572 (read-string "New buffer name: " name-default)
3573 name-default)))
3574 (rename-buffer name t)))))
3576 (defun message-fill-yanked-message (&optional justifyp)
3577 "Fill the paragraphs of a message yanked into this one.
3578 Numeric argument means justify as well."
3579 (interactive "P")
3580 (save-excursion
3581 (goto-char (point-min))
3582 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3583 (let ((fill-prefix message-yank-prefix))
3584 (fill-individual-paragraphs (point) (point-max) justifyp))))
3586 (defun message-indent-citation (&optional start end yank-only)
3587 "Modify text just inserted from a message to be cited.
3588 The inserted text should be the region.
3589 When this function returns, the region is again around the modified text.
3591 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3592 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3593 (unless start (setq start (point)))
3594 (unless yank-only
3595 ;; Remove unwanted headers.
3596 (when message-ignored-cited-headers
3597 (let (all-removed)
3598 (save-restriction
3599 (narrow-to-region
3600 (goto-char start)
3601 (if (search-forward "\n\n" nil t)
3602 (1- (point))
3603 (point)))
3604 (message-remove-header message-ignored-cited-headers t)
3605 (when (= (point-min) (point-max))
3606 (setq all-removed t))
3607 (goto-char (point-max)))
3608 (if all-removed
3609 (goto-char start)
3610 (forward-line 1))))
3611 ;; Delete blank lines at the start of the buffer.
3612 (while (and (point-min)
3613 (eolp)
3614 (not (eobp)))
3615 (message-delete-line))
3616 ;; Delete blank lines at the end of the buffer.
3617 (goto-char (point-max))
3618 (unless (eolp)
3619 (insert "\n"))
3620 (while (and (zerop (forward-line -1))
3621 (looking-at "$"))
3622 (message-delete-line)))
3623 ;; Do the indentation.
3624 (if (null message-yank-prefix)
3625 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3626 (save-excursion
3627 (goto-char start)
3628 (while (< (point) (or end (mark t)))
3629 (cond ((looking-at ">")
3630 (insert message-yank-cited-prefix))
3631 ((looking-at "^$")
3632 (insert message-yank-empty-prefix))
3634 (insert message-yank-prefix)))
3635 (forward-line 1))))
3636 (goto-char start))
3638 (defun message-remove-blank-cited-lines (&optional remove)
3639 "Remove cited lines containing only blanks.
3640 If REMOVE is non-nil, remove newlines, too.
3642 To use this automatically, you may add this function to
3643 `gnus-message-setup-hook'."
3644 (interactive "P")
3645 (let ((citexp
3646 (concat
3647 "^\\("
3648 (when (boundp 'message-yank-cited-prefix)
3649 (concat message-yank-cited-prefix "\\|"))
3650 message-yank-prefix
3651 "\\)+ *\n"
3653 (gnus-message 8 "removing `%s'" citexp)
3654 (save-excursion
3655 (message-goto-body)
3656 (while (re-search-forward citexp nil t)
3657 (replace-match (if remove "" "\n"))))))
3659 (defvar message-cite-reply-above nil
3660 "If non-nil, start own text above the quote.
3662 Note: Top posting is bad netiquette. Don't use it unless you
3663 really must. You probably want to set variable only for specific
3664 groups, e.g. using `gnus-posting-styles':
3666 (eval (set (make-local-variable 'message-cite-reply-above) t))
3668 This variable has no effect in news postings.")
3670 (defun message-yank-original (&optional arg)
3671 "Insert the message being replied to, if any.
3672 Puts point before the text and mark after.
3673 Normally indents each nonblank line ARG spaces (default 3). However,
3674 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3676 This function uses `message-cite-function' to do the actual citing.
3678 Just \\[universal-argument] as argument means don't indent, insert no
3679 prefix, and don't delete any headers."
3680 (interactive "P")
3681 (let ((modified (buffer-modified-p))
3682 body-text)
3683 (when (and message-reply-buffer
3684 message-cite-function)
3685 (when message-cite-reply-above
3686 (if (and (not (message-news-p))
3687 (or (eq message-cite-reply-above 'is-evil)
3688 (y-or-n-p "\
3689 Top posting is bad netiquette. Please don't top post unless you really must.
3690 Really top post? ")))
3691 (save-excursion
3692 (setq body-text
3693 (buffer-substring (message-goto-body)
3694 (point-max)))
3695 (delete-region (message-goto-body) (point-max)))
3696 (set (make-local-variable 'message-cite-reply-above) nil)))
3697 (if (bufferp message-reply-buffer)
3698 (delete-windows-on message-reply-buffer t))
3699 (push-mark (save-excursion
3700 (cond
3701 ((bufferp message-reply-buffer)
3702 (insert-buffer-substring message-reply-buffer))
3703 ((and (consp message-reply-buffer)
3704 (functionp (car message-reply-buffer)))
3705 (apply (car message-reply-buffer)
3706 (cdr message-reply-buffer))))
3707 (unless (bolp)
3708 (insert ?\n))
3709 (point)))
3710 (unless arg
3711 (funcall message-cite-function)
3712 (unless (eq (char-before (mark t)) ?\n)
3713 (let ((pt (point)))
3714 (goto-char (mark t))
3715 (insert-before-markers ?\n)
3716 (goto-char pt))))
3717 (when message-cite-reply-above
3718 (message-goto-body)
3719 (insert body-text)
3720 (insert (if (bolp) "\n" "\n\n"))
3721 (message-goto-body))
3722 ;; Add a `message-setup-very-last-hook' here?
3723 ;; Add `gnus-article-highlight-citation' here?
3724 (unless modified
3725 (setq message-checksum (message-checksum))))))
3727 (defun message-yank-buffer (buffer)
3728 "Insert BUFFER into the current buffer and quote it."
3729 (interactive "bYank buffer: ")
3730 (let ((message-reply-buffer (get-buffer buffer)))
3731 (save-window-excursion
3732 (message-yank-original))))
3734 (defun message-buffers ()
3735 "Return a list of active message buffers."
3736 (let (buffers)
3737 (save-current-buffer
3738 (dolist (buffer (buffer-list t))
3739 (set-buffer buffer)
3740 (when (and (eq major-mode 'message-mode)
3741 (null message-sent-message-via))
3742 (push (buffer-name buffer) buffers))))
3743 (nreverse buffers)))
3745 (defun message-cite-original-1 (strip-signature)
3746 "Cite an original message.
3747 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3748 original message.
3750 This function uses `mail-citation-hook' if that is non-nil."
3751 (if (and (boundp 'mail-citation-hook)
3752 mail-citation-hook)
3753 (run-hooks 'mail-citation-hook)
3754 (let* ((start (point))
3755 (end (mark t))
3756 (x-no-archive nil)
3757 (functions
3758 (when message-indent-citation-function
3759 (if (listp message-indent-citation-function)
3760 message-indent-citation-function
3761 (list message-indent-citation-function))))
3762 ;; This function may be called by `gnus-summary-yank-message' and
3763 ;; may insert a different article from the original. So, we will
3764 ;; modify the value of `message-reply-headers' with that article.
3765 (message-reply-headers
3766 (save-restriction
3767 (narrow-to-region start end)
3768 (message-narrow-to-head-1)
3769 (setq x-no-archive (message-fetch-field "x-no-archive"))
3770 (vector 0
3771 (or (message-fetch-field "subject") "none")
3772 (or (message-fetch-field "from") "nobody")
3773 (message-fetch-field "date")
3774 (message-fetch-field "message-id" t)
3775 (message-fetch-field "references")
3776 0 0 ""))))
3777 (mml-quote-region start end)
3778 (when strip-signature
3779 ;; Allow undoing.
3780 (undo-boundary)
3781 (goto-char end)
3782 (when (re-search-backward message-signature-separator start t)
3783 ;; Also peel off any blank lines before the signature.
3784 (forward-line -1)
3785 (while (looking-at "^[ \t]*$")
3786 (forward-line -1))
3787 (forward-line 1)
3788 (delete-region (point) end)
3789 (unless (search-backward "\n\n" start t)
3790 ;; Insert a blank line if it is peeled off.
3791 (insert "\n"))))
3792 (goto-char start)
3793 (mapc 'funcall functions)
3794 (when message-citation-line-function
3795 (unless (bolp)
3796 (insert "\n"))
3797 (funcall message-citation-line-function))
3798 (when (and x-no-archive
3799 (not message-cite-articles-with-x-no-archive)
3800 (string-match "yes" x-no-archive))
3801 (undo-boundary)
3802 (delete-region (point) (mark t))
3803 (insert "> [Quoted text removed due to X-No-Archive]\n")
3804 (push-mark)
3805 (forward-line -1)))))
3807 (defun message-cite-original ()
3808 "Cite function in the standard Message manner."
3809 (message-cite-original-1 nil))
3811 (defvar gnus-extract-address-components)
3813 (autoload 'format-spec "format-spec")
3815 (defun message-insert-formatted-citation-line (&optional from date)
3816 "Function that inserts a formatted citation line.
3818 See `message-citation-line-format'."
3819 ;; The optional args are for testing/debugging. They will disappear later.
3820 ;; Example:
3821 ;; (with-temp-buffer
3822 ;; (message-insert-formatted-citation-line
3823 ;; "John Doe <john.doe@example.invalid>"
3824 ;; (current-time))
3825 ;; (buffer-string))
3826 (when (or message-reply-headers (and from date))
3827 (unless from
3828 (setq from (mail-header-from message-reply-headers)))
3829 (let* ((data (condition-case ()
3830 (funcall (if (boundp gnus-extract-address-components)
3831 gnus-extract-address-components
3832 'mail-extract-address-components)
3833 from)
3834 (error nil)))
3835 (name (car data))
3836 (fname name)
3837 (lname name)
3838 (net (car (cdr data)))
3839 (name-or-net (or (car data)
3840 (car (cdr data)) from))
3841 (replydate
3843 date
3844 ;; We need Gnus functionality if the user wants date or time from
3845 ;; the original article:
3846 (when (string-match "%[^fnNFL]" message-citation-line-format)
3847 (autoload 'gnus-date-get-time "gnus-util")
3848 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3849 (flist
3850 (let ((i ?A) lst)
3851 (when (stringp name)
3852 ;; Guess first name and last name:
3853 (cond ((string-match
3854 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3855 (setq fname (nth 0 (split-string name "[ \t]+"))
3856 lname (nth 1 (split-string name "[ \t]+"))))
3857 ((string-match
3858 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3859 (setq fname (nth 1 (split-string name "[ \t,]+"))
3860 lname (nth 0 (split-string name "[ \t,]+"))))
3861 ((string-match
3862 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3863 (setq fname name
3864 lname ""))))
3865 ;; The following letters are not used in `format-time-string':
3866 (push ?E lst) (push "<E>" lst)
3867 (push ?F lst) (push fname lst)
3868 ;; We might want to use "" instead of "<X>" later.
3869 (push ?J lst) (push "<J>" lst)
3870 (push ?K lst) (push "<K>" lst)
3871 (push ?L lst) (push lname lst)
3872 (push ?N lst) (push name-or-net lst)
3873 (push ?O lst) (push "<O>" lst)
3874 (push ?P lst) (push "<P>" lst)
3875 (push ?Q lst) (push "<Q>" lst)
3876 (push ?f lst) (push from lst)
3877 (push ?i lst) (push "<i>" lst)
3878 (push ?n lst) (push net lst)
3879 (push ?o lst) (push "<o>" lst)
3880 (push ?q lst) (push "<q>" lst)
3881 (push ?t lst) (push "<t>" lst)
3882 (push ?v lst) (push "<v>" lst)
3883 ;; Delegate the rest to `format-time-string':
3884 (while (<= i ?z)
3885 (when (and (not (memq i lst))
3886 ;; Skip (Z,a)
3887 (or (<= i ?Z)
3888 (>= i ?a)))
3889 (push i lst)
3890 (push (condition-case nil
3891 (format-time-string (format "%%%c" i) replydate)
3892 (error (format ">%c<" i)))
3893 lst))
3894 (setq i (1+ i)))
3895 (reverse lst)))
3896 (spec (apply 'format-spec-make flist)))
3897 (insert (format-spec message-citation-line-format spec)))
3898 (newline)))
3900 (defun message-cite-original-without-signature ()
3901 "Cite function in the standard Message manner.
3902 This function strips off the signature from the original message."
3903 (message-cite-original-1 t))
3905 (defun message-insert-citation-line ()
3906 "Insert a simple citation line."
3907 (when message-reply-headers
3908 (insert (mail-header-from message-reply-headers) " writes:")
3909 (newline)
3910 (newline)))
3912 (defun message-position-on-field (header &rest afters)
3913 (let ((case-fold-search t))
3914 (save-restriction
3915 (narrow-to-region
3916 (goto-char (point-min))
3917 (progn
3918 (re-search-forward
3919 (concat "^" (regexp-quote mail-header-separator) "$"))
3920 (match-beginning 0)))
3921 (goto-char (point-min))
3922 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3923 (progn
3924 (re-search-forward "^[^ \t]" nil 'move)
3925 (beginning-of-line)
3926 (skip-chars-backward "\n")
3928 (while (and afters
3929 (not (re-search-forward
3930 (concat "^" (regexp-quote (car afters)) ":")
3931 nil t)))
3932 (pop afters))
3933 (when afters
3934 (re-search-forward "^[^ \t]" nil 'move)
3935 (beginning-of-line))
3936 (insert header ": \n")
3937 (forward-char -1)
3938 nil))))
3940 (defun message-remove-signature ()
3941 "Remove the signature from the text between point and mark.
3942 The text will also be indented the normal way."
3943 (save-excursion
3944 (let ((start (point))
3945 mark)
3946 (if (not (re-search-forward message-signature-separator (mark t) t))
3947 ;; No signature here, so we just indent the cited text.
3948 (message-indent-citation)
3949 ;; Find the last non-empty line.
3950 (forward-line -1)
3951 (while (looking-at "[ \t]*$")
3952 (forward-line -1))
3953 (forward-line 1)
3954 (setq mark (set-marker (make-marker) (point)))
3955 (goto-char start)
3956 (message-indent-citation)
3957 ;; Enable undoing the deletion.
3958 (undo-boundary)
3959 (delete-region mark (mark t))
3960 (set-marker mark nil)))))
3965 ;;; Sending messages
3968 (defun message-send-and-exit (&optional arg)
3969 "Send message like `message-send', then, if no errors, exit from mail buffer."
3970 (interactive "P")
3971 (let ((buf (current-buffer))
3972 (actions message-exit-actions))
3973 (when (and (message-send arg)
3974 (buffer-name buf))
3975 (if message-kill-buffer-on-exit
3976 (kill-buffer buf)
3977 (bury-buffer buf)
3978 (when (eq buf (current-buffer))
3979 (message-bury buf)))
3980 (message-do-actions actions)
3981 t)))
3983 (defun message-dont-send ()
3984 "Don't send the message you have been editing.
3985 Instead, just auto-save the buffer and then bury it."
3986 (interactive)
3987 (set-buffer-modified-p t)
3988 (save-buffer)
3989 (let ((actions message-postpone-actions))
3990 (message-bury (current-buffer))
3991 (message-do-actions actions)))
3993 (defun message-kill-buffer ()
3994 "Kill the current buffer."
3995 (interactive)
3996 (when (or (not (buffer-modified-p))
3997 (not message-kill-buffer-query)
3998 (yes-or-no-p "Message modified; kill anyway? "))
3999 (let ((actions message-kill-actions)
4000 (draft-article message-draft-article)
4001 (auto-save-file-name buffer-auto-save-file-name)
4002 (file-name buffer-file-name)
4003 (modified (buffer-modified-p)))
4004 (setq buffer-file-name nil)
4005 (kill-buffer (current-buffer))
4006 (when (and (or (and auto-save-file-name
4007 (file-exists-p auto-save-file-name))
4008 (and file-name
4009 (file-exists-p file-name)))
4010 (progn
4011 ;; If the message buffer has lived in a dedicated window,
4012 ;; `kill-buffer' has killed the frame. Thus the
4013 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4014 ;; that the user can see the question by raising the
4015 ;; current frame:
4016 (raise-frame)
4017 (yes-or-no-p (format "Remove the backup file%s? "
4018 (if modified " too" "")))))
4019 (ignore-errors
4020 (delete-file auto-save-file-name))
4021 (let ((message-draft-article draft-article))
4022 (message-disassociate-draft)))
4023 (message-do-actions actions))))
4025 (defun message-bury (buffer)
4026 "Bury this mail BUFFER."
4027 (let ((newbuf (other-buffer buffer)))
4028 (bury-buffer buffer)
4029 (if (and (window-dedicated-p (selected-window))
4030 (not (null (delq (selected-frame) (visible-frame-list)))))
4031 (delete-frame (selected-frame))
4032 (switch-to-buffer newbuf))))
4034 (defun message-send (&optional arg)
4035 "Send the message in the current buffer.
4036 If `message-interactive' is non-nil, wait for success indication or
4037 error messages, and inform user.
4038 Otherwise any failure is reported in a message back to the user from
4039 the mailer.
4040 The usage of ARG is defined by the instance that called Message.
4041 It should typically alter the sending method in some way or other."
4042 (interactive "P")
4043 ;; Make it possible to undo the coming changes.
4044 (undo-boundary)
4045 (let ((inhibit-read-only t))
4046 (put-text-property (point-min) (point-max) 'read-only nil))
4047 (message-fix-before-sending)
4048 (run-hooks 'message-send-hook)
4049 (when message-confirm-send
4050 (or (y-or-n-p "Send message? ")
4051 (keyboard-quit)))
4052 (message message-sending-message)
4053 (let ((alist message-send-method-alist)
4054 (success t)
4055 elem sent dont-barf-on-no-method
4056 (message-options message-options))
4057 (message-options-set-recipient)
4058 (while (and success
4059 (setq elem (pop alist)))
4060 (when (funcall (cadr elem))
4061 (when (and (or (not (memq (car elem)
4062 message-sent-message-via))
4063 (message-fetch-field "supersedes")
4064 (if (or (message-gnksa-enable-p 'multiple-copies)
4065 (not (eq (car elem) 'news)))
4066 (y-or-n-p
4067 (format
4068 "Already sent message via %s; resend? "
4069 (car elem)))
4070 (error "Denied posting -- multiple copies")))
4071 (setq success (funcall (caddr elem) arg)))
4072 (setq sent t))))
4073 (unless (or sent
4074 (not success)
4075 (let ((fcc (message-fetch-field "Fcc"))
4076 (gcc (message-fetch-field "Gcc")))
4077 (when (or fcc gcc)
4078 (or (eq message-allow-no-recipients 'always)
4079 (and (not (eq message-allow-no-recipients 'never))
4080 (setq dont-barf-on-no-method
4081 (gnus-y-or-n-p
4082 (format "No receiver, perform %s anyway? "
4083 (cond ((and fcc gcc) "Fcc and Gcc")
4084 (fcc "Fcc")
4085 (t "Gcc"))))))))))
4086 (error "No methods specified to send by"))
4087 (when (or dont-barf-on-no-method
4088 (and success sent))
4089 (message-do-fcc)
4090 (save-excursion
4091 (run-hooks 'message-sent-hook))
4092 (message "Sending...done")
4093 ;; Do ecomplete address snarfing.
4094 (when (message-mail-alias-type-p 'ecomplete)
4095 (message-put-addresses-in-ecomplete))
4096 ;; Mark the buffer as unmodified and delete auto-save.
4097 (set-buffer-modified-p nil)
4098 (delete-auto-save-file-if-necessary t)
4099 (message-disassociate-draft)
4100 ;; Delete other mail buffers and stuff.
4101 (message-do-send-housekeeping)
4102 (message-do-actions message-send-actions)
4103 ;; Return success.
4104 t)))
4106 (defun message-send-via-mail (arg)
4107 "Send the current message via mail."
4108 (message-send-mail arg))
4110 (defun message-send-via-news (arg)
4111 "Send the current message via news."
4112 (funcall message-send-news-function arg))
4114 (defmacro message-check (type &rest forms)
4115 "Eval FORMS if TYPE is to be checked."
4116 `(or (message-check-element ,type)
4117 (save-excursion
4118 ,@forms)))
4120 (put 'message-check 'lisp-indent-function 1)
4121 (put 'message-check 'edebug-form-spec '(form body))
4123 (defun message-text-with-property (prop &optional start end reverse)
4124 "Return a list of start and end positions where the text has PROP.
4125 START and END bound the search, they default to `point-min' and
4126 `point-max' respectively. If REVERSE is non-nil, find text which does
4127 not have PROP."
4128 (unless start
4129 (setq start (point-min)))
4130 (unless end
4131 (setq end (point-max)))
4132 (let (next regions)
4133 (if reverse
4134 (while (and start
4135 (setq start (text-property-any start end prop nil)))
4136 (setq next (next-single-property-change start prop nil end))
4137 (push (cons start (or next end)) regions)
4138 (setq start next))
4139 (while (and start
4140 (or (get-text-property start prop)
4141 (and (setq start (next-single-property-change
4142 start prop nil end))
4143 (get-text-property start prop))))
4144 (setq next (text-property-any start end prop nil))
4145 (push (cons start (or next end)) regions)
4146 (setq start next)))
4147 (nreverse regions)))
4149 (defcustom message-bogus-addresses
4150 ;; '("noreply" "nospam" "invalid")
4151 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4152 "List of regexps of potentially bogus mail addresses.
4153 See `message-check-recipients' how to setup checking.
4155 This list should make it possible to catch typos or warn about
4156 spam-trap addresses. It doesn't aim to verify strict RFC
4157 conformance."
4158 :version "23.1" ;; No Gnus
4159 :group 'message-headers
4160 :type '(choice
4161 (const :tag "None" nil)
4162 (list
4163 (set :inline t
4164 (const "noreply")
4165 (const "nospam")
4166 (const "invalid")
4167 (const :tag "duplicate @" "@@")
4168 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4169 ;; Already caught by `message-valid-fqdn-regexp'
4170 ;; (const :tag "`_' in domain part" "@.*_")
4171 (const :tag "whitespace" "[ \t]"))
4172 (repeat :inline t
4173 :tag "Other"
4174 (regexp)))))
4176 (defun message-fix-before-sending ()
4177 "Do various things to make the message nice before sending it."
4178 ;; Make sure there's a newline at the end of the message.
4179 (goto-char (point-max))
4180 (unless (bolp)
4181 (insert "\n"))
4182 ;; Make the hidden headers visible.
4183 (widen)
4184 ;; Sort headers before sending the message.
4185 (message-sort-headers)
4186 ;; Make invisible text visible.
4187 ;; It doesn't seem as if this is useful, since the invisible property
4188 ;; is clobbered by an after-change hook anyhow.
4189 (message-check 'invisible-text
4190 (let ((regions (message-text-with-property 'invisible))
4191 from to)
4192 (when regions
4193 (while regions
4194 (setq from (caar regions)
4195 to (cdar regions)
4196 regions (cdr regions))
4197 (put-text-property from to 'invisible nil)
4198 (message-overlay-put (message-make-overlay from to)
4199 'face 'highlight))
4200 (unless (yes-or-no-p
4201 "Invisible text found and made visible; continue sending? ")
4202 (error "Invisible text found and made visible")))))
4203 (message-check 'illegible-text
4204 (let (char found choice)
4205 (message-goto-body)
4206 (while (progn
4207 (skip-chars-forward mm-7bit-chars)
4208 (when (get-text-property (point) 'no-illegible-text)
4209 ;; There is a signed or encrypted raw message part
4210 ;; that is considered to be safe.
4211 (goto-char (or (next-single-property-change
4212 (point) 'no-illegible-text)
4213 (point-max))))
4214 (setq char (char-after)))
4215 (when (or (< (mm-char-int char) 128)
4216 (and (mm-multibyte-p)
4217 (memq (char-charset char)
4218 '(eight-bit-control eight-bit-graphic
4219 ;; Emacs 23, Bug#1770:
4220 eight-bit
4221 control-1))
4222 (not (get-text-property
4223 (point) 'untranslated-utf-8))))
4224 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4225 'face 'highlight)
4226 (setq found t))
4227 (forward-char))
4228 (when found
4229 (setq choice
4230 (gnus-multiple-choice
4231 "Non-printable characters found. Continue sending?"
4232 `((?d "Remove non-printable characters and send")
4233 (?r ,(format
4234 "Replace non-printable characters with \"%s\" and send"
4235 message-replacement-char))
4236 (?i "Ignore non-printable characters and send")
4237 (?e "Continue editing"))))
4238 (if (eq choice ?e)
4239 (error "Non-printable characters"))
4240 (message-goto-body)
4241 (skip-chars-forward mm-7bit-chars)
4242 (while (not (eobp))
4243 (when (let ((char (char-after)))
4244 (or (< (mm-char-int char) 128)
4245 (and (mm-multibyte-p)
4246 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4247 ;; things like undecodable utf-8 (in Emacs 21?).
4248 ;; Should at least use find-coding-systems-region.
4249 ;; -- fx
4250 (memq (char-charset char)
4251 '(eight-bit-control eight-bit-graphic
4252 ;; Emacs 23, Bug#1770:
4253 eight-bit
4254 control-1))
4255 (not (get-text-property
4256 (point) 'untranslated-utf-8)))))
4257 (if (eq choice ?i)
4258 (message-kill-all-overlays)
4259 (delete-char 1)
4260 (when (eq choice ?r)
4261 (insert message-replacement-char))))
4262 (forward-char)
4263 (skip-chars-forward mm-7bit-chars)))))
4264 (message-check 'bogus-recipient
4265 ;; Warn before sending a mail to an invalid address.
4266 (message-check-recipients)))
4268 (defun message-bogus-recipient-p (recipients)
4269 "Check if a mail address in RECIPIENTS looks bogus.
4271 RECIPIENTS is a mail header. Return a list of potentially bogus
4272 addresses. If none is found, return nil.
4274 An address might be bogus if the domain part is not fully
4275 qualified, see `message-valid-fqdn-regexp', or if there's a
4276 matching entry in `message-bogus-addresses'."
4277 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4278 (let (found)
4279 (mapc (lambda (address)
4280 (setq address (cadr address))
4281 (when
4282 (or (not
4284 (not (string-match "@" address))
4285 (string-match
4286 (concat ".@.*\\("
4287 message-valid-fqdn-regexp "\\)\\'") address)))
4288 (and message-bogus-addresses
4289 (let ((re
4290 (if (listp message-bogus-addresses)
4291 (mapconcat 'identity
4292 message-bogus-addresses
4293 "\\|")
4294 message-bogus-addresses)))
4295 (string-match re address))))
4296 (push address found)))
4298 (mail-extract-address-components recipients t))
4299 found))
4301 (defun message-check-recipients ()
4302 "Warn before composing or sending a mail to an invalid address.
4304 This function could be useful in `message-setup-hook'."
4305 (interactive)
4306 (save-restriction
4307 (message-narrow-to-headers)
4308 (dolist (hdr '("To" "Cc" "Bcc"))
4309 (let ((addr (message-fetch-field hdr)))
4310 (when (stringp addr)
4311 (dolist (bog (message-bogus-recipient-p addr))
4312 (and bog
4313 (not (y-or-n-p
4314 (format
4315 "Address `%s' might be bogus. Continue? " bog)))
4316 (error "Bogus address"))))))))
4318 (custom-add-option 'message-setup-hook 'message-check-recipients)
4320 (defun message-add-action (action &rest types)
4321 "Add ACTION to be performed when doing an exit of type TYPES."
4322 (while types
4323 (add-to-list (intern (format "message-%s-actions" (pop types)))
4324 action)))
4326 (defun message-delete-action (action &rest types)
4327 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4328 (let (var)
4329 (while types
4330 (set (setq var (intern (format "message-%s-actions" (pop types))))
4331 (delq action (symbol-value var))))))
4333 (defun message-do-actions (actions)
4334 "Perform all actions in ACTIONS."
4335 ;; Now perform actions on successful sending.
4336 (dolist (action actions)
4337 (ignore-errors
4338 (cond
4339 ;; A simple function.
4340 ((functionp action)
4341 (funcall action))
4342 ;; Something to be evaled.
4344 (eval action))))))
4346 (defun message-send-mail-partially ()
4347 "Send mail as message/partial."
4348 ;; replace the header delimiter with a blank line
4349 (goto-char (point-min))
4350 (re-search-forward
4351 (concat "^" (regexp-quote mail-header-separator) "\n"))
4352 (replace-match "\n")
4353 (run-hooks 'message-send-mail-hook)
4354 (let ((p (goto-char (point-min)))
4355 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4356 (curbuf (current-buffer))
4357 (id (message-make-message-id)) (n 1)
4358 plist total header required-mail-headers)
4359 (while (not (eobp))
4360 (if (< (point-max) (+ p message-send-mail-partially-limit))
4361 (goto-char (point-max))
4362 (goto-char (+ p message-send-mail-partially-limit))
4363 (beginning-of-line)
4364 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4365 (push p plist)
4366 (setq p (point)))
4367 (setq total (length plist))
4368 (push (point-max) plist)
4369 (setq plist (nreverse plist))
4370 (unwind-protect
4371 (save-excursion
4372 (setq p (pop plist))
4373 (while plist
4374 (set-buffer curbuf)
4375 (copy-to-buffer tembuf p (car plist))
4376 (set-buffer tembuf)
4377 (goto-char (point-min))
4378 (if header
4379 (progn
4380 (goto-char (point-min))
4381 (narrow-to-region (point) (point))
4382 (insert header))
4383 (message-goto-eoh)
4384 (setq header (buffer-substring (point-min) (point)))
4385 (goto-char (point-min))
4386 (narrow-to-region (point) (point))
4387 (insert header)
4388 (message-remove-header "Mime-Version")
4389 (message-remove-header "Content-Type")
4390 (message-remove-header "Content-Transfer-Encoding")
4391 (message-remove-header "Message-ID")
4392 (message-remove-header "Lines")
4393 (goto-char (point-max))
4394 (insert "Mime-Version: 1.0\n")
4395 (setq header (buffer-string)))
4396 (goto-char (point-max))
4397 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4398 id n total))
4399 (forward-char -1)
4400 (let ((mail-header-separator ""))
4401 (when (memq 'Message-ID message-required-mail-headers)
4402 (insert "Message-ID: " (message-make-message-id) "\n"))
4403 (when (memq 'Lines message-required-mail-headers)
4404 (insert "Lines: " (message-make-lines) "\n"))
4405 (message-goto-subject)
4406 (end-of-line)
4407 (insert (format " (%d/%d)" n total))
4408 (widen)
4409 (funcall (or message-send-mail-real-function
4410 message-send-mail-function)))
4411 (setq n (+ n 1))
4412 (setq p (pop plist))
4413 (erase-buffer)))
4414 (kill-buffer tembuf))))
4416 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4418 (defun message-send-mail (&optional arg)
4419 (require 'mail-utils)
4420 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4421 (case-fold-search nil)
4422 (news (message-news-p))
4423 (mailbuf (current-buffer))
4424 (message-this-is-mail t)
4425 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4426 ;; maybe it should not be), which this file requires. Hence
4427 ;; the fboundp test is always true. Loading it from gnus-msg
4428 ;; loads many Gnus files (Bug#5642). If
4429 ;; gnus-group-posting-charset-alist hasn't been customized,
4430 ;; this is just going to return nil anyway. FIXME it would
4431 ;; be good to improve this further, because even if g-g-p-c-a
4432 ;; has been customized, that is likely to just be for news.
4433 ;; Eg either move the definition from gnus-msg, or separate out
4434 ;; the mail and news parts.
4435 (message-posting-charset
4436 (if (and (fboundp 'gnus-setup-posting-charset)
4437 (boundp 'gnus-group-posting-charset-alist))
4438 (gnus-setup-posting-charset nil)
4439 message-posting-charset))
4440 (headers message-required-mail-headers))
4441 (when (and message-generate-hashcash
4442 (not (eq message-generate-hashcash 'opportunistic)))
4443 (message "Generating hashcash...")
4444 (require 'hashcash)
4445 ;; Wait for calculations already started to finish...
4446 (hashcash-wait-async)
4447 ;; ...and do calculations not already done. mail-add-payment
4448 ;; will leave existing X-Hashcash headers alone.
4449 (mail-add-payment)
4450 (message "Generating hashcash...done"))
4451 (save-restriction
4452 (message-narrow-to-headers)
4453 ;; Generate the Mail-Followup-To header if the header is not there...
4454 (if (and (message-subscribed-p)
4455 (not (mail-fetch-field "mail-followup-to")))
4456 (setq headers
4457 (cons
4458 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4459 message-required-mail-headers))
4460 ;; otherwise, delete the MFT header if the field is empty
4461 (when (equal "" (mail-fetch-field "mail-followup-to"))
4462 (message-remove-header "^Mail-Followup-To:")))
4463 ;; Insert some headers.
4464 (let ((message-deletable-headers
4465 (if news nil message-deletable-headers)))
4466 (message-generate-headers headers))
4467 ;; Check continuation headers.
4468 (message-check 'continuation-headers
4469 (goto-char (point-min))
4470 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4471 (goto-char (match-beginning 0))
4472 (if (y-or-n-p "Fix continuation lines? ")
4473 (insert " ")
4474 (forward-line 1)
4475 (unless (y-or-n-p "Send anyway? ")
4476 (error "Failed to send the message")))))
4477 ;; Let the user do all of the above.
4478 (run-hooks 'message-header-hook))
4479 (unwind-protect
4480 (with-current-buffer tembuf
4481 (erase-buffer)
4482 ;; Avoid copying text props (except hard newlines).
4483 (insert (with-current-buffer mailbuf
4484 (mml-buffer-substring-no-properties-except-hard-newlines
4485 (point-min) (point-max))))
4486 ;; Remove some headers.
4487 (message-encode-message-body)
4488 (save-restriction
4489 (message-narrow-to-headers)
4490 ;; We (re)generate the Lines header.
4491 (when (memq 'Lines message-required-mail-headers)
4492 (message-generate-headers '(Lines)))
4493 ;; Remove some headers.
4494 (message-remove-header message-ignored-mail-headers t)
4495 (let ((mail-parse-charset message-default-charset))
4496 (mail-encode-encoded-word-buffer)))
4497 (goto-char (point-max))
4498 ;; require one newline at the end.
4499 (or (= (preceding-char) ?\n)
4500 (insert ?\n))
4501 (message-cleanup-headers)
4502 ;; FIXME: we're inserting the courtesy copy after encoding.
4503 ;; This is wrong if the courtesy copy string contains
4504 ;; non-ASCII characters. -- jh
4505 (when
4506 (save-restriction
4507 (message-narrow-to-headers)
4508 (and news
4509 (or (message-fetch-field "cc")
4510 (message-fetch-field "bcc")
4511 (message-fetch-field "to"))
4512 (let ((content-type (message-fetch-field
4513 "content-type")))
4514 (and
4516 (not content-type)
4517 (string= "text/plain"
4518 (car
4519 (mail-header-parse-content-type
4520 content-type))))
4521 (not
4522 (string= "base64"
4523 (message-fetch-field
4524 "content-transfer-encoding")))))))
4525 (message-insert-courtesy-copy))
4526 ;; Let's make sure we encoded all the body.
4527 (assert (save-excursion
4528 (goto-char (point-min))
4529 (not (re-search-forward "[^\000-\377]" nil t))))
4530 (mm-disable-multibyte)
4531 (if (or (not message-send-mail-partially-limit)
4532 (< (buffer-size) message-send-mail-partially-limit)
4533 (not (message-y-or-n-p
4534 "The message size is too large, split? "
4537 The message size, "
4538 (/ (buffer-size) 1000) "KB, is too large.
4540 Some mail gateways (MTA's) bounce large messages. To avoid the
4541 problem, answer `y', and the message will be split into several
4542 smaller pieces, the size of each is about "
4543 (/ message-send-mail-partially-limit 1000)
4544 "KB except the last
4545 one.
4547 However, some mail readers (MUA's) can't read split messages, i.e.,
4548 mails in message/partially format. Answer `n', and the message will be
4549 sent in one piece.
4551 The size limit is controlled by `message-send-mail-partially-limit'.
4552 If you always want Gnus to send messages in one piece, set
4553 `message-send-mail-partially-limit' to nil.
4554 ")))
4555 (progn
4556 (message "Sending via mail...")
4557 (funcall (or message-send-mail-real-function
4558 message-send-mail-function)))
4559 (message-send-mail-partially)))
4560 (kill-buffer tembuf))
4561 (set-buffer mailbuf)
4562 (push 'mail message-sent-message-via)))
4564 (defun message-send-mail-with-sendmail ()
4565 "Send off the prepared buffer with sendmail."
4566 (require 'sendmail)
4567 (let ((errbuf (if message-interactive
4568 (message-generate-new-buffer-clone-locals
4569 " sendmail errors")
4571 resend-to-addresses delimline)
4572 (unwind-protect
4573 (progn
4574 (let ((case-fold-search t))
4575 (save-restriction
4576 (message-narrow-to-headers)
4577 (setq resend-to-addresses (message-fetch-field "resent-to")))
4578 ;; Change header-delimiter to be what sendmail expects.
4579 (goto-char (point-min))
4580 (re-search-forward
4581 (concat "^" (regexp-quote mail-header-separator) "\n"))
4582 (replace-match "\n")
4583 (backward-char 1)
4584 (setq delimline (point-marker))
4585 (run-hooks 'message-send-mail-hook)
4586 ;; Insert an extra newline if we need it to work around
4587 ;; Sun's bug that swallows newlines.
4588 (goto-char (1+ delimline))
4589 (when (eval message-mailer-swallows-blank-line)
4590 (newline))
4591 (when message-interactive
4592 (with-current-buffer errbuf
4593 (erase-buffer))))
4594 (let* ((default-directory "/")
4595 (coding-system-for-write message-send-coding-system)
4596 (cpr (apply
4597 'call-process-region
4598 (append
4599 (list (point-min) (point-max)
4600 (cond ((boundp 'sendmail-program)
4601 sendmail-program)
4602 ((file-exists-p "/usr/sbin/sendmail")
4603 "/usr/sbin/sendmail")
4604 ((file-exists-p "/usr/lib/sendmail")
4605 "/usr/lib/sendmail")
4606 ((file-exists-p "/usr/ucblib/sendmail")
4607 "/usr/ucblib/sendmail")
4608 (t "fakemail"))
4609 nil errbuf nil "-oi")
4610 message-sendmail-extra-arguments
4611 ;; Always specify who from,
4612 ;; since some systems have broken sendmails.
4613 ;; But some systems are more broken with -f, so
4614 ;; we'll let users override this.
4615 (and (null message-sendmail-f-is-evil)
4616 (list "-f" (message-sendmail-envelope-from)))
4617 ;; These mean "report errors by mail"
4618 ;; and "deliver in background".
4619 (if (null message-interactive) '("-oem" "-odb"))
4620 ;; Get the addresses from the message
4621 ;; unless this is a resend.
4622 ;; We must not do that for a resend
4623 ;; because we would find the original addresses.
4624 ;; For a resend, include the specific addresses.
4625 (if resend-to-addresses
4626 (list resend-to-addresses)
4627 '("-t"))))))
4628 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4629 (if errbuf (pop-to-buffer errbuf))
4630 (error "Sending...failed with exit value %d" cpr)))
4631 (when message-interactive
4632 (with-current-buffer errbuf
4633 (goto-char (point-min))
4634 (while (re-search-forward "\n+ *" nil t)
4635 (replace-match "; "))
4636 (if (not (zerop (buffer-size)))
4637 (error "Sending...failed to %s"
4638 (buffer-string))))))
4639 (when (bufferp errbuf)
4640 (kill-buffer errbuf)))))
4642 (defun message-send-mail-with-qmail ()
4643 "Pass the prepared message buffer to qmail-inject.
4644 Refer to the documentation for the variable `message-send-mail-function'
4645 to find out how to use this."
4646 ;; replace the header delimiter with a blank line
4647 (goto-char (point-min))
4648 (re-search-forward
4649 (concat "^" (regexp-quote mail-header-separator) "\n"))
4650 (replace-match "\n")
4651 (run-hooks 'message-send-mail-hook)
4652 ;; send the message
4653 (case
4654 (let ((coding-system-for-write message-send-coding-system))
4655 (apply
4656 'call-process-region (point-min) (point-max)
4657 message-qmail-inject-program nil nil nil
4658 ;; qmail-inject's default behavior is to look for addresses on the
4659 ;; command line; if there're none, it scans the headers.
4660 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4662 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4663 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4664 ;; message from stdin.
4666 ;; qmail also has the advantage of not having been raped by
4667 ;; various vendors, so we don't have to allow for that, either --
4668 ;; compare this with message-send-mail-with-sendmail and weep
4669 ;; for sendmail's lost innocence.
4671 ;; all this is way cool coz it lets us keep the arguments entirely
4672 ;; free for -inject-arguments -- a big win for the user and for us
4673 ;; since we don't have to play that double-guessing game and the user
4674 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4675 (if (functionp message-qmail-inject-args)
4676 (funcall message-qmail-inject-args)
4677 message-qmail-inject-args)))
4678 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4679 ;; we have to look at the retval instead
4680 (0 nil)
4681 (100 (error "qmail-inject reported permanent failure"))
4682 (111 (error "qmail-inject reported transient failure"))
4683 ;; should never happen
4684 (t (error "qmail-inject reported unknown failure"))))
4686 (defun message-send-mail-with-mh ()
4687 "Send the prepared message buffer with mh."
4688 (let ((mh-previous-window-config nil)
4689 (name (mh-new-draft-name)))
4690 (setq buffer-file-name name)
4691 ;; MH wants to generate these headers itself.
4692 (when message-mh-deletable-headers
4693 (let ((headers message-mh-deletable-headers))
4694 (while headers
4695 (goto-char (point-min))
4696 (and (re-search-forward
4697 (concat "^" (symbol-name (car headers)) ": *") nil t)
4698 (message-delete-line))
4699 (pop headers))))
4700 (run-hooks 'message-send-mail-hook)
4701 ;; Pass it on to mh.
4702 (mh-send-letter)))
4704 (defun message-smtpmail-send-it ()
4705 "Send the prepared message buffer with `smtpmail-send-it'.
4706 The only difference from `smtpmail-send-it' is that this command
4707 evaluates `message-send-mail-hook' just before sending a message.
4708 It is useful if your ISP requires the POP-before-SMTP
4709 authentication. See the Gnus manual for details."
4710 (run-hooks 'message-send-mail-hook)
4711 (smtpmail-send-it))
4713 (defun message-send-mail-with-mailclient ()
4714 "Send the prepared message buffer with `mailclient-send-it'.
4715 The only difference from `mailclient-send-it' is that this
4716 command evaluates `message-send-mail-hook' just before sending a message."
4717 (run-hooks 'message-send-mail-hook)
4718 (mailclient-send-it))
4720 (defun message-canlock-generate ()
4721 "Return a string that is non-trivial to guess.
4722 Do not use this for anything important, it is cryptographically weak."
4723 (require 'sha1)
4724 (let (sha1-maximum-internal-length)
4725 (sha1 (concat (message-unique-id)
4726 (format "%x%x%x" (random) (random t) (random))
4727 (prin1-to-string (recent-keys))
4728 (prin1-to-string (garbage-collect))))))
4730 (defvar canlock-password)
4731 (defvar canlock-password-for-verify)
4733 (defun message-canlock-password ()
4734 "The password used by message for cancel locks.
4735 This is the value of `canlock-password', if that option is non-nil.
4736 Otherwise, generate and save a value for `canlock-password' first."
4737 (require 'canlock)
4738 (unless canlock-password
4739 (customize-save-variable 'canlock-password (message-canlock-generate))
4740 (setq canlock-password-for-verify canlock-password))
4741 canlock-password)
4743 (defun message-insert-canlock ()
4744 (when message-insert-canlock
4745 (message-canlock-password)
4746 (canlock-insert-header)))
4748 (autoload 'nnheader-get-report "nnheader")
4750 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4752 (defun message-send-news (&optional arg)
4753 (require 'gnus-msg)
4754 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4755 (case-fold-search nil)
4756 (method (if (functionp message-post-method)
4757 (funcall message-post-method arg)
4758 message-post-method))
4759 (newsgroups-field (save-restriction
4760 (message-narrow-to-headers-or-head)
4761 (message-fetch-field "Newsgroups")))
4762 (followup-field (save-restriction
4763 (message-narrow-to-headers-or-head)
4764 (message-fetch-field "Followup-To")))
4765 ;; BUG: We really need to get the charset for each name in the
4766 ;; Newsgroups and Followup-To lines to allow crossposting
4767 ;; between group namess with incompatible character sets.
4768 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4769 (group-field-charset
4770 (gnus-group-name-charset method newsgroups-field))
4771 (followup-field-charset
4772 (gnus-group-name-charset method (or followup-field "")))
4773 (rfc2047-header-encoding-alist
4774 (append (when group-field-charset
4775 (list (cons "Newsgroups" group-field-charset)))
4776 (when followup-field-charset
4777 (list (cons "Followup-To" followup-field-charset)))
4778 rfc2047-header-encoding-alist))
4779 (messbuf (current-buffer))
4780 (message-syntax-checks
4781 (if (and arg
4782 (listp message-syntax-checks))
4783 (cons '(existing-newsgroups . disabled)
4784 message-syntax-checks)
4785 message-syntax-checks))
4786 (message-this-is-news t)
4787 (message-posting-charset
4788 (gnus-setup-posting-charset newsgroups-field))
4789 result)
4790 (if (not (message-check-news-body-syntax))
4792 (save-restriction
4793 (message-narrow-to-headers)
4794 ;; Insert some headers.
4795 (message-generate-headers message-required-news-headers)
4796 (message-insert-canlock)
4797 ;; Let the user do all of the above.
4798 (run-hooks 'message-header-hook))
4799 ;; Note: This check will be disabled by the ".*" default value for
4800 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4801 (when (and group-field-charset
4802 (listp message-syntax-checks))
4803 (setq message-syntax-checks
4804 (cons '(valid-newsgroups . disabled)
4805 message-syntax-checks)))
4806 (message-cleanup-headers)
4807 (if (not (let ((message-post-method method))
4808 (message-check-news-syntax)))
4810 (unwind-protect
4811 (with-current-buffer tembuf
4812 (buffer-disable-undo)
4813 (erase-buffer)
4814 ;; Avoid copying text props (except hard newlines).
4815 (insert
4816 (with-current-buffer messbuf
4817 (mml-buffer-substring-no-properties-except-hard-newlines
4818 (point-min) (point-max))))
4819 (message-encode-message-body)
4820 ;; Remove some headers.
4821 (save-restriction
4822 (message-narrow-to-headers)
4823 ;; We (re)generate the Lines header.
4824 (when (memq 'Lines message-required-mail-headers)
4825 (message-generate-headers '(Lines)))
4826 ;; Remove some headers.
4827 (message-remove-header message-ignored-news-headers t)
4828 (let ((mail-parse-charset message-default-charset))
4829 (mail-encode-encoded-word-buffer)))
4830 (goto-char (point-max))
4831 ;; require one newline at the end.
4832 (or (= (preceding-char) ?\n)
4833 (insert ?\n))
4834 (let ((case-fold-search t))
4835 ;; Remove the delimiter.
4836 (goto-char (point-min))
4837 (re-search-forward
4838 (concat "^" (regexp-quote mail-header-separator) "\n"))
4839 (replace-match "\n")
4840 (backward-char 1))
4841 (run-hooks 'message-send-news-hook)
4842 (gnus-open-server method)
4843 (message "Sending news via %s..." (gnus-server-string method))
4844 (setq result (let ((mail-header-separator ""))
4845 (gnus-request-post method))))
4846 (kill-buffer tembuf))
4847 (set-buffer messbuf)
4848 (if result
4849 (push 'news message-sent-message-via)
4850 (message "Couldn't send message via news: %s"
4851 (nnheader-get-report (car method)))
4852 nil)))))
4855 ;;; Header generation & syntax checking.
4858 (defun message-check-element (type)
4859 "Return non-nil if this TYPE is not to be checked."
4860 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4862 (let ((able (assq type message-syntax-checks)))
4863 (and (consp able)
4864 (eq (cdr able) 'disabled)))))
4866 (defun message-check-news-syntax ()
4867 "Check the syntax of the message."
4868 (save-excursion
4869 (save-restriction
4870 (widen)
4871 ;; We narrow to the headers and check them first.
4872 (save-excursion
4873 (save-restriction
4874 (message-narrow-to-headers)
4875 (message-check-news-header-syntax))))))
4877 (defun message-check-news-header-syntax ()
4878 (and
4879 ;; Check Newsgroups header.
4880 (message-check 'newsgroups
4881 (let ((group (message-fetch-field "newsgroups")))
4883 (and group
4884 (not (string-match "\\`[ \t]*\\'" group)))
4885 (ignore
4886 (message
4887 "The newsgroups field is empty or missing. Posting is denied.")))))
4888 ;; Check the Subject header.
4889 (message-check 'subject
4890 (let* ((case-fold-search t)
4891 (subject (message-fetch-field "subject")))
4893 (and subject
4894 (not (string-match "\\`[ \t]*\\'" subject)))
4895 (ignore
4896 (message
4897 "The subject field is empty or missing. Posting is denied.")))))
4898 ;; Check for commands in Subject.
4899 (message-check 'subject-cmsg
4900 (if (string-match "^cmsg " (message-fetch-field "subject"))
4901 (y-or-n-p
4902 "The control code \"cmsg\" is in the subject. Really post? ")
4904 ;; Check long header lines.
4905 (message-check 'long-header-lines
4906 (let ((start (point))
4907 (header nil)
4908 (length 0)
4909 found)
4910 (while (and (not found)
4911 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4912 (if (> (- (point) (match-beginning 0)) 998)
4913 (setq found t
4914 length (- (point) (match-beginning 0)))
4915 (setq header (match-string-no-properties 1)))
4916 (setq start (match-beginning 0))
4917 (forward-line 1))
4918 (if found
4919 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4920 header length))
4921 t)))
4922 ;; Check for multiple identical headers.
4923 (message-check 'multiple-headers
4924 (let (found)
4925 (while (and (not found)
4926 (re-search-forward "^[^ \t:]+: " nil t))
4927 (save-excursion
4928 (or (re-search-forward
4929 (concat "^"
4930 (regexp-quote
4931 (setq found
4932 (buffer-substring
4933 (match-beginning 0) (- (match-end 0) 2))))
4934 ":")
4935 nil t)
4936 (setq found nil))))
4937 (if found
4938 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4939 t)))
4940 ;; Check for Version and Sendsys.
4941 (message-check 'sendsys
4942 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4943 (y-or-n-p
4944 (format "The article contains a %s command. Really post? "
4945 (buffer-substring (match-beginning 0)
4946 (1- (match-end 0)))))
4948 ;; See whether we can shorten Followup-To.
4949 (message-check 'shorten-followup-to
4950 (let ((newsgroups (message-fetch-field "newsgroups"))
4951 (followup-to (message-fetch-field "followup-to"))
4953 (when (and newsgroups
4954 (string-match "," newsgroups)
4955 (not followup-to)
4956 (not
4957 (zerop
4958 (length
4959 (setq to (completing-read
4960 "Followups to (default no Followup-To header): "
4961 (mapcar #'list
4962 (cons "poster"
4963 (message-tokenize-header
4964 newsgroups)))))))))
4965 (goto-char (point-min))
4966 (insert "Followup-To: " to "\n"))
4968 ;; Check "Shoot me".
4969 (message-check 'shoot
4970 (if (re-search-forward
4971 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4972 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4974 ;; Check for Approved.
4975 (message-check 'approved
4976 (if (re-search-forward "^Approved:" nil t)
4977 (y-or-n-p "The article contains an Approved header. Really post? ")
4979 ;; Check the Message-ID header.
4980 (message-check 'message-id
4981 (let* ((case-fold-search t)
4982 (message-id (message-fetch-field "message-id" t)))
4983 (or (not message-id)
4984 ;; Is there an @ in the ID?
4985 (and (string-match "@" message-id)
4986 ;; Is there a dot in the ID?
4987 (string-match "@[^.]*\\." message-id)
4988 ;; Does the ID end with a dot?
4989 (not (string-match "\\.>" message-id)))
4990 (y-or-n-p
4991 (format "The Message-ID looks strange: \"%s\". Really post? "
4992 message-id)))))
4993 ;; Check the Newsgroups & Followup-To headers.
4994 (message-check 'existing-newsgroups
4995 (let* ((case-fold-search t)
4996 (newsgroups (message-fetch-field "newsgroups"))
4997 (followup-to (message-fetch-field "followup-to"))
4998 (groups (message-tokenize-header
4999 (if followup-to
5000 (concat newsgroups "," followup-to)
5001 newsgroups)))
5002 (post-method (if (functionp message-post-method)
5003 (funcall message-post-method)
5004 message-post-method))
5005 ;; KLUDGE to handle nnvirtual groups. Doing this right
5006 ;; would probably involve a new nnoo function.
5007 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5008 (method (if (and (consp post-method)
5009 (eq (car post-method) 'nnvirtual)
5010 gnus-message-group-art)
5011 (let ((group (car (nnvirtual-find-group-art
5012 (car gnus-message-group-art)
5013 (cdr gnus-message-group-art)))))
5014 (gnus-find-method-for-group group))
5015 post-method))
5016 (known-groups
5017 (mapcar (lambda (n)
5018 (gnus-group-name-decode
5019 (gnus-group-real-name n)
5020 (gnus-group-name-charset method n)))
5021 (gnus-groups-from-server method)))
5022 errors)
5023 (while groups
5024 (when (and (not (equal (car groups) "poster"))
5025 (not (member (car groups) known-groups))
5026 (not (member (car groups) errors)))
5027 (push (car groups) errors))
5028 (pop groups))
5029 (cond
5030 ;; Gnus is not running.
5031 ((or (not (and (boundp 'gnus-active-hashtb)
5032 gnus-active-hashtb))
5033 (not (boundp 'gnus-read-active-file)))
5035 ;; We don't have all the group names.
5036 ((and (or (not gnus-read-active-file)
5037 (eq gnus-read-active-file 'some))
5038 errors)
5039 (y-or-n-p
5040 (format
5041 "Really use %s possibly unknown group%s: %s? "
5042 (if (= (length errors) 1) "this" "these")
5043 (if (= (length errors) 1) "" "s")
5044 (mapconcat 'identity errors ", "))))
5045 ;; There were no errors.
5046 ((not errors)
5048 ;; There are unknown groups.
5050 (y-or-n-p
5051 (format
5052 "Really post to %s unknown group%s: %s? "
5053 (if (= (length errors) 1) "this" "these")
5054 (if (= (length errors) 1) "" "s")
5055 (mapconcat 'identity errors ", ")))))))
5056 ;; Check continuation headers.
5057 (message-check 'continuation-headers
5058 (goto-char (point-min))
5059 (let ((do-posting t))
5060 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5061 (goto-char (match-beginning 0))
5062 (if (y-or-n-p "Fix continuation lines? ")
5063 (insert " ")
5064 (forward-line 1)
5065 (unless (y-or-n-p "Send anyway? ")
5066 (setq do-posting nil))))
5067 do-posting))
5068 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5069 (message-check 'valid-newsgroups
5070 (let ((case-fold-search t)
5071 (headers '("Newsgroups" "Followup-To"))
5072 header error)
5073 (while (and headers (not error))
5074 (when (setq header (mail-fetch-field (car headers)))
5075 (if (or
5076 (not
5077 (string-match
5078 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5079 header))
5080 (memq
5081 nil (mapcar
5082 (lambda (g)
5083 (not (string-match "\\.\\'\\|\\.\\." g)))
5084 (message-tokenize-header header ","))))
5085 (setq error t)))
5086 (unless error
5087 (pop headers)))
5088 (if (not error)
5090 (y-or-n-p
5091 (format "The %s header looks odd: \"%s\". Really post? "
5092 (car headers) header)))))
5093 (message-check 'repeated-newsgroups
5094 (let ((case-fold-search t)
5095 (headers '("Newsgroups" "Followup-To"))
5096 header error groups group)
5097 (while (and headers
5098 (not error))
5099 (when (setq header (mail-fetch-field (pop headers)))
5100 (setq groups (message-tokenize-header header ","))
5101 (while (setq group (pop groups))
5102 (when (member group groups)
5103 (setq error group
5104 groups nil)))))
5105 (if (not error)
5107 (y-or-n-p
5108 (format "Group %s is repeated in headers. Really post? " error)))))
5109 ;; Check the From header.
5110 (message-check 'from
5111 (let* ((case-fold-search t)
5112 (from (message-fetch-field "from"))
5114 (cond
5115 ((not from)
5116 (message "There is no From line. Posting is denied.")
5117 nil)
5118 ((or (not (string-match
5119 "@[^\\.]*\\."
5120 (setq ad (nth 1 (mail-extract-address-components
5121 from))))) ;larsi@ifi
5122 (string-match "\\.\\." ad) ;larsi@ifi..uio
5123 (string-match "@\\." ad) ;larsi@.ifi.uio
5124 (string-match "\\.$" ad) ;larsi@ifi.uio.
5125 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5126 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5127 (message
5128 "Denied posting -- the From looks strange: \"%s\"." from)
5129 nil)
5130 ((let ((addresses (rfc822-addresses from)))
5131 ;; `rfc822-addresses' returns a string if parsing fails.
5132 (while (and (consp addresses)
5133 (not (eq (string-to-char (car addresses)) ?\()))
5134 (setq addresses (cdr addresses)))
5135 addresses)
5136 (message
5137 "Denied posting -- bad From address: \"%s\"." from)
5138 nil)
5139 (t t))))
5140 ;; Check the Reply-To header.
5141 (message-check 'reply-to
5142 (let* ((case-fold-search t)
5143 (reply-to (message-fetch-field "reply-to"))
5145 (cond
5146 ((not reply-to)
5148 ((string-match "," reply-to)
5149 (y-or-n-p
5150 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5151 reply-to)))
5152 ((or (not (string-match
5153 "@[^\\.]*\\."
5154 (setq ad (nth 1 (mail-extract-address-components
5155 reply-to))))) ;larsi@ifi
5156 (string-match "\\.\\." ad) ;larsi@ifi..uio
5157 (string-match "@\\." ad) ;larsi@.ifi.uio
5158 (string-match "\\.$" ad) ;larsi@ifi.uio.
5159 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5160 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5161 (y-or-n-p
5162 (format
5163 "The Reply-To looks strange: \"%s\". Really post? "
5164 reply-to)))
5165 (t t))))))
5167 (defun message-check-news-body-syntax ()
5168 (and
5169 ;; Check for long lines.
5170 (message-check 'long-lines
5171 (goto-char (point-min))
5172 (re-search-forward
5173 (concat "^" (regexp-quote mail-header-separator) "$"))
5174 (forward-line 1)
5175 (while (and
5176 (or (looking-at
5177 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5178 (let ((p (point)))
5179 (end-of-line)
5180 (< (- (point) p) 80)))
5181 (zerop (forward-line 1))))
5182 (or (bolp)
5183 (eobp)
5184 (y-or-n-p
5185 "You have lines longer than 79 characters. Really post? ")))
5186 ;; Check whether the article is empty.
5187 (message-check 'empty
5188 (goto-char (point-min))
5189 (re-search-forward
5190 (concat "^" (regexp-quote mail-header-separator) "$"))
5191 (forward-line 1)
5192 (let ((b (point)))
5193 (goto-char (point-max))
5194 (re-search-backward message-signature-separator nil t)
5195 (beginning-of-line)
5196 (or (re-search-backward "[^ \n\t]" b t)
5197 (if (message-gnksa-enable-p 'empty-article)
5198 (y-or-n-p "Empty article. Really post? ")
5199 (message "Denied posting -- Empty article.")
5200 nil))))
5201 ;; Check for control characters.
5202 (message-check 'control-chars
5203 (if (re-search-forward
5204 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5205 nil t)
5206 (y-or-n-p
5207 "The article contains control characters. Really post? ")
5209 ;; Check excessive size.
5210 (message-check 'size
5211 (if (> (buffer-size) 60000)
5212 (y-or-n-p
5213 (format "The article is %d octets long. Really post? "
5214 (buffer-size)))
5216 ;; Check whether any new text has been added.
5217 (message-check 'new-text
5219 (not message-checksum)
5220 (not (eq (message-checksum) message-checksum))
5221 (if (message-gnksa-enable-p 'quoted-text-only)
5222 (y-or-n-p
5223 "It looks like no new text has been added. Really post? ")
5224 (message "Denied posting -- no new text has been added.")
5225 nil)))
5226 ;; Check the length of the signature.
5227 (message-check 'signature
5228 (let (sig-start sig-end)
5229 (goto-char (point-max))
5230 (if (not (re-search-backward message-signature-separator nil t))
5232 (setq sig-start (1+ (point-at-eol)))
5233 (setq sig-end
5234 (if (re-search-forward
5235 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5236 (- (point-at-bol) 1)
5237 (point-max)))
5238 (if (>= (count-lines sig-start sig-end) 5)
5239 (if (message-gnksa-enable-p 'signature)
5240 (y-or-n-p
5241 (format "Signature is excessively long (%d lines). Really post? "
5242 (count-lines sig-start sig-end)))
5243 (message "Denied posting -- Excessive signature.")
5244 nil)
5245 t))))
5246 ;; Ensure that text follows last quoted portion.
5247 (message-check 'quoting-style
5248 (goto-char (point-max))
5249 (let ((no-problem t))
5250 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5251 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5252 (if no-problem
5254 (if (message-gnksa-enable-p 'quoted-text-only)
5255 (y-or-n-p "Your text should follow quoted text. Really post? ")
5256 ;; Ensure that
5257 (goto-char (point-min))
5258 (re-search-forward
5259 (concat "^" (regexp-quote mail-header-separator) "$"))
5260 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5261 (y-or-n-p "Your text should follow quoted text. Really post? ")
5262 (message "Denied posting -- only quoted text.")
5263 nil)))))))
5265 (defun message-checksum ()
5266 "Return a \"checksum\" for the current buffer."
5267 (let ((sum 0))
5268 (save-excursion
5269 (goto-char (point-min))
5270 (re-search-forward
5271 (concat "^" (regexp-quote mail-header-separator) "$"))
5272 (while (not (eobp))
5273 (when (not (looking-at "[ \t\n]"))
5274 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5275 (char-after))))
5276 (forward-char 1)))
5277 sum))
5279 (defun message-do-fcc ()
5280 "Process Fcc headers in the current buffer."
5281 (let ((case-fold-search t)
5282 (buf (current-buffer))
5283 list file
5284 (mml-externalize-attachments message-fcc-externalize-attachments))
5285 (save-excursion
5286 (save-restriction
5287 (message-narrow-to-headers)
5288 (setq file (message-fetch-field "fcc" t)))
5289 (when file
5290 (set-buffer (get-buffer-create " *message temp*"))
5291 (erase-buffer)
5292 (insert-buffer-substring buf)
5293 (message-encode-message-body)
5294 (save-restriction
5295 (message-narrow-to-headers)
5296 (while (setq file (message-fetch-field "fcc" t))
5297 (push file list)
5298 (message-remove-header "fcc" nil t))
5299 (let ((mail-parse-charset message-default-charset)
5300 (rfc2047-header-encoding-alist
5301 (cons '("Newsgroups" . default)
5302 rfc2047-header-encoding-alist)))
5303 (mail-encode-encoded-word-buffer)))
5304 (goto-char (point-min))
5305 (when (re-search-forward
5306 (concat "^" (regexp-quote mail-header-separator) "$")
5307 nil t)
5308 (replace-match "" t t ))
5309 ;; Process FCC operations.
5310 (while list
5311 (setq file (pop list))
5312 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5313 ;; Pipe the article to the program in question.
5314 (call-process-region (point-min) (point-max) shell-file-name
5315 nil nil nil shell-command-switch
5316 (match-string 1 file))
5317 ;; Save the article.
5318 (setq file (expand-file-name file))
5319 (unless (file-exists-p (file-name-directory file))
5320 (make-directory (file-name-directory file) t))
5321 (if (and message-fcc-handler-function
5322 (not (eq message-fcc-handler-function 'rmail-output)))
5323 (funcall message-fcc-handler-function file)
5324 ;; FIXME this option, rmail-output (also used if
5325 ;; message-fcc-handler-function is nil) is not
5326 ;; documented anywhere AFAICS. It should work in Emacs
5327 ;; 23; I suspect it does not work in Emacs 22.
5328 ;; FIXME I don't see the need for the two different cases here.
5329 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5330 ;; the third argument just controls \"Wrote file\" message.
5331 (if (and (file-readable-p file) (mail-file-babyl-p file))
5332 (rmail-output file 1 nil t)
5333 (let ((mail-use-rfc822 t))
5334 (rmail-output file 1 t t))))))
5335 (kill-buffer (current-buffer))))))
5337 (defun message-output (filename)
5338 "Append this article to Unix/babyl mail file FILENAME."
5339 (if (and (file-readable-p filename)
5340 (mail-file-babyl-p filename))
5341 (gnus-output-to-rmail filename t)
5342 (gnus-output-to-mail filename t)))
5344 (defun message-cleanup-headers ()
5345 "Do various automatic cleanups of the headers."
5346 ;; Remove empty lines in the header.
5347 (save-restriction
5348 (message-narrow-to-headers)
5349 ;; Remove blank lines.
5350 (while (re-search-forward "^[ \t]*\n" nil t)
5351 (replace-match "" t t))
5353 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5354 ;; spaces to comma and eliminate spaces around commas. Eliminate
5355 ;; embedded line breaks.
5356 (goto-char (point-min))
5357 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5358 (save-restriction
5359 (narrow-to-region
5360 (point)
5361 (if (re-search-forward "^[^ \t]" nil t)
5362 (match-beginning 0)
5363 (forward-line 1)
5364 (point)))
5365 (goto-char (point-min))
5366 (while (re-search-forward "\n[ \t]+" nil t)
5367 (replace-match " " t t)) ;No line breaks (too confusing)
5368 (goto-char (point-min))
5369 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5370 (replace-match "," t t))
5371 (goto-char (point-min))
5372 ;; Remove trailing commas.
5373 (when (re-search-forward ",+$" nil t)
5374 (replace-match "" t t))))))
5376 (defun message-make-date (&optional now)
5377 "Make a valid data header.
5378 If NOW, use that time instead."
5379 (let ((system-time-locale "C"))
5380 (format-time-string "%a, %d %b %Y %T %z" now)))
5382 (defun message-insert-expires (days)
5383 "Insert the Expires header. Expiry in DAYS days."
5384 (interactive "NExpire article in how many days? ")
5385 (save-excursion
5386 (message-position-on-field "Expires" "X-Draft-From")
5387 (insert (message-make-expires-date days))))
5389 (defun message-make-expires-date (days)
5390 "Make date string for the Expires header. Expiry in DAYS days.
5392 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5393 (let* ((cur (decode-time (current-time)))
5394 (nday (+ days (nth 3 cur))))
5395 (setf (nth 3 cur) nday)
5396 (message-make-date (apply 'encode-time cur))))
5398 (defun message-make-message-id ()
5399 "Make a unique Message-ID."
5400 (concat "<" (message-unique-id)
5401 (let ((psubject (save-excursion (message-fetch-field "subject")))
5402 (psupersedes
5403 (save-excursion (message-fetch-field "supersedes"))))
5404 (if (or
5405 (and message-reply-headers
5406 (mail-header-references message-reply-headers)
5407 (mail-header-subject message-reply-headers)
5408 psubject
5409 (not (string=
5410 (message-strip-subject-re
5411 (mail-header-subject message-reply-headers))
5412 (message-strip-subject-re psubject))))
5413 (and psupersedes
5414 (string-match "_-_@" psupersedes)))
5415 "_-_" ""))
5416 "@" (message-make-fqdn) ">"))
5418 (defvar message-unique-id-char nil)
5420 ;; If you ever change this function, make sure the new version
5421 ;; cannot generate IDs that the old version could.
5422 ;; You might for example insert a "." somewhere (not next to another dot
5423 ;; or string boundary), or modify the "fsf" string.
5424 (defun message-unique-id ()
5425 ;; Don't use microseconds from (current-time), they may be unsupported.
5426 ;; Instead we use this randomly inited counter.
5427 (setq message-unique-id-char
5428 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5429 ;; (current-time) returns 16-bit ints,
5430 ;; and 2^16*25 just fits into 4 digits i base 36.
5431 (* 25 25)))
5432 (let ((tm (current-time)))
5433 (concat
5434 (if (or (memq system-type '(ms-dos emx))
5435 ;; message-number-base36 doesn't handle bigints.
5436 (floatp (user-uid)))
5437 (let ((user (downcase (user-login-name))))
5438 (while (string-match "[^a-z0-9_]" user)
5439 (aset user (match-beginning 0) ?_))
5440 user)
5441 (message-number-base36 (user-uid) -1))
5442 (message-number-base36 (+ (car tm)
5443 (lsh (% message-unique-id-char 25) 16)) 4)
5444 (message-number-base36 (+ (nth 1 tm)
5445 (lsh (/ message-unique-id-char 25) 16)) 4)
5446 ;; Append a given name, because while the generated ID is unique
5447 ;; to this newsreader, other newsreaders might otherwise generate
5448 ;; the same ID via another algorithm.
5449 ".fsf")))
5451 (defun message-number-base36 (num len)
5452 (if (if (< len 0)
5453 (<= num 0)
5454 (= len 0))
5456 (concat (message-number-base36 (/ num 36) (1- len))
5457 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5458 (% num 36))))))
5460 (defun message-make-organization ()
5461 "Make an Organization header."
5462 (let* ((organization
5463 (when message-user-organization
5464 (if (functionp message-user-organization)
5465 (funcall message-user-organization)
5466 message-user-organization))))
5467 (with-temp-buffer
5468 (mm-enable-multibyte)
5469 (cond ((stringp organization)
5470 (insert organization))
5471 ((and (eq t organization)
5472 message-user-organization-file
5473 (file-exists-p message-user-organization-file))
5474 (insert-file-contents message-user-organization-file)))
5475 (goto-char (point-min))
5476 (while (re-search-forward "[\t\n]+" nil t)
5477 (replace-match "" t t))
5478 (unless (zerop (buffer-size))
5479 (buffer-string)))))
5481 (defun message-make-lines ()
5482 "Count the number of lines and return numeric string."
5483 (save-excursion
5484 (save-restriction
5485 (widen)
5486 (message-goto-body)
5487 (int-to-string (count-lines (point) (point-max))))))
5489 (defun message-make-references ()
5490 "Return the References header for this message."
5491 (when message-reply-headers
5492 (let ((message-id (mail-header-id message-reply-headers))
5493 (references (mail-header-references message-reply-headers)))
5494 (if (or references message-id)
5495 (concat (or references "") (and references " ")
5496 (or message-id ""))
5497 nil))))
5499 (defun message-make-in-reply-to ()
5500 "Return the In-Reply-To header for this message."
5501 (when message-reply-headers
5502 (let ((from (mail-header-from message-reply-headers))
5503 (date (mail-header-date message-reply-headers))
5504 (msg-id (mail-header-id message-reply-headers)))
5505 (when from
5506 (let ((name (mail-extract-address-components from)))
5507 (concat
5508 msg-id (if msg-id " (")
5509 (if (car name)
5510 (if (string-match "[^\000-\177]" (car name))
5511 ;; Quote a string containing non-ASCII characters.
5512 ;; It will make the RFC2047 encoder cause an error
5513 ;; if there are special characters.
5514 (mm-with-multibyte-buffer
5515 (insert (car name))
5516 (goto-char (point-min))
5517 (while (search-forward "\"" nil t)
5518 (when (prog2
5519 (backward-char)
5520 (zerop (% (skip-chars-backward "\\\\") 2))
5521 (goto-char (match-beginning 0)))
5522 (insert "\\"))
5523 (forward-char))
5524 ;; Those quotes will be removed by the RFC2047 encoder.
5525 (concat "\"" (buffer-string) "\""))
5526 (car name))
5527 (nth 1 name))
5528 "'s message of \""
5529 (if (or (not date) (string= date ""))
5530 "(unknown date)" date)
5531 "\"" (if msg-id ")")))))))
5533 (defun message-make-distribution ()
5534 "Make a Distribution header."
5535 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5536 (cond ((functionp message-distribution-function)
5537 (funcall message-distribution-function))
5538 (t orig-distribution))))
5540 (defun message-make-expires ()
5541 "Return an Expires header based on `message-expires'."
5542 (let ((current (current-time))
5543 (future (* 1.0 message-expires 60 60 24)))
5544 ;; Add the future to current.
5545 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5546 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5547 (message-make-date current)))
5549 (defun message-make-path ()
5550 "Return uucp path."
5551 (let ((login-name (user-login-name)))
5552 (cond ((null message-user-path)
5553 (concat (system-name) "!" login-name))
5554 ((stringp message-user-path)
5555 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5556 (concat message-user-path "!" login-name))
5557 (t login-name))))
5559 (defun message-make-from (&optional name address)
5560 "Make a From header."
5561 (let* ((style message-from-style)
5562 (login (or address (message-make-address)))
5563 (fullname (or name
5564 (and (boundp 'user-full-name)
5565 user-full-name)
5566 (user-full-name))))
5567 (when (string= fullname "&")
5568 (setq fullname (user-login-name)))
5569 (with-temp-buffer
5570 (mm-enable-multibyte)
5571 (cond
5572 ((or (null style)
5573 (equal fullname ""))
5574 (insert login))
5575 ((or (eq style 'angles)
5576 (and (not (eq style 'parens))
5577 ;; Use angles if no quoting is needed, or if parens would
5578 ;; need quoting too.
5579 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5580 (let ((tmp (concat fullname nil)))
5581 (while (string-match "([^()]*)" tmp)
5582 (aset tmp (match-beginning 0) ?-)
5583 (aset tmp (1- (match-end 0)) ?-))
5584 (string-match "[\\()]" tmp)))))
5585 (insert fullname)
5586 (goto-char (point-min))
5587 ;; Look for a character that cannot appear unquoted
5588 ;; according to RFC 822.
5589 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5590 ;; Quote fullname, escaping specials.
5591 (goto-char (point-min))
5592 (insert "\"")
5593 (while (re-search-forward "[\"\\]" nil 1)
5594 (replace-match "\\\\\\&" t))
5595 (insert "\""))
5596 (insert " <" login ">"))
5597 (t ; 'parens or default
5598 (insert login " (")
5599 (let ((fullname-start (point)))
5600 (insert fullname)
5601 (goto-char fullname-start)
5602 ;; RFC 822 says \ and nonmatching parentheses
5603 ;; must be escaped in comments.
5604 ;; Escape every instance of ()\ ...
5605 (while (re-search-forward "[()\\]" nil 1)
5606 (replace-match "\\\\\\&" t))
5607 ;; ... then undo escaping of matching parentheses,
5608 ;; including matching nested parentheses.
5609 (goto-char fullname-start)
5610 (while (re-search-forward
5611 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5612 nil 1)
5613 (replace-match "\\1(\\3)" t)
5614 (goto-char fullname-start)))
5615 (insert ")")))
5616 (buffer-string))))
5618 (defun message-make-sender ()
5619 "Return the \"real\" user address.
5620 This function tries to ignore all user modifications, and
5621 give as trustworthy answer as possible."
5622 (concat (user-login-name) "@" (system-name)))
5624 (defun message-make-address ()
5625 "Make the address of the user."
5626 (or (message-user-mail-address)
5627 (concat (user-login-name) "@" (message-make-domain))))
5629 (defun message-user-mail-address ()
5630 "Return the pertinent part of `user-mail-address'."
5631 (when (and user-mail-address
5632 (string-match "@.*\\." user-mail-address))
5633 (if (string-match " " user-mail-address)
5634 (nth 1 (mail-extract-address-components user-mail-address))
5635 user-mail-address)))
5637 (defun message-sendmail-envelope-from ()
5638 "Return the envelope from."
5639 (cond ((eq message-sendmail-envelope-from 'header)
5640 (nth 1 (mail-extract-address-components
5641 (message-fetch-field "from"))))
5642 ((stringp message-sendmail-envelope-from)
5643 message-sendmail-envelope-from)
5645 (message-make-address))))
5647 (defun message-make-fqdn ()
5648 "Return user's fully qualified domain name."
5649 (let* ((system-name (system-name))
5650 (user-mail (message-user-mail-address))
5651 (user-domain
5652 (if (and user-mail
5653 (string-match "@\\(.*\\)\\'" user-mail))
5654 (match-string 1 user-mail)))
5655 (case-fold-search t))
5656 (cond
5657 ((and message-user-fqdn
5658 (stringp message-user-fqdn)
5659 (string-match message-valid-fqdn-regexp message-user-fqdn)
5660 (not (string-match message-bogus-system-names message-user-fqdn)))
5661 ;; `message-user-fqdn' seems to be valid
5662 message-user-fqdn)
5663 ((and (string-match message-valid-fqdn-regexp system-name)
5664 (not (string-match message-bogus-system-names system-name)))
5665 ;; `system-name' returned the right result.
5666 system-name)
5667 ;; Try `mail-host-address'.
5668 ((and (boundp 'mail-host-address)
5669 (stringp mail-host-address)
5670 (string-match message-valid-fqdn-regexp mail-host-address)
5671 (not (string-match message-bogus-system-names mail-host-address)))
5672 mail-host-address)
5673 ;; We try `user-mail-address' as a backup.
5674 ((and user-domain
5675 (stringp user-domain)
5676 (string-match message-valid-fqdn-regexp user-domain)
5677 (not (string-match message-bogus-system-names user-domain)))
5678 user-domain)
5679 ;; Default to this bogus thing.
5681 (concat system-name
5682 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5684 (defun message-make-host-name ()
5685 "Return the name of the host."
5686 (let ((fqdn (message-make-fqdn)))
5687 (string-match "^[^.]+\\." fqdn)
5688 (substring fqdn 0 (1- (match-end 0)))))
5690 (defun message-make-domain ()
5691 "Return the domain name."
5692 (or mail-host-address
5693 (message-make-fqdn)))
5695 (defun message-to-list-only ()
5696 "Send a message to the list only.
5697 Remove all addresses but the list address from To and Cc headers."
5698 (interactive)
5699 (let ((listaddr (message-make-mail-followup-to t)))
5700 (when listaddr
5701 (save-excursion
5702 (message-remove-header "to")
5703 (message-remove-header "cc")
5704 (message-position-on-field "To" "X-Draft-From")
5705 (insert listaddr)))))
5707 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5708 "Return the Mail-Followup-To header.
5709 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5710 subscribed address (and not the additional To and Cc header contents)."
5711 (let* ((case-fold-search t)
5712 (to (message-fetch-field "To"))
5713 (cc (message-fetch-field "cc"))
5714 (msg-recipients (concat to (and to cc ", ") cc))
5715 (recipients
5716 (mapcar 'mail-strip-quoted-names
5717 (message-tokenize-header msg-recipients)))
5718 (file-regexps
5719 (if message-subscribed-address-file
5720 (let (begin end item re)
5721 (save-excursion
5722 (with-temp-buffer
5723 (insert-file-contents message-subscribed-address-file)
5724 (while (not (eobp))
5725 (setq begin (point))
5726 (forward-line 1)
5727 (setq end (point))
5728 (if (bolp) (setq end (1- end)))
5729 (setq item (regexp-quote (buffer-substring begin end)))
5730 (if re (setq re (concat re "\\|" item))
5731 (setq re (concat "\\`\\(" item))))
5732 (and re (list (concat re "\\)\\'"))))))))
5733 (mft-regexps (apply 'append message-subscribed-regexps
5734 (mapcar 'regexp-quote
5735 message-subscribed-addresses)
5736 file-regexps
5737 (mapcar 'funcall
5738 message-subscribed-address-functions))))
5739 (save-match-data
5740 (let ((list
5741 (loop for recipient in recipients
5742 when (loop for regexp in mft-regexps
5743 when (string-match regexp recipient) return t)
5744 return recipient)))
5745 (when list
5746 (if only-show-subscribed
5747 list
5748 msg-recipients))))))
5750 (defun message-idna-to-ascii-rhs-1 (header)
5751 "Interactively potentially IDNA encode domain names in HEADER."
5752 (let ((field (message-fetch-field header))
5753 rhs ace address)
5754 (when field
5755 (dolist (rhs
5756 (mm-delete-duplicates
5757 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5758 (mapcar 'downcase
5759 (mapcar
5760 'cadr
5761 (mail-extract-address-components field t))))))
5762 ;; Note that `rhs' will be "" if the address does not have
5763 ;; the domain part, i.e., if it is a local user's address.
5764 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5766 (downcase (idna-to-ascii rhs))))
5767 (when (and (not (equal rhs ace))
5768 (or (not (eq message-use-idna 'ask))
5769 (y-or-n-p (format "Replace %s with %s in %s:? "
5770 rhs ace header))))
5771 (goto-char (point-min))
5772 (while (re-search-forward (concat "^" header ":") nil t)
5773 (message-narrow-to-field)
5774 (while (search-forward (concat "@" rhs) nil t)
5775 (replace-match (concat "@" ace) t t))
5776 (goto-char (point-max))
5777 (widen)))))))
5779 (defun message-idna-to-ascii-rhs ()
5780 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5781 See `message-idna-encode'."
5782 (interactive)
5783 (when message-use-idna
5784 (save-excursion
5785 (save-restriction
5786 ;; `message-narrow-to-head' that recognizes only the first empty
5787 ;; line as the message header separator used to be used here.
5788 ;; However, since there is the "--text follows this line--" line
5789 ;; normally, it failed in narrowing to the headers and potentially
5790 ;; caused the IDNA encoding on lines that look like headers in
5791 ;; the message body.
5792 (message-narrow-to-headers-or-head)
5793 (message-idna-to-ascii-rhs-1 "From")
5794 (message-idna-to-ascii-rhs-1 "To")
5795 (message-idna-to-ascii-rhs-1 "Reply-To")
5796 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5797 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5798 (message-idna-to-ascii-rhs-1 "Cc")))))
5800 (defun message-generate-headers (headers)
5801 "Prepare article HEADERS.
5802 Headers already prepared in the buffer are not modified."
5803 (setq headers (append headers message-required-headers))
5804 (save-restriction
5805 (message-narrow-to-headers)
5806 (let* ((Date (message-make-date))
5807 (Message-ID (message-make-message-id))
5808 (Organization (message-make-organization))
5809 (From (message-make-from))
5810 (Path (message-make-path))
5811 (Subject nil)
5812 (Newsgroups nil)
5813 (In-Reply-To (message-make-in-reply-to))
5814 (References (message-make-references))
5815 (To nil)
5816 (Distribution (message-make-distribution))
5817 (Lines (message-make-lines))
5818 (User-Agent message-newsreader)
5819 (Expires (message-make-expires))
5820 (case-fold-search t)
5821 (optionalp nil)
5822 header value elem header-string)
5823 ;; First we remove any old generated headers.
5824 (let ((headers message-deletable-headers))
5825 (unless (buffer-modified-p)
5826 (setq headers (delq 'Message-ID (copy-sequence headers))))
5827 (while headers
5828 (goto-char (point-min))
5829 (and (re-search-forward
5830 (concat "^" (symbol-name (car headers)) ": *") nil t)
5831 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5832 (message-delete-line))
5833 (pop headers)))
5834 ;; Go through all the required headers and see if they are in the
5835 ;; articles already. If they are not, or are empty, they are
5836 ;; inserted automatically - except for Subject, Newsgroups and
5837 ;; Distribution.
5838 (while headers
5839 (goto-char (point-min))
5840 (setq elem (pop headers))
5841 (if (consp elem)
5842 (if (eq (car elem) 'optional)
5843 (setq header (cdr elem)
5844 optionalp t)
5845 (setq header (car elem)))
5846 (setq header elem))
5847 (setq header-string (if (stringp header)
5848 header
5849 (symbol-name header)))
5850 (when (or (not (re-search-forward
5851 (concat "^"
5852 (regexp-quote (downcase header-string))
5853 ":")
5854 nil t))
5855 (progn
5856 ;; The header was found. We insert a space after the
5857 ;; colon, if there is none.
5858 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5859 ;; Find out whether the header is empty.
5860 (looking-at "[ \t]*\n[^ \t]")))
5861 ;; So we find out what value we should insert.
5862 (setq value
5863 (cond
5864 ((and (consp elem)
5865 (eq (car elem) 'optional)
5866 (not (member header-string message-inserted-headers)))
5867 ;; This is an optional header. If the cdr of this
5868 ;; is something that is nil, then we do not insert
5869 ;; this header.
5870 (setq header (cdr elem))
5871 (or (and (functionp (cdr elem))
5872 (funcall (cdr elem)))
5873 (and (boundp (cdr elem))
5874 (symbol-value (cdr elem)))))
5875 ((consp elem)
5876 ;; The element is a cons. Either the cdr is a
5877 ;; string to be inserted verbatim, or it is a
5878 ;; function, and we insert the value returned from
5879 ;; this function.
5880 (or (and (stringp (cdr elem))
5881 (cdr elem))
5882 (and (functionp (cdr elem))
5883 (funcall (cdr elem)))))
5884 ((and (boundp header)
5885 (symbol-value header))
5886 ;; The element is a symbol. We insert the value
5887 ;; of this symbol, if any.
5888 (symbol-value header))
5889 ((not (message-check-element
5890 (intern (downcase (symbol-name header)))))
5891 ;; We couldn't generate a value for this header,
5892 ;; so we just ask the user.
5893 (read-from-minibuffer
5894 (format "Empty header for %s; enter value: " header)))))
5895 ;; Finally insert the header.
5896 (when (and value
5897 (not (equal value "")))
5898 (save-excursion
5899 (if (bolp)
5900 (progn
5901 ;; This header didn't exist, so we insert it.
5902 (goto-char (point-max))
5903 (let ((formatter
5904 (cdr (assq header message-header-format-alist))))
5905 (if formatter
5906 (funcall formatter header value)
5907 (insert header-string ": " value))
5908 (goto-char (message-fill-field))
5909 ;; We check whether the value was ended by a
5910 ;; newline. If not, we insert one.
5911 (unless (bolp)
5912 (insert "\n"))
5913 (forward-line -1)))
5914 ;; The value of this header was empty, so we clear
5915 ;; totally and insert the new value.
5916 (delete-region (point) (point-at-eol))
5917 ;; If the header is optional, and the header was
5918 ;; empty, we can't insert it anyway.
5919 (unless optionalp
5920 (push header-string message-inserted-headers)
5921 (insert value)
5922 (message-fill-field)))
5923 ;; Add the deletable property to the headers that require it.
5924 (and (memq header message-deletable-headers)
5925 (progn (beginning-of-line) (looking-at "[^:]+: "))
5926 (add-text-properties
5927 (point) (match-end 0)
5928 '(message-deletable t face italic) (current-buffer)))))))
5929 ;; Insert new Sender if the From is strange.
5930 (let ((from (message-fetch-field "from"))
5931 (sender (message-fetch-field "sender"))
5932 (secure-sender (message-make-sender)))
5933 (when (and from
5934 (not (message-check-element 'sender))
5935 (not (string=
5936 (downcase
5937 (cadr (mail-extract-address-components from)))
5938 (downcase secure-sender)))
5939 (or (null sender)
5940 (not
5941 (string=
5942 (downcase
5943 (cadr (mail-extract-address-components sender)))
5944 (downcase secure-sender)))))
5945 (goto-char (point-min))
5946 ;; Rename any old Sender headers to Original-Sender.
5947 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5948 (beginning-of-line)
5949 (insert "Original-")
5950 (beginning-of-line))
5951 (when (or (message-news-p)
5952 (string-match "@.+\\.." secure-sender))
5953 (insert "Sender: " secure-sender "\n"))))
5954 ;; Check for IDNA
5955 (message-idna-to-ascii-rhs))))
5957 (defun message-insert-courtesy-copy ()
5958 "Insert a courtesy message in mail copies of combined messages."
5959 (let (newsgroups)
5960 (save-excursion
5961 (save-restriction
5962 (message-narrow-to-headers)
5963 (when (setq newsgroups (message-fetch-field "newsgroups"))
5964 (goto-char (point-max))
5965 (insert "Posted-To: " newsgroups "\n")))
5966 (forward-line 1)
5967 (when message-courtesy-message
5968 (cond
5969 ((string-match "%s" message-courtesy-message)
5970 (insert (format message-courtesy-message newsgroups)))
5972 (insert message-courtesy-message)))))))
5975 ;;; Setting up a message buffer
5978 (defun message-skip-to-next-address ()
5979 (let ((end (save-excursion
5980 (message-next-header)
5981 (point)))
5982 quoted char)
5983 (when (looking-at ",")
5984 (forward-char 1))
5985 (while (and (not (= (point) end))
5986 (or (not (eq char ?,))
5987 quoted))
5988 (skip-chars-forward "^,\"" (point-max))
5989 (when (eq (setq char (following-char)) ?\")
5990 (setq quoted (not quoted)))
5991 (unless (= (point) end)
5992 (forward-char 1)))
5993 (skip-chars-forward " \t\n")))
5995 (defun message-fill-address (header value)
5996 (insert (capitalize (symbol-name header))
5997 ": "
5998 (if (consp value) (car value) value)
5999 "\n")
6000 (message-fill-field-address))
6002 (defun message-split-line ()
6003 "Split current line, moving portion beyond point vertically down.
6004 If the current line has `message-yank-prefix', insert it on the new line."
6005 (interactive "*")
6006 (condition-case nil
6007 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6008 (error
6009 (split-line))))
6011 (defun message-insert-header (header value)
6012 (insert (capitalize (symbol-name header))
6013 ": "
6014 (if (consp value) (car value) value)))
6016 (defun message-field-name ()
6017 (save-excursion
6018 (goto-char (point-min))
6019 (when (looking-at "\\([^:]+\\):")
6020 (intern (capitalize (match-string 1))))))
6022 (defun message-fill-field ()
6023 (save-excursion
6024 (save-restriction
6025 (message-narrow-to-field)
6026 (let ((field-name (message-field-name)))
6027 (funcall (or (cadr (assq field-name message-field-fillers))
6028 'message-fill-field-general)))
6029 (point-max))))
6031 (defun message-fill-field-address ()
6032 (while (not (eobp))
6033 (message-skip-to-next-address)
6034 (let (last)
6035 (if (and (> (current-column) 78)
6036 last)
6037 (progn
6038 (save-excursion
6039 (goto-char last)
6040 (insert "\n\t"))
6041 (setq last (1+ (point))))
6042 (setq last (1+ (point)))))))
6044 (defun message-fill-field-general ()
6045 (let ((begin (point))
6046 (fill-column 78)
6047 (fill-prefix "\t"))
6048 (while (and (search-forward "\n" nil t)
6049 (not (eobp)))
6050 (replace-match " " t t))
6051 (fill-region-as-paragraph begin (point-max))
6052 ;; Tapdance around looong Message-IDs.
6053 (forward-line -1)
6054 (when (looking-at "[ \t]*$")
6055 (message-delete-line))
6056 (goto-char begin)
6057 (search-forward ":" nil t)
6058 (when (looking-at "\n[ \t]+")
6059 (replace-match " " t t))
6060 (goto-char (point-max))))
6062 (defun message-shorten-1 (list cut surplus)
6063 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6064 (setcdr (nthcdr (- cut 2) list)
6065 (nthcdr (+ (- cut 2) surplus 1) list)))
6067 (defun message-shorten-references (header references)
6068 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6069 When sending via news, also check that the REFERENCES are less
6070 than 988 characters long, and if they are not, trim them until
6071 they are."
6072 (let ((maxcount 21)
6073 (count 0)
6074 (cut 2)
6075 refs)
6076 (with-temp-buffer
6077 (insert references)
6078 (goto-char (point-min))
6079 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6080 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6081 ;; Message-IDs in original References").
6082 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6083 (push (match-string 0) refs))
6084 (setq refs (nreverse refs)
6085 count (length refs)))
6087 ;; If the list has more than MAXCOUNT elements, trim it by
6088 ;; removing the CUTth element and the required number of
6089 ;; elements that follow.
6090 (when (> count maxcount)
6091 (let ((surplus (- count maxcount)))
6092 (message-shorten-1 refs cut surplus)
6093 (decf count surplus)))
6095 ;; When sending via news, make sure the total folded length will
6096 ;; be less than 998 characters. This is to cater to broken INN
6097 ;; 2.3 which counts the total number of characters in a header
6098 ;; rather than the physical line length of each line, as it should.
6100 ;; This hack should be removed when it's believed than INN 2.3 is
6101 ;; no longer widely used.
6103 ;; At this point the headers have not been generated, thus we use
6104 ;; message-this-is-news directly.
6105 (when message-this-is-news
6106 (while (< 998
6107 (with-temp-buffer
6108 (message-insert-header
6109 header (mapconcat #'identity refs " "))
6110 (buffer-size)))
6111 (message-shorten-1 refs cut 1)))
6112 ;; Finally, collect the references back into a string and insert
6113 ;; it into the buffer.
6114 (message-insert-header header (mapconcat #'identity refs " "))))
6116 (defun message-position-point ()
6117 "Move point to where the user probably wants to find it."
6118 (message-narrow-to-headers)
6119 (cond
6120 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6121 (search-backward ":" )
6122 (widen)
6123 (forward-char 1)
6124 (if (eq (char-after) ? )
6125 (forward-char 1)
6126 (insert " ")))
6128 (goto-char (point-max))
6129 (widen)
6130 (forward-line 1)
6131 (unless (looking-at "$")
6132 (forward-line 2)))
6133 (sit-for 0)))
6135 (defcustom message-beginning-of-line t
6136 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6137 goes to beginning of header values."
6138 :version "22.1"
6139 :group 'message-buffers
6140 :link '(custom-manual "(message)Movement")
6141 :type 'boolean)
6143 (defun message-beginning-of-line (&optional n)
6144 "Move point to beginning of header value or to beginning of line.
6145 The prefix argument N is passed directly to `beginning-of-line'.
6147 This command is identical to `beginning-of-line' if point is
6148 outside the message header or if the option `message-beginning-of-line'
6149 is nil.
6151 If point is in the message header and on a (non-continued) header
6152 line, move point to the beginning of the header value or the beginning of line,
6153 whichever is closer. If point is already at beginning of line, move point to
6154 beginning of header value. Therefore, repeated calls will toggle point
6155 between beginning of field and beginning of line."
6156 (interactive "p")
6157 (let ((zrs 'zmacs-region-stays))
6158 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6159 (set zrs t)))
6160 (if (and message-beginning-of-line
6161 (message-point-in-header-p))
6162 (let* ((here (point))
6163 (bol (progn (beginning-of-line n) (point)))
6164 (eol (point-at-eol))
6165 (eoh (re-search-forward ": *" eol t)))
6166 (goto-char
6167 (if (and eoh (or (< eoh here) (= bol here)))
6168 eoh bol)))
6169 (beginning-of-line n)))
6171 (defun message-buffer-name (type &optional to group)
6172 "Return a new (unique) buffer name based on TYPE and TO."
6173 (cond
6174 ;; Generate a new buffer name The Message Way.
6175 ((memq message-generate-new-buffers '(unique t))
6176 (generate-new-buffer-name
6177 (concat "*" type
6178 (if to
6179 (concat " to "
6180 (or (car (mail-extract-address-components to))
6181 to) "")
6183 (if (and group (not (string= group ""))) (concat " on " group) "")
6184 "*")))
6185 ;; Check whether `message-generate-new-buffers' is a function,
6186 ;; and if so, call it.
6187 ((functionp message-generate-new-buffers)
6188 (funcall message-generate-new-buffers type to group))
6189 ((eq message-generate-new-buffers 'unsent)
6190 (generate-new-buffer-name
6191 (concat "*unsent " type
6192 (if to
6193 (concat " to "
6194 (or (car (mail-extract-address-components to))
6195 to) "")
6197 (if (and group (not (string= group ""))) (concat " on " group) "")
6198 "*")))
6199 ;; Search for the existing message buffer with the specified name.
6201 (let* ((new (if (eq message-generate-new-buffers 'standard)
6202 (generate-new-buffer-name (concat "*" type " message*"))
6203 (let ((message-generate-new-buffers 'unique))
6204 (message-buffer-name type to group))))
6205 (regexp (concat "\\`"
6206 (regexp-quote
6207 (if (string-match "<[0-9]+>\\'" new)
6208 (substring new 0 (match-beginning 0))
6209 new))
6210 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6211 (case-fold-search nil))
6212 (or (cdar
6213 (last
6214 (sort
6215 (delq nil
6216 (mapcar
6217 (lambda (b)
6218 (when (and (string-match regexp (setq b (buffer-name b)))
6219 (eq (with-current-buffer b major-mode)
6220 'message-mode))
6221 (cons (string-to-number (or (match-string 1 b) "1"))
6222 b)))
6223 (buffer-list)))
6224 'car-less-than-car)))
6225 new)))))
6227 (defun message-pop-to-buffer (name &optional switch-function)
6228 "Pop to buffer NAME, and warn if it already exists and is modified."
6229 (let ((buffer (get-buffer name)))
6230 (if (and buffer
6231 (buffer-name buffer))
6232 (let ((window (get-buffer-window buffer 0)))
6233 (if window
6234 ;; Raise the frame already displaying the message buffer.
6235 (progn
6236 (gnus-select-frame-set-input-focus (window-frame window))
6237 (select-window window))
6238 (funcall (or switch-function 'pop-to-buffer) buffer)
6239 (set-buffer buffer))
6240 (when (and (buffer-modified-p)
6241 (not (prog1
6242 (y-or-n-p
6243 "Message already being composed; erase? ")
6244 (message nil))))
6245 (error "Message being composed")))
6246 (funcall (or switch-function 'pop-to-buffer) name)
6247 (set-buffer name))
6248 (erase-buffer)
6249 (message-mode)))
6251 (defun message-do-send-housekeeping ()
6252 "Kill old message buffers."
6253 ;; We might have sent this buffer already. Delete it from the
6254 ;; list of buffers.
6255 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6256 (while (and message-max-buffers
6257 message-buffer-list
6258 (>= (length message-buffer-list) message-max-buffers))
6259 ;; Kill the oldest buffer -- unless it has been changed.
6260 (let ((buffer (pop message-buffer-list)))
6261 (when (and (buffer-name buffer)
6262 (not (buffer-modified-p buffer)))
6263 (kill-buffer buffer))))
6264 ;; Rename the buffer.
6265 (if message-send-rename-function
6266 (funcall message-send-rename-function)
6267 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6268 (when (string-match
6269 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6270 (buffer-name))
6271 (let ((name (match-string 2 (buffer-name)))
6272 to group)
6273 (if (not (or (null name)
6274 (string-equal name "mail")
6275 (string-equal name "posting")))
6276 (setq name (concat "*sent " name "*"))
6277 (message-narrow-to-headers)
6278 (setq to (message-fetch-field "to"))
6279 (setq group (message-fetch-field "newsgroups"))
6280 (widen)
6281 (setq name
6282 (cond
6283 (to (concat "*sent mail to "
6284 (or (car (mail-extract-address-components to))
6285 to) "*"))
6286 ((and group (not (string= group "")))
6287 (concat "*sent posting on " group "*"))
6288 (t "*sent mail*"))))
6289 (unless (string-equal name (buffer-name))
6290 (rename-buffer name t)))))
6291 ;; Push the current buffer onto the list.
6292 (when message-max-buffers
6293 (setq message-buffer-list
6294 (nconc message-buffer-list (list (current-buffer))))))
6296 (defun message-mail-user-agent ()
6297 (let ((mua (cond
6298 ((not message-mail-user-agent) nil)
6299 ((eq message-mail-user-agent t) mail-user-agent)
6300 (t message-mail-user-agent))))
6301 (if (memq mua '(message-user-agent gnus-user-agent))
6303 mua)))
6305 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6306 ;; form (FUNCTION . ARGS).
6307 (defun message-setup (headers &optional yank-action actions
6308 continue switch-function)
6309 (let ((mua (message-mail-user-agent))
6310 subject to field)
6311 (if (not (and message-this-is-mail mua))
6312 (message-setup-1 headers yank-action actions)
6313 (setq headers (copy-sequence headers))
6314 (setq field (assq 'Subject headers))
6315 (when field
6316 (setq subject (cdr field))
6317 (setq headers (delq field headers)))
6318 (setq field (assq 'To headers))
6319 (when field
6320 (setq to (cdr field))
6321 (setq headers (delq field headers)))
6322 (let ((mail-user-agent mua))
6323 (compose-mail to subject
6324 (mapcar (lambda (item)
6325 (cons
6326 (format "%s" (car item))
6327 (cdr item)))
6328 headers)
6329 continue switch-function
6330 (if (bufferp yank-action)
6331 (list 'insert-buffer yank-action)
6332 yank-action)
6333 actions)))))
6335 (defun message-headers-to-generate (headers included-headers excluded-headers)
6336 "Return a list that includes all headers from HEADERS.
6337 If INCLUDED-HEADERS is a list, just include those headers. If it is
6338 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6339 are not included."
6340 (let ((result nil)
6341 header-name)
6342 (dolist (header headers)
6343 (setq header-name (cond
6344 ((and (consp header)
6345 (eq (car header) 'optional))
6346 ;; On the form (optional . Header)
6347 (cdr header))
6348 ((consp header)
6349 ;; On the form (Header . function)
6350 (car header))
6352 ;; Just a Header.
6353 header)))
6354 (when (and (not (memq header-name excluded-headers))
6355 (or (eq included-headers t)
6356 (memq header-name included-headers)))
6357 (push header result)))
6358 (nreverse result)))
6360 (defun message-setup-1 (headers &optional yank-action actions)
6361 (dolist (action actions)
6362 (condition-case nil
6363 (add-to-list 'message-send-actions
6364 `(apply ',(car action) ',(cdr action)))))
6365 (setq message-reply-buffer
6366 (if (and (consp yank-action)
6367 (eq (car yank-action) 'insert-buffer))
6368 (nth 1 yank-action)
6369 yank-action))
6370 (goto-char (point-min))
6371 ;; Insert all the headers.
6372 (mail-header-format
6373 (let ((h headers)
6374 (alist message-header-format-alist))
6375 (while h
6376 (unless (assq (caar h) message-header-format-alist)
6377 (push (list (caar h)) alist))
6378 (pop h))
6379 alist)
6380 headers)
6381 (delete-region (point) (progn (forward-line -1) (point)))
6382 (when message-default-headers
6383 (insert message-default-headers)
6384 (or (bolp) (insert ?\n)))
6385 (insert mail-header-separator "\n")
6386 (forward-line -1)
6387 (when (message-news-p)
6388 (when message-default-news-headers
6389 (insert message-default-news-headers)
6390 (or (bolp) (insert ?\n)))
6391 (when message-generate-headers-first
6392 (message-generate-headers
6393 (message-headers-to-generate
6394 (append message-required-news-headers
6395 message-required-headers)
6396 message-generate-headers-first
6397 '(Lines Subject)))))
6398 (when (message-mail-p)
6399 (when message-default-mail-headers
6400 (insert message-default-mail-headers)
6401 (or (bolp) (insert ?\n)))
6402 (when message-generate-headers-first
6403 (message-generate-headers
6404 (message-headers-to-generate
6405 (append message-required-mail-headers
6406 message-required-headers)
6407 message-generate-headers-first
6408 '(Lines Subject)))))
6409 (run-hooks 'message-signature-setup-hook)
6410 (message-insert-signature)
6411 (save-restriction
6412 (message-narrow-to-headers)
6413 (run-hooks 'message-header-setup-hook))
6414 (setq buffer-undo-list nil)
6415 (when message-generate-hashcash
6416 ;; Generate hashcash headers for recipients already known
6417 (mail-add-payment-async))
6418 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6419 ;; values.
6420 (run-hooks 'message-setup-hook)
6421 ;; Do this last to give it precedence over posting styles, etc.
6422 (when (message-mail-p)
6423 (save-restriction
6424 (message-narrow-to-headers)
6425 (if message-alternative-emails
6426 (message-use-alternative-email-as-from))))
6427 (message-position-point)
6428 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6429 (set-buffer-modified-p nil)
6430 (undo-boundary))
6432 (defun message-set-auto-save-file-name ()
6433 "Associate the message buffer with a file in the drafts directory."
6434 (when message-auto-save-directory
6435 (unless (file-directory-p
6436 (directory-file-name message-auto-save-directory))
6437 (make-directory message-auto-save-directory t))
6438 (if (gnus-alive-p)
6439 (setq message-draft-article
6440 (nndraft-request-associate-buffer "drafts"))
6442 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6443 ;; But Gnus is not alive, so arrange to save the draft message in a
6444 ;; regular file in message-auto-save-directory. Append a unique
6445 ;; time-based suffix to the filename to allow multiple drafts to be saved
6446 ;; simultaneously without overwriting each other (which mimics the
6447 ;; functionality of the Gnus drafts folder).
6448 (setq buffer-file-name (expand-file-name
6449 (concat
6450 (if (memq system-type
6451 '(ms-dos ms-windows windows-nt
6452 cygwin cygwin32 win32 w32
6453 mswindows))
6454 "message"
6455 "*message*")
6456 (format-time-string "-%Y%m%d-%H%M%S"))
6457 message-auto-save-directory))
6458 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6459 (clear-visited-file-modtime)
6460 (setq buffer-file-coding-system message-draft-coding-system)))
6462 (defun message-disassociate-draft ()
6463 "Disassociate the message buffer from the drafts directory."
6464 (when message-draft-article
6465 (nndraft-request-expire-articles
6466 (list message-draft-article) "drafts" nil t)))
6468 (defun message-insert-headers ()
6469 "Generate the headers for the article."
6470 (interactive)
6471 (save-excursion
6472 (save-restriction
6473 (message-narrow-to-headers)
6474 (when (message-news-p)
6475 (message-generate-headers
6476 (delq 'Lines
6477 (delq 'Subject
6478 (copy-sequence message-required-news-headers)))))
6479 (when (message-mail-p)
6480 (message-generate-headers
6481 (delq 'Lines
6482 (delq 'Subject
6483 (copy-sequence message-required-mail-headers))))))))
6488 ;;; Commands for interfacing with message
6491 ;;;###autoload
6492 (defun message-mail (&optional to subject
6493 other-headers continue switch-function
6494 yank-action send-actions)
6495 "Start editing a mail message to be sent.
6496 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6497 to continue editing a message already being composed. SWITCH-FUNCTION
6498 is a function used to switch to and display the mail buffer."
6499 (interactive)
6500 (let ((message-this-is-mail t))
6501 (unless (message-mail-user-agent)
6502 (message-pop-to-buffer
6503 ;; Search for the existing message buffer if `continue' is non-nil.
6504 (let ((message-generate-new-buffers
6505 (when (or (not continue)
6506 (eq message-generate-new-buffers 'standard)
6507 (functionp message-generate-new-buffers))
6508 message-generate-new-buffers)))
6509 (message-buffer-name "mail" to))
6510 switch-function))
6511 (message-setup
6512 (nconc
6513 `((To . ,(or to "")) (Subject . ,(or subject "")))
6514 (when other-headers other-headers))
6515 yank-action send-actions continue switch-function)
6516 ;; FIXME: Should return nil if failure.
6519 ;;;###autoload
6520 (defun message-news (&optional newsgroups subject)
6521 "Start editing a news article to be sent."
6522 (interactive)
6523 (let ((message-this-is-news t))
6524 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6525 (message-setup `((Newsgroups . ,(or newsgroups ""))
6526 (Subject . ,(or subject ""))))))
6528 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6529 "Discard mail address in full names.
6530 When the full name in reply headers contains the mail
6531 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6532 ADDRCELL is a cons cell where the car is the mail address and the
6533 cdr is the complete address (full name and mail address)."
6534 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6535 (regexp-quote (car addrcell)))
6536 (cdr addrcell))
6537 (cons (car addrcell) (car addrcell))
6538 addrcell))
6540 (defcustom message-alter-recipients-function nil
6541 "Function called to allow alteration of reply header structures.
6542 It is called in `message-get-reply-headers' for each recipient.
6543 The function is called with one parameter, a cons cell ..."
6544 :type '(choice (const :tag "None" nil)
6545 (const :tag "Discard bogus full name"
6546 message-alter-recipients-discard-bogus-full-name)
6547 function)
6548 :version "23.1" ;; No Gnus
6549 :group 'message-headers)
6551 (defun message-get-reply-headers (wide &optional to-address address-headers)
6552 (let (follow-to mct never-mct to cc author mft recipients extra)
6553 ;; Find all relevant headers we need.
6554 (save-restriction
6555 (message-narrow-to-headers-or-head)
6556 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6557 ;; message-header-synonyms.
6558 (setq to (or (message-fetch-field "to")
6559 (and (loop for synonym in message-header-synonyms
6560 when (memq 'Original-To synonym)
6561 return t)
6562 (message-fetch-field "original-to")))
6563 cc (message-fetch-field "cc")
6564 extra (when message-extra-wide-headers
6565 (mapconcat 'identity
6566 (mapcar 'message-fetch-field
6567 message-extra-wide-headers)
6568 ", "))
6569 mct (message-fetch-field "mail-copies-to")
6570 author (or (message-fetch-field "mail-reply-to")
6571 (message-fetch-field "reply-to")
6572 (message-fetch-field "from")
6574 mft (and message-use-mail-followup-to
6575 (message-fetch-field "mail-followup-to"))))
6577 ;; Handle special values of Mail-Copies-To.
6578 (when mct
6579 (cond ((or (equal (downcase mct) "never")
6580 (equal (downcase mct) "nobody"))
6581 (setq never-mct t)
6582 (setq mct nil))
6583 ((or (equal (downcase mct) "always")
6584 (equal (downcase mct) "poster"))
6585 (setq mct author))))
6587 (save-match-data
6588 ;; Build (textual) list of new recipient addresses.
6589 (cond
6590 ((not wide)
6591 (setq recipients (concat ", " author)))
6592 (address-headers
6593 (dolist (header address-headers)
6594 (let ((value (message-fetch-field header)))
6595 (when value
6596 (setq recipients (concat recipients ", " value))))))
6597 ((and mft
6598 (string-match "[^ \t,]" mft)
6599 (or (not (eq message-use-mail-followup-to 'ask))
6600 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6601 You should normally obey the Mail-Followup-To: header. In this
6602 article, it has the value of
6604 " mft "
6606 which directs your response to " (if (string-match "," mft)
6607 "the specified addresses"
6608 "that address only") ".
6610 Most commonly, Mail-Followup-To is used by a mailing list poster to
6611 express that responses should be sent to just the list, and not the
6612 poster as well.
6614 If a message is posted to several mailing lists, Mail-Followup-To may
6615 also be used to direct the following discussion to one list only,
6616 because discussions that are spread over several lists tend to be
6617 fragmented and very difficult to follow.
6619 Also, some source/announcement lists are not intended for discussion;
6620 responses here are directed to other addresses.
6622 You may customize the variable `message-use-mail-followup-to', if you
6623 want to get rid of this query permanently.")))
6624 (setq recipients (concat ", " mft)))
6625 (to-address
6626 (setq recipients (concat ", " to-address))
6627 ;; If the author explicitly asked for a copy, we don't deny it to them.
6628 (if mct (setq recipients (concat recipients ", " mct))))
6630 (setq recipients (if never-mct "" (concat ", " author)))
6631 (if to (setq recipients (concat recipients ", " to)))
6632 (if cc (setq recipients (concat recipients ", " cc)))
6633 (if extra (setq recipients (concat recipients ", " extra)))
6634 (if mct (setq recipients (concat recipients ", " mct)))))
6635 (if (>= (length recipients) 2)
6636 ;; Strip the leading ", ".
6637 (setq recipients (substring recipients 2)))
6638 ;; Squeeze whitespace.
6639 (while (string-match "[ \t][ \t]+" recipients)
6640 (setq recipients (replace-match " " t t recipients)))
6641 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6642 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6643 (setq recipients (rmail-dont-reply-to recipients)))
6644 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6645 (if (string-equal recipients "")
6646 (setq recipients author))
6647 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6648 (setq recipients
6649 (mapcar
6650 (lambda (addr)
6651 (if message-alter-recipients-function
6652 (funcall message-alter-recipients-function
6653 (cons (downcase (mail-strip-quoted-names addr))
6654 addr))
6655 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6656 (message-tokenize-header recipients)))
6657 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6658 (let ((s recipients))
6659 (while s
6660 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6662 ;; Remove hierarchical lists that are contained within each other,
6663 ;; if message-hierarchical-addresses is defined.
6664 (when message-hierarchical-addresses
6665 (let ((plain-addrs (mapcar 'car recipients))
6666 subaddrs recip)
6667 (while plain-addrs
6668 (setq subaddrs (assoc (car plain-addrs)
6669 message-hierarchical-addresses)
6670 plain-addrs (cdr plain-addrs))
6671 (when subaddrs
6672 (setq subaddrs (cdr subaddrs))
6673 (while subaddrs
6674 (setq recip (assoc (car subaddrs) recipients)
6675 subaddrs (cdr subaddrs))
6676 (if recip
6677 (setq recipients (delq recip recipients))))))))
6679 ;; Build the header alist. Allow the user to be asked whether
6680 ;; or not to reply to all recipients in a wide reply.
6681 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6682 (when (and recipients
6683 (or (not message-wide-reply-confirm-recipients)
6684 (y-or-n-p "Reply to all recipients? ")))
6685 (setq recipients (mapconcat
6686 (lambda (addr) (cdr addr)) recipients ", "))
6687 (if (string-match "^ +" recipients)
6688 (setq recipients (substring recipients (match-end 0))))
6689 (push (cons 'Cc recipients) follow-to)))
6690 follow-to))
6692 (defcustom message-simplify-subject-functions
6693 '(message-strip-list-identifiers
6694 message-strip-subject-re
6695 message-strip-subject-trailing-was
6696 message-strip-subject-encoded-words)
6697 "List of functions taking a string argument that simplify subjects.
6698 The functions are applied when replying to a message.
6700 Useful functions to put in this list include:
6701 `message-strip-list-identifiers', `message-strip-subject-re',
6702 `message-strip-subject-trailing-was', and
6703 `message-strip-subject-encoded-words'."
6704 :version "22.1" ;; Gnus 5.10.9
6705 :group 'message-various
6706 :type '(repeat function))
6708 (defun message-simplify-subject (subject &optional functions)
6709 "Return simplified SUBJECT."
6710 (unless functions
6711 ;; Simplify fully:
6712 (setq functions message-simplify-subject-functions))
6713 (when (and (memq 'message-strip-list-identifiers functions)
6714 gnus-list-identifiers)
6715 (setq subject (message-strip-list-identifiers subject)))
6716 (when (memq 'message-strip-subject-re functions)
6717 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6718 (when (and (memq 'message-strip-subject-trailing-was functions)
6719 message-subject-trailing-was-query)
6720 (setq subject (message-strip-subject-trailing-was subject)))
6721 (when (memq 'message-strip-subject-encoded-words functions)
6722 (setq subject (message-strip-subject-encoded-words subject)))
6723 subject)
6725 ;;;###autoload
6726 (defun message-reply (&optional to-address wide)
6727 "Start editing a reply to the article in the current buffer."
6728 (interactive)
6729 (require 'gnus-sum) ; for gnus-list-identifiers
6730 (let ((cur (current-buffer))
6731 from subject date reply-to to cc
6732 references message-id follow-to
6733 (inhibit-point-motion-hooks t)
6734 (message-this-is-mail t)
6735 gnus-warning)
6736 (save-restriction
6737 (message-narrow-to-head-1)
6738 ;; Allow customizations to have their say.
6739 (if (not wide)
6740 ;; This is a regular reply.
6741 (when (functionp message-reply-to-function)
6742 (save-excursion
6743 (setq follow-to (funcall message-reply-to-function))))
6744 ;; This is a followup.
6745 (when (functionp message-wide-reply-to-function)
6746 (save-excursion
6747 (setq follow-to
6748 (funcall message-wide-reply-to-function)))))
6749 (setq message-id (message-fetch-field "message-id" t)
6750 references (message-fetch-field "references")
6751 date (message-fetch-field "date")
6752 from (or (message-fetch-field "from") "nobody")
6753 subject (or (message-fetch-field "subject") "none"))
6755 ;; Strip list identifiers, "Re: ", and "was:"
6756 (setq subject (message-simplify-subject subject))
6758 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6759 (string-match "<[^>]+>" gnus-warning))
6760 (setq message-id (match-string 0 gnus-warning)))
6762 (unless follow-to
6763 (setq follow-to (message-get-reply-headers wide to-address))))
6765 (unless (message-mail-user-agent)
6766 (message-pop-to-buffer
6767 (message-buffer-name
6768 (if wide "wide reply" "reply") from
6769 (if wide to-address nil))))
6771 (setq message-reply-headers
6772 (vector 0 subject from date message-id references 0 0 ""))
6774 (message-setup
6775 `((Subject . ,subject)
6776 ,@follow-to)
6777 cur)))
6779 ;;;###autoload
6780 (defun message-wide-reply (&optional to-address)
6781 "Make a \"wide\" reply to the message in the current buffer."
6782 (interactive)
6783 (message-reply to-address t))
6785 ;;;###autoload
6786 (defun message-followup (&optional to-newsgroups)
6787 "Follow up to the message in the current buffer.
6788 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6789 (interactive)
6790 (require 'gnus-sum) ; for gnus-list-identifiers
6791 (let ((cur (current-buffer))
6792 from subject date reply-to mrt mct
6793 references message-id follow-to
6794 (inhibit-point-motion-hooks t)
6795 (message-this-is-news t)
6796 followup-to distribution newsgroups gnus-warning posted-to)
6797 (save-restriction
6798 (narrow-to-region
6799 (goto-char (point-min))
6800 (if (search-forward "\n\n" nil t)
6801 (1- (point))
6802 (point-max)))
6803 (when (functionp message-followup-to-function)
6804 (setq follow-to
6805 (funcall message-followup-to-function)))
6806 (setq from (message-fetch-field "from")
6807 date (message-fetch-field "date")
6808 subject (or (message-fetch-field "subject") "none")
6809 references (message-fetch-field "references")
6810 message-id (message-fetch-field "message-id" t)
6811 followup-to (message-fetch-field "followup-to")
6812 newsgroups (message-fetch-field "newsgroups")
6813 posted-to (message-fetch-field "posted-to")
6814 reply-to (message-fetch-field "reply-to")
6815 mrt (message-fetch-field "mail-reply-to")
6816 distribution (message-fetch-field "distribution")
6817 mct (message-fetch-field "mail-copies-to"))
6818 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6819 (string-match "<[^>]+>" gnus-warning))
6820 (setq message-id (match-string 0 gnus-warning)))
6821 ;; Remove bogus distribution.
6822 (when (and (stringp distribution)
6823 (let ((case-fold-search t))
6824 (string-match "world" distribution)))
6825 (setq distribution nil))
6826 ;; Strip list identifiers, "Re: ", and "was:"
6827 (setq subject (message-simplify-subject subject))
6828 (widen))
6830 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6832 (setq message-reply-headers
6833 (vector 0 subject from date message-id references 0 0 ""))
6835 (message-setup
6836 `((Subject . ,subject)
6837 ,@(cond
6838 (to-newsgroups
6839 (list (cons 'Newsgroups to-newsgroups)))
6840 (follow-to follow-to)
6841 ((and followup-to message-use-followup-to)
6842 (list
6843 (cond
6844 ((equal (downcase followup-to) "poster")
6845 (if (or (eq message-use-followup-to 'use)
6846 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6847 You should normally obey the Followup-To: header.
6849 `Followup-To: poster' sends your response via e-mail instead of news.
6851 A typical situation where `Followup-To: poster' is used is when the poster
6852 does not read the newsgroup, so he wouldn't see any replies sent to it.
6854 You may customize the variable `message-use-followup-to', if you
6855 want to get rid of this query permanently."))
6856 (progn
6857 (setq message-this-is-news nil)
6858 (cons 'To (or mrt reply-to from "")))
6859 (cons 'Newsgroups newsgroups)))
6861 (if (or (equal followup-to newsgroups)
6862 (not (eq message-use-followup-to 'ask))
6863 (message-y-or-n-p
6864 (concat "Obey Followup-To: " followup-to "? ") t "\
6865 You should normally obey the Followup-To: header.
6867 `Followup-To: " followup-to "'
6868 directs your response to " (if (string-match "," followup-to)
6869 "the specified newsgroups"
6870 "that newsgroup only") ".
6872 If a message is posted to several newsgroups, Followup-To is often
6873 used to direct the following discussion to one newsgroup only,
6874 because discussions that are spread over several newsgroup tend to
6875 be fragmented and very difficult to follow.
6877 Also, some source/announcement newsgroups are not intended for discussion;
6878 responses here are directed to other newsgroups.
6880 You may customize the variable `message-use-followup-to', if you
6881 want to get rid of this query permanently."))
6882 (cons 'Newsgroups followup-to)
6883 (cons 'Newsgroups newsgroups))))))
6884 (posted-to
6885 `((Newsgroups . ,posted-to)))
6887 `((Newsgroups . ,newsgroups))))
6888 ,@(and distribution (list (cons 'Distribution distribution)))
6889 ,@(when (and mct
6890 (not (or (equal (downcase mct) "never")
6891 (equal (downcase mct) "nobody"))))
6892 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6893 (equal (downcase mct) "poster"))
6894 (or mrt reply-to from "")
6895 mct)))))
6897 cur)))
6899 (defun message-is-yours-p ()
6900 "Non-nil means current article is yours.
6901 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6902 are yours except those that have Cancel-Lock header not belonging to you.
6903 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6904 regexp to match all of yours addresses."
6905 ;; Canlock-logic as suggested by Per Abrahamsen
6906 ;; <abraham@dina.kvl.dk>
6908 ;; IF article has cancel-lock THEN
6909 ;; IF we can verify it THEN
6910 ;; issue cancel
6911 ;; ELSE
6912 ;; error: cancellock: article is not yours
6913 ;; ELSE
6914 ;; Use old rules, comparing sender...
6915 (save-excursion
6916 (save-restriction
6917 (message-narrow-to-head-1)
6918 (if (message-fetch-field "Cancel-Lock")
6919 (if (null (canlock-verify))
6921 (error "Failed to verify Cancel-lock: This article is not yours"))
6922 (let (sender from)
6924 (message-gnksa-enable-p 'cancel-messages)
6925 (and (setq sender (message-fetch-field "sender"))
6926 (string-equal (downcase sender)
6927 (downcase (message-make-sender))))
6928 ;; Email address in From field equals to our address
6929 (and (setq from (message-fetch-field "from"))
6930 (string-equal
6931 (downcase (car (mail-header-parse-address from)))
6932 (downcase (car (mail-header-parse-address
6933 (message-make-from))))))
6934 ;; Email address in From field matches
6935 ;; 'message-alternative-emails' regexp
6936 (and from
6937 message-alternative-emails
6938 (string-match
6939 message-alternative-emails
6940 (car (mail-header-parse-address from))))))))))
6942 ;;;###autoload
6943 (defun message-cancel-news (&optional arg)
6944 "Cancel an article you posted.
6945 If ARG, allow editing of the cancellation message."
6946 (interactive "P")
6947 (unless (message-news-p)
6948 (error "This is not a news article; canceling is impossible"))
6949 (let (from newsgroups message-id distribution buf)
6950 (save-excursion
6951 ;; Get header info from original article.
6952 (save-restriction
6953 (message-narrow-to-head-1)
6954 (setq from (message-fetch-field "from")
6955 newsgroups (message-fetch-field "newsgroups")
6956 message-id (message-fetch-field "message-id" t)
6957 distribution (message-fetch-field "distribution")))
6958 ;; Make sure that this article was written by the user.
6959 (unless (message-is-yours-p)
6960 (error "This article is not yours"))
6961 (when (yes-or-no-p "Do you really want to cancel this article? ")
6962 ;; Make control message.
6963 (if arg
6964 (message-news)
6965 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6966 (erase-buffer)
6967 (insert "Newsgroups: " newsgroups "\n"
6968 "From: " from "\n"
6969 "Subject: cmsg cancel " message-id "\n"
6970 "Control: cancel " message-id "\n"
6971 (if distribution
6972 (concat "Distribution: " distribution "\n")
6974 mail-header-separator "\n"
6975 message-cancel-message)
6976 (run-hooks 'message-cancel-hook)
6977 (unless arg
6978 (message "Canceling your article...")
6979 (if (let ((message-syntax-checks
6980 'dont-check-for-anything-just-trust-me))
6981 (funcall message-send-news-function))
6982 (message "Canceling your article...done"))
6983 (kill-buffer buf))))))
6985 ;;;###autoload
6986 (defun message-supersede ()
6987 "Start composing a message to supersede the current message.
6988 This is done simply by taking the old article and adding a Supersedes
6989 header line with the old Message-ID."
6990 (interactive)
6991 (let ((cur (current-buffer)))
6992 ;; Check whether the user owns the article that is to be superseded.
6993 (unless (message-is-yours-p)
6994 (error "This article is not yours"))
6995 ;; Get a normal message buffer.
6996 (message-pop-to-buffer (message-buffer-name "supersede"))
6997 (insert-buffer-substring cur)
6998 (mime-to-mml)
6999 (message-narrow-to-head-1)
7000 ;; Remove unwanted headers.
7001 (when message-ignored-supersedes-headers
7002 (message-remove-header message-ignored-supersedes-headers t))
7003 (goto-char (point-min))
7004 (if (not (re-search-forward "^Message-ID: " nil t))
7005 (error "No Message-ID in this article")
7006 (replace-match "Supersedes: " t t))
7007 (goto-char (point-max))
7008 (insert mail-header-separator)
7009 (widen)
7010 (forward-line 1)))
7012 ;;;###autoload
7013 (defun message-recover ()
7014 "Reread contents of current buffer from its last auto-save file."
7015 (interactive)
7016 (let ((file-name (make-auto-save-file-name)))
7017 (cond ((save-window-excursion
7018 (with-output-to-temp-buffer "*Directory*"
7019 (with-current-buffer standard-output
7020 (fundamental-mode)) ; for Emacs 20.4+
7021 (buffer-disable-undo standard-output)
7022 (let ((default-directory "/"))
7023 (call-process
7024 "ls" nil standard-output nil "-l" file-name)))
7025 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7026 (let ((buffer-read-only nil))
7027 (erase-buffer)
7028 (insert-file-contents file-name nil)))
7029 (t (error "message-recover cancelled")))))
7031 ;;; Washing Subject:
7033 (defun message-wash-subject (subject)
7034 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7035 Previous forwarders, replyers, etc. may add it."
7036 (with-temp-buffer
7037 (insert subject)
7038 (goto-char (point-min))
7039 ;; strip Re/Fwd stuff off the beginning
7040 (while (re-search-forward
7041 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7042 (replace-match ""))
7044 ;; and gnus-style forwards [foo@bar.com] subject
7045 (goto-char (point-min))
7046 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7047 (replace-match ""))
7049 ;; and off the end
7050 (goto-char (point-max))
7051 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7052 (replace-match ""))
7054 ;; and finally, any whitespace that was left-over
7055 (goto-char (point-min))
7056 (while (re-search-forward "^[ \t]+" nil t)
7057 (replace-match ""))
7058 (goto-char (point-max))
7059 (while (re-search-backward "[ \t]+$" nil t)
7060 (replace-match ""))
7062 (buffer-string)))
7064 ;;; Forwarding messages.
7066 (defvar message-forward-decoded-p nil
7067 "Non-nil means the original message is decoded.")
7069 (defun message-forward-subject-name-subject (subject)
7070 "Generate a SUBJECT for a forwarded message.
7071 The form is: [Source] Subject, where if the original message was mail,
7072 Source is the name of the sender, and if the original message was
7073 news, Source is the list of newsgroups is was posted to."
7074 (let* ((group (message-fetch-field "newsgroups"))
7075 (from (message-fetch-field "from"))
7076 (prefix
7077 (if group
7078 (gnus-group-decoded-name group)
7079 (or (and from (or
7080 (car (gnus-extract-address-components from))
7081 (cadr (gnus-extract-address-components from))))
7082 "(nowhere)"))))
7083 (concat "["
7084 (if message-forward-decoded-p
7085 prefix
7086 (mail-decode-encoded-word-string prefix))
7087 "] " subject)))
7089 (defun message-forward-subject-author-subject (subject)
7090 "Generate a SUBJECT for a forwarded message.
7091 The form is: [Source] Subject, where if the original message was mail,
7092 Source is the sender, and if the original message was news, Source is
7093 the list of newsgroups is was posted to."
7094 (let* ((group (message-fetch-field "newsgroups"))
7095 (prefix
7096 (if group
7097 (gnus-group-decoded-name group)
7098 (or (message-fetch-field "from")
7099 "(nowhere)"))))
7100 (concat "["
7101 (if message-forward-decoded-p
7102 prefix
7103 (mail-decode-encoded-word-string prefix))
7104 "] " subject)))
7106 (defun message-forward-subject-fwd (subject)
7107 "Generate a SUBJECT for a forwarded message.
7108 The form is: Fwd: Subject, where Subject is the original subject of
7109 the message."
7110 (if (string-match "^Fwd: " subject)
7111 subject
7112 (concat "Fwd: " subject)))
7114 (defun message-make-forward-subject ()
7115 "Return a Subject header suitable for the message in the current buffer."
7116 (save-excursion
7117 (save-restriction
7118 (message-narrow-to-head-1)
7119 (let ((funcs message-make-forward-subject-function)
7120 (subject (message-fetch-field "Subject")))
7121 (setq subject
7122 (if subject
7123 (if message-forward-decoded-p
7124 subject
7125 (mail-decode-encoded-word-string subject))
7126 ""))
7127 (when message-wash-forwarded-subjects
7128 (setq subject (message-wash-subject subject)))
7129 ;; Make sure funcs is a list.
7130 (and funcs
7131 (not (listp funcs))
7132 (setq funcs (list funcs)))
7133 ;; Apply funcs in order, passing subject generated by previous
7134 ;; func to the next one.
7135 (dolist (func funcs)
7136 (when (functionp func)
7137 (setq subject (funcall func subject))))
7138 subject))))
7140 (defvar gnus-article-decoded-p)
7143 ;;;###autoload
7144 (defun message-forward (&optional news digest)
7145 "Forward the current message via mail.
7146 Optional NEWS will use news to forward instead of mail.
7147 Optional DIGEST will use digest to forward."
7148 (interactive "P")
7149 (let* ((cur (current-buffer))
7150 (message-forward-decoded-p
7151 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7152 gnus-article-decoded-p ;; In an article buffer.
7153 message-forward-decoded-p))
7154 (subject (message-make-forward-subject)))
7155 (if news
7156 (message-news nil subject)
7157 (message-mail nil subject))
7158 (message-forward-make-body cur digest)))
7160 (defun message-forward-make-body-plain (forward-buffer)
7161 (insert
7162 "\n-------------------- Start of forwarded message --------------------\n")
7163 (let ((b (point)) e)
7164 (insert
7165 (with-temp-buffer
7166 (mm-disable-multibyte)
7167 (insert
7168 (with-current-buffer forward-buffer
7169 (mm-with-unibyte-current-buffer (buffer-string))))
7170 (mm-enable-multibyte)
7171 (mime-to-mml)
7172 (goto-char (point-min))
7173 (when (looking-at "From ")
7174 (replace-match "X-From-Line: "))
7175 (buffer-string)))
7176 (setq e (point))
7177 (insert
7178 "\n-------------------- End of forwarded message --------------------\n")
7179 (message-remove-ignored-headers b e)))
7181 (defun message-remove-ignored-headers (b e)
7182 (when message-forward-ignored-headers
7183 (save-restriction
7184 (narrow-to-region b e)
7185 (goto-char b)
7186 (narrow-to-region (point)
7187 (or (search-forward "\n\n" nil t) (point)))
7188 (let ((ignored (if (stringp message-forward-ignored-headers)
7189 (list message-forward-ignored-headers)
7190 message-forward-ignored-headers)))
7191 (dolist (elem ignored)
7192 (message-remove-header elem t))))))
7194 (defun message-forward-make-body-mime (forward-buffer)
7195 (let ((b (point)))
7196 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7197 (save-restriction
7198 (narrow-to-region (point) (point))
7199 (mml-insert-buffer forward-buffer)
7200 (goto-char (point-min))
7201 (when (looking-at "From ")
7202 (replace-match "X-From-Line: "))
7203 (goto-char (point-max)))
7204 (insert "<#/part>\n")
7205 ;; Consider there is no illegible text.
7206 (add-text-properties
7207 b (point)
7208 `(no-illegible-text t rear-nonsticky t start-open t))))
7210 (defun message-forward-make-body-mml (forward-buffer)
7211 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7212 (let ((b (point)) e)
7213 (if (not message-forward-decoded-p)
7214 (insert
7215 (with-temp-buffer
7216 (mm-disable-multibyte)
7217 (insert
7218 (with-current-buffer forward-buffer
7219 (mm-with-unibyte-current-buffer (buffer-string))))
7220 (mm-enable-multibyte)
7221 (mime-to-mml)
7222 (goto-char (point-min))
7223 (when (looking-at "From ")
7224 (replace-match "X-From-Line: "))
7225 (buffer-string)))
7226 (save-restriction
7227 (narrow-to-region (point) (point))
7228 (mml-insert-buffer forward-buffer)
7229 (goto-char (point-min))
7230 (when (looking-at "From ")
7231 (replace-match "X-From-Line: "))
7232 (goto-char (point-max))))
7233 (setq e (point))
7234 (insert "<#/mml>\n")
7235 (when (and (not message-forward-decoded-p)
7236 message-forward-ignored-headers)
7237 (message-remove-ignored-headers b e))))
7239 (defun message-forward-make-body-digest-plain (forward-buffer)
7240 (insert
7241 "\n-------------------- Start of forwarded message --------------------\n")
7242 (let ((b (point)) e)
7243 (mml-insert-buffer forward-buffer)
7244 (setq e (point))
7245 (insert
7246 "\n-------------------- End of forwarded message --------------------\n")))
7248 (defun message-forward-make-body-digest-mime (forward-buffer)
7249 (insert "\n<#multipart type=digest>\n")
7250 (let ((b (point)) e)
7251 (insert-buffer-substring forward-buffer)
7252 (setq e (point))
7253 (insert "<#/multipart>\n")
7254 (save-restriction
7255 (narrow-to-region b e)
7256 (goto-char b)
7257 (narrow-to-region (point)
7258 (or (search-forward "\n\n" nil t) (point)))
7259 (delete-region (point-min) (point-max)))))
7261 (defun message-forward-make-body-digest (forward-buffer)
7262 (if message-forward-as-mime
7263 (message-forward-make-body-digest-mime forward-buffer)
7264 (message-forward-make-body-digest-plain forward-buffer)))
7266 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7267 (autoload 'mm-uu-dissect "mm-uu")
7269 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7270 "Say whether the current buffer contains signed or encrypted message.
7271 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7272 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7273 is for the internal use."
7274 (unless handles
7275 (let ((mm-decrypt-option 'never)
7276 (mm-verify-option 'never))
7277 (if (setq handles (mm-dissect-buffer nil t))
7278 (unless dont-emulate-mime
7279 (mm-uu-dissect-text-parts handles))
7280 (unless dont-emulate-mime
7281 (setq handles (mm-uu-dissect))))))
7282 ;; Check text/plain message in which there is a signed or encrypted
7283 ;; body that has been encoded by B or Q.
7284 (unless (or handles dont-emulate-mime)
7285 (let ((cur (current-buffer))
7286 (mm-decrypt-option 'never)
7287 (mm-verify-option 'never))
7288 (with-temp-buffer
7289 (insert-buffer-substring cur)
7290 (when (setq handles (mm-dissect-buffer t t))
7291 (if (and (prog1
7292 (bufferp (car handles))
7293 (mm-destroy-parts handles))
7294 (equal (mm-handle-media-type handles) "text/plain"))
7295 (progn
7296 (mm-decode-content-transfer-encoding
7297 (mm-handle-encoding handles))
7298 (setq handles (mm-uu-dissect)))
7299 (setq handles nil))))))
7300 (when handles
7301 (prog1
7302 (catch 'found
7303 (dolist (handle (if (stringp (car handles))
7304 (if (member (car handles)
7305 '("multipart/signed"
7306 "multipart/encrypted"))
7307 (throw 'found t)
7308 (cdr handles))
7309 (list handles)))
7310 (if (stringp (car handle))
7311 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7312 (throw 'found t))
7313 (when (and (bufferp (car handle))
7314 (equal (mm-handle-media-type handle)
7315 "message/rfc822"))
7316 (with-current-buffer (mm-handle-buffer handle)
7317 (when (message-signed-or-encrypted-p dont-emulate-mime)
7318 (throw 'found t)))))))
7319 (mm-destroy-parts handles))))
7321 ;;;###autoload
7322 (defun message-forward-make-body (forward-buffer &optional digest)
7323 ;; Put point where we want it before inserting the forwarded
7324 ;; message.
7325 (if message-forward-before-signature
7326 (message-goto-body)
7327 (goto-char (point-max)))
7328 (if digest
7329 (message-forward-make-body-digest forward-buffer)
7330 (if message-forward-as-mime
7331 (if (and message-forward-show-mml
7332 (not (and (eq message-forward-show-mml 'best)
7333 ;; Use the raw form in the body if it contains
7334 ;; signed or encrypted message so as not to be
7335 ;; destroyed by re-encoding.
7336 (with-current-buffer forward-buffer
7337 (condition-case nil
7338 (message-signed-or-encrypted-p)
7339 (error t))))))
7340 (message-forward-make-body-mml forward-buffer)
7341 (message-forward-make-body-mime forward-buffer))
7342 (message-forward-make-body-plain forward-buffer)))
7343 (message-position-point))
7345 (declare-function rmail-toggle-header "rmail" (&optional arg))
7347 ;;;###autoload
7348 (defun message-forward-rmail-make-body (forward-buffer)
7349 (save-window-excursion
7350 (set-buffer forward-buffer)
7351 (if (rmail-msg-is-pruned)
7352 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7353 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7354 (rmail-toggle-header 0)))) ; Emacs 23
7355 (message-forward-make-body forward-buffer))
7357 ;; Fixme: Should have defcustom.
7358 ;;;###autoload
7359 (defun message-insinuate-rmail ()
7360 "Let RMAIL use message to forward."
7361 (interactive)
7362 (setq rmail-enable-mime-composing t)
7363 (setq rmail-insert-mime-forwarded-message-function
7364 'message-forward-rmail-make-body))
7366 ;;;###autoload
7367 (defun message-resend (address)
7368 "Resend the current article to ADDRESS."
7369 (interactive
7370 (list (message-read-from-minibuffer "Resend message to: ")))
7371 (message "Resending message to %s..." address)
7372 (save-excursion
7373 (let ((cur (current-buffer))
7374 beg)
7375 ;; We first set up a normal mail buffer.
7376 (unless (message-mail-user-agent)
7377 (set-buffer (get-buffer-create " *message resend*"))
7378 (erase-buffer))
7379 (let ((message-this-is-mail t)
7380 message-generate-hashcash
7381 message-setup-hook)
7382 (message-setup `((To . ,address))))
7383 ;; Insert our usual headers.
7384 (message-generate-headers '(From Date To Message-ID))
7385 (message-narrow-to-headers)
7386 ;; Remove X-Draft-From header etc.
7387 (message-remove-header message-ignored-mail-headers t)
7388 ;; Rename them all to "Resent-*".
7389 (goto-char (point-min))
7390 (while (re-search-forward "^[A-Za-z]" nil t)
7391 (forward-char -1)
7392 (insert "Resent-"))
7393 (widen)
7394 (forward-line)
7395 (delete-region (point) (point-max))
7396 (setq beg (point))
7397 ;; Insert the message to be resent.
7398 (insert-buffer-substring cur)
7399 (goto-char (point-min))
7400 (search-forward "\n\n")
7401 (forward-char -1)
7402 (save-restriction
7403 (narrow-to-region beg (point))
7404 (message-remove-header message-ignored-resent-headers t)
7405 (goto-char (point-max)))
7406 (insert mail-header-separator)
7407 ;; Rename all old ("Also-")Resent headers.
7408 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7409 (beginning-of-line)
7410 (insert "Also-"))
7411 ;; Quote any "From " lines at the beginning.
7412 (goto-char beg)
7413 (when (looking-at "From ")
7414 (replace-match "X-From-Line: "))
7415 ;; Send it.
7416 (let ((message-inhibit-body-encoding t)
7417 message-required-mail-headers
7418 message-generate-hashcash
7419 rfc2047-encode-encoded-words)
7420 (message-send-mail))
7421 (kill-buffer (current-buffer)))
7422 (message "Resending message to %s...done" address)))
7424 ;;;###autoload
7425 (defun message-bounce ()
7426 "Re-mail the current message.
7427 This only makes sense if the current message is a bounce message that
7428 contains some mail you have written which has been bounced back to
7429 you."
7430 (interactive)
7431 (let ((handles (mm-dissect-buffer t))
7432 boundary)
7433 (message-pop-to-buffer (message-buffer-name "bounce"))
7434 (if (stringp (car handles))
7435 ;; This is a MIME bounce.
7436 (mm-insert-part (car (last handles)))
7437 ;; This is a non-MIME bounce, so we try to remove things
7438 ;; manually.
7439 (mm-insert-part handles)
7440 (undo-boundary)
7441 (goto-char (point-min))
7442 (re-search-forward "\n\n+" nil t)
7443 (setq boundary (point))
7444 ;; We remove everything before the bounced mail.
7445 (if (or (re-search-forward message-unsent-separator nil t)
7446 (progn
7447 (search-forward "\n\n" nil 'move)
7448 (re-search-backward "^Return-Path:.*\n" boundary t)))
7449 (progn
7450 (forward-line 1)
7451 (delete-region (point-min)
7452 (if (re-search-forward "^[^ \n\t]+:" nil t)
7453 (match-beginning 0)
7454 (point))))
7455 (goto-char boundary)
7456 (when (re-search-backward "^.?From .*\n" nil t)
7457 (delete-region (match-beginning 0) (match-end 0)))))
7458 (mime-to-mml)
7459 (save-restriction
7460 (message-narrow-to-head-1)
7461 (message-remove-header message-ignored-bounced-headers t)
7462 (goto-char (point-max))
7463 (insert mail-header-separator))
7464 (message-position-point)))
7467 ;;; Interactive entry points for new message buffers.
7470 ;;;###autoload
7471 (defun message-mail-other-window (&optional to subject)
7472 "Like `message-mail' command, but display mail buffer in another window."
7473 (interactive)
7474 (unless (message-mail-user-agent)
7475 (let ((pop-up-windows t)
7476 (special-display-buffer-names nil)
7477 (special-display-regexps nil)
7478 (same-window-buffer-names nil)
7479 (same-window-regexps nil))
7480 (message-pop-to-buffer (message-buffer-name "mail" to))))
7481 (let ((message-this-is-mail t))
7482 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7483 nil nil nil 'switch-to-buffer-other-window)))
7485 ;;;###autoload
7486 (defun message-mail-other-frame (&optional to subject)
7487 "Like `message-mail' command, but display mail buffer in another frame."
7488 (interactive)
7489 (unless (message-mail-user-agent)
7490 (let ((pop-up-frames t)
7491 (special-display-buffer-names nil)
7492 (special-display-regexps nil)
7493 (same-window-buffer-names nil)
7494 (same-window-regexps nil))
7495 (message-pop-to-buffer (message-buffer-name "mail" to))))
7496 (let ((message-this-is-mail t))
7497 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7498 nil nil nil 'switch-to-buffer-other-frame)))
7500 ;;;###autoload
7501 (defun message-news-other-window (&optional newsgroups subject)
7502 "Start editing a news article to be sent."
7503 (interactive)
7504 (let ((pop-up-windows t)
7505 (special-display-buffer-names nil)
7506 (special-display-regexps nil)
7507 (same-window-buffer-names nil)
7508 (same-window-regexps nil))
7509 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7510 (let ((message-this-is-news t))
7511 (message-setup `((Newsgroups . ,(or newsgroups ""))
7512 (Subject . ,(or subject ""))))))
7514 ;;;###autoload
7515 (defun message-news-other-frame (&optional newsgroups subject)
7516 "Start editing a news article to be sent."
7517 (interactive)
7518 (let ((pop-up-frames t)
7519 (special-display-buffer-names nil)
7520 (special-display-regexps nil)
7521 (same-window-buffer-names nil)
7522 (same-window-regexps nil))
7523 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7524 (let ((message-this-is-news t))
7525 (message-setup `((Newsgroups . ,(or newsgroups ""))
7526 (Subject . ,(or subject ""))))))
7528 ;;; underline.el
7530 ;; This code should be moved to underline.el (from which it is stolen).
7532 ;;;###autoload
7533 (defun message-bold-region (start end)
7534 "Bold all nonblank characters in the region.
7535 Works by overstriking characters.
7536 Called from program, takes two arguments START and END
7537 which specify the range to operate on."
7538 (interactive "r")
7539 (save-excursion
7540 (let ((end1 (make-marker)))
7541 (move-marker end1 (max start end))
7542 (goto-char (min start end))
7543 (while (< (point) end1)
7544 (or (looking-at "[_\^@- ]")
7545 (insert (char-after) "\b"))
7546 (forward-char 1)))))
7548 ;;;###autoload
7549 (defun message-unbold-region (start end)
7550 "Remove all boldness (overstruck characters) in the region.
7551 Called from program, takes two arguments START and END
7552 which specify the range to operate on."
7553 (interactive "r")
7554 (save-excursion
7555 (let ((end1 (make-marker)))
7556 (move-marker end1 (max start end))
7557 (goto-char (min start end))
7558 (while (search-forward "\b" end1 t)
7559 (if (eq (char-after) (char-after (- (point) 2)))
7560 (delete-char -2))))))
7562 (defun message-exchange-point-and-mark ()
7563 "Exchange point and mark, but don't activate region if it was inactive."
7564 (goto-char (prog1 (mark t)
7565 (set-marker (mark-marker) (point)))))
7567 (defalias 'message-make-overlay 'make-overlay)
7568 (defalias 'message-delete-overlay 'delete-overlay)
7569 (defalias 'message-overlay-put 'overlay-put)
7570 (defun message-kill-all-overlays ()
7571 (if (featurep 'xemacs)
7572 (map-extents (lambda (extent ignore) (delete-extent extent)))
7573 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7575 ;; Support for toolbar
7576 (defvar tool-bar-mode)
7578 ;; Note: The :set function in the `message-tool-bar*' variables will only
7579 ;; affect _new_ message buffers. We might add a function that walks thru all
7580 ;; message-mode buffers and force the update.
7581 (defun message-tool-bar-update (&optional symbol value)
7582 "Update message mode toolbar.
7583 Setter function for custom variables."
7584 (setq-default message-tool-bar-map nil)
7585 (when symbol
7586 ;; When used as ":set" function:
7587 (set-default symbol value)))
7589 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7590 'message-tool-bar-gnome
7591 'message-tool-bar-retro)
7592 "Specifies the message mode tool bar.
7594 It can be either a list or a symbol refering to a list. See
7595 `gmm-tool-bar-from-list' for the format of the list. The
7596 default key map is `message-mode-map'.
7598 Pre-defined symbols include `message-tool-bar-gnome' and
7599 `message-tool-bar-retro'."
7600 :type '(repeat gmm-tool-bar-list-item)
7601 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7602 (const :tag "Retro look" message-tool-bar-retro)
7603 (repeat :tag "User defined list" gmm-tool-bar-item)
7604 (symbol))
7605 :version "23.1" ;; No Gnus
7606 :initialize 'custom-initialize-default
7607 :set 'message-tool-bar-update
7608 :group 'message)
7610 (defcustom message-tool-bar-gnome
7611 '((ispell-message "spell" nil
7612 :visible (or (not (boundp 'flyspell-mode))
7613 (not flyspell-mode)))
7614 (flyspell-buffer "spell" t
7615 :visible (and (boundp 'flyspell-mode)
7616 flyspell-mode)
7617 :help "Flyspell whole buffer")
7618 (gmm-ignore "separator")
7619 (message-send-and-exit "mail/send")
7620 (message-dont-send "mail/save-draft")
7621 (message-kill-buffer "close") ;; stock_cancel
7622 (mml-attach-file "attach" mml-mode-map)
7623 (mml-preview "mail/preview" mml-mode-map)
7624 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7625 (message-insert-importance-high "important" nil :visible nil)
7626 (message-insert-importance-low "unimportant" nil :visible nil)
7627 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7628 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7629 (message-info "help" t :help "Message manual"))
7630 "List of items for the message tool bar (GNOME style).
7632 See `gmm-tool-bar-from-list' for details on the format of the list."
7633 :type '(repeat gmm-tool-bar-item)
7634 :version "23.1" ;; No Gnus
7635 :initialize 'custom-initialize-default
7636 :set 'message-tool-bar-update
7637 :group 'message)
7639 (defcustom message-tool-bar-retro
7640 '(;; Old Emacs 21 icon for consistency.
7641 (message-send-and-exit "gnus/mail-send")
7642 (message-kill-buffer "close")
7643 (message-dont-send "cancel")
7644 (mml-attach-file "attach" mml-mode-map)
7645 (ispell-message "spell")
7646 (mml-preview "preview" mml-mode-map)
7647 (message-insert-importance-high "gnus/important")
7648 (message-insert-importance-low "gnus/unimportant")
7649 (message-insert-disposition-notification-to "gnus/receipt"))
7650 "List of items for the message tool bar (retro style).
7652 See `gmm-tool-bar-from-list' for details on the format of the list."
7653 :type '(repeat gmm-tool-bar-item)
7654 :version "23.1" ;; No Gnus
7655 :initialize 'custom-initialize-default
7656 :set 'message-tool-bar-update
7657 :group 'message)
7659 (defcustom message-tool-bar-zap-list
7660 '(new-file open-file dired kill-buffer write-file
7661 print-buffer customize help)
7662 "List of icon items from the global tool bar.
7663 These items are not displayed on the message mode tool bar.
7665 See `gmm-tool-bar-from-list' for the format of the list."
7666 :type 'gmm-tool-bar-zap-list
7667 :version "23.1" ;; No Gnus
7668 :initialize 'custom-initialize-default
7669 :set 'message-tool-bar-update
7670 :group 'message)
7672 (defvar image-load-path)
7674 (defun message-make-tool-bar (&optional force)
7675 "Make a message mode tool bar from `message-tool-bar-list'.
7676 When FORCE, rebuild the tool bar."
7677 (when (and (not (featurep 'xemacs))
7678 (boundp 'tool-bar-mode)
7679 tool-bar-mode
7680 (or (not message-tool-bar-map) force))
7681 (setq message-tool-bar-map
7682 (let* ((load-path
7683 (gmm-image-load-path-for-library "message"
7684 "mail/save-draft.xpm"
7685 nil t))
7686 (image-load-path (cons (car load-path)
7687 (when (boundp 'image-load-path)
7688 image-load-path))))
7689 (gmm-tool-bar-from-list message-tool-bar
7690 message-tool-bar-zap-list
7691 'message-mode-map))))
7692 message-tool-bar-map)
7694 ;;; Group name completion.
7696 (defcustom message-newgroups-header-regexp
7697 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7698 "Regexp that match headers that lists groups."
7699 :group 'message
7700 :type 'regexp)
7702 (defcustom message-completion-alist
7703 (list (cons message-newgroups-header-regexp 'message-expand-group)
7704 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7705 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7706 . message-expand-name)
7707 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7708 . message-expand-name))
7709 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7710 :version "22.1"
7711 :group 'message
7712 :type '(alist :key-type regexp :value-type function))
7714 (defcustom message-expand-name-databases
7715 (list 'bbdb 'eudc)
7716 "List of databases to try for name completion (`message-expand-name').
7717 Each element is a symbol and can be `bbdb' or `eudc'."
7718 :group 'message
7719 :type '(set (const bbdb) (const eudc)))
7721 (defcustom message-tab-body-function nil
7722 "*Function to execute when `message-tab' (TAB) is executed in the body.
7723 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7724 :version "22.1"
7725 :group 'message
7726 :link '(custom-manual "(message)Various Commands")
7727 :type '(choice (const nil)
7728 function))
7730 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7732 (defun message-tab ()
7733 "Complete names according to `message-completion-alist'.
7734 Execute function specified by `message-tab-body-function' when not in
7735 those headers."
7736 (interactive)
7737 (let ((alist message-completion-alist))
7738 (while (and alist
7739 (let ((mail-abbrev-mode-regexp (caar alist)))
7740 (not (mail-abbrev-in-expansion-header-p))))
7741 (setq alist (cdr alist)))
7742 (funcall (or (cdar alist) message-tab-body-function
7743 (lookup-key text-mode-map "\t")
7744 (lookup-key global-map "\t")
7745 'indent-relative))))
7747 (eval-and-compile
7748 (condition-case nil
7749 (with-temp-buffer
7750 (let ((standard-output (current-buffer)))
7751 (eval '(display-completion-list nil "")))
7752 (defalias 'message-display-completion-list 'display-completion-list))
7753 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7754 (defun message-display-completion-list (completions &optional ignore)
7755 "Display the list of completions, COMPLETIONS, using `standard-output'."
7756 (display-completion-list completions)))))
7758 (defun message-expand-group ()
7759 "Expand the group name under point."
7760 (let* ((b (save-excursion
7761 (save-restriction
7762 (narrow-to-region
7763 (save-excursion
7764 (beginning-of-line)
7765 (skip-chars-forward "^:")
7766 (1+ (point)))
7767 (point))
7768 (skip-chars-backward "^, \t\n") (point))))
7769 (completion-ignore-case t)
7770 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7771 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7772 (message-completion-in-region e b hashtb)))
7774 (defalias 'message-completion-in-region
7775 (if (fboundp 'completion-in-region)
7776 'completion-in-region
7777 (lambda (e b hashtb)
7778 (let* ((string (buffer-substring b e))
7779 (completions (all-completions string hashtb))
7780 comp)
7781 (delete-region b (point))
7782 (cond
7783 ((= (length completions) 1)
7784 (if (string= (car completions) string)
7785 (progn
7786 (insert string)
7787 (message "Only matching group"))
7788 (insert (car completions))))
7789 ((and (setq comp (try-completion string hashtb))
7790 (not (string= comp string)))
7791 (insert comp))
7793 (insert string)
7794 (if (not comp)
7795 (message "No matching groups")
7796 (save-selected-window
7797 (pop-to-buffer "*Completions*")
7798 (buffer-disable-undo)
7799 (let ((buffer-read-only nil))
7800 (erase-buffer)
7801 (let ((standard-output (current-buffer)))
7802 (message-display-completion-list (sort completions 'string<)
7803 string))
7804 (setq buffer-read-only nil)
7805 (goto-char (point-min))
7806 (delete-region (point)
7807 (progn (forward-line 3) (point))))))))))))
7809 (defun message-expand-name ()
7810 (cond ((and (memq 'eudc message-expand-name-databases)
7811 (boundp 'eudc-protocol)
7812 eudc-protocol)
7813 (eudc-expand-inline))
7814 ((and (memq 'bbdb message-expand-name-databases)
7815 (fboundp 'bbdb-complete-name))
7816 (bbdb-complete-name))
7818 (expand-abbrev))))
7820 ;;; Help stuff.
7822 (defun message-talkative-question (ask question show &rest text)
7823 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7824 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7825 The following arguments may contain lists of values."
7826 (if (and show
7827 (setq text (message-flatten-list text)))
7828 (save-window-excursion
7829 (with-output-to-temp-buffer " *MESSAGE information message*"
7830 (with-current-buffer " *MESSAGE information message*"
7831 (fundamental-mode) ; for Emacs 20.4+
7832 (mapc 'princ text)
7833 (goto-char (point-min))))
7834 (funcall ask question))
7835 (funcall ask question)))
7837 (defun message-flatten-list (list)
7838 "Return a new, flat list that contains all elements of LIST.
7840 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7841 => (1 2 3 4 5 6 7)"
7842 (cond ((consp list)
7843 (apply 'append (mapcar 'message-flatten-list list)))
7844 (list
7845 (list list))))
7847 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7848 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7849 Then clone the local variables and values from the old buffer to the
7850 new one, cloning only the locals having a substring matching the
7851 regexp VARSTR."
7852 (let ((oldbuf (current-buffer)))
7853 (with-current-buffer (generate-new-buffer name)
7854 (message-clone-locals oldbuf varstr)
7855 (current-buffer))))
7857 (defun message-clone-locals (buffer &optional varstr)
7858 "Clone the local variables from BUFFER to the current buffer."
7859 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7860 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7861 (mapcar
7862 (lambda (local)
7863 (when (and (consp local)
7864 (car local)
7865 (string-match regexp (symbol-name (car local)))
7866 (or (null varstr)
7867 (string-match varstr (symbol-name (car local)))))
7868 (ignore-errors
7869 (set (make-local-variable (car local))
7870 (cdr local)))))
7871 locals)))
7874 ;;; MIME functions
7877 (defvar message-inhibit-body-encoding nil)
7879 (defun message-encode-message-body ()
7880 (unless message-inhibit-body-encoding
7881 (let ((mail-parse-charset (or mail-parse-charset
7882 message-default-charset))
7883 (case-fold-search t)
7884 lines content-type-p)
7885 (message-goto-body)
7886 (save-restriction
7887 (narrow-to-region (point) (point-max))
7888 (let ((new (mml-generate-mime)))
7889 (when new
7890 (delete-region (point-min) (point-max))
7891 (insert new)
7892 (goto-char (point-min))
7893 (if (eq (aref new 0) ?\n)
7894 (delete-char 1)
7895 (search-forward "\n\n")
7896 (setq lines (buffer-substring (point-min) (1- (point))))
7897 (delete-region (point-min) (point))))))
7898 (save-restriction
7899 (message-narrow-to-headers-or-head)
7900 (message-remove-header "Mime-Version")
7901 (goto-char (point-max))
7902 (insert "MIME-Version: 1.0\n")
7903 (when lines
7904 (insert lines))
7905 (setq content-type-p
7906 (or mml-boundary
7907 (re-search-backward "^Content-Type:" nil t))))
7908 (save-restriction
7909 (message-narrow-to-headers-or-head)
7910 (message-remove-first-header "Content-Type")
7911 (message-remove-first-header "Content-Transfer-Encoding"))
7912 ;; We always make sure that the message has a Content-Type
7913 ;; header. This is because some broken MTAs and MUAs get
7914 ;; awfully confused when confronted with a message with a
7915 ;; MIME-Version header and without a Content-Type header. For
7916 ;; instance, Solaris' /usr/bin/mail.
7917 (unless content-type-p
7918 (goto-char (point-min))
7919 ;; For unknown reason, MIME-Version doesn't exist.
7920 (when (re-search-forward "^MIME-Version:" nil t)
7921 (forward-line 1)
7922 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7924 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7925 "Read from the minibuffer while providing abbrev expansion."
7926 (if (fboundp 'mail-abbrevs-setup)
7927 (let ((mail-abbrev-mode-regexp "")
7928 (minibuffer-setup-hook 'mail-abbrevs-setup)
7929 (minibuffer-local-map message-minibuffer-local-map))
7930 (read-from-minibuffer prompt initial-contents))
7931 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7932 (minibuffer-local-map message-minibuffer-local-map))
7933 (read-string prompt initial-contents))))
7935 (defun message-use-alternative-email-as-from ()
7936 "Set From field of the outgoing message to the first matching
7937 address in `message-alternative-emails', looking at To, Cc and
7938 From headers in the original article."
7939 (require 'mail-utils)
7940 (let* ((fields '("To" "Cc" "From"))
7941 (emails
7942 (split-string
7943 (mail-strip-quoted-names
7944 (mapconcat 'message-fetch-reply-field fields ","))
7945 "[ \f\t\n\r\v,]+"))
7946 email)
7947 (while emails
7948 (if (string-match message-alternative-emails (car emails))
7949 (setq email (car emails)
7950 emails nil))
7951 (pop emails))
7952 (unless (or (not email) (equal email user-mail-address))
7953 (message-remove-header "From")
7954 (goto-char (point-max))
7955 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7956 "\n"))))
7958 (defun message-options-get (symbol)
7959 (cdr (assq symbol message-options)))
7961 (defun message-options-set (symbol value)
7962 (let ((the-cons (assq symbol message-options)))
7963 (if the-cons
7964 (if value
7965 (setcdr the-cons value)
7966 (setq message-options (delq the-cons message-options)))
7967 (and value
7968 (push (cons symbol value) message-options))))
7969 value)
7971 (defun message-options-set-recipient ()
7972 (save-restriction
7973 (message-narrow-to-headers-or-head)
7974 (message-options-set 'message-sender
7975 (mail-strip-quoted-names
7976 (message-fetch-field "from")))
7977 (message-options-set 'message-recipients
7978 (mail-strip-quoted-names
7979 (let ((to (message-fetch-field "to"))
7980 (cc (message-fetch-field "cc"))
7981 (bcc (message-fetch-field "bcc")))
7982 (concat
7983 (or to "")
7984 (if (and to cc) ", ")
7985 (or cc "")
7986 (if (and (or to cc) bcc) ", ")
7987 (or bcc "")))))))
7989 (defun message-hide-headers ()
7990 "Hide headers based on the `message-hidden-headers' variable."
7991 (let ((regexps (if (stringp message-hidden-headers)
7992 (list message-hidden-headers)
7993 message-hidden-headers))
7994 (inhibit-point-motion-hooks t)
7995 (after-change-functions nil)
7996 (end-of-headers (point-min)))
7997 (when regexps
7998 (save-excursion
7999 (save-restriction
8000 (message-narrow-to-headers)
8001 (goto-char (point-min))
8002 (while (not (eobp))
8003 (if (not (message-hide-header-p regexps))
8004 (message-next-header)
8005 (let ((begin (point))
8006 header header-len)
8007 (message-next-header)
8008 (setq header (buffer-substring begin (point))
8009 header-len (- (point) begin))
8010 (delete-region begin (point))
8011 (goto-char end-of-headers)
8012 (insert header)
8013 (setq end-of-headers
8014 (+ end-of-headers header-len))))))))
8015 (narrow-to-region end-of-headers (point-max))))
8017 (defun message-hide-header-p (regexps)
8018 (let ((result nil)
8019 (reverse nil))
8020 (when (eq (car regexps) 'not)
8021 (setq reverse t)
8022 (pop regexps))
8023 (dolist (regexp regexps)
8024 (setq result (or result (looking-at regexp))))
8025 (if reverse
8026 (not result)
8027 result)))
8029 (declare-function ecomplete-add-item "ecomplete" (type key text))
8030 (declare-function ecomplete-save "ecomplete" ())
8032 (defun message-put-addresses-in-ecomplete ()
8033 (require 'ecomplete)
8034 (dolist (header '("to" "cc" "from" "reply-to"))
8035 (let ((value (message-field-value header)))
8036 (dolist (string (mail-header-parse-addresses value 'raw))
8037 (setq string
8038 (gnus-replace-in-string
8039 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8040 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8041 string))))
8042 (ecomplete-save))
8044 (autoload 'ecomplete-display-matches "ecomplete")
8046 (defun message-display-abbrev (&optional choose)
8047 "Display the next possible abbrev for the text before point."
8048 (interactive (list t))
8049 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8050 (message-point-in-header-p)
8051 (save-excursion
8052 (beginning-of-line)
8053 (while (and (memq (char-after) '(?\t ? ))
8054 (zerop (forward-line -1))))
8055 (looking-at "To:\\|Cc:")))
8056 (let* ((end (point))
8057 (start (save-excursion
8058 (and (re-search-backward "[\n\t ]" nil t)
8059 (1+ (point)))))
8060 (word (when start (buffer-substring start end)))
8061 (match (when (and word
8062 (not (zerop (length word))))
8063 (ecomplete-display-matches 'mail word choose))))
8064 (when (and choose match)
8065 (delete-region start end)
8066 (insert match)))))
8068 ;; To send pre-formatted letters like the example below, you can use
8069 ;; `message-send-form-letter':
8070 ;; --8<---------------cut here---------------start------------->8---
8071 ;; To: alice@invalid.invalid
8072 ;; Subject: Verification of your contact information
8073 ;; From: Contact verification <admin@foo.invalid>
8074 ;; --text follows this line--
8075 ;; Hi Alice,
8076 ;; please verify that your contact information is still valid:
8077 ;; Alice A, A avenue 11, 1111 A town, Austria
8078 ;; ----------next form letter message follows this line----------
8079 ;; To: bob@invalid.invalid
8080 ;; Subject: Verification of your contact information
8081 ;; From: Contact verification <admin@foo.invalid>
8082 ;; --text follows this line--
8083 ;; Hi Bob,
8084 ;; please verify that your contact information is still valid:
8085 ;; Bob, B street 22, 22222 Be town, Belgium
8086 ;; ----------next form letter message follows this line----------
8087 ;; To: charlie@invalid.invalid
8088 ;; Subject: Verification of your contact information
8089 ;; From: Contact verification <admin@foo.invalid>
8090 ;; --text follows this line--
8091 ;; Hi Charlie,
8092 ;; please verify that your contact information is still valid:
8093 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8094 ;; --8<---------------cut here---------------end--------------->8---
8096 ;; FIXME: What is the most common term (circular letter, form letter, serial
8097 ;; letter, standard letter) for such kind of letter? See also
8098 ;; <http://en.wikipedia.org/wiki/Form_letter>
8100 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8101 ;; `message-form-letter-separator', i.e. highlight each message like a single
8102 ;; message.
8104 (defcustom message-form-letter-separator
8105 "\n----------next form letter message follows this line----------\n"
8106 "Separator for `message-send-form-letter'."
8107 ;; :group 'message-form-letter
8108 :group 'message-various
8109 :version "23.1" ;; No Gnus
8110 :type 'string)
8112 (defcustom message-send-form-letter-delay 1
8113 "Delay in seconds when sending a message with `message-send-form-letter'.
8114 Only used when `message-send-form-letter' is called with non-nil
8115 argument `force'."
8116 ;; :group 'message-form-letter
8117 :group 'message-various
8118 :version "23.1" ;; No Gnus
8119 :type 'integer)
8121 (defun message-send-form-letter (&optional force)
8122 "Sent all form letter messages from current buffer.
8123 Unless FORCE, prompt before sending.
8125 The messages are separated by `message-form-letter-separator'.
8126 Header and body are separated by `mail-header-separator'."
8127 (interactive "P")
8128 (let ((sent 0) (skipped 0)
8129 start end text
8130 buff
8131 to done)
8132 (goto-char (point-min))
8133 (while (not done)
8134 (setq start (point)
8135 end (if (search-forward message-form-letter-separator nil t)
8136 (- (point) (length message-form-letter-separator) -1)
8137 (setq done t)
8138 (point-max)))
8139 (setq text
8140 (buffer-substring-no-properties start end))
8141 (setq buff (generate-new-buffer "*mail - form letter*"))
8142 (with-current-buffer buff
8143 (insert text)
8144 (message-mode)
8145 (setq to (message-fetch-field "To"))
8146 (switch-to-buffer buff)
8147 (when force
8148 (sit-for message-send-form-letter-delay))
8149 (if (or force
8150 (y-or-n-p (format "Send message to `%s'? " to)))
8151 (progn
8152 (setq sent (1+ sent))
8153 (message-send-and-exit))
8154 (message (format "Message to `%s' skipped." to))
8155 (setq skipped (1+ skipped)))
8156 (when (buffer-live-p buff)
8157 (kill-buffer buff))))
8158 (message "%s message(s) sent, %s skipped." sent skipped)))
8160 (defun message-replace-header (header new-value &optional after force)
8161 "Remove HEADER and insert the NEW-VALUE.
8162 If AFTER, insert after this header. If FORCE, insert new field
8163 even if NEW-VALUE is empty."
8164 ;; Similar to `nnheader-replace-header' but for message buffers.
8165 (save-excursion
8166 (save-restriction
8167 (message-narrow-to-headers)
8168 (message-remove-header header))
8169 (when (or force (> (length new-value) 0))
8170 (if after
8171 (message-position-on-field header after)
8172 (message-position-on-field header))
8173 (insert new-value))))
8175 (defcustom message-recipients-without-full-name
8176 (list "ding@gnus.org"
8177 "bugs@gnus.org"
8178 "emacs-devel@gnu.org"
8179 "emacs-pretest-bug@gnu.org"
8180 "bug-gnu-emacs@gnu.org")
8181 "Mail addresses that have no full name.
8182 Used in `message-simplify-recipients'."
8183 ;; Maybe the addresses could be extracted from
8184 ;; `gnus-parameter-to-list-alist'?
8185 :type '(choice (const :tag "None" nil)
8186 (repeat string))
8187 :version "23.1" ;; No Gnus
8188 :group 'message-headers)
8190 (defun message-simplify-recipients ()
8191 (interactive)
8192 (dolist (hdr '("Cc" "To"))
8193 (message-replace-header
8195 (mapconcat
8196 (lambda (addrcomp)
8197 (if (and message-recipients-without-full-name
8198 (string-match
8199 (regexp-opt message-recipients-without-full-name)
8200 (cadr addrcomp)))
8201 (cadr addrcomp)
8202 (if (car addrcomp)
8203 (message-make-from (car addrcomp) (cadr addrcomp))
8204 (cadr addrcomp))))
8205 (when (message-fetch-field hdr)
8206 (mail-extract-address-components
8207 (message-fetch-field hdr) t))
8208 ", "))))
8210 (when (featurep 'xemacs)
8211 (require 'messagexmas)
8212 (message-xmas-redefine))
8214 (provide 'message)
8216 (run-hooks 'message-load-hook)
8218 ;; Local Variables:
8219 ;; coding: iso-8859-1
8220 ;; End:
8222 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
8223 ;;; message.el ends here