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