1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
176 'gnus-gcc-mark-as-read)
178 (defcustom gnus-gcc-externalize-attachments nil
179 "Should local-file attachments be included as external parts in Gcc copies?
180 If it is `all', attach files as external parts;
181 if a regexp and matches the Gcc group name, attach files as external parts;
182 if nil, attach files as normal parts."
185 :type '(choice (const nil :tag "None")
186 (const all :tag "Any")
187 (string :tag "Regexp")))
189 (gnus-define-group-parameter
190 posting-charset-alist
193 "Return the permitted unencoded charsets for posting of GROUP."
194 :variable gnus-group-posting-charset-alist
196 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
197 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
198 (message-this-is-mail nil nil)
199 (message-this-is-news nil t))
201 "Alist of regexps and permitted unencoded charsets for posting.
202 Each element of the alist has the form (TEST HEADER BODY-LIST), where
203 TEST is either a regular expression matching the newsgroup header or a
205 HEADER is the charset which may be left unencoded in the header (nil
206 means encode all charsets),
207 BODY-LIST is a list of charsets which may be encoded using 8bit
208 content-transfer encoding in the body, or one of the special values
209 nil (always encode using quoted-printable) or t (always use 8bit).
211 Note that any value other than nil for HEADER infringes some RFCs, so
212 use this option with care."
213 :variable-group gnus-charset
215 '(repeat (list :tag "Permitted unencoded charsets"
217 (regexp :tag "Group")
218 (const :tag "Mail message" :value message-this-is-mail)
219 (const :tag "News article" :value message-this-is-news))
220 (choice :tag "Header"
221 (const :tag "None" nil)
222 (symbol :tag "Charset"))
224 (const :tag "Any" :value t)
225 (const :tag "None" :value nil)
226 (repeat :tag "Charsets"
227 (symbol :tag "Charset")))))
228 :parameter-type '(choice :tag "Permitted unencoded charsets"
231 :parameter-document "\
232 List of charsets that are permitted to be unencoded.")
234 (defcustom gnus-debug-files
235 '("gnus.el" "gnus-sum.el" "gnus-group.el"
236 "gnus-art.el" "gnus-start.el" "gnus-async.el"
237 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
238 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
239 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
240 "Files whose variables will be reported in `gnus-bug'."
243 :type '(repeat (string :tag "File")))
245 (defcustom gnus-debug-exclude-variables
246 '(mm-mime-mule-charset-alist
247 nnmail-split-fancy message-minibuffer-local-map)
248 "Variables that should not be reported in `gnus-bug'."
251 :type '(repeat (symbol :tag "Variable")))
253 (defcustom gnus-discouraged-post-methods
254 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
255 "A list of back ends that are not used in \"real\" newsgroups.
256 This variable is used only when `gnus-post-method' is `current'."
258 :group 'gnus-group-foreign
259 :type '(repeat (symbol :tag "Back end")))
261 (defcustom gnus-message-replysign
263 "Automatically sign replies to signed messages.
264 See also the `mml-default-sign-method' variable."
268 (defcustom gnus-message-replyencrypt
270 "Automatically encrypt replies to encrypted messages.
271 See also the `mml-default-encrypt-method' variable."
275 (defcustom gnus-message-replysignencrypted
277 "Setting this causes automatically encrypted messages to also be signed."
281 (defcustom gnus-confirm-mail-reply-to-news nil
282 "If non-nil, Gnus requests confirmation when replying to news.
283 This is done because new users often reply by mistake when reading
285 This can also be a function receiving the group name as the only
286 parameter which should return non-nil iff a confirmation is needed, or
287 a regexp, in which case a confirmation is asked for iff the group name
291 :type '(choice (const :tag "No" nil)
293 (regexp :tag "Iff group matches regexp")
294 (function :tag "Iff function evaluates to non-nil")))
296 (defcustom gnus-confirm-treat-mail-like-news
298 "If non-nil, Gnus will treat mail like news with regard to confirmation
299 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
300 for fine-tuning this.
301 If nil, Gnus will never ask for confirmation if replying to mail."
306 (defcustom gnus-summary-resend-default-address t
307 "If non-nil, Gnus tries to suggest a default address to resend to.
308 If nil, the address field will always be empty after invoking
309 `gnus-summary-resend-message'."
313 ;;; Internal variables.
315 (defvar gnus-inhibit-posting-styles nil
316 "Inhibit the use of posting styles.")
318 (defvar gnus-article-yanked-articles nil)
319 (defvar gnus-message-buffer "*Mail Gnus*")
320 (defvar gnus-article-copy nil)
321 (defvar gnus-check-before-posting nil)
322 (defvar gnus-last-posting-server nil)
323 (defvar gnus-message-group-art nil)
325 (defvar gnus-msg-force-broken-reply-to nil)
327 (defconst gnus-bug-message
328 (format "Sending a bug report to the Gnus Towers.
329 ========================================
331 This gnus is the %s%s.
332 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
333 Developers. (the addresses below are mailing list addresses)
335 ========================================
337 The buffer below is a mail buffer. When you press `C-c C-c', it will
338 be sent to the Gnus Bug Exterminators.
340 The thing near the bottom of the buffer is how the environment
341 settings will be included in the mail. Please do not delete that.
342 They will tell the Bug People what your environment is, so that it
343 will be easier to locate the bugs.
345 If you have found a bug that makes Emacs go \"beep\", set
346 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
347 and include the backtrace in your bug report.
349 Please describe the bug in annoying, painstaking detail.
351 Thank you for your help in stamping out bugs.
354 (if (string= gnus-product-name "Semi-gnus")
356 ", a modified version of Semi-gnus")))
359 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
363 ;;; Gnus Posting Functions
366 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
367 "p" gnus-summary-post-news
368 "i" gnus-summary-news-other-window
369 "f" gnus-summary-followup
370 "F" gnus-summary-followup-with-original
371 "c" gnus-summary-cancel-article
372 "s" gnus-summary-supersede-article
373 "r" gnus-summary-reply
374 "y" gnus-summary-yank-message
375 "R" gnus-summary-reply-with-original
376 "w" gnus-summary-wide-reply
377 "W" gnus-summary-wide-reply-with-original
378 "v" gnus-summary-very-wide-reply
379 "V" gnus-summary-very-wide-reply-with-original
380 "n" gnus-summary-followup-to-mail
381 "N" gnus-summary-followup-to-mail-with-original
382 "m" gnus-summary-mail-other-window
383 "u" gnus-uu-post-news
384 "\M-c" gnus-summary-mail-crosspost-complaint
385 "Br" gnus-summary-reply-broken-reply-to
386 "BR" gnus-summary-reply-broken-reply-to-with-original
387 "om" gnus-summary-mail-forward
388 "op" gnus-summary-post-forward
389 "Om" gnus-summary-digest-mail-forward
390 "Op" gnus-summary-digest-post-forward
391 "P" gnus-summary-execute-command-with-posting-style)
393 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
394 "b" gnus-summary-resend-bounced-mail
395 ;; "c" gnus-summary-send-draft
396 "r" gnus-summary-resend-message
397 "e" gnus-summary-resend-message-edit)
399 ;;; Internal functions.
401 (defun gnus-inews-make-draft (articles)
403 (gnus-inews-make-draft-meta-information
404 ,gnus-newsgroup-name ',articles)))
406 (defvar gnus-article-reply nil)
407 (defmacro gnus-setup-message (config &rest forms)
408 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
409 (buffer (make-symbol "gnus-setup-message-buffer"))
410 (article (make-symbol "gnus-setup-message-article"))
411 (yanked (make-symbol "gnus-setup-yanked-articles"))
412 (group (make-symbol "gnus-setup-message-group")))
413 `(let ((,winconf (current-window-configuration))
414 (,buffer (buffer-name (current-buffer)))
415 (,article gnus-article-reply)
416 (,yanked gnus-article-yanked-articles)
417 (,group gnus-newsgroup-name)
418 (message-header-setup-hook
419 (copy-sequence message-header-setup-hook))
420 (message-mode-hook (copy-sequence message-mode-hook))
421 (message-startup-parameter-alist
422 '((reply-buffer . gnus-copy-article-buffer)
423 (original-buffer . gnus-original-article-buffer)
424 (user-agent . Gnus))))
425 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
426 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
427 ;; #### FIXME: for a reason that I did not manage to identify yet,
428 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
429 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
430 ;; After evaluation of @forms below, it gets the value we actually want
431 ;; to override, and the posting styles are used. For that reason, I've
432 ;; added an optional argument to `gnus-configure-posting-styles' to
433 ;; make sure that the correct value for the group name is used. -- drv
434 (add-hook 'message-mode-hook
435 (if (memq ,config '(reply-yank reply))
437 (gnus-configure-posting-styles ,group))
439 ;; There may be an old " *gnus article copy*" buffer.
440 (let (gnus-article-copy)
441 (gnus-configure-posting-styles ,group)))))
442 (gnus-pull ',(intern gnus-draft-meta-information-header)
443 message-required-headers)
445 (not (string= ,group "")))
447 (intern gnus-draft-meta-information-header)
448 (gnus-inews-make-draft (or ,yanked ,article)))
449 message-required-headers))
453 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
455 (setq gnus-message-buffer (current-buffer))
456 (set (make-local-variable 'gnus-message-group-art)
457 (cons ,group ,article))
458 (set (make-local-variable 'gnus-newsgroup-name) ,group)
459 (gnus-maybe-setup-default-charset)
460 (gnus-run-hooks 'gnus-message-setup-hook))
461 (message-hide-headers)
463 (gnus-configure-windows ,config t)
464 (run-hooks 'post-command-hook)
465 (set-buffer-modified-p nil))))
467 (defun gnus-inews-make-draft-meta-information (group articles)
468 (when (numberp articles)
469 (setq articles (list articles)))
470 (concat "(\"" group "\""
484 (defun gnus-msg-mail (&optional to subject other-headers continue
485 switch-action yank-action send-actions)
486 "Start editing a mail message to be sent.
487 Like `message-mail', but with Gnus paraphernalia, particularly the
488 Gcc: header for archiving purposes."
490 (let ((buf (current-buffer))
492 (gnus-setup-message 'message
493 (message-mail to subject other-headers continue
494 nil yank-action send-actions))
496 (setq mail-buf (current-buffer))
497 (switch-to-buffer buf)
498 (apply switch-action mail-buf nil)))
499 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
502 (defvar save-selected-window-window)
505 (defun gnus-button-mailto (address)
507 (set-buffer (gnus-copy-article-buffer))
508 (gnus-setup-message 'message
509 (message-reply address))
510 (and (boundp 'save-selected-window-window)
511 (not (window-live-p save-selected-window-window))
512 (setq save-selected-window-window (selected-window))))
515 (defun gnus-button-reply (&optional to-address wide)
516 "Like `message-reply'."
518 (gnus-setup-message 'message
519 (message-reply to-address wide))
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 (define-mail-user-agent 'gnus-user-agent
526 'gnus-msg-mail 'message-send-and-exit
527 'message-kill-buffer 'message-send-hook)
529 (defun gnus-setup-posting-charset (group)
530 (let ((alist gnus-group-posting-charset-alist)
531 (group (or group ""))
535 (while (setq elem (pop alist))
536 (when (or (and (stringp (car elem))
537 (string-match (car elem) group))
538 (and (functionp (car elem))
539 (funcall (car elem) group))
540 (and (symbolp (car elem))
541 (symbol-value (car elem))))
542 (throw 'found (cons (cadr elem) (caddr elem)))))))))
544 (defun gnus-inews-add-send-actions (winconf buffer article
545 &optional config yanked)
546 (gnus-make-local-hook 'message-sent-hook)
547 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
548 'gnus-inews-do-gcc) nil t)
550 (gnus-make-local-hook 'message-header-hook)
551 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
552 (setq message-post-method
554 (gnus-post-method arg ,gnus-newsgroup-name)))
555 (setq message-user-agent (gnus-message-make-user-agent))
556 (unless message-use-multi-frames
558 `(if (gnus-buffer-exists-p ,buffer)
559 (set-window-configuration ,winconf))
560 'exit 'postpone 'kill))
561 (let ((to-be-marked (cond
564 (lambda (x) (if (listp x) (car x) x)) yanked))
565 (article (if (listp article) article (list article)))
568 `(when (gnus-buffer-exists-p ,buffer)
572 (if (eq config 'forward)
573 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
574 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
577 (put 'gnus-setup-message 'lisp-indent-function 1)
578 (put 'gnus-setup-message 'edebug-form-spec '(form body))
580 ;;; Post news commands of Gnus group mode and summary mode
582 (defun gnus-group-mail (&optional arg)
583 "Start composing a mail.
584 If ARG, use the group under the point to find a posting style.
585 If ARG is 1, prompt for a group name to find the posting style."
587 ;; We can't `let' gnus-newsgroup-name here, since that leads
588 ;; to local variables leaking.
589 (let ((group gnus-newsgroup-name)
590 ;; make sure last viewed article doesn't affect posting styles:
592 (buffer (current-buffer)))
595 (setq gnus-newsgroup-name
597 (if (= 1 (prefix-numeric-value arg))
598 (completing-read "Use posting style of group: "
599 gnus-active-hashtb nil
600 (gnus-read-active-file-p))
601 (gnus-group-group-name))
603 ;; #### see comment in gnus-setup-message -- drv
604 (gnus-setup-message 'message (message-mail)))
607 (setq gnus-newsgroup-name group)))))
609 (defun gnus-group-news (&optional arg)
610 "Start composing a news.
611 If ARG, post to group under point.
612 If ARG is 1, prompt for group name to post to.
614 This function prepares a news even when using mail groups. This is useful
615 for posting messages to mail groups without actually sending them over the
616 network. The corresponding back end must have a 'request-post method."
618 ;; We can't `let' gnus-newsgroup-name here, since that leads
619 ;; to local variables leaking.
620 (let ((group gnus-newsgroup-name)
621 ;; make sure last viewed article doesn't affect posting styles:
623 (buffer (current-buffer)))
626 (setq gnus-newsgroup-name
628 (if (= 1 (prefix-numeric-value arg))
629 (completing-read "Use group: "
630 gnus-active-hashtb nil
631 (gnus-read-active-file-p))
632 (gnus-group-group-name))
634 ;; #### see comment in gnus-setup-message -- drv
635 (gnus-setup-message 'message
636 (message-news (gnus-group-real-name gnus-newsgroup-name))))
639 (setq gnus-newsgroup-name group)))))
641 (defun gnus-group-post-news (&optional arg)
642 "Start composing a message (a news by default).
643 If ARG, post to group under point. If ARG is 1, prompt for group name.
644 Depending on the selected group, the message might be either a mail or
647 ;; Bind this variable here to make message mode hooks work ok.
648 (let ((gnus-newsgroup-name
650 (if (= 1 (prefix-numeric-value arg))
651 (completing-read "Newsgroup: " gnus-active-hashtb nil
652 (gnus-read-active-file-p))
653 (gnus-group-group-name))
655 ;; make sure last viewed article doesn't affect posting styles:
657 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
658 (string= gnus-newsgroup-name ""))))
660 (defun gnus-summary-mail-other-window (&optional arg)
661 "Start composing a mail in another window.
662 Use the posting of the current group by default.
663 If ARG, don't do that. If ARG is 1, prompt for group name to find the
666 ;; We can't `let' gnus-newsgroup-name here, since that leads
667 ;; to local variables leaking.
668 (let ((group gnus-newsgroup-name)
669 ;; make sure last viewed article doesn't affect posting styles:
671 (buffer (current-buffer)))
674 (setq gnus-newsgroup-name
676 (if (= 1 (prefix-numeric-value arg))
677 (completing-read "Use group: "
678 gnus-active-hashtb nil
679 (gnus-read-active-file-p))
681 gnus-newsgroup-name))
682 ;; #### see comment in gnus-setup-message -- drv
683 (gnus-setup-message 'message (message-mail)))
686 (setq gnus-newsgroup-name group)))))
688 (defun gnus-summary-news-other-window (&optional arg)
689 "Start composing a news in another window.
690 Post to the current group by default.
691 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
693 This function prepares a news even when using mail groups. This is useful
694 for posting messages to mail groups without actually sending them over the
695 network. The corresponding back end must have a 'request-post method."
697 ;; We can't `let' gnus-newsgroup-name here, since that leads
698 ;; to local variables leaking.
699 (let ((group gnus-newsgroup-name)
700 ;; make sure last viewed article doesn't affect posting styles:
702 (buffer (current-buffer)))
705 (setq gnus-newsgroup-name
707 (if (= 1 (prefix-numeric-value arg))
708 (completing-read "Use group: "
709 gnus-active-hashtb nil
710 (gnus-read-active-file-p))
712 gnus-newsgroup-name))
713 ;; #### see comment in gnus-setup-message -- drv
714 (gnus-setup-message 'message
716 (message-news (gnus-group-real-name gnus-newsgroup-name))
717 (set (make-local-variable 'gnus-discouraged-post-methods)
719 (car (gnus-find-method-for-group gnus-newsgroup-name))
720 gnus-discouraged-post-methods)))))
723 (setq gnus-newsgroup-name group)))))
725 (defun gnus-summary-post-news (&optional arg)
726 "Start composing a message. Post to the current group by default.
727 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
728 Depending on the selected group, the message might be either a mail or
731 ;; Bind this variable here to make message mode hooks work ok.
732 (let ((gnus-newsgroup-name
734 (if (= 1 (prefix-numeric-value arg))
735 (completing-read "Newsgroup: " gnus-active-hashtb nil
736 (gnus-read-active-file-p))
738 gnus-newsgroup-name))
739 ;; make sure last viewed article doesn't affect posting styles:
741 (gnus-post-news 'post gnus-newsgroup-name)))
744 (defun gnus-summary-followup (yank &optional force-news)
745 "Compose a followup to an article.
746 If prefix argument YANK is non-nil, the original article is yanked
748 YANK is a list of elements, where the car of each element is the
749 article number, and the cdr is the string to be yanked."
751 (list (and current-prefix-arg
752 (gnus-summary-work-articles 1))))
754 (gnus-summary-goto-subject
755 (if (listp (car yank))
758 (save-window-excursion
759 (gnus-summary-select-article))
760 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
761 (gnus-newsgroup-name gnus-newsgroup-name))
763 (gnus-post-news nil gnus-newsgroup-name
764 headers gnus-article-buffer
766 (gnus-summary-handle-replysign)))
768 (defun gnus-summary-followup-with-original (n &optional force-news)
769 "Compose a followup to an article and include the original article.
770 The text in the region will be yanked. If the region isn't
771 active, the entire article will be yanked."
773 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
775 (defun gnus-summary-followup-to-mail (&optional arg)
776 "Followup to the current mail message via news."
778 (list (and current-prefix-arg
779 (gnus-summary-work-articles 1))))
780 (gnus-summary-followup arg t))
782 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
783 "Followup to the current mail message via news."
785 (gnus-summary-followup (gnus-summary-work-articles arg) t))
787 (defun gnus-inews-yank-articles (articles)
788 (let (beg article yank-string
789 (more-than-one (cdr articles))
790 (cur (current-buffer))
793 (while (setq article (pop articles))
794 (when (listp article)
795 (setq yank-string (nth 1 article)
796 article (nth 0 article)))
797 (save-window-excursion
798 (set-buffer gnus-summary-buffer)
799 (gnus-summary-select-article nil nil nil article)
800 (gnus-summary-remove-process-mark article))
802 ;; Gathering references.
804 (setq refs (message-list-references
806 (mail-header-references gnus-current-headers)
807 (mail-header-message-id gnus-current-headers)))
808 (when message-use-multi-frames
809 (when (setq window (get-buffer-window cur t))
810 (select-frame (window-frame window)))))
812 (gnus-copy-article-buffer nil yank-string)
813 (let ((message-reply-buffer gnus-article-copy)
814 (message-reply-headers
815 ;; The headers are decoded.
816 (with-current-buffer gnus-article-copy
818 (nnheader-narrow-to-headers)
819 (nnheader-parse-naked-head)))))
820 (message-yank-original)
821 (setq beg (or beg (mark t))))
826 ;; Replace with the gathered references.
830 (message-narrow-to-headers)
831 (let ((case-fold-search t))
832 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
834 (goto-char (point-max))))
836 (list (or (assq 'References message-header-format-alist)
837 '(References . message-shorten-references)))
838 (list (cons 'References
839 (mapconcat 'identity (nreverse refs) " "))))
840 (backward-delete-char 1))
846 (defun gnus-summary-cancel-article (&optional n symp)
847 "Cancel an article you posted.
848 Uses the process-prefix convention. If given the symbolic
849 prefix `a', cancel using the standard posting method; if not
850 post using the current select method."
851 (interactive (gnus-interactive "P\ny"))
852 (let ((message-post-method
854 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
855 (dolist (article (gnus-summary-work-articles n))
856 (when (gnus-summary-select-article t nil nil article)
857 (when (gnus-eval-in-buffer-window gnus-article-buffer
859 (set-buffer gnus-original-article-buffer)
860 (message-cancel-news)))
861 (gnus-summary-mark-as-read article gnus-canceled-mark)
862 (gnus-cache-remove-article 1))
863 (gnus-article-hide-headers-if-wanted))
864 (gnus-summary-remove-process-mark article))))
866 (defun gnus-summary-supersede-article ()
867 "Compose an article that will supersede a previous article.
868 This is done simply by taking the old article and adding a Supersedes
869 header line with the old Message-ID."
871 (let ((article (gnus-summary-article-number)))
872 (gnus-setup-message 'reply-yank
873 (gnus-summary-select-article t)
874 (set-buffer gnus-original-article-buffer)
878 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
880 (set-buffer ,gnus-summary-buffer)
881 (gnus-cache-possibly-remove-article ,article nil nil nil t)
882 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
883 message-send-actions))))
887 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
888 ;; make a copy of the article buffer with all text properties removed
889 ;; this copy is in the buffer gnus-article-copy.
890 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
891 ;; this buffer should be passed to all mail/news reply/post routines.
892 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
894 (set-buffer gnus-article-copy)
895 (set-buffer-multibyte t))
896 (let ((article-buffer (or article-buffer gnus-article-buffer))
898 (if (not (and (get-buffer article-buffer)
899 (gnus-buffer-exists-p article-buffer)))
900 (error "Can't find any article buffer")
902 (set-buffer article-buffer)
903 (let ((gnus-newsgroup-charset (or gnus-article-charset
904 gnus-newsgroup-charset))
905 (gnus-newsgroup-ignored-charsets
906 (or gnus-article-ignored-charsets
907 gnus-newsgroup-ignored-charsets)))
909 ;; Copy over the (displayed) article buffer, delete
910 ;; hidden text and remove text properties.
912 (copy-to-buffer gnus-article-copy (point-min) (point-max))
913 (set-buffer gnus-article-copy)
914 ;; There's invisible and intangible text in T-gnus. Especially,
915 ;; if there is a boundary line (X-Boundary: ------------------),
916 ;; in the end of a header, it will cause a serious problem.
917 (add-text-properties (point-min) (point-max)
918 '(invisible nil intangible nil))
921 (delete-region (point) (point-max))
922 (insert yank-string))
923 ;; Encode bitmap smileys to ordinary text.
924 ;; Possibly, the original text might be restored.
925 (static-unless (featurep 'xemacs)
926 (when (featurep 'smiley-mule)
927 (smiley-encode-buffer)))
928 (gnus-article-delete-text-of-type 'annotation)
929 (gnus-remove-text-with-property 'gnus-prev)
930 (gnus-remove-text-with-property 'gnus-next)
931 (gnus-remove-text-with-property 'gnus-decoration)
932 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
935 (static-if (featurep 'xemacs)
936 ;; Revome smiley extents for (possibly) XEmacs 21.1.
938 (buffer-substring-no-properties (point-min)
940 (buffer-substring-no-properties (point-min) (point-max)))
942 ;; Find the original headers.
943 (set-buffer gnus-original-article-buffer)
944 (goto-char (point-min))
945 (while (looking-at message-unix-mail-delimiter)
947 (let ((mail-header-separator ""))
949 end (or (message-goto-body)
950 ;; There may be just a header.
952 ;; Delete the headers from the displayed articles.
953 (set-buffer gnus-article-copy)
954 (let ((mail-header-separator ""))
955 (delete-region (goto-char (point-min))
956 (or (message-goto-body) (point-max))))
957 ;; Insert the original article headers.
958 (insert-buffer-substring gnus-original-article-buffer beg end)
960 (let ((gnus-article-decode-hook
961 (delq 'article-decode-charset
962 (copy-sequence gnus-article-decode-hook))))
963 ;; Needed for T-gnus.
964 (add-hook 'gnus-article-decode-hook
965 'article-decode-encoded-words)
966 (run-hooks 'gnus-article-decode-hook)))))
969 (defun gnus-post-news (post &optional group header article-buffer yank subject
972 (gnus-copy-article-buffer))
973 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
974 (gnus-article-yanked-articles yank)
975 (add-to-list gnus-add-to-list))
976 (gnus-setup-message (cond (yank 'reply-yank)
977 (article-buffer 'reply)
979 (let* ((group (or group gnus-newsgroup-name))
980 (charset (gnus-group-name-charset nil group))
982 to-address to-group mailing-list to-list
985 (setq to-address (gnus-parameter-to-address group)
986 to-group (gnus-group-find-parameter group 'to-group)
987 to-list (gnus-parameter-to-list group)
988 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
989 mailing-list (when gnus-mailing-list-groups
990 (string-match gnus-mailing-list-groups group))
991 group (gnus-group-name-decode (gnus-group-real-name group)
993 (if (or (and to-group
994 (gnus-news-group-p to-group))
997 (and (gnus-news-group-p
998 (or pgroup gnus-newsgroup-name)
999 (or header gnus-current-article))
1007 (and (not (gnus-virtual-group-p pgroup)) group)))
1008 (set-buffer gnus-article-copy)
1009 (gnus-msg-treat-broken-reply-to)
1010 (message-followup (if (or newsgroup-p force-news)
1011 (if (save-restriction
1012 (article-narrow-to-head)
1013 (message-fetch-field "newsgroups"))
1020 (message-mail (or to-address to-list))
1021 ;; Arrange for mail groups that have no `to-address' to
1022 ;; get that when the user sends off the mail.
1023 (when (and (not to-list)
1026 (push (list 'gnus-inews-add-to-address pgroup)
1027 message-send-actions)))
1028 (set-buffer gnus-article-copy)
1029 (gnus-msg-treat-broken-reply-to)
1030 (message-wide-reply to-address)))
1032 (gnus-inews-yank-articles yank))))))
1034 (defun gnus-msg-treat-broken-reply-to (&optional force)
1035 "Remove the Reply-to header if broken-reply-to."
1037 (gnus-group-find-parameter
1038 gnus-newsgroup-name 'broken-reply-to))
1040 (message-narrow-to-head)
1041 (message-remove-header "reply-to"))))
1043 (defun gnus-post-method (arg group &optional silent)
1044 "Return the posting method based on GROUP and ARG.
1045 If SILENT, don't prompt the user."
1046 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1048 (group-method (gnus-find-method-for-group group)))
1050 ;; If the group-method is nil (which shouldn't happen) we use
1051 ;; the default method.
1052 ((null group-method)
1053 (or (and (listp gnus-post-method) ;If not current/native/nil
1054 (not (listp (car gnus-post-method))) ; and not a list of methods
1055 gnus-post-method) ;then use it.
1057 message-post-method))
1058 ;; We want the inverse of the default
1059 ((and arg (not (eq arg 0)))
1060 (if (eq gnus-post-method 'current)
1063 ;; We query the user for a post method.
1065 (and (listp gnus-post-method)
1066 (listp (car gnus-post-method))))
1068 ;; Collect all methods we know about.
1070 (when (listp gnus-post-method)
1071 (if (listp (car gnus-post-method))
1073 (list gnus-post-method)))
1074 gnus-secondary-select-methods
1075 (mapcar 'cdr gnus-server-alist)
1076 (mapcar 'car gnus-opened-servers)
1077 (list gnus-select-method)
1078 (list group-method)))
1079 method-alist post-methods method)
1080 ;; Weed out all mail methods.
1082 (setq method (gnus-server-get-method "" (pop methods)))
1083 (when (and (or (gnus-method-option-p method 'post)
1084 (gnus-method-option-p method 'post-mail))
1085 (not (member method post-methods)))
1086 (push method post-methods)))
1087 ;; Create a name-method alist.
1091 (if (equal (cadr m) "")
1092 (list (symbol-name (car m)) m)
1093 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1098 (setq gnus-last-posting-server
1100 gnus-last-posting-server)
1101 ;; Just use the last value.
1102 gnus-last-posting-server
1104 "Posting method: " method-alist nil t
1105 (cons (or gnus-last-posting-server "") 0))))
1107 ;; Override normal method.
1108 ((and (eq gnus-post-method 'current)
1109 (not (memq (car group-method) gnus-discouraged-post-methods))
1110 (gnus-get-function group-method 'request-post t))
1113 ;; Use gnus-post-method.
1114 ((listp gnus-post-method) ;A method...
1115 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1117 ;; Use the normal select method (nil or native).
1118 (t gnus-select-method))))
1121 ;; Dummies to avoid byte-compile warning.
1123 (defvar xemacs-codename))
1125 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1127 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1128 variable `mime-edit-user-agent-value' is bound, the value will be
1129 included in the return value, and `gnus-user-agent' is ignored. If
1130 MAX-COLUMN is specified, the return value will be folded up as it were
1131 filled. NEWLINE-PRODUCT specifies whether a newline should be
1132 inserted in front of each product-token. If the value is t or `hard',
1133 it works strictly. Otherwise, if it is non-nil (e.g. `soft'), it
1134 works semi-strictly.
1136 Here is an odd example, which inserts a User-Agent: header when you
1137 begin to compose a message:
1139 \(add-hook 'gnus-message-setup-hook
1141 (setq message-user-agent nil)
1144 (message-narrow-to-headers)
1145 (goto-char (point-max))
1146 (insert \"User-Agent: \"
1147 (gnus-message-make-user-agent t 76 'soft)
1150 (let ((gnus-v (gnus-extended-version))
1152 (cond ((and include-mime-info
1153 (boundp 'mime-edit-user-agent-value))
1154 (setq user-agent (concat gnus-v " " mime-edit-user-agent-value)))
1155 ((eq gnus-user-agent 'gnus-mime-edit)
1157 (if (boundp 'mime-edit-user-agent-value)
1158 (concat gnus-v " " mime-edit-user-agent-value)
1161 (setq user-agent (if (stringp gnus-user-agent)
1164 (let ((emacs-v (gnus-emacs-version)))
1166 (concat " " emacs-v))))))))
1168 (unless (natnump max-column)
1169 (setq max-column 76))
1171 (set-buffer-multibyte t)
1172 (insert (mapconcat 'identity (split-string user-agent) " "))
1173 (goto-char (point-min))
1175 start agent agents width element swidth)
1176 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1177 (setq start (match-beginning 0))
1178 (if (eq (char-after start) ?\()
1182 (push (buffer-substring start (point)) agent))
1184 (push (nreverse agent) agents))
1185 (setq agent (list (match-string 1)))))
1187 (push (nreverse agent) agents))
1188 (setq agents (nreverse agents))
1189 (if (> (+ 12 (string-width (caar agents))) max-column)
1190 (setq user-agent "\n"
1195 (setq agent (car agents)
1196 agents (cdr agents))
1197 (when (and (not bol)
1198 (or (memq newline-product '(t hard))
1199 (and newline-product
1201 (string-width (mapconcat 'identity
1204 (setq user-agent (concat user-agent "\n")
1208 (setq element (car agent)
1209 swidth (string-width element)
1212 (setq user-agent (if (member user-agent '("" "\n"))
1213 (concat user-agent element)
1214 (concat user-agent " " element))
1215 width (+ width 1 swidth)
1217 (if (> (+ width 1 swidth) max-column)
1218 (setq user-agent (concat user-agent "\n " element)
1220 (setq user-agent (concat user-agent " " element)
1221 width (+ width 1 swidth)))))))))
1226 ;;; Gnus Mail Functions
1229 ;;; Mail reply commands of Gnus summary mode
1231 (defun gnus-summary-reply (&optional yank wide very-wide)
1232 "Start composing a mail reply to the current message.
1233 If prefix argument YANK is non-nil, the original article is yanked
1235 If WIDE, make a wide reply.
1236 If VERY-WIDE, make a very wide reply."
1238 (list (and current-prefix-arg
1239 (gnus-summary-work-articles 1))))
1240 ;; Allow user to require confirmation before replying by mail to the
1241 ;; author of a news article (or mail message).
1243 (not (or (gnus-news-group-p gnus-newsgroup-name)
1244 gnus-confirm-treat-mail-like-news))
1245 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1246 (string-match gnus-confirm-mail-reply-to-news
1247 gnus-newsgroup-name))
1248 ((functionp gnus-confirm-mail-reply-to-news)
1249 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1250 (t gnus-confirm-mail-reply-to-news)))
1251 (y-or-n-p "Really reply by mail to article author? "))
1253 (if (listp (car yank))
1256 (gnus-article-reply (or article (gnus-summary-article-number)))
1257 (gnus-article-yanked-articles yank)
1259 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1261 (gnus-summary-goto-subject article))
1262 (gnus-setup-message (if yank 'reply-yank 'reply)
1264 (gnus-summary-select-article)
1265 (dolist (article very-wide)
1266 (gnus-summary-select-article nil nil nil article)
1268 (set-buffer (gnus-copy-article-buffer))
1269 (gnus-msg-treat-broken-reply-to)
1271 (message-narrow-to-head)
1272 (setq headers (concat headers (buffer-string)))))))
1273 (set-buffer (gnus-copy-article-buffer))
1274 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1276 (message-narrow-to-head)
1280 (goto-char (point-max)))
1281 (message-reply nil wide)
1283 (gnus-inews-yank-articles yank))
1284 (gnus-summary-handle-replysign)))))
1286 (defun gnus-summary-handle-replysign ()
1287 "Check the various replysign variables and take action accordingly."
1288 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1289 (let (signed encrypted)
1291 (set-buffer gnus-article-buffer)
1292 (setq signed (memq 'signed gnus-article-wash-types))
1293 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1294 (cond ((and gnus-message-replyencrypt encrypted)
1295 (mml-secure-message mml-default-encrypt-method
1296 (if gnus-message-replysignencrypted
1299 ((and gnus-message-replysign signed)
1300 (mml-secure-message mml-default-sign-method 'sign))))))
1302 (defun gnus-summary-reply-with-original (n &optional wide)
1303 "Start composing a reply mail to the current message.
1304 The original article will be yanked."
1306 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1308 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1309 "Like `gnus-summary-reply' except removing reply-to field.
1310 If prefix argument YANK is non-nil, the original article is yanked
1312 If WIDE, make a wide reply.
1313 If VERY-WIDE, make a very wide reply."
1315 (list (and current-prefix-arg
1316 (gnus-summary-work-articles 1))))
1317 (let ((gnus-msg-force-broken-reply-to t))
1318 (gnus-summary-reply yank wide very-wide)))
1320 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1321 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1322 The original article will be yanked."
1324 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1326 (defun gnus-summary-wide-reply (&optional yank)
1327 "Start composing a 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))
1335 (defun gnus-summary-wide-reply-with-original (n)
1336 "Start composing a wide reply mail to the current message.
1337 The original article will be yanked.
1338 Uses the process/prefix convention."
1340 (gnus-summary-reply-with-original n t))
1342 (defun gnus-summary-very-wide-reply (&optional yank)
1343 "Start composing a very wide reply mail to the current message.
1344 If prefix argument YANK is non-nil, the original article is yanked
1347 (list (and current-prefix-arg
1348 (gnus-summary-work-articles 1))))
1349 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1351 (defun gnus-summary-very-wide-reply-with-original (n)
1352 "Start composing a very wide reply mail to the current message.
1353 The original article will be yanked."
1356 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1358 (defun gnus-summary-mail-forward (&optional full-headers post)
1359 "Forward the current message(s) to another user.
1360 If process marks exist, forward all marked messages;
1361 If FULL-HEADERS (the prefix), include full headers when forwarding.
1363 Note that this function definition for T-gnus is totally different
1364 from the original Gnus."
1366 (if (cdr (gnus-summary-work-articles nil))
1367 ;; Process marks are given.
1368 (gnus-summary-digest-mail-forward nil post)
1369 ;; No process marks.
1370 (let* ((gnus-article-reply (gnus-summary-article-number))
1371 (gnus-article-yanked-articles (list gnus-article-reply))
1373 (message-included-forward-headers
1374 (if full-headers "" message-included-forward-headers)))
1375 (gnus-setup-message 'forward
1376 (gnus-summary-select-article)
1377 (setq charset default-mime-charset)
1378 (set-buffer gnus-original-article-buffer)
1379 (make-local-variable 'default-mime-charset)
1380 (setq default-mime-charset charset)
1381 (message-forward post)))))
1383 (defun gnus-summary-digest-mail-forward (&optional n post)
1384 "Digests and forwards all articles in this series.
1385 If N is a positive number, forward the N next articles.
1386 If N is a negative number, forward the N previous articles.
1387 If N is nil and any articles have been marked with the process mark,
1388 forward those articles instead.
1389 Optional POST will use news to forward instead of mail."
1391 (let* ((articles (gnus-summary-work-articles n))
1392 (gnus-article-yanked-articles (copy-sequence articles))
1393 (topics "Topics:\n")
1394 subject article frame)
1395 (when (car articles)
1396 (gnus-setup-message 'forward
1397 (gnus-summary-select-article)
1399 (setq articles (sort articles '<)
1400 subject "Digested Articles")
1401 (with-current-buffer gnus-original-article-buffer
1402 (setq subject (message-make-forward-subject))))
1404 (message-news nil subject)
1405 (message-mail nil subject))
1406 (when (and message-use-multi-frames (cdr articles))
1407 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1409 (while (setq article (pop articles))
1410 (save-window-excursion
1411 (set-buffer gnus-summary-buffer)
1412 (gnus-summary-select-article nil nil nil article)
1413 (setq topics (concat topics " "
1414 (mail-header-subject gnus-current-headers)
1416 (gnus-summary-remove-process-mark article))
1418 (select-frame frame))
1419 (insert (mime-make-tag "message" "rfc822") "\n")
1420 (narrow-to-region (point) (point))
1421 (insert-buffer-substring gnus-original-article-buffer)
1423 (article-narrow-to-head)
1424 (message-remove-header message-included-forward-headers t nil t))
1425 (goto-char (point-max))
1431 (mime-edit-enclose-digest-region (point)(mark t))))))
1433 (defun gnus-summary-digest-post-forward (&optional n)
1434 "Digest and forwards all articles in this series to a newsgroup.
1435 If N is a positive number, forward the N next articles.
1436 If N is a negative number, forward the N previous articles.
1437 If N is nil and any articles have been marked with the process mark,
1438 forward those articles instead."
1440 (gnus-summary-digest-mail-forward n t))
1442 (defun gnus-summary-resend-message (address n)
1443 "Resend the current article to ADDRESS."
1445 (list (message-read-from-minibuffer
1446 "Resend message(s) to: "
1447 (when (and gnus-summary-resend-default-address
1448 (gnus-buffer-live-p gnus-original-article-buffer))
1449 ;; If some other article is currently selected, the
1450 ;; initial-contents is wrong. Whatever, it is just the
1451 ;; initial-contents.
1452 (with-current-buffer gnus-original-article-buffer
1453 (nnmail-fetch-field "to"))))
1454 current-prefix-arg))
1455 (dolist (article (gnus-summary-work-articles n))
1456 (gnus-summary-select-article nil nil nil article)
1458 (set-buffer gnus-original-article-buffer)
1459 (message-resend address))
1460 (gnus-summary-mark-article-as-forwarded article)))
1462 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1463 (defun gnus-summary-resend-message-edit ()
1464 "Resend an article that has already been sent.
1465 A new buffer will be created to allow the user to modify body and
1466 contents of the message, and then, everything will happen as when
1467 composing a new message."
1469 (let ((article (gnus-summary-article-number)))
1470 (gnus-setup-message 'reply-yank
1471 (gnus-summary-select-article t)
1472 (set-buffer gnus-original-article-buffer)
1473 (let ((cur (current-buffer))
1474 (to (message-fetch-field "to")))
1475 ;; Get a normal message buffer.
1476 (message-pop-to-buffer (message-buffer-name "Resend" to))
1477 (insert-buffer-substring cur)
1479 ;; T-gnus change: Use MIME-Edit to recompose a message.
1481 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1482 (fset 'mime-edit-decode-single-part-in-buffer
1483 (lambda (&rest args)
1484 (if (let ((content-type (car args)))
1485 (and (eq 'message (mime-content-type-primary-type
1487 (eq 'rfc822 (mime-content-type-subtype
1489 (setcar (cdr args) 'not-decode-text))
1492 (mime-edit-again nil t)
1493 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1494 (message-narrow-to-head-1)
1495 (insert "From: " (message-make-from) "\n")
1496 (while (re-search-forward "^From:" nil t)
1498 (insert "Original-"))
1499 (message-remove-header "^>From[\t ]" t)
1501 ;; Gnus will generate a new one when sending.
1502 (message-remove-header "Message-ID")
1503 (message-remove-header message-ignored-resent-headers t)
1504 ;; Remove unwanted headers.
1505 (goto-char (point-max))
1506 (insert mail-header-separator)
1507 (goto-char (point-min))
1508 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1512 (defun gnus-summary-post-forward (&optional full-headers)
1513 "Forward the current article to a newsgroup.
1514 If FULL-HEADERS (the prefix), include full headers when forwarding."
1516 (gnus-summary-mail-forward full-headers t))
1518 (defvar gnus-nastygram-message
1519 "The following article was inappropriately posted to %s.\n\n"
1520 "Format string to insert in nastygrams.
1521 The current group name will be inserted at \"%s\".")
1523 (defun gnus-summary-mail-nastygram (n)
1524 "Send a nastygram to the author of the current article."
1526 (when (or gnus-expert-user
1528 "Really send a nastygram to the author of the current article? "))
1529 (let ((group gnus-newsgroup-name))
1530 (gnus-summary-reply-with-original n)
1531 (set-buffer gnus-message-buffer)
1533 (insert (format gnus-nastygram-message group))
1534 (message-send-and-exit))))
1536 (defun gnus-summary-mail-crosspost-complaint (n)
1537 "Send a complaint about crossposting to the current article(s)."
1539 (dolist (article (gnus-summary-work-articles n))
1540 (set-buffer gnus-summary-buffer)
1541 (gnus-summary-goto-subject article)
1542 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1543 newsgroups followup-to)
1544 (gnus-summary-select-article)
1545 (set-buffer gnus-original-article-buffer)
1546 (if (and (<= (length (message-tokenize-header
1548 (mail-fetch-field "newsgroups"))
1551 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1552 (not (member group (message-tokenize-header
1553 followup-to ", ")))))
1555 (gnus-message 1 "Followup-to restricted")
1556 (gnus-message 1 "Not a crossposted article"))
1557 (set-buffer gnus-summary-buffer)
1558 (gnus-summary-reply-with-original 1)
1559 (set-buffer gnus-message-buffer)
1561 (insert (format gnus-crosspost-complaint newsgroups group))
1562 (message-goto-subject)
1563 (re-search-forward " *$")
1564 (replace-match " (crosspost notification)" t t)
1565 (gnus-deactivate-mark)
1566 (when (gnus-y-or-n-p "Send this complaint? ")
1567 (message-send-and-exit))))))
1569 (defun gnus-mail-parse-comma-list ()
1572 (skip-chars-forward " ")
1575 (skip-chars-forward "^,")
1580 (narrow-to-region beg (point))
1583 (while (search-forward "\"" nil t)
1587 (skip-chars-forward ",")
1588 (skip-chars-forward "^,"))
1589 (skip-chars-backward " ")
1590 (push (buffer-substring beg (point))
1592 (skip-chars-forward "^,")
1593 (skip-chars-forward ", "))
1596 (defun gnus-inews-add-to-address (group)
1597 (let ((to-address (mail-fetch-field "to")))
1598 (when (and to-address
1600 ;; This mail group doesn't have a `to-list', so we add one
1602 (when (gnus-y-or-n-p
1603 (format "Do you want to add this as `to-list': %s? " to-address))
1604 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1606 (defun gnus-put-message ()
1607 "Put the current message in some group and return to Gnus."
1609 (let ((reply gnus-article-reply)
1610 (winconf gnus-prev-winconf)
1611 (group gnus-newsgroup-name))
1613 (not (gnus-group-read-only-p group)))
1614 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1616 (when (gnus-group-entry group)
1617 (error "No such group: %s" group))
1621 (message-narrow-to-headers)
1622 (let ((gnus-deletable-headers nil))
1623 (message-generate-headers
1624 (if (message-news-p)
1625 message-required-news-headers
1626 message-required-mail-headers)))
1627 (goto-char (point-max))
1628 (if (string-match " " group)
1629 (insert "Gcc: \"" group "\"\n")
1630 (insert "Gcc: " group "\n"))
1633 (when (and (get-buffer gnus-group-buffer)
1634 (gnus-buffer-exists-p (car-safe reply))
1636 (set-buffer (car reply))
1637 (gnus-summary-mark-article-as-replied (cdr reply)))
1639 (set-window-configuration winconf))))
1641 (defun gnus-article-mail (yank)
1642 "Send a reply to the address near point.
1643 If YANK is non-nil, include the original article."
1647 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1648 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1650 (gnus-msg-mail address)
1652 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1654 (defvar nntp-server-type)
1656 "Send a bug report to the Gnus maintainers."
1658 (unless (gnus-alive-p)
1659 (error "Gnus has been shut down"))
1660 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1661 (unless (message-mail-user-agent)
1662 (message-pop-to-buffer "*Gnus Bug*")
1663 (delete-other-windows)
1664 (when gnus-bug-create-help-buffer
1665 (switch-to-buffer "*Gnus Help Bug*")
1667 (insert gnus-bug-message)
1668 (goto-char (point-min))
1670 (set-buffer "*Gnus Bug*")))
1671 (let ((message-this-is-mail t))
1672 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1673 (when gnus-bug-create-help-buffer
1674 (push `(gnus-bug-kill-buffer) message-send-actions))
1675 (goto-char (point-min))
1676 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1678 (insert gnus-product-name " " gnus-version-number
1679 " (r" gnus-revision-number ") "
1680 "based on " gnus-original-product-name " v"
1681 gnus-original-version-number "\n"
1682 (emacs-version) "\n")
1683 (when (and (boundp 'nntp-server-type)
1684 (stringp nntp-server-type))
1685 (insert nntp-server-type))
1686 (insert "\n\n\n\n\n")
1687 (let (mime-content-types)
1688 (mime-edit-insert-tag
1689 "application" "emacs-lisp"
1690 "\nContent-Disposition: inline\nContent-Description: User settings"))
1691 (insert (with-temp-buffer
1694 (let (mime-content-types)
1695 (mime-edit-insert-tag "text" "plain"))
1696 (goto-char (point-min))
1697 (search-forward "Subject: " nil t)
1700 (defun gnus-bug-kill-buffer ()
1701 (when (get-buffer "*Gnus Help Bug*")
1702 (kill-buffer "*Gnus Help Bug*")))
1704 (defun gnus-summary-yank-message (buffer n)
1705 "Yank the current article into a composed message."
1707 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1708 current-prefix-arg))
1709 (when (gnus-buffer-live-p buffer)
1710 (let ((summary-frame (selected-frame))
1711 (message-frame (when (static-if (featurep 'xemacs)
1712 (device-on-window-system-p)
1714 (let ((window (get-buffer-window buffer t)))
1716 (window-frame window)))))
1717 (separator (concat "^" (regexp-quote mail-header-separator)
1719 (gnus-summary-iterate n
1720 (gnus-summary-select-article)
1721 (gnus-copy-article-buffer)
1722 (when (frame-live-p message-frame)
1723 (raise-frame message-frame)
1724 (select-frame message-frame))
1725 (with-current-buffer buffer
1726 (when (save-excursion
1728 (let (case-fold-search)
1729 (and (not (re-search-backward separator nil t))
1730 (re-search-forward separator nil t))))
1731 (goto-char (match-end 0)))
1732 (message-yank-buffer gnus-article-copy))
1733 (select-frame summary-frame))
1734 (when (frame-live-p message-frame)
1735 (select-frame message-frame)))))
1737 (defun gnus-debug ()
1738 "Attempts to go through the Gnus source file and report what variables have been changed.
1739 The source file has to be in the Emacs load path."
1741 (let ((files gnus-debug-files)
1743 file expr olist sym)
1744 (gnus-message 4 "Please wait while we snoop your variables...")
1745 ;; Go through all the files looking for non-default values for variables.
1748 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1751 (when (and (setq file (locate-library (pop files)))
1752 (file-exists-p file))
1753 (insert-file-contents file)
1754 (goto-char (point-min))
1755 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1756 (gnus-message 4 "Malformed sources in file %s" file)
1757 (narrow-to-region (point-min) (point))
1758 (goto-char (point-min))
1759 (while (setq expr (ignore-errors (read (current-buffer))))
1761 (and (memq (car expr) '(defvar defcustom defvoo))
1762 (stringp (nth 3 expr))
1763 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1764 (or (not (boundp (nth 1 expr)))
1765 (not (equal (eval (nth 2 expr))
1766 (symbol-value (nth 1 expr)))))
1767 (push (nth 1 expr) olist)))))))
1768 (kill-buffer (current-buffer)))
1769 (when (setq olist (nreverse olist))
1770 (insert ";----------------- Environment follows ------------------\n\n"))
1772 (if (boundp (car olist))
1776 ,(if (or (consp (setq sym (symbol-value (car olist))))
1778 (not (or (eq sym nil)
1780 (list 'quote (symbol-value (car olist)))
1781 (symbol-value (car olist))))))
1782 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1783 (setq olist (cdr olist)))
1784 ;; Remove any control chars - they seem to cause trouble for some
1785 ;; mailers. (Byte-compiled output from the stuff above.)
1787 (while (re-search-forward (string-as-multibyte
1788 "[\000-\010\013-\037\200-\237]") nil t)
1789 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1791 ;; Break MIME tags purposely.
1793 (while (re-search-forward mime-edit-tag-regexp nil t)
1794 (goto-char (1+ (match-beginning 0)))
1797 ;;; Treatment of rejected articles.
1800 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1801 "Re-mail the current message.
1802 This only makes sense if the current message is a bounce message that
1803 contains some mail you have written which has been bounced back to
1805 If FETCH, try to fetch the article that this is a reply to, if indeed
1808 (gnus-summary-select-article t)
1809 (set-buffer gnus-original-article-buffer)
1810 (gnus-setup-message 'compose-bounce
1811 (let* ((references (mail-fetch-field "references"))
1812 (parent (and references (gnus-parent-id references))))
1814 ;; If there are references, we fetch the article we answered to.
1816 (gnus-summary-refer-article parent)
1817 (gnus-summary-show-all-headers)))))
1821 (defun gnus-inews-group-method (group)
1823 ;; If the group doesn't exist, we assume
1824 ;; it's an archive group...
1825 ((and (null (gnus-get-info group))
1826 (eq (car (gnus-server-to-method gnus-message-archive-method))
1827 (car (gnus-server-to-method (gnus-group-method group)))))
1828 gnus-message-archive-method)
1830 ((gnus-info-method (gnus-get-info group))
1831 (gnus-info-method (gnus-get-info group)))
1833 (t (gnus-server-to-method (gnus-group-method group)))))
1835 ;; Do Gcc handling, which copied the message over to some group.
1836 (defun gnus-inews-do-gcc (&optional gcc)
1840 (message-narrow-to-headers)
1841 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1842 (coding-system-for-write 'raw-text)
1843 groups group method group-art
1844 mml-externalize-attachments)
1846 (message-remove-header "gcc")
1848 (setq groups (message-unquote-tokens
1849 (message-tokenize-header gcc " ,")))
1850 ;; Copy the article over to some group(s).
1851 (while (setq group (pop groups))
1852 (unless (gnus-check-server
1853 (setq method (gnus-inews-group-method group)))
1854 (error "Can't open server %s" (if (stringp method) method
1856 (unless (gnus-request-group group nil method)
1857 (gnus-request-create-group group method))
1858 (setq mml-externalize-attachments
1859 (if (stringp gnus-gcc-externalize-attachments)
1860 (string-match gnus-gcc-externalize-attachments group)
1861 gnus-gcc-externalize-attachments))
1863 (nnheader-set-temp-buffer " *acc*")
1864 (insert-buffer-substring message-encoding-buffer)
1865 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1866 (goto-char (point-min))
1867 (when (re-search-forward
1868 (concat "^" (regexp-quote mail-header-separator) "$")
1870 (replace-match "" t t ))
1871 (when (or (not (gnus-check-backend-function
1872 'request-accept-article group))
1873 (not (setq group-art
1874 (gnus-request-accept-article
1875 group method t t))))
1876 (gnus-message 1 "Couldn't store article in group %s: %s"
1877 group (gnus-status-message method)))
1878 (when (and group-art
1879 ;; FIXME: Should gcc-mark-as-read work when
1880 ;; Gnus is not running?
1882 (or gnus-gcc-mark-as-read
1884 (boundp 'gnus-inews-mark-gcc-as-read)
1885 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1886 (gnus-group-mark-article-read group (cdr group-art)))
1887 (kill-buffer (current-buffer)))))))))
1889 (defun gnus-inews-insert-gcc ()
1890 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1893 (message-narrow-to-headers)
1894 (let* ((group gnus-outgoing-message-group)
1898 ((or (stringp group) (list group))
1903 (if (string-match " " gcc)
1904 (concat "\"" gcc "\"")
1906 (mapconcat (lambda (group)
1907 (if (string-match " " group)
1908 (concat "\"" group "\"")
1913 (defun gnus-inews-insert-archive-gcc (&optional group)
1914 "Insert the Gcc to say where the article is to be archived."
1915 (let* ((var gnus-message-archive-group)
1916 (group (or group gnus-newsgroup-name ""))
1918 (and gnus-newsgroup-name
1919 (not (equal gnus-newsgroup-name ""))
1920 (gnus-group-find-parameter
1921 gnus-newsgroup-name 'gcc-self)))
1925 ((null gnus-message-archive-method)
1929 ;; Just a single group.
1932 ;; We don't want this.
1934 ((and (listp var) (stringp (car var)))
1935 ;; A list of groups.
1939 (funcall var group))
1941 ;; An alist of regexps/functions/forms.
1946 ((stringp (caar var))
1948 (when (string-match (caar var) group)
1950 ((functionp (car var))
1952 (funcall (car var) group))
1954 (eval (car var)))))))
1955 (setq var (cdr var)))
1958 (when (or groups gcc-self-val)
1959 (when (stringp groups)
1960 (setq groups (list groups)))
1963 (message-narrow-to-headers)
1964 (goto-char (point-max))
1967 ;; Use the `gcc-self' param value instead.
1970 (if (stringp gcc-self-val)
1971 (if (string-match " " gcc-self-val)
1972 (concat "\"" gcc-self-val "\"")
1974 ;; In nndoc groups, we use the parent group name
1975 ;; instead of the current group.
1976 (let ((group (or (gnus-group-find-parameter
1977 gnus-newsgroup-name 'parent-group)
1979 (if (string-match " " group)
1980 (concat "\"" group "\"")
1982 (if (not (eq gcc-self-val 'none))
1984 (gnus-delete-line)))
1985 ;; Use the list of groups.
1986 (while (setq name (pop groups))
1987 (let ((str (if (string-match ":" name)
1989 (gnus-group-prefixed-name
1990 name gnus-message-archive-method))))
1991 (insert (if (string-match " " str)
1992 (concat "\"" str "\"")
1998 (defun gnus-mailing-list-followup-to ()
1999 "Look at the headers in the current buffer and return a Mail-Followup-To address."
2000 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
2001 (list-post (gnus-fetch-original-field "list-post")))
2002 (when (and list-post
2003 (string-match "mailto:\\([^>]+\\)" list-post))
2004 (setq list-post (match-string 1 list-post)))
2010 (defun gnus-configure-posting-styles (&optional group-name)
2011 "Configure posting styles according to `gnus-posting-styles'."
2012 (unless gnus-inhibit-posting-styles
2013 (let ((group (or group-name gnus-newsgroup-name ""))
2014 (styles gnus-posting-styles)
2015 style match attribute results
2017 ;; If the group has a posting-style parameter, add it at the end with a
2018 ;; regexp matching everything, to be sure it takes precedence over all
2020 (when gnus-newsgroup-name
2021 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2023 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2024 ;; Go through all styles and look for matches.
2025 (dolist (style styles)
2026 (setq match (pop style))
2027 (goto-char (point-min))
2030 ;; Regexp string match on the group name.
2031 (string-match match group))
2033 ;; Obsolete format of header match.
2034 (and (gnus-buffer-live-p gnus-article-copy)
2035 (with-current-buffer gnus-article-copy
2037 (nnheader-narrow-to-headers)
2038 (let ((header (message-fetch-field (pop style))))
2040 (string-match (pop style) header)))))))
2041 ((or (symbolp match)
2045 ;; Function to be called.
2048 ;; Variable to be checked.
2049 (symbol-value match))))
2052 ((eq (car match) 'header)
2053 ;; New format of header match.
2054 (and (gnus-buffer-live-p gnus-article-copy)
2055 (with-current-buffer gnus-article-copy
2057 (nnheader-narrow-to-headers)
2058 (let ((header (message-fetch-field (nth 1 match))))
2060 (string-match (nth 2 match) header)))))))
2062 ;; This is a form to be evaled.
2064 ;; We have a match, so we set the variables.
2065 (setq style (gnus-configure-posting-style style nil))
2066 (dolist (attribute style)
2067 (setq results (delq (assoc (car attribute) results) results))
2068 (push attribute results))))
2069 ;; Now we have all the styles, so we insert them.
2070 (setq name (assq 'name results)
2071 address (assq 'address results))
2072 (setq results (delq name (delq address results)))
2073 (gnus-make-local-hook 'message-setup-hook)
2074 (setq results (sort results (lambda (x y)
2075 (string-lessp (car x) (car y)))))
2076 (dolist (result results)
2077 (add-hook 'message-setup-hook
2079 ((eq 'eval (car result))
2081 ((eq 'body (car result))
2085 (insert ,(cdr result)))))
2086 ((eq 'signature (car result))
2087 (set (make-local-variable 'message-signature) nil)
2088 (set (make-local-variable 'message-signature-file) nil)
2089 (if (not (cdr result))
2093 (let ((message-signature ,(cdr result)))
2094 (when message-signature
2095 (message-insert-signature)))))))
2098 (if (symbolp (car result))
2099 (capitalize (symbol-name (car result)))
2103 (message-remove-header ,header)
2104 (let ((value ,(cdr result)))
2107 (insert ,header ": " value)
2109 (insert "\n")))))))))
2111 (when (or name address)
2112 (add-hook 'message-setup-hook
2114 (set (make-local-variable 'user-mail-address)
2115 ,(or (cdr address) user-mail-address))
2116 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2118 ,(or (cdr address) user-mail-address)))
2120 (message-remove-header "From")
2122 (insert "From: " (message-make-from) "\n"))))
2125 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2126 (defun gnus-configure-posting-style (style stack)
2127 "Parse one posting style STYLE and returns the value as an alist."
2128 (let (results element variable filep value v)
2129 (dolist (attribute style)
2130 (setq element (pop attribute)
2135 ((eq (car attribute) ':file)
2138 ((eq (car attribute) :value)
2142 ;; We get the value.
2147 ((or (symbolp value)
2149 (cond ((functionp value)
2152 (symbol-value value))))
2155 ;; Translate obsolescent value.
2157 ((eq element 'signature-file)
2158 (setq element 'signature
2160 ((eq element 'x-face-file)
2161 (setq element 'x-face
2163 ;; Get the contents of file elems.
2165 (setq v (with-temp-buffer
2166 (insert-file-contents v)
2167 (goto-char (point-max))
2171 (if (eq element 'import)
2173 (if (member v stack)
2174 (error "Circular import of \"%s\"" v))
2176 (nconc (nreverse (gnus-configure-posting-style
2177 (cdr (assoc v gnus-named-posting-styles))
2180 (push (cons element v) results)))
2181 (nreverse results)))
2183 (defun gnus-summary-execute-command-with-posting-style (style command)
2184 "Temporarily select a posting-style named STYLE and execute COMMAND."
2186 (let ((style (completing-read "Posting style: "
2187 gnus-named-posting-styles nil t)))
2191 (format "Command to execute with %s: " style))))))
2192 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2193 (call-interactively command)))
2196 ;;; @ for MIME Edit mode
2199 (defun gnus-maybe-setup-default-charset ()
2201 (and (boundp 'gnus-summary-buffer)
2202 (buffer-live-p gnus-summary-buffer)
2204 (set-buffer gnus-summary-buffer)
2205 default-mime-charset))))
2208 (make-local-variable 'default-mime-charset)
2209 (setq default-mime-charset charset)
2213 ;;; @ for MIME view mode
2216 (defun gnus-following-method (buf)
2217 (gnus-setup-message 'reply-yank
2219 (if (message-news-p)
2221 (message-reply nil 'wide))
2222 (let ((message-reply-buffer buf))
2223 (message-yank-original))
2224 (message-goto-body))
2228 ;;; Allow redefinition of functions.
2234 ;;; gnus-msg.el ends here