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