T-gnus v6.17.2.
[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   (interactive "P")
761   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
762
763 (defun gnus-summary-followup-to-mail (&optional arg)
764   "Followup to the current mail message via news."
765   (interactive
766    (list (and current-prefix-arg
767               (gnus-summary-work-articles 1))))
768   (gnus-summary-followup arg t))
769
770 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
771   "Followup to the current mail message via news."
772   (interactive "P")
773   (gnus-summary-followup (gnus-summary-work-articles arg) t))
774
775 (defun gnus-inews-yank-articles (articles)
776   (let (beg article yank-string
777             (more-than-one (cdr articles))
778             (cur (current-buffer))
779             refs window)
780     (message-goto-body)
781     (while (setq article (pop articles))
782       (when (listp article)
783         (setq yank-string (nth 1 article)
784               article (nth 0 article)))
785       (save-window-excursion
786         (set-buffer gnus-summary-buffer)
787         (gnus-summary-select-article nil nil nil article)
788         (gnus-summary-remove-process-mark article))
789
790       ;; Gathering references.
791       (when more-than-one
792         (setq refs (message-list-references
793                     refs
794                     (mail-header-references gnus-current-headers)
795                     (mail-header-message-id gnus-current-headers)))
796         (when message-use-multi-frames
797           (when (setq window (get-buffer-window cur t))
798             (select-frame (window-frame window)))))
799
800       (gnus-copy-article-buffer nil yank-string)
801       (let ((message-reply-buffer gnus-article-copy)
802             (message-reply-headers
803              ;; The headers are decoded.
804              (with-current-buffer gnus-article-copy
805                (save-restriction
806                  (nnheader-narrow-to-headers)
807                  (nnheader-parse-naked-head)))))
808         (message-yank-original)
809         (setq beg (or beg (mark t))))
810       (when articles
811         (insert "\n")))
812     (push-mark)
813
814     ;; Replace with the gathered references.
815     (when refs
816       (push-mark beg)
817       (save-restriction
818         (message-narrow-to-headers)
819         (let ((case-fold-search t))
820           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
821               (replace-match "")
822             (goto-char (point-max))))
823         (mail-header-format
824          (list (or (assq 'References message-header-format-alist)
825                    '(References . message-shorten-references)))
826          (list (cons 'References
827                      (mapconcat 'identity (nreverse refs) " "))))
828         (backward-delete-char 1))
829       (setq beg (mark t))
830       (pop-mark))
831
832     (goto-char beg)))
833
834 (defun gnus-summary-cancel-article (&optional n symp)
835   "Cancel an article you posted.
836 Uses the process-prefix convention.  If given the symbolic
837 prefix `a', cancel using the standard posting method; if not
838 post using the current select method."
839   (interactive (gnus-interactive "P\ny"))
840   (let ((articles (gnus-summary-work-articles n))
841         (message-post-method
842          `(lambda (arg)
843             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
844         article)
845     (while (setq article (pop articles))
846       (when (gnus-summary-select-article t nil nil article)
847         (when (gnus-eval-in-buffer-window gnus-article-buffer
848                 (save-excursion
849                   (set-buffer gnus-original-article-buffer)
850                   (message-cancel-news)))
851           (gnus-summary-mark-as-read article gnus-canceled-mark)
852           (gnus-cache-remove-article 1))
853         (gnus-article-hide-headers-if-wanted))
854       (gnus-summary-remove-process-mark article))))
855
856 (defun gnus-summary-supersede-article ()
857   "Compose an article that will supersede a previous article.
858 This is done simply by taking the old article and adding a Supersedes
859 header line with the old Message-ID."
860   (interactive)
861   (let ((article (gnus-summary-article-number)))
862     (gnus-setup-message 'reply-yank
863       (gnus-summary-select-article t)
864       (set-buffer gnus-original-article-buffer)
865       (message-supersede)
866       (push
867        `((lambda ()
868            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
869              (save-excursion
870                (set-buffer ,gnus-summary-buffer)
871                (gnus-cache-possibly-remove-article ,article nil nil nil t)
872                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
873        message-send-actions))))
874
875 \f
876
877 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
878   ;; make a copy of the article buffer with all text properties removed
879   ;; this copy is in the buffer gnus-article-copy.
880   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
881   ;; this buffer should be passed to all mail/news reply/post routines.
882   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
883   (save-excursion
884     (set-buffer gnus-article-copy)
885     (set-buffer-multibyte t))
886   (let ((article-buffer (or article-buffer gnus-article-buffer))
887         end beg)
888     (if (not (and (get-buffer article-buffer)
889                   (gnus-buffer-exists-p article-buffer)))
890         (error "Can't find any article buffer")
891       (save-excursion
892         (set-buffer article-buffer)
893         (let ((gnus-newsgroup-charset (or gnus-article-charset
894                                           gnus-newsgroup-charset))
895               (gnus-newsgroup-ignored-charsets
896                (or gnus-article-ignored-charsets
897                    gnus-newsgroup-ignored-charsets)))
898           (save-restriction
899             ;; Copy over the (displayed) article buffer, delete
900             ;; hidden text and remove text properties.
901             (widen)
902             (copy-to-buffer gnus-article-copy (point-min) (point-max))
903             (set-buffer gnus-article-copy)
904             ;; There's invisible and intangible text in T-gnus.  Especially,
905             ;; if there is a boundary line (X-Boundary: ------------------),
906             ;; in the end of a header, it will cause a serious problem.
907             (add-text-properties (point-min) (point-max)
908                                  '(invisible nil intangible nil))
909             (when yank-string
910               (message-goto-body)
911               (delete-region (point) (point-max))
912               (insert yank-string))
913             ;; Encode bitmap smileys to ordinary text.
914             ;; Possibly, the original text might be restored.
915             (static-unless (featurep 'xemacs)
916               (when (featurep 'smiley-mule)
917                 (smiley-encode-buffer)))
918             (gnus-article-delete-text-of-type 'annotation)
919             (gnus-remove-text-with-property 'gnus-prev)
920             (gnus-remove-text-with-property 'gnus-next)
921             (gnus-remove-text-with-property 'gnus-decoration)
922             (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
923             (insert
924              (prog1
925                  (static-if (featurep 'xemacs)
926                      ;; Revome smiley extents for (possibly) XEmacs 21.1.
927                      (format "%s"
928                              (buffer-substring-no-properties (point-min)
929                                                              (point-max)))
930                    (buffer-substring-no-properties (point-min) (point-max)))
931                (erase-buffer)))
932             ;; Find the original headers.
933             (set-buffer gnus-original-article-buffer)
934             (goto-char (point-min))
935             (while (looking-at message-unix-mail-delimiter)
936               (forward-line 1))
937             (let ((mail-header-separator ""))
938               (setq beg (point)
939                     end (or (message-goto-body)
940                             ;; There may be just a header.
941                             (point-max))))
942             ;; Delete the headers from the displayed articles.
943             (set-buffer gnus-article-copy)
944             (let ((mail-header-separator ""))
945               (delete-region (goto-char (point-min))
946                              (or (message-goto-body) (point-max))))
947             ;; Insert the original article headers.
948             (insert-buffer-substring gnus-original-article-buffer beg end)
949             ;; Decode charsets.
950             (let ((gnus-article-decode-hook
951                    (delq 'article-decode-charset
952                          (copy-sequence gnus-article-decode-hook))))
953               ;; Needed for T-gnus.
954               (add-hook 'gnus-article-decode-hook
955                         'article-decode-encoded-words)
956               (run-hooks 'gnus-article-decode-hook)))))
957       gnus-article-copy)))
958
959 (defun gnus-post-news (post &optional group header article-buffer yank subject
960                             force-news)
961   (when article-buffer
962     (gnus-copy-article-buffer))
963   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
964         (gnus-article-yanked-articles yank)
965         (add-to-list gnus-add-to-list))
966     (gnus-setup-message (cond (yank 'reply-yank)
967                               (article-buffer 'reply)
968                               (t 'message))
969       (let* ((group (or group gnus-newsgroup-name))
970              (charset (gnus-group-name-charset nil group))
971              (pgroup group)
972              to-address to-group mailing-list to-list
973              newsgroup-p)
974         (when group
975           (setq to-address (gnus-parameter-to-address group)
976                 to-group (gnus-group-find-parameter group 'to-group)
977                 to-list (gnus-parameter-to-list group)
978                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
979                 mailing-list (when gnus-mailing-list-groups
980                                (string-match gnus-mailing-list-groups group))
981                 group (gnus-group-name-decode (gnus-group-real-name group)
982                                               charset)))
983         (if (or (and to-group
984                      (gnus-news-group-p to-group))
985                 newsgroup-p
986                 force-news
987                 (and (gnus-news-group-p
988                       (or pgroup gnus-newsgroup-name)
989                       (or header gnus-current-article))
990                      (not mailing-list)
991                      (not to-list)
992                      (not to-address)))
993             ;; This is news.
994             (if post
995                 (message-news
996                  (or to-group
997                      (and (not (gnus-virtual-group-p pgroup)) group)))
998               (set-buffer gnus-article-copy)
999               (gnus-msg-treat-broken-reply-to)
1000               (message-followup (if (or newsgroup-p force-news)
1001                                     (if (save-restriction
1002                                           (article-narrow-to-head)
1003                                           (message-fetch-field "newsgroups"))
1004                                         nil
1005                                       "")
1006                                   to-group)))
1007           ;; The is mail.
1008           (if post
1009               (progn
1010                 (message-mail (or to-address to-list))
1011                 ;; Arrange for mail groups that have no `to-address' to
1012                 ;; get that when the user sends off the mail.
1013                 (when (and (not to-list)
1014                            (not to-address)
1015                            add-to-list)
1016                   (push (list 'gnus-inews-add-to-address pgroup)
1017                         message-send-actions)))
1018             (set-buffer gnus-article-copy)
1019             (gnus-msg-treat-broken-reply-to)
1020             (message-wide-reply to-address)))
1021         (when yank
1022           (gnus-inews-yank-articles yank))))))
1023
1024 (defun gnus-msg-treat-broken-reply-to (&optional force)
1025   "Remove the Reply-to header if broken-reply-to."
1026   (when (or force
1027             (gnus-group-find-parameter
1028              gnus-newsgroup-name 'broken-reply-to))
1029     (save-restriction
1030       (message-narrow-to-head)
1031       (message-remove-header "reply-to"))))
1032
1033 (defun gnus-post-method (arg group &optional silent)
1034   "Return the posting method based on GROUP and ARG.
1035 If SILENT, don't prompt the user."
1036   (let ((gnus-post-method (or (gnus-parameter-post-method group)
1037                               gnus-post-method))
1038         (group-method (gnus-find-method-for-group group)))
1039     (cond
1040      ;; If the group-method is nil (which shouldn't happen) we use
1041      ;; the default method.
1042      ((null group-method)
1043       (or (and (listp gnus-post-method) ;If not current/native/nil
1044                (not (listp (car gnus-post-method))) ; and not a list of methods
1045                gnus-post-method)        ;then use it.
1046           gnus-select-method
1047           message-post-method))
1048      ;; We want the inverse of the default
1049      ((and arg (not (eq arg 0)))
1050       (if (eq gnus-post-method 'current)
1051           gnus-select-method
1052         group-method))
1053      ;; We query the user for a post method.
1054      ((or arg
1055           (and (listp gnus-post-method)
1056                (listp (car gnus-post-method))))
1057       (let* ((methods
1058               ;; Collect all methods we know about.
1059               (append
1060                (when (listp gnus-post-method)
1061                  (if (listp (car gnus-post-method))
1062                      gnus-post-method
1063                    (list gnus-post-method)))
1064                gnus-secondary-select-methods
1065                (mapcar 'cdr gnus-server-alist)
1066                (mapcar 'car gnus-opened-servers)
1067                (list gnus-select-method)
1068                (list group-method)))
1069              method-alist post-methods method)
1070         ;; Weed out all mail methods.
1071         (while methods
1072           (setq method (gnus-server-get-method "" (pop methods)))
1073           (when (and (or (gnus-method-option-p method 'post)
1074                          (gnus-method-option-p method 'post-mail))
1075                      (not (member method post-methods)))
1076             (push method post-methods)))
1077         ;; Create a name-method alist.
1078         (setq method-alist
1079               (mapcar
1080                (lambda (m)
1081                  (if (equal (cadr m) "")
1082                      (list (symbol-name (car m)) m)
1083                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1084                post-methods))
1085         ;; Query the user.
1086         (cadr
1087          (assoc
1088           (setq gnus-last-posting-server
1089                 (if (and silent
1090                          gnus-last-posting-server)
1091                     ;; Just use the last value.
1092                     gnus-last-posting-server
1093                   (completing-read
1094                    "Posting method: " method-alist nil t
1095                    (cons (or gnus-last-posting-server "") 0))))
1096           method-alist))))
1097      ;; Override normal method.
1098      ((and (eq gnus-post-method 'current)
1099            (not (memq (car group-method) gnus-discouraged-post-methods))
1100            (gnus-get-function group-method 'request-post t))
1101       (assert (not arg))
1102       group-method)
1103      ;; Use gnus-post-method.
1104      ((listp gnus-post-method)          ;A method...
1105       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1106       gnus-post-method)
1107      ;; Use the normal select method (nil or native).
1108      (t gnus-select-method))))
1109
1110 \f
1111 ;; Dummies to avoid byte-compile warning.
1112 (eval-when-compile
1113   (defvar xemacs-codename))
1114
1115 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1116                                                  newline-product)
1117   "Return a user-agent info.  If INCLUDE-MIME-INFO is non-nil and the
1118 variable `mime-edit-user-agent-value' is bound, the value will be
1119 included in the return value, and `gnus-user-agent' is ignored.  If
1120 MAX-COLUMN is specified, the return value will be folded up as it were
1121 filled.  NEWLINE-PRODUCT specifies whether a newline should be
1122 inserted in front of each product-token.  If the value is t or `hard',
1123 it works strictly.  Otherwise, if it is non-nil (e.g. `soft'), it
1124 works semi-strictly.
1125
1126 Here is an odd example, which inserts a User-Agent: header when you
1127 begin to compose a message:
1128
1129 \(add-hook 'gnus-message-setup-hook
1130           (lambda nil
1131             (setq message-user-agent nil)
1132             (save-excursion
1133               (save-restriction
1134                 (message-narrow-to-headers)
1135                 (goto-char (point-max))
1136                 (insert \"User-Agent: \"
1137                         (gnus-message-make-user-agent t 76 'soft)
1138                         \"\\n\")))))
1139 "
1140   (let ((gnus-v (gnus-extended-version))
1141         user-agent)
1142     (cond ((and include-mime-info
1143                 (boundp 'mime-edit-user-agent-value))
1144            (setq user-agent (concat gnus-v " " mime-edit-user-agent-value)))
1145           ((eq gnus-user-agent 'gnus-mime-edit)
1146            (setq user-agent
1147                  (if (boundp 'mime-edit-user-agent-value)
1148                      (concat gnus-v " " mime-edit-user-agent-value)
1149                    gnus-v)))
1150           (t
1151            (setq user-agent (if (stringp gnus-user-agent)
1152                                 gnus-user-agent
1153                               (concat gnus-v
1154                                       (let ((emacs-v (gnus-emacs-version)))
1155                                         (when emacs-v
1156                                           (concat " " emacs-v))))))))
1157     (when max-column
1158       (unless (natnump max-column)
1159         (setq max-column 76))
1160       (with-temp-buffer
1161         (set-buffer-multibyte t)
1162         (insert (mapconcat 'identity (split-string user-agent) " "))
1163         (goto-char (point-min))
1164         (let ((bol t)
1165               start agent agents width element swidth)
1166           (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1167             (setq start (match-beginning 0))
1168             (if (eq (char-after start) ?\()
1169                 (progn
1170                   (goto-char start)
1171                   (forward-list)
1172                   (push (buffer-substring start (point)) agent))
1173               (when agent
1174                 (push (nreverse agent) agents))
1175               (setq agent (list (match-string 1)))))
1176           (when agent
1177             (push (nreverse agent) agents))
1178           (setq agents (nreverse agents))
1179           (if (> (+ 12 (string-width (caar agents))) max-column)
1180               (setq user-agent "\n"
1181                     width 0)
1182             (setq user-agent ""
1183                   width 11))
1184           (while agents
1185             (setq agent (car agents)
1186                   agents (cdr agents))
1187             (when (and (not bol)
1188                        (or (memq newline-product '(t hard))
1189                            (and newline-product
1190                                 (> (+ width 1
1191                                       (string-width (mapconcat 'identity
1192                                                                agent " ")))
1193                                    max-column))))
1194               (setq user-agent (concat user-agent "\n")
1195                     width 0
1196                     bol t))
1197             (while agent
1198               (setq element (car agent)
1199                     swidth (string-width element)
1200                     agent (cdr agent))
1201               (if bol
1202                   (setq user-agent (if (member user-agent '("" "\n"))
1203                                        (concat user-agent element)
1204                                      (concat user-agent " " element))
1205                         width (+ width 1 swidth)
1206                         bol nil)
1207                 (if (> (+ width 1 swidth) max-column)
1208                     (setq user-agent (concat user-agent "\n " element)
1209                           width (1+ swidth))
1210                   (setq user-agent (concat user-agent " " element)
1211                         width (+ width 1 swidth)))))))))
1212     user-agent))
1213
1214 \f
1215 ;;;
1216 ;;; Gnus Mail Functions
1217 ;;;
1218
1219 ;;; Mail reply commands of Gnus summary mode
1220
1221 (defun gnus-summary-reply (&optional yank wide very-wide)
1222   "Start composing a mail reply to the current message.
1223 If prefix argument YANK is non-nil, the original article is yanked
1224 automatically.
1225 If WIDE, make a wide reply.
1226 If VERY-WIDE, make a very wide reply."
1227   (interactive
1228    (list (and current-prefix-arg
1229               (gnus-summary-work-articles 1))))
1230   ;; Allow user to require confirmation before replying by mail to the
1231   ;; author of a news article (or mail message).
1232   (when (or
1233             (not (or (gnus-news-group-p gnus-newsgroup-name)
1234                      gnus-confirm-treat-mail-like-news))
1235             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1236                         (string-match gnus-confirm-mail-reply-to-news
1237                                       gnus-newsgroup-name))
1238                        ((functionp gnus-confirm-mail-reply-to-news)
1239                         (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1240                        (t gnus-confirm-mail-reply-to-news)))
1241             (y-or-n-p "Really reply by mail to article author? "))
1242     (let* ((article
1243             (if (listp (car yank))
1244                 (caar yank)
1245               (car yank)))
1246            (gnus-article-reply (or article (gnus-summary-article-number)))
1247            (gnus-article-yanked-articles yank)
1248            (headers ""))
1249       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1250       (when yank
1251         (gnus-summary-goto-subject article))
1252       (gnus-setup-message (if yank 'reply-yank 'reply)
1253         (if (not very-wide)
1254             (gnus-summary-select-article)
1255           (dolist (article very-wide)
1256             (gnus-summary-select-article nil nil nil article)
1257             (save-excursion
1258               (set-buffer (gnus-copy-article-buffer))
1259               (gnus-msg-treat-broken-reply-to)
1260               (save-restriction
1261                 (message-narrow-to-head)
1262                 (setq headers (concat headers (buffer-string)))))))
1263         (set-buffer (gnus-copy-article-buffer))
1264         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1265         (save-restriction
1266           (message-narrow-to-head)
1267           (when very-wide
1268             (erase-buffer)
1269             (insert headers))
1270           (goto-char (point-max)))
1271         (message-reply nil wide)
1272         (when yank
1273           (gnus-inews-yank-articles yank))
1274         (gnus-summary-handle-replysign)))))
1275
1276 (defun gnus-summary-handle-replysign ()
1277   "Check the various replysign variables and take action accordingly."
1278   (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1279     (let (signed encrypted)
1280       (save-excursion
1281         (set-buffer gnus-article-buffer)
1282         (setq signed (memq 'signed gnus-article-wash-types))
1283         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1284       (cond ((and gnus-message-replyencrypt encrypted)
1285              (mml-secure-message mml-default-encrypt-method
1286                                  (if gnus-message-replysignencrypted
1287                                      'signencrypt
1288                                    'encrypt)))
1289             ((and gnus-message-replysign signed)
1290              (mml-secure-message mml-default-sign-method 'sign))))))
1291
1292 (defun gnus-summary-reply-with-original (n &optional wide)
1293   "Start composing a reply mail to the current message.
1294 The original article will be yanked."
1295   (interactive "P")
1296   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1297
1298 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1299   "Like `gnus-summary-reply' except removing reply-to field.
1300 If prefix argument YANK is non-nil, the original article is yanked
1301 automatically.
1302 If WIDE, make a wide reply.
1303 If VERY-WIDE, make a very wide reply."
1304   (interactive
1305    (list (and current-prefix-arg
1306               (gnus-summary-work-articles 1))))
1307   (let ((gnus-msg-force-broken-reply-to t))
1308     (gnus-summary-reply yank wide very-wide)))
1309
1310 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1311   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1312 The original article will be yanked."
1313   (interactive "P")
1314   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1315
1316 (defun gnus-summary-wide-reply (&optional yank)
1317   "Start composing a wide reply mail to the current message.
1318 If prefix argument YANK is non-nil, the original article is yanked
1319 automatically."
1320   (interactive
1321    (list (and current-prefix-arg
1322               (gnus-summary-work-articles 1))))
1323   (gnus-summary-reply yank t))
1324
1325 (defun gnus-summary-wide-reply-with-original (n)
1326   "Start composing a wide reply mail to the current message.
1327 The original article will be yanked.
1328 Uses the process/prefix convention."
1329   (interactive "P")
1330   (gnus-summary-reply-with-original n t))
1331
1332 (defun gnus-summary-very-wide-reply (&optional yank)
1333   "Start composing a very wide reply mail to the current message.
1334 If prefix argument YANK is non-nil, the original article is yanked
1335 automatically."
1336   (interactive
1337    (list (and current-prefix-arg
1338               (gnus-summary-work-articles 1))))
1339   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1340
1341 (defun gnus-summary-very-wide-reply-with-original (n)
1342   "Start composing a very wide reply mail to the current message.
1343 The original article will be yanked."
1344   (interactive "P")
1345   (gnus-summary-reply
1346    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1347
1348 (defun gnus-summary-mail-forward (&optional full-headers post)
1349   "Forward the current message(s) to another user.
1350 If process marks exist, forward all marked messages;
1351 If FULL-HEADERS (the prefix), include full headers when forwarding.
1352
1353 Note that this function definition for T-gnus is totally different
1354 from the original Gnus."
1355   (interactive "P")
1356   (if (cdr (gnus-summary-work-articles nil))
1357       ;; Process marks are given.
1358       (gnus-summary-digest-mail-forward nil post)
1359     ;; No process marks.
1360     (let* ((gnus-article-reply (gnus-summary-article-number))
1361            (gnus-article-yanked-articles (list gnus-article-reply))
1362            charset
1363            (message-included-forward-headers
1364             (if full-headers "" message-included-forward-headers)))
1365       (gnus-setup-message 'forward
1366         (gnus-summary-select-article)
1367         (setq charset default-mime-charset)
1368         (set-buffer gnus-original-article-buffer)
1369         (make-local-variable 'default-mime-charset)
1370         (setq default-mime-charset charset)
1371         (message-forward post)))))
1372
1373 (defun gnus-summary-digest-mail-forward (&optional n post)
1374   "Digests and forwards all articles in this series.
1375 If N is a positive number, forward the N next articles.
1376 If N is a negative number, forward the N previous articles.
1377 If N is nil and any articles have been marked with the process mark,
1378 forward those articles instead.
1379 Optional POST will use news to forward instead of mail."
1380   (interactive "P")
1381   (let* ((articles (gnus-summary-work-articles n))
1382          (gnus-article-yanked-articles (copy-sequence articles))
1383          (topics "Topics:\n")
1384          subject article frame)
1385     (when (car articles)
1386       (gnus-setup-message 'forward
1387         (gnus-summary-select-article)
1388         (if (cdr articles)
1389             (setq articles (sort articles '<)
1390                   subject "Digested Articles")
1391           (with-current-buffer gnus-original-article-buffer
1392             (setq subject (message-make-forward-subject))))
1393         (if post
1394             (message-news nil subject)
1395           (message-mail nil subject))
1396         (when (and message-use-multi-frames (cdr articles))
1397           (setq frame (window-frame (get-buffer-window (current-buffer)))))
1398         (message-goto-body)
1399         (while (setq article (pop articles))
1400           (save-window-excursion
1401             (set-buffer gnus-summary-buffer)
1402             (gnus-summary-select-article nil nil nil article)
1403             (setq topics (concat topics "    "
1404                                  (mail-header-subject gnus-current-headers)
1405                                  "\n"))
1406             (gnus-summary-remove-process-mark article))
1407           (when frame
1408             (select-frame frame))
1409           (insert (mime-make-tag "message" "rfc822") "\n")
1410           (narrow-to-region (point) (point))
1411           (insert-buffer-substring gnus-original-article-buffer)
1412           (save-restriction
1413             (article-narrow-to-head)
1414             (message-remove-header message-included-forward-headers t nil t))
1415           (goto-char (point-max))
1416           (widen))
1417         (push-mark)
1418         (message-goto-body)
1419         (insert topics)
1420         (message-goto-body)
1421         (mime-edit-enclose-digest-region (point)(mark t))))))
1422
1423 (defun gnus-summary-digest-post-forward (&optional n)
1424   "Digest and forwards all articles in this series to a newsgroup.
1425 If N is a positive number, forward the N next articles.
1426 If N is a negative number, forward the N previous articles.
1427 If N is nil and any articles have been marked with the process mark,
1428 forward those articles instead."
1429   (interactive "P")
1430   (gnus-summary-digest-mail-forward n t))
1431
1432 (defun gnus-summary-resend-message (address n)
1433   "Resend the current article to ADDRESS."
1434   (interactive
1435    (list (message-read-from-minibuffer
1436           "Resend message(s) to: "
1437           (when (and gnus-summary-resend-default-address
1438                      (gnus-buffer-live-p gnus-original-article-buffer))
1439             ;; If some other article is currently selected, the
1440             ;; initial-contents is wrong. Whatever, it is just the
1441             ;; initial-contents.
1442             (with-current-buffer gnus-original-article-buffer
1443               (nnmail-fetch-field "to"))))
1444          current-prefix-arg))
1445   (let ((articles (gnus-summary-work-articles n))
1446         article)
1447     (while (setq article (pop articles))
1448       (gnus-summary-select-article nil nil nil article)
1449       (save-excursion
1450         (set-buffer gnus-original-article-buffer)
1451         (message-resend address))
1452       (gnus-summary-mark-article-as-forwarded article))))
1453
1454 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1455 (defun gnus-summary-resend-message-edit ()
1456   "Resend an article that has already been sent.
1457 A new buffer will be created to allow the user to modify body and
1458 contents of the message, and then, everything will happen as when
1459 composing a new message."
1460   (interactive)
1461   (let ((article (gnus-summary-article-number)))
1462     (gnus-setup-message 'reply-yank
1463       (gnus-summary-select-article t)
1464       (set-buffer gnus-original-article-buffer)
1465       (let ((cur (current-buffer))
1466             (to (message-fetch-field "to")))
1467         ;; Get a normal message buffer.
1468         (message-pop-to-buffer (message-buffer-name "Resend" to))
1469         (insert-buffer-substring cur)
1470
1471         ;; T-gnus change: Use MIME-Edit to recompose a message.
1472         ;;(mime-to-mml)
1473         (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1474           (fset 'mime-edit-decode-single-part-in-buffer
1475                 (lambda (&rest args)
1476                   (if (let ((content-type (car args)))
1477                         (and (eq 'message (mime-content-type-primary-type
1478                                            content-type))
1479                              (eq 'rfc822 (mime-content-type-subtype
1480                                           content-type))))
1481                       (setcar (cdr args) 'not-decode-text))
1482                   (apply ofn args)))
1483           (unwind-protect
1484               (mime-edit-again nil t)
1485             (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1486         (message-narrow-to-head-1)
1487         (insert "From: " (message-make-from) "\n")
1488         (while (re-search-forward "^From:" nil t)
1489           (beginning-of-line)
1490           (insert "Original-"))
1491         (message-remove-header "^>From[\t ]" t)
1492
1493         ;; Gnus will generate a new one when sending.
1494         (message-remove-header "Message-ID")
1495         (message-remove-header message-ignored-resent-headers t)
1496         ;; Remove unwanted headers.
1497         (goto-char (point-max))
1498         (insert mail-header-separator)
1499         (goto-char (point-min))
1500         (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1501           (forward-char 1))
1502         (widen)))))
1503
1504 (defun gnus-summary-post-forward (&optional full-headers)
1505   "Forward the current article to a newsgroup.
1506 If FULL-HEADERS (the prefix), include full headers when forwarding."
1507   (interactive "P")
1508   (gnus-summary-mail-forward full-headers t))
1509
1510 (defvar gnus-nastygram-message
1511   "The following article was inappropriately posted to %s.\n\n"
1512   "Format string to insert in nastygrams.
1513 The current group name will be inserted at \"%s\".")
1514
1515 (defun gnus-summary-mail-nastygram (n)
1516   "Send a nastygram to the author of the current article."
1517   (interactive "P")
1518   (when (or gnus-expert-user
1519             (gnus-y-or-n-p
1520              "Really send a nastygram to the author of the current article? "))
1521     (let ((group gnus-newsgroup-name))
1522       (gnus-summary-reply-with-original n)
1523       (set-buffer gnus-message-buffer)
1524       (message-goto-body)
1525       (insert (format gnus-nastygram-message group))
1526       (message-send-and-exit))))
1527
1528 (defun gnus-summary-mail-crosspost-complaint (n)
1529   "Send a complaint about crossposting to the current article(s)."
1530   (interactive "P")
1531   (let ((articles (gnus-summary-work-articles n))
1532         article)
1533     (while (setq article (pop articles))
1534       (set-buffer gnus-summary-buffer)
1535       (gnus-summary-goto-subject article)
1536       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1537             newsgroups followup-to)
1538         (gnus-summary-select-article)
1539         (set-buffer gnus-original-article-buffer)
1540         (if (and (<= (length (message-tokenize-header
1541                               (setq newsgroups
1542                                     (mail-fetch-field "newsgroups"))
1543                               ", "))
1544                      1)
1545                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1546                      (not (member group (message-tokenize-header
1547                                          followup-to ", ")))))
1548             (if followup-to
1549                 (gnus-message 1 "Followup-to restricted")
1550               (gnus-message 1 "Not a crossposted article"))
1551           (set-buffer gnus-summary-buffer)
1552           (gnus-summary-reply-with-original 1)
1553           (set-buffer gnus-message-buffer)
1554           (message-goto-body)
1555           (insert (format gnus-crosspost-complaint newsgroups group))
1556           (message-goto-subject)
1557           (re-search-forward " *$")
1558           (replace-match " (crosspost notification)" t t)
1559           (gnus-deactivate-mark)
1560           (when (gnus-y-or-n-p "Send this complaint? ")
1561             (message-send-and-exit)))))))
1562
1563 (defun gnus-mail-parse-comma-list ()
1564   (let (accumulated
1565         beg)
1566     (skip-chars-forward " ")
1567     (while (not (eobp))
1568       (setq beg (point))
1569       (skip-chars-forward "^,")
1570       (while (zerop
1571               (save-excursion
1572                 (save-restriction
1573                   (let ((i 0))
1574                     (narrow-to-region beg (point))
1575                     (goto-char beg)
1576                     (logand (progn
1577                               (while (search-forward "\"" nil t)
1578                                 (incf i))
1579                               (if (zerop i) 2 i))
1580                             2)))))
1581         (skip-chars-forward ",")
1582         (skip-chars-forward "^,"))
1583       (skip-chars-backward " ")
1584       (push (buffer-substring beg (point))
1585             accumulated)
1586       (skip-chars-forward "^,")
1587       (skip-chars-forward ", "))
1588     accumulated))
1589
1590 (defun gnus-inews-add-to-address (group)
1591   (let ((to-address (mail-fetch-field "to")))
1592     (when (and to-address
1593                (gnus-alive-p))
1594       ;; This mail group doesn't have a `to-list', so we add one
1595       ;; here.  Magic!
1596       (when (gnus-y-or-n-p
1597              (format "Do you want to add this as `to-list': %s? " to-address))
1598         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1599
1600 (defun gnus-put-message ()
1601   "Put the current message in some group and return to Gnus."
1602   (interactive)
1603   (let ((reply gnus-article-reply)
1604         (winconf gnus-prev-winconf)
1605         (group gnus-newsgroup-name))
1606     (unless (and group
1607                  (not (gnus-group-read-only-p group)))
1608       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1609
1610     (when (gnus-group-entry group)
1611       (error "No such group: %s" group))
1612     (save-excursion
1613       (save-restriction
1614         (widen)
1615         (message-narrow-to-headers)
1616         (let ((gnus-deletable-headers nil))
1617           (message-generate-headers
1618            (if (message-news-p)
1619                message-required-news-headers
1620              message-required-mail-headers)))
1621         (goto-char (point-max))
1622         (if (string-match " " group)
1623             (insert "Gcc: \"" group "\"\n")
1624           (insert "Gcc: " group "\n"))
1625         (widen)))
1626     (gnus-inews-do-gcc)
1627     (when (and (get-buffer gnus-group-buffer)
1628                (gnus-buffer-exists-p (car-safe reply))
1629                (cdr reply))
1630       (set-buffer (car reply))
1631       (gnus-summary-mark-article-as-replied (cdr reply)))
1632     (when winconf
1633       (set-window-configuration winconf))))
1634
1635 (defun gnus-article-mail (yank)
1636   "Send a reply to the address near point.
1637 If YANK is non-nil, include the original article."
1638   (interactive "P")
1639   (let ((address
1640          (buffer-substring
1641           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1642           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1643     (when address
1644       (gnus-msg-mail address)
1645       (when yank
1646         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1647
1648 (defvar nntp-server-type)
1649 (defun gnus-bug ()
1650   "Send a bug report to the Gnus maintainers."
1651   (interactive)
1652   (unless (gnus-alive-p)
1653     (error "Gnus has been shut down"))
1654   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1655     (unless (message-mail-user-agent)
1656       (message-pop-to-buffer "*Gnus Bug*")
1657       (delete-other-windows)
1658       (when gnus-bug-create-help-buffer
1659         (switch-to-buffer "*Gnus Help Bug*")
1660         (erase-buffer)
1661         (insert gnus-bug-message)
1662         (goto-char (point-min))
1663         (sit-for 0)
1664         (set-buffer "*Gnus Bug*")))
1665     (let ((message-this-is-mail t))
1666       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1667     (when gnus-bug-create-help-buffer
1668       (push `(gnus-bug-kill-buffer) message-send-actions))
1669     (goto-char (point-min))
1670     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1671     (forward-line 1)
1672     (insert gnus-product-name " " gnus-version-number
1673             " (r" gnus-revision-number ") "
1674             "based on " gnus-original-product-name " v"
1675             gnus-original-version-number "\n"
1676             (emacs-version) "\n")
1677     (when (and (boundp 'nntp-server-type)
1678                (stringp nntp-server-type))
1679       (insert nntp-server-type))
1680     (insert "\n\n\n\n\n")
1681     (let (mime-content-types)
1682       (mime-edit-insert-tag
1683        "application" "emacs-lisp"
1684        "\nContent-Disposition: inline\nContent-Description: User settings"))
1685     (insert (with-temp-buffer
1686               (gnus-debug)
1687               (buffer-string)))
1688     (let (mime-content-types)
1689       (mime-edit-insert-tag "text" "plain"))
1690     (goto-char (point-min))
1691     (search-forward "Subject: " nil t)
1692     (message "")))
1693
1694 (defun gnus-bug-kill-buffer ()
1695   (when (get-buffer "*Gnus Help Bug*")
1696     (kill-buffer "*Gnus Help Bug*")))
1697
1698 (defun gnus-summary-yank-message (buffer n)
1699   "Yank the current article into a composed message."
1700   (interactive
1701    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1702          current-prefix-arg))
1703   (when (gnus-buffer-live-p buffer)
1704     (let ((summary-frame (selected-frame))
1705           (message-frame (when (static-if (featurep 'xemacs)
1706                                    (device-on-window-system-p)
1707                                  window-system)
1708                            (let ((window (get-buffer-window buffer t)))
1709                              (when window
1710                                (window-frame window)))))
1711           (separator (concat "^" (regexp-quote mail-header-separator)
1712                              "\n")))
1713       (gnus-summary-iterate n
1714         (gnus-summary-select-article)
1715         (gnus-copy-article-buffer)
1716         (when (frame-live-p message-frame)
1717           (raise-frame message-frame)
1718           (select-frame message-frame))
1719         (with-current-buffer buffer
1720           (when (save-excursion
1721                   (beginning-of-line)
1722                   (let (case-fold-search)
1723                     (and (not (re-search-backward separator nil t))
1724                          (re-search-forward separator nil t))))
1725             (goto-char (match-end 0)))
1726           (message-yank-buffer gnus-article-copy))
1727         (select-frame summary-frame))
1728       (when (frame-live-p message-frame)
1729         (select-frame message-frame)))))
1730
1731 (defun gnus-debug ()
1732   "Attempts to go through the Gnus source file and report what variables have been changed.
1733 The source file has to be in the Emacs load path."
1734   (interactive)
1735   (let ((files gnus-debug-files)
1736         (point (point))
1737         file expr olist sym)
1738     (gnus-message 4 "Please wait while we snoop your variables...")
1739     ;; Go through all the files looking for non-default values for variables.
1740     (save-excursion
1741       (sit-for 0)
1742       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1743       (while files
1744         (erase-buffer)
1745         (when (and (setq file (locate-library (pop files)))
1746                    (file-exists-p file))
1747           (insert-file-contents file)
1748           (goto-char (point-min))
1749           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1750               (gnus-message 4 "Malformed sources in file %s" file)
1751             (narrow-to-region (point-min) (point))
1752             (goto-char (point-min))
1753             (while (setq expr (ignore-errors (read (current-buffer))))
1754               (ignore-errors
1755                 (and (memq (car expr) '(defvar defcustom defvoo))
1756                      (stringp (nth 3 expr))
1757                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1758                      (or (not (boundp (nth 1 expr)))
1759                          (not (equal (eval (nth 2 expr))
1760                                      (symbol-value (nth 1 expr)))))
1761                      (push (nth 1 expr) olist)))))))
1762       (kill-buffer (current-buffer)))
1763     (when (setq olist (nreverse olist))
1764       (insert ";----------------- Environment follows ------------------\n\n"))
1765     (while olist
1766       (if (boundp (car olist))
1767           (ignore-errors
1768             (pp `(setq ,(car olist)
1769                        ,(if (or (consp (setq sym (symbol-value (car olist))))
1770                                 (and (symbolp sym)
1771                                      (not (or (eq sym nil)
1772                                               (eq sym t)))))
1773                             (list 'quote (symbol-value (car olist)))
1774                           (symbol-value (car olist))))
1775                 (current-buffer)))
1776         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1777       (setq olist (cdr olist)))
1778     ;; Remove any control chars - they seem to cause trouble for some
1779     ;; mailers.  (Byte-compiled output from the stuff above.)
1780     (goto-char point)
1781     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1782       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1783                      t t))
1784     ;; Break MIME tags purposely.
1785     (goto-char point)
1786     (while (re-search-forward mime-edit-tag-regexp nil t)
1787       (goto-char (1+ (match-beginning 0)))
1788       (insert "X"))))
1789
1790 ;;; Treatment of rejected articles.
1791 ;;; Bounced mail.
1792
1793 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1794   "Re-mail the current message.
1795 This only makes sense if the current message is a bounce message that
1796 contains some mail you have written which has been bounced back to
1797 you.
1798 If FETCH, try to fetch the article that this is a reply to, if indeed
1799 this is a reply."
1800   (interactive "P")
1801   (gnus-summary-select-article t)
1802   (set-buffer gnus-original-article-buffer)
1803   (gnus-setup-message 'compose-bounce
1804     (let* ((references (mail-fetch-field "references"))
1805            (parent (and references (gnus-parent-id references))))
1806       (message-bounce)
1807       ;; If there are references, we fetch the article we answered to.
1808       (and fetch parent
1809            (gnus-summary-refer-article parent)
1810            (gnus-summary-show-all-headers)))))
1811
1812 ;;; Gcc handling.
1813
1814 (defun gnus-inews-group-method (group)
1815   (cond
1816    ;; If the group doesn't exist, we assume
1817    ;; it's an archive group...
1818    ((and (null (gnus-get-info group))
1819          (eq (car (gnus-server-to-method gnus-message-archive-method))
1820              (car (gnus-server-to-method (gnus-group-method group)))))
1821     gnus-message-archive-method)
1822    ;; Use the method.
1823    ((gnus-info-method (gnus-get-info group))
1824     (gnus-info-method (gnus-get-info group)))
1825    ;; Find the method.
1826    (t (gnus-server-to-method (gnus-group-method group)))))
1827
1828 ;; Do Gcc handling, which copied the message over to some group.
1829 (defun gnus-inews-do-gcc (&optional gcc)
1830   (interactive)
1831   (save-excursion
1832     (save-restriction
1833       (message-narrow-to-headers)
1834       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1835             (coding-system-for-write 'raw-text)
1836             groups group method group-art
1837             mml-externalize-attachments)
1838         (when gcc
1839           (message-remove-header "gcc")
1840           (widen)
1841           (setq groups (message-unquote-tokens
1842                         (message-tokenize-header gcc " ,")))
1843           ;; Copy the article over to some group(s).
1844           (while (setq group (pop groups))
1845             (unless (gnus-check-server
1846                      (setq method (gnus-inews-group-method group)))
1847               (error "Can't open server %s" (if (stringp method) method
1848                                               (car method))))
1849             (unless (gnus-request-group group nil method)
1850               (gnus-request-create-group group method))
1851             (setq mml-externalize-attachments
1852                   (if (stringp gnus-gcc-externalize-attachments)
1853                       (string-match gnus-gcc-externalize-attachments group)
1854                     gnus-gcc-externalize-attachments))
1855             (save-excursion
1856               (nnheader-set-temp-buffer " *acc*")
1857               (insert-buffer-substring message-encoding-buffer)
1858               (gnus-run-hooks 'gnus-before-do-gcc-hook)
1859               (goto-char (point-min))
1860               (when (re-search-forward
1861                      (concat "^" (regexp-quote mail-header-separator) "$")
1862                      nil t)
1863                 (replace-match "" t t ))
1864               (unless (setq group-art
1865                             (gnus-request-accept-article group method t t))
1866                 (gnus-message 1 "Couldn't store article in group %s: %s"
1867                               group (gnus-status-message method))
1868                 (sit-for 2))
1869               (when (and group-art
1870                          ;; FIXME: Should gcc-mark-as-read work when
1871                          ;; Gnus is not running?
1872                          (gnus-alive-p)
1873                          (or gnus-gcc-mark-as-read
1874                              (and
1875                               (boundp 'gnus-inews-mark-gcc-as-read)
1876                               (symbol-value 'gnus-inews-mark-gcc-as-read))))
1877                 (gnus-group-mark-article-read group (cdr group-art)))
1878               (kill-buffer (current-buffer)))))))))
1879
1880 (defun gnus-inews-insert-gcc ()
1881   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1882   (save-excursion
1883     (save-restriction
1884       (message-narrow-to-headers)
1885       (let* ((group gnus-outgoing-message-group)
1886              (gcc (cond
1887                    ((functionp group)
1888                     (funcall group))
1889                    ((or (stringp group) (list group))
1890                     group))))
1891         (when gcc
1892           (insert "Gcc: "
1893                   (if (stringp gcc)
1894                       (if (string-match " " gcc)
1895                           (concat "\"" gcc "\"")
1896                         gcc)
1897                     (mapconcat (lambda (group)
1898                                  (if (string-match " " group)
1899                                      (concat "\"" group "\"")
1900                                    group))
1901                                gcc " "))
1902                   "\n"))))))
1903
1904 (defun gnus-inews-insert-archive-gcc (&optional group)
1905   "Insert the Gcc to say where the article is to be archived."
1906   (let* ((var gnus-message-archive-group)
1907          (group (or group gnus-newsgroup-name ""))
1908          (gcc-self-val
1909           (and gnus-newsgroup-name
1910                (not (equal gnus-newsgroup-name ""))
1911                (gnus-group-find-parameter
1912                 gnus-newsgroup-name 'gcc-self)))
1913          result
1914          (groups
1915           (cond
1916            ((null gnus-message-archive-method)
1917             ;; Ignore.
1918             nil)
1919            ((stringp var)
1920             ;; Just a single group.
1921             (list var))
1922            ((null var)
1923             ;; We don't want this.
1924             nil)
1925            ((and (listp var) (stringp (car var)))
1926             ;; A list of groups.
1927             var)
1928            ((functionp var)
1929             ;; A function.
1930             (funcall var group))
1931            (t
1932             ;; An alist of regexps/functions/forms.
1933             (while (and var
1934                         (not
1935                          (setq result
1936                                (cond
1937                                 ((stringp (caar var))
1938                                  ;; Regexp.
1939                                  (when (string-match (caar var) group)
1940                                    (cdar var)))
1941                                 ((functionp (car var))
1942                                  ;; Function.
1943                                  (funcall (car var) group))
1944                                 (t
1945                                  (eval (car var)))))))
1946               (setq var (cdr var)))
1947             result)))
1948          name)
1949     (when (or groups gcc-self-val)
1950       (when (stringp groups)
1951         (setq groups (list groups)))
1952       (save-excursion
1953         (save-restriction
1954           (message-narrow-to-headers)
1955           (goto-char (point-max))
1956           (insert "Gcc: ")
1957           (if gcc-self-val
1958               ;; Use the `gcc-self' param value instead.
1959               (progn
1960                 (insert
1961                  (if (stringp gcc-self-val)
1962                      (if (string-match " " gcc-self-val)
1963                          (concat "\"" gcc-self-val "\"")
1964                        gcc-self-val)
1965                    ;; In nndoc groups, we use the parent group name
1966                    ;; instead of the current group.
1967                    (let ((group (or (gnus-group-find-parameter
1968                                      gnus-newsgroup-name 'parent-group)
1969                                     group)))
1970                      (if (string-match " " group)
1971                          (concat "\"" group "\"")
1972                        group))))
1973                 (if (not (eq gcc-self-val 'none))
1974                     (insert "\n")
1975                   (gnus-delete-line)))
1976             ;; Use the list of groups.
1977             (while (setq name (pop groups))
1978               (let ((str (if (string-match ":" name)
1979                              name
1980                            (gnus-group-prefixed-name
1981                             name gnus-message-archive-method))))
1982                 (insert (if (string-match " " str)
1983                             (concat "\"" str "\"")
1984                           str)))
1985               (when groups
1986                 (insert " ")))
1987             (insert "\n")))))))
1988
1989 (defun gnus-mailing-list-followup-to ()
1990   "Look at the headers in the current buffer and return a Mail-Followup-To address."
1991   (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1992         (list-post (gnus-fetch-original-field "list-post")))
1993     (when (and list-post
1994                (string-match "mailto:\\([^>]+\\)" list-post))
1995       (setq list-post (match-string 1 list-post)))
1996     (or list-post
1997         x-been-there)))
1998
1999 ;;; Posting styles.
2000
2001 (defun gnus-configure-posting-styles (&optional group-name)
2002   "Configure posting styles according to `gnus-posting-styles'."
2003   (unless gnus-inhibit-posting-styles
2004     (let ((group (or group-name gnus-newsgroup-name ""))
2005           (styles gnus-posting-styles)
2006           style match attribute results
2007           name address)
2008       ;; If the group has a posting-style parameter, add it at the end with a
2009       ;; regexp matching everything, to be sure it takes precedence over all
2010       ;; the others.
2011       (when gnus-newsgroup-name
2012         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2013           (when tmp-style
2014             (setq styles (append styles (list (cons ".*" tmp-style)))))))
2015       ;; Go through all styles and look for matches.
2016       (dolist (style styles)
2017         (setq match (pop style))
2018         (goto-char (point-min))
2019         (when (cond
2020                ((stringp match)
2021                 ;; Regexp string match on the group name.
2022                 (string-match match group))
2023                ((eq match 'header)
2024                 ;; Obsolete format of header match.
2025                 (and (gnus-buffer-live-p gnus-article-copy)
2026                      (with-current-buffer gnus-article-copy
2027                        (let ((header (message-fetch-field (pop style))))
2028                          (and header
2029                               (string-match (pop style) header))))))
2030                ((or (symbolp match)
2031                     (functionp match))
2032                 (cond
2033                  ((functionp match)
2034                   ;; Function to be called.
2035                   (funcall match))
2036                  ((boundp match)
2037                   ;; Variable to be checked.
2038                   (symbol-value match))))
2039                ((listp match)
2040                 (cond
2041                  ((eq (car match) 'header)
2042                   ;; New format of header match.
2043                   (and (gnus-buffer-live-p gnus-article-copy)
2044                        (with-current-buffer gnus-article-copy
2045                          (let ((header (message-fetch-field (nth 1 match))))
2046                            (and header
2047                                 (string-match (nth 2 match) header))))))
2048                  (t
2049                   ;; This is a form to be evaled.
2050                   (eval match)))))
2051           ;; We have a match, so we set the variables.
2052           (setq style (gnus-configure-posting-style style nil))
2053           (dolist (attribute style)
2054             (setq results (delq (assoc (car attribute) results) results))
2055             (push attribute results))))
2056       ;; Now we have all the styles, so we insert them.
2057       (setq name (assq 'name results)
2058             address (assq 'address results))
2059       (setq results (delq name (delq address results)))
2060       (gnus-make-local-hook 'message-setup-hook)
2061       (setq results (sort results (lambda (x y)
2062                                     (string-lessp (car x) (car y)))))
2063       (dolist (result results)
2064         (add-hook 'message-setup-hook
2065                   (cond
2066                    ((eq 'eval (car result))
2067                     'ignore)
2068                    ((eq 'body (car result))
2069                     `(lambda ()
2070                        (save-excursion
2071                          (message-goto-body)
2072                          (insert ,(cdr result)))))
2073                    ((eq 'signature (car result))
2074                     (set (make-local-variable 'message-signature) nil)
2075                     (set (make-local-variable 'message-signature-file) nil)
2076                     (if (not (cdr result))
2077                         'ignore
2078                       `(lambda ()
2079                          (save-excursion
2080                            (let ((message-signature ,(cdr result)))
2081                              (when message-signature
2082                                (message-insert-signature)))))))
2083                    (t
2084                     (let ((header
2085                            (if (symbolp (car result))
2086                                (capitalize (symbol-name (car result)))
2087                              (car result))))
2088                       `(lambda ()
2089                          (save-excursion
2090                            (message-remove-header ,header)
2091                            (let ((value ,(cdr result)))
2092                              (when value
2093                                (message-goto-eoh)
2094                                (insert ,header ": " value)
2095                                (unless (bolp)
2096                                  (insert "\n")))))))))
2097                   nil 'local))
2098       (when (or name address)
2099         (add-hook 'message-setup-hook
2100                   `(lambda ()
2101                      (set (make-local-variable 'user-mail-address)
2102                           ,(or (cdr address) user-mail-address))
2103                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
2104                            (user-mail-address
2105                             ,(or (cdr address) user-mail-address)))
2106                        (save-excursion
2107                          (message-remove-header "From")
2108                          (message-goto-eoh)
2109                          (insert "From: " (message-make-from) "\n"))))
2110                   nil 'local)))))
2111
2112 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2113 (defun gnus-configure-posting-style (style stack)
2114   "Parse one posting style STYLE and returns the value as an alist."
2115   (let (results element variable filep value v)
2116     (dolist (attribute style)
2117       (setq element (pop attribute)
2118             variable nil
2119             filep nil)
2120       (setq value
2121             (cond
2122              ((eq (car attribute) ':file)
2123               (setq filep t)
2124               (cadr attribute))
2125              ((eq (car attribute) :value)
2126               (cadr attribute))
2127              (t
2128               (car attribute))))
2129       ;; We get the value.
2130       (setq v
2131             (cond
2132              ((stringp value)
2133               value)
2134              ((or (symbolp value)
2135                   (functionp value))
2136               (cond ((functionp value)
2137                      (funcall value))
2138                     ((boundp value)
2139                      (symbol-value value))))
2140              ((listp value)
2141               (eval value))))
2142       ;; Translate obsolescent value.
2143       (cond
2144        ((eq element 'signature-file)
2145         (setq element 'signature
2146               filep t))
2147        ((eq element 'x-face-file)
2148         (setq element 'x-face
2149               filep t)))
2150       ;; Get the contents of file elems.
2151       (when (and filep v)
2152         (setq v (with-temp-buffer
2153                   (insert-file-contents v)
2154                   (goto-char (point-max))
2155                   (while (bolp)
2156                     (delete-char -1))
2157                   (buffer-string))))
2158       (if (eq element 'import)
2159           (progn
2160             (if (member v stack)
2161                 (error "Circular import of \"%s\"" v))
2162             (setq results
2163                   (nconc (nreverse (gnus-configure-posting-style
2164                                     (cdr (assoc v gnus-named-posting-styles))
2165                                     (cons v stack)))
2166                          results)))
2167         (push (cons element v) results)))
2168     (nreverse results)))
2169
2170 (defun gnus-summary-execute-command-with-posting-style (style command)
2171   "Temporarily select a posting-style named STYLE and execute COMMAND."
2172   (interactive
2173    (let ((style (completing-read "Posting style: "
2174                                  gnus-named-posting-styles nil t)))
2175      (list style
2176            (key-binding
2177             (read-key-sequence
2178              (format "Command to execute with %s: " style))))))
2179   (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2180     (call-interactively command)))
2181
2182
2183 ;;; @ for MIME Edit mode
2184 ;;;
2185
2186 (defun gnus-maybe-setup-default-charset ()
2187   (let ((charset
2188          (and (boundp 'gnus-summary-buffer)
2189               (buffer-live-p gnus-summary-buffer)
2190               (save-excursion
2191                 (set-buffer gnus-summary-buffer)
2192                 default-mime-charset))))
2193     (if charset
2194         (progn
2195           (make-local-variable 'default-mime-charset)
2196           (setq default-mime-charset charset)
2197           ))))
2198
2199
2200 ;;; @ for MIME view mode
2201 ;;;
2202
2203 (defun gnus-following-method (buf)
2204   (gnus-setup-message 'reply-yank
2205     (set-buffer buf)
2206     (if (message-news-p)
2207         (message-followup)
2208       (message-reply nil 'wide))
2209     (let ((message-reply-buffer buf))
2210       (message-yank-original))
2211     (message-goto-body))
2212   (kill-buffer buf))
2213
2214
2215 ;;; Allow redefinition of functions.
2216
2217 (gnus-ems-redefine)
2218
2219 (provide 'gnus-msg)
2220
2221 ;;; gnus-msg.el ends here