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