Mercurial > emacs
annotate lisp/gnus/message.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | f6ca32374b0b |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; message.el --- composing mail and news messages |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: mail, news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;; This mode provides mail-sending facilities from within Emacs. It | |
27 ;; consists mainly of large chunks of code from the sendmail.el, | |
28 ;; gnus-msg.el and rnewspost.el files. | |
29 | |
30 ;;; Code: | |
31 | |
19525
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
32 (eval-when-compile (require 'cl)) |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
33 |
17493 | 34 (require 'mailheader) |
35 (require 'rmail) | |
36 (require 'nnheader) | |
37 (require 'timezone) | |
38 (require 'easymenu) | |
39 (require 'custom) | |
40 (if (string-match "XEmacs\\|Lucid" emacs-version) | |
41 (require 'mail-abbrevs) | |
42 (require 'mailabbrev)) | |
43 | |
44 (defgroup message '((user-mail-address custom-variable) | |
45 (user-full-name custom-variable)) | |
46 "Mail and news message composing." | |
47 :link '(custom-manual "(message)Top") | |
48 :group 'mail | |
49 :group 'news) | |
50 | |
51 (put 'user-mail-address 'custom-type 'string) | |
52 (put 'user-full-name 'custom-type 'string) | |
53 | |
54 (defgroup message-various nil | |
55 "Various Message Variables" | |
56 :link '(custom-manual "(message)Various Message Variables") | |
57 :group 'message) | |
58 | |
59 (defgroup message-buffers nil | |
60 "Message Buffers" | |
61 :link '(custom-manual "(message)Message Buffers") | |
62 :group 'message) | |
63 | |
64 (defgroup message-sending nil | |
65 "Message Sending" | |
66 :link '(custom-manual "(message)Sending Variables") | |
67 :group 'message) | |
68 | |
69 (defgroup message-interface nil | |
70 "Message Interface" | |
71 :link '(custom-manual "(message)Interface") | |
72 :group 'message) | |
73 | |
74 (defgroup message-forwarding nil | |
75 "Message Forwarding" | |
76 :link '(custom-manual "(message)Forwarding") | |
77 :group 'message-interface) | |
78 | |
79 (defgroup message-insertion nil | |
80 "Message Insertion" | |
81 :link '(custom-manual "(message)Insertion") | |
82 :group 'message) | |
83 | |
84 (defgroup message-headers nil | |
85 "Message Headers" | |
86 :link '(custom-manual "(message)Message Headers") | |
87 :group 'message) | |
88 | |
89 (defgroup message-news nil | |
90 "Composing News Messages" | |
91 :group 'message) | |
92 | |
93 (defgroup message-mail nil | |
94 "Composing Mail Messages" | |
95 :group 'message) | |
96 | |
97 (defgroup message-faces nil | |
98 "Faces used for message composing." | |
99 :group 'message | |
100 :group 'faces) | |
101 | |
102 (defcustom message-directory "~/Mail/" | |
103 "*Directory from which all other mail file variables are derived." | |
104 :group 'message-various | |
105 :type 'directory) | |
106 | |
107 (defcustom message-max-buffers 10 | |
108 "*How many buffers to keep before starting to kill them off." | |
109 :group 'message-buffers | |
110 :type 'integer) | |
111 | |
112 (defcustom message-send-rename-function nil | |
113 "Function called to rename the buffer after sending it." | |
114 :group 'message-buffers | |
115 :type 'function) | |
116 | |
117 (defcustom message-fcc-handler-function 'message-output | |
118 "*A function called to save outgoing articles. | |
119 This function will be called with the name of the file to store the | |
120 article in. The default function is `message-output' which saves in Unix | |
121 mailbox format." | |
122 :type '(radio (function-item message-output) | |
123 (function :tag "Other")) | |
124 :group 'message-sending) | |
125 | |
126 (defcustom message-courtesy-message | |
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n" | |
128 "*This is inserted at the start of a mailed copy of a posted message. | |
129 If the string contains the format spec \"%s\", the Newsgroups | |
130 the article has been posted to will be inserted there. | |
131 If this variable is nil, no such courtesy message will be added." | |
132 :group 'message-sending | |
133 :type 'string) | |
134 | |
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):" | |
136 "*Regexp that matches headers to be removed in resent bounced mail." | |
137 :group 'message-interface | |
138 :type 'regexp) | |
139 | |
140 ;;;###autoload | |
141 (defcustom message-from-style 'default | |
142 "*Specifies how \"From\" headers look. | |
143 | |
144 If `nil', they contain just the return address like: | |
145 king@grassland.com | |
146 If `parens', they look like: | |
147 king@grassland.com (Elvis Parsley) | |
148 If `angles', they look like: | |
149 Elvis Parsley <king@grassland.com> | |
150 | |
151 Otherwise, most addresses look like `angles', but they look like | |
152 `parens' if `angles' would need quoting and `parens' would not." | |
153 :type '(choice (const :tag "simple" nil) | |
154 (const parens) | |
155 (const angles) | |
156 (const default)) | |
157 :group 'message-headers) | |
158 | |
159 (defcustom message-syntax-checks nil | |
160 ;; Guess this one shouldn't be easy to customize... | |
161 "Controls what syntax checks should not be performed on outgoing posts. | |
162 To disable checking of long signatures, for instance, add | |
163 `(signature . disabled)' to this list. | |
164 | |
165 Don't touch this variable unless you really know what you're doing. | |
166 | |
167 Checks include subject-cmsg multiple-headers sendsys message-id from | |
168 long-lines control-chars size new-text redirected-followup signature | |
169 approved sender empty empty-headers message-id from subject | |
170 shorten-followup-to existing-newsgroups." | |
171 :group 'message-news) | |
172 | |
173 (defcustom message-required-news-headers | |
174 '(From Newsgroups Subject Date Message-ID | |
175 (optional . Organization) Lines | |
176 (optional . X-Newsreader)) | |
177 "Headers to be generated or prompted for when posting an article. | |
178 RFC977 and RFC1036 require From, Date, Newsgroups, Subject, | |
179 Message-ID. Organization, Lines, In-Reply-To, Expires, and | |
180 X-Newsreader are optional. If don't you want message to insert some | |
181 header, remove it from this list." | |
182 :group 'message-news | |
183 :group 'message-headers | |
184 :type '(repeat sexp)) | |
185 | |
186 (defcustom message-required-mail-headers | |
187 '(From Subject Date (optional . In-Reply-To) Message-ID Lines | |
188 (optional . X-Mailer)) | |
189 "Headers to be generated or prompted for when mailing a message. | |
190 RFC822 required that From, Date, To, Subject and Message-ID be | |
191 included. Organization, Lines and X-Mailer are optional." | |
192 :group 'message-mail | |
193 :group 'message-headers | |
194 :type '(repeat sexp)) | |
195 | |
196 (defcustom message-deletable-headers '(Message-ID Date Lines) | |
197 "Headers to be deleted if they already exist and were generated by message previously." | |
198 :group 'message-headers | |
199 :type 'sexp) | |
200 | |
201 (defcustom message-ignored-news-headers | |
202 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:\\|^Resent-Fcc:" | |
203 "*Regexp of headers to be removed unconditionally before posting." | |
204 :group 'message-news | |
205 :group 'message-headers | |
206 :type 'regexp) | |
207 | |
208 (defcustom message-ignored-mail-headers "^Gcc:\\|^Fcc:\\|^Resent-Fcc:" | |
209 "*Regexp of headers to be removed unconditionally before mailing." | |
210 :group 'message-mail | |
211 :group 'message-headers | |
212 :type 'regexp) | |
213 | |
214 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:\\|^Supersedes:" | |
215 "*Header lines matching this regexp will be deleted before posting. | |
216 It's best to delete old Path and Date headers before posting to avoid | |
217 any confusion." | |
218 :group 'message-interface | |
219 :type 'regexp) | |
220 | |
221 ;;;###autoload | |
222 (defcustom message-signature-separator "^-- *$" | |
223 "Regexp matching the signature separator." | |
224 :type 'regexp | |
225 :group 'message-various) | |
226 | |
227 (defcustom message-elide-elipsis "\n[...]\n\n" | |
228 "*The string which is inserted for elided text.") | |
229 | |
230 (defcustom message-interactive nil | |
231 "Non-nil means when sending a message wait for and display errors. | |
232 nil means let mailer mail back a message to report errors." | |
233 :group 'message-sending | |
234 :group 'message-mail | |
235 :type 'boolean) | |
236 | |
237 (defcustom message-generate-new-buffers t | |
238 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called. | |
239 If this is a function, call that function with three parameters: The type, | |
240 the to address and the group name. (Any of these may be nil.) The function | |
241 should return the new buffer name." | |
242 :group 'message-buffers | |
243 :type '(choice (const :tag "off" nil) | |
244 (const :tag "on" t) | |
245 (function fun))) | |
246 | |
247 (defcustom message-kill-buffer-on-exit nil | |
248 "*Non-nil means that the message buffer will be killed after sending a message." | |
249 :group 'message-buffers | |
250 :type 'boolean) | |
251 | |
252 (defvar gnus-local-organization) | |
253 (defcustom message-user-organization | |
254 (or (and (boundp 'gnus-local-organization) | |
255 (stringp gnus-local-organization) | |
256 gnus-local-organization) | |
257 (getenv "ORGANIZATION") | |
258 t) | |
259 "*String to be used as an Organization header. | |
260 If t, use `message-user-organization-file'." | |
261 :group 'message-headers | |
262 :type '(choice string | |
263 (const :tag "consult file" t))) | |
264 | |
265 ;;;###autoload | |
266 (defcustom message-user-organization-file "/usr/lib/news/organization" | |
267 "*Local news organization file." | |
268 :type 'file | |
269 :group 'message-headers) | |
270 | |
271 (defcustom message-autosave-directory "~/" | |
272 ; (concat (file-name-as-directory message-directory) "drafts/") | |
273 "*Directory where message autosaves buffers. | |
274 If nil, message won't autosave." | |
275 :group 'message-buffers | |
276 :type 'directory) | |
277 | |
278 (defcustom message-forward-start-separator | |
279 "------- Start of forwarded message -------\n" | |
280 "*Delimiter inserted before forwarded messages." | |
281 :group 'message-forwarding | |
282 :type 'string) | |
283 | |
284 (defcustom message-forward-end-separator | |
285 "------- End of forwarded message -------\n" | |
286 "*Delimiter inserted after forwarded messages." | |
287 :group 'message-forwarding | |
288 :type 'string) | |
289 | |
290 (defcustom message-signature-before-forwarded-message t | |
291 "*If non-nil, put the signature before any included forwarded message." | |
292 :group 'message-forwarding | |
293 :type 'boolean) | |
294 | |
295 (defcustom message-included-forward-headers | |
296 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:" | |
297 "*Regexp matching headers to be included in forwarded messages." | |
298 :group 'message-forwarding | |
299 :type 'regexp) | |
300 | |
301 (defcustom message-ignored-resent-headers "^Return-receipt" | |
302 "*All headers that match this regexp will be deleted when resending a message." | |
303 :group 'message-interface | |
304 :type 'regexp) | |
305 | |
306 (defcustom message-ignored-cited-headers "." | |
307 "*Delete these headers from the messages you yank." | |
308 :group 'message-insertion | |
309 :type 'regexp) | |
310 | |
311 (defcustom message-cancel-message "I am canceling my own article." | |
312 "Message to be inserted in the cancel message." | |
313 :group 'message-interface | |
314 :type 'string) | |
315 | |
316 ;; Useful to set in site-init.el | |
317 ;;;###autoload | |
318 (defcustom message-send-mail-function 'message-send-mail-with-sendmail | |
319 "Function to call to send the current buffer as mail. | |
320 The headers should be delimited by a line whose contents match the | |
321 variable `mail-header-separator'. | |
322 | |
323 Legal values include `message-send-mail-with-sendmail' (the default), | |
324 `message-send-mail-with-mh' and `message-send-mail-with-qmail'." | |
325 :type '(radio (function-item message-send-mail-with-sendmail) | |
326 (function-item message-send-mail-with-mh) | |
327 (function-item message-send-mail-with-qmail) | |
328 (function :tag "Other")) | |
329 :group 'message-sending | |
330 :group 'message-mail) | |
331 | |
332 (defcustom message-send-news-function 'message-send-news | |
333 "Function to call to send the current buffer as news. | |
334 The headers should be delimited by a line whose contents match the | |
335 variable `mail-header-separator'." | |
336 :group 'message-sending | |
337 :group 'message-news | |
338 :type 'function) | |
339 | |
340 (defcustom message-reply-to-function nil | |
341 "Function that should return a list of headers. | |
342 This function should pick out addresses from the To, Cc, and From headers | |
343 and respond with new To and Cc headers." | |
344 :group 'message-interface | |
345 :type 'function) | |
346 | |
347 (defcustom message-wide-reply-to-function nil | |
348 "Function that should return a list of headers. | |
349 This function should pick out addresses from the To, Cc, and From headers | |
350 and respond with new To and Cc headers." | |
351 :group 'message-interface | |
352 :type 'function) | |
353 | |
354 (defcustom message-followup-to-function nil | |
355 "Function that should return a list of headers. | |
356 This function should pick out addresses from the To, Cc, and From headers | |
357 and respond with new To and Cc headers." | |
358 :group 'message-interface | |
359 :type 'function) | |
360 | |
361 (defcustom message-use-followup-to 'ask | |
362 "*Specifies what to do with Followup-To header. | |
363 If nil, always ignore the header. If it is t, use its value, but | |
364 query before using the \"poster\" value. If it is the symbol `ask', | |
365 always query the user whether to use the value. If it is the symbol | |
366 `use', always use the value." | |
367 :group 'message-interface | |
368 :type '(choice (const :tag "ignore" nil) | |
369 (const use) | |
370 (const ask))) | |
371 | |
372 ;; stuff relating to broken sendmail in MMDF | |
373 (defcustom message-sendmail-f-is-evil nil | |
374 "*Non-nil means that \"-f username\" should not be added to the sendmail | |
375 command line, because it is even more evil than leaving it out." | |
376 :group 'message-sending | |
377 :type 'boolean) | |
378 | |
379 ;; qmail-related stuff | |
380 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject" | |
381 "Location of the qmail-inject program." | |
382 :group 'message-sending | |
383 :type 'file) | |
384 | |
385 (defcustom message-qmail-inject-args nil | |
386 "Arguments passed to qmail-inject programs. | |
387 This should be a list of strings, one string for each argument. | |
388 | |
389 For e.g., if you wish to set the envelope sender address so that bounces | |
390 go to the right place or to deal with listserv's usage of that address, you | |
391 might set this variable to '(\"-f\" \"you@some.where\")." | |
392 :group 'message-sending | |
393 :type '(repeat string)) | |
394 | |
395 (defvar gnus-post-method) | |
396 (defvar gnus-select-method) | |
397 (defcustom message-post-method | |
398 (cond ((and (boundp 'gnus-post-method) | |
399 gnus-post-method) | |
400 gnus-post-method) | |
401 ((boundp 'gnus-select-method) | |
402 gnus-select-method) | |
403 (t '(nnspool ""))) | |
404 "Method used to post news." | |
405 :group 'message-news | |
406 :group 'message-sending | |
407 ;; This should be the `gnus-select-method' widget, but that might | |
408 ;; create a dependence to `gnus.el'. | |
409 :type 'sexp) | |
410 | |
411 (defcustom message-generate-headers-first nil | |
412 "*If non-nil, generate all possible headers before composing." | |
413 :group 'message-headers | |
414 :type 'boolean) | |
415 | |
416 (defcustom message-setup-hook nil | |
417 "Normal hook, run each time a new outgoing message is initialized. | |
418 The function `message-setup' runs this hook." | |
419 :group 'message-various | |
420 :type 'hook) | |
421 | |
422 (defcustom message-signature-setup-hook nil | |
423 "Normal hook, run each time a new outgoing message is initialized. | |
424 It is run after the headers have been inserted and before | |
425 the signature is inserted." | |
426 :group 'message-various | |
427 :type 'hook) | |
428 | |
429 (defcustom message-mode-hook nil | |
430 "Hook run in message mode buffers." | |
431 :group 'message-various | |
432 :type 'hook) | |
433 | |
434 (defcustom message-header-hook nil | |
435 "Hook run in a message mode buffer narrowed to the headers." | |
436 :group 'message-various | |
437 :type 'hook) | |
438 | |
439 (defcustom message-header-setup-hook nil | |
440 "Hook called narrowed to the headers when setting up a message | |
441 buffer." | |
442 :group 'message-various | |
443 :type 'hook) | |
444 | |
445 ;;;###autoload | |
446 (defcustom message-citation-line-function 'message-insert-citation-line | |
447 "*Function called to insert the \"Whomever writes:\" line." | |
448 :type 'function | |
449 :group 'message-insertion) | |
450 | |
451 ;;;###autoload | |
452 (defcustom message-yank-prefix "> " | |
453 "*Prefix inserted on the lines of yanked messages. | |
454 nil means use indentation." | |
455 :type 'string | |
456 :group 'message-insertion) | |
457 | |
458 (defcustom message-indentation-spaces 3 | |
459 "*Number of spaces to insert at the beginning of each cited line. | |
460 Used by `message-yank-original' via `message-yank-cite'." | |
461 :group 'message-insertion | |
462 :type 'integer) | |
463 | |
464 ;;;###autoload | |
465 (defcustom message-cite-function | |
466 (if (and (boundp 'mail-citation-hook) | |
467 mail-citation-hook) | |
468 mail-citation-hook | |
469 'message-cite-original) | |
470 "*Function for citing an original message." | |
471 :type '(radio (function-item message-cite-original) | |
472 (function-item sc-cite-original) | |
473 (function :tag "Other")) | |
474 :group 'message-insertion) | |
475 | |
476 ;;;###autoload | |
477 (defcustom message-indent-citation-function 'message-indent-citation | |
478 "*Function for modifying a citation just inserted in the mail buffer. | |
479 This can also be a list of functions. Each function can find the | |
480 citation between (point) and (mark t). And each function should leave | |
481 point and mark around the citation text as modified." | |
482 :type 'function | |
483 :group 'message-insertion) | |
484 | |
485 (defvar message-abbrevs-loaded nil) | |
486 | |
487 ;;;###autoload | |
488 (defcustom message-signature t | |
489 "*String to be inserted at the end of the message buffer. | |
490 If t, the `message-signature-file' file will be inserted instead. | |
491 If a function, the result from the function will be used instead. | |
492 If a form, the result from the form will be used instead." | |
493 :type 'sexp | |
494 :group 'message-insertion) | |
495 | |
496 ;;;###autoload | |
497 (defcustom message-signature-file "~/.signature" | |
498 "*File containing the text inserted at end of message buffer." | |
499 :type 'file | |
500 :group 'message-insertion) | |
501 | |
502 (defcustom message-distribution-function nil | |
503 "*Function called to return a Distribution header." | |
504 :group 'message-news | |
505 :group 'message-headers | |
506 :type 'function) | |
507 | |
508 (defcustom message-expires 14 | |
509 "Number of days before your article expires." | |
510 :group 'message-news | |
511 :group 'message-headers | |
512 :link '(custom-manual "(message)News Headers") | |
513 :type 'integer) | |
514 | |
515 (defcustom message-user-path nil | |
516 "If nil, use the NNTP server name in the Path header. | |
517 If stringp, use this; if non-nil, use no host name (user name only)." | |
518 :group 'message-news | |
519 :group 'message-headers | |
520 :link '(custom-manual "(message)News Headers") | |
521 :type '(choice (const :tag "nntp" nil) | |
522 (string :tag "name") | |
523 (sexp :tag "none" :format "%t" t))) | |
524 | |
525 (defvar message-reply-buffer nil) | |
526 (defvar message-reply-headers nil) | |
527 (defvar message-newsreader nil) | |
528 (defvar message-mailer nil) | |
529 (defvar message-sent-message-via nil) | |
530 (defvar message-checksum nil) | |
531 (defvar message-send-actions nil | |
532 "A list of actions to be performed upon successful sending of a message.") | |
533 (defvar message-exit-actions nil | |
534 "A list of actions to be performed upon exiting after sending a message.") | |
535 (defvar message-kill-actions nil | |
536 "A list of actions to be performed before killing a message buffer.") | |
537 (defvar message-postpone-actions nil | |
538 "A list of actions to be performed after postponing a message.") | |
539 | |
540 (defcustom message-default-headers "" | |
541 "*A string containing header lines to be inserted in outgoing messages. | |
542 It is inserted before you edit the message, so you can edit or delete | |
543 these lines." | |
544 :group 'message-headers | |
545 :type 'string) | |
546 | |
547 (defcustom message-default-mail-headers "" | |
548 "*A string of header lines to be inserted in outgoing mails." | |
549 :group 'message-headers | |
550 :group 'message-mail | |
551 :type 'string) | |
552 | |
553 (defcustom message-default-news-headers "" | |
554 "*A string of header lines to be inserted in outgoing news | |
555 articles." | |
556 :group 'message-headers | |
557 :group 'message-news | |
558 :type 'string) | |
559 | |
560 ;; Note: could use /usr/ucb/mail instead of sendmail; | |
561 ;; options -t, and -v if not interactive. | |
562 (defcustom message-mailer-swallows-blank-line | |
563 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" | |
564 system-configuration) | |
565 (file-readable-p "/etc/sendmail.cf") | |
566 (let ((buffer (get-buffer-create " *temp*"))) | |
567 (unwind-protect | |
568 (save-excursion | |
569 (set-buffer buffer) | |
570 (insert-file-contents "/etc/sendmail.cf") | |
571 (goto-char (point-min)) | |
572 (let ((case-fold-search nil)) | |
573 (re-search-forward "^OR\\>" nil t))) | |
574 (kill-buffer buffer)))) | |
575 ;; According to RFC822, "The field-name must be composed of printable | |
576 ;; ASCII characters (i. e., characters that have decimal values between | |
577 ;; 33 and 126, except colon)", i. e., any chars except ctl chars, | |
578 ;; space, or colon. | |
579 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:")) | |
580 "Set this non-nil if the system's mailer runs the header and body together. | |
581 \(This problem exists on Sunos 4 when sendmail is run in remote mode.) | |
582 The value should be an expression to test whether the problem will | |
583 actually occur." | |
584 :group 'message-sending | |
585 :type 'sexp) | |
586 | |
19525
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
587 ;; Ignore errors in case this is used in Emacs 19. |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
588 ;; Don't use ignore-errors because this is copied into loaddefs.el. |
19481
4d492290e085
(message-user-agent): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
589 ;;;###autoload |
19525
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
590 (condition-case nil |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
591 (define-mail-user-agent 'message-user-agent |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
592 'message-mail 'message-send-and-exit |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
593 'message-kill-buffer 'message-send-hook) |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
594 (error nil)) |
17493 | 595 |
596 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender) | |
597 "If non-nil, delete the deletable headers before feeding to mh.") | |
598 | |
599 ;;; Internal variables. | |
600 ;;; Well, not really internal. | |
601 | |
602 (defvar message-mode-syntax-table | |
603 (let ((table (copy-syntax-table text-mode-syntax-table))) | |
604 (modify-syntax-entry ?% ". " table) | |
605 table) | |
606 "Syntax table used while in Message mode.") | |
607 | |
608 (defvar message-mode-abbrev-table text-mode-abbrev-table | |
609 "Abbrev table used in Message mode buffers. | |
610 Defaults to `text-mode-abbrev-table'.") | |
611 (defgroup message-headers nil | |
612 "Message headers." | |
613 :link '(custom-manual "(message)Variables") | |
614 :group 'message) | |
615 | |
616 (defface message-header-to-face | |
617 '((((class color) | |
618 (background dark)) | |
619 (:foreground "green2" :bold t)) | |
620 (((class color) | |
621 (background light)) | |
622 (:foreground "MidnightBlue" :bold t)) | |
623 (t | |
624 (:bold t :italic t))) | |
625 "Face used for displaying From headers." | |
626 :group 'message-faces) | |
627 | |
628 (defface message-header-cc-face | |
629 '((((class color) | |
630 (background dark)) | |
631 (:foreground "green4" :bold t)) | |
632 (((class color) | |
633 (background light)) | |
634 (:foreground "MidnightBlue")) | |
635 (t | |
636 (:bold t))) | |
637 "Face used for displaying Cc headers." | |
638 :group 'message-faces) | |
639 | |
640 (defface message-header-subject-face | |
641 '((((class color) | |
642 (background dark)) | |
643 (:foreground "green3")) | |
644 (((class color) | |
645 (background light)) | |
646 (:foreground "navy blue" :bold t)) | |
647 (t | |
648 (:bold t))) | |
649 "Face used for displaying subject headers." | |
650 :group 'message-faces) | |
651 | |
652 (defface message-header-newsgroups-face | |
653 '((((class color) | |
654 (background dark)) | |
655 (:foreground "yellow" :bold t :italic t)) | |
656 (((class color) | |
657 (background light)) | |
658 (:foreground "blue4" :bold t :italic t)) | |
659 (t | |
660 (:bold t :italic t))) | |
661 "Face used for displaying newsgroups headers." | |
662 :group 'message-faces) | |
663 | |
664 (defface message-header-other-face | |
665 '((((class color) | |
666 (background dark)) | |
667 (:foreground "red4")) | |
668 (((class color) | |
669 (background light)) | |
670 (:foreground "steel blue")) | |
671 (t | |
672 (:bold t :italic t))) | |
673 "Face used for displaying newsgroups headers." | |
674 :group 'message-faces) | |
675 | |
676 (defface message-header-name-face | |
677 '((((class color) | |
678 (background dark)) | |
679 (:foreground "DarkGreen")) | |
680 (((class color) | |
681 (background light)) | |
682 (:foreground "cornflower blue")) | |
683 (t | |
684 (:bold t))) | |
685 "Face used for displaying header names." | |
686 :group 'message-faces) | |
687 | |
688 (defface message-header-xheader-face | |
689 '((((class color) | |
690 (background dark)) | |
691 (:foreground "blue")) | |
692 (((class color) | |
693 (background light)) | |
694 (:foreground "blue")) | |
695 (t | |
696 (:bold t))) | |
697 "Face used for displaying X-Header headers." | |
698 :group 'message-faces) | |
699 | |
700 (defface message-separator-face | |
701 '((((class color) | |
702 (background dark)) | |
703 (:foreground "blue4")) | |
704 (((class color) | |
705 (background light)) | |
706 (:foreground "brown")) | |
707 (t | |
708 (:bold t))) | |
709 "Face used for displaying the separator." | |
710 :group 'message-faces) | |
711 | |
712 (defface message-cited-text-face | |
713 '((((class color) | |
714 (background dark)) | |
715 (:foreground "red")) | |
716 (((class color) | |
717 (background light)) | |
718 (:foreground "red")) | |
719 (t | |
720 (:bold t))) | |
721 "Face used for displaying cited text names." | |
722 :group 'message-faces) | |
723 | |
724 (defvar message-font-lock-keywords | |
725 (let* ((cite-prefix "A-Za-z") | |
726 (cite-suffix (concat cite-prefix "0-9_.@-")) | |
727 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)")) | |
728 `((,(concat "^\\(To:\\)" content) | |
729 (1 'message-header-name-face) | |
730 (2 'message-header-to-face nil t)) | |
731 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^Reply-To:\\)" content) | |
732 (1 'message-header-name-face) | |
733 (2 'message-header-cc-face nil t)) | |
734 (,(concat "^\\(Subject:\\)" content) | |
735 (1 'message-header-name-face) | |
736 (2 'message-header-subject-face nil t)) | |
737 (,(concat "^\\(Newsgroups:\\|Followup-to:\\)" content) | |
738 (1 'message-header-name-face) | |
739 (2 'message-header-newsgroups-face nil t)) | |
740 (,(concat "^\\([^: \n\t]+:\\)" content) | |
741 (1 'message-header-name-face) | |
742 (2 'message-header-other-face nil t)) | |
743 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content) | |
744 (1 'message-header-name-face) | |
745 (2 'message-header-name-face)) | |
746 (,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$") | |
747 1 'message-separator-face) | |
748 (,(concat "^[ \t]*" | |
749 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?" | |
750 "[>|}].*") | |
751 (0 'message-cited-text-face)))) | |
752 "Additional expressions to highlight in Message mode.") | |
753 | |
754 (defvar message-face-alist | |
755 '((bold . bold-region) | |
756 (underline . underline-region) | |
757 (default . (lambda (b e) | |
758 (unbold-region b e) | |
759 (ununderline-region b e)))) | |
760 "Alist of mail and news faces for facemenu. | |
761 The cdr of ech entry is a function for applying the face to a region.") | |
762 | |
763 (defcustom message-send-hook nil | |
764 "Hook run before sending messages." | |
765 :group 'message-various | |
766 :options '(ispell-message) | |
767 :type 'hook) | |
768 | |
769 (defcustom message-send-mail-hook nil | |
770 "Hook run before sending mail messages." | |
771 :group 'message-various | |
772 :type 'hook) | |
773 | |
774 (defcustom message-send-news-hook nil | |
775 "Hook run before sending news messages." | |
776 :group 'message-various | |
777 :type 'hook) | |
778 | |
779 (defcustom message-sent-hook nil | |
780 "Hook run after sending messages." | |
781 :group 'message-various | |
782 :type 'hook) | |
783 | |
784 ;;; Internal variables. | |
785 | |
786 (defvar message-buffer-list nil) | |
787 (defvar message-this-is-news nil) | |
788 (defvar message-this-is-mail nil) | |
789 | |
790 ;; Byte-compiler warning | |
791 (defvar gnus-active-hashtb) | |
792 (defvar gnus-read-active-file) | |
793 | |
794 ;;; Regexp matching the delimiter of messages in UNIX mail format | |
19762
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
795 ;;; (UNIX From lines), minus the initial ^. It should be a copy |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
796 ;;; of rmail.el's rmail-unix-mail-delimiter. |
17493 | 797 (defvar message-unix-mail-delimiter |
798 (let ((time-zone-regexp | |
799 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?" | |
800 "\\|[-+]?[0-9][0-9][0-9][0-9]" | |
801 "\\|" | |
802 "\\) *"))) | |
803 (concat | |
804 "From " | |
805 | |
19762
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
806 ;; Many things can happen to an RFC 822 mailbox before it is put into |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
807 ;; a `From' line. The leading phrase can be stripped, e.g. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
808 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
809 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
810 ;; can be removed, e.g. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
811 ;; From: joe@y.z (Joe K |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
812 ;; User) |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
813 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
814 ;; From: Joe User |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
815 ;; <joe@y.z> |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
816 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
817 ;; The mailbox can be removed or be replaced by white space, e.g. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
818 ;; From: "Joe User"{space}{tab} |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
819 ;; <joe@y.z> |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
820 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996', |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
821 ;; where {space} and {tab} represent the Ascii space and tab characters. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
822 ;; We want to match the results of any of these manglings. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
823 ;; The following regexp rejects names whose first characters are |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
824 ;; obviously bogus, but after that anything goes. |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
825 "\\([^\0-\b\n-\r\^?].*\\)? " |
17493 | 826 |
827 ;; The time the message was sent. | |
19762
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
828 "\\([^\0-\r \^?]+\\) +" ; day of the week |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
829 "\\([^\0-\r \^?]+\\) +" ; month |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
830 "\\([0-3]?[0-9]\\) +" ; day of month |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
831 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day |
17493 | 832 |
833 ;; Perhaps a time zone, specified by an abbreviation, or by a | |
834 ;; numeric offset. | |
835 time-zone-regexp | |
836 | |
837 ;; The year. | |
19762
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
838 " \\([0-9][0-9]+\\) *" |
17493 | 839 |
840 ;; On some systems the time zone can appear after the year, too. | |
841 time-zone-regexp | |
842 | |
843 ;; Old uucp cruft. | |
844 "\\(remote from .*\\)?" | |
845 | |
19762
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
846 "\n")) |
f6ca32374b0b
(message-unix-mail-delimiter): Initialize
Richard M. Stallman <rms@gnu.org>
parents:
19525
diff
changeset
|
847 nil) |
17493 | 848 |
849 (defvar message-unsent-separator | |
850 (concat "^ *---+ +Unsent message follows +---+ *$\\|" | |
851 "^ *---+ +Returned message +---+ *$\\|" | |
852 "^Start of returned message$\\|" | |
853 "^ *---+ +Original message +---+ *$\\|" | |
854 "^ *--+ +begin message +--+ *$\\|" | |
855 "^ *---+ +Original message follows +---+ *$\\|" | |
856 "^|? *---+ +Message text follows: +---+ *|?$") | |
857 "A regexp that matches the separator before the text of a failed message.") | |
858 | |
859 (defvar message-header-format-alist | |
860 `((Newsgroups) | |
861 (To . message-fill-address) | |
862 (Cc . message-fill-address) | |
863 (Subject) | |
864 (In-Reply-To) | |
865 (Fcc) | |
866 (Bcc) | |
867 (Date) | |
868 (Organization) | |
869 (Distribution) | |
870 (Lines) | |
871 (Expires) | |
872 (Message-ID) | |
873 (References) | |
874 (X-Mailer) | |
875 (X-Newsreader)) | |
876 "Alist used for formatting headers.") | |
877 | |
878 (eval-and-compile | |
879 (autoload 'message-setup-toolbar "messagexmas") | |
880 (autoload 'mh-send-letter "mh-comp") | |
881 (autoload 'gnus-point-at-eol "gnus-util") | |
882 (autoload 'gnus-point-at-bol "gnus-util") | |
883 (autoload 'gnus-output-to-mail "gnus-util") | |
884 (autoload 'gnus-output-to-rmail "gnus-util") | |
885 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")) | |
886 | |
887 | |
888 | |
889 ;;; | |
890 ;;; Utility functions. | |
891 ;;; | |
892 | |
893 (defmacro message-y-or-n-p (question show &rest text) | |
894 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW" | |
895 `(message-talkative-question 'y-or-n-p ,question ,show ,@text)) | |
896 | |
897 ;; Delete the current line (and the next N lines.); | |
898 (defmacro message-delete-line (&optional n) | |
899 `(delete-region (progn (beginning-of-line) (point)) | |
900 (progn (forward-line ,(or n 1)) (point)))) | |
901 | |
902 (defun message-tokenize-header (header &optional separator) | |
903 "Split HEADER into a list of header elements. | |
904 \",\" is used as the separator." | |
905 (if (not header) | |
906 nil | |
907 (let ((regexp (format "[%s]+" (or separator ","))) | |
908 (beg 1) | |
909 (first t) | |
910 quoted elems paren) | |
911 (save-excursion | |
912 (message-set-work-buffer) | |
913 (insert header) | |
914 (goto-char (point-min)) | |
915 (while (not (eobp)) | |
916 (if first | |
917 (setq first nil) | |
918 (forward-char 1)) | |
919 (cond ((and (> (point) beg) | |
920 (or (eobp) | |
921 (and (looking-at regexp) | |
922 (not quoted) | |
923 (not paren)))) | |
924 (push (buffer-substring beg (point)) elems) | |
925 (setq beg (match-end 0))) | |
926 ((= (following-char) ?\") | |
927 (setq quoted (not quoted))) | |
928 ((and (= (following-char) ?\() | |
929 (not quoted)) | |
930 (setq paren t)) | |
931 ((and (= (following-char) ?\)) | |
932 (not quoted)) | |
933 (setq paren nil)))) | |
934 (nreverse elems))))) | |
935 | |
936 (defun message-mail-file-mbox-p (file) | |
937 "Say whether FILE looks like a Unix mbox file." | |
938 (when (and (file-exists-p file) | |
939 (file-readable-p file) | |
940 (file-regular-p file)) | |
941 (nnheader-temp-write nil | |
942 (nnheader-insert-file-contents file) | |
943 (goto-char (point-min)) | |
944 (looking-at message-unix-mail-delimiter)))) | |
945 | |
946 (defun message-fetch-field (header &optional not-all) | |
947 "The same as `mail-fetch-field', only remove all newlines." | |
948 (let ((value (mail-fetch-field header nil (not not-all)))) | |
949 (when value | |
950 (nnheader-replace-chars-in-string value ?\n ? )))) | |
951 | |
952 (defun message-add-header (&rest headers) | |
953 "Add the HEADERS to the message header, skipping those already present." | |
954 (while headers | |
955 (let (hclean) | |
956 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers)) | |
957 (error "Invalid header `%s'" (car headers))) | |
958 (setq hclean (match-string 1 (car headers))) | |
959 (save-restriction | |
960 (message-narrow-to-headers) | |
961 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t) | |
962 (insert (car headers) ?\n)))) | |
963 (setq headers (cdr headers)))) | |
964 | |
965 (defun message-fetch-reply-field (header) | |
966 "Fetch FIELD from the message we're replying to." | |
967 (when (and message-reply-buffer | |
968 (buffer-name message-reply-buffer)) | |
969 (save-excursion | |
970 (set-buffer message-reply-buffer) | |
971 (message-fetch-field header)))) | |
972 | |
973 (defun message-set-work-buffer () | |
974 (if (get-buffer " *message work*") | |
975 (progn | |
976 (set-buffer " *message work*") | |
977 (erase-buffer)) | |
978 (set-buffer (get-buffer-create " *message work*")) | |
979 (kill-all-local-variables) | |
980 (buffer-disable-undo (current-buffer)))) | |
981 | |
982 (defun message-functionp (form) | |
983 "Return non-nil if FORM is funcallable." | |
984 (or (and (symbolp form) (fboundp form)) | |
985 (and (listp form) (eq (car form) 'lambda)) | |
986 (compiled-function-p form))) | |
987 | |
988 (defun message-strip-subject-re (subject) | |
989 "Remove \"Re:\" from subject lines." | |
990 (if (string-match "^[Rr][Ee]: *" subject) | |
991 (substring subject (match-end 0)) | |
992 subject)) | |
993 | |
994 (defun message-remove-header (header &optional is-regexp first reverse) | |
995 "Remove HEADER in the narrowed buffer. | |
996 If REGEXP, HEADER is a regular expression. | |
997 If FIRST, only remove the first instance of the header. | |
998 Return the number of headers removed." | |
999 (goto-char (point-min)) | |
1000 (let ((regexp (if is-regexp header (concat "^" header ":"))) | |
1001 (number 0) | |
1002 (case-fold-search t) | |
1003 last) | |
1004 (while (and (not (eobp)) | |
1005 (not last)) | |
1006 (if (if reverse | |
1007 (not (looking-at regexp)) | |
1008 (looking-at regexp)) | |
1009 (progn | |
1010 (incf number) | |
1011 (when first | |
1012 (setq last t)) | |
1013 (delete-region | |
1014 (point) | |
1015 ;; There might be a continuation header, so we have to search | |
1016 ;; until we find a new non-continuation line. | |
1017 (progn | |
1018 (forward-line 1) | |
1019 (if (re-search-forward "^[^ \t]" nil t) | |
1020 (goto-char (match-beginning 0)) | |
1021 (point-max))))) | |
1022 (forward-line 1) | |
1023 (if (re-search-forward "^[^ \t]" nil t) | |
1024 (goto-char (match-beginning 0)) | |
1025 (point-max)))) | |
1026 number)) | |
1027 | |
1028 (defun message-narrow-to-headers () | |
1029 "Narrow the buffer to the head of the message." | |
1030 (widen) | |
1031 (narrow-to-region | |
1032 (goto-char (point-min)) | |
1033 (if (re-search-forward | |
1034 (concat "^" (regexp-quote mail-header-separator) "\n") nil t) | |
1035 (match-beginning 0) | |
1036 (point-max))) | |
1037 (goto-char (point-min))) | |
1038 | |
1039 (defun message-narrow-to-head () | |
1040 "Narrow the buffer to the head of the message." | |
1041 (widen) | |
1042 (narrow-to-region | |
1043 (goto-char (point-min)) | |
1044 (if (search-forward "\n\n" nil 1) | |
1045 (1- (point)) | |
1046 (point-max))) | |
1047 (goto-char (point-min))) | |
1048 | |
1049 (defun message-news-p () | |
1050 "Say whether the current buffer contains a news message." | |
1051 (or message-this-is-news | |
1052 (save-excursion | |
1053 (save-restriction | |
1054 (message-narrow-to-headers) | |
1055 (message-fetch-field "newsgroups"))))) | |
1056 | |
1057 (defun message-mail-p () | |
1058 "Say whether the current buffer contains a mail message." | |
1059 (or message-this-is-mail | |
1060 (save-excursion | |
1061 (save-restriction | |
1062 (message-narrow-to-headers) | |
1063 (or (message-fetch-field "to") | |
1064 (message-fetch-field "cc") | |
1065 (message-fetch-field "bcc")))))) | |
1066 | |
1067 (defun message-next-header () | |
1068 "Go to the beginning of the next header." | |
1069 (beginning-of-line) | |
1070 (or (eobp) (forward-char 1)) | |
1071 (not (if (re-search-forward "^[^ \t]" nil t) | |
1072 (beginning-of-line) | |
1073 (goto-char (point-max))))) | |
1074 | |
1075 (defun message-sort-headers-1 () | |
1076 "Sort the buffer as headers using `message-rank' text props." | |
1077 (goto-char (point-min)) | |
1078 (sort-subr | |
1079 nil 'message-next-header | |
1080 (lambda () | |
1081 (message-next-header) | |
1082 (unless (bobp) | |
1083 (forward-char -1))) | |
1084 (lambda () | |
1085 (or (get-text-property (point) 'message-rank) | |
1086 10000)))) | |
1087 | |
1088 (defun message-sort-headers () | |
1089 "Sort the headers of the current message according to `message-header-format-alist'." | |
1090 (interactive) | |
1091 (save-excursion | |
1092 (save-restriction | |
1093 (let ((max (1+ (length message-header-format-alist))) | |
1094 rank) | |
1095 (message-narrow-to-headers) | |
1096 (while (re-search-forward "^[^ \n]+:" nil t) | |
1097 (put-text-property | |
1098 (match-beginning 0) (1+ (match-beginning 0)) | |
1099 'message-rank | |
1100 (if (setq rank (length (memq (assq (intern (buffer-substring | |
1101 (match-beginning 0) | |
1102 (1- (match-end 0)))) | |
1103 message-header-format-alist) | |
1104 message-header-format-alist))) | |
1105 (- max rank) | |
1106 (1+ max))))) | |
1107 (message-sort-headers-1)))) | |
1108 | |
1109 | |
1110 | |
1111 ;;; | |
1112 ;;; Message mode | |
1113 ;;; | |
1114 | |
1115 ;;; Set up keymap. | |
1116 | |
1117 (defvar message-mode-map nil) | |
1118 | |
1119 (unless message-mode-map | |
1120 (setq message-mode-map (copy-keymap text-mode-map)) | |
1121 (define-key message-mode-map "\C-c?" 'describe-mode) | |
1122 | |
1123 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to) | |
1124 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc) | |
1125 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc) | |
1126 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc) | |
1127 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject) | |
1128 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to) | |
1129 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups) | |
1130 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution) | |
1131 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to) | |
1132 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords) | |
1133 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary) | |
1134 (define-key message-mode-map "\C-c\C-b" 'message-goto-body) | |
1135 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature) | |
1136 | |
1137 (define-key message-mode-map "\C-c\C-t" 'message-insert-to) | |
1138 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups) | |
1139 | |
1140 (define-key message-mode-map "\C-c\C-y" 'message-yank-original) | |
1141 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message) | |
1142 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature) | |
1143 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body) | |
1144 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers) | |
1145 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer) | |
1146 | |
1147 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit) | |
1148 (define-key message-mode-map "\C-c\C-s" 'message-send) | |
1149 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer) | |
1150 (define-key message-mode-map "\C-c\C-d" 'message-dont-send) | |
1151 | |
1152 (define-key message-mode-map "\C-c\C-e" 'message-elide-region) | |
1153 | |
1154 (define-key message-mode-map "\t" 'message-tab)) | |
1155 | |
1156 (easy-menu-define | |
1157 message-mode-menu message-mode-map "Message Menu." | |
1158 '("Message" | |
1159 ["Sort Headers" message-sort-headers t] | |
1160 ["Yank Original" message-yank-original t] | |
1161 ["Fill Yanked Message" message-fill-yanked-message t] | |
1162 ["Insert Signature" message-insert-signature t] | |
1163 ["Caesar (rot13) Message" message-caesar-buffer-body t] | |
1164 ["Caesar (rot13) Region" message-caesar-region (mark t)] | |
1165 ["Elide Region" message-elide-region (mark t)] | |
1166 ["Rename buffer" message-rename-buffer t] | |
1167 ["Spellcheck" ispell-message t] | |
1168 "----" | |
1169 ["Send Message" message-send-and-exit t] | |
1170 ["Abort Message" message-dont-send t])) | |
1171 | |
1172 (easy-menu-define | |
1173 message-mode-field-menu message-mode-map "" | |
1174 '("Field" | |
1175 ["Fetch To" message-insert-to t] | |
1176 ["Fetch Newsgroups" message-insert-newsgroups t] | |
1177 "----" | |
1178 ["To" message-goto-to t] | |
1179 ["Subject" message-goto-subject t] | |
1180 ["Cc" message-goto-cc t] | |
1181 ["Reply-To" message-goto-reply-to t] | |
1182 ["Summary" message-goto-summary t] | |
1183 ["Keywords" message-goto-keywords t] | |
1184 ["Newsgroups" message-goto-newsgroups t] | |
1185 ["Followup-To" message-goto-followup-to t] | |
1186 ["Distribution" message-goto-distribution t] | |
1187 ["Body" message-goto-body t] | |
1188 ["Signature" message-goto-signature t])) | |
1189 | |
1190 (defvar facemenu-add-face-function) | |
1191 (defvar facemenu-remove-face-function) | |
1192 | |
1193 ;;;###autoload | |
1194 (defun message-mode () | |
1195 "Major mode for editing mail and news to be sent. | |
1196 Like Text Mode but with these additional commands: | |
1197 C-c C-s message-send (send the message) C-c C-c message-send-and-exit | |
1198 C-c C-f move to a header field (and create it if there isn't): | |
1199 C-c C-f C-t move to To C-c C-f C-s move to Subject | |
1200 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc | |
1201 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To | |
1202 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups | |
1203 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution | |
1204 C-c C-f C-f move to Followup-To | |
1205 C-c C-t message-insert-to (add a To header to a news followup) | |
1206 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply) | |
1207 C-c C-b message-goto-body (move to beginning of message text). | |
1208 C-c C-i message-goto-signature (move to the beginning of the signature). | |
1209 C-c C-w message-insert-signature (insert `message-signature-file' file). | |
1210 C-c C-y message-yank-original (insert current message, if any). | |
1211 C-c C-q message-fill-yanked-message (fill what was yanked). | |
1212 C-c C-e message-elide-region (elide the text between point and mark). | |
1213 C-c C-r message-caesar-buffer-body (rot13 the message body)." | |
1214 (interactive) | |
1215 (kill-all-local-variables) | |
1216 (make-local-variable 'message-reply-buffer) | |
1217 (setq message-reply-buffer nil) | |
1218 (make-local-variable 'message-send-actions) | |
1219 (make-local-variable 'message-exit-actions) | |
1220 (make-local-variable 'message-kill-actions) | |
1221 (make-local-variable 'message-postpone-actions) | |
1222 (set-syntax-table message-mode-syntax-table) | |
1223 (use-local-map message-mode-map) | |
1224 (setq local-abbrev-table message-mode-abbrev-table) | |
1225 (setq major-mode 'message-mode) | |
1226 (setq mode-name "Message") | |
1227 (setq buffer-offer-save t) | |
1228 (make-local-variable 'font-lock-defaults) | |
1229 (setq font-lock-defaults '(message-font-lock-keywords t)) | |
1230 (make-local-variable 'facemenu-add-face-function) | |
1231 (make-local-variable 'facemenu-remove-face-function) | |
1232 (setq facemenu-add-face-function | |
1233 (lambda (face end) | |
1234 (let ((face-fun (cdr (assq face message-face-alist)))) | |
1235 (if face-fun | |
1236 (funcall face-fun (point) end) | |
1237 (error "Face %s not configured for %s mode" face mode-name))) | |
1238 "") | |
1239 facemenu-remove-face-function t) | |
1240 (make-local-variable 'paragraph-separate) | |
1241 (make-local-variable 'paragraph-start) | |
1242 (setq paragraph-start (concat (regexp-quote mail-header-separator) | |
1243 "$\\|[ \t]*[-_][-_][-_]+$\\|" | |
1244 "-- $\\|" | |
1245 paragraph-start)) | |
1246 (setq paragraph-separate (concat (regexp-quote mail-header-separator) | |
1247 "$\\|[ \t]*[-_][-_][-_]+$\\|" | |
1248 "-- $\\|" | |
1249 paragraph-separate)) | |
1250 (make-local-variable 'message-reply-headers) | |
1251 (setq message-reply-headers nil) | |
1252 (make-local-variable 'message-newsreader) | |
1253 (make-local-variable 'message-mailer) | |
1254 (make-local-variable 'message-post-method) | |
1255 (make-local-variable 'message-sent-message-via) | |
1256 (setq message-sent-message-via nil) | |
1257 (make-local-variable 'message-checksum) | |
1258 (setq message-checksum nil) | |
1259 ;;(when (fboundp 'mail-hist-define-keys) | |
1260 ;; (mail-hist-define-keys)) | |
1261 (when (string-match "XEmacs\\|Lucid" emacs-version) | |
1262 (message-setup-toolbar)) | |
1263 (easy-menu-add message-mode-menu message-mode-map) | |
1264 (easy-menu-add message-mode-field-menu message-mode-map) | |
1265 ;; Allow mail alias things. | |
1266 (if (fboundp 'mail-abbrevs-setup) | |
1267 (mail-abbrevs-setup) | |
1268 (funcall (intern "mail-aliases-setup"))) | |
1269 (run-hooks 'text-mode-hook 'message-mode-hook)) | |
1270 | |
1271 | |
1272 | |
1273 ;;; | |
1274 ;;; Message mode commands | |
1275 ;;; | |
1276 | |
1277 ;;; Movement commands | |
1278 | |
1279 (defun message-goto-to () | |
1280 "Move point to the To header." | |
1281 (interactive) | |
1282 (message-position-on-field "To")) | |
1283 | |
1284 (defun message-goto-subject () | |
1285 "Move point to the Subject header." | |
1286 (interactive) | |
1287 (message-position-on-field "Subject")) | |
1288 | |
1289 (defun message-goto-cc () | |
1290 "Move point to the Cc header." | |
1291 (interactive) | |
1292 (message-position-on-field "Cc" "To")) | |
1293 | |
1294 (defun message-goto-bcc () | |
1295 "Move point to the Bcc header." | |
1296 (interactive) | |
1297 (message-position-on-field "Bcc" "Cc" "To")) | |
1298 | |
1299 (defun message-goto-fcc () | |
1300 "Move point to the Fcc header." | |
1301 (interactive) | |
1302 (message-position-on-field "Fcc" "To" "Newsgroups")) | |
1303 | |
1304 (defun message-goto-reply-to () | |
1305 "Move point to the Reply-To header." | |
1306 (interactive) | |
1307 (message-position-on-field "Reply-To" "Subject")) | |
1308 | |
1309 (defun message-goto-newsgroups () | |
1310 "Move point to the Newsgroups header." | |
1311 (interactive) | |
1312 (message-position-on-field "Newsgroups")) | |
1313 | |
1314 (defun message-goto-distribution () | |
1315 "Move point to the Distribution header." | |
1316 (interactive) | |
1317 (message-position-on-field "Distribution")) | |
1318 | |
1319 (defun message-goto-followup-to () | |
1320 "Move point to the Followup-To header." | |
1321 (interactive) | |
1322 (message-position-on-field "Followup-To" "Newsgroups")) | |
1323 | |
1324 (defun message-goto-keywords () | |
1325 "Move point to the Keywords header." | |
1326 (interactive) | |
1327 (message-position-on-field "Keywords" "Subject")) | |
1328 | |
1329 (defun message-goto-summary () | |
1330 "Move point to the Summary header." | |
1331 (interactive) | |
1332 (message-position-on-field "Summary" "Subject")) | |
1333 | |
1334 (defun message-goto-body () | |
1335 "Move point to the beginning of the message body." | |
1336 (interactive) | |
1337 (if (looking-at "[ \t]*\n") (expand-abbrev)) | |
1338 (goto-char (point-min)) | |
1339 (search-forward (concat "\n" mail-header-separator "\n") nil t)) | |
1340 | |
1341 (defun message-goto-signature () | |
1342 "Move point to the beginning of the message signature." | |
1343 (interactive) | |
1344 (goto-char (point-min)) | |
1345 (if (re-search-forward message-signature-separator nil t) | |
1346 (forward-line 1) | |
1347 (goto-char (point-max)))) | |
1348 | |
1349 | |
1350 | |
1351 (defun message-insert-to () | |
1352 "Insert a To header that points to the author of the article being replied to." | |
1353 (interactive) | |
1354 (let ((co (message-fetch-reply-field "mail-copies-to"))) | |
1355 (when (and co | |
1356 (equal (downcase co) "never")) | |
1357 (error "The user has requested not to have copies sent via mail"))) | |
1358 (when (and (message-position-on-field "To") | |
1359 (mail-fetch-field "to") | |
1360 (not (string-match "\\` *\\'" (mail-fetch-field "to")))) | |
1361 (insert ", ")) | |
1362 (insert (or (message-fetch-reply-field "reply-to") | |
1363 (message-fetch-reply-field "from") ""))) | |
1364 | |
1365 (defun message-insert-newsgroups () | |
1366 "Insert the Newsgroups header from the article being replied to." | |
1367 (interactive) | |
1368 (when (and (message-position-on-field "Newsgroups") | |
1369 (mail-fetch-field "newsgroups") | |
1370 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups")))) | |
1371 (insert ",")) | |
1372 (insert (or (message-fetch-reply-field "newsgroups") ""))) | |
1373 | |
1374 | |
1375 | |
1376 ;;; Various commands | |
1377 | |
1378 (defun message-insert-signature (&optional force) | |
1379 "Insert a signature. See documentation for the `message-signature' variable." | |
1380 (interactive (list 0)) | |
1381 (let* ((signature | |
1382 (cond | |
1383 ((and (null message-signature) | |
1384 (eq force 0)) | |
1385 (save-excursion | |
1386 (goto-char (point-max)) | |
1387 (not (re-search-backward | |
1388 message-signature-separator nil t)))) | |
1389 ((and (null message-signature) | |
1390 force) | |
1391 t) | |
1392 ((message-functionp message-signature) | |
1393 (funcall message-signature)) | |
1394 ((listp message-signature) | |
1395 (eval message-signature)) | |
1396 (t message-signature))) | |
1397 (signature | |
1398 (cond ((stringp signature) | |
1399 signature) | |
1400 ((and (eq t signature) | |
1401 message-signature-file | |
1402 (file-exists-p message-signature-file)) | |
1403 signature)))) | |
1404 (when signature | |
1405 (goto-char (point-max)) | |
1406 ;; Insert the signature. | |
1407 (unless (bolp) | |
1408 (insert "\n")) | |
1409 (insert "\n-- \n") | |
1410 (if (eq signature t) | |
1411 (insert-file-contents message-signature-file) | |
1412 (insert signature)) | |
1413 (goto-char (point-max)) | |
1414 (or (bolp) (insert "\n"))))) | |
1415 | |
1416 (defun message-elide-region (b e) | |
1417 "Elide the text between point and mark. An ellipsis (from | |
1418 message-elide-elipsis) will be inserted where the text was killed." | |
1419 (interactive "r") | |
1420 (kill-region b e) | |
1421 (unless (bolp) | |
1422 (insert "\n")) | |
1423 (insert message-elide-elipsis)) | |
1424 | |
1425 (defvar message-caesar-translation-table nil) | |
1426 | |
1427 (defun message-caesar-region (b e &optional n) | |
1428 "Caesar rotation of region by N, default 13, for decrypting netnews." | |
1429 (interactive | |
1430 (list | |
1431 (min (point) (or (mark t) (point))) | |
1432 (max (point) (or (mark t) (point))) | |
1433 (when current-prefix-arg | |
1434 (prefix-numeric-value current-prefix-arg)))) | |
1435 | |
1436 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N | |
1437 (unless (or (zerop n) ; no action needed for a rot of 0 | |
1438 (= b e)) ; no region to rotate | |
1439 ;; We build the table, if necessary. | |
1440 (when (or (not message-caesar-translation-table) | |
1441 (/= (aref message-caesar-translation-table ?a) (+ ?a n))) | |
1442 (setq message-caesar-translation-table | |
1443 (message-make-caesar-translation-table n))) | |
1444 ;; Then we translate the region. Do it this way to retain | |
1445 ;; text properties. | |
1446 (while (< b e) | |
1447 (subst-char-in-region | |
1448 b (1+ b) (char-after b) | |
1449 (aref message-caesar-translation-table (char-after b))) | |
1450 (incf b)))) | |
1451 | |
1452 (defun message-make-caesar-translation-table (n) | |
1453 "Create a rot table with offset N." | |
1454 (let ((i -1) | |
1455 (table (make-string 256 0))) | |
1456 (while (< (incf i) 256) | |
1457 (aset table i i)) | |
1458 (concat | |
1459 (substring table 0 ?A) | |
1460 (substring table (+ ?A n) (+ ?A n (- 26 n))) | |
1461 (substring table ?A (+ ?A n)) | |
1462 (substring table (+ ?A 26) ?a) | |
1463 (substring table (+ ?a n) (+ ?a n (- 26 n))) | |
1464 (substring table ?a (+ ?a n)) | |
1465 (substring table (+ ?a 26) 255)))) | |
1466 | |
1467 (defun message-caesar-buffer-body (&optional rotnum) | |
1468 "Caesar rotates all letters in the current buffer by 13 places. | |
1469 Used to encode/decode possibly offensive messages (commonly in net.jokes). | |
1470 With prefix arg, specifies the number of places to rotate each letter forward. | |
1471 Mail and USENET news headers are not rotated." | |
1472 (interactive (if current-prefix-arg | |
1473 (list (prefix-numeric-value current-prefix-arg)) | |
1474 (list nil))) | |
1475 (save-excursion | |
1476 (save-restriction | |
1477 (when (message-goto-body) | |
1478 (narrow-to-region (point) (point-max))) | |
1479 (message-caesar-region (point-min) (point-max) rotnum)))) | |
1480 | |
1481 (defun message-pipe-buffer-body (program) | |
1482 "Pipe the message body in the current buffer through PROGRAM." | |
1483 (save-excursion | |
1484 (save-restriction | |
1485 (when (message-goto-body) | |
1486 (narrow-to-region (point) (point-max))) | |
1487 (let ((body (buffer-substring (point-min) (point-max)))) | |
1488 (unless (equal 0 (call-process-region | |
1489 (point-min) (point-max) program t t)) | |
1490 (insert body) | |
1491 (message "%s failed." program)))))) | |
1492 | |
1493 (defun message-rename-buffer (&optional enter-string) | |
1494 "Rename the *message* buffer to \"*message* RECIPIENT\". | |
1495 If the function is run with a prefix, it will ask for a new buffer | |
1496 name, rather than giving an automatic name." | |
1497 (interactive "Pbuffer name: ") | |
1498 (save-excursion | |
1499 (save-restriction | |
1500 (goto-char (point-min)) | |
1501 (narrow-to-region (point) | |
1502 (search-forward mail-header-separator nil 'end)) | |
1503 (let* ((mail-to (or | |
1504 (if (message-news-p) (message-fetch-field "Newsgroups") | |
1505 (message-fetch-field "To")) | |
1506 "")) | |
1507 (mail-trimmed-to | |
1508 (if (string-match "," mail-to) | |
1509 (concat (substring mail-to 0 (match-beginning 0)) ", ...") | |
1510 mail-to)) | |
1511 (name-default (concat "*message* " mail-trimmed-to)) | |
1512 (name (if enter-string | |
1513 (read-string "New buffer name: " name-default) | |
1514 name-default)) | |
1515 (default-directory | |
1516 (file-name-as-directory message-autosave-directory))) | |
1517 (rename-buffer name t))))) | |
1518 | |
1519 (defun message-fill-yanked-message (&optional justifyp) | |
1520 "Fill the paragraphs of a message yanked into this one. | |
1521 Numeric argument means justify as well." | |
1522 (interactive "P") | |
1523 (save-excursion | |
1524 (goto-char (point-min)) | |
1525 (search-forward (concat "\n" mail-header-separator "\n") nil t) | |
1526 (let ((fill-prefix message-yank-prefix)) | |
1527 (fill-individual-paragraphs (point) (point-max) justifyp t)))) | |
1528 | |
1529 (defun message-indent-citation () | |
1530 "Modify text just inserted from a message to be cited. | |
1531 The inserted text should be the region. | |
1532 When this function returns, the region is again around the modified text. | |
1533 | |
1534 Normally, indent each nonblank line `message-indentation-spaces' spaces. | |
1535 However, if `message-yank-prefix' is non-nil, insert that prefix on each line." | |
1536 (let ((start (point))) | |
1537 ;; Remove unwanted headers. | |
1538 (when message-ignored-cited-headers | |
1539 (let (all-removed) | |
1540 (save-restriction | |
1541 (narrow-to-region | |
1542 (goto-char start) | |
1543 (if (search-forward "\n\n" nil t) | |
1544 (1- (point)) | |
1545 (point))) | |
1546 (message-remove-header message-ignored-cited-headers t) | |
1547 (when (= (point-min) (point-max)) | |
1548 (setq all-removed t)) | |
1549 (goto-char (point-max))) | |
1550 (if all-removed | |
1551 (goto-char start) | |
1552 (forward-line 1)))) | |
1553 ;; Delete blank lines at the start of the buffer. | |
1554 (while (and (point-min) | |
1555 (eolp) | |
1556 (not (eobp))) | |
1557 (message-delete-line)) | |
1558 ;; Delete blank lines at the end of the buffer. | |
1559 (goto-char (point-max)) | |
1560 (unless (eolp) | |
1561 (insert "\n")) | |
1562 (while (and (zerop (forward-line -1)) | |
1563 (looking-at "$")) | |
1564 (message-delete-line)) | |
1565 ;; Do the indentation. | |
1566 (if (null message-yank-prefix) | |
1567 (indent-rigidly start (mark t) message-indentation-spaces) | |
1568 (save-excursion | |
1569 (goto-char start) | |
1570 (while (< (point) (mark t)) | |
1571 (insert message-yank-prefix) | |
1572 (forward-line 1)))) | |
1573 (goto-char start))) | |
1574 | |
1575 (defun message-yank-original (&optional arg) | |
1576 "Insert the message being replied to, if any. | |
1577 Puts point before the text and mark after. | |
1578 Normally indents each nonblank line ARG spaces (default 3). However, | |
1579 if `message-yank-prefix' is non-nil, insert that prefix on each line. | |
1580 | |
1581 This function uses `message-cite-function' to do the actual citing. | |
1582 | |
1583 Just \\[universal-argument] as argument means don't indent, insert no | |
1584 prefix, and don't delete any headers." | |
1585 (interactive "P") | |
1586 (let ((modified (buffer-modified-p))) | |
1587 (when (and message-reply-buffer | |
1588 message-cite-function) | |
1589 (delete-windows-on message-reply-buffer t) | |
1590 (insert-buffer message-reply-buffer) | |
1591 (funcall message-cite-function) | |
1592 (message-exchange-point-and-mark) | |
1593 (unless (bolp) | |
1594 (insert ?\n)) | |
1595 (unless modified | |
1596 (setq message-checksum (cons (message-checksum) (buffer-size))))))) | |
1597 | |
1598 (defun message-cite-original () | |
1599 "Cite function in the standard Message manner." | |
1600 (let ((start (point)) | |
1601 (functions | |
1602 (when message-indent-citation-function | |
1603 (if (listp message-indent-citation-function) | |
1604 message-indent-citation-function | |
1605 (list message-indent-citation-function))))) | |
1606 (goto-char start) | |
1607 (while functions | |
1608 (funcall (pop functions))) | |
1609 (when message-citation-line-function | |
1610 (unless (bolp) | |
1611 (insert "\n")) | |
1612 (funcall message-citation-line-function)))) | |
1613 | |
1614 (defun message-insert-citation-line () | |
1615 "Function that inserts a simple citation line." | |
1616 (when message-reply-headers | |
1617 (insert (mail-header-from message-reply-headers) " writes:\n\n"))) | |
1618 | |
1619 (defun message-position-on-field (header &rest afters) | |
1620 (let ((case-fold-search t)) | |
1621 (save-restriction | |
1622 (narrow-to-region | |
1623 (goto-char (point-min)) | |
1624 (progn | |
1625 (re-search-forward | |
1626 (concat "^" (regexp-quote mail-header-separator) "$")) | |
1627 (match-beginning 0))) | |
1628 (goto-char (point-min)) | |
1629 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t) | |
1630 (progn | |
1631 (re-search-forward "^[^ \t]" nil 'move) | |
1632 (beginning-of-line) | |
1633 (skip-chars-backward "\n") | |
1634 t) | |
1635 (while (and afters | |
1636 (not (re-search-forward | |
1637 (concat "^" (regexp-quote (car afters)) ":") | |
1638 nil t))) | |
1639 (pop afters)) | |
1640 (when afters | |
1641 (re-search-forward "^[^ \t]" nil 'move) | |
1642 (beginning-of-line)) | |
1643 (insert header ": \n") | |
1644 (forward-char -1) | |
1645 nil)))) | |
1646 | |
1647 (defun message-remove-signature () | |
1648 "Remove the signature from the text between point and mark. | |
1649 The text will also be indented the normal way." | |
1650 (save-excursion | |
1651 (let ((start (point)) | |
1652 mark) | |
1653 (if (not (re-search-forward message-signature-separator (mark t) t)) | |
1654 ;; No signature here, so we just indent the cited text. | |
1655 (message-indent-citation) | |
1656 ;; Find the last non-empty line. | |
1657 (forward-line -1) | |
1658 (while (looking-at "[ \t]*$") | |
1659 (forward-line -1)) | |
1660 (forward-line 1) | |
1661 (setq mark (set-marker (make-marker) (point))) | |
1662 (goto-char start) | |
1663 (message-indent-citation) | |
1664 ;; Enable undoing the deletion. | |
1665 (undo-boundary) | |
1666 (delete-region mark (mark t)) | |
1667 (set-marker mark nil))))) | |
1668 | |
1669 | |
1670 | |
1671 ;;; | |
1672 ;;; Sending messages | |
1673 ;;; | |
1674 | |
1675 (defun message-send-and-exit (&optional arg) | |
1676 "Send message like `message-send', then, if no errors, exit from mail buffer." | |
1677 (interactive "P") | |
1678 (let ((buf (current-buffer)) | |
1679 (actions message-exit-actions)) | |
1680 (when (and (message-send arg) | |
1681 (buffer-name buf)) | |
1682 (if message-kill-buffer-on-exit | |
1683 (kill-buffer buf) | |
1684 (bury-buffer buf) | |
1685 (when (eq buf (current-buffer)) | |
1686 (message-bury buf))) | |
1687 (message-do-actions actions)))) | |
1688 | |
1689 (defun message-dont-send () | |
1690 "Don't send the message you have been editing." | |
1691 (interactive) | |
1692 (let ((actions message-postpone-actions)) | |
1693 (message-bury (current-buffer)) | |
1694 (message-do-actions actions))) | |
1695 | |
1696 (defun message-kill-buffer () | |
1697 "Kill the current buffer." | |
1698 (interactive) | |
1699 (when (or (not (buffer-modified-p)) | |
1700 (yes-or-no-p "Message modified; kill anyway? ")) | |
1701 (let ((actions message-kill-actions)) | |
1702 (kill-buffer (current-buffer)) | |
1703 (message-do-actions actions)))) | |
1704 | |
1705 (defun message-bury (buffer) | |
1706 "Bury this mail buffer." | |
1707 (let ((newbuf (other-buffer buffer))) | |
1708 (bury-buffer buffer) | |
1709 (if (and (fboundp 'frame-parameters) | |
1710 (cdr (assq 'dedicated (frame-parameters))) | |
1711 (not (null (delq (selected-frame) (visible-frame-list))))) | |
1712 (delete-frame (selected-frame)) | |
1713 (switch-to-buffer newbuf)))) | |
1714 | |
1715 (defun message-send (&optional arg) | |
1716 "Send the message in the current buffer. | |
1717 If `message-interactive' is non-nil, wait for success indication | |
1718 or error messages, and inform user. | |
1719 Otherwise any failure is reported in a message back to | |
1720 the user from the mailer." | |
1721 (interactive "P") | |
1722 (when (if buffer-file-name | |
1723 (y-or-n-p (format "Send buffer contents as %s message? " | |
1724 (if (message-mail-p) | |
1725 (if (message-news-p) "mail and news" "mail") | |
1726 "news"))) | |
1727 (or (buffer-modified-p) | |
1728 (y-or-n-p "No changes in the buffer; really send? "))) | |
1729 ;; Make it possible to undo the coming changes. | |
1730 (undo-boundary) | |
1731 (let ((inhibit-read-only t)) | |
1732 (put-text-property (point-min) (point-max) 'read-only nil)) | |
1733 (message-fix-before-sending) | |
1734 (run-hooks 'message-send-hook) | |
1735 (message "Sending...") | |
1736 (when (and (or (not (message-news-p)) | |
1737 (and (or (not (memq 'news message-sent-message-via)) | |
1738 (y-or-n-p | |
1739 "Already sent message via news; resend? ")) | |
1740 (funcall message-send-news-function arg))) | |
1741 (or (not (message-mail-p)) | |
1742 (and (or (not (memq 'mail message-sent-message-via)) | |
1743 (y-or-n-p | |
1744 "Already sent message via mail; resend? ")) | |
1745 (message-send-mail arg)))) | |
1746 (message-do-fcc) | |
1747 ;;(when (fboundp 'mail-hist-put-headers-into-history) | |
1748 ;; (mail-hist-put-headers-into-history)) | |
1749 (run-hooks 'message-sent-hook) | |
1750 (message "Sending...done") | |
1751 ;; If buffer has no file, mark it as unmodified and delete autosave. | |
1752 (unless buffer-file-name | |
1753 (set-buffer-modified-p nil) | |
1754 (delete-auto-save-file-if-necessary t)) | |
1755 ;; Delete other mail buffers and stuff. | |
1756 (message-do-send-housekeeping) | |
1757 (message-do-actions message-send-actions) | |
1758 ;; Return success. | |
1759 t))) | |
1760 | |
1761 (defun message-fix-before-sending () | |
1762 "Do various things to make the message nice before sending it." | |
1763 ;; Make sure there's a newline at the end of the message. | |
1764 (goto-char (point-max)) | |
1765 (unless (bolp) | |
1766 (insert "\n"))) | |
1767 | |
1768 (defun message-add-action (action &rest types) | |
1769 "Add ACTION to be performed when doing an exit of type TYPES." | |
1770 (let (var) | |
1771 (while types | |
1772 (set (setq var (intern (format "message-%s-actions" (pop types)))) | |
1773 (nconc (symbol-value var) (list action)))))) | |
1774 | |
1775 (defun message-do-actions (actions) | |
1776 "Perform all actions in ACTIONS." | |
1777 ;; Now perform actions on successful sending. | |
1778 (while actions | |
1779 (ignore-errors | |
1780 (cond | |
1781 ;; A simple function. | |
1782 ((message-functionp (car actions)) | |
1783 (funcall (car actions))) | |
1784 ;; Something to be evaled. | |
1785 (t | |
1786 (eval (car actions))))) | |
1787 (pop actions))) | |
1788 | |
1789 (defun message-send-mail (&optional arg) | |
1790 (require 'mail-utils) | |
1791 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp")) | |
1792 (case-fold-search nil) | |
1793 (news (message-news-p)) | |
1794 (mailbuf (current-buffer))) | |
1795 (save-restriction | |
1796 (message-narrow-to-headers) | |
1797 ;; Insert some headers. | |
1798 (let ((message-deletable-headers | |
1799 (if news nil message-deletable-headers))) | |
1800 (message-generate-headers message-required-mail-headers)) | |
1801 ;; Let the user do all of the above. | |
1802 (run-hooks 'message-header-hook)) | |
1803 (unwind-protect | |
1804 (save-excursion | |
1805 (set-buffer tembuf) | |
1806 (erase-buffer) | |
1807 ;; Avoid copying text props. | |
1808 (insert (format | |
1809 "%s" (save-excursion | |
1810 (set-buffer mailbuf) | |
1811 (buffer-string)))) | |
1812 ;; Remove some headers. | |
1813 (save-restriction | |
1814 (message-narrow-to-headers) | |
1815 ;; Remove some headers. | |
1816 (message-remove-header message-ignored-mail-headers t)) | |
1817 (goto-char (point-max)) | |
1818 ;; require one newline at the end. | |
1819 (or (= (preceding-char) ?\n) | |
1820 (insert ?\n)) | |
1821 (when (and news | |
1822 (or (message-fetch-field "cc") | |
1823 (message-fetch-field "to"))) | |
1824 (message-insert-courtesy-copy)) | |
1825 (funcall message-send-mail-function)) | |
1826 (kill-buffer tembuf)) | |
1827 (set-buffer mailbuf) | |
1828 (push 'mail message-sent-message-via))) | |
1829 | |
1830 (defun message-send-mail-with-sendmail () | |
1831 "Send off the prepared buffer with sendmail." | |
1832 (let ((errbuf (if message-interactive | |
1833 (generate-new-buffer " sendmail errors") | |
1834 0)) | |
1835 resend-to-addresses delimline) | |
1836 (let ((case-fold-search t)) | |
1837 (save-restriction | |
1838 (message-narrow-to-headers) | |
1839 (setq resend-to-addresses (message-fetch-field "resent-to"))) | |
1840 ;; Change header-delimiter to be what sendmail expects. | |
1841 (goto-char (point-min)) | |
1842 (re-search-forward | |
1843 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
1844 (replace-match "\n") | |
1845 (backward-char 1) | |
1846 (setq delimline (point-marker)) | |
1847 (run-hooks 'message-send-mail-hook) | |
1848 ;; Insert an extra newline if we need it to work around | |
1849 ;; Sun's bug that swallows newlines. | |
1850 (goto-char (1+ delimline)) | |
1851 (when (eval message-mailer-swallows-blank-line) | |
1852 (newline)) | |
1853 (when message-interactive | |
1854 (save-excursion | |
1855 (set-buffer errbuf) | |
1856 (erase-buffer)))) | |
1857 (let ((default-directory "/")) | |
1858 (apply 'call-process-region | |
1859 (append (list (point-min) (point-max) | |
1860 (if (boundp 'sendmail-program) | |
1861 sendmail-program | |
1862 "/usr/lib/sendmail") | |
1863 nil errbuf nil "-oi") | |
1864 ;; Always specify who from, | |
1865 ;; since some systems have broken sendmails. | |
1866 ;; But some systems are more broken with -f, so | |
1867 ;; we'll let users override this. | |
1868 (if (null message-sendmail-f-is-evil) | |
1869 (list "-f" (user-login-name))) | |
1870 ;; These mean "report errors by mail" | |
1871 ;; and "deliver in background". | |
1872 (if (null message-interactive) '("-oem" "-odb")) | |
1873 ;; Get the addresses from the message | |
1874 ;; unless this is a resend. | |
1875 ;; We must not do that for a resend | |
1876 ;; because we would find the original addresses. | |
1877 ;; For a resend, include the specific addresses. | |
1878 (if resend-to-addresses | |
1879 (list resend-to-addresses) | |
1880 '("-t"))))) | |
1881 (when message-interactive | |
1882 (save-excursion | |
1883 (set-buffer errbuf) | |
1884 (goto-char (point-min)) | |
1885 (while (re-search-forward "\n\n* *" nil t) | |
1886 (replace-match "; ")) | |
1887 (if (not (zerop (buffer-size))) | |
1888 (error "Sending...failed to %s" | |
1889 (buffer-substring (point-min) (point-max))))) | |
1890 (when (bufferp errbuf) | |
1891 (kill-buffer errbuf))))) | |
1892 | |
1893 (defun message-send-mail-with-qmail () | |
1894 "Pass the prepared message buffer to qmail-inject. | |
1895 Refer to the documentation for the variable `message-send-mail-function' | |
1896 to find out how to use this." | |
1897 ;; replace the header delimiter with a blank line | |
1898 (goto-char (point-min)) | |
1899 (re-search-forward | |
1900 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
1901 (replace-match "\n") | |
1902 (run-hooks 'message-send-mail-hook) | |
1903 ;; send the message | |
1904 (case | |
1905 (apply | |
1906 'call-process-region 1 (point-max) message-qmail-inject-program | |
1907 nil nil nil | |
1908 ;; qmail-inject's default behaviour is to look for addresses on the | |
1909 ;; command line; if there're none, it scans the headers. | |
1910 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin. | |
1911 ;; | |
1912 ;; in general, ALL of qmail-inject's defaults are perfect for simply | |
1913 ;; reading a formatted (i. e., at least a To: or Resent-To header) | |
1914 ;; message from stdin. | |
1915 ;; | |
1916 ;; qmail also has the advantage of not having been raped by | |
1917 ;; various vendors, so we don't have to allow for that, either -- | |
1918 ;; compare this with message-send-mail-with-sendmail and weep | |
1919 ;; for sendmail's lost innocence. | |
1920 ;; | |
1921 ;; all this is way cool coz it lets us keep the arguments entirely | |
1922 ;; free for -inject-arguments -- a big win for the user and for us | |
1923 ;; since we don't have to play that double-guessing game and the user | |
1924 ;; gets full control (no gestapo'ish -f's, for instance). --sj | |
1925 message-qmail-inject-args) | |
1926 ;; qmail-inject doesn't say anything on it's stdout/stderr, | |
1927 ;; we have to look at the retval instead | |
1928 (0 nil) | |
1929 (1 (error "qmail-inject reported permanent failure.")) | |
1930 (111 (error "qmail-inject reported transient failure.")) | |
1931 ;; should never happen | |
1932 (t (error "qmail-inject reported unknown failure.")))) | |
1933 | |
1934 (defun message-send-mail-with-mh () | |
1935 "Send the prepared message buffer with mh." | |
1936 (let ((mh-previous-window-config nil) | |
1937 (name (make-temp-name | |
1938 (concat (file-name-as-directory | |
1939 (expand-file-name message-autosave-directory)) | |
1940 "msg.")))) | |
1941 (setq buffer-file-name name) | |
1942 ;; MH wants to generate these headers itself. | |
1943 (when message-mh-deletable-headers | |
1944 (let ((headers message-mh-deletable-headers)) | |
1945 (while headers | |
1946 (goto-char (point-min)) | |
1947 (and (re-search-forward | |
1948 (concat "^" (symbol-name (car headers)) ": *") nil t) | |
1949 (message-delete-line)) | |
1950 (pop headers)))) | |
1951 (run-hooks 'message-send-mail-hook) | |
1952 ;; Pass it on to mh. | |
1953 (mh-send-letter))) | |
1954 | |
1955 (defun message-send-news (&optional arg) | |
1956 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*")) | |
1957 (case-fold-search nil) | |
1958 (method (if (message-functionp message-post-method) | |
1959 (funcall message-post-method arg) | |
1960 message-post-method)) | |
1961 (messbuf (current-buffer)) | |
1962 (message-syntax-checks | |
1963 (if arg | |
1964 (cons '(existing-newsgroups . disabled) | |
1965 message-syntax-checks) | |
1966 message-syntax-checks)) | |
1967 result) | |
1968 (save-restriction | |
1969 (message-narrow-to-headers) | |
1970 ;; Insert some headers. | |
1971 (message-generate-headers message-required-news-headers) | |
1972 ;; Let the user do all of the above. | |
1973 (run-hooks 'message-header-hook)) | |
1974 (message-cleanup-headers) | |
1975 (if (not (message-check-news-syntax)) | |
1976 (progn | |
1977 ;;(message "Posting not performed") | |
1978 nil) | |
1979 (unwind-protect | |
1980 (save-excursion | |
1981 (set-buffer tembuf) | |
1982 (buffer-disable-undo (current-buffer)) | |
1983 (erase-buffer) | |
1984 ;; Avoid copying text props. | |
1985 (insert (format | |
1986 "%s" (save-excursion | |
1987 (set-buffer messbuf) | |
1988 (buffer-string)))) | |
1989 ;; Remove some headers. | |
1990 (save-restriction | |
1991 (message-narrow-to-headers) | |
1992 ;; Remove some headers. | |
1993 (message-remove-header message-ignored-news-headers t)) | |
1994 (goto-char (point-max)) | |
1995 ;; require one newline at the end. | |
1996 (or (= (preceding-char) ?\n) | |
1997 (insert ?\n)) | |
1998 (let ((case-fold-search t)) | |
1999 ;; Remove the delimiter. | |
2000 (goto-char (point-min)) | |
2001 (re-search-forward | |
2002 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
2003 (replace-match "\n") | |
2004 (backward-char 1)) | |
2005 (run-hooks 'message-send-news-hook) | |
2006 (require (car method)) | |
2007 (funcall (intern (format "%s-open-server" (car method))) | |
2008 (cadr method) (cddr method)) | |
2009 (setq result | |
2010 (funcall (intern (format "%s-request-post" (car method)))))) | |
2011 (kill-buffer tembuf)) | |
2012 (set-buffer messbuf) | |
2013 (if result | |
2014 (push 'news message-sent-message-via) | |
2015 (message "Couldn't send message via news: %s" | |
2016 (nnheader-get-report (car method))) | |
2017 nil)))) | |
2018 | |
2019 ;;; | |
2020 ;;; Header generation & syntax checking. | |
2021 ;;; | |
2022 | |
2023 (defmacro message-check (type &rest forms) | |
2024 "Eval FORMS if TYPE is to be checked." | |
2025 `(or (message-check-element ,type) | |
2026 (save-excursion | |
2027 ,@forms))) | |
2028 | |
2029 (put 'message-check 'lisp-indent-function 1) | |
2030 (put 'message-check 'edebug-form-spec '(form body)) | |
2031 | |
2032 (defun message-check-element (type) | |
2033 "Returns non-nil if this type is not to be checked." | |
2034 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me) | |
2035 t | |
2036 (let ((able (assq type message-syntax-checks))) | |
2037 (and (consp able) | |
2038 (eq (cdr able) 'disabled))))) | |
2039 | |
2040 (defun message-check-news-syntax () | |
2041 "Check the syntax of the message." | |
2042 (save-excursion | |
2043 (save-restriction | |
2044 (widen) | |
2045 (and | |
2046 ;; We narrow to the headers and check them first. | |
2047 (save-excursion | |
2048 (save-restriction | |
2049 (message-narrow-to-headers) | |
2050 (message-check-news-header-syntax))) | |
2051 ;; Check the body. | |
2052 (message-check-news-body-syntax))))) | |
2053 | |
2054 (defun message-check-news-header-syntax () | |
2055 (and | |
2056 ;; Check the Subject header. | |
2057 (message-check 'subject | |
2058 (let* ((case-fold-search t) | |
2059 (subject (message-fetch-field "subject"))) | |
2060 (or | |
2061 (and subject | |
2062 (not (string-match "\\`[ \t]*\\'" subject))) | |
2063 (ignore | |
2064 (message | |
2065 "The subject field is empty or missing. Posting is denied."))))) | |
2066 ;; Check for commands in Subject. | |
2067 (message-check 'subject-cmsg | |
2068 (if (string-match "^cmsg " (message-fetch-field "subject")) | |
2069 (y-or-n-p | |
2070 "The control code \"cmsg\" is in the subject. Really post? ") | |
2071 t)) | |
2072 ;; Check for multiple identical headers. | |
2073 (message-check 'multiple-headers | |
2074 (let (found) | |
2075 (while (and (not found) | |
2076 (re-search-forward "^[^ \t:]+: " nil t)) | |
2077 (save-excursion | |
2078 (or (re-search-forward | |
2079 (concat "^" | |
2080 (regexp-quote | |
2081 (setq found | |
2082 (buffer-substring | |
2083 (match-beginning 0) (- (match-end 0) 2)))) | |
2084 ":") | |
2085 nil t) | |
2086 (setq found nil)))) | |
2087 (if found | |
2088 (y-or-n-p (format "Multiple %s headers. Really post? " found)) | |
2089 t))) | |
2090 ;; Check for Version and Sendsys. | |
2091 (message-check 'sendsys | |
2092 (if (re-search-forward "^Sendsys:\\|^Version:" nil t) | |
2093 (y-or-n-p | |
2094 (format "The article contains a %s command. Really post? " | |
2095 (buffer-substring (match-beginning 0) | |
2096 (1- (match-end 0))))) | |
2097 t)) | |
2098 ;; See whether we can shorten Followup-To. | |
2099 (message-check 'shorten-followup-to | |
2100 (let ((newsgroups (message-fetch-field "newsgroups")) | |
2101 (followup-to (message-fetch-field "followup-to")) | |
2102 to) | |
2103 (when (and newsgroups | |
2104 (string-match "," newsgroups) | |
2105 (not followup-to) | |
2106 (not | |
2107 (zerop | |
2108 (length | |
2109 (setq to (completing-read | |
2110 "Followups to: (default all groups) " | |
2111 (mapcar (lambda (g) (list g)) | |
2112 (cons "poster" | |
2113 (message-tokenize-header | |
2114 newsgroups))))))))) | |
2115 (goto-char (point-min)) | |
2116 (insert "Followup-To: " to "\n")) | |
2117 t)) | |
2118 ;; Check "Shoot me". | |
2119 (message-check 'shoot | |
2120 (if (re-search-forward | |
2121 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t) | |
2122 (y-or-n-p "You appear to have a misconfigured system. Really post? ") | |
2123 t)) | |
2124 ;; Check for Approved. | |
2125 (message-check 'approved | |
2126 (if (re-search-forward "^Approved:" nil t) | |
2127 (y-or-n-p "The article contains an Approved header. Really post? ") | |
2128 t)) | |
2129 ;; Check the Message-ID header. | |
2130 (message-check 'message-id | |
2131 (let* ((case-fold-search t) | |
2132 (message-id (message-fetch-field "message-id" t))) | |
2133 (or (not message-id) | |
2134 (and (string-match "@" message-id) | |
2135 (string-match "@[^\\.]*\\." message-id)) | |
2136 (y-or-n-p | |
2137 (format "The Message-ID looks strange: \"%s\". Really post? " | |
2138 message-id))))) | |
2139 ;; Check the Newsgroups & Followup-To headers. | |
2140 (message-check 'existing-newsgroups | |
2141 (let* ((case-fold-search t) | |
2142 (newsgroups (message-fetch-field "newsgroups")) | |
2143 (followup-to (message-fetch-field "followup-to")) | |
2144 (groups (message-tokenize-header | |
2145 (if followup-to | |
2146 (concat newsgroups "," followup-to) | |
2147 newsgroups))) | |
2148 (hashtb (and (boundp 'gnus-active-hashtb) | |
2149 gnus-active-hashtb)) | |
2150 errors) | |
2151 (if (or (not hashtb) | |
2152 (not (boundp 'gnus-read-active-file)) | |
2153 (not gnus-read-active-file) | |
2154 (eq gnus-read-active-file 'some)) | |
2155 t | |
2156 (while groups | |
2157 (when (and (not (boundp (intern (car groups) hashtb))) | |
2158 (not (equal (car groups) "poster"))) | |
2159 (push (car groups) errors)) | |
2160 (pop groups)) | |
2161 (if (not errors) | |
2162 t | |
2163 (y-or-n-p | |
2164 (format | |
2165 "Really post to %s unknown group%s: %s " | |
2166 (if (= (length errors) 1) "this" "these") | |
2167 (if (= (length errors) 1) "" "s") | |
2168 (mapconcat 'identity errors ", "))))))) | |
2169 ;; Check the Newsgroups & Followup-To headers for syntax errors. | |
2170 (message-check 'valid-newsgroups | |
2171 (let ((case-fold-search t) | |
2172 (headers '("Newsgroups" "Followup-To")) | |
2173 header error) | |
2174 (while (and headers (not error)) | |
2175 (when (setq header (mail-fetch-field (car headers))) | |
2176 (if (or | |
2177 (not | |
2178 (string-match | |
2179 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'" | |
2180 header)) | |
2181 (memq | |
2182 nil (mapcar | |
2183 (lambda (g) | |
2184 (not (string-match "\\.\\'\\|\\.\\." g))) | |
2185 (message-tokenize-header header ",")))) | |
2186 (setq error t))) | |
2187 (unless error | |
2188 (pop headers))) | |
2189 (if (not error) | |
2190 t | |
2191 (y-or-n-p | |
2192 (format "The %s header looks odd: \"%s\". Really post? " | |
2193 (car headers) header))))) | |
2194 ;; Check the From header. | |
2195 (message-check 'from | |
2196 (let* ((case-fold-search t) | |
2197 (from (message-fetch-field "from")) | |
2198 (ad (nth 1 (mail-extract-address-components from)))) | |
2199 (cond | |
2200 ((not from) | |
2201 (message "There is no From line. Posting is denied.") | |
2202 nil) | |
2203 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi | |
2204 (string-match "\\.\\." ad) ;larsi@ifi..uio | |
2205 (string-match "@\\." ad) ;larsi@.ifi.uio | |
2206 (string-match "\\.$" ad) ;larsi@ifi.uio. | |
2207 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio | |
2208 (string-match "(.*).*(.*)" from)) ;(lars) (lars) | |
2209 (message | |
2210 "Denied posting -- the From looks strange: \"%s\"." from) | |
2211 nil) | |
2212 (t t)))))) | |
2213 | |
2214 (defun message-check-news-body-syntax () | |
2215 (and | |
2216 ;; Check for long lines. | |
2217 (message-check 'long-lines | |
2218 (goto-char (point-min)) | |
2219 (re-search-forward | |
2220 (concat "^" (regexp-quote mail-header-separator) "$")) | |
2221 (while (and | |
2222 (progn | |
2223 (end-of-line) | |
2224 (< (current-column) 80)) | |
2225 (zerop (forward-line 1)))) | |
2226 (or (bolp) | |
2227 (eobp) | |
2228 (y-or-n-p | |
2229 "You have lines longer than 79 characters. Really post? "))) | |
2230 ;; Check whether the article is empty. | |
2231 (message-check 'empty | |
2232 (goto-char (point-min)) | |
2233 (re-search-forward | |
2234 (concat "^" (regexp-quote mail-header-separator) "$")) | |
2235 (forward-line 1) | |
2236 (let ((b (point))) | |
2237 (goto-char (point-max)) | |
2238 (re-search-backward message-signature-separator nil t) | |
2239 (beginning-of-line) | |
2240 (or (re-search-backward "[^ \n\t]" b t) | |
2241 (y-or-n-p "Empty article. Really post? ")))) | |
2242 ;; Check for control characters. | |
2243 (message-check 'control-chars | |
2244 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t) | |
2245 (y-or-n-p | |
2246 "The article contains control characters. Really post? ") | |
2247 t)) | |
2248 ;; Check excessive size. | |
2249 (message-check 'size | |
2250 (if (> (buffer-size) 60000) | |
2251 (y-or-n-p | |
2252 (format "The article is %d octets long. Really post? " | |
2253 (buffer-size))) | |
2254 t)) | |
2255 ;; Check whether any new text has been added. | |
2256 (message-check 'new-text | |
2257 (or | |
2258 (not message-checksum) | |
2259 (not (and (eq (message-checksum) (car message-checksum)) | |
2260 (eq (buffer-size) (cdr message-checksum)))) | |
2261 (y-or-n-p | |
2262 "It looks like no new text has been added. Really post? "))) | |
2263 ;; Check the length of the signature. | |
2264 (message-check 'signature | |
2265 (goto-char (point-max)) | |
2266 (if (or (not (re-search-backward message-signature-separator nil t)) | |
2267 (search-forward message-forward-end-separator nil t)) | |
2268 t | |
2269 (if (> (count-lines (point) (point-max)) 5) | |
2270 (y-or-n-p | |
2271 (format | |
2272 "Your .sig is %d lines; it should be max 4. Really post? " | |
2273 (1- (count-lines (point) (point-max))))) | |
2274 t))))) | |
2275 | |
2276 (defun message-checksum () | |
2277 "Return a \"checksum\" for the current buffer." | |
2278 (let ((sum 0)) | |
2279 (save-excursion | |
2280 (goto-char (point-min)) | |
2281 (re-search-forward | |
2282 (concat "^" (regexp-quote mail-header-separator) "$")) | |
2283 (while (not (eobp)) | |
2284 (when (not (looking-at "[ \t\n]")) | |
2285 (setq sum (logxor (ash sum 1) (following-char)))) | |
2286 (forward-char 1))) | |
2287 sum)) | |
2288 | |
2289 (defun message-do-fcc () | |
2290 "Process Fcc headers in the current buffer." | |
2291 (let ((case-fold-search t) | |
2292 (buf (current-buffer)) | |
2293 list file) | |
2294 (save-excursion | |
2295 (set-buffer (get-buffer-create " *message temp*")) | |
2296 (buffer-disable-undo (current-buffer)) | |
2297 (erase-buffer) | |
2298 (insert-buffer-substring buf) | |
2299 (save-restriction | |
2300 (message-narrow-to-headers) | |
2301 (while (setq file (message-fetch-field "fcc")) | |
2302 (push file list) | |
2303 (message-remove-header "fcc" nil t))) | |
2304 (goto-char (point-min)) | |
2305 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$")) | |
2306 (replace-match "" t t) | |
2307 ;; Process FCC operations. | |
2308 (while list | |
2309 (setq file (pop list)) | |
2310 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file) | |
2311 ;; Pipe the article to the program in question. | |
2312 (call-process-region (point-min) (point-max) shell-file-name | |
2313 nil nil nil shell-command-switch | |
2314 (match-string 1 file)) | |
2315 ;; Save the article. | |
2316 (setq file (expand-file-name file)) | |
2317 (unless (file-exists-p (file-name-directory file)) | |
2318 (make-directory (file-name-directory file) t)) | |
2319 (if (and message-fcc-handler-function | |
2320 (not (eq message-fcc-handler-function 'rmail-output))) | |
2321 (funcall message-fcc-handler-function file) | |
2322 (if (and (file-readable-p file) (mail-file-babyl-p file)) | |
2323 (rmail-output file 1 nil t) | |
2324 (let ((mail-use-rfc822 t)) | |
2325 (rmail-output file 1 t t)))))) | |
2326 | |
2327 (kill-buffer (current-buffer))))) | |
2328 | |
2329 (defun message-output (filename) | |
2330 "Append this article to Unix/babyl mail file.." | |
2331 (if (and (file-readable-p filename) | |
2332 (mail-file-babyl-p filename)) | |
2333 (gnus-output-to-rmail filename t) | |
2334 (gnus-output-to-mail filename t))) | |
2335 | |
2336 (defun message-cleanup-headers () | |
2337 "Do various automatic cleanups of the headers." | |
2338 ;; Remove empty lines in the header. | |
2339 (save-restriction | |
2340 (message-narrow-to-headers) | |
2341 (while (re-search-forward "^[ \t]*\n" nil t) | |
2342 (replace-match "" t t))) | |
2343 | |
2344 ;; Correct Newsgroups and Followup-To headers: change sequence of | |
2345 ;; spaces to comma and eliminate spaces around commas. Eliminate | |
2346 ;; embedded line breaks. | |
2347 (goto-char (point-min)) | |
2348 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t) | |
2349 (save-restriction | |
2350 (narrow-to-region | |
2351 (point) | |
2352 (if (re-search-forward "^[^ \t]" nil t) | |
2353 (match-beginning 0) | |
2354 (forward-line 1) | |
2355 (point))) | |
2356 (goto-char (point-min)) | |
2357 (while (re-search-forward "\n[ \t]+" nil t) | |
2358 (replace-match " " t t)) ;No line breaks (too confusing) | |
2359 (goto-char (point-min)) | |
2360 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t) | |
2361 (replace-match "," t t)) | |
2362 (goto-char (point-min)) | |
2363 ;; Remove trailing commas. | |
2364 (when (re-search-forward ",+$" nil t) | |
2365 (replace-match "" t t))))) | |
2366 | |
2367 (defun message-make-date () | |
2368 "Make a valid data header." | |
2369 (let ((now (current-time))) | |
2370 (timezone-make-date-arpa-standard | |
2371 (current-time-string now) (current-time-zone now)))) | |
2372 | |
2373 (defun message-make-message-id () | |
2374 "Make a unique Message-ID." | |
2375 (concat "<" (message-unique-id) | |
2376 (let ((psubject (save-excursion (message-fetch-field "subject")))) | |
2377 (if (and message-reply-headers | |
2378 (mail-header-references message-reply-headers) | |
2379 (mail-header-subject message-reply-headers) | |
2380 psubject | |
2381 (mail-header-subject message-reply-headers) | |
2382 (not (string= | |
2383 (message-strip-subject-re | |
2384 (mail-header-subject message-reply-headers)) | |
2385 (message-strip-subject-re psubject)))) | |
2386 "_-_" "")) | |
2387 "@" (message-make-fqdn) ">")) | |
2388 | |
2389 (defvar message-unique-id-char nil) | |
2390 | |
2391 ;; If you ever change this function, make sure the new version | |
2392 ;; cannot generate IDs that the old version could. | |
2393 ;; You might for example insert a "." somewhere (not next to another dot | |
2394 ;; or string boundary), or modify the "fsf" string. | |
2395 (defun message-unique-id () | |
2396 ;; Don't use microseconds from (current-time), they may be unsupported. | |
2397 ;; Instead we use this randomly inited counter. | |
2398 (setq message-unique-id-char | |
2399 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20))))) | |
2400 ;; (current-time) returns 16-bit ints, | |
2401 ;; and 2^16*25 just fits into 4 digits i base 36. | |
2402 (* 25 25))) | |
2403 (let ((tm (current-time))) | |
2404 (concat | |
2405 (if (memq system-type '(ms-dos emx vax-vms)) | |
2406 (let ((user (downcase (user-login-name)))) | |
2407 (while (string-match "[^a-z0-9_]" user) | |
2408 (aset user (match-beginning 0) ?_)) | |
2409 user) | |
2410 (message-number-base36 (user-uid) -1)) | |
2411 (message-number-base36 (+ (car tm) | |
2412 (lsh (% message-unique-id-char 25) 16)) 4) | |
2413 (message-number-base36 (+ (nth 1 tm) | |
2414 (lsh (/ message-unique-id-char 25) 16)) 4) | |
2415 ;; Append the newsreader name, because while the generated | |
2416 ;; ID is unique to this newsreader, other newsreaders might | |
2417 ;; otherwise generate the same ID via another algorithm. | |
2418 ".fsf"))) | |
2419 | |
2420 (defun message-number-base36 (num len) | |
2421 (if (if (< len 0) | |
2422 (<= num 0) | |
2423 (= len 0)) | |
2424 "" | |
2425 (concat (message-number-base36 (/ num 36) (1- len)) | |
2426 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210" | |
2427 (% num 36)))))) | |
2428 | |
2429 (defun message-make-organization () | |
2430 "Make an Organization header." | |
2431 (let* ((organization | |
2432 (or (getenv "ORGANIZATION") | |
2433 (when message-user-organization | |
2434 (if (message-functionp message-user-organization) | |
2435 (funcall message-user-organization) | |
2436 message-user-organization))))) | |
2437 (save-excursion | |
2438 (message-set-work-buffer) | |
2439 (cond ((stringp organization) | |
2440 (insert organization)) | |
2441 ((and (eq t organization) | |
2442 message-user-organization-file | |
2443 (file-exists-p message-user-organization-file)) | |
2444 (insert-file-contents message-user-organization-file))) | |
2445 (goto-char (point-min)) | |
2446 (while (re-search-forward "[\t\n]+" nil t) | |
2447 (replace-match "" t t)) | |
2448 (unless (zerop (buffer-size)) | |
2449 (buffer-string))))) | |
2450 | |
2451 (defun message-make-lines () | |
2452 "Count the number of lines and return numeric string." | |
2453 (save-excursion | |
2454 (save-restriction | |
2455 (widen) | |
2456 (goto-char (point-min)) | |
2457 (re-search-forward | |
2458 (concat "^" (regexp-quote mail-header-separator) "$")) | |
2459 (forward-line 1) | |
2460 (int-to-string (count-lines (point) (point-max)))))) | |
2461 | |
2462 (defun message-make-in-reply-to () | |
2463 "Return the In-Reply-To header for this message." | |
2464 (when message-reply-headers | |
2465 (let ((from (mail-header-from message-reply-headers)) | |
2466 (date (mail-header-date message-reply-headers))) | |
2467 (when from | |
2468 (let ((stop-pos | |
2469 (string-match " *at \\| *@ \\| *(\\| *<" from))) | |
2470 (concat (if stop-pos (substring from 0 stop-pos) from) | |
2471 "'s message of " | |
2472 (if (or (not date) (string= date "")) | |
2473 "(unknown date)" date))))))) | |
2474 | |
2475 (defun message-make-distribution () | |
2476 "Make a Distribution header." | |
2477 (let ((orig-distribution (message-fetch-reply-field "distribution"))) | |
2478 (cond ((message-functionp message-distribution-function) | |
2479 (funcall message-distribution-function)) | |
2480 (t orig-distribution)))) | |
2481 | |
2482 (defun message-make-expires () | |
2483 "Return an Expires header based on `message-expires'." | |
2484 (let ((current (current-time)) | |
2485 (future (* 1.0 message-expires 60 60 24))) | |
2486 ;; Add the future to current. | |
2487 (setcar current (+ (car current) (round (/ future (expt 2 16))))) | |
2488 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16)))) | |
2489 ;; Return the date in the future in UT. | |
2490 (timezone-make-date-arpa-standard | |
2491 (current-time-string current) (current-time-zone current) '(0 "UT")))) | |
2492 | |
2493 (defun message-make-path () | |
2494 "Return uucp path." | |
2495 (let ((login-name (user-login-name))) | |
2496 (cond ((null message-user-path) | |
2497 (concat (system-name) "!" login-name)) | |
2498 ((stringp message-user-path) | |
2499 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com. | |
2500 (concat message-user-path "!" login-name)) | |
2501 (t login-name)))) | |
2502 | |
2503 (defun message-make-from () | |
2504 "Make a From header." | |
2505 (let* ((style message-from-style) | |
2506 (login (message-make-address)) | |
2507 (fullname | |
2508 (or (and (boundp 'user-full-name) | |
2509 user-full-name) | |
2510 (user-full-name)))) | |
2511 (when (string= fullname "&") | |
2512 (setq fullname (user-login-name))) | |
2513 (save-excursion | |
2514 (message-set-work-buffer) | |
2515 (cond | |
2516 ((or (null style) | |
2517 (equal fullname "")) | |
2518 (insert login)) | |
2519 ((or (eq style 'angles) | |
2520 (and (not (eq style 'parens)) | |
2521 ;; Use angles if no quoting is needed, or if parens would | |
2522 ;; need quoting too. | |
2523 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname)) | |
2524 (let ((tmp (concat fullname nil))) | |
2525 (while (string-match "([^()]*)" tmp) | |
2526 (aset tmp (match-beginning 0) ?-) | |
2527 (aset tmp (1- (match-end 0)) ?-)) | |
2528 (string-match "[\\()]" tmp))))) | |
2529 (insert fullname) | |
2530 (goto-char (point-min)) | |
2531 ;; Look for a character that cannot appear unquoted | |
2532 ;; according to RFC 822. | |
2533 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1) | |
2534 ;; Quote fullname, escaping specials. | |
2535 (goto-char (point-min)) | |
2536 (insert "\"") | |
2537 (while (re-search-forward "[\"\\]" nil 1) | |
2538 (replace-match "\\\\\\&" t)) | |
2539 (insert "\"")) | |
2540 (insert " <" login ">")) | |
2541 (t ; 'parens or default | |
2542 (insert login " (") | |
2543 (let ((fullname-start (point))) | |
2544 (insert fullname) | |
2545 (goto-char fullname-start) | |
2546 ;; RFC 822 says \ and nonmatching parentheses | |
2547 ;; must be escaped in comments. | |
2548 ;; Escape every instance of ()\ ... | |
2549 (while (re-search-forward "[()\\]" nil 1) | |
2550 (replace-match "\\\\\\&" t)) | |
2551 ;; ... then undo escaping of matching parentheses, | |
2552 ;; including matching nested parentheses. | |
2553 (goto-char fullname-start) | |
2554 (while (re-search-forward | |
2555 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)" | |
2556 nil 1) | |
2557 (replace-match "\\1(\\3)" t) | |
2558 (goto-char fullname-start))) | |
2559 (insert ")"))) | |
2560 (buffer-string)))) | |
2561 | |
2562 (defun message-make-sender () | |
2563 "Return the \"real\" user address. | |
2564 This function tries to ignore all user modifications, and | |
2565 give as trustworthy answer as possible." | |
2566 (concat (user-login-name) "@" (system-name))) | |
2567 | |
2568 (defun message-make-address () | |
2569 "Make the address of the user." | |
2570 (or (message-user-mail-address) | |
2571 (concat (user-login-name) "@" (message-make-domain)))) | |
2572 | |
2573 (defun message-user-mail-address () | |
2574 "Return the pertinent part of `user-mail-address'." | |
2575 (when user-mail-address | |
2576 (if (string-match " " user-mail-address) | |
2577 (nth 1 (mail-extract-address-components user-mail-address)) | |
2578 user-mail-address))) | |
2579 | |
2580 (defun message-make-fqdn () | |
2581 "Return user's fully qualified domain name." | |
2582 (let ((system-name (system-name)) | |
2583 (user-mail (message-user-mail-address))) | |
2584 (cond | |
2585 ((string-match "[^.]\\.[^.]" system-name) | |
2586 ;; `system-name' returned the right result. | |
2587 system-name) | |
2588 ;; Try `mail-host-address'. | |
2589 ((and (boundp 'mail-host-address) | |
2590 (stringp mail-host-address) | |
2591 (string-match "\\." mail-host-address)) | |
2592 mail-host-address) | |
2593 ;; We try `user-mail-address' as a backup. | |
2594 ((and (string-match "\\." user-mail) | |
2595 (string-match "@\\(.*\\)\\'" user-mail)) | |
2596 (match-string 1 user-mail)) | |
2597 ;; Default to this bogus thing. | |
2598 (t | |
2599 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me"))))) | |
2600 | |
2601 (defun message-make-host-name () | |
2602 "Return the name of the host." | |
2603 (let ((fqdn (message-make-fqdn))) | |
2604 (string-match "^[^.]+\\." fqdn) | |
2605 (substring fqdn 0 (1- (match-end 0))))) | |
2606 | |
2607 (defun message-make-domain () | |
2608 "Return the domain name." | |
2609 (or mail-host-address | |
2610 (message-make-fqdn))) | |
2611 | |
2612 (defun message-generate-headers (headers) | |
2613 "Prepare article HEADERS. | |
2614 Headers already prepared in the buffer are not modified." | |
2615 (save-restriction | |
2616 (message-narrow-to-headers) | |
2617 (let* ((Date (message-make-date)) | |
2618 (Message-ID (message-make-message-id)) | |
2619 (Organization (message-make-organization)) | |
2620 (From (message-make-from)) | |
2621 (Path (message-make-path)) | |
2622 (Subject nil) | |
2623 (Newsgroups nil) | |
2624 (In-Reply-To (message-make-in-reply-to)) | |
2625 (To nil) | |
2626 (Distribution (message-make-distribution)) | |
2627 (Lines (message-make-lines)) | |
2628 (X-Newsreader message-newsreader) | |
2629 (X-Mailer (and (not (message-fetch-field "X-Newsreader")) | |
2630 message-mailer)) | |
2631 (Expires (message-make-expires)) | |
2632 (case-fold-search t) | |
2633 header value elem) | |
2634 ;; First we remove any old generated headers. | |
2635 (let ((headers message-deletable-headers)) | |
2636 (while headers | |
2637 (goto-char (point-min)) | |
2638 (and (re-search-forward | |
2639 (concat "^" (symbol-name (car headers)) ": *") nil t) | |
2640 (get-text-property (1+ (match-beginning 0)) 'message-deletable) | |
2641 (message-delete-line)) | |
2642 (pop headers))) | |
2643 ;; Go through all the required headers and see if they are in the | |
2644 ;; articles already. If they are not, or are empty, they are | |
2645 ;; inserted automatically - except for Subject, Newsgroups and | |
2646 ;; Distribution. | |
2647 (while headers | |
2648 (goto-char (point-min)) | |
2649 (setq elem (pop headers)) | |
2650 (if (consp elem) | |
2651 (if (eq (car elem) 'optional) | |
2652 (setq header (cdr elem)) | |
2653 (setq header (car elem))) | |
2654 (setq header elem)) | |
2655 (when (or (not (re-search-forward | |
2656 (concat "^" (downcase (symbol-name header)) ":") | |
2657 nil t)) | |
2658 (progn | |
2659 ;; The header was found. We insert a space after the | |
2660 ;; colon, if there is none. | |
2661 (if (/= (following-char) ? ) (insert " ") (forward-char 1)) | |
2662 ;; Find out whether the header is empty... | |
2663 (looking-at "[ \t]*$"))) | |
2664 ;; So we find out what value we should insert. | |
2665 (setq value | |
2666 (cond | |
2667 ((and (consp elem) (eq (car elem) 'optional)) | |
2668 ;; This is an optional header. If the cdr of this | |
2669 ;; is something that is nil, then we do not insert | |
2670 ;; this header. | |
2671 (setq header (cdr elem)) | |
2672 (or (and (fboundp (cdr elem)) (funcall (cdr elem))) | |
2673 (and (boundp (cdr elem)) (symbol-value (cdr elem))))) | |
2674 ((consp elem) | |
2675 ;; The element is a cons. Either the cdr is a | |
2676 ;; string to be inserted verbatim, or it is a | |
2677 ;; function, and we insert the value returned from | |
2678 ;; this function. | |
2679 (or (and (stringp (cdr elem)) (cdr elem)) | |
2680 (and (fboundp (cdr elem)) (funcall (cdr elem))))) | |
2681 ((and (boundp header) (symbol-value header)) | |
2682 ;; The element is a symbol. We insert the value | |
2683 ;; of this symbol, if any. | |
2684 (symbol-value header)) | |
2685 (t | |
2686 ;; We couldn't generate a value for this header, | |
2687 ;; so we just ask the user. | |
2688 (read-from-minibuffer | |
2689 (format "Empty header for %s; enter value: " header))))) | |
2690 ;; Finally insert the header. | |
2691 (when (and value | |
2692 (not (equal value ""))) | |
2693 (save-excursion | |
2694 (if (bolp) | |
2695 (progn | |
2696 ;; This header didn't exist, so we insert it. | |
2697 (goto-char (point-max)) | |
2698 (insert (symbol-name header) ": " value "\n") | |
2699 (forward-line -1)) | |
2700 ;; The value of this header was empty, so we clear | |
2701 ;; totally and insert the new value. | |
2702 (delete-region (point) (gnus-point-at-eol)) | |
2703 (insert value)) | |
2704 ;; Add the deletable property to the headers that require it. | |
2705 (and (memq header message-deletable-headers) | |
2706 (progn (beginning-of-line) (looking-at "[^:]+: ")) | |
2707 (add-text-properties | |
2708 (point) (match-end 0) | |
2709 '(message-deletable t face italic) (current-buffer))))))) | |
2710 ;; Insert new Sender if the From is strange. | |
2711 (let ((from (message-fetch-field "from")) | |
2712 (sender (message-fetch-field "sender")) | |
2713 (secure-sender (message-make-sender))) | |
2714 (when (and from | |
2715 (not (message-check-element 'sender)) | |
2716 (not (string= | |
2717 (downcase | |
2718 (cadr (mail-extract-address-components from))) | |
2719 (downcase secure-sender))) | |
2720 (or (null sender) | |
2721 (not | |
2722 (string= | |
2723 (downcase | |
2724 (cadr (mail-extract-address-components sender))) | |
2725 (downcase secure-sender))))) | |
2726 (goto-char (point-min)) | |
2727 ;; Rename any old Sender headers to Original-Sender. | |
2728 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t) | |
2729 (beginning-of-line) | |
2730 (insert "Original-") | |
2731 (beginning-of-line)) | |
2732 (when (or (message-news-p) | |
2733 (string-match "^[^@]@.+\\..+" secure-sender)) | |
2734 (insert "Sender: " secure-sender "\n"))))))) | |
2735 | |
2736 (defun message-insert-courtesy-copy () | |
2737 "Insert a courtesy message in mail copies of combined messages." | |
2738 (let (newsgroups) | |
2739 (save-excursion | |
2740 (save-restriction | |
2741 (message-narrow-to-headers) | |
2742 (when (setq newsgroups (message-fetch-field "newsgroups")) | |
2743 (goto-char (point-max)) | |
2744 (insert "Posted-To: " newsgroups "\n"))) | |
2745 (forward-line 1) | |
2746 (when message-courtesy-message | |
2747 (cond | |
2748 ((string-match "%s" message-courtesy-message) | |
2749 (insert (format message-courtesy-message newsgroups))) | |
2750 (t | |
2751 (insert message-courtesy-message))))))) | |
2752 | |
2753 ;;; | |
2754 ;;; Setting up a message buffer | |
2755 ;;; | |
2756 | |
2757 (defun message-fill-address (header value) | |
2758 (save-restriction | |
2759 (narrow-to-region (point) (point)) | |
2760 (insert (capitalize (symbol-name header)) | |
2761 ": " | |
2762 (if (consp value) (car value) value) | |
2763 "\n") | |
2764 (narrow-to-region (point-min) (1- (point-max))) | |
2765 (let (quoted last) | |
2766 (goto-char (point-min)) | |
2767 (while (not (eobp)) | |
2768 (skip-chars-forward "^,\"" (point-max)) | |
2769 (if (or (= (following-char) ?,) | |
2770 (eobp)) | |
2771 (when (not quoted) | |
2772 (if (and (> (current-column) 78) | |
2773 last) | |
2774 (progn | |
2775 (save-excursion | |
2776 (goto-char last) | |
2777 (insert "\n\t")) | |
2778 (setq last (1+ (point)))) | |
2779 (setq last (1+ (point))))) | |
2780 (setq quoted (not quoted))) | |
2781 (unless (eobp) | |
2782 (forward-char 1)))) | |
2783 (goto-char (point-max)) | |
2784 (widen) | |
2785 (forward-line 1))) | |
2786 | |
2787 (defun message-fill-header (header value) | |
2788 (let ((begin (point)) | |
2789 (fill-column 78) | |
2790 (fill-prefix "\t")) | |
2791 (insert (capitalize (symbol-name header)) | |
2792 ": " | |
2793 (if (consp value) (car value) value) | |
2794 "\n") | |
2795 (save-restriction | |
2796 (narrow-to-region begin (point)) | |
2797 (fill-region-as-paragraph begin (point)) | |
2798 ;; Tapdance around looong Message-IDs. | |
2799 (forward-line -1) | |
2800 (when (looking-at "[ \t]*$") | |
2801 (message-delete-line)) | |
2802 (goto-char begin) | |
2803 (re-search-forward ":" nil t) | |
2804 (when (looking-at "\n[ \t]+") | |
2805 (replace-match " " t t)) | |
2806 (goto-char (point-max))))) | |
2807 | |
2808 (defun message-position-point () | |
2809 "Move point to where the user probably wants to find it." | |
2810 (message-narrow-to-headers) | |
2811 (cond | |
2812 ((re-search-forward "^[^:]+:[ \t]*$" nil t) | |
2813 (search-backward ":" ) | |
2814 (widen) | |
2815 (forward-char 1) | |
2816 (if (= (following-char) ? ) | |
2817 (forward-char 1) | |
2818 (insert " "))) | |
2819 (t | |
2820 (goto-char (point-max)) | |
2821 (widen) | |
2822 (forward-line 1) | |
2823 (unless (looking-at "$") | |
2824 (forward-line 2))) | |
2825 (sit-for 0))) | |
2826 | |
2827 (defun message-buffer-name (type &optional to group) | |
2828 "Return a new (unique) buffer name based on TYPE and TO." | |
2829 (cond | |
2830 ;; Check whether `message-generate-new-buffers' is a function, | |
2831 ;; and if so, call it. | |
2832 ((message-functionp message-generate-new-buffers) | |
2833 (funcall message-generate-new-buffers type to group)) | |
2834 ;; Generate a new buffer name The Message Way. | |
2835 (message-generate-new-buffers | |
2836 (generate-new-buffer-name | |
2837 (concat "*" type | |
2838 (if to | |
2839 (concat " to " | |
2840 (or (car (mail-extract-address-components to)) | |
2841 to) "") | |
2842 "") | |
2843 (if (and group (not (string= group ""))) (concat " on " group) "") | |
2844 "*"))) | |
2845 ;; Use standard name. | |
2846 (t | |
2847 (format "*%s message*" type)))) | |
2848 | |
2849 (defun message-pop-to-buffer (name) | |
2850 "Pop to buffer NAME, and warn if it already exists and is modified." | |
2851 (let ((buffer (get-buffer name))) | |
2852 (if (and buffer | |
2853 (buffer-name buffer)) | |
2854 (progn | |
2855 (set-buffer (pop-to-buffer buffer)) | |
2856 (when (and (buffer-modified-p) | |
2857 (not (y-or-n-p | |
2858 "Message already being composed; erase? "))) | |
2859 (error "Message being composed"))) | |
2860 (set-buffer (pop-to-buffer name)))) | |
2861 (erase-buffer) | |
2862 (message-mode)) | |
2863 | |
2864 (defun message-do-send-housekeeping () | |
2865 "Kill old message buffers." | |
2866 ;; We might have sent this buffer already. Delete it from the | |
2867 ;; list of buffers. | |
2868 (setq message-buffer-list (delq (current-buffer) message-buffer-list)) | |
2869 (while (and message-max-buffers | |
2870 message-buffer-list | |
2871 (>= (length message-buffer-list) message-max-buffers)) | |
2872 ;; Kill the oldest buffer -- unless it has been changed. | |
2873 (let ((buffer (pop message-buffer-list))) | |
2874 (when (and (buffer-name buffer) | |
2875 (not (buffer-modified-p buffer))) | |
2876 (kill-buffer buffer)))) | |
2877 ;; Rename the buffer. | |
2878 (if message-send-rename-function | |
2879 (funcall message-send-rename-function) | |
2880 (when (string-match "\\`\\*" (buffer-name)) | |
2881 (rename-buffer | |
2882 (concat "*sent " (substring (buffer-name) (match-end 0))) t))) | |
2883 ;; Push the current buffer onto the list. | |
2884 (when message-max-buffers | |
2885 (setq message-buffer-list | |
2886 (nconc message-buffer-list (list (current-buffer)))))) | |
2887 | |
2888 (defvar mc-modes-alist) | |
2889 (defun message-setup (headers &optional replybuffer actions) | |
2890 (when (and (boundp 'mc-modes-alist) | |
2891 (not (assq 'message-mode mc-modes-alist))) | |
2892 (push '(message-mode (encrypt . mc-encrypt-message) | |
2893 (sign . mc-sign-message)) | |
2894 mc-modes-alist)) | |
2895 (when actions | |
2896 (setq message-send-actions actions)) | |
2897 (setq message-reply-buffer replybuffer) | |
2898 (goto-char (point-min)) | |
2899 ;; Insert all the headers. | |
2900 (mail-header-format | |
2901 (let ((h headers) | |
2902 (alist message-header-format-alist)) | |
2903 (while h | |
2904 (unless (assq (caar h) message-header-format-alist) | |
2905 (push (list (caar h)) alist)) | |
2906 (pop h)) | |
2907 alist) | |
2908 headers) | |
2909 (delete-region (point) (progn (forward-line -1) (point))) | |
2910 (when message-default-headers | |
2911 (insert message-default-headers)) | |
2912 (put-text-property | |
2913 (point) | |
2914 (progn | |
2915 (insert mail-header-separator "\n") | |
2916 (1- (point))) | |
2917 'read-only nil) | |
2918 (forward-line -1) | |
2919 (when (message-news-p) | |
2920 (when message-default-news-headers | |
2921 (insert message-default-news-headers)) | |
2922 (when message-generate-headers-first | |
2923 (message-generate-headers | |
2924 (delq 'Lines | |
2925 (delq 'Subject | |
2926 (copy-sequence message-required-news-headers)))))) | |
2927 (when (message-mail-p) | |
2928 (when message-default-mail-headers | |
2929 (insert message-default-mail-headers)) | |
2930 (when message-generate-headers-first | |
2931 (message-generate-headers | |
2932 (delq 'Lines | |
2933 (delq 'Subject | |
2934 (copy-sequence message-required-mail-headers)))))) | |
2935 (run-hooks 'message-signature-setup-hook) | |
2936 (message-insert-signature) | |
2937 (message-set-auto-save-file-name) | |
2938 (save-restriction | |
2939 (message-narrow-to-headers) | |
2940 (run-hooks 'message-header-setup-hook)) | |
2941 (set-buffer-modified-p nil) | |
2942 (run-hooks 'message-setup-hook) | |
2943 (message-position-point) | |
2944 (undo-boundary)) | |
2945 | |
2946 (defun message-set-auto-save-file-name () | |
2947 "Associate the message buffer with a file in the drafts directory." | |
2948 (when message-autosave-directory | |
2949 (unless (file-exists-p message-autosave-directory) | |
2950 (make-directory message-autosave-directory t)) | |
2951 (let ((name (make-temp-name | |
2952 (expand-file-name | |
2953 (concat (file-name-as-directory message-autosave-directory) | |
2954 "msg."))))) | |
2955 (setq buffer-auto-save-file-name | |
2956 (save-excursion | |
2957 (prog1 | |
2958 (progn | |
2959 (set-buffer (get-buffer-create " *draft tmp*")) | |
2960 (setq buffer-file-name name) | |
2961 (make-auto-save-file-name)) | |
2962 (kill-buffer (current-buffer))))) | |
2963 (clear-visited-file-modtime)))) | |
2964 | |
2965 | |
2966 | |
2967 ;;; | |
2968 ;;; Commands for interfacing with message | |
2969 ;;; | |
2970 | |
2971 ;;;###autoload | |
2972 (defun message-mail (&optional to subject | |
2973 other-headers continue switch-function | |
2974 yank-action send-actions) | |
2975 "Start editing a mail message to be sent." | |
2976 (interactive) | |
2977 (let ((message-this-is-mail t)) | |
2978 (message-pop-to-buffer (message-buffer-name "mail" to)) | |
2979 (message-setup | |
2980 (nconc | |
2981 `((To . ,(or to "")) (Subject . ,(or subject ""))) | |
2982 (when other-headers other-headers))))) | |
2983 | |
2984 ;;;###autoload | |
2985 (defun message-news (&optional newsgroups subject) | |
2986 "Start editing a news article to be sent." | |
2987 (interactive) | |
2988 (let ((message-this-is-news t)) | |
2989 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)) | |
2990 (message-setup `((Newsgroups . ,(or newsgroups "")) | |
2991 (Subject . ,(or subject "")))))) | |
2992 | |
2993 ;;;###autoload | |
2994 (defun message-reply (&optional to-address wide ignore-reply-to) | |
2995 "Start editing a reply to the article in the current buffer." | |
2996 (interactive) | |
2997 (let ((cur (current-buffer)) | |
2998 from subject date reply-to to cc | |
2999 references message-id follow-to | |
3000 (inhibit-point-motion-hooks t) | |
3001 mct never-mct gnus-warning) | |
3002 (save-restriction | |
3003 (message-narrow-to-head) | |
3004 ;; Allow customizations to have their say. | |
3005 (if (not wide) | |
3006 ;; This is a regular reply. | |
3007 (if (message-functionp message-reply-to-function) | |
3008 (setq follow-to (funcall message-reply-to-function))) | |
3009 ;; This is a followup. | |
3010 (if (message-functionp message-wide-reply-to-function) | |
3011 (save-excursion | |
3012 (setq follow-to | |
3013 (funcall message-wide-reply-to-function))))) | |
3014 ;; Find all relevant headers we need. | |
3015 (setq from (message-fetch-field "from") | |
3016 date (message-fetch-field "date") | |
3017 subject (or (message-fetch-field "subject") "none") | |
3018 to (message-fetch-field "to") | |
3019 cc (message-fetch-field "cc") | |
3020 mct (message-fetch-field "mail-copies-to") | |
3021 reply-to (unless ignore-reply-to (message-fetch-field "reply-to")) | |
3022 references (message-fetch-field "references") | |
3023 message-id (message-fetch-field "message-id" t)) | |
3024 ;; Remove any (buggy) Re:'s that are present and make a | |
3025 ;; proper one. | |
3026 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject) | |
3027 (setq subject (substring subject (match-end 0)))) | |
3028 (setq subject (concat "Re: " subject)) | |
3029 | |
3030 (when (and (setq gnus-warning (message-fetch-field "gnus-warning")) | |
3031 (string-match "<[^>]+>" gnus-warning)) | |
3032 (setq message-id (match-string 0 gnus-warning))) | |
3033 | |
3034 ;; Handle special values of Mail-Copies-To. | |
3035 (when mct | |
3036 (cond ((equal (downcase mct) "never") | |
3037 (setq never-mct t) | |
3038 (setq mct nil)) | |
3039 ((equal (downcase mct) "always") | |
3040 (setq mct (or reply-to from))))) | |
3041 | |
3042 (unless follow-to | |
3043 (if (or (not wide) | |
3044 to-address) | |
3045 (setq follow-to (list (cons 'To (or to-address reply-to from)))) | |
3046 (let (ccalist) | |
3047 (save-excursion | |
3048 (message-set-work-buffer) | |
3049 (unless never-mct | |
3050 (insert (or reply-to from ""))) | |
3051 (insert (if to (concat (if (bolp) "" ", ") to "") "")) | |
3052 (insert (if mct (concat (if (bolp) "" ", ") mct) "")) | |
3053 (insert (if cc (concat (if (bolp) "" ", ") cc) "")) | |
3054 (goto-char (point-min)) | |
3055 (while (re-search-forward "[ \t]+" nil t) | |
3056 (replace-match " " t t)) | |
3057 ;; Remove addresses that match `rmail-dont-reply-to-names'. | |
3058 (insert (prog1 (rmail-dont-reply-to (buffer-string)) | |
3059 (erase-buffer))) | |
3060 (goto-char (point-min)) | |
3061 ;; Perhaps Mail-Copies-To: never removed the only address? | |
3062 (when (eobp) | |
3063 (insert (or reply-to from ""))) | |
3064 (setq ccalist | |
3065 (mapcar | |
3066 (lambda (addr) | |
3067 (cons (mail-strip-quoted-names addr) addr)) | |
3068 (message-tokenize-header (buffer-string)))) | |
3069 (let ((s ccalist)) | |
3070 (while s | |
3071 (setq ccalist (delq (assoc (car (pop s)) s) ccalist))))) | |
3072 (setq follow-to (list (cons 'To (cdr (pop ccalist))))) | |
3073 (when ccalist | |
3074 (let ((ccs (cons 'Cc (mapconcat | |
3075 (lambda (addr) (cdr addr)) ccalist ", ")))) | |
3076 (when (string-match "^ +" (cdr ccs)) | |
3077 (setcdr ccs (substring (cdr ccs) (match-end 0)))) | |
3078 (push ccs follow-to)))))) | |
3079 (widen)) | |
3080 | |
3081 (message-pop-to-buffer (message-buffer-name | |
3082 (if wide "wide reply" "reply") from | |
3083 (if wide to-address nil))) | |
3084 | |
3085 (setq message-reply-headers | |
3086 (vector 0 subject from date message-id references 0 0 "")) | |
3087 | |
3088 (message-setup | |
3089 `((Subject . ,subject) | |
3090 ,@follow-to | |
3091 ,@(if (or references message-id) | |
3092 `((References . ,(concat (or references "") (and references " ") | |
3093 (or message-id "")))) | |
3094 nil)) | |
3095 cur))) | |
3096 | |
3097 ;;;###autoload | |
3098 (defun message-wide-reply (&optional to-address ignore-reply-to) | |
3099 "Make a \"wide\" reply to the message in the current buffer." | |
3100 (interactive) | |
3101 (message-reply to-address t ignore-reply-to)) | |
3102 | |
3103 ;;;###autoload | |
3104 (defun message-followup (&optional to-newsgroups) | |
3105 "Follow up to the message in the current buffer. | |
3106 If TO-NEWSGROUPS, use that as the new Newsgroups line." | |
3107 (interactive) | |
3108 (let ((cur (current-buffer)) | |
3109 from subject date reply-to mct | |
3110 references message-id follow-to | |
3111 (inhibit-point-motion-hooks t) | |
3112 (message-this-is-news t) | |
3113 followup-to distribution newsgroups gnus-warning posted-to) | |
3114 (save-restriction | |
3115 (narrow-to-region | |
3116 (goto-char (point-min)) | |
3117 (if (search-forward "\n\n" nil t) | |
3118 (1- (point)) | |
3119 (point-max))) | |
3120 (when (message-functionp message-followup-to-function) | |
3121 (setq follow-to | |
3122 (funcall message-followup-to-function))) | |
3123 (setq from (message-fetch-field "from") | |
3124 date (message-fetch-field "date") | |
3125 subject (or (message-fetch-field "subject") "none") | |
3126 references (message-fetch-field "references") | |
3127 message-id (message-fetch-field "message-id" t) | |
3128 followup-to (message-fetch-field "followup-to") | |
3129 newsgroups (message-fetch-field "newsgroups") | |
3130 posted-to (message-fetch-field "posted-to") | |
3131 reply-to (message-fetch-field "reply-to") | |
3132 distribution (message-fetch-field "distribution") | |
3133 mct (message-fetch-field "mail-copies-to")) | |
3134 (when (and (setq gnus-warning (message-fetch-field "gnus-warning")) | |
3135 (string-match "<[^>]+>" gnus-warning)) | |
3136 (setq message-id (match-string 0 gnus-warning))) | |
3137 ;; Remove bogus distribution. | |
3138 (when (and (stringp distribution) | |
3139 (let ((case-fold-search t)) | |
3140 (string-match "world" distribution))) | |
3141 (setq distribution nil)) | |
3142 ;; Remove any (buggy) Re:'s that are present and make a | |
3143 ;; proper one. | |
3144 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject) | |
3145 (setq subject (substring subject (match-end 0)))) | |
3146 (setq subject (concat "Re: " subject)) | |
3147 (widen)) | |
3148 | |
3149 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups)) | |
3150 | |
3151 (message-setup | |
3152 `((Subject . ,subject) | |
3153 ,@(cond | |
3154 (to-newsgroups | |
3155 (list (cons 'Newsgroups to-newsgroups))) | |
3156 (follow-to follow-to) | |
3157 ((and followup-to message-use-followup-to) | |
3158 (list | |
3159 (cond | |
3160 ((equal (downcase followup-to) "poster") | |
3161 (if (or (eq message-use-followup-to 'use) | |
3162 (message-y-or-n-p "Obey Followup-To: poster? " t "\ | |
3163 You should normally obey the Followup-To: header. | |
3164 | |
3165 `Followup-To: poster' sends your response via e-mail instead of news. | |
3166 | |
3167 A typical situation where `Followup-To: poster' is used is when the poster | |
3168 does not read the newsgroup, so he wouldn't see any replies sent to it.")) | |
3169 (progn | |
3170 (setq message-this-is-news nil) | |
3171 (cons 'To (or reply-to from ""))) | |
3172 (cons 'Newsgroups newsgroups))) | |
3173 (t | |
3174 (if (or (equal followup-to newsgroups) | |
3175 (not (eq message-use-followup-to 'ask)) | |
3176 (message-y-or-n-p | |
3177 (concat "Obey Followup-To: " followup-to "? ") t "\ | |
3178 You should normally obey the Followup-To: header. | |
3179 | |
3180 `Followup-To: " followup-to "' | |
3181 directs your response to " (if (string-match "," followup-to) | |
3182 "the specified newsgroups" | |
3183 "that newsgroup only") ". | |
3184 | |
3185 If a message is posted to several newsgroups, Followup-To is often | |
3186 used to direct the following discussion to one newsgroup only, | |
3187 because discussions that are spread over several newsgroup tend to | |
3188 be fragmented and very difficult to follow. | |
3189 | |
3190 Also, some source/announcement newsgroups are not indented for discussion; | |
3191 responses here are directed to other newsgroups.")) | |
3192 (cons 'Newsgroups followup-to) | |
3193 (cons 'Newsgroups newsgroups)))))) | |
3194 (posted-to | |
3195 `((Newsgroups . ,posted-to))) | |
3196 (t | |
3197 `((Newsgroups . ,newsgroups)))) | |
3198 ,@(and distribution (list (cons 'Distribution distribution))) | |
3199 ,@(if (or references message-id) | |
3200 `((References . ,(concat (or references "") (and references " ") | |
3201 (or message-id ""))))) | |
3202 ,@(when (and mct | |
3203 (not (equal (downcase mct) "never"))) | |
3204 (list (cons 'Cc (if (equal (downcase mct) "always") | |
3205 (or reply-to from "") | |
3206 mct))))) | |
3207 | |
3208 cur) | |
3209 | |
3210 (setq message-reply-headers | |
3211 (vector 0 subject from date message-id references 0 0 "")))) | |
3212 | |
3213 | |
3214 ;;;###autoload | |
3215 (defun message-cancel-news () | |
3216 "Cancel an article you posted." | |
3217 (interactive) | |
3218 (unless (message-news-p) | |
3219 (error "This is not a news article; canceling is impossible")) | |
3220 (when (yes-or-no-p "Do you really want to cancel this article? ") | |
3221 (let (from newsgroups message-id distribution buf) | |
3222 (save-excursion | |
3223 ;; Get header info. from original article. | |
3224 (save-restriction | |
3225 (message-narrow-to-head) | |
3226 (setq from (message-fetch-field "from") | |
3227 newsgroups (message-fetch-field "newsgroups") | |
3228 message-id (message-fetch-field "message-id" t) | |
3229 distribution (message-fetch-field "distribution"))) | |
3230 ;; Make sure that this article was written by the user. | |
3231 (unless (string-equal | |
3232 (downcase (cadr (mail-extract-address-components from))) | |
3233 (downcase (message-make-address))) | |
3234 (error "This article is not yours")) | |
3235 ;; Make control message. | |
3236 (setq buf (set-buffer (get-buffer-create " *message cancel*"))) | |
3237 (buffer-disable-undo (current-buffer)) | |
3238 (erase-buffer) | |
3239 (insert "Newsgroups: " newsgroups "\n" | |
3240 "From: " (message-make-from) "\n" | |
3241 "Subject: cmsg cancel " message-id "\n" | |
3242 "Control: cancel " message-id "\n" | |
3243 (if distribution | |
3244 (concat "Distribution: " distribution "\n") | |
3245 "") | |
3246 mail-header-separator "\n" | |
3247 message-cancel-message) | |
3248 (message "Canceling your article...") | |
3249 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me)) | |
3250 (funcall message-send-news-function)) | |
3251 (message "Canceling your article...done") | |
3252 (kill-buffer buf))))) | |
3253 | |
3254 ;;;###autoload | |
3255 (defun message-supersede () | |
3256 "Start composing a message to supersede the current message. | |
3257 This is done simply by taking the old article and adding a Supersedes | |
3258 header line with the old Message-ID." | |
3259 (interactive) | |
3260 (let ((cur (current-buffer))) | |
3261 ;; Check whether the user owns the article that is to be superseded. | |
3262 (unless (string-equal | |
3263 (downcase (cadr (mail-extract-address-components | |
3264 (message-fetch-field "from")))) | |
3265 (downcase (message-make-address))) | |
3266 (error "This article is not yours")) | |
3267 ;; Get a normal message buffer. | |
3268 (message-pop-to-buffer (message-buffer-name "supersede")) | |
3269 (insert-buffer-substring cur) | |
3270 (message-narrow-to-head) | |
3271 ;; Remove unwanted headers. | |
3272 (when message-ignored-supersedes-headers | |
3273 (message-remove-header message-ignored-supersedes-headers t)) | |
3274 (goto-char (point-min)) | |
3275 (if (not (re-search-forward "^Message-ID: " nil t)) | |
3276 (error "No Message-ID in this article") | |
3277 (replace-match "Supersedes: " t t)) | |
3278 (goto-char (point-max)) | |
3279 (insert mail-header-separator) | |
3280 (widen) | |
3281 (forward-line 1))) | |
3282 | |
3283 ;;;###autoload | |
3284 (defun message-recover () | |
3285 "Reread contents of current buffer from its last auto-save file." | |
3286 (interactive) | |
3287 (let ((file-name (make-auto-save-file-name))) | |
3288 (cond ((save-window-excursion | |
3289 (if (not (eq system-type 'vax-vms)) | |
3290 (with-output-to-temp-buffer "*Directory*" | |
3291 (buffer-disable-undo standard-output) | |
3292 (let ((default-directory "/")) | |
3293 (call-process | |
3294 "ls" nil standard-output nil "-l" file-name)))) | |
3295 (yes-or-no-p (format "Recover auto save file %s? " file-name))) | |
3296 (let ((buffer-read-only nil)) | |
3297 (erase-buffer) | |
3298 (insert-file-contents file-name nil))) | |
3299 (t (error "message-recover cancelled"))))) | |
3300 | |
3301 ;;; Forwarding messages. | |
3302 | |
3303 (defun message-make-forward-subject () | |
3304 "Return a Subject header suitable for the message in the current buffer." | |
3305 (save-excursion | |
3306 (save-restriction | |
3307 (current-buffer) | |
3308 (message-narrow-to-head) | |
3309 (concat "[" (or (message-fetch-field | |
3310 (if (message-news-p) "newsgroups" "from")) | |
3311 "(nowhere)") | |
3312 "] " (or (message-fetch-field "Subject") ""))))) | |
3313 | |
3314 ;;;###autoload | |
3315 (defun message-forward (&optional news) | |
3316 "Forward the current message via mail. | |
3317 Optional NEWS will use news to forward instead of mail." | |
3318 (interactive "P") | |
3319 (let ((cur (current-buffer)) | |
3320 (subject (message-make-forward-subject)) | |
3321 art-beg) | |
3322 (if news (message-news nil subject) (message-mail nil subject)) | |
3323 ;; Put point where we want it before inserting the forwarded | |
3324 ;; message. | |
3325 (if message-signature-before-forwarded-message | |
3326 (goto-char (point-max)) | |
3327 (message-goto-body)) | |
3328 ;; Make sure we're at the start of the line. | |
3329 (unless (eolp) | |
3330 (insert "\n")) | |
3331 ;; Narrow to the area we are to insert. | |
3332 (narrow-to-region (point) (point)) | |
3333 ;; Insert the separators and the forwarded buffer. | |
3334 (insert message-forward-start-separator) | |
3335 (setq art-beg (point)) | |
3336 (insert-buffer-substring cur) | |
3337 (goto-char (point-max)) | |
3338 (insert message-forward-end-separator) | |
3339 (set-text-properties (point-min) (point-max) nil) | |
3340 ;; Remove all unwanted headers. | |
3341 (goto-char art-beg) | |
3342 (narrow-to-region (point) (if (search-forward "\n\n" nil t) | |
3343 (1- (point)) | |
3344 (point))) | |
3345 (goto-char (point-min)) | |
3346 (message-remove-header message-included-forward-headers t nil t) | |
3347 (widen) | |
3348 (message-position-point))) | |
3349 | |
3350 ;;;###autoload | |
3351 (defun message-resend (address) | |
3352 "Resend the current article to ADDRESS." | |
3353 (interactive "sResend message to: ") | |
3354 (message "Resending message to %s..." address) | |
3355 (save-excursion | |
3356 (let ((cur (current-buffer)) | |
3357 beg) | |
3358 ;; We first set up a normal mail buffer. | |
3359 (set-buffer (get-buffer-create " *message resend*")) | |
3360 (buffer-disable-undo (current-buffer)) | |
3361 (erase-buffer) | |
3362 (message-setup `((To . ,address))) | |
3363 ;; Insert our usual headers. | |
3364 (message-generate-headers '(From Date To)) | |
3365 (message-narrow-to-headers) | |
3366 ;; Rename them all to "Resent-*". | |
3367 (while (re-search-forward "^[A-Za-z]" nil t) | |
3368 (forward-char -1) | |
3369 (insert "Resent-")) | |
3370 (widen) | |
3371 (forward-line) | |
3372 (delete-region (point) (point-max)) | |
3373 (setq beg (point)) | |
3374 ;; Insert the message to be resent. | |
3375 (insert-buffer-substring cur) | |
3376 (goto-char (point-min)) | |
3377 (search-forward "\n\n") | |
3378 (forward-char -1) | |
3379 (save-restriction | |
3380 (narrow-to-region beg (point)) | |
3381 (message-remove-header message-ignored-resent-headers t) | |
3382 (goto-char (point-max))) | |
3383 (insert mail-header-separator) | |
3384 ;; Rename all old ("Also-")Resent headers. | |
3385 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t) | |
3386 (beginning-of-line) | |
3387 (insert "Also-")) | |
3388 ;; Quote any "From " lines at the beginning. | |
3389 (goto-char beg) | |
3390 (when (looking-at "From ") | |
3391 (replace-match "X-From-Line: ")) | |
3392 ;; Send it. | |
3393 (message-send-mail) | |
3394 (kill-buffer (current-buffer))) | |
3395 (message "Resending message to %s...done" address))) | |
3396 | |
3397 ;;;###autoload | |
3398 (defun message-bounce () | |
3399 "Re-mail the current message. | |
3400 This only makes sense if the current message is a bounce message than | |
3401 contains some mail you have written which has been bounced back to | |
3402 you." | |
3403 (interactive) | |
3404 (let ((cur (current-buffer)) | |
3405 boundary) | |
3406 (message-pop-to-buffer (message-buffer-name "bounce")) | |
3407 (insert-buffer-substring cur) | |
3408 (undo-boundary) | |
3409 (message-narrow-to-head) | |
3410 (if (and (message-fetch-field "Mime-Version") | |
3411 (setq boundary (message-fetch-field "Content-Type"))) | |
3412 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary) | |
3413 (setq boundary (concat (match-string 1 boundary) " *\n" | |
3414 "Content-Type: message/rfc822")) | |
3415 (setq boundary nil))) | |
3416 (widen) | |
3417 (goto-char (point-min)) | |
3418 (search-forward "\n\n" nil t) | |
3419 (or (and boundary | |
3420 (re-search-forward boundary nil t) | |
3421 (forward-line 2)) | |
3422 (and (re-search-forward message-unsent-separator nil t) | |
3423 (forward-line 1)) | |
3424 (re-search-forward "^Return-Path:.*\n" nil t)) | |
3425 ;; We remove everything before the bounced mail. | |
3426 (delete-region | |
3427 (point-min) | |
3428 (if (re-search-forward "^[^ \n\t]+:" nil t) | |
3429 (match-beginning 0) | |
3430 (point))) | |
3431 (save-restriction | |
3432 (message-narrow-to-head) | |
3433 (message-remove-header message-ignored-bounced-headers t) | |
3434 (goto-char (point-max)) | |
3435 (insert mail-header-separator)) | |
3436 (message-position-point))) | |
3437 | |
3438 ;;; | |
3439 ;;; Interactive entry points for new message buffers. | |
3440 ;;; | |
3441 | |
3442 ;;;###autoload | |
3443 (defun message-mail-other-window (&optional to subject) | |
3444 "Like `message-mail' command, but display mail buffer in another window." | |
3445 (interactive) | |
3446 (let ((pop-up-windows t) | |
3447 (special-display-buffer-names nil) | |
3448 (special-display-regexps nil) | |
3449 (same-window-buffer-names nil) | |
3450 (same-window-regexps nil)) | |
3451 (message-pop-to-buffer (message-buffer-name "mail" to))) | |
3452 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))) | |
3453 | |
3454 ;;;###autoload | |
3455 (defun message-mail-other-frame (&optional to subject) | |
3456 "Like `message-mail' command, but display mail buffer in another frame." | |
3457 (interactive) | |
3458 (let ((pop-up-frames t) | |
3459 (special-display-buffer-names nil) | |
3460 (special-display-regexps nil) | |
3461 (same-window-buffer-names nil) | |
3462 (same-window-regexps nil)) | |
3463 (message-pop-to-buffer (message-buffer-name "mail" to))) | |
3464 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))) | |
3465 | |
3466 ;;;###autoload | |
3467 (defun message-news-other-window (&optional newsgroups subject) | |
3468 "Start editing a news article to be sent." | |
3469 (interactive) | |
3470 (let ((pop-up-windows t) | |
3471 (special-display-buffer-names nil) | |
3472 (special-display-regexps nil) | |
3473 (same-window-buffer-names nil) | |
3474 (same-window-regexps nil)) | |
3475 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))) | |
3476 (message-setup `((Newsgroups . ,(or newsgroups "")) | |
3477 (Subject . ,(or subject ""))))) | |
3478 | |
3479 ;;;###autoload | |
3480 (defun message-news-other-frame (&optional newsgroups subject) | |
3481 "Start editing a news article to be sent." | |
3482 (interactive) | |
3483 (let ((pop-up-frames t) | |
3484 (special-display-buffer-names nil) | |
3485 (special-display-regexps nil) | |
3486 (same-window-buffer-names nil) | |
3487 (same-window-regexps nil)) | |
3488 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))) | |
3489 (message-setup `((Newsgroups . ,(or newsgroups "")) | |
3490 (Subject . ,(or subject ""))))) | |
3491 | |
3492 ;;; underline.el | |
3493 | |
3494 ;; This code should be moved to underline.el (from which it is stolen). | |
3495 | |
3496 ;;;###autoload | |
3497 (defun bold-region (start end) | |
3498 "Bold all nonblank characters in the region. | |
3499 Works by overstriking characters. | |
3500 Called from program, takes two arguments START and END | |
3501 which specify the range to operate on." | |
3502 (interactive "r") | |
3503 (save-excursion | |
3504 (let ((end1 (make-marker))) | |
3505 (move-marker end1 (max start end)) | |
3506 (goto-char (min start end)) | |
3507 (while (< (point) end1) | |
3508 (or (looking-at "[_\^@- ]") | |
3509 (insert (following-char) "\b")) | |
3510 (forward-char 1))))) | |
3511 | |
3512 ;;;###autoload | |
3513 (defun unbold-region (start end) | |
3514 "Remove all boldness (overstruck characters) in the region. | |
3515 Called from program, takes two arguments START and END | |
3516 which specify the range to operate on." | |
3517 (interactive "r") | |
3518 (save-excursion | |
3519 (let ((end1 (make-marker))) | |
3520 (move-marker end1 (max start end)) | |
3521 (goto-char (min start end)) | |
3522 (while (re-search-forward "\b" end1 t) | |
3523 (if (eq (following-char) (char-after (- (point) 2))) | |
3524 (delete-char -2)))))) | |
3525 | |
3526 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark) | |
3527 | |
3528 ;; Support for toolbar | |
3529 (when (string-match "XEmacs\\|Lucid" emacs-version) | |
3530 (require 'messagexmas)) | |
3531 | |
3532 ;;; Group name completion. | |
3533 | |
3534 (defvar message-newgroups-header-regexp | |
3535 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" | |
3536 "Regexp that match headers that lists groups.") | |
3537 | |
3538 (defun message-tab () | |
3539 "Expand group names in Newsgroups and Followup-To headers. | |
3540 Do a `tab-to-tab-stop' if not in those headers." | |
3541 (interactive) | |
3542 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp)) | |
3543 (mail-abbrev-in-expansion-header-p)) | |
3544 (message-expand-group) | |
3545 (tab-to-tab-stop))) | |
3546 | |
3547 (defvar gnus-active-hashtb) | |
3548 (defun message-expand-group () | |
3549 (let* ((b (save-excursion | |
3550 (save-restriction | |
3551 (narrow-to-region | |
3552 (save-excursion | |
3553 (beginning-of-line) | |
3554 (skip-chars-forward "^:") | |
3555 (1+ (point))) | |
3556 (point)) | |
3557 (skip-chars-backward "^, \t\n") (point)))) | |
3558 (completion-ignore-case t) | |
3559 (string (buffer-substring b (point))) | |
3560 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)) | |
3561 (completions (all-completions string hashtb)) | |
3562 (cur (current-buffer)) | |
3563 comp) | |
3564 (delete-region b (point)) | |
3565 (cond | |
3566 ((= (length completions) 1) | |
3567 (if (string= (car completions) string) | |
3568 (progn | |
3569 (insert string) | |
3570 (message "Only matching group")) | |
3571 (insert (car completions)))) | |
3572 ((and (setq comp (try-completion string hashtb)) | |
3573 (not (string= comp string))) | |
3574 (insert comp)) | |
3575 (t | |
3576 (insert string) | |
3577 (if (not comp) | |
3578 (message "No matching groups") | |
3579 (pop-to-buffer "*Completions*") | |
3580 (buffer-disable-undo (current-buffer)) | |
3581 (let ((buffer-read-only nil)) | |
3582 (erase-buffer) | |
3583 (let ((standard-output (current-buffer))) | |
3584 (display-completion-list (sort completions 'string<))) | |
3585 (goto-char (point-min)) | |
3586 (pop-to-buffer cur))))))) | |
3587 | |
3588 ;;; Help stuff. | |
3589 | |
3590 (defun message-talkative-question (ask question show &rest text) | |
19525
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
3591 "Call FUNCTION with argument QUESTION; optionally display TEXT... args. |
59026d8478f7
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
19481
diff
changeset
|
3592 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer. |
17493 | 3593 The following arguments may contain lists of values." |
3594 (if (and show | |
3595 (setq text (message-flatten-list text))) | |
3596 (save-window-excursion | |
3597 (save-excursion | |
3598 (with-output-to-temp-buffer " *MESSAGE information message*" | |
3599 (set-buffer " *MESSAGE information message*") | |
3600 (mapcar 'princ text) | |
3601 (goto-char (point-min)))) | |
3602 (funcall ask question)) | |
3603 (funcall ask question))) | |
3604 | |
3605 (defun message-flatten-list (list) | |
3606 "Return a new, flat list that contains all elements of LIST. | |
3607 | |
3608 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7)) | |
3609 => (1 2 3 4 5 6 7)" | |
3610 (cond ((consp list) | |
3611 (apply 'append (mapcar 'message-flatten-list list))) | |
3612 (list | |
3613 (list list)))) | |
3614 | |
3615 (defun message-generate-new-buffer-clone-locals (name &optional varstr) | |
3616 "Create and return a buffer with a name based on NAME using generate-new-buffer. | |
3617 Then clone the local variables and values from the old buffer to the | |
3618 new one, cloning only the locals having a substring matching the | |
3619 regexp varstr." | |
3620 (let ((oldlocals (buffer-local-variables))) | |
3621 (save-excursion | |
3622 (set-buffer (generate-new-buffer name)) | |
3623 (mapcar (lambda (dude) | |
3624 (when (and (car dude) | |
3625 (or (not varstr) | |
3626 (string-match varstr (symbol-name (car dude))))) | |
3627 (ignore-errors | |
3628 (set (make-local-variable (car dude)) | |
3629 (cdr dude))))) | |
3630 oldlocals) | |
3631 (current-buffer)))) | |
3632 | |
3633 (run-hooks 'message-load-hook) | |
3634 | |
3635 (provide 'message) | |
3636 | |
3637 ;;; message.el ends here |