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
290 :type '(choice (const :tag "No" nil)
292 (regexp :tag "Iff group matches regexp")
293 (function :tag "Iff function evaluates to non-nil")))
295 (defcustom gnus-confirm-treat-mail-like-news
297 "If non-nil, Gnus will treat mail like news with regard to confirmation
298 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
299 for fine-tuning this.
300 If nil, Gnus will never ask for confirmation if replying to mail."
304 (defcustom gnus-summary-resend-default-address t
305 "If non-nil, Gnus tries to suggest a default address to resend to.
306 If nil, the address field will always be empty after invoking
307 `gnus-summary-resend-message'."
311 ;;; Internal variables.
313 (defvar gnus-inhibit-posting-styles nil
314 "Inhibit the use of posting styles.")
316 (defvar gnus-article-yanked-articles nil)
317 (defvar gnus-message-buffer "*Mail Gnus*")
318 (defvar gnus-article-copy nil)
319 (defvar gnus-check-before-posting nil)
320 (defvar gnus-last-posting-server nil)
321 (defvar gnus-message-group-art nil)
323 (defvar gnus-msg-force-broken-reply-to nil)
325 (defconst gnus-bug-message
326 (format "Sending a bug report to the Gnus Towers.
327 ========================================
329 This gnus is the %s%s.
330 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
331 Developers. (the addresses below are mailing list addresses)
333 ========================================
335 The buffer below is a mail buffer. When you press `C-c C-c', it will
336 be sent to the Gnus Bug Exterminators.
338 The thing near the bottom of the buffer is how the environment
339 settings will be included in the mail. Please do not delete that.
340 They will tell the Bug People what your environment is, so that it
341 will be easier to locate the bugs.
343 If you have found a bug that makes Emacs go \"beep\", set
344 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
345 and include the backtrace in your bug report.
347 Please describe the bug in annoying, painstaking detail.
349 Thank you for your help in stamping out bugs.
352 (if (string= gnus-product-name "Semi-gnus")
354 ", a modified version of Semi-gnus")))
357 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
361 ;;; Gnus Posting Functions
364 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
365 "p" gnus-summary-post-news
366 "i" gnus-summary-news-other-window
367 "f" gnus-summary-followup
368 "F" gnus-summary-followup-with-original
369 "c" gnus-summary-cancel-article
370 "s" gnus-summary-supersede-article
371 "r" gnus-summary-reply
372 "y" gnus-summary-yank-message
373 "R" gnus-summary-reply-with-original
374 "w" gnus-summary-wide-reply
375 "W" gnus-summary-wide-reply-with-original
376 "v" gnus-summary-very-wide-reply
377 "V" gnus-summary-very-wide-reply-with-original
378 "n" gnus-summary-followup-to-mail
379 "N" gnus-summary-followup-to-mail-with-original
380 "m" gnus-summary-mail-other-window
381 "u" gnus-uu-post-news
382 "\M-c" gnus-summary-mail-crosspost-complaint
383 "Br" gnus-summary-reply-broken-reply-to
384 "BR" gnus-summary-reply-broken-reply-to-with-original
385 "om" gnus-summary-mail-forward
386 "op" gnus-summary-post-forward
387 "Om" gnus-summary-digest-mail-forward
388 "Op" gnus-summary-digest-post-forward
389 "P" gnus-summary-execute-command-with-posting-style)
391 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
392 "b" gnus-summary-resend-bounced-mail
393 ;; "c" gnus-summary-send-draft
394 "r" gnus-summary-resend-message
395 "e" gnus-summary-resend-message-edit)
397 ;;; Internal functions.
399 (defun gnus-inews-make-draft (articles)
401 (gnus-inews-make-draft-meta-information
402 ,gnus-newsgroup-name ',articles)))
404 (defvar gnus-article-reply nil)
405 (defmacro gnus-setup-message (config &rest forms)
406 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
407 (buffer (make-symbol "gnus-setup-message-buffer"))
408 (article (make-symbol "gnus-setup-message-article"))
409 (yanked (make-symbol "gnus-setup-yanked-articles"))
410 (group (make-symbol "gnus-setup-message-group")))
411 `(let ((,winconf (current-window-configuration))
412 (,buffer (buffer-name (current-buffer)))
413 (,article gnus-article-reply)
414 (,yanked gnus-article-yanked-articles)
415 (,group gnus-newsgroup-name)
416 (message-header-setup-hook
417 (copy-sequence message-header-setup-hook))
418 (message-mode-hook (copy-sequence message-mode-hook))
419 (message-startup-parameter-alist
420 '((reply-buffer . gnus-copy-article-buffer)
421 (original-buffer . gnus-original-article-buffer)
422 (user-agent . Gnus))))
423 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
424 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
425 ;; #### FIXME: for a reason that I did not manage to identify yet,
426 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
427 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
428 ;; After evaluation of @forms below, it gets the value we actually want
429 ;; to override, and the posting styles are used. For that reason, I've
430 ;; added an optional argument to `gnus-configure-posting-styles' to
431 ;; make sure that the correct value for the group name is used. -- drv
432 (add-hook 'message-mode-hook
433 (if (memq ,config '(reply-yank reply))
435 (gnus-configure-posting-styles ,group))
437 ;; There may be an old " *gnus article copy*" buffer.
438 (let (gnus-article-copy)
439 (gnus-configure-posting-styles ,group)))))
440 (gnus-pull ',(intern gnus-draft-meta-information-header)
441 message-required-headers)
443 (not (string= ,group "")))
445 (intern gnus-draft-meta-information-header)
446 (gnus-inews-make-draft ,yanked))
447 message-required-headers))
451 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
453 (setq gnus-message-buffer (current-buffer))
454 (set (make-local-variable 'gnus-message-group-art)
455 (cons ,group ,article))
456 (set (make-local-variable 'gnus-newsgroup-name) ,group)
457 (gnus-maybe-setup-default-charset)
458 (gnus-run-hooks 'gnus-message-setup-hook))
459 (message-hide-headers)
461 (gnus-configure-windows ,config t)
462 (run-hooks 'post-command-hook)
463 (set-buffer-modified-p nil))))
465 (defun gnus-inews-make-draft-meta-information (group articles)
466 (when (numberp articles)
467 (setq articles (list articles)))
468 (concat "(\"" group "\" "
481 (defun gnus-msg-mail (&optional to subject other-headers continue
482 switch-action yank-action send-actions)
483 "Start editing a mail message to be sent.
484 Like `message-mail', but with Gnus paraphernalia, particularly the
485 Gcc: header for archiving purposes."
487 (let ((buf (current-buffer))
489 (gnus-setup-message 'message
490 (message-mail to subject other-headers continue
491 nil yank-action send-actions))
493 (setq mail-buf (current-buffer))
494 (switch-to-buffer buf)
495 (apply switch-action mail-buf nil)))
496 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
499 (defvar save-selected-window-window)
502 (defun gnus-button-mailto (address)
504 (set-buffer (gnus-copy-article-buffer))
505 (gnus-setup-message 'message
506 (message-reply address))
507 (and (boundp 'save-selected-window-window)
508 (not (window-live-p save-selected-window-window))
509 (setq save-selected-window-window (selected-window))))
512 (defun gnus-button-reply (&optional to-address wide)
513 "Like `message-reply'."
515 (gnus-setup-message 'message
516 (message-reply to-address wide))
517 (and (boundp 'save-selected-window-window)
518 (not (window-live-p save-selected-window-window))
519 (setq save-selected-window-window (selected-window))))
522 (define-mail-user-agent 'gnus-user-agent
523 'gnus-msg-mail 'message-send-and-exit
524 'message-kill-buffer 'message-send-hook)
526 (defun gnus-setup-posting-charset (group)
527 (let ((alist gnus-group-posting-charset-alist)
528 (group (or group ""))
532 (while (setq elem (pop alist))
533 (when (or (and (stringp (car elem))
534 (string-match (car elem) group))
535 (and (functionp (car elem))
536 (funcall (car elem) group))
537 (and (symbolp (car elem))
538 (symbol-value (car elem))))
539 (throw 'found (cons (cadr elem) (caddr elem)))))))))
541 (defun gnus-inews-add-send-actions (winconf buffer article
542 &optional config yanked)
543 (gnus-make-local-hook 'message-sent-hook)
544 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
545 'gnus-inews-do-gcc) nil t)
547 (gnus-make-local-hook 'message-header-hook)
548 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
549 (setq message-post-method
551 (gnus-post-method arg ,gnus-newsgroup-name)))
552 (setq message-user-agent (gnus-message-make-user-agent))
553 (unless message-use-multi-frames
555 `(if (gnus-buffer-exists-p ,buffer)
556 (set-window-configuration ,winconf))
557 'exit 'postpone 'kill))
558 (let ((to-be-marked (cond
561 (lambda (x) (if (listp x) (car x) x)) yanked))
562 (article (if (listp article) article (list article)))
565 `(when (gnus-buffer-exists-p ,buffer)
569 (if (eq config 'forward)
570 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
571 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
574 (put 'gnus-setup-message 'lisp-indent-function 1)
575 (put 'gnus-setup-message 'edebug-form-spec '(form body))
577 ;;; Post news commands of Gnus group mode and summary mode
579 (defun gnus-group-mail (&optional arg)
580 "Start composing a mail.
581 If ARG, use the group under the point to find a posting style.
582 If ARG is 1, prompt for a group name to find the posting style."
584 ;; We can't `let' gnus-newsgroup-name here, since that leads
585 ;; to local variables leaking.
586 (let ((group gnus-newsgroup-name)
587 ;; make sure last viewed article doesn't affect posting styles:
589 (buffer (current-buffer)))
592 (setq gnus-newsgroup-name
594 (if (= 1 (prefix-numeric-value arg))
595 (completing-read "Use posting style of group: "
596 gnus-active-hashtb nil
597 (gnus-read-active-file-p))
598 (gnus-group-group-name))
600 ;; #### see comment in gnus-setup-message -- drv
601 (gnus-setup-message 'message (message-mail)))
604 (setq gnus-newsgroup-name group)))))
606 (defun gnus-group-news (&optional arg)
607 "Start composing a news.
608 If ARG, post to group under point.
609 If ARG is 1, prompt for group name to post to.
611 This function prepares a news even when using mail groups. This is useful
612 for posting messages to mail groups without actually sending them over the
613 network. The corresponding back end must have a 'request-post method."
615 ;; We can't `let' gnus-newsgroup-name here, since that leads
616 ;; to local variables leaking.
617 (let ((group gnus-newsgroup-name)
618 ;; make sure last viewed article doesn't affect posting styles:
620 (buffer (current-buffer)))
623 (setq gnus-newsgroup-name
625 (if (= 1 (prefix-numeric-value arg))
626 (completing-read "Use group: "
627 gnus-active-hashtb nil
628 (gnus-read-active-file-p))
629 (gnus-group-group-name))
631 ;; #### see comment in gnus-setup-message -- drv
632 (gnus-setup-message 'message
633 (message-news (gnus-group-real-name gnus-newsgroup-name))))
636 (setq gnus-newsgroup-name group)))))
638 (defun gnus-group-post-news (&optional arg)
639 "Start composing a message (a news by default).
640 If ARG, post to group under point. If ARG is 1, prompt for group name.
641 Depending on the selected group, the message might be either a mail or
644 ;; Bind this variable here to make message mode hooks work ok.
645 (let ((gnus-newsgroup-name
647 (if (= 1 (prefix-numeric-value arg))
648 (completing-read "Newsgroup: " gnus-active-hashtb nil
649 (gnus-read-active-file-p))
650 (gnus-group-group-name))
652 ;; make sure last viewed article doesn't affect posting styles:
654 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
655 (string= gnus-newsgroup-name ""))))
657 (defun gnus-summary-mail-other-window (&optional arg)
658 "Start composing a mail in another window.
659 Use the posting of the current group by default.
660 If ARG, don't do that. If ARG is 1, prompt for group name to find the
663 ;; We can't `let' gnus-newsgroup-name here, since that leads
664 ;; to local variables leaking.
665 (let ((group gnus-newsgroup-name)
666 ;; make sure last viewed article doesn't affect posting styles:
668 (buffer (current-buffer)))
671 (setq gnus-newsgroup-name
673 (if (= 1 (prefix-numeric-value arg))
674 (completing-read "Use group: "
675 gnus-active-hashtb nil
676 (gnus-read-active-file-p))
678 gnus-newsgroup-name))
679 ;; #### see comment in gnus-setup-message -- drv
680 (gnus-setup-message 'message (message-mail)))
683 (setq gnus-newsgroup-name group)))))
685 (defun gnus-summary-news-other-window (&optional arg)
686 "Start composing a news in another window.
687 Post to the current group by default.
688 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
690 This function prepares a news even when using mail groups. This is useful
691 for posting messages to mail groups without actually sending them over the
692 network. The corresponding back end must have a 'request-post method."
694 ;; We can't `let' gnus-newsgroup-name here, since that leads
695 ;; to local variables leaking.
696 (let ((group gnus-newsgroup-name)
697 ;; make sure last viewed article doesn't affect posting styles:
699 (buffer (current-buffer)))
702 (setq gnus-newsgroup-name
704 (if (= 1 (prefix-numeric-value arg))
705 (completing-read "Use group: "
706 gnus-active-hashtb nil
707 (gnus-read-active-file-p))
709 gnus-newsgroup-name))
710 ;; #### see comment in gnus-setup-message -- drv
711 (gnus-setup-message 'message
713 (message-news (gnus-group-real-name gnus-newsgroup-name))
714 (set (make-local-variable 'gnus-discouraged-post-methods)
716 (car (gnus-find-method-for-group gnus-newsgroup-name))
717 gnus-discouraged-post-methods)))))
720 (setq gnus-newsgroup-name group)))))
722 (defun gnus-summary-post-news (&optional arg)
723 "Start composing a message. Post to the current group by default.
724 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
725 Depending on the selected group, the message might be either a mail or
728 ;; Bind this variable here to make message mode hooks work ok.
729 (let ((gnus-newsgroup-name
731 (if (= 1 (prefix-numeric-value arg))
732 (completing-read "Newsgroup: " gnus-active-hashtb nil
733 (gnus-read-active-file-p))
735 gnus-newsgroup-name))
736 ;; make sure last viewed article doesn't affect posting styles:
738 (gnus-post-news 'post gnus-newsgroup-name)))
741 (defun gnus-summary-followup (yank &optional force-news)
742 "Compose a followup to an article.
743 If prefix argument YANK is non-nil, the original article is yanked
745 YANK is a list of elements, where the car of each element is the
746 article number, and the cdr is the string to be yanked."
748 (list (and current-prefix-arg
749 (gnus-summary-work-articles 1))))
751 (gnus-summary-goto-subject
752 (if (listp (car yank))
755 (save-window-excursion
756 (gnus-summary-select-article))
757 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
758 (gnus-newsgroup-name gnus-newsgroup-name))
760 (gnus-post-news nil gnus-newsgroup-name
761 headers gnus-article-buffer
763 (gnus-summary-handle-replysign)))
765 (defun gnus-summary-followup-with-original (n &optional force-news)
766 "Compose a followup to an article and include the original article.
767 The text in the region will be yanked. If the region isn't
768 active, the entire article will be yanked."
770 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
772 (defun gnus-summary-followup-to-mail (&optional arg)
773 "Followup to the current mail message via news."
775 (list (and current-prefix-arg
776 (gnus-summary-work-articles 1))))
777 (gnus-summary-followup arg t))
779 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
780 "Followup to the current mail message via news."
782 (gnus-summary-followup (gnus-summary-work-articles arg) t))
784 (defun gnus-inews-yank-articles (articles)
785 (let (beg article yank-string
786 (more-than-one (cdr articles))
787 (cur (current-buffer))
790 (while (setq article (pop articles))
791 (when (listp article)
792 (setq yank-string (nth 1 article)
793 article (nth 0 article)))
794 (save-window-excursion
795 (set-buffer gnus-summary-buffer)
796 (gnus-summary-select-article nil nil nil article)
797 (gnus-summary-remove-process-mark article))
799 ;; Gathering references.
801 (setq refs (message-list-references
803 (mail-header-references gnus-current-headers)
804 (mail-header-message-id gnus-current-headers)))
805 (when message-use-multi-frames
806 (when (setq window (get-buffer-window cur t))
807 (select-frame (window-frame window)))))
809 (gnus-copy-article-buffer nil yank-string)
810 (let ((message-reply-buffer gnus-article-copy)
811 (message-reply-headers
812 ;; The headers are decoded.
813 (with-current-buffer gnus-article-copy
815 (nnheader-narrow-to-headers)
816 (nnheader-parse-naked-head)))))
817 (message-yank-original)
818 (setq beg (or beg (mark t))))
823 ;; Replace with the gathered references.
827 (message-narrow-to-headers)
828 (let ((case-fold-search t))
829 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
831 (goto-char (point-max))))
833 (list (or (assq 'References message-header-format-alist)
834 '(References . message-shorten-references)))
835 (list (cons 'References
836 (mapconcat 'identity (nreverse refs) " "))))
837 (backward-delete-char 1))
843 (defun gnus-summary-cancel-article (&optional n symp)
844 "Cancel an article you posted.
845 Uses the process-prefix convention. If given the symbolic
846 prefix `a', cancel using the standard posting method; if not
847 post using the current select method."
848 (interactive (gnus-interactive "P\ny"))
849 (let ((articles (gnus-summary-work-articles n))
852 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
854 (while (setq article (pop articles))
855 (when (gnus-summary-select-article t nil nil article)
856 (when (gnus-eval-in-buffer-window gnus-article-buffer
858 (set-buffer gnus-original-article-buffer)
859 (message-cancel-news)))
860 (gnus-summary-mark-as-read article gnus-canceled-mark)
861 (gnus-cache-remove-article 1))
862 (gnus-article-hide-headers-if-wanted))
863 (gnus-summary-remove-process-mark article))))
865 (defun gnus-summary-supersede-article ()
866 "Compose an article that will supersede a previous article.
867 This is done simply by taking the old article and adding a Supersedes
868 header line with the old Message-ID."
870 (let ((article (gnus-summary-article-number)))
871 (gnus-setup-message 'reply-yank
872 (gnus-summary-select-article t)
873 (set-buffer gnus-original-article-buffer)
877 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
879 (set-buffer ,gnus-summary-buffer)
880 (gnus-cache-possibly-remove-article ,article nil nil nil t)
881 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
882 message-send-actions))))
886 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
887 ;; make a copy of the article buffer with all text properties removed
888 ;; this copy is in the buffer gnus-article-copy.
889 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
890 ;; this buffer should be passed to all mail/news reply/post routines.
891 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
893 (set-buffer gnus-article-copy)
894 (set-buffer-multibyte t))
895 (let ((article-buffer (or article-buffer gnus-article-buffer))
897 (if (not (and (get-buffer article-buffer)
898 (gnus-buffer-exists-p article-buffer)))
899 (error "Can't find any article buffer")
901 (set-buffer article-buffer)
902 (let ((gnus-newsgroup-charset (or gnus-article-charset
903 gnus-newsgroup-charset))
904 (gnus-newsgroup-ignored-charsets
905 (or gnus-article-ignored-charsets
906 gnus-newsgroup-ignored-charsets)))
908 ;; Copy over the (displayed) article buffer, delete
909 ;; hidden text and remove text properties.
911 (copy-to-buffer gnus-article-copy (point-min) (point-max))
912 (set-buffer gnus-article-copy)
913 ;; There's invisible and intangible text in T-gnus. Especially,
914 ;; if there is a boundary line (X-Boundary: ------------------),
915 ;; in the end of a header, it will cause a serious problem.
916 (add-text-properties (point-min) (point-max)
917 '(invisible nil intangible nil))
920 (delete-region (point) (point-max))
921 (insert yank-string))
922 ;; Encode bitmap smileys to ordinary text.
923 ;; Possibly, the original text might be restored.
924 (static-unless (featurep 'xemacs)
925 (when (featurep 'smiley-mule)
926 (smiley-encode-buffer)))
927 (gnus-article-delete-text-of-type 'annotation)
928 (gnus-remove-text-with-property 'gnus-prev)
929 (gnus-remove-text-with-property 'gnus-next)
930 (gnus-remove-text-with-property 'gnus-decoration)
931 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
934 (static-if (featurep 'xemacs)
935 ;; Revome smiley extents for (possibly) XEmacs 21.1.
937 (buffer-substring-no-properties (point-min)
939 (buffer-substring-no-properties (point-min) (point-max)))
941 ;; Find the original headers.
942 (set-buffer gnus-original-article-buffer)
943 (goto-char (point-min))
944 (while (looking-at message-unix-mail-delimiter)
946 (let ((mail-header-separator ""))
948 end (or (message-goto-body)
949 ;; There may be just a header.
951 ;; Delete the headers from the displayed articles.
952 (set-buffer gnus-article-copy)
953 (let ((mail-header-separator ""))
954 (delete-region (goto-char (point-min))
955 (or (message-goto-body) (point-max))))
956 ;; Insert the original article headers.
957 (insert-buffer-substring gnus-original-article-buffer beg end)
959 (let ((gnus-article-decode-hook
960 (delq 'article-decode-charset
961 (copy-sequence gnus-article-decode-hook))))
962 ;; Needed for T-gnus.
963 (add-hook 'gnus-article-decode-hook
964 'article-decode-encoded-words)
965 (run-hooks 'gnus-article-decode-hook)))))
968 (defun gnus-post-news (post &optional group header article-buffer yank subject
971 (gnus-copy-article-buffer))
972 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
973 (gnus-article-yanked-articles yank)
974 (add-to-list gnus-add-to-list))
975 (gnus-setup-message (cond (yank 'reply-yank)
976 (article-buffer 'reply)
978 (let* ((group (or group gnus-newsgroup-name))
979 (charset (gnus-group-name-charset nil group))
981 to-address to-group mailing-list to-list
984 (setq to-address (gnus-parameter-to-address group)
985 to-group (gnus-group-find-parameter group 'to-group)
986 to-list (gnus-parameter-to-list group)
987 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
988 mailing-list (when gnus-mailing-list-groups
989 (string-match gnus-mailing-list-groups group))
990 group (gnus-group-name-decode (gnus-group-real-name group)
992 (if (or (and to-group
993 (gnus-news-group-p to-group))
996 (and (gnus-news-group-p
997 (or pgroup gnus-newsgroup-name)
998 (or header gnus-current-article))
1006 (and (not (gnus-virtual-group-p pgroup)) group)))
1007 (set-buffer gnus-article-copy)
1008 (gnus-msg-treat-broken-reply-to)
1009 (message-followup (if (or newsgroup-p force-news)
1010 (if (save-restriction
1011 (article-narrow-to-head)
1012 (message-fetch-field "newsgroups"))
1019 (message-mail (or to-address to-list))
1020 ;; Arrange for mail groups that have no `to-address' to
1021 ;; get that when the user sends off the mail.
1022 (when (and (not to-list)
1025 (push (list 'gnus-inews-add-to-address pgroup)
1026 message-send-actions)))
1027 (set-buffer gnus-article-copy)
1028 (gnus-msg-treat-broken-reply-to)
1029 (message-wide-reply to-address)))
1031 (gnus-inews-yank-articles yank))))))
1033 (defun gnus-msg-treat-broken-reply-to (&optional force)
1034 "Remove the Reply-to header if broken-reply-to."
1036 (gnus-group-find-parameter
1037 gnus-newsgroup-name 'broken-reply-to))
1039 (message-narrow-to-head)
1040 (message-remove-header "reply-to"))))
1042 (defun gnus-post-method (arg group &optional silent)
1043 "Return the posting method based on GROUP and ARG.
1044 If SILENT, don't prompt the user."
1045 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1047 (group-method (gnus-find-method-for-group group)))
1049 ;; If the group-method is nil (which shouldn't happen) we use
1050 ;; the default method.
1051 ((null group-method)
1052 (or (and (listp gnus-post-method) ;If not current/native/nil
1053 (not (listp (car gnus-post-method))) ; and not a list of methods
1054 gnus-post-method) ;then use it.
1056 message-post-method))
1057 ;; We want the inverse of the default
1058 ((and arg (not (eq arg 0)))
1059 (if (eq gnus-post-method 'current)
1062 ;; We query the user for a post method.
1064 (and (listp gnus-post-method)
1065 (listp (car gnus-post-method))))
1067 ;; Collect all methods we know about.
1069 (when (listp gnus-post-method)
1070 (if (listp (car gnus-post-method))
1072 (list gnus-post-method)))
1073 gnus-secondary-select-methods
1074 (mapcar 'cdr gnus-server-alist)
1075 (mapcar 'car gnus-opened-servers)
1076 (list gnus-select-method)
1077 (list group-method)))
1078 method-alist post-methods method)
1079 ;; Weed out all mail methods.
1081 (setq method (gnus-server-get-method "" (pop methods)))
1082 (when (and (or (gnus-method-option-p method 'post)
1083 (gnus-method-option-p method 'post-mail))
1084 (not (member method post-methods)))
1085 (push method post-methods)))
1086 ;; Create a name-method alist.
1090 (if (equal (cadr m) "")
1091 (list (symbol-name (car m)) m)
1092 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1097 (setq gnus-last-posting-server
1099 gnus-last-posting-server)
1100 ;; Just use the last value.
1101 gnus-last-posting-server
1103 "Posting method: " method-alist nil t
1104 (cons (or gnus-last-posting-server "") 0))))
1106 ;; Override normal method.
1107 ((and (eq gnus-post-method 'current)
1108 (not (memq (car group-method) gnus-discouraged-post-methods))
1109 (gnus-get-function group-method 'request-post t))
1112 ;; Use gnus-post-method.
1113 ((listp gnus-post-method) ;A method...
1114 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1116 ;; Use the normal select method (nil or native).
1117 (t gnus-select-method))))
1120 ;; Dummies to avoid byte-compile warning.
1122 (defvar xemacs-codename))
1124 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1126 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1127 variable `mime-edit-user-agent-value' is bound, the value will be
1128 included in the return value, and `gnus-user-agent' is ignored. If
1129 MAX-COLUMN is specified, the return value will be folded up as it were
1130 filled. NEWLINE-PRODUCT specifies whether a newline should be
1131 inserted in front of each product-token. If the value is t or `hard',
1132 it works strictly. Otherwise, if it is non-nil (e.g. `soft'), it
1133 works semi-strictly.
1135 Here is an odd example, which inserts a User-Agent: header when you
1136 begin to compose a message:
1138 \(add-hook 'gnus-message-setup-hook
1140 (setq message-user-agent nil)
1143 (message-narrow-to-headers)
1144 (goto-char (point-max))
1145 (insert \"User-Agent: \"
1146 (gnus-message-make-user-agent t 76 'soft)
1149 (let ((gnus-v (gnus-extended-version))
1151 (cond ((and include-mime-info
1152 (boundp 'mime-edit-user-agent-value))
1153 (setq user-agent (concat gnus-v " " mime-edit-user-agent-value)))
1154 ((eq gnus-user-agent 'gnus-mime-edit)
1156 (if (boundp 'mime-edit-user-agent-value)
1157 (concat gnus-v " " mime-edit-user-agent-value)
1160 (setq user-agent (if (stringp gnus-user-agent)
1163 (let ((emacs-v (gnus-emacs-version)))
1165 (concat " " emacs-v))))))))
1167 (unless (natnump max-column)
1168 (setq max-column 76))
1170 (set-buffer-multibyte t)
1171 (insert (mapconcat 'identity (split-string user-agent) " "))
1172 (goto-char (point-min))
1174 start agent agents width element swidth)
1175 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1176 (setq start (match-beginning 0))
1177 (if (eq (char-after start) ?\()
1181 (push (buffer-substring start (point)) agent))
1183 (push (nreverse agent) agents))
1184 (setq agent (list (match-string 1)))))
1186 (push (nreverse agent) agents))
1187 (setq agents (nreverse agents))
1188 (if (> (+ 12 (string-width (caar agents))) max-column)
1189 (setq user-agent "\n"
1194 (setq agent (car agents)
1195 agents (cdr agents))
1196 (when (and (not bol)
1197 (or (memq newline-product '(t hard))
1198 (and newline-product
1200 (string-width (mapconcat 'identity
1203 (setq user-agent (concat user-agent "\n")
1207 (setq element (car agent)
1208 swidth (string-width element)
1211 (setq user-agent (if (member user-agent '("" "\n"))
1212 (concat user-agent element)
1213 (concat user-agent " " element))
1214 width (+ width 1 swidth)
1216 (if (> (+ width 1 swidth) max-column)
1217 (setq user-agent (concat user-agent "\n " element)
1219 (setq user-agent (concat user-agent " " element)
1220 width (+ width 1 swidth)))))))))
1225 ;;; Gnus Mail Functions
1228 ;;; Mail reply commands of Gnus summary mode
1230 (defun gnus-summary-reply (&optional yank wide very-wide)
1231 "Start composing a mail reply to the current message.
1232 If prefix argument YANK is non-nil, the original article is yanked
1234 If WIDE, make a wide reply.
1235 If VERY-WIDE, make a very wide reply."
1237 (list (and current-prefix-arg
1238 (gnus-summary-work-articles 1))))
1239 ;; Allow user to require confirmation before replying by mail to the
1240 ;; author of a news article (or mail message).
1242 (not (or (gnus-news-group-p gnus-newsgroup-name)
1243 gnus-confirm-treat-mail-like-news))
1244 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1245 (string-match gnus-confirm-mail-reply-to-news
1246 gnus-newsgroup-name))
1247 ((functionp gnus-confirm-mail-reply-to-news)
1248 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1249 (t gnus-confirm-mail-reply-to-news)))
1250 (y-or-n-p "Really reply by mail to article author? "))
1252 (if (listp (car yank))
1255 (gnus-article-reply (or article (gnus-summary-article-number)))
1256 (gnus-article-yanked-articles yank)
1258 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1260 (gnus-summary-goto-subject article))
1261 (gnus-setup-message (if yank 'reply-yank 'reply)
1263 (gnus-summary-select-article)
1264 (dolist (article very-wide)
1265 (gnus-summary-select-article nil nil nil article)
1267 (set-buffer (gnus-copy-article-buffer))
1268 (gnus-msg-treat-broken-reply-to)
1270 (message-narrow-to-head)
1271 (setq headers (concat headers (buffer-string)))))))
1272 (set-buffer (gnus-copy-article-buffer))
1273 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1275 (message-narrow-to-head)
1279 (goto-char (point-max)))
1280 (message-reply nil wide)
1282 (gnus-inews-yank-articles yank))
1283 (gnus-summary-handle-replysign)))))
1285 (defun gnus-summary-handle-replysign ()
1286 "Check the various replysign variables and take action accordingly."
1287 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1288 (let (signed encrypted)
1290 (set-buffer gnus-article-buffer)
1291 (setq signed (memq 'signed gnus-article-wash-types))
1292 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1293 (cond ((and gnus-message-replyencrypt encrypted)
1294 (mml-secure-message mml-default-encrypt-method
1295 (if gnus-message-replysignencrypted
1298 ((and gnus-message-replysign signed)
1299 (mml-secure-message mml-default-sign-method 'sign))))))
1301 (defun gnus-summary-reply-with-original (n &optional wide)
1302 "Start composing a reply mail to the current message.
1303 The original article will be yanked."
1305 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1307 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1308 "Like `gnus-summary-reply' except removing reply-to field.
1309 If prefix argument YANK is non-nil, the original article is yanked
1311 If WIDE, make a wide reply.
1312 If VERY-WIDE, make a very wide reply."
1314 (list (and current-prefix-arg
1315 (gnus-summary-work-articles 1))))
1316 (let ((gnus-msg-force-broken-reply-to t))
1317 (gnus-summary-reply yank wide very-wide)))
1319 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1320 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1321 The original article will be yanked."
1323 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1325 (defun gnus-summary-wide-reply (&optional yank)
1326 "Start composing a wide reply mail to the current message.
1327 If prefix argument YANK is non-nil, the original article is yanked
1330 (list (and current-prefix-arg
1331 (gnus-summary-work-articles 1))))
1332 (gnus-summary-reply yank t))
1334 (defun gnus-summary-wide-reply-with-original (n)
1335 "Start composing a wide reply mail to the current message.
1336 The original article will be yanked.
1337 Uses the process/prefix convention."
1339 (gnus-summary-reply-with-original n t))
1341 (defun gnus-summary-very-wide-reply (&optional yank)
1342 "Start composing a very wide reply mail to the current message.
1343 If prefix argument YANK is non-nil, the original article is yanked
1346 (list (and current-prefix-arg
1347 (gnus-summary-work-articles 1))))
1348 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1350 (defun gnus-summary-very-wide-reply-with-original (n)
1351 "Start composing a very wide reply mail to the current message.
1352 The original article will be yanked."
1355 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1357 (defun gnus-summary-mail-forward (&optional full-headers post)
1358 "Forward the current message(s) to another user.
1359 If process marks exist, forward all marked messages;
1360 If FULL-HEADERS (the prefix), include full headers when forwarding.
1362 Note that this function definition for T-gnus is totally different
1363 from the original Gnus."
1365 (if (cdr (gnus-summary-work-articles nil))
1366 ;; Process marks are given.
1367 (gnus-summary-digest-mail-forward nil post)
1368 ;; No process marks.
1369 (let* ((gnus-article-reply (gnus-summary-article-number))
1370 (gnus-article-yanked-articles (list gnus-article-reply))
1372 (message-included-forward-headers
1373 (if full-headers "" message-included-forward-headers)))
1374 (gnus-setup-message 'forward
1375 (gnus-summary-select-article)
1376 (setq charset default-mime-charset)
1377 (set-buffer gnus-original-article-buffer)
1378 (make-local-variable 'default-mime-charset)
1379 (setq default-mime-charset charset)
1380 (message-forward post)))))
1382 (defun gnus-summary-digest-mail-forward (&optional n post)
1383 "Digests and forwards all articles in this series.
1384 If N is a positive number, forward the N next articles.
1385 If N is a negative number, forward the N previous articles.
1386 If N is nil and any articles have been marked with the process mark,
1387 forward those articles instead.
1388 Optional POST will use news to forward instead of mail."
1390 (let* ((articles (gnus-summary-work-articles n))
1391 (gnus-article-yanked-articles (copy-sequence articles))
1392 (topics "Topics:\n")
1393 subject article frame)
1394 (when (car articles)
1395 (gnus-setup-message 'forward
1396 (gnus-summary-select-article)
1398 (setq articles (sort articles '<)
1399 subject "Digested Articles")
1400 (with-current-buffer gnus-original-article-buffer
1401 (setq subject (message-make-forward-subject))))
1403 (message-news nil subject)
1404 (message-mail nil subject))
1405 (when (and message-use-multi-frames (cdr articles))
1406 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1408 (while (setq article (pop articles))
1409 (save-window-excursion
1410 (set-buffer gnus-summary-buffer)
1411 (gnus-summary-select-article nil nil nil article)
1412 (setq topics (concat topics " "
1413 (mail-header-subject gnus-current-headers)
1415 (gnus-summary-remove-process-mark article))
1417 (select-frame frame))
1418 (insert (mime-make-tag "message" "rfc822") "\n")
1419 (narrow-to-region (point) (point))
1420 (insert-buffer-substring gnus-original-article-buffer)
1422 (article-narrow-to-head)
1423 (message-remove-header message-included-forward-headers t nil t))
1424 (goto-char (point-max))
1430 (mime-edit-enclose-digest-region (point)(mark t))))))
1432 (defun gnus-summary-digest-post-forward (&optional n)
1433 "Digest and forwards all articles in this series to a newsgroup.
1434 If N is a positive number, forward the N next articles.
1435 If N is a negative number, forward the N previous articles.
1436 If N is nil and any articles have been marked with the process mark,
1437 forward those articles instead."
1439 (gnus-summary-digest-mail-forward n t))
1441 (defun gnus-summary-resend-message (address n)
1442 "Resend the current article to ADDRESS."
1444 (list (message-read-from-minibuffer
1445 "Resend message(s) to: "
1446 (when (and gnus-summary-resend-default-address
1447 (gnus-buffer-live-p gnus-original-article-buffer))
1448 ;; If some other article is currently selected, the
1449 ;; initial-contents is wrong. Whatever, it is just the
1450 ;; initial-contents.
1451 (with-current-buffer gnus-original-article-buffer
1452 (nnmail-fetch-field "to"))))
1453 current-prefix-arg))
1454 (let ((articles (gnus-summary-work-articles n))
1456 (while (setq article (pop articles))
1457 (gnus-summary-select-article nil nil nil article)
1459 (set-buffer gnus-original-article-buffer)
1460 (message-resend address))
1461 (gnus-summary-mark-article-as-forwarded article))))
1463 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1464 (defun gnus-summary-resend-message-edit ()
1465 "Resend an article that has already been sent.
1466 A new buffer will be created to allow the user to modify body and
1467 contents of the message, and then, everything will happen as when
1468 composing a new message."
1470 (let ((article (gnus-summary-article-number)))
1471 (gnus-setup-message 'reply-yank
1472 (gnus-summary-select-article t)
1473 (set-buffer gnus-original-article-buffer)
1474 (let ((cur (current-buffer))
1475 (to (message-fetch-field "to")))
1476 ;; Get a normal message buffer.
1477 (message-pop-to-buffer (message-buffer-name "Resend" to))
1478 (insert-buffer-substring cur)
1480 ;; T-gnus change: Use MIME-Edit to recompose a message.
1482 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1483 (fset 'mime-edit-decode-single-part-in-buffer
1484 (lambda (&rest args)
1485 (if (let ((content-type (car args)))
1486 (and (eq 'message (mime-content-type-primary-type
1488 (eq 'rfc822 (mime-content-type-subtype
1490 (setcar (cdr args) 'not-decode-text))
1493 (mime-edit-again nil t)
1494 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1495 (message-narrow-to-head-1)
1496 (insert "From: " (message-make-from) "\n")
1497 (while (re-search-forward "^From:" nil t)
1499 (insert "Original-"))
1500 (message-remove-header "^>From[\t ]" t)
1502 ;; Gnus will generate a new one when sending.
1503 (message-remove-header "Message-ID")
1504 (message-remove-header message-ignored-resent-headers t)
1505 ;; Remove unwanted headers.
1506 (goto-char (point-max))
1507 (insert mail-header-separator)
1508 (goto-char (point-min))
1509 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1513 (defun gnus-summary-post-forward (&optional full-headers)
1514 "Forward the current article to a newsgroup.
1515 If FULL-HEADERS (the prefix), include full headers when forwarding."
1517 (gnus-summary-mail-forward full-headers t))
1519 (defvar gnus-nastygram-message
1520 "The following article was inappropriately posted to %s.\n\n"
1521 "Format string to insert in nastygrams.
1522 The current group name will be inserted at \"%s\".")
1524 (defun gnus-summary-mail-nastygram (n)
1525 "Send a nastygram to the author of the current article."
1527 (when (or gnus-expert-user
1529 "Really send a nastygram to the author of the current article? "))
1530 (let ((group gnus-newsgroup-name))
1531 (gnus-summary-reply-with-original n)
1532 (set-buffer gnus-message-buffer)
1534 (insert (format gnus-nastygram-message group))
1535 (message-send-and-exit))))
1537 (defun gnus-summary-mail-crosspost-complaint (n)
1538 "Send a complaint about crossposting to the current article(s)."
1540 (let ((articles (gnus-summary-work-articles n))
1542 (while (setq article (pop articles))
1543 (set-buffer gnus-summary-buffer)
1544 (gnus-summary-goto-subject article)
1545 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1546 newsgroups followup-to)
1547 (gnus-summary-select-article)
1548 (set-buffer gnus-original-article-buffer)
1549 (if (and (<= (length (message-tokenize-header
1551 (mail-fetch-field "newsgroups"))
1554 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1555 (not (member group (message-tokenize-header
1556 followup-to ", ")))))
1558 (gnus-message 1 "Followup-to restricted")
1559 (gnus-message 1 "Not a crossposted article"))
1560 (set-buffer gnus-summary-buffer)
1561 (gnus-summary-reply-with-original 1)
1562 (set-buffer gnus-message-buffer)
1564 (insert (format gnus-crosspost-complaint newsgroups group))
1565 (message-goto-subject)
1566 (re-search-forward " *$")
1567 (replace-match " (crosspost notification)" t t)
1568 (gnus-deactivate-mark)
1569 (when (gnus-y-or-n-p "Send this complaint? ")
1570 (message-send-and-exit)))))))
1572 (defun gnus-mail-parse-comma-list ()
1575 (skip-chars-forward " ")
1578 (skip-chars-forward "^,")
1583 (narrow-to-region beg (point))
1586 (while (search-forward "\"" nil t)
1590 (skip-chars-forward ",")
1591 (skip-chars-forward "^,"))
1592 (skip-chars-backward " ")
1593 (push (buffer-substring beg (point))
1595 (skip-chars-forward "^,")
1596 (skip-chars-forward ", "))
1599 (defun gnus-inews-add-to-address (group)
1600 (let ((to-address (mail-fetch-field "to")))
1601 (when (and to-address
1603 ;; This mail group doesn't have a `to-list', so we add one
1605 (when (gnus-y-or-n-p
1606 (format "Do you want to add this as `to-list': %s? " to-address))
1607 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1609 (defun gnus-put-message ()
1610 "Put the current message in some group and return to Gnus."
1612 (let ((reply gnus-article-reply)
1613 (winconf gnus-prev-winconf)
1614 (group gnus-newsgroup-name))
1616 (not (gnus-group-read-only-p group)))
1617 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1619 (when (gnus-group-entry group)
1620 (error "No such group: %s" group))
1624 (message-narrow-to-headers)
1625 (let ((gnus-deletable-headers nil))
1626 (message-generate-headers
1627 (if (message-news-p)
1628 message-required-news-headers
1629 message-required-mail-headers)))
1630 (goto-char (point-max))
1631 (if (string-match " " group)
1632 (insert "Gcc: \"" group "\"\n")
1633 (insert "Gcc: " group "\n"))
1636 (when (and (get-buffer gnus-group-buffer)
1637 (gnus-buffer-exists-p (car-safe reply))
1639 (set-buffer (car reply))
1640 (gnus-summary-mark-article-as-replied (cdr reply)))
1642 (set-window-configuration winconf))))
1644 (defun gnus-article-mail (yank)
1645 "Send a reply to the address near point.
1646 If YANK is non-nil, include the original article."
1650 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1651 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1653 (gnus-msg-mail address)
1655 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1657 (defvar nntp-server-type)
1659 "Send a bug report to the Gnus maintainers."
1661 (unless (gnus-alive-p)
1662 (error "Gnus has been shut down"))
1663 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1664 (unless (message-mail-user-agent)
1665 (message-pop-to-buffer "*Gnus Bug*")
1666 (delete-other-windows)
1667 (when gnus-bug-create-help-buffer
1668 (switch-to-buffer "*Gnus Help Bug*")
1670 (insert gnus-bug-message)
1671 (goto-char (point-min))
1673 (set-buffer "*Gnus Bug*")))
1674 (let ((message-this-is-mail t))
1675 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1676 (when gnus-bug-create-help-buffer
1677 (push `(gnus-bug-kill-buffer) message-send-actions))
1678 (goto-char (point-min))
1679 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1681 (insert gnus-product-name " " gnus-version-number
1682 " (r" gnus-revision-number ") "
1683 "based on " gnus-original-product-name " v"
1684 gnus-original-version-number "\n"
1685 (emacs-version) "\n")
1686 (when (and (boundp 'nntp-server-type)
1687 (stringp nntp-server-type))
1688 (insert nntp-server-type))
1689 (insert "\n\n\n\n\n")
1690 (let (mime-content-types)
1691 (mime-edit-insert-tag
1692 "application" "emacs-lisp"
1693 "\nContent-Disposition: inline\nContent-Description: User settings"))
1694 (insert (with-temp-buffer
1697 (let (mime-content-types)
1698 (mime-edit-insert-tag "text" "plain"))
1699 (goto-char (point-min))
1700 (search-forward "Subject: " nil t)
1703 (defun gnus-bug-kill-buffer ()
1704 (when (get-buffer "*Gnus Help Bug*")
1705 (kill-buffer "*Gnus Help Bug*")))
1707 (defun gnus-summary-yank-message (buffer n)
1708 "Yank the current article into a composed message."
1710 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1711 current-prefix-arg))
1712 (when (gnus-buffer-live-p buffer)
1713 (let ((summary-frame (selected-frame))
1714 (message-frame (when (static-if (featurep 'xemacs)
1715 (device-on-window-system-p)
1717 (let ((window (get-buffer-window buffer t)))
1719 (window-frame window)))))
1720 (separator (concat "^" (regexp-quote mail-header-separator)
1722 (gnus-summary-iterate n
1723 (gnus-summary-select-article)
1724 (gnus-copy-article-buffer)
1725 (when (frame-live-p message-frame)
1726 (raise-frame message-frame)
1727 (select-frame message-frame))
1728 (with-current-buffer buffer
1729 (when (save-excursion
1731 (let (case-fold-search)
1732 (and (not (re-search-backward separator nil t))
1733 (re-search-forward separator nil t))))
1734 (goto-char (match-end 0)))
1735 (message-yank-buffer gnus-article-copy))
1736 (select-frame summary-frame))
1737 (when (frame-live-p message-frame)
1738 (select-frame message-frame)))))
1740 (defun gnus-debug ()
1741 "Attempts to go through the Gnus source file and report what variables have been changed.
1742 The source file has to be in the Emacs load path."
1744 (let ((files gnus-debug-files)
1746 file expr olist sym)
1747 (gnus-message 4 "Please wait while we snoop your variables...")
1748 ;; Go through all the files looking for non-default values for variables.
1751 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1754 (when (and (setq file (locate-library (pop files)))
1755 (file-exists-p file))
1756 (insert-file-contents file)
1757 (goto-char (point-min))
1758 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1759 (gnus-message 4 "Malformed sources in file %s" file)
1760 (narrow-to-region (point-min) (point))
1761 (goto-char (point-min))
1762 (while (setq expr (ignore-errors (read (current-buffer))))
1764 (and (memq (car expr) '(defvar defcustom defvoo))
1765 (stringp (nth 3 expr))
1766 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1767 (or (not (boundp (nth 1 expr)))
1768 (not (equal (eval (nth 2 expr))
1769 (symbol-value (nth 1 expr)))))
1770 (push (nth 1 expr) olist)))))))
1771 (kill-buffer (current-buffer)))
1772 (when (setq olist (nreverse olist))
1773 (insert ";----------------- Environment follows ------------------\n\n"))
1775 (if (boundp (car olist))
1779 ,(if (or (consp (setq sym (symbol-value (car olist))))
1781 (not (or (eq sym nil)
1783 (list 'quote (symbol-value (car olist)))
1784 (symbol-value (car olist))))))
1785 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1786 (setq olist (cdr olist)))
1787 ;; Remove any control chars - they seem to cause trouble for some
1788 ;; mailers. (Byte-compiled output from the stuff above.)
1790 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1791 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1793 ;; Break MIME tags purposely.
1795 (while (re-search-forward mime-edit-tag-regexp nil t)
1796 (goto-char (1+ (match-beginning 0)))
1799 ;;; Treatment of rejected articles.
1802 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1803 "Re-mail the current message.
1804 This only makes sense if the current message is a bounce message that
1805 contains some mail you have written which has been bounced back to
1807 If FETCH, try to fetch the article that this is a reply to, if indeed
1810 (gnus-summary-select-article t)
1811 (set-buffer gnus-original-article-buffer)
1812 (gnus-setup-message 'compose-bounce
1813 (let* ((references (mail-fetch-field "references"))
1814 (parent (and references (gnus-parent-id references))))
1816 ;; If there are references, we fetch the article we answered to.
1818 (gnus-summary-refer-article parent)
1819 (gnus-summary-show-all-headers)))))
1823 (defun gnus-inews-group-method (group)
1825 ;; If the group doesn't exist, we assume
1826 ;; it's an archive group...
1827 ((and (null (gnus-get-info group))
1828 (eq (car (gnus-server-to-method gnus-message-archive-method))
1829 (car (gnus-server-to-method (gnus-group-method group)))))
1830 gnus-message-archive-method)
1832 ((gnus-info-method (gnus-get-info group))
1833 (gnus-info-method (gnus-get-info group)))
1835 (t (gnus-server-to-method (gnus-group-method group)))))
1837 ;; Do Gcc handling, which copied the message over to some group.
1838 (defun gnus-inews-do-gcc (&optional gcc)
1842 (message-narrow-to-headers)
1843 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1844 (coding-system-for-write 'raw-text)
1845 groups group method group-art
1846 mml-externalize-attachments)
1848 (message-remove-header "gcc")
1850 (setq groups (message-unquote-tokens
1851 (message-tokenize-header gcc " ,")))
1852 ;; Copy the article over to some group(s).
1853 (while (setq group (pop groups))
1854 (unless (gnus-check-server
1855 (setq method (gnus-inews-group-method group)))
1856 (error "Can't open server %s" (if (stringp method) method
1858 (unless (gnus-request-group group nil method)
1859 (gnus-request-create-group group method))
1860 (setq mml-externalize-attachments
1861 (if (stringp gnus-gcc-externalize-attachments)
1862 (string-match gnus-gcc-externalize-attachments group)
1863 gnus-gcc-externalize-attachments))
1865 (nnheader-set-temp-buffer " *acc*")
1866 (insert-buffer-substring message-encoding-buffer)
1867 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1868 (goto-char (point-min))
1869 (when (re-search-forward
1870 (concat "^" (regexp-quote mail-header-separator) "$")
1872 (replace-match "" t t ))
1873 (when (or (not (gnus-check-backend-function
1874 'request-accept-article group))
1875 (not (setq group-art
1876 (gnus-request-accept-article
1877 group method t t))))
1878 (gnus-message 1 "Couldn't store article in group %s: %s"
1879 group (gnus-status-message method)))
1880 (when (and group-art
1881 ;; FIXME: Should gcc-mark-as-read work when
1882 ;; Gnus is not running?
1884 (or gnus-gcc-mark-as-read
1886 (boundp 'gnus-inews-mark-gcc-as-read)
1887 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1888 (gnus-group-mark-article-read group (cdr group-art)))
1889 (kill-buffer (current-buffer)))))))))
1891 (defun gnus-inews-insert-gcc ()
1892 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1895 (message-narrow-to-headers)
1896 (let* ((group gnus-outgoing-message-group)
1900 ((or (stringp group) (list group))
1905 (if (string-match " " gcc)
1906 (concat "\"" gcc "\"")
1908 (mapconcat (lambda (group)
1909 (if (string-match " " group)
1910 (concat "\"" group "\"")
1915 (defun gnus-inews-insert-archive-gcc (&optional group)
1916 "Insert the Gcc to say where the article is to be archived."
1917 (let* ((var gnus-message-archive-group)
1918 (group (or group gnus-newsgroup-name ""))
1920 (and gnus-newsgroup-name
1921 (not (equal gnus-newsgroup-name ""))
1922 (gnus-group-find-parameter
1923 gnus-newsgroup-name 'gcc-self)))
1927 ((null gnus-message-archive-method)
1931 ;; Just a single group.
1934 ;; We don't want this.
1936 ((and (listp var) (stringp (car var)))
1937 ;; A list of groups.
1941 (funcall var group))
1943 ;; An alist of regexps/functions/forms.
1948 ((stringp (caar var))
1950 (when (string-match (caar var) group)
1952 ((functionp (car var))
1954 (funcall (car var) group))
1956 (eval (car var)))))))
1957 (setq var (cdr var)))
1960 (when (or groups gcc-self-val)
1961 (when (stringp groups)
1962 (setq groups (list groups)))
1965 (message-narrow-to-headers)
1966 (goto-char (point-max))
1969 ;; Use the `gcc-self' param value instead.
1972 (if (stringp gcc-self-val)
1973 (if (string-match " " gcc-self-val)
1974 (concat "\"" gcc-self-val "\"")
1976 ;; In nndoc groups, we use the parent group name
1977 ;; instead of the current group.
1978 (let ((group (or (gnus-group-find-parameter
1979 gnus-newsgroup-name 'parent-group)
1981 (if (string-match " " group)
1982 (concat "\"" group "\"")
1984 (if (not (eq gcc-self-val 'none))
1986 (gnus-delete-line)))
1987 ;; Use the list of groups.
1988 (while (setq name (pop groups))
1989 (let ((str (if (string-match ":" name)
1991 (gnus-group-prefixed-name
1992 name gnus-message-archive-method))))
1993 (insert (if (string-match " " str)
1994 (concat "\"" str "\"")
2000 (defun gnus-mailing-list-followup-to ()
2001 "Look at the headers in the current buffer and return a Mail-Followup-To address."
2002 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
2003 (list-post (gnus-fetch-original-field "list-post")))
2004 (when (and list-post
2005 (string-match "mailto:\\([^>]+\\)" list-post))
2006 (setq list-post (match-string 1 list-post)))
2012 (defun gnus-configure-posting-styles (&optional group-name)
2013 "Configure posting styles according to `gnus-posting-styles'."
2014 (unless gnus-inhibit-posting-styles
2015 (let ((group (or group-name gnus-newsgroup-name ""))
2016 (styles gnus-posting-styles)
2017 style match attribute results
2019 ;; If the group has a posting-style parameter, add it at the end with a
2020 ;; regexp matching everything, to be sure it takes precedence over all
2022 (when gnus-newsgroup-name
2023 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2025 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2026 ;; Go through all styles and look for matches.
2027 (dolist (style styles)
2028 (setq match (pop style))
2029 (goto-char (point-min))
2032 ;; Regexp string match on the group name.
2033 (string-match match group))
2035 ;; Obsolete format of header match.
2036 (and (gnus-buffer-live-p gnus-article-copy)
2037 (with-current-buffer gnus-article-copy
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
2056 (let ((header (message-fetch-field (nth 1 match))))
2058 (string-match (nth 2 match) header))))))
2060 ;; This is a form to be evaled.
2062 ;; We have a match, so we set the variables.
2063 (setq style (gnus-configure-posting-style style nil))
2064 (dolist (attribute style)
2065 (setq results (delq (assoc (car attribute) results) results))
2066 (push attribute results))))
2067 ;; Now we have all the styles, so we insert them.
2068 (setq name (assq 'name results)
2069 address (assq 'address results))
2070 (setq results (delq name (delq address results)))
2071 (gnus-make-local-hook 'message-setup-hook)
2072 (setq results (sort results (lambda (x y)
2073 (string-lessp (car x) (car y)))))
2074 (dolist (result results)
2075 (add-hook 'message-setup-hook
2077 ((eq 'eval (car result))
2079 ((eq 'body (car result))
2083 (insert ,(cdr result)))))
2084 ((eq 'signature (car result))
2085 (set (make-local-variable 'message-signature) nil)
2086 (set (make-local-variable 'message-signature-file) nil)
2087 (if (not (cdr result))
2091 (let ((message-signature ,(cdr result)))
2092 (when message-signature
2093 (message-insert-signature)))))))
2096 (if (symbolp (car result))
2097 (capitalize (symbol-name (car result)))
2101 (message-remove-header ,header)
2102 (let ((value ,(cdr result)))
2105 (insert ,header ": " value)
2107 (insert "\n")))))))))
2109 (when (or name address)
2110 (add-hook 'message-setup-hook
2112 (set (make-local-variable 'user-mail-address)
2113 ,(or (cdr address) user-mail-address))
2114 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2116 ,(or (cdr address) user-mail-address)))
2118 (message-remove-header "From")
2120 (insert "From: " (message-make-from) "\n"))))
2123 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2124 (defun gnus-configure-posting-style (style stack)
2125 "Parse one posting style STYLE and returns the value as an alist."
2126 (let (results element variable filep value v)
2127 (dolist (attribute style)
2128 (setq element (pop attribute)
2133 ((eq (car attribute) ':file)
2136 ((eq (car attribute) :value)
2140 ;; We get the value.
2145 ((or (symbolp value)
2147 (cond ((functionp value)
2150 (symbol-value value))))
2153 ;; Translate obsolescent value.
2155 ((eq element 'signature-file)
2156 (setq element 'signature
2158 ((eq element 'x-face-file)
2159 (setq element 'x-face
2161 ;; Get the contents of file elems.
2163 (setq v (with-temp-buffer
2164 (insert-file-contents v)
2165 (goto-char (point-max))
2169 (if (eq element 'import)
2171 (if (member v stack)
2172 (error "Circular import of \"%s\"" v))
2174 (nconc (nreverse (gnus-configure-posting-style
2175 (cdr (assoc v gnus-named-posting-styles))
2178 (push (cons element v) results)))
2179 (nreverse results)))
2181 (defun gnus-summary-execute-command-with-posting-style (style command)
2182 "Temporarily select a posting-style named STYLE and execute COMMAND."
2184 (let ((style (completing-read "Posting style: "
2185 gnus-named-posting-styles nil t)))
2189 (format "Command to execute with %s: " style))))))
2190 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2191 (call-interactively command)))
2194 ;;; @ for MIME Edit mode
2197 (defun gnus-maybe-setup-default-charset ()
2199 (and (boundp 'gnus-summary-buffer)
2200 (buffer-live-p gnus-summary-buffer)
2202 (set-buffer gnus-summary-buffer)
2203 default-mime-charset))))
2206 (make-local-variable 'default-mime-charset)
2207 (setq default-mime-charset charset)
2211 ;;; @ for MIME view mode
2214 (defun gnus-following-method (buf)
2215 (gnus-setup-message 'reply-yank
2217 (if (message-news-p)
2219 (message-reply nil 'wide))
2220 (let ((message-reply-buffer buf))
2221 (message-yank-original))
2222 (message-goto-body))
2226 ;;; Allow redefinition of functions.
2232 ;;; gnus-msg.el ends here