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