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