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