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