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