*** empty log message ***
[emacs.git] / lisp / gnus / message.el
blob5aa9eabccdf74685595300058b16944d265707f7
1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
31 ;;; Code:
33 (eval-when-compile
34 (require 'cl)
35 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
36 (require 'mailheader)
37 (require 'nnheader)
38 ;; This is apparently necessary even though things are autoloaded:
39 (if (featurep 'xemacs)
40 (require 'mail-abbrevs))
41 (require 'mail-parse)
42 (require 'mml)
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
48 :group 'mail
49 :group 'news)
51 (put 'user-mail-address 'custom-type 'string)
52 (put 'user-full-name 'custom-type 'string)
54 (defgroup message-various nil
55 "Various Message Variables"
56 :link '(custom-manual "(message)Various Message Variables")
57 :group 'message)
59 (defgroup message-buffers nil
60 "Message Buffers"
61 :link '(custom-manual "(message)Message Buffers")
62 :group 'message)
64 (defgroup message-sending nil
65 "Message Sending"
66 :link '(custom-manual "(message)Sending Variables")
67 :group 'message)
69 (defgroup message-interface nil
70 "Message Interface"
71 :link '(custom-manual "(message)Interface")
72 :group 'message)
74 (defgroup message-forwarding nil
75 "Message Forwarding"
76 :link '(custom-manual "(message)Forwarding")
77 :group 'message-interface)
79 (defgroup message-insertion nil
80 "Message Insertion"
81 :link '(custom-manual "(message)Insertion")
82 :group 'message)
84 (defgroup message-headers nil
85 "Message Headers"
86 :link '(custom-manual "(message)Message Headers")
87 :group 'message)
89 (defgroup message-news nil
90 "Composing News Messages"
91 :group 'message)
93 (defgroup message-mail nil
94 "Composing Mail Messages"
95 :group 'message)
97 (defgroup message-faces nil
98 "Faces used for message composing."
99 :group 'message
100 :group 'faces)
102 (defcustom message-directory "~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group 'message-various
105 :type 'directory)
107 (defcustom message-max-buffers 10
108 "*How many buffers to keep before starting to kill them off."
109 :group 'message-buffers
110 :type 'integer)
112 (defcustom message-send-rename-function nil
113 "Function called to rename the buffer after sending it."
114 :group 'message-buffers
115 :type '(choice function (const nil)))
117 (defcustom message-fcc-handler-function 'message-output
118 "*A function called to save outgoing articles.
119 This function will be called with the name of the file to store the
120 article in. The default function is `message-output' which saves in Unix
121 mailbox format."
122 :type '(radio (function-item message-output)
123 (function :tag "Other"))
124 :group 'message-sending)
126 (defcustom message-courtesy-message
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
128 "*This is inserted at the start of a mailed copy of a posted message.
129 If the string contains the format spec \"%s\", the Newsgroups
130 the article has been posted to will be inserted there.
131 If this variable is nil, no such courtesy message will be added."
132 :group 'message-sending
133 :type 'string)
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
136 "*Regexp that matches headers to be removed in resent bounced mail."
137 :group 'message-interface
138 :type 'regexp)
140 ;;;###autoload
141 (defcustom message-from-style 'default
142 "*Specifies how \"From\" headers look.
144 If nil, they contain just the return address like:
145 king@grassland.com
146 If `parens', they look like:
147 king@grassland.com (Elvis Parsley)
148 If `angles', they look like:
149 Elvis Parsley <king@grassland.com>
151 Otherwise, most addresses look like `angles', but they look like
152 `parens' if `angles' would need quoting and `parens' would not."
153 :type '(choice (const :tag "simple" nil)
154 (const parens)
155 (const angles)
156 (const default))
157 :group 'message-headers)
159 (defcustom message-syntax-checks nil
160 ;; Guess this one shouldn't be easy to customize...
161 "*Controls what syntax checks should not be performed on outgoing posts.
162 To disable checking of long signatures, for instance, add
163 `(signature . disabled)' to this list.
165 Don't touch this variable unless you really know what you're doing.
167 Checks include `subject-cmsg', `multiple-headers', `sendsys',
168 `message-id', `from', `long-lines', `control-chars', `size',
169 `new-text', `quoting-style', `redirected-followup', `signature',
170 `approved', `sender', `empty', `empty-headers', `message-id', `from',
171 `subject', `shorten-followup-to', `existing-newsgroups',
172 `buffer-file-name', `unchanged', `newsgroups'."
173 :group 'message-news
174 :type '(repeat sexp)) ; Fixme: improve this
176 (defcustom message-required-news-headers
177 '(From Newsgroups Subject Date Message-ID
178 (optional . Organization) Lines
179 (optional . User-Agent))
180 "*Headers to be generated or prompted for when posting an article.
181 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
182 Message-ID. Organization, Lines, In-Reply-To, Expires, and
183 User-Agent are optional. If don't you want message to insert some
184 header, remove it from this list."
185 :group 'message-news
186 :group 'message-headers
187 :type '(repeat sexp))
189 (defcustom message-required-mail-headers
190 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
191 (optional . User-Agent))
192 "*Headers to be generated or prompted for when mailing a message.
193 RFC822 required that From, Date, To, Subject and Message-ID be
194 included. Organization, Lines and User-Agent are optional."
195 :group 'message-mail
196 :group 'message-headers
197 :type '(repeat sexp))
199 (defcustom message-deletable-headers '(Message-ID Date Lines)
200 "Headers to be deleted if they already exist and were generated by message previously."
201 :group 'message-headers
202 :type 'sexp)
204 (defcustom message-ignored-news-headers
205 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
206 "*Regexp of headers to be removed unconditionally before posting."
207 :group 'message-news
208 :group 'message-headers
209 :type 'regexp)
211 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
212 "*Regexp of headers to be removed unconditionally before mailing."
213 :group 'message-mail
214 :group 'message-headers
215 :type 'regexp)
217 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
218 "*Header lines matching this regexp will be deleted before posting.
219 It's best to delete old Path and Date headers before posting to avoid
220 any confusion."
221 :group 'message-interface
222 :type 'regexp)
224 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
225 "*Regexp matching \"Re: \" in the subject line."
226 :group 'message-various
227 :type 'regexp)
229 ;;;###autoload
230 (defcustom message-signature-separator "^-- *$"
231 "Regexp matching the signature separator."
232 :type 'regexp
233 :group 'message-various)
235 (defcustom message-elide-ellipsis "\n[...]\n\n"
236 "*The string which is inserted for elided text."
237 :type 'string
238 :group 'message-various)
240 (defcustom message-interactive nil
241 "Non-nil means when sending a message wait for and display errors.
242 nil means let mailer mail back a message to report errors."
243 :group 'message-sending
244 :group 'message-mail
245 :type 'boolean)
247 (defcustom message-generate-new-buffers 'unique
248 "*Non-nil means create a new message buffer whenever `message-setup' is called.
249 If this is a function, call that function with three parameters: The type,
250 the to address and the group name. (Any of these may be nil.) The function
251 should return the new buffer name."
252 :group 'message-buffers
253 :type '(choice (const :tag "off" nil)
254 (const :tag "unique" unique)
255 (const :tag "unsent" unsent)
256 (function fun)))
258 (defcustom message-kill-buffer-on-exit nil
259 "*Non-nil means that the message buffer will be killed after sending a message."
260 :group 'message-buffers
261 :type 'boolean)
263 (eval-when-compile
264 (defvar gnus-local-organization))
265 (defcustom message-user-organization
266 (or (and (boundp 'gnus-local-organization)
267 (stringp gnus-local-organization)
268 gnus-local-organization)
269 (getenv "ORGANIZATION")
271 "*String to be used as an Organization header.
272 If t, use `message-user-organization-file'."
273 :group 'message-headers
274 :type '(choice string
275 (const :tag "consult file" t)))
277 ;;;###autoload
278 (defcustom message-user-organization-file "/usr/lib/news/organization"
279 "*Local news organization file."
280 :type 'file
281 :group 'message-headers)
283 (defcustom message-make-forward-subject-function
284 'message-forward-subject-author-subject
285 "*List of functions called to generate subject headers for forwarded messages.
286 The subject generated by the previous function is passed into each
287 successive function.
289 The provided functions are:
291 * `message-forward-subject-author-subject' (Source of article (author or
292 newsgroup)), in brackets followed by the subject
293 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
294 to it."
295 :group 'message-forwarding
296 :type '(radio (function-item message-forward-subject-author-subject)
297 (function-item message-forward-subject-fwd)
298 (repeat :tag "List of functions" function)))
300 (defcustom message-forward-as-mime t
301 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
302 :version "21.1"
303 :group 'message-forwarding
304 :type 'boolean)
306 (defcustom message-forward-show-mml t
307 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
308 :version "21.1"
309 :group 'message-forwarding
310 :type 'boolean)
312 (defcustom message-forward-before-signature t
313 "*If non-nil, put forwarded message before signature, else after."
314 :group 'message-forwarding
315 :type 'boolean)
317 (defcustom message-wash-forwarded-subjects nil
318 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
319 :group 'message-forwarding
320 :type 'boolean)
322 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
323 "*All headers that match this regexp will be deleted when resending a message."
324 :group 'message-interface
325 :type 'regexp)
327 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
328 "*All headers that match this regexp will be deleted when forwarding a message."
329 :version "21.1"
330 :group 'message-forwarding
331 :type '(choice (const :tag "None" nil)
332 regexp))
334 (defcustom message-ignored-cited-headers "."
335 "*Delete these headers from the messages you yank."
336 :group 'message-insertion
337 :type 'regexp)
339 (defcustom message-cancel-message "I am canceling my own article.\n"
340 "Message to be inserted in the cancel message."
341 :group 'message-interface
342 :type 'string)
344 ;; Useful to set in site-init.el
345 ;;;###autoload
346 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
347 "Function to call to send the current buffer as mail.
348 The headers should be delimited by a line whose contents match the
349 variable `mail-header-separator'.
351 Valid values include `message-send-mail-with-sendmail' (the default),
352 `message-send-mail-with-mh', `message-send-mail-with-qmail',
353 `smtpmail-send-it' and `feedmail-send-it'.
355 See also `send-mail-function'."
356 :type '(radio (function-item message-send-mail-with-sendmail)
357 (function-item message-send-mail-with-mh)
358 (function-item message-send-mail-with-qmail)
359 (function-item smtpmail-send-it)
360 (function-item feedmail-send-it)
361 (function :tag "Other"))
362 :group 'message-sending
363 :group 'message-mail)
365 (defcustom message-send-news-function 'message-send-news
366 "Function to call to send the current buffer as news.
367 The headers should be delimited by a line whose contents match the
368 variable `mail-header-separator'."
369 :group 'message-sending
370 :group 'message-news
371 :type 'function)
373 (defcustom message-reply-to-function nil
374 "If non-nil, function that should return a list of headers.
375 This function should pick out addresses from the To, Cc, and From headers
376 and respond with new To and Cc headers."
377 :group 'message-interface
378 :type '(choice function (const nil)))
380 (defcustom message-wide-reply-to-function nil
381 "If non-nil, function that should return a list of headers.
382 This function should pick out addresses from the To, Cc, and From headers
383 and respond with new To and Cc headers."
384 :group 'message-interface
385 :type '(choice function (const nil)))
387 (defcustom message-followup-to-function nil
388 "If non-nil, function that should return a list of headers.
389 This function should pick out addresses from the To, Cc, and From headers
390 and respond with new To and Cc headers."
391 :group 'message-interface
392 :type '(choice function (const nil)))
394 (defcustom message-use-followup-to 'ask
395 "*Specifies what to do with Followup-To header.
396 If nil, always ignore the header. If it is t, use its value, but
397 query before using the \"poster\" value. If it is the symbol `ask',
398 always query the user whether to use the value. If it is the symbol
399 `use', always use the value."
400 :group 'message-interface
401 :type '(choice (const :tag "ignore" nil)
402 (const use)
403 (const ask)))
405 (defcustom message-sendmail-f-is-evil nil
406 "*Non-nil means don't add \"-f username\" to the sendmail command line.
407 Doing so would be even more evil than leaving it out."
408 :group 'message-sending
409 :type 'boolean)
411 ;; qmail-related stuff
412 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
413 "Location of the qmail-inject program."
414 :group 'message-sending
415 :type 'file)
417 (defcustom message-qmail-inject-args nil
418 "Arguments passed to qmail-inject programs.
419 This should be a list of strings, one string for each argument.
421 For e.g., if you wish to set the envelope sender address so that bounces
422 go to the right place or to deal with listserv's usage of that address, you
423 might set this variable to '(\"-f\" \"you@some.where\")."
424 :group 'message-sending
425 :type '(repeat string))
427 (defvar message-cater-to-broken-inn t
428 "Non-nil means Gnus should not fold the `References' header.
429 Folding `References' makes ancient versions of INN create incorrect
430 NOV lines.")
432 (eval-when-compile
433 (defvar gnus-post-method)
434 (defvar gnus-select-method))
435 (defcustom message-post-method
436 (cond ((and (boundp 'gnus-post-method)
437 (listp gnus-post-method)
438 gnus-post-method)
439 gnus-post-method)
440 ((boundp 'gnus-select-method)
441 gnus-select-method)
442 (t '(nnspool "")))
443 "*Method used to post news.
444 Note that when posting from inside Gnus, for instance, this
445 variable isn't used."
446 :group 'message-news
447 :group 'message-sending
448 ;; This should be the `gnus-select-method' widget, but that might
449 ;; create a dependence to `gnus.el'.
450 :type 'sexp)
452 (defcustom message-generate-headers-first nil
453 "*If non-nil, generate all possible headers before composing."
454 :group 'message-headers
455 :type 'boolean)
457 (defcustom message-setup-hook nil
458 "Normal hook, run each time a new outgoing message is initialized.
459 The function `message-setup' runs this hook."
460 :group 'message-various
461 :type 'hook)
463 (defcustom message-cancel-hook nil
464 "Hook run when cancelling articles."
465 :group 'message-various
466 :type 'hook)
468 (defcustom message-signature-setup-hook nil
469 "Normal hook, run each time a new outgoing message is initialized.
470 It is run after the headers have been inserted and before
471 the signature is inserted."
472 :group 'message-various
473 :type 'hook)
475 (defcustom message-mode-hook nil
476 "Hook run in message mode buffers."
477 :group 'message-various
478 :type 'hook)
480 (defcustom message-header-hook nil
481 "Hook run in a message mode buffer narrowed to the headers."
482 :group 'message-various
483 :type 'hook)
485 (defcustom message-header-setup-hook nil
486 "Hook called narrowed to the headers when setting up a message buffer."
487 :group 'message-various
488 :type 'hook)
490 ;;;###autoload
491 (defcustom message-citation-line-function 'message-insert-citation-line
492 "*Function called to insert the \"Whomever writes:\" line."
493 :type 'function
494 :group 'message-insertion)
496 ;;;###autoload
497 (defcustom message-yank-prefix "> "
498 "*Prefix inserted on the lines of yanked messages."
499 :type 'string
500 :group 'message-insertion)
502 (defcustom message-indentation-spaces 3
503 "*Number of spaces to insert at the beginning of each cited line.
504 Used by `message-yank-original' via `message-yank-cite'."
505 :group 'message-insertion
506 :type 'integer)
508 ;;;###autoload
509 (defcustom message-cite-function 'message-cite-original
510 "*Function for citing an original message.
511 Predefined functions include `message-cite-original' and
512 `message-cite-original-without-signature'.
513 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
514 :type '(radio (function-item message-cite-original)
515 (function-item message-cite-original-without-signature)
516 (function-item sc-cite-original)
517 (function :tag "Other"))
518 :group 'message-insertion)
520 ;;;###autoload
521 (defcustom message-indent-citation-function 'message-indent-citation
522 "*Function for modifying a citation just inserted in the mail buffer.
523 This can also be a list of functions. Each function can find the
524 citation between (point) and (mark t). And each function should leave
525 point and mark around the citation text as modified."
526 :type 'function
527 :group 'message-insertion)
529 (defvar message-abbrevs-loaded nil)
531 ;;;###autoload
532 (defcustom message-signature t
533 "*String to be inserted at the end of the message buffer.
534 If t, the `message-signature-file' file will be inserted instead.
535 If a function, the result from the function will be used instead.
536 If a form, the result from the form will be used instead."
537 :type 'sexp
538 :group 'message-insertion)
540 ;;;###autoload
541 (defcustom message-signature-file "~/.signature"
542 "*Name of file containing the text inserted at end of message buffer.
543 Ignored if the named file doesn't exist.
544 If nil, don't insert a signature."
545 :type '(choice file (const :tags "None" nil))
546 :group 'message-insertion)
548 (defcustom message-distribution-function nil
549 "*Function called to return a Distribution header."
550 :group 'message-news
551 :group 'message-headers
552 :type '(choice function (const nil)))
554 (defcustom message-expires 14
555 "Number of days before your article expires."
556 :group 'message-news
557 :group 'message-headers
558 :link '(custom-manual "(message)News Headers")
559 :type 'integer)
561 (defcustom message-user-path nil
562 "If nil, use the NNTP server name in the Path header.
563 If stringp, use this; if non-nil, use no host name (user name only)."
564 :group 'message-news
565 :group 'message-headers
566 :link '(custom-manual "(message)News Headers")
567 :type '(choice (const :tag "nntp" nil)
568 (string :tag "name")
569 (sexp :tag "none" :format "%t" t)))
571 (defvar message-reply-buffer nil)
572 (defvar message-reply-headers nil)
573 (defvar message-newsreader nil)
574 (defvar message-mailer nil)
575 (defvar message-sent-message-via nil)
576 (defvar message-checksum nil)
577 (defvar message-send-actions nil
578 "A list of actions to be performed upon successful sending of a message.")
579 (defvar message-exit-actions nil
580 "A list of actions to be performed upon exiting after sending a message.")
581 (defvar message-kill-actions nil
582 "A list of actions to be performed before killing a message buffer.")
583 (defvar message-postpone-actions nil
584 "A list of actions to be performed after postponing a message.")
586 (define-widget 'message-header-lines 'text
587 "All header lines must be LFD terminated."
588 :format "%{%t%}:%n%v"
589 :valid-regexp "^\\'"
590 :error "All header lines must be newline terminated")
592 (defcustom message-default-headers ""
593 "*A string containing header lines to be inserted in outgoing messages.
594 It is inserted before you edit the message, so you can edit or delete
595 these lines."
596 :group 'message-headers
597 :type 'message-header-lines)
599 (defcustom message-default-mail-headers ""
600 "*A string of header lines to be inserted in outgoing mails."
601 :group 'message-headers
602 :group 'message-mail
603 :type 'message-header-lines)
605 (defcustom message-default-news-headers ""
606 "*A string of header lines to be inserted in outgoing news articles."
607 :group 'message-headers
608 :group 'message-news
609 :type 'message-header-lines)
611 ;; Note: could use /usr/ucb/mail instead of sendmail;
612 ;; options -t, and -v if not interactive.
613 (defcustom message-mailer-swallows-blank-line
614 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
615 system-configuration)
616 (file-readable-p "/etc/sendmail.cf")
617 (let ((buffer (get-buffer-create " *temp*")))
618 (unwind-protect
619 (save-excursion
620 (set-buffer buffer)
621 (insert-file-contents "/etc/sendmail.cf")
622 (goto-char (point-min))
623 (let ((case-fold-search nil))
624 (re-search-forward "^OR\\>" nil t)))
625 (kill-buffer buffer))))
626 ;; According to RFC822, "The field-name must be composed of printable
627 ;; ASCII characters (i. e., characters that have decimal values between
628 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
629 ;; space, or colon.
630 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
631 "*Set this non-nil if the system's mailer runs the header and body together.
632 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
633 The value should be an expression to test whether the problem will
634 actually occur."
635 :group 'message-sending
636 :type 'sexp)
638 ;;;###autoload
639 (define-mail-user-agent 'message-user-agent
640 'message-mail 'message-send-and-exit
641 'message-kill-buffer 'message-send-hook)
643 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
644 "If non-nil, delete the deletable headers before feeding to mh.")
646 (defvar message-send-method-alist
647 '((news message-news-p message-send-via-news)
648 (mail message-mail-p message-send-via-mail))
649 "Alist of ways to send outgoing messages.
650 Each element has the form
652 \(TYPE PREDICATE FUNCTION)
654 where TYPE is a symbol that names the method; PREDICATE is a function
655 called without any parameters to determine whether the message is
656 a message of type TYPE; and FUNCTION is a function to be called if
657 PREDICATE returns non-nil. FUNCTION is called with one parameter --
658 the prefix.")
660 (defcustom message-mail-alias-type 'abbrev
661 "*What alias expansion type to use in Message buffers.
662 The default is `abbrev', which uses mailabbrev. nil switches
663 mail aliases off."
664 :group 'message
665 :link '(custom-manual "(message)Mail Aliases")
666 :type '(choice (const :tag "Use Mailabbrev" abbrev)
667 (const :tag "No expansion" nil)))
669 (defcustom message-auto-save-directory
670 (file-name-as-directory (nnheader-concat message-directory "drafts"))
671 "*Directory where Message auto-saves buffers if Gnus isn't running.
672 If nil, Message won't auto-save."
673 :group 'message-buffers
674 :type '(choice directory (const :tag "Don't auto-save" nil)))
676 (defcustom message-buffer-naming-style 'unique
677 "*The way new message buffers are named.
678 Valid values are `unique' and `unsent'."
679 :version "21.1"
680 :group 'message-buffers
681 :type '(choice (const :tag "unique" unique)
682 (const :tag "unsent" unsent)))
684 (defcustom message-default-charset
685 (and (not (mm-multibyte-p)) 'iso-8859-1)
686 "Default charset used in non-MULE Emacsen.
687 If nil, you might be asked to input the charset."
688 :version "21.1"
689 :group 'message
690 :type 'symbol)
692 (defcustom message-dont-reply-to-names
693 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
694 "*A regexp specifying names to prune when doing wide replies.
695 A value of nil means exclude your own name only."
696 :version "21.1"
697 :group 'message
698 :type '(choice (const :tag "Yourself" nil)
699 regexp))
701 ;;; Internal variables.
702 ;;; Well, not really internal.
704 (defvar message-mode-syntax-table
705 (let ((table (copy-syntax-table text-mode-syntax-table)))
706 (modify-syntax-entry ?% ". " table)
707 (modify-syntax-entry ?> ". " table)
708 (modify-syntax-entry ?< ". " table)
709 table)
710 "Syntax table used while in Message mode.")
712 (defvar message-mode-abbrev-table text-mode-abbrev-table
713 "Abbrev table used in Message mode buffers.
714 Defaults to `text-mode-abbrev-table'.")
716 (defface message-header-to-face
717 '((((class color)
718 (background dark))
719 (:foreground "green2" :weight bold))
720 (((class color)
721 (background light))
722 (:foreground "MidnightBlue" :weight bold))
724 (:weight bold :slant italic)))
725 "Face used for displaying From headers."
726 :group 'message-faces)
728 (defface message-header-cc-face
729 '((((class color)
730 (background dark))
731 (:foreground "green4" :weight bold))
732 (((class color)
733 (background light))
734 (:foreground "MidnightBlue"))
736 (:weight bold)))
737 "Face used for displaying Cc headers."
738 :group 'message-faces)
740 (defface message-header-subject-face
741 '((((class color)
742 (background dark))
743 (:foreground "green3"))
744 (((class color)
745 (background light))
746 (:foreground "navy blue" :weight bold))
748 (:weight bold)))
749 "Face used for displaying subject headers."
750 :group 'message-faces)
752 (defface message-header-newsgroups-face
753 '((((class color)
754 (background dark))
755 (:foreground "yellow" :weight bold :slant italic))
756 (((class color)
757 (background light))
758 (:foreground "blue4" :weight bold :slant italic))
760 (:weight bold :slant italic)))
761 "Face used for displaying newsgroups headers."
762 :group 'message-faces)
764 (defface message-header-other-face
765 '((((class color)
766 (background dark))
767 (:foreground "#b00000"))
768 (((class color)
769 (background light))
770 (:foreground "steel blue"))
772 (:weight bold :slant italic)))
773 "Face used for displaying newsgroups headers."
774 :group 'message-faces)
776 (defface message-header-name-face
777 '((((class color)
778 (background dark))
779 (:foreground "DarkGreen"))
780 (((class color)
781 (background light))
782 (:foreground "cornflower blue"))
784 (:weight bold)))
785 "Face used for displaying header names."
786 :group 'message-faces)
788 (defface message-header-xheader-face
789 '((((class color)
790 (background dark))
791 (:foreground "blue"))
792 (((class color)
793 (background light))
794 (:foreground "blue"))
796 (:weight bold)))
797 "Face used for displaying X-Header headers."
798 :group 'message-faces)
800 (defface message-separator-face
801 '((((class color)
802 (background dark))
803 (:foreground "blue3"))
804 (((class color)
805 (background light))
806 (:foreground "brown"))
808 (:weight bold)))
809 "Face used for displaying the separator."
810 :group 'message-faces)
812 (defface message-cited-text-face
813 '((((class color)
814 (background dark))
815 (:foreground "red"))
816 (((class color)
817 (background light))
818 (:foreground "red"))
820 (:weight bold)))
821 "Face used for displaying cited text names."
822 :group 'message-faces)
824 (defface message-mml-face
825 '((((class color)
826 (background dark))
827 (:foreground "ForestGreen"))
828 (((class color)
829 (background light))
830 (:foreground "ForestGreen"))
832 (:weight bold)))
833 "Face used for displaying MML."
834 :group 'message-faces)
836 (defvar message-font-lock-keywords
837 (let* ((cite-prefix "[:alpha:]")
838 (cite-suffix (concat cite-prefix "0-9_.@-"))
839 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
840 `((,(concat "^\\([Tt]o:\\)" content)
841 (1 'message-header-name-face)
842 (2 'message-header-to-face nil t))
843 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
844 (1 'message-header-name-face)
845 (2 'message-header-cc-face nil t))
846 (,(concat "^\\([Ss]ubject:\\)" content)
847 (1 'message-header-name-face)
848 (2 'message-header-subject-face nil t))
849 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
850 (1 'message-header-name-face)
851 (2 'message-header-newsgroups-face nil t))
852 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
853 (1 'message-header-name-face)
854 (2 'message-header-other-face nil t))
855 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
856 (1 'message-header-name-face)
857 (2 'message-header-name-face))
858 ,@(if (and mail-header-separator
859 (not (equal mail-header-separator "")))
860 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
861 1 'message-separator-face))
862 nil)
863 (,(concat "^[ \t]*"
864 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
865 "[:>|}].*")
866 (0 'message-cited-text-face))
867 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
868 (0 'message-mml-face))))
869 "Additional expressions to highlight in Message mode.")
871 ;; XEmacs does it like this. For Emacs, we have to set the
872 ;; `font-lock-defaults' buffer-local variable.
873 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
875 (defvar message-face-alist
876 '((bold . bold-region)
877 (underline . underline-region)
878 (default . (lambda (b e)
879 (unbold-region b e)
880 (ununderline-region b e))))
881 "Alist of mail and news faces for facemenu.
882 The cdr of each entry is a function for applying the face to a region.")
884 (defcustom message-send-hook nil
885 "Hook run before sending messages."
886 :group 'message-various
887 :options '(ispell-message)
888 :type 'hook)
890 (defcustom message-send-mail-hook nil
891 "Hook run before sending mail messages."
892 :group 'message-various
893 :type 'hook)
895 (defcustom message-send-news-hook nil
896 "Hook run before sending news messages."
897 :group 'message-various
898 :type 'hook)
900 (defcustom message-sent-hook nil
901 "Hook run after sending messages."
902 :group 'message-various
903 :type 'hook)
905 (defvar message-send-coding-system 'binary
906 "Coding system to encode outgoing mail.")
908 (defvar message-draft-coding-system
909 mm-auto-save-coding-system
910 "Coding system to compose mail.")
912 (defcustom message-send-mail-partially-limit 1000000
913 "The limitation of messages sent as message/partial.
914 The lower bound of message size in characters, beyond which the message
915 should be sent in several parts. If it is nil, the size is unlimited."
916 :version "21.1"
917 :group 'message-buffers
918 :type '(choice (const :tag "unlimited" nil)
919 (integer 1000000)))
921 (defcustom message-alternative-emails nil
922 "A regexp to match the alternative email addresses.
923 The first matched address (not primary one) is used in the From field."
924 :group 'message-headers
925 :type '(choice (const :tag "Always use primary" nil)
926 regexp))
928 (defcustom message-mail-user-agent nil
929 "Like `mail-user-agent'.
930 Except if it is nil, use Gnus native MUA; if it is t, use
931 `mail-user-agent'."
932 :type '(radio (const :tag "Gnus native"
933 :format "%t\n"
934 nil)
935 (const :tag "`mail-user-agent'"
936 :format "%t\n"
938 (function-item :tag "Default Emacs mail"
939 :format "%t\n"
940 sendmail-user-agent)
941 (function-item :tag "Emacs interface to MH"
942 :format "%t\n"
943 mh-e-user-agent)
944 (function :tag "Other"))
945 :version "21.1"
946 :group 'message)
948 ;;; Internal variables.
950 (defvar message-sending-message "Sending...")
951 (defvar message-buffer-list nil)
952 (defvar message-this-is-news nil)
953 (defvar message-this-is-mail nil)
954 (defvar message-draft-article nil)
955 (defvar message-mime-part nil)
956 (defvar message-posting-charset nil)
958 ;; Byte-compiler warning
959 (eval-when-compile
960 (defvar gnus-active-hashtb)
961 (defvar gnus-read-active-file))
963 ;;; Regexp matching the delimiter of messages in UNIX mail format
964 ;;; (UNIX From lines), minus the initial ^. It should be a copy
965 ;;; of rmail.el's rmail-unix-mail-delimiter.
966 (defvar message-unix-mail-delimiter
967 (let ((time-zone-regexp
968 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
969 "\\|[-+]?[0-9][0-9][0-9][0-9]"
970 "\\|"
971 "\\) *")))
972 (concat
973 "From "
975 ;; Many things can happen to an RFC 822 mailbox before it is put into
976 ;; a `From' line. The leading phrase can be stripped, e.g.
977 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
978 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
979 ;; can be removed, e.g.
980 ;; From: joe@y.z (Joe K
981 ;; User)
982 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
983 ;; From: Joe User
984 ;; <joe@y.z>
985 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
986 ;; The mailbox can be removed or be replaced by white space, e.g.
987 ;; From: "Joe User"{space}{tab}
988 ;; <joe@y.z>
989 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
990 ;; where {space} and {tab} represent the Ascii space and tab characters.
991 ;; We want to match the results of any of these manglings.
992 ;; The following regexp rejects names whose first characters are
993 ;; obviously bogus, but after that anything goes.
994 "\\([^\0-\b\n-\r\^?].*\\)? "
996 ;; The time the message was sent.
997 "\\([^\0-\r \^?]+\\) +" ; day of the week
998 "\\([^\0-\r \^?]+\\) +" ; month
999 "\\([0-3]?[0-9]\\) +" ; day of month
1000 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1002 ;; Perhaps a time zone, specified by an abbreviation, or by a
1003 ;; numeric offset.
1004 time-zone-regexp
1006 ;; The year.
1007 " \\([0-9][0-9]+\\) *"
1009 ;; On some systems the time zone can appear after the year, too.
1010 time-zone-regexp
1012 ;; Old uucp cruft.
1013 "\\(remote from .*\\)?"
1015 "\n"))
1016 "Regexp matching the delimiter of messages in UNIX mail format.")
1018 (defvar message-unsent-separator
1019 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1020 "^ *---+ +Returned message +---+ *$\\|"
1021 "^Start of returned message$\\|"
1022 "^ *---+ +Original message +---+ *$\\|"
1023 "^ *--+ +begin message +--+ *$\\|"
1024 "^ *---+ +Original message follows +---+ *$\\|"
1025 "^ *---+ +Undelivered message follows +---+ *$\\|"
1026 "^|? *---+ +Message text follows: +---+ *|?$")
1027 "A regexp that matches the separator before the text of a failed message.")
1029 (defvar message-header-format-alist
1030 `((Newsgroups)
1031 (To . message-fill-address)
1032 (Cc . message-fill-address)
1033 (Subject)
1034 (In-Reply-To)
1035 (Fcc)
1036 (Bcc)
1037 (Date)
1038 (Organization)
1039 (Distribution)
1040 (Lines)
1041 (Expires)
1042 (Message-ID)
1043 (References . message-shorten-references)
1044 (User-Agent))
1045 "Alist used for formatting headers.")
1047 (eval-and-compile
1048 (autoload 'message-setup-toolbar "messagexmas")
1049 (autoload 'mh-new-draft-name "mh-comp")
1050 (autoload 'mh-send-letter "mh-comp")
1051 (autoload 'gnus-point-at-eol "gnus-util")
1052 (autoload 'gnus-point-at-bol "gnus-util")
1053 (autoload 'gnus-output-to-rmail "gnus-util")
1054 (autoload 'gnus-output-to-mail "gnus-util")
1055 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1056 (autoload 'nndraft-request-associate-buffer "nndraft")
1057 (autoload 'nndraft-request-expire-articles "nndraft")
1058 (autoload 'gnus-open-server "gnus-int")
1059 (autoload 'gnus-request-post "gnus-int")
1060 (autoload 'gnus-alive-p "gnus-util")
1061 (autoload 'gnus-group-name-charset "gnus-group")
1062 (autoload 'rmail-output "rmailout"))
1067 ;;; Utility functions.
1070 (defmacro message-y-or-n-p (question show &rest text)
1071 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1072 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1074 (defmacro message-delete-line (&optional n)
1075 "Delete the current line (and the next N lines)."
1076 `(delete-region (progn (beginning-of-line) (point))
1077 (progn (forward-line ,(or n 1)) (point))))
1079 (defun message-unquote-tokens (elems)
1080 "Remove double quotes (\") from strings in list ELEMS."
1081 (mapcar (lambda (item)
1082 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1083 (setq item (concat (match-string 1 item)
1084 (match-string 2 item))))
1085 item)
1086 elems))
1088 (defun message-tokenize-header (header &optional separator)
1089 "Split HEADER into a list of header elements.
1090 SEPARATOR is a string of characters to be used as separators. \",\"
1091 is used by default."
1092 (if (not header)
1094 (let ((regexp (format "[%s]+" (or separator ",")))
1095 (beg 1)
1096 (first t)
1097 quoted elems paren)
1098 (save-excursion
1099 (message-set-work-buffer)
1100 (insert header)
1101 (goto-char (point-min))
1102 (while (not (eobp))
1103 (if first
1104 (setq first nil)
1105 (forward-char 1))
1106 (cond ((and (> (point) beg)
1107 (or (eobp)
1108 (and (looking-at regexp)
1109 (not quoted)
1110 (not paren))))
1111 (push (buffer-substring beg (point)) elems)
1112 (setq beg (match-end 0)))
1113 ((eq (char-after) ?\")
1114 (setq quoted (not quoted)))
1115 ((and (eq (char-after) ?\()
1116 (not quoted))
1117 (setq paren t))
1118 ((and (eq (char-after) ?\))
1119 (not quoted))
1120 (setq paren nil))))
1121 (nreverse elems)))))
1123 (defun message-mail-file-mbox-p (file)
1124 "Say whether FILE looks like a Unix mbox file."
1125 (when (and (file-exists-p file)
1126 (file-readable-p file)
1127 (file-regular-p file))
1128 (with-temp-buffer
1129 (nnheader-insert-file-contents file)
1130 (goto-char (point-min))
1131 (looking-at message-unix-mail-delimiter))))
1133 (defun message-fetch-field (header &optional not-all)
1134 "The same as `mail-fetch-field', only remove all newlines."
1135 (let* ((inhibit-point-motion-hooks t)
1136 (case-fold-search t)
1137 (value (mail-fetch-field header nil (not not-all))))
1138 (when value
1139 (while (string-match "\n[\t ]+" value)
1140 (setq value (replace-match " " t t value)))
1141 (set-text-properties 0 (length value) nil value)
1142 value)))
1144 (defun message-narrow-to-field ()
1145 "Narrow the buffer to the header on the current line."
1146 (beginning-of-line)
1147 (narrow-to-region
1148 (point)
1149 (progn
1150 (forward-line 1)
1151 (if (re-search-forward "^[^ \n\t]" nil t)
1152 (progn
1153 (beginning-of-line)
1154 (point))
1155 (point-max))))
1156 (goto-char (point-min)))
1158 (defun message-add-header (&rest headers)
1159 "Add the HEADERS to the message header, skipping those already present."
1160 (while headers
1161 (let (hclean)
1162 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1163 (error "Invalid header `%s'" (car headers)))
1164 (setq hclean (match-string 1 (car headers)))
1165 (save-restriction
1166 (message-narrow-to-headers)
1167 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1168 (insert (car headers) ?\n))))
1169 (setq headers (cdr headers))))
1172 (defun message-fetch-reply-field (header)
1173 "Fetch field HEADER from the message we're replying to."
1174 (when (and message-reply-buffer
1175 (buffer-name message-reply-buffer))
1176 (save-excursion
1177 (set-buffer message-reply-buffer)
1178 (message-fetch-field header))))
1180 (defun message-set-work-buffer ()
1181 (if (get-buffer " *message work*")
1182 (progn
1183 (set-buffer " *message work*")
1184 (erase-buffer))
1185 (set-buffer (get-buffer-create " *message work*"))
1186 (kill-all-local-variables)
1187 (mm-enable-multibyte)))
1189 (defun message-functionp (form)
1190 "Return non-nil if FORM is funcallable."
1191 (or (and (symbolp form) (fboundp form))
1192 (and (listp form) (eq (car form) 'lambda))
1193 (byte-code-function-p form)))
1195 (defun message-strip-list-identifiers (subject)
1196 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1197 (require 'gnus-sum) ; for gnus-list-identifiers
1198 (let ((regexp (if (stringp gnus-list-identifiers)
1199 gnus-list-identifiers
1200 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1201 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1202 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1203 (concat (substring subject 0 (match-beginning 1))
1204 (or (match-string 3 subject)
1205 (match-string 5 subject))
1206 (substring subject
1207 (match-end 1)))
1208 subject)))
1210 (defun message-strip-subject-re (subject)
1211 "Remove \"Re:\" from subject lines in string SUBJECT."
1212 (if (string-match message-subject-re-regexp subject)
1213 (substring subject (match-end 0))
1214 subject))
1216 (defun message-remove-header (header &optional is-regexp first reverse)
1217 "Remove HEADER in the narrowed buffer.
1218 If IS-REGEXP, HEADER is a regular expression.
1219 If FIRST, only remove the first instance of the header.
1220 Return the number of headers removed."
1221 (goto-char (point-min))
1222 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1223 (number 0)
1224 (case-fold-search t)
1225 last)
1226 (while (and (not (eobp))
1227 (not last))
1228 (if (if reverse
1229 (not (looking-at regexp))
1230 (looking-at regexp))
1231 (progn
1232 (incf number)
1233 (when first
1234 (setq last t))
1235 (delete-region
1236 (point)
1237 ;; There might be a continuation header, so we have to search
1238 ;; until we find a new non-continuation line.
1239 (progn
1240 (forward-line 1)
1241 (if (re-search-forward "^[^ \t]" nil t)
1242 (goto-char (match-beginning 0))
1243 (point-max)))))
1244 (forward-line 1)
1245 (if (re-search-forward "^[^ \t]" nil t)
1246 (goto-char (match-beginning 0))
1247 (goto-char (point-max)))))
1248 number))
1250 (defun message-remove-first-header (header)
1251 "Remove the first instance of HEADER if there is more than one."
1252 (let ((count 0)
1253 (regexp (concat "^" (regexp-quote header) ":")))
1254 (save-excursion
1255 (goto-char (point-min))
1256 (while (re-search-forward regexp nil t)
1257 (incf count)))
1258 (while (> count 1)
1259 (message-remove-header header nil t)
1260 (decf count))))
1262 (defun message-narrow-to-headers ()
1263 "Narrow the buffer to the head of the message."
1264 (widen)
1265 (narrow-to-region
1266 (goto-char (point-min))
1267 (if (re-search-forward
1268 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1269 (match-beginning 0)
1270 (point-max)))
1271 (goto-char (point-min)))
1273 (defun message-narrow-to-head-1 ()
1274 "Like `message-narrow-to-head'. Don't widen."
1275 (narrow-to-region
1276 (goto-char (point-min))
1277 (if (search-forward "\n\n" nil 1)
1278 (1- (point))
1279 (point-max)))
1280 (goto-char (point-min)))
1282 (defun message-narrow-to-head ()
1283 "Narrow the buffer to the head of the message.
1284 Point is left at the beginning of the narrowed-to region."
1285 (widen)
1286 (message-narrow-to-head-1))
1288 (defun message-narrow-to-headers-or-head ()
1289 "Narrow the buffer to the head of the message."
1290 (widen)
1291 (narrow-to-region
1292 (goto-char (point-min))
1293 (cond
1294 ((re-search-forward
1295 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1296 (match-beginning 0))
1297 ((search-forward "\n\n" nil t)
1298 (1- (point)))
1300 (point-max))))
1301 (goto-char (point-min)))
1303 (defun message-news-p ()
1304 "Say whether the current buffer contains a news message."
1305 (and (not message-this-is-mail)
1306 (or message-this-is-news
1307 (save-excursion
1308 (save-restriction
1309 (message-narrow-to-headers)
1310 (and (message-fetch-field "newsgroups")
1311 (not (message-fetch-field "posted-to"))))))))
1313 (defun message-mail-p ()
1314 "Say whether the current buffer contains a mail message."
1315 (and (not message-this-is-news)
1316 (or message-this-is-mail
1317 (save-excursion
1318 (save-restriction
1319 (message-narrow-to-headers)
1320 (or (message-fetch-field "to")
1321 (message-fetch-field "cc")
1322 (message-fetch-field "bcc")))))))
1324 (defun message-next-header ()
1325 "Go to the beginning of the next header."
1326 (beginning-of-line)
1327 (or (eobp) (forward-char 1))
1328 (not (if (re-search-forward "^[^ \t]" nil t)
1329 (beginning-of-line)
1330 (goto-char (point-max)))))
1332 (defun message-sort-headers-1 ()
1333 "Sort the buffer as headers using `message-rank' text props."
1334 (goto-char (point-min))
1335 (require 'sort)
1336 (sort-subr
1337 nil 'message-next-header
1338 (lambda ()
1339 (message-next-header)
1340 (unless (bobp)
1341 (forward-char -1)))
1342 (lambda ()
1343 (or (get-text-property (point) 'message-rank)
1344 10000))))
1346 (defun message-sort-headers ()
1347 "Sort the headers of the current message according to `message-header-format-alist'."
1348 (interactive)
1349 (save-excursion
1350 (save-restriction
1351 (let ((max (1+ (length message-header-format-alist)))
1352 rank)
1353 (message-narrow-to-headers)
1354 (while (re-search-forward "^[^ \n]+:" nil t)
1355 (put-text-property
1356 (match-beginning 0) (1+ (match-beginning 0))
1357 'message-rank
1358 (if (setq rank (length (memq (assq (intern (buffer-substring
1359 (match-beginning 0)
1360 (1- (match-end 0))))
1361 message-header-format-alist)
1362 message-header-format-alist)))
1363 (- max rank)
1364 (1+ max)))))
1365 (message-sort-headers-1))))
1370 ;;; Message mode
1373 ;;; Set up keymap.
1375 (defvar message-mode-map nil)
1377 (unless message-mode-map
1378 (setq message-mode-map (make-keymap))
1379 (set-keymap-parent message-mode-map text-mode-map)
1380 (define-key message-mode-map "\C-c?" 'describe-mode)
1382 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1383 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1384 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1385 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1386 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1387 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1388 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1389 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1390 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1391 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1392 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1393 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1394 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1396 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1397 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1399 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1400 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1401 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1402 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1403 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1404 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1405 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1406 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1408 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1409 (define-key message-mode-map "\C-c\C-s" 'message-send)
1410 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1411 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1413 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1414 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1415 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1416 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1417 (define-key message-mode-map [remap split-line] 'message-split-line)
1419 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1421 (define-key message-mode-map "\t" 'message-tab))
1423 (easy-menu-define
1424 message-mode-menu message-mode-map "Message Menu."
1425 '("Message"
1426 ["Sort Headers" message-sort-headers t]
1427 ["Yank Original" message-yank-original t]
1428 ["Fill Yanked Message" message-fill-yanked-message t]
1429 ["Insert Signature" message-insert-signature t]
1430 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1431 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1432 ["Elide Region" message-elide-region (mark t)]
1433 ["Delete Outside Region" message-delete-not-region (mark t)]
1434 ["Kill To Signature" message-kill-to-signature t]
1435 ["Newline and Reformat" message-newline-and-reformat t]
1436 ["Rename buffer" message-rename-buffer t]
1437 ["Spellcheck" ispell-message
1438 :help "Spellcheck this message"]
1439 ["Attach file as MIME" mml-attach-file
1440 :help "Attach a file at point"]
1441 "----"
1442 ["Send Message" message-send-and-exit
1443 :help "Send this message"]
1444 ["Abort Message" message-dont-send
1445 :help "File this draft message and exit"]
1446 ["Kill Message" message-kill-buffer
1447 :help "Delete this message without sending"]))
1449 (easy-menu-define
1450 message-mode-field-menu message-mode-map ""
1451 '("Field"
1452 ["Fetch To" message-insert-to t]
1453 ["Fetch Newsgroups" message-insert-newsgroups t]
1454 "----"
1455 ["To" message-goto-to t]
1456 ["Subject" message-goto-subject t]
1457 ["Cc" message-goto-cc t]
1458 ["Reply-To" message-goto-reply-to t]
1459 ["Summary" message-goto-summary t]
1460 ["Keywords" message-goto-keywords t]
1461 ["Newsgroups" message-goto-newsgroups t]
1462 ["Followup-To" message-goto-followup-to t]
1463 ["Distribution" message-goto-distribution t]
1464 ["Body" message-goto-body t]
1465 ["Signature" message-goto-signature t]))
1467 (eval-when-compile
1468 (defvar facemenu-add-face-function)
1469 (defvar facemenu-remove-face-function))
1471 ;;;###autoload
1472 (defun message-mode ()
1473 "Major mode for editing mail and news to be sent.
1474 Like Text Mode but with these additional commands:\\<message-mode-map>
1475 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1476 C-c C-d Postpone sending the message C-c C-k Kill the message
1477 C-c C-f move to a header field (and create it if there isn't):
1478 C-c C-f C-t move to To C-c C-f C-s move to Subject
1479 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1480 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1481 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1482 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1483 C-c C-f C-f move to Followup-To
1484 C-c C-t `message-insert-to' (add a To header to a news followup)
1485 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1486 C-c C-b `message-goto-body' (move to beginning of message text).
1487 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1488 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1489 C-c C-y `message-yank-original' (insert current message, if any).
1490 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1491 C-c C-e `message-elide-region' (elide the text between point and mark).
1492 C-c C-v `message-delete-not-region' (remove the text outside the region).
1493 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1494 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1495 C-c C-a `mml-attach-file' (attach a file as MIME).
1496 M-RET `message-newline-and-reformat' (break the line and reformat)."
1497 (interactive)
1498 (if (local-variable-p 'mml-buffer-list (current-buffer))
1499 (mml-destroy-buffers))
1500 (kill-all-local-variables)
1501 (set (make-local-variable 'message-reply-buffer) nil)
1502 (make-local-variable 'message-send-actions)
1503 (make-local-variable 'message-exit-actions)
1504 (make-local-variable 'message-kill-actions)
1505 (make-local-variable 'message-postpone-actions)
1506 (make-local-variable 'message-draft-article)
1507 (make-local-hook 'kill-buffer-hook)
1508 (set-syntax-table message-mode-syntax-table)
1509 (use-local-map message-mode-map)
1510 (setq local-abbrev-table message-mode-abbrev-table)
1511 (setq major-mode 'message-mode)
1512 (setq mode-name "Message")
1513 (setq buffer-offer-save t)
1514 (make-local-variable 'facemenu-add-face-function)
1515 (make-local-variable 'facemenu-remove-face-function)
1516 (setq facemenu-add-face-function
1517 (lambda (face end)
1518 (let ((face-fun (cdr (assq face message-face-alist))))
1519 (if face-fun
1520 (funcall face-fun (point) end)
1521 (error "Face %s not configured for %s mode" face mode-name)))
1523 facemenu-remove-face-function t)
1524 (make-local-variable 'message-reply-headers)
1525 (setq message-reply-headers nil)
1526 (make-local-variable 'message-newsreader)
1527 (make-local-variable 'message-mailer)
1528 (make-local-variable 'message-post-method)
1529 (set (make-local-variable 'message-sent-message-via) nil)
1530 (set (make-local-variable 'message-checksum) nil)
1531 (set (make-local-variable 'message-mime-part) 0)
1532 (message-setup-fill-variables)
1533 ;; Allow using comment commands to add/remove quoting.
1534 (set (make-local-variable 'comment-start) message-yank-prefix)
1535 ;;(when (fboundp 'mail-hist-define-keys)
1536 ;; (mail-hist-define-keys))
1537 (if (featurep 'xemacs)
1538 (message-setup-toolbar)
1539 (set (make-local-variable 'font-lock-defaults)
1540 '(message-font-lock-keywords t))
1541 (if (boundp 'message-tool-bar-map)
1542 (set (make-local-variable 'tool-bar-map) message-tool-bar-map)))
1543 (easy-menu-add message-mode-menu message-mode-map)
1544 (easy-menu-add message-mode-field-menu message-mode-map)
1545 ;; Allow mail alias things.
1546 (when (eq message-mail-alias-type 'abbrev)
1547 (if (fboundp 'mail-abbrevs-setup)
1548 (mail-abbrevs-setup)
1549 (mail-aliases-setup)))
1550 (unless buffer-file-name
1551 (message-set-auto-save-file-name))
1552 (mm-enable-multibyte)
1553 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1554 (setq indent-tabs-mode nil)
1555 (mml-mode)
1556 (run-hooks 'text-mode-hook 'message-mode-hook))
1558 (defun message-setup-fill-variables ()
1559 "Setup message fill variables."
1560 (make-local-variable 'paragraph-separate)
1561 (make-local-variable 'paragraph-start)
1562 (make-local-variable 'adaptive-fill-regexp)
1563 (unless (boundp 'adaptive-fill-first-line-regexp)
1564 (setq adaptive-fill-first-line-regexp nil))
1565 (make-local-variable 'adaptive-fill-first-line-regexp)
1566 (make-local-variable 'auto-fill-inhibit-regexp)
1567 (let ((quote-prefix-regexp
1568 (concat
1569 "[ \t]*" ; possible initial space
1570 "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
1571 "\\w+>\\|" ; supercite-style prefix
1572 "[|:>]" ; standard prefix
1573 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1574 (setq paragraph-start
1575 (concat
1576 (regexp-quote mail-header-separator) "$\\|"
1577 "[ \t]*$\\|" ; blank lines
1578 "-- $\\|" ; signature delimiter
1579 "---+$\\|" ; delimiters for forwarded messages
1580 page-delimiter "$\\|" ; spoiler warnings
1581 ".*wrote:$\\|" ; attribution lines
1582 quote-prefix-regexp "$")) ; empty lines in quoted text
1583 (setq paragraph-separate paragraph-start)
1584 (setq adaptive-fill-regexp
1585 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1586 (setq adaptive-fill-first-line-regexp
1587 (concat quote-prefix-regexp "\\|"
1588 adaptive-fill-first-line-regexp))
1589 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1594 ;;; Message mode commands
1597 ;;; Movement commands
1599 (defun message-goto-to ()
1600 "Move point to the To header."
1601 (interactive)
1602 (message-position-on-field "To"))
1604 (defun message-goto-subject ()
1605 "Move point to the Subject header."
1606 (interactive)
1607 (message-position-on-field "Subject"))
1609 (defun message-goto-cc ()
1610 "Move point to the Cc header."
1611 (interactive)
1612 (message-position-on-field "Cc" "To"))
1614 (defun message-goto-bcc ()
1615 "Move point to the Bcc header."
1616 (interactive)
1617 (message-position-on-field "Bcc" "Cc" "To"))
1619 (defun message-goto-fcc ()
1620 "Move point to the Fcc header."
1621 (interactive)
1622 (message-position-on-field "Fcc" "To" "Newsgroups"))
1624 (defun message-goto-reply-to ()
1625 "Move point to the Reply-To header."
1626 (interactive)
1627 (message-position-on-field "Reply-To" "Subject"))
1629 (defun message-goto-newsgroups ()
1630 "Move point to the Newsgroups header."
1631 (interactive)
1632 (message-position-on-field "Newsgroups"))
1634 (defun message-goto-distribution ()
1635 "Move point to the Distribution header."
1636 (interactive)
1637 (message-position-on-field "Distribution"))
1639 (defun message-goto-followup-to ()
1640 "Move point to the Followup-To header."
1641 (interactive)
1642 (message-position-on-field "Followup-To" "Newsgroups"))
1644 (defun message-goto-keywords ()
1645 "Move point to the Keywords header."
1646 (interactive)
1647 (message-position-on-field "Keywords" "Subject"))
1649 (defun message-goto-summary ()
1650 "Move point to the Summary header."
1651 (interactive)
1652 (message-position-on-field "Summary" "Subject"))
1654 (defun message-goto-body ()
1655 "Move point to the beginning of the message body."
1656 (interactive)
1657 (if (looking-at "[ \t]*\n") (expand-abbrev))
1658 (goto-char (point-min))
1659 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1660 (search-forward "\n\n" nil t)))
1662 (defun message-goto-eoh ()
1663 "Move point to the end of the headers."
1664 (interactive)
1665 (message-goto-body)
1666 (forward-line -1))
1668 (defun message-goto-signature ()
1669 "Move point to the beginning of the message signature.
1670 If there is no signature in the article, go to the end and
1671 return nil."
1672 (interactive)
1673 (goto-char (point-min))
1674 (if (re-search-forward message-signature-separator nil t)
1675 (forward-line 1)
1676 (goto-char (point-max))
1677 nil))
1681 (defun message-insert-to (&optional force)
1682 "Insert a To header that points to the author of the article being replied to.
1683 If the original author requested not to be sent mail, the function signals
1684 an error.
1685 With the prefix argument FORCE, insert the header anyway."
1686 (interactive "P")
1687 (let ((co (message-fetch-reply-field "mail-copies-to")))
1688 (when (and (null force)
1690 (or (equal (downcase co) "never")
1691 (equal (downcase co) "nobody")))
1692 (error "The user has requested not to have copies sent via mail")))
1693 (when (and (message-position-on-field "To")
1694 (mail-fetch-field "to")
1695 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1696 (insert ", "))
1697 (insert (or (message-fetch-reply-field "reply-to")
1698 (message-fetch-reply-field "from") "")))
1700 (defun message-widen-reply ()
1701 "Widen the reply to include maximum recipients."
1702 (interactive)
1703 (let ((follow-to
1704 (and message-reply-buffer
1705 (buffer-name message-reply-buffer)
1706 (save-excursion
1707 (set-buffer message-reply-buffer)
1708 (message-get-reply-headers t)))))
1709 (save-excursion
1710 (save-restriction
1711 (message-narrow-to-headers)
1712 (dolist (elem follow-to)
1713 (message-remove-header (symbol-name (car elem)))
1714 (goto-char (point-min))
1715 (insert (symbol-name (car elem)) ": "
1716 (cdr elem) "\n"))))))
1718 (defun message-insert-newsgroups ()
1719 "Insert the Newsgroups header from the article being replied to."
1720 (interactive)
1721 (when (and (message-position-on-field "Newsgroups")
1722 (mail-fetch-field "newsgroups")
1723 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1724 (insert ","))
1725 (insert (or (message-fetch-reply-field "newsgroups") "")))
1729 ;;; Various commands
1731 (defun message-delete-not-region (beg end)
1732 "Delete everything in the body of the current message outside of the region."
1733 (interactive "r")
1734 (save-excursion
1735 (goto-char end)
1736 (delete-region (point) (if (not (message-goto-signature))
1737 (point)
1738 (forward-line -2)
1739 (point)))
1740 (insert "\n")
1741 (goto-char beg)
1742 (delete-region beg (progn (message-goto-body)
1743 (forward-line 2)
1744 (point))))
1745 (when (message-goto-signature)
1746 (forward-line -2)))
1748 (defun message-kill-to-signature ()
1749 "Deletes all text up to the signature."
1750 (interactive)
1751 (let ((point (point)))
1752 (message-goto-signature)
1753 (unless (eobp)
1754 (forward-line -2))
1755 (kill-region point (point))
1756 (unless (bolp)
1757 (insert "\n"))))
1759 (defun message-newline-and-reformat ()
1760 "Insert four newlines, and then reformat if inside quoted text."
1761 (interactive)
1762 ;; The Latin-1 angle quote looks pretty dubious. -- fx
1763 (let ((prefix "[]>»|:}+ \t]*")
1764 (supercite-thing "[-._[:alnum:]]*[>]+[ \t]*")
1765 quoted point)
1766 (unless (bolp)
1767 (save-excursion
1768 (beginning-of-line)
1769 (when (looking-at (concat prefix
1770 supercite-thing))
1771 (setq quoted (match-string 0))))
1772 (insert "\n"))
1773 (setq point (point))
1774 (insert "\n\n\n")
1775 (delete-region (point) (re-search-forward "[ \t]*"))
1776 (when quoted
1777 (insert quoted))
1778 (fill-paragraph nil)
1779 (goto-char point)
1780 (forward-line 1)))
1782 (defun message-split-line ()
1783 "Split current line, moving portion beyond point vertically down.
1784 If the current line has `message-yank-prefix', insert it on the new line."
1785 (interactive "*")
1786 (split-line message-yank-prefix))
1788 (defun message-insert-signature (&optional force)
1789 "Insert a signature. See documentation for variable `message-signature'."
1790 (interactive (list 0))
1791 (let* ((signature
1792 (cond
1793 ((and (null message-signature)
1794 (eq force 0))
1795 (save-excursion
1796 (goto-char (point-max))
1797 (not (re-search-backward message-signature-separator nil t))))
1798 ((and (null message-signature)
1799 force)
1801 ((message-functionp message-signature)
1802 (funcall message-signature))
1803 ((listp message-signature)
1804 (eval message-signature))
1805 (t message-signature)))
1806 (signature
1807 (cond ((stringp signature)
1808 signature)
1809 ((and (eq t signature)
1810 message-signature-file
1811 (file-exists-p message-signature-file))
1812 signature))))
1813 (when signature
1814 (goto-char (point-max))
1815 ;; Insert the signature.
1816 (unless (bolp)
1817 (insert "\n"))
1818 (insert "\n-- \n")
1819 (if (eq signature t)
1820 (insert-file-contents message-signature-file)
1821 (insert signature))
1822 (goto-char (point-max))
1823 (or (bolp) (insert "\n")))))
1825 (defun message-elide-region (b e)
1826 "Elide the text in the region.
1827 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1828 text was killed."
1829 (interactive "r")
1830 (kill-region b e)
1831 (insert message-elide-ellipsis))
1833 (defvar message-caesar-translation-table nil)
1835 (defun message-caesar-region (b e &optional n)
1836 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
1837 (interactive
1838 (list
1839 (min (point) (or (mark t) (point)))
1840 (max (point) (or (mark t) (point)))
1841 (when current-prefix-arg
1842 (prefix-numeric-value current-prefix-arg))))
1844 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1845 (unless (or (zerop n) ; no action needed for a rot of 0
1846 (= b e)) ; no region to rotate
1847 ;; We build the table, if necessary.
1848 (when (or (not message-caesar-translation-table)
1849 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1850 (setq message-caesar-translation-table
1851 (message-make-caesar-translation-table n)))
1852 (translate-region b e message-caesar-translation-table)))
1854 (defun message-make-caesar-translation-table (n)
1855 "Create a rot table with offset N."
1856 (let ((i -1)
1857 (table (make-string 256 0)))
1858 (while (< (incf i) 256)
1859 (aset table i i))
1860 (concat
1861 (substring table 0 ?A)
1862 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1863 (substring table ?A (+ ?A n))
1864 (substring table (+ ?A 26) ?a)
1865 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1866 (substring table ?a (+ ?a n))
1867 (substring table (+ ?a 26) 255))))
1869 (defun message-caesar-buffer-body (&optional rotnum)
1870 "Caesar rotate all letters in the current buffer by 13 places.
1871 Used to encode/decode possibly offensive messages (commonly in rec.humor).
1872 With prefix arg, specifies the number of places to rotate each letter forward.
1873 Mail and USENET news headers are not rotated."
1874 (interactive (if current-prefix-arg
1875 (list (prefix-numeric-value current-prefix-arg))
1876 (list nil)))
1877 (save-excursion
1878 (save-restriction
1879 (when (message-goto-body)
1880 (narrow-to-region (point) (point-max)))
1881 (message-caesar-region (point-min) (point-max) rotnum))))
1883 (defun message-pipe-buffer-body (program)
1884 "Pipe the message body in the current buffer through PROGRAM."
1885 (save-excursion
1886 (save-restriction
1887 (when (message-goto-body)
1888 (narrow-to-region (point) (point-max)))
1889 (shell-command-on-region
1890 (point-min) (point-max) program nil t))))
1892 (defun message-rename-buffer (&optional enter-string)
1893 "Rename the *message* buffer to \"*message* RECIPIENT\".
1894 If the function is run with a prefix, it will ask for a new buffer
1895 name, rather than giving an automatic name."
1896 (interactive "Pbuffer name: ")
1897 (save-excursion
1898 (save-restriction
1899 (goto-char (point-min))
1900 (narrow-to-region (point)
1901 (search-forward mail-header-separator nil 'end))
1902 (let* ((mail-to (or
1903 (if (message-news-p) (message-fetch-field "Newsgroups")
1904 (message-fetch-field "To"))
1905 ""))
1906 (mail-trimmed-to
1907 (if (string-match "," mail-to)
1908 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1909 mail-to))
1910 (name-default (concat "*message* " mail-trimmed-to))
1911 (name (if enter-string
1912 (read-string "New buffer name: " name-default)
1913 name-default)))
1914 (rename-buffer name t)))))
1916 (defun message-fill-yanked-message (&optional justifyp)
1917 "Fill the paragraphs of a message yanked into this one.
1918 Numeric argument means justify as well."
1919 (interactive "P")
1920 (save-excursion
1921 (goto-char (point-min))
1922 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1923 (let ((fill-prefix message-yank-prefix))
1924 (fill-individual-paragraphs (point) (point-max) justifyp))))
1926 (defun message-indent-citation ()
1927 "Modify text just inserted from a message to be cited.
1928 The inserted text should be the region.
1929 When this function returns, the region is again around the modified text.
1931 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1932 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1933 (let ((start (point)))
1934 ;; Remove unwanted headers.
1935 (when message-ignored-cited-headers
1936 (let (all-removed)
1937 (save-restriction
1938 (narrow-to-region
1939 (goto-char start)
1940 (if (search-forward "\n\n" nil t)
1941 (1- (point))
1942 (point)))
1943 (message-remove-header message-ignored-cited-headers t)
1944 (when (= (point-min) (point-max))
1945 (setq all-removed t))
1946 (goto-char (point-max)))
1947 (if all-removed
1948 (goto-char start)
1949 (forward-line 1))))
1950 ;; Delete blank lines at the start of the buffer.
1951 (while (and (point-min)
1952 (eolp)
1953 (not (eobp)))
1954 (message-delete-line))
1955 ;; Delete blank lines at the end of the buffer.
1956 (goto-char (point-max))
1957 (unless (eolp)
1958 (insert "\n"))
1959 (while (and (zerop (forward-line -1))
1960 (looking-at "$"))
1961 (message-delete-line))
1962 ;; Do the indentation.
1963 (if (null message-yank-prefix)
1964 (indent-rigidly start (mark t) message-indentation-spaces)
1965 (save-excursion
1966 (goto-char start)
1967 (while (< (point) (mark t))
1968 (insert message-yank-prefix)
1969 (forward-line 1))))
1970 (goto-char start)))
1972 (defun message-yank-original (&optional arg)
1973 "Insert the message being replied to, if any.
1974 Puts point before the text and mark after.
1975 Normally indents each nonblank line ARG spaces (default 3). However,
1976 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1978 This function uses `message-cite-function' to do the actual citing.
1980 Just \\[universal-argument] as argument means don't indent, insert no
1981 prefix, and don't delete any headers."
1982 (interactive "P")
1983 (let ((modified (buffer-modified-p)))
1984 (when (and message-reply-buffer
1985 message-cite-function)
1986 (delete-windows-on message-reply-buffer t)
1987 (insert-buffer message-reply-buffer)
1988 (unless arg
1989 (funcall message-cite-function))
1990 (message-exchange-point-and-mark)
1991 (unless (bolp)
1992 (insert ?\n))
1993 (unless modified
1994 (setq message-checksum (message-checksum))))))
1996 (defun message-yank-buffer (buffer)
1997 "Insert BUFFER into the current buffer and quote it."
1998 (interactive "bYank buffer: ")
1999 (let ((message-reply-buffer buffer))
2000 (save-window-excursion
2001 (message-yank-original))))
2003 (defun message-buffers ()
2004 "Return a list of active message buffers."
2005 (let (buffers)
2006 (save-excursion
2007 (dolist (buffer (buffer-list t))
2008 (set-buffer buffer)
2009 (when (and (eq major-mode 'message-mode)
2010 (null message-sent-message-via))
2011 (push (buffer-name buffer) buffers))))
2012 (nreverse buffers)))
2014 (defun message-cite-original-without-signature ()
2015 "Cite function in the standard Message manner."
2016 (let ((start (point))
2017 (end (mark t))
2018 (functions
2019 (when message-indent-citation-function
2020 (if (listp message-indent-citation-function)
2021 message-indent-citation-function
2022 (list message-indent-citation-function)))))
2023 (mml-quote-region start end)
2024 ;; Allow undoing.
2025 (undo-boundary)
2026 (goto-char end)
2027 (when (re-search-backward message-signature-separator start t)
2028 ;; Also peel off any blank lines before the signature.
2029 (forward-line -1)
2030 (while (looking-at "^[ \t]*$")
2031 (forward-line -1))
2032 (forward-line 1)
2033 (delete-region (point) end)
2034 (unless (search-backward "\n\n" start t)
2035 ;; Insert a blank line if it is peeled off.
2036 (insert "\n")))
2037 (goto-char start)
2038 (while functions
2039 (funcall (pop functions)))
2040 (when message-citation-line-function
2041 (unless (bolp)
2042 (insert "\n"))
2043 (funcall message-citation-line-function))))
2045 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2046 (defun message-cite-original ()
2047 "Cite function in the standard Message manner."
2048 (if (and (boundp 'mail-citation-hook)
2049 mail-citation-hook)
2050 (run-hooks 'mail-citation-hook)
2051 (let ((start (point))
2052 (end (mark t))
2053 (functions
2054 (when message-indent-citation-function
2055 (if (listp message-indent-citation-function)
2056 message-indent-citation-function
2057 (list message-indent-citation-function)))))
2058 (mml-quote-region start end)
2059 (goto-char start)
2060 (while functions
2061 (funcall (pop functions)))
2062 (when message-citation-line-function
2063 (unless (bolp)
2064 (insert "\n"))
2065 (funcall message-citation-line-function)))))
2067 (defun message-insert-citation-line ()
2068 "Insert a simple citation line."
2069 (when message-reply-headers
2070 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2072 (defun message-position-on-field (header &rest afters)
2073 (let ((case-fold-search t))
2074 (save-restriction
2075 (narrow-to-region
2076 (goto-char (point-min))
2077 (progn
2078 (re-search-forward
2079 (concat "^" (regexp-quote mail-header-separator) "$"))
2080 (match-beginning 0)))
2081 (goto-char (point-min))
2082 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2083 (progn
2084 (re-search-forward "^[^ \t]" nil 'move)
2085 (beginning-of-line)
2086 (skip-chars-backward "\n")
2088 (while (and afters
2089 (not (re-search-forward
2090 (concat "^" (regexp-quote (car afters)) ":")
2091 nil t)))
2092 (pop afters))
2093 (when afters
2094 (re-search-forward "^[^ \t]" nil 'move)
2095 (beginning-of-line))
2096 (insert header ": \n")
2097 (forward-char -1)
2098 nil))))
2100 (defun message-remove-signature ()
2101 "Remove the signature from the text between point and mark.
2102 The text will also be indented the normal way."
2103 (save-excursion
2104 (let ((start (point))
2105 mark)
2106 (if (not (re-search-forward message-signature-separator (mark t) t))
2107 ;; No signature here, so we just indent the cited text.
2108 (message-indent-citation)
2109 ;; Find the last non-empty line.
2110 (forward-line -1)
2111 (while (looking-at "[ \t]*$")
2112 (forward-line -1))
2113 (forward-line 1)
2114 (setq mark (set-marker (make-marker) (point)))
2115 (goto-char start)
2116 (message-indent-citation)
2117 ;; Enable undoing the deletion.
2118 (undo-boundary)
2119 (delete-region mark (mark t))
2120 (set-marker mark nil)))))
2125 ;;; Sending messages
2128 (defun message-send-and-exit (&optional arg)
2129 "Send message like `message-send', then, if no errors, exit from mail buffer."
2130 (interactive "P")
2131 (let ((buf (current-buffer))
2132 (actions message-exit-actions))
2133 (when (and (message-send arg)
2134 (buffer-name buf))
2135 (if message-kill-buffer-on-exit
2136 (kill-buffer buf)
2137 (bury-buffer buf)
2138 (when (eq buf (current-buffer))
2139 (message-bury buf)))
2140 (message-do-actions actions)
2141 t)))
2143 (defun message-dont-send ()
2144 "Don't send the message you have been editing."
2145 (interactive)
2146 (set-buffer-modified-p t)
2147 (save-buffer)
2148 (let ((actions message-postpone-actions))
2149 (message-bury (current-buffer))
2150 (message-do-actions actions)))
2152 (defun message-kill-buffer ()
2153 "Kill the current buffer."
2154 (interactive)
2155 (when (or (not (buffer-modified-p))
2156 (yes-or-no-p "Message modified; kill anyway? "))
2157 (let ((actions message-kill-actions))
2158 (setq buffer-file-name nil)
2159 (kill-buffer (current-buffer))
2160 (message-do-actions actions))))
2162 (defun message-bury (buffer)
2163 "Bury this mail BUFFER."
2164 (let ((newbuf (other-buffer buffer)))
2165 (bury-buffer buffer)
2166 (if (and (fboundp 'frame-parameters)
2167 (cdr (assq 'dedicated (frame-parameters)))
2168 (not (null (delq (selected-frame) (visible-frame-list)))))
2169 (delete-frame (selected-frame))
2170 (switch-to-buffer newbuf))))
2172 (defun message-send (&optional arg)
2173 "Send the message in the current buffer.
2174 If `message-interactive' is non-nil, wait for success indication or
2175 error messages, and inform user.
2176 Otherwise any failure is reported in a message back to the user from
2177 the mailer.
2178 The usage of ARG is defined by the instance that called Message.
2179 It should typically alter the sending method in some way or other."
2180 (interactive "P")
2181 ;; Make it possible to undo the coming changes.
2182 (undo-boundary)
2183 (let ((inhibit-read-only t))
2184 (put-text-property (point-min) (point-max) 'read-only nil))
2185 (message-fix-before-sending)
2186 (run-hooks 'message-send-hook)
2187 (message message-sending-message)
2188 (let ((alist message-send-method-alist)
2189 (success t)
2190 elem sent)
2191 (while (and success
2192 (setq elem (pop alist)))
2193 (when (funcall (cadr elem))
2194 (when (and (or (not (memq (car elem)
2195 message-sent-message-via))
2196 (y-or-n-p
2197 (format
2198 "Already sent message via %s; resend? "
2199 (car elem))))
2200 (setq success (funcall (caddr elem) arg)))
2201 (setq sent t))))
2202 (unless (or sent (not success))
2203 (error "No methods specified to send by"))
2204 (when (and success sent)
2205 (message-do-fcc)
2206 (save-excursion
2207 (run-hooks 'message-sent-hook))
2208 (message "Sending...done")
2209 ;; Mark the buffer as unmodified and delete auto-save.
2210 (set-buffer-modified-p nil)
2211 (delete-auto-save-file-if-necessary t)
2212 (message-disassociate-draft)
2213 ;; Delete other mail buffers and stuff.
2214 (message-do-send-housekeeping)
2215 (message-do-actions message-send-actions)
2216 ;; Return success.
2217 t)))
2219 (defun message-send-via-mail (arg)
2220 "Send the current message via mail."
2221 (message-send-mail arg))
2223 (defun message-send-via-news (arg)
2224 "Send the current message via news."
2225 (funcall message-send-news-function arg))
2227 (defmacro message-check (type &rest forms)
2228 "Eval FORMS if TYPE is to be checked."
2229 `(or (message-check-element ,type)
2230 (save-excursion
2231 ,@forms)))
2233 (put 'message-check 'lisp-indent-function 1)
2234 (put 'message-check 'edebug-form-spec '(form body))
2236 (defun message-fix-before-sending ()
2237 "Do various things to make the message nice before sending it."
2238 ;; Make sure there's a newline at the end of the message.
2239 (goto-char (point-max))
2240 (unless (bolp)
2241 (insert "\n"))
2242 ;; Delete all invisible text.
2243 (message-check 'invisible-text
2244 (when (text-property-any (point-min) (point-max) 'invisible t)
2245 (put-text-property (point-min) (point-max) 'invisible nil)
2246 (unless (yes-or-no-p
2247 "Invisible text found and made visible; continue posting? ")
2248 (error "Invisible text found and made visible")))))
2250 (defun message-add-action (action &rest types)
2251 "Add ACTION to be performed when doing an exit of type TYPES."
2252 (let (var)
2253 (while types
2254 (set (setq var (intern (format "message-%s-actions" (pop types))))
2255 (nconc (symbol-value var) (list action))))))
2257 (defun message-do-actions (actions)
2258 "Perform all actions in ACTIONS."
2259 ;; Now perform actions on successful sending.
2260 (while actions
2261 (ignore-errors
2262 (cond
2263 ;; A simple function.
2264 ((message-functionp (car actions))
2265 (funcall (car actions)))
2266 ;; Something to be evaled.
2268 (eval (car actions)))))
2269 (pop actions)))
2271 (defun message-send-mail-partially ()
2272 "Sendmail as message/partial."
2273 ;; replace the header delimiter with a blank line
2274 (goto-char (point-min))
2275 (re-search-forward
2276 (concat "^" (regexp-quote mail-header-separator) "\n"))
2277 (replace-match "\n")
2278 (run-hooks 'message-send-mail-hook)
2279 (let ((p (goto-char (point-min)))
2280 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2281 (curbuf (current-buffer))
2282 (id (message-make-message-id)) (n 1)
2283 plist total header required-mail-headers)
2284 (while (not (eobp))
2285 (if (< (point-max) (+ p message-send-mail-partially-limit))
2286 (goto-char (point-max))
2287 (goto-char (+ p message-send-mail-partially-limit))
2288 (beginning-of-line)
2289 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2290 (push p plist)
2291 (setq p (point)))
2292 (setq total (length plist))
2293 (push (point-max) plist)
2294 (setq plist (nreverse plist))
2295 (unwind-protect
2296 (save-excursion
2297 (setq p (pop plist))
2298 (while plist
2299 (set-buffer curbuf)
2300 (copy-to-buffer tembuf p (car plist))
2301 (set-buffer tembuf)
2302 (goto-char (point-min))
2303 (if header
2304 (progn
2305 (goto-char (point-min))
2306 (narrow-to-region (point) (point))
2307 (insert header))
2308 (message-goto-eoh)
2309 (setq header (buffer-substring (point-min) (point)))
2310 (goto-char (point-min))
2311 (narrow-to-region (point) (point))
2312 (insert header)
2313 (message-remove-header "Mime-Version")
2314 (message-remove-header "Content-Type")
2315 (message-remove-header "Content-Transfer-Encoding")
2316 (message-remove-header "Message-ID")
2317 (message-remove-header "Lines")
2318 (goto-char (point-max))
2319 (insert "Mime-Version: 1.0\n")
2320 (setq header (buffer-substring (point-min) (point-max))))
2321 (goto-char (point-max))
2322 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2323 id n total))
2324 (let ((mail-header-separator ""))
2325 (when (memq 'Message-ID message-required-mail-headers)
2326 (insert "Message-ID: " (message-make-message-id) "\n"))
2327 (when (memq 'Lines message-required-mail-headers)
2328 (let ((mail-header-separator ""))
2329 (insert "Lines: " (message-make-lines) "\n")))
2330 (message-goto-subject)
2331 (end-of-line)
2332 (insert (format " (%d/%d)" n total))
2333 (goto-char (point-max))
2334 (insert "\n")
2335 (widen)
2336 (mm-with-unibyte-current-buffer
2337 (funcall message-send-mail-function)))
2338 (setq n (+ n 1))
2339 (setq p (pop plist))
2340 (erase-buffer)))
2341 (kill-buffer tembuf))))
2343 (defun message-send-mail (&optional arg)
2344 (require 'mail-utils)
2345 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2346 (case-fold-search nil)
2347 (news (message-news-p))
2348 (mailbuf (current-buffer))
2349 (message-this-is-mail t)
2350 (message-posting-charset
2351 (if (fboundp 'gnus-setup-posting-charset)
2352 (gnus-setup-posting-charset nil)
2353 message-posting-charset)))
2354 (save-restriction
2355 (message-narrow-to-headers)
2356 ;; Insert some headers.
2357 (let ((message-deletable-headers
2358 (if news nil message-deletable-headers)))
2359 (message-generate-headers message-required-mail-headers))
2360 ;; Let the user do all of the above.
2361 (run-hooks 'message-header-hook))
2362 (unwind-protect
2363 (save-excursion
2364 (set-buffer tembuf)
2365 (erase-buffer)
2366 ;; Avoid copying text props.
2367 (insert (with-current-buffer mailbuf
2368 (buffer-substring-no-properties (point-min) (point-max))))
2369 ;; Remove some headers.
2370 (message-encode-message-body)
2371 (save-restriction
2372 (message-narrow-to-headers)
2373 ;; We (re)generate the Lines header.
2374 (when (memq 'Lines message-required-mail-headers)
2375 (message-generate-headers '(Lines)))
2376 ;; Remove some headers.
2377 (message-remove-header message-ignored-mail-headers t)
2378 (let ((mail-parse-charset message-default-charset))
2379 (mail-encode-encoded-word-buffer)))
2380 (goto-char (point-max))
2381 ;; require one newline at the end.
2382 (or (= (preceding-char) ?\n)
2383 (insert ?\n))
2384 (when
2385 (save-restriction
2386 (message-narrow-to-headers)
2387 (and news
2388 (or (message-fetch-field "cc")
2389 (message-fetch-field "to"))
2390 (let ((content-type (message-fetch-field "content-type")))
2392 (not content-type)
2393 (string= "text/plain"
2394 (car
2395 (mail-header-parse-content-type
2396 content-type)))))))
2397 (message-insert-courtesy-copy))
2398 (if (or (not message-send-mail-partially-limit)
2399 (< (point-max) message-send-mail-partially-limit)
2400 (not (y-or-n-p "The message size is too large, should it be sent partially? ")))
2401 (mm-with-unibyte-current-buffer
2402 (funcall message-send-mail-function))
2403 (message-send-mail-partially)))
2404 (kill-buffer tembuf))
2405 (set-buffer mailbuf)
2406 (push 'mail message-sent-message-via)))
2408 (defun message-send-mail-with-sendmail ()
2409 "Send off the prepared buffer with sendmail."
2410 (let ((errbuf (if message-interactive
2411 (message-generate-new-buffer-clone-locals
2412 " sendmail errors")
2414 resend-to-addresses delimline)
2415 (let ((case-fold-search t))
2416 (save-restriction
2417 (message-narrow-to-headers)
2418 (setq resend-to-addresses (message-fetch-field "resent-to")))
2419 ;; Change header-delimiter to be what sendmail expects.
2420 (goto-char (point-min))
2421 (re-search-forward
2422 (concat "^" (regexp-quote mail-header-separator) "\n"))
2423 (replace-match "\n")
2424 (backward-char 1)
2425 (setq delimline (point-marker))
2426 (run-hooks 'message-send-mail-hook)
2427 ;; Insert an extra newline if we need it to work around
2428 ;; Sun's bug that swallows newlines.
2429 (goto-char (1+ delimline))
2430 (when (eval message-mailer-swallows-blank-line)
2431 (newline))
2432 (when message-interactive
2433 (save-excursion
2434 (set-buffer errbuf)
2435 (erase-buffer))))
2436 (let ((default-directory "/")
2437 (coding-system-for-write message-send-coding-system))
2438 (apply 'call-process-region
2439 (append (list (point-min) (point-max)
2440 (if (boundp 'sendmail-program)
2441 sendmail-program
2442 "/usr/lib/sendmail")
2443 nil errbuf nil "-oi")
2444 ;; Always specify who from,
2445 ;; since some systems have broken sendmails.
2446 ;; But some systems are more broken with -f, so
2447 ;; we'll let users override this.
2448 (if (null message-sendmail-f-is-evil)
2449 (list "-f" (message-make-address)))
2450 ;; These mean "report errors by mail"
2451 ;; and "deliver in background".
2452 (if (null message-interactive) '("-oem" "-odb"))
2453 ;; Get the addresses from the message
2454 ;; unless this is a resend.
2455 ;; We must not do that for a resend
2456 ;; because we would find the original addresses.
2457 ;; For a resend, include the specific addresses.
2458 (if resend-to-addresses
2459 (list resend-to-addresses)
2460 '("-t")))))
2461 (when message-interactive
2462 (save-excursion
2463 (set-buffer errbuf)
2464 (goto-char (point-min))
2465 (while (re-search-forward "\n\n* *" nil t)
2466 (replace-match "; "))
2467 (if (not (zerop (buffer-size)))
2468 (error "Sending...failed to %s"
2469 (buffer-substring (point-min) (point-max)))))
2470 (when (bufferp errbuf)
2471 (kill-buffer errbuf)))))
2473 (defun message-send-mail-with-qmail ()
2474 "Pass the prepared message buffer to qmail-inject.
2475 Refer to the documentation for the variable `message-send-mail-function'
2476 to find out how to use this."
2477 ;; replace the header delimiter with a blank line
2478 (goto-char (point-min))
2479 (re-search-forward
2480 (concat "^" (regexp-quote mail-header-separator) "\n"))
2481 (replace-match "\n")
2482 (run-hooks 'message-send-mail-hook)
2483 ;; send the message
2484 (case
2485 (let ((coding-system-for-write message-send-coding-system))
2486 (apply
2487 'call-process-region 1 (point-max) message-qmail-inject-program
2488 nil nil nil
2489 ;; qmail-inject's default behaviour is to look for addresses on the
2490 ;; command line; if there're none, it scans the headers.
2491 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2493 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2494 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2495 ;; message from stdin.
2497 ;; qmail also has the advantage of not having been raped by
2498 ;; various vendors, so we don't have to allow for that, either --
2499 ;; compare this with message-send-mail-with-sendmail and weep
2500 ;; for sendmail's lost innocence.
2502 ;; all this is way cool coz it lets us keep the arguments entirely
2503 ;; free for -inject-arguments -- a big win for the user and for us
2504 ;; since we don't have to play that double-guessing game and the user
2505 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2506 message-qmail-inject-args))
2507 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2508 ;; we have to look at the retval instead
2509 (0 nil)
2510 (1 (error "qmail-inject reported permanent failure"))
2511 (111 (error "qmail-inject reported transient failure"))
2512 ;; should never happen
2513 (t (error "qmail-inject reported unknown failure"))))
2515 (defun message-send-mail-with-mh ()
2516 "Send the prepared message buffer with mh."
2517 (let ((mh-previous-window-config nil)
2518 (name (mh-new-draft-name)))
2519 (setq buffer-file-name name)
2520 ;; MH wants to generate these headers itself.
2521 (when message-mh-deletable-headers
2522 (let ((headers message-mh-deletable-headers))
2523 (while headers
2524 (goto-char (point-min))
2525 (and (re-search-forward
2526 (concat "^" (symbol-name (car headers)) ": *") nil t)
2527 (message-delete-line))
2528 (pop headers))))
2529 (run-hooks 'message-send-mail-hook)
2530 ;; Pass it on to mh.
2531 (mh-send-letter)))
2533 (defun message-send-news (&optional arg)
2534 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2535 (case-fold-search nil)
2536 (method (if (message-functionp message-post-method)
2537 (funcall message-post-method arg)
2538 message-post-method))
2539 (group-name-charset (gnus-group-name-charset method ""))
2540 (rfc2047-header-encoding-alist
2541 (if group-name-charset
2542 (cons (cons "Newsgroups" group-name-charset)
2543 rfc2047-header-encoding-alist)
2544 rfc2047-header-encoding-alist))
2545 (messbuf (current-buffer))
2546 (message-syntax-checks
2547 (if arg
2548 (cons '(existing-newsgroups . disabled)
2549 message-syntax-checks)
2550 message-syntax-checks))
2551 (message-this-is-news t)
2552 (message-posting-charset (gnus-setup-posting-charset
2553 (save-restriction
2554 (message-narrow-to-headers-or-head)
2555 (message-fetch-field "Newsgroups"))))
2556 result)
2557 (if (not (message-check-news-body-syntax))
2559 (save-restriction
2560 (message-narrow-to-headers)
2561 ;; Insert some headers.
2562 (message-generate-headers message-required-news-headers)
2563 ;; Let the user do all of the above.
2564 (run-hooks 'message-header-hook))
2565 (if group-name-charset
2566 (setq message-syntax-checks
2567 (cons '(valid-newsgroups . disabled)
2568 message-syntax-checks)))
2569 (message-cleanup-headers)
2570 (if (not (message-check-news-syntax))
2572 (unwind-protect
2573 (save-excursion
2574 (set-buffer tembuf)
2575 (buffer-disable-undo)
2576 (erase-buffer)
2577 ;; Avoid copying text props.
2578 (insert (with-current-buffer messbuf
2579 (buffer-substring-no-properties
2580 (point-min) (point-max))))
2581 (message-encode-message-body)
2582 ;; Remove some headers.
2583 (save-restriction
2584 (message-narrow-to-headers)
2585 ;; We (re)generate the Lines header.
2586 (when (memq 'Lines message-required-mail-headers)
2587 (message-generate-headers '(Lines)))
2588 ;; Remove some headers.
2589 (message-remove-header message-ignored-news-headers t)
2590 (let ((mail-parse-charset message-default-charset))
2591 (mail-encode-encoded-word-buffer)))
2592 (goto-char (point-max))
2593 ;; require one newline at the end.
2594 (or (= (preceding-char) ?\n)
2595 (insert ?\n))
2596 (let ((case-fold-search t))
2597 ;; Remove the delimiter.
2598 (goto-char (point-min))
2599 (re-search-forward
2600 (concat "^" (regexp-quote mail-header-separator) "\n"))
2601 (replace-match "\n")
2602 (backward-char 1))
2603 (run-hooks 'message-send-news-hook)
2604 (gnus-open-server method)
2605 (setq result (let ((mail-header-separator ""))
2606 (gnus-request-post method))))
2607 (kill-buffer tembuf))
2608 (set-buffer messbuf)
2609 (if result
2610 (push 'news message-sent-message-via)
2611 (message "Couldn't send message via news: %s"
2612 (nnheader-get-report (car method)))
2613 nil)))))
2616 ;;; Header generation & syntax checking.
2619 (defun message-check-element (type)
2620 "Return non-nil if this TYPE is not to be checked."
2621 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2623 (let ((able (assq type message-syntax-checks)))
2624 (and (consp able)
2625 (eq (cdr able) 'disabled)))))
2627 (defun message-check-news-syntax ()
2628 "Check the syntax of the message."
2629 (save-excursion
2630 (save-restriction
2631 (widen)
2632 ;; We narrow to the headers and check them first.
2633 (save-excursion
2634 (save-restriction
2635 (message-narrow-to-headers)
2636 (message-check-news-header-syntax))))))
2638 (defun message-check-news-header-syntax ()
2639 (and
2640 ;; Check Newsgroups header.
2641 (message-check 'newsgroups
2642 (let ((group (message-fetch-field "newsgroups")))
2644 (and group
2645 (not (string-match "\\`[ \t]*\\'" group)))
2646 (ignore
2647 (message
2648 "The newsgroups field is empty or missing. Posting is denied.")))))
2649 ;; Check the Subject header.
2650 (message-check 'subject
2651 (let* ((case-fold-search t)
2652 (subject (message-fetch-field "subject")))
2654 (and subject
2655 (not (string-match "\\`[ \t]*\\'" subject)))
2656 (ignore
2657 (message
2658 "The subject field is empty or missing. Posting is denied.")))))
2659 ;; Check for commands in Subject.
2660 (message-check 'subject-cmsg
2661 (if (string-match "^cmsg " (message-fetch-field "subject"))
2662 (y-or-n-p
2663 "The control code \"cmsg\" is in the subject. Really post? ")
2665 ;; Check for multiple identical headers.
2666 (message-check 'multiple-headers
2667 (let (found)
2668 (while (and (not found)
2669 (re-search-forward "^[^ \t:]+: " nil t))
2670 (save-excursion
2671 (or (re-search-forward
2672 (concat "^"
2673 (regexp-quote
2674 (setq found
2675 (buffer-substring
2676 (match-beginning 0) (- (match-end 0) 2))))
2677 ":")
2678 nil t)
2679 (setq found nil))))
2680 (if found
2681 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2682 t)))
2683 ;; Check for Version and Sendsys.
2684 (message-check 'sendsys
2685 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2686 (y-or-n-p
2687 (format "The article contains a %s command. Really post? "
2688 (buffer-substring (match-beginning 0)
2689 (1- (match-end 0)))))
2691 ;; See whether we can shorten Followup-To.
2692 (message-check 'shorten-followup-to
2693 (let ((newsgroups (message-fetch-field "newsgroups"))
2694 (followup-to (message-fetch-field "followup-to"))
2696 (when (and newsgroups
2697 (string-match "," newsgroups)
2698 (not followup-to)
2699 (not
2700 (zerop
2701 (length
2702 (setq to (completing-read
2703 "Followups to: (default all groups) "
2704 (mapcar (lambda (g) (list g))
2705 (cons "poster"
2706 (message-tokenize-header
2707 newsgroups)))))))))
2708 (goto-char (point-min))
2709 (insert "Followup-To: " to "\n"))
2711 ;; Check "Shoot me".
2712 (message-check 'shoot
2713 (if (re-search-forward
2714 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2715 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2717 ;; Check for Approved.
2718 (message-check 'approved
2719 (if (re-search-forward "^Approved:" nil t)
2720 (y-or-n-p "The article contains an Approved header. Really post? ")
2722 ;; Check the Message-ID header.
2723 (message-check 'message-id
2724 (let* ((case-fold-search t)
2725 (message-id (message-fetch-field "message-id" t)))
2726 (or (not message-id)
2727 ;; Is there an @ in the ID?
2728 (and (string-match "@" message-id)
2729 ;; Is there a dot in the ID?
2730 (string-match "@[^.]*\\." message-id)
2731 ;; Does the ID end with a dot?
2732 (not (string-match "\\.>" message-id)))
2733 (y-or-n-p
2734 (format "The Message-ID looks strange: \"%s\". Really post? "
2735 message-id)))))
2736 ;; Check the Newsgroups & Followup-To headers.
2737 (message-check 'existing-newsgroups
2738 (let* ((case-fold-search t)
2739 (newsgroups (message-fetch-field "newsgroups"))
2740 (followup-to (message-fetch-field "followup-to"))
2741 (groups (message-tokenize-header
2742 (if followup-to
2743 (concat newsgroups "," followup-to)
2744 newsgroups)))
2745 (hashtb (and (boundp 'gnus-active-hashtb)
2746 gnus-active-hashtb))
2747 errors)
2748 (if (or (not hashtb)
2749 (not (boundp 'gnus-read-active-file))
2750 (not gnus-read-active-file)
2751 (eq gnus-read-active-file 'some))
2753 (while groups
2754 (when (and (not (boundp (intern (car groups) hashtb)))
2755 (not (equal (car groups) "poster")))
2756 (push (car groups) errors))
2757 (pop groups))
2758 (if (not errors)
2760 (y-or-n-p
2761 (format
2762 "Really post to %s unknown group%s: %s? "
2763 (if (= (length errors) 1) "this" "these")
2764 (if (= (length errors) 1) "" "s")
2765 (mapconcat 'identity errors ", ")))))))
2766 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2767 (message-check 'valid-newsgroups
2768 (let ((case-fold-search t)
2769 (headers '("Newsgroups" "Followup-To"))
2770 header error)
2771 (while (and headers (not error))
2772 (when (setq header (mail-fetch-field (car headers)))
2773 (if (or
2774 (not
2775 (string-match
2776 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2777 header))
2778 (memq
2779 nil (mapcar
2780 (lambda (g)
2781 (not (string-match "\\.\\'\\|\\.\\." g)))
2782 (message-tokenize-header header ","))))
2783 (setq error t)))
2784 (unless error
2785 (pop headers)))
2786 (if (not error)
2788 (y-or-n-p
2789 (format "The %s header looks odd: \"%s\". Really post? "
2790 (car headers) header)))))
2791 (message-check 'repeated-newsgroups
2792 (let ((case-fold-search t)
2793 (headers '("Newsgroups" "Followup-To"))
2794 header error groups group)
2795 (while (and headers
2796 (not error))
2797 (when (setq header (mail-fetch-field (pop headers)))
2798 (setq groups (message-tokenize-header header ","))
2799 (while (setq group (pop groups))
2800 (when (member group groups)
2801 (setq error group
2802 groups nil)))))
2803 (if (not error)
2805 (y-or-n-p
2806 (format "Group %s is repeated in headers. Really post? " error)))))
2807 ;; Check the From header.
2808 (message-check 'from
2809 (let* ((case-fold-search t)
2810 (from (message-fetch-field "from"))
2812 (cond
2813 ((not from)
2814 (message "There is no From line. Posting is denied.")
2815 nil)
2816 ((or (not (string-match
2817 "@[^\\.]*\\."
2818 (setq ad (nth 1 (mail-extract-address-components
2819 from))))) ;larsi@ifi
2820 (string-match "\\.\\." ad) ;larsi@ifi..uio
2821 (string-match "@\\." ad) ;larsi@.ifi.uio
2822 (string-match "\\.$" ad) ;larsi@ifi.uio.
2823 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2824 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2825 (message
2826 "Denied posting -- the From looks strange: \"%s\"." from)
2827 nil)
2828 (t t))))))
2830 (defun message-check-news-body-syntax ()
2831 (and
2832 ;; Check for long lines.
2833 (message-check 'long-lines
2834 (goto-char (point-min))
2835 (re-search-forward
2836 (concat "^" (regexp-quote mail-header-separator) "$"))
2837 (while (and
2838 (progn
2839 (end-of-line)
2840 (< (current-column) 80))
2841 (zerop (forward-line 1))))
2842 (or (bolp)
2843 (eobp)
2844 (y-or-n-p
2845 "You have lines longer than 79 characters. Really post? ")))
2846 ;; Check whether the article is empty.
2847 (message-check 'empty
2848 (goto-char (point-min))
2849 (re-search-forward
2850 (concat "^" (regexp-quote mail-header-separator) "$"))
2851 (forward-line 1)
2852 (let ((b (point)))
2853 (goto-char (point-max))
2854 (re-search-backward message-signature-separator nil t)
2855 (beginning-of-line)
2856 (or (re-search-backward "[^ \n\t]" b t)
2857 (y-or-n-p "Empty article. Really post? "))))
2858 ;; Check for control characters.
2859 (message-check 'control-chars
2860 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2861 (y-or-n-p
2862 "The article contains control characters. Really post? ")
2864 ;; Check excessive size.
2865 (message-check 'size
2866 (if (> (buffer-size) 60000)
2867 (y-or-n-p
2868 (format "The article is %d octets long. Really post? "
2869 (buffer-size)))
2871 ;; Check whether any new text has been added.
2872 (message-check 'new-text
2874 (not message-checksum)
2875 (not (eq (message-checksum) message-checksum))
2876 (y-or-n-p
2877 "It looks like no new text has been added. Really post? ")))
2878 ;; Check the length of the signature.
2879 (message-check 'signature
2880 (goto-char (point-max))
2881 (if (> (count-lines (point) (point-max)) 5)
2882 (y-or-n-p
2883 (format
2884 "Your .sig is %d lines; it should be max 4. Really post? "
2885 (1- (count-lines (point) (point-max)))))
2887 ;; Ensure that text follows last quoted portion.
2888 (message-check 'quoting-style
2889 (goto-char (point-max))
2890 (let ((no-problem t))
2891 (when (search-backward-regexp "^>[^\n]*\n>" nil t)
2892 (setq no-problem nil)
2893 (while (not (eobp))
2894 (when (and (not (eolp)) (looking-at "[^> \t]"))
2895 (setq no-problem t))
2896 (forward-line)))
2897 (if no-problem
2899 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
2901 (defun message-checksum ()
2902 "Return a \"checksum\" for the current buffer."
2903 (let ((sum 0))
2904 (save-excursion
2905 (goto-char (point-min))
2906 (re-search-forward
2907 (concat "^" (regexp-quote mail-header-separator) "$"))
2908 (while (not (eobp))
2909 (when (not (looking-at "[ \t\n]"))
2910 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2911 (char-after))))
2912 (forward-char 1)))
2913 sum))
2915 (defun message-do-fcc ()
2916 "Process Fcc headers in the current buffer."
2917 (let ((case-fold-search t)
2918 (buf (current-buffer))
2919 list file)
2920 (save-excursion
2921 (set-buffer (get-buffer-create " *message temp*"))
2922 (erase-buffer)
2923 (insert-buffer-substring buf)
2924 (save-restriction
2925 (message-narrow-to-headers)
2926 (while (setq file (message-fetch-field "fcc"))
2927 (push file list)
2928 (message-remove-header "fcc" nil t)))
2929 (message-encode-message-body)
2930 (save-restriction
2931 (message-narrow-to-headers)
2932 (let ((mail-parse-charset message-default-charset)
2933 (rfc2047-header-encoding-alist
2934 (cons '("Newsgroups" . default)
2935 rfc2047-header-encoding-alist)))
2936 (mail-encode-encoded-word-buffer)))
2937 (goto-char (point-min))
2938 (when (re-search-forward
2939 (concat "^" (regexp-quote mail-header-separator) "$")
2940 nil t)
2941 (replace-match "" t t ))
2942 ;; Process FCC operations.
2943 (while list
2944 (setq file (pop list))
2945 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2946 ;; Pipe the article to the program in question.
2947 (call-process-region (point-min) (point-max) shell-file-name
2948 nil nil nil shell-command-switch
2949 (match-string 1 file))
2950 ;; Save the article.
2951 (setq file (expand-file-name file))
2952 (unless (file-exists-p (file-name-directory file))
2953 (make-directory (file-name-directory file) t))
2954 (if (and message-fcc-handler-function
2955 (not (eq message-fcc-handler-function 'rmail-output)))
2956 (funcall message-fcc-handler-function file)
2957 (if (and (file-readable-p file) (mail-file-babyl-p file))
2958 (rmail-output file 1 nil t)
2959 (let ((mail-use-rfc822 t))
2960 (rmail-output file 1 t t))))))
2961 (kill-buffer (current-buffer)))))
2963 (defun message-output (filename)
2964 "Append this article to Unix/babyl mail file FILENAME."
2965 (if (and (file-readable-p filename)
2966 (mail-file-babyl-p filename))
2967 (gnus-output-to-rmail filename t)
2968 (gnus-output-to-mail filename t)))
2970 (defun message-cleanup-headers ()
2971 "Do various automatic cleanups of the headers."
2972 ;; Remove empty lines in the header.
2973 (save-restriction
2974 (message-narrow-to-headers)
2975 ;; Remove blank lines.
2976 (while (re-search-forward "^[ \t]*\n" nil t)
2977 (replace-match "" t t))
2979 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2980 ;; spaces to comma and eliminate spaces around commas. Eliminate
2981 ;; embedded line breaks.
2982 (goto-char (point-min))
2983 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2984 (save-restriction
2985 (narrow-to-region
2986 (point)
2987 (if (re-search-forward "^[^ \t]" nil t)
2988 (match-beginning 0)
2989 (forward-line 1)
2990 (point)))
2991 (goto-char (point-min))
2992 (while (re-search-forward "\n[ \t]+" nil t)
2993 (replace-match " " t t)) ;No line breaks (too confusing)
2994 (goto-char (point-min))
2995 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2996 (replace-match "," t t))
2997 (goto-char (point-min))
2998 ;; Remove trailing commas.
2999 (when (re-search-forward ",+$" nil t)
3000 (replace-match "" t t))))))
3002 (defun message-make-date (&optional now)
3003 "Make a valid data header.
3004 If NOW, use that time instead."
3005 (let* ((now (or now (current-time)))
3006 (zone (nth 8 (decode-time now)))
3007 (sign "+"))
3008 (when (< zone 0)
3009 (setq sign "-")
3010 (setq zone (- zone)))
3011 (concat
3012 (format-time-string "%d" now)
3013 ;; The month name of the %b spec is locale-specific. Pfff.
3014 (format " %s "
3015 (capitalize (car (rassoc (nth 4 (decode-time now))
3016 parse-time-months))))
3017 (format-time-string "%Y %H:%M:%S " now)
3018 ;; We do all of this because XEmacs doesn't have the %z spec.
3019 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3021 (defun message-make-message-id ()
3022 "Make a unique Message-ID."
3023 (concat "<" (message-unique-id)
3024 (let ((psubject (save-excursion (message-fetch-field "subject")))
3025 (psupersedes
3026 (save-excursion (message-fetch-field "supersedes"))))
3027 (if (or
3028 (and message-reply-headers
3029 (mail-header-references message-reply-headers)
3030 (mail-header-subject message-reply-headers)
3031 psubject
3032 (not (string=
3033 (message-strip-subject-re
3034 (mail-header-subject message-reply-headers))
3035 (message-strip-subject-re psubject))))
3036 (and psupersedes
3037 (string-match "_-_@" psupersedes)))
3038 "_-_" ""))
3039 "@" (message-make-fqdn) ">"))
3041 (defvar message-unique-id-char nil)
3043 ;; If you ever change this function, make sure the new version
3044 ;; cannot generate IDs that the old version could.
3045 ;; You might for example insert a "." somewhere (not next to another dot
3046 ;; or string boundary), or modify the "fsf" string.
3047 (defun message-unique-id ()
3048 ;; Don't use microseconds from (current-time), they may be unsupported.
3049 ;; Instead we use this randomly inited counter.
3050 (setq message-unique-id-char
3051 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3052 ;; (current-time) returns 16-bit ints,
3053 ;; and 2^16*25 just fits into 4 digits i base 36.
3054 (* 25 25)))
3055 (let ((tm (current-time)))
3056 (concat
3057 (if (memq system-type '(ms-dos emx vax-vms))
3058 (let ((user (downcase (user-login-name))))
3059 (while (string-match "[^a-z0-9_]" user)
3060 (aset user (match-beginning 0) ?_))
3061 user)
3062 (message-number-base36 (user-uid) -1))
3063 (message-number-base36 (+ (car tm)
3064 (lsh (% message-unique-id-char 25) 16)) 4)
3065 (message-number-base36 (+ (nth 1 tm)
3066 (lsh (/ message-unique-id-char 25) 16)) 4)
3067 ;; Append the newsreader name, because while the generated
3068 ;; ID is unique to this newsreader, other newsreaders might
3069 ;; otherwise generate the same ID via another algorithm.
3070 ".fsf")))
3072 (defun message-number-base36 (num len)
3073 (if (if (< len 0)
3074 (<= num 0)
3075 (= len 0))
3077 (concat (message-number-base36 (/ num 36) (1- len))
3078 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3079 (% num 36))))))
3081 (defun message-make-organization ()
3082 "Make an Organization header."
3083 (let* ((organization
3084 (when message-user-organization
3085 (if (message-functionp message-user-organization)
3086 (funcall message-user-organization)
3087 message-user-organization))))
3088 (save-excursion
3089 (message-set-work-buffer)
3090 (cond ((stringp organization)
3091 (insert organization))
3092 ((and (eq t organization)
3093 message-user-organization-file
3094 (file-exists-p message-user-organization-file))
3095 (insert-file-contents message-user-organization-file)))
3096 (goto-char (point-min))
3097 (while (re-search-forward "[\t\n]+" nil t)
3098 (replace-match "" t t))
3099 (unless (zerop (buffer-size))
3100 (buffer-string)))))
3102 (defun message-make-lines ()
3103 "Count the number of lines and return numeric string."
3104 (save-excursion
3105 (save-restriction
3106 (widen)
3107 (goto-char (point-min))
3108 (re-search-forward
3109 (concat "^" (regexp-quote mail-header-separator) "$"))
3110 (forward-line 1)
3111 (int-to-string (count-lines (point) (point-max))))))
3113 (defun message-make-in-reply-to ()
3114 "Return the In-Reply-To header for this message."
3115 (when message-reply-headers
3116 (mail-header-message-id message-reply-headers)))
3118 (defun message-make-distribution ()
3119 "Make a Distribution header."
3120 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3121 (cond ((message-functionp message-distribution-function)
3122 (funcall message-distribution-function))
3123 (t orig-distribution))))
3125 (defun message-make-expires ()
3126 "Return an Expires header based on `message-expires'."
3127 (let ((current (current-time))
3128 (future (* 1.0 message-expires 60 60 24)))
3129 ;; Add the future to current.
3130 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3131 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3132 (message-make-date current)))
3134 (defun message-make-path ()
3135 "Return uucp path."
3136 (let ((login-name (user-login-name)))
3137 (cond ((null message-user-path)
3138 (concat (system-name) "!" login-name))
3139 ((stringp message-user-path)
3140 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3141 (concat message-user-path "!" login-name))
3142 (t login-name))))
3144 (defun message-make-from ()
3145 "Make a From header."
3146 (let* ((style message-from-style)
3147 (login (message-make-address))
3148 (fullname
3149 (or (and (boundp 'user-full-name)
3150 user-full-name)
3151 (user-full-name))))
3152 (when (string= fullname "&")
3153 (setq fullname (user-login-name)))
3154 (save-excursion
3155 (message-set-work-buffer)
3156 (cond
3157 ((or (null style)
3158 (equal fullname ""))
3159 (insert login))
3160 ((or (eq style 'angles)
3161 (and (not (eq style 'parens))
3162 ;; Use angles if no quoting is needed, or if parens would
3163 ;; need quoting too.
3164 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3165 (let ((tmp (concat fullname nil)))
3166 (while (string-match "([^()]*)" tmp)
3167 (aset tmp (match-beginning 0) ?-)
3168 (aset tmp (1- (match-end 0)) ?-))
3169 (string-match "[\\()]" tmp)))))
3170 (insert fullname)
3171 (goto-char (point-min))
3172 ;; Look for a character that cannot appear unquoted
3173 ;; according to RFC 822.
3174 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3175 ;; Quote fullname, escaping specials.
3176 (goto-char (point-min))
3177 (insert "\"")
3178 (while (re-search-forward "[\"\\]" nil 1)
3179 (replace-match "\\\\\\&" t))
3180 (insert "\""))
3181 (insert " <" login ">"))
3182 (t ; 'parens or default
3183 (insert login " (")
3184 (let ((fullname-start (point)))
3185 (insert fullname)
3186 (goto-char fullname-start)
3187 ;; RFC 822 says \ and nonmatching parentheses
3188 ;; must be escaped in comments.
3189 ;; Escape every instance of ()\ ...
3190 (while (re-search-forward "[()\\]" nil 1)
3191 (replace-match "\\\\\\&" t))
3192 ;; ... then undo escaping of matching parentheses,
3193 ;; including matching nested parentheses.
3194 (goto-char fullname-start)
3195 (while (re-search-forward
3196 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3197 nil 1)
3198 (replace-match "\\1(\\3)" t)
3199 (goto-char fullname-start)))
3200 (insert ")")))
3201 (buffer-string))))
3203 (defun message-make-sender ()
3204 "Return the \"real\" user address.
3205 This function tries to ignore all user modifications, and
3206 give as trustworthy answer as possible."
3207 (concat (user-login-name) "@" (system-name)))
3209 (defun message-make-address ()
3210 "Make the address of the user."
3211 (or (message-user-mail-address)
3212 (concat (user-login-name) "@" (message-make-domain))))
3214 (defun message-user-mail-address ()
3215 "Return the pertinent part of `user-mail-address'."
3216 (when user-mail-address
3217 (if (string-match " " user-mail-address)
3218 (nth 1 (mail-extract-address-components user-mail-address))
3219 user-mail-address)))
3221 (defun message-make-fqdn ()
3222 "Return user's fully qualified domain name."
3223 (let ((system-name (system-name))
3224 (user-mail (message-user-mail-address)))
3225 (cond
3226 ((string-match "[^.]\\.[^.]" system-name)
3227 ;; `system-name' returned the right result.
3228 system-name)
3229 ;; Try `mail-host-address'.
3230 ((and (boundp 'mail-host-address)
3231 (stringp mail-host-address)
3232 (string-match "\\." mail-host-address))
3233 mail-host-address)
3234 ;; We try `user-mail-address' as a backup.
3235 ((and user-mail
3236 (string-match "\\." user-mail)
3237 (string-match "@\\(.*\\)\\'" user-mail))
3238 (match-string 1 user-mail))
3239 ;; Default to this bogus thing.
3241 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3243 (defun message-make-host-name ()
3244 "Return the name of the host."
3245 (let ((fqdn (message-make-fqdn)))
3246 (string-match "^[^.]+\\." fqdn)
3247 (substring fqdn 0 (1- (match-end 0)))))
3249 (defun message-make-domain ()
3250 "Return the domain name."
3251 (or mail-host-address
3252 (message-make-fqdn)))
3254 (defun message-generate-headers (headers)
3255 "Prepare article HEADERS.
3256 Headers already prepared in the buffer are not modified."
3257 (save-restriction
3258 (message-narrow-to-headers)
3259 (let* ((Date (message-make-date))
3260 (Message-ID (message-make-message-id))
3261 (Organization (message-make-organization))
3262 (From (message-make-from))
3263 (Path (message-make-path))
3264 (Subject nil)
3265 (Newsgroups nil)
3266 (In-Reply-To (message-make-in-reply-to))
3267 (To nil)
3268 (Distribution (message-make-distribution))
3269 (Lines (message-make-lines))
3270 (User-Agent message-newsreader)
3271 (Expires (message-make-expires))
3272 (case-fold-search t)
3273 header value elem)
3274 ;; First we remove any old generated headers.
3275 (let ((headers message-deletable-headers))
3276 (unless (buffer-modified-p)
3277 (setq headers (delq 'Message-ID (copy-sequence headers))))
3278 (while headers
3279 (goto-char (point-min))
3280 (and (re-search-forward
3281 (concat "^" (symbol-name (car headers)) ": *") nil t)
3282 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3283 (message-delete-line))
3284 (pop headers)))
3285 ;; Go through all the required headers and see if they are in the
3286 ;; articles already. If they are not, or are empty, they are
3287 ;; inserted automatically - except for Subject, Newsgroups and
3288 ;; Distribution.
3289 (while headers
3290 (goto-char (point-min))
3291 (setq elem (pop headers))
3292 (if (consp elem)
3293 (if (eq (car elem) 'optional)
3294 (setq header (cdr elem))
3295 (setq header (car elem)))
3296 (setq header elem))
3297 (when (or (not (re-search-forward
3298 (concat "^"
3299 (regexp-quote
3300 (downcase
3301 (if (stringp header)
3302 header
3303 (symbol-name header))))
3304 ":")
3305 nil t))
3306 (progn
3307 ;; The header was found. We insert a space after the
3308 ;; colon, if there is none.
3309 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3310 ;; Find out whether the header is empty...
3311 (looking-at "[ \t]*\n[^ \t]")))
3312 ;; So we find out what value we should insert.
3313 (setq value
3314 (cond
3315 ((and (consp elem) (eq (car elem) 'optional))
3316 ;; This is an optional header. If the cdr of this
3317 ;; is something that is nil, then we do not insert
3318 ;; this header.
3319 (setq header (cdr elem))
3320 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3321 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3322 ((consp elem)
3323 ;; The element is a cons. Either the cdr is a
3324 ;; string to be inserted verbatim, or it is a
3325 ;; function, and we insert the value returned from
3326 ;; this function.
3327 (or (and (stringp (cdr elem)) (cdr elem))
3328 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3329 ((and (boundp header) (symbol-value header))
3330 ;; The element is a symbol. We insert the value
3331 ;; of this symbol, if any.
3332 (symbol-value header))
3333 ((not (message-check-element header))
3334 ;; We couldn't generate a value for this header,
3335 ;; so we just ask the user.
3336 (read-from-minibuffer
3337 (format "Empty header for %s; enter value: " header)))))
3338 ;; Finally insert the header.
3339 (when (and value
3340 (not (equal value "")))
3341 (save-excursion
3342 (if (bolp)
3343 (progn
3344 ;; This header didn't exist, so we insert it.
3345 (goto-char (point-max))
3346 (insert (if (stringp header) header (symbol-name header))
3347 ": " value "\n")
3348 (forward-line -1))
3349 ;; The value of this header was empty, so we clear
3350 ;; totally and insert the new value.
3351 (delete-region (point) (gnus-point-at-eol))
3352 (insert value))
3353 ;; Add the deletable property to the headers that require it.
3354 (and (memq header message-deletable-headers)
3355 (progn (beginning-of-line) (looking-at "[^:]+: "))
3356 (add-text-properties
3357 (point) (match-end 0)
3358 '(message-deletable t face italic) (current-buffer)))))))
3359 ;; Insert new Sender if the From is strange.
3360 (let ((from (message-fetch-field "from"))
3361 (sender (message-fetch-field "sender"))
3362 (secure-sender (message-make-sender)))
3363 (when (and from
3364 (not (message-check-element 'sender))
3365 (not (string=
3366 (downcase
3367 (cadr (mail-extract-address-components from)))
3368 (downcase secure-sender)))
3369 (or (null sender)
3370 (not
3371 (string=
3372 (downcase
3373 (cadr (mail-extract-address-components sender)))
3374 (downcase secure-sender)))))
3375 (goto-char (point-min))
3376 ;; Rename any old Sender headers to Original-Sender.
3377 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3378 (beginning-of-line)
3379 (insert "Original-")
3380 (beginning-of-line))
3381 (when (or (message-news-p)
3382 (string-match "@.+\\.." secure-sender))
3383 (insert "Sender: " secure-sender "\n")))))))
3385 (defun message-insert-courtesy-copy ()
3386 "Insert a courtesy message in mail copies of combined messages."
3387 (let (newsgroups)
3388 (save-excursion
3389 (save-restriction
3390 (message-narrow-to-headers)
3391 (when (setq newsgroups (message-fetch-field "newsgroups"))
3392 (goto-char (point-max))
3393 (insert "Posted-To: " newsgroups "\n")))
3394 (forward-line 1)
3395 (when message-courtesy-message
3396 (cond
3397 ((string-match "%s" message-courtesy-message)
3398 (insert (format message-courtesy-message newsgroups)))
3400 (insert message-courtesy-message)))))))
3403 ;;; Setting up a message buffer
3406 (defun message-fill-address (header value)
3407 (save-restriction
3408 (narrow-to-region (point) (point))
3409 (insert (capitalize (symbol-name header))
3410 ": "
3411 (if (consp value) (car value) value)
3412 "\n")
3413 (narrow-to-region (point-min) (1- (point-max)))
3414 (let (quoted last)
3415 (goto-char (point-min))
3416 (while (not (eobp))
3417 (skip-chars-forward "^,\"" (point-max))
3418 (if (or (eq (char-after) ?,)
3419 (eobp))
3420 (when (not quoted)
3421 (if (and (> (current-column) 78)
3422 last)
3423 (progn
3424 (save-excursion
3425 (goto-char last)
3426 (insert "\n\t"))
3427 (setq last (1+ (point))))
3428 (setq last (1+ (point)))))
3429 (setq quoted (not quoted)))
3430 (unless (eobp)
3431 (forward-char 1))))
3432 (goto-char (point-max))
3433 (widen)
3434 (forward-line 1)))
3436 (defun message-fill-header (header value)
3437 (let ((begin (point))
3438 (fill-column 78)
3439 (fill-prefix "\t"))
3440 (insert (capitalize (symbol-name header))
3441 ": "
3442 (if (consp value) (car value) value)
3443 "\n")
3444 (save-restriction
3445 (narrow-to-region begin (point))
3446 (fill-region-as-paragraph begin (point))
3447 ;; Tapdance around looong Message-IDs.
3448 (forward-line -1)
3449 (when (looking-at "[ \t]*$")
3450 (message-delete-line))
3451 (goto-char begin)
3452 (re-search-forward ":" nil t)
3453 (when (looking-at "\n[ \t]+")
3454 (replace-match " " t t))
3455 (goto-char (point-max)))))
3457 (defun message-shorten-1 (list cut surplus)
3458 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
3459 (setcdr (nthcdr (- cut 2) list)
3460 (nthcdr (+ (- cut 2) surplus 1) list)))
3462 (defun message-shorten-references (header references)
3463 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3464 If folding is disallowed, also check that the REFERENCES are less
3465 than 988 characters long, and if they are not, trim them until they are."
3466 (let ((maxcount 31)
3467 (count 0)
3468 (cut 6)
3469 refs)
3470 (with-temp-buffer
3471 (insert references)
3472 (goto-char (point-min))
3473 ;; Cons a list of valid references.
3474 (while (re-search-forward "<[^>]+>" nil t)
3475 (push (match-string 0) refs))
3476 (setq refs (nreverse refs)
3477 count (length refs)))
3479 ;; If the list has more than MAXCOUNT elements, trim it by
3480 ;; removing the CUTth element and the required number of
3481 ;; elements that follow.
3482 (when (> count maxcount)
3483 (let ((surplus (- count maxcount)))
3484 (message-shorten-1 refs cut surplus)
3485 (decf count surplus)))
3487 ;; If folding is disallowed, make sure the total length (including
3488 ;; the spaces between) will be less than MAXSIZE characters.
3490 ;; Only disallow folding for News messages. At this point the headers
3491 ;; have not been generated, thus we use message-this-is-news directly.
3492 (when (and message-this-is-news message-cater-to-broken-inn)
3493 (let ((maxsize 988)
3494 (totalsize (+ (apply #'+ (mapcar #'length refs))
3495 (1- count)))
3496 (surplus 0)
3497 (ptr (nthcdr (1- cut) refs)))
3498 ;; Decide how many elements to cut off...
3499 (while (> totalsize maxsize)
3500 (decf totalsize (1+ (length (car ptr))))
3501 (incf surplus)
3502 (setq ptr (cdr ptr)))
3503 ;; ...and do it.
3504 (when (> surplus 0)
3505 (message-shorten-1 refs cut surplus))))
3507 ;; Finally, collect the references back into a string and insert
3508 ;; it into the buffer.
3509 (let ((refstring (mapconcat #'identity refs " ")))
3510 (if (and message-this-is-news message-cater-to-broken-inn)
3511 (insert (capitalize (symbol-name header)) ": "
3512 refstring "\n")
3513 (message-fill-header header refstring)))))
3515 (defun message-position-point ()
3516 "Move point to where the user probably wants to find it."
3517 (message-narrow-to-headers)
3518 (cond
3519 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3520 (search-backward ":" )
3521 (widen)
3522 (forward-char 1)
3523 (if (eq (char-after) ? )
3524 (forward-char 1)
3525 (insert " ")))
3527 (goto-char (point-max))
3528 (widen)
3529 (forward-line 1)
3530 (unless (looking-at "$")
3531 (forward-line 2)))
3532 (sit-for 0)))
3534 (defun message-buffer-name (type &optional to group)
3535 "Return a new (unique) buffer name based on TYPE and TO."
3536 (cond
3537 ;; Generate a new buffer name The Message Way.
3538 ((eq message-generate-new-buffers 'unique)
3539 (generate-new-buffer-name
3540 (concat "*" type
3541 (if to
3542 (concat " to "
3543 (or (car (mail-extract-address-components to))
3544 to) "")
3546 (if (and group (not (string= group ""))) (concat " on " group) "")
3547 "*")))
3548 ;; Check whether `message-generate-new-buffers' is a function,
3549 ;; and if so, call it.
3550 ((message-functionp message-generate-new-buffers)
3551 (funcall message-generate-new-buffers type to group))
3552 ((eq message-generate-new-buffers 'unsent)
3553 (generate-new-buffer-name
3554 (concat "*unsent " type
3555 (if to
3556 (concat " to "
3557 (or (car (mail-extract-address-components to))
3558 to) "")
3560 (if (and group (not (string= group ""))) (concat " on " group) "")
3561 "*")))
3562 ;; Use standard name.
3564 (format "*%s message*" type))))
3566 (defun message-pop-to-buffer (name)
3567 "Pop to buffer NAME, and warn if it already exists and is modified."
3568 (let ((buffer (get-buffer name)))
3569 (if (and buffer
3570 (buffer-name buffer))
3571 (progn
3572 (set-buffer (pop-to-buffer buffer))
3573 (when (and (buffer-modified-p)
3574 (not (y-or-n-p
3575 "Message already being composed; erase? ")))
3576 (error "Message being composed")))
3577 (set-buffer (pop-to-buffer name)))
3578 (erase-buffer)
3579 (message-mode)))
3581 (defun message-do-send-housekeeping ()
3582 "Kill old message buffers."
3583 ;; We might have sent this buffer already. Delete it from the
3584 ;; list of buffers.
3585 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3586 (while (and message-max-buffers
3587 message-buffer-list
3588 (>= (length message-buffer-list) message-max-buffers))
3589 ;; Kill the oldest buffer -- unless it has been changed.
3590 (let ((buffer (pop message-buffer-list)))
3591 (when (and (buffer-name buffer)
3592 (not (buffer-modified-p buffer)))
3593 (kill-buffer buffer))))
3594 ;; Rename the buffer.
3595 (if message-send-rename-function
3596 (funcall message-send-rename-function)
3597 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3598 (rename-buffer
3599 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3600 ;; Push the current buffer onto the list.
3601 (when message-max-buffers
3602 (setq message-buffer-list
3603 (nconc message-buffer-list (list (current-buffer))))))
3605 (defun message-mail-user-agent ()
3606 (let ((mua (cond
3607 ((not message-mail-user-agent) nil)
3608 ((eq message-mail-user-agent t) mail-user-agent)
3609 (t message-mail-user-agent))))
3610 (if (memq mua '(message-user-agent gnus-user-agent))
3612 mua)))
3614 (defun message-setup (headers &optional replybuffer actions switch-function)
3615 (let ((mua (message-mail-user-agent))
3616 subject to field yank-action)
3617 (if (not (and message-this-is-mail mua))
3618 (message-setup-1 headers replybuffer actions)
3619 (if replybuffer
3620 (setq yank-action (list 'insert-buffer replybuffer)))
3621 (setq headers (copy-sequence headers))
3622 (setq field (assq 'Subject headers))
3623 (when field
3624 (setq subject (cdr field))
3625 (setq headers (delq field headers)))
3626 (setq field (assq 'To headers))
3627 (when field
3628 (setq to (cdr field))
3629 (setq headers (delq field headers)))
3630 (let ((mail-user-agent mua))
3631 (compose-mail to subject
3632 (mapcar (lambda (item)
3633 (cons
3634 (format "%s" (car item))
3635 (cdr item)))
3636 headers)
3637 nil switch-function yank-action actions)))))
3639 (eval-when-compile (defvar mc-modes-alist))
3640 (defun message-setup-1 (headers &optional replybuffer actions)
3641 (when (and (boundp 'mc-modes-alist)
3642 (not (assq 'message-mode mc-modes-alist)))
3643 (push '(message-mode (encrypt . mc-encrypt-message)
3644 (sign . mc-sign-message))
3645 mc-modes-alist))
3646 (dolist (action actions)
3647 (condition-case nil
3648 (add-to-list 'message-send-actions
3649 `(apply ',(car action) ',(cdr action)))))
3650 (setq message-reply-buffer replybuffer)
3651 (goto-char (point-min))
3652 ;; Insert all the headers.
3653 (mail-header-format
3654 (let ((h headers)
3655 (alist message-header-format-alist))
3656 (while h
3657 (unless (assq (caar h) message-header-format-alist)
3658 (push (list (caar h)) alist))
3659 (pop h))
3660 alist)
3661 headers)
3662 (delete-region (point) (progn (forward-line -1) (point)))
3663 (when message-default-headers
3664 (insert message-default-headers)
3665 (or (bolp) (insert ?\n)))
3666 (put-text-property
3667 (point)
3668 (progn
3669 (insert mail-header-separator "\n")
3670 (1- (point)))
3671 'read-only nil)
3672 (forward-line -1)
3673 (when (message-news-p)
3674 (when message-default-news-headers
3675 (insert message-default-news-headers)
3676 (or (bolp) (insert ?\n)))
3677 (when message-generate-headers-first
3678 (message-generate-headers
3679 (delq 'Lines
3680 (delq 'Subject
3681 (copy-sequence message-required-news-headers))))))
3682 (when (message-mail-p)
3683 (when message-default-mail-headers
3684 (insert message-default-mail-headers)
3685 (or (bolp) (insert ?\n)))
3686 (when message-generate-headers-first
3687 (message-generate-headers
3688 (delq 'Lines
3689 (delq 'Subject
3690 (copy-sequence message-required-mail-headers))))))
3691 (run-hooks 'message-signature-setup-hook)
3692 (message-insert-signature)
3693 (save-restriction
3694 (message-narrow-to-headers)
3695 (if message-alternative-emails
3696 (message-use-alternative-email-as-from))
3697 (run-hooks 'message-header-setup-hook))
3698 (set-buffer-modified-p nil)
3699 (setq buffer-undo-list nil)
3700 (run-hooks 'message-setup-hook)
3701 (message-position-point)
3702 (undo-boundary))
3704 (defun message-set-auto-save-file-name ()
3705 "Associate the message buffer with a file in the drafts directory."
3706 (when message-auto-save-directory
3707 (unless (file-directory-p
3708 (directory-file-name message-auto-save-directory))
3709 (make-directory message-auto-save-directory t))
3710 (if (gnus-alive-p)
3711 (setq message-draft-article
3712 (nndraft-request-associate-buffer "drafts"))
3713 (setq buffer-file-name (expand-file-name "*message*"
3714 message-auto-save-directory))
3715 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3716 (clear-visited-file-modtime)
3717 (setq buffer-file-coding-system message-draft-coding-system)))
3719 (defun message-disassociate-draft ()
3720 "Disassociate the message buffer from the drafts directory."
3721 (when message-draft-article
3722 (nndraft-request-expire-articles
3723 (list message-draft-article) "drafts" nil t)))
3725 (defun message-insert-headers ()
3726 "Generate the headers for the article."
3727 (interactive)
3728 (save-excursion
3729 (save-restriction
3730 (message-narrow-to-headers)
3731 (when (message-news-p)
3732 (message-generate-headers
3733 (delq 'Lines
3734 (delq 'Subject
3735 (copy-sequence message-required-news-headers)))))
3736 (when (message-mail-p)
3737 (message-generate-headers
3738 (delq 'Lines
3739 (delq 'Subject
3740 (copy-sequence message-required-mail-headers))))))))
3745 ;;; Commands for interfacing with message
3748 ;;;###autoload
3749 (defun message-mail (&optional to subject
3750 other-headers continue switch-function
3751 yank-action send-actions)
3752 "Start editing a mail message to be sent.
3753 OTHER-HEADERS is an alist of header/value pairs."
3754 (interactive)
3755 (let ((message-this-is-mail t) replybuffer)
3756 (unless (message-mail-user-agent)
3757 (message-pop-to-buffer (message-buffer-name "mail" to)))
3758 ;; FIXME: message-mail should do something if YANK-ACTION is not
3759 ;; insert-buffer.
3760 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
3761 (setq replybuffer (nth 1 yank-action)))
3762 (message-setup
3763 (nconc
3764 `((To . ,(or to "")) (Subject . ,(or subject "")))
3765 (when other-headers other-headers))
3766 replybuffer send-actions)
3767 ;; FIXME: Should return nil if failure.
3770 ;;;###autoload
3771 (defun message-news (&optional newsgroups subject)
3772 "Start editing a news article to be sent."
3773 (interactive)
3774 (let ((message-this-is-news t))
3775 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3776 (message-setup `((Newsgroups . ,(or newsgroups ""))
3777 (Subject . ,(or subject ""))))))
3779 (defun message-get-reply-headers (wide &optional to-address)
3780 (let (follow-to mct never-mct from to cc reply-to ccalist)
3781 ;; Find all relevant headers we need.
3782 (setq from (message-fetch-field "from")
3783 to (message-fetch-field "to")
3784 cc (message-fetch-field "cc")
3785 mct (message-fetch-field "mail-copies-to")
3786 reply-to (message-fetch-field "reply-to"))
3788 ;; Handle special values of Mail-Copies-To.
3789 (when mct
3790 (cond ((or (equal (downcase mct) "never")
3791 (equal (downcase mct) "nobody"))
3792 (setq never-mct t)
3793 (setq mct nil))
3794 ((or (equal (downcase mct) "always")
3795 (equal (downcase mct) "poster"))
3796 (setq mct (or reply-to from)))))
3798 (if (or (not wide)
3799 to-address)
3800 (progn
3801 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3802 (when (and wide mct)
3803 (push (cons 'Cc mct) follow-to)))
3804 (let (ccalist)
3805 (save-excursion
3806 (message-set-work-buffer)
3807 (unless never-mct
3808 (insert (or reply-to from "")))
3809 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3810 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3811 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3812 (goto-char (point-min))
3813 (while (re-search-forward "[ \t]+" nil t)
3814 (replace-match " " t t))
3815 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3816 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
3817 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3818 (erase-buffer))))
3819 (goto-char (point-min))
3820 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3821 (when (eobp)
3822 (insert (or reply-to from "")))
3823 (setq ccalist
3824 (mapcar
3825 (lambda (addr)
3826 (cons (mail-strip-quoted-names addr) addr))
3827 (message-tokenize-header (buffer-string))))
3828 (let ((s ccalist))
3829 (while s
3830 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3831 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3832 (when ccalist
3833 (let ((ccs (cons 'Cc (mapconcat
3834 (lambda (addr) (cdr addr)) ccalist ", "))))
3835 (when (string-match "^ +" (cdr ccs))
3836 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3837 (push ccs follow-to)))))
3838 follow-to))
3841 ;;;###autoload
3842 (defun message-reply (&optional to-address wide)
3843 "Start editing a reply to the article in the current buffer."
3844 (interactive)
3845 (require 'gnus-sum) ; for gnus-list-identifiers
3846 (let ((cur (current-buffer))
3847 from subject date reply-to to cc
3848 references message-id follow-to
3849 (inhibit-point-motion-hooks t)
3850 (message-this-is-mail t)
3851 gnus-warning)
3852 (save-restriction
3853 (message-narrow-to-head-1)
3854 ;; Allow customizations to have their say.
3855 (if (not wide)
3856 ;; This is a regular reply.
3857 (if (message-functionp message-reply-to-function)
3858 (setq follow-to (funcall message-reply-to-function)))
3859 ;; This is a followup.
3860 (if (message-functionp message-wide-reply-to-function)
3861 (save-excursion
3862 (setq follow-to
3863 (funcall message-wide-reply-to-function)))))
3864 (setq message-id (message-fetch-field "message-id" t)
3865 references (message-fetch-field "references")
3866 date (message-fetch-field "date")
3867 from (message-fetch-field "from")
3868 subject (or (message-fetch-field "subject") "none"))
3869 (if gnus-list-identifiers
3870 (setq subject (message-strip-list-identifiers subject)))
3871 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3873 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3874 (string-match "<[^>]+>" gnus-warning))
3875 (setq message-id (match-string 0 gnus-warning)))
3877 (unless follow-to
3878 (setq follow-to (message-get-reply-headers wide to-address))))
3880 (unless (message-mail-user-agent)
3881 (message-pop-to-buffer
3882 (message-buffer-name
3883 (if wide "wide reply" "reply") from
3884 (if wide to-address nil))))
3886 (setq message-reply-headers
3887 (vector 0 subject from date message-id references 0 0 ""))
3889 (message-setup
3890 `((Subject . ,subject)
3891 ,@follow-to
3892 ,@(if (or references message-id)
3893 `((References . ,(concat (or references "") (and references " ")
3894 (or message-id ""))))
3895 nil))
3896 cur)))
3898 ;;;###autoload
3899 (defun message-wide-reply (&optional to-address)
3900 "Make a \"wide\" reply to the message in the current buffer."
3901 (interactive)
3902 (message-reply to-address t))
3904 ;;;###autoload
3905 (defun message-followup (&optional to-newsgroups)
3906 "Follow up to the message in the current buffer.
3907 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3908 (interactive)
3909 (require 'gnus-sum) ; for gnus-list-identifiers
3910 (let ((cur (current-buffer))
3911 from subject date reply-to mct
3912 references message-id follow-to
3913 (inhibit-point-motion-hooks t)
3914 (message-this-is-news t)
3915 followup-to distribution newsgroups gnus-warning posted-to)
3916 (save-restriction
3917 (narrow-to-region
3918 (goto-char (point-min))
3919 (if (search-forward "\n\n" nil t)
3920 (1- (point))
3921 (point-max)))
3922 (when (message-functionp message-followup-to-function)
3923 (setq follow-to
3924 (funcall message-followup-to-function)))
3925 (setq from (message-fetch-field "from")
3926 date (message-fetch-field "date")
3927 subject (or (message-fetch-field "subject") "none")
3928 references (message-fetch-field "references")
3929 message-id (message-fetch-field "message-id" t)
3930 followup-to (message-fetch-field "followup-to")
3931 newsgroups (message-fetch-field "newsgroups")
3932 posted-to (message-fetch-field "posted-to")
3933 reply-to (message-fetch-field "reply-to")
3934 distribution (message-fetch-field "distribution")
3935 mct (message-fetch-field "mail-copies-to"))
3936 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3937 (string-match "<[^>]+>" gnus-warning))
3938 (setq message-id (match-string 0 gnus-warning)))
3939 ;; Remove bogus distribution.
3940 (when (and (stringp distribution)
3941 (let ((case-fold-search t))
3942 (string-match "world" distribution)))
3943 (setq distribution nil))
3944 (if gnus-list-identifiers
3945 (setq subject (message-strip-list-identifiers subject)))
3946 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3947 (widen))
3949 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3951 (message-setup
3952 `((Subject . ,subject)
3953 ,@(cond
3954 (to-newsgroups
3955 (list (cons 'Newsgroups to-newsgroups)))
3956 (follow-to follow-to)
3957 ((and followup-to message-use-followup-to)
3958 (list
3959 (cond
3960 ((equal (downcase followup-to) "poster")
3961 (if (or (eq message-use-followup-to 'use)
3962 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3963 You should normally obey the Followup-To: header.
3965 `Followup-To: poster' sends your response via e-mail instead of news.
3967 A typical situation where `Followup-To: poster' is used is when the poster
3968 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3969 (progn
3970 (setq message-this-is-news nil)
3971 (cons 'To (or reply-to from "")))
3972 (cons 'Newsgroups newsgroups)))
3974 (if (or (equal followup-to newsgroups)
3975 (not (eq message-use-followup-to 'ask))
3976 (message-y-or-n-p
3977 (concat "Obey Followup-To: " followup-to "? ") t "\
3978 You should normally obey the Followup-To: header.
3980 `Followup-To: " followup-to "'
3981 directs your response to " (if (string-match "," followup-to)
3982 "the specified newsgroups"
3983 "that newsgroup only") ".
3985 If a message is posted to several newsgroups, Followup-To is often
3986 used to direct the following discussion to one newsgroup only,
3987 because discussions that are spread over several newsgroup tend to
3988 be fragmented and very difficult to follow.
3990 Also, some source/announcement newsgroups are not indented for discussion;
3991 responses here are directed to other newsgroups."))
3992 (cons 'Newsgroups followup-to)
3993 (cons 'Newsgroups newsgroups))))))
3994 (posted-to
3995 `((Newsgroups . ,posted-to)))
3997 `((Newsgroups . ,newsgroups))))
3998 ,@(and distribution (list (cons 'Distribution distribution)))
3999 ,@(if (or references message-id)
4000 `((References . ,(concat (or references "") (and references " ")
4001 (or message-id "")))))
4002 ,@(when (and mct
4003 (not (or (equal (downcase mct) "never")
4004 (equal (downcase mct) "nobody"))))
4005 (list (cons 'Cc (if (or (equal (downcase mct) "always")
4006 (equal (downcase mct) "poster"))
4007 (or reply-to from "")
4008 mct)))))
4010 cur)
4012 (setq message-reply-headers
4013 (vector 0 subject from date message-id references 0 0 ""))))
4016 ;;;###autoload
4017 (defun message-cancel-news (&optional arg)
4018 "Cancel an article you posted.
4019 If ARG, allow editing of the cancellation message."
4020 (interactive "P")
4021 (unless (message-news-p)
4022 (error "This is not a news article; canceling is impossible"))
4023 (when (yes-or-no-p "Do you really want to cancel this article? ")
4024 (let (from newsgroups message-id distribution buf sender)
4025 (save-excursion
4026 ;; Get header info from original article.
4027 (save-restriction
4028 (message-narrow-to-head-1)
4029 (setq from (message-fetch-field "from")
4030 sender (message-fetch-field "sender")
4031 newsgroups (message-fetch-field "newsgroups")
4032 message-id (message-fetch-field "message-id" t)
4033 distribution (message-fetch-field "distribution")))
4034 ;; Make sure that this article was written by the user.
4035 (unless (or (and sender
4036 (string-equal
4037 (downcase sender)
4038 (downcase (message-make-sender))))
4039 (string-equal
4040 (downcase (cadr (mail-extract-address-components from)))
4041 (downcase (cadr (mail-extract-address-components
4042 (message-make-from))))))
4043 (error "This article is not yours"))
4044 ;; Make control message.
4045 (if arg
4046 (message-news)
4047 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4048 (erase-buffer)
4049 (insert "Newsgroups: " newsgroups "\n"
4050 "From: " from "\n"
4051 "Subject: cmsg cancel " message-id "\n"
4052 "Control: cancel " message-id "\n"
4053 (if distribution
4054 (concat "Distribution: " distribution "\n")
4056 mail-header-separator "\n"
4057 message-cancel-message)
4058 (run-hooks 'message-cancel-hook)
4059 (unless arg
4060 (message "Canceling your article...")
4061 (if (let ((message-syntax-checks
4062 'dont-check-for-anything-just-trust-me))
4063 (funcall message-send-news-function))
4064 (message "Canceling your article...done"))
4065 (kill-buffer buf))))))
4067 ;;;###autoload
4068 (defun message-supersede ()
4069 "Start composing a message to supersede the current message.
4070 This is done simply by taking the old article and adding a Supersedes
4071 header line with the old Message-ID."
4072 (interactive)
4073 (let ((cur (current-buffer))
4074 (sender (message-fetch-field "sender"))
4075 (from (message-fetch-field "from")))
4076 ;; Check whether the user owns the article that is to be superseded.
4077 (unless (or (and sender
4078 (string-equal
4079 (downcase sender)
4080 (downcase (message-make-sender))))
4081 (string-equal
4082 (downcase (cadr (mail-extract-address-components from)))
4083 (downcase (cadr (mail-extract-address-components
4084 (message-make-from))))))
4085 (error "This article is not yours"))
4086 ;; Get a normal message buffer.
4087 (message-pop-to-buffer (message-buffer-name "supersede"))
4088 (insert-buffer-substring cur)
4089 (mime-to-mml)
4090 (message-narrow-to-head-1)
4091 ;; Remove unwanted headers.
4092 (when message-ignored-supersedes-headers
4093 (message-remove-header message-ignored-supersedes-headers t))
4094 (goto-char (point-min))
4095 (if (not (re-search-forward "^Message-ID: " nil t))
4096 (error "No Message-ID in this article")
4097 (replace-match "Supersedes: " t t))
4098 (goto-char (point-max))
4099 (insert mail-header-separator)
4100 (widen)
4101 (forward-line 1)))
4103 ;;;###autoload
4104 (defun message-recover ()
4105 "Reread contents of current buffer from its last auto-save file."
4106 (interactive)
4107 (let ((file-name (make-auto-save-file-name)))
4108 (cond ((save-window-excursion
4109 (if (not (eq system-type 'vax-vms))
4110 (with-output-to-temp-buffer "*Directory*"
4111 (with-current-buffer standard-output
4112 (fundamental-mode)) ; for Emacs 20.4+
4113 (buffer-disable-undo standard-output)
4114 (let ((default-directory "/"))
4115 (call-process
4116 "ls" nil standard-output nil "-l" file-name))))
4117 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4118 (let ((buffer-read-only nil))
4119 (erase-buffer)
4120 (insert-file-contents file-name nil)))
4121 (t (error "message-recover cancelled")))))
4123 ;;; Washing Subject:
4125 (defun message-wash-subject (subject)
4126 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
4127 Previous forwarders, replyers, etc. may add it."
4128 (with-temp-buffer
4129 (insert subject)
4130 (goto-char (point-min))
4131 ;; strip Re/Fwd stuff off the beginning
4132 (while (re-search-forward
4133 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4134 (replace-match ""))
4136 ;; and gnus-style forwards [foo@bar.com] subject
4137 (goto-char (point-min))
4138 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4139 (replace-match ""))
4141 ;; and off the end
4142 (goto-char (point-max))
4143 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4144 (replace-match ""))
4146 ;; and finally, any whitespace that was left-over
4147 (goto-char (point-min))
4148 (while (re-search-forward "^[ \t]+" nil t)
4149 (replace-match ""))
4150 (goto-char (point-max))
4151 (while (re-search-backward "[ \t]+$" nil t)
4152 (replace-match ""))
4154 (buffer-string)))
4156 ;;; Forwarding messages.
4158 (defvar message-forward-decoded-p nil
4159 "Non-nil means the original message is decoded.")
4161 (defun message-forward-subject-author-subject (subject)
4162 "Generate a SUBJECT for a forwarded message.
4163 The form is: [Source] Subject, where if the original message was mail,
4164 Source is the sender, and if the original message was news, Source is
4165 the list of newsgroups is was posted to."
4166 (concat "["
4167 (let ((prefix
4168 (or (message-fetch-field "newsgroups")
4169 (message-fetch-field "from")
4170 "(nowhere)")))
4171 (if message-forward-decoded-p
4172 prefix
4173 (mail-decode-encoded-word-string prefix)))
4174 "] " subject))
4176 (defun message-forward-subject-fwd (subject)
4177 "Generate a SUBJECT for a forwarded message.
4178 The form is: Fwd: Subject, where Subject is the original subject of
4179 the message."
4180 (concat "Fwd: " subject))
4182 (defun message-make-forward-subject ()
4183 "Return a Subject header suitable for the message in the current buffer."
4184 (save-excursion
4185 (save-restriction
4186 (message-narrow-to-head-1)
4187 (let ((funcs message-make-forward-subject-function)
4188 (subject (message-fetch-field "Subject")))
4189 (setq subject
4190 (if subject
4191 (if message-forward-decoded-p
4192 subject
4193 (mail-decode-encoded-word-string subject))
4194 ""))
4195 (if message-wash-forwarded-subjects
4196 (setq subject (message-wash-subject subject)))
4197 ;; Make sure funcs is a list.
4198 (and funcs
4199 (not (listp funcs))
4200 (setq funcs (list funcs)))
4201 ;; Apply funcs in order, passing subject generated by previous
4202 ;; func to the next one.
4203 (while funcs
4204 (when (message-functionp (car funcs))
4205 (setq subject (funcall (car funcs) subject)))
4206 (setq funcs (cdr funcs)))
4207 subject))))
4209 (eval-when-compile
4210 (defvar gnus-article-decoded-p))
4213 ;;;###autoload
4214 (defun message-forward (&optional news digest)
4215 "Forward the current message via mail.
4216 Optional NEWS will use news to forward instead of mail.
4217 Optional DIGEST will use digest to forward."
4218 (interactive "P")
4219 (let* ((cur (current-buffer))
4220 (message-forward-decoded-p
4221 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
4222 gnus-article-decoded-p ;; In an article buffer.
4223 message-forward-decoded-p))
4224 (subject (message-make-forward-subject)))
4225 (if news
4226 (message-news nil subject)
4227 (message-mail nil subject))
4228 (message-forward-make-body cur digest)))
4230 ;;;###autoload
4231 (defun message-forward-make-body (forward-buffer &optional digest)
4232 ;; Put point where we want it before inserting the forwarded
4233 ;; message.
4234 (if message-forward-before-signature
4235 (message-goto-body)
4236 (goto-char (point-max)))
4237 (if message-forward-as-mime
4238 (if digest
4239 (insert "\n<#multipart type=digest>\n")
4240 (if message-forward-show-mml
4241 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4242 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4243 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4244 (let ((b (point)) e)
4245 (if digest
4246 (if message-forward-as-mime
4247 (insert-buffer-substring forward-buffer)
4248 (mml-insert-buffer forward-buffer))
4249 (if (and message-forward-show-mml
4250 (not message-forward-decoded-p))
4251 (insert
4252 (with-temp-buffer
4253 (mm-disable-multibyte) ;; Must copy buffer in unibyte mode
4254 (insert
4255 (with-current-buffer forward-buffer
4256 (mm-string-as-unibyte (buffer-string))))
4257 (mm-enable-multibyte)
4258 (mime-to-mml)
4259 (goto-char (point-min))
4260 (when (looking-at "From ")
4261 (replace-match "X-From-Line: "))
4262 (buffer-string)))
4263 (save-restriction
4264 (narrow-to-region (point) (point))
4265 (mml-insert-buffer forward-buffer)
4266 (goto-char (point-min))
4267 (when (looking-at "From ")
4268 (replace-match "X-From-Line: "))
4269 (goto-char (point-max)))))
4270 (setq e (point))
4271 (if message-forward-as-mime
4272 (if digest
4273 (insert "<#/multipart>\n")
4274 (if message-forward-show-mml
4275 (insert "<#/mml>\n")
4276 (insert "<#/part>\n")))
4277 (insert "\n-------------------- End of forwarded message --------------------\n"))
4278 (if (and digest message-forward-as-mime)
4279 (save-restriction
4280 (narrow-to-region b e)
4281 (goto-char b)
4282 (narrow-to-region (point)
4283 (or (search-forward "\n\n" nil t) (point)))
4284 (delete-region (point-min) (point-max)))
4285 (when (and (not current-prefix-arg)
4286 message-forward-ignored-headers)
4287 (save-restriction
4288 (narrow-to-region b e)
4289 (goto-char b)
4290 (narrow-to-region (point)
4291 (or (search-forward "\n\n" nil t) (point)))
4292 (message-remove-header message-forward-ignored-headers t)))))
4293 (message-position-point))
4295 ;;;###autoload
4296 (defun message-forward-rmail-make-body (forward-buffer)
4297 (save-window-excursion
4298 (set-buffer forward-buffer)
4299 (if (rmail-msg-is-pruned)
4300 (rmail-msg-restore-non-pruned-header)))
4301 (message-forward-make-body forward-buffer))
4303 ;;;###autoload
4304 (defun message-insinuate-rmail ()
4305 "Let RMAIL uses message to forward."
4306 (interactive)
4307 (setq rmail-enable-mime-composing t)
4308 (setq rmail-insert-mime-forwarded-message-function
4309 'message-forward-rmail-make-body))
4311 ;;;###autoload
4312 (defun message-resend (address)
4313 "Resend the current article to ADDRESS."
4314 (interactive
4315 (list (message-read-from-minibuffer "Resend message to: ")))
4316 (message "Resending message to %s..." address)
4317 (save-excursion
4318 (let ((cur (current-buffer))
4319 beg)
4320 ;; We first set up a normal mail buffer.
4321 (unless (message-mail-user-agent)
4322 (set-buffer (get-buffer-create " *message resend*"))
4323 (erase-buffer))
4324 (let ((message-this-is-mail t))
4325 (message-setup `((To . ,address))))
4326 ;; Insert our usual headers.
4327 (message-generate-headers '(From Date To))
4328 (message-narrow-to-headers)
4329 ;; Rename them all to "Resent-*".
4330 (while (re-search-forward "^[A-Za-z]" nil t)
4331 (forward-char -1)
4332 (insert "Resent-"))
4333 (widen)
4334 (forward-line)
4335 (delete-region (point) (point-max))
4336 (setq beg (point))
4337 ;; Insert the message to be resent.
4338 (insert-buffer-substring cur)
4339 (goto-char (point-min))
4340 (search-forward "\n\n")
4341 (forward-char -1)
4342 (save-restriction
4343 (narrow-to-region beg (point))
4344 (message-remove-header message-ignored-resent-headers t)
4345 (goto-char (point-max)))
4346 (insert mail-header-separator)
4347 ;; Rename all old ("Also-")Resent headers.
4348 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4349 (beginning-of-line)
4350 (insert "Also-"))
4351 ;; Quote any "From " lines at the beginning.
4352 (goto-char beg)
4353 (when (looking-at "From ")
4354 (replace-match "X-From-Line: "))
4355 ;; Send it.
4356 (let ((message-inhibit-body-encoding t)
4357 message-required-mail-headers)
4358 (message-send-mail))
4359 (kill-buffer (current-buffer)))
4360 (message "Resending message to %s...done" address)))
4362 ;;;###autoload
4363 (defun message-bounce ()
4364 "Re-mail the current message.
4365 This only makes sense if the current message is a bounce message that
4366 contains some mail you have written which has been bounced back to
4367 you."
4368 (interactive)
4369 (let ((handles (mm-dissect-buffer t))
4370 boundary)
4371 (message-pop-to-buffer (message-buffer-name "bounce"))
4372 (if (stringp (car handles))
4373 ;; This is a MIME bounce.
4374 (mm-insert-part (car (last handles)))
4375 ;; This is a non-MIME bounce, so we try to remove things
4376 ;; manually.
4377 (mm-insert-part handles)
4378 (undo-boundary)
4379 (goto-char (point-min))
4380 (search-forward "\n\n" nil t)
4381 (or (and (re-search-forward message-unsent-separator nil t)
4382 (forward-line 1))
4383 (re-search-forward "^Return-Path:.*\n" nil t))
4384 ;; We remove everything before the bounced mail.
4385 (delete-region
4386 (point-min)
4387 (if (re-search-forward "^[^ \n\t]+:" nil t)
4388 (match-beginning 0)
4389 (point))))
4390 (mm-enable-multibyte)
4391 (mime-to-mml)
4392 (save-restriction
4393 (message-narrow-to-head-1)
4394 (message-remove-header message-ignored-bounced-headers t)
4395 (goto-char (point-max))
4396 (insert mail-header-separator))
4397 (message-position-point)))
4400 ;;; Interactive entry points for new message buffers.
4403 ;;;###autoload
4404 (defun message-mail-other-window (&optional to subject)
4405 "Like `message-mail' command, but display mail buffer in another window."
4406 (interactive)
4407 (unless (message-mail-user-agent)
4408 (let ((pop-up-windows t)
4409 (special-display-buffer-names nil)
4410 (special-display-regexps nil)
4411 (same-window-buffer-names nil)
4412 (same-window-regexps nil))
4413 (message-pop-to-buffer (message-buffer-name "mail" to))))
4414 (let ((message-this-is-mail t))
4415 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4416 nil nil 'switch-to-buffer-other-window)))
4418 ;;;###autoload
4419 (defun message-mail-other-frame (&optional to subject)
4420 "Like `message-mail' command, but display mail buffer in another frame."
4421 (interactive)
4422 (unless (message-mail-user-agent)
4423 (let ((pop-up-frames t)
4424 (special-display-buffer-names nil)
4425 (special-display-regexps nil)
4426 (same-window-buffer-names nil)
4427 (same-window-regexps nil))
4428 (message-pop-to-buffer (message-buffer-name "mail" to))))
4429 (let ((message-this-is-mail t))
4430 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4431 nil nil 'switch-to-buffer-other-frame)))
4433 ;;;###autoload
4434 (defun message-news-other-window (&optional newsgroups subject)
4435 "Start editing a news article to be sent."
4436 (interactive)
4437 (let ((pop-up-windows t)
4438 (special-display-buffer-names nil)
4439 (special-display-regexps nil)
4440 (same-window-buffer-names nil)
4441 (same-window-regexps nil))
4442 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4443 (let ((message-this-is-news t))
4444 (message-setup `((Newsgroups . ,(or newsgroups ""))
4445 (Subject . ,(or subject ""))))))
4447 ;;;###autoload
4448 (defun message-news-other-frame (&optional newsgroups subject)
4449 "Start editing a news article to be sent."
4450 (interactive)
4451 (let ((pop-up-frames t)
4452 (special-display-buffer-names nil)
4453 (special-display-regexps nil)
4454 (same-window-buffer-names nil)
4455 (same-window-regexps nil))
4456 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4457 (let ((message-this-is-news t))
4458 (message-setup `((Newsgroups . ,(or newsgroups ""))
4459 (Subject . ,(or subject ""))))))
4461 ;;; underline.el
4463 ;; This code should be moved to underline.el (from which it is stolen).
4465 ;;;###autoload
4466 (defun bold-region (start end)
4467 "Bold all nonblank characters in the region.
4468 Works by overstriking characters.
4469 Called from program, takes two arguments START and END
4470 which specify the range to operate on."
4471 (interactive "r")
4472 (save-excursion
4473 (let ((end1 (make-marker)))
4474 (move-marker end1 (max start end))
4475 (goto-char (min start end))
4476 (while (< (point) end1)
4477 (or (looking-at "[_\^@- ]")
4478 (insert (char-after) "\b"))
4479 (forward-char 1)))))
4481 ;;;###autoload
4482 (defun unbold-region (start end)
4483 "Remove all boldness (overstruck characters) in the region.
4484 Called from program, takes two arguments START and END
4485 which specify the range to operate on."
4486 (interactive "r")
4487 (save-excursion
4488 (let ((end1 (make-marker)))
4489 (move-marker end1 (max start end))
4490 (goto-char (min start end))
4491 (while (re-search-forward "\b" end1 t)
4492 (if (eq (char-after) (char-after (- (point) 2)))
4493 (delete-char -2))))))
4495 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4497 ;; Support for toolbar
4498 (eval-when-compile (defvar tool-bar-map))
4499 (if (featurep 'xemacs)
4500 (require 'messagexmas)
4501 (when (and
4502 (condition-case nil (require 'tool-bar) (error nil))
4503 (fboundp 'tool-bar-add-item-from-menu)
4504 tool-bar-mode)
4505 (defvar message-tool-bar-map
4506 (let ((tool-bar-map (copy-keymap tool-bar-map)))
4507 ;; Zap some items which aren't so relevant and take up space.
4508 (dolist (key '(print-buffer kill-buffer save-buffer write-file
4509 dired open-file))
4510 (define-key tool-bar-map (vector key) nil))
4512 (tool-bar-add-item-from-menu
4513 'message-send-and-exit "mail_send" message-mode-map)
4514 (tool-bar-add-item-from-menu
4515 'message-kill-buffer "close" message-mode-map)
4516 (tool-bar-add-item-from-menu
4517 'message-dont-send "cancel" message-mode-map)
4518 (tool-bar-add-item-from-menu
4519 'mml-attach-file "attach" message-mode-map)
4520 (tool-bar-add-item-from-menu
4521 'ispell-message "spell" message-mode-map)
4522 tool-bar-map))))
4524 ;;; Group name completion.
4526 (defvar message-newgroups-header-regexp
4527 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4528 "Regexp that match headers that lists groups.")
4530 (defun message-tab ()
4531 "Expand group names in Newsgroups and Followup-To headers.
4532 Do a `tab-to-tab-stop' if not in those headers."
4533 (interactive)
4534 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4535 (mail-abbrev-in-expansion-header-p))
4536 (message-expand-group)
4537 (tab-to-tab-stop)))
4539 (defun message-expand-group ()
4540 "Expand the group name under point."
4541 (let* ((b (save-excursion
4542 (save-restriction
4543 (narrow-to-region
4544 (save-excursion
4545 (beginning-of-line)
4546 (skip-chars-forward "^:")
4547 (1+ (point)))
4548 (point))
4549 (skip-chars-backward "^, \t\n") (point))))
4550 (completion-ignore-case t)
4551 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4552 (point))))
4553 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4554 (completions (all-completions string hashtb))
4555 comp)
4556 (delete-region b (point))
4557 (cond
4558 ((= (length completions) 1)
4559 (if (string= (car completions) string)
4560 (progn
4561 (insert string)
4562 (message "Only matching group"))
4563 (insert (car completions))))
4564 ((and (setq comp (try-completion string hashtb))
4565 (not (string= comp string)))
4566 (insert comp))
4568 (insert string)
4569 (if (not comp)
4570 (message "No matching groups")
4571 (save-selected-window
4572 (pop-to-buffer "*Completions*")
4573 (buffer-disable-undo)
4574 (let ((buffer-read-only nil))
4575 (erase-buffer)
4576 (let ((standard-output (current-buffer)))
4577 (display-completion-list (sort completions 'string<)))
4578 (goto-char (point-min))
4579 (delete-region (point) (progn (forward-line 3) (point))))))))))
4581 ;;; Help stuff.
4583 (defun message-talkative-question (ask question show &rest text)
4584 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4585 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4586 The following arguments may contain lists of values."
4587 (if (and show
4588 (setq text (message-flatten-list text)))
4589 (save-window-excursion
4590 (save-excursion
4591 (with-output-to-temp-buffer " *MESSAGE information message*"
4592 (set-buffer " *MESSAGE information message*")
4593 (fundamental-mode) ; for Emacs 20.4+
4594 (mapcar 'princ text)
4595 (goto-char (point-min))))
4596 (funcall ask question))
4597 (funcall ask question)))
4599 (defun message-flatten-list (list)
4600 "Return a new, flat list that contains all elements of LIST.
4602 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4603 => (1 2 3 4 5 6 7)"
4604 (cond ((consp list)
4605 (apply 'append (mapcar 'message-flatten-list list)))
4606 (list
4607 (list list))))
4609 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4610 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
4611 Then clone the local variables and values from the old buffer to the
4612 new one, cloning only the locals having a substring matching the
4613 regexp varstr."
4614 (let ((oldbuf (current-buffer)))
4615 (save-excursion
4616 (set-buffer (generate-new-buffer name))
4617 (message-clone-locals oldbuf varstr)
4618 (current-buffer))))
4620 (defun message-clone-locals (buffer &optional varstr)
4621 "Clone the local variables from BUFFER to the current buffer."
4622 (let ((locals (save-excursion
4623 (set-buffer buffer)
4624 (buffer-local-variables)))
4625 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4626 (mapcar
4627 (lambda (local)
4628 (when (and (consp local)
4629 (car local)
4630 (string-match regexp (symbol-name (car local)))
4631 (or (null varstr)
4632 (string-match varstr (symbol-name (car local)))))
4633 (ignore-errors
4634 (set (make-local-variable (car local))
4635 (cdr local)))))
4636 locals)))
4639 ;;; MIME functions
4642 (defvar message-inhibit-body-encoding nil)
4644 (defun message-encode-message-body ()
4645 (unless message-inhibit-body-encoding
4646 (let ((mail-parse-charset (or mail-parse-charset
4647 message-default-charset))
4648 (case-fold-search t)
4649 lines content-type-p)
4650 (message-goto-body)
4651 (save-restriction
4652 (narrow-to-region (point) (point-max))
4653 (let ((new (mml-generate-mime)))
4654 (when new
4655 (delete-region (point-min) (point-max))
4656 (insert new)
4657 (goto-char (point-min))
4658 (if (eq (aref new 0) ?\n)
4659 (delete-char 1)
4660 (search-forward "\n\n")
4661 (setq lines (buffer-substring (point-min) (1- (point))))
4662 (delete-region (point-min) (point))))))
4663 (save-restriction
4664 (message-narrow-to-headers-or-head)
4665 (message-remove-header "Mime-Version")
4666 (goto-char (point-max))
4667 (insert "MIME-Version: 1.0\n")
4668 (when lines
4669 (insert lines))
4670 (setq content-type-p
4671 (re-search-backward "^Content-Type:" nil t)))
4672 (save-restriction
4673 (message-narrow-to-headers-or-head)
4674 (message-remove-first-header "Content-Type")
4675 (message-remove-first-header "Content-Transfer-Encoding"))
4676 ;; We always make sure that the message has a Content-Type header.
4677 ;; This is because some broken MTAs and MUAs get awfully confused
4678 ;; when confronted with a message with a MIME-Version header and
4679 ;; without a Content-Type header. For instance, Solaris'
4680 ;; /usr/bin/mail.
4681 (unless content-type-p
4682 (goto-char (point-min))
4683 ;; For unknown reason, MIME-Version doesn't exist.
4684 (when (re-search-forward "^MIME-Version:" nil t)
4685 (forward-line 1)
4686 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
4688 (defun message-read-from-minibuffer (prompt)
4689 "Read from the minibuffer while providing abbrev expansion."
4690 (if (fboundp 'mail-abbrevs-setup)
4691 (let ((mail-abbrev-mode-regexp "")
4692 (minibuffer-setup-hook 'mail-abbrevs-setup))
4693 (read-from-minibuffer prompt))
4694 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
4695 (read-string prompt))))
4697 (defun message-use-alternative-email-as-from ()
4698 (require 'mail-utils)
4699 (let* ((fields '("To" "Cc"))
4700 (emails
4701 (split-string
4702 (mail-strip-quoted-names
4703 (mapconcat 'message-fetch-reply-field fields ","))
4704 "[ \f\t\n\r\v,]+"))
4705 email)
4706 (while emails
4707 (if (string-match message-alternative-emails (car emails))
4708 (setq email (car emails)
4709 emails nil))
4710 (pop emails))
4711 (unless (or (not email) (equal email user-mail-address))
4712 (goto-char (point-max))
4713 (insert "From: " email "\n"))))
4715 (provide 'message)
4717 (run-hooks 'message-load-hook)
4719 ;; Local Variables:
4720 ;; coding: iso-8859-1
4721 ;; End:
4723 ;;; message.el ends here