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