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