a8fa0e943274e4deb7fb6c58c32163a472388605
[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
674 (defun gnus-summary-followup-with-original (n &optional force-news)
675   "Compose a followup to an article and include the original article."
676   (interactive "P")
677   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
678
679 (defun gnus-summary-followup-to-mail (&optional arg)
680   "Followup to the current mail message via news."
681   (interactive
682    (list (and current-prefix-arg
683               (gnus-summary-work-articles 1))))
684   (gnus-summary-followup arg t))
685
686 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
687   "Followup to the current mail message via news."
688   (interactive "P")
689   (gnus-summary-followup (gnus-summary-work-articles arg) t))
690
691 (defun gnus-inews-yank-articles (articles)
692   (let (beg article yank-string
693             (more-than-one (cdr articles))
694             (cur (current-buffer))
695             refs window)
696     (message-goto-body)
697     (while (setq article (pop articles))
698       (when (listp article)
699         (setq yank-string (nth 1 article)
700               article (nth 0 article)))
701       (save-window-excursion
702         (set-buffer gnus-summary-buffer)
703         (gnus-summary-select-article nil nil nil article)
704         (gnus-summary-remove-process-mark article))
705
706       ;; Gathering references.
707       (when more-than-one
708         (setq refs (message-list-references
709                     refs
710                     (mail-header-references gnus-current-headers)
711                     (mail-header-message-id gnus-current-headers)))
712         (when message-use-multi-frames
713           (when (setq window (get-buffer-window cur t))
714             (select-frame (window-frame window)))))
715
716       (gnus-copy-article-buffer nil yank-string)
717       (let ((message-reply-buffer gnus-article-copy)
718             (message-reply-headers
719              ;; The headers are decoded.
720              (with-current-buffer gnus-article-copy
721                (save-restriction
722                  (nnheader-narrow-to-headers)
723                  (ietf-drums-unfold-fws)
724                  (nnheader-parse-head t)))))
725         (message-yank-original)
726         (setq beg (or beg (mark t))))
727       (when articles
728         (insert "\n")))
729     (push-mark)
730
731     ;; Replace with the gathered references.
732     (when refs
733       (push-mark beg)
734       (save-restriction
735         (message-narrow-to-headers)
736         (let ((case-fold-search t))
737           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
738               (replace-match "")
739             (goto-char (point-max))))
740         (mail-header-format
741          (list (or (assq 'References message-header-format-alist)
742                    '(References . message-shorten-references)))
743          (list (cons 'References
744                      (mapconcat 'identity (nreverse refs) " "))))
745         (backward-delete-char 1))
746       (setq beg (mark t))
747       (pop-mark))
748
749     (goto-char beg)))
750
751 (defun gnus-summary-cancel-article (&optional n symp)
752   "Cancel an article you posted.
753 Uses the process-prefix convention.  If given the symbolic
754 prefix `a', cancel using the standard posting method; if not
755 post using the current select method."
756   (interactive (gnus-interactive "P\ny"))
757   (let ((articles (gnus-summary-work-articles n))
758         (message-post-method
759          `(lambda (arg)
760             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
761         article)
762     (while (setq article (pop articles))
763       (when (gnus-summary-select-article t nil nil article)
764         (when (gnus-eval-in-buffer-window gnus-article-buffer
765                 (save-excursion
766                   (set-buffer gnus-original-article-buffer)
767                   (message-cancel-news)))
768           (gnus-summary-mark-as-read article gnus-canceled-mark)
769           (gnus-cache-remove-article 1))
770         (gnus-article-hide-headers-if-wanted))
771       (gnus-summary-remove-process-mark article))))
772
773 (defun gnus-summary-supersede-article ()
774   "Compose an article that will supersede a previous article.
775 This is done simply by taking the old article and adding a Supersedes
776 header line with the old Message-ID."
777   (interactive)
778   (let ((article (gnus-summary-article-number)))
779     (gnus-setup-message 'reply-yank
780       (gnus-summary-select-article t)
781       (set-buffer gnus-original-article-buffer)
782       (message-supersede)
783       (push
784        `((lambda ()
785            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
786              (save-excursion
787                (set-buffer ,gnus-summary-buffer)
788                (gnus-cache-possibly-remove-article ,article nil nil nil t)
789                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
790        message-send-actions))))
791
792 \f
793
794 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
795   ;; make a copy of the article buffer with all text properties removed
796   ;; this copy is in the buffer gnus-article-copy.
797   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
798   ;; this buffer should be passed to all mail/news reply/post routines.
799   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
800   (let ((article-buffer (or article-buffer gnus-article-buffer))
801         end beg)
802     (if (not (and (get-buffer article-buffer)
803                   (gnus-buffer-exists-p article-buffer)))
804         (error "Can't find any article buffer")
805       (save-excursion
806         (set-buffer article-buffer)
807         (let ((gnus-newsgroup-charset (or gnus-article-charset
808                                           gnus-newsgroup-charset))
809               (gnus-newsgroup-ignored-charsets
810                (or gnus-article-ignored-charsets
811                    gnus-newsgroup-ignored-charsets)))
812           (save-restriction
813             ;; Copy over the (displayed) article buffer, delete
814             ;; hidden text and remove text properties.
815             (widen)
816             (let ((inhibit-read-only t))
817               (copy-to-buffer gnus-article-copy (point-min) (point-max))
818               (set-buffer gnus-article-copy)
819               (when yank-string
820                 (message-goto-body)
821                 (delete-region (point) (point-max))
822                 (insert yank-string))
823               ;; Encode bitmap smileys to ordinary text.
824               ;; Possibly, the original text might be restored.
825               (static-unless (featurep 'xemacs)
826                 (when (featurep 'smiley-mule)
827                   (smiley-encode-buffer)))
828               (gnus-article-delete-text-of-type 'annotation)
829               (gnus-remove-text-with-property 'gnus-prev)
830               (gnus-remove-text-with-property 'gnus-next)
831               (gnus-remove-text-with-property 'gnus-decoration)
832               (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
833               (insert
834                (prog1
835                    (static-if (featurep 'xemacs)
836                        ;; Revome smiley extents for (possibly) XEmacs 21.1.
837                        (format "%s"
838                                (buffer-substring-no-properties (point-min)
839                                                                (point-max)))
840                      (buffer-substring-no-properties (point-min) (point-max)))
841                  (erase-buffer))))
842             ;; Find the original headers.
843             (set-buffer gnus-original-article-buffer)
844             (goto-char (point-min))
845             (while (looking-at message-unix-mail-delimiter)
846               (forward-line 1))
847             (setq beg (point)
848                   end (or (message-goto-body) beg))
849             ;; Delete the headers from the displayed articles.
850             (set-buffer gnus-article-copy)
851             (delete-region (goto-char (point-min))
852                            (or (message-goto-body) (point-max)))
853             ;; Insert the original article headers.
854             (insert-buffer-substring gnus-original-article-buffer beg end)
855             ;; Decode charsets.
856             (let ((gnus-article-decode-hook
857                    (delq 'article-decode-charset
858                          (copy-sequence gnus-article-decode-hook))))
859               ;; Needed for T-gnus.
860               (add-hook 'gnus-article-decode-hook
861                         'article-decode-encoded-words)
862               (run-hooks 'gnus-article-decode-hook)))))
863       gnus-article-copy)))
864
865 (defun gnus-post-news (post &optional group header article-buffer yank subject
866                             force-news)
867   (when article-buffer
868     (gnus-copy-article-buffer))
869   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
870         (add-to-list gnus-add-to-list))
871     (gnus-setup-message (cond (yank 'reply-yank)
872                               (article-buffer 'reply)
873                               (t 'message))
874       (let* ((group (or group gnus-newsgroup-name))
875              (charset (gnus-group-name-charset nil group))
876              (pgroup group)
877              to-address to-group mailing-list to-list
878              newsgroup-p)
879         (when group
880           (setq to-address (gnus-parameter-to-address group)
881                 to-group (gnus-group-find-parameter group 'to-group)
882                 to-list (gnus-parameter-to-list group)
883                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
884                 mailing-list (when gnus-mailing-list-groups
885                                (string-match gnus-mailing-list-groups group))
886                 group (gnus-group-name-decode (gnus-group-real-name group)
887                                               charset)))
888         (if (or (and to-group
889                      (gnus-news-group-p to-group))
890                 newsgroup-p
891                 force-news
892                 (and (gnus-news-group-p
893                       (or pgroup gnus-newsgroup-name)
894                       (or header gnus-current-article))
895                      (not mailing-list)
896                      (not to-list)
897                      (not to-address)))
898             ;; This is news.
899             (if post
900                 (message-news (or to-group group))
901               (set-buffer gnus-article-copy)
902               (gnus-msg-treat-broken-reply-to)
903               (message-followup (if (or newsgroup-p force-news)
904                                     (if (save-restriction
905                                           (article-narrow-to-head)
906                                           (message-fetch-field "newsgroups"))
907                                         nil
908                                       "")
909                                   to-group)))
910           ;; The is mail.
911           (if post
912               (progn
913                 (message-mail (or to-address to-list))
914                 ;; Arrange for mail groups that have no `to-address' to
915                 ;; get that when the user sends off the mail.
916                 (when (and (not to-list)
917                            (not to-address)
918                            add-to-list)
919                   (push (list 'gnus-inews-add-to-address pgroup)
920                         message-send-actions)))
921             (set-buffer gnus-article-copy)
922             (gnus-msg-treat-broken-reply-to)
923             (message-wide-reply to-address)))
924         (when yank
925           (gnus-inews-yank-articles yank))))))
926
927 (defun gnus-msg-treat-broken-reply-to (&optional force)
928   "Remove the Reply-to header iff broken-reply-to."
929   (when (or force
930             (gnus-group-find-parameter
931              gnus-newsgroup-name 'broken-reply-to))
932     (save-restriction
933       (message-narrow-to-head)
934       (message-remove-header "reply-to"))))
935
936 (defun gnus-post-method (arg group &optional silent)
937   "Return the posting method based on GROUP and ARG.
938 If SILENT, don't prompt the user."
939   (let ((gnus-post-method (or (gnus-parameter-post-method group)
940                               gnus-post-method))
941         (group-method (gnus-find-method-for-group group)))
942     (cond
943      ;; If the group-method is nil (which shouldn't happen) we use
944      ;; the default method.
945      ((null group-method)
946       (or (and (listp gnus-post-method) ;If not current/native/nil
947                (not (listp (car gnus-post-method))) ; and not a list of methods
948                gnus-post-method)        ;then use it.
949           gnus-select-method
950           message-post-method))
951      ;; We want the inverse of the default
952      ((and arg (not (eq arg 0)))
953       (if (eq gnus-post-method 'current)
954           gnus-select-method
955         group-method))
956      ;; We query the user for a post method.
957      ((or arg
958           (and (listp gnus-post-method)
959                (listp (car gnus-post-method))))
960       (let* ((methods
961               ;; Collect all methods we know about.
962               (append
963                (when (listp gnus-post-method)
964                  (if (listp (car gnus-post-method))
965                      gnus-post-method
966                    (list gnus-post-method)))
967                gnus-secondary-select-methods
968                (mapcar 'cdr gnus-server-alist)
969                (mapcar 'car gnus-opened-servers)
970                (list gnus-select-method)
971                (list group-method)))
972              method-alist post-methods method)
973         ;; Weed out all mail methods.
974         (while methods
975           (setq method (gnus-server-get-method "" (pop methods)))
976           (when (and (or (gnus-method-option-p method 'post)
977                          (gnus-method-option-p method 'post-mail))
978                      (not (member method post-methods)))
979             (push method post-methods)))
980         ;; Create a name-method alist.
981         (setq method-alist
982               (mapcar
983                (lambda (m)
984                  (if (equal (cadr m) "")
985                      (list (symbol-name (car m)) m)
986                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
987                post-methods))
988         ;; Query the user.
989         (cadr
990          (assoc
991           (setq gnus-last-posting-server
992                 (if (and silent
993                          gnus-last-posting-server)
994                     ;; Just use the last value.
995                     gnus-last-posting-server
996                   (completing-read
997                    "Posting method: " method-alist nil t
998                    (cons (or gnus-last-posting-server "") 0))))
999           method-alist))))
1000      ;; Override normal method.
1001      ((and (eq gnus-post-method 'current)
1002            (not (memq (car group-method) gnus-discouraged-post-methods))
1003            (gnus-get-function group-method 'request-post t))
1004       (assert (not arg))
1005       group-method)
1006      ;; Use gnus-post-method.
1007      ((listp gnus-post-method)          ;A method...
1008       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1009       gnus-post-method)
1010      ;; Use the normal select method (nil or native).
1011      (t gnus-select-method))))
1012
1013 \f
1014 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1015                                                  newline-product)
1016   "Return a user-agent info.  If INCLUDE-MIME-INFO is non-nil and the
1017 variable `mime-edit-user-agent-value' is bound, the value will be
1018 included in the return value.  If MAX-COLUMN is specified, the return
1019 value will be folded up as it were filled.  NEWLINE-PRODUCT specifies
1020 whether a newline should be inserted in front of each product-token.
1021 If the value is t or `hard', it works strictly.  Otherwise, if it is
1022 non-nil (e.g. `soft'), it works semi-strictly.
1023
1024 Here is an example of how to use this function:
1025
1026 \(add-hook 'gnus-message-setup-hook
1027           (lambda nil
1028             (setq message-user-agent nil)
1029             (save-excursion
1030               (save-restriction
1031                 (message-narrow-to-headers)
1032                 (goto-char (point-max))
1033                 (insert \"User-Agent: \"
1034                         (gnus-message-make-user-agent t 76 'soft)
1035                         \"\\n\")))))
1036 "
1037   (let ((user-agent (if (and include-mime-info
1038                              (boundp 'mime-edit-user-agent-value))
1039                         (concat (gnus-extended-version)
1040                                 " "
1041                                 mime-edit-user-agent-value)
1042                       (gnus-extended-version))))
1043     (when max-column
1044       (unless (natnump max-column)
1045         (setq max-column 76))
1046       (with-temp-buffer
1047         (set-buffer-multibyte t)
1048         (insert (mapconcat 'identity (split-string user-agent) " "))
1049         (goto-char (point-min))
1050         (let ((bol t)
1051               start agent agents width element swidth)
1052           (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1053             (setq start (match-beginning 0))
1054             (if (eq (char-after start) ?\()
1055                 (progn
1056                   (goto-char start)
1057                   (forward-list)
1058                   (push (buffer-substring start (point)) agent))
1059               (when agent
1060                 (push (nreverse agent) agents))
1061               (setq agent (list (match-string 1)))))
1062           (when agent
1063             (push (nreverse agent) agents))
1064           (setq agents (nreverse agents))
1065           (if (> (+ 12 (string-width (caar agents))) max-column)
1066               (setq user-agent "\n"
1067                     width 0)
1068             (setq user-agent ""
1069                   width 11))
1070           (while agents
1071             (setq agent (car agents)
1072                   agents (cdr agents))
1073             (when (and (not bol)
1074                        (or (memq newline-product '(t hard))
1075                            (and newline-product
1076                                 (> (+ width 1
1077                                       (string-width (mapconcat 'identity
1078                                                                agent " ")))
1079                                    max-column))))
1080               (setq user-agent (concat user-agent "\n")
1081                     width 0
1082                     bol t))
1083             (while agent
1084               (setq element (car agent)
1085                     swidth (string-width element)
1086                     agent (cdr agent))
1087               (if bol
1088                   (setq user-agent (if (member user-agent '("" "\n"))
1089                                        (concat user-agent element)
1090                                      (concat user-agent " " element))
1091                         width (+ width 1 swidth)
1092                         bol nil)
1093                 (if (> (+ width 1 swidth) max-column)
1094                     (setq user-agent (concat user-agent "\n " element)
1095                           width (1+ swidth))
1096                   (setq user-agent (concat user-agent " " element)
1097                         width (+ width 1 swidth)))))))))
1098     user-agent))
1099
1100 \f
1101 ;;;
1102 ;;; Gnus Mail Functions
1103 ;;;
1104
1105 ;;; Mail reply commands of Gnus summary mode
1106
1107 (defun gnus-summary-reply (&optional yank wide very-wide)
1108   "Start composing a mail reply to the current message.
1109 If prefix argument YANK is non-nil, the original article is yanked
1110 automatically.
1111 If WIDE, make a wide reply.
1112 If VERY-WIDE, make a very wide reply."
1113   (interactive
1114    (list (and current-prefix-arg
1115               (gnus-summary-work-articles 1))))
1116   ;; Allow user to require confirmation before replying by mail to the
1117   ;; author of a news article.
1118   (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1119             (not gnus-confirm-mail-reply-to-news)
1120             (y-or-n-p "Really reply by mail to article author? "))
1121     (let* ((article
1122             (if (listp (car yank))
1123                 (caar yank)
1124               (car yank)))
1125            (gnus-article-reply (or article (gnus-summary-article-number)))
1126            (headers ""))
1127       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1128       (when yank
1129         (gnus-summary-goto-subject article))
1130       (gnus-setup-message (if yank 'reply-yank 'reply)
1131         (if (not very-wide)
1132             (gnus-summary-select-article)
1133           (dolist (article very-wide)
1134             (gnus-summary-select-article nil nil nil article)
1135             (save-excursion
1136               (set-buffer (gnus-copy-article-buffer))
1137               (gnus-msg-treat-broken-reply-to)
1138               (save-restriction
1139                 (message-narrow-to-head)
1140                 (setq headers (concat headers (buffer-string)))))))
1141         (set-buffer (gnus-copy-article-buffer))
1142         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1143         (save-restriction
1144           (message-narrow-to-head)
1145           (when very-wide
1146             (erase-buffer)
1147             (insert headers))
1148           (goto-char (point-max)))
1149         (message-reply nil wide)
1150         (when yank
1151           (gnus-inews-yank-articles yank))
1152 ;;      (when (or gnus-message-replysign gnus-message-replyencrypt)
1153 ;;        (let (signed encrypted)
1154 ;;          (save-excursion
1155 ;;            (set-buffer gnus-article-buffer)
1156 ;;            (setq signed (memq 'signed gnus-article-wash-types))
1157 ;;            (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1158 ;;          (cond ((and gnus-message-replysign signed)
1159 ;;                 (mml-secure-message mml-default-sign-method 'sign))
1160 ;;                ((and gnus-message-replyencrypt encrypted)
1161 ;;                 (mml-secure-message mml-default-encrypt-method
1162 ;;                                     (if gnus-message-replysignencrypted
1163 ;;                                         'signencrypt
1164 ;;                                       'encrypt))))))
1165         ))))
1166
1167 (defun gnus-summary-reply-with-original (n &optional wide)
1168   "Start composing a reply mail to the current message.
1169 The original article will be yanked."
1170   (interactive "P")
1171   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1172
1173 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1174   "Like `gnus-summary-reply' except removing reply-to field.
1175 If prefix argument YANK is non-nil, the original article is yanked
1176 automatically.
1177 If WIDE, make a wide reply.
1178 If VERY-WIDE, make a very wide reply."
1179   (interactive
1180    (list (and current-prefix-arg
1181               (gnus-summary-work-articles 1))))
1182   (let ((gnus-msg-force-broken-reply-to t))
1183     (gnus-summary-reply yank wide very-wide)))
1184
1185 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1186   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1187 The original article will be yanked."
1188   (interactive "P")
1189   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1190
1191 (defun gnus-summary-wide-reply (&optional yank)
1192   "Start composing a wide reply mail to the current message.
1193 If prefix argument YANK is non-nil, the original article is yanked
1194 automatically."
1195   (interactive
1196    (list (and current-prefix-arg
1197               (gnus-summary-work-articles 1))))
1198   (gnus-summary-reply yank t))
1199
1200 (defun gnus-summary-wide-reply-with-original (n)
1201   "Start composing a wide reply mail to the current message.
1202 The original article will be yanked."
1203   (interactive "P")
1204   (gnus-summary-reply-with-original n t))
1205
1206 (defun gnus-summary-very-wide-reply (&optional yank)
1207   "Start composing a very wide reply mail to the current message.
1208 If prefix argument YANK is non-nil, the original article is yanked
1209 automatically."
1210   (interactive
1211    (list (and current-prefix-arg
1212               (gnus-summary-work-articles 1))))
1213   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1214
1215 (defun gnus-summary-very-wide-reply-with-original (n)
1216   "Start composing a very wide reply mail to the current message.
1217 The original article will be yanked."
1218   (interactive "P")
1219   (gnus-summary-reply
1220    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1221
1222 (defun gnus-summary-mail-forward (&optional full-headers post)
1223   "Forward the current message(s) to another user.
1224 If process marks exist, forward all marked messages;
1225 If FULL-HEADERS (the prefix), include full headers when forwarding.
1226
1227 Note that this function definition for T-gnus is totally different
1228 from the original Gnus."
1229   (interactive "P")
1230   (if (null (cdr (gnus-summary-work-articles nil)))
1231       (gnus-setup-message 'forward
1232         (gnus-summary-select-article)
1233         (let ((charset default-mime-charset))
1234           (set-buffer gnus-original-article-buffer)
1235           (make-local-variable 'default-mime-charset)
1236           (setq default-mime-charset charset))
1237         (let ((message-included-forward-headers
1238                (if full-headers "" message-included-forward-headers)))
1239           (message-forward post)))
1240     (gnus-summary-digest-mail-forward nil post)))
1241
1242 (defun gnus-summary-digest-mail-forward (&optional n post)
1243   "Digests and forwards all articles in this series.
1244 If N is a positive number, forward the N next articles.
1245 If N is a negative number, forward the N previous articles.
1246 If N is nil and any articles have been marked with the process mark,
1247 forward those articles instead.
1248 Optional POST will use news to forward instead of mail."
1249   (interactive "P")
1250   (let ((articles (gnus-summary-work-articles n))
1251         (topics "Topics:\n")
1252         subject article frame)
1253     (when (car articles)
1254       (gnus-setup-message 'forward
1255         (gnus-summary-select-article)
1256         (if (cdr articles)
1257             (setq articles (sort articles '<)
1258                   subject "Digested Articles")
1259           (with-current-buffer gnus-original-article-buffer
1260             (setq subject (message-make-forward-subject))))
1261         (if post
1262             (message-news nil subject)
1263           (message-mail nil subject))
1264         (when (and message-use-multi-frames (cdr articles))
1265           (setq frame (window-frame (get-buffer-window (current-buffer)))))
1266         (message-goto-body)
1267         (while (setq article (pop articles))
1268           (save-window-excursion
1269             (set-buffer gnus-summary-buffer)
1270             (gnus-summary-select-article nil nil nil article)
1271             (setq topics (concat topics "    "
1272                                  (mail-header-subject gnus-current-headers)
1273                                  "\n"))
1274             (gnus-summary-remove-process-mark article))
1275           (when frame
1276             (select-frame frame))
1277           (insert (mime-make-tag "message" "rfc822") "\n")
1278           (narrow-to-region (point) (point))
1279           (insert-buffer-substring gnus-original-article-buffer)
1280           (save-restriction
1281             (article-narrow-to-head)
1282             (message-remove-header message-included-forward-headers t nil t))
1283           (goto-char (point-max))
1284           (widen))
1285         (push-mark)
1286         (message-goto-body)
1287         (insert topics)
1288         (message-goto-body)
1289         (mime-edit-enclose-digest-region (point)(mark t))))))
1290
1291 (defun gnus-summary-digest-post-forward (&optional n)
1292   "Digest and forwards all articles in this series to a newsgroup.
1293 If N is a positive number, forward the N next articles.
1294 If N is a negative number, forward the N previous articles.
1295 If N is nil and any articles have been marked with the process mark,
1296 forward those articles instead."
1297   (interactive "P")
1298   (gnus-summary-digest-mail-forward n t))
1299
1300 (defun gnus-summary-resend-message (address n)
1301   "Resend the current article to ADDRESS."
1302   (interactive
1303    (list (message-read-from-minibuffer
1304           "Resend message(s) to: "
1305           (when (gnus-buffer-live-p gnus-original-article-buffer)
1306             ;; If some other article is currently selected, the
1307             ;; initial-contents is wrong. Whatever, it is just the
1308             ;; initial-contents.
1309             (with-current-buffer gnus-original-article-buffer
1310               (nnmail-fetch-field "to"))))
1311          current-prefix-arg))
1312   (let ((articles (gnus-summary-work-articles n))
1313         article)
1314     (while (setq article (pop articles))
1315       (gnus-summary-select-article nil nil nil article)
1316       (save-excursion
1317         (set-buffer gnus-original-article-buffer)
1318         (message-resend address))
1319       (gnus-summary-mark-article-as-forwarded article))))
1320
1321 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1322 (defun gnus-summary-resend-message-edit ()
1323   "Resend an article that has already been sent.
1324 A new buffer will be created to allow the user to modify body and
1325 contents of the message, and then, everything will happen as when
1326 composing a new message."
1327   (interactive)
1328   (let ((article (gnus-summary-article-number)))
1329     (gnus-setup-message 'reply-yank
1330       (gnus-summary-select-article t)
1331       (set-buffer gnus-original-article-buffer)
1332       (let ((cur (current-buffer))
1333             (to (message-fetch-field "to")))
1334         ;; Get a normal message buffer.
1335         (message-pop-to-buffer (message-buffer-name "Resend" to))
1336         (insert-buffer-substring cur)
1337
1338         ;; T-gnus change: Use MIME-Edit to recompose a message.
1339         ;;(mime-to-mml)
1340         (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1341           (fset 'mime-edit-decode-single-part-in-buffer
1342                 (lambda (&rest args)
1343                   (if (let ((content-type (car args)))
1344                         (and (eq 'message (mime-content-type-primary-type
1345                                            content-type))
1346                              (eq 'rfc822 (mime-content-type-subtype
1347                                           content-type))))
1348                       (setcar (cdr args) 'not-decode-text))
1349                   (apply ofn args)))
1350           (unwind-protect
1351               (mime-edit-again nil t)
1352             (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1353         (message-narrow-to-head-1)
1354         (insert "From: " (message-make-from) "\n")
1355         (while (re-search-forward "^From:" nil t)
1356           (beginning-of-line)
1357           (insert "Original-"))
1358         (message-remove-header "^>From[\t ]" t)
1359
1360         ;; Gnus will generate a new one when sending.
1361         (message-remove-header "Message-ID")
1362         (message-remove-header message-ignored-resent-headers t)
1363         ;; Remove unwanted headers.
1364         (goto-char (point-max))
1365         (insert mail-header-separator)
1366         (goto-char (point-min))
1367         (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1368         (forward-char 1)
1369         (widen)))))
1370
1371 (defun gnus-summary-post-forward (&optional full-headers)
1372   "Forward the current article to a newsgroup.
1373 If FULL-HEADERS (the prefix), include full headers when forwarding."
1374   (interactive "P")
1375   (gnus-summary-mail-forward full-headers t))
1376
1377 (defvar gnus-nastygram-message
1378   "The following article was inappropriately posted to %s.\n\n"
1379   "Format string to insert in nastygrams.
1380 The current group name will be inserted at \"%s\".")
1381
1382 (defun gnus-summary-mail-nastygram (n)
1383   "Send a nastygram to the author of the current article."
1384   (interactive "P")
1385   (when (or gnus-expert-user
1386             (gnus-y-or-n-p
1387              "Really send a nastygram to the author of the current article? "))
1388     (let ((group gnus-newsgroup-name))
1389       (gnus-summary-reply-with-original n)
1390       (set-buffer gnus-message-buffer)
1391       (message-goto-body)
1392       (insert (format gnus-nastygram-message group))
1393       (message-send-and-exit))))
1394
1395 (defun gnus-summary-mail-crosspost-complaint (n)
1396   "Send a complaint about crossposting to the current article(s)."
1397   (interactive "P")
1398   (let ((articles (gnus-summary-work-articles n))
1399         article)
1400     (while (setq article (pop articles))
1401       (set-buffer gnus-summary-buffer)
1402       (gnus-summary-goto-subject article)
1403       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1404             newsgroups followup-to)
1405         (gnus-summary-select-article)
1406         (set-buffer gnus-original-article-buffer)
1407         (if (and (<= (length (message-tokenize-header
1408                               (setq newsgroups
1409                                     (mail-fetch-field "newsgroups"))
1410                               ", "))
1411                      1)
1412                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1413                      (not (member group (message-tokenize-header
1414                                          followup-to ", ")))))
1415             (if followup-to
1416                 (gnus-message 1 "Followup-to restricted")
1417               (gnus-message 1 "Not a crossposted article"))
1418           (set-buffer gnus-summary-buffer)
1419           (gnus-summary-reply-with-original 1)
1420           (set-buffer gnus-message-buffer)
1421           (message-goto-body)
1422           (insert (format gnus-crosspost-complaint newsgroups group))
1423           (message-goto-subject)
1424           (re-search-forward " *$")
1425           (replace-match " (crosspost notification)" t t)
1426           (gnus-deactivate-mark)
1427           (when (gnus-y-or-n-p "Send this complaint? ")
1428             (message-send-and-exit)))))))
1429
1430 (defun gnus-mail-parse-comma-list ()
1431   (let (accumulated
1432         beg)
1433     (skip-chars-forward " ")
1434     (while (not (eobp))
1435       (setq beg (point))
1436       (skip-chars-forward "^,")
1437       (while (zerop
1438               (save-excursion
1439                 (save-restriction
1440                   (let ((i 0))
1441                     (narrow-to-region beg (point))
1442                     (goto-char beg)
1443                     (logand (progn
1444                               (while (search-forward "\"" nil t)
1445                                 (incf i))
1446                               (if (zerop i) 2 i))
1447                             2)))))
1448         (skip-chars-forward ",")
1449         (skip-chars-forward "^,"))
1450       (skip-chars-backward " ")
1451       (push (buffer-substring beg (point))
1452             accumulated)
1453       (skip-chars-forward "^,")
1454       (skip-chars-forward ", "))
1455     accumulated))
1456
1457 (defun gnus-inews-add-to-address (group)
1458   (let ((to-address (mail-fetch-field "to")))
1459     (when (and to-address
1460                (gnus-alive-p))
1461       ;; This mail group doesn't have a `to-list', so we add one
1462       ;; here.  Magic!
1463       (when (gnus-y-or-n-p
1464              (format "Do you want to add this as `to-list': %s " to-address))
1465         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1466
1467 (defun gnus-put-message ()
1468   "Put the current message in some group and return to Gnus."
1469   (interactive)
1470   (let ((reply gnus-article-reply)
1471         (winconf gnus-prev-winconf)
1472         (group gnus-newsgroup-name))
1473     (unless (and group
1474                  (not (gnus-group-read-only-p group)))
1475       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1476
1477     (when (gnus-gethash group gnus-newsrc-hashtb)
1478       (error "No such group: %s" group))
1479     (save-excursion
1480       (save-restriction
1481         (widen)
1482         (message-narrow-to-headers)
1483         (let ((gnus-deletable-headers nil))
1484           (message-generate-headers
1485            (if (message-news-p)
1486                message-required-news-headers
1487              message-required-mail-headers)))
1488         (goto-char (point-max))
1489         (insert "Gcc: " group "\n")
1490         (widen)))
1491     (gnus-inews-do-gcc)
1492     (when (and (get-buffer gnus-group-buffer)
1493                (gnus-buffer-exists-p (car-safe reply))
1494                (cdr reply))
1495       (set-buffer (car reply))
1496       (gnus-summary-mark-article-as-replied (cdr reply)))
1497     (when winconf
1498       (set-window-configuration winconf))))
1499
1500 (defun gnus-article-mail (yank)
1501   "Send a reply to the address near point.
1502 If YANK is non-nil, include the original article."
1503   (interactive "P")
1504   (let ((address
1505          (buffer-substring
1506           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1507           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1508     (when address
1509       (gnus-msg-mail address)
1510       (when yank
1511         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1512
1513 (defvar nntp-server-type)
1514 (defun gnus-bug ()
1515   "Send a bug report to the Gnus maintainers."
1516   (interactive)
1517   (unless (gnus-alive-p)
1518     (error "Gnus has been shut down"))
1519   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1520     (unless (message-mail-user-agent)
1521       (message-pop-to-buffer "*Gnus Bug*")
1522       (delete-other-windows)
1523       (when gnus-bug-create-help-buffer
1524         (switch-to-buffer "*Gnus Help Bug*")
1525         (erase-buffer)
1526         (insert gnus-bug-message)
1527         (goto-char (point-min))
1528         (sit-for 0)
1529         (set-buffer "*Gnus Bug*")))
1530     (let ((message-this-is-mail t))
1531       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1532     (when gnus-bug-create-help-buffer
1533       (push `(gnus-bug-kill-buffer) message-send-actions))
1534     (goto-char (point-min))
1535     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1536     (forward-line 1)
1537     (insert gnus-product-name " " gnus-version-number
1538             " (r" gnus-revision-number ") "
1539             "based on " gnus-original-product-name " v"
1540             gnus-original-version-number "\n"
1541             (emacs-version) "\n")
1542     (when (and (boundp 'nntp-server-type)
1543                (stringp nntp-server-type))
1544       (insert nntp-server-type))
1545     (insert "\n\n\n\n\n")
1546     (let (mime-content-types)
1547       (mime-edit-insert-tag
1548        "application" "emacs-lisp"
1549        "\nContent-Disposition: inline\nContent-Description: User settings"))
1550     (insert (with-temp-buffer
1551               (gnus-debug)
1552               (buffer-string)))
1553     (let (mime-content-types)
1554       (mime-edit-insert-tag "text" "plain"))
1555     (goto-char (point-min))
1556     (search-forward "Subject: " nil t)
1557     (message "")))
1558
1559 (defun gnus-bug-kill-buffer ()
1560   (when (get-buffer "*Gnus Help Bug*")
1561     (kill-buffer "*Gnus Help Bug*")))
1562
1563 (defun gnus-summary-yank-message (buffer n)
1564   "Yank the current article into a composed message."
1565   (interactive
1566    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1567          current-prefix-arg))
1568   (when (gnus-buffer-live-p buffer)
1569     (let ((summary-frame (selected-frame))
1570           (message-frame (when (static-if (featurep 'xemacs)
1571                                    (device-on-window-system-p)
1572                                  window-system)
1573                            (let ((window (get-buffer-window buffer t)))
1574                              (when window
1575                                (window-frame window)))))
1576           (separator (concat "^" (regexp-quote mail-header-separator)
1577                              "\n")))
1578       (gnus-summary-iterate n
1579         (gnus-summary-select-article)
1580         (gnus-copy-article-buffer)
1581         (when (frame-live-p message-frame)
1582           (raise-frame message-frame)
1583           (select-frame message-frame))
1584         (with-current-buffer buffer
1585           (when (save-excursion
1586                   (beginning-of-line)
1587                   (let (case-fold-search)
1588                     (and (not (re-search-backward separator nil t))
1589                          (re-search-forward separator nil t))))
1590             (goto-char (match-end 0)))
1591           (message-yank-buffer gnus-article-copy))
1592         (select-frame summary-frame))
1593       (when (frame-live-p message-frame)
1594         (select-frame message-frame)))))
1595
1596 (defun gnus-debug ()
1597   "Attempts to go through the Gnus source file and report what variables have been changed.
1598 The source file has to be in the Emacs load path."
1599   (interactive)
1600   (let ((files gnus-debug-files)
1601         (point (point))
1602         file expr olist sym)
1603     (gnus-message 4 "Please wait while we snoop your variables...")
1604     ;; Go through all the files looking for non-default values for variables.
1605     (save-excursion
1606       (sit-for 0)
1607       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1608       (while files
1609         (erase-buffer)
1610         (when (and (setq file (locate-library (pop files)))
1611                    (file-exists-p file))
1612           (insert-file-contents file)
1613           (goto-char (point-min))
1614           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1615               (gnus-message 4 "Malformed sources in file %s" file)
1616             (narrow-to-region (point-min) (point))
1617             (goto-char (point-min))
1618             (while (setq expr (ignore-errors (read (current-buffer))))
1619               (ignore-errors
1620                 (and (memq (car expr) '(defvar defcustom defvoo))
1621                      (stringp (nth 3 expr))
1622                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1623                      (or (not (boundp (nth 1 expr)))
1624                          (not (equal (eval (nth 2 expr))
1625                                      (symbol-value (nth 1 expr)))))
1626                      (push (nth 1 expr) olist)))))))
1627       (kill-buffer (current-buffer)))
1628     (when (setq olist (nreverse olist))
1629       (insert ";----------------- Environment follows ------------------\n\n"))
1630     (while olist
1631       (if (boundp (car olist))
1632           (condition-case ()
1633               (pp `(setq ,(car olist)
1634                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1635                                   (and (symbolp sym)
1636                                        (not (or (eq sym nil)
1637                                                 (eq sym t)))))
1638                               (list 'quote (symbol-value (car olist)))
1639                             (symbol-value (car olist))))
1640                   (current-buffer))
1641             (error
1642              (format "(setq %s 'whatever)\n" (car olist))))
1643         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1644       (setq olist (cdr olist)))
1645     ;; Remove any control chars - they seem to cause trouble for some
1646     ;; mailers.  (Byte-compiled output from the stuff above.)
1647     (goto-char point)
1648     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1649       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1650                      t t))
1651     ;; Break MIME tags purposely.
1652     (goto-char point)
1653     (while (re-search-forward mime-edit-tag-regexp nil t)
1654       (goto-char (1+ (match-beginning 0)))
1655       (insert "X"))))
1656
1657 ;;; Treatment of rejected articles.
1658 ;;; Bounced mail.
1659
1660 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1661   "Re-mail the current message.
1662 This only makes sense if the current message is a bounce message than
1663 contains some mail you have written which has been bounced back to
1664 you.
1665 If FETCH, try to fetch the article that this is a reply to, if indeed
1666 this is a reply."
1667   (interactive "P")
1668   (gnus-summary-select-article t)
1669   (set-buffer gnus-original-article-buffer)
1670   (gnus-setup-message 'compose-bounce
1671     (let* ((references (mail-fetch-field "references"))
1672            (parent (and references (gnus-parent-id references))))
1673       (message-bounce)
1674       ;; If there are references, we fetch the article we answered to.
1675       (and fetch parent
1676            (gnus-summary-refer-article parent)
1677            (gnus-summary-show-all-headers)))))
1678
1679 ;;; Gcc handling.
1680
1681 (defun gnus-inews-group-method (group)
1682   (cond
1683    ;; If the group doesn't exist, we assume
1684    ;; it's an archive group...
1685    ((and (null (gnus-get-info group))
1686          (eq (car (gnus-server-to-method gnus-message-archive-method))
1687              (car (gnus-server-to-method (gnus-group-method group)))))
1688     gnus-message-archive-method)
1689    ;; Use the method.
1690    ((gnus-info-method (gnus-get-info group))
1691     (gnus-info-method (gnus-get-info group)))
1692    ;; Find the method.
1693    (t (gnus-server-to-method (gnus-group-method group)))))
1694
1695 ;; Do Gcc handling, which copied the message over to some group.
1696 (defun gnus-inews-do-gcc (&optional gcc)
1697   (interactive)
1698   (save-excursion
1699     (save-restriction
1700       (message-narrow-to-headers)
1701       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1702             (coding-system-for-write 'raw-text)
1703             (output-coding-system 'raw-text)
1704             groups group method group-art
1705             mml-externalize-attachments)
1706         (when gcc
1707           (message-remove-header "gcc")
1708           (widen)
1709           (setq groups (message-unquote-tokens
1710                         (message-tokenize-header gcc " ,")))
1711           ;; Copy the article over to some group(s).
1712           (while (setq group (pop groups))
1713             (unless (gnus-check-server
1714                      (setq method (gnus-inews-group-method group)))
1715               (error "Can't open server %s" (if (stringp method) method
1716                                               (car method))))
1717             (unless (gnus-request-group group nil method)
1718               (gnus-request-create-group group method))
1719             (setq mml-externalize-attachments
1720                   (if (stringp gnus-gcc-externalize-attachments)
1721                       (string-match gnus-gcc-externalize-attachments group)
1722                     gnus-gcc-externalize-attachments))
1723             (save-excursion
1724               (nnheader-set-temp-buffer " *acc*")
1725               (insert-buffer-substring message-encoding-buffer)
1726               (gnus-run-hooks 'gnus-before-do-gcc-hook)
1727               (goto-char (point-min))
1728               (when (re-search-forward
1729                      (concat "^" (regexp-quote mail-header-separator) "$")
1730                      nil t)
1731                 (replace-match "" t t ))
1732               (unless (setq group-art
1733                             (gnus-request-accept-article group method t t))
1734                 (gnus-message 1 "Couldn't store article in group %s: %s"
1735                               group (gnus-status-message method))
1736                 (sit-for 2))
1737               (when (and group-art
1738                          (or gnus-gcc-mark-as-read
1739                              gnus-inews-mark-gcc-as-read))
1740                 (gnus-group-mark-article-read group (cdr group-art)))
1741               (kill-buffer (current-buffer)))))))))
1742
1743 (defun gnus-inews-insert-gcc ()
1744   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1745   (save-excursion
1746     (save-restriction
1747       (message-narrow-to-headers)
1748       (let* ((group gnus-outgoing-message-group)
1749              (gcc (cond
1750                    ((gnus-functionp group)
1751                     (funcall group))
1752                    ((or (stringp group) (list group))
1753                     group))))
1754         (when gcc
1755           (insert "Gcc: "
1756                   (if (stringp gcc) gcc
1757                     (mapconcat 'identity gcc " "))
1758                   "\n"))))))
1759
1760 (defun gnus-inews-insert-archive-gcc (&optional group)
1761   "Insert the Gcc to say where the article is to be archived."
1762   (let* ((var gnus-message-archive-group)
1763          (group (or group gnus-newsgroup-name ""))
1764          (gcc-self-val
1765           (and gnus-newsgroup-name
1766                (not (equal gnus-newsgroup-name ""))
1767                (gnus-group-find-parameter
1768                 gnus-newsgroup-name 'gcc-self)))
1769          result
1770          (groups
1771           (cond
1772            ((null gnus-message-archive-method)
1773             ;; Ignore.
1774             nil)
1775            ((stringp var)
1776             ;; Just a single group.
1777             (list var))
1778            ((null var)
1779             ;; We don't want this.
1780             nil)
1781            ((and (listp var) (stringp (car var)))
1782             ;; A list of groups.
1783             var)
1784            ((gnus-functionp var)
1785             ;; A function.
1786             (funcall var group))
1787            (t
1788             ;; An alist of regexps/functions/forms.
1789             (while (and var
1790                         (not
1791                          (setq result
1792                                (cond
1793                                 ((stringp (caar var))
1794                                  ;; Regexp.
1795                                  (when (string-match (caar var) group)
1796                                    (cdar var)))
1797                                 ((gnus-functionp (car var))
1798                                  ;; Function.
1799                                  (funcall (car var) group))
1800                                 (t
1801                                  (eval (car var)))))))
1802               (setq var (cdr var)))
1803             result)))
1804          name)
1805     (when (or groups gcc-self-val)
1806       (when (stringp groups)
1807         (setq groups (list groups)))
1808       (save-excursion
1809         (save-restriction
1810           (message-narrow-to-headers)
1811           (goto-char (point-max))
1812           (insert "Gcc: ")
1813           (if gcc-self-val
1814               ;; Use the `gcc-self' param value instead.
1815               (progn
1816                 (insert
1817                  (if (stringp gcc-self-val)
1818                      gcc-self-val
1819                    group))
1820                 (if (not (eq gcc-self-val 'none))
1821                     (insert "\n")
1822                   (progn
1823                     (beginning-of-line)
1824                     (kill-line))))
1825             ;; Use the list of groups.
1826             (while (setq name (pop groups))
1827               (insert (if (string-match ":" name)
1828                           name
1829                         (gnus-group-prefixed-name
1830                          name gnus-message-archive-method)))
1831               (when groups
1832                 (insert " ")))
1833             (insert "\n")))))))
1834
1835 ;;; Posting styles.
1836
1837 (defun gnus-configure-posting-styles (&optional group-name)
1838   "Configure posting styles according to `gnus-posting-styles'."
1839   (unless gnus-inhibit-posting-styles
1840     (let ((group (or group-name gnus-newsgroup-name ""))
1841           (styles gnus-posting-styles)
1842           style match variable attribute value v results
1843           filep name address element)
1844       ;; If the group has a posting-style parameter, add it at the end with a
1845       ;; regexp matching everything, to be sure it takes precedence over all
1846       ;; the others.
1847       (when gnus-newsgroup-name
1848         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1849           (when tmp-style
1850             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1851       ;; Go through all styles and look for matches.
1852       (dolist (style styles)
1853         (setq match (pop style))
1854         (goto-char (point-min))
1855         (when (cond
1856                ((stringp match)
1857                 ;; Regexp string match on the group name.
1858                 (string-match match group))
1859                ((eq match 'header)
1860                 ;; Obsolete format of header match.
1861                 (and (gnus-buffer-live-p gnus-article-copy)
1862                      (with-current-buffer gnus-article-copy
1863                        (let ((header (message-fetch-field (pop style))))
1864                          (and header
1865                               (string-match (pop style) header))))))
1866                ((or (symbolp match)
1867                     (gnus-functionp match))
1868                 (cond
1869                  ((gnus-functionp match)
1870                   ;; Function to be called.
1871                   (funcall match))
1872                  ((boundp match)
1873                   ;; Variable to be checked.
1874                   (symbol-value match))))
1875                ((listp match)
1876                 (cond
1877                  ((eq (car match) 'header)
1878                   ;; New format of header match.
1879                   (and (gnus-buffer-live-p gnus-article-copy)
1880                        (with-current-buffer gnus-article-copy
1881                          (let ((header (message-fetch-field (nth 1 match))))
1882                            (and header
1883                                 (string-match (nth 2 match) header))))))
1884                  (t
1885                   ;; This is a form to be evaled.
1886                   (eval match)))))
1887           ;; We have a match, so we set the variables.
1888           (dolist (attribute style)
1889             (setq element (pop attribute)
1890                   variable nil
1891                   filep nil)
1892             (setq value
1893                   (cond
1894                    ((eq (car attribute) ':file)
1895                     (setq filep t)
1896                     (cadr attribute))
1897                    ((eq (car attribute) :value)
1898                     (cadr attribute))
1899                    (t
1900                     (car attribute))))
1901             ;; We get the value.
1902             (setq v
1903                   (cond
1904                    ((stringp value)
1905                     value)
1906                    ((or (symbolp value)
1907                         (gnus-functionp value))
1908                     (cond ((gnus-functionp value)
1909                            (funcall value))
1910                           ((boundp value)
1911                            (symbol-value value))))
1912                    ((listp value)
1913                     (eval value))))
1914             ;; Translate obsolescent value.
1915             (cond
1916              ((eq element 'signature-file)
1917               (setq element 'signature
1918                     filep t))
1919              ((eq element 'x-face-file)
1920               (setq element 'x-face
1921                     filep t)))
1922             ;; Get the contents of file elems.
1923             (when (and filep v)
1924               (setq v (with-temp-buffer
1925                         (insert-file-contents v)
1926                         (goto-char (point-max))
1927                         (while (bolp)
1928                           (delete-char -1))
1929                         (buffer-string))))
1930             (setq results (delq (assoc element results) results))
1931             (push (cons element v) results))))
1932       ;; Now we have all the styles, so we insert them.
1933       (setq name (assq 'name results)
1934             address (assq 'address results))
1935       (setq results (delq name (delq address results)))
1936       ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1937       (make-local-hook 'message-setup-hook)
1938       (dolist (result results)
1939         (add-hook 'message-setup-hook
1940                   (cond
1941                    ((eq 'eval (car result))
1942                     'ignore)
1943                    ((eq 'body (car result))
1944                     `(lambda ()
1945                        (save-excursion
1946                          (message-goto-body)
1947                          (insert ,(cdr result)))))
1948                    ((eq 'signature (car result))
1949                     (set (make-local-variable 'message-signature) nil)
1950                     (set (make-local-variable 'message-signature-file) nil)
1951                     (if (not (cdr result))
1952                         'ignore
1953                       `(lambda ()
1954                          (save-excursion
1955                            (let ((message-signature ,(cdr result)))
1956                              (when message-signature
1957                                (message-insert-signature)))))))
1958                    (t
1959                     (let ((header
1960                            (if (symbolp (car result))
1961                                (capitalize (symbol-name (car result)))
1962                              (car result))))
1963                       `(lambda ()
1964                          (save-excursion
1965                            (message-remove-header ,header)
1966                            (let ((value ,(cdr result)))
1967                              (when value
1968                                (message-goto-eoh)
1969                                (insert ,header ": " value "\n"))))))))
1970                   nil 'local))
1971       (when (or name address)
1972         (add-hook 'message-setup-hook
1973                   `(lambda ()
1974                      (set (make-local-variable 'user-mail-address)
1975                           ,(or (cdr address) user-mail-address))
1976                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1977                            (user-mail-address
1978                             ,(or (cdr address) user-mail-address)))
1979                        (save-excursion
1980                          (message-remove-header "From")
1981                          (message-goto-eoh)
1982                          (insert "From: " (message-make-from) "\n"))))
1983                   nil 'local)))))
1984
1985
1986 ;;; @ for MIME Edit mode
1987 ;;;
1988
1989 (defun gnus-maybe-setup-default-charset ()
1990   (let ((charset
1991          (and (boundp 'gnus-summary-buffer)
1992               (buffer-live-p gnus-summary-buffer)
1993               (save-excursion
1994                 (set-buffer gnus-summary-buffer)
1995                 default-mime-charset))))
1996     (if charset
1997         (progn
1998           (make-local-variable 'default-mime-charset)
1999           (setq default-mime-charset charset)
2000           ))))
2001
2002
2003 ;;; @ for MIME view mode
2004 ;;;
2005
2006 (defun gnus-following-method (buf)
2007   (gnus-setup-message 'reply-yank
2008     (set-buffer buf)
2009     (if (message-news-p)
2010         (message-followup)
2011       (message-reply nil 'wide))
2012     (let ((message-reply-buffer buf))
2013       (message-yank-original))
2014     (message-goto-body))
2015   (kill-buffer buf))
2016
2017
2018 ;;; Allow redefinition of functions.
2019
2020 (gnus-ems-redefine)
2021
2022 (provide 'gnus-msg)
2023
2024 ;;; gnus-msg.el ends here