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