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