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