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