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