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