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