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