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