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