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