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