(pop3-open-ssl-stream): Do away with w32-related
[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   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-maybe-setup-default-charset)
378          (gnus-run-hooks 'gnus-message-setup-hook))
379        (gnus-add-buffer)
380        (gnus-configure-windows ,config t)
381        (run-hooks 'post-command-hook)
382        (set-buffer-modified-p nil))))
383
384 (defun gnus-inews-insert-draft-meta-information (group article)
385   (save-excursion
386     (when (and group
387                (not (string= group ""))
388                (not (message-fetch-field gnus-draft-meta-information-header)))
389       (goto-char (point-min))
390       (insert gnus-draft-meta-information-header ": (\"" group "\" "
391               (if article (number-to-string
392                            (if (listp article)
393                                (car article)
394                              article)) "\"\"")
395               ")\n"))))
396
397 ;;;###autoload
398 (defun gnus-msg-mail (&optional to subject other-headers continue
399                                 switch-action yank-action send-actions)
400   "Start editing a mail message to be sent.
401 Like `message-mail', but with Gnus paraphernalia, particularly the
402 Gcc: header for archiving purposes."
403   (interactive)
404   (let ((buf (current-buffer))
405         mail-buf)
406     (gnus-setup-message 'message
407       (message-mail to subject other-headers continue
408                     nil yank-action send-actions))
409     (when switch-action
410       (setq mail-buf (current-buffer))
411       (switch-to-buffer buf)
412       (apply switch-action mail-buf nil)))
413   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
414   t)
415
416 (defvar save-selected-window-window)
417
418 ;;;###autoload
419 (defun gnus-button-mailto (address)
420   "Mail to ADDRESS."
421   (set-buffer (gnus-copy-article-buffer))
422   (gnus-setup-message 'message
423     (message-reply address))
424   (and (boundp 'save-selected-window-window)
425        (not (window-live-p save-selected-window-window))
426        (setq save-selected-window-window (selected-window))))
427
428 ;;;###autoload
429 (defun gnus-button-reply (&optional to-address wide)
430   "Like `message-reply'."
431   (interactive)
432   (gnus-setup-message 'message
433     (message-reply to-address wide))
434   (and (boundp 'save-selected-window-window)
435        (not (window-live-p save-selected-window-window))
436        (setq save-selected-window-window (selected-window))))
437
438 ;;;###autoload
439 (define-mail-user-agent 'gnus-user-agent
440   'gnus-msg-mail 'message-send-and-exit
441   'message-kill-buffer 'message-send-hook)
442
443 (defun gnus-setup-posting-charset (group)
444   (let ((alist gnus-group-posting-charset-alist)
445         (group (or group ""))
446         elem)
447     (when group
448       (catch 'found
449         (while (setq elem (pop alist))
450           (when (or (and (stringp (car elem))
451                          (string-match (car elem) group))
452                     (and (gnus-functionp (car elem))
453                          (funcall (car elem) group))
454                     (and (symbolp (car elem))
455                          (symbol-value (car elem))))
456             (throw 'found (cons (cadr elem) (caddr elem)))))))))
457
458 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
459   (make-local-hook 'message-sent-hook)
460   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
461                                  'gnus-inews-do-gcc) nil t)
462   (when gnus-agent
463     (make-local-hook 'message-header-hook)
464     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
465   (setq message-post-method
466         `(lambda (arg)
467            (gnus-post-method arg ,gnus-newsgroup-name)))
468   (setq message-user-agent (gnus-extended-version))
469   (when (not message-use-multi-frames)
470     (message-add-action
471      `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
472   (message-add-action
473    `(when (gnus-buffer-exists-p ,buffer)
474       (save-excursion
475         (set-buffer ,buffer)
476         ,(when article
477            (if (eq config 'forward)
478                `(gnus-summary-mark-article-as-forwarded ',article)
479              `(gnus-summary-mark-article-as-replied ',article)))))
480    'send))
481
482 (put 'gnus-setup-message 'lisp-indent-function 1)
483 (put 'gnus-setup-message 'edebug-form-spec '(form body))
484
485 ;;; Post news commands of Gnus group mode and summary mode
486
487 (defun gnus-group-mail (&optional arg)
488   "Start composing a mail.
489 If ARG, use the group under the point to find a posting style.
490 If ARG is 1, prompt for a group name to find the posting style."
491   (interactive "P")
492   ;; We can't `let' gnus-newsgroup-name here, since that leads
493   ;; to local variables leaking.
494   (let ((group gnus-newsgroup-name)
495         (buffer (current-buffer)))
496     (unwind-protect
497         (progn
498           (setq gnus-newsgroup-name
499                 (if arg
500                     (if (= 1 (prefix-numeric-value arg))
501                         (completing-read "Use posting style of group: "
502                                          gnus-active-hashtb nil
503                                          (gnus-read-active-file-p))
504                       (gnus-group-group-name))
505                   ""))
506           ;; #### see comment in gnus-setup-message -- drv
507           (gnus-setup-message 'message (message-mail)))
508       (save-excursion
509         (set-buffer buffer)
510         (setq gnus-newsgroup-name group)))))
511
512 (defun gnus-group-news (&optional arg)
513   "Start composing a news.
514 If ARG, post to group under point.
515 If ARG is 1, prompt for group name to post to.
516
517 This function prepares a news even when using mail groups.  This is useful
518 for posting messages to mail groups without actually sending them over the
519 network.  The corresponding backend must have a 'request-post method."
520   (interactive "P")
521   ;; We can't `let' gnus-newsgroup-name here, since that leads
522   ;; to local variables leaking.
523   (let ((group gnus-newsgroup-name)
524         (buffer (current-buffer)))
525     (unwind-protect
526         (progn
527           (setq gnus-newsgroup-name
528                 (if arg
529                     (if (= 1 (prefix-numeric-value arg))
530                         (completing-read "Use group: "
531                                          gnus-active-hashtb nil
532                                          (gnus-read-active-file-p))
533                       (gnus-group-group-name))
534                   ""))
535           ;; #### see comment in gnus-setup-message -- drv
536           (gnus-setup-message 'message
537             (message-news (gnus-group-real-name gnus-newsgroup-name))))
538       (save-excursion
539         (set-buffer buffer)
540         (setq gnus-newsgroup-name group)))))
541
542 (defun gnus-group-post-news (&optional arg)
543   "Start composing a message (a news by default).
544 If ARG, post to group under point.  If ARG is 1, prompt for group name.
545 Depending on the selected group, the message might be either a mail or
546 a news."
547   (interactive "P")
548   ;; Bind this variable here to make message mode hooks work ok.
549   (let ((gnus-newsgroup-name
550          (if arg
551              (if (= 1 (prefix-numeric-value arg))
552                  (completing-read "Newsgroup: " gnus-active-hashtb nil
553                                   (gnus-read-active-file-p))
554                (gnus-group-group-name))
555            "")))
556     (gnus-post-news 'post gnus-newsgroup-name)))
557
558 (defun gnus-summary-mail-other-window (&optional arg)
559   "Start composing a mail in another window.
560 Use the posting of the current group by default.
561 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
562 posting style."
563   (interactive "P")
564   ;; We can't `let' gnus-newsgroup-name here, since that leads
565   ;; to local variables leaking.
566   (let ((group gnus-newsgroup-name)
567         (buffer (current-buffer)))
568     (unwind-protect
569         (progn
570           (setq gnus-newsgroup-name
571                 (if arg
572                     (if (= 1 (prefix-numeric-value arg))
573                         (completing-read "Use group: "
574                                          gnus-active-hashtb nil
575                                          (gnus-read-active-file-p))
576                       "")
577                   gnus-newsgroup-name))
578           ;; #### see comment in gnus-setup-message -- drv
579           (gnus-setup-message 'message (message-mail)))
580       (save-excursion
581         (set-buffer buffer)
582         (setq gnus-newsgroup-name group)))))
583
584 (defun gnus-summary-news-other-window (&optional arg)
585   "Start composing a news in another window.
586 Post to the current group by default.
587 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
588
589 This function prepares a news even when using mail groups.  This is useful
590 for posting messages to mail groups without actually sending them over the
591 network.  The corresponding backend must have a 'request-post method."
592   (interactive "P")
593   ;; We can't `let' gnus-newsgroup-name here, since that leads
594   ;; to local variables leaking.
595   (let ((group gnus-newsgroup-name)
596         (buffer (current-buffer)))
597     (unwind-protect
598         (progn
599           (setq gnus-newsgroup-name
600                 (if arg
601                     (if (= 1 (prefix-numeric-value arg))
602                         (completing-read "Use group: "
603                                          gnus-active-hashtb nil
604                                          (gnus-read-active-file-p))
605                       "")
606                   gnus-newsgroup-name))
607           ;; #### see comment in gnus-setup-message -- drv
608           (gnus-setup-message 'message
609             (message-news (gnus-group-real-name gnus-newsgroup-name))))
610       (save-excursion
611         (set-buffer buffer)
612         (setq gnus-newsgroup-name group)))))
613
614 (defun gnus-summary-post-news (&optional arg)
615   "Start composing a message.  Post to the current group by default.
616 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
617 Depending on the selected group, the message might be either a mail or
618 a news."
619   (interactive "P")
620   ;; Bind this variable here to make message mode hooks work ok.
621   (let ((gnus-newsgroup-name
622          (if arg
623              (if (= 1 (prefix-numeric-value arg))
624                  (completing-read "Newsgroup: " gnus-active-hashtb nil
625                                   (gnus-read-active-file-p))
626                "")
627            gnus-newsgroup-name)))
628     (gnus-post-news 'post gnus-newsgroup-name)))
629
630
631 (defun gnus-summary-followup (yank &optional force-news)
632   "Compose a followup to an article.
633 If prefix argument YANK is non-nil, the original article is yanked
634 automatically.
635 YANK is a list of elements, where the car of each element is the
636 article number, and the two following numbers is the region to be
637 yanked."
638   (interactive
639    (list (and current-prefix-arg
640               (gnus-summary-work-articles 1))))
641   (when yank
642     (gnus-summary-goto-subject
643      (if (listp (car yank))
644          (caar yank)
645        (car yank))))
646   (save-window-excursion
647     (gnus-summary-select-article))
648   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
649         (gnus-newsgroup-name gnus-newsgroup-name))
650     ;; Send a followup.
651     (gnus-post-news nil gnus-newsgroup-name
652                     headers gnus-article-buffer
653                     yank nil force-news)))
654
655 (defun gnus-summary-followup-with-original (n &optional force-news)
656   "Compose a followup to an article and include the original article."
657   (interactive "P")
658   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
659
660 (defun gnus-summary-followup-to-mail (&optional arg)
661   "Followup to the current mail message via news."
662   (interactive
663    (list (and current-prefix-arg
664               (gnus-summary-work-articles 1))))
665   (gnus-summary-followup arg t))
666
667 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
668   "Followup to the current mail message via news."
669   (interactive "P")
670   (gnus-summary-followup (gnus-summary-work-articles arg) t))
671
672 (defun gnus-inews-yank-articles (articles)
673   (let (beg article yank-string
674             (more-than-one (cdr articles))
675             (cur (current-buffer))
676             refs window)
677     (message-goto-body)
678     (while (setq article (pop articles))
679       (when (listp article)
680         (setq yank-string (nth 1 article)
681               article (nth 0 article)))
682       (save-window-excursion
683         (set-buffer gnus-summary-buffer)
684         (gnus-summary-select-article nil nil nil article)
685         (gnus-summary-remove-process-mark article))
686
687       ;; Gathering references.
688       (when more-than-one
689         (setq refs (message-list-references
690                     refs
691                     (mail-header-references gnus-current-headers)
692                     (mail-header-message-id gnus-current-headers)))
693         (when message-use-multi-frames
694           (when (setq window (get-buffer-window cur t))
695             (select-frame (window-frame window)))))
696
697       (gnus-copy-article-buffer nil yank-string)
698       (let ((message-reply-buffer gnus-article-copy)
699             (message-reply-headers
700              ;; The headers are decoded.
701              (with-current-buffer gnus-article-copy
702                (nnheader-parse-head t))))
703         (message-yank-original)
704         (setq beg (or beg (mark t))))
705       (when articles
706         (insert "\n")))
707     (push-mark)
708
709     ;; Replace with the gathered references.
710     (when refs
711       (push-mark beg)
712       (save-restriction
713         (message-narrow-to-headers)
714         (let ((case-fold-search t))
715           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
716               (replace-match "")
717             (goto-char (point-max))))
718         (mail-header-format
719          (list (or (assq 'References message-header-format-alist)
720                    '(References . message-shorten-references)))
721          (list (cons 'References
722                      (mapconcat 'identity (nreverse refs) " "))))
723         (backward-delete-char 1))
724       (setq beg (mark t))
725       (pop-mark))
726
727     (goto-char beg)))
728
729 (defun gnus-summary-cancel-article (&optional n symp)
730   "Cancel an article you posted.
731 Uses the process-prefix convention.  If given the symbolic
732 prefix `a', cancel using the standard posting method; if not
733 post using the current select method."
734   (interactive (gnus-interactive "P\ny"))
735   (let ((articles (gnus-summary-work-articles n))
736         (message-post-method
737          `(lambda (arg)
738             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
739         article)
740     (while (setq article (pop articles))
741       (when (gnus-summary-select-article t nil nil article)
742         (when (gnus-eval-in-buffer-window gnus-article-buffer
743                 (save-excursion
744                   (set-buffer gnus-original-article-buffer)
745                   (message-cancel-news)))
746           (gnus-summary-mark-as-read article gnus-canceled-mark)
747           (gnus-cache-remove-article 1))
748         (gnus-article-hide-headers-if-wanted))
749       (gnus-summary-remove-process-mark article))))
750
751 (defun gnus-summary-supersede-article ()
752   "Compose an article that will supersede a previous article.
753 This is done simply by taking the old article and adding a Supersedes
754 header line with the old Message-ID."
755   (interactive)
756   (let ((article (gnus-summary-article-number)))
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   (gnus-setup-message 'compose-bounce
1644     (let* ((references (mail-fetch-field "references"))
1645            (parent (and references (gnus-parent-id references))))
1646       (message-bounce)
1647       ;; If there are references, we fetch the article we answered to.
1648       (and fetch parent
1649            (gnus-summary-refer-article parent)
1650            (gnus-summary-show-all-headers)))))
1651
1652 ;;; Gcc handling.
1653
1654 (defun gnus-inews-group-method (group)
1655   (cond
1656    ;; If the group doesn't exist, we assume
1657    ;; it's an archive group...
1658    ((and (null (gnus-get-info group))
1659          (eq (car (gnus-server-to-method gnus-message-archive-method))
1660              (car (gnus-server-to-method (gnus-group-method group)))))
1661     gnus-message-archive-method)
1662    ;; Use the method.
1663    ((gnus-info-method (gnus-get-info group))
1664     (gnus-info-method (gnus-get-info group)))
1665    ;; Find the method.
1666    (t (gnus-server-to-method (gnus-group-method group)))))
1667
1668 ;; Do Gcc handling, which copied the message over to some group.
1669 (defun gnus-inews-do-gcc (&optional gcc)
1670   (interactive)
1671   (save-excursion
1672     (save-restriction
1673       (message-narrow-to-headers)
1674       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1675             (coding-system-for-write 'raw-text)
1676             (output-coding-system 'raw-text)
1677             groups group method group-art
1678             mml-externalize-attachments)
1679         (when gcc
1680           (message-remove-header "gcc")
1681           (widen)
1682           (setq groups (message-unquote-tokens
1683                         (message-tokenize-header gcc " ,")))
1684           ;; Copy the article over to some group(s).
1685           (while (setq group (pop groups))
1686             (unless (gnus-check-server
1687                      (setq method (gnus-inews-group-method group)))
1688               (error "Can't open server %s" (if (stringp method) method
1689                                               (car method))))
1690             (unless (gnus-request-group group nil method)
1691               (gnus-request-create-group group method))
1692             (setq mml-externalize-attachments
1693                   (if (stringp gnus-gcc-externalize-attachments)
1694                       (string-match gnus-gcc-externalize-attachments group)
1695                     gnus-gcc-externalize-attachments))
1696             (save-excursion
1697               (nnheader-set-temp-buffer " *acc*")
1698               (insert-buffer-substring message-encoding-buffer)
1699               (gnus-run-hooks 'gnus-before-do-gcc-hook)
1700               (goto-char (point-min))
1701               (when (re-search-forward
1702                      (concat "^" (regexp-quote mail-header-separator) "$")
1703                      nil t)
1704                 (replace-match "" t t ))
1705               (unless (setq group-art
1706                             (gnus-request-accept-article group method t t))
1707                 (gnus-message 1 "Couldn't store article in group %s: %s"
1708                               group (gnus-status-message method))
1709                 (sit-for 2))
1710               (when (and group-art
1711                          (or gnus-gcc-mark-as-read
1712                              gnus-inews-mark-gcc-as-read))
1713                 (gnus-group-mark-article-read group (cdr group-art)))
1714               (kill-buffer (current-buffer)))))))))
1715
1716 (defun gnus-inews-insert-gcc ()
1717   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1718   (save-excursion
1719     (save-restriction
1720       (message-narrow-to-headers)
1721       (let* ((group gnus-outgoing-message-group)
1722              (gcc (cond
1723                    ((gnus-functionp group)
1724                     (funcall group))
1725                    ((or (stringp group) (list group))
1726                     group))))
1727         (when gcc
1728           (insert "Gcc: "
1729                   (if (stringp gcc) gcc
1730                     (mapconcat 'identity gcc " "))
1731                   "\n"))))))
1732
1733 (defun gnus-inews-insert-archive-gcc (&optional group)
1734   "Insert the Gcc to say where the article is to be archived."
1735   (let* ((var gnus-message-archive-group)
1736          (group (or group gnus-newsgroup-name ""))
1737          (gcc-self-val
1738           (and gnus-newsgroup-name
1739                (not (equal gnus-newsgroup-name ""))
1740                (gnus-group-find-parameter
1741                 gnus-newsgroup-name 'gcc-self)))
1742          result
1743          (groups
1744           (cond
1745            ((null gnus-message-archive-method)
1746             ;; Ignore.
1747             nil)
1748            ((stringp var)
1749             ;; Just a single group.
1750             (list var))
1751            ((null var)
1752             ;; We don't want this.
1753             nil)
1754            ((and (listp var) (stringp (car var)))
1755             ;; A list of groups.
1756             var)
1757            ((gnus-functionp var)
1758             ;; A function.
1759             (funcall var group))
1760            (t
1761             ;; An alist of regexps/functions/forms.
1762             (while (and var
1763                         (not
1764                          (setq result
1765                                (cond
1766                                 ((stringp (caar var))
1767                                  ;; Regexp.
1768                                  (when (string-match (caar var) group)
1769                                    (cdar var)))
1770                                 ((gnus-functionp (car var))
1771                                  ;; Function.
1772                                  (funcall (car var) group))
1773                                 (t
1774                                  (eval (car var)))))))
1775               (setq var (cdr var)))
1776             result)))
1777          name)
1778     (when (or groups gcc-self-val)
1779       (when (stringp groups)
1780         (setq groups (list groups)))
1781       (save-excursion
1782         (save-restriction
1783           (message-narrow-to-headers)
1784           (goto-char (point-max))
1785           (insert "Gcc: ")
1786           (if gcc-self-val
1787               ;; Use the `gcc-self' param value instead.
1788               (progn
1789                 (insert
1790                  (if (stringp gcc-self-val)
1791                      gcc-self-val
1792                    group))
1793                 (if (not (eq gcc-self-val 'none))
1794                     (insert "\n")
1795                   (progn
1796                     (beginning-of-line)
1797                     (kill-line))))
1798             ;; Use the list of groups.
1799             (while (setq name (pop groups))
1800               (insert (if (string-match ":" name)
1801                           name
1802                         (gnus-group-prefixed-name
1803                          name gnus-message-archive-method)))
1804               (when groups
1805                 (insert " ")))
1806             (insert "\n")))))))
1807
1808 ;;; Posting styles.
1809
1810 (defun gnus-configure-posting-styles (&optional group-name)
1811   "Configure posting styles according to `gnus-posting-styles'."
1812   (unless gnus-inhibit-posting-styles
1813     (let ((group (or group-name gnus-newsgroup-name ""))
1814           (styles gnus-posting-styles)
1815           style match variable attribute value v results
1816           filep name address element)
1817       ;; If the group has a posting-style parameter, add it at the end with a
1818       ;; regexp matching everything, to be sure it takes precedence over all
1819       ;; the others.
1820       (when gnus-newsgroup-name
1821         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1822           (when tmp-style
1823             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1824       ;; Go through all styles and look for matches.
1825       (dolist (style styles)
1826         (setq match (pop style))
1827         (goto-char (point-min))
1828         (when (cond
1829                ((stringp match)
1830                 ;; Regexp string match on the group name.
1831                 (string-match match group))
1832                ((eq match 'header)
1833                 ;; Obsolete format of header match.
1834                 (and (gnus-buffer-live-p gnus-article-copy)
1835                      (with-current-buffer gnus-article-copy
1836                        (let ((header (message-fetch-field (pop style))))
1837                          (and header
1838                               (string-match (pop style) header))))))
1839                ((or (symbolp match)
1840                     (gnus-functionp match))
1841                 (cond
1842                  ((gnus-functionp match)
1843                   ;; Function to be called.
1844                   (funcall match))
1845                  ((boundp match)
1846                   ;; Variable to be checked.
1847                   (symbol-value match))))
1848                ((listp match)
1849                 (cond
1850                  ((eq (car match) 'header)
1851                   ;; New format of header match.
1852                   (and (gnus-buffer-live-p gnus-article-copy)
1853                        (with-current-buffer gnus-article-copy
1854                          (let ((header (message-fetch-field (nth 1 match))))
1855                            (and header
1856                                 (string-match (nth 2 match) header))))))
1857                  (t
1858                   ;; This is a form to be evaled.
1859                   (eval match)))))
1860           ;; We have a match, so we set the variables.
1861           (dolist (attribute style)
1862             (setq element (pop attribute)
1863                   variable nil
1864                   filep nil)
1865             (setq value
1866                   (cond
1867                    ((eq (car attribute) ':file)
1868                     (setq filep t)
1869                     (cadr attribute))
1870                    ((eq (car attribute) :value)
1871                     (cadr attribute))
1872                    (t
1873                     (car attribute))))
1874             ;; We get the value.
1875             (setq v
1876                   (cond
1877                    ((stringp value)
1878                     value)
1879                    ((or (symbolp value)
1880                         (gnus-functionp value))
1881                     (cond ((gnus-functionp value)
1882                            (funcall value))
1883                           ((boundp value)
1884                            (symbol-value value))))
1885                    ((listp value)
1886                     (eval value))))
1887             ;; Translate obsolescent value.
1888             (cond
1889              ((eq element 'signature-file)
1890               (setq element 'signature
1891                     filep t))
1892              ((eq element 'x-face-file)
1893               (setq element 'x-face
1894                     filep t)))
1895             ;; Get the contents of file elems.
1896             (when (and filep v)
1897               (setq v (with-temp-buffer
1898                         (insert-file-contents v)
1899                         (goto-char (point-max))
1900                         (while (bolp)
1901                           (delete-char -1))
1902                         (buffer-string))))
1903             (setq results (delq (assoc element results) results))
1904             (push (cons element v) results))))
1905       ;; Now we have all the styles, so we insert them.
1906       (setq name (assq 'name results)
1907             address (assq 'address results))
1908       (setq results (delq name (delq address results)))
1909       ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1910       (make-local-hook 'message-setup-hook)
1911       (dolist (result results)
1912         (add-hook 'message-setup-hook
1913                   (cond
1914                    ((eq 'eval (car result))
1915                     'ignore)
1916                    ((eq 'body (car result))
1917                     `(lambda ()
1918                        (save-excursion
1919                          (message-goto-body)
1920                          (insert ,(cdr result)))))
1921                    ((eq 'signature (car result))
1922                     (set (make-local-variable 'message-signature) nil)
1923                     (set (make-local-variable 'message-signature-file) nil)
1924                     (if (not (cdr result))
1925                         'ignore
1926                       `(lambda ()
1927                          (save-excursion
1928                            (let ((message-signature ,(cdr result)))
1929                              (when message-signature
1930                                (message-insert-signature)))))))
1931                    (t
1932                     (let ((header
1933                            (if (symbolp (car result))
1934                                (capitalize (symbol-name (car result)))
1935                              (car result))))
1936                       `(lambda ()
1937                          (save-excursion
1938                            (message-remove-header ,header)
1939                            (let ((value ,(cdr result)))
1940                              (when value
1941                                (message-goto-eoh)
1942                                (insert ,header ": " value "\n"))))))))
1943                   nil 'local))
1944       (when (or name address)
1945         (add-hook 'message-setup-hook
1946                   `(lambda ()
1947                      (set (make-local-variable 'user-mail-address)
1948                           ,(or (cdr address) user-mail-address))
1949                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1950                            (user-mail-address
1951                             ,(or (cdr address) user-mail-address)))
1952                        (save-excursion
1953                          (message-remove-header "From")
1954                          (message-goto-eoh)
1955                          (insert "From: " (message-make-from) "\n"))))
1956                   nil 'local)))))
1957
1958
1959 ;;; @ for MIME Edit mode
1960 ;;;
1961
1962 (defun gnus-maybe-setup-default-charset ()
1963   (let ((charset
1964          (and (boundp 'gnus-summary-buffer)
1965               (buffer-live-p gnus-summary-buffer)
1966               (save-excursion
1967                 (set-buffer gnus-summary-buffer)
1968                 default-mime-charset))))
1969     (if charset
1970         (progn
1971           (make-local-variable 'default-mime-charset)
1972           (setq default-mime-charset charset)
1973           ))))
1974
1975
1976 ;;; @ for MIME view mode
1977 ;;;
1978
1979 (defun gnus-following-method (buf)
1980   (gnus-setup-message 'reply-yank
1981     (set-buffer buf)
1982     (if (message-news-p)
1983         (message-followup)
1984       (message-reply nil 'wide))
1985     (let ((message-reply-buffer buf))
1986       (message-yank-original))
1987     (message-goto-body))
1988   (kill-buffer buf))
1989
1990
1991 ;;; Allow redefinition of functions.
1992
1993 (gnus-ems-redefine)
1994
1995 (provide 'gnus-msg)
1996
1997 ;;; gnus-msg.el ends here