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