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
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 message-id from
168 long-lines control-chars size new-text quoting-style
169 redirected-followup signature approved sender empty empty-headers
170 message-id from subject shorten-followup-to existing-newsgroups
171 buffer-file-name unchanged newsgroups."
173 :type
'(repeat sexp
))
175 (defcustom message-required-news-headers
176 '(From Newsgroups Subject Date Message-ID
177 (optional . Organization
) Lines
178 (optional . User-Agent
))
179 "*Headers to be generated or prompted for when posting an article.
180 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
181 Message-ID. Organization, Lines, In-Reply-To, Expires, and
182 User-Agent are optional. If don't you want message to insert some
183 header, remove it from this list."
185 :group
'message-headers
186 :type
'(repeat sexp
))
188 (defcustom message-required-mail-headers
189 '(From Subject Date
(optional . In-Reply-To
) Message-ID Lines
190 (optional . User-Agent
))
191 "*Headers to be generated or prompted for when mailing a message.
192 RFC822 required that From, Date, To, Subject and Message-ID be
193 included. Organization, Lines and User-Agent are optional."
195 :group
'message-headers
196 :type
'(repeat sexp
))
198 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
199 "Headers to be deleted if they already exist and were generated by message previously."
200 :group
'message-headers
203 (defcustom message-ignored-news-headers
204 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
205 "*Regexp of headers to be removed unconditionally before posting."
207 :group
'message-headers
210 (defcustom message-ignored-mail-headers
"^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
211 "*Regexp of headers to be removed unconditionally before mailing."
213 :group
'message-headers
216 (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:"
217 "*Header lines matching this regexp will be deleted before posting.
218 It's best to delete old Path and Date headers before posting to avoid
220 :group
'message-interface
223 (defcustom message-subject-re-regexp
"^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
224 "*Regexp matching \"Re: \" in the subject line."
225 :group
'message-various
229 (defcustom message-signature-separator
"^-- *$"
230 "Regexp matching the signature separator."
232 :group
'message-various
)
234 (defcustom message-elide-ellipsis
"\n[...]\n\n"
235 "*The string which is inserted for elided text."
237 :group
'message-various
)
239 (defcustom message-interactive nil
240 "Non-nil means when sending a message wait for and display errors.
241 nil means let mailer mail back a message to report errors."
242 :group
'message-sending
246 (defcustom message-generate-new-buffers
'unique
247 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
248 If this is a function, call that function with three parameters: The type,
249 the to address and the group name. (Any of these may be nil.) The function
250 should return the new buffer name."
251 :group
'message-buffers
252 :type
'(choice (const :tag
"off" nil
)
253 (const :tag
"unique" unique
)
254 (const :tag
"unsent" unsent
)
257 (defcustom message-kill-buffer-on-exit nil
258 "*Non-nil means that the message buffer will be killed after sending a message."
259 :group
'message-buffers
263 (defvar gnus-local-organization
))
264 (defcustom message-user-organization
265 (or (and (boundp 'gnus-local-organization
)
266 (stringp gnus-local-organization
)
267 gnus-local-organization
)
268 (getenv "ORGANIZATION")
270 "*String to be used as an Organization header.
271 If t, use `message-user-organization-file'."
272 :group
'message-headers
273 :type
'(choice string
274 (const :tag
"consult file" t
)))
277 (defcustom message-user-organization-file
"/usr/lib/news/organization"
278 "*Local news organization file."
280 :group
'message-headers
)
282 (defcustom message-make-forward-subject-function
283 'message-forward-subject-author-subject
284 "*A list of functions that are called to generate a subject header for forwarded messages.
285 The subject generated by the previous function is passed into each
288 The provided functions are:
290 * message-forward-subject-author-subject (Source of article (author or
291 newsgroup)), in brackets followed by the subject
292 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
294 :group
'message-forwarding
295 :type
'(radio (function-item message-forward-subject-author-subject
)
296 (function-item message-forward-subject-fwd
)))
298 (defcustom message-forward-as-mime t
299 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
301 :group
'message-forwarding
304 (defcustom message-forward-show-mml t
305 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
306 :group
'message-forwarding
309 (defcustom message-forward-before-signature t
310 "*If non-nil, put forwarded message before signature, else after."
311 :group
'message-forwarding
314 (defcustom message-wash-forwarded-subjects nil
315 "*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."
316 :group
'message-forwarding
319 (defcustom message-ignored-resent-headers
"^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
320 "*All headers that match this regexp will be deleted when resending a message."
321 :group
'message-interface
324 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
325 "*All headers that match this regexp will be deleted when forwarding a message."
327 :group
'message-forwarding
328 :type
'(choice (const :tag
"None" nil
)
331 (defcustom message-ignored-cited-headers
"."
332 "*Delete these headers from the messages you yank."
333 :group
'message-insertion
336 (defcustom message-cancel-message
"I am canceling my own article.\n"
337 "Message to be inserted in the cancel message."
338 :group
'message-interface
341 ;; Useful to set in site-init.el
343 (defcustom message-send-mail-function
'message-send-mail-with-sendmail
344 "Function to call to send the current buffer as mail.
345 The headers should be delimited by a line whose contents match the
346 variable `mail-header-separator'.
348 Valid values include `message-send-mail-with-sendmail' (the default),
349 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
351 :type
'(radio (function-item message-send-mail-with-sendmail
)
352 (function-item message-send-mail-with-mh
)
353 (function-item message-send-mail-with-qmail
)
354 (function-item smtpmail-send-it
)
355 (function :tag
"Other"))
356 :group
'message-sending
357 :group
'message-mail
)
359 (defcustom message-send-news-function
'message-send-news
360 "Function to call to send the current buffer as news.
361 The headers should be delimited by a line whose contents match the
362 variable `mail-header-separator'."
363 :group
'message-sending
367 (defcustom message-reply-to-function nil
368 "Function that should return a list of headers.
369 This function should pick out addresses from the To, Cc, and From headers
370 and respond with new To and Cc headers."
371 :group
'message-interface
374 (defcustom message-wide-reply-to-function nil
375 "Function that should return a list of headers.
376 This function should pick out addresses from the To, Cc, and From headers
377 and respond with new To and Cc headers."
378 :group
'message-interface
381 (defcustom message-followup-to-function nil
382 "Function that should return a list of headers.
383 This function should pick out addresses from the To, Cc, and From headers
384 and respond with new To and Cc headers."
385 :group
'message-interface
388 (defcustom message-use-followup-to
'ask
389 "*Specifies what to do with Followup-To header.
390 If nil, always ignore the header. If it is t, use its value, but
391 query before using the \"poster\" value. If it is the symbol `ask',
392 always query the user whether to use the value. If it is the symbol
393 `use', always use the value."
394 :group
'message-interface
395 :type
'(choice (const :tag
"ignore" nil
)
399 (defcustom message-sendmail-f-is-evil nil
400 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
401 Doing so would be even more evil than leaving it out."
402 :group
'message-sending
405 ;; qmail-related stuff
406 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
407 "Location of the qmail-inject program."
408 :group
'message-sending
411 (defcustom message-qmail-inject-args nil
412 "Arguments passed to qmail-inject programs.
413 This should be a list of strings, one string for each argument.
415 For e.g., if you wish to set the envelope sender address so that bounces
416 go to the right place or to deal with listserv's usage of that address, you
417 might set this variable to '(\"-f\" \"you@some.where\")."
418 :group
'message-sending
419 :type
'(repeat string
))
421 (defvar message-cater-to-broken-inn t
422 "Non-nil means Gnus should not fold the `References' header.
423 Folding `References' makes ancient versions of INN create incorrect
427 (defvar gnus-post-method
)
428 (defvar gnus-select-method
))
429 (defcustom message-post-method
430 (cond ((and (boundp 'gnus-post-method
)
431 (listp gnus-post-method
)
434 ((boundp 'gnus-select-method
)
437 "*Method used to post news.
438 Note that when posting from inside Gnus, for instance, this
439 variable isn't used."
441 :group
'message-sending
442 ;; This should be the `gnus-select-method' widget, but that might
443 ;; create a dependence to `gnus.el'.
446 (defcustom message-generate-headers-first nil
447 "*If non-nil, generate all possible headers before composing."
448 :group
'message-headers
451 (defcustom message-setup-hook nil
452 "Normal hook, run each time a new outgoing message is initialized.
453 The function `message-setup' runs this hook."
454 :group
'message-various
457 (defcustom message-cancel-hook nil
458 "Hook run when cancelling articles."
459 :group
'message-various
462 (defcustom message-signature-setup-hook nil
463 "Normal hook, run each time a new outgoing message is initialized.
464 It is run after the headers have been inserted and before
465 the signature is inserted."
466 :group
'message-various
469 (defcustom message-mode-hook nil
470 "Hook run in message mode buffers."
471 :group
'message-various
474 (defcustom message-header-hook nil
475 "Hook run in a message mode buffer narrowed to the headers."
476 :group
'message-various
479 (defcustom message-header-setup-hook nil
480 "Hook called narrowed to the headers when setting up a message buffer."
481 :group
'message-various
485 (defcustom message-citation-line-function
'message-insert-citation-line
486 "*Function called to insert the \"Whomever writes:\" line."
488 :group
'message-insertion
)
491 (defcustom message-yank-prefix
"> "
492 "*Prefix inserted on the lines of yanked messages."
494 :group
'message-insertion
)
496 (defcustom message-indentation-spaces
3
497 "*Number of spaces to insert at the beginning of each cited line.
498 Used by `message-yank-original' via `message-yank-cite'."
499 :group
'message-insertion
503 (defcustom message-cite-function
'message-cite-original
504 "*Function for citing an original message.
505 Predefined functions include `message-cite-original' and
506 `message-cite-original-without-signature'.
507 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
508 :type
'(radio (function-item message-cite-original
)
509 (function-item message-cite-original-without-signature
)
510 (function-item sc-cite-original
)
511 (function :tag
"Other"))
512 :group
'message-insertion
)
515 (defcustom message-indent-citation-function
'message-indent-citation
516 "*Function for modifying a citation just inserted in the mail buffer.
517 This can also be a list of functions. Each function can find the
518 citation between (point) and (mark t). And each function should leave
519 point and mark around the citation text as modified."
521 :group
'message-insertion
)
523 (defvar message-abbrevs-loaded nil
)
526 (defcustom message-signature t
527 "*String to be inserted at the end of the message buffer.
528 If t, the `message-signature-file' file will be inserted instead.
529 If a function, the result from the function will be used instead.
530 If a form, the result from the form will be used instead."
532 :group
'message-insertion
)
535 (defcustom message-signature-file
"~/.signature"
536 "*File containing the text inserted at end of message buffer."
538 :group
'message-insertion
)
540 (defcustom message-distribution-function nil
541 "*Function called to return a Distribution header."
543 :group
'message-headers
546 (defcustom message-expires
14
547 "Number of days before your article expires."
549 :group
'message-headers
550 :link
'(custom-manual "(message)News Headers")
553 (defcustom message-user-path nil
554 "If nil, use the NNTP server name in the Path header.
555 If stringp, use this; if non-nil, use no host name (user name only)."
557 :group
'message-headers
558 :link
'(custom-manual "(message)News Headers")
559 :type
'(choice (const :tag
"nntp" nil
)
561 (sexp :tag
"none" :format
"%t" t
)))
563 (defvar message-reply-buffer nil
)
564 (defvar message-reply-headers nil
)
565 (defvar message-newsreader nil
)
566 (defvar message-mailer nil
)
567 (defvar message-sent-message-via nil
)
568 (defvar message-checksum nil
)
569 (defvar message-send-actions nil
570 "A list of actions to be performed upon successful sending of a message.")
571 (defvar message-exit-actions nil
572 "A list of actions to be performed upon exiting after sending a message.")
573 (defvar message-kill-actions nil
574 "A list of actions to be performed before killing a message buffer.")
575 (defvar message-postpone-actions nil
576 "A list of actions to be performed after postponing a message.")
578 (define-widget 'message-header-lines
'text
579 "All header lines must be LFD terminated."
582 :error
"All header lines must be newline terminated")
584 (defcustom message-default-headers
""
585 "*A string containing header lines to be inserted in outgoing messages.
586 It is inserted before you edit the message, so you can edit or delete
588 :group
'message-headers
589 :type
'message-header-lines
)
591 (defcustom message-default-mail-headers
""
592 "*A string of header lines to be inserted in outgoing mails."
593 :group
'message-headers
595 :type
'message-header-lines
)
597 (defcustom message-default-news-headers
""
598 "*A string of header lines to be inserted in outgoing news articles."
599 :group
'message-headers
601 :type
'message-header-lines
)
603 ;; Note: could use /usr/ucb/mail instead of sendmail;
604 ;; options -t, and -v if not interactive.
605 (defcustom message-mailer-swallows-blank-line
606 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
607 system-configuration
)
608 (file-readable-p "/etc/sendmail.cf")
609 (let ((buffer (get-buffer-create " *temp*")))
613 (insert-file-contents "/etc/sendmail.cf")
614 (goto-char (point-min))
615 (let ((case-fold-search nil
))
616 (re-search-forward "^OR\\>" nil t
)))
617 (kill-buffer buffer
))))
618 ;; According to RFC822, "The field-name must be composed of printable
619 ;; ASCII characters (i. e., characters that have decimal values between
620 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
622 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
623 "*Set this non-nil if the system's mailer runs the header and body together.
624 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
625 The value should be an expression to test whether the problem will
627 :group
'message-sending
631 (define-mail-user-agent 'message-user-agent
632 'message-mail
'message-send-and-exit
633 'message-kill-buffer
'message-send-hook
)
635 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
636 "If non-nil, delete the deletable headers before feeding to mh.")
638 (defvar message-send-method-alist
639 '((news message-news-p message-send-via-news
)
640 (mail message-mail-p message-send-via-mail
))
641 "Alist of ways to send outgoing messages.
642 Each element has the form
644 \(TYPE PREDICATE FUNCTION)
646 where TYPE is a symbol that names the method; PREDICATE is a function
647 called without any parameters to determine whether the message is
648 a message of type TYPE; and FUNCTION is a function to be called if
649 PREDICATE returns non-nil. FUNCTION is called with one parameter --
652 (defvar message-mail-alias-type
'abbrev
653 "*What alias expansion type to use in Message buffers.
654 The default is `abbrev', which uses mailabbrev. nil switches
657 (defcustom message-auto-save-directory
658 (nnheader-concat message-directory
"drafts/")
659 "*Directory where Message auto-saves buffers if Gnus isn't running.
660 If nil, Message won't auto-save."
661 :group
'message-buffers
664 (defcustom message-buffer-naming-style
'unique
665 "*The way new message buffers are named.
666 Valid valued are `unique' and `unsent'."
668 :group
'message-buffers
669 :type
'(choice (const :tag
"unique" unique
)
670 (const :tag
"unsent" unsent
)))
672 (defcustom message-default-charset
673 (and (not (mm-multibyte-p)) 'iso-8859-1
)
674 "Default charset used in non-MULE Emacsen.
675 If nil, you might be asked to input the charset."
680 (defcustom message-dont-reply-to-names
681 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
682 "*A regexp specifying names to prune when doing wide replies.
683 A value of nil means exclude your own name only."
686 :type
'(choice (const :tag
"Yourself" nil
)
689 ;;; Internal variables.
690 ;;; Well, not really internal.
692 (defvar message-mode-syntax-table
693 (let ((table (copy-syntax-table text-mode-syntax-table
)))
694 (modify-syntax-entry ?%
". " table
)
695 (modify-syntax-entry ?
> ". " table
)
696 (modify-syntax-entry ?
< ". " table
)
698 "Syntax table used while in Message mode.")
700 (defvar message-mode-abbrev-table text-mode-abbrev-table
701 "Abbrev table used in Message mode buffers.
702 Defaults to `text-mode-abbrev-table'.")
703 (defgroup message-headers nil
705 :link
'(custom-manual "(message)Variables")
708 (defface message-header-to-face
711 (:foreground
"green2" :bold t
))
714 (:foreground
"MidnightBlue" :bold t
))
716 (:bold t
:italic t
)))
717 "Face used for displaying From headers."
718 :group
'message-faces
)
720 (defface message-header-cc-face
723 (:foreground
"green4" :bold t
))
726 (:foreground
"MidnightBlue"))
729 "Face used for displaying Cc headers."
730 :group
'message-faces
)
732 (defface message-header-subject-face
735 (:foreground
"green3"))
738 (:foreground
"navy blue" :bold t
))
741 "Face used for displaying subject headers."
742 :group
'message-faces
)
744 (defface message-header-newsgroups-face
747 (:foreground
"yellow" :bold t
:italic t
))
750 (:foreground
"blue4" :bold t
:italic t
))
752 (:bold t
:italic t
)))
753 "Face used for displaying newsgroups headers."
754 :group
'message-faces
)
756 (defface message-header-other-face
759 (:foreground
"#b00000"))
762 (:foreground
"steel blue"))
764 (:bold t
:italic t
)))
765 "Face used for displaying newsgroups headers."
766 :group
'message-faces
)
768 (defface message-header-name-face
771 (:foreground
"DarkGreen"))
774 (:foreground
"cornflower blue"))
777 "Face used for displaying header names."
778 :group
'message-faces
)
780 (defface message-header-xheader-face
783 (:foreground
"blue"))
786 (:foreground
"blue"))
789 "Face used for displaying X-Header headers."
790 :group
'message-faces
)
792 (defface message-separator-face
795 (:foreground
"blue3"))
798 (:foreground
"brown"))
801 "Face used for displaying the separator."
802 :group
'message-faces
)
804 (defface message-cited-text-face
813 "Face used for displaying cited text names."
814 :group
'message-faces
)
816 (defface message-mml-face
819 (:foreground
"ForestGreen"))
822 (:foreground
"ForestGreen"))
825 "Face used for displaying MML."
826 :group
'message-faces
)
828 (defvar message-font-lock-keywords
829 (let* ((cite-prefix "[:alpha:]")
830 (cite-suffix (concat cite-prefix
"0-9_.@-"))
831 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
832 `((,(concat "^\\([Tt]o:\\)" content
)
833 (1 'message-header-name-face
)
834 (2 'message-header-to-face nil t
))
835 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
)
836 (1 'message-header-name-face
)
837 (2 'message-header-cc-face nil t
))
838 (,(concat "^\\([Ss]ubject:\\)" content
)
839 (1 'message-header-name-face
)
840 (2 'message-header-subject-face nil t
))
841 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
)
842 (1 'message-header-name-face
)
843 (2 'message-header-newsgroups-face nil t
))
844 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content
)
845 (1 'message-header-name-face
)
846 (2 'message-header-other-face nil t
))
847 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content
)
848 (1 'message-header-name-face
)
849 (2 'message-header-name-face
))
850 ,@(if (and mail-header-separator
851 (not (equal mail-header-separator
"")))
852 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
853 1 'message-separator-face
))
856 "\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
858 (0 'message-cited-text-face
))
859 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
860 (0 'message-mml-face
))))
861 "Additional expressions to highlight in Message mode.")
863 ;; XEmacs does it like this. For Emacs, we have to set the
864 ;; `font-lock-defaults' buffer-local variable.
865 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
867 (defvar message-face-alist
868 '((bold . bold-region
)
869 (underline . underline-region
)
870 (default .
(lambda (b e
)
872 (ununderline-region b e
))))
873 "Alist of mail and news faces for facemenu.
874 The cdr of ech entry is a function for applying the face to a region.")
876 (defcustom message-send-hook nil
877 "Hook run before sending messages."
878 :group
'message-various
879 :options
'(ispell-message)
882 (defcustom message-send-mail-hook nil
883 "Hook run before sending mail messages."
884 :group
'message-various
887 (defcustom message-send-news-hook nil
888 "Hook run before sending news messages."
889 :group
'message-various
892 (defcustom message-sent-hook nil
893 "Hook run after sending messages."
894 :group
'message-various
897 (defvar message-send-coding-system
'binary
898 "Coding system to encode outgoing mail.")
900 (defvar message-draft-coding-system
901 mm-auto-save-coding-system
902 "Coding system to compose mail.")
904 (defcustom message-send-mail-partially-limit
1000000
905 "The limitation of messages sent as message/partial.
906 The lower bound of message size in characters, beyond which the message
907 should be sent in several parts. If it is nil, the size is unlimited."
909 :group
'message-buffers
910 :type
'(choice (const :tag
"unlimited" nil
)
913 (defcustom message-alternative-emails nil
914 "A regexp to match the alternative email addresses.
915 The first matched address (not primary one) is used in the From field."
916 :group
'message-headers
917 :type
'(choice (const :tag
"Always use primary" nil
)
920 ;;; Internal variables.
922 (defvar message-sending-message
"Sending...")
923 (defvar message-buffer-list nil
)
924 (defvar message-this-is-news nil
)
925 (defvar message-this-is-mail nil
)
926 (defvar message-draft-article nil
)
927 (defvar message-mime-part nil
)
928 (defvar message-posting-charset nil
)
930 ;; Byte-compiler warning
932 (defvar gnus-active-hashtb
)
933 (defvar gnus-read-active-file
))
935 ;;; Regexp matching the delimiter of messages in UNIX mail format
936 ;;; (UNIX From lines), minus the initial ^. It should be a copy
937 ;;; of rmail.el's rmail-unix-mail-delimiter.
938 (defvar message-unix-mail-delimiter
939 (let ((time-zone-regexp
940 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
941 "\\|[-+]?[0-9][0-9][0-9][0-9]"
947 ;; Many things can happen to an RFC 822 mailbox before it is put into
948 ;; a `From' line. The leading phrase can be stripped, e.g.
949 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
950 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
951 ;; can be removed, e.g.
952 ;; From: joe@y.z (Joe K
954 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
957 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
958 ;; The mailbox can be removed or be replaced by white space, e.g.
959 ;; From: "Joe User"{space}{tab}
961 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
962 ;; where {space} and {tab} represent the Ascii space and tab characters.
963 ;; We want to match the results of any of these manglings.
964 ;; The following regexp rejects names whose first characters are
965 ;; obviously bogus, but after that anything goes.
966 "\\([^\0-\b\n-\r\^?].*\\)? "
968 ;; The time the message was sent.
969 "\\([^\0-\r \^?]+\\) +" ; day of the week
970 "\\([^\0-\r \^?]+\\) +" ; month
971 "\\([0-3]?[0-9]\\) +" ; day of month
972 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
974 ;; Perhaps a time zone, specified by an abbreviation, or by a
979 " \\([0-9][0-9]+\\) *"
981 ;; On some systems the time zone can appear after the year, too.
985 "\\(remote from .*\\)?"
988 "Regexp matching the delimiter of messages in UNIX mail format.")
990 (defvar message-unsent-separator
991 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
992 "^ *---+ +Returned message +---+ *$\\|"
993 "^Start of returned message$\\|"
994 "^ *---+ +Original message +---+ *$\\|"
995 "^ *--+ +begin message +--+ *$\\|"
996 "^ *---+ +Original message follows +---+ *$\\|"
997 "^ *---+ +Undelivered message follows +---+ *$\\|"
998 "^|? *---+ +Message text follows: +---+ *|?$")
999 "A regexp that matches the separator before the text of a failed message.")
1001 (defvar message-header-format-alist
1003 (To . message-fill-address
)
1004 (Cc . message-fill-address
)
1015 (References . message-shorten-references
)
1017 "Alist used for formatting headers.")
1020 (autoload 'message-setup-toolbar
"messagexmas")
1021 (autoload 'mh-new-draft-name
"mh-comp")
1022 (autoload 'mh-send-letter
"mh-comp")
1023 (autoload 'gnus-point-at-eol
"gnus-util")
1024 (autoload 'gnus-point-at-bol
"gnus-util")
1025 (autoload 'gnus-output-to-rmail
"gnus-util")
1026 (autoload 'gnus-output-to-mail
"gnus-util")
1027 (autoload 'mail-abbrev-in-expansion-header-p
"mailabbrev")
1028 (autoload 'nndraft-request-associate-buffer
"nndraft")
1029 (autoload 'nndraft-request-expire-articles
"nndraft")
1030 (autoload 'gnus-open-server
"gnus-int")
1031 (autoload 'gnus-request-post
"gnus-int")
1032 (autoload 'gnus-alive-p
"gnus-util")
1033 (autoload 'gnus-group-name-charset
"gnus-group")
1034 (autoload 'rmail-output
"rmail"))
1039 ;;; Utility functions.
1042 (defmacro message-y-or-n-p
(question show
&rest text
)
1043 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1044 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1046 ;; Delete the current line (and the next N lines.);
1047 (defmacro message-delete-line
(&optional n
)
1048 `(delete-region (progn (beginning-of-line) (point))
1049 (progn (forward-line ,(or n
1)) (point))))
1051 (defun message-unquote-tokens (elems)
1052 "Remove double quotes (\") from strings in list."
1053 (mapcar (lambda (item)
1054 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1055 (setq item
(concat (match-string 1 item
)
1056 (match-string 2 item
))))
1060 (defun message-tokenize-header (header &optional separator
)
1061 "Split HEADER into a list of header elements.
1062 SEPARATOR is a string of characters to be used as separators. \",\"
1063 is used by default."
1066 (let ((regexp (format "[%s]+" (or separator
",")))
1071 (message-set-work-buffer)
1073 (goto-char (point-min))
1078 (cond ((and (> (point) beg
)
1080 (and (looking-at regexp
)
1083 (push (buffer-substring beg
(point)) elems
)
1084 (setq beg
(match-end 0)))
1085 ((eq (char-after) ?
\")
1086 (setq quoted
(not quoted
)))
1087 ((and (eq (char-after) ?\
()
1090 ((and (eq (char-after) ?\
))
1093 (nreverse elems
)))))
1095 (defun message-mail-file-mbox-p (file)
1096 "Say whether FILE looks like a Unix mbox file."
1097 (when (and (file-exists-p file
)
1098 (file-readable-p file
)
1099 (file-regular-p file
))
1101 (nnheader-insert-file-contents file
)
1102 (goto-char (point-min))
1103 (looking-at message-unix-mail-delimiter
))))
1105 (defun message-fetch-field (header &optional not-all
)
1106 "The same as `mail-fetch-field', only remove all newlines."
1107 (let* ((inhibit-point-motion-hooks t
)
1108 (case-fold-search t
)
1109 (value (mail-fetch-field header nil
(not not-all
))))
1111 (while (string-match "\n[\t ]+" value
)
1112 (setq value
(replace-match " " t t value
)))
1113 (set-text-properties 0 (length value
) nil value
)
1116 (defun message-narrow-to-field ()
1117 "Narrow the buffer to the header on the current line."
1123 (if (re-search-forward "^[^ \n\t]" nil t
)
1128 (goto-char (point-min)))
1130 (defun message-add-header (&rest headers
)
1131 "Add the HEADERS to the message header, skipping those already present."
1134 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1135 (error "Invalid header `%s'" (car headers
)))
1136 (setq hclean
(match-string 1 (car headers
)))
1138 (message-narrow-to-headers)
1139 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1140 (insert (car headers
) ?
\n))))
1141 (setq headers
(cdr headers
))))
1144 (defun message-fetch-reply-field (header)
1145 "Fetch FIELD from the message we're replying to."
1146 (when (and message-reply-buffer
1147 (buffer-name message-reply-buffer
))
1149 (set-buffer message-reply-buffer
)
1150 (message-fetch-field header
))))
1152 (defun message-set-work-buffer ()
1153 (if (get-buffer " *message work*")
1155 (set-buffer " *message work*")
1157 (set-buffer (get-buffer-create " *message work*"))
1158 (kill-all-local-variables)
1159 (mm-enable-multibyte)))
1161 (defun message-functionp (form)
1162 "Return non-nil if FORM is funcallable."
1163 (or (and (symbolp form
) (fboundp form
))
1164 (and (listp form
) (eq (car form
) 'lambda
))
1165 (byte-code-function-p form
)))
1167 (defun message-strip-list-identifiers (subject)
1168 "Remove list identifiers in `gnus-list-identifiers'."
1169 (require 'gnus-sum
) ; for gnus-list-identifiers
1170 (let ((regexp (if (stringp gnus-list-identifiers
)
1171 gnus-list-identifiers
1172 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
1173 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1174 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
1175 (concat (substring subject
0 (match-beginning 1))
1176 (or (match-string 3 subject
)
1177 (match-string 5 subject
))
1182 (defun message-strip-subject-re (subject)
1183 "Remove \"Re:\" from subject lines."
1184 (if (string-match message-subject-re-regexp subject
)
1185 (substring subject
(match-end 0))
1188 (defun message-remove-header (header &optional is-regexp first reverse
)
1189 "Remove HEADER in the narrowed buffer.
1190 If REGEXP, HEADER is a regular expression.
1191 If FIRST, only remove the first instance of the header.
1192 Return the number of headers removed."
1193 (goto-char (point-min))
1194 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
1196 (case-fold-search t
)
1198 (while (and (not (eobp))
1201 (not (looking-at regexp
))
1202 (looking-at regexp
))
1209 ;; There might be a continuation header, so we have to search
1210 ;; until we find a new non-continuation line.
1213 (if (re-search-forward "^[^ \t]" nil t
)
1214 (goto-char (match-beginning 0))
1217 (if (re-search-forward "^[^ \t]" nil t
)
1218 (goto-char (match-beginning 0))
1219 (goto-char (point-max)))))
1222 (defun message-remove-first-header (header)
1223 "Remove the first instance of HEADER if there is more than one."
1225 (regexp (concat "^" (regexp-quote header
) ":")))
1227 (goto-char (point-min))
1228 (while (re-search-forward regexp nil t
)
1231 (message-remove-header header nil t
)
1234 (defun message-narrow-to-headers ()
1235 "Narrow the buffer to the head of the message."
1238 (goto-char (point-min))
1239 (if (re-search-forward
1240 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
1243 (goto-char (point-min)))
1245 (defun message-narrow-to-head ()
1246 "Narrow the buffer to the head of the message.
1247 Point is left at the beginning of the narrowed-to region."
1250 (goto-char (point-min))
1251 (if (search-forward "\n\n" nil
1)
1254 (goto-char (point-min)))
1256 (defun message-narrow-to-headers-or-head ()
1257 "Narrow the buffer to the head of the message."
1260 (goto-char (point-min))
1263 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
1264 (match-beginning 0))
1265 ((search-forward "\n\n" nil t
)
1269 (goto-char (point-min)))
1271 (defun message-news-p ()
1272 "Say whether the current buffer contains a news message."
1273 (and (not message-this-is-mail
)
1274 (or message-this-is-news
1277 (message-narrow-to-headers)
1278 (and (message-fetch-field "newsgroups")
1279 (not (message-fetch-field "posted-to"))))))))
1281 (defun message-mail-p ()
1282 "Say whether the current buffer contains a mail message."
1283 (and (not message-this-is-news
)
1284 (or message-this-is-mail
1287 (message-narrow-to-headers)
1288 (or (message-fetch-field "to")
1289 (message-fetch-field "cc")
1290 (message-fetch-field "bcc")))))))
1292 (defun message-next-header ()
1293 "Go to the beginning of the next header."
1295 (or (eobp) (forward-char 1))
1296 (not (if (re-search-forward "^[^ \t]" nil t
)
1298 (goto-char (point-max)))))
1300 (defun message-sort-headers-1 ()
1301 "Sort the buffer as headers using `message-rank' text props."
1302 (goto-char (point-min))
1305 nil
'message-next-header
1307 (message-next-header)
1311 (or (get-text-property (point) 'message-rank
)
1314 (defun message-sort-headers ()
1315 "Sort the headers of the current message according to `message-header-format-alist'."
1319 (let ((max (1+ (length message-header-format-alist
)))
1321 (message-narrow-to-headers)
1322 (while (re-search-forward "^[^ \n]+:" nil t
)
1324 (match-beginning 0) (1+ (match-beginning 0))
1326 (if (setq rank
(length (memq (assq (intern (buffer-substring
1328 (1- (match-end 0))))
1329 message-header-format-alist
)
1330 message-header-format-alist
)))
1333 (message-sort-headers-1))))
1343 (defvar message-mode-map nil
)
1345 (unless message-mode-map
1346 (setq message-mode-map
(make-keymap))
1347 (set-keymap-parent message-mode-map text-mode-map
)
1348 (define-key message-mode-map
"\C-c?" 'describe-mode
)
1350 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
1351 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
1352 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
1353 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
1354 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
1355 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
1356 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
1357 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
1358 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
1359 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
1360 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
1361 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
1362 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
1364 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
1365 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
1367 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
1368 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
1369 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
1370 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
1371 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
1372 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
1373 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
1374 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
1376 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
1377 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
1378 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
1379 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
1381 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
1382 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
1383 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
1384 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
1386 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
1388 (define-key message-mode-map
"\t" 'message-tab
))
1391 message-mode-menu message-mode-map
"Message Menu."
1393 ["Sort Headers" message-sort-headers t
]
1394 ["Yank Original" message-yank-original t
]
1395 ["Fill Yanked Message" message-fill-yanked-message t
]
1396 ["Insert Signature" message-insert-signature t
]
1397 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
1398 ["Caesar (rot13) Region" message-caesar-region
(mark t
)]
1399 ["Elide Region" message-elide-region
(mark t
)]
1400 ["Delete Outside Region" message-delete-not-region
(mark t
)]
1401 ["Kill To Signature" message-kill-to-signature t
]
1402 ["Newline and Reformat" message-newline-and-reformat t
]
1403 ["Rename buffer" message-rename-buffer t
]
1404 ["Spellcheck" ispell-message
1405 :help
"Spellcheck this message"]
1406 ["Attach file as MIME" mml-attach-file
1407 :help
"Attach a file at point"]
1409 ["Send Message" message-send-and-exit
1410 :help
"Send this message"]
1411 ["Abort Message" message-dont-send
1412 :help
"File this draft message and exit"]
1413 ["Kill Message" message-kill-buffer
1414 :help
"Delete this message without sending"]))
1417 message-mode-field-menu message-mode-map
""
1419 ["Fetch To" message-insert-to t
]
1420 ["Fetch Newsgroups" message-insert-newsgroups t
]
1422 ["To" message-goto-to t
]
1423 ["Subject" message-goto-subject t
]
1424 ["Cc" message-goto-cc t
]
1425 ["Reply-To" message-goto-reply-to t
]
1426 ["Summary" message-goto-summary t
]
1427 ["Keywords" message-goto-keywords t
]
1428 ["Newsgroups" message-goto-newsgroups t
]
1429 ["Followup-To" message-goto-followup-to t
]
1430 ["Distribution" message-goto-distribution t
]
1431 ["Body" message-goto-body t
]
1432 ["Signature" message-goto-signature t
]))
1435 (defvar facemenu-add-face-function
)
1436 (defvar facemenu-remove-face-function
))
1439 (defun message-mode ()
1440 "Major mode for editing mail and news to be sent.
1441 Like Text Mode but with these additional commands:
1442 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1443 C-c C-d Pospone sending the message C-c C-k Kill the message
1444 C-c C-f move to a header field (and create it if there isn't):
1445 C-c C-f C-t move to To C-c C-f C-s move to Subject
1446 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1447 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1448 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1449 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1450 C-c C-f C-f move to Followup-To
1451 C-c C-t message-insert-to (add a To header to a news followup)
1452 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1453 C-c C-b message-goto-body (move to beginning of message text).
1454 C-c C-i message-goto-signature (move to the beginning of the signature).
1455 C-c C-w message-insert-signature (insert `message-signature-file' file).
1456 C-c C-y message-yank-original (insert current message, if any).
1457 C-c C-q message-fill-yanked-message (fill what was yanked).
1458 C-c C-e message-elide-region (elide the text between point and mark).
1459 C-c C-v message-delete-not-region (remove the text outside the region).
1460 C-c C-z message-kill-to-signature (kill the text up to the signature).
1461 C-c C-r message-caesar-buffer-body (rot13 the message body).
1462 C-c C-a mml-attach-file (attach a file as MIME).
1463 M-RET message-newline-and-reformat (break the line and reformat)."
1465 (if (local-variable-p 'mml-buffer-list
(current-buffer))
1466 (mml-destroy-buffers))
1467 (kill-all-local-variables)
1468 (set (make-local-variable 'message-reply-buffer
) nil
)
1469 (make-local-variable 'message-send-actions
)
1470 (make-local-variable 'message-exit-actions
)
1471 (make-local-variable 'message-kill-actions
)
1472 (make-local-variable 'message-postpone-actions
)
1473 (make-local-variable 'message-draft-article
)
1474 (make-local-hook 'kill-buffer-hook
)
1475 (set-syntax-table message-mode-syntax-table
)
1476 (use-local-map message-mode-map
)
1477 (setq local-abbrev-table message-mode-abbrev-table
)
1478 (setq major-mode
'message-mode
)
1479 (setq mode-name
"Message")
1480 (setq buffer-offer-save t
)
1481 (make-local-variable 'facemenu-add-face-function
)
1482 (make-local-variable 'facemenu-remove-face-function
)
1483 (setq facemenu-add-face-function
1485 (let ((face-fun (cdr (assq face message-face-alist
))))
1487 (funcall face-fun
(point) end
)
1488 (error "Face %s not configured for %s mode" face mode-name
)))
1490 facemenu-remove-face-function t
)
1491 (make-local-variable 'message-reply-headers
)
1492 (setq message-reply-headers nil
)
1493 (make-local-variable 'message-newsreader
)
1494 (make-local-variable 'message-mailer
)
1495 (make-local-variable 'message-post-method
)
1496 (set (make-local-variable 'message-sent-message-via
) nil
)
1497 (set (make-local-variable 'message-checksum
) nil
)
1498 (set (make-local-variable 'message-mime-part
) 0)
1499 (message-setup-fill-variables)
1500 ;;(when (fboundp 'mail-hist-define-keys)
1501 ;; (mail-hist-define-keys))
1502 (if (featurep 'xemacs
)
1503 (message-setup-toolbar)
1504 (set (make-local-variable 'font-lock-defaults
)
1505 '(message-font-lock-keywords t
))
1506 (if (boundp 'message-tool-bar-map
)
1507 (set (make-local-variable 'tool-bar-map
) message-tool-bar-map
)))
1508 (easy-menu-add message-mode-menu message-mode-map
)
1509 (easy-menu-add message-mode-field-menu message-mode-map
)
1510 ;; Allow mail alias things.
1511 (when (eq message-mail-alias-type
'abbrev
)
1512 (if (fboundp 'mail-abbrevs-setup
)
1513 (mail-abbrevs-setup)
1514 (mail-aliases-setup)))
1515 (message-set-auto-save-file-name)
1516 (mm-enable-multibyte)
1517 (make-local-variable 'indent-tabs-mode
) ;Turn off tabs for indentation.
1518 (setq indent-tabs-mode nil
)
1520 (run-hooks 'text-mode-hook
'message-mode-hook
))
1522 (defun message-setup-fill-variables ()
1523 "Setup message fill variables."
1524 (make-local-variable 'paragraph-separate
)
1525 (make-local-variable 'paragraph-start
)
1526 (make-local-variable 'adaptive-fill-regexp
)
1527 (unless (boundp 'adaptive-fill-first-line-regexp
)
1528 (setq adaptive-fill-first-line-regexp nil
))
1529 (make-local-variable 'adaptive-fill-first-line-regexp
)
1530 (make-local-variable 'auto-fill-inhibit-regexp
)
1531 (let ((quote-prefix-regexp
1533 "[ \t]*" ; possible initial space
1534 "\\(\\(" (regexp-quote message-yank-prefix
) "\\|" ; user's prefix
1535 "\\w+>\\|" ; supercite-style prefix
1536 "[|:>]" ; standard prefix
1537 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1538 (setq paragraph-start
1540 (regexp-quote mail-header-separator
) "$\\|"
1541 "[ \t]*$\\|" ; blank lines
1542 "-- $\\|" ; signature delimiter
1543 "---+$\\|" ; delimiters for forwarded messages
1544 page-delimiter
"$\\|" ; spoiler warnings
1545 ".*wrote:$\\|" ; attribution lines
1546 quote-prefix-regexp
"$")) ; empty lines in quoted text
1547 (setq paragraph-separate paragraph-start
)
1548 (setq adaptive-fill-regexp
1549 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
1550 (setq adaptive-fill-first-line-regexp
1551 (concat quote-prefix-regexp
"\\|"
1552 adaptive-fill-first-line-regexp
))
1553 (setq auto-fill-inhibit-regexp
"^[A-Z][^: \n\t]+:")))
1558 ;;; Message mode commands
1561 ;;; Movement commands
1563 (defun message-goto-to ()
1564 "Move point to the To header."
1566 (message-position-on-field "To"))
1568 (defun message-goto-subject ()
1569 "Move point to the Subject header."
1571 (message-position-on-field "Subject"))
1573 (defun message-goto-cc ()
1574 "Move point to the Cc header."
1576 (message-position-on-field "Cc" "To"))
1578 (defun message-goto-bcc ()
1579 "Move point to the Bcc header."
1581 (message-position-on-field "Bcc" "Cc" "To"))
1583 (defun message-goto-fcc ()
1584 "Move point to the Fcc header."
1586 (message-position-on-field "Fcc" "To" "Newsgroups"))
1588 (defun message-goto-reply-to ()
1589 "Move point to the Reply-To header."
1591 (message-position-on-field "Reply-To" "Subject"))
1593 (defun message-goto-newsgroups ()
1594 "Move point to the Newsgroups header."
1596 (message-position-on-field "Newsgroups"))
1598 (defun message-goto-distribution ()
1599 "Move point to the Distribution header."
1601 (message-position-on-field "Distribution"))
1603 (defun message-goto-followup-to ()
1604 "Move point to the Followup-To header."
1606 (message-position-on-field "Followup-To" "Newsgroups"))
1608 (defun message-goto-keywords ()
1609 "Move point to the Keywords header."
1611 (message-position-on-field "Keywords" "Subject"))
1613 (defun message-goto-summary ()
1614 "Move point to the Summary header."
1616 (message-position-on-field "Summary" "Subject"))
1618 (defun message-goto-body ()
1619 "Move point to the beginning of the message body."
1621 (if (looking-at "[ \t]*\n") (expand-abbrev))
1622 (goto-char (point-min))
1623 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1624 (search-forward "\n\n" nil t
)))
1626 (defun message-goto-eoh ()
1627 "Move point to the end of the headers."
1632 (defun message-goto-signature ()
1633 "Move point to the beginning of the message signature.
1634 If there is no signature in the article, go to the end and
1637 (goto-char (point-min))
1638 (if (re-search-forward message-signature-separator nil t
)
1640 (goto-char (point-max))
1645 (defun message-insert-to (&optional force
)
1646 "Insert a To header that points to the author of the article being replied to.
1647 If the original author requested not to be sent mail, the function signals
1649 With the prefix argument FORCE, insert the header anyway."
1651 (let ((co (message-fetch-reply-field "mail-copies-to")))
1652 (when (and (null force
)
1654 (or (equal (downcase co
) "never")
1655 (equal (downcase co
) "nobody")))
1656 (error "The user has requested not to have copies sent via mail")))
1657 (when (and (message-position-on-field "To")
1658 (mail-fetch-field "to")
1659 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1661 (insert (or (message-fetch-reply-field "reply-to")
1662 (message-fetch-reply-field "from") "")))
1664 (defun message-widen-reply ()
1665 "Widen the reply to include maximum recipients."
1668 (and message-reply-buffer
1669 (buffer-name message-reply-buffer
)
1671 (set-buffer message-reply-buffer
)
1672 (message-get-reply-headers t
)))))
1675 (message-narrow-to-headers)
1676 (dolist (elem follow-to
)
1677 (message-remove-header (symbol-name (car elem
)))
1678 (goto-char (point-min))
1679 (insert (symbol-name (car elem
)) ": "
1680 (cdr elem
) "\n"))))))
1682 (defun message-insert-newsgroups ()
1683 "Insert the Newsgroups header from the article being replied to."
1685 (when (and (message-position-on-field "Newsgroups")
1686 (mail-fetch-field "newsgroups")
1687 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1689 (insert (or (message-fetch-reply-field "newsgroups") "")))
1693 ;;; Various commands
1695 (defun message-delete-not-region (beg end
)
1696 "Delete everything in the body of the current message that is outside of the region."
1700 (delete-region (point) (if (not (message-goto-signature))
1706 (delete-region beg
(progn (message-goto-body)
1709 (when (message-goto-signature)
1712 (defun message-kill-to-signature ()
1713 "Deletes all text up to the signature."
1715 (let ((point (point)))
1716 (message-goto-signature)
1719 (kill-region point
(point))
1723 (defun message-newline-and-reformat ()
1724 "Insert four newlines, and then reformat if inside quoted text."
1726 ;; The Latin-1 angle quote looks pretty dubious. -- fx
1727 (let ((prefix "[]>»|:}+ \t]*")
1728 (supercite-thing "[-._[:alnum:]]*[>]+[ \t]*")
1733 (when (looking-at (concat prefix
1735 (setq quoted
(match-string 0))))
1737 (setq point
(point))
1739 (delete-region (point) (re-search-forward "[ \t]*"))
1742 (fill-paragraph nil
)
1746 (defun message-insert-signature (&optional force
)
1747 "Insert a signature. See documentation for the `message-signature' variable."
1748 (interactive (list 0))
1751 ((and (null message-signature
)
1754 (goto-char (point-max))
1755 (not (re-search-backward message-signature-separator nil t
))))
1756 ((and (null message-signature
)
1759 ((message-functionp message-signature
)
1760 (funcall message-signature
))
1761 ((listp message-signature
)
1762 (eval message-signature
))
1763 (t message-signature
)))
1765 (cond ((stringp signature
)
1767 ((and (eq t signature
)
1768 message-signature-file
1769 (file-exists-p message-signature-file
))
1772 (goto-char (point-max))
1773 ;; Insert the signature.
1777 (if (eq signature t
)
1778 (insert-file-contents message-signature-file
)
1780 (goto-char (point-max))
1781 (or (bolp) (insert "\n")))))
1783 (defun message-elide-region (b e
)
1784 "Elide the text between point and mark.
1785 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1789 (insert message-elide-ellipsis
))
1791 (defvar message-caesar-translation-table nil
)
1793 (defun message-caesar-region (b e
&optional n
)
1794 "Caesar rotation of region by N, default 13, for decrypting netnews."
1797 (min (point) (or (mark t
) (point)))
1798 (max (point) (or (mark t
) (point)))
1799 (when current-prefix-arg
1800 (prefix-numeric-value current-prefix-arg
))))
1802 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
1803 (unless (or (zerop n
) ; no action needed for a rot of 0
1804 (= b e
)) ; no region to rotate
1805 ;; We build the table, if necessary.
1806 (when (or (not message-caesar-translation-table
)
1807 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
1808 (setq message-caesar-translation-table
1809 (message-make-caesar-translation-table n
)))
1810 (translate-region b e message-caesar-translation-table
)))
1812 (defun message-make-caesar-translation-table (n)
1813 "Create a rot table with offset N."
1815 (table (make-string 256 0)))
1816 (while (< (incf i
) 256)
1819 (substring table
0 ?A
)
1820 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
1821 (substring table ?A
(+ ?A n
))
1822 (substring table
(+ ?A
26) ?a
)
1823 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
1824 (substring table ?a
(+ ?a n
))
1825 (substring table
(+ ?a
26) 255))))
1827 (defun message-caesar-buffer-body (&optional rotnum
)
1828 "Caesar rotates all letters in the current buffer by 13 places.
1829 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1830 With prefix arg, specifies the number of places to rotate each letter forward.
1831 Mail and USENET news headers are not rotated."
1832 (interactive (if current-prefix-arg
1833 (list (prefix-numeric-value current-prefix-arg
))
1837 (when (message-goto-body)
1838 (narrow-to-region (point) (point-max)))
1839 (message-caesar-region (point-min) (point-max) rotnum
))))
1841 (defun message-pipe-buffer-body (program)
1842 "Pipe the message body in the current buffer through PROGRAM."
1845 (when (message-goto-body)
1846 (narrow-to-region (point) (point-max)))
1847 (shell-command-on-region
1848 (point-min) (point-max) program nil t
))))
1850 (defun message-rename-buffer (&optional enter-string
)
1851 "Rename the *message* buffer to \"*message* RECIPIENT\".
1852 If the function is run with a prefix, it will ask for a new buffer
1853 name, rather than giving an automatic name."
1854 (interactive "Pbuffer name: ")
1857 (goto-char (point-min))
1858 (narrow-to-region (point)
1859 (search-forward mail-header-separator nil
'end
))
1861 (if (message-news-p) (message-fetch-field "Newsgroups")
1862 (message-fetch-field "To"))
1865 (if (string-match "," mail-to
)
1866 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
1868 (name-default (concat "*message* " mail-trimmed-to
))
1869 (name (if enter-string
1870 (read-string "New buffer name: " name-default
)
1872 (rename-buffer name t
)))))
1874 (defun message-fill-yanked-message (&optional justifyp
)
1875 "Fill the paragraphs of a message yanked into this one.
1876 Numeric argument means justify as well."
1879 (goto-char (point-min))
1880 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
1881 (let ((fill-prefix message-yank-prefix
))
1882 (fill-individual-paragraphs (point) (point-max) justifyp
))))
1884 (defun message-indent-citation ()
1885 "Modify text just inserted from a message to be cited.
1886 The inserted text should be the region.
1887 When this function returns, the region is again around the modified text.
1889 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1890 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1891 (let ((start (point)))
1892 ;; Remove unwanted headers.
1893 (when message-ignored-cited-headers
1898 (if (search-forward "\n\n" nil t
)
1901 (message-remove-header message-ignored-cited-headers t
)
1902 (when (= (point-min) (point-max))
1903 (setq all-removed t
))
1904 (goto-char (point-max)))
1908 ;; Delete blank lines at the start of the buffer.
1909 (while (and (point-min)
1912 (message-delete-line))
1913 ;; Delete blank lines at the end of the buffer.
1914 (goto-char (point-max))
1917 (while (and (zerop (forward-line -
1))
1919 (message-delete-line))
1920 ;; Do the indentation.
1921 (if (null message-yank-prefix
)
1922 (indent-rigidly start
(mark t
) message-indentation-spaces
)
1925 (while (< (point) (mark t
))
1926 (insert message-yank-prefix
)
1930 (defun message-yank-original (&optional arg
)
1931 "Insert the message being replied to, if any.
1932 Puts point before the text and mark after.
1933 Normally indents each nonblank line ARG spaces (default 3). However,
1934 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1936 This function uses `message-cite-function' to do the actual citing.
1938 Just \\[universal-argument] as argument means don't indent, insert no
1939 prefix, and don't delete any headers."
1941 (let ((modified (buffer-modified-p)))
1942 (when (and message-reply-buffer
1943 message-cite-function
)
1944 (delete-windows-on message-reply-buffer t
)
1945 (insert-buffer message-reply-buffer
)
1946 (funcall message-cite-function
)
1947 (message-exchange-point-and-mark)
1951 (setq message-checksum
(message-checksum))))))
1953 (defun message-yank-buffer (buffer)
1954 "Insert BUFFER into the current buffer and quote it."
1955 (interactive "bYank buffer: ")
1956 (let ((message-reply-buffer buffer
))
1957 (save-window-excursion
1958 (message-yank-original))))
1960 (defun message-buffers ()
1961 "Return a list of active message buffers."
1964 (dolist (buffer (buffer-list t
))
1966 (when (and (eq major-mode
'message-mode
)
1967 (null message-sent-message-via
))
1968 (push (buffer-name buffer
) buffers
))))
1969 (nreverse buffers
)))
1971 (defun message-cite-original-without-signature ()
1972 "Cite function in the standard Message manner."
1973 (let ((start (point))
1976 (when message-indent-citation-function
1977 (if (listp message-indent-citation-function
)
1978 message-indent-citation-function
1979 (list message-indent-citation-function
)))))
1980 (mml-quote-region start end
)
1984 (when (re-search-backward message-signature-separator start t
)
1985 ;; Also peel off any blank lines before the signature.
1987 (while (looking-at "^[ \t]*$")
1990 (delete-region (point) end
))
1993 (funcall (pop functions
)))
1994 (when message-citation-line-function
1997 (funcall message-citation-line-function
))))
1999 (eval-when-compile (defvar mail-citation-hook
)) ;Compiler directive
2000 (defun message-cite-original ()
2001 "Cite function in the standard Message manner."
2002 (if (and (boundp 'mail-citation-hook
)
2004 (run-hooks 'mail-citation-hook
)
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
)
2015 (funcall (pop functions
)))
2016 (when message-citation-line-function
2019 (funcall message-citation-line-function
)))))
2021 (defun message-insert-citation-line ()
2022 "Function that inserts a simple citation line."
2023 (when message-reply-headers
2024 (insert (mail-header-from message-reply-headers
) " writes:\n\n")))
2026 (defun message-position-on-field (header &rest afters
)
2027 (let ((case-fold-search t
))
2030 (goto-char (point-min))
2033 (concat "^" (regexp-quote mail-header-separator
) "$"))
2034 (match-beginning 0)))
2035 (goto-char (point-min))
2036 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
2038 (re-search-forward "^[^ \t]" nil
'move
)
2040 (skip-chars-backward "\n")
2043 (not (re-search-forward
2044 (concat "^" (regexp-quote (car afters
)) ":")
2048 (re-search-forward "^[^ \t]" nil
'move
)
2049 (beginning-of-line))
2050 (insert header
": \n")
2054 (defun message-remove-signature ()
2055 "Remove the signature from the text between point and mark.
2056 The text will also be indented the normal way."
2058 (let ((start (point))
2060 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
2061 ;; No signature here, so we just indent the cited text.
2062 (message-indent-citation)
2063 ;; Find the last non-empty line.
2065 (while (looking-at "[ \t]*$")
2068 (setq mark
(set-marker (make-marker) (point)))
2070 (message-indent-citation)
2071 ;; Enable undoing the deletion.
2073 (delete-region mark
(mark t
))
2074 (set-marker mark nil
)))))
2079 ;;; Sending messages
2082 (defun message-send-and-exit (&optional arg
)
2083 "Send message like `message-send', then, if no errors, exit from mail buffer."
2085 (let ((buf (current-buffer))
2086 (actions message-exit-actions
))
2087 (when (and (message-send arg
)
2089 (if message-kill-buffer-on-exit
2092 (when (eq buf
(current-buffer))
2093 (message-bury buf
)))
2094 (message-do-actions actions
)
2097 (defun message-dont-send ()
2098 "Don't send the message you have been editing."
2100 (set-buffer-modified-p t
)
2102 (let ((actions message-postpone-actions
))
2103 (message-bury (current-buffer))
2104 (message-do-actions actions
)))
2106 (defun message-kill-buffer ()
2107 "Kill the current buffer."
2109 (when (or (not (buffer-modified-p))
2110 (yes-or-no-p "Message modified; kill anyway? "))
2111 (let ((actions message-kill-actions
))
2112 (setq buffer-file-name nil
)
2113 (kill-buffer (current-buffer))
2114 (message-do-actions actions
))))
2116 (defun message-bury (buffer)
2117 "Bury this mail buffer."
2118 (let ((newbuf (other-buffer buffer
)))
2119 (bury-buffer buffer
)
2120 (if (and (fboundp 'frame-parameters
)
2121 (cdr (assq 'dedicated
(frame-parameters)))
2122 (not (null (delq (selected-frame) (visible-frame-list)))))
2123 (delete-frame (selected-frame))
2124 (switch-to-buffer newbuf
))))
2126 (defun message-send (&optional arg
)
2127 "Send the message in the current buffer.
2128 If `message-interactive' is non-nil, wait for success indication or
2129 error messages, and inform user.
2130 Otherwise any failure is reported in a message back to the user from
2132 The usage of ARG is defined by the instance that called Message.
2133 It should typically alter the sending method in some way or other."
2135 ;; Make it possible to undo the coming changes.
2137 (let ((inhibit-read-only t
))
2138 (put-text-property (point-min) (point-max) 'read-only nil
))
2139 (message-fix-before-sending)
2140 (run-hooks 'message-send-hook
)
2141 (message message-sending-message
)
2142 (let ((alist message-send-method-alist
)
2146 (setq elem
(pop alist
)))
2147 (when (funcall (cadr elem
))
2148 (when (and (or (not (memq (car elem
)
2149 message-sent-message-via
))
2152 "Already sent message via %s; resend? "
2154 (setq success
(funcall (caddr elem
) arg
)))
2156 (unless (or sent
(not success
))
2157 (error "No methods specified to send by"))
2158 (when (and success sent
)
2161 (run-hooks 'message-sent-hook
))
2162 (message "Sending...done")
2163 ;; Mark the buffer as unmodified and delete auto-save.
2164 (set-buffer-modified-p nil
)
2165 (delete-auto-save-file-if-necessary t
)
2166 (message-disassociate-draft)
2167 ;; Delete other mail buffers and stuff.
2168 (message-do-send-housekeeping)
2169 (message-do-actions message-send-actions
)
2173 (defun message-send-via-mail (arg)
2174 "Send the current message via mail."
2175 (message-send-mail arg
))
2177 (defun message-send-via-news (arg)
2178 "Send the current message via news."
2179 (funcall message-send-news-function arg
))
2181 (defmacro message-check
(type &rest forms
)
2182 "Eval FORMS if TYPE is to be checked."
2183 `(or (message-check-element ,type
)
2187 (put 'message-check
'lisp-indent-function
1)
2188 (put 'message-check
'edebug-form-spec
'(form body
))
2190 (defun message-fix-before-sending ()
2191 "Do various things to make the message nice before sending it."
2192 ;; Make sure there's a newline at the end of the message.
2193 (goto-char (point-max))
2196 ;; Delete all invisible text.
2197 (message-check 'invisible-text
2198 (when (text-property-any (point-min) (point-max) 'invisible t
)
2199 (put-text-property (point-min) (point-max) 'invisible nil
)
2200 (unless (yes-or-no-p
2201 "Invisible text found and made visible; continue posting? ")
2202 (error "Invisible text found and made visible")))))
2204 (defun message-add-action (action &rest types
)
2205 "Add ACTION to be performed when doing an exit of type TYPES."
2208 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
2209 (nconc (symbol-value var
) (list action
))))))
2211 (defun message-do-actions (actions)
2212 "Perform all actions in ACTIONS."
2213 ;; Now perform actions on successful sending.
2217 ;; A simple function.
2218 ((message-functionp (car actions
))
2219 (funcall (car actions
)))
2220 ;; Something to be evaled.
2222 (eval (car actions
)))))
2225 (defun message-send-mail-partially ()
2226 "Sendmail as message/partial."
2227 ;; replace the header delimiter with a blank line
2228 (goto-char (point-min))
2230 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2231 (replace-match "\n")
2232 (run-hooks 'message-send-mail-hook
)
2233 (let ((p (goto-char (point-min)))
2234 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2235 (curbuf (current-buffer))
2236 (id (message-make-message-id)) (n 1)
2237 plist total header required-mail-headers
)
2239 (if (< (point-max) (+ p message-send-mail-partially-limit
))
2240 (goto-char (point-max))
2241 (goto-char (+ p message-send-mail-partially-limit
))
2243 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
2246 (setq total
(length plist
))
2247 (push (point-max) plist
)
2248 (setq plist
(nreverse plist
))
2251 (setq p
(pop plist
))
2254 (copy-to-buffer tembuf p
(car plist
))
2256 (goto-char (point-min))
2259 (goto-char (point-min))
2260 (narrow-to-region (point) (point))
2263 (setq header
(buffer-substring (point-min) (point)))
2264 (goto-char (point-min))
2265 (narrow-to-region (point) (point))
2267 (message-remove-header "Mime-Version")
2268 (message-remove-header "Content-Type")
2269 (message-remove-header "Content-Transfer-Encoding")
2270 (message-remove-header "Message-ID")
2271 (message-remove-header "Lines")
2272 (goto-char (point-max))
2273 (insert "Mime-Version: 1.0\n")
2274 (setq header
(buffer-substring (point-min) (point-max))))
2275 (goto-char (point-max))
2276 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2278 (let ((mail-header-separator ""))
2279 (when (memq 'Message-ID message-required-mail-headers
)
2280 (insert "Message-ID: " (message-make-message-id) "\n"))
2281 (when (memq 'Lines message-required-mail-headers
)
2282 (let ((mail-header-separator ""))
2283 (insert "Lines: " (message-make-lines) "\n")))
2284 (message-goto-subject)
2286 (insert (format " (%d/%d)" n total
))
2287 (goto-char (point-max))
2290 (mm-with-unibyte-current-buffer
2291 (funcall message-send-mail-function
)))
2293 (setq p
(pop plist
))
2295 (kill-buffer tembuf
))))
2297 (defun message-send-mail (&optional arg
)
2298 (require 'mail-utils
)
2299 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2300 (case-fold-search nil
)
2301 (news (message-news-p))
2302 (mailbuf (current-buffer))
2303 (message-this-is-mail t
)
2304 (message-posting-charset
2305 (if (fboundp 'gnus-setup-posting-charset
)
2306 (gnus-setup-posting-charset nil
)
2307 message-posting-charset
)))
2309 (message-narrow-to-headers)
2310 ;; Insert some headers.
2311 (let ((message-deletable-headers
2312 (if news nil message-deletable-headers
)))
2313 (message-generate-headers message-required-mail-headers
))
2314 ;; Let the user do all of the above.
2315 (run-hooks 'message-header-hook
))
2320 ;; Avoid copying text props.
2322 "%s" (save-excursion
2323 (set-buffer mailbuf
)
2325 ;; Remove some headers.
2326 (message-encode-message-body)
2328 (message-narrow-to-headers)
2329 ;; We (re)generate the Lines header.
2330 (when (memq 'Lines message-required-mail-headers
)
2331 (message-generate-headers '(Lines)))
2332 ;; Remove some headers.
2333 (message-remove-header message-ignored-mail-headers t
)
2334 (let ((mail-parse-charset message-default-charset
))
2335 (mail-encode-encoded-word-buffer)))
2336 (goto-char (point-max))
2337 ;; require one newline at the end.
2338 (or (= (preceding-char) ?
\n)
2342 (message-narrow-to-headers)
2344 (or (message-fetch-field "cc")
2345 (message-fetch-field "to"))
2346 (string= "text/plain"
2348 (mail-header-parse-content-type
2349 (message-fetch-field "content-type"))))))
2350 (message-insert-courtesy-copy))
2351 (if (or (not message-send-mail-partially-limit
)
2352 (< (point-max) message-send-mail-partially-limit
)
2353 (not (y-or-n-p "The message size is too large, should it be sent partially?")))
2354 (mm-with-unibyte-current-buffer
2355 (funcall message-send-mail-function
))
2356 (message-send-mail-partially)))
2357 (kill-buffer tembuf
))
2358 (set-buffer mailbuf
)
2359 (push 'mail message-sent-message-via
)))
2361 (defun message-send-mail-with-sendmail ()
2362 "Send off the prepared buffer with sendmail."
2363 (let ((errbuf (if message-interactive
2364 (message-generate-new-buffer-clone-locals
2367 resend-to-addresses delimline
)
2368 (let ((case-fold-search t
))
2370 (message-narrow-to-headers)
2371 (setq resend-to-addresses
(message-fetch-field "resent-to")))
2372 ;; Change header-delimiter to be what sendmail expects.
2373 (goto-char (point-min))
2375 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2376 (replace-match "\n")
2378 (setq delimline
(point-marker))
2379 (run-hooks 'message-send-mail-hook
)
2380 ;; Insert an extra newline if we need it to work around
2381 ;; Sun's bug that swallows newlines.
2382 (goto-char (1+ delimline
))
2383 (when (eval message-mailer-swallows-blank-line
)
2385 (when message-interactive
2389 (let ((default-directory "/")
2390 (coding-system-for-write message-send-coding-system
))
2391 (apply 'call-process-region
2392 (append (list (point-min) (point-max)
2393 (if (boundp 'sendmail-program
)
2395 "/usr/lib/sendmail")
2396 nil errbuf nil
"-oi")
2397 ;; Always specify who from,
2398 ;; since some systems have broken sendmails.
2399 ;; But some systems are more broken with -f, so
2400 ;; we'll let users override this.
2401 (if (null message-sendmail-f-is-evil
)
2402 (list "-f" (message-make-address)))
2403 ;; These mean "report errors by mail"
2404 ;; and "deliver in background".
2405 (if (null message-interactive
) '("-oem" "-odb"))
2406 ;; Get the addresses from the message
2407 ;; unless this is a resend.
2408 ;; We must not do that for a resend
2409 ;; because we would find the original addresses.
2410 ;; For a resend, include the specific addresses.
2411 (if resend-to-addresses
2412 (list resend-to-addresses
)
2414 (when message-interactive
2417 (goto-char (point-min))
2418 (while (re-search-forward "\n\n* *" nil t
)
2419 (replace-match "; "))
2420 (if (not (zerop (buffer-size)))
2421 (error "Sending...failed to %s"
2422 (buffer-substring (point-min) (point-max)))))
2423 (when (bufferp errbuf
)
2424 (kill-buffer errbuf
)))))
2426 (defun message-send-mail-with-qmail ()
2427 "Pass the prepared message buffer to qmail-inject.
2428 Refer to the documentation for the variable `message-send-mail-function'
2429 to find out how to use this."
2430 ;; replace the header delimiter with a blank line
2431 (goto-char (point-min))
2433 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2434 (replace-match "\n")
2435 (run-hooks 'message-send-mail-hook
)
2438 (let ((coding-system-for-write message-send-coding-system
))
2440 'call-process-region
1 (point-max) message-qmail-inject-program
2442 ;; qmail-inject's default behaviour is to look for addresses on the
2443 ;; command line; if there're none, it scans the headers.
2444 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2446 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2447 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2448 ;; message from stdin.
2450 ;; qmail also has the advantage of not having been raped by
2451 ;; various vendors, so we don't have to allow for that, either --
2452 ;; compare this with message-send-mail-with-sendmail and weep
2453 ;; for sendmail's lost innocence.
2455 ;; all this is way cool coz it lets us keep the arguments entirely
2456 ;; free for -inject-arguments -- a big win for the user and for us
2457 ;; since we don't have to play that double-guessing game and the user
2458 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2459 message-qmail-inject-args
))
2460 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2461 ;; we have to look at the retval instead
2463 (1 (error "qmail-inject reported permanent failure"))
2464 (111 (error "qmail-inject reported transient failure"))
2465 ;; should never happen
2466 (t (error "qmail-inject reported unknown failure"))))
2468 (defun message-send-mail-with-mh ()
2469 "Send the prepared message buffer with mh."
2470 (let ((mh-previous-window-config nil
)
2471 (name (mh-new-draft-name)))
2472 (setq buffer-file-name name
)
2473 ;; MH wants to generate these headers itself.
2474 (when message-mh-deletable-headers
2475 (let ((headers message-mh-deletable-headers
))
2477 (goto-char (point-min))
2478 (and (re-search-forward
2479 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
2480 (message-delete-line))
2482 (run-hooks 'message-send-mail-hook
)
2483 ;; Pass it on to mh.
2486 (defun message-send-news (&optional arg
)
2487 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2488 (case-fold-search nil
)
2489 (method (if (message-functionp message-post-method
)
2490 (funcall message-post-method arg
)
2491 message-post-method
))
2492 (group-name-charset (gnus-group-name-charset method
""))
2493 (rfc2047-header-encoding-alist
2494 (if group-name-charset
2495 (cons (cons "Newsgroups" group-name-charset
)
2496 rfc2047-header-encoding-alist
)
2497 rfc2047-header-encoding-alist
))
2498 (messbuf (current-buffer))
2499 (message-syntax-checks
2501 (cons '(existing-newsgroups . disabled
)
2502 message-syntax-checks
)
2503 message-syntax-checks
))
2504 (message-this-is-news t
)
2505 (message-posting-charset (gnus-setup-posting-charset
2507 (message-narrow-to-headers-or-head)
2508 (message-fetch-field "Newsgroups"))))
2510 (if (not (message-check-news-body-syntax))
2513 (message-narrow-to-headers)
2514 ;; Insert some headers.
2515 (message-generate-headers message-required-news-headers
)
2516 ;; Let the user do all of the above.
2517 (run-hooks 'message-header-hook
))
2518 (if group-name-charset
2519 (setq message-syntax-checks
2520 (cons '(valid-newsgroups . disabled
)
2521 message-syntax-checks
)))
2522 (message-cleanup-headers)
2523 (if (not (message-check-news-syntax))
2528 (buffer-disable-undo)
2530 ;; Avoid copying text props.
2532 "%s" (save-excursion
2533 (set-buffer messbuf
)
2535 (message-encode-message-body)
2536 ;; Remove some headers.
2538 (message-narrow-to-headers)
2539 ;; We (re)generate the Lines header.
2540 (when (memq 'Lines message-required-mail-headers
)
2541 (message-generate-headers '(Lines)))
2542 ;; Remove some headers.
2543 (message-remove-header message-ignored-news-headers t
)
2544 (let ((mail-parse-charset message-default-charset
))
2545 (mail-encode-encoded-word-buffer)))
2546 (goto-char (point-max))
2547 ;; require one newline at the end.
2548 (or (= (preceding-char) ?
\n)
2550 (let ((case-fold-search t
))
2551 ;; Remove the delimiter.
2552 (goto-char (point-min))
2554 (concat "^" (regexp-quote mail-header-separator
) "\n"))
2555 (replace-match "\n")
2557 (run-hooks 'message-send-news-hook
)
2558 (gnus-open-server method
)
2559 (setq result
(let ((mail-header-separator ""))
2560 (gnus-request-post method
))))
2561 (kill-buffer tembuf
))
2562 (set-buffer messbuf
)
2564 (push 'news message-sent-message-via
)
2565 (message "Couldn't send message via news: %s"
2566 (nnheader-get-report (car method
)))
2570 ;;; Header generation & syntax checking.
2573 (defun message-check-element (type)
2574 "Returns non-nil if this type is not to be checked."
2575 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
2577 (let ((able (assq type message-syntax-checks
)))
2579 (eq (cdr able
) 'disabled
)))))
2581 (defun message-check-news-syntax ()
2582 "Check the syntax of the message."
2586 ;; We narrow to the headers and check them first.
2589 (message-narrow-to-headers)
2590 (message-check-news-header-syntax))))))
2592 (defun message-check-news-header-syntax ()
2594 ;; Check Newsgroups header.
2595 (message-check 'newsgroups
2596 (let ((group (message-fetch-field "newsgroups")))
2599 (not (string-match "\\`[ \t]*\\'" group
)))
2602 "The newsgroups field is empty or missing. Posting is denied.")))))
2603 ;; Check the Subject header.
2604 (message-check 'subject
2605 (let* ((case-fold-search t
)
2606 (subject (message-fetch-field "subject")))
2609 (not (string-match "\\`[ \t]*\\'" subject
)))
2612 "The subject field is empty or missing. Posting is denied.")))))
2613 ;; Check for commands in Subject.
2614 (message-check 'subject-cmsg
2615 (if (string-match "^cmsg " (message-fetch-field "subject"))
2617 "The control code \"cmsg\" is in the subject. Really post? ")
2619 ;; Check for multiple identical headers.
2620 (message-check 'multiple-headers
2622 (while (and (not found
)
2623 (re-search-forward "^[^ \t:]+: " nil t
))
2625 (or (re-search-forward
2630 (match-beginning 0) (- (match-end 0) 2))))
2635 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
2637 ;; Check for Version and Sendsys.
2638 (message-check 'sendsys
2639 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
2641 (format "The article contains a %s command. Really post? "
2642 (buffer-substring (match-beginning 0)
2643 (1- (match-end 0)))))
2645 ;; See whether we can shorten Followup-To.
2646 (message-check 'shorten-followup-to
2647 (let ((newsgroups (message-fetch-field "newsgroups"))
2648 (followup-to (message-fetch-field "followup-to"))
2650 (when (and newsgroups
2651 (string-match "," newsgroups
)
2656 (setq to
(completing-read
2657 "Followups to: (default all groups) "
2658 (mapcar (lambda (g) (list g
))
2660 (message-tokenize-header
2662 (goto-char (point-min))
2663 (insert "Followup-To: " to
"\n"))
2665 ;; Check "Shoot me".
2666 (message-check 'shoot
2667 (if (re-search-forward
2668 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t
)
2669 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2671 ;; Check for Approved.
2672 (message-check 'approved
2673 (if (re-search-forward "^Approved:" nil t
)
2674 (y-or-n-p "The article contains an Approved header. Really post? ")
2676 ;; Check the Message-ID header.
2677 (message-check 'message-id
2678 (let* ((case-fold-search t
)
2679 (message-id (message-fetch-field "message-id" t
)))
2680 (or (not message-id
)
2681 ;; Is there an @ in the ID?
2682 (and (string-match "@" message-id
)
2683 ;; Is there a dot in the ID?
2684 (string-match "@[^.]*\\." message-id
)
2685 ;; Does the ID end with a dot?
2686 (not (string-match "\\.>" message-id
)))
2688 (format "The Message-ID looks strange: \"%s\". Really post? "
2690 ;; Check the Newsgroups & Followup-To headers.
2691 (message-check 'existing-newsgroups
2692 (let* ((case-fold-search t
)
2693 (newsgroups (message-fetch-field "newsgroups"))
2694 (followup-to (message-fetch-field "followup-to"))
2695 (groups (message-tokenize-header
2697 (concat newsgroups
"," followup-to
)
2699 (hashtb (and (boundp 'gnus-active-hashtb
)
2700 gnus-active-hashtb
))
2702 (if (or (not hashtb
)
2703 (not (boundp 'gnus-read-active-file
))
2704 (not gnus-read-active-file
)
2705 (eq gnus-read-active-file
'some
))
2708 (when (and (not (boundp (intern (car groups
) hashtb
)))
2709 (not (equal (car groups
) "poster")))
2710 (push (car groups
) errors
))
2716 "Really post to %s unknown group%s: %s "
2717 (if (= (length errors
) 1) "this" "these")
2718 (if (= (length errors
) 1) "" "s")
2719 (mapconcat 'identity errors
", ")))))))
2720 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2721 (message-check 'valid-newsgroups
2722 (let ((case-fold-search t
)
2723 (headers '("Newsgroups" "Followup-To"))
2725 (while (and headers
(not error
))
2726 (when (setq header
(mail-fetch-field (car headers
)))
2730 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2735 (not (string-match "\\.\\'\\|\\.\\." g
)))
2736 (message-tokenize-header header
","))))
2743 (format "The %s header looks odd: \"%s\". Really post? "
2744 (car headers
) header
)))))
2745 (message-check 'repeated-newsgroups
2746 (let ((case-fold-search t
)
2747 (headers '("Newsgroups" "Followup-To"))
2748 header error groups group
)
2751 (when (setq header
(mail-fetch-field (pop headers
)))
2752 (setq groups
(message-tokenize-header header
","))
2753 (while (setq group
(pop groups
))
2754 (when (member group groups
)
2760 (format "Group %s is repeated in headers. Really post? " error
)))))
2761 ;; Check the From header.
2762 (message-check 'from
2763 (let* ((case-fold-search t
)
2764 (from (message-fetch-field "from"))
2768 (message "There is no From line. Posting is denied.")
2770 ((or (not (string-match
2772 (setq ad
(nth 1 (mail-extract-address-components
2773 from
))))) ;larsi@ifi
2774 (string-match "\\.\\." ad
) ;larsi@ifi..uio
2775 (string-match "@\\." ad
) ;larsi@.ifi.uio
2776 (string-match "\\.$" ad
) ;larsi@ifi.uio.
2777 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
2778 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
2780 "Denied posting -- the From looks strange: \"%s\"." from
)
2784 (defun message-check-news-body-syntax ()
2786 ;; Check for long lines.
2787 (message-check 'long-lines
2788 (goto-char (point-min))
2790 (concat "^" (regexp-quote mail-header-separator
) "$"))
2794 (< (current-column) 80))
2795 (zerop (forward-line 1))))
2799 "You have lines longer than 79 characters. Really post? ")))
2800 ;; Check whether the article is empty.
2801 (message-check 'empty
2802 (goto-char (point-min))
2804 (concat "^" (regexp-quote mail-header-separator
) "$"))
2807 (goto-char (point-max))
2808 (re-search-backward message-signature-separator nil t
)
2810 (or (re-search-backward "[^ \n\t]" b t
)
2811 (y-or-n-p "Empty article. Really post? "))))
2812 ;; Check for control characters.
2813 (message-check 'control-chars
2814 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t
)
2816 "The article contains control characters. Really post? ")
2818 ;; Check excessive size.
2819 (message-check 'size
2820 (if (> (buffer-size) 60000)
2822 (format "The article is %d octets long. Really post? "
2825 ;; Check whether any new text has been added.
2826 (message-check 'new-text
2828 (not message-checksum
)
2829 (not (eq (message-checksum) message-checksum
))
2831 "It looks like no new text has been added. Really post? ")))
2832 ;; Check the length of the signature.
2833 (message-check 'signature
2834 (goto-char (point-max))
2835 (if (> (count-lines (point) (point-max)) 5)
2838 "Your .sig is %d lines; it should be max 4. Really post? "
2839 (1- (count-lines (point) (point-max)))))
2841 ;; Ensure that text follows last quoted portion.
2842 (message-check 'quoting-style
2843 (goto-char (point-max))
2844 (let ((no-problem t
))
2845 (when (search-backward-regexp "^>[^\n]*\n>" nil t
)
2846 (setq no-problem nil
)
2848 (when (and (not (eolp)) (looking-at "[^> \t]"))
2849 (setq no-problem t
))
2853 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
2855 (defun message-checksum ()
2856 "Return a \"checksum\" for the current buffer."
2859 (goto-char (point-min))
2861 (concat "^" (regexp-quote mail-header-separator
) "$"))
2863 (when (not (looking-at "[ \t\n]"))
2864 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
2869 (defun message-do-fcc ()
2870 "Process Fcc headers in the current buffer."
2871 (let ((case-fold-search t
)
2872 (buf (current-buffer))
2875 (set-buffer (get-buffer-create " *message temp*"))
2877 (insert-buffer-substring buf
)
2879 (message-narrow-to-headers)
2880 (while (setq file
(message-fetch-field "fcc"))
2882 (message-remove-header "fcc" nil t
)))
2883 (message-encode-message-body)
2885 (message-narrow-to-headers)
2886 (let ((mail-parse-charset message-default-charset
)
2887 (rfc2047-header-encoding-alist
2888 (cons '("Newsgroups" . default
)
2889 rfc2047-header-encoding-alist
)))
2890 (mail-encode-encoded-word-buffer)))
2891 (goto-char (point-min))
2892 (when (re-search-forward
2893 (concat "^" (regexp-quote mail-header-separator
) "$")
2895 (replace-match "" t t
))
2896 ;; Process FCC operations.
2898 (setq file
(pop list
))
2899 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
2900 ;; Pipe the article to the program in question.
2901 (call-process-region (point-min) (point-max) shell-file-name
2902 nil nil nil shell-command-switch
2903 (match-string 1 file
))
2904 ;; Save the article.
2905 (setq file
(expand-file-name file
))
2906 (unless (file-exists-p (file-name-directory file
))
2907 (make-directory (file-name-directory file
) t
))
2908 (if (and message-fcc-handler-function
2909 (not (eq message-fcc-handler-function
'rmail-output
)))
2910 (funcall message-fcc-handler-function file
)
2911 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
2912 (rmail-output file
1 nil t
)
2913 (let ((mail-use-rfc822 t
))
2914 (rmail-output file
1 t t
))))))
2915 (kill-buffer (current-buffer)))))
2917 (defun message-output (filename)
2918 "Append this article to Unix/babyl mail file.."
2919 (if (and (file-readable-p filename
)
2920 (mail-file-babyl-p filename
))
2921 (gnus-output-to-rmail filename t
)
2922 (gnus-output-to-mail filename t
)))
2924 (defun message-cleanup-headers ()
2925 "Do various automatic cleanups of the headers."
2926 ;; Remove empty lines in the header.
2928 (message-narrow-to-headers)
2929 ;; Remove blank lines.
2930 (while (re-search-forward "^[ \t]*\n" nil t
)
2931 (replace-match "" t t
))
2933 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2934 ;; spaces to comma and eliminate spaces around commas. Eliminate
2935 ;; embedded line breaks.
2936 (goto-char (point-min))
2937 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
2941 (if (re-search-forward "^[^ \t]" nil t
)
2945 (goto-char (point-min))
2946 (while (re-search-forward "\n[ \t]+" nil t
)
2947 (replace-match " " t t
)) ;No line breaks (too confusing)
2948 (goto-char (point-min))
2949 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
2950 (replace-match "," t t
))
2951 (goto-char (point-min))
2952 ;; Remove trailing commas.
2953 (when (re-search-forward ",+$" nil t
)
2954 (replace-match "" t t
))))))
2956 (defun message-make-date (&optional now
)
2957 "Make a valid data header.
2958 If NOW, use that time instead."
2959 (let* ((now (or now
(current-time)))
2960 (zone (nth 8 (decode-time now
)))
2964 (setq zone
(- zone
)))
2966 (format-time-string "%d" now
)
2967 ;; The month name of the %b spec is locale-specific. Pfff.
2969 (capitalize (car (rassoc (nth 4 (decode-time now
))
2970 parse-time-months
))))
2971 (format-time-string "%Y %H:%M:%S " now
)
2972 ;; We do all of this because XEmacs doesn't have the %z spec.
2973 (format "%s%02d%02d" sign
(/ zone
3600) (/ (% zone
3600) 60)))))
2975 (defun message-make-message-id ()
2976 "Make a unique Message-ID."
2977 (concat "<" (message-unique-id)
2978 (let ((psubject (save-excursion (message-fetch-field "subject")))
2980 (save-excursion (message-fetch-field "supersedes"))))
2982 (and message-reply-headers
2983 (mail-header-references message-reply-headers
)
2984 (mail-header-subject message-reply-headers
)
2986 (mail-header-subject message-reply-headers
)
2988 (message-strip-subject-re
2989 (mail-header-subject message-reply-headers
))
2990 (message-strip-subject-re psubject
))))
2992 (string-match "_-_@" psupersedes
)))
2994 "@" (message-make-fqdn) ">"))
2996 (defvar message-unique-id-char nil
)
2998 ;; If you ever change this function, make sure the new version
2999 ;; cannot generate IDs that the old version could.
3000 ;; You might for example insert a "." somewhere (not next to another dot
3001 ;; or string boundary), or modify the "fsf" string.
3002 (defun message-unique-id ()
3003 ;; Don't use microseconds from (current-time), they may be unsupported.
3004 ;; Instead we use this randomly inited counter.
3005 (setq message-unique-id-char
3006 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
3007 ;; (current-time) returns 16-bit ints,
3008 ;; and 2^16*25 just fits into 4 digits i base 36.
3010 (let ((tm (current-time)))
3012 (if (memq system-type
'(ms-dos emx vax-vms
))
3013 (let ((user (downcase (user-login-name))))
3014 (while (string-match "[^a-z0-9_]" user
)
3015 (aset user
(match-beginning 0) ?_
))
3017 (message-number-base36 (user-uid) -
1))
3018 (message-number-base36 (+ (car tm
)
3019 (lsh (% message-unique-id-char
25) 16)) 4)
3020 (message-number-base36 (+ (nth 1 tm
)
3021 (lsh (/ message-unique-id-char
25) 16)) 4)
3022 ;; Append the newsreader name, because while the generated
3023 ;; ID is unique to this newsreader, other newsreaders might
3024 ;; otherwise generate the same ID via another algorithm.
3027 (defun message-number-base36 (num len
)
3032 (concat (message-number-base36 (/ num
36) (1- len
))
3033 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3036 (defun message-make-organization ()
3037 "Make an Organization header."
3038 (let* ((organization
3039 (when message-user-organization
3040 (if (message-functionp message-user-organization
)
3041 (funcall message-user-organization
)
3042 message-user-organization
))))
3044 (message-set-work-buffer)
3045 (cond ((stringp organization
)
3046 (insert organization
))
3047 ((and (eq t organization
)
3048 message-user-organization-file
3049 (file-exists-p message-user-organization-file
))
3050 (insert-file-contents message-user-organization-file
)))
3051 (goto-char (point-min))
3052 (while (re-search-forward "[\t\n]+" nil t
)
3053 (replace-match "" t t
))
3054 (unless (zerop (buffer-size))
3057 (defun message-make-lines ()
3058 "Count the number of lines and return numeric string."
3062 (goto-char (point-min))
3064 (concat "^" (regexp-quote mail-header-separator
) "$"))
3066 (int-to-string (count-lines (point) (point-max))))))
3068 (defun message-make-in-reply-to ()
3069 "Return the In-Reply-To header for this message."
3070 (when message-reply-headers
3071 (mail-header-message-id message-reply-headers
)))
3073 (defun message-make-distribution ()
3074 "Make a Distribution header."
3075 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3076 (cond ((message-functionp message-distribution-function
)
3077 (funcall message-distribution-function
))
3078 (t orig-distribution
))))
3080 (defun message-make-expires ()
3081 "Return an Expires header based on `message-expires'."
3082 (let ((current (current-time))
3083 (future (* 1.0 message-expires
60 60 24)))
3084 ;; Add the future to current.
3085 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
3086 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
3087 (message-make-date current
)))
3089 (defun message-make-path ()
3091 (let ((login-name (user-login-name)))
3092 (cond ((null message-user-path
)
3093 (concat (system-name) "!" login-name
))
3094 ((stringp message-user-path
)
3095 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3096 (concat message-user-path
"!" login-name
))
3099 (defun message-make-from ()
3100 "Make a From header."
3101 (let* ((style message-from-style
)
3102 (login (message-make-address))
3104 (or (and (boundp 'user-full-name
)
3107 (when (string= fullname
"&")
3108 (setq fullname
(user-login-name)))
3110 (message-set-work-buffer)
3113 (equal fullname
""))
3115 ((or (eq style
'angles
)
3116 (and (not (eq style
'parens
))
3117 ;; Use angles if no quoting is needed, or if parens would
3118 ;; need quoting too.
3119 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
3120 (let ((tmp (concat fullname nil
)))
3121 (while (string-match "([^()]*)" tmp
)
3122 (aset tmp
(match-beginning 0) ?-
)
3123 (aset tmp
(1- (match-end 0)) ?-
))
3124 (string-match "[\\()]" tmp
)))))
3126 (goto-char (point-min))
3127 ;; Look for a character that cannot appear unquoted
3128 ;; according to RFC 822.
3129 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
3130 ;; Quote fullname, escaping specials.
3131 (goto-char (point-min))
3133 (while (re-search-forward "[\"\\]" nil
1)
3134 (replace-match "\\\\\\&" t
))
3136 (insert " <" login
">"))
3137 (t ; 'parens or default
3139 (let ((fullname-start (point)))
3141 (goto-char fullname-start
)
3142 ;; RFC 822 says \ and nonmatching parentheses
3143 ;; must be escaped in comments.
3144 ;; Escape every instance of ()\ ...
3145 (while (re-search-forward "[()\\]" nil
1)
3146 (replace-match "\\\\\\&" t
))
3147 ;; ... then undo escaping of matching parentheses,
3148 ;; including matching nested parentheses.
3149 (goto-char fullname-start
)
3150 (while (re-search-forward
3151 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3153 (replace-match "\\1(\\3)" t
)
3154 (goto-char fullname-start
)))
3158 (defun message-make-sender ()
3159 "Return the \"real\" user address.
3160 This function tries to ignore all user modifications, and
3161 give as trustworthy answer as possible."
3162 (concat (user-login-name) "@" (system-name)))
3164 (defun message-make-address ()
3165 "Make the address of the user."
3166 (or (message-user-mail-address)
3167 (concat (user-login-name) "@" (message-make-domain))))
3169 (defun message-user-mail-address ()
3170 "Return the pertinent part of `user-mail-address'."
3171 (when user-mail-address
3172 (if (string-match " " user-mail-address
)
3173 (nth 1 (mail-extract-address-components user-mail-address
))
3174 user-mail-address
)))
3176 (defun message-make-fqdn ()
3177 "Return user's fully qualified domain name."
3178 (let ((system-name (system-name))
3179 (user-mail (message-user-mail-address)))
3181 ((string-match "[^.]\\.[^.]" system-name
)
3182 ;; `system-name' returned the right result.
3184 ;; Try `mail-host-address'.
3185 ((and (boundp 'mail-host-address
)
3186 (stringp mail-host-address
)
3187 (string-match "\\." mail-host-address
))
3189 ;; We try `user-mail-address' as a backup.
3191 (string-match "\\." user-mail
)
3192 (string-match "@\\(.*\\)\\'" user-mail
))
3193 (match-string 1 user-mail
))
3194 ;; Default to this bogus thing.
3196 (concat system-name
".i-did-not-set--mail-host-address--so-shoot-me")))))
3198 (defun message-make-host-name ()
3199 "Return the name of the host."
3200 (let ((fqdn (message-make-fqdn)))
3201 (string-match "^[^.]+\\." fqdn
)
3202 (substring fqdn
0 (1- (match-end 0)))))
3204 (defun message-make-domain ()
3205 "Return the domain name."
3206 (or mail-host-address
3207 (message-make-fqdn)))
3209 (defun message-generate-headers (headers)
3210 "Prepare article HEADERS.
3211 Headers already prepared in the buffer are not modified."
3213 (message-narrow-to-headers)
3214 (let* ((Date (message-make-date))
3215 (Message-ID (message-make-message-id))
3216 (Organization (message-make-organization))
3217 (From (message-make-from))
3218 (Path (message-make-path))
3221 (In-Reply-To (message-make-in-reply-to))
3223 (Distribution (message-make-distribution))
3224 (Lines (message-make-lines))
3225 (User-Agent message-newsreader
)
3226 (Expires (message-make-expires))
3227 (case-fold-search t
)
3229 ;; First we remove any old generated headers.
3230 (let ((headers message-deletable-headers
))
3231 (unless (buffer-modified-p)
3232 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
3234 (goto-char (point-min))
3235 (and (re-search-forward
3236 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
3237 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
3238 (message-delete-line))
3240 ;; Go through all the required headers and see if they are in the
3241 ;; articles already. If they are not, or are empty, they are
3242 ;; inserted automatically - except for Subject, Newsgroups and
3245 (goto-char (point-min))
3246 (setq elem
(pop headers
))
3248 (if (eq (car elem
) 'optional
)
3249 (setq header
(cdr elem
))
3250 (setq header
(car elem
)))
3252 (when (or (not (re-search-forward
3256 (if (stringp header
)
3258 (symbol-name header
))))
3262 ;; The header was found. We insert a space after the
3263 ;; colon, if there is none.
3264 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
3265 ;; Find out whether the header is empty...
3266 (looking-at "[ \t]*\n[^ \t]")))
3267 ;; So we find out what value we should insert.
3270 ((and (consp elem
) (eq (car elem
) 'optional
))
3271 ;; This is an optional header. If the cdr of this
3272 ;; is something that is nil, then we do not insert
3274 (setq header
(cdr elem
))
3275 (or (and (fboundp (cdr elem
)) (funcall (cdr elem
)))
3276 (and (boundp (cdr elem
)) (symbol-value (cdr elem
)))))
3278 ;; The element is a cons. Either the cdr is a
3279 ;; string to be inserted verbatim, or it is a
3280 ;; function, and we insert the value returned from
3282 (or (and (stringp (cdr elem
)) (cdr elem
))
3283 (and (fboundp (cdr elem
)) (funcall (cdr elem
)))))
3284 ((and (boundp header
) (symbol-value header
))
3285 ;; The element is a symbol. We insert the value
3286 ;; of this symbol, if any.
3287 (symbol-value header
))
3288 ((not (message-check-element header
))
3289 ;; We couldn't generate a value for this header,
3290 ;; so we just ask the user.
3291 (read-from-minibuffer
3292 (format "Empty header for %s; enter value: " header
)))))
3293 ;; Finally insert the header.
3295 (not (equal value
"")))
3299 ;; This header didn't exist, so we insert it.
3300 (goto-char (point-max))
3301 (insert (if (stringp header
) header
(symbol-name header
))
3304 ;; The value of this header was empty, so we clear
3305 ;; totally and insert the new value.
3306 (delete-region (point) (gnus-point-at-eol))
3308 ;; Add the deletable property to the headers that require it.
3309 (and (memq header message-deletable-headers
)
3310 (progn (beginning-of-line) (looking-at "[^:]+: "))
3311 (add-text-properties
3312 (point) (match-end 0)
3313 '(message-deletable t face italic
) (current-buffer)))))))
3314 ;; Insert new Sender if the From is strange.
3315 (let ((from (message-fetch-field "from"))
3316 (sender (message-fetch-field "sender"))
3317 (secure-sender (message-make-sender)))
3319 (not (message-check-element 'sender
))
3322 (cadr (mail-extract-address-components from
)))
3323 (downcase secure-sender
)))
3328 (cadr (mail-extract-address-components sender
)))
3329 (downcase secure-sender
)))))
3330 (goto-char (point-min))
3331 ;; Rename any old Sender headers to Original-Sender.
3332 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
3334 (insert "Original-")
3335 (beginning-of-line))
3336 (when (or (message-news-p)
3337 (string-match "@.+\\.." secure-sender
))
3338 (insert "Sender: " secure-sender
"\n")))))))
3340 (defun message-insert-courtesy-copy ()
3341 "Insert a courtesy message in mail copies of combined messages."
3345 (message-narrow-to-headers)
3346 (when (setq newsgroups
(message-fetch-field "newsgroups"))
3347 (goto-char (point-max))
3348 (insert "Posted-To: " newsgroups
"\n")))
3350 (when message-courtesy-message
3352 ((string-match "%s" message-courtesy-message
)
3353 (insert (format message-courtesy-message newsgroups
)))
3355 (insert message-courtesy-message
)))))))
3358 ;;; Setting up a message buffer
3361 (defun message-fill-address (header value
)
3363 (narrow-to-region (point) (point))
3364 (insert (capitalize (symbol-name header
))
3366 (if (consp value
) (car value
) value
)
3368 (narrow-to-region (point-min) (1- (point-max)))
3370 (goto-char (point-min))
3372 (skip-chars-forward "^,\"" (point-max))
3373 (if (or (eq (char-after) ?
,)
3376 (if (and (> (current-column) 78)
3382 (setq last
(1+ (point))))
3383 (setq last
(1+ (point)))))
3384 (setq quoted
(not quoted
)))
3387 (goto-char (point-max))
3391 (defun message-fill-header (header value
)
3392 (let ((begin (point))
3395 (insert (capitalize (symbol-name header
))
3397 (if (consp value
) (car value
) value
)
3400 (narrow-to-region begin
(point))
3401 (fill-region-as-paragraph begin
(point))
3402 ;; Tapdance around looong Message-IDs.
3404 (when (looking-at "[ \t]*$")
3405 (message-delete-line))
3407 (re-search-forward ":" nil t
)
3408 (when (looking-at "\n[ \t]+")
3409 (replace-match " " t t
))
3410 (goto-char (point-max)))))
3412 (defun message-shorten-1 (list cut surplus
)
3413 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3414 (setcdr (nthcdr (- cut
2) list
)
3415 (nthcdr (+ (- cut
2) surplus
1) list
)))
3417 (defun message-shorten-references (header references
)
3418 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3419 If folding is disallowed, also check that the REFERENCES are less
3420 than 988 characters long, and if they are not, trim them until they are."
3427 (goto-char (point-min))
3428 ;; Cons a list of valid references.
3429 (while (re-search-forward "<[^>]+>" nil t
)
3430 (push (match-string 0) refs
))
3431 (setq refs
(nreverse refs
)
3432 count
(length refs
)))
3434 ;; If the list has more than MAXCOUNT elements, trim it by
3435 ;; removing the CUTth element and the required number of
3436 ;; elements that follow.
3437 (when (> count maxcount
)
3438 (let ((surplus (- count maxcount
)))
3439 (message-shorten-1 refs cut surplus
)
3440 (decf count surplus
)))
3442 ;; If folding is disallowed, make sure the total length (including
3443 ;; the spaces between) will be less than MAXSIZE characters.
3445 ;; Only disallow folding for News messages. At this point the headers
3446 ;; have not been generated, thus we use message-this-is-news directly.
3447 (when (and message-this-is-news message-cater-to-broken-inn
)
3449 (totalsize (+ (apply #'+ (mapcar #'length refs
))
3452 (ptr (nthcdr (1- cut
) refs
)))
3453 ;; Decide how many elements to cut off...
3454 (while (> totalsize maxsize
)
3455 (decf totalsize
(1+ (length (car ptr
))))
3457 (setq ptr
(cdr ptr
)))
3460 (message-shorten-1 refs cut surplus
))))
3462 ;; Finally, collect the references back into a string and insert
3463 ;; it into the buffer.
3464 (let ((refstring (mapconcat #'identity refs
" ")))
3465 (if (and message-this-is-news message-cater-to-broken-inn
)
3466 (insert (capitalize (symbol-name header
)) ": "
3468 (message-fill-header header refstring
)))))
3470 (defun message-position-point ()
3471 "Move point to where the user probably wants to find it."
3472 (message-narrow-to-headers)
3474 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
3475 (search-backward ":" )
3478 (if (eq (char-after) ?
)
3482 (goto-char (point-max))
3485 (unless (looking-at "$")
3489 (defun message-buffer-name (type &optional to group
)
3490 "Return a new (unique) buffer name based on TYPE and TO."
3492 ;; Generate a new buffer name The Message Way.
3493 ((eq message-generate-new-buffers
'unique
)
3494 (generate-new-buffer-name
3498 (or (car (mail-extract-address-components to
))
3501 (if (and group
(not (string= group
""))) (concat " on " group
) "")
3503 ;; Check whether `message-generate-new-buffers' is a function,
3504 ;; and if so, call it.
3505 ((message-functionp message-generate-new-buffers
)
3506 (funcall message-generate-new-buffers type to group
))
3507 ((eq message-generate-new-buffers
'unsent
)
3508 (generate-new-buffer-name
3509 (concat "*unsent " type
3512 (or (car (mail-extract-address-components to
))
3515 (if (and group
(not (string= group
""))) (concat " on " group
) "")
3517 ;; Use standard name.
3519 (format "*%s message*" type
))))
3521 (defun message-pop-to-buffer (name)
3522 "Pop to buffer NAME, and warn if it already exists and is modified."
3523 (let ((buffer (get-buffer name
)))
3525 (buffer-name buffer
))
3527 (set-buffer (pop-to-buffer buffer
))
3528 (when (and (buffer-modified-p)
3530 "Message already being composed; erase? ")))
3531 (error "Message being composed")))
3532 (set-buffer (pop-to-buffer name
)))
3536 (defun message-do-send-housekeeping ()
3537 "Kill old message buffers."
3538 ;; We might have sent this buffer already. Delete it from the
3540 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
3541 (while (and message-max-buffers
3543 (>= (length message-buffer-list
) message-max-buffers
))
3544 ;; Kill the oldest buffer -- unless it has been changed.
3545 (let ((buffer (pop message-buffer-list
)))
3546 (when (and (buffer-name buffer
)
3547 (not (buffer-modified-p buffer
)))
3548 (kill-buffer buffer
))))
3549 ;; Rename the buffer.
3550 (if message-send-rename-function
3551 (funcall message-send-rename-function
)
3552 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3554 (concat "*sent " (substring (buffer-name) (match-end 0))) t
)))
3555 ;; Push the current buffer onto the list.
3556 (when message-max-buffers
3557 (setq message-buffer-list
3558 (nconc message-buffer-list
(list (current-buffer))))))
3560 (eval-when-compile (defvar mc-modes-alist
))
3561 (defun message-setup (headers &optional replybuffer actions
)
3562 (when (and (boundp 'mc-modes-alist
)
3563 (not (assq 'message-mode mc-modes-alist
)))
3564 (push '(message-mode (encrypt . mc-encrypt-message
)
3565 (sign . mc-sign-message
))
3568 (setq message-send-actions actions
))
3569 (setq message-reply-buffer replybuffer
)
3570 (goto-char (point-min))
3571 ;; Insert all the headers.
3574 (alist message-header-format-alist
))
3576 (unless (assq (caar h
) message-header-format-alist
)
3577 (push (list (caar h
)) alist
))
3581 (delete-region (point) (progn (forward-line -
1) (point)))
3582 (when message-default-headers
3583 (insert message-default-headers
)
3584 (or (bolp) (insert ?
\n)))
3588 (insert mail-header-separator
"\n")
3592 (when (message-news-p)
3593 (when message-default-news-headers
3594 (insert message-default-news-headers
)
3595 (or (bolp) (insert ?
\n)))
3596 (when message-generate-headers-first
3597 (message-generate-headers
3600 (copy-sequence message-required-news-headers
))))))
3601 (when (message-mail-p)
3602 (when message-default-mail-headers
3603 (insert message-default-mail-headers
)
3604 (or (bolp) (insert ?
\n)))
3605 (when message-generate-headers-first
3606 (message-generate-headers
3609 (copy-sequence message-required-mail-headers
))))))
3610 (run-hooks 'message-signature-setup-hook
)
3611 (message-insert-signature)
3613 (message-narrow-to-headers)
3614 (if message-alternative-emails
3615 (message-use-alternative-email-as-from))
3616 (run-hooks 'message-header-setup-hook
))
3617 (set-buffer-modified-p nil
)
3618 (setq buffer-undo-list nil
)
3619 (run-hooks 'message-setup-hook
)
3620 (message-position-point)
3623 (defun message-set-auto-save-file-name ()
3624 "Associate the message buffer with a file in the drafts directory."
3625 (when message-auto-save-directory
3627 (setq message-draft-article
3628 (nndraft-request-associate-buffer "drafts"))
3629 (setq buffer-file-name
(expand-file-name "*message*"
3630 message-auto-save-directory
))
3631 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
3632 (clear-visited-file-modtime)
3633 (setq buffer-file-coding-system message-draft-coding-system
)))
3635 (defun message-disassociate-draft ()
3636 "Disassociate the message buffer from the drafts directory."
3637 (when message-draft-article
3638 (nndraft-request-expire-articles
3639 (list message-draft-article
) "drafts" nil t
)))
3641 (defun message-insert-headers ()
3642 "Generate the headers for the article."
3646 (message-narrow-to-headers)
3647 (when (message-news-p)
3648 (message-generate-headers
3651 (copy-sequence message-required-news-headers
)))))
3652 (when (message-mail-p)
3653 (message-generate-headers
3656 (copy-sequence message-required-mail-headers
))))))))
3661 ;;; Commands for interfacing with message
3665 (defun message-mail (&optional to subject
3666 other-headers continue switch-function
3667 yank-action send-actions
)
3668 "Start editing a mail message to be sent.
3669 OTHER-HEADERS is an alist of header/value pairs."
3671 (let ((message-this-is-mail t
))
3672 (message-pop-to-buffer (message-buffer-name "mail" to
))
3675 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
3676 (when other-headers other-headers
)))))
3679 (defun message-news (&optional newsgroups subject
)
3680 "Start editing a news article to be sent."
3682 (let ((message-this-is-news t
))
3683 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
))
3684 (message-setup `((Newsgroups .
,(or newsgroups
""))
3685 (Subject .
,(or subject
""))))))
3687 (defun message-get-reply-headers (wide &optional to-address
)
3688 (let (follow-to mct never-mct from to cc reply-to ccalist
)
3689 ;; Find all relevant headers we need.
3690 (setq from
(message-fetch-field "from")
3691 to
(message-fetch-field "to")
3692 cc
(message-fetch-field "cc")
3693 mct
(message-fetch-field "mail-copies-to")
3694 reply-to
(message-fetch-field "reply-to"))
3696 ;; Handle special values of Mail-Copies-To.
3698 (cond ((or (equal (downcase mct
) "never")
3699 (equal (downcase mct
) "nobody"))
3702 ((or (equal (downcase mct
) "always")
3703 (equal (downcase mct
) "poster"))
3704 (setq mct
(or reply-to from
)))))
3709 (setq follow-to
(list (cons 'To
(or to-address reply-to from
))))
3710 (when (and wide mct
)
3711 (push (cons 'Cc mct
) follow-to
)))
3714 (message-set-work-buffer)
3716 (insert (or reply-to from
"")))
3717 (insert (if to
(concat (if (bolp) "" ", ") to
"") ""))
3718 (insert (if mct
(concat (if (bolp) "" ", ") mct
) ""))
3719 (insert (if cc
(concat (if (bolp) "" ", ") cc
) ""))
3720 (goto-char (point-min))
3721 (while (re-search-forward "[ \t]+" nil t
)
3722 (replace-match " " t t
))
3723 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3724 (let ((rmail-dont-reply-to-names message-dont-reply-to-names
))
3725 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3727 (goto-char (point-min))
3728 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3730 (insert (or reply-to from
"")))
3734 (cons (mail-strip-quoted-names addr
) addr
))
3735 (message-tokenize-header (buffer-string))))
3738 (setq ccalist
(delq (assoc (car (pop s
)) s
) ccalist
)))))
3739 (setq follow-to
(list (cons 'To
(cdr (pop ccalist
)))))
3741 (let ((ccs (cons 'Cc
(mapconcat
3742 (lambda (addr) (cdr addr
)) ccalist
", "))))
3743 (when (string-match "^ +" (cdr ccs
))
3744 (setcdr ccs
(substring (cdr ccs
) (match-end 0))))
3745 (push ccs follow-to
)))))
3750 (defun message-reply (&optional to-address wide
)
3751 "Start editing a reply to the article in the current buffer."
3753 (require 'gnus-sum
) ; for gnus-list-identifiers
3754 (let ((cur (current-buffer))
3755 from subject date reply-to to cc
3756 references message-id follow-to
3757 (inhibit-point-motion-hooks t
)
3758 (message-this-is-mail t
)
3761 (message-narrow-to-head)
3762 ;; Allow customizations to have their say.
3764 ;; This is a regular reply.
3765 (if (message-functionp message-reply-to-function
)
3766 (setq follow-to
(funcall message-reply-to-function
)))
3767 ;; This is a followup.
3768 (if (message-functionp message-wide-reply-to-function
)
3771 (funcall message-wide-reply-to-function
)))))
3772 (setq message-id
(message-fetch-field "message-id" t
)
3773 references
(message-fetch-field "references")
3774 date
(message-fetch-field "date")
3775 from
(message-fetch-field "from")
3776 subject
(or (message-fetch-field "subject") "none"))
3777 (if gnus-list-identifiers
3778 (setq subject
(message-strip-list-identifiers subject
)))
3779 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
3781 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3782 (string-match "<[^>]+>" gnus-warning
))
3783 (setq message-id
(match-string 0 gnus-warning
)))
3786 (setq follow-to
(message-get-reply-headers wide to-address
))))
3788 (message-pop-to-buffer
3789 (message-buffer-name
3790 (if wide
"wide reply" "reply") from
3791 (if wide to-address nil
)))
3793 (setq message-reply-headers
3794 (vector 0 subject from date message-id references
0 0 ""))
3797 `((Subject .
,subject
)
3799 ,@(if (or references message-id
)
3800 `((References .
,(concat (or references
"") (and references
" ")
3801 (or message-id
""))))
3806 (defun message-wide-reply (&optional to-address
)
3807 "Make a \"wide\" reply to the message in the current buffer."
3809 (message-reply to-address t
))
3812 (defun message-followup (&optional to-newsgroups
)
3813 "Follow up to the message in the current buffer.
3814 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3816 (require 'gnus-sum
) ; for gnus-list-identifiers
3817 (let ((cur (current-buffer))
3818 from subject date reply-to mct
3819 references message-id follow-to
3820 (inhibit-point-motion-hooks t
)
3821 (message-this-is-news t
)
3822 followup-to distribution newsgroups gnus-warning posted-to
)
3825 (goto-char (point-min))
3826 (if (search-forward "\n\n" nil t
)
3829 (when (message-functionp message-followup-to-function
)
3831 (funcall message-followup-to-function
)))
3832 (setq from
(message-fetch-field "from")
3833 date
(message-fetch-field "date")
3834 subject
(or (message-fetch-field "subject") "none")
3835 references
(message-fetch-field "references")
3836 message-id
(message-fetch-field "message-id" t
)
3837 followup-to
(message-fetch-field "followup-to")
3838 newsgroups
(message-fetch-field "newsgroups")
3839 posted-to
(message-fetch-field "posted-to")
3840 reply-to
(message-fetch-field "reply-to")
3841 distribution
(message-fetch-field "distribution")
3842 mct
(message-fetch-field "mail-copies-to"))
3843 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
3844 (string-match "<[^>]+>" gnus-warning
))
3845 (setq message-id
(match-string 0 gnus-warning
)))
3846 ;; Remove bogus distribution.
3847 (when (and (stringp distribution
)
3848 (let ((case-fold-search t
))
3849 (string-match "world" distribution
)))
3850 (setq distribution nil
))
3851 (if gnus-list-identifiers
3852 (setq subject
(message-strip-list-identifiers subject
)))
3853 (setq subject
(concat "Re: " (message-strip-subject-re subject
)))
3856 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
3859 `((Subject .
,subject
)
3862 (list (cons 'Newsgroups to-newsgroups
)))
3863 (follow-to follow-to
)
3864 ((and followup-to message-use-followup-to
)
3867 ((equal (downcase followup-to
) "poster")
3868 (if (or (eq message-use-followup-to
'use
)
3869 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
3870 You should normally obey the Followup-To: header.
3872 `Followup-To: poster' sends your response via e-mail instead of news.
3874 A typical situation where `Followup-To: poster' is used is when the poster
3875 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3877 (setq message-this-is-news nil
)
3878 (cons 'To
(or reply-to from
"")))
3879 (cons 'Newsgroups newsgroups
)))
3881 (if (or (equal followup-to newsgroups
)
3882 (not (eq message-use-followup-to
'ask
))
3884 (concat "Obey Followup-To: " followup-to
"? ") t
"\
3885 You should normally obey the Followup-To: header.
3887 `Followup-To: " followup-to
"'
3888 directs your response to " (if (string-match "," followup-to
)
3889 "the specified newsgroups"
3890 "that newsgroup only") ".
3892 If a message is posted to several newsgroups, Followup-To is often
3893 used to direct the following discussion to one newsgroup only,
3894 because discussions that are spread over several newsgroup tend to
3895 be fragmented and very difficult to follow.
3897 Also, some source/announcement newsgroups are not indented for discussion;
3898 responses here are directed to other newsgroups."))
3899 (cons 'Newsgroups followup-to
)
3900 (cons 'Newsgroups newsgroups
))))))
3902 `((Newsgroups .
,posted-to
)))
3904 `((Newsgroups .
,newsgroups
))))
3905 ,@(and distribution
(list (cons 'Distribution distribution
)))
3906 ,@(if (or references message-id
)
3907 `((References .
,(concat (or references
"") (and references
" ")
3908 (or message-id
"")))))
3910 (not (or (equal (downcase mct
) "never")
3911 (equal (downcase mct
) "nobody"))))
3912 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
3913 (equal (downcase mct
) "poster"))
3914 (or reply-to from
"")
3919 (setq message-reply-headers
3920 (vector 0 subject from date message-id references
0 0 ""))))
3924 (defun message-cancel-news (&optional arg
)
3925 "Cancel an article you posted.
3926 If ARG, allow editing of the cancellation message."
3928 (unless (message-news-p)
3929 (error "This is not a news article; canceling is impossible"))
3930 (when (yes-or-no-p "Do you really want to cancel this article? ")
3931 (let (from newsgroups message-id distribution buf sender
)
3933 ;; Get header info from original article.
3935 (message-narrow-to-head)
3936 (setq from
(message-fetch-field "from")
3937 sender
(message-fetch-field "sender")
3938 newsgroups
(message-fetch-field "newsgroups")
3939 message-id
(message-fetch-field "message-id" t
)
3940 distribution
(message-fetch-field "distribution")))
3941 ;; Make sure that this article was written by the user.
3942 (unless (or (and sender
3945 (downcase (message-make-sender))))
3947 (downcase (cadr (mail-extract-address-components from
)))
3948 (downcase (cadr (mail-extract-address-components
3949 (message-make-from))))))
3950 (error "This article is not yours"))
3951 ;; Make control message.
3954 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
3956 (insert "Newsgroups: " newsgroups
"\n"
3958 "Subject: cmsg cancel " message-id
"\n"
3959 "Control: cancel " message-id
"\n"
3961 (concat "Distribution: " distribution
"\n")
3963 mail-header-separator
"\n"
3964 message-cancel-message
)
3965 (run-hooks 'message-cancel-hook
)
3967 (message "Canceling your article...")
3968 (if (let ((message-syntax-checks
3969 'dont-check-for-anything-just-trust-me
))
3970 (funcall message-send-news-function
))
3971 (message "Canceling your article...done"))
3972 (kill-buffer buf
))))))
3975 (defun message-supersede ()
3976 "Start composing a message to supersede the current message.
3977 This is done simply by taking the old article and adding a Supersedes
3978 header line with the old Message-ID."
3980 (let ((cur (current-buffer))
3981 (sender (message-fetch-field "sender"))
3982 (from (message-fetch-field "from")))
3983 ;; Check whether the user owns the article that is to be superseded.
3984 (unless (or (and sender
3987 (downcase (message-make-sender))))
3989 (downcase (cadr (mail-extract-address-components from
)))
3990 (downcase (cadr (mail-extract-address-components
3991 (message-make-from))))))
3992 (error "This article is not yours"))
3993 ;; Get a normal message buffer.
3994 (message-pop-to-buffer (message-buffer-name "supersede"))
3995 (insert-buffer-substring cur
)
3997 (message-narrow-to-head)
3998 ;; Remove unwanted headers.
3999 (when message-ignored-supersedes-headers
4000 (message-remove-header message-ignored-supersedes-headers t
))
4001 (goto-char (point-min))
4002 (if (not (re-search-forward "^Message-ID: " nil t
))
4003 (error "No Message-ID in this article")
4004 (replace-match "Supersedes: " t t
))
4005 (goto-char (point-max))
4006 (insert mail-header-separator
)
4011 (defun message-recover ()
4012 "Reread contents of current buffer from its last auto-save file."
4014 (let ((file-name (make-auto-save-file-name)))
4015 (cond ((save-window-excursion
4016 (if (not (eq system-type
'vax-vms
))
4017 (with-output-to-temp-buffer "*Directory*"
4018 (with-current-buffer standard-output
4019 (fundamental-mode)) ; for Emacs 20.4+
4020 (buffer-disable-undo standard-output
)
4021 (let ((default-directory "/"))
4023 "ls" nil standard-output nil
"-l" file-name
))))
4024 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
4025 (let ((buffer-read-only nil
))
4027 (insert-file-contents file-name nil
)))
4028 (t (error "message-recover cancelled")))))
4030 ;;; Washing Subject:
4032 (defun message-wash-subject (subject)
4033 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4035 (insert-string subject
)
4036 (goto-char (point-min))
4037 ;; strip Re/Fwd stuff off the beginning
4038 (while (re-search-forward
4039 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
4042 ;; and gnus-style forwards [foo@bar.com] subject
4043 (goto-char (point-min))
4044 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
4048 (goto-char (point-max))
4049 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
4052 ;; and finally, any whitespace that was left-over
4053 (goto-char (point-min))
4054 (while (re-search-forward "^[ \t]+" nil t
)
4056 (goto-char (point-max))
4057 (while (re-search-backward "[ \t]+$" nil t
)
4062 ;;; Forwarding messages.
4064 (defun message-forward-subject-author-subject (subject)
4065 "Generate a subject for a forwarded message.
4066 The form is: [Source] Subject, where if the original message was mail,
4067 Source is the sender, and if the original message was news, Source is
4068 the list of newsgroups is was posted to."
4070 (or (message-fetch-field
4071 (if (message-news-p) "newsgroups" "from"))
4075 (defun message-forward-subject-fwd (subject)
4076 "Generate a subject for a forwarded message.
4077 The form is: Fwd: Subject, where Subject is the original subject of
4079 (concat "Fwd: " subject
))
4081 (defun message-make-forward-subject ()
4082 "Return a Subject header suitable for the message in the current buffer."
4086 (message-narrow-to-head)
4087 (let ((funcs message-make-forward-subject-function
)
4088 (subject (if message-wash-forwarded-subjects
4089 (message-wash-subject
4090 (or (message-fetch-field "Subject") ""))
4091 (or (message-fetch-field "Subject") ""))))
4092 ;; Make sure funcs is a list.
4095 (setq funcs
(list funcs
)))
4096 ;; Apply funcs in order, passing subject generated by previous
4097 ;; func to the next one.
4099 (when (message-functionp (car funcs
))
4100 (setq subject
(funcall (car funcs
) subject
)))
4101 (setq funcs
(cdr funcs
)))
4105 (defun message-forward (&optional news digest
)
4106 "Forward the current message via mail.
4107 Optional NEWS will use news to forward instead of mail.
4108 Optional DIGEST will use digest to forward."
4110 (let* ((cur (current-buffer))
4111 (subject (if message-forward-show-mml
4112 (message-make-forward-subject)
4113 (mail-decode-encoded-word-string
4114 (message-make-forward-subject))))
4117 (message-news nil subject
)
4118 (message-mail nil subject
))
4119 ;; Put point where we want it before inserting the forwarded
4121 (if message-forward-before-signature
4123 (goto-char (point-max)))
4124 (if message-forward-as-mime
4126 (insert "\n<#multipart type=digest>\n")
4127 (if message-forward-show-mml
4128 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4129 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4130 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4131 (let ((b (point)) e
)
4133 (if message-forward-as-mime
4134 (insert-buffer-substring cur
)
4135 (mml-insert-buffer cur
))
4136 (if message-forward-show-mml
4137 (insert-buffer-substring cur
)
4138 (mml-insert-buffer cur
)))
4140 (if message-forward-as-mime
4142 (insert "<#/multipart>\n")
4143 (if message-forward-show-mml
4144 (insert "<#/mml>\n")
4145 (insert "<#/part>\n")))
4146 (insert "\n-------------------- End of forwarded message --------------------\n"))
4147 (if (and digest message-forward-as-mime
)
4149 (narrow-to-region b e
)
4151 (narrow-to-region (point)
4152 (or (search-forward "\n\n" nil t
) (point)))
4153 (delete-region (point-min) (point-max)))
4154 (when (and (not current-prefix-arg
)
4155 message-forward-ignored-headers
)
4157 (narrow-to-region b e
)
4159 (narrow-to-region (point)
4160 (or (search-forward "\n\n" nil t
) (point)))
4161 (message-remove-header message-forward-ignored-headers t
)))))
4162 (message-position-point)))
4165 (defun message-resend (address)
4166 "Resend the current article to ADDRESS."
4168 (list (message-read-from-minibuffer "Resend message to: ")))
4169 (message "Resending message to %s..." address
)
4171 (let ((cur (current-buffer))
4173 ;; We first set up a normal mail buffer.
4174 (set-buffer (get-buffer-create " *message resend*"))
4176 (message-setup `((To .
,address
)))
4177 ;; Insert our usual headers.
4178 (message-generate-headers '(From Date To
))
4179 (message-narrow-to-headers)
4180 ;; Rename them all to "Resent-*".
4181 (while (re-search-forward "^[A-Za-z]" nil t
)
4186 (delete-region (point) (point-max))
4188 ;; Insert the message to be resent.
4189 (insert-buffer-substring cur
)
4190 (goto-char (point-min))
4191 (search-forward "\n\n")
4194 (narrow-to-region beg
(point))
4195 (message-remove-header message-ignored-resent-headers t
)
4196 (goto-char (point-max)))
4197 (insert mail-header-separator
)
4198 ;; Rename all old ("Also-")Resent headers.
4199 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
4202 ;; Quote any "From " lines at the beginning.
4204 (when (looking-at "From ")
4205 (replace-match "X-From-Line: "))
4207 (let ((message-inhibit-body-encoding t
)
4208 message-required-mail-headers
)
4209 (message-send-mail))
4210 (kill-buffer (current-buffer)))
4211 (message "Resending message to %s...done" address
)))
4214 (defun message-bounce ()
4215 "Re-mail the current message.
4216 This only makes sense if the current message is a bounce message that
4217 contains some mail you have written which has been bounced back to
4220 (let ((handles (mm-dissect-buffer t
))
4222 (message-pop-to-buffer (message-buffer-name "bounce"))
4223 (if (stringp (car handles
))
4224 ;; This is a MIME bounce.
4225 (mm-insert-part (car (last handles
)))
4226 ;; This is a non-MIME bounce, so we try to remove things
4228 (mm-insert-part handles
)
4230 (goto-char (point-min))
4231 (search-forward "\n\n" nil t
)
4232 (or (and (re-search-forward message-unsent-separator nil t
)
4234 (re-search-forward "^Return-Path:.*\n" nil t
))
4235 ;; We remove everything before the bounced mail.
4238 (if (re-search-forward "^[^ \n\t]+:" nil t
)
4241 (mm-enable-multibyte)
4244 (message-narrow-to-head)
4245 (message-remove-header message-ignored-bounced-headers t
)
4246 (goto-char (point-max))
4247 (insert mail-header-separator
))
4248 (message-position-point)))
4251 ;;; Interactive entry points for new message buffers.
4255 (defun message-mail-other-window (&optional to subject
)
4256 "Like `message-mail' command, but display mail buffer in another window."
4258 (let ((pop-up-windows t
)
4259 (special-display-buffer-names nil
)
4260 (special-display-regexps nil
)
4261 (same-window-buffer-names nil
)
4262 (same-window-regexps nil
))
4263 (message-pop-to-buffer (message-buffer-name "mail" to
)))
4264 (let ((message-this-is-mail t
))
4265 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
""))))))
4268 (defun message-mail-other-frame (&optional to subject
)
4269 "Like `message-mail' command, but display mail buffer in another frame."
4271 (let ((pop-up-frames t
)
4272 (special-display-buffer-names nil
)
4273 (special-display-regexps nil
)
4274 (same-window-buffer-names nil
)
4275 (same-window-regexps nil
))
4276 (message-pop-to-buffer (message-buffer-name "mail" to
)))
4277 (let ((message-this-is-mail t
))
4278 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
""))))))
4281 (defun message-news-other-window (&optional newsgroups subject
)
4282 "Start editing a news article to be sent."
4284 (let ((pop-up-windows t
)
4285 (special-display-buffer-names nil
)
4286 (special-display-regexps nil
)
4287 (same-window-buffer-names nil
)
4288 (same-window-regexps nil
))
4289 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
4290 (let ((message-this-is-news t
))
4291 (message-setup `((Newsgroups .
,(or newsgroups
""))
4292 (Subject .
,(or subject
""))))))
4295 (defun message-news-other-frame (&optional newsgroups subject
)
4296 "Start editing a news article to be sent."
4298 (let ((pop-up-frames t
)
4299 (special-display-buffer-names nil
)
4300 (special-display-regexps nil
)
4301 (same-window-buffer-names nil
)
4302 (same-window-regexps nil
))
4303 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups
)))
4304 (let ((message-this-is-news t
))
4305 (message-setup `((Newsgroups .
,(or newsgroups
""))
4306 (Subject .
,(or subject
""))))))
4310 ;; This code should be moved to underline.el (from which it is stolen).
4313 (defun bold-region (start end
)
4314 "Bold all nonblank characters in the region.
4315 Works by overstriking characters.
4316 Called from program, takes two arguments START and END
4317 which specify the range to operate on."
4320 (let ((end1 (make-marker)))
4321 (move-marker end1
(max start end
))
4322 (goto-char (min start end
))
4323 (while (< (point) end1
)
4324 (or (looking-at "[_\^@- ]")
4325 (insert (char-after) "\b"))
4326 (forward-char 1)))))
4329 (defun unbold-region (start end
)
4330 "Remove all boldness (overstruck characters) in the region.
4331 Called from program, takes two arguments START and END
4332 which specify the range to operate on."
4335 (let ((end1 (make-marker)))
4336 (move-marker end1
(max start end
))
4337 (goto-char (min start end
))
4338 (while (re-search-forward "\b" end1 t
)
4339 (if (eq (char-after) (char-after (- (point) 2)))
4340 (delete-char -
2))))))
4342 (defalias 'message-exchange-point-and-mark
'exchange-point-and-mark
)
4344 ;; Support for toolbar
4345 (eval-when-compile (defvar tool-bar-map
))
4346 (if (featurep 'xemacs
)
4347 (require 'messagexmas
)
4348 (when (and (fboundp 'tool-bar-add-item-from-menu
)
4350 (defvar message-tool-bar-map
4351 (let ((tool-bar-map (copy-keymap tool-bar-map
)))
4352 ;; Zap some items which aren't so relevant and take up space.
4353 (dolist (key '(print-buffer kill-buffer save-buffer write-file
4355 (define-key tool-bar-map
(vector key
) nil
))
4357 (tool-bar-add-item-from-menu
4358 'message-send-and-exit
"mail_send" message-mode-map
)
4359 (tool-bar-add-item-from-menu
4360 'message-kill-buffer
"close" message-mode-map
)
4361 (tool-bar-add-item-from-menu
4362 'message-dont-send
"cancel" message-mode-map
)
4363 (tool-bar-add-item-from-menu
4364 'mml-attach-file
"attach" message-mode-map
)
4365 (tool-bar-add-item-from-menu
4366 'ispell-message
"spell" message-mode-map
)
4369 ;;; Group name completion.
4371 (defvar message-newgroups-header-regexp
4372 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4373 "Regexp that match headers that lists groups.")
4375 (defun message-tab ()
4376 "Expand group names in Newsgroups and Followup-To headers.
4377 Do a `tab-to-tab-stop' if not in those headers."
4379 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp
))
4380 (mail-abbrev-in-expansion-header-p))
4381 (message-expand-group)
4384 (defun message-expand-group ()
4385 "Expand the group name under point."
4386 (let* ((b (save-excursion
4391 (skip-chars-forward "^:")
4394 (skip-chars-backward "^, \t\n") (point))))
4395 (completion-ignore-case t
)
4396 (string (buffer-substring b
(progn (skip-chars-forward "^,\t\n ")
4398 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
))
4399 (completions (all-completions string hashtb
))
4401 (delete-region b
(point))
4403 ((= (length completions
) 1)
4404 (if (string= (car completions
) string
)
4407 (message "Only matching group"))
4408 (insert (car completions
))))
4409 ((and (setq comp
(try-completion string hashtb
))
4410 (not (string= comp string
)))
4415 (message "No matching groups")
4416 (save-selected-window
4417 (pop-to-buffer "*Completions*")
4418 (buffer-disable-undo)
4419 (let ((buffer-read-only nil
))
4421 (let ((standard-output (current-buffer)))
4422 (display-completion-list (sort completions
'string
<)))
4423 (goto-char (point-min))
4424 (delete-region (point) (progn (forward-line 3) (point))))))))))
4428 (defun message-talkative-question (ask question show
&rest text
)
4429 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4430 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4431 The following arguments may contain lists of values."
4433 (setq text
(message-flatten-list text
)))
4434 (save-window-excursion
4436 (with-output-to-temp-buffer " *MESSAGE information message*"
4437 (set-buffer " *MESSAGE information message*")
4438 (fundamental-mode) ; for Emacs 20.4+
4439 (mapcar 'princ text
)
4440 (goto-char (point-min))))
4441 (funcall ask question
))
4442 (funcall ask question
)))
4444 (defun message-flatten-list (list)
4445 "Return a new, flat list that contains all elements of LIST.
4447 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4450 (apply 'append
(mapcar 'message-flatten-list list
)))
4454 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
4455 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4456 Then clone the local variables and values from the old buffer to the
4457 new one, cloning only the locals having a substring matching the
4459 (let ((oldbuf (current-buffer)))
4461 (set-buffer (generate-new-buffer name
))
4462 (message-clone-locals oldbuf varstr
)
4465 (defun message-clone-locals (buffer &optional varstr
)
4466 "Clone the local variables from BUFFER to the current buffer."
4467 (let ((locals (save-excursion
4469 (buffer-local-variables)))
4470 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4473 (when (and (consp local
)
4475 (string-match regexp
(symbol-name (car local
)))
4477 (string-match varstr
(symbol-name (car local
)))))
4479 (set (make-local-variable (car local
))
4483 ;;; Miscellaneous functions
4485 ;; stolen (and renamed) from nnheader.el
4486 (if (fboundp 'subst-char-in-string
)
4487 (defsubst message-replace-chars-in-string
(string from to
)
4488 (subst-char-in-string from to string
))
4489 (defun message-replace-chars-in-string (string from to
)
4490 "Replace characters in STRING from FROM to TO."
4491 (let ((string (substring string
0)) ;Copy string.
4492 (len (length string
))
4494 ;; Replace all occurrences of FROM with TO.
4496 (when (= (aref string idx
) from
)
4497 (aset string idx to
))
4498 (setq idx
(1+ idx
)))
4505 (defvar message-inhibit-body-encoding nil
)
4507 (defun message-encode-message-body ()
4508 (unless message-inhibit-body-encoding
4509 (let ((mail-parse-charset (or mail-parse-charset
4510 message-default-charset
))
4511 (case-fold-search t
)
4512 lines content-type-p
)
4515 (narrow-to-region (point) (point-max))
4516 (let ((new (mml-generate-mime)))
4518 (delete-region (point-min) (point-max))
4520 (goto-char (point-min))
4521 (if (eq (aref new
0) ?
\n)
4523 (search-forward "\n\n")
4524 (setq lines
(buffer-substring (point-min) (1- (point))))
4525 (delete-region (point-min) (point))))))
4527 (message-narrow-to-headers-or-head)
4528 (message-remove-header "Mime-Version")
4529 (goto-char (point-max))
4530 (insert "MIME-Version: 1.0\n")
4533 (setq content-type-p
4534 (re-search-backward "^Content-Type:" nil t
)))
4536 (message-narrow-to-headers-or-head)
4537 (message-remove-first-header "Content-Type")
4538 (message-remove-first-header "Content-Transfer-Encoding"))
4539 ;; We always make sure that the message has a Content-Type header.
4540 ;; This is because some broken MTAs and MUAs get awfully confused
4541 ;; when confronted with a message with a MIME-Version header and
4542 ;; without a Content-Type header. For instance, Solaris'
4544 (unless content-type-p
4545 (goto-char (point-min))
4546 (re-search-forward "^MIME-Version:")
4548 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4550 (defun message-read-from-minibuffer (prompt)
4551 "Read from the minibuffer while providing abbrev expansion."
4552 (if (fboundp 'mail-abbrevs-setup
)
4553 (let ((mail-abbrev-mode-regexp "")
4554 (minibuffer-setup-hook 'mail-abbrevs-setup
))
4555 (read-from-minibuffer prompt
))
4556 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
))
4557 (read-string prompt
))))
4559 (defun message-use-alternative-email-as-from ()
4560 (require 'mail-utils
)
4561 (let* ((fields '("To" "Cc"))
4564 (mail-strip-quoted-names
4565 (mapconcat 'message-fetch-reply-field fields
","))
4569 (if (string-match message-alternative-emails
(car emails
))
4570 (setq email
(car emails
)
4573 (unless (or (not email
) (equal email user-mail-address
))
4574 (goto-char (point-max))
4575 (insert "From: " email
"\n"))))
4579 (run-hooks 'message-load-hook
)
4582 ;; coding: iso-8859-1
4585 ;;; message.el ends here