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