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