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