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