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