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