1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
43 (defcustom gnus-post-method 'current
44 "*Preferred method for posting USENET news.
46 If this variable is `current' (which is the default), Gnus will use
47 the \"current\" select method when posting. If it is `native', Gnus
48 will use the native select method when posting.
50 This method will not be used in mail groups and the like, only in
53 If not `native' nor `current', the value must be a valid method as discussed
54 in the documentation of `gnus-select-method'. It can also be a list of
55 methods. If that is the case, the user will be queried for what select
56 method to use when posting."
57 :group 'gnus-group-foreign
58 :link '(custom-manual "(gnus)Posting Server")
59 :type `(choice (const native)
61 (sexp :tag "Methods" ,gnus-select-method)))
63 (defcustom gnus-outgoing-message-group nil
64 "*All outgoing messages will be put in this group.
65 If you want to store all your outgoing mail and articles in the group
66 \"nnml:archive\", you set this variable to that value. This variable
67 can also be a list of group names.
69 If you want to have greater control over what group to put each
70 message in, you can set this variable to a function that checks the
71 current newsgroup name and then returns a suitable group name (or list
74 :type '(choice (string :tag "Group")
77 (defcustom gnus-mailing-list-groups nil
78 "*If non-nil a regexp matching groups that are really mailing lists.
79 This is useful when you're reading a mailing list that has been
80 gatewayed to a newsgroup, and you want to followup to an article in
83 :type '(choice (regexp)
86 (defcustom gnus-add-to-list nil
87 "*If non-nil, add a `to-list' parameter automatically."
91 (defcustom gnus-crosspost-complaint
94 You posted the article below with the following Newsgroups header:
98 The %s group, at least, was an inappropriate recipient
99 of this message. Please trim your Newsgroups header to exclude this
100 group before posting in the future.
105 "Format string to be inserted when complaining about crossposts.
106 The first %s will be replaced by the Newsgroups header;
107 the second with the current group name."
111 (defcustom gnus-message-setup-hook nil
112 "Hook run after setting up a message buffer."
116 (defcustom gnus-bug-create-help-buffer t
117 "*Should we create the *Gnus Help Bug* buffer?"
121 (defcustom gnus-posting-styles nil
122 "*Alist of styles to use when posting.
123 See Info node `(gnus)Posting Styles'."
125 :link '(custom-manual "(gnus)Posting Styles")
126 :type '(repeat (cons (choice (regexp)
129 (string :tag "Header")
130 (regexp :tag "Regexp"))
134 (choice (const signature)
135 (const signature-file)
143 (string :tag "Header"))
149 (defcustom gnus-named-posting-styles nil
150 "Alist mapping names to the user-defined posting styles."
152 :type '(repeat (cons string
154 (choice (const signature)
155 (const signature-file)
163 (string :tag "Header"))
169 (defcustom gnus-gcc-mark-as-read nil
170 "If non-nil, automatically mark Gcc articles as read."
175 (defvar gnus-inews-mark-gcc-as-read nil
176 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
178 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
179 'gnus-gcc-mark-as-read)
181 (defcustom gnus-gcc-externalize-attachments nil
182 "Should local-file attachments be included as external parts in Gcc copies?
183 If it is `all', attach files as external parts;
184 if a regexp and matches the Gcc group name, attach files as external parts;
185 if nil, attach files as normal parts."
188 :type '(choice (const nil :tag "None")
189 (const all :tag "Any")
190 (string :tag "Regexp")))
192 (gnus-define-group-parameter
193 posting-charset-alist
196 "Return the permitted unencoded charsets for posting of GROUP."
197 :variable gnus-group-posting-charset-alist
199 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
200 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
201 (message-this-is-mail nil nil)
202 (message-this-is-news nil t))
204 "Alist of regexps and permitted unencoded charsets for posting.
205 Each element of the alist has the form (TEST HEADER BODY-LIST), where
206 TEST is either a regular expression matching the newsgroup header or a
208 HEADER is the charset which may be left unencoded in the header (nil
209 means encode all charsets),
210 BODY-LIST is a list of charsets which may be encoded using 8bit
211 content-transfer encoding in the body, or one of the special values
212 nil (always encode using quoted-printable) or t (always use 8bit).
214 Note that any value other than nil for HEADER infringes some RFCs, so
215 use this option with care."
216 :variable-group gnus-charset
218 '(repeat (list :tag "Permitted unencoded charsets"
220 (regexp :tag "Group")
221 (const :tag "Mail message" :value message-this-is-mail)
222 (const :tag "News article" :value message-this-is-news))
223 (choice :tag "Header"
224 (const :tag "None" nil)
225 (symbol :tag "Charset"))
227 (const :tag "Any" :value t)
228 (const :tag "None" :value nil)
229 (repeat :tag "Charsets"
230 (symbol :tag "Charset")))))
231 :parameter-type '(choice :tag "Permitted unencoded charsets"
234 :parameter-document "\
235 List of charsets that are permitted to be unencoded.")
237 (defcustom gnus-debug-files
238 '("gnus.el" "gnus-sum.el" "gnus-group.el"
239 "gnus-art.el" "gnus-start.el" "gnus-async.el"
240 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
241 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
242 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
243 "Files whose variables will be reported in `gnus-bug'."
246 :type '(repeat (string :tag "File")))
248 (defcustom gnus-debug-exclude-variables
249 '(mm-mime-mule-charset-alist
250 nnmail-split-fancy message-minibuffer-local-map)
251 "Variables that should not be reported in `gnus-bug'."
254 :type '(repeat (symbol :tag "Variable")))
256 (defcustom gnus-discouraged-post-methods
257 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
258 "A list of back ends that are not used in \"real\" newsgroups.
259 This variable is used only when `gnus-post-method' is `current'."
261 :group 'gnus-group-foreign
262 :type '(repeat (symbol :tag "Back end")))
264 (defcustom gnus-message-replysign
266 "Automatically sign replies to signed messages.
267 See also the `mml-default-sign-method' variable."
271 (defcustom gnus-message-replyencrypt
273 "Automatically encrypt replies to encrypted messages.
274 See also the `mml-default-encrypt-method' variable."
278 (defcustom gnus-message-replysignencrypted
280 "Setting this causes automatically encryped messages to also be signed."
284 (defcustom gnus-confirm-mail-reply-to-news nil
285 "If non-nil, Gnus requests confirmation when replying to news.
286 This is done because new users often reply by mistake when reading
288 This can also be a function receiving the group name as the only
289 parameter which should return non-nil iff a confirmation is needed, or
290 a regexp, in which case a confirmation is asked for iff the group name
293 :type '(choice (const :tag "No" nil)
295 (regexp :tag "Iff group matches regexp")
296 (function :tag "Iff function evaluates to non-nil")))
298 (defcustom gnus-confirm-treat-mail-like-news
300 "If non-nil, Gnus will treat mail like news with regard to confirmation
301 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
302 for fine-tuning this.
303 If nil, Gnus will never ask for confirmation if replying to mail."
307 (defcustom gnus-summary-resend-default-address t
308 "If non-nil, Gnus tries to suggest a default address to resend to.
309 If nil, the address field will always be empty after invoking
310 `gnus-summary-resend-message'."
314 (defcustom gnus-user-agent 'emacs-gnus-type
315 "Which information should be exposed in the User-Agent header.
317 It can be one of the symbols `gnus' \(show only Gnus version\), `emacs-gnus'
318 \(show only Emacs and Gnus versions\), `emacs-gnus-config' \(same as
319 `emacs-gnus' plus system configuration\), `emacs-gnus-type' \(same as
320 `emacs-gnus' plus system type\) or a custom string. If you set it to a
321 string, be sure to use a valid format, see RFC 2616."
324 (item :tag "Show Gnus and Emacs versions and system type"
326 (item :tag "Show Gnus and Emacs versions and system configuration"
328 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
329 (item :tag "Show only Gnus version" gnus)
330 (string :tag "Other")))
332 ;;; Internal variables.
334 (defvar gnus-inhibit-posting-styles nil
335 "Inhibit the use of posting styles.")
337 (defvar gnus-article-yanked-articles nil)
338 (defvar gnus-message-buffer "*Mail Gnus*")
339 (defvar gnus-article-copy nil)
340 (defvar gnus-check-before-posting nil)
341 (defvar gnus-last-posting-server nil)
342 (defvar gnus-message-group-art nil)
344 (defvar gnus-msg-force-broken-reply-to nil)
346 (defconst gnus-bug-message
347 (format "Sending a bug report to the Gnus Towers.
348 ========================================
350 This gnus is the %s%s.
351 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
352 Developers. (the addresses below are mailing list addresses)
354 ========================================
356 The buffer below is a mail buffer. When you press `C-c C-c', it will
357 be sent to the Gnus Bug Exterminators.
359 The thing near the bottom of the buffer is how the environment
360 settings will be included in the mail. Please do not delete that.
361 They will tell the Bug People what your environment is, so that it
362 will be easier to locate the bugs.
364 If you have found a bug that makes Emacs go \"beep\", set
365 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
366 and include the backtrace in your bug report.
368 Please describe the bug in annoying, painstaking detail.
370 Thank you for your help in stamping out bugs.
373 (if (string= gnus-product-name "Semi-gnus")
375 ", a modified version of Semi-gnus")))
378 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
379 (autoload 'news-setup "rnewspost")
380 (autoload 'news-reply-mode "rnewspost")
381 (autoload 'rmail-dont-reply-to "mail-utils")
382 (autoload 'rmail-output "rmailout"))
386 ;;; Gnus Posting Functions
389 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
390 "p" gnus-summary-post-news
391 "i" gnus-summary-news-other-window
392 "f" gnus-summary-followup
393 "F" gnus-summary-followup-with-original
394 "c" gnus-summary-cancel-article
395 "s" gnus-summary-supersede-article
396 "r" gnus-summary-reply
397 "y" gnus-summary-yank-message
398 "R" gnus-summary-reply-with-original
399 "w" gnus-summary-wide-reply
400 "W" gnus-summary-wide-reply-with-original
401 "v" gnus-summary-very-wide-reply
402 "V" gnus-summary-very-wide-reply-with-original
403 "n" gnus-summary-followup-to-mail
404 "N" gnus-summary-followup-to-mail-with-original
405 "m" gnus-summary-mail-other-window
406 "u" gnus-uu-post-news
407 "\M-c" gnus-summary-mail-crosspost-complaint
408 "Br" gnus-summary-reply-broken-reply-to
409 "BR" gnus-summary-reply-broken-reply-to-with-original
410 "om" gnus-summary-mail-forward
411 "op" gnus-summary-post-forward
412 "Om" gnus-summary-digest-mail-forward
413 "Op" gnus-summary-digest-post-forward
414 "P" gnus-summary-execute-command-with-posting-style)
416 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
417 "b" gnus-summary-resend-bounced-mail
418 ;; "c" gnus-summary-send-draft
419 "r" gnus-summary-resend-message
420 "e" gnus-summary-resend-message-edit)
422 ;;; Internal functions.
424 (defun gnus-inews-make-draft ()
426 (gnus-inews-make-draft-meta-information
427 ,gnus-newsgroup-name ',gnus-article-reply)))
429 (defvar gnus-article-reply nil)
430 (defmacro gnus-setup-message (config &rest forms)
431 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
432 (buffer (make-symbol "gnus-setup-message-buffer"))
433 (article (make-symbol "gnus-setup-message-article"))
434 (yanked (make-symbol "gnus-setup-yanked-articles"))
435 (group (make-symbol "gnus-setup-message-group")))
436 `(let ((,winconf (current-window-configuration))
437 (,buffer (buffer-name (current-buffer)))
438 (,article gnus-article-reply)
439 (,yanked gnus-article-yanked-articles)
440 (,group gnus-newsgroup-name)
441 (message-header-setup-hook
442 (copy-sequence message-header-setup-hook))
443 (message-mode-hook (copy-sequence message-mode-hook))
444 (message-startup-parameter-alist
445 '((reply-buffer . gnus-copy-article-buffer)
446 (original-buffer . gnus-original-article-buffer)
447 (user-agent . Gnus))))
448 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
449 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
450 ;; #### FIXME: for a reason that I did not manage to identify yet,
451 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
452 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
453 ;; After evaluation of @forms below, it gets the value we actually want
454 ;; to override, and the posting styles are used. For that reason, I've
455 ;; added an optional argument to `gnus-configure-posting-styles' to
456 ;; make sure that the correct value for the group name is used. -- drv
457 (add-hook 'message-mode-hook
459 (gnus-configure-posting-styles ,group)))
460 (gnus-pull ',(intern gnus-draft-meta-information-header)
461 message-required-headers)
463 (not (string= ,group "")))
465 (intern gnus-draft-meta-information-header)
466 (gnus-inews-make-draft))
467 message-required-headers))
471 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
473 (setq gnus-message-buffer (current-buffer))
474 (set (make-local-variable 'gnus-message-group-art)
475 (cons ,group ,article))
476 (set (make-local-variable 'gnus-newsgroup-name) ,group)
477 (gnus-maybe-setup-default-charset)
478 (gnus-run-hooks 'gnus-message-setup-hook))
479 (message-hide-headers)
481 (gnus-configure-windows ,config t)
482 (run-hooks 'post-command-hook)
483 (set-buffer-modified-p nil))))
485 (defun gnus-inews-make-draft-meta-information (group article)
486 (concat "(\"" group "\" "
487 (if article (number-to-string
494 (defun gnus-msg-mail (&optional to subject other-headers continue
495 switch-action yank-action send-actions)
496 "Start editing a mail message to be sent.
497 Like `message-mail', but with Gnus paraphernalia, particularly the
498 Gcc: header for archiving purposes."
500 (let ((buf (current-buffer))
502 (gnus-setup-message 'message
503 (message-mail to subject other-headers continue
504 nil yank-action send-actions))
506 (setq mail-buf (current-buffer))
507 (switch-to-buffer buf)
508 (apply switch-action mail-buf nil)))
509 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
512 (defvar save-selected-window-window)
515 (defun gnus-button-mailto (address)
517 (set-buffer (gnus-copy-article-buffer))
518 (gnus-setup-message 'message
519 (message-reply address))
520 (and (boundp 'save-selected-window-window)
521 (not (window-live-p save-selected-window-window))
522 (setq save-selected-window-window (selected-window))))
525 (defun gnus-button-reply (&optional to-address wide)
526 "Like `message-reply'."
528 (gnus-setup-message 'message
529 (message-reply to-address wide))
530 (and (boundp 'save-selected-window-window)
531 (not (window-live-p save-selected-window-window))
532 (setq save-selected-window-window (selected-window))))
535 (define-mail-user-agent 'gnus-user-agent
536 'gnus-msg-mail 'message-send-and-exit
537 'message-kill-buffer 'message-send-hook)
539 (defun gnus-setup-posting-charset (group)
540 (let ((alist gnus-group-posting-charset-alist)
541 (group (or group ""))
545 (while (setq elem (pop alist))
546 (when (or (and (stringp (car elem))
547 (string-match (car elem) group))
548 (and (gnus-functionp (car elem))
549 (funcall (car elem) group))
550 (and (symbolp (car elem))
551 (symbol-value (car elem))))
552 (throw 'found (cons (cadr elem) (caddr elem)))))))))
554 (defun gnus-inews-add-send-actions (winconf buffer article
555 &optional config yanked)
556 (make-local-hook 'message-sent-hook)
557 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
558 'gnus-inews-do-gcc) nil t)
560 (make-local-hook 'message-header-hook)
561 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
562 (setq message-post-method
564 (gnus-post-method arg ,gnus-newsgroup-name)))
565 (setq message-user-agent (gnus-extended-version))
566 (unless message-use-multi-frames
568 `(if (gnus-buffer-exists-p ,buffer)
569 (set-window-configuration ,winconf))
570 'exit 'postpone 'kill))
571 (let ((to-be-marked (cond
573 (article (if (listp article) article (list article)))
576 `(when (gnus-buffer-exists-p ,buffer)
580 (if (eq config 'forward)
581 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
582 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
585 (put 'gnus-setup-message 'lisp-indent-function 1)
586 (put 'gnus-setup-message 'edebug-form-spec '(form body))
588 ;;; Post news commands of Gnus group mode and summary mode
590 (defun gnus-group-mail (&optional arg)
591 "Start composing a mail.
592 If ARG, use the group under the point to find a posting style.
593 If ARG is 1, prompt for a group name to find the posting style."
595 ;; We can't `let' gnus-newsgroup-name here, since that leads
596 ;; to local variables leaking.
597 (let ((group gnus-newsgroup-name)
598 ;; make sure last viewed article doesn't affect posting styles:
600 (buffer (current-buffer)))
603 (setq gnus-newsgroup-name
605 (if (= 1 (prefix-numeric-value arg))
606 (completing-read "Use posting style of group: "
607 gnus-active-hashtb nil
608 (gnus-read-active-file-p))
609 (gnus-group-group-name))
611 ;; #### see comment in gnus-setup-message -- drv
612 (gnus-setup-message 'message (message-mail)))
615 (setq gnus-newsgroup-name group)))))
617 (defun gnus-group-news (&optional arg)
618 "Start composing a news.
619 If ARG, post to group under point.
620 If ARG is 1, prompt for group name to post to.
622 This function prepares a news even when using mail groups. This is useful
623 for posting messages to mail groups without actually sending them over the
624 network. The corresponding backend must have a 'request-post method."
626 ;; We can't `let' gnus-newsgroup-name here, since that leads
627 ;; to local variables leaking.
628 (let ((group gnus-newsgroup-name)
629 ;; make sure last viewed article doesn't affect posting styles:
631 (buffer (current-buffer)))
634 (setq gnus-newsgroup-name
636 (if (= 1 (prefix-numeric-value arg))
637 (completing-read "Use group: "
638 gnus-active-hashtb nil
639 (gnus-read-active-file-p))
640 (gnus-group-group-name))
642 ;; #### see comment in gnus-setup-message -- drv
643 (gnus-setup-message 'message
644 (message-news (gnus-group-real-name gnus-newsgroup-name))))
647 (setq gnus-newsgroup-name group)))))
649 (defun gnus-group-post-news (&optional arg)
650 "Start composing a message (a news by default).
651 If ARG, post to group under point. If ARG is 1, prompt for group name.
652 Depending on the selected group, the message might be either a mail or
655 ;; Bind this variable here to make message mode hooks work ok.
656 (let ((gnus-newsgroup-name
658 (if (= 1 (prefix-numeric-value arg))
659 (completing-read "Newsgroup: " gnus-active-hashtb nil
660 (gnus-read-active-file-p))
661 (gnus-group-group-name))
663 ;; make sure last viewed article doesn't affect posting styles:
665 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
666 (string= gnus-newsgroup-name ""))))
668 (defun gnus-summary-mail-other-window (&optional arg)
669 "Start composing a mail in another window.
670 Use the posting of the current group by default.
671 If ARG, don't do that. If ARG is 1, prompt for group name to find the
674 ;; We can't `let' gnus-newsgroup-name here, since that leads
675 ;; to local variables leaking.
676 (let ((group gnus-newsgroup-name)
677 ;; make sure last viewed article doesn't affect posting styles:
679 (buffer (current-buffer)))
682 (setq gnus-newsgroup-name
684 (if (= 1 (prefix-numeric-value arg))
685 (completing-read "Use group: "
686 gnus-active-hashtb nil
687 (gnus-read-active-file-p))
689 gnus-newsgroup-name))
690 ;; #### see comment in gnus-setup-message -- drv
691 (gnus-setup-message 'message (message-mail)))
694 (setq gnus-newsgroup-name group)))))
696 (defun gnus-summary-news-other-window (&optional arg)
697 "Start composing a news in another window.
698 Post to the current group by default.
699 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
701 This function prepares a news even when using mail groups. This is useful
702 for posting messages to mail groups without actually sending them over the
703 network. The corresponding backend must have a 'request-post method."
705 ;; We can't `let' gnus-newsgroup-name here, since that leads
706 ;; to local variables leaking.
707 (let ((group gnus-newsgroup-name)
708 ;; make sure last viewed article doesn't affect posting styles:
710 (buffer (current-buffer)))
713 (setq gnus-newsgroup-name
715 (if (= 1 (prefix-numeric-value arg))
716 (completing-read "Use group: "
717 gnus-active-hashtb nil
718 (gnus-read-active-file-p))
720 gnus-newsgroup-name))
721 ;; #### see comment in gnus-setup-message -- drv
722 (gnus-setup-message 'message
723 (message-news (gnus-group-real-name gnus-newsgroup-name))))
726 (setq gnus-newsgroup-name group)))))
728 (defun gnus-summary-post-news (&optional arg)
729 "Start composing a message. Post to the current group by default.
730 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
731 Depending on the selected group, the message might be either a mail or
734 ;; Bind this variable here to make message mode hooks work ok.
735 (let ((gnus-newsgroup-name
737 (if (= 1 (prefix-numeric-value arg))
738 (completing-read "Newsgroup: " gnus-active-hashtb nil
739 (gnus-read-active-file-p))
741 gnus-newsgroup-name))
742 ;; make sure last viewed article doesn't affect posting styles:
744 (gnus-post-news 'post gnus-newsgroup-name)))
747 (defun gnus-summary-followup (yank &optional force-news)
748 "Compose a followup to an article.
749 If prefix argument YANK is non-nil, the original article is yanked
751 YANK is a list of elements, where the car of each element is the
752 article number, and the two following numbers is the region to be
755 (list (and current-prefix-arg
756 (gnus-summary-work-articles 1))))
758 (gnus-summary-goto-subject
759 (if (listp (car yank))
762 (save-window-excursion
763 (gnus-summary-select-article))
764 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
765 (gnus-newsgroup-name gnus-newsgroup-name))
767 (gnus-post-news nil gnus-newsgroup-name
768 headers gnus-article-buffer
770 (gnus-summary-handle-replysign)))
772 (defun gnus-summary-followup-with-original (n &optional force-news)
773 "Compose a followup to an article and include the original article."
775 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
777 (defun gnus-summary-followup-to-mail (&optional arg)
778 "Followup to the current mail message via news."
780 (list (and current-prefix-arg
781 (gnus-summary-work-articles 1))))
782 (gnus-summary-followup arg t))
784 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
785 "Followup to the current mail message via news."
787 (gnus-summary-followup (gnus-summary-work-articles arg) t))
789 (defun gnus-inews-yank-articles (articles)
790 (let (beg article yank-string
791 (more-than-one (cdr articles))
792 (cur (current-buffer))
795 (while (setq article (pop articles))
796 (when (listp article)
797 (setq yank-string (nth 1 article)
798 article (nth 0 article)))
799 (save-window-excursion
800 (set-buffer gnus-summary-buffer)
801 (gnus-summary-select-article nil nil nil article)
802 (gnus-summary-remove-process-mark article))
804 ;; Gathering references.
806 (setq refs (message-list-references
808 (mail-header-references gnus-current-headers)
809 (mail-header-message-id gnus-current-headers)))
810 (when message-use-multi-frames
811 (when (setq window (get-buffer-window cur t))
812 (select-frame (window-frame window)))))
814 (gnus-copy-article-buffer nil yank-string)
815 (let ((message-reply-buffer gnus-article-copy)
816 (message-reply-headers
817 ;; The headers are decoded.
818 (with-current-buffer gnus-article-copy
820 (nnheader-narrow-to-headers)
821 (nnheader-parse-naked-head)))))
822 (message-yank-original)
823 (setq beg (or beg (mark t))))
828 ;; Replace with the gathered references.
832 (message-narrow-to-headers)
833 (let ((case-fold-search t))
834 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
836 (goto-char (point-max))))
838 (list (or (assq 'References message-header-format-alist)
839 '(References . message-shorten-references)))
840 (list (cons 'References
841 (mapconcat 'identity (nreverse refs) " "))))
842 (backward-delete-char 1))
848 (defun gnus-summary-cancel-article (&optional n symp)
849 "Cancel an article you posted.
850 Uses the process-prefix convention. If given the symbolic
851 prefix `a', cancel using the standard posting method; if not
852 post using the current select method."
853 (interactive (gnus-interactive "P\ny"))
854 (let ((articles (gnus-summary-work-articles n))
857 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
859 (while (setq article (pop articles))
860 (when (gnus-summary-select-article t nil nil article)
861 (when (gnus-eval-in-buffer-window gnus-article-buffer
863 (set-buffer gnus-original-article-buffer)
864 (message-cancel-news)))
865 (gnus-summary-mark-as-read article gnus-canceled-mark)
866 (gnus-cache-remove-article 1))
867 (gnus-article-hide-headers-if-wanted))
868 (gnus-summary-remove-process-mark article))))
870 (defun gnus-summary-supersede-article ()
871 "Compose an article that will supersede a previous article.
872 This is done simply by taking the old article and adding a Supersedes
873 header line with the old Message-ID."
875 (let ((article (gnus-summary-article-number)))
876 (gnus-setup-message 'reply-yank
877 (gnus-summary-select-article t)
878 (set-buffer gnus-original-article-buffer)
882 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
884 (set-buffer ,gnus-summary-buffer)
885 (gnus-cache-possibly-remove-article ,article nil nil nil t)
886 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
887 message-send-actions))))
891 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
892 ;; make a copy of the article buffer with all text properties removed
893 ;; this copy is in the buffer gnus-article-copy.
894 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
895 ;; this buffer should be passed to all mail/news reply/post routines.
896 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
898 (set-buffer gnus-article-copy)
899 (set-buffer-multibyte t))
900 (let ((article-buffer (or article-buffer gnus-article-buffer))
902 (if (not (and (get-buffer article-buffer)
903 (gnus-buffer-exists-p article-buffer)))
904 (error "Can't find any article buffer")
906 (set-buffer article-buffer)
907 (let ((gnus-newsgroup-charset (or gnus-article-charset
908 gnus-newsgroup-charset))
909 (gnus-newsgroup-ignored-charsets
910 (or gnus-article-ignored-charsets
911 gnus-newsgroup-ignored-charsets)))
913 ;; Copy over the (displayed) article buffer, delete
914 ;; hidden text and remove text properties.
916 (copy-to-buffer gnus-article-copy (point-min) (point-max))
917 (set-buffer gnus-article-copy)
918 ;; There's invisible and intangible text in T-gnus. Especially,
919 ;; if there is a boundary line (X-Boundary: ------------------),
920 ;; in the end of a header, it will cause a serious problem.
921 (add-text-properties (point-min) (point-max)
922 '(invisible nil intangible nil))
925 (delete-region (point) (point-max))
926 (insert yank-string))
927 ;; Encode bitmap smileys to ordinary text.
928 ;; Possibly, the original text might be restored.
929 (static-unless (featurep 'xemacs)
930 (when (featurep 'smiley-mule)
931 (smiley-encode-buffer)))
932 (gnus-article-delete-text-of-type 'annotation)
933 (gnus-remove-text-with-property 'gnus-prev)
934 (gnus-remove-text-with-property 'gnus-next)
935 (gnus-remove-text-with-property 'gnus-decoration)
936 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
939 (static-if (featurep 'xemacs)
940 ;; Revome smiley extents for (possibly) XEmacs 21.1.
942 (buffer-substring-no-properties (point-min)
944 (buffer-substring-no-properties (point-min) (point-max)))
946 ;; Find the original headers.
947 (set-buffer gnus-original-article-buffer)
948 (goto-char (point-min))
949 (while (looking-at message-unix-mail-delimiter)
951 (let ((mail-header-separator ""))
953 end (or (message-goto-body)
954 ;; There may be just a header.
956 ;; Delete the headers from the displayed articles.
957 (set-buffer gnus-article-copy)
958 (let ((mail-header-separator ""))
959 (delete-region (goto-char (point-min))
960 (or (message-goto-body) (point-max))))
961 ;; Insert the original article headers.
962 (insert-buffer-substring gnus-original-article-buffer beg end)
964 (let ((gnus-article-decode-hook
965 (delq 'article-decode-charset
966 (copy-sequence gnus-article-decode-hook))))
967 ;; Needed for T-gnus.
968 (add-hook 'gnus-article-decode-hook
969 'article-decode-encoded-words)
970 (run-hooks 'gnus-article-decode-hook)))))
973 (defun gnus-post-news (post &optional group header article-buffer yank subject
976 (gnus-copy-article-buffer))
977 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
978 (gnus-article-yanked-articles yank)
979 (add-to-list gnus-add-to-list))
980 (gnus-setup-message (cond (yank 'reply-yank)
981 (article-buffer 'reply)
983 (let* ((group (or group gnus-newsgroup-name))
984 (charset (gnus-group-name-charset nil group))
986 to-address to-group mailing-list to-list
989 (setq to-address (gnus-parameter-to-address group)
990 to-group (gnus-group-find-parameter group 'to-group)
991 to-list (gnus-parameter-to-list group)
992 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
993 mailing-list (when gnus-mailing-list-groups
994 (string-match gnus-mailing-list-groups group))
995 group (gnus-group-name-decode (gnus-group-real-name group)
997 (if (or (and to-group
998 (gnus-news-group-p to-group))
1001 (and (gnus-news-group-p
1002 (or pgroup gnus-newsgroup-name)
1003 (or header gnus-current-article))
1009 (message-news (or to-group group))
1010 (set-buffer gnus-article-copy)
1011 (gnus-msg-treat-broken-reply-to)
1012 (message-followup (if (or newsgroup-p force-news)
1013 (if (save-restriction
1014 (article-narrow-to-head)
1015 (message-fetch-field "newsgroups"))
1022 (message-mail (or to-address to-list))
1023 ;; Arrange for mail groups that have no `to-address' to
1024 ;; get that when the user sends off the mail.
1025 (when (and (not to-list)
1028 (push (list 'gnus-inews-add-to-address pgroup)
1029 message-send-actions)))
1030 (set-buffer gnus-article-copy)
1031 (gnus-msg-treat-broken-reply-to)
1032 (message-wide-reply to-address)))
1034 (gnus-inews-yank-articles yank))))))
1036 (defun gnus-msg-treat-broken-reply-to (&optional force)
1037 "Remove the Reply-to header if broken-reply-to."
1039 (gnus-group-find-parameter
1040 gnus-newsgroup-name 'broken-reply-to))
1042 (message-narrow-to-head)
1043 (message-remove-header "reply-to"))))
1045 (defun gnus-post-method (arg group &optional silent)
1046 "Return the posting method based on GROUP and ARG.
1047 If SILENT, don't prompt the user."
1048 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1050 (group-method (gnus-find-method-for-group group)))
1052 ;; If the group-method is nil (which shouldn't happen) we use
1053 ;; the default method.
1054 ((null group-method)
1055 (or (and (listp gnus-post-method) ;If not current/native/nil
1056 (not (listp (car gnus-post-method))) ; and not a list of methods
1057 gnus-post-method) ;then use it.
1059 message-post-method))
1060 ;; We want the inverse of the default
1061 ((and arg (not (eq arg 0)))
1062 (if (eq gnus-post-method 'current)
1065 ;; We query the user for a post method.
1067 (and (listp gnus-post-method)
1068 (listp (car gnus-post-method))))
1070 ;; Collect all methods we know about.
1072 (when (listp gnus-post-method)
1073 (if (listp (car gnus-post-method))
1075 (list gnus-post-method)))
1076 gnus-secondary-select-methods
1077 (mapcar 'cdr gnus-server-alist)
1078 (mapcar 'car gnus-opened-servers)
1079 (list gnus-select-method)
1080 (list group-method)))
1081 method-alist post-methods method)
1082 ;; Weed out all mail methods.
1084 (setq method (gnus-server-get-method "" (pop methods)))
1085 (when (and (or (gnus-method-option-p method 'post)
1086 (gnus-method-option-p method 'post-mail))
1087 (not (member method post-methods)))
1088 (push method post-methods)))
1089 ;; Create a name-method alist.
1093 (if (equal (cadr m) "")
1094 (list (symbol-name (car m)) m)
1095 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1100 (setq gnus-last-posting-server
1102 gnus-last-posting-server)
1103 ;; Just use the last value.
1104 gnus-last-posting-server
1106 "Posting method: " method-alist nil t
1107 (cons (or gnus-last-posting-server "") 0))))
1109 ;; Override normal method.
1110 ((and (eq gnus-post-method 'current)
1111 (not (memq (car group-method) gnus-discouraged-post-methods))
1112 (gnus-get-function group-method 'request-post t))
1115 ;; Use gnus-post-method.
1116 ((listp gnus-post-method) ;A method...
1117 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1119 ;; Use the normal select method (nil or native).
1120 (t gnus-select-method))))
1123 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1125 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1126 variable `mime-edit-user-agent-value' is bound, the value will be
1127 included in the return value. If MAX-COLUMN is specified, the return
1128 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1129 whether a newline should be inserted in front of each product-token.
1130 If the value is t or `hard', it works strictly. Otherwise, if it is
1131 non-nil (e.g. `soft'), it works semi-strictly.
1133 Here is an example of how to use this function:
1135 \(add-hook 'gnus-message-setup-hook
1137 (setq message-user-agent nil)
1140 (message-narrow-to-headers)
1141 (goto-char (point-max))
1142 (insert \"User-Agent: \"
1143 (gnus-message-make-user-agent t 76 'soft)
1146 (let ((user-agent (if (and include-mime-info
1147 (boundp 'mime-edit-user-agent-value))
1148 (concat (gnus-extended-version)
1150 mime-edit-user-agent-value)
1151 (gnus-extended-version))))
1153 (unless (natnump max-column)
1154 (setq max-column 76))
1156 (set-buffer-multibyte t)
1157 (insert (mapconcat 'identity (split-string user-agent) " "))
1158 (goto-char (point-min))
1160 start agent agents width element swidth)
1161 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1162 (setq start (match-beginning 0))
1163 (if (eq (char-after start) ?\()
1167 (push (buffer-substring start (point)) agent))
1169 (push (nreverse agent) agents))
1170 (setq agent (list (match-string 1)))))
1172 (push (nreverse agent) agents))
1173 (setq agents (nreverse agents))
1174 (if (> (+ 12 (string-width (caar agents))) max-column)
1175 (setq user-agent "\n"
1180 (setq agent (car agents)
1181 agents (cdr agents))
1182 (when (and (not bol)
1183 (or (memq newline-product '(t hard))
1184 (and newline-product
1186 (string-width (mapconcat 'identity
1189 (setq user-agent (concat user-agent "\n")
1193 (setq element (car agent)
1194 swidth (string-width element)
1197 (setq user-agent (if (member user-agent '("" "\n"))
1198 (concat user-agent element)
1199 (concat user-agent " " element))
1200 width (+ width 1 swidth)
1202 (if (> (+ width 1 swidth) max-column)
1203 (setq user-agent (concat user-agent "\n " element)
1205 (setq user-agent (concat user-agent " " element)
1206 width (+ width 1 swidth)))))))))
1211 ;;; Gnus Mail Functions
1214 ;;; Mail reply commands of Gnus summary mode
1216 (defun gnus-summary-reply (&optional yank wide very-wide)
1217 "Start composing a mail reply to the current message.
1218 If prefix argument YANK is non-nil, the original article is yanked
1220 If WIDE, make a wide reply.
1221 If VERY-WIDE, make a very wide reply."
1223 (list (and current-prefix-arg
1224 (gnus-summary-work-articles 1))))
1225 ;; Allow user to require confirmation before replying by mail to the
1226 ;; author of a news article (or mail message).
1228 (not (or (gnus-news-group-p gnus-newsgroup-name)
1229 gnus-confirm-treat-mail-like-news))
1230 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1231 (string-match gnus-confirm-mail-reply-to-news
1232 gnus-newsgroup-name))
1233 ((functionp gnus-confirm-mail-reply-to-news)
1234 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1235 (t gnus-confirm-mail-reply-to-news)))
1236 (y-or-n-p "Really reply by mail to article author? "))
1238 (if (listp (car yank))
1241 (gnus-article-reply (or article (gnus-summary-article-number)))
1242 (gnus-article-yanked-articles yank)
1244 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1246 (gnus-summary-goto-subject article))
1247 (gnus-setup-message (if yank 'reply-yank 'reply)
1249 (gnus-summary-select-article)
1250 (dolist (article very-wide)
1251 (gnus-summary-select-article nil nil nil article)
1253 (set-buffer (gnus-copy-article-buffer))
1254 (gnus-msg-treat-broken-reply-to)
1256 (message-narrow-to-head)
1257 (setq headers (concat headers (buffer-string)))))))
1258 (set-buffer (gnus-copy-article-buffer))
1259 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1261 (message-narrow-to-head)
1265 (goto-char (point-max)))
1266 (message-reply nil wide)
1268 (gnus-inews-yank-articles yank))
1269 (gnus-summary-handle-replysign)))))
1271 (defun gnus-summary-handle-replysign ()
1272 "Check the various replysign variables and take action accordingly."
1273 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1274 (let (signed encrypted)
1276 (set-buffer gnus-article-buffer)
1277 (setq signed (memq 'signed gnus-article-wash-types))
1278 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1279 (cond ((and gnus-message-replyencrypt encrypted)
1280 (mml-secure-message mml-default-encrypt-method
1281 (if gnus-message-replysignencrypted
1284 ((and gnus-message-replysign signed)
1285 (mml-secure-message mml-default-sign-method 'sign))))))
1287 (defun gnus-summary-reply-with-original (n &optional wide)
1288 "Start composing a reply mail to the current message.
1289 The original article will be yanked."
1291 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1293 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1294 "Like `gnus-summary-reply' except removing reply-to field.
1295 If prefix argument YANK is non-nil, the original article is yanked
1297 If WIDE, make a wide reply.
1298 If VERY-WIDE, make a very wide reply."
1300 (list (and current-prefix-arg
1301 (gnus-summary-work-articles 1))))
1302 (let ((gnus-msg-force-broken-reply-to t))
1303 (gnus-summary-reply yank wide very-wide)))
1305 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1306 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1307 The original article will be yanked."
1309 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1311 (defun gnus-summary-wide-reply (&optional yank)
1312 "Start composing a wide reply mail to the current message.
1313 If prefix argument YANK is non-nil, the original article is yanked
1316 (list (and current-prefix-arg
1317 (gnus-summary-work-articles 1))))
1318 (gnus-summary-reply yank t))
1320 (defun gnus-summary-wide-reply-with-original (n)
1321 "Start composing a wide reply mail to the current message.
1322 The original article will be yanked."
1324 (gnus-summary-reply-with-original n t))
1326 (defun gnus-summary-very-wide-reply (&optional yank)
1327 "Start composing a very wide reply mail to the current message.
1328 If prefix argument YANK is non-nil, the original article is yanked
1331 (list (and current-prefix-arg
1332 (gnus-summary-work-articles 1))))
1333 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1335 (defun gnus-summary-very-wide-reply-with-original (n)
1336 "Start composing a very wide reply mail to the current message.
1337 The original article will be yanked."
1340 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1342 (defun gnus-summary-mail-forward (&optional full-headers post)
1343 "Forward the current message(s) to another user.
1344 If process marks exist, forward all marked messages;
1345 If FULL-HEADERS (the prefix), include full headers when forwarding.
1347 Note that this function definition for T-gnus is totally different
1348 from the original Gnus."
1350 (if (cdr (gnus-summary-work-articles nil))
1351 ;; Process marks are given.
1352 (gnus-summary-digest-mail-forward nil post)
1353 ;; No process marks.
1354 (let* ((gnus-article-reply (gnus-summary-article-number))
1355 (gnus-article-yanked-articles (list gnus-article-reply))
1357 (message-included-forward-headers
1358 (if full-headers "" message-included-forward-headers)))
1359 (gnus-setup-message 'forward
1360 (gnus-summary-select-article)
1361 (setq charset default-mime-charset)
1362 (set-buffer gnus-original-article-buffer)
1363 (make-local-variable 'default-mime-charset)
1364 (setq default-mime-charset charset)
1365 (message-forward post)))))
1367 (defun gnus-summary-digest-mail-forward (&optional n post)
1368 "Digests and forwards all articles in this series.
1369 If N is a positive number, forward the N next articles.
1370 If N is a negative number, forward the N previous articles.
1371 If N is nil and any articles have been marked with the process mark,
1372 forward those articles instead.
1373 Optional POST will use news to forward instead of mail."
1375 (let* ((articles (gnus-summary-work-articles n))
1376 (gnus-article-yanked-articles (copy-sequence articles))
1377 (topics "Topics:\n")
1378 subject article frame)
1379 (when (car articles)
1380 (gnus-setup-message 'forward
1381 (gnus-summary-select-article)
1383 (setq articles (sort articles '<)
1384 subject "Digested Articles")
1385 (with-current-buffer gnus-original-article-buffer
1386 (setq subject (message-make-forward-subject))))
1388 (message-news nil subject)
1389 (message-mail nil subject))
1390 (when (and message-use-multi-frames (cdr articles))
1391 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1393 (while (setq article (pop articles))
1394 (save-window-excursion
1395 (set-buffer gnus-summary-buffer)
1396 (gnus-summary-select-article nil nil nil article)
1397 (setq topics (concat topics " "
1398 (mail-header-subject gnus-current-headers)
1400 (gnus-summary-remove-process-mark article))
1402 (select-frame frame))
1403 (insert (mime-make-tag "message" "rfc822") "\n")
1404 (narrow-to-region (point) (point))
1405 (insert-buffer-substring gnus-original-article-buffer)
1407 (article-narrow-to-head)
1408 (message-remove-header message-included-forward-headers t nil t))
1409 (goto-char (point-max))
1415 (mime-edit-enclose-digest-region (point)(mark t))))))
1417 (defun gnus-summary-digest-post-forward (&optional n)
1418 "Digest and forwards all articles in this series to a newsgroup.
1419 If N is a positive number, forward the N next articles.
1420 If N is a negative number, forward the N previous articles.
1421 If N is nil and any articles have been marked with the process mark,
1422 forward those articles instead."
1424 (gnus-summary-digest-mail-forward n t))
1426 (defun gnus-summary-resend-message (address n)
1427 "Resend the current article to ADDRESS."
1429 (list (message-read-from-minibuffer
1430 "Resend message(s) to: "
1431 (when (and gnus-summary-resend-default-address
1432 (gnus-buffer-live-p gnus-original-article-buffer))
1433 ;; If some other article is currently selected, the
1434 ;; initial-contents is wrong. Whatever, it is just the
1435 ;; initial-contents.
1436 (with-current-buffer gnus-original-article-buffer
1437 (nnmail-fetch-field "to"))))
1438 current-prefix-arg))
1439 (let ((articles (gnus-summary-work-articles n))
1441 (while (setq article (pop articles))
1442 (gnus-summary-select-article nil nil nil article)
1444 (set-buffer gnus-original-article-buffer)
1445 (message-resend address))
1446 (gnus-summary-mark-article-as-forwarded article))))
1448 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1449 (defun gnus-summary-resend-message-edit ()
1450 "Resend an article that has already been sent.
1451 A new buffer will be created to allow the user to modify body and
1452 contents of the message, and then, everything will happen as when
1453 composing a new message."
1455 (let ((article (gnus-summary-article-number)))
1456 (gnus-setup-message 'reply-yank
1457 (gnus-summary-select-article t)
1458 (set-buffer gnus-original-article-buffer)
1459 (let ((cur (current-buffer))
1460 (to (message-fetch-field "to")))
1461 ;; Get a normal message buffer.
1462 (message-pop-to-buffer (message-buffer-name "Resend" to))
1463 (insert-buffer-substring cur)
1465 ;; T-gnus change: Use MIME-Edit to recompose a message.
1467 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1468 (fset 'mime-edit-decode-single-part-in-buffer
1469 (lambda (&rest args)
1470 (if (let ((content-type (car args)))
1471 (and (eq 'message (mime-content-type-primary-type
1473 (eq 'rfc822 (mime-content-type-subtype
1475 (setcar (cdr args) 'not-decode-text))
1478 (mime-edit-again nil t)
1479 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1480 (message-narrow-to-head-1)
1481 (insert "From: " (message-make-from) "\n")
1482 (while (re-search-forward "^From:" nil t)
1484 (insert "Original-"))
1485 (message-remove-header "^>From[\t ]" t)
1487 ;; Gnus will generate a new one when sending.
1488 (message-remove-header "Message-ID")
1489 (message-remove-header message-ignored-resent-headers t)
1490 ;; Remove unwanted headers.
1491 (goto-char (point-max))
1492 (insert mail-header-separator)
1493 (goto-char (point-min))
1494 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1498 (defun gnus-summary-post-forward (&optional full-headers)
1499 "Forward the current article to a newsgroup.
1500 If FULL-HEADERS (the prefix), include full headers when forwarding."
1502 (gnus-summary-mail-forward full-headers t))
1504 (defvar gnus-nastygram-message
1505 "The following article was inappropriately posted to %s.\n\n"
1506 "Format string to insert in nastygrams.
1507 The current group name will be inserted at \"%s\".")
1509 (defun gnus-summary-mail-nastygram (n)
1510 "Send a nastygram to the author of the current article."
1512 (when (or gnus-expert-user
1514 "Really send a nastygram to the author of the current article? "))
1515 (let ((group gnus-newsgroup-name))
1516 (gnus-summary-reply-with-original n)
1517 (set-buffer gnus-message-buffer)
1519 (insert (format gnus-nastygram-message group))
1520 (message-send-and-exit))))
1522 (defun gnus-summary-mail-crosspost-complaint (n)
1523 "Send a complaint about crossposting to the current article(s)."
1525 (let ((articles (gnus-summary-work-articles n))
1527 (while (setq article (pop articles))
1528 (set-buffer gnus-summary-buffer)
1529 (gnus-summary-goto-subject article)
1530 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1531 newsgroups followup-to)
1532 (gnus-summary-select-article)
1533 (set-buffer gnus-original-article-buffer)
1534 (if (and (<= (length (message-tokenize-header
1536 (mail-fetch-field "newsgroups"))
1539 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1540 (not (member group (message-tokenize-header
1541 followup-to ", ")))))
1543 (gnus-message 1 "Followup-to restricted")
1544 (gnus-message 1 "Not a crossposted article"))
1545 (set-buffer gnus-summary-buffer)
1546 (gnus-summary-reply-with-original 1)
1547 (set-buffer gnus-message-buffer)
1549 (insert (format gnus-crosspost-complaint newsgroups group))
1550 (message-goto-subject)
1551 (re-search-forward " *$")
1552 (replace-match " (crosspost notification)" t t)
1553 (gnus-deactivate-mark)
1554 (when (gnus-y-or-n-p "Send this complaint? ")
1555 (message-send-and-exit)))))))
1557 (defun gnus-mail-parse-comma-list ()
1560 (skip-chars-forward " ")
1563 (skip-chars-forward "^,")
1568 (narrow-to-region beg (point))
1571 (while (search-forward "\"" nil t)
1575 (skip-chars-forward ",")
1576 (skip-chars-forward "^,"))
1577 (skip-chars-backward " ")
1578 (push (buffer-substring beg (point))
1580 (skip-chars-forward "^,")
1581 (skip-chars-forward ", "))
1584 (defun gnus-inews-add-to-address (group)
1585 (let ((to-address (mail-fetch-field "to")))
1586 (when (and to-address
1588 ;; This mail group doesn't have a `to-list', so we add one
1590 (when (gnus-y-or-n-p
1591 (format "Do you want to add this as `to-list': %s " to-address))
1592 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1594 (defun gnus-put-message ()
1595 "Put the current message in some group and return to Gnus."
1597 (let ((reply gnus-article-reply)
1598 (winconf gnus-prev-winconf)
1599 (group gnus-newsgroup-name))
1601 (not (gnus-group-read-only-p group)))
1602 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1604 (when (gnus-gethash group gnus-newsrc-hashtb)
1605 (error "No such group: %s" group))
1609 (message-narrow-to-headers)
1610 (let ((gnus-deletable-headers nil))
1611 (message-generate-headers
1612 (if (message-news-p)
1613 message-required-news-headers
1614 message-required-mail-headers)))
1615 (goto-char (point-max))
1616 (if (string-match " " group)
1617 (insert "Gcc: \"" group "\"\n")
1618 (insert "Gcc: " group "\n"))
1621 (when (and (get-buffer gnus-group-buffer)
1622 (gnus-buffer-exists-p (car-safe reply))
1624 (set-buffer (car reply))
1625 (gnus-summary-mark-article-as-replied (cdr reply)))
1627 (set-window-configuration winconf))))
1629 (defun gnus-article-mail (yank)
1630 "Send a reply to the address near point.
1631 If YANK is non-nil, include the original article."
1635 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1636 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1638 (gnus-msg-mail address)
1640 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1642 (defvar nntp-server-type)
1644 "Send a bug report to the Gnus maintainers."
1646 (unless (gnus-alive-p)
1647 (error "Gnus has been shut down"))
1648 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1649 (unless (message-mail-user-agent)
1650 (message-pop-to-buffer "*Gnus Bug*")
1651 (delete-other-windows)
1652 (when gnus-bug-create-help-buffer
1653 (switch-to-buffer "*Gnus Help Bug*")
1655 (insert gnus-bug-message)
1656 (goto-char (point-min))
1658 (set-buffer "*Gnus Bug*")))
1659 (let ((message-this-is-mail t))
1660 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1661 (when gnus-bug-create-help-buffer
1662 (push `(gnus-bug-kill-buffer) message-send-actions))
1663 (goto-char (point-min))
1664 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1666 (insert gnus-product-name " " gnus-version-number
1667 " (r" gnus-revision-number ") "
1668 "based on " gnus-original-product-name " v"
1669 gnus-original-version-number "\n"
1670 (emacs-version) "\n")
1671 (when (and (boundp 'nntp-server-type)
1672 (stringp nntp-server-type))
1673 (insert nntp-server-type))
1674 (insert "\n\n\n\n\n")
1675 (let (mime-content-types)
1676 (mime-edit-insert-tag
1677 "application" "emacs-lisp"
1678 "\nContent-Disposition: inline\nContent-Description: User settings"))
1679 (insert (with-temp-buffer
1682 (let (mime-content-types)
1683 (mime-edit-insert-tag "text" "plain"))
1684 (goto-char (point-min))
1685 (search-forward "Subject: " nil t)
1688 (defun gnus-bug-kill-buffer ()
1689 (when (get-buffer "*Gnus Help Bug*")
1690 (kill-buffer "*Gnus Help Bug*")))
1692 (defun gnus-summary-yank-message (buffer n)
1693 "Yank the current article into a composed message."
1695 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1696 current-prefix-arg))
1697 (when (gnus-buffer-live-p buffer)
1698 (let ((summary-frame (selected-frame))
1699 (message-frame (when (static-if (featurep 'xemacs)
1700 (device-on-window-system-p)
1702 (let ((window (get-buffer-window buffer t)))
1704 (window-frame window)))))
1705 (separator (concat "^" (regexp-quote mail-header-separator)
1707 (gnus-summary-iterate n
1708 (gnus-summary-select-article)
1709 (gnus-copy-article-buffer)
1710 (when (frame-live-p message-frame)
1711 (raise-frame message-frame)
1712 (select-frame message-frame))
1713 (with-current-buffer buffer
1714 (when (save-excursion
1716 (let (case-fold-search)
1717 (and (not (re-search-backward separator nil t))
1718 (re-search-forward separator nil t))))
1719 (goto-char (match-end 0)))
1720 (message-yank-buffer gnus-article-copy))
1721 (select-frame summary-frame))
1722 (when (frame-live-p message-frame)
1723 (select-frame message-frame)))))
1725 (defun gnus-debug ()
1726 "Attempts to go through the Gnus source file and report what variables have been changed.
1727 The source file has to be in the Emacs load path."
1729 (let ((files gnus-debug-files)
1731 file expr olist sym)
1732 (gnus-message 4 "Please wait while we snoop your variables...")
1733 ;; Go through all the files looking for non-default values for variables.
1736 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1739 (when (and (setq file (locate-library (pop files)))
1740 (file-exists-p file))
1741 (insert-file-contents file)
1742 (goto-char (point-min))
1743 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1744 (gnus-message 4 "Malformed sources in file %s" file)
1745 (narrow-to-region (point-min) (point))
1746 (goto-char (point-min))
1747 (while (setq expr (ignore-errors (read (current-buffer))))
1749 (and (memq (car expr) '(defvar defcustom defvoo))
1750 (stringp (nth 3 expr))
1751 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1752 (or (not (boundp (nth 1 expr)))
1753 (not (equal (eval (nth 2 expr))
1754 (symbol-value (nth 1 expr)))))
1755 (push (nth 1 expr) olist)))))))
1756 (kill-buffer (current-buffer)))
1757 (when (setq olist (nreverse olist))
1758 (insert ";----------------- Environment follows ------------------\n\n"))
1760 (if (boundp (car olist))
1762 (pp `(setq ,(car olist)
1763 ,(if (or (consp (setq sym (symbol-value (car olist))))
1765 (not (or (eq sym nil)
1767 (list 'quote (symbol-value (car olist)))
1768 (symbol-value (car olist))))
1770 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1771 (setq olist (cdr olist)))
1772 ;; Remove any control chars - they seem to cause trouble for some
1773 ;; mailers. (Byte-compiled output from the stuff above.)
1775 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1776 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1778 ;; Break MIME tags purposely.
1780 (while (re-search-forward mime-edit-tag-regexp nil t)
1781 (goto-char (1+ (match-beginning 0)))
1784 ;;; Treatment of rejected articles.
1787 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1788 "Re-mail the current message.
1789 This only makes sense if the current message is a bounce message than
1790 contains some mail you have written which has been bounced back to
1792 If FETCH, try to fetch the article that this is a reply to, if indeed
1795 (gnus-summary-select-article t)
1796 (set-buffer gnus-original-article-buffer)
1797 (gnus-setup-message 'compose-bounce
1798 (let* ((references (mail-fetch-field "references"))
1799 (parent (and references (gnus-parent-id references))))
1801 ;; If there are references, we fetch the article we answered to.
1803 (gnus-summary-refer-article parent)
1804 (gnus-summary-show-all-headers)))))
1808 (defun gnus-inews-group-method (group)
1810 ;; If the group doesn't exist, we assume
1811 ;; it's an archive group...
1812 ((and (null (gnus-get-info group))
1813 (eq (car (gnus-server-to-method gnus-message-archive-method))
1814 (car (gnus-server-to-method (gnus-group-method group)))))
1815 gnus-message-archive-method)
1817 ((gnus-info-method (gnus-get-info group))
1818 (gnus-info-method (gnus-get-info group)))
1820 (t (gnus-server-to-method (gnus-group-method group)))))
1822 ;; Do Gcc handling, which copied the message over to some group.
1823 (defun gnus-inews-do-gcc (&optional gcc)
1827 (message-narrow-to-headers)
1828 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1829 (coding-system-for-write 'raw-text)
1830 (output-coding-system 'raw-text)
1831 groups group method group-art
1832 mml-externalize-attachments)
1834 (message-remove-header "gcc")
1836 (setq groups (message-unquote-tokens
1837 (message-tokenize-header gcc " ,")))
1838 ;; Copy the article over to some group(s).
1839 (while (setq group (pop groups))
1840 (unless (gnus-check-server
1841 (setq method (gnus-inews-group-method group)))
1842 (error "Can't open server %s" (if (stringp method) method
1844 (unless (gnus-request-group group nil method)
1845 (gnus-request-create-group group method))
1846 (setq mml-externalize-attachments
1847 (if (stringp gnus-gcc-externalize-attachments)
1848 (string-match gnus-gcc-externalize-attachments group)
1849 gnus-gcc-externalize-attachments))
1851 (nnheader-set-temp-buffer " *acc*")
1852 (insert-buffer-substring message-encoding-buffer)
1853 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1854 (goto-char (point-min))
1855 (when (re-search-forward
1856 (concat "^" (regexp-quote mail-header-separator) "$")
1858 (replace-match "" t t ))
1859 (unless (setq group-art
1860 (gnus-request-accept-article group method t t))
1861 (gnus-message 1 "Couldn't store article in group %s: %s"
1862 group (gnus-status-message method))
1864 (when (and group-art
1865 ;; FIXME: Should gcc-mark-as-read work when
1866 ;; Gnus is not running?
1868 (or gnus-gcc-mark-as-read
1869 gnus-inews-mark-gcc-as-read))
1870 (gnus-group-mark-article-read group (cdr group-art)))
1871 (kill-buffer (current-buffer)))))))))
1873 (defun gnus-inews-insert-gcc ()
1874 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1877 (message-narrow-to-headers)
1878 (let* ((group gnus-outgoing-message-group)
1880 ((gnus-functionp group)
1882 ((or (stringp group) (list group))
1887 (if (string-match " " gcc)
1888 (concat "\"" gcc "\"")
1890 (mapconcat (lambda (group)
1891 (if (string-match " " group)
1892 (concat "\"" group "\"")
1897 (defun gnus-inews-insert-archive-gcc (&optional group)
1898 "Insert the Gcc to say where the article is to be archived."
1899 (let* ((var gnus-message-archive-group)
1900 (group (or group gnus-newsgroup-name ""))
1902 (and gnus-newsgroup-name
1903 (not (equal gnus-newsgroup-name ""))
1904 (gnus-group-find-parameter
1905 gnus-newsgroup-name 'gcc-self)))
1909 ((null gnus-message-archive-method)
1913 ;; Just a single group.
1916 ;; We don't want this.
1918 ((and (listp var) (stringp (car var)))
1919 ;; A list of groups.
1921 ((gnus-functionp var)
1923 (funcall var group))
1925 ;; An alist of regexps/functions/forms.
1930 ((stringp (caar var))
1932 (when (string-match (caar var) group)
1934 ((gnus-functionp (car var))
1936 (funcall (car var) group))
1938 (eval (car var)))))))
1939 (setq var (cdr var)))
1942 (when (or groups gcc-self-val)
1943 (when (stringp groups)
1944 (setq groups (list groups)))
1947 (message-narrow-to-headers)
1948 (goto-char (point-max))
1951 ;; Use the `gcc-self' param value instead.
1954 (if (stringp gcc-self-val)
1955 (if (string-match " " gcc-self-val)
1956 (concat "\"" gcc-self-val "\"")
1958 (if (string-match " " group)
1959 (concat "\"" group "\"")
1961 (if (not (eq gcc-self-val 'none))
1963 (gnus-delete-line)))
1964 ;; Use the list of groups.
1965 (while (setq name (pop groups))
1966 (let ((str (if (string-match ":" name)
1968 (gnus-group-prefixed-name
1969 name gnus-message-archive-method))))
1970 (insert (if (string-match " " str)
1971 (concat "\"" str "\"")
1977 (defun gnus-mailing-list-followup-to ()
1978 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1979 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1980 (list-post (gnus-fetch-original-field "list-post")))
1981 (when (and list-post
1982 (string-match "mailto:\\([^>]+\\)" list-post))
1983 (setq list-post (match-string 1 list-post)))
1989 (defun gnus-configure-posting-styles (&optional group-name)
1990 "Configure posting styles according to `gnus-posting-styles'."
1991 (unless gnus-inhibit-posting-styles
1992 (let ((group (or group-name gnus-newsgroup-name ""))
1993 (styles gnus-posting-styles)
1994 style match attribute results
1996 ;; If the group has a posting-style parameter, add it at the end with a
1997 ;; regexp matching everything, to be sure it takes precedence over all
1999 (when gnus-newsgroup-name
2000 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2002 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2003 ;; Go through all styles and look for matches.
2004 (dolist (style styles)
2005 (setq match (pop style))
2006 (goto-char (point-min))
2009 ;; Regexp string match on the group name.
2010 (string-match match group))
2012 ;; Obsolete format of header match.
2013 (and (gnus-buffer-live-p gnus-article-copy)
2014 (with-current-buffer gnus-article-copy
2015 (let ((header (message-fetch-field (pop style))))
2017 (string-match (pop style) header))))))
2018 ((or (symbolp match)
2019 (gnus-functionp match))
2021 ((gnus-functionp match)
2022 ;; Function to be called.
2025 ;; Variable to be checked.
2026 (symbol-value match))))
2029 ((eq (car match) 'header)
2030 ;; New format of header match.
2031 (and (gnus-buffer-live-p gnus-article-copy)
2032 (with-current-buffer gnus-article-copy
2033 (let ((header (message-fetch-field (nth 1 match))))
2035 (string-match (nth 2 match) header))))))
2037 ;; This is a form to be evaled.
2039 ;; We have a match, so we set the variables.
2040 (setq style (gnus-configure-posting-style style nil))
2041 (dolist (attribute style)
2042 (setq results (delq (assoc (car attribute) results) results))
2043 (push attribute results))))
2044 ;; Now we have all the styles, so we insert them.
2045 (setq name (assq 'name results)
2046 address (assq 'address results))
2047 (setq results (delq name (delq address results)))
2048 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2049 (make-local-hook 'message-setup-hook)
2050 (setq results (sort results (lambda (x y)
2051 (string-lessp (car x) (car y)))))
2052 (dolist (result results)
2053 (add-hook 'message-setup-hook
2055 ((eq 'eval (car result))
2057 ((eq 'body (car result))
2061 (insert ,(cdr result)))))
2062 ((eq 'signature (car result))
2063 (set (make-local-variable 'message-signature) nil)
2064 (set (make-local-variable 'message-signature-file) nil)
2065 (if (not (cdr result))
2069 (let ((message-signature ,(cdr result)))
2070 (when message-signature
2071 (message-insert-signature)))))))
2074 (if (symbolp (car result))
2075 (capitalize (symbol-name (car result)))
2079 (message-remove-header ,header)
2080 (let ((value ,(cdr result)))
2083 (insert ,header ": " value)
2085 (insert "\n")))))))))
2087 (when (or name address)
2088 (add-hook 'message-setup-hook
2090 (set (make-local-variable 'user-mail-address)
2091 ,(or (cdr address) user-mail-address))
2092 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2094 ,(or (cdr address) user-mail-address)))
2096 (message-remove-header "From")
2098 (insert "From: " (message-make-from) "\n"))))
2101 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2102 (defun gnus-configure-posting-style (style stack)
2103 "Parse one posting style STYLE and returns the value as an alist."
2104 (let (results element variable filep value v)
2105 (dolist (attribute style)
2106 (setq element (pop attribute)
2111 ((eq (car attribute) ':file)
2114 ((eq (car attribute) :value)
2118 ;; We get the value.
2123 ((or (symbolp value)
2124 (gnus-functionp value))
2125 (cond ((gnus-functionp value)
2128 (symbol-value value))))
2131 ;; Translate obsolescent value.
2133 ((eq element 'signature-file)
2134 (setq element 'signature
2136 ((eq element 'x-face-file)
2137 (setq element 'x-face
2139 ;; Get the contents of file elems.
2141 (setq v (with-temp-buffer
2142 (insert-file-contents v)
2143 (goto-char (point-max))
2147 (if (eq element 'import)
2149 (if (member v stack)
2150 (error "Circular import of \"%s\"" v))
2152 (nconc (nreverse (gnus-configure-posting-style
2153 (cdr (assoc v gnus-named-posting-styles))
2156 (push (cons element v) results)))
2157 (nreverse results)))
2159 (defun gnus-summary-execute-command-with-posting-style (style command)
2160 "Temporarily select a posting-style named STYLE and execute COMMAND."
2162 (let ((style (completing-read "Posting style: "
2163 gnus-named-posting-styles nil t)))
2167 (format "Command to execute with %s: " style))))))
2168 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2169 (call-interactively command)))
2172 ;;; @ for MIME Edit mode
2175 (defun gnus-maybe-setup-default-charset ()
2177 (and (boundp 'gnus-summary-buffer)
2178 (buffer-live-p gnus-summary-buffer)
2180 (set-buffer gnus-summary-buffer)
2181 default-mime-charset))))
2184 (make-local-variable 'default-mime-charset)
2185 (setq default-mime-charset charset)
2189 ;;; @ for MIME view mode
2192 (defun gnus-following-method (buf)
2193 (gnus-setup-message 'reply-yank
2195 (if (message-news-p)
2197 (message-reply nil 'wide))
2198 (let ((message-reply-buffer buf))
2199 (message-yank-original))
2200 (message-goto-body))
2204 ;;; Allow redefinition of functions.
2210 ;;; gnus-msg.el ends here