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