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