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