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