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