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