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