(shr-render-td): Only do colours at the final rendering.
[gnus.git] / lisp / gnus-msg.el
blob08fef2327ad47961bd698d9c746f7122bdd29a20
1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2011 Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 (eval-when-compile (require 'cl))
30 (require 'gnus)
31 (require 'gnus-ems)
32 (require 'message)
33 (require 'gnus-art)
34 (require 'gnus-util)
36 (defcustom gnus-post-method 'current
37 "*Preferred method for posting USENET news.
39 If this variable is `current' (which is the default), Gnus will use
40 the \"current\" select method when posting. If it is `native', Gnus
41 will use the native select method when posting.
43 This method will not be used in mail groups and the like, only in
44 \"real\" newsgroups.
46 If not `native' nor `current', the value must be a valid method as discussed
47 in the documentation of `gnus-select-method'. It can also be a list of
48 methods. If that is the case, the user will be queried for what select
49 method to use when posting."
50 :group 'gnus-group-foreign
51 :link '(custom-manual "(gnus)Posting Server")
52 :type `(choice (const native)
53 (const current)
54 (sexp :tag "Methods" ,gnus-select-method)))
56 (defcustom gnus-outgoing-message-group nil
57 "All outgoing messages will be put in this group.
58 If you want to store all your outgoing mail and articles in the group
59 \"nnml:archive\", you set this variable to that value. This variable
60 can also be a list of group names.
62 If you want to have greater control over what group to put each
63 message in, you can set this variable to a function that checks the
64 current newsgroup name and then returns a suitable group name (or list
65 of names)."
66 :group 'gnus-message
67 :type '(choice (const nil)
68 (function)
69 (string :tag "Group")
70 (repeat :tag "List of groups" (string :tag "Group"))))
72 (make-obsolete-variable 'gnus-outgoing-message-group 'gnus-message-archive-group "24.1")
74 (defcustom gnus-mailing-list-groups nil
75 "*If non-nil a regexp matching groups that are really mailing lists.
76 This is useful when you're reading a mailing list that has been
77 gatewayed to a newsgroup, and you want to followup to an article in
78 the group."
79 :group 'gnus-message
80 :type '(choice (regexp)
81 (const nil)))
83 (defcustom gnus-add-to-list nil
84 "*If non-nil, add a `to-list' parameter automatically."
85 :group 'gnus-message
86 :type 'boolean)
88 (defcustom gnus-crosspost-complaint
89 "Hi,
91 You posted the article below with the following Newsgroups header:
93 Newsgroups: %s
95 The %s group, at least, was an inappropriate recipient
96 of this message. Please trim your Newsgroups header to exclude this
97 group before posting in the future.
99 Thank you.
102 "Format string to be inserted when complaining about crossposts.
103 The first %s will be replaced by the Newsgroups header;
104 the second with the current group name."
105 :group 'gnus-message
106 :type 'string)
108 (defcustom gnus-message-setup-hook nil
109 "Hook run after setting up a message buffer."
110 :group 'gnus-message
111 :options '(message-remove-blank-cited-lines)
112 :type 'hook)
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
116 :group 'gnus-message
117 :type 'boolean)
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
122 :group 'gnus-message
123 :link '(custom-manual "(gnus)Posting Styles")
124 :type '(repeat (cons (choice (regexp)
125 (variable)
126 (list (const header)
127 (string :tag "Header")
128 (regexp :tag "Regexp"))
129 (function)
130 (sexp))
131 (repeat (list
132 (choice (const signature)
133 (const signature-file)
134 (const organization)
135 (const address)
136 (const x-face-file)
137 (const name)
138 (const body)
139 (symbol)
140 (string :tag "Header"))
141 (choice (string)
142 (function)
143 (variable)
144 (sexp)))))))
146 (defcustom gnus-gcc-mark-as-read nil
147 "If non-nil, automatically mark Gcc articles as read."
148 :version "22.1"
149 :group 'gnus-message
150 :type 'boolean)
152 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
153 'gnus-gcc-mark-as-read "Emacs 22.1")
155 (defcustom gnus-gcc-externalize-attachments nil
156 "Should local-file attachments be included as external parts in Gcc copies?
157 If it is `all', attach files as external parts;
158 if a regexp and matches the Gcc group name, attach files as external parts;
159 if nil, attach files as normal parts."
160 :version "22.1"
161 :group 'gnus-message
162 :type '(choice (const nil :tag "None")
163 (const all :tag "Any")
164 (string :tag "Regexp")))
166 (gnus-define-group-parameter
167 posting-charset-alist
168 :type list
169 :function-document
170 "Return the permitted unencoded charsets for posting of GROUP."
171 :variable gnus-group-posting-charset-alist
172 :variable-default
173 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
174 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
175 (message-this-is-mail nil nil)
176 (message-this-is-news nil t))
177 :variable-document
178 "Alist of regexps and permitted unencoded charsets for posting.
179 Each element of the alist has the form (TEST HEADER BODY-LIST), where
180 TEST is either a regular expression matching the newsgroup header or a
181 variable to query,
182 HEADER is the charset which may be left unencoded in the header (nil
183 means encode all charsets),
184 BODY-LIST is a list of charsets which may be encoded using 8bit
185 content-transfer encoding in the body, or one of the special values
186 nil (always encode using quoted-printable) or t (always use 8bit).
188 Note that any value other than nil for HEADER infringes some RFCs, so
189 use this option with care."
190 :variable-group gnus-charset
191 :variable-type
192 '(repeat (list :tag "Permitted unencoded charsets"
193 (choice :tag "Where"
194 (regexp :tag "Group")
195 (const :tag "Mail message" :value message-this-is-mail)
196 (const :tag "News article" :value message-this-is-news))
197 (choice :tag "Header"
198 (const :tag "None" nil)
199 (symbol :tag "Charset"))
200 (choice :tag "Body"
201 (const :tag "Any" :value t)
202 (const :tag "None" :value nil)
203 (repeat :tag "Charsets"
204 (symbol :tag "Charset")))))
205 :parameter-type '(choice :tag "Permitted unencoded charsets"
206 :value nil
207 (repeat (symbol)))
208 :parameter-document "\
209 List of charsets that are permitted to be unencoded.")
211 (defcustom gnus-debug-files
212 '("gnus.el" "gnus-sum.el" "gnus-group.el"
213 "gnus-art.el" "gnus-start.el" "gnus-async.el"
214 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
215 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
216 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
217 "Files whose variables will be reported in `gnus-bug'."
218 :version "22.1"
219 :group 'gnus-message
220 :type '(repeat (string :tag "File")))
222 (defcustom gnus-debug-exclude-variables
223 '(mm-mime-mule-charset-alist
224 nnmail-split-fancy message-minibuffer-local-map)
225 "Variables that should not be reported in `gnus-bug'."
226 :version "22.1"
227 :group 'gnus-message
228 :type '(repeat (symbol :tag "Variable")))
230 (defcustom gnus-discouraged-post-methods
231 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
232 "A list of back ends that are not used in \"real\" newsgroups.
233 This variable is used only when `gnus-post-method' is `current'."
234 :version "22.1"
235 :group 'gnus-group-foreign
236 :type '(repeat (symbol :tag "Back end")))
238 (defcustom gnus-message-replysign
240 "Automatically sign replies to signed messages.
241 See also the `mml-default-sign-method' variable."
242 :group 'gnus-message
243 :type 'boolean)
245 (defcustom gnus-message-replyencrypt t
246 "Automatically encrypt replies to encrypted messages.
247 See also the `mml-default-encrypt-method' variable."
248 :version "24.1"
249 :group 'gnus-message
250 :type 'boolean)
252 (defcustom gnus-message-replysignencrypted
254 "Setting this causes automatically encrypted messages to also be signed."
255 :group 'gnus-message
256 :type 'boolean)
258 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
259 (not gnus-expert-user))
260 "If non-nil, Gnus requests confirmation when replying to news.
261 This is done because new users often reply by mistake when reading
262 news.
263 This can also be a function receiving the group name as the only
264 parameter, which should return non-nil if a confirmation is needed; or
265 a regexp, in which case a confirmation is asked for if the group name
266 matches the regexp."
267 :version "23.1" ;; No Gnus (default changed)
268 :group 'gnus-message
269 :type '(choice (const :tag "No" nil)
270 (const :tag "Yes" t)
271 (regexp :tag "If group matches regexp")
272 (function :tag "If function evaluates to non-nil")))
274 (defcustom gnus-confirm-treat-mail-like-news
276 "If non-nil, Gnus will treat mail like news with regard to confirmation
277 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
278 for fine-tuning this.
279 If nil, Gnus will never ask for confirmation if replying to mail."
280 :version "22.1"
281 :group 'gnus-message
282 :type 'boolean)
284 (defcustom gnus-summary-resend-default-address t
285 "If non-nil, Gnus tries to suggest a default address to resend to.
286 If nil, the address field will always be empty after invoking
287 `gnus-summary-resend-message'."
288 :version "22.1"
289 :group 'gnus-message
290 :type 'boolean)
292 (defcustom gnus-message-highlight-citation
293 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
294 "Enable highlighting of different citation levels in message-mode."
295 :version "23.1" ;; No Gnus
296 :group 'gnus-cite
297 :group 'gnus-message
298 :type 'boolean)
300 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
302 ;;; Internal variables.
304 (defvar gnus-inhibit-posting-styles nil
305 "Inhibit the use of posting styles.")
307 (defvar gnus-article-yanked-articles nil)
308 (defvar gnus-message-buffer "*Mail Gnus*")
309 (defvar gnus-article-copy nil)
310 (defvar gnus-check-before-posting nil)
311 (defvar gnus-last-posting-server nil)
312 (defvar gnus-message-group-art nil)
314 (defvar gnus-msg-force-broken-reply-to nil)
316 (defconst gnus-bug-message
317 "Sending a bug report to the Gnus Towers.
318 ========================================
320 The buffer below is a mail buffer. When you press `C-c C-c', it will
321 be sent to the Gnus Bug Exterminators.
323 The thing near the bottom of the buffer is how the environment
324 settings will be included in the mail. Please do not delete that.
325 They will tell the Bug People what your environment is, so that it
326 will be easier to locate the bugs.
328 If you have found a bug that makes Emacs go \"beep\", set
329 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
330 and include the backtrace in your bug report.
332 Please describe the bug in annoying, painstaking detail.
334 Thank you for your help in stamping out bugs.
337 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
341 ;;; Gnus Posting Functions
344 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
345 "p" gnus-summary-post-news
346 "i" gnus-summary-news-other-window
347 "f" gnus-summary-followup
348 "F" gnus-summary-followup-with-original
349 "c" gnus-summary-cancel-article
350 "s" gnus-summary-supersede-article
351 "r" gnus-summary-reply
352 "y" gnus-summary-yank-message
353 "R" gnus-summary-reply-with-original
354 "w" gnus-summary-wide-reply
355 "W" gnus-summary-wide-reply-with-original
356 "v" gnus-summary-very-wide-reply
357 "V" gnus-summary-very-wide-reply-with-original
358 "n" gnus-summary-followup-to-mail
359 "N" gnus-summary-followup-to-mail-with-original
360 "m" gnus-summary-mail-other-window
361 "u" gnus-uu-post-news
362 "\M-c" gnus-summary-mail-crosspost-complaint
363 "Br" gnus-summary-reply-broken-reply-to
364 "BR" gnus-summary-reply-broken-reply-to-with-original
365 "om" gnus-summary-mail-forward
366 "op" gnus-summary-post-forward
367 "Om" gnus-uu-digest-mail-forward
368 "Op" gnus-uu-digest-post-forward)
370 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
371 "b" gnus-summary-resend-bounced-mail
372 ;; "c" gnus-summary-send-draft
373 "r" gnus-summary-resend-message
374 "e" gnus-summary-resend-message-edit)
376 ;;; Internal functions.
378 (defun gnus-inews-make-draft (articles)
379 `(lambda ()
380 (gnus-inews-make-draft-meta-information
381 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
383 (defvar gnus-article-reply nil)
384 (defmacro gnus-setup-message (config &rest forms)
385 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
386 (buffer (make-symbol "gnus-setup-message-buffer"))
387 (article (make-symbol "gnus-setup-message-article"))
388 (yanked (make-symbol "gnus-setup-yanked-articles"))
389 (group (make-symbol "gnus-setup-message-group")))
390 `(let ((,winconf (current-window-configuration))
391 (,buffer (buffer-name (current-buffer)))
392 (,article gnus-article-reply)
393 (,yanked gnus-article-yanked-articles)
394 (,group gnus-newsgroup-name)
395 (message-header-setup-hook
396 (copy-sequence message-header-setup-hook))
397 (mbl mml-buffer-list)
398 (message-mode-hook (copy-sequence message-mode-hook)))
399 (setq mml-buffer-list nil)
400 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
401 ;; message-newsreader and message-mailer were formerly set in
402 ;; gnus-inews-add-send-actions, but this is too late when
403 ;; message-generate-headers-first is used. --ansel
404 (add-hook 'message-mode-hook
405 (lambda nil
406 (setq message-newsreader
407 (setq message-mailer (gnus-extended-version)))))
408 ;; #### FIXME: for a reason that I did not manage to identify yet,
409 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
410 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
411 ;; After evaluation of @forms below, it gets the value we actually want
412 ;; to override, and the posting styles are used. For that reason, I've
413 ;; added an optional argument to `gnus-configure-posting-styles' to
414 ;; make sure that the correct value for the group name is used. -- drv
415 (add-hook 'message-mode-hook
416 (if (memq ,config '(reply-yank reply))
417 (lambda ()
418 (gnus-configure-posting-styles ,group))
419 (lambda ()
420 ;; There may be an old " *gnus article copy*" buffer.
421 (let (gnus-article-copy)
422 (gnus-configure-posting-styles ,group)))))
423 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
424 message-required-headers)
425 (when (and ,group
426 (not (string= ,group "")))
427 (push (cons
428 (intern gnus-draft-meta-information-header)
429 (gnus-inews-make-draft (or ,yanked ,article)))
430 message-required-headers))
431 (unwind-protect
432 (progn
433 ,@forms)
434 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
435 ,yanked)
436 (setq gnus-message-buffer (current-buffer))
437 (set (make-local-variable 'gnus-message-group-art)
438 (cons ,group ,article))
439 (set (make-local-variable 'gnus-newsgroup-name) ,group)
440 ;; Enable highlighting of different citation levels
441 (when gnus-message-highlight-citation
442 (gnus-message-citation-mode 1))
443 (gnus-run-hooks 'gnus-message-setup-hook)
444 (if (eq major-mode 'message-mode)
445 (let ((mbl1 mml-buffer-list))
446 (setq mml-buffer-list mbl) ;; Global value
447 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
448 (gnus-make-local-hook 'kill-buffer-hook)
449 (gnus-make-local-hook 'change-major-mode-hook)
450 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
451 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
452 (mml-destroy-buffers)
453 (setq mml-buffer-list mbl)))
454 (message-hide-headers)
455 (gnus-add-buffer)
456 (gnus-configure-windows ,config t)
457 (run-hooks 'post-command-hook)
458 (set-buffer-modified-p nil))))
460 (defun gnus-inews-make-draft-meta-information (group articles)
461 (when (numberp articles)
462 (setq articles (list articles)))
463 (concat "(\"" group "\""
464 (if articles
465 (concat " "
466 (mapconcat
467 (lambda (elem)
468 (number-to-string
469 (if (consp elem)
470 (car elem)
471 elem)))
472 articles " "))
474 ")"))
476 ;;;###autoload
477 (defun gnus-msg-mail (&optional to subject other-headers continue
478 switch-action yank-action send-actions return-action)
479 "Start editing a mail message to be sent.
480 Like `message-mail', but with Gnus paraphernalia, particularly the
481 Gcc: header for archiving purposes."
482 (interactive)
483 (let ((buf (current-buffer))
484 mail-buf)
485 (gnus-setup-message 'message
486 (message-mail to subject other-headers continue
487 nil yank-action send-actions return-action))
488 (when switch-action
489 (setq mail-buf (current-buffer))
490 (switch-to-buffer buf)
491 (apply switch-action mail-buf nil)))
492 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
495 ;;;###autoload
496 (defun gnus-button-mailto (address)
497 "Mail to ADDRESS."
498 (set-buffer (gnus-copy-article-buffer))
499 (gnus-setup-message 'message
500 (message-reply address)))
502 ;;;###autoload
503 (defun gnus-button-reply (&optional to-address wide)
504 "Like `message-reply'."
505 (interactive)
506 (gnus-setup-message 'message
507 (message-reply to-address wide)))
509 ;;;###autoload
510 (define-mail-user-agent 'gnus-user-agent
511 'gnus-msg-mail 'message-send-and-exit
512 'message-kill-buffer 'message-send-hook)
514 (defun gnus-setup-posting-charset (group)
515 (let ((alist gnus-group-posting-charset-alist)
516 (group (or group ""))
517 elem)
518 (when group
519 (catch 'found
520 (while (setq elem (pop alist))
521 (when (or (and (stringp (car elem))
522 (string-match (car elem) group))
523 (and (functionp (car elem))
524 (funcall (car elem) group))
525 (and (symbolp (car elem))
526 (symbol-value (car elem))))
527 (throw 'found (cons (cadr elem) (caddr elem)))))))))
529 (defun gnus-inews-add-send-actions (winconf buffer article
530 &optional config yanked)
531 (gnus-make-local-hook 'message-sent-hook)
532 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
533 'gnus-inews-do-gcc) nil t)
534 (when gnus-agent
535 (gnus-make-local-hook 'message-header-hook)
536 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
537 (setq message-post-method
538 `(lambda (&optional arg)
539 (gnus-post-method arg ,gnus-newsgroup-name)))
540 (message-add-action
541 `(when (gnus-buffer-exists-p ,buffer)
542 (set-window-configuration ,winconf))
543 'exit 'postpone 'kill)
544 (let ((to-be-marked (cond
545 (yanked
546 (mapcar
547 (lambda (x) (if (listp x) (car x) x)) yanked))
548 (article (if (listp article) article (list article)))
549 (t nil))))
550 (message-add-action
551 `(when (gnus-buffer-exists-p ,buffer)
552 (with-current-buffer ,buffer
553 ,(when to-be-marked
554 (if (eq config 'forward)
555 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
556 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
557 'send)))
559 (put 'gnus-setup-message 'lisp-indent-function 1)
560 (put 'gnus-setup-message 'edebug-form-spec '(form body))
562 ;;; Post news commands of Gnus group mode and summary mode
564 (defun gnus-group-mail (&optional arg)
565 "Start composing a mail.
566 If ARG, use the group under the point to find a posting style.
567 If ARG is 1, prompt for a group name to find the posting style."
568 (interactive "P")
569 ;; We can't `let' gnus-newsgroup-name here, since that leads
570 ;; to local variables leaking.
571 (let ((group gnus-newsgroup-name)
572 ;; make sure last viewed article doesn't affect posting styles:
573 (gnus-article-copy)
574 (buffer (current-buffer)))
575 (unwind-protect
576 (progn
577 (setq gnus-newsgroup-name
578 (if arg
579 (if (= 1 (prefix-numeric-value arg))
580 (gnus-group-completing-read
581 "Use posting style of group"
582 nil (gnus-read-active-file-p))
583 (gnus-group-group-name))
584 ""))
585 ;; #### see comment in gnus-setup-message -- drv
586 (gnus-setup-message 'message (message-mail)))
587 (with-current-buffer buffer
588 (setq gnus-newsgroup-name group)))))
590 (defun gnus-group-news (&optional arg)
591 "Start composing a news.
592 If ARG, post to group under point.
593 If ARG is 1, prompt for group name to post to.
595 This function prepares a news even when using mail groups. This is useful
596 for posting messages to mail groups without actually sending them over the
597 network. The corresponding back end must have a 'request-post method."
598 (interactive "P")
599 ;; We can't `let' gnus-newsgroup-name here, since that leads
600 ;; to local variables leaking.
601 (let ((group gnus-newsgroup-name)
602 ;; make sure last viewed article doesn't affect posting styles:
603 (gnus-article-copy)
604 (buffer (current-buffer)))
605 (unwind-protect
606 (progn
607 (setq gnus-newsgroup-name
608 (if arg
609 (if (= 1 (prefix-numeric-value arg))
610 (gnus-group-completing-read "Use group"
612 (gnus-read-active-file-p))
613 (gnus-group-group-name))
614 ""))
615 ;; #### see comment in gnus-setup-message -- drv
616 (gnus-setup-message 'message
617 (message-news (gnus-group-real-name gnus-newsgroup-name))))
618 (with-current-buffer buffer
619 (setq gnus-newsgroup-name group)))))
621 (defun gnus-group-post-news (&optional arg)
622 "Start composing a message (a news by default).
623 If ARG, post to group under point. If ARG is 1, prompt for group name.
624 Depending on the selected group, the message might be either a mail or
625 a news."
626 (interactive "P")
627 ;; Bind this variable here to make message mode hooks work ok.
628 (let ((gnus-newsgroup-name
629 (if arg
630 (if (= 1 (prefix-numeric-value arg))
631 (gnus-group-completing-read "Newsgroup" nil
632 (gnus-read-active-file-p))
633 (gnus-group-group-name))
634 ""))
635 ;; make sure last viewed article doesn't affect posting styles:
636 (gnus-article-copy))
637 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
638 (string= gnus-newsgroup-name ""))))
640 (defun gnus-summary-mail-other-window (&optional arg)
641 "Start composing a mail in another window.
642 Use the posting of the current group by default.
643 If ARG, don't do that. If ARG is 1, prompt for group name to find the
644 posting style."
645 (interactive "P")
646 ;; We can't `let' gnus-newsgroup-name here, since that leads
647 ;; to local variables leaking.
648 (let ((group gnus-newsgroup-name)
649 ;; make sure last viewed article doesn't affect posting styles:
650 (gnus-article-copy)
651 (buffer (current-buffer)))
652 (unwind-protect
653 (progn
654 (setq gnus-newsgroup-name
655 (if arg
656 (if (= 1 (prefix-numeric-value arg))
657 (gnus-group-completing-read "Use group"
659 (gnus-read-active-file-p))
661 gnus-newsgroup-name))
662 ;; #### see comment in gnus-setup-message -- drv
663 (gnus-setup-message 'message (message-mail)))
664 (with-current-buffer buffer
665 (setq gnus-newsgroup-name group)))))
667 (defun gnus-summary-news-other-window (&optional arg)
668 "Start composing a news in another window.
669 Post to the current group by default.
670 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
672 This function prepares a news even when using mail groups. This is useful
673 for posting messages to mail groups without actually sending them over the
674 network. The corresponding back end must have a 'request-post method."
675 (interactive "P")
676 ;; We can't `let' gnus-newsgroup-name here, since that leads
677 ;; to local variables leaking.
678 (let ((group gnus-newsgroup-name)
679 ;; make sure last viewed article doesn't affect posting styles:
680 (gnus-article-copy)
681 (buffer (current-buffer)))
682 (unwind-protect
683 (progn
684 (setq gnus-newsgroup-name
685 (if arg
686 (if (= 1 (prefix-numeric-value arg))
687 (gnus-group-completing-read "Use group"
689 (gnus-read-active-file-p))
691 gnus-newsgroup-name))
692 ;; #### see comment in gnus-setup-message -- drv
693 (gnus-setup-message 'message
694 (progn
695 (message-news (gnus-group-real-name gnus-newsgroup-name))
696 (set (make-local-variable 'gnus-discouraged-post-methods)
697 (remove
698 (car (gnus-find-method-for-group gnus-newsgroup-name))
699 gnus-discouraged-post-methods)))))
700 (with-current-buffer buffer
701 (setq gnus-newsgroup-name group)))))
703 (defun gnus-summary-post-news (&optional arg)
704 "Start composing a message. Post to the current group by default.
705 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
706 Depending on the selected group, the message might be either a mail or
707 a news."
708 (interactive "P")
709 ;; Bind this variable here to make message mode hooks work ok.
710 (let ((gnus-newsgroup-name
711 (if arg
712 (if (= 1 (prefix-numeric-value arg))
713 (gnus-group-completing-read "Newsgroup" nil
714 (gnus-read-active-file-p))
716 gnus-newsgroup-name))
717 ;; make sure last viewed article doesn't affect posting styles:
718 (gnus-article-copy))
719 (gnus-post-news 'post gnus-newsgroup-name)))
722 (defun gnus-summary-followup (yank &optional force-news)
723 "Compose a followup to an article.
724 If prefix argument YANK is non-nil, the original article is yanked
725 automatically.
726 YANK is a list of elements, where the car of each element is the
727 article number, and the cdr is the string to be yanked."
728 (interactive
729 (list (and current-prefix-arg
730 (gnus-summary-work-articles 1))))
731 (when yank
732 (gnus-summary-goto-subject
733 (if (listp (car yank))
734 (caar yank)
735 (car yank))))
736 (save-window-excursion
737 (gnus-summary-select-article))
738 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
739 (gnus-newsgroup-name gnus-newsgroup-name))
740 ;; Send a followup.
741 (gnus-post-news nil gnus-newsgroup-name
742 headers gnus-article-buffer
743 yank nil force-news)
744 (gnus-summary-handle-replysign)))
746 (defun gnus-summary-followup-with-original (n &optional force-news)
747 "Compose a followup to an article and include the original article.
748 The text in the region will be yanked. If the region isn't
749 active, the entire article will be yanked."
750 (interactive "P")
751 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
753 (defun gnus-summary-followup-to-mail (&optional arg)
754 "Followup to the current mail message via news."
755 (interactive
756 (list (and current-prefix-arg
757 (gnus-summary-work-articles 1))))
758 (gnus-summary-followup arg t))
760 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
761 "Followup to the current mail message via news."
762 (interactive "P")
763 (gnus-summary-followup (gnus-summary-work-articles arg) t))
765 (defun gnus-inews-yank-articles (articles)
766 (let (beg article yank-string)
767 (message-goto-body)
768 (while (setq article (pop articles))
769 (when (listp article)
770 (setq yank-string (nth 1 article)
771 article (nth 0 article)))
772 (save-window-excursion
773 (set-buffer gnus-summary-buffer)
774 (gnus-summary-select-article nil nil nil article)
775 (gnus-summary-remove-process-mark article))
776 (gnus-copy-article-buffer nil yank-string)
777 (let ((message-reply-buffer gnus-article-copy)
778 (message-reply-headers
779 ;; The headers are decoded.
780 (with-current-buffer gnus-article-copy
781 (save-restriction
782 (nnheader-narrow-to-headers)
783 (nnheader-parse-naked-head)))))
784 (message-yank-original)
785 (message-exchange-point-and-mark)
786 (setq beg (or beg (mark t))))
787 (when articles
788 (insert "\n")))
789 (push-mark)
790 (goto-char beg)))
792 (defun gnus-summary-cancel-article (&optional n symp)
793 "Cancel an article you posted.
794 Uses the process-prefix convention. If given the symbolic
795 prefix `a', cancel using the standard posting method; if not
796 post using the current select method."
797 (interactive (gnus-interactive "P\ny"))
798 (let ((message-post-method
799 `(lambda (arg)
800 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
801 (dolist (article (gnus-summary-work-articles n))
802 (when (gnus-summary-select-article t nil nil article)
803 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
804 (message-cancel-news))
805 (gnus-summary-mark-as-read article gnus-canceled-mark)
806 (gnus-cache-remove-article 1))
807 (gnus-article-hide-headers-if-wanted))
808 (gnus-summary-remove-process-mark article))))
810 (defun gnus-summary-supersede-article ()
811 "Compose an article that will supersede a previous article.
812 This is done simply by taking the old article and adding a Supersedes
813 header line with the old Message-ID."
814 (interactive)
815 (let ((article (gnus-summary-article-number))
816 (mail-parse-charset gnus-newsgroup-charset))
817 (gnus-setup-message 'reply-yank
818 (gnus-summary-select-article t)
819 (set-buffer gnus-original-article-buffer)
820 (message-supersede)
821 (push
822 `((lambda ()
823 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
824 (with-current-buffer ,gnus-summary-buffer
825 (gnus-cache-possibly-remove-article ,article nil nil nil t)
826 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
827 message-send-actions)
828 ;; Add Gcc header.
829 (gnus-inews-insert-gcc))))
833 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
834 ;; make a copy of the article buffer with all text properties removed
835 ;; this copy is in the buffer gnus-article-copy.
836 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
837 ;; this buffer should be passed to all mail/news reply/post routines.
838 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
839 (with-current-buffer gnus-article-copy
840 (mm-enable-multibyte))
841 (let ((article-buffer (or article-buffer gnus-article-buffer))
842 end beg)
843 (if (not (and (get-buffer article-buffer)
844 (gnus-buffer-exists-p article-buffer)))
845 (error "Can't find any article buffer")
846 (with-current-buffer article-buffer
847 (let ((gnus-newsgroup-charset (or gnus-article-charset
848 gnus-newsgroup-charset))
849 (gnus-newsgroup-ignored-charsets
850 (or gnus-article-ignored-charsets
851 gnus-newsgroup-ignored-charsets)))
852 (save-restriction
853 ;; Copy over the (displayed) article buffer, delete
854 ;; hidden text and remove text properties.
855 (widen)
856 (copy-to-buffer gnus-article-copy (point-min) (point-max))
857 (set-buffer gnus-article-copy)
858 (when yank-string
859 (message-goto-body)
860 (delete-region (point) (point-max))
861 (insert yank-string))
862 (gnus-article-delete-text-of-type 'annotation)
863 (gnus-article-delete-text-of-type 'multipart)
864 (gnus-remove-text-with-property 'gnus-prev)
865 (gnus-remove-text-with-property 'gnus-next)
866 (gnus-remove-text-with-property 'gnus-decoration)
867 (insert
868 (prog1
869 (buffer-substring-no-properties (point-min) (point-max))
870 (erase-buffer)))
871 ;; Find the original headers.
872 (set-buffer gnus-original-article-buffer)
873 (goto-char (point-min))
874 (while (looking-at message-unix-mail-delimiter)
875 (forward-line 1))
876 (let ((mail-header-separator ""))
877 (setq beg (point)
878 end (or (message-goto-body)
879 ;; There may be just a header.
880 (point-max))))
881 ;; Delete the headers from the displayed articles.
882 (set-buffer gnus-article-copy)
883 (let ((mail-header-separator ""))
884 (delete-region (goto-char (point-min))
885 (or (message-goto-body) (point-max))))
886 ;; Insert the original article headers.
887 (insert-buffer-substring gnus-original-article-buffer beg end)
888 ;; Decode charsets.
889 (let ((gnus-article-decode-hook
890 (delq 'article-decode-charset
891 (copy-sequence gnus-article-decode-hook)))
892 (rfc2047-quote-decoded-words-containing-tspecials t))
893 (run-hooks 'gnus-article-decode-hook)))))
894 gnus-article-copy)))
896 (defun gnus-post-news (post &optional group header article-buffer yank subject
897 force-news)
898 (when article-buffer
899 (gnus-copy-article-buffer))
900 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
901 (gnus-article-yanked-articles yank)
902 (add-to-list gnus-add-to-list))
903 (gnus-setup-message (cond (yank 'reply-yank)
904 (article-buffer 'reply)
905 (t 'message))
906 (let* ((group (or group gnus-newsgroup-name))
907 (charset (gnus-group-name-charset nil group))
908 (pgroup group)
909 to-address to-group mailing-list to-list
910 newsgroup-p)
911 (when group
912 (setq to-address (gnus-parameter-to-address group)
913 to-group (gnus-group-find-parameter group 'to-group)
914 to-list (gnus-parameter-to-list group)
915 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
916 mailing-list (when gnus-mailing-list-groups
917 (string-match gnus-mailing-list-groups group))
918 group (gnus-group-name-decode (gnus-group-real-name group)
919 charset)))
920 (if (or (and to-group
921 (gnus-news-group-p to-group))
922 newsgroup-p
923 force-news
924 (and (gnus-news-group-p
925 (or pgroup gnus-newsgroup-name)
926 (or header gnus-current-article))
927 (not mailing-list)
928 (not to-list)
929 (not to-address)))
930 ;; This is news.
931 (if post
932 (message-news
933 (or to-group
934 (and (not (gnus-virtual-group-p pgroup)) group)))
935 (set-buffer gnus-article-copy)
936 (gnus-msg-treat-broken-reply-to)
937 (message-followup (if (or newsgroup-p force-news)
938 (if (save-restriction
939 (article-narrow-to-head)
940 (message-fetch-field "newsgroups"))
943 to-group)))
944 ;; The is mail.
945 (if post
946 (progn
947 (message-mail (or to-address to-list))
948 ;; Arrange for mail groups that have no `to-address' to
949 ;; get that when the user sends off the mail.
950 (when (and (not to-list)
951 (not to-address)
952 add-to-list)
953 (push (list 'gnus-inews-add-to-address pgroup)
954 message-send-actions)))
955 (set-buffer gnus-article-copy)
956 (gnus-msg-treat-broken-reply-to)
957 (message-wide-reply to-address)))
958 (when yank
959 (gnus-inews-yank-articles yank))))))
961 (defun gnus-msg-treat-broken-reply-to (&optional force)
962 "Remove the Reply-to header if broken-reply-to."
963 (when (or force
964 (gnus-group-find-parameter
965 gnus-newsgroup-name 'broken-reply-to))
966 (save-restriction
967 (message-narrow-to-head)
968 (message-remove-header "reply-to"))))
970 (defun gnus-post-method (arg group &optional silent)
971 "Return the posting method based on GROUP and ARG.
972 If SILENT, don't prompt the user."
973 (let ((gnus-post-method (or (gnus-parameter-post-method group)
974 gnus-post-method))
975 (group-method (gnus-find-method-for-group group)))
976 (cond
977 ;; If the group-method is nil (which shouldn't happen) we use
978 ;; the default method.
979 ((null group-method)
980 (or (and (listp gnus-post-method) ;If not current/native/nil
981 (not (listp (car gnus-post-method))) ; and not a list of methods
982 gnus-post-method) ;then use it.
983 gnus-select-method
984 message-post-method))
985 ;; We want the inverse of the default
986 ((and arg (not (eq arg 0)))
987 (if (eq gnus-post-method 'current)
988 gnus-select-method
989 group-method))
990 ;; We query the user for a post method.
991 ((or arg
992 (and (listp gnus-post-method)
993 (listp (car gnus-post-method))))
994 (let* ((methods
995 ;; Collect all methods we know about.
996 (append
997 (when (listp gnus-post-method)
998 (if (listp (car gnus-post-method))
999 gnus-post-method
1000 (list gnus-post-method)))
1001 gnus-secondary-select-methods
1002 (mapcar 'cdr gnus-server-alist)
1003 (mapcar 'car gnus-opened-servers)
1004 (list gnus-select-method)
1005 (list group-method)))
1006 method-alist post-methods method)
1007 ;; Weed out all mail methods.
1008 (while methods
1009 (setq method (gnus-server-get-method "" (pop methods)))
1010 (when (and (or (gnus-method-option-p method 'post)
1011 (gnus-method-option-p method 'post-mail))
1012 (not (member method post-methods)))
1013 (push method post-methods)))
1014 ;; Create a name-method alist.
1015 (setq method-alist
1016 (mapcar
1017 (lambda (m)
1018 (if (equal (cadr m) "")
1019 (list (symbol-name (car m)) m)
1020 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1021 post-methods))
1022 ;; Query the user.
1023 (cadr
1024 (assoc
1025 (setq gnus-last-posting-server
1026 (if (and silent
1027 gnus-last-posting-server)
1028 ;; Just use the last value.
1029 gnus-last-posting-server
1030 (gnus-completing-read
1031 "Posting method" (mapcar 'car method-alist) t
1032 (cons (or gnus-last-posting-server "") 0))))
1033 method-alist))))
1034 ;; Override normal method.
1035 ((and (eq gnus-post-method 'current)
1036 (not (memq (car group-method) gnus-discouraged-post-methods))
1037 (gnus-get-function group-method 'request-post t))
1038 (assert (not arg))
1039 group-method)
1040 ;; Use gnus-post-method.
1041 ((listp gnus-post-method) ;A method...
1042 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1043 gnus-post-method)
1044 ;; Use the normal select method (nil or native).
1045 (t gnus-select-method))))
1049 (defun gnus-extended-version ()
1050 "Stringified Gnus version and Emacs version.
1051 See the variable `gnus-user-agent'."
1052 (interactive)
1053 (if (stringp gnus-user-agent)
1054 gnus-user-agent
1055 ;; `gnus-user-agent' is a list:
1056 (let* ((float-output-format nil)
1057 (gnus-v
1058 (when (memq 'gnus gnus-user-agent)
1059 (concat "Gnus/"
1060 (prin1-to-string (gnus-continuum-version gnus-version) t)
1061 " (" gnus-version ")")))
1062 (emacs-v (gnus-emacs-version)))
1063 (concat gnus-v (when (and gnus-v emacs-v) " ")
1064 emacs-v))))
1068 ;;; Gnus Mail Functions
1071 ;;; Mail reply commands of Gnus summary mode
1073 (defun gnus-summary-reply (&optional yank wide very-wide)
1074 "Start composing a mail reply to the current message.
1075 If prefix argument YANK is non-nil, the original article is yanked
1076 automatically.
1077 If WIDE, make a wide reply.
1078 If VERY-WIDE, make a very wide reply."
1079 (interactive
1080 (list (and current-prefix-arg
1081 (gnus-summary-work-articles 1))))
1082 ;; Allow user to require confirmation before replying by mail to the
1083 ;; author of a news article (or mail message).
1084 (when (or
1085 (not (or (gnus-news-group-p gnus-newsgroup-name)
1086 gnus-confirm-treat-mail-like-news))
1087 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1088 (string-match gnus-confirm-mail-reply-to-news
1089 gnus-newsgroup-name))
1090 ((functionp gnus-confirm-mail-reply-to-news)
1091 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1092 (t gnus-confirm-mail-reply-to-news)))
1093 (if (or wide very-wide)
1094 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1095 ;; wide replies.
1096 (y-or-n-p "Really reply by mail to article author? ")))
1097 (let* ((article
1098 (if (listp (car yank))
1099 (caar yank)
1100 (car yank)))
1101 (gnus-article-reply (or article (gnus-summary-article-number)))
1102 (gnus-article-yanked-articles yank)
1103 (headers ""))
1104 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1105 (when yank
1106 (gnus-summary-goto-subject article))
1107 (gnus-setup-message (if yank 'reply-yank 'reply)
1108 (if (not very-wide)
1109 (gnus-summary-select-article)
1110 (dolist (article very-wide)
1111 (gnus-summary-select-article nil nil nil article)
1112 (with-current-buffer (gnus-copy-article-buffer)
1113 (gnus-msg-treat-broken-reply-to)
1114 (save-restriction
1115 (message-narrow-to-head)
1116 (setq headers (concat headers (buffer-string)))))))
1117 (set-buffer (gnus-copy-article-buffer))
1118 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1119 (save-restriction
1120 (message-narrow-to-head)
1121 (when very-wide
1122 (erase-buffer)
1123 (insert headers))
1124 (goto-char (point-max)))
1125 (mml-quote-region (point) (point-max))
1126 (message-reply nil wide)
1127 (when yank
1128 (gnus-inews-yank-articles yank))
1129 (gnus-summary-handle-replysign)))))
1131 (defun gnus-summary-handle-replysign ()
1132 "Check the various replysign variables and take action accordingly."
1133 (when (or gnus-message-replysign gnus-message-replyencrypt)
1134 (let (signed encrypted)
1135 (with-current-buffer gnus-article-buffer
1136 (setq signed (memq 'signed gnus-article-wash-types))
1137 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1138 (cond ((and gnus-message-replyencrypt encrypted)
1139 (mml-secure-message mml-default-encrypt-method
1140 (if gnus-message-replysignencrypted
1141 'signencrypt
1142 'encrypt)))
1143 ((and gnus-message-replysign signed)
1144 (mml-secure-message mml-default-sign-method 'sign))))))
1146 (defun gnus-summary-reply-with-original (n &optional wide)
1147 "Start composing a reply mail to the current message.
1148 The original article will be yanked."
1149 (interactive "P")
1150 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1152 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1153 "Like `gnus-summary-reply' except removing reply-to field.
1154 If prefix argument YANK is non-nil, the original article is yanked
1155 automatically.
1156 If WIDE, make a wide reply.
1157 If VERY-WIDE, make a very wide reply."
1158 (interactive
1159 (list (and current-prefix-arg
1160 (gnus-summary-work-articles 1))))
1161 (let ((gnus-msg-force-broken-reply-to t))
1162 (gnus-summary-reply yank wide very-wide)))
1164 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1165 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1166 The original article will be yanked."
1167 (interactive "P")
1168 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1170 (defun gnus-summary-wide-reply (&optional yank)
1171 "Start composing a wide reply mail to the current message.
1172 If prefix argument YANK is non-nil, the original article is yanked
1173 automatically."
1174 (interactive
1175 (list (and current-prefix-arg
1176 (gnus-summary-work-articles 1))))
1177 (gnus-summary-reply yank t))
1179 (defun gnus-summary-wide-reply-with-original (n)
1180 "Start composing a wide reply mail to the current message.
1181 The original article will be yanked.
1182 Uses the process/prefix convention."
1183 (interactive "P")
1184 (gnus-summary-reply-with-original n t))
1186 (defun gnus-summary-very-wide-reply (&optional yank)
1187 "Start composing a very wide reply mail to the current message.
1188 If prefix argument YANK is non-nil, the original article is yanked
1189 automatically."
1190 (interactive
1191 (list (and current-prefix-arg
1192 (gnus-summary-work-articles 1))))
1193 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1195 (defun gnus-summary-very-wide-reply-with-original (n)
1196 "Start composing a very wide reply mail to the current message.
1197 The original article will be yanked."
1198 (interactive "P")
1199 (gnus-summary-reply
1200 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1202 (defun gnus-summary-mail-forward (&optional arg post)
1203 "Forward the current message(s) to another user.
1204 If process marks exist, forward all marked messages;
1205 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1206 if ARG is 1, decode the message and forward directly inline;
1207 if ARG is 2, forward message as an rfc822 MIME section;
1208 if ARG is 3, decode message and forward as an rfc822 MIME section;
1209 if ARG is 4, forward message directly inline;
1210 otherwise, use flipped `message-forward-as-mime'.
1211 If POST, post instead of mail.
1212 For the `inline' alternatives, also see the variable
1213 `message-forward-ignored-headers'."
1214 (interactive "P")
1215 (if (cdr (gnus-summary-work-articles nil))
1216 ;; Process marks are given.
1217 (gnus-uu-digest-mail-forward arg post)
1218 ;; No process marks.
1219 (let ((message-forward-as-mime message-forward-as-mime)
1220 (message-forward-show-mml message-forward-show-mml))
1221 (cond
1222 ((null arg))
1223 ((eq arg 1)
1224 (setq message-forward-as-mime nil
1225 message-forward-show-mml t))
1226 ((eq arg 2)
1227 (setq message-forward-as-mime t
1228 message-forward-show-mml nil))
1229 ((eq arg 3)
1230 (setq message-forward-as-mime t
1231 message-forward-show-mml t))
1232 ((eq arg 4)
1233 (setq message-forward-as-mime nil
1234 message-forward-show-mml nil))
1236 (setq message-forward-as-mime (not message-forward-as-mime))))
1237 (let* ((gnus-article-reply (gnus-summary-article-number))
1238 (gnus-article-yanked-articles (list gnus-article-reply)))
1239 (gnus-setup-message 'forward
1240 (gnus-summary-select-article)
1241 (let ((mail-parse-charset
1242 (or (and (gnus-buffer-live-p gnus-article-buffer)
1243 (with-current-buffer gnus-article-buffer
1244 gnus-article-charset))
1245 gnus-newsgroup-charset))
1246 (mail-parse-ignored-charsets
1247 gnus-newsgroup-ignored-charsets))
1248 (set-buffer gnus-original-article-buffer)
1249 (message-forward post)))))))
1251 (defun gnus-summary-resend-message (address n)
1252 "Resend the current article to ADDRESS."
1253 (interactive
1254 (list (message-read-from-minibuffer
1255 "Resend message(s) to: "
1256 (when (and gnus-summary-resend-default-address
1257 (gnus-buffer-live-p gnus-original-article-buffer))
1258 ;; If some other article is currently selected, the
1259 ;; initial-contents is wrong. Whatever, it is just the
1260 ;; initial-contents.
1261 (with-current-buffer gnus-original-article-buffer
1262 (nnmail-fetch-field "to"))))
1263 current-prefix-arg))
1264 (dolist (article (gnus-summary-work-articles n))
1265 (gnus-summary-select-article nil nil nil article)
1266 (with-current-buffer gnus-original-article-buffer
1267 (let ((gnus-gcc-externalize-attachments nil))
1268 (message-resend address)))
1269 (gnus-summary-mark-article-as-forwarded article)))
1271 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1272 (defun gnus-summary-resend-message-edit ()
1273 "Resend an article that has already been sent.
1274 A new buffer will be created to allow the user to modify body and
1275 contents of the message, and then, everything will happen as when
1276 composing a new message."
1277 (interactive)
1278 (let ((mail-parse-charset gnus-newsgroup-charset))
1279 (gnus-setup-message 'reply-yank
1280 (gnus-summary-select-article t)
1281 (set-buffer gnus-original-article-buffer)
1282 (let ((cur (current-buffer))
1283 (to (message-fetch-field "to")))
1284 ;; Get a normal message buffer.
1285 (message-pop-to-buffer (message-buffer-name "Resend" to))
1286 (insert-buffer-substring cur)
1287 (mime-to-mml)
1288 (message-narrow-to-head-1)
1289 ;; Gnus will generate a new one when sending.
1290 (message-remove-header "Message-ID")
1291 ;; Remove unwanted headers.
1292 (message-remove-header message-ignored-resent-headers t)
1293 (goto-char (point-max))
1294 (insert mail-header-separator)
1295 ;; Add Gcc header.
1296 (gnus-inews-insert-gcc)
1297 (goto-char (point-min))
1298 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1299 (forward-char 1))
1300 (widen)))))
1302 (defun gnus-summary-post-forward (&optional arg)
1303 "Forward the current article to a newsgroup.
1304 See `gnus-summary-mail-forward' for ARG."
1305 (interactive "P")
1306 (gnus-summary-mail-forward arg t))
1308 (defun gnus-summary-mail-crosspost-complaint (n)
1309 "Send a complaint about crossposting to the current article(s)."
1310 (interactive "P")
1311 (dolist (article (gnus-summary-work-articles n))
1312 (set-buffer gnus-summary-buffer)
1313 (gnus-summary-goto-subject article)
1314 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1315 newsgroups followup-to)
1316 (gnus-summary-select-article)
1317 (set-buffer gnus-original-article-buffer)
1318 (if (and (<= (length (message-tokenize-header
1319 (setq newsgroups
1320 (mail-fetch-field "newsgroups"))
1321 ", "))
1323 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1324 (not (member group (message-tokenize-header
1325 followup-to ", ")))))
1326 (if followup-to
1327 (gnus-message 1 "Followup-to restricted")
1328 (gnus-message 1 "Not a crossposted article"))
1329 (set-buffer gnus-summary-buffer)
1330 (gnus-summary-reply-with-original 1)
1331 (set-buffer gnus-message-buffer)
1332 (message-goto-body)
1333 (insert (format gnus-crosspost-complaint newsgroups group))
1334 (message-goto-subject)
1335 (re-search-forward " *$")
1336 (replace-match " (crosspost notification)" t t)
1337 (gnus-deactivate-mark)
1338 (when (gnus-y-or-n-p "Send this complaint? ")
1339 (message-send-and-exit))))))
1341 (defun gnus-mail-parse-comma-list ()
1342 (let (accumulated
1343 beg)
1344 (skip-chars-forward " ")
1345 (while (not (eobp))
1346 (setq beg (point))
1347 (skip-chars-forward "^,")
1348 (while (zerop
1349 (save-excursion
1350 (save-restriction
1351 (let ((i 0))
1352 (narrow-to-region beg (point))
1353 (goto-char beg)
1354 (logand (progn
1355 (while (search-forward "\"" nil t)
1356 (incf i))
1357 (if (zerop i) 2 i))
1358 2)))))
1359 (skip-chars-forward ",")
1360 (skip-chars-forward "^,"))
1361 (skip-chars-backward " ")
1362 (push (buffer-substring beg (point))
1363 accumulated)
1364 (skip-chars-forward "^,")
1365 (skip-chars-forward ", "))
1366 accumulated))
1368 (defun gnus-inews-add-to-address (group)
1369 (let ((to-address (mail-fetch-field "to")))
1370 (when (and to-address
1371 (gnus-alive-p))
1372 ;; This mail group doesn't have a `to-list', so we add one
1373 ;; here. Magic!
1374 (when (gnus-y-or-n-p
1375 (format "Do you want to add this as `to-list': %s? " to-address))
1376 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1378 (defun gnus-put-message ()
1379 "Put the current message in some group and return to Gnus."
1380 (interactive)
1381 (let ((reply gnus-article-reply)
1382 (winconf gnus-prev-winconf)
1383 (group gnus-newsgroup-name))
1384 (unless (and group
1385 (not (gnus-group-read-only-p group)))
1386 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1388 (when (gnus-group-entry group)
1389 (error "No such group: %s" group))
1390 (save-excursion
1391 (save-restriction
1392 (widen)
1393 (message-narrow-to-headers)
1394 (let ((gnus-deletable-headers nil))
1395 (message-generate-headers
1396 (if (message-news-p)
1397 message-required-news-headers
1398 message-required-mail-headers)))
1399 (goto-char (point-max))
1400 (if (string-match " " group)
1401 (insert "Gcc: \"" group "\"\n")
1402 (insert "Gcc: " group "\n"))
1403 (widen)))
1404 (gnus-inews-do-gcc)
1405 (when (and (get-buffer gnus-group-buffer)
1406 (gnus-buffer-exists-p (car-safe reply))
1407 (cdr reply))
1408 (set-buffer (car reply))
1409 (gnus-summary-mark-article-as-replied (cdr reply)))
1410 (when winconf
1411 (set-window-configuration winconf))))
1413 (defun gnus-article-mail (yank)
1414 "Send a reply to the address near point.
1415 If YANK is non-nil, include the original article."
1416 (interactive "P")
1417 (let ((address
1418 (buffer-substring
1419 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1420 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1421 (when address
1422 (gnus-msg-mail address)
1423 (when yank
1424 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1426 (defvar nntp-server-type)
1427 (defun gnus-bug ()
1428 "Send a bug report to the Gnus maintainers."
1429 (interactive)
1430 (unless (gnus-alive-p)
1431 (error "Gnus has been shut down"))
1432 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1433 (unless (message-mail-user-agent)
1434 (delete-other-windows)
1435 (when gnus-bug-create-help-buffer
1436 (switch-to-buffer "*Gnus Help Bug*")
1437 (erase-buffer)
1438 (insert gnus-bug-message)
1439 (goto-char (point-min)))
1440 (message-pop-to-buffer "*Gnus Bug*"))
1441 (let ((message-this-is-mail t))
1442 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1443 (when gnus-bug-create-help-buffer
1444 (push `(gnus-bug-kill-buffer) message-send-actions))
1445 (goto-char (point-min))
1446 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1447 (forward-line 1)
1448 (insert (gnus-version) "\n"
1449 (emacs-version) "\n")
1450 (when (and (boundp 'nntp-server-type)
1451 (stringp nntp-server-type))
1452 (insert nntp-server-type))
1453 (insert "\n\n\n\n\n")
1454 (let (text)
1455 (with-current-buffer (gnus-get-buffer-create " *gnus environment info*")
1456 (erase-buffer)
1457 (gnus-debug)
1458 (setq text (buffer-string)))
1459 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1460 (goto-char (point-min))
1461 (search-forward "Subject: " nil t)
1462 (message "")))
1464 (defun gnus-bug-kill-buffer ()
1465 (when (get-buffer "*Gnus Help Bug*")
1466 (kill-buffer "*Gnus Help Bug*")))
1468 (defun gnus-summary-yank-message (buffer n)
1469 "Yank the current article into a composed message."
1470 (interactive
1471 (list (gnus-completing-read "Buffer" (message-buffers) t)
1472 current-prefix-arg))
1473 (gnus-summary-iterate n
1474 (let ((gnus-inhibit-treatment t))
1475 (gnus-summary-select-article))
1476 (with-current-buffer buffer
1477 (message-yank-buffer gnus-article-buffer))))
1479 (defun gnus-debug ()
1480 "Attempts to go through the Gnus source file and report what variables have been changed.
1481 The source file has to be in the Emacs load path."
1482 (interactive)
1483 (let ((files gnus-debug-files)
1484 (point (point))
1485 file expr olist sym)
1486 (gnus-message 4 "Please wait while we snoop your variables...")
1487 (sit-for 0)
1488 ;; Go through all the files looking for non-default values for variables.
1489 (with-current-buffer (gnus-get-buffer-create " *gnus bug info*")
1490 (while files
1491 (erase-buffer)
1492 (when (and (setq file (locate-library (pop files)))
1493 (file-exists-p file))
1494 (insert-file-contents file)
1495 (goto-char (point-min))
1496 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1497 (gnus-message 4 "Malformed sources in file %s" file)
1498 (narrow-to-region (point-min) (point))
1499 (goto-char (point-min))
1500 (while (setq expr (ignore-errors (read (current-buffer))))
1501 (ignore-errors
1502 (and (or (eq (car expr) 'defvar)
1503 (eq (car expr) 'defcustom))
1504 (stringp (nth 3 expr))
1505 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1506 (or (not (boundp (nth 1 expr)))
1507 (not (equal (eval (nth 2 expr))
1508 (symbol-value (nth 1 expr)))))
1509 (push (nth 1 expr) olist)))))))
1510 (kill-buffer (current-buffer)))
1511 (when (setq olist (nreverse olist))
1512 (insert "------------------ Environment follows ------------------\n\n"))
1513 (while olist
1514 (if (boundp (car olist))
1515 (ignore-errors
1516 (gnus-pp
1517 `(setq ,(car olist)
1518 ,(if (or (consp (setq sym (symbol-value (car olist))))
1519 (and (symbolp sym)
1520 (not (or (eq sym nil)
1521 (eq sym t)))))
1522 (list 'quote (symbol-value (car olist)))
1523 (symbol-value (car olist))))))
1524 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1525 (setq olist (cdr olist)))
1526 (insert "\n\n")
1527 ;; Remove any control chars - they seem to cause trouble for some
1528 ;; mailers. (Byte-compiled output from the stuff above.)
1529 (goto-char point)
1530 (while (re-search-forward (mm-string-to-multibyte
1531 "[\000-\010\013-\037\200-\237]") nil t)
1532 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1533 t t))))
1535 ;;; Treatment of rejected articles.
1536 ;;; Bounced mail.
1538 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1539 "Re-mail the current message.
1540 This only makes sense if the current message is a bounce message that
1541 contains some mail you have written which has been bounced back to
1542 you.
1543 If FETCH, try to fetch the article that this is a reply to, if indeed
1544 this is a reply."
1545 (interactive "P")
1546 (gnus-summary-select-article t)
1547 (let (summary-buffer parent)
1548 (if fetch
1549 (progn
1550 (setq summary-buffer (current-buffer))
1551 (set-buffer gnus-original-article-buffer)
1552 (article-goto-body)
1553 (when (re-search-forward "^References:\n?" nil t)
1554 (while (memq (char-after) '(?\t ? ))
1555 (forward-line 1))
1556 (skip-chars-backward "\t\n ")
1557 (setq parent
1558 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1559 (set-buffer gnus-original-article-buffer))
1560 (gnus-setup-message 'compose-bounce
1561 (message-bounce)
1562 ;; Add Gcc header.
1563 (gnus-inews-insert-gcc)
1564 ;; If there are references, we fetch the article we answered to.
1565 (when parent
1566 (with-current-buffer summary-buffer
1567 (gnus-summary-refer-article parent)
1568 (gnus-summary-show-all-headers))))))
1570 ;;; Gcc handling.
1572 (defun gnus-inews-group-method (group)
1573 (cond
1574 ;; If the group doesn't exist, we assume
1575 ;; it's an archive group...
1576 ((and (null (gnus-get-info group))
1577 (eq (car (gnus-server-to-method gnus-message-archive-method))
1578 (car (gnus-server-to-method (gnus-group-method group)))))
1579 gnus-message-archive-method)
1580 ;; Use the method.
1581 ((gnus-info-method (gnus-get-info group))
1582 (gnus-info-method (gnus-get-info group)))
1583 ;; Find the method.
1584 (t (gnus-server-to-method (gnus-group-method group)))))
1586 ;; Do Gcc handling, which copied the message over to some group.
1587 (defun gnus-inews-do-gcc (&optional gcc)
1588 (interactive)
1589 (save-excursion
1590 (save-restriction
1591 (message-narrow-to-headers)
1592 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1593 (cur (current-buffer))
1594 groups group method group-art
1595 mml-externalize-attachments)
1596 (when gcc
1597 (message-remove-header "gcc")
1598 (widen)
1599 (setq groups (message-unquote-tokens
1600 (message-tokenize-header gcc " ,")))
1601 ;; Copy the article over to some group(s).
1602 (while (setq group (pop groups))
1603 (setq method (gnus-inews-group-method group)
1604 group (mm-encode-coding-string
1605 group
1606 (gnus-group-name-charset method group)))
1607 (unless (gnus-check-server method)
1608 (error "Can't open server %s" (if (stringp method) method
1609 (car method))))
1610 (unless (gnus-request-group group t method)
1611 (gnus-request-create-group group method))
1612 (setq mml-externalize-attachments
1613 (if (stringp gnus-gcc-externalize-attachments)
1614 (string-match gnus-gcc-externalize-attachments group)
1615 gnus-gcc-externalize-attachments))
1616 (save-excursion
1617 (nnheader-set-temp-buffer " *acc*")
1618 (insert-buffer-substring cur)
1619 (message-encode-message-body)
1620 (save-restriction
1621 (message-narrow-to-headers)
1622 (let* ((mail-parse-charset message-default-charset)
1623 (newsgroups-field (save-restriction
1624 (message-narrow-to-headers-or-head)
1625 (message-fetch-field "Newsgroups")))
1626 (followup-field (save-restriction
1627 (message-narrow-to-headers-or-head)
1628 (message-fetch-field "Followup-To")))
1629 ;; BUG: We really need to get the charset for
1630 ;; each name in the Newsgroups and Followup-To
1631 ;; lines to allow crossposting between group
1632 ;; namess with incompatible character sets.
1633 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1634 (group-field-charset
1635 (gnus-group-name-charset
1636 method (or newsgroups-field "")))
1637 (followup-field-charset
1638 (gnus-group-name-charset
1639 method (or followup-field "")))
1640 (rfc2047-header-encoding-alist
1641 (append
1642 (when group-field-charset
1643 (list (cons "Newsgroups" group-field-charset)))
1644 (when followup-field-charset
1645 (list (cons "Followup-To" followup-field-charset)))
1646 rfc2047-header-encoding-alist)))
1647 (mail-encode-encoded-word-buffer)))
1648 (goto-char (point-min))
1649 (when (re-search-forward
1650 (concat "^" (regexp-quote mail-header-separator) "$")
1651 nil t)
1652 (replace-match "" t t ))
1653 (when (or (not (gnus-check-backend-function
1654 'request-accept-article group))
1655 (not (setq group-art
1656 (gnus-request-accept-article
1657 group method t t))))
1658 (gnus-message 1 "Couldn't store article in group %s: %s"
1659 group (gnus-status-message method)))
1660 (when (stringp method)
1661 (setq method (gnus-server-to-method method)))
1662 (when (and (listp method)
1663 (gnus-native-method-p method))
1664 (setq group (gnus-group-short-name group)))
1665 (when (and group-art
1666 ;; FIXME: Should gcc-mark-as-read work when
1667 ;; Gnus is not running?
1668 (gnus-alive-p)
1669 (or gnus-gcc-mark-as-read
1670 (and
1671 (boundp 'gnus-inews-mark-gcc-as-read)
1672 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1673 (gnus-group-mark-article-read group (cdr group-art)))
1674 (kill-buffer (current-buffer)))))))))
1676 (defun gnus-inews-insert-gcc (&optional group)
1677 "Insert the Gcc to say where the article is to be archived."
1678 (let* ((group (or group gnus-newsgroup-name))
1679 (group (when group (gnus-group-decoded-name group)))
1680 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1681 (gcc-self-val
1682 (and group (gnus-group-find-parameter group 'gcc-self)))
1683 result
1684 (groups
1685 (cond
1686 ((null gnus-message-archive-method)
1687 ;; Ignore.
1688 nil)
1689 ((stringp var)
1690 ;; Just a single group.
1691 (list var))
1692 ((null var)
1693 ;; We don't want this.
1694 nil)
1695 ((and (listp var) (stringp (car var)))
1696 ;; A list of groups.
1697 var)
1698 ((functionp var)
1699 ;; A function.
1700 (funcall var group))
1702 ;; An alist of regexps/functions/forms.
1703 (while (and var
1704 (not
1705 (setq result
1706 (cond
1707 ((stringp (caar var))
1708 ;; Regexp.
1709 (when (string-match (caar var) group)
1710 (cdar var)))
1711 ((functionp (car var))
1712 ;; Function.
1713 (funcall (car var) group))
1715 (eval (car var)))))))
1716 (setq var (cdr var)))
1717 result)))
1718 name)
1719 (when (or groups gcc-self-val)
1720 (when (stringp groups)
1721 (setq groups (list groups)))
1722 (save-excursion
1723 (save-restriction
1724 (message-narrow-to-headers)
1725 (goto-char (point-max))
1726 (insert "Gcc: ")
1727 (if gcc-self-val
1728 ;; Use the `gcc-self' param value instead.
1729 (progn
1730 (insert
1731 (if (stringp gcc-self-val)
1732 (if (string-match " " gcc-self-val)
1733 (concat "\"" gcc-self-val "\"")
1734 gcc-self-val)
1735 ;; In nndoc groups, we use the parent group name
1736 ;; instead of the current group.
1737 (let ((group (or (gnus-group-find-parameter
1738 gnus-newsgroup-name 'parent-group)
1739 group)))
1740 (if (string-match " " group)
1741 (concat "\"" group "\"")
1742 group))))
1743 (if (not (eq gcc-self-val 'none))
1744 (insert "\n")
1745 (gnus-delete-line)))
1746 ;; Use the list of groups.
1747 (while (setq name (pop groups))
1748 (let ((str (if (string-match ":" name)
1749 name
1750 (gnus-group-prefixed-name
1751 name gnus-message-archive-method))))
1752 (insert (if (string-match " " str)
1753 (concat "\"" str "\"")
1754 str)))
1755 (when groups
1756 (insert " ")))
1757 (insert "\n")))))))
1759 (defun gnus-mailing-list-followup-to ()
1760 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1761 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1762 (list-post (gnus-fetch-original-field "list-post")))
1763 (when (and list-post
1764 (string-match "mailto:\\([^>]+\\)" list-post))
1765 (setq list-post (match-string 1 list-post)))
1766 (or list-post
1767 x-been-there)))
1769 ;;; Posting styles.
1771 (defun gnus-configure-posting-styles (&optional group-name)
1772 "Configure posting styles according to `gnus-posting-styles'."
1773 (unless gnus-inhibit-posting-styles
1774 (let ((group (or group-name gnus-newsgroup-name ""))
1775 (styles gnus-posting-styles)
1776 style match attribute value v results
1777 filep name address element)
1778 ;; If the group has a posting-style parameter, add it at the end with a
1779 ;; regexp matching everything, to be sure it takes precedence over all
1780 ;; the others.
1781 (when gnus-newsgroup-name
1782 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1783 (when tmp-style
1784 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1785 ;; Go through all styles and look for matches.
1786 (dolist (style styles)
1787 (setq match (pop style))
1788 (goto-char (point-min))
1789 (when (cond
1790 ((stringp match)
1791 ;; Regexp string match on the group name.
1792 (string-match match group))
1793 ((eq match 'header)
1794 ;; Obsolete format of header match.
1795 (and (gnus-buffer-live-p gnus-article-copy)
1796 (with-current-buffer gnus-article-copy
1797 (save-restriction
1798 (nnheader-narrow-to-headers)
1799 (let ((header (message-fetch-field (pop style))))
1800 (and header
1801 (string-match (pop style) header)))))))
1802 ((or (symbolp match)
1803 (functionp match))
1804 (cond
1805 ((functionp match)
1806 ;; Function to be called.
1807 (funcall match))
1808 ((boundp match)
1809 ;; Variable to be checked.
1810 (symbol-value match))))
1811 ((listp match)
1812 (cond
1813 ((eq (car match) 'header)
1814 ;; New format of header match.
1815 (and (gnus-buffer-live-p gnus-article-copy)
1816 (with-current-buffer gnus-article-copy
1817 (save-restriction
1818 (nnheader-narrow-to-headers)
1819 (let ((header (message-fetch-field (nth 1 match))))
1820 (and header
1821 (string-match (nth 2 match) header)))))))
1823 ;; This is a form to be evaled.
1824 (eval match)))))
1825 ;; We have a match, so we set the variables.
1826 (dolist (attribute style)
1827 (setq element (pop attribute)
1828 filep nil)
1829 (setq value
1830 (cond
1831 ((eq (car attribute) :file)
1832 (setq filep t)
1833 (cadr attribute))
1834 ((eq (car attribute) :value)
1835 (cadr attribute))
1837 (car attribute))))
1838 ;; We get the value.
1839 (setq v
1840 (cond
1841 ((stringp value)
1842 (if (and (stringp match)
1843 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1844 (match-beginning 1))
1845 (gnus-match-substitute-replacement value nil nil group)
1846 value))
1847 ((or (symbolp value)
1848 (functionp value))
1849 (cond ((functionp value)
1850 (funcall value))
1851 ((boundp value)
1852 (symbol-value value))))
1853 ((listp value)
1854 (eval value))))
1855 ;; Translate obsolescent value.
1856 (cond
1857 ((eq element 'signature-file)
1858 (setq element 'signature
1859 filep t))
1860 ((eq element 'x-face-file)
1861 (setq element 'x-face
1862 filep t)))
1863 ;; Post-processing for the signature posting-style:
1864 (and (eq element 'signature) filep
1865 message-signature-directory
1866 ;; don't actually use the signature directory
1867 ;; if message-signature-file contains a path.
1868 (not (file-name-directory v))
1869 (setq v (nnheader-concat message-signature-directory v)))
1870 ;; Get the contents of file elems.
1871 (when (and filep v)
1872 (setq v (with-temp-buffer
1873 (insert-file-contents v)
1874 (buffer-substring
1875 (point-min)
1876 (progn
1877 (goto-char (point-max))
1878 (if (zerop (skip-chars-backward "\n"))
1879 (point)
1880 (1+ (point))))))))
1881 (setq results (delq (assoc element results) results))
1882 (push (cons element v) results))))
1883 ;; Now we have all the styles, so we insert them.
1884 (setq name (assq 'name results)
1885 address (assq 'address results))
1886 (setq results (delq name (delq address results)))
1887 (gnus-make-local-hook 'message-setup-hook)
1888 (setq results (sort results (lambda (x y)
1889 (string-lessp (car x) (car y)))))
1890 (dolist (result results)
1891 (add-hook 'message-setup-hook
1892 (cond
1893 ((eq 'eval (car result))
1894 'ignore)
1895 ((eq 'body (car result))
1896 `(lambda ()
1897 (save-excursion
1898 (message-goto-body)
1899 (insert ,(cdr result)))))
1900 ((eq 'signature (car result))
1901 (set (make-local-variable 'message-signature) nil)
1902 (set (make-local-variable 'message-signature-file) nil)
1903 (if (not (cdr result))
1904 'ignore
1905 `(lambda ()
1906 (save-excursion
1907 (let ((message-signature ,(cdr result)))
1908 (when message-signature
1909 (message-insert-signature)))))))
1911 (let ((header
1912 (if (symbolp (car result))
1913 (capitalize (symbol-name (car result)))
1914 (car result))))
1915 `(lambda ()
1916 (save-excursion
1917 (message-remove-header ,header)
1918 (let ((value ,(cdr result)))
1919 (when value
1920 (message-goto-eoh)
1921 (insert ,header ": " value)
1922 (unless (bolp)
1923 (insert "\n")))))))))
1924 nil 'local))
1925 (when (or name address)
1926 (add-hook 'message-setup-hook
1927 `(lambda ()
1928 (set (make-local-variable 'user-mail-address)
1929 ,(or (cdr address) user-mail-address))
1930 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1931 (user-mail-address
1932 ,(or (cdr address) user-mail-address)))
1933 (save-excursion
1934 (message-remove-header "From")
1935 (message-goto-eoh)
1936 (insert "From: " (message-make-from) "\n"))))
1937 nil 'local)))))
1939 ;;; Allow redefinition of functions.
1941 (gnus-ems-redefine)
1943 (provide 'gnus-msg)
1945 ;;; gnus-msg.el ends here