T-gnus 6.15.10 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
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)))
623
624 (defun gnus-summary-mail-other-window (&optional arg)
625   "Start composing a mail in another window.
626 Use the posting of the current group by default.
627 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
628 posting style."
629   (interactive "P")
630   ;; We can't `let' gnus-newsgroup-name here, since that leads
631   ;; to local variables leaking.
632   (let ((group gnus-newsgroup-name)
633         ;; make sure last viewed article doesn't affect posting styles:
634         (gnus-article-copy)
635         (buffer (current-buffer)))
636     (unwind-protect
637         (progn
638           (setq gnus-newsgroup-name
639                 (if arg
640                     (if (= 1 (prefix-numeric-value arg))
641                         (completing-read "Use group: "
642                                          gnus-active-hashtb nil
643                                          (gnus-read-active-file-p))
644                       "")
645                   gnus-newsgroup-name))
646           ;; #### see comment in gnus-setup-message -- drv
647           (gnus-setup-message 'message (message-mail)))
648       (save-excursion
649         (set-buffer buffer)
650         (setq gnus-newsgroup-name group)))))
651
652 (defun gnus-summary-news-other-window (&optional arg)
653   "Start composing a news in another window.
654 Post to the current group by default.
655 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
656
657 This function prepares a news even when using mail groups.  This is useful
658 for posting messages to mail groups without actually sending them over the
659 network.  The corresponding backend must have a 'request-post method."
660   (interactive "P")
661   ;; We can't `let' gnus-newsgroup-name here, since that leads
662   ;; to local variables leaking.
663   (let ((group gnus-newsgroup-name)
664         ;; make sure last viewed article doesn't affect posting styles:
665         (gnus-article-copy)
666         (buffer (current-buffer)))
667     (unwind-protect
668         (progn
669           (setq gnus-newsgroup-name
670                 (if arg
671                     (if (= 1 (prefix-numeric-value arg))
672                         (completing-read "Use group: "
673                                          gnus-active-hashtb nil
674                                          (gnus-read-active-file-p))
675                       "")
676                   gnus-newsgroup-name))
677           ;; #### see comment in gnus-setup-message -- drv
678           (gnus-setup-message 'message
679             (message-news (gnus-group-real-name gnus-newsgroup-name))))
680       (save-excursion
681         (set-buffer buffer)
682         (setq gnus-newsgroup-name group)))))
683
684 (defun gnus-summary-post-news (&optional arg)
685   "Start composing a message.  Post to the current group by default.
686 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
687 Depending on the selected group, the message might be either a mail or
688 a news."
689   (interactive "P")
690   ;; Bind this variable here to make message mode hooks work ok.
691   (let ((gnus-newsgroup-name
692          (if arg
693              (if (= 1 (prefix-numeric-value arg))
694                  (completing-read "Newsgroup: " gnus-active-hashtb nil
695                                   (gnus-read-active-file-p))
696                "")
697            gnus-newsgroup-name))
698         ;; make sure last viewed article doesn't affect posting styles:
699         (gnus-article-copy))
700     (gnus-post-news 'post gnus-newsgroup-name)))
701
702
703 (defun gnus-summary-followup (yank &optional force-news)
704   "Compose a followup to an article.
705 If prefix argument YANK is non-nil, the original article is yanked
706 automatically.
707 YANK is a list of elements, where the car of each element is the
708 article number, and the two following numbers is the region to be
709 yanked."
710   (interactive
711    (list (and current-prefix-arg
712               (gnus-summary-work-articles 1))))
713   (when yank
714     (gnus-summary-goto-subject
715      (if (listp (car yank))
716          (caar yank)
717        (car yank))))
718   (save-window-excursion
719     (gnus-summary-select-article))
720   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
721         (gnus-newsgroup-name gnus-newsgroup-name))
722     ;; Send a followup.
723     (gnus-post-news nil gnus-newsgroup-name
724                     headers gnus-article-buffer
725                     yank nil force-news)
726     (gnus-summary-handle-replysign)))
727
728 (defun gnus-summary-followup-with-original (n &optional force-news)
729   "Compose a followup to an article and include the original article."
730   (interactive "P")
731   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
732
733 (defun gnus-summary-followup-to-mail (&optional arg)
734   "Followup to the current mail message via news."
735   (interactive
736    (list (and current-prefix-arg
737               (gnus-summary-work-articles 1))))
738   (gnus-summary-followup arg t))
739
740 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
741   "Followup to the current mail message via news."
742   (interactive "P")
743   (gnus-summary-followup (gnus-summary-work-articles arg) t))
744
745 (defun gnus-inews-yank-articles (articles)
746   (let (beg article yank-string
747             (more-than-one (cdr articles))
748             (cur (current-buffer))
749             refs window)
750     (message-goto-body)
751     (while (setq article (pop articles))
752       (when (listp article)
753         (setq yank-string (nth 1 article)
754               article (nth 0 article)))
755       (save-window-excursion
756         (set-buffer gnus-summary-buffer)
757         (gnus-summary-select-article nil nil nil article)
758         (gnus-summary-remove-process-mark article))
759
760       ;; Gathering references.
761       (when more-than-one
762         (setq refs (message-list-references
763                     refs
764                     (mail-header-references gnus-current-headers)
765                     (mail-header-message-id gnus-current-headers)))
766         (when message-use-multi-frames
767           (when (setq window (get-buffer-window cur t))
768             (select-frame (window-frame window)))))
769
770       (gnus-copy-article-buffer nil yank-string)
771       (let ((message-reply-buffer gnus-article-copy)
772             (message-reply-headers
773              ;; The headers are decoded.
774              (with-current-buffer gnus-article-copy
775                (save-restriction
776                  (nnheader-narrow-to-headers)
777                  (nnheader-parse-naked-head)))))
778         (message-yank-original)
779         (setq beg (or beg (mark t))))
780       (when articles
781         (insert "\n")))
782     (push-mark)
783
784     ;; Replace with the gathered references.
785     (when refs
786       (push-mark beg)
787       (save-restriction
788         (message-narrow-to-headers)
789         (let ((case-fold-search t))
790           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
791               (replace-match "")
792             (goto-char (point-max))))
793         (mail-header-format
794          (list (or (assq 'References message-header-format-alist)
795                    '(References . message-shorten-references)))
796          (list (cons 'References
797                      (mapconcat 'identity (nreverse refs) " "))))
798         (backward-delete-char 1))
799       (setq beg (mark t))
800       (pop-mark))
801
802     (goto-char beg)))
803
804 (defun gnus-summary-cancel-article (&optional n symp)
805   "Cancel an article you posted.
806 Uses the process-prefix convention.  If given the symbolic
807 prefix `a', cancel using the standard posting method; if not
808 post using the current select method."
809   (interactive (gnus-interactive "P\ny"))
810   (let ((articles (gnus-summary-work-articles n))
811         (message-post-method
812          `(lambda (arg)
813             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
814         article)
815     (while (setq article (pop articles))
816       (when (gnus-summary-select-article t nil nil article)
817         (when (gnus-eval-in-buffer-window gnus-article-buffer
818                 (save-excursion
819                   (set-buffer gnus-original-article-buffer)
820                   (message-cancel-news)))
821           (gnus-summary-mark-as-read article gnus-canceled-mark)
822           (gnus-cache-remove-article 1))
823         (gnus-article-hide-headers-if-wanted))
824       (gnus-summary-remove-process-mark article))))
825
826 (defun gnus-summary-supersede-article ()
827   "Compose an article that will supersede a previous article.
828 This is done simply by taking the old article and adding a Supersedes
829 header line with the old Message-ID."
830   (interactive)
831   (let ((article (gnus-summary-article-number)))
832     (gnus-setup-message 'reply-yank
833       (gnus-summary-select-article t)
834       (set-buffer gnus-original-article-buffer)
835       (message-supersede)
836       (push
837        `((lambda ()
838            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
839              (save-excursion
840                (set-buffer ,gnus-summary-buffer)
841                (gnus-cache-possibly-remove-article ,article nil nil nil t)
842                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
843        message-send-actions))))
844
845 \f
846
847 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
848   ;; make a copy of the article buffer with all text properties removed
849   ;; this copy is in the buffer gnus-article-copy.
850   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
851   ;; this buffer should be passed to all mail/news reply/post routines.
852   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
853   (save-excursion
854     (set-buffer gnus-article-copy)
855     (set-buffer-multibyte t))
856   (let ((article-buffer (or article-buffer gnus-article-buffer))
857         end beg)
858     (if (not (and (get-buffer article-buffer)
859                   (gnus-buffer-exists-p article-buffer)))
860         (error "Can't find any article buffer")
861       (save-excursion
862         (set-buffer article-buffer)
863         (let ((gnus-newsgroup-charset (or gnus-article-charset
864                                           gnus-newsgroup-charset))
865               (gnus-newsgroup-ignored-charsets
866                (or gnus-article-ignored-charsets
867                    gnus-newsgroup-ignored-charsets)))
868           (save-restriction
869             ;; Copy over the (displayed) article buffer, delete
870             ;; hidden text and remove text properties.
871             (widen)
872             (copy-to-buffer gnus-article-copy (point-min) (point-max))
873             (set-buffer gnus-article-copy)
874             ;; There's invisible and intangible text in T-gnus.  Especially,
875             ;; if there is a boundary line (X-Boundary: ------------------),
876             ;; in the end of a header, it will cause a serious problem.
877             (add-text-properties (point-min) (point-max)
878                                  '(invisible nil intangible nil))
879             (when yank-string
880               (message-goto-body)
881               (delete-region (point) (point-max))
882               (insert yank-string))
883             ;; Encode bitmap smileys to ordinary text.
884             ;; Possibly, the original text might be restored.
885             (static-unless (featurep 'xemacs)
886               (when (featurep 'smiley-mule)
887                 (smiley-encode-buffer)))
888             (gnus-article-delete-text-of-type 'annotation)
889             (gnus-remove-text-with-property 'gnus-prev)
890             (gnus-remove-text-with-property 'gnus-next)
891             (gnus-remove-text-with-property 'gnus-decoration)
892             (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
893             (insert
894              (prog1
895                  (static-if (featurep 'xemacs)
896                      ;; Revome smiley extents for (possibly) XEmacs 21.1.
897                      (format "%s"
898                              (buffer-substring-no-properties (point-min)
899                                                              (point-max)))
900                    (buffer-substring-no-properties (point-min) (point-max)))
901                (erase-buffer)))
902             ;; Find the original headers.
903             (set-buffer gnus-original-article-buffer)
904             (goto-char (point-min))
905             (while (looking-at message-unix-mail-delimiter)
906               (forward-line 1))
907             (let ((mail-header-separator ""))
908               (setq beg (point)
909                     end (or (message-goto-body) beg)))
910             ;; Delete the headers from the displayed articles.
911             (set-buffer gnus-article-copy)
912             (let ((mail-header-separator ""))
913               (delete-region (goto-char (point-min))
914                              (or (message-goto-body) (point-max))))
915             ;; Insert the original article headers.
916             (insert-buffer-substring gnus-original-article-buffer beg end)
917             ;; Decode charsets.
918             (let ((gnus-article-decode-hook
919                    (delq 'article-decode-charset
920                          (copy-sequence gnus-article-decode-hook))))
921               ;; Needed for T-gnus.
922               (add-hook 'gnus-article-decode-hook
923                         'article-decode-encoded-words)
924               (run-hooks 'gnus-article-decode-hook)))))
925       gnus-article-copy)))
926
927 (defun gnus-post-news (post &optional group header article-buffer yank subject
928                             force-news)
929   (when article-buffer
930     (gnus-copy-article-buffer))
931   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
932         (gnus-article-yanked-articles yank)
933         (add-to-list gnus-add-to-list))
934     (gnus-setup-message (cond (yank 'reply-yank)
935                               (article-buffer 'reply)
936                               (t 'message))
937       (let* ((group (or group gnus-newsgroup-name))
938              (charset (gnus-group-name-charset nil group))
939              (pgroup group)
940              to-address to-group mailing-list to-list
941              newsgroup-p)
942         (when group
943           (setq to-address (gnus-parameter-to-address group)
944                 to-group (gnus-group-find-parameter group 'to-group)
945                 to-list (gnus-parameter-to-list group)
946                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
947                 mailing-list (when gnus-mailing-list-groups
948                                (string-match gnus-mailing-list-groups group))
949                 group (gnus-group-name-decode (gnus-group-real-name group)
950                                               charset)))
951         (if (or (and to-group
952                      (gnus-news-group-p to-group))
953                 newsgroup-p
954                 force-news
955                 (and (gnus-news-group-p
956                       (or pgroup gnus-newsgroup-name)
957                       (or header gnus-current-article))
958                      (not mailing-list)
959                      (not to-list)
960                      (not to-address)))
961             ;; This is news.
962             (if post
963                 (message-news (or to-group group))
964               (set-buffer gnus-article-copy)
965               (gnus-msg-treat-broken-reply-to)
966               (message-followup (if (or newsgroup-p force-news)
967                                     (if (save-restriction
968                                           (article-narrow-to-head)
969                                           (message-fetch-field "newsgroups"))
970                                         nil
971                                       "")
972                                   to-group)))
973           ;; The is mail.
974           (if post
975               (progn
976                 (message-mail (or to-address to-list))
977                 ;; Arrange for mail groups that have no `to-address' to
978                 ;; get that when the user sends off the mail.
979                 (when (and (not to-list)
980                            (not to-address)
981                            add-to-list)
982                   (push (list 'gnus-inews-add-to-address pgroup)
983                         message-send-actions)))
984             (set-buffer gnus-article-copy)
985             (gnus-msg-treat-broken-reply-to)
986             (message-wide-reply to-address)))
987         (when yank
988           (gnus-inews-yank-articles yank))))))
989
990 (defun gnus-msg-treat-broken-reply-to (&optional force)
991   "Remove the Reply-to header if broken-reply-to."
992   (when (or force
993             (gnus-group-find-parameter
994              gnus-newsgroup-name 'broken-reply-to))
995     (save-restriction
996       (message-narrow-to-head)
997       (message-remove-header "reply-to"))))
998
999 (defun gnus-post-method (arg group &optional silent)
1000   "Return the posting method based on GROUP and ARG.
1001 If SILENT, don't prompt the user."
1002   (let ((gnus-post-method (or (gnus-parameter-post-method group)
1003                               gnus-post-method))
1004         (group-method (gnus-find-method-for-group group)))
1005     (cond
1006      ;; If the group-method is nil (which shouldn't happen) we use
1007      ;; the default method.
1008      ((null group-method)
1009       (or (and (listp gnus-post-method) ;If not current/native/nil
1010                (not (listp (car gnus-post-method))) ; and not a list of methods
1011                gnus-post-method)        ;then use it.
1012           gnus-select-method
1013           message-post-method))
1014      ;; We want the inverse of the default
1015      ((and arg (not (eq arg 0)))
1016       (if (eq gnus-post-method 'current)
1017           gnus-select-method
1018         group-method))
1019      ;; We query the user for a post method.
1020      ((or arg
1021           (and (listp gnus-post-method)
1022                (listp (car gnus-post-method))))
1023       (let* ((methods
1024               ;; Collect all methods we know about.
1025               (append
1026                (when (listp gnus-post-method)
1027                  (if (listp (car gnus-post-method))
1028                      gnus-post-method
1029                    (list gnus-post-method)))
1030                gnus-secondary-select-methods
1031                (mapcar 'cdr gnus-server-alist)
1032                (mapcar 'car gnus-opened-servers)
1033                (list gnus-select-method)
1034                (list group-method)))
1035              method-alist post-methods method)
1036         ;; Weed out all mail methods.
1037         (while methods
1038           (setq method (gnus-server-get-method "" (pop methods)))
1039           (when (and (or (gnus-method-option-p method 'post)
1040                          (gnus-method-option-p method 'post-mail))
1041                      (not (member method post-methods)))
1042             (push method post-methods)))
1043         ;; Create a name-method alist.
1044         (setq method-alist
1045               (mapcar
1046                (lambda (m)
1047                  (if (equal (cadr m) "")
1048                      (list (symbol-name (car m)) m)
1049                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1050                post-methods))
1051         ;; Query the user.
1052         (cadr
1053          (assoc
1054           (setq gnus-last-posting-server
1055                 (if (and silent
1056                          gnus-last-posting-server)
1057                     ;; Just use the last value.
1058                     gnus-last-posting-server
1059                   (completing-read
1060                    "Posting method: " method-alist nil t
1061                    (cons (or gnus-last-posting-server "") 0))))
1062           method-alist))))
1063      ;; Override normal method.
1064      ((and (eq gnus-post-method 'current)
1065            (not (memq (car group-method) gnus-discouraged-post-methods))
1066            (gnus-get-function group-method 'request-post t))
1067       (assert (not arg))
1068       group-method)
1069      ;; Use gnus-post-method.
1070      ((listp gnus-post-method)          ;A method...
1071       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1072       gnus-post-method)
1073      ;; Use the normal select method (nil or native).
1074      (t gnus-select-method))))
1075
1076 \f
1077 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1078                                                  newline-product)
1079   "Return a user-agent info.  If INCLUDE-MIME-INFO is non-nil and the
1080 variable `mime-edit-user-agent-value' is bound, the value will be
1081 included in the return value.  If MAX-COLUMN is specified, the return
1082 value will be folded up as it were filled.  NEWLINE-PRODUCT specifies
1083 whether a newline should be inserted in front of each product-token.
1084 If the value is t or `hard', it works strictly.  Otherwise, if it is
1085 non-nil (e.g. `soft'), it works semi-strictly.
1086
1087 Here is an example of how to use this function:
1088
1089 \(add-hook 'gnus-message-setup-hook
1090           (lambda nil
1091             (setq message-user-agent nil)
1092             (save-excursion
1093               (save-restriction
1094                 (message-narrow-to-headers)
1095                 (goto-char (point-max))
1096                 (insert \"User-Agent: \"
1097                         (gnus-message-make-user-agent t 76 'soft)
1098                         \"\\n\")))))
1099 "
1100   (let ((user-agent (if (and include-mime-info
1101                              (boundp 'mime-edit-user-agent-value))
1102                         (concat (gnus-extended-version)
1103                                 " "
1104                                 mime-edit-user-agent-value)
1105                       (gnus-extended-version))))
1106     (when max-column
1107       (unless (natnump max-column)
1108         (setq max-column 76))
1109       (with-temp-buffer
1110         (set-buffer-multibyte t)
1111         (insert (mapconcat 'identity (split-string user-agent) " "))
1112         (goto-char (point-min))
1113         (let ((bol t)
1114               start agent agents width element swidth)
1115           (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1116             (setq start (match-beginning 0))
1117             (if (eq (char-after start) ?\()
1118                 (progn
1119                   (goto-char start)
1120                   (forward-list)
1121                   (push (buffer-substring start (point)) agent))
1122               (when agent
1123                 (push (nreverse agent) agents))
1124               (setq agent (list (match-string 1)))))
1125           (when agent
1126             (push (nreverse agent) agents))
1127           (setq agents (nreverse agents))
1128           (if (> (+ 12 (string-width (caar agents))) max-column)
1129               (setq user-agent "\n"
1130                     width 0)
1131             (setq user-agent ""
1132                   width 11))
1133           (while agents
1134             (setq agent (car agents)
1135                   agents (cdr agents))
1136             (when (and (not bol)
1137                        (or (memq newline-product '(t hard))
1138                            (and newline-product
1139                                 (> (+ width 1
1140                                       (string-width (mapconcat 'identity
1141                                                                agent " ")))
1142                                    max-column))))
1143               (setq user-agent (concat user-agent "\n")
1144                     width 0
1145                     bol t))
1146             (while agent
1147               (setq element (car agent)
1148                     swidth (string-width element)
1149                     agent (cdr agent))
1150               (if bol
1151                   (setq user-agent (if (member user-agent '("" "\n"))
1152                                        (concat user-agent element)
1153                                      (concat user-agent " " element))
1154                         width (+ width 1 swidth)
1155                         bol nil)
1156                 (if (> (+ width 1 swidth) max-column)
1157                     (setq user-agent (concat user-agent "\n " element)
1158                           width (1+ swidth))
1159                   (setq user-agent (concat user-agent " " element)
1160                         width (+ width 1 swidth)))))))))
1161     user-agent))
1162
1163 \f
1164 ;;;
1165 ;;; Gnus Mail Functions
1166 ;;;
1167
1168 ;;; Mail reply commands of Gnus summary mode
1169
1170 (defun gnus-summary-reply (&optional yank wide very-wide)
1171   "Start composing a mail reply to the current message.
1172 If prefix argument YANK is non-nil, the original article is yanked
1173 automatically.
1174 If WIDE, make a wide reply.
1175 If VERY-WIDE, make a very wide reply."
1176   (interactive
1177    (list (and current-prefix-arg
1178               (gnus-summary-work-articles 1))))
1179   ;; Allow user to require confirmation before replying by mail to the
1180   ;; author of a news article.
1181   (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1182             (not gnus-confirm-mail-reply-to-news)
1183             (y-or-n-p "Really reply by mail to article author? "))
1184     (let* ((article
1185             (if (listp (car yank))
1186                 (caar yank)
1187               (car yank)))
1188            (gnus-article-reply (or article (gnus-summary-article-number)))
1189            (gnus-article-yanked-articles yank)
1190            (headers ""))
1191       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1192       (when yank
1193         (gnus-summary-goto-subject article))
1194       (gnus-setup-message (if yank 'reply-yank 'reply)
1195         (if (not very-wide)
1196             (gnus-summary-select-article)
1197           (dolist (article very-wide)
1198             (gnus-summary-select-article nil nil nil article)
1199             (save-excursion
1200               (set-buffer (gnus-copy-article-buffer))
1201               (gnus-msg-treat-broken-reply-to)
1202               (save-restriction
1203                 (message-narrow-to-head)
1204                 (setq headers (concat headers (buffer-string)))))))
1205         (set-buffer (gnus-copy-article-buffer))
1206         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1207         (save-restriction
1208           (message-narrow-to-head)
1209           (when very-wide
1210             (erase-buffer)
1211             (insert headers))
1212           (goto-char (point-max)))
1213         (message-reply nil wide)
1214         (when yank
1215           (gnus-inews-yank-articles yank))
1216         (gnus-summary-handle-replysign)))))
1217
1218 (defun gnus-summary-handle-replysign ()
1219   "Check the various replysign variables and take action accordingly."
1220   (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1221     (let (signed encrypted)
1222       (save-excursion
1223         (set-buffer gnus-article-buffer)
1224         (setq signed (memq 'signed gnus-article-wash-types))
1225         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1226       (cond ((and gnus-message-replyencrypt encrypted)
1227              (mml-secure-message mml-default-encrypt-method
1228                                  (if gnus-message-replysignencrypted
1229                                      'signencrypt
1230                                    'encrypt)))
1231             ((and gnus-message-replysign signed)
1232              (mml-secure-message mml-default-sign-method 'sign))))))
1233
1234 (defun gnus-summary-reply-with-original (n &optional wide)
1235   "Start composing a reply mail to the current message.
1236 The original article will be yanked."
1237   (interactive "P")
1238   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1239
1240 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1241   "Like `gnus-summary-reply' except removing reply-to field.
1242 If prefix argument YANK is non-nil, the original article is yanked
1243 automatically.
1244 If WIDE, make a wide reply.
1245 If VERY-WIDE, make a very wide reply."
1246   (interactive
1247    (list (and current-prefix-arg
1248               (gnus-summary-work-articles 1))))
1249   (let ((gnus-msg-force-broken-reply-to t))
1250     (gnus-summary-reply yank wide very-wide)))
1251
1252 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1253   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1254 The original article will be yanked."
1255   (interactive "P")
1256   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1257
1258 (defun gnus-summary-wide-reply (&optional yank)
1259   "Start composing a wide reply mail to the current message.
1260 If prefix argument YANK is non-nil, the original article is yanked
1261 automatically."
1262   (interactive
1263    (list (and current-prefix-arg
1264               (gnus-summary-work-articles 1))))
1265   (gnus-summary-reply yank t))
1266
1267 (defun gnus-summary-wide-reply-with-original (n)
1268   "Start composing a wide reply mail to the current message.
1269 The original article will be yanked."
1270   (interactive "P")
1271   (gnus-summary-reply-with-original n t))
1272
1273 (defun gnus-summary-very-wide-reply (&optional yank)
1274   "Start composing a very wide reply mail to the current message.
1275 If prefix argument YANK is non-nil, the original article is yanked
1276 automatically."
1277   (interactive
1278    (list (and current-prefix-arg
1279               (gnus-summary-work-articles 1))))
1280   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1281
1282 (defun gnus-summary-very-wide-reply-with-original (n)
1283   "Start composing a very wide reply mail to the current message.
1284 The original article will be yanked."
1285   (interactive "P")
1286   (gnus-summary-reply
1287    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1288
1289 (defun gnus-summary-mail-forward (&optional full-headers post)
1290   "Forward the current message(s) to another user.
1291 If process marks exist, forward all marked messages;
1292 If FULL-HEADERS (the prefix), include full headers when forwarding.
1293
1294 Note that this function definition for T-gnus is totally different
1295 from the original Gnus."
1296   (interactive "P")
1297   (if (cdr (gnus-summary-work-articles nil))
1298       ;; Process marks are given.
1299       (gnus-summary-digest-mail-forward nil post)
1300     ;; No process marks.
1301     (let* ((gnus-article-reply (gnus-summary-article-number))
1302            (gnus-article-yanked-articles (list (list gnus-article-reply)))
1303            charset
1304            (message-included-forward-headers
1305             (if full-headers "" message-included-forward-headers)))
1306       (gnus-setup-message 'forward
1307         (gnus-summary-select-article)
1308         (setq charset default-mime-charset)
1309         (set-buffer gnus-original-article-buffer)
1310         (make-local-variable 'default-mime-charset)
1311         (setq default-mime-charset charset)
1312         (message-forward post)))))
1313
1314 (defun gnus-summary-digest-mail-forward (&optional n post)
1315   "Digests and forwards all articles in this series.
1316 If N is a positive number, forward the N next articles.
1317 If N is a negative number, forward the N previous articles.
1318 If N is nil and any articles have been marked with the process mark,
1319 forward those articles instead.
1320 Optional POST will use news to forward instead of mail."
1321   (interactive "P")
1322   (let ((articles (gnus-summary-work-articles n))
1323         (topics "Topics:\n")
1324         subject article frame)
1325     (when (car articles)
1326       (gnus-setup-message 'forward
1327         (gnus-summary-select-article)
1328         (if (cdr articles)
1329             (setq articles (sort articles '<)
1330                   subject "Digested Articles")
1331           (with-current-buffer gnus-original-article-buffer
1332             (setq subject (message-make-forward-subject))))
1333         (if post
1334             (message-news nil subject)
1335           (message-mail nil subject))
1336         (when (and message-use-multi-frames (cdr articles))
1337           (setq frame (window-frame (get-buffer-window (current-buffer)))))
1338         (message-goto-body)
1339         (while (setq article (pop articles))
1340           (save-window-excursion
1341             (set-buffer gnus-summary-buffer)
1342             (gnus-summary-select-article nil nil nil article)
1343             (setq topics (concat topics "    "
1344                                  (mail-header-subject gnus-current-headers)
1345                                  "\n"))
1346             (gnus-summary-remove-process-mark article))
1347           (when frame
1348             (select-frame frame))
1349           (insert (mime-make-tag "message" "rfc822") "\n")
1350           (narrow-to-region (point) (point))
1351           (insert-buffer-substring gnus-original-article-buffer)
1352           (save-restriction
1353             (article-narrow-to-head)
1354             (message-remove-header message-included-forward-headers t nil t))
1355           (goto-char (point-max))
1356           (widen))
1357         (push-mark)
1358         (message-goto-body)
1359         (insert topics)
1360         (message-goto-body)
1361         (mime-edit-enclose-digest-region (point)(mark t))))))
1362
1363 (defun gnus-summary-digest-post-forward (&optional n)
1364   "Digest and forwards all articles in this series to a newsgroup.
1365 If N is a positive number, forward the N next articles.
1366 If N is a negative number, forward the N previous articles.
1367 If N is nil and any articles have been marked with the process mark,
1368 forward those articles instead."
1369   (interactive "P")
1370   (gnus-summary-digest-mail-forward n t))
1371
1372 (defun gnus-summary-resend-message (address n)
1373   "Resend the current article to ADDRESS."
1374   (interactive
1375    (list (message-read-from-minibuffer
1376           "Resend message(s) to: "
1377           (when (and gnus-summary-resend-default-address
1378                      (gnus-buffer-live-p gnus-original-article-buffer))
1379             ;; If some other article is currently selected, the
1380             ;; initial-contents is wrong. Whatever, it is just the
1381             ;; initial-contents.
1382             (with-current-buffer gnus-original-article-buffer
1383               (nnmail-fetch-field "to"))))
1384          current-prefix-arg))
1385   (let ((articles (gnus-summary-work-articles n))
1386         article)
1387     (while (setq article (pop articles))
1388       (gnus-summary-select-article nil nil nil article)
1389       (save-excursion
1390         (set-buffer gnus-original-article-buffer)
1391         (message-resend address))
1392       (gnus-summary-mark-article-as-forwarded article))))
1393
1394 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1395 (defun gnus-summary-resend-message-edit ()
1396   "Resend an article that has already been sent.
1397 A new buffer will be created to allow the user to modify body and
1398 contents of the message, and then, everything will happen as when
1399 composing a new message."
1400   (interactive)
1401   (let ((article (gnus-summary-article-number)))
1402     (gnus-setup-message 'reply-yank
1403       (gnus-summary-select-article t)
1404       (set-buffer gnus-original-article-buffer)
1405       (let ((cur (current-buffer))
1406             (to (message-fetch-field "to")))
1407         ;; Get a normal message buffer.
1408         (message-pop-to-buffer (message-buffer-name "Resend" to))
1409         (insert-buffer-substring cur)
1410
1411         ;; T-gnus change: Use MIME-Edit to recompose a message.
1412         ;;(mime-to-mml)
1413         (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1414           (fset 'mime-edit-decode-single-part-in-buffer
1415                 (lambda (&rest args)
1416                   (if (let ((content-type (car args)))
1417                         (and (eq 'message (mime-content-type-primary-type
1418                                            content-type))
1419                              (eq 'rfc822 (mime-content-type-subtype
1420                                           content-type))))
1421                       (setcar (cdr args) 'not-decode-text))
1422                   (apply ofn args)))
1423           (unwind-protect
1424               (mime-edit-again nil t)
1425             (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1426         (message-narrow-to-head-1)
1427         (insert "From: " (message-make-from) "\n")
1428         (while (re-search-forward "^From:" nil t)
1429           (beginning-of-line)
1430           (insert "Original-"))
1431         (message-remove-header "^>From[\t ]" t)
1432
1433         ;; Gnus will generate a new one when sending.
1434         (message-remove-header "Message-ID")
1435         (message-remove-header message-ignored-resent-headers t)
1436         ;; Remove unwanted headers.
1437         (goto-char (point-max))
1438         (insert mail-header-separator)
1439         (goto-char (point-min))
1440         (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1441         (forward-char 1)
1442         (widen)))))
1443
1444 (defun gnus-summary-post-forward (&optional full-headers)
1445   "Forward the current article to a newsgroup.
1446 If FULL-HEADERS (the prefix), include full headers when forwarding."
1447   (interactive "P")
1448   (gnus-summary-mail-forward full-headers t))
1449
1450 (defvar gnus-nastygram-message
1451   "The following article was inappropriately posted to %s.\n\n"
1452   "Format string to insert in nastygrams.
1453 The current group name will be inserted at \"%s\".")
1454
1455 (defun gnus-summary-mail-nastygram (n)
1456   "Send a nastygram to the author of the current article."
1457   (interactive "P")
1458   (when (or gnus-expert-user
1459             (gnus-y-or-n-p
1460              "Really send a nastygram to the author of the current article? "))
1461     (let ((group gnus-newsgroup-name))
1462       (gnus-summary-reply-with-original n)
1463       (set-buffer gnus-message-buffer)
1464       (message-goto-body)
1465       (insert (format gnus-nastygram-message group))
1466       (message-send-and-exit))))
1467
1468 (defun gnus-summary-mail-crosspost-complaint (n)
1469   "Send a complaint about crossposting to the current article(s)."
1470   (interactive "P")
1471   (let ((articles (gnus-summary-work-articles n))
1472         article)
1473     (while (setq article (pop articles))
1474       (set-buffer gnus-summary-buffer)
1475       (gnus-summary-goto-subject article)
1476       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1477             newsgroups followup-to)
1478         (gnus-summary-select-article)
1479         (set-buffer gnus-original-article-buffer)
1480         (if (and (<= (length (message-tokenize-header
1481                               (setq newsgroups
1482                                     (mail-fetch-field "newsgroups"))
1483                               ", "))
1484                      1)
1485                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1486                      (not (member group (message-tokenize-header
1487                                          followup-to ", ")))))
1488             (if followup-to
1489                 (gnus-message 1 "Followup-to restricted")
1490               (gnus-message 1 "Not a crossposted article"))
1491           (set-buffer gnus-summary-buffer)
1492           (gnus-summary-reply-with-original 1)
1493           (set-buffer gnus-message-buffer)
1494           (message-goto-body)
1495           (insert (format gnus-crosspost-complaint newsgroups group))
1496           (message-goto-subject)
1497           (re-search-forward " *$")
1498           (replace-match " (crosspost notification)" t t)
1499           (gnus-deactivate-mark)
1500           (when (gnus-y-or-n-p "Send this complaint? ")
1501             (message-send-and-exit)))))))
1502
1503 (defun gnus-mail-parse-comma-list ()
1504   (let (accumulated
1505         beg)
1506     (skip-chars-forward " ")
1507     (while (not (eobp))
1508       (setq beg (point))
1509       (skip-chars-forward "^,")
1510       (while (zerop
1511               (save-excursion
1512                 (save-restriction
1513                   (let ((i 0))
1514                     (narrow-to-region beg (point))
1515                     (goto-char beg)
1516                     (logand (progn
1517                               (while (search-forward "\"" nil t)
1518                                 (incf i))
1519                               (if (zerop i) 2 i))
1520                             2)))))
1521         (skip-chars-forward ",")
1522         (skip-chars-forward "^,"))
1523       (skip-chars-backward " ")
1524       (push (buffer-substring beg (point))
1525             accumulated)
1526       (skip-chars-forward "^,")
1527       (skip-chars-forward ", "))
1528     accumulated))
1529
1530 (defun gnus-inews-add-to-address (group)
1531   (let ((to-address (mail-fetch-field "to")))
1532     (when (and to-address
1533                (gnus-alive-p))
1534       ;; This mail group doesn't have a `to-list', so we add one
1535       ;; here.  Magic!
1536       (when (gnus-y-or-n-p
1537              (format "Do you want to add this as `to-list': %s " to-address))
1538         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1539
1540 (defun gnus-put-message ()
1541   "Put the current message in some group and return to Gnus."
1542   (interactive)
1543   (let ((reply gnus-article-reply)
1544         (winconf gnus-prev-winconf)
1545         (group gnus-newsgroup-name))
1546     (unless (and group
1547                  (not (gnus-group-read-only-p group)))
1548       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1549
1550     (when (gnus-gethash group gnus-newsrc-hashtb)
1551       (error "No such group: %s" group))
1552     (save-excursion
1553       (save-restriction
1554         (widen)
1555         (message-narrow-to-headers)
1556         (let ((gnus-deletable-headers nil))
1557           (message-generate-headers
1558            (if (message-news-p)
1559                message-required-news-headers
1560              message-required-mail-headers)))
1561         (goto-char (point-max))
1562         (if (string-match " " group)
1563             (insert "Gcc: \"" group "\"\n")
1564           (insert "Gcc: " group "\n"))
1565         (widen)))
1566     (gnus-inews-do-gcc)
1567     (when (and (get-buffer gnus-group-buffer)
1568                (gnus-buffer-exists-p (car-safe reply))
1569                (cdr reply))
1570       (set-buffer (car reply))
1571       (gnus-summary-mark-article-as-replied (cdr reply)))
1572     (when winconf
1573       (set-window-configuration winconf))))
1574
1575 (defun gnus-article-mail (yank)
1576   "Send a reply to the address near point.
1577 If YANK is non-nil, include the original article."
1578   (interactive "P")
1579   (let ((address
1580          (buffer-substring
1581           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1582           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1583     (when address
1584       (gnus-msg-mail address)
1585       (when yank
1586         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1587
1588 (defvar nntp-server-type)
1589 (defun gnus-bug ()
1590   "Send a bug report to the Gnus maintainers."
1591   (interactive)
1592   (unless (gnus-alive-p)
1593     (error "Gnus has been shut down"))
1594   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1595     (unless (message-mail-user-agent)
1596       (message-pop-to-buffer "*Gnus Bug*")
1597       (delete-other-windows)
1598       (when gnus-bug-create-help-buffer
1599         (switch-to-buffer "*Gnus Help Bug*")
1600         (erase-buffer)
1601         (insert gnus-bug-message)
1602         (goto-char (point-min))
1603         (sit-for 0)
1604         (set-buffer "*Gnus Bug*")))
1605     (let ((message-this-is-mail t))
1606       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1607     (when gnus-bug-create-help-buffer
1608       (push `(gnus-bug-kill-buffer) message-send-actions))
1609     (goto-char (point-min))
1610     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1611     (forward-line 1)
1612     (insert gnus-product-name " " gnus-version-number
1613             " (r" gnus-revision-number ") "
1614             "based on " gnus-original-product-name " v"
1615             gnus-original-version-number "\n"
1616             (emacs-version) "\n")
1617     (when (and (boundp 'nntp-server-type)
1618                (stringp nntp-server-type))
1619       (insert nntp-server-type))
1620     (insert "\n\n\n\n\n")
1621     (let (mime-content-types)
1622       (mime-edit-insert-tag
1623        "application" "emacs-lisp"
1624        "\nContent-Disposition: inline\nContent-Description: User settings"))
1625     (insert (with-temp-buffer
1626               (gnus-debug)
1627               (buffer-string)))
1628     (let (mime-content-types)
1629       (mime-edit-insert-tag "text" "plain"))
1630     (goto-char (point-min))
1631     (search-forward "Subject: " nil t)
1632     (message "")))
1633
1634 (defun gnus-bug-kill-buffer ()
1635   (when (get-buffer "*Gnus Help Bug*")
1636     (kill-buffer "*Gnus Help Bug*")))
1637
1638 (defun gnus-summary-yank-message (buffer n)
1639   "Yank the current article into a composed message."
1640   (interactive
1641    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1642          current-prefix-arg))
1643   (when (gnus-buffer-live-p buffer)
1644     (let ((summary-frame (selected-frame))
1645           (message-frame (when (static-if (featurep 'xemacs)
1646                                    (device-on-window-system-p)
1647                                  window-system)
1648                            (let ((window (get-buffer-window buffer t)))
1649                              (when window
1650                                (window-frame window)))))
1651           (separator (concat "^" (regexp-quote mail-header-separator)
1652                              "\n")))
1653       (gnus-summary-iterate n
1654         (gnus-summary-select-article)
1655         (gnus-copy-article-buffer)
1656         (when (frame-live-p message-frame)
1657           (raise-frame message-frame)
1658           (select-frame message-frame))
1659         (with-current-buffer buffer
1660           (when (save-excursion
1661                   (beginning-of-line)
1662                   (let (case-fold-search)
1663                     (and (not (re-search-backward separator nil t))
1664                          (re-search-forward separator nil t))))
1665             (goto-char (match-end 0)))
1666           (message-yank-buffer gnus-article-copy))
1667         (select-frame summary-frame))
1668       (when (frame-live-p message-frame)
1669         (select-frame message-frame)))))
1670
1671 (defun gnus-debug ()
1672   "Attempts to go through the Gnus source file and report what variables have been changed.
1673 The source file has to be in the Emacs load path."
1674   (interactive)
1675   (let ((files gnus-debug-files)
1676         (point (point))
1677         file expr olist sym)
1678     (gnus-message 4 "Please wait while we snoop your variables...")
1679     ;; Go through all the files looking for non-default values for variables.
1680     (save-excursion
1681       (sit-for 0)
1682       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1683       (while files
1684         (erase-buffer)
1685         (when (and (setq file (locate-library (pop files)))
1686                    (file-exists-p file))
1687           (insert-file-contents file)
1688           (goto-char (point-min))
1689           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1690               (gnus-message 4 "Malformed sources in file %s" file)
1691             (narrow-to-region (point-min) (point))
1692             (goto-char (point-min))
1693             (while (setq expr (ignore-errors (read (current-buffer))))
1694               (ignore-errors
1695                 (and (memq (car expr) '(defvar defcustom defvoo))
1696                      (stringp (nth 3 expr))
1697                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1698                      (or (not (boundp (nth 1 expr)))
1699                          (not (equal (eval (nth 2 expr))
1700                                      (symbol-value (nth 1 expr)))))
1701                      (push (nth 1 expr) olist)))))))
1702       (kill-buffer (current-buffer)))
1703     (when (setq olist (nreverse olist))
1704       (insert ";----------------- Environment follows ------------------\n\n"))
1705     (while olist
1706       (if (boundp (car olist))
1707           (condition-case ()
1708               (pp `(setq ,(car olist)
1709                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1710                                   (and (symbolp sym)
1711                                        (not (or (eq sym nil)
1712                                                 (eq sym t)))))
1713                               (list 'quote (symbol-value (car olist)))
1714                             (symbol-value (car olist))))
1715                   (current-buffer))
1716             (error
1717              (format "(setq %s 'whatever)\n" (car olist))))
1718         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1719       (setq olist (cdr olist)))
1720     ;; Remove any control chars - they seem to cause trouble for some
1721     ;; mailers.  (Byte-compiled output from the stuff above.)
1722     (goto-char point)
1723     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1724       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1725                      t t))
1726     ;; Break MIME tags purposely.
1727     (goto-char point)
1728     (while (re-search-forward mime-edit-tag-regexp nil t)
1729       (goto-char (1+ (match-beginning 0)))
1730       (insert "X"))))
1731
1732 ;;; Treatment of rejected articles.
1733 ;;; Bounced mail.
1734
1735 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1736   "Re-mail the current message.
1737 This only makes sense if the current message is a bounce message than
1738 contains some mail you have written which has been bounced back to
1739 you.
1740 If FETCH, try to fetch the article that this is a reply to, if indeed
1741 this is a reply."
1742   (interactive "P")
1743   (gnus-summary-select-article t)
1744   (set-buffer gnus-original-article-buffer)
1745   (gnus-setup-message 'compose-bounce
1746     (let* ((references (mail-fetch-field "references"))
1747            (parent (and references (gnus-parent-id references))))
1748       (message-bounce)
1749       ;; If there are references, we fetch the article we answered to.
1750       (and fetch parent
1751            (gnus-summary-refer-article parent)
1752            (gnus-summary-show-all-headers)))))
1753
1754 ;;; Gcc handling.
1755
1756 (defun gnus-inews-group-method (group)
1757   (cond
1758    ;; If the group doesn't exist, we assume
1759    ;; it's an archive group...
1760    ((and (null (gnus-get-info group))
1761          (eq (car (gnus-server-to-method gnus-message-archive-method))
1762              (car (gnus-server-to-method (gnus-group-method group)))))
1763     gnus-message-archive-method)
1764    ;; Use the method.
1765    ((gnus-info-method (gnus-get-info group))
1766     (gnus-info-method (gnus-get-info group)))
1767    ;; Find the method.
1768    (t (gnus-server-to-method (gnus-group-method group)))))
1769
1770 ;; Do Gcc handling, which copied the message over to some group.
1771 (defun gnus-inews-do-gcc (&optional gcc)
1772   (interactive)
1773   (save-excursion
1774     (save-restriction
1775       (message-narrow-to-headers)
1776       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1777             (coding-system-for-write 'raw-text)
1778             (output-coding-system 'raw-text)
1779             groups group method group-art
1780             mml-externalize-attachments)
1781         (when gcc
1782           (message-remove-header "gcc")
1783           (widen)
1784           (setq groups (message-unquote-tokens
1785                         (message-tokenize-header gcc " ,")))
1786           ;; Copy the article over to some group(s).
1787           (while (setq group (pop groups))
1788             (unless (gnus-check-server
1789                      (setq method (gnus-inews-group-method group)))
1790               (error "Can't open server %s" (if (stringp method) method
1791                                               (car method))))
1792             (unless (gnus-request-group group nil method)
1793               (gnus-request-create-group group method))
1794             (setq mml-externalize-attachments
1795                   (if (stringp gnus-gcc-externalize-attachments)
1796                       (string-match gnus-gcc-externalize-attachments group)
1797                     gnus-gcc-externalize-attachments))
1798             (save-excursion
1799               (nnheader-set-temp-buffer " *acc*")
1800               (insert-buffer-substring message-encoding-buffer)
1801               (gnus-run-hooks 'gnus-before-do-gcc-hook)
1802               (goto-char (point-min))
1803               (when (re-search-forward
1804                      (concat "^" (regexp-quote mail-header-separator) "$")
1805                      nil t)
1806                 (replace-match "" t t ))
1807               (unless (setq group-art
1808                             (gnus-request-accept-article group method t t))
1809                 (gnus-message 1 "Couldn't store article in group %s: %s"
1810                               group (gnus-status-message method))
1811                 (sit-for 2))
1812               (when (and group-art
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 "\n"))))))))
2021                   nil 'local))
2022       (when (or name address)
2023         (add-hook 'message-setup-hook
2024                   `(lambda ()
2025                      (set (make-local-variable 'user-mail-address)
2026                           ,(or (cdr address) user-mail-address))
2027                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
2028                            (user-mail-address
2029                             ,(or (cdr address) user-mail-address)))
2030                        (save-excursion
2031                          (message-remove-header "From")
2032                          (message-goto-eoh)
2033                          (insert "From: " (message-make-from) "\n"))))
2034                   nil 'local)))))
2035
2036 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2037 (defun gnus-configure-posting-style (style stack)
2038   "Parse one posting style STYLE and returns the value as an alist."
2039   (let (results element variable filep value v)
2040     (dolist (attribute style)
2041       (setq element (pop attribute)
2042             variable nil
2043             filep nil)
2044       (setq value
2045             (cond
2046              ((eq (car attribute) ':file)
2047               (setq filep t)
2048               (cadr attribute))
2049              ((eq (car attribute) :value)
2050               (cadr attribute))
2051              (t
2052               (car attribute))))
2053       ;; We get the value.
2054       (setq v
2055             (cond
2056              ((stringp value)
2057               value)
2058              ((or (symbolp value)
2059                   (gnus-functionp value))
2060               (cond ((gnus-functionp value)
2061                      (funcall value))
2062                     ((boundp value)
2063                      (symbol-value value))))
2064              ((listp value)
2065               (eval value))))
2066       ;; Translate obsolescent value.
2067       (cond
2068        ((eq element 'signature-file)
2069         (setq element 'signature
2070               filep t))
2071        ((eq element 'x-face-file)
2072         (setq element 'x-face
2073               filep t)))
2074       ;; Get the contents of file elems.
2075       (when (and filep v)
2076         (setq v (with-temp-buffer
2077                   (insert-file-contents v)
2078                   (goto-char (point-max))
2079                   (while (bolp)
2080                     (delete-char -1))
2081                   (buffer-string))))
2082       (if (eq element 'import)
2083           (progn
2084             (if (member v stack)
2085                 (error "Circular import of \"%s\"" v))
2086             (setq results
2087                   (nconc (nreverse (gnus-configure-posting-style
2088                                     (cdr (assoc v gnus-named-posting-styles))
2089                                     (cons v stack)))
2090                          results)))
2091         (push (cons element v) results)))
2092     (nreverse results)))
2093
2094 (defun gnus-summary-execute-command-with-posting-style (style command)
2095   "Temporarily select a posting-style named STYLE and execute COMMAND."
2096   (interactive
2097    (let ((style (completing-read "Posting style: "
2098                                  gnus-named-posting-styles nil t)))
2099      (list style
2100            (key-binding
2101             (read-key-sequence
2102              (format "Command to execute with %s: " style))))))
2103   (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2104     (call-interactively command)))
2105
2106
2107 ;;; @ for MIME Edit mode
2108 ;;;
2109
2110 (defun gnus-maybe-setup-default-charset ()
2111   (let ((charset
2112          (and (boundp 'gnus-summary-buffer)
2113               (buffer-live-p gnus-summary-buffer)
2114               (save-excursion
2115                 (set-buffer gnus-summary-buffer)
2116                 default-mime-charset))))
2117     (if charset
2118         (progn
2119           (make-local-variable 'default-mime-charset)
2120           (setq default-mime-charset charset)
2121           ))))
2122
2123
2124 ;;; @ for MIME view mode
2125 ;;;
2126
2127 (defun gnus-following-method (buf)
2128   (gnus-setup-message 'reply-yank
2129     (set-buffer buf)
2130     (if (message-news-p)
2131         (message-followup)
2132       (message-reply nil 'wide))
2133     (let ((message-reply-buffer buf))
2134       (message-yank-original))
2135     (message-goto-body))
2136   (kill-buffer buf))
2137
2138
2139 ;;; Allow redefinition of functions.
2140
2141 (gnus-ems-redefine)
2142
2143 (provide 'gnus-msg)
2144
2145 ;;; gnus-msg.el ends here