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