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 ()
401 (gnus-inews-make-draft-meta-information
402 ,gnus-newsgroup-name ',gnus-article-reply)))
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))
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 article)
466 (concat "(\"" group "\" "
467 (if article (number-to-string
474 (defun gnus-msg-mail (&optional to subject other-headers continue
475 switch-action yank-action send-actions)
476 "Start editing a mail message to be sent.
477 Like `message-mail', but with Gnus paraphernalia, particularly the
478 Gcc: header for archiving purposes."
480 (let ((buf (current-buffer))
482 (gnus-setup-message 'message
483 (message-mail to subject other-headers continue
484 nil yank-action send-actions))
486 (setq mail-buf (current-buffer))
487 (switch-to-buffer buf)
488 (apply switch-action mail-buf nil)))
489 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
492 (defvar save-selected-window-window)
495 (defun gnus-button-mailto (address)
497 (set-buffer (gnus-copy-article-buffer))
498 (gnus-setup-message 'message
499 (message-reply address))
500 (and (boundp 'save-selected-window-window)
501 (not (window-live-p save-selected-window-window))
502 (setq save-selected-window-window (selected-window))))
505 (defun gnus-button-reply (&optional to-address wide)
506 "Like `message-reply'."
508 (gnus-setup-message 'message
509 (message-reply to-address wide))
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 (define-mail-user-agent 'gnus-user-agent
516 'gnus-msg-mail 'message-send-and-exit
517 'message-kill-buffer 'message-send-hook)
519 (defun gnus-setup-posting-charset (group)
520 (let ((alist gnus-group-posting-charset-alist)
521 (group (or group ""))
525 (while (setq elem (pop alist))
526 (when (or (and (stringp (car elem))
527 (string-match (car elem) group))
528 (and (functionp (car elem))
529 (funcall (car elem) group))
530 (and (symbolp (car elem))
531 (symbol-value (car elem))))
532 (throw 'found (cons (cadr elem) (caddr elem)))))))))
534 (defun gnus-inews-add-send-actions (winconf buffer article
535 &optional config yanked)
536 (gnus-make-local-hook 'message-sent-hook)
537 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
538 'gnus-inews-do-gcc) nil t)
540 (gnus-make-local-hook 'message-header-hook)
541 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
542 (setq message-post-method
544 (gnus-post-method arg ,gnus-newsgroup-name)))
545 (setq message-user-agent (gnus-message-make-user-agent))
546 (unless message-use-multi-frames
548 `(if (gnus-buffer-exists-p ,buffer)
549 (set-window-configuration ,winconf))
550 'exit 'postpone 'kill))
551 (let ((to-be-marked (cond
554 (lambda (x) (if (listp x) (car x) x)) yanked))
555 (article (if (listp article) article (list article)))
558 `(when (gnus-buffer-exists-p ,buffer)
562 (if (eq config 'forward)
563 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
564 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
567 (put 'gnus-setup-message 'lisp-indent-function 1)
568 (put 'gnus-setup-message 'edebug-form-spec '(form body))
570 ;;; Post news commands of Gnus group mode and summary mode
572 (defun gnus-group-mail (&optional arg)
573 "Start composing a mail.
574 If ARG, use the group under the point to find a posting style.
575 If ARG is 1, prompt for a group name to find the posting style."
577 ;; We can't `let' gnus-newsgroup-name here, since that leads
578 ;; to local variables leaking.
579 (let ((group gnus-newsgroup-name)
580 ;; make sure last viewed article doesn't affect posting styles:
582 (buffer (current-buffer)))
585 (setq gnus-newsgroup-name
587 (if (= 1 (prefix-numeric-value arg))
588 (completing-read "Use posting style of group: "
589 gnus-active-hashtb nil
590 (gnus-read-active-file-p))
591 (gnus-group-group-name))
593 ;; #### see comment in gnus-setup-message -- drv
594 (gnus-setup-message 'message (message-mail)))
597 (setq gnus-newsgroup-name group)))))
599 (defun gnus-group-news (&optional arg)
600 "Start composing a news.
601 If ARG, post to group under point.
602 If ARG is 1, prompt for group name to post to.
604 This function prepares a news even when using mail groups. This is useful
605 for posting messages to mail groups without actually sending them over the
606 network. The corresponding back end must have a 'request-post method."
608 ;; We can't `let' gnus-newsgroup-name here, since that leads
609 ;; to local variables leaking.
610 (let ((group gnus-newsgroup-name)
611 ;; make sure last viewed article doesn't affect posting styles:
613 (buffer (current-buffer)))
616 (setq gnus-newsgroup-name
618 (if (= 1 (prefix-numeric-value arg))
619 (completing-read "Use group: "
620 gnus-active-hashtb nil
621 (gnus-read-active-file-p))
622 (gnus-group-group-name))
624 ;; #### see comment in gnus-setup-message -- drv
625 (gnus-setup-message 'message
626 (message-news (gnus-group-real-name gnus-newsgroup-name))))
629 (setq gnus-newsgroup-name group)))))
631 (defun gnus-group-post-news (&optional arg)
632 "Start composing a message (a news by default).
633 If ARG, post to group under point. If ARG is 1, prompt for group name.
634 Depending on the selected group, the message might be either a mail or
637 ;; Bind this variable here to make message mode hooks work ok.
638 (let ((gnus-newsgroup-name
640 (if (= 1 (prefix-numeric-value arg))
641 (completing-read "Newsgroup: " gnus-active-hashtb nil
642 (gnus-read-active-file-p))
643 (gnus-group-group-name))
645 ;; make sure last viewed article doesn't affect posting styles:
647 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
648 (string= gnus-newsgroup-name ""))))
650 (defun gnus-summary-mail-other-window (&optional arg)
651 "Start composing a mail in another window.
652 Use the posting of the current group by default.
653 If ARG, don't do that. If ARG is 1, prompt for group name to find the
656 ;; We can't `let' gnus-newsgroup-name here, since that leads
657 ;; to local variables leaking.
658 (let ((group gnus-newsgroup-name)
659 ;; make sure last viewed article doesn't affect posting styles:
661 (buffer (current-buffer)))
664 (setq gnus-newsgroup-name
666 (if (= 1 (prefix-numeric-value arg))
667 (completing-read "Use group: "
668 gnus-active-hashtb nil
669 (gnus-read-active-file-p))
671 gnus-newsgroup-name))
672 ;; #### see comment in gnus-setup-message -- drv
673 (gnus-setup-message 'message (message-mail)))
676 (setq gnus-newsgroup-name group)))))
678 (defun gnus-summary-news-other-window (&optional arg)
679 "Start composing a news in another window.
680 Post to the current group by default.
681 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
683 This function prepares a news even when using mail groups. This is useful
684 for posting messages to mail groups without actually sending them over the
685 network. The corresponding back end must have a 'request-post method."
687 ;; We can't `let' gnus-newsgroup-name here, since that leads
688 ;; to local variables leaking.
689 (let ((group gnus-newsgroup-name)
690 ;; make sure last viewed article doesn't affect posting styles:
692 (buffer (current-buffer)))
695 (setq gnus-newsgroup-name
697 (if (= 1 (prefix-numeric-value arg))
698 (completing-read "Use group: "
699 gnus-active-hashtb nil
700 (gnus-read-active-file-p))
702 gnus-newsgroup-name))
703 ;; #### see comment in gnus-setup-message -- drv
704 (gnus-setup-message 'message
706 (message-news (gnus-group-real-name gnus-newsgroup-name))
707 (set (make-local-variable 'gnus-discouraged-post-methods)
709 (car (gnus-find-method-for-group gnus-newsgroup-name))
710 gnus-discouraged-post-methods)))))
713 (setq gnus-newsgroup-name group)))))
715 (defun gnus-summary-post-news (&optional arg)
716 "Start composing a message. Post to the current group by default.
717 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
718 Depending on the selected group, the message might be either a mail or
721 ;; Bind this variable here to make message mode hooks work ok.
722 (let ((gnus-newsgroup-name
724 (if (= 1 (prefix-numeric-value arg))
725 (completing-read "Newsgroup: " gnus-active-hashtb nil
726 (gnus-read-active-file-p))
728 gnus-newsgroup-name))
729 ;; make sure last viewed article doesn't affect posting styles:
731 (gnus-post-news 'post gnus-newsgroup-name)))
734 (defun gnus-summary-followup (yank &optional force-news)
735 "Compose a followup to an article.
736 If prefix argument YANK is non-nil, the original article is yanked
738 YANK is a list of elements, where the car of each element is the
739 article number, and the cdr is the string to be yanked."
741 (list (and current-prefix-arg
742 (gnus-summary-work-articles 1))))
744 (gnus-summary-goto-subject
745 (if (listp (car yank))
748 (save-window-excursion
749 (gnus-summary-select-article))
750 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
751 (gnus-newsgroup-name gnus-newsgroup-name))
753 (gnus-post-news nil gnus-newsgroup-name
754 headers gnus-article-buffer
756 (gnus-summary-handle-replysign)))
758 (defun gnus-summary-followup-with-original (n &optional force-news)
759 "Compose a followup to an article and include the original article."
761 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
763 (defun gnus-summary-followup-to-mail (&optional arg)
764 "Followup to the current mail message via news."
766 (list (and current-prefix-arg
767 (gnus-summary-work-articles 1))))
768 (gnus-summary-followup arg t))
770 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
771 "Followup to the current mail message via news."
773 (gnus-summary-followup (gnus-summary-work-articles arg) t))
775 (defun gnus-inews-yank-articles (articles)
776 (let (beg article yank-string
777 (more-than-one (cdr articles))
778 (cur (current-buffer))
781 (while (setq article (pop articles))
782 (when (listp article)
783 (setq yank-string (nth 1 article)
784 article (nth 0 article)))
785 (save-window-excursion
786 (set-buffer gnus-summary-buffer)
787 (gnus-summary-select-article nil nil nil article)
788 (gnus-summary-remove-process-mark article))
790 ;; Gathering references.
792 (setq refs (message-list-references
794 (mail-header-references gnus-current-headers)
795 (mail-header-message-id gnus-current-headers)))
796 (when message-use-multi-frames
797 (when (setq window (get-buffer-window cur t))
798 (select-frame (window-frame window)))))
800 (gnus-copy-article-buffer nil yank-string)
801 (let ((message-reply-buffer gnus-article-copy)
802 (message-reply-headers
803 ;; The headers are decoded.
804 (with-current-buffer gnus-article-copy
806 (nnheader-narrow-to-headers)
807 (nnheader-parse-naked-head)))))
808 (message-yank-original)
809 (setq beg (or beg (mark t))))
814 ;; Replace with the gathered references.
818 (message-narrow-to-headers)
819 (let ((case-fold-search t))
820 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
822 (goto-char (point-max))))
824 (list (or (assq 'References message-header-format-alist)
825 '(References . message-shorten-references)))
826 (list (cons 'References
827 (mapconcat 'identity (nreverse refs) " "))))
828 (backward-delete-char 1))
834 (defun gnus-summary-cancel-article (&optional n symp)
835 "Cancel an article you posted.
836 Uses the process-prefix convention. If given the symbolic
837 prefix `a', cancel using the standard posting method; if not
838 post using the current select method."
839 (interactive (gnus-interactive "P\ny"))
840 (let ((articles (gnus-summary-work-articles n))
843 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
845 (while (setq article (pop articles))
846 (when (gnus-summary-select-article t nil nil article)
847 (when (gnus-eval-in-buffer-window gnus-article-buffer
849 (set-buffer gnus-original-article-buffer)
850 (message-cancel-news)))
851 (gnus-summary-mark-as-read article gnus-canceled-mark)
852 (gnus-cache-remove-article 1))
853 (gnus-article-hide-headers-if-wanted))
854 (gnus-summary-remove-process-mark article))))
856 (defun gnus-summary-supersede-article ()
857 "Compose an article that will supersede a previous article.
858 This is done simply by taking the old article and adding a Supersedes
859 header line with the old Message-ID."
861 (let ((article (gnus-summary-article-number)))
862 (gnus-setup-message 'reply-yank
863 (gnus-summary-select-article t)
864 (set-buffer gnus-original-article-buffer)
868 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
870 (set-buffer ,gnus-summary-buffer)
871 (gnus-cache-possibly-remove-article ,article nil nil nil t)
872 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
873 message-send-actions))))
877 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
878 ;; make a copy of the article buffer with all text properties removed
879 ;; this copy is in the buffer gnus-article-copy.
880 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
881 ;; this buffer should be passed to all mail/news reply/post routines.
882 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
884 (set-buffer gnus-article-copy)
885 (set-buffer-multibyte t))
886 (let ((article-buffer (or article-buffer gnus-article-buffer))
888 (if (not (and (get-buffer article-buffer)
889 (gnus-buffer-exists-p article-buffer)))
890 (error "Can't find any article buffer")
892 (set-buffer article-buffer)
893 (let ((gnus-newsgroup-charset (or gnus-article-charset
894 gnus-newsgroup-charset))
895 (gnus-newsgroup-ignored-charsets
896 (or gnus-article-ignored-charsets
897 gnus-newsgroup-ignored-charsets)))
899 ;; Copy over the (displayed) article buffer, delete
900 ;; hidden text and remove text properties.
902 (copy-to-buffer gnus-article-copy (point-min) (point-max))
903 (set-buffer gnus-article-copy)
904 ;; There's invisible and intangible text in T-gnus. Especially,
905 ;; if there is a boundary line (X-Boundary: ------------------),
906 ;; in the end of a header, it will cause a serious problem.
907 (add-text-properties (point-min) (point-max)
908 '(invisible nil intangible nil))
911 (delete-region (point) (point-max))
912 (insert yank-string))
913 ;; Encode bitmap smileys to ordinary text.
914 ;; Possibly, the original text might be restored.
915 (static-unless (featurep 'xemacs)
916 (when (featurep 'smiley-mule)
917 (smiley-encode-buffer)))
918 (gnus-article-delete-text-of-type 'annotation)
919 (gnus-remove-text-with-property 'gnus-prev)
920 (gnus-remove-text-with-property 'gnus-next)
921 (gnus-remove-text-with-property 'gnus-decoration)
922 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
925 (static-if (featurep 'xemacs)
926 ;; Revome smiley extents for (possibly) XEmacs 21.1.
928 (buffer-substring-no-properties (point-min)
930 (buffer-substring-no-properties (point-min) (point-max)))
932 ;; Find the original headers.
933 (set-buffer gnus-original-article-buffer)
934 (goto-char (point-min))
935 (while (looking-at message-unix-mail-delimiter)
937 (let ((mail-header-separator ""))
939 end (or (message-goto-body)
940 ;; There may be just a header.
942 ;; Delete the headers from the displayed articles.
943 (set-buffer gnus-article-copy)
944 (let ((mail-header-separator ""))
945 (delete-region (goto-char (point-min))
946 (or (message-goto-body) (point-max))))
947 ;; Insert the original article headers.
948 (insert-buffer-substring gnus-original-article-buffer beg end)
950 (let ((gnus-article-decode-hook
951 (delq 'article-decode-charset
952 (copy-sequence gnus-article-decode-hook))))
953 ;; Needed for T-gnus.
954 (add-hook 'gnus-article-decode-hook
955 'article-decode-encoded-words)
956 (run-hooks 'gnus-article-decode-hook)))))
959 (defun gnus-post-news (post &optional group header article-buffer yank subject
962 (gnus-copy-article-buffer))
963 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
964 (gnus-article-yanked-articles yank)
965 (add-to-list gnus-add-to-list))
966 (gnus-setup-message (cond (yank 'reply-yank)
967 (article-buffer 'reply)
969 (let* ((group (or group gnus-newsgroup-name))
970 (charset (gnus-group-name-charset nil group))
972 to-address to-group mailing-list to-list
975 (setq to-address (gnus-parameter-to-address group)
976 to-group (gnus-group-find-parameter group 'to-group)
977 to-list (gnus-parameter-to-list group)
978 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
979 mailing-list (when gnus-mailing-list-groups
980 (string-match gnus-mailing-list-groups group))
981 group (gnus-group-name-decode (gnus-group-real-name group)
983 (if (or (and to-group
984 (gnus-news-group-p to-group))
987 (and (gnus-news-group-p
988 (or pgroup gnus-newsgroup-name)
989 (or header gnus-current-article))
997 (and (not (gnus-virtual-group-p pgroup)) group)))
998 (set-buffer gnus-article-copy)
999 (gnus-msg-treat-broken-reply-to)
1000 (message-followup (if (or newsgroup-p force-news)
1001 (if (save-restriction
1002 (article-narrow-to-head)
1003 (message-fetch-field "newsgroups"))
1010 (message-mail (or to-address to-list))
1011 ;; Arrange for mail groups that have no `to-address' to
1012 ;; get that when the user sends off the mail.
1013 (when (and (not to-list)
1016 (push (list 'gnus-inews-add-to-address pgroup)
1017 message-send-actions)))
1018 (set-buffer gnus-article-copy)
1019 (gnus-msg-treat-broken-reply-to)
1020 (message-wide-reply to-address)))
1022 (gnus-inews-yank-articles yank))))))
1024 (defun gnus-msg-treat-broken-reply-to (&optional force)
1025 "Remove the Reply-to header if broken-reply-to."
1027 (gnus-group-find-parameter
1028 gnus-newsgroup-name 'broken-reply-to))
1030 (message-narrow-to-head)
1031 (message-remove-header "reply-to"))))
1033 (defun gnus-post-method (arg group &optional silent)
1034 "Return the posting method based on GROUP and ARG.
1035 If SILENT, don't prompt the user."
1036 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1038 (group-method (gnus-find-method-for-group group)))
1040 ;; If the group-method is nil (which shouldn't happen) we use
1041 ;; the default method.
1042 ((null group-method)
1043 (or (and (listp gnus-post-method) ;If not current/native/nil
1044 (not (listp (car gnus-post-method))) ; and not a list of methods
1045 gnus-post-method) ;then use it.
1047 message-post-method))
1048 ;; We want the inverse of the default
1049 ((and arg (not (eq arg 0)))
1050 (if (eq gnus-post-method 'current)
1053 ;; We query the user for a post method.
1055 (and (listp gnus-post-method)
1056 (listp (car gnus-post-method))))
1058 ;; Collect all methods we know about.
1060 (when (listp gnus-post-method)
1061 (if (listp (car gnus-post-method))
1063 (list gnus-post-method)))
1064 gnus-secondary-select-methods
1065 (mapcar 'cdr gnus-server-alist)
1066 (mapcar 'car gnus-opened-servers)
1067 (list gnus-select-method)
1068 (list group-method)))
1069 method-alist post-methods method)
1070 ;; Weed out all mail methods.
1072 (setq method (gnus-server-get-method "" (pop methods)))
1073 (when (and (or (gnus-method-option-p method 'post)
1074 (gnus-method-option-p method 'post-mail))
1075 (not (member method post-methods)))
1076 (push method post-methods)))
1077 ;; Create a name-method alist.
1081 (if (equal (cadr m) "")
1082 (list (symbol-name (car m)) m)
1083 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1088 (setq gnus-last-posting-server
1090 gnus-last-posting-server)
1091 ;; Just use the last value.
1092 gnus-last-posting-server
1094 "Posting method: " method-alist nil t
1095 (cons (or gnus-last-posting-server "") 0))))
1097 ;; Override normal method.
1098 ((and (eq gnus-post-method 'current)
1099 (not (memq (car group-method) gnus-discouraged-post-methods))
1100 (gnus-get-function group-method 'request-post t))
1103 ;; Use gnus-post-method.
1104 ((listp gnus-post-method) ;A method...
1105 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1107 ;; Use the normal select method (nil or native).
1108 (t gnus-select-method))))
1111 ;; Dummies to avoid byte-compile warning.
1113 (defvar xemacs-codename))
1115 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1117 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1118 variable `mime-edit-user-agent-value' is bound, the value will be
1119 included in the return value, and `gnus-user-agent' is ignored. If
1120 MAX-COLUMN is specified, the return value will be folded up as it were
1121 filled. NEWLINE-PRODUCT specifies whether a newline should be
1122 inserted in front of each product-token. If the value is t or `hard',
1123 it works strictly. Otherwise, if it is non-nil (e.g. `soft'), it
1124 works semi-strictly.
1126 Here is an odd example, which inserts a User-Agent: header when you
1127 begin to compose a message:
1129 \(add-hook 'gnus-message-setup-hook
1131 (setq message-user-agent nil)
1134 (message-narrow-to-headers)
1135 (goto-char (point-max))
1136 (insert \"User-Agent: \"
1137 (gnus-message-make-user-agent t 76 'soft)
1140 (let ((gnus-v (gnus-extended-version))
1142 (cond ((and include-mime-info
1143 (boundp 'mime-edit-user-agent-value))
1144 (setq user-agent (concat gnus-v " " mime-edit-user-agent-value)))
1145 ((eq gnus-user-agent 'gnus-mime-edit)
1147 (if (boundp 'mime-edit-user-agent-value)
1148 (concat gnus-v " " mime-edit-user-agent-value)
1151 (setq user-agent (if (stringp gnus-user-agent)
1154 (let ((emacs-v (gnus-emacs-version)))
1156 (concat " " emacs-v))))))))
1158 (unless (natnump max-column)
1159 (setq max-column 76))
1161 (set-buffer-multibyte t)
1162 (insert (mapconcat 'identity (split-string user-agent) " "))
1163 (goto-char (point-min))
1165 start agent agents width element swidth)
1166 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1167 (setq start (match-beginning 0))
1168 (if (eq (char-after start) ?\()
1172 (push (buffer-substring start (point)) agent))
1174 (push (nreverse agent) agents))
1175 (setq agent (list (match-string 1)))))
1177 (push (nreverse agent) agents))
1178 (setq agents (nreverse agents))
1179 (if (> (+ 12 (string-width (caar agents))) max-column)
1180 (setq user-agent "\n"
1185 (setq agent (car agents)
1186 agents (cdr agents))
1187 (when (and (not bol)
1188 (or (memq newline-product '(t hard))
1189 (and newline-product
1191 (string-width (mapconcat 'identity
1194 (setq user-agent (concat user-agent "\n")
1198 (setq element (car agent)
1199 swidth (string-width element)
1202 (setq user-agent (if (member user-agent '("" "\n"))
1203 (concat user-agent element)
1204 (concat user-agent " " element))
1205 width (+ width 1 swidth)
1207 (if (> (+ width 1 swidth) max-column)
1208 (setq user-agent (concat user-agent "\n " element)
1210 (setq user-agent (concat user-agent " " element)
1211 width (+ width 1 swidth)))))))))
1216 ;;; Gnus Mail Functions
1219 ;;; Mail reply commands of Gnus summary mode
1221 (defun gnus-summary-reply (&optional yank wide very-wide)
1222 "Start composing a mail reply to the current message.
1223 If prefix argument YANK is non-nil, the original article is yanked
1225 If WIDE, make a wide reply.
1226 If VERY-WIDE, make a very wide reply."
1228 (list (and current-prefix-arg
1229 (gnus-summary-work-articles 1))))
1230 ;; Allow user to require confirmation before replying by mail to the
1231 ;; author of a news article (or mail message).
1233 (not (or (gnus-news-group-p gnus-newsgroup-name)
1234 gnus-confirm-treat-mail-like-news))
1235 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1236 (string-match gnus-confirm-mail-reply-to-news
1237 gnus-newsgroup-name))
1238 ((functionp gnus-confirm-mail-reply-to-news)
1239 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1240 (t gnus-confirm-mail-reply-to-news)))
1241 (y-or-n-p "Really reply by mail to article author? "))
1243 (if (listp (car yank))
1246 (gnus-article-reply (or article (gnus-summary-article-number)))
1247 (gnus-article-yanked-articles yank)
1249 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1251 (gnus-summary-goto-subject article))
1252 (gnus-setup-message (if yank 'reply-yank 'reply)
1254 (gnus-summary-select-article)
1255 (dolist (article very-wide)
1256 (gnus-summary-select-article nil nil nil article)
1258 (set-buffer (gnus-copy-article-buffer))
1259 (gnus-msg-treat-broken-reply-to)
1261 (message-narrow-to-head)
1262 (setq headers (concat headers (buffer-string)))))))
1263 (set-buffer (gnus-copy-article-buffer))
1264 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1266 (message-narrow-to-head)
1270 (goto-char (point-max)))
1271 (message-reply nil wide)
1273 (gnus-inews-yank-articles yank))
1274 (gnus-summary-handle-replysign)))))
1276 (defun gnus-summary-handle-replysign ()
1277 "Check the various replysign variables and take action accordingly."
1278 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1279 (let (signed encrypted)
1281 (set-buffer gnus-article-buffer)
1282 (setq signed (memq 'signed gnus-article-wash-types))
1283 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1284 (cond ((and gnus-message-replyencrypt encrypted)
1285 (mml-secure-message mml-default-encrypt-method
1286 (if gnus-message-replysignencrypted
1289 ((and gnus-message-replysign signed)
1290 (mml-secure-message mml-default-sign-method 'sign))))))
1292 (defun gnus-summary-reply-with-original (n &optional wide)
1293 "Start composing a reply mail to the current message.
1294 The original article will be yanked."
1296 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1298 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1299 "Like `gnus-summary-reply' except removing reply-to field.
1300 If prefix argument YANK is non-nil, the original article is yanked
1302 If WIDE, make a wide reply.
1303 If VERY-WIDE, make a very wide reply."
1305 (list (and current-prefix-arg
1306 (gnus-summary-work-articles 1))))
1307 (let ((gnus-msg-force-broken-reply-to t))
1308 (gnus-summary-reply yank wide very-wide)))
1310 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1311 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1312 The original article will be yanked."
1314 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1316 (defun gnus-summary-wide-reply (&optional yank)
1317 "Start composing a wide reply mail to the current message.
1318 If prefix argument YANK is non-nil, the original article is yanked
1321 (list (and current-prefix-arg
1322 (gnus-summary-work-articles 1))))
1323 (gnus-summary-reply yank t))
1325 (defun gnus-summary-wide-reply-with-original (n)
1326 "Start composing a wide reply mail to the current message.
1327 The original article will be yanked.
1328 Uses the process/prefix convention."
1330 (gnus-summary-reply-with-original n t))
1332 (defun gnus-summary-very-wide-reply (&optional yank)
1333 "Start composing a very wide reply mail to the current message.
1334 If prefix argument YANK is non-nil, the original article is yanked
1337 (list (and current-prefix-arg
1338 (gnus-summary-work-articles 1))))
1339 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1341 (defun gnus-summary-very-wide-reply-with-original (n)
1342 "Start composing a very wide reply mail to the current message.
1343 The original article will be yanked."
1346 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1348 (defun gnus-summary-mail-forward (&optional full-headers post)
1349 "Forward the current message(s) to another user.
1350 If process marks exist, forward all marked messages;
1351 If FULL-HEADERS (the prefix), include full headers when forwarding.
1353 Note that this function definition for T-gnus is totally different
1354 from the original Gnus."
1356 (if (cdr (gnus-summary-work-articles nil))
1357 ;; Process marks are given.
1358 (gnus-summary-digest-mail-forward nil post)
1359 ;; No process marks.
1360 (let* ((gnus-article-reply (gnus-summary-article-number))
1361 (gnus-article-yanked-articles (list gnus-article-reply))
1363 (message-included-forward-headers
1364 (if full-headers "" message-included-forward-headers)))
1365 (gnus-setup-message 'forward
1366 (gnus-summary-select-article)
1367 (setq charset default-mime-charset)
1368 (set-buffer gnus-original-article-buffer)
1369 (make-local-variable 'default-mime-charset)
1370 (setq default-mime-charset charset)
1371 (message-forward post)))))
1373 (defun gnus-summary-digest-mail-forward (&optional n post)
1374 "Digests and forwards all articles in this series.
1375 If N is a positive number, forward the N next articles.
1376 If N is a negative number, forward the N previous articles.
1377 If N is nil and any articles have been marked with the process mark,
1378 forward those articles instead.
1379 Optional POST will use news to forward instead of mail."
1381 (let* ((articles (gnus-summary-work-articles n))
1382 (gnus-article-yanked-articles (copy-sequence articles))
1383 (topics "Topics:\n")
1384 subject article frame)
1385 (when (car articles)
1386 (gnus-setup-message 'forward
1387 (gnus-summary-select-article)
1389 (setq articles (sort articles '<)
1390 subject "Digested Articles")
1391 (with-current-buffer gnus-original-article-buffer
1392 (setq subject (message-make-forward-subject))))
1394 (message-news nil subject)
1395 (message-mail nil subject))
1396 (when (and message-use-multi-frames (cdr articles))
1397 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1399 (while (setq article (pop articles))
1400 (save-window-excursion
1401 (set-buffer gnus-summary-buffer)
1402 (gnus-summary-select-article nil nil nil article)
1403 (setq topics (concat topics " "
1404 (mail-header-subject gnus-current-headers)
1406 (gnus-summary-remove-process-mark article))
1408 (select-frame frame))
1409 (insert (mime-make-tag "message" "rfc822") "\n")
1410 (narrow-to-region (point) (point))
1411 (insert-buffer-substring gnus-original-article-buffer)
1413 (article-narrow-to-head)
1414 (message-remove-header message-included-forward-headers t nil t))
1415 (goto-char (point-max))
1421 (mime-edit-enclose-digest-region (point)(mark t))))))
1423 (defun gnus-summary-digest-post-forward (&optional n)
1424 "Digest and forwards all articles in this series to a newsgroup.
1425 If N is a positive number, forward the N next articles.
1426 If N is a negative number, forward the N previous articles.
1427 If N is nil and any articles have been marked with the process mark,
1428 forward those articles instead."
1430 (gnus-summary-digest-mail-forward n t))
1432 (defun gnus-summary-resend-message (address n)
1433 "Resend the current article to ADDRESS."
1435 (list (message-read-from-minibuffer
1436 "Resend message(s) to: "
1437 (when (and gnus-summary-resend-default-address
1438 (gnus-buffer-live-p gnus-original-article-buffer))
1439 ;; If some other article is currently selected, the
1440 ;; initial-contents is wrong. Whatever, it is just the
1441 ;; initial-contents.
1442 (with-current-buffer gnus-original-article-buffer
1443 (nnmail-fetch-field "to"))))
1444 current-prefix-arg))
1445 (let ((articles (gnus-summary-work-articles n))
1447 (while (setq article (pop articles))
1448 (gnus-summary-select-article nil nil nil article)
1450 (set-buffer gnus-original-article-buffer)
1451 (message-resend address))
1452 (gnus-summary-mark-article-as-forwarded article))))
1454 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1455 (defun gnus-summary-resend-message-edit ()
1456 "Resend an article that has already been sent.
1457 A new buffer will be created to allow the user to modify body and
1458 contents of the message, and then, everything will happen as when
1459 composing a new message."
1461 (let ((article (gnus-summary-article-number)))
1462 (gnus-setup-message 'reply-yank
1463 (gnus-summary-select-article t)
1464 (set-buffer gnus-original-article-buffer)
1465 (let ((cur (current-buffer))
1466 (to (message-fetch-field "to")))
1467 ;; Get a normal message buffer.
1468 (message-pop-to-buffer (message-buffer-name "Resend" to))
1469 (insert-buffer-substring cur)
1471 ;; T-gnus change: Use MIME-Edit to recompose a message.
1473 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1474 (fset 'mime-edit-decode-single-part-in-buffer
1475 (lambda (&rest args)
1476 (if (let ((content-type (car args)))
1477 (and (eq 'message (mime-content-type-primary-type
1479 (eq 'rfc822 (mime-content-type-subtype
1481 (setcar (cdr args) 'not-decode-text))
1484 (mime-edit-again nil t)
1485 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1486 (message-narrow-to-head-1)
1487 (insert "From: " (message-make-from) "\n")
1488 (while (re-search-forward "^From:" nil t)
1490 (insert "Original-"))
1491 (message-remove-header "^>From[\t ]" t)
1493 ;; Gnus will generate a new one when sending.
1494 (message-remove-header "Message-ID")
1495 (message-remove-header message-ignored-resent-headers t)
1496 ;; Remove unwanted headers.
1497 (goto-char (point-max))
1498 (insert mail-header-separator)
1499 (goto-char (point-min))
1500 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1504 (defun gnus-summary-post-forward (&optional full-headers)
1505 "Forward the current article to a newsgroup.
1506 If FULL-HEADERS (the prefix), include full headers when forwarding."
1508 (gnus-summary-mail-forward full-headers t))
1510 (defvar gnus-nastygram-message
1511 "The following article was inappropriately posted to %s.\n\n"
1512 "Format string to insert in nastygrams.
1513 The current group name will be inserted at \"%s\".")
1515 (defun gnus-summary-mail-nastygram (n)
1516 "Send a nastygram to the author of the current article."
1518 (when (or gnus-expert-user
1520 "Really send a nastygram to the author of the current article? "))
1521 (let ((group gnus-newsgroup-name))
1522 (gnus-summary-reply-with-original n)
1523 (set-buffer gnus-message-buffer)
1525 (insert (format gnus-nastygram-message group))
1526 (message-send-and-exit))))
1528 (defun gnus-summary-mail-crosspost-complaint (n)
1529 "Send a complaint about crossposting to the current article(s)."
1531 (let ((articles (gnus-summary-work-articles n))
1533 (while (setq article (pop articles))
1534 (set-buffer gnus-summary-buffer)
1535 (gnus-summary-goto-subject article)
1536 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1537 newsgroups followup-to)
1538 (gnus-summary-select-article)
1539 (set-buffer gnus-original-article-buffer)
1540 (if (and (<= (length (message-tokenize-header
1542 (mail-fetch-field "newsgroups"))
1545 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1546 (not (member group (message-tokenize-header
1547 followup-to ", ")))))
1549 (gnus-message 1 "Followup-to restricted")
1550 (gnus-message 1 "Not a crossposted article"))
1551 (set-buffer gnus-summary-buffer)
1552 (gnus-summary-reply-with-original 1)
1553 (set-buffer gnus-message-buffer)
1555 (insert (format gnus-crosspost-complaint newsgroups group))
1556 (message-goto-subject)
1557 (re-search-forward " *$")
1558 (replace-match " (crosspost notification)" t t)
1559 (gnus-deactivate-mark)
1560 (when (gnus-y-or-n-p "Send this complaint? ")
1561 (message-send-and-exit)))))))
1563 (defun gnus-mail-parse-comma-list ()
1566 (skip-chars-forward " ")
1569 (skip-chars-forward "^,")
1574 (narrow-to-region beg (point))
1577 (while (search-forward "\"" nil t)
1581 (skip-chars-forward ",")
1582 (skip-chars-forward "^,"))
1583 (skip-chars-backward " ")
1584 (push (buffer-substring beg (point))
1586 (skip-chars-forward "^,")
1587 (skip-chars-forward ", "))
1590 (defun gnus-inews-add-to-address (group)
1591 (let ((to-address (mail-fetch-field "to")))
1592 (when (and to-address
1594 ;; This mail group doesn't have a `to-list', so we add one
1596 (when (gnus-y-or-n-p
1597 (format "Do you want to add this as `to-list': %s? " to-address))
1598 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1600 (defun gnus-put-message ()
1601 "Put the current message in some group and return to Gnus."
1603 (let ((reply gnus-article-reply)
1604 (winconf gnus-prev-winconf)
1605 (group gnus-newsgroup-name))
1607 (not (gnus-group-read-only-p group)))
1608 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1610 (when (gnus-group-entry group)
1611 (error "No such group: %s" group))
1615 (message-narrow-to-headers)
1616 (let ((gnus-deletable-headers nil))
1617 (message-generate-headers
1618 (if (message-news-p)
1619 message-required-news-headers
1620 message-required-mail-headers)))
1621 (goto-char (point-max))
1622 (if (string-match " " group)
1623 (insert "Gcc: \"" group "\"\n")
1624 (insert "Gcc: " group "\n"))
1627 (when (and (get-buffer gnus-group-buffer)
1628 (gnus-buffer-exists-p (car-safe reply))
1630 (set-buffer (car reply))
1631 (gnus-summary-mark-article-as-replied (cdr reply)))
1633 (set-window-configuration winconf))))
1635 (defun gnus-article-mail (yank)
1636 "Send a reply to the address near point.
1637 If YANK is non-nil, include the original article."
1641 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1642 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1644 (gnus-msg-mail address)
1646 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1648 (defvar nntp-server-type)
1650 "Send a bug report to the Gnus maintainers."
1652 (unless (gnus-alive-p)
1653 (error "Gnus has been shut down"))
1654 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1655 (unless (message-mail-user-agent)
1656 (message-pop-to-buffer "*Gnus Bug*")
1657 (delete-other-windows)
1658 (when gnus-bug-create-help-buffer
1659 (switch-to-buffer "*Gnus Help Bug*")
1661 (insert gnus-bug-message)
1662 (goto-char (point-min))
1664 (set-buffer "*Gnus Bug*")))
1665 (let ((message-this-is-mail t))
1666 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1667 (when gnus-bug-create-help-buffer
1668 (push `(gnus-bug-kill-buffer) message-send-actions))
1669 (goto-char (point-min))
1670 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1672 (insert gnus-product-name " " gnus-version-number
1673 " (r" gnus-revision-number ") "
1674 "based on " gnus-original-product-name " v"
1675 gnus-original-version-number "\n"
1676 (emacs-version) "\n")
1677 (when (and (boundp 'nntp-server-type)
1678 (stringp nntp-server-type))
1679 (insert nntp-server-type))
1680 (insert "\n\n\n\n\n")
1681 (let (mime-content-types)
1682 (mime-edit-insert-tag
1683 "application" "emacs-lisp"
1684 "\nContent-Disposition: inline\nContent-Description: User settings"))
1685 (insert (with-temp-buffer
1688 (let (mime-content-types)
1689 (mime-edit-insert-tag "text" "plain"))
1690 (goto-char (point-min))
1691 (search-forward "Subject: " nil t)
1694 (defun gnus-bug-kill-buffer ()
1695 (when (get-buffer "*Gnus Help Bug*")
1696 (kill-buffer "*Gnus Help Bug*")))
1698 (defun gnus-summary-yank-message (buffer n)
1699 "Yank the current article into a composed message."
1701 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1702 current-prefix-arg))
1703 (when (gnus-buffer-live-p buffer)
1704 (let ((summary-frame (selected-frame))
1705 (message-frame (when (static-if (featurep 'xemacs)
1706 (device-on-window-system-p)
1708 (let ((window (get-buffer-window buffer t)))
1710 (window-frame window)))))
1711 (separator (concat "^" (regexp-quote mail-header-separator)
1713 (gnus-summary-iterate n
1714 (gnus-summary-select-article)
1715 (gnus-copy-article-buffer)
1716 (when (frame-live-p message-frame)
1717 (raise-frame message-frame)
1718 (select-frame message-frame))
1719 (with-current-buffer buffer
1720 (when (save-excursion
1722 (let (case-fold-search)
1723 (and (not (re-search-backward separator nil t))
1724 (re-search-forward separator nil t))))
1725 (goto-char (match-end 0)))
1726 (message-yank-buffer gnus-article-copy))
1727 (select-frame summary-frame))
1728 (when (frame-live-p message-frame)
1729 (select-frame message-frame)))))
1731 (defun gnus-debug ()
1732 "Attempts to go through the Gnus source file and report what variables have been changed.
1733 The source file has to be in the Emacs load path."
1735 (let ((files gnus-debug-files)
1737 file expr olist sym)
1738 (gnus-message 4 "Please wait while we snoop your variables...")
1739 ;; Go through all the files looking for non-default values for variables.
1742 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1745 (when (and (setq file (locate-library (pop files)))
1746 (file-exists-p file))
1747 (insert-file-contents file)
1748 (goto-char (point-min))
1749 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1750 (gnus-message 4 "Malformed sources in file %s" file)
1751 (narrow-to-region (point-min) (point))
1752 (goto-char (point-min))
1753 (while (setq expr (ignore-errors (read (current-buffer))))
1755 (and (memq (car expr) '(defvar defcustom defvoo))
1756 (stringp (nth 3 expr))
1757 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1758 (or (not (boundp (nth 1 expr)))
1759 (not (equal (eval (nth 2 expr))
1760 (symbol-value (nth 1 expr)))))
1761 (push (nth 1 expr) olist)))))))
1762 (kill-buffer (current-buffer)))
1763 (when (setq olist (nreverse olist))
1764 (insert ";----------------- Environment follows ------------------\n\n"))
1766 (if (boundp (car olist))
1768 (pp `(setq ,(car olist)
1769 ,(if (or (consp (setq sym (symbol-value (car olist))))
1771 (not (or (eq sym nil)
1773 (list 'quote (symbol-value (car olist)))
1774 (symbol-value (car olist))))
1776 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1777 (setq olist (cdr olist)))
1778 ;; Remove any control chars - they seem to cause trouble for some
1779 ;; mailers. (Byte-compiled output from the stuff above.)
1781 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1782 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1784 ;; Break MIME tags purposely.
1786 (while (re-search-forward mime-edit-tag-regexp nil t)
1787 (goto-char (1+ (match-beginning 0)))
1790 ;;; Treatment of rejected articles.
1793 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1794 "Re-mail the current message.
1795 This only makes sense if the current message is a bounce message that
1796 contains some mail you have written which has been bounced back to
1798 If FETCH, try to fetch the article that this is a reply to, if indeed
1801 (gnus-summary-select-article t)
1802 (set-buffer gnus-original-article-buffer)
1803 (gnus-setup-message 'compose-bounce
1804 (let* ((references (mail-fetch-field "references"))
1805 (parent (and references (gnus-parent-id references))))
1807 ;; If there are references, we fetch the article we answered to.
1809 (gnus-summary-refer-article parent)
1810 (gnus-summary-show-all-headers)))))
1814 (defun gnus-inews-group-method (group)
1816 ;; If the group doesn't exist, we assume
1817 ;; it's an archive group...
1818 ((and (null (gnus-get-info group))
1819 (eq (car (gnus-server-to-method gnus-message-archive-method))
1820 (car (gnus-server-to-method (gnus-group-method group)))))
1821 gnus-message-archive-method)
1823 ((gnus-info-method (gnus-get-info group))
1824 (gnus-info-method (gnus-get-info group)))
1826 (t (gnus-server-to-method (gnus-group-method group)))))
1828 ;; Do Gcc handling, which copied the message over to some group.
1829 (defun gnus-inews-do-gcc (&optional gcc)
1833 (message-narrow-to-headers)
1834 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1835 (coding-system-for-write 'raw-text)
1836 groups group method group-art
1837 mml-externalize-attachments)
1839 (message-remove-header "gcc")
1841 (setq groups (message-unquote-tokens
1842 (message-tokenize-header gcc " ,")))
1843 ;; Copy the article over to some group(s).
1844 (while (setq group (pop groups))
1845 (unless (gnus-check-server
1846 (setq method (gnus-inews-group-method group)))
1847 (error "Can't open server %s" (if (stringp method) method
1849 (unless (gnus-request-group group nil method)
1850 (gnus-request-create-group group method))
1851 (setq mml-externalize-attachments
1852 (if (stringp gnus-gcc-externalize-attachments)
1853 (string-match gnus-gcc-externalize-attachments group)
1854 gnus-gcc-externalize-attachments))
1856 (nnheader-set-temp-buffer " *acc*")
1857 (insert-buffer-substring message-encoding-buffer)
1858 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1859 (goto-char (point-min))
1860 (when (re-search-forward
1861 (concat "^" (regexp-quote mail-header-separator) "$")
1863 (replace-match "" t t ))
1864 (unless (setq group-art
1865 (gnus-request-accept-article group method t t))
1866 (gnus-message 1 "Couldn't store article in group %s: %s"
1867 group (gnus-status-message method))
1869 (when (and group-art
1870 ;; FIXME: Should gcc-mark-as-read work when
1871 ;; Gnus is not running?
1873 (or gnus-gcc-mark-as-read
1875 (boundp 'gnus-inews-mark-gcc-as-read)
1876 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1877 (gnus-group-mark-article-read group (cdr group-art)))
1878 (kill-buffer (current-buffer)))))))))
1880 (defun gnus-inews-insert-gcc ()
1881 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1884 (message-narrow-to-headers)
1885 (let* ((group gnus-outgoing-message-group)
1889 ((or (stringp group) (list group))
1894 (if (string-match " " gcc)
1895 (concat "\"" gcc "\"")
1897 (mapconcat (lambda (group)
1898 (if (string-match " " group)
1899 (concat "\"" group "\"")
1904 (defun gnus-inews-insert-archive-gcc (&optional group)
1905 "Insert the Gcc to say where the article is to be archived."
1906 (let* ((var gnus-message-archive-group)
1907 (group (or group gnus-newsgroup-name ""))
1909 (and gnus-newsgroup-name
1910 (not (equal gnus-newsgroup-name ""))
1911 (gnus-group-find-parameter
1912 gnus-newsgroup-name 'gcc-self)))
1916 ((null gnus-message-archive-method)
1920 ;; Just a single group.
1923 ;; We don't want this.
1925 ((and (listp var) (stringp (car var)))
1926 ;; A list of groups.
1930 (funcall var group))
1932 ;; An alist of regexps/functions/forms.
1937 ((stringp (caar var))
1939 (when (string-match (caar var) group)
1941 ((functionp (car var))
1943 (funcall (car var) group))
1945 (eval (car var)))))))
1946 (setq var (cdr var)))
1949 (when (or groups gcc-self-val)
1950 (when (stringp groups)
1951 (setq groups (list groups)))
1954 (message-narrow-to-headers)
1955 (goto-char (point-max))
1958 ;; Use the `gcc-self' param value instead.
1961 (if (stringp gcc-self-val)
1962 (if (string-match " " gcc-self-val)
1963 (concat "\"" gcc-self-val "\"")
1965 ;; In nndoc groups, we use the parent group name
1966 ;; instead of the current group.
1967 (let ((group (or (gnus-group-find-parameter
1968 gnus-newsgroup-name 'parent-group)
1970 (if (string-match " " group)
1971 (concat "\"" group "\"")
1973 (if (not (eq gcc-self-val 'none))
1975 (gnus-delete-line)))
1976 ;; Use the list of groups.
1977 (while (setq name (pop groups))
1978 (let ((str (if (string-match ":" name)
1980 (gnus-group-prefixed-name
1981 name gnus-message-archive-method))))
1982 (insert (if (string-match " " str)
1983 (concat "\"" str "\"")
1989 (defun gnus-mailing-list-followup-to ()
1990 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1991 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1992 (list-post (gnus-fetch-original-field "list-post")))
1993 (when (and list-post
1994 (string-match "mailto:\\([^>]+\\)" list-post))
1995 (setq list-post (match-string 1 list-post)))
2001 (defun gnus-configure-posting-styles (&optional group-name)
2002 "Configure posting styles according to `gnus-posting-styles'."
2003 (unless gnus-inhibit-posting-styles
2004 (let ((group (or group-name gnus-newsgroup-name ""))
2005 (styles gnus-posting-styles)
2006 style match attribute results
2008 ;; If the group has a posting-style parameter, add it at the end with a
2009 ;; regexp matching everything, to be sure it takes precedence over all
2011 (when gnus-newsgroup-name
2012 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2014 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2015 ;; Go through all styles and look for matches.
2016 (dolist (style styles)
2017 (setq match (pop style))
2018 (goto-char (point-min))
2021 ;; Regexp string match on the group name.
2022 (string-match match group))
2024 ;; Obsolete format of header match.
2025 (and (gnus-buffer-live-p gnus-article-copy)
2026 (with-current-buffer gnus-article-copy
2027 (let ((header (message-fetch-field (pop style))))
2029 (string-match (pop style) header))))))
2030 ((or (symbolp match)
2034 ;; Function to be called.
2037 ;; Variable to be checked.
2038 (symbol-value match))))
2041 ((eq (car match) 'header)
2042 ;; New format of header match.
2043 (and (gnus-buffer-live-p gnus-article-copy)
2044 (with-current-buffer gnus-article-copy
2045 (let ((header (message-fetch-field (nth 1 match))))
2047 (string-match (nth 2 match) header))))))
2049 ;; This is a form to be evaled.
2051 ;; We have a match, so we set the variables.
2052 (setq style (gnus-configure-posting-style style nil))
2053 (dolist (attribute style)
2054 (setq results (delq (assoc (car attribute) results) results))
2055 (push attribute results))))
2056 ;; Now we have all the styles, so we insert them.
2057 (setq name (assq 'name results)
2058 address (assq 'address results))
2059 (setq results (delq name (delq address results)))
2060 (gnus-make-local-hook 'message-setup-hook)
2061 (setq results (sort results (lambda (x y)
2062 (string-lessp (car x) (car y)))))
2063 (dolist (result results)
2064 (add-hook 'message-setup-hook
2066 ((eq 'eval (car result))
2068 ((eq 'body (car result))
2072 (insert ,(cdr result)))))
2073 ((eq 'signature (car result))
2074 (set (make-local-variable 'message-signature) nil)
2075 (set (make-local-variable 'message-signature-file) nil)
2076 (if (not (cdr result))
2080 (let ((message-signature ,(cdr result)))
2081 (when message-signature
2082 (message-insert-signature)))))))
2085 (if (symbolp (car result))
2086 (capitalize (symbol-name (car result)))
2090 (message-remove-header ,header)
2091 (let ((value ,(cdr result)))
2094 (insert ,header ": " value)
2096 (insert "\n")))))))))
2098 (when (or name address)
2099 (add-hook 'message-setup-hook
2101 (set (make-local-variable 'user-mail-address)
2102 ,(or (cdr address) user-mail-address))
2103 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2105 ,(or (cdr address) user-mail-address)))
2107 (message-remove-header "From")
2109 (insert "From: " (message-make-from) "\n"))))
2112 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2113 (defun gnus-configure-posting-style (style stack)
2114 "Parse one posting style STYLE and returns the value as an alist."
2115 (let (results element variable filep value v)
2116 (dolist (attribute style)
2117 (setq element (pop attribute)
2122 ((eq (car attribute) ':file)
2125 ((eq (car attribute) :value)
2129 ;; We get the value.
2134 ((or (symbolp value)
2136 (cond ((functionp value)
2139 (symbol-value value))))
2142 ;; Translate obsolescent value.
2144 ((eq element 'signature-file)
2145 (setq element 'signature
2147 ((eq element 'x-face-file)
2148 (setq element 'x-face
2150 ;; Get the contents of file elems.
2152 (setq v (with-temp-buffer
2153 (insert-file-contents v)
2154 (goto-char (point-max))
2158 (if (eq element 'import)
2160 (if (member v stack)
2161 (error "Circular import of \"%s\"" v))
2163 (nconc (nreverse (gnus-configure-posting-style
2164 (cdr (assoc v gnus-named-posting-styles))
2167 (push (cons element v) results)))
2168 (nreverse results)))
2170 (defun gnus-summary-execute-command-with-posting-style (style command)
2171 "Temporarily select a posting-style named STYLE and execute COMMAND."
2173 (let ((style (completing-read "Posting style: "
2174 gnus-named-posting-styles nil t)))
2178 (format "Command to execute with %s: " style))))))
2179 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2180 (call-interactively command)))
2183 ;;; @ for MIME Edit mode
2186 (defun gnus-maybe-setup-default-charset ()
2188 (and (boundp 'gnus-summary-buffer)
2189 (buffer-live-p gnus-summary-buffer)
2191 (set-buffer gnus-summary-buffer)
2192 default-mime-charset))))
2195 (make-local-variable 'default-mime-charset)
2196 (setq default-mime-charset charset)
2200 ;;; @ for MIME view mode
2203 (defun gnus-following-method (buf)
2204 (gnus-setup-message 'reply-yank
2206 (if (message-news-p)
2208 (message-reply nil 'wide))
2209 (let ((message-reply-buffer buf))
2210 (message-yank-original))
2211 (message-goto-body))
2215 ;;; Allow redefinition of functions.
2221 ;;; gnus-msg.el ends here