(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / gnus / message.el
blobeaac4e390a9c87d9efeac755185ff6cf2507fbe6
1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
31 ;;; Code:
33 (eval-when-compile
34 (require 'cl)
35 (defvar gnus-message-group-art)
36 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
37 (require 'canlock)
38 (require 'mailheader)
39 (require 'nnheader)
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (if (featurep 'xemacs)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
46 (require 'mail-parse)
47 (require 'mml)
48 (require 'rfc822)
49 (eval-and-compile
50 (autoload 'gnus-find-method-for-group "gnus")
51 (autoload 'nnvirtual-find-group-art "nnvirtual")
52 (autoload 'gnus-group-decoded-name "gnus-group"))
54 (defgroup message '((user-mail-address custom-variable)
55 (user-full-name custom-variable))
56 "Mail and news message composing."
57 :link '(custom-manual "(message)Top")
58 :group 'mail
59 :group 'news)
61 (put 'user-mail-address 'custom-type 'string)
62 (put 'user-full-name 'custom-type 'string)
64 (defgroup message-various nil
65 "Various Message Variables"
66 :link '(custom-manual "(message)Various Message Variables")
67 :group 'message)
69 (defgroup message-buffers nil
70 "Message Buffers"
71 :link '(custom-manual "(message)Message Buffers")
72 :group 'message)
74 (defgroup message-sending nil
75 "Message Sending"
76 :link '(custom-manual "(message)Sending Variables")
77 :group 'message)
79 (defgroup message-interface nil
80 "Message Interface"
81 :link '(custom-manual "(message)Interface")
82 :group 'message)
84 (defgroup message-forwarding nil
85 "Message Forwarding"
86 :link '(custom-manual "(message)Forwarding")
87 :group 'message-interface)
89 (defgroup message-insertion nil
90 "Message Insertion"
91 :link '(custom-manual "(message)Insertion")
92 :group 'message)
94 (defgroup message-headers nil
95 "Message Headers"
96 :link '(custom-manual "(message)Message Headers")
97 :group 'message)
99 (defgroup message-news nil
100 "Composing News Messages"
101 :group 'message)
103 (defgroup message-mail nil
104 "Composing Mail Messages"
105 :group 'message)
107 (defgroup message-faces nil
108 "Faces used for message composing."
109 :group 'message
110 :group 'faces)
112 (defcustom message-directory "~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group 'message-various
115 :type 'directory)
117 (defcustom message-max-buffers 10
118 "*How many buffers to keep before starting to kill them off."
119 :group 'message-buffers
120 :type 'integer)
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group 'message-buffers
125 :type '(choice function (const nil)))
127 (defcustom message-fcc-handler-function 'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
131 mailbox format."
132 :type '(radio (function-item message-output)
133 (function :tag "Other"))
134 :group 'message-sending)
136 (defcustom message-fcc-externalize-attachments nil
137 "If non-nil, attachments are included as external parts in Fcc copies."
138 :version "22.1"
139 :type 'boolean
140 :group 'message-sending)
142 (defcustom message-courtesy-message
143 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
144 "*This is inserted at the start of a mailed copy of a posted message.
145 If the string contains the format spec \"%s\", the Newsgroups
146 the article has been posted to will be inserted there.
147 If this variable is nil, no such courtesy message will be added."
148 :group 'message-sending
149 :type '(radio string (const nil)))
151 (defcustom message-ignored-bounced-headers
152 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
153 "*Regexp that matches headers to be removed in resent bounced mail."
154 :group 'message-interface
155 :type 'regexp)
157 ;;;###autoload
158 (defcustom message-from-style 'default
159 "*Specifies how \"From\" headers look.
161 If nil, they contain just the return address like:
162 king@grassland.com
163 If `parens', they look like:
164 king@grassland.com (Elvis Parsley)
165 If `angles', they look like:
166 Elvis Parsley <king@grassland.com>
168 Otherwise, most addresses look like `angles', but they look like
169 `parens' if `angles' would need quoting and `parens' would not."
170 :type '(choice (const :tag "simple" nil)
171 (const parens)
172 (const angles)
173 (const default))
174 :group 'message-headers)
176 (defcustom message-insert-canlock t
177 "Whether to insert a Cancel-Lock header in news postings."
178 :version "22.1"
179 :group 'message-headers
180 :type 'boolean)
182 (defcustom message-syntax-checks
183 (if message-insert-canlock '((sender . disabled)) nil)
184 ;; Guess this one shouldn't be easy to customize...
185 "*Controls what syntax checks should not be performed on outgoing posts.
186 To disable checking of long signatures, for instance, add
187 `(signature . disabled)' to this list.
189 Don't touch this variable unless you really know what you're doing.
191 Checks include `subject-cmsg', `multiple-headers', `sendsys',
192 `message-id', `from', `long-lines', `control-chars', `size',
193 `new-text', `quoting-style', `redirected-followup', `signature',
194 `approved', `sender', `empty', `empty-headers', `message-id', `from',
195 `subject', `shorten-followup-to', `existing-newsgroups',
196 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
197 `continuation-headers', `long-header-lines', `invisible-text' and
198 `illegible-text'."
199 :group 'message-news
200 :type '(repeat sexp)) ; Fixme: improve this
202 (defcustom message-required-headers '((optional . References)
203 From)
204 "*Headers to be generated or prompted for when sending a message.
205 Also see `message-required-news-headers' and
206 `message-required-mail-headers'."
207 :version "22.1"
208 :group 'message-news
209 :group 'message-headers
210 :link '(custom-manual "(message)Message Headers")
211 :type '(repeat sexp))
213 (defcustom message-draft-headers '(References From)
214 "*Headers to be generated when saving a draft message."
215 :version "22.1"
216 :group 'message-news
217 :group 'message-headers
218 :link '(custom-manual "(message)Message Headers")
219 :type '(repeat sexp))
221 (defcustom message-required-news-headers
222 '(From Newsgroups Subject Date Message-ID
223 (optional . Organization)
224 (optional . User-Agent))
225 "*Headers to be generated or prompted for when posting an article.
226 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
227 Message-ID. Organization, Lines, In-Reply-To, Expires, and
228 User-Agent are optional. If don't you want message to insert some
229 header, remove it from this list."
230 :group 'message-news
231 :group 'message-headers
232 :link '(custom-manual "(message)Message Headers")
233 :type '(repeat sexp))
235 (defcustom message-required-mail-headers
236 '(From Subject Date (optional . In-Reply-To) Message-ID
237 (optional . User-Agent))
238 "*Headers to be generated or prompted for when mailing a message.
239 It is recommended that From, Date, To, Subject and Message-ID be
240 included. Organization and User-Agent are optional."
241 :group 'message-mail
242 :group 'message-headers
243 :link '(custom-manual "(message)Message Headers")
244 :type '(repeat sexp))
246 (defcustom message-deletable-headers '(Message-ID Date Lines)
247 "Headers to be deleted if they already exist and were generated by message previously."
248 :group 'message-headers
249 :link '(custom-manual "(message)Message Headers")
250 :type 'sexp)
252 (defcustom message-ignored-news-headers
253 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
254 "*Regexp of headers to be removed unconditionally before posting."
255 :group 'message-news
256 :group 'message-headers
257 :link '(custom-manual "(message)Message Headers")
258 :type '(repeat :value-to-internal (lambda (widget value)
259 (custom-split-regexp-maybe value))
260 :match (lambda (widget value)
261 (or (stringp value)
262 (widget-editable-list-match widget value)))
263 regexp))
265 (defcustom message-ignored-mail-headers
266 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
267 "*Regexp of headers to be removed unconditionally before mailing."
268 :group 'message-mail
269 :group 'message-headers
270 :link '(custom-manual "(message)Mail Headers")
271 :type 'regexp)
273 (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:"
274 "*Header lines matching this regexp will be deleted before posting.
275 It's best to delete old Path and Date headers before posting to avoid
276 any confusion."
277 :group 'message-interface
278 :link '(custom-manual "(message)Superseding")
279 :type '(repeat :value-to-internal (lambda (widget value)
280 (custom-split-regexp-maybe value))
281 :match (lambda (widget value)
282 (or (stringp value)
283 (widget-editable-list-match widget value)))
284 regexp))
286 (defcustom message-subject-re-regexp
287 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
288 "*Regexp matching \"Re: \" in the subject line."
289 :group 'message-various
290 :link '(custom-manual "(message)Message Headers")
291 :type 'regexp)
293 ;;; Start of variables adopted from `message-utils.el'.
295 (defcustom message-subject-trailing-was-query 'ask
296 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
297 If nil, leave the subject unchanged. If it is the symbol `ask', query
298 the user what do do. In this case, the subject is matched against
299 `message-subject-trailing-was-ask-regexp'. If
300 `message-subject-trailing-was-query' is t, always strip the trailing
301 old subject. In this case, `message-subject-trailing-was-regexp' is
302 used."
303 :version "22.1"
304 :type '(choice (const :tag "never" nil)
305 (const :tag "always strip" t)
306 (const ask))
307 :link '(custom-manual "(message)Message Headers")
308 :group 'message-various)
310 (defcustom message-subject-trailing-was-ask-regexp
311 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
312 "*Regexp matching \"(was: <old subject>)\" in the subject line.
314 The function `message-strip-subject-trailing-was' uses this regexp if
315 `message-subject-trailing-was-query' is set to the symbol `ask'. If
316 the variable is t instead of `ask', use
317 `message-subject-trailing-was-regexp' instead.
319 It is okay to create some false positives here, as the user is asked."
320 :version "22.1"
321 :group 'message-various
322 :link '(custom-manual "(message)Message Headers")
323 :type 'regexp)
325 (defcustom message-subject-trailing-was-regexp
326 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
327 "*Regexp matching \"(was: <old subject>)\" in the subject line.
329 If `message-subject-trailing-was-query' is set to t, the subject is
330 matched against `message-subject-trailing-was-regexp' in
331 `message-strip-subject-trailing-was'. You should use a regexp creating very
332 few false positives here."
333 :version "22.1"
334 :group 'message-various
335 :link '(custom-manual "(message)Message Headers")
336 :type 'regexp)
338 ;;; marking inserted text
340 (defcustom message-mark-insert-begin
341 "--8<---------------cut here---------------start------------->8---\n"
342 "How to mark the beginning of some inserted text."
343 :version "22.1"
344 :type 'string
345 :link '(custom-manual "(message)Insertion Variables")
346 :group 'message-various)
348 (defcustom message-mark-insert-end
349 "--8<---------------cut here---------------end--------------->8---\n"
350 "How to mark the end of some inserted text."
351 :version "22.1"
352 :type 'string
353 :link '(custom-manual "(message)Insertion Variables")
354 :group 'message-various)
356 (defcustom message-archive-header "X-No-Archive: Yes\n"
357 "Header to insert when you don't want your article to be archived.
358 Archives \(such as groups.google.com\) respect this header."
359 :version "22.1"
360 :type 'string
361 :link '(custom-manual "(message)Header Commands")
362 :group 'message-various)
364 (defcustom message-archive-note
365 "X-No-Archive: Yes - save http://groups.google.com/"
366 "Note to insert why you wouldn't want this posting archived.
367 If nil, don't insert any text in the body."
368 :version "22.1"
369 :type '(radio string (const nil))
370 :link '(custom-manual "(message)Header Commands")
371 :group 'message-various)
373 ;;; Crossposts and Followups
374 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
375 ;; new suggestions by R. Weikusat <rw at another.de>
377 (defvar message-cross-post-old-target nil
378 "Old target for cross-posts or follow-ups.")
379 (make-variable-buffer-local 'message-cross-post-old-target)
381 (defcustom message-cross-post-default t
382 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
383 If nil, `message-cross-post-followup-to' will only do a followup. Note that
384 you can explicitly override this setting by calling
385 `message-cross-post-followup-to' with a prefix."
386 :version "22.1"
387 :type 'boolean
388 :group 'message-various)
390 (defcustom message-cross-post-note "Crosspost & Followup-To: "
391 "Note to insert before signature to notify of cross-post and follow-up."
392 :version "22.1"
393 :type 'string
394 :group 'message-various)
396 (defcustom message-followup-to-note "Followup-To: "
397 "Note to insert before signature to notify of follow-up only."
398 :version "22.1"
399 :type 'string
400 :group 'message-various)
402 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
403 "Function to use to insert note about Crosspost or Followup-To.
404 The function will be called with four arguments. The function should not only
405 insert a note, but also ensure old notes are deleted. See the documentation
406 for `message-cross-post-insert-note'."
407 :version "22.1"
408 :type 'function
409 :group 'message-various)
411 ;;; End of variables adopted from `message-utils.el'.
413 ;;;###autoload
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 "*Non-nil means create a new message buffer whenever `message-setup' is called.
436 If this is a function, call that function with three parameters: The type,
437 the to address and the group name. (Any of these may be nil.) The function
438 should return the new buffer name."
439 :group 'message-buffers
440 :link '(custom-manual "(message)Message Buffers")
441 :type '(choice (const :tag "off" nil)
442 (const :tag "unique" unique)
443 (const :tag "unsent" unsent)
444 (function fun)))
446 (defcustom message-kill-buffer-on-exit nil
447 "*Non-nil means that the message buffer will be killed after sending a message."
448 :group 'message-buffers
449 :link '(custom-manual "(message)Message Buffers")
450 :type 'boolean)
452 (eval-when-compile
453 (defvar gnus-local-organization))
454 (defcustom message-user-organization
455 (or (and (boundp 'gnus-local-organization)
456 (stringp gnus-local-organization)
457 gnus-local-organization)
458 (getenv "ORGANIZATION")
460 "*String to be used as an Organization header.
461 If t, use `message-user-organization-file'."
462 :group 'message-headers
463 :type '(choice string
464 (const :tag "consult file" t)))
466 ;;;###autoload
467 (defcustom message-user-organization-file "/usr/lib/news/organization"
468 "*Local news organization file."
469 :type 'file
470 :link '(custom-manual "(message)News Headers")
471 :group 'message-headers)
473 (defcustom message-make-forward-subject-function
474 #'message-forward-subject-name-subject
475 "*List of functions called to generate subject headers for forwarded messages.
476 The subject generated by the previous function is passed into each
477 successive function.
479 The provided functions are:
481 * `message-forward-subject-author-subject' Source of article (author or
482 newsgroup), in brackets followed by the subject
483 * `message-forward-subject-name-subject' Source of article (name of author
484 or newsgroup), in brackets followed by the subject
485 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
486 to it."
487 :group 'message-forwarding
488 :link '(custom-manual "(message)Forwarding")
489 :type '(radio (function-item message-forward-subject-author-subject)
490 (function-item message-forward-subject-fwd)
491 (function-item message-forward-subject-name-subject)
492 (repeat :tag "List of functions" function)))
494 (defcustom message-forward-as-mime t
495 "*Non-nil means forward messages as an inline/rfc822 MIME section.
496 Otherwise, directly inline the old message in the forwarded message."
497 :version "21.1"
498 :group 'message-forwarding
499 :link '(custom-manual "(message)Forwarding")
500 :type 'boolean)
502 (defcustom message-forward-show-mml 'best
503 "*Non-nil means show forwarded messages as MML (decoded from MIME).
504 Otherwise, forwarded messages are unchanged.
505 Can also be the symbol `best' to indicate that MML should be
506 used, except when it is a bad idea to use MML. One example where
507 it is a bad idea is when forwarding a signed or encrypted
508 message, because converting MIME to MML would invalidate the
509 digital signature."
510 :version "21.1"
511 :group 'message-forwarding
512 :type '(choice (const :tag "use MML" t)
513 (const :tag "don't use MML " nil)
514 (const :tag "use MML when appropriate" best)))
516 (defcustom message-forward-before-signature t
517 "*Non-nil means put forwarded message before signature, else after."
518 :group 'message-forwarding
519 :type 'boolean)
521 (defcustom message-wash-forwarded-subjects nil
522 "*Non-nil means try to remove as much cruft as possible from the subject.
523 Done before generating the new subject of a forward."
524 :group 'message-forwarding
525 :link '(custom-manual "(message)Forwarding")
526 :type 'boolean)
528 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
529 "*All headers that match this regexp will be deleted when resending a message."
530 :group 'message-interface
531 :link '(custom-manual "(message)Resending")
532 :type '(repeat :value-to-internal (lambda (widget value)
533 (custom-split-regexp-maybe value))
534 :match (lambda (widget value)
535 (or (stringp value)
536 (widget-editable-list-match widget value)))
537 regexp))
539 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
540 "*All headers that match this regexp will be deleted when forwarding a message."
541 :version "21.1"
542 :group 'message-forwarding
543 :type '(repeat :value-to-internal (lambda (widget value)
544 (custom-split-regexp-maybe value))
545 :match (lambda (widget value)
546 (or (stringp value)
547 (widget-editable-list-match widget value)))
548 regexp))
550 (defcustom message-ignored-cited-headers "."
551 "*Delete these headers from the messages you yank."
552 :group 'message-insertion
553 :link '(custom-manual "(message)Insertion Variables")
554 :type 'regexp)
556 (defcustom message-cite-prefix-regexp
557 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
558 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
559 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
560 (let ((old-table (syntax-table))
561 non-word-constituents)
562 (set-syntax-table text-mode-syntax-table)
563 (setq non-word-constituents
564 (concat
565 (if (string-match "\\w" "-") "" "-")
566 (if (string-match "\\w" "_") "" "_")
567 (if (string-match "\\w" ".") "" ".")))
568 (set-syntax-table old-table)
569 (if (equal non-word-constituents "")
570 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
571 (concat "\\([ \t]*\\(\\w\\|["
572 non-word-constituents
573 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
574 "*Regexp matching the longest possible citation prefix on a line."
575 :version "22.1"
576 :group 'message-insertion
577 :link '(custom-manual "(message)Insertion Variables")
578 :type 'regexp)
580 (defcustom message-cancel-message "I am canceling my own article.\n"
581 "Message to be inserted in the cancel message."
582 :group 'message-interface
583 :link '(custom-manual "(message)Canceling News")
584 :type 'string)
586 ;; Useful to set in site-init.el
587 ;;;###autoload
588 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
589 "Function to call to send the current buffer as mail.
590 The headers should be delimited by a line whose contents match the
591 variable `mail-header-separator'.
593 Valid values include `message-send-mail-with-sendmail' (the default),
594 `message-send-mail-with-mh', `message-send-mail-with-qmail',
595 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
597 See also `send-mail-function'."
598 :type '(radio (function-item message-send-mail-with-sendmail)
599 (function-item message-send-mail-with-mh)
600 (function-item message-send-mail-with-qmail)
601 (function-item message-smtpmail-send-it)
602 (function-item smtpmail-send-it)
603 (function-item feedmail-send-it)
604 (function :tag "Other"))
605 :group 'message-sending
606 :link '(custom-manual "(message)Mail Variables")
607 :group 'message-mail)
609 (defcustom message-send-news-function 'message-send-news
610 "Function to call to send the current buffer as news.
611 The headers should be delimited by a line whose contents match the
612 variable `mail-header-separator'."
613 :group 'message-sending
614 :group 'message-news
615 :link '(custom-manual "(message)News Variables")
616 :type 'function)
618 (defcustom message-reply-to-function nil
619 "If non-nil, function that should return a list of headers.
620 This function should pick out addresses from the To, Cc, and From headers
621 and respond with new To and Cc headers."
622 :group 'message-interface
623 :link '(custom-manual "(message)Reply")
624 :type '(choice function (const nil)))
626 (defcustom message-wide-reply-to-function nil
627 "If non-nil, function that should return a list of headers.
628 This function should pick out addresses from the To, Cc, and From headers
629 and respond with new To and Cc headers."
630 :group 'message-interface
631 :link '(custom-manual "(message)Wide Reply")
632 :type '(choice function (const nil)))
634 (defcustom message-followup-to-function nil
635 "If non-nil, function that should return a list of headers.
636 This function should pick out addresses from the To, Cc, and From headers
637 and respond with new To and Cc headers."
638 :group 'message-interface
639 :link '(custom-manual "(message)Followup")
640 :type '(choice function (const nil)))
642 (defcustom message-use-followup-to 'ask
643 "*Specifies what to do with Followup-To header.
644 If nil, always ignore the header. If it is t, use its value, but
645 query before using the \"poster\" value. If it is the symbol `ask',
646 always query the user whether to use the value. If it is the symbol
647 `use', always use the value."
648 :group 'message-interface
649 :link '(custom-manual "(message)Followup")
650 :type '(choice (const :tag "ignore" nil)
651 (const :tag "use & query" t)
652 (const use)
653 (const ask)))
655 (defcustom message-use-mail-followup-to 'use
656 "*Specifies what to do with Mail-Followup-To header.
657 If nil, always ignore the header. If it is the symbol `ask', always
658 query the user whether to use the value. If it is the symbol `use',
659 always use the value."
660 :version "22.1"
661 :group 'message-interface
662 :link '(custom-manual "(message)Mailing Lists")
663 :type '(choice (const :tag "ignore" nil)
664 (const use)
665 (const ask)))
667 (defcustom message-subscribed-address-functions nil
668 "*Specifies functions for determining list subscription.
669 If nil, do not attempt to determine list subscription with functions.
670 If non-nil, this variable contains a list of functions which return
671 regular expressions to match lists. These functions can be used in
672 conjunction with `message-subscribed-regexps' and
673 `message-subscribed-addresses'."
674 :version "22.1"
675 :group 'message-interface
676 :link '(custom-manual "(message)Mailing Lists")
677 :type '(repeat sexp))
679 (defcustom message-subscribed-address-file nil
680 "*A file containing addresses the user is subscribed to.
681 If nil, do not look at any files to determine list subscriptions. If
682 non-nil, each line of this file should be a mailing list address."
683 :version "22.1"
684 :group 'message-interface
685 :link '(custom-manual "(message)Mailing Lists")
686 :type '(radio file (const nil)))
688 (defcustom message-subscribed-addresses nil
689 "*Specifies a list of addresses the user is subscribed to.
690 If nil, do not use any predefined list subscriptions. This list of
691 addresses can be used in conjunction with
692 `message-subscribed-address-functions' and `message-subscribed-regexps'."
693 :version "22.1"
694 :group 'message-interface
695 :link '(custom-manual "(message)Mailing Lists")
696 :type '(repeat string))
698 (defcustom message-subscribed-regexps nil
699 "*Specifies a list of addresses the user is subscribed to.
700 If nil, do not use any predefined list subscriptions. This list of
701 regular expressions can be used in conjunction with
702 `message-subscribed-address-functions' and `message-subscribed-addresses'."
703 :version "22.1"
704 :group 'message-interface
705 :link '(custom-manual "(message)Mailing Lists")
706 :type '(repeat regexp))
708 (defcustom message-allow-no-recipients 'ask
709 "Specifies what to do when there are no recipients other than Gcc/Fcc.
710 If it is the symbol `always', the posting is allowed. If it is the
711 symbol `never', the posting is not allowed. If it is the symbol
712 `ask', you are prompted."
713 :version "22.1"
714 :group 'message-interface
715 :link '(custom-manual "(message)Message Headers")
716 :type '(choice (const always)
717 (const never)
718 (const ask)))
720 (defcustom message-sendmail-f-is-evil nil
721 "*Non-nil means don't add \"-f username\" to the sendmail command line.
722 Doing so would be even more evil than leaving it out."
723 :group 'message-sending
724 :link '(custom-manual "(message)Mail Variables")
725 :type 'boolean)
727 (defcustom message-sendmail-envelope-from nil
728 "*Envelope-from when sending mail with sendmail.
729 If this is nil, use `user-mail-address'. If it is the symbol
730 `header', use the From: header of the message."
731 :version "22.1"
732 :type '(choice (string :tag "From name")
733 (const :tag "Use From: header from message" header)
734 (const :tag "Use `user-mail-address'" nil))
735 :link '(custom-manual "(message)Mail Variables")
736 :group 'message-sending)
738 ;; qmail-related stuff
739 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
740 "Location of the qmail-inject program."
741 :group 'message-sending
742 :link '(custom-manual "(message)Mail Variables")
743 :type 'file)
745 (defcustom message-qmail-inject-args nil
746 "Arguments passed to qmail-inject programs.
747 This should be a list of strings, one string for each argument. It
748 may also be a function.
750 For e.g., if you wish to set the envelope sender address so that bounces
751 go to the right place or to deal with listserv's usage of that address, you
752 might set this variable to '(\"-f\" \"you@some.where\")."
753 :group 'message-sending
754 :link '(custom-manual "(message)Mail Variables")
755 :type '(choice (function)
756 (repeat string)))
758 (defvar message-cater-to-broken-inn t
759 "Non-nil means Gnus should not fold the `References' header.
760 Folding `References' makes ancient versions of INN create incorrect
761 NOV lines.")
763 (eval-when-compile
764 (defvar gnus-post-method)
765 (defvar gnus-select-method))
766 (defcustom message-post-method
767 (cond ((and (boundp 'gnus-post-method)
768 (listp gnus-post-method)
769 gnus-post-method)
770 gnus-post-method)
771 ((boundp 'gnus-select-method)
772 gnus-select-method)
773 (t '(nnspool "")))
774 "*Method used to post news.
775 Note that when posting from inside Gnus, for instance, this
776 variable isn't used."
777 :group 'message-news
778 :group 'message-sending
779 ;; This should be the `gnus-select-method' widget, but that might
780 ;; create a dependence to `gnus.el'.
781 :type 'sexp)
783 ;; FIXME: This should be a temporary workaround until someone implements a
784 ;; proper solution. If a crash happens while replying, the auto-save file
785 ;; will *not* have a `References:' header if `message-generate-headers-first'
786 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
787 (defcustom message-generate-headers-first '(references)
788 "Which headers should be generated before starting to compose a message.
789 If t, generate all required headers. This can also be a list of headers to
790 generate. The variables `message-required-news-headers' and
791 `message-required-mail-headers' specify which headers to generate.
793 Note that the variable `message-deletable-headers' specifies headers which
794 are to be deleted and then re-generated before sending, so this variable
795 will not have a visible effect for those headers."
796 :group 'message-headers
797 :link '(custom-manual "(message)Message Headers")
798 :type '(choice (const :tag "None" nil)
799 (const :tag "References" '(references))
800 (const :tag "All" t)
801 (repeat (sexp :tag "Header"))))
803 (defcustom message-setup-hook nil
804 "Normal hook, run each time a new outgoing message is initialized.
805 The function `message-setup' runs this hook."
806 :group 'message-various
807 :link '(custom-manual "(message)Various Message Variables")
808 :type 'hook)
810 (defcustom message-cancel-hook nil
811 "Hook run when cancelling articles."
812 :group 'message-various
813 :link '(custom-manual "(message)Various Message Variables")
814 :type 'hook)
816 (defcustom message-signature-setup-hook nil
817 "Normal hook, run each time a new outgoing message is initialized.
818 It is run after the headers have been inserted and before
819 the signature is inserted."
820 :group 'message-various
821 :link '(custom-manual "(message)Various Message Variables")
822 :type 'hook)
824 (defcustom message-mode-hook nil
825 "Hook run in message mode buffers."
826 :group 'message-various
827 :type 'hook)
829 (defcustom message-header-hook nil
830 "Hook run in a message mode buffer narrowed to the headers."
831 :group 'message-various
832 :type 'hook)
834 (defcustom message-header-setup-hook nil
835 "Hook called narrowed to the headers when setting up a message buffer."
836 :group 'message-various
837 :link '(custom-manual "(message)Various Message Variables")
838 :type 'hook)
840 (defcustom message-minibuffer-local-map
841 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
842 (set-keymap-parent map minibuffer-local-map)
843 map)
844 "Keymap for `message-read-from-minibuffer'."
845 :version "22.1"
846 :group 'message-various)
848 ;;;###autoload
849 (defcustom message-citation-line-function 'message-insert-citation-line
850 "*Function called to insert the \"Whomever writes:\" line.
852 Note that Gnus provides a feature where the reader can click on
853 `writes:' to hide the cited text. If you change this line too much,
854 people who read your message will have to change their Gnus
855 configuration. See the variable `gnus-cite-attribution-suffix'."
856 :type 'function
857 :link '(custom-manual "(message)Insertion Variables")
858 :group 'message-insertion)
860 ;;;###autoload
861 (defcustom message-yank-prefix "> "
862 "*Prefix inserted on the lines of yanked messages.
863 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
864 See also `message-yank-cited-prefix'."
865 :type 'string
866 :link '(custom-manual "(message)Insertion Variables")
867 :group 'message-insertion)
869 (defcustom message-yank-cited-prefix ">"
870 "*Prefix inserted on cited or empty lines of yanked messages.
871 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
872 See also `message-yank-prefix'."
873 :version "22.1"
874 :type 'string
875 :link '(custom-manual "(message)Insertion Variables")
876 :group 'message-insertion)
878 (defcustom message-indentation-spaces 3
879 "*Number of spaces to insert at the beginning of each cited line.
880 Used by `message-yank-original' via `message-yank-cite'."
881 :group 'message-insertion
882 :link '(custom-manual "(message)Insertion Variables")
883 :type 'integer)
885 ;;;###autoload
886 (defcustom message-cite-function 'message-cite-original
887 "*Function for citing an original message.
888 Predefined functions include `message-cite-original' and
889 `message-cite-original-without-signature'.
890 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
891 :type '(radio (function-item message-cite-original)
892 (function-item message-cite-original-without-signature)
893 (function-item sc-cite-original)
894 (function :tag "Other"))
895 :link '(custom-manual "(message)Insertion Variables")
896 :group 'message-insertion)
898 ;;;###autoload
899 (defcustom message-indent-citation-function 'message-indent-citation
900 "*Function for modifying a citation just inserted in the mail buffer.
901 This can also be a list of functions. Each function can find the
902 citation between (point) and (mark t). And each function should leave
903 point and mark around the citation text as modified."
904 :type 'function
905 :link '(custom-manual "(message)Insertion Variables")
906 :group 'message-insertion)
908 ;;;###autoload
909 (defcustom message-signature t
910 "*String to be inserted at the end of the message buffer.
911 If t, the `message-signature-file' file will be inserted instead.
912 If a function, the result from the function will be used instead.
913 If a form, the result from the form will be used instead."
914 :type 'sexp
915 :link '(custom-manual "(message)Insertion Variables")
916 :group 'message-insertion)
918 ;;;###autoload
919 (defcustom message-signature-file "~/.signature"
920 "*Name of file containing the text inserted at end of message buffer.
921 Ignored if the named file doesn't exist.
922 If nil, don't insert a signature."
923 :type '(choice file (const :tags "None" nil))
924 :link '(custom-manual "(message)Insertion Variables")
925 :group 'message-insertion)
927 ;;;###autoload
928 (defcustom message-signature-insert-empty-line t
929 "*If non-nil, insert an empty line before the signature separator."
930 :version "22.1"
931 :type 'boolean
932 :link '(custom-manual "(message)Insertion Variables")
933 :group 'message-insertion)
935 (defcustom message-distribution-function nil
936 "*Function called to return a Distribution header."
937 :group 'message-news
938 :group 'message-headers
939 :link '(custom-manual "(message)News Headers")
940 :type '(choice function (const nil)))
942 (defcustom message-expires 14
943 "Number of days before your article expires."
944 :group 'message-news
945 :group 'message-headers
946 :link '(custom-manual "(message)News Headers")
947 :type 'integer)
949 (defcustom message-user-path nil
950 "If nil, use the NNTP server name in the Path header.
951 If stringp, use this; if non-nil, use no host name (user name only)."
952 :group 'message-news
953 :group 'message-headers
954 :link '(custom-manual "(message)News Headers")
955 :type '(choice (const :tag "nntp" nil)
956 (string :tag "name")
957 (sexp :tag "none" :format "%t" t)))
959 (defvar message-reply-buffer nil)
960 (defvar message-reply-headers nil
961 "The headers of the current replied article.
962 It is a vector of the following headers:
963 \[number subject from date id references chars lines xref extra].")
964 (defvar message-newsreader nil)
965 (defvar message-mailer nil)
966 (defvar message-sent-message-via nil)
967 (defvar message-checksum nil)
968 (defvar message-send-actions nil
969 "A list of actions to be performed upon successful sending of a message.")
970 (defvar message-exit-actions nil
971 "A list of actions to be performed upon exiting after sending a message.")
972 (defvar message-kill-actions nil
973 "A list of actions to be performed before killing a message buffer.")
974 (defvar message-postpone-actions nil
975 "A list of actions to be performed after postponing a message.")
977 (define-widget 'message-header-lines 'text
978 "All header lines must be LFD terminated."
979 :format "%{%t%}:%n%v"
980 :valid-regexp "^\\'"
981 :error "All header lines must be newline terminated")
983 (defcustom message-default-headers ""
984 "*A string containing header lines to be inserted in outgoing messages.
985 It is inserted before you edit the message, so you can edit or delete
986 these lines."
987 :group 'message-headers
988 :link '(custom-manual "(message)Message Headers")
989 :type 'message-header-lines)
991 (defcustom message-default-mail-headers ""
992 "*A string of header lines to be inserted in outgoing mails."
993 :group 'message-headers
994 :group 'message-mail
995 :link '(custom-manual "(message)Mail Headers")
996 :type 'message-header-lines)
998 (defcustom message-default-news-headers ""
999 "*A string of header lines to be inserted in outgoing news articles."
1000 :group 'message-headers
1001 :group 'message-news
1002 :link '(custom-manual "(message)News Headers")
1003 :type 'message-header-lines)
1005 ;; Note: could use /usr/ucb/mail instead of sendmail;
1006 ;; options -t, and -v if not interactive.
1007 (defcustom message-mailer-swallows-blank-line
1008 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1009 system-configuration)
1010 (file-readable-p "/etc/sendmail.cf")
1011 (let ((buffer (get-buffer-create " *temp*")))
1012 (unwind-protect
1013 (save-excursion
1014 (set-buffer buffer)
1015 (insert-file-contents "/etc/sendmail.cf")
1016 (goto-char (point-min))
1017 (let ((case-fold-search nil))
1018 (re-search-forward "^OR\\>" nil t)))
1019 (kill-buffer buffer))))
1020 ;; According to RFC822, "The field-name must be composed of printable
1021 ;; ASCII characters (i. e., characters that have decimal values between
1022 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1023 ;; space, or colon.
1024 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1025 "*Set this non-nil if the system's mailer runs the header and body together.
1026 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1027 The value should be an expression to test whether the problem will
1028 actually occur."
1029 :group 'message-sending
1030 :link '(custom-manual "(message)Mail Variables")
1031 :type 'sexp)
1033 ;;;###autoload
1034 (define-mail-user-agent 'message-user-agent
1035 'message-mail 'message-send-and-exit
1036 'message-kill-buffer 'message-send-hook)
1038 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1039 "If non-nil, delete the deletable headers before feeding to mh.")
1041 (defvar message-send-method-alist
1042 '((news message-news-p message-send-via-news)
1043 (mail message-mail-p message-send-via-mail))
1044 "Alist of ways to send outgoing messages.
1045 Each element has the form
1047 \(TYPE PREDICATE FUNCTION)
1049 where TYPE is a symbol that names the method; PREDICATE is a function
1050 called without any parameters to determine whether the message is
1051 a message of type TYPE; and FUNCTION is a function to be called if
1052 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1053 the prefix.")
1055 (defcustom message-mail-alias-type 'abbrev
1056 "*What alias expansion type to use in Message buffers.
1057 The default is `abbrev', which uses mailabbrev. nil switches
1058 mail aliases off."
1059 :group 'message
1060 :link '(custom-manual "(message)Mail Aliases")
1061 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1062 (const :tag "No expansion" nil)))
1064 (defcustom message-auto-save-directory
1065 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1066 "*Directory where Message auto-saves buffers if Gnus isn't running.
1067 If nil, Message won't auto-save."
1068 :group 'message-buffers
1069 :link '(custom-manual "(message)Various Message Variables")
1070 :type '(choice directory (const :tag "Don't auto-save" nil)))
1072 (defcustom message-default-charset
1073 (and (not (mm-multibyte-p)) 'iso-8859-1)
1074 "Default charset used in non-MULE Emacsen.
1075 If nil, you might be asked to input the charset."
1076 :version "21.1"
1077 :group 'message
1078 :link '(custom-manual "(message)Various Message Variables")
1079 :type 'symbol)
1081 (defcustom message-dont-reply-to-names
1082 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1083 "*A regexp specifying addresses to prune when doing wide replies.
1084 A value of nil means exclude your own user name only."
1085 :version "21.1"
1086 :group 'message
1087 :link '(custom-manual "(message)Wide Reply")
1088 :type '(choice (const :tag "Yourself" nil)
1089 regexp))
1091 (defvar message-shoot-gnksa-feet nil
1092 "*A list of GNKSA feet you are allowed to shoot.
1093 Gnus gives you all the opportunity you could possibly want for
1094 shooting yourself in the foot. Also, Gnus allows you to shoot the
1095 feet of Good Net-Keeping Seal of Approval. The following are foot
1096 candidates:
1097 `empty-article' Allow you to post an empty article;
1098 `quoted-text-only' Allow you to post quoted text only;
1099 `multiple-copies' Allow you to post multiple copies;
1100 `cancel-messages' Allow you to cancel or supersede messages from
1101 your other email addresses.")
1103 (defsubst message-gnksa-enable-p (feature)
1104 (or (not (listp message-shoot-gnksa-feet))
1105 (memq feature message-shoot-gnksa-feet)))
1107 (defcustom message-hidden-headers nil
1108 "Regexp of headers to be hidden when composing new messages.
1109 This can also be a list of regexps to match headers. Or a list
1110 starting with `not' and followed by regexps."
1111 :version "22.1"
1112 :group 'message
1113 :link '(custom-manual "(message)Message Headers")
1114 :type '(repeat regexp))
1116 ;;; Internal variables.
1117 ;;; Well, not really internal.
1119 (defvar message-mode-syntax-table
1120 (let ((table (copy-syntax-table text-mode-syntax-table)))
1121 (modify-syntax-entry ?% ". " table)
1122 (modify-syntax-entry ?> ". " table)
1123 (modify-syntax-entry ?< ". " table)
1124 table)
1125 "Syntax table used while in Message mode.")
1127 (defface message-header-to-face
1128 '((((class color)
1129 (background dark))
1130 (:foreground "green2" :bold t))
1131 (((class color)
1132 (background light))
1133 (:foreground "MidnightBlue" :bold t))
1135 (:bold t :italic t)))
1136 "Face used for displaying From headers."
1137 :group 'message-faces)
1139 (defface message-header-cc-face
1140 '((((class color)
1141 (background dark))
1142 (:foreground "green4" :bold t))
1143 (((class color)
1144 (background light))
1145 (:foreground "MidnightBlue"))
1147 (:bold t)))
1148 "Face used for displaying Cc headers."
1149 :group 'message-faces)
1151 (defface message-header-subject-face
1152 '((((class color)
1153 (background dark))
1154 (:foreground "green3"))
1155 (((class color)
1156 (background light))
1157 (:foreground "navy blue" :bold t))
1159 (:bold t)))
1160 "Face used for displaying subject headers."
1161 :group 'message-faces)
1163 (defface message-header-newsgroups-face
1164 '((((class color)
1165 (background dark))
1166 (:foreground "yellow" :bold t :italic t))
1167 (((class color)
1168 (background light))
1169 (:foreground "blue4" :bold t :italic t))
1171 (:bold t :italic t)))
1172 "Face used for displaying newsgroups headers."
1173 :group 'message-faces)
1175 (defface message-header-other-face
1176 '((((class color)
1177 (background dark))
1178 (:foreground "#b00000"))
1179 (((class color)
1180 (background light))
1181 (:foreground "steel blue"))
1183 (:bold t :italic t)))
1184 "Face used for displaying newsgroups headers."
1185 :group 'message-faces)
1187 (defface message-header-name-face
1188 '((((class color)
1189 (background dark))
1190 (:foreground "DarkGreen"))
1191 (((class color)
1192 (background light))
1193 (:foreground "cornflower blue"))
1195 (:bold t)))
1196 "Face used for displaying header names."
1197 :group 'message-faces)
1199 (defface message-header-xheader-face
1200 '((((class color)
1201 (background dark))
1202 (:foreground "blue"))
1203 (((class color)
1204 (background light))
1205 (:foreground "blue"))
1207 (:bold t)))
1208 "Face used for displaying X-Header headers."
1209 :group 'message-faces)
1211 (defface message-separator-face
1212 '((((class color)
1213 (background dark))
1214 (:foreground "blue3"))
1215 (((class color)
1216 (background light))
1217 (:foreground "brown"))
1219 (:bold t)))
1220 "Face used for displaying the separator."
1221 :group 'message-faces)
1223 (defface message-cited-text-face
1224 '((((class color)
1225 (background dark))
1226 (:foreground "red"))
1227 (((class color)
1228 (background light))
1229 (:foreground "red"))
1231 (:bold t)))
1232 "Face used for displaying cited text names."
1233 :group 'message-faces)
1235 (defface message-mml-face
1236 '((((class color)
1237 (background dark))
1238 (:foreground "ForestGreen"))
1239 (((class color)
1240 (background light))
1241 (:foreground "ForestGreen"))
1243 (:bold t)))
1244 "Face used for displaying MML."
1245 :group 'message-faces)
1247 (defun message-font-lock-make-header-matcher (regexp)
1248 (let ((form
1249 `(lambda (limit)
1250 (let ((start (point)))
1251 (save-restriction
1252 (widen)
1253 (goto-char (point-min))
1254 (if (re-search-forward
1255 (concat "^" (regexp-quote mail-header-separator) "$")
1256 nil t)
1257 (setq limit (min limit (match-beginning 0))))
1258 (goto-char start))
1259 (and (< start limit)
1260 (re-search-forward ,regexp limit t))))))
1261 (if (featurep 'bytecomp)
1262 (byte-compile form)
1263 form)))
1265 (defvar message-font-lock-keywords
1266 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1267 `((,(message-font-lock-make-header-matcher
1268 (concat "^\\([Tt]o:\\)" content))
1269 (1 'message-header-name-face)
1270 (2 'message-header-to-face nil t))
1271 (,(message-font-lock-make-header-matcher
1272 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1273 (1 'message-header-name-face)
1274 (2 'message-header-cc-face nil t))
1275 (,(message-font-lock-make-header-matcher
1276 (concat "^\\([Ss]ubject:\\)" content))
1277 (1 'message-header-name-face)
1278 (2 'message-header-subject-face nil t))
1279 (,(message-font-lock-make-header-matcher
1280 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1281 (1 'message-header-name-face)
1282 (2 'message-header-newsgroups-face nil t))
1283 (,(message-font-lock-make-header-matcher
1284 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1285 (1 'message-header-name-face)
1286 (2 'message-header-other-face nil t))
1287 (,(message-font-lock-make-header-matcher
1288 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1289 (1 'message-header-name-face)
1290 (2 'message-header-name-face))
1291 ,@(if (and mail-header-separator
1292 (not (equal mail-header-separator "")))
1293 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1294 1 'message-separator-face))
1295 nil)
1296 ((lambda (limit)
1297 (re-search-forward (concat "^\\("
1298 message-cite-prefix-regexp
1299 "\\).*")
1300 limit t))
1301 (0 'message-cited-text-face))
1302 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1303 (0 'message-mml-face))))
1304 "Additional expressions to highlight in Message mode.")
1307 ;; XEmacs does it like this. For Emacs, we have to set the
1308 ;; `font-lock-defaults' buffer-local variable.
1309 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1311 (defvar message-face-alist
1312 '((bold . bold-region)
1313 (underline . underline-region)
1314 (default . (lambda (b e)
1315 (unbold-region b e)
1316 (ununderline-region b e))))
1317 "Alist of mail and news faces for facemenu.
1318 The cdr of each entry is a function for applying the face to a region.")
1320 (defcustom message-send-hook nil
1321 "Hook run before sending messages.
1322 This hook is run quite early when sending."
1323 :group 'message-various
1324 :options '(ispell-message)
1325 :link '(custom-manual "(message)Various Message Variables")
1326 :type 'hook)
1328 (defcustom message-send-mail-hook nil
1329 "Hook run before sending mail messages.
1330 This hook is run very late -- just before the message is sent as
1331 mail."
1332 :group 'message-various
1333 :link '(custom-manual "(message)Various Message Variables")
1334 :type 'hook)
1336 (defcustom message-send-news-hook nil
1337 "Hook run before sending news messages.
1338 This hook is run very late -- just before the message is sent as
1339 news."
1340 :group 'message-various
1341 :link '(custom-manual "(message)Various Message Variables")
1342 :type 'hook)
1344 (defcustom message-sent-hook nil
1345 "Hook run after sending messages."
1346 :group 'message-various
1347 :type 'hook)
1349 (defvar message-send-coding-system 'binary
1350 "Coding system to encode outgoing mail.")
1352 (defvar message-draft-coding-system
1353 mm-auto-save-coding-system
1354 "*Coding system to compose mail.
1355 If you'd like to make it possible to share draft files between XEmacs
1356 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1357 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1359 (defcustom message-send-mail-partially-limit 1000000
1360 "The limitation of messages sent as message/partial.
1361 The lower bound of message size in characters, beyond which the message
1362 should be sent in several parts. If it is nil, the size is unlimited."
1363 :version "21.1"
1364 :group 'message-buffers
1365 :link '(custom-manual "(message)Mail Variables")
1366 :type '(choice (const :tag "unlimited" nil)
1367 (integer 1000000)))
1369 (defcustom message-alternative-emails nil
1370 "A regexp to match the alternative email addresses.
1371 The first matched address (not primary one) is used in the From field."
1372 :group 'message-headers
1373 :link '(custom-manual "(message)Message Headers")
1374 :type '(choice (const :tag "Always use primary" nil)
1375 regexp))
1377 (defcustom message-hierarchical-addresses nil
1378 "A list of hierarchical mail address definitions.
1380 Inside each entry, the first address is the \"top\" address, and
1381 subsequent addresses are subaddresses; this is used to indicate that
1382 mail sent to the first address will automatically be delivered to the
1383 subaddresses. So if the first address appears in the recipient list
1384 for a message, the subaddresses will be removed (if present) before
1385 the mail is sent. All addresses in this structure should be
1386 downcased."
1387 :version "22.1"
1388 :group 'message-headers
1389 :type '(repeat (repeat string)))
1391 (defcustom message-mail-user-agent nil
1392 "Like `mail-user-agent'.
1393 Except if it is nil, use Gnus native MUA; if it is t, use
1394 `mail-user-agent'."
1395 :version "22.1"
1396 :type '(radio (const :tag "Gnus native"
1397 :format "%t\n"
1398 nil)
1399 (const :tag "`mail-user-agent'"
1400 :format "%t\n"
1402 (function-item :tag "Default Emacs mail"
1403 :format "%t\n"
1404 sendmail-user-agent)
1405 (function-item :tag "Emacs interface to MH"
1406 :format "%t\n"
1407 mh-e-user-agent)
1408 (function :tag "Other"))
1409 :version "21.1"
1410 :group 'message)
1412 (defcustom message-wide-reply-confirm-recipients nil
1413 "Whether to confirm a wide reply to multiple email recipients.
1414 If this variable is nil, don't ask whether to reply to all recipients.
1415 If this variable is non-nil, pose the question \"Reply to all
1416 recipients?\" before a wide reply to multiple recipients. If the user
1417 answers yes, reply to all recipients as usual. If the user answers
1418 no, only reply back to the author."
1419 :version "22.1"
1420 :group 'message-headers
1421 :link '(custom-manual "(message)Wide Reply")
1422 :type 'boolean)
1424 (defcustom message-user-fqdn nil
1425 "*Domain part of Messsage-Ids."
1426 :version "22.1"
1427 :group 'message-headers
1428 :link '(custom-manual "(message)News Headers")
1429 :type '(radio (const :format "%v " nil)
1430 (string :format "FQDN: %v")))
1432 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1433 (file-error))
1434 (mm-coding-system-p 'utf-8)
1435 (executable-find idna-program)
1436 'ask)
1437 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1438 :version "22.1"
1439 :group 'message-headers
1440 :link '(custom-manual "(message)IDNA")
1441 :type '(choice (const :tag "Ask" ask)
1442 (const :tag "Never" nil)
1443 (const :tag "Always" t)))
1445 ;;; Internal variables.
1447 (defvar message-sending-message "Sending...")
1448 (defvar message-buffer-list nil)
1449 (defvar message-this-is-news nil)
1450 (defvar message-this-is-mail nil)
1451 (defvar message-draft-article nil)
1452 (defvar message-mime-part nil)
1453 (defvar message-posting-charset nil)
1454 (defvar message-inserted-headers nil)
1456 ;; Byte-compiler warning
1457 (eval-when-compile
1458 (defvar gnus-active-hashtb)
1459 (defvar gnus-read-active-file))
1461 ;;; Regexp matching the delimiter of messages in UNIX mail format
1462 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1463 ;;; of rmail.el's rmail-unix-mail-delimiter.
1464 (defvar message-unix-mail-delimiter
1465 (let ((time-zone-regexp
1466 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1467 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1468 "\\|"
1469 "\\) *")))
1470 (concat
1471 "From "
1473 ;; Many things can happen to an RFC 822 mailbox before it is put into
1474 ;; a `From' line. The leading phrase can be stripped, e.g.
1475 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1476 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1477 ;; can be removed, e.g.
1478 ;; From: joe@y.z (Joe K
1479 ;; User)
1480 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1481 ;; From: Joe User
1482 ;; <joe@y.z>
1483 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1484 ;; The mailbox can be removed or be replaced by white space, e.g.
1485 ;; From: "Joe User"{space}{tab}
1486 ;; <joe@y.z>
1487 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1488 ;; where {space} and {tab} represent the Ascii space and tab characters.
1489 ;; We want to match the results of any of these manglings.
1490 ;; The following regexp rejects names whose first characters are
1491 ;; obviously bogus, but after that anything goes.
1492 "\\([^\0-\b\n-\r\^?].*\\)?"
1494 ;; The time the message was sent.
1495 "\\([^\0-\r \^?]+\\) +" ; day of the week
1496 "\\([^\0-\r \^?]+\\) +" ; month
1497 "\\([0-3]?[0-9]\\) +" ; day of month
1498 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1500 ;; Perhaps a time zone, specified by an abbreviation, or by a
1501 ;; numeric offset.
1502 time-zone-regexp
1504 ;; The year.
1505 " \\([0-9][0-9]+\\) *"
1507 ;; On some systems the time zone can appear after the year, too.
1508 time-zone-regexp
1510 ;; Old uucp cruft.
1511 "\\(remote from .*\\)?"
1513 "\n"))
1514 "Regexp matching the delimiter of messages in UNIX mail format.")
1516 (defvar message-unsent-separator
1517 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1518 "^ *---+ +Returned message +---+ *$\\|"
1519 "^Start of returned message$\\|"
1520 "^ *---+ +Original message +---+ *$\\|"
1521 "^ *--+ +begin message +--+ *$\\|"
1522 "^ *---+ +Original message follows +---+ *$\\|"
1523 "^ *---+ +Undelivered message follows +---+ *$\\|"
1524 "^|? *---+ +Message text follows: +---+ *|?$")
1525 "A regexp that matches the separator before the text of a failed message.")
1527 (defvar message-header-format-alist
1528 `((Newsgroups)
1529 (To . message-fill-address)
1530 (Cc . message-fill-address)
1531 (Subject)
1532 (In-Reply-To)
1533 (Fcc)
1534 (Bcc)
1535 (Date)
1536 (Organization)
1537 (Distribution)
1538 (Lines)
1539 (Expires)
1540 (Message-ID)
1541 (References . message-shorten-references)
1542 (User-Agent))
1543 "Alist used for formatting headers.")
1545 (defvar message-options nil
1546 "Some saved answers when sending message.")
1548 (defvar message-send-mail-real-function nil
1549 "Internal send mail function.")
1551 (defvar message-bogus-system-names "^localhost\\."
1552 "The regexp of bogus system names.")
1554 (defcustom message-valid-fqdn-regexp
1555 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1556 ;; valid TLDs:
1557 "\\([a-z][a-z]" ;; two letter country TDLs
1558 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1559 "\\|aero\\|coop\\|info\\|name\\|museum"
1560 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1561 "\\)")
1562 "Regular expression that matches a valid FQDN."
1563 ;; see also: gnus-button-valid-fqdn-regexp
1564 :version "22.1"
1565 :group 'message-headers
1566 :type 'regexp)
1568 (eval-and-compile
1569 (autoload 'idna-to-ascii "idna")
1570 (autoload 'message-setup-toolbar "messagexmas")
1571 (autoload 'mh-new-draft-name "mh-comp")
1572 (autoload 'mh-send-letter "mh-comp")
1573 (autoload 'gnus-point-at-eol "gnus-util")
1574 (autoload 'gnus-point-at-bol "gnus-util")
1575 (autoload 'gnus-output-to-rmail "gnus-util")
1576 (autoload 'gnus-output-to-mail "gnus-util")
1577 (autoload 'nndraft-request-associate-buffer "nndraft")
1578 (autoload 'nndraft-request-expire-articles "nndraft")
1579 (autoload 'gnus-open-server "gnus-int")
1580 (autoload 'gnus-request-post "gnus-int")
1581 (autoload 'gnus-alive-p "gnus-util")
1582 (autoload 'gnus-server-string "gnus")
1583 (autoload 'gnus-group-name-charset "gnus-group")
1584 (autoload 'gnus-group-name-decode "gnus-group")
1585 (autoload 'gnus-groups-from-server "gnus")
1586 (autoload 'rmail-output "rmailout")
1587 (autoload 'gnus-delay-article "gnus-delay")
1588 (autoload 'gnus-make-local-hook "gnus-util")
1589 (autoload 'gnus-extract-address-components "gnus-util"))
1594 ;;; Utility functions.
1597 (defmacro message-y-or-n-p (question show &rest text)
1598 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1599 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1601 (defmacro message-delete-line (&optional n)
1602 "Delete the current line (and the next N lines)."
1603 `(delete-region (progn (beginning-of-line) (point))
1604 (progn (forward-line ,(or n 1)) (point))))
1606 (defun message-mark-active-p ()
1607 "Non-nil means the mark and region are currently active in this buffer."
1608 mark-active)
1610 (defun message-unquote-tokens (elems)
1611 "Remove double quotes (\") from strings in list ELEMS."
1612 (mapcar (lambda (item)
1613 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1614 (setq item (concat (match-string 1 item)
1615 (match-string 2 item))))
1616 item)
1617 elems))
1619 (defun message-tokenize-header (header &optional separator)
1620 "Split HEADER into a list of header elements.
1621 SEPARATOR is a string of characters to be used as separators. \",\"
1622 is used by default."
1623 (if (not header)
1625 (let ((regexp (format "[%s]+" (or separator ",")))
1626 (first t)
1627 beg quoted elems paren)
1628 (with-temp-buffer
1629 (mm-enable-multibyte)
1630 (setq beg (point-min))
1631 (insert header)
1632 (goto-char (point-min))
1633 (while (not (eobp))
1634 (if first
1635 (setq first nil)
1636 (forward-char 1))
1637 (cond ((and (> (point) beg)
1638 (or (eobp)
1639 (and (looking-at regexp)
1640 (not quoted)
1641 (not paren))))
1642 (push (buffer-substring beg (point)) elems)
1643 (setq beg (match-end 0)))
1644 ((eq (char-after) ?\")
1645 (setq quoted (not quoted)))
1646 ((and (eq (char-after) ?\()
1647 (not quoted))
1648 (setq paren t))
1649 ((and (eq (char-after) ?\))
1650 (not quoted))
1651 (setq paren nil))))
1652 (nreverse elems)))))
1654 (defun message-mail-file-mbox-p (file)
1655 "Say whether FILE looks like a Unix mbox file."
1656 (when (and (file-exists-p file)
1657 (file-readable-p file)
1658 (file-regular-p file))
1659 (with-temp-buffer
1660 (nnheader-insert-file-contents file)
1661 (goto-char (point-min))
1662 (looking-at message-unix-mail-delimiter))))
1664 (defun message-fetch-field (header &optional not-all)
1665 "The same as `mail-fetch-field', only remove all newlines.
1666 The buffer is expected to be narrowed to just the header of the message;
1667 see `message-narrow-to-headers-or-head'."
1668 (let* ((inhibit-point-motion-hooks t)
1669 (case-fold-search t)
1670 (value (mail-fetch-field header nil (not not-all))))
1671 (when value
1672 (while (string-match "\n[\t ]+" value)
1673 (setq value (replace-match " " t t value)))
1674 (set-text-properties 0 (length value) nil value)
1675 value)))
1677 (defun message-field-value (header &optional not-all)
1678 "The same as `message-fetch-field', only narrow to the headers first."
1679 (save-excursion
1680 (save-restriction
1681 (message-narrow-to-headers-or-head)
1682 (message-fetch-field header not-all))))
1684 (defun message-narrow-to-field ()
1685 "Narrow the buffer to the header on the current line."
1686 (beginning-of-line)
1687 (narrow-to-region
1688 (point)
1689 (progn
1690 (forward-line 1)
1691 (if (re-search-forward "^[^ \n\t]" nil t)
1692 (progn
1693 (beginning-of-line)
1694 (point))
1695 (point-max))))
1696 (goto-char (point-min)))
1698 (defun message-add-header (&rest headers)
1699 "Add the HEADERS to the message header, skipping those already present."
1700 (while headers
1701 (let (hclean)
1702 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1703 (error "Invalid header `%s'" (car headers)))
1704 (setq hclean (match-string 1 (car headers)))
1705 (save-restriction
1706 (message-narrow-to-headers)
1707 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1708 (goto-char (point-max))
1709 (if (string-match "\n$" (car headers))
1710 (insert (car headers))
1711 (insert (car headers) ?\n)))))
1712 (setq headers (cdr headers))))
1714 (defmacro message-with-reply-buffer (&rest forms)
1715 "Evaluate FORMS in the reply buffer, if it exists."
1716 `(when (and message-reply-buffer
1717 (buffer-name message-reply-buffer))
1718 (save-excursion
1719 (set-buffer message-reply-buffer)
1720 ,@forms)))
1722 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1723 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1725 (defun message-fetch-reply-field (header)
1726 "Fetch field HEADER from the message we're replying to."
1727 (message-with-reply-buffer
1728 (save-restriction
1729 (mail-narrow-to-head)
1730 (message-fetch-field header))))
1732 (defun message-strip-list-identifiers (subject)
1733 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1734 (require 'gnus-sum) ; for gnus-list-identifiers
1735 (let ((regexp (if (stringp gnus-list-identifiers)
1736 gnus-list-identifiers
1737 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1738 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1739 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1740 (concat (substring subject 0 (match-beginning 1))
1741 (or (match-string 3 subject)
1742 (match-string 5 subject))
1743 (substring subject
1744 (match-end 1)))
1745 subject)))
1747 (defun message-strip-subject-re (subject)
1748 "Remove \"Re:\" from subject lines in string SUBJECT."
1749 (if (string-match message-subject-re-regexp subject)
1750 (substring subject (match-end 0))
1751 subject))
1753 ;;; Start of functions adopted from `message-utils.el'.
1755 (defun message-strip-subject-trailing-was (subject)
1756 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1757 Leading \"Re: \" is not stripped by this function. Use the function
1758 `message-strip-subject-re' for this."
1759 (let* ((query message-subject-trailing-was-query)
1760 (new) (found))
1761 (setq found
1762 (string-match
1763 (if (eq query 'ask)
1764 message-subject-trailing-was-ask-regexp
1765 message-subject-trailing-was-regexp)
1766 subject))
1767 (if found
1768 (setq new (substring subject 0 (match-beginning 0))))
1769 (if (or (not found) (eq query nil))
1770 subject
1771 (if (eq query 'ask)
1772 (if (message-y-or-n-p
1773 "Strip `(was: <old subject>)' in subject? " t
1774 (concat
1775 "Strip `(was: <old subject>)' in subject "
1776 "and use the new one instead?\n\n"
1777 "Current subject is: \""
1778 subject "\"\n\n"
1779 "New subject would be: \""
1780 new "\"\n\n"
1781 "See the variable `message-subject-trailing-was-query' "
1782 "to get rid of this query."
1784 new subject)
1785 new))))
1787 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1789 ;;;###autoload
1790 (defun message-change-subject (new-subject)
1791 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1792 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1793 (interactive
1794 (list
1795 (read-from-minibuffer "New subject: ")))
1796 (cond ((and (not (or (null new-subject) ; new subject not empty
1797 (zerop (string-width new-subject))
1798 (string-match "^[ \t]*$" new-subject))))
1799 (save-excursion
1800 (let ((old-subject
1801 (save-restriction
1802 (message-narrow-to-headers)
1803 (message-fetch-field "Subject"))))
1804 (cond ((not old-subject)
1805 (error "No current subject"))
1806 ((not (string-match
1807 (concat "^[ \t]*"
1808 (regexp-quote new-subject)
1809 " \t]*$")
1810 old-subject)) ; yes, it really is a new subject
1811 ;; delete eventual Re: prefix
1812 (setq old-subject
1813 (message-strip-subject-re old-subject))
1814 (message-goto-subject)
1815 (message-delete-line)
1816 (insert (concat "Subject: "
1817 new-subject
1818 " (was: "
1819 old-subject ")\n")))))))))
1821 ;;;###autoload
1822 (defun message-mark-inserted-region (beg end)
1823 "Mark some region in the current article with enclosing tags.
1824 See `message-mark-insert-begin' and `message-mark-insert-end'."
1825 (interactive "r")
1826 (save-excursion
1827 ;; add to the end of the region first, otherwise end would be invalid
1828 (goto-char end)
1829 (insert message-mark-insert-end)
1830 (goto-char beg)
1831 (insert message-mark-insert-begin)))
1833 ;;;###autoload
1834 (defun message-mark-insert-file (file)
1835 "Insert FILE at point, marking it with enclosing tags.
1836 See `message-mark-insert-begin' and `message-mark-insert-end'."
1837 (interactive "fFile to insert: ")
1838 ;; reverse insertion to get correct result.
1839 (let ((p (point)))
1840 (insert message-mark-insert-end)
1841 (goto-char p)
1842 (insert-file-contents file)
1843 (goto-char p)
1844 (insert message-mark-insert-begin)))
1846 ;;;###autoload
1847 (defun message-add-archive-header ()
1848 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1849 The note can be customized using `message-archive-note'. When called with a
1850 prefix argument, ask for a text to insert. If you don't want the note in the
1851 body, set `message-archive-note' to nil."
1852 (interactive)
1853 (if current-prefix-arg
1854 (setq message-archive-note
1855 (read-from-minibuffer "Reason for No-Archive: "
1856 (cons message-archive-note 0))))
1857 (save-excursion
1858 (if (message-goto-signature)
1859 (re-search-backward message-signature-separator))
1860 (when message-archive-note
1861 (insert message-archive-note)
1862 (newline))
1863 (message-add-header message-archive-header)
1864 (message-sort-headers)))
1866 ;;;###autoload
1867 (defun message-cross-post-followup-to-header (target-group)
1868 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1869 With prefix-argument just set Follow-Up, don't cross-post."
1870 (interactive
1871 (list ; Completion based on Gnus
1872 (completing-read "Followup To: "
1873 (if (boundp 'gnus-newsrc-alist)
1874 gnus-newsrc-alist)
1875 nil nil '("poster" . 0)
1876 (if (boundp 'gnus-group-history)
1877 'gnus-group-history))))
1878 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1879 (message-goto-newsgroups)
1880 (beginning-of-line)
1881 ;; if we already did a crosspost before, kill old target
1882 (if (and message-cross-post-old-target
1883 (re-search-forward
1884 (regexp-quote (concat "," message-cross-post-old-target))
1885 nil t))
1886 (replace-match ""))
1887 ;; unless (followup is to poster or user explicitly asked not
1888 ;; to cross-post, or target-group is already in Newsgroups)
1889 ;; add target-group to Newsgroups line.
1890 (cond ((and (or
1891 ;; def: cross-post, req:no
1892 (and message-cross-post-default (not current-prefix-arg))
1893 ;; def: no-cross-post, req:yes
1894 (and (not message-cross-post-default) current-prefix-arg))
1895 (not (string-match "poster" target-group))
1896 (not (string-match (regexp-quote target-group)
1897 (message-fetch-field "Newsgroups"))))
1898 (end-of-line)
1899 (insert (concat "," target-group))))
1900 (end-of-line) ; ensure Followup: comes after Newsgroups:
1901 ;; unless new followup would be identical to Newsgroups line
1902 ;; make a new Followup-To line
1903 (if (not (string-match (concat "^[ \t]*"
1904 target-group
1905 "[ \t]*$")
1906 (message-fetch-field "Newsgroups")))
1907 (insert (concat "\nFollowup-To: " target-group)))
1908 (setq message-cross-post-old-target target-group))
1910 ;;;###autoload
1911 (defun message-cross-post-insert-note (target-group cross-post in-old
1912 old-groups)
1913 "Insert a in message body note about a set Followup or Crosspost.
1914 If there have been previous notes, delete them. TARGET-GROUP specifies the
1915 group to Followup-To. When CROSS-POST is t, insert note about
1916 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1917 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1918 been made to before the user asked for a Crosspost."
1919 ;; start scanning body for previous uses
1920 (message-goto-signature)
1921 (let ((head (re-search-backward
1922 (concat "^" mail-header-separator)
1923 nil t))) ; just search in body
1924 (message-goto-signature)
1925 (while (re-search-backward
1926 (concat "^" (regexp-quote message-cross-post-note) ".*")
1927 head t)
1928 (message-delete-line))
1929 (message-goto-signature)
1930 (while (re-search-backward
1931 (concat "^" (regexp-quote message-followup-to-note) ".*")
1932 head t)
1933 (message-delete-line))
1934 ;; insert new note
1935 (if (message-goto-signature)
1936 (re-search-backward message-signature-separator))
1937 (if (or in-old
1938 (not cross-post)
1939 (string-match "^[ \t]*poster[ \t]*$" target-group))
1940 (insert (concat message-followup-to-note target-group "\n"))
1941 (insert (concat message-cross-post-note target-group "\n")))))
1943 ;;;###autoload
1944 (defun message-cross-post-followup-to (target-group)
1945 "Crossposts message and set Followup-To to TARGET-GROUP.
1946 With prefix-argument just set Follow-Up, don't cross-post."
1947 (interactive
1948 (list ; Completion based on Gnus
1949 (completing-read "Followup To: "
1950 (if (boundp 'gnus-newsrc-alist)
1951 gnus-newsrc-alist)
1952 nil nil '("poster" . 0)
1953 (if (boundp 'gnus-group-history)
1954 'gnus-group-history))))
1955 (cond ((not (or (null target-group) ; new subject not empty
1956 (zerop (string-width target-group))
1957 (string-match "^[ \t]*$" target-group)))
1958 (save-excursion
1959 (let* ((old-groups (message-fetch-field "Newsgroups"))
1960 (in-old (string-match
1961 (regexp-quote target-group)
1962 (or old-groups ""))))
1963 ;; check whether target exactly matches old Newsgroups
1964 (cond ((not old-groups)
1965 (error "No current newsgroup"))
1966 ((or (not in-old)
1967 (not (string-match
1968 (concat "^[ \t]*"
1969 (regexp-quote target-group)
1970 "[ \t]*$")
1971 old-groups)))
1972 ;; yes, Newsgroups line must change
1973 (message-cross-post-followup-to-header target-group)
1974 ;; insert note whether we do cross-post or followup-to
1975 (funcall message-cross-post-note-function
1976 target-group
1977 (if (or (and message-cross-post-default
1978 (not current-prefix-arg))
1979 (and (not message-cross-post-default)
1980 current-prefix-arg)) t)
1981 in-old old-groups))))))))
1983 ;;; Reduce To: to Cc: or Bcc: header
1985 ;;;###autoload
1986 (defun message-reduce-to-to-cc ()
1987 "Replace contents of To: header with contents of Cc: or Bcc: header."
1988 (interactive)
1989 (let ((cc-content
1990 (save-restriction (message-narrow-to-headers)
1991 (message-fetch-field "cc")))
1992 (bcc nil))
1993 (if (and (not cc-content)
1994 (setq cc-content
1995 (save-restriction
1996 (message-narrow-to-headers)
1997 (message-fetch-field "bcc"))))
1998 (setq bcc t))
1999 (cond (cc-content
2000 (save-excursion
2001 (message-goto-to)
2002 (message-delete-line)
2003 (insert (concat "To: " cc-content "\n"))
2004 (save-restriction
2005 (message-narrow-to-headers)
2006 (message-remove-header (if bcc
2007 "bcc"
2008 "cc"))))))))
2010 ;;; End of functions adopted from `message-utils.el'.
2012 (defun message-remove-header (header &optional is-regexp first reverse)
2013 "Remove HEADER in the narrowed buffer.
2014 If IS-REGEXP, HEADER is a regular expression.
2015 If FIRST, only remove the first instance of the header.
2016 Return the number of headers removed."
2017 (goto-char (point-min))
2018 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2019 (number 0)
2020 (case-fold-search t)
2021 last)
2022 (while (and (not (eobp))
2023 (not last))
2024 (if (if reverse
2025 (not (looking-at regexp))
2026 (looking-at regexp))
2027 (progn
2028 (incf number)
2029 (when first
2030 (setq last t))
2031 (delete-region
2032 (point)
2033 ;; There might be a continuation header, so we have to search
2034 ;; until we find a new non-continuation line.
2035 (progn
2036 (forward-line 1)
2037 (if (re-search-forward "^[^ \t]" nil t)
2038 (goto-char (match-beginning 0))
2039 (point-max)))))
2040 (forward-line 1)
2041 (if (re-search-forward "^[^ \t]" nil t)
2042 (goto-char (match-beginning 0))
2043 (goto-char (point-max)))))
2044 number))
2046 (defun message-remove-first-header (header)
2047 "Remove the first instance of HEADER if there is more than one."
2048 (let ((count 0)
2049 (regexp (concat "^" (regexp-quote header) ":")))
2050 (save-excursion
2051 (goto-char (point-min))
2052 (while (re-search-forward regexp nil t)
2053 (incf count)))
2054 (while (> count 1)
2055 (message-remove-header header nil t)
2056 (decf count))))
2058 (defun message-narrow-to-headers ()
2059 "Narrow the buffer to the head of the message."
2060 (widen)
2061 (narrow-to-region
2062 (goto-char (point-min))
2063 (if (re-search-forward
2064 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2065 (match-beginning 0)
2066 (point-max)))
2067 (goto-char (point-min)))
2069 (defun message-narrow-to-head-1 ()
2070 "Like `message-narrow-to-head'. Don't widen."
2071 (narrow-to-region
2072 (goto-char (point-min))
2073 (if (search-forward "\n\n" nil 1)
2074 (1- (point))
2075 (point-max)))
2076 (goto-char (point-min)))
2078 (defun message-narrow-to-head ()
2079 "Narrow the buffer to the head of the message.
2080 Point is left at the beginning of the narrowed-to region."
2081 (widen)
2082 (message-narrow-to-head-1))
2084 (defun message-narrow-to-headers-or-head ()
2085 "Narrow the buffer to the head of the message."
2086 (widen)
2087 (narrow-to-region
2088 (goto-char (point-min))
2089 (cond
2090 ((re-search-forward
2091 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2092 (match-beginning 0))
2093 ((search-forward "\n\n" nil t)
2094 (1- (point)))
2096 (point-max))))
2097 (goto-char (point-min)))
2099 (defun message-news-p ()
2100 "Say whether the current buffer contains a news message."
2101 (and (not message-this-is-mail)
2102 (or message-this-is-news
2103 (save-excursion
2104 (save-restriction
2105 (message-narrow-to-headers)
2106 (and (message-fetch-field "newsgroups")
2107 (not (message-fetch-field "posted-to"))))))))
2109 (defun message-mail-p ()
2110 "Say whether the current buffer contains a mail message."
2111 (and (not message-this-is-news)
2112 (or message-this-is-mail
2113 (save-excursion
2114 (save-restriction
2115 (message-narrow-to-headers)
2116 (or (message-fetch-field "to")
2117 (message-fetch-field "cc")
2118 (message-fetch-field "bcc")))))))
2120 (defun message-subscribed-p ()
2121 "Say whether we need to insert a MFT header."
2122 (or message-subscribed-regexps
2123 message-subscribed-addresses
2124 message-subscribed-address-file
2125 message-subscribed-address-functions))
2127 (defun message-next-header ()
2128 "Go to the beginning of the next header."
2129 (beginning-of-line)
2130 (or (eobp) (forward-char 1))
2131 (not (if (re-search-forward "^[^ \t]" nil t)
2132 (beginning-of-line)
2133 (goto-char (point-max)))))
2135 (defun message-sort-headers-1 ()
2136 "Sort the buffer as headers using `message-rank' text props."
2137 (goto-char (point-min))
2138 (require 'sort)
2139 (sort-subr
2140 nil 'message-next-header
2141 (lambda ()
2142 (message-next-header)
2143 (unless (bobp)
2144 (forward-char -1)))
2145 (lambda ()
2146 (or (get-text-property (point) 'message-rank)
2147 10000))))
2149 (defun message-sort-headers ()
2150 "Sort the headers of the current message according to `message-header-format-alist'."
2151 (interactive)
2152 (save-excursion
2153 (save-restriction
2154 (let ((max (1+ (length message-header-format-alist)))
2155 rank)
2156 (message-narrow-to-headers)
2157 (while (re-search-forward "^[^ \n]+:" nil t)
2158 (put-text-property
2159 (match-beginning 0) (1+ (match-beginning 0))
2160 'message-rank
2161 (if (setq rank (length (memq (assq (intern (buffer-substring
2162 (match-beginning 0)
2163 (1- (match-end 0))))
2164 message-header-format-alist)
2165 message-header-format-alist)))
2166 (- max rank)
2167 (1+ max)))))
2168 (message-sort-headers-1))))
2174 ;;; Message mode
2177 ;;; Set up keymap.
2179 (defvar message-mode-map nil)
2181 (unless message-mode-map
2182 (setq message-mode-map (make-keymap))
2183 (set-keymap-parent message-mode-map text-mode-map)
2184 (define-key message-mode-map "\C-c?" 'describe-mode)
2186 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2187 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2188 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2189 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2190 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2191 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2192 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2193 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2194 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2195 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2196 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2197 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2198 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2199 (define-key message-mode-map "\C-c\C-f\C-i"
2200 'message-insert-or-toggle-importance)
2201 (define-key message-mode-map "\C-c\C-f\C-a"
2202 'message-generate-unsubscribed-mail-followup-to)
2204 ;; modify headers (and insert notes in body)
2205 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2207 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2208 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2209 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2210 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2211 ;; mark inserted text
2212 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2213 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2215 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2216 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2218 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2219 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2220 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2221 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2223 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2224 (define-key message-mode-map "\C-c\M-n"
2225 'message-insert-disposition-notification-to)
2227 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2228 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2229 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2230 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2231 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2232 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2233 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2234 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2236 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2237 (define-key message-mode-map "\C-c\C-s" 'message-send)
2238 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2239 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2240 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2242 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2243 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2244 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2245 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2246 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2247 (define-key message-mode-map [remap split-line] 'message-split-line)
2249 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2251 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2252 (define-key message-mode-map "\t" 'message-tab)
2253 (define-key message-mode-map "\M-;" 'comment-region))
2255 (easy-menu-define
2256 message-mode-menu message-mode-map "Message Menu."
2257 `("Message"
2258 ["Yank Original" message-yank-original message-reply-buffer]
2259 ["Fill Yanked Message" message-fill-yanked-message t]
2260 ["Insert Signature" message-insert-signature t]
2261 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2262 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2263 ["Elide Region" message-elide-region
2264 :active (message-mark-active-p)
2265 ,@(if (featurep 'xemacs) nil
2266 '(:help "Replace text in region with an ellipsis"))]
2267 ["Delete Outside Region" message-delete-not-region
2268 :active (message-mark-active-p)
2269 ,@(if (featurep 'xemacs) nil
2270 '(:help "Delete all quoted text outside region"))]
2271 ["Kill To Signature" message-kill-to-signature t]
2272 ["Newline and Reformat" message-newline-and-reformat t]
2273 ["Rename buffer" message-rename-buffer t]
2274 ["Spellcheck" ispell-message
2275 ,@(if (featurep 'xemacs) '(t)
2276 '(:help "Spellcheck this message"))]
2277 "----"
2278 ["Insert Region Marked" message-mark-inserted-region
2279 :active (message-mark-active-p)
2280 ,@(if (featurep 'xemacs) nil
2281 '(:help "Mark region with enclosing tags"))]
2282 ["Insert File Marked..." message-mark-insert-file
2283 ,@(if (featurep 'xemacs) '(t)
2284 '(:help "Insert file at point marked with enclosing tags"))]
2285 "----"
2286 ["Send Message" message-send-and-exit
2287 ,@(if (featurep 'xemacs) '(t)
2288 '(:help "Send this message"))]
2289 ["Postpone Message" message-dont-send
2290 ,@(if (featurep 'xemacs) '(t)
2291 '(:help "File this draft message and exit"))]
2292 ["Send at Specific Time..." gnus-delay-article
2293 ,@(if (featurep 'xemacs) '(t)
2294 '(:help "Ask, then arrange to send message at that time"))]
2295 ["Kill Message" message-kill-buffer
2296 ,@(if (featurep 'xemacs) '(t)
2297 '(:help "Delete this message without sending"))]))
2299 (easy-menu-define
2300 message-mode-field-menu message-mode-map ""
2301 `("Field"
2302 ["To" message-goto-to t]
2303 ["From" message-goto-from t]
2304 ["Subject" message-goto-subject t]
2305 ["Change subject..." message-change-subject t]
2306 ["Cc" message-goto-cc t]
2307 ["Bcc" message-goto-bcc t]
2308 ["Fcc" message-goto-fcc t]
2309 ["Reply-To" message-goto-reply-to t]
2310 ["Flag As Important" message-insert-importance-high
2311 ,@(if (featurep 'xemacs) '(t)
2312 '(:help "Mark this message as important"))]
2313 ["Flag As Unimportant" message-insert-importance-low
2314 ,@(if (featurep 'xemacs) '(t)
2315 '(:help "Mark this message as unimportant"))]
2316 ["Request Receipt"
2317 message-insert-disposition-notification-to
2318 ,@(if (featurep 'xemacs) '(t)
2319 '(:help "Request a receipt notification"))]
2320 "----"
2321 ;; (typical) news stuff
2322 ["Summary" message-goto-summary t]
2323 ["Keywords" message-goto-keywords t]
2324 ["Newsgroups" message-goto-newsgroups t]
2325 ["Fetch Newsgroups" message-insert-newsgroups t]
2326 ["Followup-To" message-goto-followup-to t]
2327 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2328 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2329 ["Distribution" message-goto-distribution t]
2330 ["X-No-Archive:" message-add-archive-header t ]
2331 "----"
2332 ;; (typical) mailing-lists stuff
2333 ["Fetch To" message-insert-to
2334 ,@(if (featurep 'xemacs) '(t)
2335 '(:help "Insert a To header that points to the author."))]
2336 ["Fetch To and Cc" message-insert-wide-reply
2337 ,@(if (featurep 'xemacs) '(t)
2338 '(:help
2339 "Insert To and Cc headers as if you were doing a wide reply."))]
2340 "----"
2341 ["Send to list only" message-to-list-only t]
2342 ["Mail-Followup-To" message-goto-mail-followup-to t]
2343 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2344 ,@(if (featurep 'xemacs) '(t)
2345 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2346 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2347 "----"
2348 ["Sort Headers" message-sort-headers t]
2349 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2350 ["Goto Body" message-goto-body t]
2351 ["Goto Signature" message-goto-signature t]))
2353 (defvar message-tool-bar-map nil)
2355 (eval-when-compile
2356 (defvar facemenu-add-face-function)
2357 (defvar facemenu-remove-face-function))
2359 ;;; Forbidden properties
2361 ;; We use `after-change-functions' to keep special text properties
2362 ;; that interfer with the normal function of message mode out of the
2363 ;; buffer.
2365 (defcustom message-strip-special-text-properties t
2366 "Strip special properties from the message buffer.
2368 Emacs has a number of special text properties which can break message
2369 composing in various ways. If this option is set, message will strip
2370 these properties from the message composition buffer. However, some
2371 packages requires these properties to be present in order to work.
2372 If you use one of these packages, turn this option off, and hope the
2373 message composition doesn't break too bad."
2374 :version "22.1"
2375 :group 'message-various
2376 :link '(custom-manual "(message)Various Message Variables")
2377 :type 'boolean)
2379 (defconst message-forbidden-properties
2380 ;; No reason this should be clutter up customize. We make it a
2381 ;; property list (rather than a list of property symbols), to be
2382 ;; directly useful for `remove-text-properties'.
2383 '(field nil read-only nil invisible nil intangible nil
2384 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2385 insert-behind-hooks nil point-entered nil point-left nil)
2386 ;; Other special properties:
2387 ;; category, face, display: probably doesn't do any harm.
2388 ;; fontified: is used by font-lock.
2389 ;; syntax-table, local-map: I dunno.
2390 ;; We need to add XEmacs names to the list.
2391 "Property list of with properties forbidden in message buffers.
2392 The values of the properties are ignored, only the property names are used.")
2394 (defun message-tamago-not-in-use-p (pos)
2395 "Return t when tamago version 4 is not in use at the cursor position.
2396 Tamago version 4 is a popular input method for writing Japanese text.
2397 It uses the properties `intangible', `invisible', `modification-hooks'
2398 and `read-only' when translating ascii or kana text to kanji text.
2399 These properties are essential to work, so we should never strip them."
2400 (not (and (boundp 'egg-modefull-mode)
2401 (symbol-value 'egg-modefull-mode)
2402 (or (memq (get-text-property pos 'intangible)
2403 '(its-part-1 its-part-2))
2404 (get-text-property pos 'egg-end)
2405 (get-text-property pos 'egg-lang)
2406 (get-text-property pos 'egg-start)))))
2408 (defun message-strip-forbidden-properties (begin end &optional old-length)
2409 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2410 This function is intended to be called from `after-change-functions'.
2411 See also `message-forbidden-properties'."
2412 (when (and message-strip-special-text-properties
2413 (message-tamago-not-in-use-p begin))
2414 (let ((buffer-read-only nil)
2415 (inhibit-read-only t))
2416 (while (not (= begin end))
2417 (when (not (get-text-property begin 'message-hidden))
2418 (remove-text-properties begin (1+ begin)
2419 message-forbidden-properties))
2420 (incf begin)))))
2422 ;;;###autoload
2423 (define-derived-mode message-mode text-mode "Message"
2424 "Major mode for editing mail and news to be sent.
2425 Like Text Mode but with these additional commands:\\<message-mode-map>
2426 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2427 C-c C-d Postpone sending the message C-c C-k Kill the message
2428 C-c C-f move to a header field (and create it if there isn't):
2429 C-c C-f C-t move to To C-c C-f C-s move to Subject
2430 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2431 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2432 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2433 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2434 C-c C-f C-o move to From (\"Originator\")
2435 C-c C-f C-f move to Followup-To
2436 C-c C-f C-m move to Mail-Followup-To
2437 C-c C-f C-i cycle through Importance values
2438 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2439 C-c C-f x crossposting with FollowUp-To header and note in body
2440 C-c C-f t replace To: header with contents of Cc: or Bcc:
2441 C-c C-f a Insert X-No-Archive: header and a note in the body
2442 C-c C-t `message-insert-to' (add a To header to a news followup)
2443 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2444 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2445 C-c C-b `message-goto-body' (move to beginning of message text).
2446 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2447 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2448 C-c C-y `message-yank-original' (insert current message, if any).
2449 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2450 C-c C-e `message-elide-region' (elide the text between point and mark).
2451 C-c C-v `message-delete-not-region' (remove the text outside the region).
2452 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2453 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2454 C-c C-a `mml-attach-file' (attach a file as MIME).
2455 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2456 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2457 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2458 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2459 M-RET `message-newline-and-reformat' (break the line and reformat)."
2460 (setq local-abbrev-table text-mode-abbrev-table)
2461 (set (make-local-variable 'message-reply-buffer) nil)
2462 (set (make-local-variable 'message-inserted-headers) nil)
2463 (set (make-local-variable 'message-send-actions) nil)
2464 (set (make-local-variable 'message-exit-actions) nil)
2465 (set (make-local-variable 'message-kill-actions) nil)
2466 (set (make-local-variable 'message-postpone-actions) nil)
2467 (set (make-local-variable 'message-draft-article) nil)
2468 (setq buffer-offer-save t)
2469 (set (make-local-variable 'facemenu-add-face-function)
2470 (lambda (face end)
2471 (let ((face-fun (cdr (assq face message-face-alist))))
2472 (if face-fun
2473 (funcall face-fun (point) end)
2474 (error "Face %s not configured for %s mode" face mode-name)))
2475 ""))
2476 (set (make-local-variable 'facemenu-remove-face-function) t)
2477 (set (make-local-variable 'message-reply-headers) nil)
2478 (make-local-variable 'message-newsreader)
2479 (make-local-variable 'message-mailer)
2480 (make-local-variable 'message-post-method)
2481 (set (make-local-variable 'message-sent-message-via) nil)
2482 (set (make-local-variable 'message-checksum) nil)
2483 (set (make-local-variable 'message-mime-part) 0)
2484 (message-setup-fill-variables)
2485 ;; Allow using comment commands to add/remove quoting.
2486 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2487 (when message-yank-prefix
2488 (set (make-local-variable 'comment-start) message-yank-prefix)
2489 (set (make-local-variable 'comment-start-skip)
2490 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2491 (if (featurep 'xemacs)
2492 (message-setup-toolbar)
2493 (set (make-local-variable 'font-lock-defaults)
2494 '(message-font-lock-keywords t))
2495 (if (boundp 'tool-bar-map)
2496 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2497 (easy-menu-add message-mode-menu message-mode-map)
2498 (easy-menu-add message-mode-field-menu message-mode-map)
2499 (gnus-make-local-hook 'after-change-functions)
2500 ;; Mmmm... Forbidden properties...
2501 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2502 nil 'local)
2503 ;; Allow mail alias things.
2504 (when (eq message-mail-alias-type 'abbrev)
2505 (if (fboundp 'mail-abbrevs-setup)
2506 (mail-abbrevs-setup)
2507 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2508 (mail-aliases-setup))))
2509 (unless buffer-file-name
2510 (message-set-auto-save-file-name))
2511 (unless (buffer-base-buffer)
2512 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2513 ;; multibyte is not necessary at all. -- zsh
2514 (mm-enable-multibyte))
2515 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2516 (mml-mode))
2518 (defun message-setup-fill-variables ()
2519 "Setup message fill variables."
2520 (set (make-local-variable 'fill-paragraph-function)
2521 'message-fill-paragraph)
2522 (make-local-variable 'paragraph-separate)
2523 (make-local-variable 'paragraph-start)
2524 (make-local-variable 'adaptive-fill-regexp)
2525 (unless (boundp 'adaptive-fill-first-line-regexp)
2526 (setq adaptive-fill-first-line-regexp nil))
2527 (make-local-variable 'adaptive-fill-first-line-regexp)
2528 (let ((quote-prefix-regexp
2529 ;; User should change message-cite-prefix-regexp if
2530 ;; message-yank-prefix is set to an abnormal value.
2531 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2532 (setq paragraph-start
2533 (concat
2534 (regexp-quote mail-header-separator) "$\\|"
2535 "[ \t]*$\\|" ; blank lines
2536 "-- $\\|" ; signature delimiter
2537 "---+$\\|" ; delimiters for forwarded messages
2538 page-delimiter "$\\|" ; spoiler warnings
2539 ".*wrote:$\\|" ; attribution lines
2540 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2541 ; mml tags
2542 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2543 (setq paragraph-separate paragraph-start)
2544 (setq adaptive-fill-regexp
2545 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2546 (setq adaptive-fill-first-line-regexp
2547 (concat quote-prefix-regexp "\\|"
2548 adaptive-fill-first-line-regexp)))
2549 (make-local-variable 'auto-fill-inhibit-regexp)
2550 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2551 (setq auto-fill-inhibit-regexp nil)
2552 (make-local-variable 'normal-auto-fill-function)
2553 (setq normal-auto-fill-function 'message-do-auto-fill)
2554 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2555 ;; In that case, ensure that it uses the right function. The real
2556 ;; solution would be not to use `define-derived-mode', and run
2557 ;; `text-mode-hook' ourself at the end of the mode.
2558 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2559 (when auto-fill-function
2560 (setq auto-fill-function normal-auto-fill-function)))
2565 ;;; Message mode commands
2568 ;;; Movement commands
2570 (defun message-goto-to ()
2571 "Move point to the To header."
2572 (interactive)
2573 (message-position-on-field "To"))
2575 (defun message-goto-from ()
2576 "Move point to the From header."
2577 (interactive)
2578 (message-position-on-field "From"))
2580 (defun message-goto-subject ()
2581 "Move point to the Subject header."
2582 (interactive)
2583 (message-position-on-field "Subject"))
2585 (defun message-goto-cc ()
2586 "Move point to the Cc header."
2587 (interactive)
2588 (message-position-on-field "Cc" "To"))
2590 (defun message-goto-bcc ()
2591 "Move point to the Bcc header."
2592 (interactive)
2593 (message-position-on-field "Bcc" "Cc" "To"))
2595 (defun message-goto-fcc ()
2596 "Move point to the Fcc header."
2597 (interactive)
2598 (message-position-on-field "Fcc" "To" "Newsgroups"))
2600 (defun message-goto-reply-to ()
2601 "Move point to the Reply-To header."
2602 (interactive)
2603 (message-position-on-field "Reply-To" "Subject"))
2605 (defun message-goto-newsgroups ()
2606 "Move point to the Newsgroups header."
2607 (interactive)
2608 (message-position-on-field "Newsgroups"))
2610 (defun message-goto-distribution ()
2611 "Move point to the Distribution header."
2612 (interactive)
2613 (message-position-on-field "Distribution"))
2615 (defun message-goto-followup-to ()
2616 "Move point to the Followup-To header."
2617 (interactive)
2618 (message-position-on-field "Followup-To" "Newsgroups"))
2620 (defun message-goto-mail-followup-to ()
2621 "Move point to the Mail-Followup-To header."
2622 (interactive)
2623 (message-position-on-field "Mail-Followup-To" "To"))
2625 (defun message-goto-keywords ()
2626 "Move point to the Keywords header."
2627 (interactive)
2628 (message-position-on-field "Keywords" "Subject"))
2630 (defun message-goto-summary ()
2631 "Move point to the Summary header."
2632 (interactive)
2633 (message-position-on-field "Summary" "Subject"))
2635 (defun message-goto-body (&optional interactivep)
2636 "Move point to the beginning of the message body."
2637 (interactive (list t))
2638 (when (and interactivep
2639 (looking-at "[ \t]*\n"))
2640 (expand-abbrev))
2641 (goto-char (point-min))
2642 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2643 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2645 (defun message-goto-eoh ()
2646 "Move point to the end of the headers."
2647 (interactive)
2648 (message-goto-body)
2649 (forward-line -1))
2651 (defun message-goto-signature ()
2652 "Move point to the beginning of the message signature.
2653 If there is no signature in the article, go to the end and
2654 return nil."
2655 (interactive)
2656 (goto-char (point-min))
2657 (if (re-search-forward message-signature-separator nil t)
2658 (forward-line 1)
2659 (goto-char (point-max))
2660 nil))
2662 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2663 "Insert a reasonable MFT header in a post to an unsubscribed list.
2664 When making original posts to a mailing list you are not subscribed to,
2665 you have to type in a MFT header by hand. The contents, usually, are
2666 the addresses of the list and your own address. This function inserts
2667 such a header automatically. It fetches the contents of the To: header
2668 in the current mail buffer, and appends the current `user-mail-address'.
2670 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2671 Cc: header are also put into the MFT."
2673 (interactive "P")
2674 (let* (cc tos)
2675 (save-restriction
2676 (message-narrow-to-headers)
2677 (message-remove-header "Mail-Followup-To")
2678 (setq cc (and include-cc (message-fetch-field "Cc")))
2679 (setq tos (if cc
2680 (concat (message-fetch-field "To") "," cc)
2681 (message-fetch-field "To"))))
2682 (message-goto-mail-followup-to)
2683 (insert (concat tos ", " user-mail-address))))
2687 (defun message-insert-to (&optional force)
2688 "Insert a To header that points to the author of the article being replied to.
2689 If the original author requested not to be sent mail, don't insert unless the
2690 prefix FORCE is given."
2691 (interactive "P")
2692 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2693 (dont (and mct (or (equal (downcase mct) "never")
2694 (equal (downcase mct) "nobody"))))
2695 (to (or (message-fetch-reply-field "mail-reply-to")
2696 (message-fetch-reply-field "reply-to")
2697 (message-fetch-reply-field "from"))))
2698 (when (and dont to)
2699 (message
2700 (if force
2701 "Ignoring the user request not to have copies sent via mail"
2702 "Complying with the user request not to have copies sent via mail")))
2703 (when (and force (not to))
2704 (error "No mail address in the article"))
2705 (when (and to (or force (not dont)))
2706 (message-carefully-insert-headers (list (cons 'To to))))))
2708 (defun message-insert-wide-reply ()
2709 "Insert To and Cc headers as if you were doing a wide reply."
2710 (interactive)
2711 (let ((headers (message-with-reply-buffer
2712 (message-get-reply-headers t))))
2713 (message-carefully-insert-headers headers)))
2715 (defcustom message-header-synonyms
2716 '((To Cc Bcc))
2717 "List of lists of header synonyms.
2718 E.g., if this list contains a member list with elements `Cc' and `To',
2719 then `message-carefully-insert-headers' will not insert a `To' header
2720 when the message is already `Cc'ed to the recipient."
2721 :version "22.1"
2722 :group 'message-headers
2723 :link '(custom-manual "(message)Message Headers")
2724 :type '(repeat sexp))
2726 (defun message-carefully-insert-headers (headers)
2727 "Insert the HEADERS, an alist, into the message buffer.
2728 Does not insert the headers when they are already present there
2729 or in the synonym headers, defined by `message-header-synonyms'."
2730 ;; FIXME: Should compare only the address and not the full name. Comparison
2731 ;; should be done case-folded (and with `string=' rather than
2732 ;; `string-match').
2733 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2734 (dolist (header headers)
2735 (let* ((header-name (symbol-name (car header)))
2736 (new-header (cdr header))
2737 (synonyms (loop for synonym in message-header-synonyms
2738 when (memq (car header) synonym) return synonym))
2739 (old-header
2740 (loop for synonym in synonyms
2741 for old-header = (mail-fetch-field (symbol-name synonym))
2742 when (and old-header (string-match new-header old-header))
2743 return synonym)))
2744 (if old-header
2745 (message "already have `%s' in `%s'" new-header old-header)
2746 (when (and (message-position-on-field header-name)
2747 (setq old-header (mail-fetch-field header-name))
2748 (not (string-match "\\` *\\'" old-header)))
2749 (insert ", "))
2750 (insert new-header)))))
2752 (defun message-widen-reply ()
2753 "Widen the reply to include maximum recipients."
2754 (interactive)
2755 (let ((follow-to
2756 (and message-reply-buffer
2757 (buffer-name message-reply-buffer)
2758 (save-excursion
2759 (set-buffer message-reply-buffer)
2760 (message-get-reply-headers t)))))
2761 (save-excursion
2762 (save-restriction
2763 (message-narrow-to-headers)
2764 (dolist (elem follow-to)
2765 (message-remove-header (symbol-name (car elem)))
2766 (goto-char (point-min))
2767 (insert (symbol-name (car elem)) ": "
2768 (cdr elem) "\n"))))))
2770 (defun message-insert-newsgroups ()
2771 "Insert the Newsgroups header from the article being replied to."
2772 (interactive)
2773 (when (and (message-position-on-field "Newsgroups")
2774 (mail-fetch-field "newsgroups")
2775 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2776 (insert ","))
2777 (insert (or (message-fetch-reply-field "newsgroups") "")))
2781 ;;; Various commands
2783 (defun message-delete-not-region (beg end)
2784 "Delete everything in the body of the current message outside of the region."
2785 (interactive "r")
2786 (let (citeprefix)
2787 (save-excursion
2788 (goto-char beg)
2789 ;; snarf citation prefix, if appropriate
2790 (unless (eq (point) (progn (beginning-of-line) (point)))
2791 (when (looking-at message-cite-prefix-regexp)
2792 (setq citeprefix (match-string 0))))
2793 (goto-char end)
2794 (delete-region (point) (if (not (message-goto-signature))
2795 (point)
2796 (forward-line -2)
2797 (point)))
2798 (insert "\n")
2799 (goto-char beg)
2800 (delete-region beg (progn (message-goto-body)
2801 (forward-line 2)
2802 (point)))
2803 (when citeprefix
2804 (insert citeprefix))))
2805 (when (message-goto-signature)
2806 (forward-line -2)))
2808 (defun message-kill-to-signature ()
2809 "Deletes all text up to the signature."
2810 (interactive)
2811 (let ((point (point)))
2812 (message-goto-signature)
2813 (unless (eobp)
2814 (end-of-line -1))
2815 (kill-region point (point))
2816 (unless (bolp)
2817 (insert "\n"))))
2819 (defun message-newline-and-reformat (&optional arg not-break)
2820 "Insert four newlines, and then reformat if inside quoted text.
2821 Prefix arg means justify as well."
2822 (interactive (list (if current-prefix-arg 'full)))
2823 (let (quoted point beg end leading-space bolp)
2824 (setq point (point))
2825 (beginning-of-line)
2826 (setq beg (point))
2827 (setq bolp (= beg point))
2828 ;; Find first line of the paragraph.
2829 (if not-break
2830 (while (and (not (eobp))
2831 (not (looking-at message-cite-prefix-regexp))
2832 (looking-at paragraph-start))
2833 (forward-line 1)))
2834 ;; Find the prefix
2835 (when (looking-at message-cite-prefix-regexp)
2836 (setq quoted (match-string 0))
2837 (goto-char (match-end 0))
2838 (looking-at "[ \t]*")
2839 (setq leading-space (match-string 0)))
2840 (if (and quoted
2841 (not not-break)
2842 (not bolp)
2843 (< (- point beg) (length quoted)))
2844 ;; break inside the cite prefix.
2845 (setq quoted nil
2846 end nil))
2847 (if quoted
2848 (progn
2849 (forward-line 1)
2850 (while (and (not (eobp))
2851 (not (looking-at paragraph-separate))
2852 (looking-at message-cite-prefix-regexp)
2853 (equal quoted (match-string 0)))
2854 (goto-char (match-end 0))
2855 (looking-at "[ \t]*")
2856 (if (> (length leading-space) (length (match-string 0)))
2857 (setq leading-space (match-string 0)))
2858 (forward-line 1))
2859 (setq end (point))
2860 (goto-char beg)
2861 (while (and (if (bobp) nil (forward-line -1) t)
2862 (not (looking-at paragraph-start))
2863 (looking-at message-cite-prefix-regexp)
2864 (equal quoted (match-string 0)))
2865 (setq beg (point))
2866 (goto-char (match-end 0))
2867 (looking-at "[ \t]*")
2868 (if (> (length leading-space) (length (match-string 0)))
2869 (setq leading-space (match-string 0)))))
2870 (while (and (not (eobp))
2871 (not (looking-at paragraph-separate))
2872 (not (looking-at message-cite-prefix-regexp)))
2873 (forward-line 1))
2874 (setq end (point))
2875 (goto-char beg)
2876 (while (and (if (bobp) nil (forward-line -1) t)
2877 (not (looking-at paragraph-start))
2878 (not (looking-at message-cite-prefix-regexp)))
2879 (setq beg (point))))
2880 (goto-char point)
2881 (save-restriction
2882 (narrow-to-region beg end)
2883 (if not-break
2884 (setq point nil)
2885 (if bolp
2886 (newline)
2887 (newline)
2888 (newline))
2889 (setq point (point))
2890 ;; (newline 2) doesn't mark both newline's as hard, so call
2891 ;; newline twice. -jas
2892 (newline)
2893 (newline)
2894 (delete-region (point) (re-search-forward "[ \t]*"))
2895 (when (and quoted (not bolp))
2896 (insert quoted leading-space)))
2897 (undo-boundary)
2898 (if quoted
2899 (let* ((adaptive-fill-regexp
2900 (regexp-quote (concat quoted leading-space)))
2901 (adaptive-fill-first-line-regexp
2902 adaptive-fill-regexp ))
2903 (fill-paragraph arg))
2904 (fill-paragraph arg))
2905 (if point (goto-char point)))))
2907 (defun message-fill-paragraph (&optional arg)
2908 "Like `fill-paragraph'."
2909 (interactive (list (if current-prefix-arg 'full)))
2910 (if (if (boundp 'filladapt-mode) filladapt-mode)
2912 (message-newline-and-reformat arg t)
2915 ;; Is it better to use `mail-header-end'?
2916 (defun message-point-in-header-p ()
2917 "Return t if point is in the header."
2918 (save-excursion
2919 (let ((p (point)))
2920 (goto-char (point-min))
2921 (not (re-search-forward
2922 (concat "^" (regexp-quote mail-header-separator) "\n")
2923 p t)))))
2925 (defun message-do-auto-fill ()
2926 "Like `do-auto-fill', but don't fill in message header."
2927 (unless (message-point-in-header-p)
2928 (do-auto-fill)))
2930 (defun message-insert-signature (&optional force)
2931 "Insert a signature. See documentation for variable `message-signature'."
2932 (interactive (list 0))
2933 (let* ((signature
2934 (cond
2935 ((and (null message-signature)
2936 (eq force 0))
2937 (save-excursion
2938 (goto-char (point-max))
2939 (not (re-search-backward message-signature-separator nil t))))
2940 ((and (null message-signature)
2941 force)
2943 ((functionp message-signature)
2944 (funcall message-signature))
2945 ((listp message-signature)
2946 (eval message-signature))
2947 (t message-signature)))
2948 (signature
2949 (cond ((stringp signature)
2950 signature)
2951 ((and (eq t signature)
2952 message-signature-file
2953 (file-exists-p message-signature-file))
2954 signature))))
2955 (when signature
2956 (goto-char (point-max))
2957 ;; Insert the signature.
2958 (unless (bolp)
2959 (insert "\n"))
2960 (when message-signature-insert-empty-line
2961 (insert "\n"))
2962 (insert "-- \n")
2963 (if (eq signature t)
2964 (insert-file-contents message-signature-file)
2965 (insert signature))
2966 (goto-char (point-max))
2967 (or (bolp) (insert "\n")))))
2969 (defun message-insert-importance-high ()
2970 "Insert header to mark message as important."
2971 (interactive)
2972 (save-excursion
2973 (save-restriction
2974 (message-narrow-to-headers)
2975 (message-remove-header "Importance"))
2976 (message-goto-eoh)
2977 (insert "Importance: high\n")))
2979 (defun message-insert-importance-low ()
2980 "Insert header to mark message as unimportant."
2981 (interactive)
2982 (save-excursion
2983 (save-restriction
2984 (message-narrow-to-headers)
2985 (message-remove-header "Importance"))
2986 (message-goto-eoh)
2987 (insert "Importance: low\n")))
2989 (defun message-insert-or-toggle-importance ()
2990 "Insert a \"Importance: high\" header, or cycle through the header values.
2991 The three allowed values according to RFC 1327 are `high', `normal'
2992 and `low'."
2993 (interactive)
2994 (save-excursion
2995 (let ((valid '("high" "normal" "low"))
2996 (new "high")
2997 cur)
2998 (save-restriction
2999 (message-narrow-to-headers)
3000 (when (setq cur (message-fetch-field "Importance"))
3001 (message-remove-header "Importance")
3002 (setq new (cond ((string= cur "high")
3003 "low")
3004 ((string= cur "low")
3005 "normal")
3007 "high")))))
3008 (message-goto-eoh)
3009 (insert (format "Importance: %s\n" new)))))
3011 (defun message-insert-disposition-notification-to ()
3012 "Request a disposition notification (return receipt) to this message.
3013 Note that this should not be used in newsgroups."
3014 (interactive)
3015 (save-excursion
3016 (save-restriction
3017 (message-narrow-to-headers)
3018 (message-remove-header "Disposition-Notification-To"))
3019 (message-goto-eoh)
3020 (insert (format "Disposition-Notification-To: %s\n"
3021 (or (message-field-value "Reply-to")
3022 (message-field-value "From")
3023 (message-make-from))))))
3025 (defun message-elide-region (b e)
3026 "Elide the text in the region.
3027 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3028 text was killed."
3029 (interactive "r")
3030 (kill-region b e)
3031 (insert message-elide-ellipsis))
3033 (defvar message-caesar-translation-table nil)
3035 (defun message-caesar-region (b e &optional n)
3036 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3037 (interactive
3038 (list
3039 (min (point) (or (mark t) (point)))
3040 (max (point) (or (mark t) (point)))
3041 (when current-prefix-arg
3042 (prefix-numeric-value current-prefix-arg))))
3044 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3045 (unless (or (zerop n) ; no action needed for a rot of 0
3046 (= b e)) ; no region to rotate
3047 ;; We build the table, if necessary.
3048 (when (or (not message-caesar-translation-table)
3049 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3050 (setq message-caesar-translation-table
3051 (message-make-caesar-translation-table n)))
3052 (translate-region b e message-caesar-translation-table)))
3054 (defun message-make-caesar-translation-table (n)
3055 "Create a rot table with offset N."
3056 (let ((i -1)
3057 (table (make-string 256 0)))
3058 (while (< (incf i) 256)
3059 (aset table i i))
3060 (concat
3061 (substring table 0 ?A)
3062 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3063 (substring table ?A (+ ?A n))
3064 (substring table (+ ?A 26) ?a)
3065 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3066 (substring table ?a (+ ?a n))
3067 (substring table (+ ?a 26) 255))))
3069 (defun message-caesar-buffer-body (&optional rotnum)
3070 "Caesar rotate all letters in the current buffer by 13 places.
3071 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3072 With prefix arg, specifies the number of places to rotate each letter forward.
3073 Mail and USENET news headers are not rotated."
3074 (interactive (if current-prefix-arg
3075 (list (prefix-numeric-value current-prefix-arg))
3076 (list nil)))
3077 (save-excursion
3078 (save-restriction
3079 (when (message-goto-body)
3080 (narrow-to-region (point) (point-max)))
3081 (message-caesar-region (point-min) (point-max) rotnum))))
3083 (defun message-pipe-buffer-body (program)
3084 "Pipe the message body in the current buffer through PROGRAM."
3085 (save-excursion
3086 (save-restriction
3087 (when (message-goto-body)
3088 (narrow-to-region (point) (point-max)))
3089 (shell-command-on-region
3090 (point-min) (point-max) program nil t))))
3092 (defun message-rename-buffer (&optional enter-string)
3093 "Rename the *message* buffer to \"*message* RECIPIENT\".
3094 If the function is run with a prefix, it will ask for a new buffer
3095 name, rather than giving an automatic name."
3096 (interactive "Pbuffer name: ")
3097 (save-excursion
3098 (save-restriction
3099 (goto-char (point-min))
3100 (narrow-to-region (point)
3101 (search-forward mail-header-separator nil 'end))
3102 (let* ((mail-to (or
3103 (if (message-news-p) (message-fetch-field "Newsgroups")
3104 (message-fetch-field "To"))
3105 ""))
3106 (mail-trimmed-to
3107 (if (string-match "," mail-to)
3108 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3109 mail-to))
3110 (name-default (concat "*message* " mail-trimmed-to))
3111 (name (if enter-string
3112 (read-string "New buffer name: " name-default)
3113 name-default)))
3114 (rename-buffer name t)))))
3116 (defun message-fill-yanked-message (&optional justifyp)
3117 "Fill the paragraphs of a message yanked into this one.
3118 Numeric argument means justify as well."
3119 (interactive "P")
3120 (save-excursion
3121 (goto-char (point-min))
3122 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3123 (let ((fill-prefix message-yank-prefix))
3124 (fill-individual-paragraphs (point) (point-max) justifyp))))
3126 (defun message-indent-citation ()
3127 "Modify text just inserted from a message to be cited.
3128 The inserted text should be the region.
3129 When this function returns, the region is again around the modified text.
3131 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3132 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3133 (let ((start (point)))
3134 ;; Remove unwanted headers.
3135 (when message-ignored-cited-headers
3136 (let (all-removed)
3137 (save-restriction
3138 (narrow-to-region
3139 (goto-char start)
3140 (if (search-forward "\n\n" nil t)
3141 (1- (point))
3142 (point)))
3143 (message-remove-header message-ignored-cited-headers t)
3144 (when (= (point-min) (point-max))
3145 (setq all-removed t))
3146 (goto-char (point-max)))
3147 (if all-removed
3148 (goto-char start)
3149 (forward-line 1))))
3150 ;; Delete blank lines at the start of the buffer.
3151 (while (and (point-min)
3152 (eolp)
3153 (not (eobp)))
3154 (message-delete-line))
3155 ;; Delete blank lines at the end of the buffer.
3156 (goto-char (point-max))
3157 (unless (eolp)
3158 (insert "\n"))
3159 (while (and (zerop (forward-line -1))
3160 (looking-at "$"))
3161 (message-delete-line))
3162 ;; Do the indentation.
3163 (if (null message-yank-prefix)
3164 (indent-rigidly start (mark t) message-indentation-spaces)
3165 (save-excursion
3166 (goto-char start)
3167 (while (< (point) (mark t))
3168 (if (or (looking-at ">") (looking-at "^$"))
3169 (insert message-yank-cited-prefix)
3170 (insert message-yank-prefix))
3171 (forward-line 1))))
3172 (goto-char start)))
3174 (defun message-yank-original (&optional arg)
3175 "Insert the message being replied to, if any.
3176 Puts point before the text and mark after.
3177 Normally indents each nonblank line ARG spaces (default 3). However,
3178 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3180 This function uses `message-cite-function' to do the actual citing.
3182 Just \\[universal-argument] as argument means don't indent, insert no
3183 prefix, and don't delete any headers."
3184 (interactive "P")
3185 (let ((modified (buffer-modified-p)))
3186 (when (and message-reply-buffer
3187 message-cite-function)
3188 (delete-windows-on message-reply-buffer t)
3189 (insert-buffer message-reply-buffer)
3190 (unless arg
3191 (funcall message-cite-function))
3192 (message-exchange-point-and-mark)
3193 (unless (bolp)
3194 (insert ?\n))
3195 (unless modified
3196 (setq message-checksum (message-checksum))))))
3198 (defun message-yank-buffer (buffer)
3199 "Insert BUFFER into the current buffer and quote it."
3200 (interactive "bYank buffer: ")
3201 (let ((message-reply-buffer (get-buffer buffer)))
3202 (save-window-excursion
3203 (message-yank-original))))
3205 (defun message-buffers ()
3206 "Return a list of active message buffers."
3207 (let (buffers)
3208 (save-excursion
3209 (dolist (buffer (buffer-list t))
3210 (set-buffer buffer)
3211 (when (and (eq major-mode 'message-mode)
3212 (null message-sent-message-via))
3213 (push (buffer-name buffer) buffers))))
3214 (nreverse buffers)))
3216 (defun message-cite-original-without-signature ()
3217 "Cite function in the standard Message manner."
3218 (let* ((start (point))
3219 (end (mark t))
3220 (functions
3221 (when message-indent-citation-function
3222 (if (listp message-indent-citation-function)
3223 message-indent-citation-function
3224 (list message-indent-citation-function))))
3225 ;; This function may be called by `gnus-summary-yank-message' and
3226 ;; may insert a different article from the original. So, we will
3227 ;; modify the value of `message-reply-headers' with that article.
3228 (message-reply-headers
3229 (save-restriction
3230 (narrow-to-region start end)
3231 (message-narrow-to-head-1)
3232 (vector 0
3233 (or (message-fetch-field "subject") "none")
3234 (message-fetch-field "from")
3235 (message-fetch-field "date")
3236 (message-fetch-field "message-id" t)
3237 (message-fetch-field "references")
3238 0 0 ""))))
3239 (mml-quote-region start end)
3240 ;; Allow undoing.
3241 (undo-boundary)
3242 (goto-char end)
3243 (when (re-search-backward message-signature-separator start t)
3244 ;; Also peel off any blank lines before the signature.
3245 (forward-line -1)
3246 (while (looking-at "^[ \t]*$")
3247 (forward-line -1))
3248 (forward-line 1)
3249 (delete-region (point) end)
3250 (unless (search-backward "\n\n" start t)
3251 ;; Insert a blank line if it is peeled off.
3252 (insert "\n")))
3253 (goto-char start)
3254 (while functions
3255 (funcall (pop functions)))
3256 (when message-citation-line-function
3257 (unless (bolp)
3258 (insert "\n"))
3259 (funcall message-citation-line-function))))
3261 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3262 (defun message-cite-original ()
3263 "Cite function in the standard Message manner."
3264 (if (and (boundp 'mail-citation-hook)
3265 mail-citation-hook)
3266 (run-hooks 'mail-citation-hook)
3267 (let* ((start (point))
3268 (end (mark t))
3269 (functions
3270 (when message-indent-citation-function
3271 (if (listp message-indent-citation-function)
3272 message-indent-citation-function
3273 (list message-indent-citation-function))))
3274 ;; This function may be called by `gnus-summary-yank-message' and
3275 ;; may insert a different article from the original. So, we will
3276 ;; modify the value of `message-reply-headers' with that article.
3277 (message-reply-headers
3278 (save-restriction
3279 (narrow-to-region start end)
3280 (message-narrow-to-head-1)
3281 (vector 0
3282 (or (message-fetch-field "subject") "none")
3283 (message-fetch-field "from")
3284 (message-fetch-field "date")
3285 (message-fetch-field "message-id" t)
3286 (message-fetch-field "references")
3287 0 0 ""))))
3288 (mml-quote-region start end)
3289 (goto-char start)
3290 (while functions
3291 (funcall (pop functions)))
3292 (when message-citation-line-function
3293 (unless (bolp)
3294 (insert "\n"))
3295 (funcall message-citation-line-function)))))
3297 (defun message-insert-citation-line ()
3298 "Insert a simple citation line."
3299 (when message-reply-headers
3300 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3302 (defun message-position-on-field (header &rest afters)
3303 (let ((case-fold-search t))
3304 (save-restriction
3305 (narrow-to-region
3306 (goto-char (point-min))
3307 (progn
3308 (re-search-forward
3309 (concat "^" (regexp-quote mail-header-separator) "$"))
3310 (match-beginning 0)))
3311 (goto-char (point-min))
3312 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3313 (progn
3314 (re-search-forward "^[^ \t]" nil 'move)
3315 (beginning-of-line)
3316 (skip-chars-backward "\n")
3318 (while (and afters
3319 (not (re-search-forward
3320 (concat "^" (regexp-quote (car afters)) ":")
3321 nil t)))
3322 (pop afters))
3323 (when afters
3324 (re-search-forward "^[^ \t]" nil 'move)
3325 (beginning-of-line))
3326 (insert header ": \n")
3327 (forward-char -1)
3328 nil))))
3330 (defun message-remove-signature ()
3331 "Remove the signature from the text between point and mark.
3332 The text will also be indented the normal way."
3333 (save-excursion
3334 (let ((start (point))
3335 mark)
3336 (if (not (re-search-forward message-signature-separator (mark t) t))
3337 ;; No signature here, so we just indent the cited text.
3338 (message-indent-citation)
3339 ;; Find the last non-empty line.
3340 (forward-line -1)
3341 (while (looking-at "[ \t]*$")
3342 (forward-line -1))
3343 (forward-line 1)
3344 (setq mark (set-marker (make-marker) (point)))
3345 (goto-char start)
3346 (message-indent-citation)
3347 ;; Enable undoing the deletion.
3348 (undo-boundary)
3349 (delete-region mark (mark t))
3350 (set-marker mark nil)))))
3355 ;;; Sending messages
3358 (defun message-send-and-exit (&optional arg)
3359 "Send message like `message-send', then, if no errors, exit from mail buffer."
3360 (interactive "P")
3361 (let ((buf (current-buffer))
3362 (actions message-exit-actions))
3363 (when (and (message-send arg)
3364 (buffer-name buf))
3365 (if message-kill-buffer-on-exit
3366 (kill-buffer buf)
3367 (bury-buffer buf)
3368 (when (eq buf (current-buffer))
3369 (message-bury buf)))
3370 (message-do-actions actions)
3371 t)))
3373 (defun message-dont-send ()
3374 "Don't send the message you have been editing.
3375 Instead, just auto-save the buffer and then bury it."
3376 (interactive)
3377 (set-buffer-modified-p t)
3378 (save-buffer)
3379 (let ((actions message-postpone-actions))
3380 (message-bury (current-buffer))
3381 (message-do-actions actions)))
3383 (defun message-kill-buffer ()
3384 "Kill the current buffer."
3385 (interactive)
3386 (when (or (not (buffer-modified-p))
3387 (yes-or-no-p "Message modified; kill anyway? "))
3388 (let ((actions message-kill-actions)
3389 (draft-article message-draft-article)
3390 (auto-save-file-name buffer-auto-save-file-name)
3391 (file-name buffer-file-name)
3392 (modified (buffer-modified-p)))
3393 (setq buffer-file-name nil)
3394 (kill-buffer (current-buffer))
3395 (when (and (or (and auto-save-file-name
3396 (file-exists-p auto-save-file-name))
3397 (and file-name
3398 (file-exists-p file-name)))
3399 (yes-or-no-p (format "Remove the backup file%s? "
3400 (if modified " too" ""))))
3401 (ignore-errors
3402 (delete-file auto-save-file-name))
3403 (let ((message-draft-article draft-article))
3404 (message-disassociate-draft)))
3405 (message-do-actions actions))))
3407 (defun message-bury (buffer)
3408 "Bury this mail BUFFER."
3409 (let ((newbuf (other-buffer buffer)))
3410 (bury-buffer buffer)
3411 (if (and (fboundp 'frame-parameters)
3412 (cdr (assq 'dedicated (frame-parameters)))
3413 (not (null (delq (selected-frame) (visible-frame-list)))))
3414 (delete-frame (selected-frame))
3415 (switch-to-buffer newbuf))))
3417 (defun message-send (&optional arg)
3418 "Send the message in the current buffer.
3419 If `message-interactive' is non-nil, wait for success indication or
3420 error messages, and inform user.
3421 Otherwise any failure is reported in a message back to the user from
3422 the mailer.
3423 The usage of ARG is defined by the instance that called Message.
3424 It should typically alter the sending method in some way or other."
3425 (interactive "P")
3426 ;; Make it possible to undo the coming changes.
3427 (undo-boundary)
3428 (let ((inhibit-read-only t))
3429 (put-text-property (point-min) (point-max) 'read-only nil))
3430 (message-fix-before-sending)
3431 (run-hooks 'message-send-hook)
3432 (message message-sending-message)
3433 (let ((alist message-send-method-alist)
3434 (success t)
3435 elem sent dont-barf-on-no-method
3436 (message-options message-options))
3437 (message-options-set-recipient)
3438 (while (and success
3439 (setq elem (pop alist)))
3440 (when (funcall (cadr elem))
3441 (when (and (or (not (memq (car elem)
3442 message-sent-message-via))
3443 (message-fetch-field "supersedes")
3444 (if (or (message-gnksa-enable-p 'multiple-copies)
3445 (not (eq (car elem) 'news)))
3446 (y-or-n-p
3447 (format
3448 "Already sent message via %s; resend? "
3449 (car elem)))
3450 (error "Denied posting -- multiple copies")))
3451 (setq success (funcall (caddr elem) arg)))
3452 (setq sent t))))
3453 (unless (or sent
3454 (not success)
3455 (let ((fcc (message-fetch-field "Fcc"))
3456 (gcc (message-fetch-field "Gcc")))
3457 (when (or fcc gcc)
3458 (or (eq message-allow-no-recipients 'always)
3459 (and (not (eq message-allow-no-recipients 'never))
3460 (setq dont-barf-on-no-method
3461 (gnus-y-or-n-p
3462 (format "No receiver, perform %s anyway? "
3463 (cond ((and fcc gcc) "Fcc and Gcc")
3464 (fcc "Fcc")
3465 (t "Gcc"))))))))))
3466 (error "No methods specified to send by"))
3467 (when (or dont-barf-on-no-method
3468 (and success sent))
3469 (message-do-fcc)
3470 (save-excursion
3471 (run-hooks 'message-sent-hook))
3472 (message "Sending...done")
3473 ;; Mark the buffer as unmodified and delete auto-save.
3474 (set-buffer-modified-p nil)
3475 (delete-auto-save-file-if-necessary t)
3476 (message-disassociate-draft)
3477 ;; Delete other mail buffers and stuff.
3478 (message-do-send-housekeeping)
3479 (message-do-actions message-send-actions)
3480 ;; Return success.
3481 t)))
3483 (defun message-send-via-mail (arg)
3484 "Send the current message via mail."
3485 (message-send-mail arg))
3487 (defun message-send-via-news (arg)
3488 "Send the current message via news."
3489 (funcall message-send-news-function arg))
3491 (defmacro message-check (type &rest forms)
3492 "Eval FORMS if TYPE is to be checked."
3493 `(or (message-check-element ,type)
3494 (save-excursion
3495 ,@forms)))
3497 (put 'message-check 'lisp-indent-function 1)
3498 (put 'message-check 'edebug-form-spec '(form body))
3500 (defun message-text-with-property (prop)
3501 "Return a list of all points where the text has PROP."
3502 (let ((points nil)
3503 (point (point-min)))
3504 (save-excursion
3505 (while (< point (point-max))
3506 (when (get-text-property point prop)
3507 (push point points))
3508 (incf point)))
3509 (nreverse points)))
3511 (defun message-fix-before-sending ()
3512 "Do various things to make the message nice before sending it."
3513 ;; Make sure there's a newline at the end of the message.
3514 (goto-char (point-max))
3515 (unless (bolp)
3516 (insert "\n"))
3517 ;; Make the hidden headers visible.
3518 (let ((points (message-text-with-property 'message-hidden)))
3519 (when points
3520 (goto-char (car points))
3521 (dolist (point points)
3522 (add-text-properties point (1+ point)
3523 '(invisible nil intangible nil)))))
3524 ;; Make invisible text visible.
3525 ;; It doesn't seem as if this is useful, since the invisible property
3526 ;; is clobbered by an after-change hook anyhow.
3527 (message-check 'invisible-text
3528 (let ((points (message-text-with-property 'invisible)))
3529 (when points
3530 (goto-char (car points))
3531 (dolist (point points)
3532 (put-text-property point (1+ point) 'invisible nil)
3533 (message-overlay-put (message-make-overlay point (1+ point))
3534 'face 'highlight))
3535 (unless (yes-or-no-p
3536 "Invisible text found and made visible; continue sending? ")
3537 (error "Invisible text found and made visible")))))
3538 (message-check 'illegible-text
3539 (let (found choice)
3540 (message-goto-body)
3541 (skip-chars-forward mm-7bit-chars)
3542 (while (not (eobp))
3543 (when (let ((char (char-after)))
3544 (or (< (mm-char-int char) 128)
3545 (and (mm-multibyte-p)
3546 (memq (char-charset char)
3547 '(eight-bit-control eight-bit-graphic
3548 control-1))
3549 (not (get-text-property
3550 (point) 'untranslated-utf-8)))))
3551 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3552 'face 'highlight)
3553 (setq found t))
3554 (forward-char)
3555 (skip-chars-forward mm-7bit-chars))
3556 (when found
3557 (setq choice
3558 (gnus-multiple-choice
3559 "Non-printable characters found. Continue sending?"
3560 '((?d "Remove non-printable characters and send")
3561 (?r "Replace non-printable characters with dots and send")
3562 (?i "Ignore non-printable characters and send")
3563 (?e "Continue editing"))))
3564 (if (eq choice ?e)
3565 (error "Non-printable characters"))
3566 (message-goto-body)
3567 (skip-chars-forward mm-7bit-chars)
3568 (while (not (eobp))
3569 (when (let ((char (char-after)))
3570 (or (< (mm-char-int char) 128)
3571 (and (mm-multibyte-p)
3572 ;; Fixme: Wrong for Emacs 22 and for things
3573 ;; like undecable utf-8. Should at least
3574 ;; use find-coding-systems-region.
3575 (memq (char-charset char)
3576 '(eight-bit-control eight-bit-graphic
3577 control-1))
3578 (not (get-text-property
3579 (point) 'untranslated-utf-8)))))
3580 (if (eq choice ?i)
3581 (message-kill-all-overlays)
3582 (delete-char 1)
3583 (when (eq choice ?r)
3584 (insert "."))))
3585 (forward-char)
3586 (skip-chars-forward mm-7bit-chars))))))
3588 (defun message-add-action (action &rest types)
3589 "Add ACTION to be performed when doing an exit of type TYPES."
3590 (while types
3591 (add-to-list (intern (format "message-%s-actions" (pop types)))
3592 action)))
3594 (defun message-delete-action (action &rest types)
3595 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3596 (let (var)
3597 (while types
3598 (set (setq var (intern (format "message-%s-actions" (pop types))))
3599 (delq action (symbol-value var))))))
3601 (defun message-do-actions (actions)
3602 "Perform all actions in ACTIONS."
3603 ;; Now perform actions on successful sending.
3604 (while actions
3605 (ignore-errors
3606 (cond
3607 ;; A simple function.
3608 ((functionp (car actions))
3609 (funcall (car actions)))
3610 ;; Something to be evaled.
3612 (eval (car actions)))))
3613 (pop actions)))
3615 (defun message-send-mail-partially ()
3616 "Send mail as message/partial."
3617 ;; replace the header delimiter with a blank line
3618 (goto-char (point-min))
3619 (re-search-forward
3620 (concat "^" (regexp-quote mail-header-separator) "\n"))
3621 (replace-match "\n")
3622 (run-hooks 'message-send-mail-hook)
3623 (let ((p (goto-char (point-min)))
3624 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3625 (curbuf (current-buffer))
3626 (id (message-make-message-id)) (n 1)
3627 plist total header required-mail-headers)
3628 (while (not (eobp))
3629 (if (< (point-max) (+ p message-send-mail-partially-limit))
3630 (goto-char (point-max))
3631 (goto-char (+ p message-send-mail-partially-limit))
3632 (beginning-of-line)
3633 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3634 (push p plist)
3635 (setq p (point)))
3636 (setq total (length plist))
3637 (push (point-max) plist)
3638 (setq plist (nreverse plist))
3639 (unwind-protect
3640 (save-excursion
3641 (setq p (pop plist))
3642 (while plist
3643 (set-buffer curbuf)
3644 (copy-to-buffer tembuf p (car plist))
3645 (set-buffer tembuf)
3646 (goto-char (point-min))
3647 (if header
3648 (progn
3649 (goto-char (point-min))
3650 (narrow-to-region (point) (point))
3651 (insert header))
3652 (message-goto-eoh)
3653 (setq header (buffer-substring (point-min) (point)))
3654 (goto-char (point-min))
3655 (narrow-to-region (point) (point))
3656 (insert header)
3657 (message-remove-header "Mime-Version")
3658 (message-remove-header "Content-Type")
3659 (message-remove-header "Content-Transfer-Encoding")
3660 (message-remove-header "Message-ID")
3661 (message-remove-header "Lines")
3662 (goto-char (point-max))
3663 (insert "Mime-Version: 1.0\n")
3664 (setq header (buffer-string)))
3665 (goto-char (point-max))
3666 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3667 id n total))
3668 (forward-char -1)
3669 (let ((mail-header-separator ""))
3670 (when (memq 'Message-ID message-required-mail-headers)
3671 (insert "Message-ID: " (message-make-message-id) "\n"))
3672 (when (memq 'Lines message-required-mail-headers)
3673 (insert "Lines: " (message-make-lines) "\n"))
3674 (message-goto-subject)
3675 (end-of-line)
3676 (insert (format " (%d/%d)" n total))
3677 (widen)
3678 (mm-with-unibyte-current-buffer
3679 (funcall (or message-send-mail-real-function
3680 message-send-mail-function))))
3681 (setq n (+ n 1))
3682 (setq p (pop plist))
3683 (erase-buffer)))
3684 (kill-buffer tembuf))))
3686 (defun message-send-mail (&optional arg)
3687 (require 'mail-utils)
3688 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3689 (case-fold-search nil)
3690 (news (message-news-p))
3691 (mailbuf (current-buffer))
3692 (message-this-is-mail t)
3693 (message-posting-charset
3694 (if (fboundp 'gnus-setup-posting-charset)
3695 (gnus-setup-posting-charset nil)
3696 message-posting-charset))
3697 (headers message-required-mail-headers))
3698 (save-restriction
3699 (message-narrow-to-headers)
3700 ;; Generate the Mail-Followup-To header if the header is not there...
3701 (if (and (message-subscribed-p)
3702 (not (mail-fetch-field "mail-followup-to")))
3703 (setq headers
3704 (cons
3705 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3706 message-required-mail-headers))
3707 ;; otherwise, delete the MFT header if the field is empty
3708 (when (equal "" (mail-fetch-field "mail-followup-to"))
3709 (message-remove-header "^Mail-Followup-To:")))
3710 ;; Insert some headers.
3711 (let ((message-deletable-headers
3712 (if news nil message-deletable-headers)))
3713 (message-generate-headers headers))
3714 ;; Let the user do all of the above.
3715 (run-hooks 'message-header-hook))
3716 (unwind-protect
3717 (save-excursion
3718 (set-buffer tembuf)
3719 (erase-buffer)
3720 ;; Avoid copying text props (except hard newlines).
3721 (insert (with-current-buffer mailbuf
3722 (mml-buffer-substring-no-properties-except-hard-newlines
3723 (point-min) (point-max))))
3724 ;; Remove some headers.
3725 (message-encode-message-body)
3726 (save-restriction
3727 (message-narrow-to-headers)
3728 ;; We (re)generate the Lines header.
3729 (when (memq 'Lines message-required-mail-headers)
3730 (message-generate-headers '(Lines)))
3731 ;; Remove some headers.
3732 (message-remove-header message-ignored-mail-headers t)
3733 (let ((mail-parse-charset message-default-charset))
3734 (mail-encode-encoded-word-buffer)))
3735 (goto-char (point-max))
3736 ;; require one newline at the end.
3737 (or (= (preceding-char) ?\n)
3738 (insert ?\n))
3739 (message-cleanup-headers)
3740 ;; FIXME: we're inserting the courtesy copy after encoding.
3741 ;; This is wrong if the courtesy copy string contains
3742 ;; non-ASCII characters. -- jh
3743 (when
3744 (save-restriction
3745 (message-narrow-to-headers)
3746 (and news
3747 (or (message-fetch-field "cc")
3748 (message-fetch-field "bcc")
3749 (message-fetch-field "to"))
3750 (let ((content-type (message-fetch-field
3751 "content-type")))
3752 (and
3754 (not content-type)
3755 (string= "text/plain"
3756 (car
3757 (mail-header-parse-content-type
3758 content-type))))
3759 (not
3760 (string= "base64"
3761 (message-fetch-field
3762 "content-transfer-encoding")))))))
3763 (message-insert-courtesy-copy))
3764 (if (or (not message-send-mail-partially-limit)
3765 (< (buffer-size) message-send-mail-partially-limit)
3766 (not (message-y-or-n-p
3767 "The message size is too large, split? "
3770 The message size, "
3771 (/ (buffer-size) 1000) "KB, is too large.
3773 Some mail gateways (MTA's) bounce large messages. To avoid the
3774 problem, answer `y', and the message will be split into several
3775 smaller pieces, the size of each is about "
3776 (/ message-send-mail-partially-limit 1000)
3777 "KB except the last
3778 one.
3780 However, some mail readers (MUA's) can't read split messages, i.e.,
3781 mails in message/partially format. Answer `n', and the message will be
3782 sent in one piece.
3784 The size limit is controlled by `message-send-mail-partially-limit'.
3785 If you always want Gnus to send messages in one piece, set
3786 `message-send-mail-partially-limit' to nil.
3787 ")))
3788 (mm-with-unibyte-current-buffer
3789 (message "Sending via mail...")
3790 (funcall (or message-send-mail-real-function
3791 message-send-mail-function)))
3792 (message-send-mail-partially)))
3793 (kill-buffer tembuf))
3794 (set-buffer mailbuf)
3795 (push 'mail message-sent-message-via)))
3797 (defun message-send-mail-with-sendmail ()
3798 "Send off the prepared buffer with sendmail."
3799 (let ((errbuf (if message-interactive
3800 (message-generate-new-buffer-clone-locals
3801 " sendmail errors")
3803 resend-to-addresses delimline)
3804 (unwind-protect
3805 (progn
3806 (let ((case-fold-search t))
3807 (save-restriction
3808 (message-narrow-to-headers)
3809 (setq resend-to-addresses (message-fetch-field "resent-to")))
3810 ;; Change header-delimiter to be what sendmail expects.
3811 (goto-char (point-min))
3812 (re-search-forward
3813 (concat "^" (regexp-quote mail-header-separator) "\n"))
3814 (replace-match "\n")
3815 (backward-char 1)
3816 (setq delimline (point-marker))
3817 (run-hooks 'message-send-mail-hook)
3818 ;; Insert an extra newline if we need it to work around
3819 ;; Sun's bug that swallows newlines.
3820 (goto-char (1+ delimline))
3821 (when (eval message-mailer-swallows-blank-line)
3822 (newline))
3823 (when message-interactive
3824 (save-excursion
3825 (set-buffer errbuf)
3826 (erase-buffer))))
3827 (let* ((default-directory "/")
3828 (coding-system-for-write message-send-coding-system)
3829 (cpr (apply
3830 'call-process-region
3831 (append
3832 (list (point-min) (point-max)
3833 (if (boundp 'sendmail-program)
3834 sendmail-program
3835 "/usr/lib/sendmail")
3836 nil errbuf nil "-oi")
3837 ;; Always specify who from,
3838 ;; since some systems have broken sendmails.
3839 ;; But some systems are more broken with -f, so
3840 ;; we'll let users override this.
3841 (if (null message-sendmail-f-is-evil)
3842 (list "-f" (message-sendmail-envelope-from)))
3843 ;; These mean "report errors by mail"
3844 ;; and "deliver in background".
3845 (if (null message-interactive) '("-oem" "-odb"))
3846 ;; Get the addresses from the message
3847 ;; unless this is a resend.
3848 ;; We must not do that for a resend
3849 ;; because we would find the original addresses.
3850 ;; For a resend, include the specific addresses.
3851 (if resend-to-addresses
3852 (list resend-to-addresses)
3853 '("-t"))))))
3854 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
3855 (error "Sending...failed with exit value %d" cpr)))
3856 (when message-interactive
3857 (save-excursion
3858 (set-buffer errbuf)
3859 (goto-char (point-min))
3860 (while (re-search-forward "\n\n* *" nil t)
3861 (replace-match "; "))
3862 (if (not (zerop (buffer-size)))
3863 (error "Sending...failed to %s"
3864 (buffer-string))))))
3865 (when (bufferp errbuf)
3866 (kill-buffer errbuf)))))
3868 (defun message-send-mail-with-qmail ()
3869 "Pass the prepared message buffer to qmail-inject.
3870 Refer to the documentation for the variable `message-send-mail-function'
3871 to find out how to use this."
3872 ;; replace the header delimiter with a blank line
3873 (goto-char (point-min))
3874 (re-search-forward
3875 (concat "^" (regexp-quote mail-header-separator) "\n"))
3876 (replace-match "\n")
3877 (run-hooks 'message-send-mail-hook)
3878 ;; send the message
3879 (case
3880 (let ((coding-system-for-write message-send-coding-system))
3881 (apply
3882 'call-process-region (point-min) (point-max)
3883 message-qmail-inject-program nil nil nil
3884 ;; qmail-inject's default behaviour is to look for addresses on the
3885 ;; command line; if there're none, it scans the headers.
3886 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3888 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3889 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3890 ;; message from stdin.
3892 ;; qmail also has the advantage of not having been raped by
3893 ;; various vendors, so we don't have to allow for that, either --
3894 ;; compare this with message-send-mail-with-sendmail and weep
3895 ;; for sendmail's lost innocence.
3897 ;; all this is way cool coz it lets us keep the arguments entirely
3898 ;; free for -inject-arguments -- a big win for the user and for us
3899 ;; since we don't have to play that double-guessing game and the user
3900 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3901 (if (functionp message-qmail-inject-args)
3902 (funcall message-qmail-inject-args)
3903 message-qmail-inject-args)))
3904 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3905 ;; we have to look at the retval instead
3906 (0 nil)
3907 (100 (error "qmail-inject reported permanent failure"))
3908 (111 (error "qmail-inject reported transient failure"))
3909 ;; should never happen
3910 (t (error "qmail-inject reported unknown failure"))))
3912 (defun message-send-mail-with-mh ()
3913 "Send the prepared message buffer with mh."
3914 (let ((mh-previous-window-config nil)
3915 (name (mh-new-draft-name)))
3916 (setq buffer-file-name name)
3917 ;; MH wants to generate these headers itself.
3918 (when message-mh-deletable-headers
3919 (let ((headers message-mh-deletable-headers))
3920 (while headers
3921 (goto-char (point-min))
3922 (and (re-search-forward
3923 (concat "^" (symbol-name (car headers)) ": *") nil t)
3924 (message-delete-line))
3925 (pop headers))))
3926 (run-hooks 'message-send-mail-hook)
3927 ;; Pass it on to mh.
3928 (mh-send-letter)))
3930 (defun message-smtpmail-send-it ()
3931 "Send the prepared message buffer with `smtpmail-send-it'.
3932 This only differs from `smtpmail-send-it' that this command evaluates
3933 `message-send-mail-hook' just before sending a message. It is useful
3934 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3935 manual for details."
3936 (run-hooks 'message-send-mail-hook)
3937 (smtpmail-send-it))
3939 (defun message-canlock-generate ()
3940 "Return a string that is non-trivial to guess.
3941 Do not use this for anything important, it is cryptographically weak."
3942 (require 'sha1)
3943 (let (sha1-maximum-internal-length)
3944 (sha1 (concat (message-unique-id)
3945 (format "%x%x%x" (random) (random t) (random))
3946 (prin1-to-string (recent-keys))
3947 (prin1-to-string (garbage-collect))))))
3949 (defun message-canlock-password ()
3950 "The password used by message for cancel locks.
3951 This is the value of `canlock-password', if that option is non-nil.
3952 Otherwise, generate and save a value for `canlock-password' first."
3953 (unless canlock-password
3954 (customize-save-variable 'canlock-password (message-canlock-generate))
3955 (setq canlock-password-for-verify canlock-password))
3956 canlock-password)
3958 (defun message-insert-canlock ()
3959 (when message-insert-canlock
3960 (message-canlock-password)
3961 (canlock-insert-header)))
3963 (defun message-send-news (&optional arg)
3964 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3965 (case-fold-search nil)
3966 (method (if (functionp message-post-method)
3967 (funcall message-post-method arg)
3968 message-post-method))
3969 (newsgroups-field (save-restriction
3970 (message-narrow-to-headers-or-head)
3971 (message-fetch-field "Newsgroups")))
3972 (followup-field (save-restriction
3973 (message-narrow-to-headers-or-head)
3974 (message-fetch-field "Followup-To")))
3975 ;; BUG: We really need to get the charset for each name in the
3976 ;; Newsgroups and Followup-To lines to allow crossposting
3977 ;; between group namess with incompatible character sets.
3978 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3979 (group-field-charset
3980 (gnus-group-name-charset method newsgroups-field))
3981 (followup-field-charset
3982 (gnus-group-name-charset method (or followup-field "")))
3983 (rfc2047-header-encoding-alist
3984 (append (when group-field-charset
3985 (list (cons "Newsgroups" group-field-charset)))
3986 (when followup-field-charset
3987 (list (cons "Followup-To" followup-field-charset)))
3988 rfc2047-header-encoding-alist))
3989 (messbuf (current-buffer))
3990 (message-syntax-checks
3991 (if (and arg
3992 (listp message-syntax-checks))
3993 (cons '(existing-newsgroups . disabled)
3994 message-syntax-checks)
3995 message-syntax-checks))
3996 (message-this-is-news t)
3997 (message-posting-charset
3998 (gnus-setup-posting-charset newsgroups-field))
3999 result)
4000 (if (not (message-check-news-body-syntax))
4002 (save-restriction
4003 (message-narrow-to-headers)
4004 ;; Insert some headers.
4005 (message-generate-headers message-required-news-headers)
4006 (message-insert-canlock)
4007 ;; Let the user do all of the above.
4008 (run-hooks 'message-header-hook))
4009 ;; Note: This check will be disabled by the ".*" default value for
4010 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4011 (when (and group-field-charset
4012 (listp message-syntax-checks))
4013 (setq message-syntax-checks
4014 (cons '(valid-newsgroups . disabled)
4015 message-syntax-checks)))
4016 (message-cleanup-headers)
4017 (if (not (let ((message-post-method method))
4018 (message-check-news-syntax)))
4020 (unwind-protect
4021 (save-excursion
4022 (set-buffer tembuf)
4023 (buffer-disable-undo)
4024 (erase-buffer)
4025 ;; Avoid copying text props (except hard newlines).
4026 (insert
4027 (with-current-buffer messbuf
4028 (mml-buffer-substring-no-properties-except-hard-newlines
4029 (point-min) (point-max))))
4030 (message-encode-message-body)
4031 ;; Remove some headers.
4032 (save-restriction
4033 (message-narrow-to-headers)
4034 ;; We (re)generate the Lines header.
4035 (when (memq 'Lines message-required-mail-headers)
4036 (message-generate-headers '(Lines)))
4037 ;; Remove some headers.
4038 (message-remove-header message-ignored-news-headers t)
4039 (let ((mail-parse-charset message-default-charset))
4040 (mail-encode-encoded-word-buffer)))
4041 (goto-char (point-max))
4042 ;; require one newline at the end.
4043 (or (= (preceding-char) ?\n)
4044 (insert ?\n))
4045 (let ((case-fold-search t))
4046 ;; Remove the delimiter.
4047 (goto-char (point-min))
4048 (re-search-forward
4049 (concat "^" (regexp-quote mail-header-separator) "\n"))
4050 (replace-match "\n")
4051 (backward-char 1))
4052 (run-hooks 'message-send-news-hook)
4053 (gnus-open-server method)
4054 (message "Sending news via %s..." (gnus-server-string method))
4055 (setq result (let ((mail-header-separator ""))
4056 (gnus-request-post method))))
4057 (kill-buffer tembuf))
4058 (set-buffer messbuf)
4059 (if result
4060 (push 'news message-sent-message-via)
4061 (message "Couldn't send message via news: %s"
4062 (nnheader-get-report (car method)))
4063 nil)))))
4066 ;;; Header generation & syntax checking.
4069 (defun message-check-element (type)
4070 "Return non-nil if this TYPE is not to be checked."
4071 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4073 (let ((able (assq type message-syntax-checks)))
4074 (and (consp able)
4075 (eq (cdr able) 'disabled)))))
4077 (defun message-check-news-syntax ()
4078 "Check the syntax of the message."
4079 (save-excursion
4080 (save-restriction
4081 (widen)
4082 ;; We narrow to the headers and check them first.
4083 (save-excursion
4084 (save-restriction
4085 (message-narrow-to-headers)
4086 (message-check-news-header-syntax))))))
4088 (defun message-check-news-header-syntax ()
4089 (and
4090 ;; Check Newsgroups header.
4091 (message-check 'newsgroups
4092 (let ((group (message-fetch-field "newsgroups")))
4094 (and group
4095 (not (string-match "\\`[ \t]*\\'" group)))
4096 (ignore
4097 (message
4098 "The newsgroups field is empty or missing. Posting is denied.")))))
4099 ;; Check the Subject header.
4100 (message-check 'subject
4101 (let* ((case-fold-search t)
4102 (subject (message-fetch-field "subject")))
4104 (and subject
4105 (not (string-match "\\`[ \t]*\\'" subject)))
4106 (ignore
4107 (message
4108 "The subject field is empty or missing. Posting is denied.")))))
4109 ;; Check for commands in Subject.
4110 (message-check 'subject-cmsg
4111 (if (string-match "^cmsg " (message-fetch-field "subject"))
4112 (y-or-n-p
4113 "The control code \"cmsg\" is in the subject. Really post? ")
4115 ;; Check long header lines.
4116 (message-check 'long-header-lines
4117 (let ((start (point))
4118 (header nil)
4119 (length 0)
4120 found)
4121 (while (and (not found)
4122 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4123 (if (> (- (point) (match-beginning 0)) 998)
4124 (setq found t
4125 length (- (point) (match-beginning 0)))
4126 (setq header (match-string-no-properties 1)))
4127 (setq start (match-beginning 0))
4128 (forward-line 1))
4129 (if found
4130 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4131 header length))
4132 t)))
4133 ;; Check for multiple identical headers.
4134 (message-check 'multiple-headers
4135 (let (found)
4136 (while (and (not found)
4137 (re-search-forward "^[^ \t:]+: " nil t))
4138 (save-excursion
4139 (or (re-search-forward
4140 (concat "^"
4141 (regexp-quote
4142 (setq found
4143 (buffer-substring
4144 (match-beginning 0) (- (match-end 0) 2))))
4145 ":")
4146 nil t)
4147 (setq found nil))))
4148 (if found
4149 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4150 t)))
4151 ;; Check for Version and Sendsys.
4152 (message-check 'sendsys
4153 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4154 (y-or-n-p
4155 (format "The article contains a %s command. Really post? "
4156 (buffer-substring (match-beginning 0)
4157 (1- (match-end 0)))))
4159 ;; See whether we can shorten Followup-To.
4160 (message-check 'shorten-followup-to
4161 (let ((newsgroups (message-fetch-field "newsgroups"))
4162 (followup-to (message-fetch-field "followup-to"))
4164 (when (and newsgroups
4165 (string-match "," newsgroups)
4166 (not followup-to)
4167 (not
4168 (zerop
4169 (length
4170 (setq to (completing-read
4171 "Followups to (default: no Followup-To header) "
4172 (mapcar #'list
4173 (cons "poster"
4174 (message-tokenize-header
4175 newsgroups)))))))))
4176 (goto-char (point-min))
4177 (insert "Followup-To: " to "\n"))
4179 ;; Check "Shoot me".
4180 (message-check 'shoot
4181 (if (re-search-forward
4182 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4183 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4185 ;; Check for Approved.
4186 (message-check 'approved
4187 (if (re-search-forward "^Approved:" nil t)
4188 (y-or-n-p "The article contains an Approved header. Really post? ")
4190 ;; Check the Message-ID header.
4191 (message-check 'message-id
4192 (let* ((case-fold-search t)
4193 (message-id (message-fetch-field "message-id" t)))
4194 (or (not message-id)
4195 ;; Is there an @ in the ID?
4196 (and (string-match "@" message-id)
4197 ;; Is there a dot in the ID?
4198 (string-match "@[^.]*\\." message-id)
4199 ;; Does the ID end with a dot?
4200 (not (string-match "\\.>" message-id)))
4201 (y-or-n-p
4202 (format "The Message-ID looks strange: \"%s\". Really post? "
4203 message-id)))))
4204 ;; Check the Newsgroups & Followup-To headers.
4205 (message-check 'existing-newsgroups
4206 (let* ((case-fold-search t)
4207 (newsgroups (message-fetch-field "newsgroups"))
4208 (followup-to (message-fetch-field "followup-to"))
4209 (groups (message-tokenize-header
4210 (if followup-to
4211 (concat newsgroups "," followup-to)
4212 newsgroups)))
4213 (post-method (if (functionp message-post-method)
4214 (funcall message-post-method)
4215 message-post-method))
4216 ;; KLUDGE to handle nnvirtual groups. Doing this right
4217 ;; would probably involve a new nnoo function.
4218 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4219 (method (if (and (consp post-method)
4220 (eq (car post-method) 'nnvirtual)
4221 gnus-message-group-art)
4222 (let ((group (car (nnvirtual-find-group-art
4223 (car gnus-message-group-art)
4224 (cdr gnus-message-group-art)))))
4225 (gnus-find-method-for-group group))
4226 post-method))
4227 (known-groups
4228 (mapcar (lambda (n)
4229 (gnus-group-name-decode
4230 (gnus-group-real-name n)
4231 (gnus-group-name-charset method n)))
4232 (gnus-groups-from-server method)))
4233 errors)
4234 (while groups
4235 (when (and (not (equal (car groups) "poster"))
4236 (not (member (car groups) known-groups))
4237 (not (member (car groups) errors)))
4238 (push (car groups) errors))
4239 (pop groups))
4240 (cond
4241 ;; Gnus is not running.
4242 ((or (not (and (boundp 'gnus-active-hashtb)
4243 gnus-active-hashtb))
4244 (not (boundp 'gnus-read-active-file)))
4246 ;; We don't have all the group names.
4247 ((and (or (not gnus-read-active-file)
4248 (eq gnus-read-active-file 'some))
4249 errors)
4250 (y-or-n-p
4251 (format
4252 "Really use %s possibly unknown group%s: %s? "
4253 (if (= (length errors) 1) "this" "these")
4254 (if (= (length errors) 1) "" "s")
4255 (mapconcat 'identity errors ", "))))
4256 ;; There were no errors.
4257 ((not errors)
4259 ;; There are unknown groups.
4261 (y-or-n-p
4262 (format
4263 "Really post to %s unknown group%s: %s? "
4264 (if (= (length errors) 1) "this" "these")
4265 (if (= (length errors) 1) "" "s")
4266 (mapconcat 'identity errors ", ")))))))
4267 ;; Check continuation headers.
4268 (message-check 'continuation-headers
4269 (goto-char (point-min))
4270 (let ((do-posting t))
4271 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4272 (if (y-or-n-p "Fix continuation lines? ")
4273 (progn
4274 (goto-char (match-beginning 0))
4275 (insert " "))
4276 (unless (y-or-n-p "Send anyway? ")
4277 (setq do-posting nil))))
4278 do-posting))
4279 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4280 (message-check 'valid-newsgroups
4281 (let ((case-fold-search t)
4282 (headers '("Newsgroups" "Followup-To"))
4283 header error)
4284 (while (and headers (not error))
4285 (when (setq header (mail-fetch-field (car headers)))
4286 (if (or
4287 (not
4288 (string-match
4289 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4290 header))
4291 (memq
4292 nil (mapcar
4293 (lambda (g)
4294 (not (string-match "\\.\\'\\|\\.\\." g)))
4295 (message-tokenize-header header ","))))
4296 (setq error t)))
4297 (unless error
4298 (pop headers)))
4299 (if (not error)
4301 (y-or-n-p
4302 (format "The %s header looks odd: \"%s\". Really post? "
4303 (car headers) header)))))
4304 (message-check 'repeated-newsgroups
4305 (let ((case-fold-search t)
4306 (headers '("Newsgroups" "Followup-To"))
4307 header error groups group)
4308 (while (and headers
4309 (not error))
4310 (when (setq header (mail-fetch-field (pop headers)))
4311 (setq groups (message-tokenize-header header ","))
4312 (while (setq group (pop groups))
4313 (when (member group groups)
4314 (setq error group
4315 groups nil)))))
4316 (if (not error)
4318 (y-or-n-p
4319 (format "Group %s is repeated in headers. Really post? " error)))))
4320 ;; Check the From header.
4321 (message-check 'from
4322 (let* ((case-fold-search t)
4323 (from (message-fetch-field "from"))
4325 (cond
4326 ((not from)
4327 (message "There is no From line. Posting is denied.")
4328 nil)
4329 ((or (not (string-match
4330 "@[^\\.]*\\."
4331 (setq ad (nth 1 (mail-extract-address-components
4332 from))))) ;larsi@ifi
4333 (string-match "\\.\\." ad) ;larsi@ifi..uio
4334 (string-match "@\\." ad) ;larsi@.ifi.uio
4335 (string-match "\\.$" ad) ;larsi@ifi.uio.
4336 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4337 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4338 (message
4339 "Denied posting -- the From looks strange: \"%s\"." from)
4340 nil)
4341 ((let ((addresses (rfc822-addresses from)))
4342 (while (and addresses
4343 (not (eq (string-to-char (car addresses)) ?\()))
4344 (setq addresses (cdr addresses)))
4345 addresses)
4346 (message
4347 "Denied posting -- bad From address: \"%s\"." from)
4348 nil)
4349 (t t))))
4350 ;; Check the Reply-To header.
4351 (message-check 'reply-to
4352 (let* ((case-fold-search t)
4353 (reply-to (message-fetch-field "reply-to"))
4355 (cond
4356 ((not reply-to)
4358 ((string-match "," reply-to)
4359 (y-or-n-p
4360 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4361 reply-to)))
4362 ((or (not (string-match
4363 "@[^\\.]*\\."
4364 (setq ad (nth 1 (mail-extract-address-components
4365 reply-to))))) ;larsi@ifi
4366 (string-match "\\.\\." ad) ;larsi@ifi..uio
4367 (string-match "@\\." ad) ;larsi@.ifi.uio
4368 (string-match "\\.$" ad) ;larsi@ifi.uio.
4369 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4370 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4371 (y-or-n-p
4372 (format
4373 "The Reply-To looks strange: \"%s\". Really post? "
4374 reply-to)))
4375 (t t))))))
4377 (defun message-check-news-body-syntax ()
4378 (and
4379 ;; Check for long lines.
4380 (message-check 'long-lines
4381 (goto-char (point-min))
4382 (re-search-forward
4383 (concat "^" (regexp-quote mail-header-separator) "$"))
4384 (forward-line 1)
4385 (while (and
4386 (or (looking-at
4387 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4388 (let ((p (point)))
4389 (end-of-line)
4390 (< (- (point) p) 80)))
4391 (zerop (forward-line 1))))
4392 (or (bolp)
4393 (eobp)
4394 (y-or-n-p
4395 "You have lines longer than 79 characters. Really post? ")))
4396 ;; Check whether the article is empty.
4397 (message-check 'empty
4398 (goto-char (point-min))
4399 (re-search-forward
4400 (concat "^" (regexp-quote mail-header-separator) "$"))
4401 (forward-line 1)
4402 (let ((b (point)))
4403 (goto-char (point-max))
4404 (re-search-backward message-signature-separator nil t)
4405 (beginning-of-line)
4406 (or (re-search-backward "[^ \n\t]" b t)
4407 (if (message-gnksa-enable-p 'empty-article)
4408 (y-or-n-p "Empty article. Really post? ")
4409 (message "Denied posting -- Empty article.")
4410 nil))))
4411 ;; Check for control characters.
4412 (message-check 'control-chars
4413 (if (re-search-forward
4414 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4415 nil t)
4416 (y-or-n-p
4417 "The article contains control characters. Really post? ")
4419 ;; Check excessive size.
4420 (message-check 'size
4421 (if (> (buffer-size) 60000)
4422 (y-or-n-p
4423 (format "The article is %d octets long. Really post? "
4424 (buffer-size)))
4426 ;; Check whether any new text has been added.
4427 (message-check 'new-text
4429 (not message-checksum)
4430 (not (eq (message-checksum) message-checksum))
4431 (if (message-gnksa-enable-p 'quoted-text-only)
4432 (y-or-n-p
4433 "It looks like no new text has been added. Really post? ")
4434 (message "Denied posting -- no new text has been added.")
4435 nil)))
4436 ;; Check the length of the signature.
4437 (message-check 'signature
4438 (goto-char (point-max))
4439 (if (> (count-lines (point) (point-max)) 5)
4440 (y-or-n-p
4441 (format
4442 "Your .sig is %d lines; it should be max 4. Really post? "
4443 (1- (count-lines (point) (point-max)))))
4445 ;; Ensure that text follows last quoted portion.
4446 (message-check 'quoting-style
4447 (goto-char (point-max))
4448 (let ((no-problem t))
4449 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4450 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4451 (if no-problem
4453 (if (message-gnksa-enable-p 'quoted-text-only)
4454 (y-or-n-p "Your text should follow quoted text. Really post? ")
4455 ;; Ensure that
4456 (goto-char (point-min))
4457 (re-search-forward
4458 (concat "^" (regexp-quote mail-header-separator) "$"))
4459 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4460 (y-or-n-p "Your text should follow quoted text. Really post? ")
4461 (message "Denied posting -- only quoted text.")
4462 nil)))))))
4464 (defun message-checksum ()
4465 "Return a \"checksum\" for the current buffer."
4466 (let ((sum 0))
4467 (save-excursion
4468 (goto-char (point-min))
4469 (re-search-forward
4470 (concat "^" (regexp-quote mail-header-separator) "$"))
4471 (while (not (eobp))
4472 (when (not (looking-at "[ \t\n]"))
4473 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4474 (char-after))))
4475 (forward-char 1)))
4476 sum))
4478 (defun message-do-fcc ()
4479 "Process Fcc headers in the current buffer."
4480 (let ((case-fold-search t)
4481 (buf (current-buffer))
4482 list file
4483 (mml-externalize-attachments message-fcc-externalize-attachments))
4484 (save-excursion
4485 (save-restriction
4486 (message-narrow-to-headers)
4487 (setq file (message-fetch-field "fcc" t)))
4488 (when file
4489 (set-buffer (get-buffer-create " *message temp*"))
4490 (erase-buffer)
4491 (insert-buffer-substring buf)
4492 (message-encode-message-body)
4493 (save-restriction
4494 (message-narrow-to-headers)
4495 (while (setq file (message-fetch-field "fcc" t))
4496 (push file list)
4497 (message-remove-header "fcc" nil t))
4498 (let ((mail-parse-charset message-default-charset)
4499 (rfc2047-header-encoding-alist
4500 (cons '("Newsgroups" . default)
4501 rfc2047-header-encoding-alist)))
4502 (mail-encode-encoded-word-buffer)))
4503 (goto-char (point-min))
4504 (when (re-search-forward
4505 (concat "^" (regexp-quote mail-header-separator) "$")
4506 nil t)
4507 (replace-match "" t t ))
4508 ;; Process FCC operations.
4509 (while list
4510 (setq file (pop list))
4511 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4512 ;; Pipe the article to the program in question.
4513 (call-process-region (point-min) (point-max) shell-file-name
4514 nil nil nil shell-command-switch
4515 (match-string 1 file))
4516 ;; Save the article.
4517 (setq file (expand-file-name file))
4518 (unless (file-exists-p (file-name-directory file))
4519 (make-directory (file-name-directory file) t))
4520 (if (and message-fcc-handler-function
4521 (not (eq message-fcc-handler-function 'rmail-output)))
4522 (funcall message-fcc-handler-function file)
4523 (if (and (file-readable-p file) (mail-file-babyl-p file))
4524 (rmail-output file 1 nil t)
4525 (let ((mail-use-rfc822 t))
4526 (rmail-output file 1 t t))))))
4527 (kill-buffer (current-buffer))))))
4529 (defun message-output (filename)
4530 "Append this article to Unix/babyl mail file FILENAME."
4531 (if (and (file-readable-p filename)
4532 (mail-file-babyl-p filename))
4533 (gnus-output-to-rmail filename t)
4534 (gnus-output-to-mail filename t)))
4536 (defun message-cleanup-headers ()
4537 "Do various automatic cleanups of the headers."
4538 ;; Remove empty lines in the header.
4539 (save-restriction
4540 (message-narrow-to-headers)
4541 ;; Remove blank lines.
4542 (while (re-search-forward "^[ \t]*\n" nil t)
4543 (replace-match "" t t))
4545 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4546 ;; spaces to comma and eliminate spaces around commas. Eliminate
4547 ;; embedded line breaks.
4548 (goto-char (point-min))
4549 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4550 (save-restriction
4551 (narrow-to-region
4552 (point)
4553 (if (re-search-forward "^[^ \t]" nil t)
4554 (match-beginning 0)
4555 (forward-line 1)
4556 (point)))
4557 (goto-char (point-min))
4558 (while (re-search-forward "\n[ \t]+" nil t)
4559 (replace-match " " t t)) ;No line breaks (too confusing)
4560 (goto-char (point-min))
4561 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4562 (replace-match "," t t))
4563 (goto-char (point-min))
4564 ;; Remove trailing commas.
4565 (when (re-search-forward ",+$" nil t)
4566 (replace-match "" t t))))))
4568 (eval-when-compile (require 'parse-time))
4569 (defun message-make-date (&optional now)
4570 "Make a valid data header.
4571 If NOW, use that time instead."
4572 (require 'parse-time)
4573 (let* ((now (or now (current-time)))
4574 (zone (nth 8 (decode-time now)))
4575 (sign "+"))
4576 (when (< zone 0)
4577 (setq sign "-")
4578 (setq zone (- zone)))
4579 (concat
4580 ;; The day name of the %a spec is locale-specific. Pfff.
4581 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4582 parse-time-weekdays))))
4583 (format-time-string "%d" now)
4584 ;; The month name of the %b spec is locale-specific. Pfff.
4585 (format " %s "
4586 (capitalize (car (rassoc (nth 4 (decode-time now))
4587 parse-time-months))))
4588 (format-time-string "%Y %H:%M:%S " now)
4589 ;; We do all of this because XEmacs doesn't have the %z spec.
4590 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4592 (defun message-make-message-id ()
4593 "Make a unique Message-ID."
4594 (concat "<" (message-unique-id)
4595 (let ((psubject (save-excursion (message-fetch-field "subject")))
4596 (psupersedes
4597 (save-excursion (message-fetch-field "supersedes"))))
4598 (if (or
4599 (and message-reply-headers
4600 (mail-header-references message-reply-headers)
4601 (mail-header-subject message-reply-headers)
4602 psubject
4603 (not (string=
4604 (message-strip-subject-re
4605 (mail-header-subject message-reply-headers))
4606 (message-strip-subject-re psubject))))
4607 (and psupersedes
4608 (string-match "_-_@" psupersedes)))
4609 "_-_" ""))
4610 "@" (message-make-fqdn) ">"))
4612 (defvar message-unique-id-char nil)
4614 ;; If you ever change this function, make sure the new version
4615 ;; cannot generate IDs that the old version could.
4616 ;; You might for example insert a "." somewhere (not next to another dot
4617 ;; or string boundary), or modify the "fsf" string.
4618 (defun message-unique-id ()
4619 ;; Don't use microseconds from (current-time), they may be unsupported.
4620 ;; Instead we use this randomly inited counter.
4621 (setq message-unique-id-char
4622 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4623 ;; (current-time) returns 16-bit ints,
4624 ;; and 2^16*25 just fits into 4 digits i base 36.
4625 (* 25 25)))
4626 (let ((tm (current-time)))
4627 (concat
4628 (if (memq system-type '(ms-dos emx vax-vms))
4629 (let ((user (downcase (user-login-name))))
4630 (while (string-match "[^a-z0-9_]" user)
4631 (aset user (match-beginning 0) ?_))
4632 user)
4633 (message-number-base36 (user-uid) -1))
4634 (message-number-base36 (+ (car tm)
4635 (lsh (% message-unique-id-char 25) 16)) 4)
4636 (message-number-base36 (+ (nth 1 tm)
4637 (lsh (/ message-unique-id-char 25) 16)) 4)
4638 ;; Append a given name, because while the generated ID is unique
4639 ;; to this newsreader, other newsreaders might otherwise generate
4640 ;; the same ID via another algorithm.
4641 ".fsf")))
4643 (defun message-number-base36 (num len)
4644 (if (if (< len 0)
4645 (<= num 0)
4646 (= len 0))
4648 (concat (message-number-base36 (/ num 36) (1- len))
4649 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4650 (% num 36))))))
4652 (defun message-make-organization ()
4653 "Make an Organization header."
4654 (let* ((organization
4655 (when message-user-organization
4656 (if (functionp message-user-organization)
4657 (funcall message-user-organization)
4658 message-user-organization))))
4659 (with-temp-buffer
4660 (mm-enable-multibyte)
4661 (cond ((stringp organization)
4662 (insert organization))
4663 ((and (eq t organization)
4664 message-user-organization-file
4665 (file-exists-p message-user-organization-file))
4666 (insert-file-contents message-user-organization-file)))
4667 (goto-char (point-min))
4668 (while (re-search-forward "[\t\n]+" nil t)
4669 (replace-match "" t t))
4670 (unless (zerop (buffer-size))
4671 (buffer-string)))))
4673 (defun message-make-lines ()
4674 "Count the number of lines and return numeric string."
4675 (save-excursion
4676 (save-restriction
4677 (widen)
4678 (message-goto-body)
4679 (int-to-string (count-lines (point) (point-max))))))
4681 (defun message-make-references ()
4682 "Return the References header for this message."
4683 (when message-reply-headers
4684 (let ((message-id (mail-header-message-id message-reply-headers))
4685 (references (mail-header-references message-reply-headers))
4686 new-references)
4687 (if (or references message-id)
4688 (concat (or references "") (and references " ")
4689 (or message-id ""))
4690 nil))))
4692 (defun message-make-in-reply-to ()
4693 "Return the In-Reply-To header for this message."
4694 (when message-reply-headers
4695 (let ((from (mail-header-from message-reply-headers))
4696 (date (mail-header-date message-reply-headers))
4697 (msg-id (mail-header-message-id message-reply-headers)))
4698 (when from
4699 (let ((name (mail-extract-address-components from)))
4700 (concat msg-id (if msg-id " (")
4701 (or (car name)
4702 (nth 1 name))
4703 "'s message of \""
4704 (if (or (not date) (string= date ""))
4705 "(unknown date)" date)
4706 "\"" (if msg-id ")")))))))
4708 (defun message-make-distribution ()
4709 "Make a Distribution header."
4710 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4711 (cond ((functionp message-distribution-function)
4712 (funcall message-distribution-function))
4713 (t orig-distribution))))
4715 (defun message-make-expires ()
4716 "Return an Expires header based on `message-expires'."
4717 (let ((current (current-time))
4718 (future (* 1.0 message-expires 60 60 24)))
4719 ;; Add the future to current.
4720 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4721 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4722 (message-make-date current)))
4724 (defun message-make-path ()
4725 "Return uucp path."
4726 (let ((login-name (user-login-name)))
4727 (cond ((null message-user-path)
4728 (concat (system-name) "!" login-name))
4729 ((stringp message-user-path)
4730 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4731 (concat message-user-path "!" login-name))
4732 (t login-name))))
4734 (defun message-make-from ()
4735 "Make a From header."
4736 (let* ((style message-from-style)
4737 (login (message-make-address))
4738 (fullname
4739 (or (and (boundp 'user-full-name)
4740 user-full-name)
4741 (user-full-name))))
4742 (when (string= fullname "&")
4743 (setq fullname (user-login-name)))
4744 (with-temp-buffer
4745 (mm-enable-multibyte)
4746 (cond
4747 ((or (null style)
4748 (equal fullname ""))
4749 (insert login))
4750 ((or (eq style 'angles)
4751 (and (not (eq style 'parens))
4752 ;; Use angles if no quoting is needed, or if parens would
4753 ;; need quoting too.
4754 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4755 (let ((tmp (concat fullname nil)))
4756 (while (string-match "([^()]*)" tmp)
4757 (aset tmp (match-beginning 0) ?-)
4758 (aset tmp (1- (match-end 0)) ?-))
4759 (string-match "[\\()]" tmp)))))
4760 (insert fullname)
4761 (goto-char (point-min))
4762 ;; Look for a character that cannot appear unquoted
4763 ;; according to RFC 822.
4764 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4765 ;; Quote fullname, escaping specials.
4766 (goto-char (point-min))
4767 (insert "\"")
4768 (while (re-search-forward "[\"\\]" nil 1)
4769 (replace-match "\\\\\\&" t))
4770 (insert "\""))
4771 (insert " <" login ">"))
4772 (t ; 'parens or default
4773 (insert login " (")
4774 (let ((fullname-start (point)))
4775 (insert fullname)
4776 (goto-char fullname-start)
4777 ;; RFC 822 says \ and nonmatching parentheses
4778 ;; must be escaped in comments.
4779 ;; Escape every instance of ()\ ...
4780 (while (re-search-forward "[()\\]" nil 1)
4781 (replace-match "\\\\\\&" t))
4782 ;; ... then undo escaping of matching parentheses,
4783 ;; including matching nested parentheses.
4784 (goto-char fullname-start)
4785 (while (re-search-forward
4786 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4787 nil 1)
4788 (replace-match "\\1(\\3)" t)
4789 (goto-char fullname-start)))
4790 (insert ")")))
4791 (buffer-string))))
4793 (defun message-make-sender ()
4794 "Return the \"real\" user address.
4795 This function tries to ignore all user modifications, and
4796 give as trustworthy answer as possible."
4797 (concat (user-login-name) "@" (system-name)))
4799 (defun message-make-address ()
4800 "Make the address of the user."
4801 (or (message-user-mail-address)
4802 (concat (user-login-name) "@" (message-make-domain))))
4804 (defun message-user-mail-address ()
4805 "Return the pertinent part of `user-mail-address'."
4806 (when (and user-mail-address
4807 (string-match "@.*\\." user-mail-address))
4808 (if (string-match " " user-mail-address)
4809 (nth 1 (mail-extract-address-components user-mail-address))
4810 user-mail-address)))
4812 (defun message-sendmail-envelope-from ()
4813 "Return the envelope from."
4814 (cond ((eq message-sendmail-envelope-from 'header)
4815 (nth 1 (mail-extract-address-components
4816 (message-fetch-field "from"))))
4817 ((stringp message-sendmail-envelope-from)
4818 message-sendmail-envelope-from)
4820 (message-make-address))))
4822 (defun message-make-fqdn ()
4823 "Return user's fully qualified domain name."
4824 (let* ((system-name (system-name))
4825 (user-mail (message-user-mail-address))
4826 (user-domain
4827 (if (and user-mail
4828 (string-match "@\\(.*\\)\\'" user-mail))
4829 (match-string 1 user-mail)))
4830 (case-fold-search t))
4831 (cond
4832 ((and message-user-fqdn
4833 (stringp message-user-fqdn)
4834 (string-match message-valid-fqdn-regexp message-user-fqdn)
4835 (not (string-match message-bogus-system-names message-user-fqdn)))
4836 message-user-fqdn)
4837 ;; `message-user-fqdn' seems to be valid
4838 ((and (string-match message-valid-fqdn-regexp system-name)
4839 (not (string-match message-bogus-system-names system-name)))
4840 ;; `system-name' returned the right result.
4841 system-name)
4842 ;; Try `mail-host-address'.
4843 ((and (boundp 'mail-host-address)
4844 (stringp mail-host-address)
4845 (string-match message-valid-fqdn-regexp mail-host-address)
4846 (not (string-match message-bogus-system-names mail-host-address)))
4847 mail-host-address)
4848 ;; We try `user-mail-address' as a backup.
4849 ((and user-domain
4850 (stringp user-domain)
4851 (string-match message-valid-fqdn-regexp user-domain)
4852 (not (string-match message-bogus-system-names user-domain)))
4853 user-domain)
4854 ;; Default to this bogus thing.
4856 (concat system-name
4857 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4859 (defun message-make-host-name ()
4860 "Return the name of the host."
4861 (let ((fqdn (message-make-fqdn)))
4862 (string-match "^[^.]+\\." fqdn)
4863 (substring fqdn 0 (1- (match-end 0)))))
4865 (defun message-make-domain ()
4866 "Return the domain name."
4867 (or mail-host-address
4868 (message-make-fqdn)))
4870 (defun message-to-list-only ()
4871 "Send a message to the list only.
4872 Remove all addresses but the list address from To and Cc headers."
4873 (interactive)
4874 (let ((listaddr (message-make-mail-followup-to t)))
4875 (when listaddr
4876 (save-excursion
4877 (message-remove-header "to")
4878 (message-remove-header "cc")
4879 (message-position-on-field "To" "X-Draft-From")
4880 (insert listaddr)))))
4882 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4883 "Return the Mail-Followup-To header.
4884 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4885 subscribed address (and not the additional To and Cc header contents)."
4886 (let* ((case-fold-search t)
4887 (to (message-fetch-field "To"))
4888 (cc (message-fetch-field "cc"))
4889 (msg-recipients (concat to (and to cc ", ") cc))
4890 (recipients
4891 (mapcar 'mail-strip-quoted-names
4892 (message-tokenize-header msg-recipients)))
4893 (file-regexps
4894 (if message-subscribed-address-file
4895 (let (begin end item re)
4896 (save-excursion
4897 (with-temp-buffer
4898 (insert-file-contents message-subscribed-address-file)
4899 (while (not (eobp))
4900 (setq begin (point))
4901 (forward-line 1)
4902 (setq end (point))
4903 (if (bolp) (setq end (1- end)))
4904 (setq item (regexp-quote (buffer-substring begin end)))
4905 (if re (setq re (concat re "\\|" item))
4906 (setq re (concat "\\`\\(" item))))
4907 (and re (list (concat re "\\)\\'"))))))))
4908 (mft-regexps (apply 'append message-subscribed-regexps
4909 (mapcar 'regexp-quote
4910 message-subscribed-addresses)
4911 file-regexps
4912 (mapcar 'funcall
4913 message-subscribed-address-functions))))
4914 (save-match-data
4915 (let ((subscribed-lists nil)
4916 (list
4917 (loop for recipient in recipients
4918 when (loop for regexp in mft-regexps
4919 when (string-match regexp recipient) return t)
4920 return recipient)))
4921 (when list
4922 (if only-show-subscribed
4923 list
4924 msg-recipients))))))
4926 (defun message-idna-to-ascii-rhs-1 (header)
4927 "Interactively potentially IDNA encode domain names in HEADER."
4928 (let ((field (message-fetch-field header))
4929 rhs ace address)
4930 (when field
4931 (dolist (address (mail-header-parse-addresses field))
4932 (setq address (car address)
4933 rhs (downcase (or (cadr (split-string address "@")) ""))
4934 ace (downcase (idna-to-ascii rhs)))
4935 (when (and (not (equal rhs ace))
4936 (or (not (eq message-use-idna 'ask))
4937 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
4938 (goto-char (point-min))
4939 (while (re-search-forward (concat "^" header ":") nil t)
4940 (message-narrow-to-field)
4941 (while (search-forward (concat "@" rhs) nil t)
4942 (replace-match (concat "@" ace) t t))
4943 (goto-char (point-max))
4944 (widen)))))))
4946 (defun message-idna-to-ascii-rhs ()
4947 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4948 See `message-idna-encode'."
4949 (interactive)
4950 (when message-use-idna
4951 (save-excursion
4952 (save-restriction
4953 (message-narrow-to-head)
4954 (message-idna-to-ascii-rhs-1 "From")
4955 (message-idna-to-ascii-rhs-1 "To")
4956 (message-idna-to-ascii-rhs-1 "Cc")))))
4958 (defun message-generate-headers (headers)
4959 "Prepare article HEADERS.
4960 Headers already prepared in the buffer are not modified."
4961 (setq headers (append headers message-required-headers))
4962 (save-restriction
4963 (message-narrow-to-headers)
4964 (let* ((Date (message-make-date))
4965 (Message-ID (message-make-message-id))
4966 (Organization (message-make-organization))
4967 (From (message-make-from))
4968 (Path (message-make-path))
4969 (Subject nil)
4970 (Newsgroups nil)
4971 (In-Reply-To (message-make-in-reply-to))
4972 (References (message-make-references))
4973 (To nil)
4974 (Distribution (message-make-distribution))
4975 (Lines (message-make-lines))
4976 (User-Agent message-newsreader)
4977 (Expires (message-make-expires))
4978 (case-fold-search t)
4979 (optionalp nil)
4980 header value elem header-string)
4981 ;; First we remove any old generated headers.
4982 (let ((headers message-deletable-headers))
4983 (unless (buffer-modified-p)
4984 (setq headers (delq 'Message-ID (copy-sequence headers))))
4985 (while headers
4986 (goto-char (point-min))
4987 (and (re-search-forward
4988 (concat "^" (symbol-name (car headers)) ": *") nil t)
4989 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4990 (message-delete-line))
4991 (pop headers)))
4992 ;; Go through all the required headers and see if they are in the
4993 ;; articles already. If they are not, or are empty, they are
4994 ;; inserted automatically - except for Subject, Newsgroups and
4995 ;; Distribution.
4996 (while headers
4997 (goto-char (point-min))
4998 (setq elem (pop headers))
4999 (if (consp elem)
5000 (if (eq (car elem) 'optional)
5001 (setq header (cdr elem)
5002 optionalp t)
5003 (setq header (car elem)))
5004 (setq header elem))
5005 (setq header-string (if (stringp header)
5006 header
5007 (symbol-name header)))
5008 (when (or (not (re-search-forward
5009 (concat "^"
5010 (regexp-quote (downcase header-string))
5011 ":")
5012 nil t))
5013 (progn
5014 ;; The header was found. We insert a space after the
5015 ;; colon, if there is none.
5016 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5017 ;; Find out whether the header is empty.
5018 (looking-at "[ \t]*\n[^ \t]")))
5019 ;; So we find out what value we should insert.
5020 (setq value
5021 (cond
5022 ((and (consp elem)
5023 (eq (car elem) 'optional)
5024 (not (member header-string message-inserted-headers)))
5025 ;; This is an optional header. If the cdr of this
5026 ;; is something that is nil, then we do not insert
5027 ;; this header.
5028 (setq header (cdr elem))
5029 (or (and (functionp (cdr elem))
5030 (funcall (cdr elem)))
5031 (and (boundp (cdr elem))
5032 (symbol-value (cdr elem)))))
5033 ((consp elem)
5034 ;; The element is a cons. Either the cdr is a
5035 ;; string to be inserted verbatim, or it is a
5036 ;; function, and we insert the value returned from
5037 ;; this function.
5038 (or (and (stringp (cdr elem))
5039 (cdr elem))
5040 (and (functionp (cdr elem))
5041 (funcall (cdr elem)))))
5042 ((and (boundp header)
5043 (symbol-value header))
5044 ;; The element is a symbol. We insert the value
5045 ;; of this symbol, if any.
5046 (symbol-value header))
5047 ((not (message-check-element header))
5048 ;; We couldn't generate a value for this header,
5049 ;; so we just ask the user.
5050 (read-from-minibuffer
5051 (format "Empty header for %s; enter value: " header)))))
5052 ;; Finally insert the header.
5053 (when (and value
5054 (not (equal value "")))
5055 (save-excursion
5056 (if (bolp)
5057 (progn
5058 ;; This header didn't exist, so we insert it.
5059 (goto-char (point-max))
5060 (let ((formatter
5061 (cdr (assq header message-header-format-alist))))
5062 (if formatter
5063 (funcall formatter header value)
5064 (insert header-string ": " value))
5065 ;; We check whether the value was ended by a
5066 ;; newline. If now, we insert one.
5067 (unless (bolp)
5068 (insert "\n"))
5069 (forward-line -1)))
5070 ;; The value of this header was empty, so we clear
5071 ;; totally and insert the new value.
5072 (delete-region (point) (gnus-point-at-eol))
5073 ;; If the header is optional, and the header was
5074 ;; empty, we con't insert it anyway.
5075 (unless optionalp
5076 (push header-string message-inserted-headers)
5077 (insert value)))
5078 ;; Add the deletable property to the headers that require it.
5079 (and (memq header message-deletable-headers)
5080 (progn (beginning-of-line) (looking-at "[^:]+: "))
5081 (add-text-properties
5082 (point) (match-end 0)
5083 '(message-deletable t face italic) (current-buffer)))))))
5084 ;; Insert new Sender if the From is strange.
5085 (let ((from (message-fetch-field "from"))
5086 (sender (message-fetch-field "sender"))
5087 (secure-sender (message-make-sender)))
5088 (when (and from
5089 (not (message-check-element 'sender))
5090 (not (string=
5091 (downcase
5092 (cadr (mail-extract-address-components from)))
5093 (downcase secure-sender)))
5094 (or (null sender)
5095 (not
5096 (string=
5097 (downcase
5098 (cadr (mail-extract-address-components sender)))
5099 (downcase secure-sender)))))
5100 (goto-char (point-min))
5101 ;; Rename any old Sender headers to Original-Sender.
5102 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5103 (beginning-of-line)
5104 (insert "Original-")
5105 (beginning-of-line))
5106 (when (or (message-news-p)
5107 (string-match "@.+\\.." secure-sender))
5108 (insert "Sender: " secure-sender "\n"))))
5109 ;; Check for IDNA
5110 (message-idna-to-ascii-rhs))))
5112 (defun message-insert-courtesy-copy ()
5113 "Insert a courtesy message in mail copies of combined messages."
5114 (let (newsgroups)
5115 (save-excursion
5116 (save-restriction
5117 (message-narrow-to-headers)
5118 (when (setq newsgroups (message-fetch-field "newsgroups"))
5119 (goto-char (point-max))
5120 (insert "Posted-To: " newsgroups "\n")))
5121 (forward-line 1)
5122 (when message-courtesy-message
5123 (cond
5124 ((string-match "%s" message-courtesy-message)
5125 (insert (format message-courtesy-message newsgroups)))
5127 (insert message-courtesy-message)))))))
5130 ;;; Setting up a message buffer
5133 (defun message-fill-address (header value)
5134 (save-restriction
5135 (narrow-to-region (point) (point))
5136 (insert (capitalize (symbol-name header))
5137 ": "
5138 (if (consp value) (car value) value)
5139 "\n")
5140 (narrow-to-region (point-min) (1- (point-max)))
5141 (let (quoted last)
5142 (goto-char (point-min))
5143 (while (not (eobp))
5144 (skip-chars-forward "^,\"" (point-max))
5145 (if (or (eq (char-after) ?,)
5146 (eobp))
5147 (when (not quoted)
5148 (if (and (> (current-column) 78)
5149 last)
5150 (progn
5151 (save-excursion
5152 (goto-char last)
5153 (insert "\n\t"))
5154 (setq last (1+ (point))))
5155 (setq last (1+ (point)))))
5156 (setq quoted (not quoted)))
5157 (unless (eobp)
5158 (forward-char 1))))
5159 (goto-char (point-max))
5160 (widen)
5161 (forward-line 1)))
5163 (defun message-split-line ()
5164 "Split current line, moving portion beyond point vertically down.
5165 If the current line has `message-yank-prefix', insert it on the new line."
5166 (interactive "*")
5167 (condition-case nil
5168 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5169 (error
5170 (split-line))))
5172 (defun message-fill-header (header value)
5173 (let ((begin (point))
5174 (fill-column 78)
5175 (fill-prefix "\t"))
5176 (insert (capitalize (symbol-name header))
5177 ": "
5178 (if (consp value) (car value) value)
5179 "\n")
5180 (save-restriction
5181 (narrow-to-region begin (point))
5182 (fill-region-as-paragraph begin (point))
5183 ;; Tapdance around looong Message-IDs.
5184 (forward-line -1)
5185 (when (looking-at "[ \t]*$")
5186 (message-delete-line))
5187 (goto-char begin)
5188 (re-search-forward ":" nil t)
5189 (when (looking-at "\n[ \t]+")
5190 (replace-match " " t t))
5191 (goto-char (point-max)))))
5193 (defun message-shorten-1 (list cut surplus)
5194 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5195 (setcdr (nthcdr (- cut 2) list)
5196 (nthcdr (+ (- cut 2) surplus 1) list)))
5198 (defun message-shorten-references (header references)
5199 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5200 If folding is disallowed, also check that the REFERENCES are less
5201 than 988 characters long, and if they are not, trim them until they are."
5202 (let ((maxcount 21)
5203 (count 0)
5204 (cut 2)
5205 refs)
5206 (with-temp-buffer
5207 (insert references)
5208 (goto-char (point-min))
5209 ;; Cons a list of valid references.
5210 (while (re-search-forward "<[^>]+>" nil t)
5211 (push (match-string 0) refs))
5212 (setq refs (nreverse refs)
5213 count (length refs)))
5215 ;; If the list has more than MAXCOUNT elements, trim it by
5216 ;; removing the CUTth element and the required number of
5217 ;; elements that follow.
5218 (when (> count maxcount)
5219 (let ((surplus (- count maxcount)))
5220 (message-shorten-1 refs cut surplus)
5221 (decf count surplus)))
5223 ;; If folding is disallowed, make sure the total length (including
5224 ;; the spaces between) will be less than MAXSIZE characters.
5226 ;; Only disallow folding for News messages. At this point the headers
5227 ;; have not been generated, thus we use message-this-is-news directly.
5228 (when (and message-this-is-news message-cater-to-broken-inn)
5229 (let ((maxsize 988)
5230 (totalsize (+ (apply #'+ (mapcar #'length refs))
5231 (1- count)))
5232 (surplus 0)
5233 (ptr (nthcdr (1- cut) refs)))
5234 ;; Decide how many elements to cut off...
5235 (while (> totalsize maxsize)
5236 (decf totalsize (1+ (length (car ptr))))
5237 (incf surplus)
5238 (setq ptr (cdr ptr)))
5239 ;; ...and do it.
5240 (when (> surplus 0)
5241 (message-shorten-1 refs cut surplus))))
5243 ;; Finally, collect the references back into a string and insert
5244 ;; it into the buffer.
5245 (let ((refstring (mapconcat #'identity refs " ")))
5246 (if (and message-this-is-news message-cater-to-broken-inn)
5247 (insert (capitalize (symbol-name header)) ": "
5248 refstring "\n")
5249 (message-fill-header header refstring)))))
5251 (defun message-position-point ()
5252 "Move point to where the user probably wants to find it."
5253 (message-narrow-to-headers)
5254 (cond
5255 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5256 (search-backward ":" )
5257 (widen)
5258 (forward-char 1)
5259 (if (eq (char-after) ? )
5260 (forward-char 1)
5261 (insert " ")))
5263 (goto-char (point-max))
5264 (widen)
5265 (forward-line 1)
5266 (unless (looking-at "$")
5267 (forward-line 2)))
5268 (sit-for 0)))
5270 (defcustom message-beginning-of-line t
5271 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5272 goes to beginning of header values."
5273 :version "22.1"
5274 :group 'message-buffers
5275 :link '(custom-manual "(message)Movement")
5276 :type 'boolean)
5278 (defun message-beginning-of-line (&optional n)
5279 "Move point to beginning of header value or to beginning of line.
5280 The prefix argument N is passed directly to `beginning-of-line'.
5282 This command is identical to `beginning-of-line' if point is
5283 outside the message header or if the option `message-beginning-of-line'
5284 is nil.
5286 If point is in the message header and on a (non-continued) header
5287 line, move point to the beginning of the header value or the beginning of line,
5288 whichever is closer. If point is already at beginning of line, move point to
5289 beginning of header value. Therefore, repeated calls will toggle point
5290 between beginning of field and beginning of line."
5291 (interactive "p")
5292 (let ((zrs 'zmacs-region-stays))
5293 (when (and (interactive-p) (boundp zrs))
5294 (set zrs t)))
5295 (if (and message-beginning-of-line
5296 (message-point-in-header-p))
5297 (let* ((here (point))
5298 (bol (progn (beginning-of-line n) (point)))
5299 (eol (gnus-point-at-eol))
5300 (eoh (re-search-forward ": *" eol t)))
5301 (goto-char
5302 (if (and eoh (or (< eoh here) (= bol here)))
5303 eoh bol)))
5304 (beginning-of-line n)))
5306 (defun message-buffer-name (type &optional to group)
5307 "Return a new (unique) buffer name based on TYPE and TO."
5308 (cond
5309 ;; Generate a new buffer name The Message Way.
5310 ((eq message-generate-new-buffers 'unique)
5311 (generate-new-buffer-name
5312 (concat "*" type
5313 (if to
5314 (concat " to "
5315 (or (car (mail-extract-address-components to))
5316 to) "")
5318 (if (and group (not (string= group ""))) (concat " on " group) "")
5319 "*")))
5320 ;; Check whether `message-generate-new-buffers' is a function,
5321 ;; and if so, call it.
5322 ((functionp message-generate-new-buffers)
5323 (funcall message-generate-new-buffers type to group))
5324 ((eq message-generate-new-buffers 'unsent)
5325 (generate-new-buffer-name
5326 (concat "*unsent " type
5327 (if to
5328 (concat " to "
5329 (or (car (mail-extract-address-components to))
5330 to) "")
5332 (if (and group (not (string= group ""))) (concat " on " group) "")
5333 "*")))
5334 ;; Use standard name.
5336 (format "*%s message*" type))))
5338 (defun message-pop-to-buffer (name)
5339 "Pop to buffer NAME, and warn if it already exists and is modified."
5340 (let ((buffer (get-buffer name)))
5341 (if (and buffer
5342 (buffer-name buffer))
5343 (progn
5344 (set-buffer (pop-to-buffer buffer))
5345 (when (and (buffer-modified-p)
5346 (not (y-or-n-p
5347 "Message already being composed; erase? ")))
5348 (error "Message being composed")))
5349 (set-buffer (pop-to-buffer name)))
5350 (erase-buffer)
5351 (message-mode)))
5353 (defun message-do-send-housekeeping ()
5354 "Kill old message buffers."
5355 ;; We might have sent this buffer already. Delete it from the
5356 ;; list of buffers.
5357 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5358 (while (and message-max-buffers
5359 message-buffer-list
5360 (>= (length message-buffer-list) message-max-buffers))
5361 ;; Kill the oldest buffer -- unless it has been changed.
5362 (let ((buffer (pop message-buffer-list)))
5363 (when (and (buffer-name buffer)
5364 (not (buffer-modified-p buffer)))
5365 (kill-buffer buffer))))
5366 ;; Rename the buffer.
5367 (if message-send-rename-function
5368 (funcall message-send-rename-function)
5369 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5370 (when (string-match
5371 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5372 (buffer-name))
5373 (let ((name (match-string 2 (buffer-name)))
5374 to group)
5375 (if (not (or (null name)
5376 (string-equal name "mail")
5377 (string-equal name "posting")))
5378 (setq name (concat "*sent " name "*"))
5379 (message-narrow-to-headers)
5380 (setq to (message-fetch-field "to"))
5381 (setq group (message-fetch-field "newsgroups"))
5382 (widen)
5383 (setq name
5384 (cond
5385 (to (concat "*sent mail to "
5386 (or (car (mail-extract-address-components to))
5387 to) "*"))
5388 ((and group (not (string= group "")))
5389 (concat "*sent posting on " group "*"))
5390 (t "*sent mail*"))))
5391 (unless (string-equal name (buffer-name))
5392 (rename-buffer name t)))))
5393 ;; Push the current buffer onto the list.
5394 (when message-max-buffers
5395 (setq message-buffer-list
5396 (nconc message-buffer-list (list (current-buffer))))))
5398 (defun message-mail-user-agent ()
5399 (let ((mua (cond
5400 ((not message-mail-user-agent) nil)
5401 ((eq message-mail-user-agent t) mail-user-agent)
5402 (t message-mail-user-agent))))
5403 (if (memq mua '(message-user-agent gnus-user-agent))
5405 mua)))
5407 (defun message-setup (headers &optional replybuffer actions switch-function)
5408 (let ((mua (message-mail-user-agent))
5409 subject to field yank-action)
5410 (if (not (and message-this-is-mail mua))
5411 (message-setup-1 headers replybuffer actions)
5412 (if replybuffer
5413 (setq yank-action (list 'insert-buffer replybuffer)))
5414 (setq headers (copy-sequence headers))
5415 (setq field (assq 'Subject headers))
5416 (when field
5417 (setq subject (cdr field))
5418 (setq headers (delq field headers)))
5419 (setq field (assq 'To headers))
5420 (when field
5421 (setq to (cdr field))
5422 (setq headers (delq field headers)))
5423 (let ((mail-user-agent mua))
5424 (compose-mail to subject
5425 (mapcar (lambda (item)
5426 (cons
5427 (format "%s" (car item))
5428 (cdr item)))
5429 headers)
5430 nil switch-function yank-action actions)))))
5432 (defun message-headers-to-generate (headers included-headers excluded-headers)
5433 "Return a list that includes all headers from HEADERS.
5434 If INCLUDED-HEADERS is a list, just include those headers. If if is
5435 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5436 are not included."
5437 (let ((result nil)
5438 header-name)
5439 (dolist (header headers)
5440 (setq header-name (cond
5441 ((and (consp header)
5442 (eq (car header) 'optional))
5443 ;; On the form (optional . Header)
5444 (cdr header))
5445 ((consp header)
5446 ;; On the form (Header . function)
5447 (car header))
5449 ;; Just a Header.
5450 header)))
5451 (when (and (not (memq header-name excluded-headers))
5452 (or (eq included-headers t)
5453 (memq header-name included-headers)))
5454 (push header result)))
5455 (nreverse result)))
5457 (defun message-setup-1 (headers &optional replybuffer actions)
5458 (dolist (action actions)
5459 (condition-case nil
5460 (add-to-list 'message-send-actions
5461 `(apply ',(car action) ',(cdr action)))))
5462 (setq message-reply-buffer replybuffer)
5463 (goto-char (point-min))
5464 ;; Insert all the headers.
5465 (mail-header-format
5466 (let ((h headers)
5467 (alist message-header-format-alist))
5468 (while h
5469 (unless (assq (caar h) message-header-format-alist)
5470 (push (list (caar h)) alist))
5471 (pop h))
5472 alist)
5473 headers)
5474 (delete-region (point) (progn (forward-line -1) (point)))
5475 (when message-default-headers
5476 (insert message-default-headers)
5477 (or (bolp) (insert ?\n)))
5478 (put-text-property
5479 (point)
5480 (progn
5481 (insert mail-header-separator "\n")
5482 (1- (point)))
5483 'read-only nil)
5484 (forward-line -1)
5485 (when (message-news-p)
5486 (when message-default-news-headers
5487 (insert message-default-news-headers)
5488 (or (bolp) (insert ?\n)))
5489 (when message-generate-headers-first
5490 (message-generate-headers
5491 (message-headers-to-generate
5492 (append message-required-news-headers
5493 message-required-headers)
5494 message-generate-headers-first
5495 '(Lines Subject)))))
5496 (when (message-mail-p)
5497 (when message-default-mail-headers
5498 (insert message-default-mail-headers)
5499 (or (bolp) (insert ?\n)))
5500 (save-restriction
5501 (message-narrow-to-headers)
5502 (if message-alternative-emails
5503 (message-use-alternative-email-as-from)))
5504 (when message-generate-headers-first
5505 (message-generate-headers
5506 (message-headers-to-generate
5507 (append message-required-mail-headers
5508 message-required-headers)
5509 message-generate-headers-first
5510 '(Lines Subject)))))
5511 (run-hooks 'message-signature-setup-hook)
5512 (message-insert-signature)
5513 (save-restriction
5514 (message-narrow-to-headers)
5515 (run-hooks 'message-header-setup-hook))
5516 (set-buffer-modified-p nil)
5517 (setq buffer-undo-list nil)
5518 (run-hooks 'message-setup-hook)
5519 (message-position-point)
5520 (undo-boundary))
5522 (defun message-set-auto-save-file-name ()
5523 "Associate the message buffer with a file in the drafts directory."
5524 (when message-auto-save-directory
5525 (unless (file-directory-p
5526 (directory-file-name message-auto-save-directory))
5527 (make-directory message-auto-save-directory t))
5528 (if (gnus-alive-p)
5529 (setq message-draft-article
5530 (nndraft-request-associate-buffer "drafts"))
5531 (setq buffer-file-name (expand-file-name
5532 (if (memq system-type
5533 '(ms-dos ms-windows windows-nt
5534 cygwin cygwin32 win32 w32
5535 mswindows))
5536 "message"
5537 "*message*")
5538 message-auto-save-directory))
5539 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5540 (clear-visited-file-modtime)
5541 (setq buffer-file-coding-system message-draft-coding-system)))
5543 (defun message-disassociate-draft ()
5544 "Disassociate the message buffer from the drafts directory."
5545 (when message-draft-article
5546 (nndraft-request-expire-articles
5547 (list message-draft-article) "drafts" nil t)))
5549 (defun message-insert-headers ()
5550 "Generate the headers for the article."
5551 (interactive)
5552 (save-excursion
5553 (save-restriction
5554 (message-narrow-to-headers)
5555 (when (message-news-p)
5556 (message-generate-headers
5557 (delq 'Lines
5558 (delq 'Subject
5559 (copy-sequence message-required-news-headers)))))
5560 (when (message-mail-p)
5561 (message-generate-headers
5562 (delq 'Lines
5563 (delq 'Subject
5564 (copy-sequence message-required-mail-headers))))))))
5569 ;;; Commands for interfacing with message
5572 ;;;###autoload
5573 (defun message-mail (&optional to subject
5574 other-headers continue switch-function
5575 yank-action send-actions)
5576 "Start editing a mail message to be sent.
5577 OTHER-HEADERS is an alist of header/value pairs."
5578 (interactive)
5579 (let ((message-this-is-mail t) replybuffer)
5580 (unless (message-mail-user-agent)
5581 (message-pop-to-buffer (message-buffer-name "mail" to)))
5582 ;; FIXME: message-mail should do something if YANK-ACTION is not
5583 ;; insert-buffer.
5584 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5585 (setq replybuffer (nth 1 yank-action)))
5586 (message-setup
5587 (nconc
5588 `((To . ,(or to "")) (Subject . ,(or subject "")))
5589 (when other-headers other-headers))
5590 replybuffer send-actions)
5591 ;; FIXME: Should return nil if failure.
5594 ;;;###autoload
5595 (defun message-news (&optional newsgroups subject)
5596 "Start editing a news article to be sent."
5597 (interactive)
5598 (let ((message-this-is-news t))
5599 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5600 (message-setup `((Newsgroups . ,(or newsgroups ""))
5601 (Subject . ,(or subject ""))))))
5603 (defun message-get-reply-headers (wide &optional to-address address-headers)
5604 (let (follow-to mct never-mct to cc author mft recipients)
5605 ;; Find all relevant headers we need.
5606 (save-restriction
5607 (message-narrow-to-headers-or-head)
5608 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5609 ;; message-header-synonyms.
5610 (setq to (or (message-fetch-field "to")
5611 (and (loop for synonym in message-header-synonyms
5612 when (memq 'Original-To synonym)
5613 return t)
5614 (message-fetch-field "original-to")))
5615 cc (message-fetch-field "cc")
5616 mct (message-fetch-field "mail-copies-to")
5617 author (or (message-fetch-field "mail-reply-to")
5618 (message-fetch-field "reply-to")
5619 (message-fetch-field "from")
5621 mft (and message-use-mail-followup-to
5622 (message-fetch-field "mail-followup-to"))))
5624 ;; Handle special values of Mail-Copies-To.
5625 (when mct
5626 (cond ((or (equal (downcase mct) "never")
5627 (equal (downcase mct) "nobody"))
5628 (setq never-mct t)
5629 (setq mct nil))
5630 ((or (equal (downcase mct) "always")
5631 (equal (downcase mct) "poster"))
5632 (setq mct author))))
5634 (save-match-data
5635 ;; Build (textual) list of new recipient addresses.
5636 (cond
5637 ((not wide)
5638 (setq recipients (concat ", " author)))
5639 (address-headers
5640 (dolist (header address-headers)
5641 (let ((value (message-fetch-field header)))
5642 (when value
5643 (setq recipients (concat recipients ", " value))))))
5644 ((and mft
5645 (string-match "[^ \t,]" mft)
5646 (or (not (eq message-use-mail-followup-to 'ask))
5647 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5648 You should normally obey the Mail-Followup-To: header. In this
5649 article, it has the value of
5651 " mft "
5653 which directs your response to " (if (string-match "," mft)
5654 "the specified addresses"
5655 "that address only") ".
5657 Most commonly, Mail-Followup-To is used by a mailing list poster to
5658 express that responses should be sent to just the list, and not the
5659 poster as well.
5661 If a message is posted to several mailing lists, Mail-Followup-To may
5662 also be used to direct the following discussion to one list only,
5663 because discussions that are spread over several lists tend to be
5664 fragmented and very difficult to follow.
5666 Also, some source/announcement lists are not intended for discussion;
5667 responses here are directed to other addresses.
5669 You may customize the variable `message-use-mail-followup-to', if you
5670 want to get rid of this query permanently.")))
5671 (setq recipients (concat ", " mft)))
5672 (to-address
5673 (setq recipients (concat ", " to-address))
5674 ;; If the author explicitly asked for a copy, we don't deny it to them.
5675 (if mct (setq recipients (concat recipients ", " mct))))
5677 (setq recipients (if never-mct "" (concat ", " author)))
5678 (if to (setq recipients (concat recipients ", " to)))
5679 (if cc (setq recipients (concat recipients ", " cc)))
5680 (if mct (setq recipients (concat recipients ", " mct)))))
5681 (if (>= (length recipients) 2)
5682 ;; Strip the leading ", ".
5683 (setq recipients (substring recipients 2)))
5684 ;; Squeeze whitespace.
5685 (while (string-match "[ \t][ \t]+" recipients)
5686 (setq recipients (replace-match " " t t recipients)))
5687 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5688 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5689 (setq recipients (rmail-dont-reply-to recipients)))
5690 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5691 (if (string-equal recipients "")
5692 (setq recipients author))
5693 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5694 (setq recipients
5695 (mapcar
5696 (lambda (addr)
5697 (cons (downcase (mail-strip-quoted-names addr)) addr))
5698 (message-tokenize-header recipients)))
5699 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5700 (let ((s recipients))
5701 (while s
5702 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5704 ;; Remove hierarchical lists that are contained within each other,
5705 ;; if message-hierarchical-addresses is defined.
5706 (when message-hierarchical-addresses
5707 (let ((plain-addrs (mapcar 'car recipients))
5708 subaddrs recip)
5709 (while plain-addrs
5710 (setq subaddrs (assoc (car plain-addrs)
5711 message-hierarchical-addresses)
5712 plain-addrs (cdr plain-addrs))
5713 (when subaddrs
5714 (setq subaddrs (cdr subaddrs))
5715 (while subaddrs
5716 (setq recip (assoc (car subaddrs) recipients)
5717 subaddrs (cdr subaddrs))
5718 (if recip
5719 (setq recipients (delq recip recipients))))))))
5721 ;; Build the header alist. Allow the user to be asked whether
5722 ;; or not to reply to all recipients in a wide reply.
5723 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5724 (when (and recipients
5725 (or (not message-wide-reply-confirm-recipients)
5726 (y-or-n-p "Reply to all recipients? ")))
5727 (setq recipients (mapconcat
5728 (lambda (addr) (cdr addr)) recipients ", "))
5729 (if (string-match "^ +" recipients)
5730 (setq recipients (substring recipients (match-end 0))))
5731 (push (cons 'Cc recipients) follow-to)))
5732 follow-to))
5734 ;;;###autoload
5735 (defun message-reply (&optional to-address wide)
5736 "Start editing a reply to the article in the current buffer."
5737 (interactive)
5738 (require 'gnus-sum) ; for gnus-list-identifiers
5739 (let ((cur (current-buffer))
5740 from subject date reply-to to cc
5741 references message-id follow-to
5742 (inhibit-point-motion-hooks t)
5743 (message-this-is-mail t)
5744 gnus-warning)
5745 (save-restriction
5746 (message-narrow-to-head-1)
5747 ;; Allow customizations to have their say.
5748 (if (not wide)
5749 ;; This is a regular reply.
5750 (when (functionp message-reply-to-function)
5751 (save-excursion
5752 (setq follow-to (funcall message-reply-to-function))))
5753 ;; This is a followup.
5754 (when (functionp message-wide-reply-to-function)
5755 (save-excursion
5756 (setq follow-to
5757 (funcall message-wide-reply-to-function)))))
5758 (setq message-id (message-fetch-field "message-id" t)
5759 references (message-fetch-field "references")
5760 date (message-fetch-field "date")
5761 from (message-fetch-field "from")
5762 subject (or (message-fetch-field "subject") "none"))
5763 (when gnus-list-identifiers
5764 (setq subject (message-strip-list-identifiers subject)))
5765 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5766 (when message-subject-trailing-was-query
5767 (setq subject (message-strip-subject-trailing-was subject)))
5769 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5770 (string-match "<[^>]+>" gnus-warning))
5771 (setq message-id (match-string 0 gnus-warning)))
5773 (unless follow-to
5774 (setq follow-to (message-get-reply-headers wide to-address))))
5776 (unless (message-mail-user-agent)
5777 (message-pop-to-buffer
5778 (message-buffer-name
5779 (if wide "wide reply" "reply") from
5780 (if wide to-address nil))))
5782 (setq message-reply-headers
5783 (vector 0 subject from date message-id references 0 0 ""))
5785 (message-setup
5786 `((Subject . ,subject)
5787 ,@follow-to)
5788 cur)))
5790 ;;;###autoload
5791 (defun message-wide-reply (&optional to-address)
5792 "Make a \"wide\" reply to the message in the current buffer."
5793 (interactive)
5794 (message-reply to-address t))
5796 ;;;###autoload
5797 (defun message-followup (&optional to-newsgroups)
5798 "Follow up to the message in the current buffer.
5799 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5800 (interactive)
5801 (require 'gnus-sum) ; for gnus-list-identifiers
5802 (let ((cur (current-buffer))
5803 from subject date reply-to mrt mct
5804 references message-id follow-to
5805 (inhibit-point-motion-hooks t)
5806 (message-this-is-news t)
5807 followup-to distribution newsgroups gnus-warning posted-to)
5808 (save-restriction
5809 (narrow-to-region
5810 (goto-char (point-min))
5811 (if (search-forward "\n\n" nil t)
5812 (1- (point))
5813 (point-max)))
5814 (when (functionp message-followup-to-function)
5815 (setq follow-to
5816 (funcall message-followup-to-function)))
5817 (setq from (message-fetch-field "from")
5818 date (message-fetch-field "date")
5819 subject (or (message-fetch-field "subject") "none")
5820 references (message-fetch-field "references")
5821 message-id (message-fetch-field "message-id" t)
5822 followup-to (message-fetch-field "followup-to")
5823 newsgroups (message-fetch-field "newsgroups")
5824 posted-to (message-fetch-field "posted-to")
5825 reply-to (message-fetch-field "reply-to")
5826 mrt (message-fetch-field "mail-reply-to")
5827 distribution (message-fetch-field "distribution")
5828 mct (message-fetch-field "mail-copies-to"))
5829 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5830 (string-match "<[^>]+>" gnus-warning))
5831 (setq message-id (match-string 0 gnus-warning)))
5832 ;; Remove bogus distribution.
5833 (when (and (stringp distribution)
5834 (let ((case-fold-search t))
5835 (string-match "world" distribution)))
5836 (setq distribution nil))
5837 (if gnus-list-identifiers
5838 (setq subject (message-strip-list-identifiers subject)))
5839 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5840 (when message-subject-trailing-was-query
5841 (setq subject (message-strip-subject-trailing-was subject)))
5842 (widen))
5844 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5846 (setq message-reply-headers
5847 (vector 0 subject from date message-id references 0 0 ""))
5849 (message-setup
5850 `((Subject . ,subject)
5851 ,@(cond
5852 (to-newsgroups
5853 (list (cons 'Newsgroups to-newsgroups)))
5854 (follow-to follow-to)
5855 ((and followup-to message-use-followup-to)
5856 (list
5857 (cond
5858 ((equal (downcase followup-to) "poster")
5859 (if (or (eq message-use-followup-to 'use)
5860 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5861 You should normally obey the Followup-To: header.
5863 `Followup-To: poster' sends your response via e-mail instead of news.
5865 A typical situation where `Followup-To: poster' is used is when the poster
5866 does not read the newsgroup, so he wouldn't see any replies sent to it.
5868 You may customize the variable `message-use-followup-to', if you
5869 want to get rid of this query permanently."))
5870 (progn
5871 (setq message-this-is-news nil)
5872 (cons 'To (or mrt reply-to from "")))
5873 (cons 'Newsgroups newsgroups)))
5875 (if (or (equal followup-to newsgroups)
5876 (not (eq message-use-followup-to 'ask))
5877 (message-y-or-n-p
5878 (concat "Obey Followup-To: " followup-to "? ") t "\
5879 You should normally obey the Followup-To: header.
5881 `Followup-To: " followup-to "'
5882 directs your response to " (if (string-match "," followup-to)
5883 "the specified newsgroups"
5884 "that newsgroup only") ".
5886 If a message is posted to several newsgroups, Followup-To is often
5887 used to direct the following discussion to one newsgroup only,
5888 because discussions that are spread over several newsgroup tend to
5889 be fragmented and very difficult to follow.
5891 Also, some source/announcement newsgroups are not intended for discussion;
5892 responses here are directed to other newsgroups.
5894 You may customize the variable `message-use-followup-to', if you
5895 want to get rid of this query permanently."))
5896 (cons 'Newsgroups followup-to)
5897 (cons 'Newsgroups newsgroups))))))
5898 (posted-to
5899 `((Newsgroups . ,posted-to)))
5901 `((Newsgroups . ,newsgroups))))
5902 ,@(and distribution (list (cons 'Distribution distribution)))
5903 ,@(when (and mct
5904 (not (or (equal (downcase mct) "never")
5905 (equal (downcase mct) "nobody"))))
5906 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5907 (equal (downcase mct) "poster"))
5908 (or mrt reply-to from "")
5909 mct)))))
5911 cur)))
5913 (defun message-is-yours-p ()
5914 "Non-nil means current article is yours.
5915 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
5916 are yours except those that have Cancel-Lock header not belonging to you.
5917 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
5918 regexp to match all of yours addresses."
5919 ;; Canlock-logic as suggested by Per Abrahamsen
5920 ;; <abraham@dina.kvl.dk>
5922 ;; IF article has cancel-lock THEN
5923 ;; IF we can verify it THEN
5924 ;; issue cancel
5925 ;; ELSE
5926 ;; error: cancellock: article is not yours
5927 ;; ELSE
5928 ;; Use old rules, comparing sender...
5929 (save-excursion
5930 (save-restriction
5931 (message-narrow-to-head-1)
5932 (if (message-fetch-field "Cancel-Lock")
5933 (if (null (canlock-verify))
5935 (error "Failed to verify Cancel-lock: This article is not yours"))
5936 (let (sender from)
5938 (message-gnksa-enable-p 'cancel-messages)
5939 (and (setq sender (message-fetch-field "sender"))
5940 (string-equal (downcase sender)
5941 (downcase (message-make-sender))))
5942 ;; Email address in From field equals to our address
5943 (and (setq from (message-fetch-field "from"))
5944 (string-equal
5945 (downcase (cadr (mail-extract-address-components from)))
5946 (downcase (cadr (mail-extract-address-components
5947 (message-make-from))))))
5948 ;; Email address in From field matches
5949 ;; 'message-alternative-emails' regexp
5950 (and from
5951 message-alternative-emails
5952 (string-match
5953 message-alternative-emails
5954 (cadr (mail-extract-address-components from))))))))))
5956 ;;;###autoload
5957 (defun message-cancel-news (&optional arg)
5958 "Cancel an article you posted.
5959 If ARG, allow editing of the cancellation message."
5960 (interactive "P")
5961 (unless (message-news-p)
5962 (error "This is not a news article; canceling is impossible"))
5963 (let (from newsgroups message-id distribution buf)
5964 (save-excursion
5965 ;; Get header info from original article.
5966 (save-restriction
5967 (message-narrow-to-head-1)
5968 (setq from (message-fetch-field "from")
5969 newsgroups (message-fetch-field "newsgroups")
5970 message-id (message-fetch-field "message-id" t)
5971 distribution (message-fetch-field "distribution")))
5972 ;; Make sure that this article was written by the user.
5973 (unless (message-is-yours-p)
5974 (error "This article is not yours"))
5975 (when (yes-or-no-p "Do you really want to cancel this article? ")
5976 ;; Make control message.
5977 (if arg
5978 (message-news)
5979 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5980 (erase-buffer)
5981 (insert "Newsgroups: " newsgroups "\n"
5982 "From: " from "\n"
5983 "Subject: cmsg cancel " message-id "\n"
5984 "Control: cancel " message-id "\n"
5985 (if distribution
5986 (concat "Distribution: " distribution "\n")
5988 mail-header-separator "\n"
5989 message-cancel-message)
5990 (run-hooks 'message-cancel-hook)
5991 (unless arg
5992 (message "Canceling your article...")
5993 (if (let ((message-syntax-checks
5994 'dont-check-for-anything-just-trust-me))
5995 (funcall message-send-news-function))
5996 (message "Canceling your article...done"))
5997 (kill-buffer buf))))))
5999 ;;;###autoload
6000 (defun message-supersede ()
6001 "Start composing a message to supersede the current message.
6002 This is done simply by taking the old article and adding a Supersedes
6003 header line with the old Message-ID."
6004 (interactive)
6005 (let ((cur (current-buffer)))
6006 ;; Check whether the user owns the article that is to be superseded.
6007 (unless (message-is-yours-p)
6008 (error "This article is not yours"))
6009 ;; Get a normal message buffer.
6010 (message-pop-to-buffer (message-buffer-name "supersede"))
6011 (insert-buffer-substring cur)
6012 (mime-to-mml)
6013 (message-narrow-to-head-1)
6014 ;; Remove unwanted headers.
6015 (when message-ignored-supersedes-headers
6016 (message-remove-header message-ignored-supersedes-headers t))
6017 (goto-char (point-min))
6018 (if (not (re-search-forward "^Message-ID: " nil t))
6019 (error "No Message-ID in this article")
6020 (replace-match "Supersedes: " t t))
6021 (goto-char (point-max))
6022 (insert mail-header-separator)
6023 (widen)
6024 (forward-line 1)))
6026 ;;;###autoload
6027 (defun message-recover ()
6028 "Reread contents of current buffer from its last auto-save file."
6029 (interactive)
6030 (let ((file-name (make-auto-save-file-name)))
6031 (cond ((save-window-excursion
6032 (if (not (eq system-type 'vax-vms))
6033 (with-output-to-temp-buffer "*Directory*"
6034 (with-current-buffer standard-output
6035 (fundamental-mode)) ; for Emacs 20.4+
6036 (buffer-disable-undo standard-output)
6037 (let ((default-directory "/"))
6038 (call-process
6039 "ls" nil standard-output nil "-l" file-name))))
6040 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6041 (let ((buffer-read-only nil))
6042 (erase-buffer)
6043 (insert-file-contents file-name nil)))
6044 (t (error "message-recover cancelled")))))
6046 ;;; Washing Subject:
6048 (defun message-wash-subject (subject)
6049 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6050 Previous forwarders, replyers, etc. may add it."
6051 (with-temp-buffer
6052 (insert subject)
6053 (goto-char (point-min))
6054 ;; strip Re/Fwd stuff off the beginning
6055 (while (re-search-forward
6056 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6057 (replace-match ""))
6059 ;; and gnus-style forwards [foo@bar.com] subject
6060 (goto-char (point-min))
6061 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6062 (replace-match ""))
6064 ;; and off the end
6065 (goto-char (point-max))
6066 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6067 (replace-match ""))
6069 ;; and finally, any whitespace that was left-over
6070 (goto-char (point-min))
6071 (while (re-search-forward "^[ \t]+" nil t)
6072 (replace-match ""))
6073 (goto-char (point-max))
6074 (while (re-search-backward "[ \t]+$" nil t)
6075 (replace-match ""))
6077 (buffer-string)))
6079 ;;; Forwarding messages.
6081 (defvar message-forward-decoded-p nil
6082 "Non-nil means the original message is decoded.")
6084 (defun message-forward-subject-name-subject (subject)
6085 "Generate a SUBJECT for a forwarded message.
6086 The form is: [Source] Subject, where if the original message was mail,
6087 Source is the name of the sender, and if the original message was
6088 news, Source is the list of newsgroups is was posted to."
6089 (let* ((group (message-fetch-field "newsgroups"))
6090 (from (message-fetch-field "from"))
6091 (prefix
6092 (if group
6093 (gnus-group-decoded-name group)
6094 (or (and from (car (gnus-extract-address-components from)))
6095 "(nowhere)"))))
6096 (concat "["
6097 (if message-forward-decoded-p
6098 prefix
6099 (mail-decode-encoded-word-string prefix))
6100 "] " subject)))
6102 (defun message-forward-subject-author-subject (subject)
6103 "Generate a SUBJECT for a forwarded message.
6104 The form is: [Source] Subject, where if the original message was mail,
6105 Source is the sender, and if the original message was news, Source is
6106 the list of newsgroups is was posted to."
6107 (let* ((group (message-fetch-field "newsgroups"))
6108 (prefix
6109 (if group
6110 (gnus-group-decoded-name group)
6111 (or (message-fetch-field "from")
6112 "(nowhere)"))))
6113 (concat "["
6114 (if message-forward-decoded-p
6115 prefix
6116 (mail-decode-encoded-word-string prefix))
6117 "] " subject)))
6119 (defun message-forward-subject-fwd (subject)
6120 "Generate a SUBJECT for a forwarded message.
6121 The form is: Fwd: Subject, where Subject is the original subject of
6122 the message."
6123 (if (string-match "^Fwd: " subject)
6124 subject
6125 (concat "Fwd: " subject)))
6127 (defun message-make-forward-subject ()
6128 "Return a Subject header suitable for the message in the current buffer."
6129 (save-excursion
6130 (save-restriction
6131 (message-narrow-to-head-1)
6132 (let ((funcs message-make-forward-subject-function)
6133 (subject (message-fetch-field "Subject")))
6134 (setq subject
6135 (if subject
6136 (if message-forward-decoded-p
6137 subject
6138 (mail-decode-encoded-word-string subject))
6139 ""))
6140 (if message-wash-forwarded-subjects
6141 (setq subject (message-wash-subject subject)))
6142 ;; Make sure funcs is a list.
6143 (and funcs
6144 (not (listp funcs))
6145 (setq funcs (list funcs)))
6146 ;; Apply funcs in order, passing subject generated by previous
6147 ;; func to the next one.
6148 (while funcs
6149 (when (functionp (car funcs))
6150 (setq subject (funcall (car funcs) subject)))
6151 (setq funcs (cdr funcs)))
6152 subject))))
6154 (eval-when-compile
6155 (defvar gnus-article-decoded-p))
6158 ;;;###autoload
6159 (defun message-forward (&optional news digest)
6160 "Forward the current message via mail.
6161 Optional NEWS will use news to forward instead of mail.
6162 Optional DIGEST will use digest to forward."
6163 (interactive "P")
6164 (let* ((cur (current-buffer))
6165 (message-forward-decoded-p
6166 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6167 gnus-article-decoded-p ;; In an article buffer.
6168 message-forward-decoded-p))
6169 (subject (message-make-forward-subject)))
6170 (if news
6171 (message-news nil subject)
6172 (message-mail nil subject))
6173 (message-forward-make-body cur digest)))
6175 (defun message-forward-make-body-plain (forward-buffer)
6176 (insert
6177 "\n-------------------- Start of forwarded message --------------------\n")
6178 (let ((b (point)) e)
6179 (insert
6180 (with-temp-buffer
6181 (mm-disable-multibyte)
6182 (insert
6183 (with-current-buffer forward-buffer
6184 (mm-with-unibyte-current-buffer (buffer-string))))
6185 (mm-enable-multibyte)
6186 (mime-to-mml)
6187 (goto-char (point-min))
6188 (when (looking-at "From ")
6189 (replace-match "X-From-Line: "))
6190 (buffer-string)))
6191 (setq e (point))
6192 (insert
6193 "\n-------------------- End of forwarded message --------------------\n")
6194 (when message-forward-ignored-headers
6195 (save-restriction
6196 (narrow-to-region b e)
6197 (goto-char b)
6198 (narrow-to-region (point)
6199 (or (search-forward "\n\n" nil t) (point)))
6200 (message-remove-header message-forward-ignored-headers t)))))
6202 (defun message-forward-make-body-mime (forward-buffer)
6203 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6204 (let ((b (point)) e)
6205 (save-restriction
6206 (narrow-to-region (point) (point))
6207 (mml-insert-buffer forward-buffer)
6208 (goto-char (point-min))
6209 (when (looking-at "From ")
6210 (replace-match "X-From-Line: "))
6211 (goto-char (point-max)))
6212 (setq e (point))
6213 (insert "<#/part>\n")))
6215 (defun message-forward-make-body-mml (forward-buffer)
6216 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6217 (let ((b (point)) e)
6218 (if (not message-forward-decoded-p)
6219 (insert
6220 (with-temp-buffer
6221 (mm-disable-multibyte)
6222 (insert
6223 (with-current-buffer forward-buffer
6224 (mm-with-unibyte-current-buffer (buffer-string))))
6225 (mm-enable-multibyte)
6226 (mime-to-mml)
6227 (goto-char (point-min))
6228 (when (looking-at "From ")
6229 (replace-match "X-From-Line: "))
6230 (buffer-string)))
6231 (save-restriction
6232 (narrow-to-region (point) (point))
6233 (mml-insert-buffer forward-buffer)
6234 (goto-char (point-min))
6235 (when (looking-at "From ")
6236 (replace-match "X-From-Line: "))
6237 (goto-char (point-max))))
6238 (setq e (point))
6239 (insert "<#/mml>\n")
6240 (when (and (not message-forward-decoded-p)
6241 message-forward-ignored-headers)
6242 (save-restriction
6243 (narrow-to-region b e)
6244 (goto-char b)
6245 (narrow-to-region (point)
6246 (or (search-forward "\n\n" nil t) (point)))
6247 (message-remove-header message-forward-ignored-headers t)))))
6249 (defun message-forward-make-body-digest-plain (forward-buffer)
6250 (insert
6251 "\n-------------------- Start of forwarded message --------------------\n")
6252 (let ((b (point)) e)
6253 (mml-insert-buffer forward-buffer)
6254 (setq e (point))
6255 (insert
6256 "\n-------------------- End of forwarded message --------------------\n")))
6258 (defun message-forward-make-body-digest-mime (forward-buffer)
6259 (insert "\n<#multipart type=digest>\n")
6260 (let ((b (point)) e)
6261 (insert-buffer-substring forward-buffer)
6262 (setq e (point))
6263 (insert "<#/multipart>\n")
6264 (save-restriction
6265 (narrow-to-region b e)
6266 (goto-char b)
6267 (narrow-to-region (point)
6268 (or (search-forward "\n\n" nil t) (point)))
6269 (delete-region (point-min) (point-max)))))
6271 (defun message-forward-make-body-digest (forward-buffer)
6272 (if message-forward-as-mime
6273 (message-forward-make-body-digest-mime forward-buffer)
6274 (message-forward-make-body-digest-plain forward-buffer)))
6276 ;;;###autoload
6277 (defun message-forward-make-body (forward-buffer &optional digest)
6278 ;; Put point where we want it before inserting the forwarded
6279 ;; message.
6280 (if message-forward-before-signature
6281 (message-goto-body)
6282 (goto-char (point-max)))
6283 (if digest
6284 (message-forward-make-body-digest forward-buffer)
6285 (if message-forward-as-mime
6286 (if (and message-forward-show-mml
6287 (not (and (eq message-forward-show-mml 'best)
6288 (with-current-buffer forward-buffer
6289 (goto-char (point-min))
6290 (re-search-forward
6291 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6292 nil t)))))
6293 (message-forward-make-body-mml forward-buffer)
6294 (message-forward-make-body-mime forward-buffer))
6295 (message-forward-make-body-plain forward-buffer)))
6296 (message-position-point))
6298 ;;;###autoload
6299 (defun message-forward-rmail-make-body (forward-buffer)
6300 (save-window-excursion
6301 (set-buffer forward-buffer)
6302 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6303 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6304 (if (rmail-msg-is-pruned)
6305 (rmail-msg-restore-non-pruned-header)))
6306 (message-forward-make-body forward-buffer))
6308 (eval-when-compile (defvar rmail-enable-mime-composing))
6310 ;; Fixme: Should have defcustom.
6311 ;;;###autoload
6312 (defun message-insinuate-rmail ()
6313 "Let RMAIL use message to forward."
6314 (interactive)
6315 (setq rmail-enable-mime-composing t)
6316 (setq rmail-insert-mime-forwarded-message-function
6317 'message-forward-rmail-make-body))
6319 ;;;###autoload
6320 (defun message-resend (address)
6321 "Resend the current article to ADDRESS."
6322 (interactive
6323 (list (message-read-from-minibuffer "Resend message to: ")))
6324 (message "Resending message to %s..." address)
6325 (save-excursion
6326 (let ((cur (current-buffer))
6327 beg)
6328 ;; We first set up a normal mail buffer.
6329 (unless (message-mail-user-agent)
6330 (set-buffer (get-buffer-create " *message resend*"))
6331 (erase-buffer))
6332 (let ((message-this-is-mail t)
6333 message-setup-hook)
6334 (message-setup `((To . ,address))))
6335 ;; Insert our usual headers.
6336 (message-generate-headers '(From Date To Message-ID))
6337 (message-narrow-to-headers)
6338 ;; Remove X-Draft-From header etc.
6339 (message-remove-header message-ignored-mail-headers t)
6340 ;; Rename them all to "Resent-*".
6341 (goto-char (point-min))
6342 (while (re-search-forward "^[A-Za-z]" nil t)
6343 (forward-char -1)
6344 (insert "Resent-"))
6345 (widen)
6346 (forward-line)
6347 (delete-region (point) (point-max))
6348 (setq beg (point))
6349 ;; Insert the message to be resent.
6350 (insert-buffer-substring cur)
6351 (goto-char (point-min))
6352 (search-forward "\n\n")
6353 (forward-char -1)
6354 (save-restriction
6355 (narrow-to-region beg (point))
6356 (message-remove-header message-ignored-resent-headers t)
6357 (goto-char (point-max)))
6358 (insert mail-header-separator)
6359 ;; Rename all old ("Also-")Resent headers.
6360 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6361 (beginning-of-line)
6362 (insert "Also-"))
6363 ;; Quote any "From " lines at the beginning.
6364 (goto-char beg)
6365 (when (looking-at "From ")
6366 (replace-match "X-From-Line: "))
6367 ;; Send it.
6368 (let ((message-inhibit-body-encoding t)
6369 message-required-mail-headers
6370 rfc2047-encode-encoded-words)
6371 (message-send-mail))
6372 (kill-buffer (current-buffer)))
6373 (message "Resending message to %s...done" address)))
6375 ;;;###autoload
6376 (defun message-bounce ()
6377 "Re-mail the current message.
6378 This only makes sense if the current message is a bounce message that
6379 contains some mail you have written which has been bounced back to
6380 you."
6381 (interactive)
6382 (let ((handles (mm-dissect-buffer t))
6383 boundary)
6384 (message-pop-to-buffer (message-buffer-name "bounce"))
6385 (if (stringp (car handles))
6386 ;; This is a MIME bounce.
6387 (mm-insert-part (car (last handles)))
6388 ;; This is a non-MIME bounce, so we try to remove things
6389 ;; manually.
6390 (mm-insert-part handles)
6391 (undo-boundary)
6392 (goto-char (point-min))
6393 (re-search-forward "\n\n+" nil t)
6394 (setq boundary (point))
6395 ;; We remove everything before the bounced mail.
6396 (if (or (re-search-forward message-unsent-separator nil t)
6397 (progn
6398 (search-forward "\n\n" nil 'move)
6399 (re-search-backward "^Return-Path:.*\n" boundary t)))
6400 (progn
6401 (forward-line 1)
6402 (delete-region (point-min)
6403 (if (re-search-forward "^[^ \n\t]+:" nil t)
6404 (match-beginning 0)
6405 (point))))
6406 (goto-char boundary)
6407 (when (re-search-backward "^.?From .*\n" nil t)
6408 (delete-region (match-beginning 0) (match-end 0)))))
6409 (mm-enable-multibyte)
6410 (save-restriction
6411 (message-narrow-to-head-1)
6412 (message-remove-header message-ignored-bounced-headers t)
6413 (goto-char (point-max))
6414 (insert mail-header-separator))
6415 (message-position-point)))
6418 ;;; Interactive entry points for new message buffers.
6421 ;;;###autoload
6422 (defun message-mail-other-window (&optional to subject)
6423 "Like `message-mail' command, but display mail buffer in another window."
6424 (interactive)
6425 (unless (message-mail-user-agent)
6426 (let ((pop-up-windows t)
6427 (special-display-buffer-names nil)
6428 (special-display-regexps nil)
6429 (same-window-buffer-names nil)
6430 (same-window-regexps nil))
6431 (message-pop-to-buffer (message-buffer-name "mail" to))))
6432 (let ((message-this-is-mail t))
6433 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6434 nil nil 'switch-to-buffer-other-window)))
6436 ;;;###autoload
6437 (defun message-mail-other-frame (&optional to subject)
6438 "Like `message-mail' command, but display mail buffer in another frame."
6439 (interactive)
6440 (unless (message-mail-user-agent)
6441 (let ((pop-up-frames t)
6442 (special-display-buffer-names nil)
6443 (special-display-regexps nil)
6444 (same-window-buffer-names nil)
6445 (same-window-regexps nil))
6446 (message-pop-to-buffer (message-buffer-name "mail" to))))
6447 (let ((message-this-is-mail t))
6448 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6449 nil nil 'switch-to-buffer-other-frame)))
6451 ;;;###autoload
6452 (defun message-news-other-window (&optional newsgroups subject)
6453 "Start editing a news article to be sent."
6454 (interactive)
6455 (let ((pop-up-windows t)
6456 (special-display-buffer-names nil)
6457 (special-display-regexps nil)
6458 (same-window-buffer-names nil)
6459 (same-window-regexps nil))
6460 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6461 (let ((message-this-is-news t))
6462 (message-setup `((Newsgroups . ,(or newsgroups ""))
6463 (Subject . ,(or subject ""))))))
6465 ;;;###autoload
6466 (defun message-news-other-frame (&optional newsgroups subject)
6467 "Start editing a news article to be sent."
6468 (interactive)
6469 (let ((pop-up-frames t)
6470 (special-display-buffer-names nil)
6471 (special-display-regexps nil)
6472 (same-window-buffer-names nil)
6473 (same-window-regexps nil))
6474 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6475 (let ((message-this-is-news t))
6476 (message-setup `((Newsgroups . ,(or newsgroups ""))
6477 (Subject . ,(or subject ""))))))
6479 ;;; underline.el
6481 ;; This code should be moved to underline.el (from which it is stolen).
6483 ;;;###autoload
6484 (defun bold-region (start end)
6485 "Bold all nonblank characters in the region.
6486 Works by overstriking characters.
6487 Called from program, takes two arguments START and END
6488 which specify the range to operate on."
6489 (interactive "r")
6490 (save-excursion
6491 (let ((end1 (make-marker)))
6492 (move-marker end1 (max start end))
6493 (goto-char (min start end))
6494 (while (< (point) end1)
6495 (or (looking-at "[_\^@- ]")
6496 (insert (char-after) "\b"))
6497 (forward-char 1)))))
6499 ;;;###autoload
6500 (defun unbold-region (start end)
6501 "Remove all boldness (overstruck characters) in the region.
6502 Called from program, takes two arguments START and END
6503 which specify the range to operate on."
6504 (interactive "r")
6505 (save-excursion
6506 (let ((end1 (make-marker)))
6507 (move-marker end1 (max start end))
6508 (goto-char (min start end))
6509 (while (re-search-forward "\b" end1 t)
6510 (if (eq (char-after) (char-after (- (point) 2)))
6511 (delete-char -2))))))
6513 (defun message-exchange-point-and-mark ()
6514 "Exchange point and mark, but don't activate region if it was inactive."
6515 (unless (prog1
6516 (message-mark-active-p)
6517 (exchange-point-and-mark))
6518 (setq mark-active nil)))
6520 (defalias 'message-make-overlay 'make-overlay)
6521 (defalias 'message-delete-overlay 'delete-overlay)
6522 (defalias 'message-overlay-put 'overlay-put)
6523 (defun message-kill-all-overlays ()
6524 (if (featurep 'xemacs)
6525 (map-extents (lambda (extent ignore) (delete-extent extent)))
6526 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6528 ;; Support for toolbar
6529 (eval-when-compile
6530 (defvar tool-bar-map)
6531 (defvar tool-bar-mode))
6533 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6534 ;; We need to make tool bar entries in local keymaps with
6535 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6536 (if (fboundp 'tool-bar-local-item-from-menu)
6537 ;; This is for Emacs 21.3
6538 (tool-bar-local-item-from-menu command icon in-map from-map props)
6539 (tool-bar-add-item-from-menu command icon from-map props)))
6541 (defun message-tool-bar-map ()
6542 (or message-tool-bar-map
6543 (setq message-tool-bar-map
6544 (and
6545 (condition-case nil (require 'tool-bar) (error nil))
6546 (fboundp 'tool-bar-add-item-from-menu)
6547 tool-bar-mode
6548 (let ((tool-bar-map (copy-keymap tool-bar-map))
6549 (load-path (mm-image-load-path)))
6550 ;; Zap some items which aren't so relevant and take
6551 ;; up space.
6552 (dolist (key '(print-buffer kill-buffer save-buffer
6553 write-file dired open-file))
6554 (define-key tool-bar-map (vector key) nil))
6555 (message-tool-bar-local-item-from-menu
6556 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6557 (message-tool-bar-local-item-from-menu
6558 'message-kill-buffer "close" tool-bar-map message-mode-map)
6559 (message-tool-bar-local-item-from-menu
6560 'message-dont-send "cancel" tool-bar-map message-mode-map)
6561 (message-tool-bar-local-item-from-menu
6562 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6563 (message-tool-bar-local-item-from-menu
6564 'ispell-message "spell" tool-bar-map message-mode-map)
6565 (message-tool-bar-local-item-from-menu
6566 'mml-preview "preview"
6567 tool-bar-map mml-mode-map)
6568 (message-tool-bar-local-item-from-menu
6569 'message-insert-importance-high "important"
6570 tool-bar-map message-mode-map)
6571 (message-tool-bar-local-item-from-menu
6572 'message-insert-importance-low "unimportant"
6573 tool-bar-map message-mode-map)
6574 (message-tool-bar-local-item-from-menu
6575 'message-insert-disposition-notification-to "receipt"
6576 tool-bar-map message-mode-map)
6577 tool-bar-map)))))
6579 ;;; Group name completion.
6581 (defcustom message-newgroups-header-regexp
6582 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6583 "Regexp that match headers that lists groups."
6584 :group 'message
6585 :type 'regexp)
6587 (defcustom message-completion-alist
6588 (list (cons message-newgroups-header-regexp 'message-expand-group)
6589 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6590 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6591 . message-expand-name)
6592 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6593 . message-expand-name))
6594 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6595 :version "22.1"
6596 :group 'message
6597 :type '(alist :key-type regexp :value-type function))
6599 (defcustom message-tab-body-function nil
6600 "*Function to execute when `message-tab' (TAB) is executed in the body.
6601 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6602 :version "22.1"
6603 :group 'message
6604 :link '(custom-manual "(message)Various Commands")
6605 :type 'function)
6607 (defun message-tab ()
6608 "Complete names according to `message-completion-alist'.
6609 Execute function specified by `message-tab-body-function' when not in
6610 those headers."
6611 (interactive)
6612 (let ((alist message-completion-alist))
6613 (while (and alist
6614 (let ((mail-abbrev-mode-regexp (caar alist)))
6615 (not (mail-abbrev-in-expansion-header-p))))
6616 (setq alist (cdr alist)))
6617 (funcall (or (cdar alist) message-tab-body-function
6618 (lookup-key text-mode-map "\t")
6619 (lookup-key global-map "\t")
6620 'indent-relative))))
6622 (defun message-expand-group ()
6623 "Expand the group name under point."
6624 (let* ((b (save-excursion
6625 (save-restriction
6626 (narrow-to-region
6627 (save-excursion
6628 (beginning-of-line)
6629 (skip-chars-forward "^:")
6630 (1+ (point)))
6631 (point))
6632 (skip-chars-backward "^, \t\n") (point))))
6633 (completion-ignore-case t)
6634 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6635 (point))))
6636 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6637 (completions (all-completions string hashtb))
6638 comp)
6639 (delete-region b (point))
6640 (cond
6641 ((= (length completions) 1)
6642 (if (string= (car completions) string)
6643 (progn
6644 (insert string)
6645 (message "Only matching group"))
6646 (insert (car completions))))
6647 ((and (setq comp (try-completion string hashtb))
6648 (not (string= comp string)))
6649 (insert comp))
6651 (insert string)
6652 (if (not comp)
6653 (message "No matching groups")
6654 (save-selected-window
6655 (pop-to-buffer "*Completions*")
6656 (buffer-disable-undo)
6657 (let ((buffer-read-only nil))
6658 (erase-buffer)
6659 (let ((standard-output (current-buffer)))
6660 (display-completion-list (sort completions 'string<)))
6661 (goto-char (point-min))
6662 (delete-region (point) (progn (forward-line 3) (point))))))))))
6664 (defun message-expand-name ()
6665 (if (fboundp 'bbdb-complete-name)
6666 (bbdb-complete-name)
6667 (expand-abbrev)))
6669 ;;; Help stuff.
6671 (defun message-talkative-question (ask question show &rest text)
6672 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6673 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6674 The following arguments may contain lists of values."
6675 (if (and show
6676 (setq text (message-flatten-list text)))
6677 (save-window-excursion
6678 (save-excursion
6679 (with-output-to-temp-buffer " *MESSAGE information message*"
6680 (set-buffer " *MESSAGE information message*")
6681 (fundamental-mode) ; for Emacs 20.4+
6682 (mapcar 'princ text)
6683 (goto-char (point-min))))
6684 (funcall ask question))
6685 (funcall ask question)))
6687 (defun message-flatten-list (list)
6688 "Return a new, flat list that contains all elements of LIST.
6690 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6691 => (1 2 3 4 5 6 7)"
6692 (cond ((consp list)
6693 (apply 'append (mapcar 'message-flatten-list list)))
6694 (list
6695 (list list))))
6697 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6698 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6699 Then clone the local variables and values from the old buffer to the
6700 new one, cloning only the locals having a substring matching the
6701 regexp VARSTR."
6702 (let ((oldbuf (current-buffer)))
6703 (save-excursion
6704 (set-buffer (generate-new-buffer name))
6705 (message-clone-locals oldbuf varstr)
6706 (current-buffer))))
6708 (defun message-clone-locals (buffer &optional varstr)
6709 "Clone the local variables from BUFFER to the current buffer."
6710 (let ((locals (save-excursion
6711 (set-buffer buffer)
6712 (buffer-local-variables)))
6713 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6714 (mapcar
6715 (lambda (local)
6716 (when (and (consp local)
6717 (car local)
6718 (string-match regexp (symbol-name (car local)))
6719 (or (null varstr)
6720 (string-match varstr (symbol-name (car local)))))
6721 (ignore-errors
6722 (set (make-local-variable (car local))
6723 (cdr local)))))
6724 locals)))
6727 ;;; MIME functions
6730 (defvar message-inhibit-body-encoding nil)
6732 (defun message-encode-message-body ()
6733 (unless message-inhibit-body-encoding
6734 (let ((mail-parse-charset (or mail-parse-charset
6735 message-default-charset))
6736 (case-fold-search t)
6737 lines content-type-p)
6738 (message-goto-body)
6739 (save-restriction
6740 (narrow-to-region (point) (point-max))
6741 (let ((new (mml-generate-mime)))
6742 (when new
6743 (delete-region (point-min) (point-max))
6744 (insert new)
6745 (goto-char (point-min))
6746 (if (eq (aref new 0) ?\n)
6747 (delete-char 1)
6748 (search-forward "\n\n")
6749 (setq lines (buffer-substring (point-min) (1- (point))))
6750 (delete-region (point-min) (point))))))
6751 (save-restriction
6752 (message-narrow-to-headers-or-head)
6753 (message-remove-header "Mime-Version")
6754 (goto-char (point-max))
6755 (insert "MIME-Version: 1.0\n")
6756 (when lines
6757 (insert lines))
6758 (setq content-type-p
6759 (or mml-boundary
6760 (re-search-backward "^Content-Type:" nil t))))
6761 (save-restriction
6762 (message-narrow-to-headers-or-head)
6763 (message-remove-first-header "Content-Type")
6764 (message-remove-first-header "Content-Transfer-Encoding"))
6765 ;; We always make sure that the message has a Content-Type
6766 ;; header. This is because some broken MTAs and MUAs get
6767 ;; awfully confused when confronted with a message with a
6768 ;; MIME-Version header and without a Content-Type header. For
6769 ;; instance, Solaris' /usr/bin/mail.
6770 (unless content-type-p
6771 (goto-char (point-min))
6772 ;; For unknown reason, MIME-Version doesn't exist.
6773 (when (re-search-forward "^MIME-Version:" nil t)
6774 (forward-line 1)
6775 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6777 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6778 "Read from the minibuffer while providing abbrev expansion."
6779 (if (fboundp 'mail-abbrevs-setup)
6780 (let ((mail-abbrev-mode-regexp "")
6781 (minibuffer-setup-hook 'mail-abbrevs-setup)
6782 (minibuffer-local-map message-minibuffer-local-map))
6783 (read-from-minibuffer prompt initial-contents))
6784 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6785 (minibuffer-local-map message-minibuffer-local-map))
6786 (read-string prompt initial-contents))))
6788 (defun message-use-alternative-email-as-from ()
6789 (require 'mail-utils)
6790 (let* ((fields '("To" "Cc"))
6791 (emails
6792 (split-string
6793 (mail-strip-quoted-names
6794 (mapconcat 'message-fetch-reply-field fields ","))
6795 "[ \f\t\n\r\v,]+"))
6796 email)
6797 (while emails
6798 (if (string-match message-alternative-emails (car emails))
6799 (setq email (car emails)
6800 emails nil))
6801 (pop emails))
6802 (unless (or (not email) (equal email user-mail-address))
6803 (goto-char (point-max))
6804 (insert "From: " email "\n"))))
6806 (defun message-options-get (symbol)
6807 (cdr (assq symbol message-options)))
6809 (defun message-options-set (symbol value)
6810 (let ((the-cons (assq symbol message-options)))
6811 (if the-cons
6812 (if value
6813 (setcdr the-cons value)
6814 (setq message-options (delq the-cons message-options)))
6815 (and value
6816 (push (cons symbol value) message-options))))
6817 value)
6819 (defun message-options-set-recipient ()
6820 (save-restriction
6821 (message-narrow-to-headers-or-head)
6822 (message-options-set 'message-sender
6823 (mail-strip-quoted-names
6824 (message-fetch-field "from")))
6825 (message-options-set 'message-recipients
6826 (mail-strip-quoted-names
6827 (let ((to (message-fetch-field "to"))
6828 (cc (message-fetch-field "cc"))
6829 (bcc (message-fetch-field "bcc")))
6830 (concat
6831 (or to "")
6832 (if (and to cc) ", ")
6833 (or cc "")
6834 (if (and (or to cc) bcc) ", ")
6835 (or bcc "")))))))
6837 (defun message-hide-headers ()
6838 "Hide headers based on the `message-hidden-headers' variable."
6839 (let ((regexps (if (stringp message-hidden-headers)
6840 (list message-hidden-headers)
6841 message-hidden-headers))
6842 (inhibit-point-motion-hooks t)
6843 (after-change-functions nil))
6844 (when regexps
6845 (save-excursion
6846 (save-restriction
6847 (message-narrow-to-headers)
6848 (goto-char (point-min))
6849 (while (not (eobp))
6850 (if (not (message-hide-header-p regexps))
6851 (message-next-header)
6852 (let ((begin (point)))
6853 (message-next-header)
6854 (add-text-properties
6855 begin (point)
6856 '(invisible t message-hidden t))))))))))
6858 (defun message-hide-header-p (regexps)
6859 (let ((result nil)
6860 (reverse nil))
6861 (when (eq (car regexps) 'not)
6862 (setq reverse t)
6863 (pop regexps))
6864 (dolist (regexp regexps)
6865 (setq result (or result (looking-at regexp))))
6866 (if reverse
6867 (not result)
6868 result)))
6870 (when (featurep 'xemacs)
6871 (require 'messagexmas)
6872 (message-xmas-redefine))
6874 (provide 'message)
6876 (run-hooks 'message-load-hook)
6878 ;; Local Variables:
6879 ;; coding: iso-8859-1
6880 ;; End:
6882 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
6883 ;;; message.el ends here