(gnus-inews-make-draft-meta-information): Really
[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
438               (mapconcat
439                (lambda (elem)
440                  (number-to-string
441                   (if (consp elem)
442                       (car elem)
443                     elem)))
444                articles " ")
445             "")
446           ")"))
447
448 ;;;###autoload
449 (defun gnus-msg-mail (&optional to subject other-headers continue
450                                 switch-action yank-action send-actions)
451   "Start editing a mail message to be sent.
452 Like `message-mail', but with Gnus paraphernalia, particularly the
453 Gcc: header for archiving purposes."
454   (interactive)
455   (let ((buf (current-buffer))
456         mail-buf)
457     (gnus-setup-message 'message
458       (message-mail to subject other-headers continue
459                     nil yank-action send-actions))
460     (when switch-action
461       (setq mail-buf (current-buffer))
462       (switch-to-buffer buf)
463       (apply switch-action mail-buf nil)))
464   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
465   t)
466
467 (defvar save-selected-window-window)
468
469 ;;;###autoload
470 (defun gnus-button-mailto (address)
471   "Mail to ADDRESS."
472   (set-buffer (gnus-copy-article-buffer))
473   (gnus-setup-message 'message
474     (message-reply address))
475   (and (boundp 'save-selected-window-window)
476        (not (window-live-p save-selected-window-window))
477        (setq save-selected-window-window (selected-window))))
478
479 ;;;###autoload
480 (defun gnus-button-reply (&optional to-address wide)
481   "Like `message-reply'."
482   (interactive)
483   (gnus-setup-message 'message
484     (message-reply to-address wide))
485   (and (boundp 'save-selected-window-window)
486        (not (window-live-p save-selected-window-window))
487        (setq save-selected-window-window (selected-window))))
488
489 ;;;###autoload
490 (define-mail-user-agent 'gnus-user-agent
491   'gnus-msg-mail 'message-send-and-exit
492   'message-kill-buffer 'message-send-hook)
493
494 (defun gnus-setup-posting-charset (group)
495   (let ((alist gnus-group-posting-charset-alist)
496         (group (or group ""))
497         elem)
498     (when group
499       (catch 'found
500         (while (setq elem (pop alist))
501           (when (or (and (stringp (car elem))
502                          (string-match (car elem) group))
503                     (and (functionp (car elem))
504                          (funcall (car elem) group))
505                     (and (symbolp (car elem))
506                          (symbol-value (car elem))))
507             (throw 'found (cons (cadr elem) (caddr elem)))))))))
508
509 (defun gnus-inews-add-send-actions (winconf buffer article
510                                             &optional config yanked)
511   (gnus-make-local-hook 'message-sent-hook)
512   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
513                                  'gnus-inews-do-gcc) nil t)
514   (when gnus-agent
515     (gnus-make-local-hook 'message-header-hook)
516     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
517   (setq message-post-method
518         `(lambda (arg)
519            (gnus-post-method arg ,gnus-newsgroup-name)))
520   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
521   (message-add-action
522    `(when (gnus-buffer-exists-p ,buffer)
523       (set-window-configuration ,winconf))
524    'exit 'postpone 'kill)
525   (let ((to-be-marked (cond
526                        (yanked
527                         (mapcar
528                          (lambda (x) (if (listp x) (car x) x)) yanked))
529                        (article (if (listp article) article (list article)))
530                        (t nil))))
531     (message-add-action
532      `(when (gnus-buffer-exists-p ,buffer)
533         (save-excursion
534           (set-buffer ,buffer)
535           ,(when to-be-marked
536              (if (eq config 'forward)
537                  `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
538                `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
539      'send)))
540
541 (put 'gnus-setup-message 'lisp-indent-function 1)
542 (put 'gnus-setup-message 'edebug-form-spec '(form body))
543
544 ;;; Post news commands of Gnus group mode and summary mode
545
546 (defun gnus-group-mail (&optional arg)
547   "Start composing a mail.
548 If ARG, use the group under the point to find a posting style.
549 If ARG is 1, prompt for a group name to find the posting style."
550   (interactive "P")
551   ;; We can't `let' gnus-newsgroup-name here, since that leads
552   ;; to local variables leaking.
553   (let ((group gnus-newsgroup-name)
554         ;; make sure last viewed article doesn't affect posting styles:
555         (gnus-article-copy)
556         (buffer (current-buffer)))
557     (unwind-protect
558         (progn
559           (setq gnus-newsgroup-name
560                 (if arg
561                     (if (= 1 (prefix-numeric-value arg))
562                         (completing-read "Use posting style of group: "
563                                          gnus-active-hashtb nil
564                                          (gnus-read-active-file-p))
565                       (gnus-group-group-name))
566                   ""))
567           ;; #### see comment in gnus-setup-message -- drv
568           (gnus-setup-message 'message (message-mail)))
569       (save-excursion
570         (set-buffer buffer)
571         (setq gnus-newsgroup-name group)))))
572
573 (defun gnus-group-news (&optional arg)
574   "Start composing a news.
575 If ARG, post to group under point.
576 If ARG is 1, prompt for group name to post to.
577
578 This function prepares a news even when using mail groups.  This is useful
579 for posting messages to mail groups without actually sending them over the
580 network.  The corresponding back end must have a 'request-post method."
581   (interactive "P")
582   ;; We can't `let' gnus-newsgroup-name here, since that leads
583   ;; to local variables leaking.
584   (let ((group gnus-newsgroup-name)
585         ;; make sure last viewed article doesn't affect posting styles:
586         (gnus-article-copy)
587         (buffer (current-buffer)))
588     (unwind-protect
589         (progn
590           (setq gnus-newsgroup-name
591                 (if arg
592                     (if (= 1 (prefix-numeric-value arg))
593                         (completing-read "Use group: "
594                                          gnus-active-hashtb nil
595                                          (gnus-read-active-file-p))
596                       (gnus-group-group-name))
597                   ""))
598           ;; #### see comment in gnus-setup-message -- drv
599           (gnus-setup-message 'message
600             (message-news (gnus-group-real-name gnus-newsgroup-name))))
601       (save-excursion
602         (set-buffer buffer)
603         (setq gnus-newsgroup-name group)))))
604
605 (defun gnus-group-post-news (&optional arg)
606   "Start composing a message (a news by default).
607 If ARG, post to group under point.  If ARG is 1, prompt for group name.
608 Depending on the selected group, the message might be either a mail or
609 a news."
610   (interactive "P")
611   ;; Bind this variable here to make message mode hooks work ok.
612   (let ((gnus-newsgroup-name
613          (if arg
614              (if (= 1 (prefix-numeric-value arg))
615                  (completing-read "Newsgroup: " gnus-active-hashtb nil
616                                   (gnus-read-active-file-p))
617                (gnus-group-group-name))
618            ""))
619         ;; make sure last viewed article doesn't affect posting styles:
620         (gnus-article-copy))
621     (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
622                     (string= gnus-newsgroup-name ""))))
623
624 (defun gnus-summary-mail-other-window (&optional arg)
625   "Start composing a mail in another window.
626 Use the posting of the current group by default.
627 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
628 posting style."
629   (interactive "P")
630   ;; We can't `let' gnus-newsgroup-name here, since that leads
631   ;; to local variables leaking.
632   (let ((group gnus-newsgroup-name)
633         ;; make sure last viewed article doesn't affect posting styles:
634         (gnus-article-copy)
635         (buffer (current-buffer)))
636     (unwind-protect
637         (progn
638           (setq gnus-newsgroup-name
639                 (if arg
640                     (if (= 1 (prefix-numeric-value arg))
641                         (completing-read "Use group: "
642                                          gnus-active-hashtb nil
643                                          (gnus-read-active-file-p))
644                       "")
645                   gnus-newsgroup-name))
646           ;; #### see comment in gnus-setup-message -- drv
647           (gnus-setup-message 'message (message-mail)))
648       (save-excursion
649         (set-buffer buffer)
650         (setq gnus-newsgroup-name group)))))
651
652 (defun gnus-summary-news-other-window (&optional arg)
653   "Start composing a news in another window.
654 Post to the current group by default.
655 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
656
657 This function prepares a news even when using mail groups.  This is useful
658 for posting messages to mail groups without actually sending them over the
659 network.  The corresponding back end must have a 'request-post method."
660   (interactive "P")
661   ;; We can't `let' gnus-newsgroup-name here, since that leads
662   ;; to local variables leaking.
663   (let ((group gnus-newsgroup-name)
664         ;; make sure last viewed article doesn't affect posting styles:
665         (gnus-article-copy)
666         (buffer (current-buffer)))
667     (unwind-protect
668         (progn
669           (setq gnus-newsgroup-name
670                 (if arg
671                     (if (= 1 (prefix-numeric-value arg))
672                         (completing-read "Use group: "
673                                          gnus-active-hashtb nil
674                                          (gnus-read-active-file-p))
675                       "")
676                   gnus-newsgroup-name))
677           ;; #### see comment in gnus-setup-message -- drv
678           (gnus-setup-message 'message
679             (progn
680               (message-news (gnus-group-real-name gnus-newsgroup-name))
681               (set (make-local-variable 'gnus-discouraged-post-methods)
682                    (remove
683                     (car (gnus-find-method-for-group gnus-newsgroup-name))
684                     gnus-discouraged-post-methods)))))
685       (save-excursion
686         (set-buffer buffer)
687         (setq gnus-newsgroup-name group)))))
688
689 (defun gnus-summary-post-news (&optional arg)
690   "Start composing a message.  Post to the current group by default.
691 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
692 Depending on the selected group, the message might be either a mail or
693 a news."
694   (interactive "P")
695   ;; Bind this variable here to make message mode hooks work ok.
696   (let ((gnus-newsgroup-name
697          (if arg
698              (if (= 1 (prefix-numeric-value arg))
699                  (completing-read "Newsgroup: " gnus-active-hashtb nil
700                                   (gnus-read-active-file-p))
701                "")
702            gnus-newsgroup-name))
703         ;; make sure last viewed article doesn't affect posting styles:
704         (gnus-article-copy))
705     (gnus-post-news 'post gnus-newsgroup-name)))
706
707
708 (defun gnus-summary-followup (yank &optional force-news)
709   "Compose a followup to an article.
710 If prefix argument YANK is non-nil, the original article is yanked
711 automatically.
712 YANK is a list of elements, where the car of each element is the
713 article number, and the cdr is the string to be yanked."
714   (interactive
715    (list (and current-prefix-arg
716               (gnus-summary-work-articles 1))))
717   (when yank
718     (gnus-summary-goto-subject
719      (if (listp (car yank))
720          (caar yank)
721        (car yank))))
722   (save-window-excursion
723     (gnus-summary-select-article))
724   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
725         (gnus-newsgroup-name gnus-newsgroup-name))
726     ;; Send a followup.
727     (gnus-post-news nil gnus-newsgroup-name
728                     headers gnus-article-buffer
729                     yank nil force-news)
730     (gnus-summary-handle-replysign)))
731
732 (defun gnus-summary-followup-with-original (n &optional force-news)
733   "Compose a followup to an article and include the original article.
734 The text in the region will be yanked.  If the region isn't
735 active, the entire article will be yanked."
736   (interactive "P")
737   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
738
739 (defun gnus-summary-followup-to-mail (&optional arg)
740   "Followup to the current mail message via news."
741   (interactive
742    (list (and current-prefix-arg
743               (gnus-summary-work-articles 1))))
744   (gnus-summary-followup arg t))
745
746 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
747   "Followup to the current mail message via news."
748   (interactive "P")
749   (gnus-summary-followup (gnus-summary-work-articles arg) t))
750
751 (defun gnus-inews-yank-articles (articles)
752   (let (beg article yank-string)
753     (message-goto-body)
754     (while (setq article (pop articles))
755       (when (listp article)
756         (setq yank-string (nth 1 article)
757               article (nth 0 article)))
758       (save-window-excursion
759         (set-buffer gnus-summary-buffer)
760         (gnus-summary-select-article nil nil nil article)
761         (gnus-summary-remove-process-mark article))
762       (gnus-copy-article-buffer nil yank-string)
763       (let ((message-reply-buffer gnus-article-copy)
764             (message-reply-headers
765              ;; The headers are decoded.
766              (with-current-buffer gnus-article-copy
767                (save-restriction
768                  (nnheader-narrow-to-headers)
769                  (nnheader-parse-naked-head)))))
770         (message-yank-original)
771         (setq beg (or beg (mark t))))
772       (when articles
773         (insert "\n")))
774     (push-mark)
775     (goto-char beg)))
776
777 (defun gnus-summary-cancel-article (&optional n symp)
778   "Cancel an article you posted.
779 Uses the process-prefix convention.  If given the symbolic
780 prefix `a', cancel using the standard posting method; if not
781 post using the current select method."
782   (interactive (gnus-interactive "P\ny"))
783   (let ((articles (gnus-summary-work-articles n))
784         (message-post-method
785          `(lambda (arg)
786             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
787         article)
788     (while (setq article (pop articles))
789       (when (gnus-summary-select-article t nil nil article)
790         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
791                 (message-cancel-news))
792           (gnus-summary-mark-as-read article gnus-canceled-mark)
793           (gnus-cache-remove-article 1))
794         (gnus-article-hide-headers-if-wanted))
795       (gnus-summary-remove-process-mark article))))
796
797 (defun gnus-summary-supersede-article ()
798   "Compose an article that will supersede a previous article.
799 This is done simply by taking the old article and adding a Supersedes
800 header line with the old Message-ID."
801   (interactive)
802   (let ((article (gnus-summary-article-number)))
803     (gnus-setup-message 'reply-yank
804       (gnus-summary-select-article t)
805       (set-buffer gnus-original-article-buffer)
806       (message-supersede)
807       (push
808        `((lambda ()
809            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
810              (save-excursion
811                (set-buffer ,gnus-summary-buffer)
812                (gnus-cache-possibly-remove-article ,article nil nil nil t)
813                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
814        message-send-actions))))
815
816 \f
817
818 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
819   ;; make a copy of the article buffer with all text properties removed
820   ;; this copy is in the buffer gnus-article-copy.
821   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
822   ;; this buffer should be passed to all mail/news reply/post routines.
823   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
824   (save-excursion
825     (set-buffer gnus-article-copy)
826     (mm-enable-multibyte))
827   (let ((article-buffer (or article-buffer gnus-article-buffer))
828         end beg)
829     (if (not (and (get-buffer article-buffer)
830                   (gnus-buffer-exists-p article-buffer)))
831         (error "Can't find any article buffer")
832       (save-excursion
833         (set-buffer article-buffer)
834         (let ((gnus-newsgroup-charset (or gnus-article-charset
835                                           gnus-newsgroup-charset))
836               (gnus-newsgroup-ignored-charsets
837                (or gnus-article-ignored-charsets
838                    gnus-newsgroup-ignored-charsets)))
839           (save-restriction
840             ;; Copy over the (displayed) article buffer, delete
841             ;; hidden text and remove text properties.
842             (widen)
843             (copy-to-buffer gnus-article-copy (point-min) (point-max))
844             (set-buffer gnus-article-copy)
845             (when yank-string
846               (message-goto-body)
847               (delete-region (point) (point-max))
848               (insert yank-string))
849             (gnus-article-delete-text-of-type 'annotation)
850             (gnus-remove-text-with-property 'gnus-prev)
851             (gnus-remove-text-with-property 'gnus-next)
852             (gnus-remove-text-with-property 'gnus-decoration)
853             (insert
854              (prog1
855                  (buffer-substring-no-properties (point-min) (point-max))
856                (erase-buffer)))
857             ;; Find the original headers.
858             (set-buffer gnus-original-article-buffer)
859             (goto-char (point-min))
860             (while (looking-at message-unix-mail-delimiter)
861               (forward-line 1))
862             (let ((mail-header-separator ""))
863               (setq beg (point)
864                     end (or (message-goto-body)
865                             ;; There may be just a header.
866                             (point-max))))
867             ;; Delete the headers from the displayed articles.
868             (set-buffer gnus-article-copy)
869             (let ((mail-header-separator ""))
870               (delete-region (goto-char (point-min))
871                              (or (message-goto-body) (point-max))))
872             ;; Insert the original article headers.
873             (insert-buffer-substring gnus-original-article-buffer beg end)
874             ;; Decode charsets.
875             (let ((gnus-article-decode-hook
876                    (delq 'article-decode-charset
877                          (copy-sequence gnus-article-decode-hook))))
878               (run-hooks 'gnus-article-decode-hook)))))
879       gnus-article-copy)))
880
881 (defun gnus-post-news (post &optional group header article-buffer yank subject
882                             force-news)
883   (when article-buffer
884     (gnus-copy-article-buffer))
885   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
886         (gnus-article-yanked-articles yank)
887         (add-to-list gnus-add-to-list))
888     (gnus-setup-message (cond (yank 'reply-yank)
889                               (article-buffer 'reply)
890                               (t 'message))
891       (let* ((group (or group gnus-newsgroup-name))
892              (charset (gnus-group-name-charset nil group))
893              (pgroup group)
894              to-address to-group mailing-list to-list
895              newsgroup-p)
896         (when group
897           (setq to-address (gnus-parameter-to-address group)
898                 to-group (gnus-group-find-parameter group 'to-group)
899                 to-list (gnus-parameter-to-list group)
900                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
901                 mailing-list (when gnus-mailing-list-groups
902                                (string-match gnus-mailing-list-groups group))
903                 group (gnus-group-name-decode (gnus-group-real-name group)
904                                               charset)))
905         (if (or (and to-group
906                      (gnus-news-group-p to-group))
907                 newsgroup-p
908                 force-news
909                 (and (gnus-news-group-p
910                       (or pgroup gnus-newsgroup-name)
911                       (or header gnus-current-article))
912                      (not mailing-list)
913                      (not to-list)
914                      (not to-address)))
915             ;; This is news.
916             (if post
917                 (message-news
918                  (or to-group
919                      (and (not (gnus-virtual-group-p pgroup)) group)))
920               (set-buffer gnus-article-copy)
921               (gnus-msg-treat-broken-reply-to)
922               (message-followup (if (or newsgroup-p force-news)
923                                     (if (save-restriction
924                                           (article-narrow-to-head)
925                                           (message-fetch-field "newsgroups"))
926                                         nil
927                                       "")
928                                   to-group)))
929           ;; The is mail.
930           (if post
931               (progn
932                 (message-mail (or to-address to-list))
933                 ;; Arrange for mail groups that have no `to-address' to
934                 ;; get that when the user sends off the mail.
935                 (when (and (not to-list)
936                            (not to-address)
937                            add-to-list)
938                   (push (list 'gnus-inews-add-to-address pgroup)
939                         message-send-actions)))
940             (set-buffer gnus-article-copy)
941             (gnus-msg-treat-broken-reply-to)
942             (message-wide-reply to-address)))
943         (when yank
944           (gnus-inews-yank-articles yank))))))
945
946 (defun gnus-msg-treat-broken-reply-to (&optional force)
947   "Remove the Reply-to header if broken-reply-to."
948   (when (or force
949             (gnus-group-find-parameter
950              gnus-newsgroup-name 'broken-reply-to))
951     (save-restriction
952       (message-narrow-to-head)
953       (message-remove-header "reply-to"))))
954
955 (defun gnus-post-method (arg group &optional silent)
956   "Return the posting method based on GROUP and ARG.
957 If SILENT, don't prompt the user."
958   (let ((gnus-post-method (or (gnus-parameter-post-method group)
959                               gnus-post-method))
960         (group-method (gnus-find-method-for-group group)))
961     (cond
962      ;; If the group-method is nil (which shouldn't happen) we use
963      ;; the default method.
964      ((null group-method)
965       (or (and (listp gnus-post-method) ;If not current/native/nil
966                (not (listp (car gnus-post-method))) ; and not a list of methods
967                gnus-post-method)        ;then use it.
968           gnus-select-method
969           message-post-method))
970      ;; We want the inverse of the default
971      ((and arg (not (eq arg 0)))
972       (if (eq gnus-post-method 'current)
973           gnus-select-method
974         group-method))
975      ;; We query the user for a post method.
976      ((or arg
977           (and (listp gnus-post-method)
978                (listp (car gnus-post-method))))
979       (let* ((methods
980               ;; Collect all methods we know about.
981               (append
982                (when (listp gnus-post-method)
983                  (if (listp (car gnus-post-method))
984                      gnus-post-method
985                    (list gnus-post-method)))
986                gnus-secondary-select-methods
987                (mapcar 'cdr gnus-server-alist)
988                (mapcar 'car gnus-opened-servers)
989                (list gnus-select-method)
990                (list group-method)))
991              method-alist post-methods method)
992         ;; Weed out all mail methods.
993         (while methods
994           (setq method (gnus-server-get-method "" (pop methods)))
995           (when (and (or (gnus-method-option-p method 'post)
996                          (gnus-method-option-p method 'post-mail))
997                      (not (member method post-methods)))
998             (push method post-methods)))
999         ;; Create a name-method alist.
1000         (setq method-alist
1001               (mapcar
1002                (lambda (m)
1003                  (if (equal (cadr m) "")
1004                      (list (symbol-name (car m)) m)
1005                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1006                post-methods))
1007         ;; Query the user.
1008         (cadr
1009          (assoc
1010           (setq gnus-last-posting-server
1011                 (if (and silent
1012                          gnus-last-posting-server)
1013                     ;; Just use the last value.
1014                     gnus-last-posting-server
1015                   (completing-read
1016                    "Posting method: " method-alist nil t
1017                    (cons (or gnus-last-posting-server "") 0))))
1018           method-alist))))
1019      ;; Override normal method.
1020      ((and (eq gnus-post-method 'current)
1021            (not (memq (car group-method) gnus-discouraged-post-methods))
1022            (gnus-get-function group-method 'request-post t))
1023       (assert (not arg))
1024       group-method)
1025      ;; Use gnus-post-method.
1026      ((listp gnus-post-method)          ;A method...
1027       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1028       gnus-post-method)
1029      ;; Use the normal select method (nil or native).
1030      (t gnus-select-method))))
1031
1032 \f
1033
1034 (defun gnus-extended-version ()
1035   "Stringified Gnus version and Emacs version.
1036 See the variable `gnus-user-agent'."
1037   (interactive)
1038   (let* ((float-output-format nil)
1039          (gnus-v
1040           (concat "Gnus/"
1041                   (prin1-to-string (gnus-continuum-version gnus-version) t)
1042                   " (" gnus-version ")"))
1043          (emacs-v (gnus-emacs-version)))
1044     (if (stringp gnus-user-agent)
1045         gnus-user-agent
1046       (concat gnus-v
1047               (when emacs-v
1048                 (concat " " emacs-v))))))
1049
1050 \f
1051 ;;;
1052 ;;; Gnus Mail Functions
1053 ;;;
1054
1055 ;;; Mail reply commands of Gnus summary mode
1056
1057 (defun gnus-summary-reply (&optional yank wide very-wide)
1058   "Start composing a mail reply to the current message.
1059 If prefix argument YANK is non-nil, the original article is yanked
1060 automatically.
1061 If WIDE, make a wide reply.
1062 If VERY-WIDE, make a very wide reply."
1063   (interactive
1064    (list (and current-prefix-arg
1065               (gnus-summary-work-articles 1))))
1066   ;; Allow user to require confirmation before replying by mail to the
1067   ;; author of a news article (or mail message).
1068   (when (or
1069             (not (or (gnus-news-group-p gnus-newsgroup-name)
1070                      gnus-confirm-treat-mail-like-news))
1071             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1072                         (string-match gnus-confirm-mail-reply-to-news
1073                                       gnus-newsgroup-name))
1074                        ((functionp gnus-confirm-mail-reply-to-news)
1075                         (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1076                        (t gnus-confirm-mail-reply-to-news)))
1077             (y-or-n-p "Really reply by mail to article author? "))
1078     (let* ((article
1079             (if (listp (car yank))
1080                 (caar yank)
1081               (car yank)))
1082            (gnus-article-reply (or article (gnus-summary-article-number)))
1083            (gnus-article-yanked-articles yank)
1084            (headers ""))
1085       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1086       (when yank
1087         (gnus-summary-goto-subject article))
1088       (gnus-setup-message (if yank 'reply-yank 'reply)
1089         (if (not very-wide)
1090             (gnus-summary-select-article)
1091           (dolist (article very-wide)
1092             (gnus-summary-select-article nil nil nil article)
1093             (save-excursion
1094               (set-buffer (gnus-copy-article-buffer))
1095               (gnus-msg-treat-broken-reply-to)
1096               (save-restriction
1097                 (message-narrow-to-head)
1098                 (setq headers (concat headers (buffer-string)))))))
1099         (set-buffer (gnus-copy-article-buffer))
1100         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1101         (save-restriction
1102           (message-narrow-to-head)
1103           (when very-wide
1104             (erase-buffer)
1105             (insert headers))
1106           (goto-char (point-max)))
1107         (mml-quote-region (point) (point-max))
1108         (message-reply nil wide)
1109         (when yank
1110           (gnus-inews-yank-articles yank))
1111         (gnus-summary-handle-replysign)))))
1112
1113 (defun gnus-summary-handle-replysign ()
1114   "Check the various replysign variables and take action accordingly."
1115   (when (or gnus-message-replysign gnus-message-replyencrypt)
1116     (let (signed encrypted)
1117       (save-excursion
1118         (set-buffer gnus-article-buffer)
1119         (setq signed (memq 'signed gnus-article-wash-types))
1120         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1121       (cond ((and gnus-message-replyencrypt encrypted)
1122              (mml-secure-message mml-default-encrypt-method
1123                                  (if gnus-message-replysignencrypted
1124                                      'signencrypt
1125                                    'encrypt)))
1126             ((and gnus-message-replysign signed)
1127              (mml-secure-message mml-default-sign-method 'sign))))))
1128
1129 (defun gnus-summary-reply-with-original (n &optional wide)
1130   "Start composing a reply mail to the current message.
1131 The original article will be yanked."
1132   (interactive "P")
1133   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1134
1135 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1136   "Like `gnus-summary-reply' except removing reply-to field.
1137 If prefix argument YANK is non-nil, the original article is yanked
1138 automatically.
1139 If WIDE, make a wide reply.
1140 If VERY-WIDE, make a very wide reply."
1141   (interactive
1142    (list (and current-prefix-arg
1143               (gnus-summary-work-articles 1))))
1144   (let ((gnus-msg-force-broken-reply-to t))
1145     (gnus-summary-reply yank wide very-wide)))
1146
1147 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1148   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1149 The original article will be yanked."
1150   (interactive "P")
1151   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1152
1153 (defun gnus-summary-wide-reply (&optional yank)
1154   "Start composing a wide reply mail to the current message.
1155 If prefix argument YANK is non-nil, the original article is yanked
1156 automatically."
1157   (interactive
1158    (list (and current-prefix-arg
1159               (gnus-summary-work-articles 1))))
1160   (gnus-summary-reply yank t))
1161
1162 (defun gnus-summary-wide-reply-with-original (n)
1163   "Start composing a wide reply mail to the current message.
1164 The original article will be yanked.
1165 Uses the process/prefix convention."
1166   (interactive "P")
1167   (gnus-summary-reply-with-original n t))
1168
1169 (defun gnus-summary-very-wide-reply (&optional yank)
1170   "Start composing a very wide reply mail to the current message.
1171 If prefix argument YANK is non-nil, the original article is yanked
1172 automatically."
1173   (interactive
1174    (list (and current-prefix-arg
1175               (gnus-summary-work-articles 1))))
1176   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1177
1178 (defun gnus-summary-very-wide-reply-with-original (n)
1179   "Start composing a very wide reply mail to the current message.
1180 The original article will be yanked."
1181   (interactive "P")
1182   (gnus-summary-reply
1183    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1184
1185 (defun gnus-summary-mail-forward (&optional arg post)
1186   "Forward the current message(s) to another user.
1187 If process marks exist, forward all marked messages;
1188 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1189 if ARG is 1, decode the message and forward directly inline;
1190 if ARG is 2, forward message as an rfc822 MIME section;
1191 if ARG is 3, decode message and forward as an rfc822 MIME section;
1192 if ARG is 4, forward message directly inline;
1193 otherwise, use flipped `message-forward-as-mime'.
1194 If POST, post instead of mail.
1195 For the `inline' alternatives, also see the variable
1196 `message-forward-ignored-headers'."
1197   (interactive "P")
1198   (if (cdr (gnus-summary-work-articles nil))
1199       ;; Process marks are given.
1200       (gnus-uu-digest-mail-forward arg post)
1201     ;; No process marks.
1202     (let ((message-forward-as-mime message-forward-as-mime)
1203           (message-forward-show-mml message-forward-show-mml))
1204       (cond
1205        ((null arg))
1206        ((eq arg 1)
1207         (setq message-forward-as-mime nil
1208               message-forward-show-mml t))
1209        ((eq arg 2)
1210         (setq message-forward-as-mime t
1211               message-forward-show-mml nil))
1212        ((eq arg 3)
1213         (setq message-forward-as-mime t
1214               message-forward-show-mml t))
1215        ((eq arg 4)
1216         (setq message-forward-as-mime nil
1217               message-forward-show-mml nil))
1218        (t
1219         (setq message-forward-as-mime (not message-forward-as-mime))))
1220       (let* ((gnus-article-reply (gnus-summary-article-number))
1221              (gnus-article-yanked-articles (list gnus-article-reply)))
1222         (gnus-setup-message 'forward
1223           (gnus-summary-select-article)
1224           (let ((mail-parse-charset
1225                  (or (and (gnus-buffer-live-p gnus-article-buffer)
1226                           (with-current-buffer gnus-article-buffer
1227                             gnus-article-charset))
1228                      gnus-newsgroup-charset))
1229                 (mail-parse-ignored-charsets
1230                  gnus-newsgroup-ignored-charsets))
1231             (set-buffer gnus-original-article-buffer)
1232             (message-forward post)))))))
1233
1234 (defun gnus-summary-resend-message (address n)
1235   "Resend the current article to ADDRESS."
1236   (interactive
1237    (list (message-read-from-minibuffer
1238           "Resend message(s) to: "
1239           (when (and gnus-summary-resend-default-address
1240                      (gnus-buffer-live-p gnus-original-article-buffer))
1241             ;; If some other article is currently selected, the
1242             ;; initial-contents is wrong. Whatever, it is just the
1243             ;; initial-contents.
1244             (with-current-buffer gnus-original-article-buffer
1245               (nnmail-fetch-field "to"))))
1246          current-prefix-arg))
1247   (let ((articles (gnus-summary-work-articles n))
1248         article)
1249     (while (setq article (pop articles))
1250       (gnus-summary-select-article nil nil nil article)
1251       (save-excursion
1252         (set-buffer gnus-original-article-buffer)
1253         (message-resend address))
1254       (gnus-summary-mark-article-as-forwarded article))))
1255
1256 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1257 (defun gnus-summary-resend-message-edit ()
1258   "Resend an article that has already been sent.
1259 A new buffer will be created to allow the user to modify body and
1260 contents of the message, and then, everything will happen as when
1261 composing a new message."
1262   (interactive)
1263   (let ((article (gnus-summary-article-number)))
1264     (gnus-setup-message 'reply-yank
1265       (gnus-summary-select-article t)
1266       (set-buffer gnus-original-article-buffer)
1267       (let ((cur (current-buffer))
1268             (to (message-fetch-field "to")))
1269         ;; Get a normal message buffer.
1270         (message-pop-to-buffer (message-buffer-name "Resend" to))
1271         (insert-buffer-substring cur)
1272         (mime-to-mml)
1273         (message-narrow-to-head-1)
1274         ;; Gnus will generate a new one when sending.
1275         (message-remove-header "Message-ID")
1276         (message-remove-header message-ignored-resent-headers t)
1277         ;; Remove unwanted headers.
1278         (goto-char (point-max))
1279         (insert mail-header-separator)
1280         (goto-char (point-min))
1281         (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1282           (forward-char 1))
1283         (widen)))))
1284
1285 (defun gnus-summary-post-forward (&optional arg)
1286   "Forward the current article to a newsgroup.
1287 See `gnus-summary-mail-forward' for ARG."
1288   (interactive "P")
1289   (gnus-summary-mail-forward arg t))
1290
1291 (defvar gnus-nastygram-message
1292   "The following article was inappropriately posted to %s.\n\n"
1293   "Format string to insert in nastygrams.
1294 The current group name will be inserted at \"%s\".")
1295
1296 (defun gnus-summary-mail-nastygram (n)
1297   "Send a nastygram to the author of the current article."
1298   (interactive "P")
1299   (when (or gnus-expert-user
1300             (gnus-y-or-n-p
1301              "Really send a nastygram to the author of the current article? "))
1302     (let ((group gnus-newsgroup-name))
1303       (gnus-summary-reply-with-original n)
1304       (set-buffer gnus-message-buffer)
1305       (message-goto-body)
1306       (insert (format gnus-nastygram-message group))
1307       (message-send-and-exit))))
1308
1309 (defun gnus-summary-mail-crosspost-complaint (n)
1310   "Send a complaint about crossposting to the current article(s)."
1311   (interactive "P")
1312   (let ((articles (gnus-summary-work-articles n))
1313         article)
1314     (while (setq article (pop articles))
1315       (set-buffer gnus-summary-buffer)
1316       (gnus-summary-goto-subject article)
1317       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1318             newsgroups followup-to)
1319         (gnus-summary-select-article)
1320         (set-buffer gnus-original-article-buffer)
1321         (if (and (<= (length (message-tokenize-header
1322                               (setq newsgroups
1323                                     (mail-fetch-field "newsgroups"))
1324                               ", "))
1325                      1)
1326                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1327                      (not (member group (message-tokenize-header
1328                                          followup-to ", ")))))
1329             (if followup-to
1330                 (gnus-message 1 "Followup-to restricted")
1331               (gnus-message 1 "Not a crossposted article"))
1332           (set-buffer gnus-summary-buffer)
1333           (gnus-summary-reply-with-original 1)
1334           (set-buffer gnus-message-buffer)
1335           (message-goto-body)
1336           (insert (format gnus-crosspost-complaint newsgroups group))
1337           (message-goto-subject)
1338           (re-search-forward " *$")
1339           (replace-match " (crosspost notification)" t t)
1340           (gnus-deactivate-mark)
1341           (when (gnus-y-or-n-p "Send this complaint? ")
1342             (message-send-and-exit)))))))
1343
1344 (defun gnus-mail-parse-comma-list ()
1345   (let (accumulated
1346         beg)
1347     (skip-chars-forward " ")
1348     (while (not (eobp))
1349       (setq beg (point))
1350       (skip-chars-forward "^,")
1351       (while (zerop
1352               (save-excursion
1353                 (save-restriction
1354                   (let ((i 0))
1355                     (narrow-to-region beg (point))
1356                     (goto-char beg)
1357                     (logand (progn
1358                               (while (search-forward "\"" nil t)
1359                                 (incf i))
1360                               (if (zerop i) 2 i))
1361                             2)))))
1362         (skip-chars-forward ",")
1363         (skip-chars-forward "^,"))
1364       (skip-chars-backward " ")
1365       (push (buffer-substring beg (point))
1366             accumulated)
1367       (skip-chars-forward "^,")
1368       (skip-chars-forward ", "))
1369     accumulated))
1370
1371 (defun gnus-inews-add-to-address (group)
1372   (let ((to-address (mail-fetch-field "to")))
1373     (when (and to-address
1374                (gnus-alive-p))
1375       ;; This mail group doesn't have a `to-list', so we add one
1376       ;; here.  Magic!
1377       (when (gnus-y-or-n-p
1378              (format "Do you want to add this as `to-list': %s? " to-address))
1379         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1380
1381 (defun gnus-put-message ()
1382   "Put the current message in some group and return to Gnus."
1383   (interactive)
1384   (let ((reply gnus-article-reply)
1385         (winconf gnus-prev-winconf)
1386         (group gnus-newsgroup-name))
1387     (unless (and group
1388                  (not (gnus-group-read-only-p group)))
1389       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1390
1391     (when (gnus-group-entry group)
1392       (error "No such group: %s" group))
1393     (save-excursion
1394       (save-restriction
1395         (widen)
1396         (message-narrow-to-headers)
1397         (let ((gnus-deletable-headers nil))
1398           (message-generate-headers
1399            (if (message-news-p)
1400                message-required-news-headers
1401              message-required-mail-headers)))
1402         (goto-char (point-max))
1403         (if (string-match " " group)
1404             (insert "Gcc: \"" group "\"\n")
1405           (insert "Gcc: " group "\n"))
1406         (widen)))
1407     (gnus-inews-do-gcc)
1408     (when (and (get-buffer gnus-group-buffer)
1409                (gnus-buffer-exists-p (car-safe reply))
1410                (cdr reply))
1411       (set-buffer (car reply))
1412       (gnus-summary-mark-article-as-replied (cdr reply)))
1413     (when winconf
1414       (set-window-configuration winconf))))
1415
1416 (defun gnus-article-mail (yank)
1417   "Send a reply to the address near point.
1418 If YANK is non-nil, include the original article."
1419   (interactive "P")
1420   (let ((address
1421          (buffer-substring
1422           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1423           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1424     (when address
1425       (gnus-msg-mail address)
1426       (when yank
1427         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1428
1429 (defvar nntp-server-type)
1430 (defun gnus-bug ()
1431   "Send a bug report to the Gnus maintainers."
1432   (interactive)
1433   (unless (gnus-alive-p)
1434     (error "Gnus has been shut down"))
1435   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1436     (unless (message-mail-user-agent)
1437       (delete-other-windows)
1438       (when gnus-bug-create-help-buffer
1439         (switch-to-buffer "*Gnus Help Bug*")
1440         (erase-buffer)
1441         (insert gnus-bug-message)
1442         (goto-char (point-min)))
1443       (message-pop-to-buffer "*Gnus Bug*"))
1444     (let ((message-this-is-mail t))
1445       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1446     (when gnus-bug-create-help-buffer
1447       (push `(gnus-bug-kill-buffer) message-send-actions))
1448     (goto-char (point-min))
1449     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1450     (forward-line 1)
1451     (insert (gnus-version) "\n"
1452             (emacs-version) "\n")
1453     (when (and (boundp 'nntp-server-type)
1454                (stringp nntp-server-type))
1455       (insert nntp-server-type))
1456     (insert "\n\n\n\n\n")
1457     (let (text)
1458       (save-excursion
1459         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1460         (erase-buffer)
1461         (gnus-debug)
1462         (setq text (buffer-string)))
1463       (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1464     (goto-char (point-min))
1465     (search-forward "Subject: " nil t)
1466     (message "")))
1467
1468 (defun gnus-bug-kill-buffer ()
1469   (when (get-buffer "*Gnus Help Bug*")
1470     (kill-buffer "*Gnus Help Bug*")))
1471
1472 (defun gnus-summary-yank-message (buffer n)
1473   "Yank the current article into a composed message."
1474   (interactive
1475    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1476          current-prefix-arg))
1477   (gnus-summary-iterate n
1478     (let ((gnus-inhibit-treatment t))
1479       (gnus-summary-select-article))
1480     (save-excursion
1481       (set-buffer buffer)
1482       (message-yank-buffer gnus-article-buffer))))
1483
1484 (defun gnus-debug ()
1485   "Attempts to go through the Gnus source file and report what variables have been changed.
1486 The source file has to be in the Emacs load path."
1487   (interactive)
1488   (let ((files gnus-debug-files)
1489         (point (point))
1490         file expr olist sym)
1491     (gnus-message 4 "Please wait while we snoop your variables...")
1492     (sit-for 0)
1493     ;; Go through all the files looking for non-default values for variables.
1494     (save-excursion
1495       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1496       (while files
1497         (erase-buffer)
1498         (when (and (setq file (locate-library (pop files)))
1499                    (file-exists-p file))
1500           (insert-file-contents file)
1501           (goto-char (point-min))
1502           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1503               (gnus-message 4 "Malformed sources in file %s" file)
1504             (narrow-to-region (point-min) (point))
1505             (goto-char (point-min))
1506             (while (setq expr (ignore-errors (read (current-buffer))))
1507               (ignore-errors
1508                 (and (or (eq (car expr) 'defvar)
1509                          (eq (car expr) 'defcustom))
1510                      (stringp (nth 3 expr))
1511                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1512                      (or (not (boundp (nth 1 expr)))
1513                          (not (equal (eval (nth 2 expr))
1514                                      (symbol-value (nth 1 expr)))))
1515                      (push (nth 1 expr) olist)))))))
1516       (kill-buffer (current-buffer)))
1517     (when (setq olist (nreverse olist))
1518       (insert "------------------ Environment follows ------------------\n\n"))
1519     (while olist
1520       (if (boundp (car olist))
1521           (ignore-errors
1522             (pp `(setq ,(car olist)
1523                        ,(if (or (consp (setq sym (symbol-value (car olist))))
1524                                 (and (symbolp sym)
1525                                      (not (or (eq sym nil)
1526                                               (eq sym t)))))
1527                             (list 'quote (symbol-value (car olist)))
1528                           (symbol-value (car olist))))
1529                 (current-buffer)))
1530         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1531       (setq olist (cdr olist)))
1532     (insert "\n\n")
1533     ;; Remove any control chars - they seem to cause trouble for some
1534     ;; mailers.  (Byte-compiled output from the stuff above.)
1535     (goto-char point)
1536     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1537       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1538                      t t))))
1539
1540 ;;; Treatment of rejected articles.
1541 ;;; Bounced mail.
1542
1543 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1544   "Re-mail the current message.
1545 This only makes sense if the current message is a bounce message that
1546 contains some mail you have written which has been bounced back to
1547 you.
1548 If FETCH, try to fetch the article that this is a reply to, if indeed
1549 this is a reply."
1550   (interactive "P")
1551   (gnus-summary-select-article t)
1552   (set-buffer gnus-original-article-buffer)
1553   (gnus-setup-message 'compose-bounce
1554     (let* ((references (mail-fetch-field "references"))
1555            (parent (and references (gnus-parent-id references))))
1556       (message-bounce)
1557       ;; If there are references, we fetch the article we answered to.
1558       (and fetch parent
1559            (gnus-summary-refer-article parent)
1560            (gnus-summary-show-all-headers)))))
1561
1562 ;;; Gcc handling.
1563
1564 (defun gnus-inews-group-method (group)
1565   (cond
1566    ;; If the group doesn't exist, we assume
1567    ;; it's an archive group...
1568    ((and (null (gnus-get-info group))
1569          (eq (car (gnus-server-to-method gnus-message-archive-method))
1570              (car (gnus-server-to-method (gnus-group-method group)))))
1571     gnus-message-archive-method)
1572    ;; Use the method.
1573    ((gnus-info-method (gnus-get-info group))
1574     (gnus-info-method (gnus-get-info group)))
1575    ;; Find the method.
1576    (t (gnus-server-to-method (gnus-group-method group)))))
1577
1578 ;; Do Gcc handling, which copied the message over to some group.
1579 (defun gnus-inews-do-gcc (&optional gcc)
1580   (interactive)
1581   (save-excursion
1582     (save-restriction
1583       (message-narrow-to-headers)
1584       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1585             (cur (current-buffer))
1586             groups group method group-art
1587             mml-externalize-attachments)
1588         (when gcc
1589           (message-remove-header "gcc")
1590           (widen)
1591           (setq groups (message-unquote-tokens
1592                         (message-tokenize-header gcc " ,")))
1593           ;; Copy the article over to some group(s).
1594           (while (setq group (pop groups))
1595             (unless (gnus-check-server
1596                      (setq method (gnus-inews-group-method group)))
1597               (error "Can't open server %s" (if (stringp method) method
1598                                               (car method))))
1599             (unless (gnus-request-group group nil method)
1600               (gnus-request-create-group group method))
1601             (setq mml-externalize-attachments
1602                   (if (stringp gnus-gcc-externalize-attachments)
1603                       (string-match gnus-gcc-externalize-attachments group)
1604                     gnus-gcc-externalize-attachments))
1605             (save-excursion
1606               (nnheader-set-temp-buffer " *acc*")
1607               (insert-buffer-substring cur)
1608               (message-encode-message-body)
1609               (save-restriction
1610                 (message-narrow-to-headers)
1611                 (let* ((mail-parse-charset message-default-charset)
1612                        (newsgroups-field (save-restriction
1613                                            (message-narrow-to-headers-or-head)
1614                                            (message-fetch-field "Newsgroups")))
1615                        (followup-field (save-restriction
1616                                          (message-narrow-to-headers-or-head)
1617                                          (message-fetch-field "Followup-To")))
1618                        ;; BUG: We really need to get the charset for
1619                        ;; each name in the Newsgroups and Followup-To
1620                        ;; lines to allow crossposting between group
1621                        ;; namess with incompatible character sets.
1622                        ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1623                        (group-field-charset
1624                         (gnus-group-name-charset
1625                          method (or newsgroups-field "")))
1626                        (followup-field-charset
1627                         (gnus-group-name-charset
1628                          method (or followup-field "")))
1629                        (rfc2047-header-encoding-alist
1630                         (append
1631                          (when group-field-charset
1632                            (list (cons "Newsgroups" group-field-charset)))
1633                          (when followup-field-charset
1634                            (list (cons "Followup-To" followup-field-charset)))
1635                          rfc2047-header-encoding-alist)))
1636                   (mail-encode-encoded-word-buffer)))
1637               (goto-char (point-min))
1638               (when (re-search-forward
1639                      (concat "^" (regexp-quote mail-header-separator) "$")
1640                      nil t)
1641                 (replace-match "" t t ))
1642               (when (or (not (gnus-check-backend-function
1643                               'request-accept-article group))
1644                         (not (setq group-art
1645                                    (gnus-request-accept-article
1646                                     group method t t))))
1647                 (gnus-message 1 "Couldn't store article in group %s: %s"
1648                               group (gnus-status-message method)))
1649               (when (and group-art
1650                          ;; FIXME: Should gcc-mark-as-read work when
1651                          ;; Gnus is not running?
1652                          (gnus-alive-p)
1653                          (or gnus-gcc-mark-as-read
1654                              (and
1655                               (boundp 'gnus-inews-mark-gcc-as-read)
1656                               (symbol-value 'gnus-inews-mark-gcc-as-read))))
1657                 (gnus-group-mark-article-read group (cdr group-art)))
1658               (kill-buffer (current-buffer)))))))))
1659
1660 (defun gnus-inews-insert-gcc ()
1661   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1662   (save-excursion
1663     (save-restriction
1664       (message-narrow-to-headers)
1665       (let* ((group gnus-outgoing-message-group)
1666              (gcc (cond
1667                    ((functionp group)
1668                     (funcall group))
1669                    ((or (stringp group) (list group))
1670                     group))))
1671         (when gcc
1672           (insert "Gcc: "
1673                   (if (stringp gcc)
1674                       (if (string-match " " gcc)
1675                           (concat "\"" gcc "\"")
1676                         gcc)
1677                     (mapconcat (lambda (group)
1678                                  (if (string-match " " group)
1679                                      (concat "\"" group "\"")
1680                                    group))
1681                                gcc " "))
1682                   "\n"))))))
1683
1684 (defun gnus-inews-insert-archive-gcc (&optional group)
1685   "Insert the Gcc to say where the article is to be archived."
1686   (let* ((var gnus-message-archive-group)
1687          (group (or group gnus-newsgroup-name ""))
1688          (gcc-self-val
1689           (and gnus-newsgroup-name
1690                (not (equal gnus-newsgroup-name ""))
1691                (gnus-group-find-parameter
1692                 gnus-newsgroup-name 'gcc-self)))
1693          result
1694          (groups
1695           (cond
1696            ((null gnus-message-archive-method)
1697             ;; Ignore.
1698             nil)
1699            ((stringp var)
1700             ;; Just a single group.
1701             (list var))
1702            ((null var)
1703             ;; We don't want this.
1704             nil)
1705            ((and (listp var) (stringp (car var)))
1706             ;; A list of groups.
1707             var)
1708            ((functionp var)
1709             ;; A function.
1710             (funcall var group))
1711            (t
1712             ;; An alist of regexps/functions/forms.
1713             (while (and var
1714                         (not
1715                          (setq result
1716                                (cond
1717                                 ((stringp (caar var))
1718                                  ;; Regexp.
1719                                  (when (string-match (caar var) group)
1720                                    (cdar var)))
1721                                 ((functionp (car var))
1722                                  ;; Function.
1723                                  (funcall (car var) group))
1724                                 (t
1725                                  (eval (car var)))))))
1726               (setq var (cdr var)))
1727             result)))
1728          name)
1729     (when (or groups gcc-self-val)
1730       (when (stringp groups)
1731         (setq groups (list groups)))
1732       (save-excursion
1733         (save-restriction
1734           (message-narrow-to-headers)
1735           (goto-char (point-max))
1736           (insert "Gcc: ")
1737           (if gcc-self-val
1738               ;; Use the `gcc-self' param value instead.
1739               (progn
1740                 (insert
1741                  (if (stringp gcc-self-val)
1742                      (if (string-match " " gcc-self-val)
1743                          (concat "\"" gcc-self-val "\"")
1744                        gcc-self-val)
1745                    ;; In nndoc groups, we use the parent group name
1746                    ;; instead of the current group.
1747                    (let ((group (or (gnus-group-find-parameter
1748                                      gnus-newsgroup-name 'parent-group)
1749                                     group)))
1750                      (if (string-match " " group)
1751                          (concat "\"" group "\"")
1752                        group))))
1753                 (if (not (eq gcc-self-val 'none))
1754                     (insert "\n")
1755                   (gnus-delete-line)))
1756             ;; Use the list of groups.
1757             (while (setq name (pop groups))
1758               (let ((str (if (string-match ":" name)
1759                              name
1760                            (gnus-group-prefixed-name
1761                             name gnus-message-archive-method))))
1762                 (insert (if (string-match " " str)
1763                             (concat "\"" str "\"")
1764                           str)))
1765               (when groups
1766                 (insert " ")))
1767             (insert "\n")))))))
1768
1769 (defun gnus-mailing-list-followup-to ()
1770   "Look at the headers in the current buffer and return a Mail-Followup-To address."
1771   (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1772         (list-post (gnus-fetch-original-field "list-post")))
1773     (when (and list-post
1774                (string-match "mailto:\\([^>]+\\)" list-post))
1775       (setq list-post (match-string 1 list-post)))
1776     (or list-post
1777         x-been-there)))
1778
1779 ;;; Posting styles.
1780
1781 (defun gnus-configure-posting-styles (&optional group-name)
1782   "Configure posting styles according to `gnus-posting-styles'."
1783   (unless gnus-inhibit-posting-styles
1784     (let ((group (or group-name gnus-newsgroup-name ""))
1785           (styles gnus-posting-styles)
1786           style match attribute value v results
1787           filep name address element)
1788       ;; If the group has a posting-style parameter, add it at the end with a
1789       ;; regexp matching everything, to be sure it takes precedence over all
1790       ;; the others.
1791       (when gnus-newsgroup-name
1792         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1793           (when tmp-style
1794             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1795       ;; Go through all styles and look for matches.
1796       (dolist (style styles)
1797         (setq match (pop style))
1798         (goto-char (point-min))
1799         (when (cond
1800                ((stringp match)
1801                 ;; Regexp string match on the group name.
1802                 (string-match match group))
1803                ((eq match 'header)
1804                 ;; Obsolete format of header match.
1805                 (and (gnus-buffer-live-p gnus-article-copy)
1806                      (with-current-buffer gnus-article-copy
1807                        (let ((header (message-fetch-field (pop style))))
1808                          (and header
1809                               (string-match (pop style) header))))))
1810                ((or (symbolp match)
1811                     (functionp match))
1812                 (cond
1813                  ((functionp match)
1814                   ;; Function to be called.
1815                   (funcall match))
1816                  ((boundp match)
1817                   ;; Variable to be checked.
1818                   (symbol-value match))))
1819                ((listp match)
1820                 (cond
1821                  ((eq (car match) 'header)
1822                   ;; New format of header match.
1823                   (and (gnus-buffer-live-p gnus-article-copy)
1824                        (with-current-buffer gnus-article-copy
1825                          (let ((header (message-fetch-field (nth 1 match))))
1826                            (and header
1827                                 (string-match (nth 2 match) header))))))
1828                  (t
1829                   ;; This is a form to be evaled.
1830                   (eval match)))))
1831           ;; We have a match, so we set the variables.
1832           (dolist (attribute style)
1833             (setq element (pop attribute)
1834                   filep nil)
1835             (setq value
1836                   (cond
1837                    ((eq (car attribute) :file)
1838                     (setq filep t)
1839                     (cadr attribute))
1840                    ((eq (car attribute) :value)
1841                     (cadr attribute))
1842                    (t
1843                     (car attribute))))
1844             ;; We get the value.
1845             (setq v
1846                   (cond
1847                    ((stringp value)
1848                     value)
1849                    ((or (symbolp value)
1850                         (functionp value))
1851                     (cond ((functionp value)
1852                            (funcall value))
1853                           ((boundp value)
1854                            (symbol-value value))))
1855                    ((listp value)
1856                     (eval value))))
1857             ;; Translate obsolescent value.
1858             (cond
1859              ((eq element 'signature-file)
1860               (setq element 'signature
1861                     filep t))
1862              ((eq element 'x-face-file)
1863               (setq element 'x-face
1864                     filep t)))
1865             ;; Get the contents of file elems.
1866             (when (and filep v)
1867               (setq v (with-temp-buffer
1868                         (insert-file-contents v)
1869                         (goto-char (point-max))
1870                         (while (bolp)
1871                           (delete-char -1))
1872                         (buffer-string))))
1873             (setq results (delq (assoc element results) results))
1874             (push (cons element v) results))))
1875       ;; Now we have all the styles, so we insert them.
1876       (setq name (assq 'name results)
1877             address (assq 'address results))
1878       (setq results (delq name (delq address results)))
1879       (gnus-make-local-hook 'message-setup-hook)
1880       (setq results (sort results (lambda (x y)
1881                                     (string-lessp (car x) (car y)))))
1882       (dolist (result results)
1883         (add-hook 'message-setup-hook
1884                   (cond
1885                    ((eq 'eval (car result))
1886                     'ignore)
1887                    ((eq 'body (car result))
1888                     `(lambda ()
1889                        (save-excursion
1890                          (message-goto-body)
1891                          (insert ,(cdr result)))))
1892                    ((eq 'signature (car result))
1893                     (set (make-local-variable 'message-signature) nil)
1894                     (set (make-local-variable 'message-signature-file) nil)
1895                     (if (not (cdr result))
1896                         'ignore
1897                       `(lambda ()
1898                          (save-excursion
1899                            (let ((message-signature ,(cdr result)))
1900                              (when message-signature
1901                                (message-insert-signature)))))))
1902                    (t
1903                     (let ((header
1904                            (if (symbolp (car result))
1905                                (capitalize (symbol-name (car result)))
1906                              (car result))))
1907                       `(lambda ()
1908                          (save-excursion
1909                            (message-remove-header ,header)
1910                            (let ((value ,(cdr result)))
1911                              (when value
1912                                (message-goto-eoh)
1913                                (insert ,header ": " value)
1914                                (unless (bolp)
1915                                  (insert "\n")))))))))
1916                   nil 'local))
1917       (when (or name address)
1918         (add-hook 'message-setup-hook
1919                   `(lambda ()
1920                      (set (make-local-variable 'user-mail-address)
1921                           ,(or (cdr address) user-mail-address))
1922                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1923                            (user-mail-address
1924                             ,(or (cdr address) user-mail-address)))
1925                        (save-excursion
1926                          (message-remove-header "From")
1927                          (message-goto-eoh)
1928                          (insert "From: " (message-make-from) "\n"))))
1929                   nil 'local)))))
1930
1931 ;;; Allow redefinition of functions.
1932
1933 (gnus-ems-redefine)
1934
1935 (provide 'gnus-msg)
1936
1937 ;;; gnus-msg.el ends here