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