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