1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
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)
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.
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.
35 (defvar gnus-list-identifiers
)) ; gnus-sum is required where necessary
38 ;; This is apparently necessary even though things are autoloaded:
39 (if (featurep 'xemacs
)
40 (require 'mail-abbrevs
))
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")
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")
59 (defgroup message-buffers nil
61 :link
'(custom-manual "(message)Message Buffers")
64 (defgroup message-sending nil
66 :link
'(custom-manual "(message)Sending Variables")
69 (defgroup message-interface nil
71 :link
'(custom-manual "(message)Interface")
74 (defgroup message-forwarding nil
76 :link
'(custom-manual "(message)Forwarding")
77 :group
'message-interface
)
79 (defgroup message-insertion nil
81 :link
'(custom-manual "(message)Insertion")
84 (defgroup message-headers nil
86 :link
'(custom-manual "(message)Message Headers")
89 (defgroup message-news nil
90 "Composing News Messages"
93 (defgroup message-mail nil
94 "Composing Mail Messages"
97 (defgroup message-faces nil
98 "Faces used for message composing."
102 (defcustom message-directory
"~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group
'message-various
107 (defcustom message-max-buffers
10
108 "*How many buffers to keep before starting to kill them off."
109 :group
'message-buffers
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
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
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
141 (defcustom message-from-style
'default
142 "*Specifies how \"From\" headers look.
144 If nil, they contain just the return address like:
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
)
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'."
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."
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."
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
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."
208 :group
'message-headers
211 (defcustom message-ignored-mail-headers
"^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
212 "*Regexp of headers to be removed unconditionally before mailing."
214 :group
'message-headers
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
221 :group
'message-interface
224 (defcustom message-subject-re-regexp
"^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
225 "*Regexp matching \"Re: \" in the subject line."
226 :group
'message-various
230 (defcustom message-signature-separator
"^-- *$"
231 "Regexp matching the signature separator."
233 :group
'message-various
)
235 (defcustom message-elide-ellipsis
"\n[...]\n\n"
236 "*The string which is inserted for elided text."
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
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
)
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
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
)))
278 (defcustom message-user-organization-file
"/usr/lib/news/organization"
279 "*Local news organization 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
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
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."
303 :group
'message-forwarding
306 (defcustom message-forward-show-mml t
307 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
309 :group
'message-forwarding
312 (defcustom message-forward-before-signature t
313 "*If non-nil, put forwarded message before signature, else after."
314 :group
'message-forwarding
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
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
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."
330 :group
'message-forwarding
331 :type
'(choice (const :tag
"None" nil
)
334 (defcustom message-ignored-cited-headers
"."
335 "*Delete these headers from the messages you yank."
336 :group
'message-insertion
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
344 ;; Useful to set in site-init.el
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
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
)
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
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
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
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
)
440 ((boundp 'gnus-select-method
)
443 "*Method used to post news.
444 Note that when posting from inside Gnus, for instance, this
445 variable isn't used."
447 :group
'message-sending
448 ;; This should be the `gnus-select-method' widget, but that might
449 ;; create a dependence to `gnus.el'.
452 (defcustom message-generate-headers-first nil
453 "*If non-nil, generate all possible headers before composing."
454 :group
'message-headers
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
463 (defcustom message-cancel-hook nil
464 "Hook run when cancelling articles."
465 :group
'message-various
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
475 (defcustom message-mode-hook nil
476 "Hook run in message mode buffers."
477 :group
'message-various
480 (defcustom message-header-hook nil
481 "Hook run in a message mode buffer narrowed to the headers."
482 :group
'message-various
485 (defcustom message-header-setup-hook nil
486 "Hook called narrowed to the headers when setting up a message buffer."
487 :group
'message-various
491 (defcustom message-citation-line-function
'message-insert-citation-line
492 "*Function called to insert the \"Whomever writes:\" line."
494 :group
'message-insertion
)
497 (defcustom message-yank-prefix
"> "
498 "*Prefix inserted on the lines of yanked messages."
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
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
)
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."
527 :group
'message-insertion
)
529 (defvar message-abbrevs-loaded nil
)
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."
538 :group
'message-insertion
)
541 (defcustom message-signature-file
"~/.signature"
542 "*File containing the text inserted at end of message buffer."
544 :group
'message-insertion
)
546 (defcustom message-distribution-function nil
547 "*Function called to return a Distribution header."
549 :group
'message-headers
550 :type
'(choice function
(const nil
)))
552 (defcustom message-expires
14
553 "Number of days before your article expires."
555 :group
'message-headers
556 :link
'(custom-manual "(message)News Headers")
559 (defcustom message-user-path nil
560 "If nil, use the NNTP server name in the Path header.
561 If stringp, use this; if non-nil, use no host name (user name only)."
563 :group
'message-headers
564 :link
'(custom-manual "(message)News Headers")
565 :type
'(choice (const :tag
"nntp" nil
)
567 (sexp :tag
"none" :format
"%t" t
)))
569 (defvar message-reply-buffer nil
)
570 (defvar message-reply-headers nil
)
571 (defvar message-newsreader nil
)
572 (defvar message-mailer nil
)
573 (defvar message-sent-message-via nil
)
574 (defvar message-checksum nil
)
575 (defvar message-send-actions nil
576 "A list of actions to be performed upon successful sending of a message.")
577 (defvar message-exit-actions nil
578 "A list of actions to be performed upon exiting after sending a message.")
579 (defvar message-kill-actions nil
580 "A list of actions to be performed before killing a message buffer.")
581 (defvar message-postpone-actions nil
582 "A list of actions to be performed after postponing a message.")
584 (define-widget 'message-header-lines
'text
585 "All header lines must be LFD terminated."
586 :format
"%{%t%}:%n%v"
588 :error
"All header lines must be newline terminated")
590 (defcustom message-default-headers
""
591 "*A string containing header lines to be inserted in outgoing messages.
592 It is inserted before you edit the message, so you can edit or delete
594 :group
'message-headers
595 :type
'message-header-lines
)
597 (defcustom message-default-mail-headers
""
598 "*A string of header lines to be inserted in outgoing mails."
599 :group
'message-headers
601 :type
'message-header-lines
)
603 (defcustom message-default-news-headers
""
604 "*A string of header lines to be inserted in outgoing news articles."
605 :group
'message-headers
607 :type
'message-header-lines
)
609 ;; Note: could use /usr/ucb/mail instead of sendmail;
610 ;; options -t, and -v if not interactive.
611 (defcustom message-mailer-swallows-blank-line
612 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
613 system-configuration
)
614 (file-readable-p "/etc/sendmail.cf")
615 (let ((buffer (get-buffer-create " *temp*")))
619 (insert-file-contents "/etc/sendmail.cf")
620 (goto-char (point-min))
621 (let ((case-fold-search nil
))
622 (re-search-forward "^OR\\>" nil t
)))
623 (kill-buffer buffer
))))
624 ;; According to RFC822, "The field-name must be composed of printable
625 ;; ASCII characters (i. e., characters that have decimal values between
626 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
628 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
629 "*Set this non-nil if the system's mailer runs the header and body together.
630 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
631 The value should be an expression to test whether the problem will
633 :group
'message-sending
637 (define-mail-user-agent 'message-user-agent
638 'message-mail
'message-send-and-exit
639 'message-kill-buffer
'message-send-hook
)
641 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
642 "If non-nil, delete the deletable headers before feeding to mh.")
644 (defvar message-send-method-alist
645 '((news message-news-p message-send-via-news
)
646 (mail message-mail-p message-send-via-mail
))
647 "Alist of ways to send outgoing messages.
648 Each element has the form
650 \(TYPE PREDICATE FUNCTION)
652 where TYPE is a symbol that names the method; PREDICATE is a function
653 called without any parameters to determine whether the message is
654 a message of type TYPE; and FUNCTION is a function to be called if
655 PREDICATE returns non-nil. FUNCTION is called with one parameter --
658 (defcustom message-mail-alias-type
'abbrev
659 "*What alias expansion type to use in Message buffers.
660 The default is `abbrev', which uses mailabbrev. nil switches
663 :link
'(custom-manual "(message)Mail Aliases")
664 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
665 (const :tag
"No expansion" nil
)))
667 (defcustom message-auto-save-directory
668 (file-name-as-directory (nnheader-concat message-directory
"drafts"))
669 "*Directory where Message auto-saves buffers if Gnus isn't running.
670 If nil, Message won't auto-save."
671 :group
'message-buffers
672 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
674 (defcustom message-buffer-naming-style
'unique
675 "*The way new message buffers are named.
676 Valid valued are `unique' and `unsent'."
678 :group
'message-buffers
679 :type
'(choice (const :tag
"unique" unique
)
680 (const :tag
"unsent" unsent
)))
682 (defcustom message-default-charset
683 (and (not (mm-multibyte-p)) 'iso-8859-1
)
684 "Default charset used in non-MULE Emacsen.
685 If nil, you might be asked to input the charset."
690 (defcustom message-dont-reply-to-names
691 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
692 "*A regexp specifying names to prune when doing wide replies.
693 A value of nil means exclude your own name only."
696 :type
'(choice (const :tag
"Yourself" nil
)
699 ;;; Internal variables.
700 ;;; Well, not really internal.
702 (defvar message-mode-syntax-table
703 (let ((table (copy-syntax-table text-mode-syntax-table
)))
704 (modify-syntax-entry ?%
". " table
)
705 (modify-syntax-entry ?
> ". " table
)
706 (modify-syntax-entry ?
< ". " table
)
708 "Syntax table used while in Message mode.")
710 (defvar message-mode-abbrev-table text-mode-abbrev-table
711 "Abbrev table used in Message mode buffers.
712 Defaults to `text-mode-abbrev-table'.")
714 (defface message-header-to-face
717 (:foreground
"green2" :bold t
))
720 (:foreground
"MidnightBlue" :bold t
))
722 (:bold t
:italic t
)))
723 "Face used for displaying From headers."
724 :group
'message-faces
)
726 (defface message-header-cc-face
729 (:foreground
"green4" :bold t
))
732 (:foreground
"MidnightBlue"))
735 "Face used for displaying Cc headers."
736 :group
'message-faces
)
738 (defface message-header-subject-face
741 (:foreground
"green3"))
744 (:foreground
"navy blue" :bold t
))
747 "Face used for displaying subject headers."
748 :group
'message-faces
)
750 (defface message-header-newsgroups-face
753 (:foreground
"yellow" :bold t
:italic t
))
756 (:foreground
"blue4" :bold t
:italic t
))
758 (:bold t
:italic t
)))
759 "Face used for displaying newsgroups headers."
760 :group
'message-faces
)
762 (defface message-header-other-face
765 (:foreground
"#b00000"))
768 (:foreground
"steel blue"))
770 (:bold t
:italic t
)))
771 "Face used for displaying newsgroups headers."
772 :group
'message-faces
)
774 (defface message-header-name-face
777 (:foreground
"DarkGreen"))
780 (:foreground
"cornflower blue"))
783 "Face used for displaying header names."
784 :group
'message-faces
)
786 (defface message-header-xheader-face
789 (:foreground
"blue"))
792 (:foreground
"blue"))
795 "Face used for displaying X-Header headers."
796 :group
'message-faces
)
798 (defface message-separator-face
801 (:foreground
"blue3"))
804 (:foreground
"brown"))
807 "Face used for displaying the separator."
808 :group
'message-faces
)
810 (defface message-cited-text-face
819 "Face used for displaying cited text names."
820 :group
'message-faces
)
822 (defface message-mml-face
825 (:foreground
"ForestGreen"))
828 (:foreground
"ForestGreen"))
831 "Face used for displaying MML."
832 :group
'message-faces
)
834 (defvar message-font-lock-keywords
835 (let* ((cite-prefix "[:alpha:]")
836 (cite-suffix (concat cite-prefix
"0-9_.@-"))
837 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
838 `((,(concat "^\\([Tt]o:\\)" content
)
839 (1 'message-header-name-face
)
840 (2 'message-header-to-face nil t
))
841 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
)
842 (1 'message-header-name-face
)
843 (2 'message-header-cc-face nil t
))
844 (,(concat "^\\([Ss]ubject:\\)" content
)
845 (1 'message-header-name-face
)
846 (2 'message-header-subject-face nil t
))
847 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
)
848 (1 'message-header-name-face
)
849 (2 'message-header-newsgroups-face nil t
))
850 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content
)
851 (1 'message-header-name-face
)
852 (2 'message-header-other-face nil t
))
853 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content
)
854 (1 'message-header-name-face
)
855 (2 'message-header-name-face
))
856 ,@(if (and mail-header-separator
857 (not (equal mail-header-separator
"")))
858 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
859 1 'message-separator-face
))
862 "\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
864 (0 'message-cited-text-face
))
865 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
866 (0 'message-mml-face
))))
867 "Additional expressions to highlight in Message mode.")
869 ;; XEmacs does it like this. For Emacs, we have to set the
870 ;; `font-lock-defaults' buffer-local variable.
871 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
873 (defvar message-face-alist
874 '((bold . bold-region
)
875 (underline . underline-region
)
876 (default .
(lambda (b e
)
878 (ununderline-region b e
))))
879 "Alist of mail and news faces for facemenu.
880 The cdr of ech entry is a function for applying the face to a region.")
882 (defcustom message-send-hook nil
883 "Hook run before sending messages."
884 :group
'message-various
885 :options
'(ispell-message)
888 (defcustom message-send-mail-hook nil
889 "Hook run before sending mail messages."
890 :group
'message-various
893 (defcustom message-send-news-hook nil
894 "Hook run before sending news messages."
895 :group
'message-various
898 (defcustom message-sent-hook nil
899 "Hook run after sending messages."
900 :group
'message-various
903 (defvar message-send-coding-system
'binary
904 "Coding system to encode outgoing mail.")
906 (defvar message-draft-coding-system
907 mm-auto-save-coding-system
908 "Coding system to compose mail.")
910 (defcustom message-send-mail-partially-limit
1000000
911 "The limitation of messages sent as message/partial.
912 The lower bound of message size in characters, beyond which the message
913 should be sent in several parts. If it is nil, the size is unlimited."
915 :group
'message-buffers
916 :type
'(choice (const :tag
"unlimited" nil
)
919 (defcustom message-alternative-emails nil
920 "A regexp to match the alternative email addresses.
921 The first matched address (not primary one) is used in the From field."
922 :group
'message-headers
923 :type
'(choice (const :tag
"Always use primary" nil
)
926 (defcustom message-mail-user-agent nil
927 "Like `mail-user-agent'.
928 Except if it is nil, use Gnus native MUA; if it is t, use
930 :type
'(radio (const :tag
"Gnus native"
933 (const :tag
"`mail-user-agent'"
936 (function-item :tag
"Default Emacs mail"
939 (function-item :tag
"Emacs interface to MH"
942 (function :tag
"Other"))
946 ;;; Internal variables.
948 (defvar message-sending-message
"Sending...")
949 (defvar message-buffer-list nil
)
950 (defvar message-this-is-news nil
)
951 (defvar message-this-is-mail nil
)
952 (defvar message-draft-article nil
)
953 (defvar message-mime-part nil
)
954 (defvar message-posting-charset nil
)
956 ;; Byte-compiler warning
958 (defvar gnus-active-hashtb
)
959 (defvar gnus-read-active-file
))
961 ;;; Regexp matching the delimiter of messages in UNIX mail format
962 ;;; (UNIX From lines), minus the initial ^. It should be a copy
963 ;;; of rmail.el's rmail-unix-mail-delimiter.
964 (defvar message-unix-mail-delimiter
965 (let ((time-zone-regexp
966 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
967 "\\|[-+]?[0-9][0-9][0-9][0-9]"
973 ;; Many things can happen to an RFC 822 mailbox before it is put into
974 ;; a `From' line. The leading phrase can be stripped, e.g.
975 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
976 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
977 ;; can be removed, e.g.
978 ;; From: joe@y.z (Joe K
980 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
983 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
984 ;; The mailbox can be removed or be replaced by white space, e.g.
985 ;; From: "Joe User"{space}{tab}
987 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
988 ;; where {space} and {tab} represent the Ascii space and tab characters.
989 ;; We want to match the results of any of these manglings.
990 ;; The following regexp rejects names whose first characters are
991 ;; obviously bogus, but after that anything goes.
992 "\\([^\0-\b\n-\r\^?].*\\)? "
994 ;; The time the message was sent.
995 "\\([^\0-\r \^?]+\\) +" ; day of the week
996 "\\([^\0-\r \^?]+\\) +" ; month
997 "\\([0-3]?[0-9]\\) +" ; day of month
998 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1000 ;; Perhaps a time zone, specified by an abbreviation, or by a
1005 " \\([0-9][0-9]+\\) *"
1007 ;; On some systems the time zone can appear after the year, too.
1011 "\\(remote from .*\\)?"
1014 "Regexp matching the delimiter of messages in UNIX mail format.")
1016 (defvar message-unsent-separator
1017 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1018 "^ *---+ +Returned message +---+ *$\\|"
1019 "^Start of returned message$\\|"
1020 "^ *---+ +Original message +---+ *$\\|"
1021 "^ *--+ +begin message +--+ *$\\|"
1022 "^ *---+ +Original message follows +---+ *$\\|"
1023 "^ *---+ +Undelivered message follows +---+ *$\\|"
1024 "^|? *---+ +Message text follows: +---+ *|?$")
1025 "A regexp that matches the separator before the text of a failed message.")
1027 (defvar message-header-format-alist
1029 (To . message-fill-address
)
1030 (Cc . message-fill-address
)
1041 (References . message-shorten-references
)
1043 "Alist used for formatting headers.")
1046 (autoload 'message-setup-toolbar
"messagexmas")
1047 (autoload 'mh-new-draft-name
"mh-comp")
1048 (autoload 'mh-send-letter
"mh-comp")
1049 (autoload 'gnus-point-at-eol
"gnus-util")
1050 (autoload 'gnus-point-at-bol
"gnus-util")
1051 (autoload 'gnus-output-to-rmail
"gnus-util")
1052 (autoload 'gnus-output-to-mail
"gnus-util")
1053 (autoload 'mail-abbrev-in-expansion-header-p
"mailabbrev")
1054 (autoload 'nndraft-request-associate-buffer
"nndraft")
1055 (autoload 'nndraft-request-expire-articles
"nndraft")
1056 (autoload 'gnus-open-server
"gnus-int")
1057 (autoload 'gnus-request-post
"gnus-int")
1058 (autoload 'gnus-alive-p
"gnus-util")
1059 (autoload 'gnus-group-name-charset
"gnus-group")
1060 (autoload 'rmail-output
"rmail"))
1065 ;;; Utility functions.
1068 (defmacro message-y-or-n-p
(question show
&rest text
)
1069 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1070 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1072 (defmacro message-delete-line
(&optional n
)
1073 "Delete the current line (and the next N lines)."
1074 `(delete-region (progn (beginning-of-line) (point))
1075 (progn (forward-line ,(or n
1)) (point))))
1077 (defun message-unquote-tokens (elems)
1078 "Remove double quotes (\") from strings in list ELEMS."
1079 (mapcar (lambda (item)
1080 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1081 (setq item
(concat (match-string 1 item
)
1082 (match-string 2 item
))))
1086 (defun message-tokenize-header (header &optional separator
)
1087 "Split HEADER into a list of header elements.
1088 SEPARATOR is a string of characters to be used as separators. \",\"
1089 is used by default."
1092 (let ((regexp (format "[%s]+" (or separator
",")))
1097 (message-set-work-buffer)
1099 (goto-char (point-min))
1104 (cond ((and (> (point) beg
)
1106 (and (looking-at regexp
)
1109 (push (buffer-substring beg
(point)) elems
)
1110 (setq beg
(match-end 0)))
1111 ((eq (char-after) ?
\")
1112 (setq quoted
(not quoted
)))
1113 ((and (eq (char-after) ?\
()
1116 ((and (eq (char-after) ?\
))
1119 (nreverse elems
)))))
1121 (defun message-mail-file-mbox-p (file)
1122 "Say whether FILE looks like a Unix mbox file."
1123 (when (and (file-exists-p file
)
1124 (file-readable-p file
)
1125 (file-regular-p file
))
1127 (nnheader-insert-file-contents file
)
1128 (goto-char (point-min))
1129 (looking-at message-unix-mail-delimiter
))))
1131 (defun message-fetch-field (header &optional not-all
)
1132 "The same as `mail-fetch-field', only remove all newlines."
1133 (let* ((inhibit-point-motion-hooks t
)
1134 (case-fold-search t
)
1135 (value (mail-fetch-field header nil
(not not-all
))))
1137 (while (string-match "\n[\t ]+" value
)
1138 (setq value
(replace-match " " t t value
)))
1139 (set-text-properties 0 (length value
) nil value
)
1142 (defun message-narrow-to-field ()
1143 "Narrow the buffer to the header on the current line."
1149 (if (re-search-forward "^[^ \n\t]" nil t
)
1154 (goto-char (point-min)))
1156 (defun message-add-header (&rest headers
)
1157 "Add the HEADERS to the message header, skipping those already present."
1160 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1161 (error "Invalid header `%s'" (car headers
)))
1162 (setq hclean
(match-string 1 (car headers
)))
1164 (message-narrow-to-headers)
1165 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1166 (insert (car headers
) ?
\n))))
1167 (setq headers
(cdr headers
))))
1170 (defun message-fetch-reply-field (header)
1171 "Fetch field HEADER from the message we're replying to."
1172 (when (and message-reply-buffer
1173 (buffer-name message-reply-buffer
))
1175 (set-buffer message-reply-buffer
)
1176 (message-fetch-field header
))))
1178 (defun message-set-work-buffer ()
1179 (if (get-buffer " *message work*")
1181 (set-buffer " *message work*")
1183 (set-buffer (get-buffer-create " *message work*"))
1184 (kill-all-local-variables)
1185 (mm-enable-multibyte)))
1187 (defun message-functionp (form)
1188 "Return non-nil if FORM is funcallable."
1189 (or (and (symbolp form
) (fboundp form
))
1190 (and (listp form
) (eq (car form
) 'lambda
))
1191 (byte-code-function-p form
)))
1193 (defun message-strip-list-identifiers (subject)
1194 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1195 (require 'gnus-sum
) ; for gnus-list-identifiers
1196 (let ((regexp (if (stringp gnus-list-identifiers
)
1197 gnus-list-identifiers
1198 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1199 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1200 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1201 (concat (substring subject
0 (match-beginning 1))
1202 (or (match-string 3 subject
)
1203 (match-string 5 subject
))
1208 (defun message-strip-subject-re (subject)
1209 "Remove \"Re:\" from subject lines in string SUBJECT."
1210 (if (string-match message-subject-re-regexp subject
)
1211 (substring subject
(match-end 0))
1214 (defun message-remove-header (header &optional is-regexp first reverse
)
1215 "Remove HEADER in the narrowed buffer.
1216 If IS-REGEXP, HEADER is a regular expression.
1217 If FIRST, only remove the first instance of the header.
1218 Return the number of headers removed."
1219 (goto-char (point-min))
1220 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
1222 (case-fold-search t
)
1224 (while (and (not (eobp))
1227 (not (looking-at regexp
))
1228 (looking-at regexp
))
1235 ;; There might be a continuation header, so we have to search
1236 ;; until we find a new non-continuation line.
1239 (if (re-search-forward "^[^ \t]" nil t
)
1240 (goto-char (match-beginning 0))
1243 (if (re-search-forward "^[^ \t]" nil t
)
1244 (goto-char (match-beginning 0))
1245 (goto-char (point-max)))))
1248 (defun message-remove-first-header (header)
1249 "Remove the first instance of HEADER if there is more than one."
1251 (regexp (concat "^" (regexp-quote header
) ":")))
1253 (goto-char (point-min))
1254 (while (re-search-forward regexp nil t
)
1257 (message-remove-header header nil t
)
1260 (defun message-narrow-to-headers ()
1261 "Narrow the buffer to the head of the message."
1264 (goto-char (point-min))
1265 (if (re-search-forward
1266 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
1269 (goto-char (point-min)))
1271 (defun message-narrow-to-head-1 ()
1272 "Like `message-narrow-to-head'. Don't widen."
1274 (goto-char (point-min))
1275 (if (search-forward "\n\n" nil
1)
1278 (goto-char (point-min)))
1280 (defun message-narrow-to-head ()
1281 "Narrow the buffer to the head of the message.
1282 Point is left at the beginning of the narrowed-to region."
1284 (message-narrow-to-head-1))
1286 (defun message-narrow-to-headers-or-head ()
1287 "Narrow the buffer to the head of the message."
1290 (goto-char (point-min))
1293 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
1294 (match-beginning 0))
1295 ((search-forward "\n\n" nil t
)
1299 (goto-char (point-min)))
1301 (defun message-news-p ()
1302 "Say whether the current buffer contains a news message."
1303 (and (not message-this-is-mail
)
1304 (or message-this-is-news
1307 (message-narrow-to-headers)
1308 (and (message-fetch-field "newsgroups")
1309 (not (message-fetch-field "posted-to"))))))))
1311 (defun message-mail-p ()
1312 "Say whether the current buffer contains a mail message."
1313 (and (not message-this-is-news
)
1314 (or message-this-is-mail
1317 (message-narrow-to-headers)
1318 (or (message-fetch-field "to")
1319 (message-fetch-field "cc")
1320 (message-fetch-field "bcc")))))))
1322 (defun message-next-header ()
1323 "Go to the beginning of the next header."
1325 (or (eobp) (forward-char 1))
1326 (not (if (re-search-forward "^[^ \t]" nil t
)
1328 (goto-char (point-max)))))
1330 (defun message-sort-headers-1 ()
1331 "Sort the buffer as headers using `message-rank' text props."
1332 (goto-char (point-min))
1335 nil
'message-next-header
1337 (message-next-header)
1341 (or (get-text-property (point) 'message-rank
)
1344 (defun message-sort-headers ()
1345 "Sort the headers of the current message according to `message-header-format-alist'."
1349 (let ((max (1+ (length message-header-format-alist
)))
1351 (message-narrow-to-headers)
1352 (while (re-search-forward "^[^ \n]+:" nil t
)
1354 (match-beginning 0) (1+ (match-beginning 0))
1356 (if (setq rank
(length (memq (assq (intern (buffer-substring
1358 (1- (match-end 0))))
1359 message-header-format-alist
)
1360 message-header-format-alist
)))
1363 (message-sort-headers-1))))
1373 (defvar message-mode-map nil
)
1375 (unless message-mode-map
1376 (setq message-mode-map
(make-keymap))
1377 (set-keymap-parent message-mode-map text-mode-map
)
1378 (define-key message-mode-map
"\C-c?" 'describe-mode
)
1380 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
1381 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
1382 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
1383 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
1384 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
1385 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
1386 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
1387 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
1388 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
1389 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
1390 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
1391 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
1392 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
1394 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
1395 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
1397 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
1398 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
1399 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
1400 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
1401 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
1402 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
1403 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
1404 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
1406 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
1407 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
1408 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
1409 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
1411 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
1412 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
1413 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
1414 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
1416 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
1418 (define-key message-mode-map
"\t" 'message-tab
))
1421 message-mode-menu message-mode-map
"Message Menu."
1423 ["Sort Headers" message-sort-headers t
]
1424 ["Yank Original" message-yank-original t
]
1425 ["Fill Yanked Message" message-fill-yanked-message t
]
1426 ["Insert Signature" message-insert-signature t
]
1427 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
1428 ["Caesar (rot13) Region" message-caesar-region
(mark t
)]
1429 ["Elide Region" message-elide-region
(mark t
)]
1430 ["Delete Outside Region" message-delete-not-region
(mark t
)]
1431 ["Kill To Signature" message-kill-to-signature t
]
1432 ["Newline and Reformat" message-newline-and-reformat t
]
1433 ["Rename buffer" message-rename-buffer t
]
1434 ["Spellcheck" ispell-message
1435 :help
"Spellcheck this message"]
1436 ["Attach file as MIME" mml-attach-file
1437 :help
"Attach a file at point"]
1439 ["Send Message" message-send-and-exit
1440 :help
"Send this message"]
1441 ["Abort Message" message-dont-send
1442 :help
"File this draft message and exit"]
1443 ["Kill Message" message-kill-buffer
1444 :help
"Delete this message without sending"]))
1447 message-mode-field-menu message-mode-map
""
1449 ["Fetch To" message-insert-to t
]
1450 ["Fetch Newsgroups" message-insert-newsgroups t
]
1452 ["To" message-goto-to t
]
1453 ["Subject" message-goto-subject t
]
1454 ["Cc" message-goto-cc t
]
1455 ["Reply-To" message-goto-reply-to t
]
1456 ["Summary" message-goto-summary t
]
1457 ["Keywords" message-goto-keywords t
]
1458 ["Newsgroups" message-goto-newsgroups t
]
1459 ["Followup-To" message-goto-followup-to t
]
1460 ["Distribution" message-goto-distribution t
]
1461 ["Body" message-goto-body t
]
1462 ["Signature" message-goto-signature t
]))
1465 (defvar facemenu-add-face-function
)
1466 (defvar facemenu-remove-face-function
))
1469 (defun message-mode ()
1470 "Major mode for editing mail and news to be sent.
1471 Like Text Mode but with these additional commands:\\<message-mode-map>
1472 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1473 C-c C-d Postpone sending the message C-c C-k Kill the message
1474 C-c C-f move to a header field (and create it if there isn't):
1475 C-c C-f C-t move to To C-c C-f C-s move to Subject
1476 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1477 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1478 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1479 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1480 C-c C-f C-f move to Followup-To
1481 C-c C-t `message-insert-to' (add a To header to a news followup)
1482 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1483 C-c C-b `message-goto-body' (move to beginning of message text).
1484 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1485 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1486 C-c C-y `message-yank-original' (insert current message, if any).
1487 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1488 C-c C-e `message-elide-region' (elide the text between point and mark).
1489 C-c C-v `message-delete-not-region' (remove the text outside the region).
1490 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1491 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1492 C-c C-a `mml-attach-file' (attach a file as MIME).
1493 M-RET `message-newline-and-reformat' (break the line and reformat)."
1495 (if (local-variable-p 'mml-buffer-list
(current-buffer))
1496 (mml-destroy-buffers))
1497 (kill-all-local-variables)
1498 (set (make-local-variable 'message-reply-buffer
) nil
)
1499 (make-local-variable 'message-send-actions
)
1500 (make-local-variable 'message-exit-actions
)
1501 (make-local-variable 'message-kill-actions
)
1502 (make-local-variable 'message-postpone-actions
)
1503 (make-local-variable 'message-draft-article
)
1504 (make-local-hook 'kill-buffer-hook
)
1505 (set-syntax-table message-mode-syntax-table
)
1506 (use-local-map message-mode-map
)
1507 (setq local-abbrev-table message-mode-abbrev-table
)
1508 (setq major-mode
'message-mode
)
1509 (setq mode-name
"Message")
1510 (setq buffer-offer-save t
)
1511 (make-local-variable 'facemenu-add-face-function
)
1512 (make-local-variable 'facemenu-remove-face-function
)
1513 (setq facemenu-add-face-function
1515 (let ((face-fun (cdr (assq face message-face-alist
))))
1517 (funcall face-fun
(point) end
)
1518 (error "Face %s not configured for %s mode" face mode-name
)))
1520 facemenu-remove-face-function t
)
1521 (make-local-variable 'message-reply-headers
)
1522 (setq message-reply-headers nil
)
1523 (make-local-variable 'message-newsreader
)
1524 (make-local-variable 'message-mailer
)
1525 (make-local-variable 'message-post-method
)
1526 (set (make-local-variable 'message-sent-message-via
) nil
)
1527 (set (make-local-variable 'message-checksum
) nil
)
1528 (set (make-local-variable 'message-mime-part
) 0)
1529 (message-setup-fill-variables)
1530 ;; Allow using comment commands to add/remove quoting.
1531 (set (make-local-variable 'comment-start
) message-yank-prefix
)
1532 ;;(when (fboundp 'mail-hist-define-keys)
1533 ;; (mail-hist-define-keys))
1534 (if (featurep 'xemacs
)
1535 (message-setup-toolbar)
1536 (set (make-local-variable 'font-lock-defaults
)
1537 '(message-font-lock-keywords t
))
1538 (if (boundp 'message-tool-bar-map
)
1539 (set (make-local-variable 'tool-bar-map
) message-tool-bar-map
)))
1540 (easy-menu-add message-mode-menu message-mode-map
)
1541 (easy-menu-add message-mode-field-menu message-mode-map
)
1542 ;; Allow mail alias things.
1543 (when (eq message-mail-alias-type
'abbrev
)
1544 (if (fboundp 'mail-abbrevs-setup
)
1545 (mail-abbrevs-setup)
1546 (mail-aliases-setup)))
1547 (message-set-auto-save-file-name)
1548 (mm-enable-multibyte)
1549 (make-local-variable 'indent-tabs-mode
) ;Turn off tabs for indentation.
1550 (setq indent-tabs-mode nil
)
1552 (run-hooks 'text-mode-hook
'message-mode-hook
))
1554 (defun message-setup-fill-variables ()
1555 "Setup message fill variables."
1556 (make-local-variable 'paragraph-separate
)
1557 (make-local-variable 'paragraph-start
)
1558 (make-local-variable 'adaptive-fill-regexp
)
1559 (unless (boundp 'adaptive-fill-first-line-regexp
)
1560 (setq adaptive-fill-first-line-regexp nil
))
1561 (make-local-variable 'adaptive-fill-first-line-regexp
)
1562 (make-local-variable 'auto-fill-inhibit-regexp
)
1563 (let ((quote-prefix-regexp
1565 "[ \t]*" ; possible initial space
1566 "\\(\\(" (regexp-quote message-yank-prefix
) "\\|" ; user's prefix
1567 "\\w+>\\|" ; supercite-style prefix
1568 "[|:>]" ; standard prefix
1569 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1570 (setq paragraph-start
1572 (regexp-quote mail-header-separator
) "$\\|"
1573 "[ \t]*$\\|" ; blank lines
1574 "-- $\\|" ; signature delimiter
1575 "---+$\\|" ; delimiters for forwarded messages
1576 page-delimiter
"$\\|" ; spoiler warnings
1577 ".*wrote:$\\|" ; attribution lines
1578 quote-prefix-regexp
"$")) ; empty lines in quoted text
1579 (setq paragraph-separate paragraph-start
)
1580 (setq adaptive-fill-regexp
1581 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
1582 (setq adaptive-fill-first-line-regexp
1583 (concat quote-prefix-regexp
"\\|"
1584 adaptive-fill-first-line-regexp
))
1585 (setq auto-fill-inhibit-regexp
"^[A-Z][^: \n\t]+:")))
1590 ;;; Message mode commands
1593 ;;; Movement commands
1595 (defun message-goto-to ()
1596 "Move point to the To header."
1598 (message-position-on-field "To"))
1600 (defun message-goto-subject ()
1601 "Move point to the Subject header."
1603 (message-position-on-field "Subject"))
1605 (defun message-goto-cc ()
1606 "Move point to the Cc header."
1608 (message-position-on-field "Cc" "To"))
1610 (defun message-goto-bcc ()
1611 "Move point to the Bcc header."
1613 (message-position-on-field "Bcc" "Cc" "To"))
1615 (defun message-goto-fcc ()
1616 "Move point to the Fcc header."
1618 (message-position-on-field "Fcc" "To" "Newsgroups"))
1620 (defun message-goto-reply-to ()
1621 "Move point to the Reply-To header."
1623 (message-position-on-field "Reply-To" "Subject"))
1625 (defun message-goto-newsgroups ()
1626 "Move point to the Newsgroups header."
1628 (message-position-on-field "Newsgroups"))
1630 (defun message-goto-distribution ()
1631 "Move point to the Distribution header."
1633 (message-position-on-field "Distribution"))
1635 (defun message-goto-followup-to ()
1636 "Move point to the Followup-To header."
1638 (message-position-on-field "Followup-To" "Newsgroups"))
1640 (defun message-goto-keywords ()
1641 "Move point to the Keywords header."
1643 (message-position-on-field "Keywords" "Subject"))
1645 (defun message-goto-summary ()
1646 "Move point to the Summary header."
1648 (message-position-on-field "Summary" "Subject"))
1650 (defun message-goto-body ()
1651 "Move point to the beginning of the message body."
1653 (if (looking-at "[ \t]*\n") (expand-abbrev))
1654 (goto-char (point-min))
1655 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1656 (search-forward "\n\n" nil t
)))
1658 (defun message-goto-eoh ()
1659 "Move point to the end of the headers."
1664 (defun message-goto-signature ()
1665 "Move point to the beginning of the message signature.
1666 If there is no signature in the article, go to the end and
1669 (goto-char (point-min))
1670 (if (re-search-forward message-signature-separator nil t
)
1672 (goto-char (point-max))
1677 (defun message-insert-to (&optional force
)
1678 "Insert a To header that points to the author of the article being replied to.
1679 If the original author requested not to be sent mail, the function signals
1681 With the prefix argument FORCE, insert the header anyway."
1683 (let ((co (message-fetch-reply-field "mail-copies-to")))
1684 (when (and (null force
)
1686 (or (equal (downcase co
) "never")
1687 (equal (downcase co
) "nobody")))
1688 (error "The user has requested not to have copies sent via mail")))
1689 (when (and (message-position-on-field "To")
1690 (mail-fetch-field "to")
1691 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1693 (insert (or (message-fetch-reply-field "reply-to")
1694 (message-fetch-reply-field "from") "")))
1696 (defun message-widen-reply ()
1697 "Widen the reply to include maximum recipients."
1700 (and message-reply-buffer
1701 (buffer-name message-reply-buffer
)
1703 (set-buffer message-reply-buffer
)
1704 (message-get-reply-headers t
)))))
1707 (message-narrow-to-headers)
1708 (dolist (elem follow-to
)
1709 (message-remove-header (symbol-name (car elem
)))
1710 (goto-char (point-min))
1711 (insert (symbol-name (car elem
)) ": "
1712 (cdr elem
) "\n"))))))
1714 (defun message-insert-newsgroups ()
1715 "Insert the Newsgroups header from the article being replied to."
1717 (when (and (message-position-on-field "Newsgroups")
1718 (mail-fetch-field "newsgroups")
1719 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1721 (insert (or (message-fetch-reply-field "newsgroups") "")))
1725 ;;; Various commands
1727 (defun message-delete-not-region (beg end
)
1728 "Delete everything in the body of the current message outside of the region."
1732 (delete-region (point) (if (not (message-goto-signature))
1738 (delete-region beg
(progn (message-goto-body)
1741 (when (message-goto-signature)
1744 (defun message-kill-to-signature ()
1745 "Deletes all text up to the signature."
1747 (let ((point (point)))
1748 (message-goto-signature)
1751 (kill-region point
(point))
1755 (defun message-newline-and-reformat ()
1756 "Insert four newlines, and then reformat if inside quoted text."
1758 ;; The Latin-1 angle quote looks pretty dubious. -- fx
1759 (let ((prefix "[]>»|:}+ \t]*")
1760 (supercite-thing "[-._[:alnum:]]*[>]+[ \t]*")
1765 (when (looking-at (concat prefix
1767 (setq quoted
(match-string 0))))
1769 (setq point
(point))
1771 (delete-region (point) (re-search-forward "[ \t]*"))
1774 (fill-paragraph nil
)
1778 (defun message-insert-signature (&optional force
)
1779 "Insert a signature. See documentation for variable `message-signature'."
1780 (interactive (list 0))
1783 ((and (null message-signature
)
1786 (goto-char (point-max))
1787 (not (re-search-backward message-signature-separator nil t
))))
1788 ((and (null message-signature
)
1791 ((message-functionp message-signature
)
1792 (funcall message-signature
))
1793 ((listp message-signature
)
1794 (eval message-signature
))
1795 (t message-signature
)))
1797 (cond ((stringp signature
)
1799 ((and (eq t signature
)
1800 message-signature-file
1801 (file-exists-p message-signature-file
))
1804 (goto-char (point-max))
1805 ;; Insert the signature.
1809 (if (eq signature t
)
1810 (insert-file-contents message-signature-file
)
1812 (goto-char (point-max))
1813 (or (bolp) (insert "\n")))))
1815 (defun message-elide-region (b e
)
1816 "Elide the text in the region.
1817 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1821 (insert message-elide-ellipsis
))
1823 (defvar message-caesar-translation-table nil
)
1825 (defun message-caesar-region (b e
&optional n
)
1826 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
1829 (min (point) (or (mark t
) (point)))
1830 (max (point) (or (mark t
) (point)))
1831 (when current-prefix-arg
1832 (prefix-numeric-value current-prefix-arg
))))
1834 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
1835 (unless (or (zerop n
) ; no action needed for a rot of 0
1836 (= b e
)) ; no region to rotate
1837 ;; We build the table, if necessary.
1838 (when (or (not message-caesar-translation-table
)
1839 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
1840 (setq message-caesar-translation-table
1841 (message-make-caesar-translation-table n
)))
1842 (translate-region b e message-caesar-translation-table
)))
1844 (defun message-make-caesar-translation-table (n)
1845 "Create a rot table with offset N."
1847 (table (make-string 256 0)))
1848 (while (< (incf i
) 256)
1851 (substring table
0 ?A
)
1852 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
1853 (substring table ?A
(+ ?A n
))
1854 (substring table
(+ ?A
26) ?a
)
1855 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
1856 (substring table ?a
(+ ?a n
))
1857 (substring table
(+ ?a
26) 255))))
1859 (defun message-caesar-buffer-body (&optional rotnum
)
1860 "Caesar rotate all letters in the current buffer by 13 places.
1861 Used to encode/decode possibly offensive messages (commonly in rec.humor).
1862 With prefix arg, specifies the number of places to rotate each letter forward.
1863 Mail and USENET news headers are not rotated."
1864 (interactive (if current-prefix-arg
1865 (list (prefix-numeric-value current-prefix-arg
))
1869 (when (message-goto-body)
1870 (narrow-to-region (point) (point-max)))
1871 (message-caesar-region (point-min) (point-max) rotnum
))))
1873 (defun message-pipe-buffer-body (program)
1874 "Pipe the message body in the current buffer through PROGRAM."
1877 (when (message-goto-body)
1878 (narrow-to-region (point) (point-max)))
1879 (shell-command-on-region
1880 (point-min) (point-max) program nil t
))))
1882 (defun message-rename-buffer (&optional enter-string
)
1883 "Rename the *message* buffer to \"*message* RECIPIENT\".
1884 If the function is run with a prefix, it will ask for a new buffer
1885 name, rather than giving an automatic name."
1886 (interactive "Pbuffer name: ")
1889 (goto-char (point-min))
1890 (narrow-to-region (point)
1891 (search-forward mail-header-separator nil
'end
))
1893 (if (message-news-p) (message-fetch-field "Newsgroups")
1894 (message-fetch-field "To"))
1897 (if (string-match "," mail-to
)
1898 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
1900 (name-default (concat "*message* " mail-trimmed-to
))
1901 (name (if enter-string
1902 (read-string "New buffer name: " name-default
)
1904 (rename-buffer name t
)))))
1906 (defun message-fill-yanked-message (&optional justifyp
)
1907 "Fill the paragraphs of a message yanked into this one.
1908 Numeric argument means justify as well."
1911 (goto-char (point-min))
1912 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1913 (let ((fill-prefix message-yank-prefix
))
1914 (fill-individual-paragraphs (point) (point-max) justifyp
))))
1916 (defun message-indent-citation ()
1917 "Modify text just inserted from a message to be cited.
1918 The inserted text should be the region.
1919 When this function returns, the region is again around the modified text.
1921 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1922 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1923 (let ((start (point)))
1924 ;; Remove unwanted headers.
1925 (when message-ignored-cited-headers
1930 (if (search-forward "\n\n" nil t
)
1933 (message-remove-header message-ignored-cited-headers t
)
1934 (when (= (point-min) (point-max))
1935 (setq all-removed t
))
1936 (goto-char (point-max)))
1940 ;; Delete blank lines at the start of the buffer.
1941 (while (and (point-min)
1944 (message-delete-line))
1945 ;; Delete blank lines at the end of the buffer.
1946 (goto-char (point-max))
1949 (while (and (zerop (forward-line -
1))
1951 (message-delete-line))
1952 ;; Do the indentation.
1953 (if (null message-yank-prefix
)
1954 (indent-rigidly start
(mark t
) message-indentation-spaces
)
1957 (while (< (point) (mark t
))
1958 (insert message-yank-prefix
)
1962 (defun message-yank-original (&optional arg
)
1963 "Insert the message being replied to, if any.
1964 Puts point before the text and mark after.
1965 Normally indents each nonblank line ARG spaces (default 3). However,
1966 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1968 This function uses `message-cite-function' to do the actual citing.
1970 Just \\[universal-argument] as argument means don't indent, insert no
1971 prefix, and don't delete any headers."
1973 (let ((modified (buffer-modified-p)))
1974 (when (and message-reply-buffer
1975 message-cite-function
)
1976 (delete-windows-on message-reply-buffer t
)
1977 (insert-buffer message-reply-buffer
)
1978 (funcall message-cite-function
)
1979 (message-exchange-point-and-mark)
1983 (setq message-checksum
(message-checksum))))))
1985 (defun message-yank-buffer (buffer)
1986 "Insert BUFFER into the current buffer and quote it."
1987 (interactive "bYank buffer: ")
1988 (let ((message-reply-buffer buffer
))
1989 (save-window-excursion
1990 (message-yank-original))))
1992 (defun message-buffers ()
1993 "Return a list of active message buffers."
1996 (dolist (buffer (buffer-list t
))
1998 (when (and (eq major-mode
'message-mode
)
1999 (null message-sent-message-via
))
2000 (push (buffer-name buffer
) buffers
))))
2001 (nreverse buffers
)))
2003 (defun message-cite-original-without-signature ()
2004 "Cite function in the standard Message manner."
2005 (let ((start (point))
2008 (when message-indent-citation-function
2009 (if (listp message-indent-citation-function
)
2010 message-indent-citation-function
2011 (list message-indent-citation-function
)))))
2012 (mml-quote-region start end
)
2016 (when (re-search-backward message-signature-separator start t
)
2017 ;; Also peel off any blank lines before the signature.
2019 (while (looking-at "^[ \t]*$")
2022 (delete-region (point) end
))
2025 (funcall (pop functions
)))
2026 (when message-citation-line-function
2029 (funcall message-citation-line-function
))))
2031 (eval-when-compile (defvar mail-citation-hook
)) ;Compiler directive
2032 (defun message-cite-original ()
2033 "Cite function in the standard Message manner."
2034 (if (and (boundp 'mail-citation-hook
)
2036 (run-hooks 'mail-citation-hook
)
2037 (let ((start (point))
2040 (when message-indent-citation-function
2041 (if (listp message-indent-citation-function
)
2042 message-indent-citation-function
2043 (list message-indent-citation-function
)))))
2044 (mml-quote-region start end
)
2047 (funcall (pop functions
)))
2048 (when message-citation-line-function
2051 (funcall message-citation-line-function
)))))
2053 (defun message-insert-citation-line ()
2054 "Insert a simple citation line."
2055 (when message-reply-headers
2056 (insert (mail-header-from message-reply-headers
) " writes:\n\n")))
2058 (defun message-position-on-field (header &rest afters
)
2059 (let ((case-fold-search t
))
2062 (goto-char (point-min))
2065 (concat "^" (regexp-quote mail-header-separator
) "$"))
2066 (match-beginning 0)))
2067 (goto-char (point-min))
2068 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
2070 (re-search-forward "^[^ \t]" nil
'move
)
2072 (skip-chars-backward "\n")
2075 (not (re-search-forward
2076 (concat "^" (regexp-quote (car afters
)) ":")
2080 (re-search-forward "^[^ \t]" nil
'move
)
2081 (beginning-of-line))
2082 (insert header
": \n")
2086 (defun message-remove-signature ()
2087 "Remove the signature from the text between point and mark.
2088 The text will also be indented the normal way."
2090 (let ((start (point))
2092 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
2093 ;; No signature here, so we just indent the cited text.
2094 (message-indent-citation)
2095 ;; Find the last non-empty line.
2097 (while (looking-at "[ \t]*$")
2100 (setq mark
(set-marker (make-marker) (point)))
2102 (message-indent-citation)
2103 ;; Enable undoing the deletion.
2105 (delete-region mark
(mark t
))
2106 (set-marker mark nil
)))))
2111 ;;; Sending messages
2114 (defun message-send-and-exit (&optional arg
)
2115 "Send message like `message-send', then, if no errors, exit from mail buffer."
2117 (let ((buf (current-buffer))
2118 (actions message-exit-actions
))
2119 (when (and (message-send arg
)
2121 (if message-kill-buffer-on-exit
2124 (when (eq buf
(current-buffer))
2125 (message-bury buf
)))
2126 (message-do-actions actions
)
2129 (defun message-dont-send ()
2130 "Don't send the message you have been editing."
2132 (set-buffer-modified-p t
)
2134 (let ((actions message-postpone-actions
))
2135 (message-bury (current-buffer))
2136 (message-do-actions actions
)))
2138 (defun message-kill-buffer ()
2139 "Kill the current buffer."
2141 (when (or (not (buffer-modified-p))
2142 (yes-or-no-p "Message modified; kill anyway? "))
2143 (let ((actions message-kill-actions
))
2144 (setq buffer-file-name nil
)
2145 (kill-buffer (current-buffer))
2146 (message-do-actions actions
))))
2148 (defun message-bury (buffer)
2149 "Bury this mail BUFFER."
2150 (let ((newbuf (other-buffer buffer
)))
2151 (bury-buffer buffer
)
2152 (if (and (fboundp 'frame-parameters
)
2153 (cdr (assq 'dedicated
(frame-parameters)))
2154 (not (null (delq (selected-frame) (visible-frame-list)))))
2155 (delete-frame (selected-frame))
2156 (switch-to-buffer newbuf
))))
2158 (defun message-send (&optional arg
)
2159 "Send the message in the current buffer.
2160 If `message-interactive' is non-nil, wait for success indication or
2161 error messages, and inform user.
2162 Otherwise any failure is reported in a message back to the user from
2164 The usage of ARG is defined by the instance that called Message.
2165 It should typically alter the sending method in some way or other."
2167 ;; Make it possible to undo the coming changes.
2169 (let ((inhibit-read-only t
))
2170 (put-text-property (point-min) (point-max) 'read-only nil
))
2171 (message-fix-before-sending)
2172 (run-hooks 'message-send-hook
)
2173 (message message-sending-message
)
2174 (let ((alist message-send-method-alist
)
2178 (setq elem
(pop alist
)))
2179 (when (funcall (cadr elem
))
2180 (when (and (or (not (memq (car elem
)
2181 message-sent-message-via
))
2184 "Already sent message via %s; resend? "
2186 (setq success
(funcall (caddr elem
) arg
)))
2188 (unless (or sent
(not success
))
2189 (error "No methods specified to send by"))
2190 (when (and success sent
)
2193 (run-hooks 'message-sent-hook
))
2194 (message "Sending...done")
2195 ;; Mark the buffer as unmodified and delete auto-save.
2196 (set-buffer-modified-p nil
)
2197 (delete-auto-save-file-if-necessary t
)
2198 (message-disassociate-draft)
2199 ;; Delete other mail buffers and stuff.
2200 (message-do-send-housekeeping)
2201 (message-do-actions message-send-actions
)
2205 (defun message-send-via-mail (arg)
2206 "Send the current message via mail."
2207 (message-send-mail arg
))
2209 (defun message-send-via-news (arg)
2210 "Send the current message via news."
2211 (funcall message-send-news-function arg
))
2213 (defmacro message-check
(type &rest forms
)
2214 "Eval FORMS if TYPE is to be checked."
2215 `(or (message-check-element ,type
)
2219 (put 'message-check
'lisp-indent-function
1)
2220 (put 'message-check
'edebug-form-spec
'(form body
))
2222 (defun message-fix-before-sending ()
2223 "Do various things to make the message nice before sending it."
2224 ;; Make sure there's a newline at the end of the message.
2225 (goto-char (point-max))
2228 ;; Delete all invisible text.
2229 (message-check 'invisible-text
2230 (when (text-property-any (point-min) (point-max) 'invisible t
)
2231 (put-text-property (point-min) (point-max) 'invisible nil
)
2232 (unless (yes-or-no-p
2233 "Invisible text found and made visible; continue posting? ")
2234 (error "Invisible text found and made visible")))))
2236 (defun message-add-action (action &rest types
)
2237 "Add ACTION to be performed when doing an exit of type TYPES."
2240 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
2241 (nconc (symbol-value var
) (list action
))))))
2243 (defun message-do-actions (actions)
2244 "Perform all actions in ACTIONS."
2245 ;; Now perform actions on successful sending.
2249 ;; A simple function.
2250 ((message-functionp (car actions
))
2251 (funcall (car actions
)))
2252 ;; Something to be evaled.
2254 (eval (car actions
)))))
2257 (defun message-send-mail-partially ()
2258 "Sendmail as message/partial."
2259 ;; replace the header delimiter with a blank line
2260 (goto-char (point-min))
2262 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2263 (replace-match "\n")
2264 (run-hooks 'message-send-mail-hook
)
2265 (let ((p (goto-char (point-min)))
2266 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2267 (curbuf (current-buffer))
2268 (id (message-make-message-id)) (n 1)
2269 plist total header required-mail-headers
)
2271 (if (< (point-max) (+ p message-send-mail-partially-limit
))
2272 (goto-char (point-max))
2273 (goto-char (+ p message-send-mail-partially-limit
))
2275 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
2278 (setq total
(length plist
))
2279 (push (point-max) plist
)
2280 (setq plist
(nreverse plist
))
2283 (setq p
(pop plist
))
2286 (copy-to-buffer tembuf p
(car plist
))
2288 (goto-char (point-min))
2291 (goto-char (point-min))
2292 (narrow-to-region (point) (point))
2295 (setq header
(buffer-substring (point-min) (point)))
2296 (goto-char (point-min))
2297 (narrow-to-region (point) (point))
2299 (message-remove-header "Mime-Version")
2300 (message-remove-header "Content-Type")
2301 (message-remove-header "Content-Transfer-Encoding")
2302 (message-remove-header "Message-ID")
2303 (message-remove-header "Lines")
2304 (goto-char (point-max))
2305 (insert "Mime-Version: 1.0\n")
2306 (setq header
(buffer-substring (point-min) (point-max))))
2307 (goto-char (point-max))
2308 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2310 (let ((mail-header-separator ""))
2311 (when (memq 'Message-ID message-required-mail-headers
)
2312 (insert "Message-ID: " (message-make-message-id) "\n"))
2313 (when (memq 'Lines message-required-mail-headers
)
2314 (let ((mail-header-separator ""))
2315 (insert "Lines: " (message-make-lines) "\n")))
2316 (message-goto-subject)
2318 (insert (format " (%d/%d)" n total
))
2319 (goto-char (point-max))
2322 (mm-with-unibyte-current-buffer
2323 (funcall message-send-mail-function
)))
2325 (setq p
(pop plist
))
2327 (kill-buffer tembuf
))))
2329 (defun message-send-mail (&optional arg
)
2330 (require 'mail-utils
)
2331 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2332 (case-fold-search nil
)
2333 (news (message-news-p))
2334 (mailbuf (current-buffer))
2335 (message-this-is-mail t
)
2336 (message-posting-charset
2337 (if (fboundp 'gnus-setup-posting-charset
)
2338 (gnus-setup-posting-charset nil
)
2339 message-posting-charset
)))
2341 (message-narrow-to-headers)
2342 ;; Insert some headers.
2343 (let ((message-deletable-headers
2344 (if news nil message-deletable-headers
)))
2345 (message-generate-headers message-required-mail-headers
))
2346 ;; Let the user do all of the above.
2347 (run-hooks 'message-header-hook
))
2352 ;; Avoid copying text props.
2353 (insert (with-current-buffer mailbuf
2354 (buffer-substring-no-properties (point-min) (point-max))))
2355 ;; Remove some headers.
2356 (message-encode-message-body)
2358 (message-narrow-to-headers)
2359 ;; We (re)generate the Lines header.
2360 (when (memq 'Lines message-required-mail-headers
)
2361 (message-generate-headers '(Lines)))
2362 ;; Remove some headers.
2363 (message-remove-header message-ignored-mail-headers t
)
2364 (let ((mail-parse-charset message-default-charset
))
2365 (mail-encode-encoded-word-buffer)))
2366 (goto-char (point-max))
2367 ;; require one newline at the end.
2368 (or (= (preceding-char) ?
\n)
2372 (message-narrow-to-headers)
2374 (or (message-fetch-field "cc")
2375 (message-fetch-field "to"))
2376 (string= "text/plain"
2378 (mail-header-parse-content-type
2379 (message-fetch-field "content-type"))))))
2380 (message-insert-courtesy-copy))
2381 (if (or (not message-send-mail-partially-limit
)
2382 (< (point-max) message-send-mail-partially-limit
)
2383 (not (y-or-n-p "The message size is too large, should it be sent partially? ")))
2384 (mm-with-unibyte-current-buffer
2385 (funcall message-send-mail-function
))
2386 (message-send-mail-partially)))
2387 (kill-buffer tembuf
))
2388 (set-buffer mailbuf
)
2389 (push 'mail message-sent-message-via
)))
2391 (defun message-send-mail-with-sendmail ()
2392 "Send off the prepared buffer with sendmail."
2393 (let ((errbuf (if message-interactive
2394 (message-generate-new-buffer-clone-locals
2397 resend-to-addresses delimline
)
2398 (let ((case-fold-search t
))
2400 (message-narrow-to-headers)
2401 (setq resend-to-addresses
(message-fetch-field "resent-to")))
2402 ;; Change header-delimiter to be what sendmail expects.
2403 (goto-char (point-min))
2405 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2406 (replace-match "\n")
2408 (setq delimline
(point-marker))
2409 (run-hooks 'message-send-mail-hook
)
2410 ;; Insert an extra newline if we need it to work around
2411 ;; Sun's bug that swallows newlines.
2412 (goto-char (1+ delimline
))
2413 (when (eval message-mailer-swallows-blank-line
)
2415 (when message-interactive
2419 (let ((default-directory "/")
2420 (coding-system-for-write message-send-coding-system
))
2421 (apply 'call-process-region
2422 (append (list (point-min) (point-max)
2423 (if (boundp 'sendmail-program
)
2425 "/usr/lib/sendmail")
2426 nil errbuf nil
"-oi")
2427 ;; Always specify who from,
2428 ;; since some systems have broken sendmails.
2429 ;; But some systems are more broken with -f, so
2430 ;; we'll let users override this.
2431 (if (null message-sendmail-f-is-evil
)
2432 (list "-f" (message-make-address)))
2433 ;; These mean "report errors by mail"
2434 ;; and "deliver in background".
2435 (if (null message-interactive
) '("-oem" "-odb"))
2436 ;; Get the addresses from the message
2437 ;; unless this is a resend.
2438 ;; We must not do that for a resend
2439 ;; because we would find the original addresses.
2440 ;; For a resend, include the specific addresses.
2441 (if resend-to-addresses
2442 (list resend-to-addresses
)
2444 (when message-interactive
2447 (goto-char (point-min))
2448 (while (re-search-forward "\n\n* *" nil t
)
2449 (replace-match "; "))
2450 (if (not (zerop (buffer-size)))
2451 (error "Sending...failed to %s"
2452 (buffer-substring (point-min) (point-max)))))
2453 (when (bufferp errbuf
)
2454 (kill-buffer errbuf
)))))
2456 (defun message-send-mail-with-qmail ()
2457 "Pass the prepared message buffer to qmail-inject.
2458 Refer to the documentation for the variable `message-send-mail-function'
2459 to find out how to use this."
2460 ;; replace the header delimiter with a blank line
2461 (goto-char (point-min))
2463 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2464 (replace-match "\n")
2465 (run-hooks 'message-send-mail-hook
)
2468 (let ((coding-system-for-write message-send-coding-system
))
2470 'call-process-region
1 (point-max) message-qmail-inject-program
2472 ;; qmail-inject's default behaviour is to look for addresses on the
2473 ;; command line; if there're none, it scans the headers.
2474 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2476 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2477 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2478 ;; message from stdin.
2480 ;; qmail also has the advantage of not having been raped by
2481 ;; various vendors, so we don't have to allow for that, either --
2482 ;; compare this with message-send-mail-with-sendmail and weep
2483 ;; for sendmail's lost innocence.
2485 ;; all this is way cool coz it lets us keep the arguments entirely
2486 ;; free for -inject-arguments -- a big win for the user and for us
2487 ;; since we don't have to play that double-guessing game and the user
2488 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2489 message-qmail-inject-args
))
2490 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2491 ;; we have to look at the retval instead
2493 (1 (error "qmail-inject reported permanent failure"))
2494 (111 (error "qmail-inject reported transient failure"))
2495 ;; should never happen
2496 (t (error "qmail-inject reported unknown failure"))))
2498 (defun message-send-mail-with-mh ()
2499 "Send the prepared message buffer with mh."
2500 (let ((mh-previous-window-config nil
)
2501 (name (mh-new-draft-name)))
2502 (setq buffer-file-name name
)
2503 ;; MH wants to generate these headers itself.
2504 (when message-mh-deletable-headers
2505 (let ((headers message-mh-deletable-headers
))
2507 (goto-char (point-min))
2508 (and (re-search-forward
2509 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
2510 (message-delete-line))
2512 (run-hooks 'message-send-mail-hook
)
2513 ;; Pass it on to mh.
2516 (defun message-send-news (&optional arg
)
2517 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2518 (case-fold-search nil
)
2519 (method (if (message-functionp message-post-method
)
2520 (funcall message-post-method arg
)
2521 message-post-method
))
2522 (group-name-charset (gnus-group-name-charset method
""))
2523 (rfc2047-header-encoding-alist
2524 (if group-name-charset
2525 (cons (cons "Newsgroups" group-name-charset
)
2526 rfc2047-header-encoding-alist
)
2527 rfc2047-header-encoding-alist
))
2528 (messbuf (current-buffer))
2529 (message-syntax-checks
2531 (cons '(existing-newsgroups . disabled
)
2532 message-syntax-checks
)
2533 message-syntax-checks
))
2534 (message-this-is-news t
)
2535 (message-posting-charset (gnus-setup-posting-charset
2537 (message-narrow-to-headers-or-head)
2538 (message-fetch-field "Newsgroups"))))
2540 (if (not (message-check-news-body-syntax))
2543 (message-narrow-to-headers)
2544 ;; Insert some headers.
2545 (message-generate-headers message-required-news-headers
)
2546 ;; Let the user do all of the above.
2547 (run-hooks 'message-header-hook
))
2548 (if group-name-charset
2549 (setq message-syntax-checks
2550 (cons '(valid-newsgroups . disabled
)
2551 message-syntax-checks
)))
2552 (message-cleanup-headers)
2553 (if (not (message-check-news-syntax))
2558 (buffer-disable-undo)
2560 ;; Avoid copying text props.
2561 (insert (with-current-buffer messbuf
2562 (buffer-substring-no-properties
2563 (point-min) (point-max))))
2564 (message-encode-message-body)
2565 ;; Remove some headers.
2567 (message-narrow-to-headers)
2568 ;; We (re)generate the Lines header.
2569 (when (memq 'Lines message-required-mail-headers
)
2570 (message-generate-headers '(Lines)))
2571 ;; Remove some headers.
2572 (message-remove-header message-ignored-news-headers t
)
2573 (let ((mail-parse-charset message-default-charset
))
2574 (mail-encode-encoded-word-buffer)))
2575 (goto-char (point-max))
2576 ;; require one newline at the end.
2577 (or (= (preceding-char) ?
\n)
2579 (let ((case-fold-search t
))
2580 ;; Remove the delimiter.
2581 (goto-char (point-min))
2583 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2584 (replace-match "\n")
2586 (run-hooks 'message-send-news-hook
)
2587 (gnus-open-server method
)
2588 (setq result
(let ((mail-header-separator ""))
2589 (gnus-request-post method
))))
2590 (kill-buffer tembuf
))
2591 (set-buffer messbuf
)
2593 (push 'news message-sent-message-via
)
2594 (message "Couldn't send message via news: %s"
2595 (nnheader-get-report (car method
)))
2599 ;;; Header generation & syntax checking.
2602 (defun message-check-element (type)
2603 "Return non-nil if this TYPE is not to be checked."
2604 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
2606 (let ((able (assq type message-syntax-checks
)))
2608 (eq (cdr able
) 'disabled
)))))
2610 (defun message-check-news-syntax ()
2611 "Check the syntax of the message."
2615 ;; We narrow to the headers and check them first.
2618 (message-narrow-to-headers)
2619 (message-check-news-header-syntax))))))
2621 (defun message-check-news-header-syntax ()
2623 ;; Check Newsgroups header.
2624 (message-check 'newsgroups
2625 (let ((group (message-fetch-field "newsgroups")))
2628 (not (string-match "\\`[ \t]*\\'" group
)))
2631 "The newsgroups field is empty or missing. Posting is denied.")))))
2632 ;; Check the Subject header.
2633 (message-check 'subject
2634 (let* ((case-fold-search t
)
2635 (subject (message-fetch-field "subject")))
2638 (not (string-match "\\`[ \t]*\\'" subject
)))
2641 "The subject field is empty or missing. Posting is denied.")))))
2642 ;; Check for commands in Subject.
2643 (message-check 'subject-cmsg
2644 (if (string-match "^cmsg " (message-fetch-field "subject"))
2646 "The control code \"cmsg\" is in the subject. Really post? ")
2648 ;; Check for multiple identical headers.
2649 (message-check 'multiple-headers
2651 (while (and (not found
)
2652 (re-search-forward "^[^ \t:]+: " nil t
))
2654 (or (re-search-forward
2659 (match-beginning 0) (- (match-end 0) 2))))
2664 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
2666 ;; Check for Version and Sendsys.
2667 (message-check 'sendsys
2668 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
2670 (format "The article contains a %s command. Really post? "
2671 (buffer-substring (match-beginning 0)
2672 (1- (match-end 0)))))
2674 ;; See whether we can shorten Followup-To.
2675 (message-check 'shorten-followup-to
2676 (let ((newsgroups (message-fetch-field "newsgroups"))
2677 (followup-to (message-fetch-field "followup-to"))
2679 (when (and newsgroups
2680 (string-match "," newsgroups
)
2685 (setq to
(completing-read
2686 "Followups to: (default all groups) "
2687 (mapcar (lambda (g) (list g
))
2689 (message-tokenize-header
2691 (goto-char (point-min))
2692 (insert "Followup-To: " to
"\n"))
2694 ;; Check "Shoot me".
2695 (message-check 'shoot
2696 (if (re-search-forward
2697 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t
)
2698 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2700 ;; Check for Approved.
2701 (message-check 'approved
2702 (if (re-search-forward "^Approved:" nil t
)
2703 (y-or-n-p "The article contains an Approved header. Really post? ")
2705 ;; Check the Message-ID header.
2706 (message-check 'message-id
2707 (let* ((case-fold-search t
)
2708 (message-id (message-fetch-field "message-id" t
)))
2709 (or (not message-id
)
2710 ;; Is there an @ in the ID?
2711 (and (string-match "@" message-id
)
2712 ;; Is there a dot in the ID?
2713 (string-match "@[^.]*\\." message-id
)
2714 ;; Does the ID end with a dot?
2715 (not (string-match "\\.>" message-id
)))
2717 (format "The Message-ID looks strange: \"%s\". Really post? "
2719 ;; Check the Newsgroups & Followup-To headers.
2720 (message-check 'existing-newsgroups
2721 (let* ((case-fold-search t
)
2722 (newsgroups (message-fetch-field "newsgroups"))
2723 (followup-to (message-fetch-field "followup-to"))
2724 (groups (message-tokenize-header
2726 (concat newsgroups
"," followup-to
)
2728 (hashtb (and (boundp 'gnus-active-hashtb
)
2729 gnus-active-hashtb
))
2731 (if (or (not hashtb
)
2732 (not (boundp 'gnus-read-active-file
))
2733 (not gnus-read-active-file
)
2734 (eq gnus-read-active-file
'some
))
2737 (when (and (not (boundp (intern (car groups
) hashtb
)))
2738 (not (equal (car groups
) "poster")))
2739 (push (car groups
) errors
))
2745 "Really post to %s unknown group%s: %s? "
2746 (if (= (length errors
) 1) "this" "these")
2747 (if (= (length errors
) 1) "" "s")
2748 (mapconcat 'identity errors
", ")))))))
2749 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2750 (message-check 'valid-newsgroups
2751 (let ((case-fold-search t
)
2752 (headers '("Newsgroups" "Followup-To"))
2754 (while (and headers
(not error
))
2755 (when (setq header
(mail-fetch-field (car headers
)))
2759 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2764 (not (string-match "\\.\\'\\|\\.\\." g
)))
2765 (message-tokenize-header header
","))))
2772 (format "The %s header looks odd: \"%s\". Really post? "
2773 (car headers
) header
)))))
2774 (message-check 'repeated-newsgroups
2775 (let ((case-fold-search t
)
2776 (headers '("Newsgroups" "Followup-To"))
2777 header error groups group
)
2780 (when (setq header
(mail-fetch-field (pop headers
)))
2781 (setq groups
(message-tokenize-header header
","))
2782 (while (setq group
(pop groups
))
2783 (when (member group groups
)
2789 (format "Group %s is repeated in headers. Really post? " error
)))))
2790 ;; Check the From header.
2791 (message-check 'from
2792 (let* ((case-fold-search t
)
2793 (from (message-fetch-field "from"))
2797 (message "There is no From line. Posting is denied.")
2799 ((or (not (string-match
2801 (setq ad
(nth 1 (mail-extract-address-components
2802 from
))))) ;larsi@ifi
2803 (string-match "\\.\\." ad
) ;larsi@ifi..uio
2804 (string-match "@\\." ad
) ;larsi@.ifi.uio
2805 (string-match "\\.$" ad
) ;larsi@ifi.uio.
2806 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
2807 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
2809 "Denied posting -- the From looks strange: \"%s\"." from
)
2813 (defun message-check-news-body-syntax ()
2815 ;; Check for long lines.
2816 (message-check 'long-lines
2817 (goto-char (point-min))
2819 (concat "^" (regexp-quote mail-header-separator
) "$"))
2823 (< (current-column) 80))
2824 (zerop (forward-line 1))))
2828 "You have lines longer than 79 characters. Really post? ")))
2829 ;; Check whether the article is empty.
2830 (message-check 'empty
2831 (goto-char (point-min))
2833 (concat "^" (regexp-quote mail-header-separator
) "$"))
2836 (goto-char (point-max))
2837 (re-search-backward message-signature-separator nil t
)
2839 (or (re-search-backward "[^ \n\t]" b t
)
2840 (y-or-n-p "Empty article. Really post? "))))
2841 ;; Check for control characters.
2842 (message-check 'control-chars
2843 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t
)
2845 "The article contains control characters. Really post? ")
2847 ;; Check excessive size.
2848 (message-check 'size
2849 (if (> (buffer-size) 60000)
2851 (format "The article is %d octets long. Really post? "
2854 ;; Check whether any new text has been added.
2855 (message-check 'new-text
2857 (not message-checksum
)
2858 (not (eq (message-checksum) message-checksum
))
2860 "It looks like no new text has been added. Really post? ")))
2861 ;; Check the length of the signature.
2862 (message-check 'signature
2863 (goto-char (point-max))
2864 (if (> (count-lines (point) (point-max)) 5)
2867 "Your .sig is %d lines; it should be max 4. Really post? "
2868 (1- (count-lines (point) (point-max)))))
2870 ;; Ensure that text follows last quoted portion.
2871 (message-check 'quoting-style
2872 (goto-char (point-max))
2873 (let ((no-problem t
))
2874 (when (search-backward-regexp "^>[^\n]*\n>" nil t
)
2875 (setq no-problem nil
)
2877 (when (and (not (eolp)) (looking-at "[^> \t]"))
2878 (setq no-problem t
))
2882 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
2884 (defun message-checksum ()
2885 "Return a \"checksum\" for the current buffer."
2888 (goto-char (point-min))
2890 (concat "^" (regexp-quote mail-header-separator
) "$"))
2892 (when (not (looking-at "[ \t\n]"))
2893 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
2898 (defun message-do-fcc ()
2899 "Process Fcc headers in the current buffer."
2900 (let ((case-fold-search t
)
2901 (buf (current-buffer))
2904 (set-buffer (get-buffer-create " *message temp*"))
2906 (insert-buffer-substring buf
)
2908 (message-narrow-to-headers)
2909 (while (setq file
(message-fetch-field "fcc"))
2911 (message-remove-header "fcc" nil t
)))
2912 (message-encode-message-body)
2914 (message-narrow-to-headers)
2915 (let ((mail-parse-charset message-default-charset
)
2916 (rfc2047-header-encoding-alist
2917 (cons '("Newsgroups" . default
)
2918 rfc2047-header-encoding-alist
)))
2919 (mail-encode-encoded-word-buffer)))
2920 (goto-char (point-min))
2921 (when (re-search-forward
2922 (concat "^" (regexp-quote mail-header-separator
) "$")
2924 (replace-match "" t t
))
2925 ;; Process FCC operations.
2927 (setq file
(pop list
))
2928 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
2929 ;; Pipe the article to the program in question.
2930 (call-process-region (point-min) (point-max) shell-file-name
2931 nil nil nil shell-command-switch
2932 (match-string 1 file
))
2933 ;; Save the article.
2934 (setq file
(expand-file-name file
))
2935 (unless (file-exists-p (file-name-directory file
))
2936 (make-directory (file-name-directory file
) t
))
2937 (if (and message-fcc-handler-function
2938 (not (eq message-fcc-handler-function
'rmail-output
)))
2939 (funcall message-fcc-handler-function file
)
2940 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
2941 (rmail-output file
1 nil t
)
2942 (let ((mail-use-rfc822 t
))
2943 (rmail-output file
1 t t
))))))
2944 (kill-buffer (current-buffer)))))
2946 (defun message-output (filename)
2947 "Append this article to Unix/babyl mail file FILENAME."
2948 (if (and (file-readable-p filename
)
2949 (mail-file-babyl-p filename
))
2950 (gnus-output-to-rmail filename t
)
2951 (gnus-output-to-mail filename t
)))
2953 (defun message-cleanup-headers ()
2954 "Do various automatic cleanups of the headers."
2955 ;; Remove empty lines in the header.
2957 (message-narrow-to-headers)
2958 ;; Remove blank lines.
2959 (while (re-search-forward "^[ \t]*\n" nil t
)
2960 (replace-match "" t t
))
2962 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2963 ;; spaces to comma and eliminate spaces around commas. Eliminate
2964 ;; embedded line breaks.
2965 (goto-char (point-min))
2966 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
2970 (if (re-search-forward "^[^ \t]" nil t
)
2974 (goto-char (point-min))
2975 (while (re-search-forward "\n[ \t]+" nil t
)
2976 (replace-match " " t t
)) ;No line breaks (too confusing)
2977 (goto-char (point-min))
2978 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
2979 (replace-match "," t t
))
2980 (goto-char (point-min))
2981 ;; Remove trailing commas.
2982 (when (re-search-forward ",+$" nil t
)
2983 (replace-match "" t t
))))))
2985 (defun message-make-date (&optional now
)
2986 "Make a valid data header.
2987 If NOW, use that time instead."
2988 (let* ((now (or now
(current-time)))
2989 (zone (nth 8 (decode-time now
)))
2993 (setq zone
(- zone
)))
2995 (format-time-string "%d" now
)
2996 ;; The month name of the %b spec is locale-specific. Pfff.
2998 (capitalize (car (rassoc (nth 4 (decode-time now
))
2999 parse-time-months
))))
3000 (format-time-string "%Y %H:%M:%S " now
)
3001 ;; We do all of this because XEmacs doesn't have the %z spec.
3002 (format "%s%02d%02d" sign
(/ zone
3600) (/ (% zone
3600) 60)))))
3004 (defun message-make-message-id ()
3005 "Make a unique Message-ID."
3006 (concat "<" (message-unique-id)
3007 (let ((psubject (save-excursion (message-fetch-field "subject")))
3009 (save-excursion (message-fetch-field "supersedes"))))
3011 (and message-reply-headers
3012 (mail-header-references message-reply-headers
)
3013 (mail-header-subject message-reply-headers
)
3016 (message-strip-subject-re
3017 (mail-header-subject message-reply-headers
))
3018 (message-strip-subject-re psubject
))))
3020 (string-match "_-_@" psupersedes
)))
3022 "@" (message-make-fqdn) ">"))
3024 (defvar message-unique-id-char nil
)
3026 ;; If you ever change this function, make sure the new version
3027 ;; cannot generate IDs that the old version could.
3028 ;; You might for example insert a "." somewhere (not next to another dot
3029 ;; or string boundary), or modify the "fsf" string.
3030 (defun message-unique-id ()
3031 ;; Don't use microseconds from (current-time), they may be unsupported.
3032 ;; Instead we use this randomly inited counter.
3033 (setq message-unique-id-char
3034 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
3035 ;; (current-time) returns 16-bit ints,
3036 ;; and 2^16*25 just fits into 4 digits i base 36.
3038 (let ((tm (current-time)))
3040 (if (memq system-type
'(ms-dos emx vax-vms
))
3041 (let ((user (downcase (user-login-name))))
3042 (while (string-match "[^a-z0-9_]" user
)
3043 (aset user
(match-beginning 0) ?_
))
3045 (message-number-base36 (user-uid) -
1))
3046 (message-number-base36 (+ (car tm
)
3047 (lsh (% message-unique-id-char
25) 16)) 4)
3048 (message-number-base36 (+ (nth 1 tm
)
3049 (lsh (/ message-unique-id-char
25) 16)) 4)
3050 ;; Append the newsreader name, because while the generated
3051 ;; ID is unique to this newsreader, other newsreaders might
3052 ;; otherwise generate the same ID via another algorithm.
3055 (defun message-number-base36 (num len
)
3060 (concat (message-number-base36 (/ num
36) (1- len
))
3061 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3064 (defun message-make-organization ()
3065 "Make an Organization header."
3066 (let* ((organization
3067 (when message-user-organization
3068 (if (message-functionp message-user-organization
)
3069 (funcall message-user-organization
)
3070 message-user-organization
))))
3072 (message-set-work-buffer)
3073 (cond ((stringp organization
)
3074 (insert organization
))
3075 ((and (eq t organization
)
3076 message-user-organization-file
3077 (file-exists-p message-user-organization-file
))
3078 (insert-file-contents message-user-organization-file
)))
3079 (goto-char (point-min))
3080 (while (re-search-forward "[\t\n]+" nil t
)
3081 (replace-match "" t t
))
3082 (unless (zerop (buffer-size))
3085 (defun message-make-lines ()
3086 "Count the number of lines and return numeric string."
3090 (goto-char (point-min))
3092 (concat "^" (regexp-quote mail-header-separator
) "$"))
3094 (int-to-string (count-lines (point) (point-max))))))
3096 (defun message-make-in-reply-to ()
3097 "Return the In-Reply-To header for this message."
3098 (when message-reply-headers
3099 (mail-header-message-id message-reply-headers
)))
3101 (defun message-make-distribution ()
3102 "Make a Distribution header."
3103 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3104 (cond ((message-functionp message-distribution-function
)
3105 (funcall message-distribution-function
))
3106 (t orig-distribution
))))
3108 (defun message-make-expires ()
3109 "Return an Expires header based on `message-expires'."
3110 (let ((current (current-time))
3111 (future (* 1.0 message-expires
60 60 24)))
3112 ;; Add the future to current.
3113 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
3114 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
3115 (message-make-date current
)))
3117 (defun message-make-path ()
3119 (let ((login-name (user-login-name)))
3120 (cond ((null message-user-path
)
3121 (concat (system-name) "!" login-name
))
3122 ((stringp message-user-path
)
3123 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3124 (concat message-user-path
"!" login-name
))
3127 (defun message-make-from ()
3128 "Make a From header."
3129 (let* ((style message-from-style
)
3130 (login (message-make-address))
3132 (or (and (boundp 'user-full-name
)
3135 (when (string= fullname
"&")
3136 (setq fullname
(user-login-name)))
3138 (message-set-work-buffer)
3141 (equal fullname
""))
3143 ((or (eq style
'angles
)
3144 (and (not (eq style
'parens
))
3145 ;; Use angles if no quoting is needed, or if parens would
3146 ;; need quoting too.
3147 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
3148 (let ((tmp (concat fullname nil
)))
3149 (while (string-match "([^()]*)" tmp
)
3150 (aset tmp
(match-beginning 0) ?-
)
3151 (aset tmp
(1- (match-end 0)) ?-
))
3152 (string-match "[\\()]" tmp
)))))
3154 (goto-char (point-min))
3155 ;; Look for a character that cannot appear unquoted
3156 ;; according to RFC 822.
3157 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
3158 ;; Quote fullname, escaping specials.
3159 (goto-char (point-min))
3161 (while (re-search-forward "[\"\\]" nil
1)
3162 (replace-match "\\\\\\&" t
))
3164 (insert " <" login
">"))
3165 (t ; 'parens or default
3167 (let ((fullname-start (point)))
3169 (goto-char fullname-start
)
3170 ;; RFC 822 says \ and nonmatching parentheses
3171 ;; must be escaped in comments.
3172 ;; Escape every instance of ()\ ...
3173 (while (re-search-forward "[()\\]" nil
1)
3174 (replace-match "\\\\\\&" t
))
3175 ;; ... then undo escaping of matching parentheses,
3176 ;; including matching nested parentheses.
3177 (goto-char fullname-start
)
3178 (while (re-search-forward
3179 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3181 (replace-match "\\1(\\3)" t
)
3182 (goto-char fullname-start
)))
3186 (defun message-make-sender ()
3187 "Return the \"real\" user address.
3188 This function tries to ignore all user modifications, and
3189 give as trustworthy answer as possible."
3190 (concat (user-login-name) "@" (system-name)))
3192 (defun message-make-address ()
3193 "Make the address of the user."
3194 (or (message-user-mail-address)
3195 (concat (user-login-name) "@" (message-make-domain))))
3197 (defun message-user-mail-address ()
3198 "Return the pertinent part of `user-mail-address'."
3199 (when user-mail-address
3200 (if (string-match " " user-mail-address
)
3201 (nth 1 (mail-extract-address-components user-mail-address
))
3202 user-mail-address
)))
3204 (defun message-make-fqdn ()
3205 "Return user's fully qualified domain name."
3206 (let ((system-name (system-name))
3207 (user-mail (message-user-mail-address)))
3209 ((string-match "[^.]\\.[^.]" system-name
)
3210 ;; `system-name' returned the right result.
3212 ;; Try `mail-host-address'.
3213 ((and (boundp 'mail-host-address
)
3214 (stringp mail-host-address
)
3215 (string-match "\\." mail-host-address
))
3217 ;; We try `user-mail-address' as a backup.
3219 (string-match "\\." user-mail
)
3220 (string-match "@\\(.*\\)\\'" user-mail
))
3221 (match-string 1 user-mail
))
3222 ;; Default to this bogus thing.
3224 (concat system-name
".i-did-not-set--mail-host-address--so-shoot-me")))))
3226 (defun message-make-host-name ()
3227 "Return the name of the host."
3228 (let ((fqdn (message-make-fqdn)))
3229 (string-match "^[^.]+\\." fqdn
)
3230 (substring fqdn
0 (1- (match-end 0)))))
3232 (defun message-make-domain ()
3233 "Return the domain name."
3234 (or mail-host-address
3235 (message-make-fqdn)))
3237 (defun message-generate-headers (headers)
3238 "Prepare article HEADERS.
3239 Headers already prepared in the buffer are not modified."
3241 (message-narrow-to-headers)
3242 (let* ((Date (message-make-date))
3243 (Message-ID (message-make-message-id))
3244 (Organization (message-make-organization))
3245 (From (message-make-from))
3246 (Path (message-make-path))
3249 (In-Reply-To (message-make-in-reply-to))
3251 (Distribution (message-make-distribution))
3252 (Lines (message-make-lines))
3253 (User-Agent message-newsreader
)
3254 (Expires (message-make-expires))
3255 (case-fold-search t
)
3257 ;; First we remove any old generated headers.
3258 (let ((headers message-deletable-headers
))
3259 (unless (buffer-modified-p)
3260 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
3262 (goto-char (point-min))
3263 (and (re-search-forward
3264 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
3265 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
3266 (message-delete-line))
3268 ;; Go through all the required headers and see if they are in the
3269 ;; articles already. If they are not, or are empty, they are
3270 ;; inserted automatically - except for Subject, Newsgroups and
3273 (goto-char (point-min))
3274 (setq elem
(pop headers
))
3276 (if (eq (car elem
) 'optional
)
3277 (setq header
(cdr elem
))
3278 (setq header
(car elem
)))
3280 (when (or (not (re-search-forward
3284 (if (stringp header
)
3286 (symbol-name header
))))
3290 ;; The header was found. We insert a space after the
3291 ;; colon, if there is none.
3292 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
3293 ;; Find out whether the header is empty...
3294 (looking-at "[ \t]*\n[^ \t]")))
3295 ;; So we find out what value we should insert.
3298 ((and (consp elem
) (eq (car elem
) 'optional
))
3299 ;; This is an optional header. If the cdr of this
3300 ;; is something that is nil, then we do not insert
3302 (setq header
(cdr elem
))
3303 (or (and (fboundp (cdr elem
)) (funcall (cdr elem
)))
3304 (and (boundp (cdr elem
)) (symbol-value (cdr elem
)))))
3306 ;; The element is a cons. Either the cdr is a
3307 ;; string to be inserted verbatim, or it is a
3308 ;; function, and we insert the value returned from
3310 (or (and (stringp (cdr elem
)) (cdr elem
))
3311 (and (fboundp (cdr elem
)) (funcall (cdr elem
)))))
3312 ((and (boundp header
) (symbol-value header
))
3313 ;; The element is a symbol. We insert the value
3314 ;; of this symbol, if any.
3315 (symbol-value header
))
3316 ((not (message-check-element header
))
3317 ;; We couldn't generate a value for this header,
3318 ;; so we just ask the user.
3319 (read-from-minibuffer
3320 (format "Empty header for %s; enter value: " header
)))))
3321 ;; Finally insert the header.
3323 (not (equal value
"")))
3327 ;; This header didn't exist, so we insert it.
3328 (goto-char (point-max))
3329 (insert (if (stringp header
) header
(symbol-name header
))
3332 ;; The value of this header was empty, so we clear
3333 ;; totally and insert the new value.
3334 (delete-region (point) (gnus-point-at-eol))
3336 ;; Add the deletable property to the headers that require it.
3337 (and (memq header message-deletable-headers
)
3338 (progn (beginning-of-line) (looking-at "[^:]+: "))
3339 (add-text-properties
3340 (point) (match-end 0)
3341 '(message-deletable t face italic
) (current-buffer)))))))
3342 ;; Insert new Sender if the From is strange.
3343 (let ((from (message-fetch-field "from"))
3344 (sender (message-fetch-field "sender"))
3345 (secure-sender (message-make-sender)))
3347 (not (message-check-element 'sender
))
3350 (cadr (mail-extract-address-components from
)))
3351 (downcase secure-sender
)))
3356 (cadr (mail-extract-address-components sender
)))
3357 (downcase secure-sender
)))))
3358 (goto-char (point-min))
3359 ;; Rename any old Sender headers to Original-Sender.
3360 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
3362 (insert "Original-")
3363 (beginning-of-line))
3364 (when (or (message-news-p)
3365 (string-match "@.+\\.." secure-sender
))
3366 (insert "Sender: " secure-sender
"\n")))))))
3368 (defun message-insert-courtesy-copy ()
3369 "Insert a courtesy message in mail copies of combined messages."
3373 (message-narrow-to-headers)
3374 (when (setq newsgroups
(message-fetch-field "newsgroups"))
3375 (goto-char (point-max))
3376 (insert "Posted-To: " newsgroups
"\n")))
3378 (when message-courtesy-message
3380 ((string-match "%s" message-courtesy-message
)
3381 (insert (format message-courtesy-message newsgroups
)))
3383 (insert message-courtesy-message
)))))))
3386 ;;; Setting up a message buffer
3389 (defun message-fill-address (header value
)
3391 (narrow-to-region (point) (point))
3392 (insert (capitalize (symbol-name header
))
3394 (if (consp value
) (car value
) value
)
3396 (narrow-to-region (point-min) (1- (point-max)))
3398 (goto-char (point-min))
3400 (skip-chars-forward "^,\"" (point-max))
3401 (if (or (eq (char-after) ?
,)
3404 (if (and (> (current-column) 78)
3410 (setq last
(1+ (point))))
3411 (setq last
(1+ (point)))))
3412 (setq quoted
(not quoted
)))
3415 (goto-char (point-max))
3419 (defun message-fill-header (header value
)
3420 (let ((begin (point))
3423 (insert (capitalize (symbol-name header
))
3425 (if (consp value
) (car value
) value
)
3428 (narrow-to-region begin
(point))
3429 (fill-region-as-paragraph begin
(point))
3430 ;; Tapdance around looong Message-IDs.
3432 (when (looking-at "[ \t]*$")
3433 (message-delete-line))
3435 (re-search-forward ":" nil t
)
3436 (when (looking-at "\n[ \t]+")
3437 (replace-match " " t t
))
3438 (goto-char (point-max)))))
3440 (defun message-shorten-1 (list cut surplus
)
3441 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
3442 (setcdr (nthcdr (- cut
2) list
)
3443 (nthcdr (+ (- cut
2) surplus
1) list
)))
3445 (defun message-shorten-references (header references
)
3446 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3447 If folding is disallowed, also check that the REFERENCES are less
3448 than 988 characters long, and if they are not, trim them until they are."
3455 (goto-char (point-min))
3456 ;; Cons a list of valid references.
3457 (while (re-search-forward "<[^>]+>" nil t
)
3458 (push (match-string 0) refs
))
3459 (setq refs
(nreverse refs
)
3460 count
(length refs
)))
3462 ;; If the list has more than MAXCOUNT elements, trim it by
3463 ;; removing the CUTth element and the required number of
3464 ;; elements that follow.
3465 (when (> count maxcount
)
3466 (let ((surplus (- count maxcount
)))
3467 (message-shorten-1 refs cut surplus
)
3468 (decf count surplus
)))
3470 ;; If folding is disallowed, make sure the total length (including
3471 ;; the spaces between) will be less than MAXSIZE characters.
3473 ;; Only disallow folding for News messages. At this point the headers
3474 ;; have not been generated, thus we use message-this-is-news directly.
3475 (when (and message-this-is-news message-cater-to-broken-inn
)
3477 (totalsize (+ (apply #'+ (mapcar #'length refs
))
3480 (ptr (nthcdr (1- cut
) refs
)))
3481 ;; Decide how many elements to cut off...
3482 (while (> totalsize maxsize
)
3483 (decf totalsize
(1+ (length (car ptr
))))
3485 (setq ptr
(cdr ptr
)))
3488 (message-shorten-1 refs cut surplus
))))
3490 ;; Finally, collect the references back into a string and insert
3491 ;; it into the buffer.
3492 (let ((refstring (mapconcat #'identity refs
" ")))
3493 (if (and message-this-is-news message-cater-to-broken-inn
)
3494 (insert (capitalize (symbol-name header
)) ": "
3496 (message-fill-header header refstring
)))))
3498 (defun message-position-point ()
3499 "Move point to where the user probably wants to find it."
3500 (message-narrow-to-headers)
3502 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
3503 (search-backward ":" )
3506 (if (eq (char-after) ?
)
3510 (goto-char (point-max))
3513 (unless (looking-at "$")
3517 (defun message-buffer-name (type &optional to group
)
3518 "Return a new (unique) buffer name based on TYPE and TO."
3520 ;; Generate a new buffer name The Message Way.
3521 ((eq message-generate-new-buffers
'unique
)
3522 (generate-new-buffer-name
3526 (or (car (mail-extract-address-components to
))
3529 (if (and group
(not (string= group
""))) (concat " on " group
) "")
3531 ;; Check whether `message-generate-new-buffers' is a function,
3532 ;; and if so, call it.
3533 ((message-functionp message-generate-new-buffers
)
3534 (funcall message-generate-new-buffers type to group
))
3535 ((eq message-generate-new-buffers
'unsent
)
3536 (generate-new-buffer-name
3537 (concat "*unsent " type
3540 (or (car (mail-extract-address-components to
))
3543 (if (and group
(not (string= group
""))) (concat " on " group
) "")
3545 ;; Use standard name.
3547 (format "*%s message*" type
))))
3549 (defun message-pop-to-buffer (name)
3550 "Pop to buffer NAME, and warn if it already exists and is modified."
3551 (let ((buffer (get-buffer name
)))
3553 (buffer-name buffer
))
3555 (set-buffer (pop-to-buffer buffer
))
3556 (when (and (buffer-modified-p)
3558 "Message already being composed; erase? ")))
3559 (error "Message being composed")))
3560 (set-buffer (pop-to-buffer name
)))
3564 (defun message-do-send-housekeeping ()
3565 "Kill old message buffers."
3566 ;; We might have sent this buffer already. Delete it from the
3568 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
3569 (while (and message-max-buffers
3571 (>= (length message-buffer-list
) message-max-buffers
))
3572 ;; Kill the oldest buffer -- unless it has been changed.
3573 (let ((buffer (pop message-buffer-list
)))
3574 (when (and (buffer-name buffer
)
3575 (not (buffer-modified-p buffer
)))
3576 (kill-buffer buffer
))))
3577 ;; Rename the buffer.
3578 (if message-send-rename-function
3579 (funcall message-send-rename-function
)
3580 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3582 (concat "*sent " (substring (buffer-name) (match-end 0))) t
)))
3583 ;; Push the current buffer onto the list.
3584 (when message-max-buffers
3585 (setq message-buffer-list
3586 (nconc message-buffer-list
(list (current-buffer))))))
3588 (defun message-mail-user-agent ()
3590 ((not message-mail-user-agent
) nil
)
3591 ((eq message-mail-user-agent t
) mail-user-agent
)
3592 (t message-mail-user-agent
))))
3593 (if (memq mua
'(message-user-agent gnus-user-agent
))
3597 (defun message-setup (headers &optional replybuffer actions switch-function
)
3598 (let ((mua (message-mail-user-agent))
3599 subject to field yank-action
)
3600 (if (not (and message-this-is-mail mua
))
3601 (message-setup-1 headers replybuffer actions
)
3603 (setq yank-action
(list 'insert-buffer replybuffer
)))
3604 (setq headers
(copy-sequence headers
))
3605 (setq field
(assq 'Subject headers
))
3607 (setq subject
(cdr field
))
3608 (setq headers
(delq field headers
)))
3609 (setq field
(assq 'To headers
))
3611 (setq to
(cdr field
))
3612 (setq headers
(delq field headers
)))
3613 (let ((mail-user-agent mua
))
3614 (compose-mail to subject
3615 (mapcar (lambda (item)
3617 (format "%s" (car item
))
3620 nil switch-function yank-action actions
)))))
3622 (eval-when-compile (defvar mc-modes-alist
))
3623 (defun message-setup-1 (headers &optional replybuffer actions
)
3624 (when (and (boundp 'mc-modes-alist
)
3625 (not (assq 'message-mode mc-modes-alist
)))
3626 (push '(message-mode (encrypt . mc-encrypt-message
)
3627 (sign . mc-sign-message
))
3630 (setq message-send-actions actions
))
3631 (setq message-reply-buffer replybuffer
)
3632 (goto-char (point-min))
3633 ;; Insert all the headers.
3636 (alist message-header-format-alist
))
3638 (unless (assq (caar h
) message-header-format-alist
)
3639 (push (list (caar h
)) alist
))
3643 (delete-region (point) (progn (forward-line -
1) (point)))
3644 (when message-default-headers
3645 (insert message-default-headers
)
3646 (or (bolp) (insert ?
\n)))
3650 (insert mail-header-separator
"\n")
3654 (when (message-news-p)
3655 (when message-default-news-headers
3656 (insert message-default-news-headers
)
3657 (or (bolp) (insert ?
\n)))
3658 (when message-generate-headers-first
3659 (message-generate-headers
3662 (copy-sequence message-required-news-headers
))))))
3663 (when (message-mail-p)
3664 (when message-default-mail-headers
3665 (insert message-default-mail-headers
)
3666 (or (bolp) (insert ?
\n)))
3667 (when message-generate-headers-first
3668 (message-generate-headers
3671 (copy-sequence message-required-mail-headers
))))))
3672 (run-hooks 'message-signature-setup-hook
)
3673 (message-insert-signature)
3675 (message-narrow-to-headers)
3676 (if message-alternative-emails
3677 (message-use-alternative-email-as-from))
3678 (run-hooks 'message-header-setup-hook
))
3679 (set-buffer-modified-p nil
)
3680 (setq buffer-undo-list nil
)
3681 (run-hooks 'message-setup-hook
)
3682 (message-position-point)
3685 (defun message-set-auto-save-file-name ()
3686 "Associate the message buffer with a file in the drafts directory."
3687 (when message-auto-save-directory
3688 (unless (file-directory-p
3689 (directory-file-name message-auto-save-directory
))
3690 (gnus-make-directory message-auto-save-directory
))
3692 (setq message-draft-article
3693 (nndraft-request-associate-buffer "drafts"))
3694 (setq buffer-file-name
(expand-file-name "*message*"
3695 message-auto-save-directory
))
3696 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
3697 (clear-visited-file-modtime)
3698 (setq buffer-file-coding-system message-draft-coding-system
)))
3700 (defun message-disassociate-draft ()
3701 "Disassociate the message buffer from the drafts directory."
3702 (when message-draft-article
3703 (nndraft-request-expire-articles
3704 (list message-draft-article
) "drafts" nil t
)))
3706 (defun message-insert-headers ()
3707 "Generate the headers for the article."
3711 (message-narrow-to-headers)
3712 (when (message-news-p)
3713 (message-generate-headers
3716 (copy-sequence message-required-news-headers
)))))
3717 (when (message-mail-p)
3718 (message-generate-headers
3721 (copy-sequence message-required-mail-headers
))))))))
3726 ;;; Commands for interfacing with message
3730 (defun message-mail (&optional to subject
3731 other-headers continue switch-function
3732 yank-action send-actions
)
3733 "Start editing a mail message to be sent.
3734 OTHER-HEADERS is an alist of header/value pairs."
3736 (let ((message-this-is-mail t
) replybuffer
)
3737 (unless (message-mail-user-agent)
3738 (message-pop-to-buffer (message-buffer-name "mail" to
)))
3739 ;; FIXME: message-mail should do something if YANK-ACTION is not
3741 (and (consp yank-action
) (eq (car yank-action
) 'insert-buffer
)
3742 (setq replybuffer
(nth 1 yank-action
)))
3745 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
3746 (when other-headers other-headers
))
3748 ;; FIXME: Should return nil if failure.
3752 (defun message-news (&optional newsgroups subject
)
3753 "Start editing a news article to be sent."
3755 (let ((message-this-is-news t
))
3756 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
))
3757 (message-setup `((Newsgroups .
,(or newsgroups
""))
3758 (Subject .
,(or subject
""))))))
3760 (defun message-get-reply-headers (wide &optional to-address
)
3761 (let (follow-to mct never-mct from to cc reply-to ccalist
)
3762 ;; Find all relevant headers we need.
3763 (setq from
(message-fetch-field "from")
3764 to
(message-fetch-field "to")
3765 cc
(message-fetch-field "cc")
3766 mct
(message-fetch-field "mail-copies-to")
3767 reply-to
(message-fetch-field "reply-to"))
3769 ;; Handle special values of Mail-Copies-To.
3771 (cond ((or (equal (downcase mct
) "never")
3772 (equal (downcase mct
) "nobody"))
3775 ((or (equal (downcase mct
) "always")
3776 (equal (downcase mct
) "poster"))
3777 (setq mct
(or reply-to from
)))))
3782 (setq follow-to
(list (cons 'To
(or to-address reply-to from
))))
3783 (when (and wide mct
)
3784 (push (cons 'Cc mct
) follow-to
)))
3787 (message-set-work-buffer)
3789 (insert (or reply-to from
"")))
3790 (insert (if to
(concat (if (bolp) "" ", ") to
"") ""))
3791 (insert (if mct
(concat (if (bolp) "" ", ") mct
) ""))
3792 (insert (if cc
(concat (if (bolp) "" ", ") cc
) ""))
3793 (goto-char (point-min))
3794 (while (re-search-forward "[ \t]+" nil t
)
3795 (replace-match " " t t
))
3796 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3797 (let ((rmail-dont-reply-to-names message-dont-reply-to-names
))
3798 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3800 (goto-char (point-min))
3801 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3803 (insert (or reply-to from
"")))
3807 (cons (mail-strip-quoted-names addr
) addr
))
3808 (message-tokenize-header (buffer-string))))
3811 (setq ccalist
(delq (assoc (car (pop s
)) s
) ccalist
)))))
3812 (setq follow-to
(list (cons 'To
(cdr (pop ccalist
)))))
3814 (let ((ccs (cons 'Cc
(mapconcat
3815 (lambda (addr) (cdr addr
)) ccalist
", "))))
3816 (when (string-match "^ +" (cdr ccs
))
3817 (setcdr ccs
(substring (cdr ccs
) (match-end 0))))
3818 (push ccs follow-to
)))))
3823 (defun message-reply (&optional to-address wide
)
3824 "Start editing a reply to the article in the current buffer."
3826 (require 'gnus-sum
) ; for gnus-list-identifiers
3827 (let ((cur (current-buffer))
3828 from subject date reply-to to cc
3829 references message-id follow-to
3830 (inhibit-point-motion-hooks t
)
3831 (message-this-is-mail t
)
3834 (message-narrow-to-head-1)
3835 ;; Allow customizations to have their say.
3837 ;; This is a regular reply.
3838 (if (message-functionp message-reply-to-function
)
3839 (setq follow-to
(funcall message-reply-to-function
)))
3840 ;; This is a followup.
3841 (if (message-functionp message-wide-reply-to-function
)
3844 (funcall message-wide-reply-to-function
)))))
3845 (setq message-id
(message-fetch-field "message-id" t
)
3846 references
(message-fetch-field "references")
3847 date
(message-fetch-field "date")
3848 from
(message-fetch-field "from")
3849 subject
(or (message-fetch-field "subject") "none"))
3850 (if gnus-list-identifiers
3851 (setq subject
(message-strip-list-identifiers subject
)))
3852 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
3854 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3855 (string-match "<[^>]+>" gnus-warning
))
3856 (setq message-id
(match-string 0 gnus-warning
)))
3859 (setq follow-to
(message-get-reply-headers wide to-address
))))
3861 (unless (message-mail-user-agent)
3862 (message-pop-to-buffer
3863 (message-buffer-name
3864 (if wide
"wide reply" "reply") from
3865 (if wide to-address nil
))))
3867 (setq message-reply-headers
3868 (vector 0 subject from date message-id references
0 0 ""))
3871 `((Subject .
,subject
)
3873 ,@(if (or references message-id
)
3874 `((References .
,(concat (or references
"") (and references
" ")
3875 (or message-id
""))))
3880 (defun message-wide-reply (&optional to-address
)
3881 "Make a \"wide\" reply to the message in the current buffer."
3883 (message-reply to-address t
))
3886 (defun message-followup (&optional to-newsgroups
)
3887 "Follow up to the message in the current buffer.
3888 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3890 (require 'gnus-sum
) ; for gnus-list-identifiers
3891 (let ((cur (current-buffer))
3892 from subject date reply-to mct
3893 references message-id follow-to
3894 (inhibit-point-motion-hooks t
)
3895 (message-this-is-news t
)
3896 followup-to distribution newsgroups gnus-warning posted-to
)
3899 (goto-char (point-min))
3900 (if (search-forward "\n\n" nil t
)
3903 (when (message-functionp message-followup-to-function
)
3905 (funcall message-followup-to-function
)))
3906 (setq from
(message-fetch-field "from")
3907 date
(message-fetch-field "date")
3908 subject
(or (message-fetch-field "subject") "none")
3909 references
(message-fetch-field "references")
3910 message-id
(message-fetch-field "message-id" t
)
3911 followup-to
(message-fetch-field "followup-to")
3912 newsgroups
(message-fetch-field "newsgroups")
3913 posted-to
(message-fetch-field "posted-to")
3914 reply-to
(message-fetch-field "reply-to")
3915 distribution
(message-fetch-field "distribution")
3916 mct
(message-fetch-field "mail-copies-to"))
3917 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3918 (string-match "<[^>]+>" gnus-warning
))
3919 (setq message-id
(match-string 0 gnus-warning
)))
3920 ;; Remove bogus distribution.
3921 (when (and (stringp distribution
)
3922 (let ((case-fold-search t
))
3923 (string-match "world" distribution
)))
3924 (setq distribution nil
))
3925 (if gnus-list-identifiers
3926 (setq subject
(message-strip-list-identifiers subject
)))
3927 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
3930 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
3933 `((Subject .
,subject
)
3936 (list (cons 'Newsgroups to-newsgroups
)))
3937 (follow-to follow-to
)
3938 ((and followup-to message-use-followup-to
)
3941 ((equal (downcase followup-to
) "poster")
3942 (if (or (eq message-use-followup-to
'use
)
3943 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
3944 You should normally obey the Followup-To: header.
3946 `Followup-To: poster' sends your response via e-mail instead of news.
3948 A typical situation where `Followup-To: poster' is used is when the poster
3949 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3951 (setq message-this-is-news nil
)
3952 (cons 'To
(or reply-to from
"")))
3953 (cons 'Newsgroups newsgroups
)))
3955 (if (or (equal followup-to newsgroups
)
3956 (not (eq message-use-followup-to
'ask
))
3958 (concat "Obey Followup-To: " followup-to
"? ") t
"\
3959 You should normally obey the Followup-To: header.
3961 `Followup-To: " followup-to
"'
3962 directs your response to " (if (string-match "," followup-to
)
3963 "the specified newsgroups"
3964 "that newsgroup only") ".
3966 If a message is posted to several newsgroups, Followup-To is often
3967 used to direct the following discussion to one newsgroup only,
3968 because discussions that are spread over several newsgroup tend to
3969 be fragmented and very difficult to follow.
3971 Also, some source/announcement newsgroups are not indented for discussion;
3972 responses here are directed to other newsgroups."))
3973 (cons 'Newsgroups followup-to
)
3974 (cons 'Newsgroups newsgroups
))))))
3976 `((Newsgroups .
,posted-to
)))
3978 `((Newsgroups .
,newsgroups
))))
3979 ,@(and distribution
(list (cons 'Distribution distribution
)))
3980 ,@(if (or references message-id
)
3981 `((References .
,(concat (or references
"") (and references
" ")
3982 (or message-id
"")))))
3984 (not (or (equal (downcase mct
) "never")
3985 (equal (downcase mct
) "nobody"))))
3986 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
3987 (equal (downcase mct
) "poster"))
3988 (or reply-to from
"")
3993 (setq message-reply-headers
3994 (vector 0 subject from date message-id references
0 0 ""))))
3998 (defun message-cancel-news (&optional arg
)
3999 "Cancel an article you posted.
4000 If ARG, allow editing of the cancellation message."
4002 (unless (message-news-p)
4003 (error "This is not a news article; canceling is impossible"))
4004 (when (yes-or-no-p "Do you really want to cancel this article? ")
4005 (let (from newsgroups message-id distribution buf sender
)
4007 ;; Get header info from original article.
4009 (message-narrow-to-head-1)
4010 (setq from
(message-fetch-field "from")
4011 sender
(message-fetch-field "sender")
4012 newsgroups
(message-fetch-field "newsgroups")
4013 message-id
(message-fetch-field "message-id" t
)
4014 distribution
(message-fetch-field "distribution")))
4015 ;; Make sure that this article was written by the user.
4016 (unless (or (and sender
4019 (downcase (message-make-sender))))
4021 (downcase (cadr (mail-extract-address-components from
)))
4022 (downcase (cadr (mail-extract-address-components
4023 (message-make-from))))))
4024 (error "This article is not yours"))
4025 ;; Make control message.
4028 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
4030 (insert "Newsgroups: " newsgroups
"\n"
4032 "Subject: cmsg cancel " message-id
"\n"
4033 "Control: cancel " message-id
"\n"
4035 (concat "Distribution: " distribution
"\n")
4037 mail-header-separator
"\n"
4038 message-cancel-message
)
4039 (run-hooks 'message-cancel-hook
)
4041 (message "Canceling your article...")
4042 (if (let ((message-syntax-checks
4043 'dont-check-for-anything-just-trust-me
))
4044 (funcall message-send-news-function
))
4045 (message "Canceling your article...done"))
4046 (kill-buffer buf
))))))
4049 (defun message-supersede ()
4050 "Start composing a message to supersede the current message.
4051 This is done simply by taking the old article and adding a Supersedes
4052 header line with the old Message-ID."
4054 (let ((cur (current-buffer))
4055 (sender (message-fetch-field "sender"))
4056 (from (message-fetch-field "from")))
4057 ;; Check whether the user owns the article that is to be superseded.
4058 (unless (or (and sender
4061 (downcase (message-make-sender))))
4063 (downcase (cadr (mail-extract-address-components from
)))
4064 (downcase (cadr (mail-extract-address-components
4065 (message-make-from))))))
4066 (error "This article is not yours"))
4067 ;; Get a normal message buffer.
4068 (message-pop-to-buffer (message-buffer-name "supersede"))
4069 (insert-buffer-substring cur
)
4071 (message-narrow-to-head-1)
4072 ;; Remove unwanted headers.
4073 (when message-ignored-supersedes-headers
4074 (message-remove-header message-ignored-supersedes-headers t
))
4075 (goto-char (point-min))
4076 (if (not (re-search-forward "^Message-ID: " nil t
))
4077 (error "No Message-ID in this article")
4078 (replace-match "Supersedes: " t t
))
4079 (goto-char (point-max))
4080 (insert mail-header-separator
)
4085 (defun message-recover ()
4086 "Reread contents of current buffer from its last auto-save file."
4088 (let ((file-name (make-auto-save-file-name)))
4089 (cond ((save-window-excursion
4090 (if (not (eq system-type
'vax-vms
))
4091 (with-output-to-temp-buffer "*Directory*"
4092 (with-current-buffer standard-output
4093 (fundamental-mode)) ; for Emacs 20.4+
4094 (buffer-disable-undo standard-output
)
4095 (let ((default-directory "/"))
4097 "ls" nil standard-output nil
"-l" file-name
))))
4098 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
4099 (let ((buffer-read-only nil
))
4101 (insert-file-contents file-name nil
)))
4102 (t (error "message-recover cancelled")))))
4104 ;;; Washing Subject:
4106 (defun message-wash-subject (subject)
4107 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
4108 Previous forwarders, replyers, etc. may add it."
4110 (insert-string subject
)
4111 (goto-char (point-min))
4112 ;; strip Re/Fwd stuff off the beginning
4113 (while (re-search-forward
4114 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
4117 ;; and gnus-style forwards [foo@bar.com] subject
4118 (goto-char (point-min))
4119 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
4123 (goto-char (point-max))
4124 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
4127 ;; and finally, any whitespace that was left-over
4128 (goto-char (point-min))
4129 (while (re-search-forward "^[ \t]+" nil t
)
4131 (goto-char (point-max))
4132 (while (re-search-backward "[ \t]+$" nil t
)
4137 ;;; Forwarding messages.
4139 (defun message-forward-subject-author-subject (subject)
4140 "Generate a SUBJECT for a forwarded message.
4141 The form is: [Source] Subject, where if the original message was mail,
4142 Source is the sender, and if the original message was news, Source is
4143 the list of newsgroups is was posted to."
4145 (or (message-fetch-field
4146 (if (message-news-p) "newsgroups" "from"))
4150 (defun message-forward-subject-fwd (subject)
4151 "Generate a SUBJECT for a forwarded message.
4152 The form is: Fwd: Subject, where Subject is the original subject of
4154 (concat "Fwd: " subject
))
4156 (defun message-make-forward-subject ()
4157 "Return a Subject header suitable for the message in the current buffer."
4160 (message-narrow-to-head-1)
4161 (let ((funcs message-make-forward-subject-function
)
4162 (subject (message-fetch-field "Subject")))
4165 (mail-decode-encoded-word-string subject
)
4167 (if message-wash-forwarded-subjects
4168 (setq subject
(message-wash-subject subject
)))
4169 ;; Make sure funcs is a list.
4172 (setq funcs
(list funcs
)))
4173 ;; Apply funcs in order, passing subject generated by previous
4174 ;; func to the next one.
4176 (when (message-functionp (car funcs
))
4177 (setq subject
(funcall (car funcs
) subject
)))
4178 (setq funcs
(cdr funcs
)))
4182 (defun message-forward (&optional news digest
)
4183 "Forward the current message via mail.
4184 Optional NEWS will use news to forward instead of mail.
4185 Optional DIGEST will use digest to forward."
4187 (let* ((cur (current-buffer))
4188 (subject (message-make-forward-subject))
4191 (message-news nil subject
)
4192 (message-mail nil subject
))
4193 ;; Put point where we want it before inserting the forwarded
4195 (if message-forward-before-signature
4197 (goto-char (point-max)))
4198 (if message-forward-as-mime
4200 (insert "\n<#multipart type=digest>\n")
4201 (if message-forward-show-mml
4202 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4203 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4204 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4205 (let ((b (point)) e
)
4207 (if message-forward-as-mime
4208 (insert-buffer-substring cur
)
4209 (mml-insert-buffer cur
))
4210 (if message-forward-show-mml
4211 (let ((target (current-buffer)) tmp
)
4213 (mm-disable-multibyte) ;; Must copy buffer in unibyte mode
4214 (setq tmp
(current-buffer))
4216 (mm-with-unibyte-current-buffer
4218 (insert-buffer-substring cur
)
4221 (mm-enable-multibyte)
4223 (goto-char (point-min))
4224 (when (looking-at "From ")
4225 (replace-match "X-From-Line: "))
4227 (insert-buffer-substring tmp
)
4230 (narrow-to-region (point) (point))
4231 (mml-insert-buffer cur
)
4232 (goto-char (point-min))
4233 (when (looking-at "From ")
4234 (replace-match "X-From-Line: "))
4235 (goto-char (point-max)))))
4237 (if message-forward-as-mime
4239 (insert "<#/multipart>\n")
4240 (if message-forward-show-mml
4241 (insert "<#/mml>\n")
4242 (insert "<#/part>\n")))
4243 (insert "\n-------------------- End of forwarded message --------------------\n"))
4244 (if (and digest message-forward-as-mime
)
4246 (narrow-to-region b e
)
4248 (narrow-to-region (point)
4249 (or (search-forward "\n\n" nil t
) (point)))
4250 (delete-region (point-min) (point-max)))
4251 (when (and (not current-prefix-arg
)
4252 message-forward-ignored-headers
)
4254 (narrow-to-region b e
)
4256 (narrow-to-region (point)
4257 (or (search-forward "\n\n" nil t
) (point)))
4258 (message-remove-header message-forward-ignored-headers t
)))))
4259 (message-position-point)))
4262 (defun message-resend (address)
4263 "Resend the current article to ADDRESS."
4265 (list (message-read-from-minibuffer "Resend message to: ")))
4266 (message "Resending message to %s..." address
)
4268 (let ((cur (current-buffer))
4270 ;; We first set up a normal mail buffer.
4271 (unless (message-mail-user-agent)
4272 (set-buffer (get-buffer-create " *message resend*"))
4274 (let ((message-this-is-mail t
))
4275 (message-setup `((To .
,address
))))
4276 ;; Insert our usual headers.
4277 (message-generate-headers '(From Date To
))
4278 (message-narrow-to-headers)
4279 ;; Rename them all to "Resent-*".
4280 (while (re-search-forward "^[A-Za-z]" nil t
)
4285 (delete-region (point) (point-max))
4287 ;; Insert the message to be resent.
4288 (insert-buffer-substring cur
)
4289 (goto-char (point-min))
4290 (search-forward "\n\n")
4293 (narrow-to-region beg
(point))
4294 (message-remove-header message-ignored-resent-headers t
)
4295 (goto-char (point-max)))
4296 (insert mail-header-separator
)
4297 ;; Rename all old ("Also-")Resent headers.
4298 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
4301 ;; Quote any "From " lines at the beginning.
4303 (when (looking-at "From ")
4304 (replace-match "X-From-Line: "))
4306 (let ((message-inhibit-body-encoding t
)
4307 message-required-mail-headers
)
4308 (message-send-mail))
4309 (kill-buffer (current-buffer)))
4310 (message "Resending message to %s...done" address
)))
4313 (defun message-bounce ()
4314 "Re-mail the current message.
4315 This only makes sense if the current message is a bounce message that
4316 contains some mail you have written which has been bounced back to
4319 (let ((handles (mm-dissect-buffer t
))
4321 (message-pop-to-buffer (message-buffer-name "bounce"))
4322 (if (stringp (car handles
))
4323 ;; This is a MIME bounce.
4324 (mm-insert-part (car (last handles
)))
4325 ;; This is a non-MIME bounce, so we try to remove things
4327 (mm-insert-part handles
)
4329 (goto-char (point-min))
4330 (search-forward "\n\n" nil t
)
4331 (or (and (re-search-forward message-unsent-separator nil t
)
4333 (re-search-forward "^Return-Path:.*\n" nil t
))
4334 ;; We remove everything before the bounced mail.
4337 (if (re-search-forward "^[^ \n\t]+:" nil t
)
4340 (mm-enable-multibyte)
4343 (message-narrow-to-head-1)
4344 (message-remove-header message-ignored-bounced-headers t
)
4345 (goto-char (point-max))
4346 (insert mail-header-separator
))
4347 (message-position-point)))
4350 ;;; Interactive entry points for new message buffers.
4354 (defun message-mail-other-window (&optional to subject
)
4355 "Like `message-mail' command, but display mail buffer in another window."
4357 (unless (message-mail-user-agent)
4358 (let ((pop-up-windows t
)
4359 (special-display-buffer-names nil
)
4360 (special-display-regexps nil
)
4361 (same-window-buffer-names nil
)
4362 (same-window-regexps nil
))
4363 (message-pop-to-buffer (message-buffer-name "mail" to
))))
4364 (let ((message-this-is-mail t
))
4365 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
4366 nil nil
'switch-to-buffer-other-window
)))
4369 (defun message-mail-other-frame (&optional to subject
)
4370 "Like `message-mail' command, but display mail buffer in another frame."
4372 (unless (message-mail-user-agent)
4373 (let ((pop-up-frames t
)
4374 (special-display-buffer-names nil
)
4375 (special-display-regexps nil
)
4376 (same-window-buffer-names nil
)
4377 (same-window-regexps nil
))
4378 (message-pop-to-buffer (message-buffer-name "mail" to
))))
4379 (let ((message-this-is-mail t
))
4380 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
4381 nil nil
'switch-to-buffer-other-frame
)))
4384 (defun message-news-other-window (&optional newsgroups subject
)
4385 "Start editing a news article to be sent."
4387 (let ((pop-up-windows t
)
4388 (special-display-buffer-names nil
)
4389 (special-display-regexps nil
)
4390 (same-window-buffer-names nil
)
4391 (same-window-regexps nil
))
4392 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
4393 (let ((message-this-is-news t
))
4394 (message-setup `((Newsgroups .
,(or newsgroups
""))
4395 (Subject .
,(or subject
""))))))
4398 (defun message-news-other-frame (&optional newsgroups subject
)
4399 "Start editing a news article to be sent."
4401 (let ((pop-up-frames t
)
4402 (special-display-buffer-names nil
)
4403 (special-display-regexps nil
)
4404 (same-window-buffer-names nil
)
4405 (same-window-regexps nil
))
4406 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
4407 (let ((message-this-is-news t
))
4408 (message-setup `((Newsgroups .
,(or newsgroups
""))
4409 (Subject .
,(or subject
""))))))
4413 ;; This code should be moved to underline.el (from which it is stolen).
4416 (defun bold-region (start end
)
4417 "Bold all nonblank characters in the region.
4418 Works by overstriking characters.
4419 Called from program, takes two arguments START and END
4420 which specify the range to operate on."
4423 (let ((end1 (make-marker)))
4424 (move-marker end1
(max start end
))
4425 (goto-char (min start end
))
4426 (while (< (point) end1
)
4427 (or (looking-at "[_\^@- ]")
4428 (insert (char-after) "\b"))
4429 (forward-char 1)))))
4432 (defun unbold-region (start end
)
4433 "Remove all boldness (overstruck characters) in the region.
4434 Called from program, takes two arguments START and END
4435 which specify the range to operate on."
4438 (let ((end1 (make-marker)))
4439 (move-marker end1
(max start end
))
4440 (goto-char (min start end
))
4441 (while (re-search-forward "\b" end1 t
)
4442 (if (eq (char-after) (char-after (- (point) 2)))
4443 (delete-char -
2))))))
4445 (defalias 'message-exchange-point-and-mark
'exchange-point-and-mark
)
4447 ;; Support for toolbar
4448 (eval-when-compile (defvar tool-bar-map
))
4449 (if (featurep 'xemacs
)
4450 (require 'messagexmas
)
4451 (when (and (fboundp 'tool-bar-add-item-from-menu
)
4453 (defvar message-tool-bar-map
4454 (let ((tool-bar-map (copy-keymap tool-bar-map
)))
4455 ;; Zap some items which aren't so relevant and take up space.
4456 (dolist (key '(print-buffer kill-buffer save-buffer write-file
4458 (define-key tool-bar-map
(vector key
) nil
))
4460 (tool-bar-add-item-from-menu
4461 'message-send-and-exit
"mail_send" message-mode-map
)
4462 (tool-bar-add-item-from-menu
4463 'message-kill-buffer
"close" message-mode-map
)
4464 (tool-bar-add-item-from-menu
4465 'message-dont-send
"cancel" message-mode-map
)
4466 (tool-bar-add-item-from-menu
4467 'mml-attach-file
"attach" message-mode-map
)
4468 (tool-bar-add-item-from-menu
4469 'ispell-message
"spell" message-mode-map
)
4472 ;;; Group name completion.
4474 (defvar message-newgroups-header-regexp
4475 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4476 "Regexp that match headers that lists groups.")
4478 (defun message-tab ()
4479 "Expand group names in Newsgroups and Followup-To headers.
4480 Do a `tab-to-tab-stop' if not in those headers."
4482 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp
))
4483 (mail-abbrev-in-expansion-header-p))
4484 (message-expand-group)
4487 (defun message-expand-group ()
4488 "Expand the group name under point."
4489 (let* ((b (save-excursion
4494 (skip-chars-forward "^:")
4497 (skip-chars-backward "^, \t\n") (point))))
4498 (completion-ignore-case t
)
4499 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
4501 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
4502 (completions (all-completions string hashtb
))
4504 (delete-region b
(point))
4506 ((= (length completions
) 1)
4507 (if (string= (car completions
) string
)
4510 (message "Only matching group"))
4511 (insert (car completions
))))
4512 ((and (setq comp
(try-completion string hashtb
))
4513 (not (string= comp string
)))
4518 (message "No matching groups")
4519 (save-selected-window
4520 (pop-to-buffer "*Completions*")
4521 (buffer-disable-undo)
4522 (let ((buffer-read-only nil
))
4524 (let ((standard-output (current-buffer)))
4525 (display-completion-list (sort completions
'string
<)))
4526 (goto-char (point-min))
4527 (delete-region (point) (progn (forward-line 3) (point))))))))))
4531 (defun message-talkative-question (ask question show
&rest text
)
4532 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4533 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4534 The following arguments may contain lists of values."
4536 (setq text
(message-flatten-list text
)))
4537 (save-window-excursion
4539 (with-output-to-temp-buffer " *MESSAGE information message*"
4540 (set-buffer " *MESSAGE information message*")
4541 (fundamental-mode) ; for Emacs 20.4+
4542 (mapcar 'princ text
)
4543 (goto-char (point-min))))
4544 (funcall ask question
))
4545 (funcall ask question
)))
4547 (defun message-flatten-list (list)
4548 "Return a new, flat list that contains all elements of LIST.
4550 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4553 (apply 'append
(mapcar 'message-flatten-list list
)))
4557 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
4558 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
4559 Then clone the local variables and values from the old buffer to the
4560 new one, cloning only the locals having a substring matching the
4562 (let ((oldbuf (current-buffer)))
4564 (set-buffer (generate-new-buffer name
))
4565 (message-clone-locals oldbuf varstr
)
4568 (defun message-clone-locals (buffer &optional varstr
)
4569 "Clone the local variables from BUFFER to the current buffer."
4570 (let ((locals (save-excursion
4572 (buffer-local-variables)))
4573 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4576 (when (and (consp local
)
4578 (string-match regexp
(symbol-name (car local
)))
4580 (string-match varstr
(symbol-name (car local
)))))
4582 (set (make-local-variable (car local
))
4590 (defvar message-inhibit-body-encoding nil
)
4592 (defun message-encode-message-body ()
4593 (unless message-inhibit-body-encoding
4594 (let ((mail-parse-charset (or mail-parse-charset
4595 message-default-charset
))
4596 (case-fold-search t
)
4597 lines content-type-p
)
4600 (narrow-to-region (point) (point-max))
4601 (let ((new (mml-generate-mime)))
4603 (delete-region (point-min) (point-max))
4605 (goto-char (point-min))
4606 (if (eq (aref new
0) ?
\n)
4608 (search-forward "\n\n")
4609 (setq lines
(buffer-substring (point-min) (1- (point))))
4610 (delete-region (point-min) (point))))))
4612 (message-narrow-to-headers-or-head)
4613 (message-remove-header "Mime-Version")
4614 (goto-char (point-max))
4615 (insert "MIME-Version: 1.0\n")
4618 (setq content-type-p
4619 (re-search-backward "^Content-Type:" nil t
)))
4621 (message-narrow-to-headers-or-head)
4622 (message-remove-first-header "Content-Type")
4623 (message-remove-first-header "Content-Transfer-Encoding"))
4624 ;; We always make sure that the message has a Content-Type header.
4625 ;; This is because some broken MTAs and MUAs get awfully confused
4626 ;; when confronted with a message with a MIME-Version header and
4627 ;; without a Content-Type header. For instance, Solaris'
4629 (unless content-type-p
4630 (goto-char (point-min))
4631 (re-search-forward "^MIME-Version:")
4633 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4635 (defun message-read-from-minibuffer (prompt)
4636 "Read from the minibuffer while providing abbrev expansion."
4637 (if (fboundp 'mail-abbrevs-setup
)
4638 (let ((mail-abbrev-mode-regexp "")
4639 (minibuffer-setup-hook 'mail-abbrevs-setup
))
4640 (read-from-minibuffer prompt
))
4641 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
))
4642 (read-string prompt
))))
4644 (defun message-use-alternative-email-as-from ()
4645 (require 'mail-utils
)
4646 (let* ((fields '("To" "Cc"))
4649 (mail-strip-quoted-names
4650 (mapconcat 'message-fetch-reply-field fields
","))
4654 (if (string-match message-alternative-emails
(car emails
))
4655 (setq email
(car emails
)
4658 (unless (or (not email
) (equal email user-mail-address
))
4659 (goto-char (point-max))
4660 (insert "From: " email
"\n"))))
4664 (run-hooks 'message-load-hook
)
4667 ;; coding: iso-8859-1
4670 ;;; message.el ends here