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