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