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 ;; 2005 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 (and gnus-novice-user
282 (not gnus-expert-user))
283 "If non-nil, Gnus requests confirmation when replying to news.
284 This is done because new users often reply by mistake when reading
286 This can also be a function receiving the group name as the only
287 parameter which should return non-nil iff a confirmation is needed, or
288 a regexp, in which case a confirmation is asked for iff the group name
292 :type '(choice (const :tag "No" nil)
294 (regexp :tag "Iff group matches regexp")
295 (function :tag "Iff function evaluates to non-nil")))
297 (defcustom gnus-confirm-treat-mail-like-news
299 "If non-nil, Gnus will treat mail like news with regard to confirmation
300 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
301 for fine-tuning this.
302 If nil, Gnus will never ask for confirmation if replying to mail."
307 (defcustom gnus-summary-resend-default-address t
308 "If non-nil, Gnus tries to suggest a default address to resend to.
309 If nil, the address field will always be empty after invoking
310 `gnus-summary-resend-message'."
315 ;;; Internal variables.
317 (defvar gnus-inhibit-posting-styles nil
318 "Inhibit the use of posting styles.")
320 (defvar gnus-article-yanked-articles nil)
321 (defvar gnus-message-buffer "*Mail Gnus*")
322 (defvar gnus-article-copy nil)
323 (defvar gnus-check-before-posting nil)
324 (defvar gnus-last-posting-server nil)
325 (defvar gnus-message-group-art nil)
327 (defvar gnus-msg-force-broken-reply-to nil)
329 (defconst gnus-bug-message
330 (format "Sending a bug report to the Gnus Towers.
331 ========================================
333 This gnus is the %s%s.
334 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
335 Developers. (the addresses below are mailing list addresses)
337 ========================================
339 The buffer below is a mail buffer. When you press `C-c C-c', it will
340 be sent to the Gnus Bug Exterminators.
342 The thing near the bottom of the buffer is how the environment
343 settings will be included in the mail. Please do not delete that.
344 They will tell the Bug People what your environment is, so that it
345 will be easier to locate the bugs.
347 If you have found a bug that makes Emacs go \"beep\", set
348 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
349 and include the backtrace in your bug report.
351 Please describe the bug in annoying, painstaking detail.
353 Thank you for your help in stamping out bugs.
356 (if (string= gnus-product-name "Semi-gnus")
358 ", a modified version of Semi-gnus")))
361 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
365 ;;; Gnus Posting Functions
368 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
369 "p" gnus-summary-post-news
370 "i" gnus-summary-news-other-window
371 "f" gnus-summary-followup
372 "F" gnus-summary-followup-with-original
373 "c" gnus-summary-cancel-article
374 "s" gnus-summary-supersede-article
375 "r" gnus-summary-reply
376 "y" gnus-summary-yank-message
377 "R" gnus-summary-reply-with-original
378 "w" gnus-summary-wide-reply
379 "W" gnus-summary-wide-reply-with-original
380 "v" gnus-summary-very-wide-reply
381 "V" gnus-summary-very-wide-reply-with-original
382 "n" gnus-summary-followup-to-mail
383 "N" gnus-summary-followup-to-mail-with-original
384 "m" gnus-summary-mail-other-window
385 "u" gnus-uu-post-news
386 "\M-c" gnus-summary-mail-crosspost-complaint
387 "Br" gnus-summary-reply-broken-reply-to
388 "BR" gnus-summary-reply-broken-reply-to-with-original
389 "om" gnus-summary-mail-forward
390 "op" gnus-summary-post-forward
391 "Om" gnus-summary-digest-mail-forward
392 "Op" gnus-summary-digest-post-forward
393 "P" gnus-summary-execute-command-with-posting-style)
395 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
396 "b" gnus-summary-resend-bounced-mail
397 ;; "c" gnus-summary-send-draft
398 "r" gnus-summary-resend-message
399 "e" gnus-summary-resend-message-edit)
401 ;;; Internal functions.
403 (defun gnus-inews-make-draft (articles)
405 (gnus-inews-make-draft-meta-information
406 ,gnus-newsgroup-name ',articles)))
408 (defvar gnus-article-reply nil)
409 (defmacro gnus-setup-message (config &rest forms)
410 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
411 (buffer (make-symbol "gnus-setup-message-buffer"))
412 (article (make-symbol "gnus-setup-message-article"))
413 (yanked (make-symbol "gnus-setup-yanked-articles"))
414 (group (make-symbol "gnus-setup-message-group")))
415 `(let ((,winconf (current-window-configuration))
416 (,buffer (buffer-name (current-buffer)))
417 (,article gnus-article-reply)
418 (,yanked gnus-article-yanked-articles)
419 (,group gnus-newsgroup-name)
420 (message-header-setup-hook
421 (copy-sequence message-header-setup-hook))
422 (message-mode-hook (copy-sequence message-mode-hook))
423 (message-startup-parameter-alist
424 '((reply-buffer . gnus-copy-article-buffer)
425 (original-buffer . gnus-original-article-buffer)
426 (user-agent . Gnus))))
427 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
428 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
429 ;; #### FIXME: for a reason that I did not manage to identify yet,
430 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
431 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
432 ;; After evaluation of @forms below, it gets the value we actually want
433 ;; to override, and the posting styles are used. For that reason, I've
434 ;; added an optional argument to `gnus-configure-posting-styles' to
435 ;; make sure that the correct value for the group name is used. -- drv
436 (add-hook 'message-mode-hook
437 (if (memq ,config '(reply-yank reply))
439 (gnus-configure-posting-styles ,group))
441 ;; There may be an old " *gnus article copy*" buffer.
442 (let (gnus-article-copy)
443 (gnus-configure-posting-styles ,group)))))
444 (gnus-pull ',(intern gnus-draft-meta-information-header)
445 message-required-headers)
447 (not (string= ,group "")))
449 (intern gnus-draft-meta-information-header)
450 (gnus-inews-make-draft (or ,yanked ,article)))
451 message-required-headers))
455 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
457 (setq gnus-message-buffer (current-buffer))
458 (set (make-local-variable 'gnus-message-group-art)
459 (cons ,group ,article))
460 (set (make-local-variable 'gnus-newsgroup-name) ,group)
461 (gnus-maybe-setup-default-charset)
462 (gnus-run-hooks 'gnus-message-setup-hook))
463 (message-hide-headers)
465 (gnus-configure-windows ,config t)
466 (run-hooks 'post-command-hook)
467 (set-buffer-modified-p nil))))
469 (defun gnus-inews-make-draft-meta-information (group articles)
470 (when (numberp articles)
471 (setq articles (list articles)))
472 (concat "(\"" group "\""
486 (defun gnus-msg-mail (&optional to subject other-headers continue
487 switch-action yank-action send-actions)
488 "Start editing a mail message to be sent.
489 Like `message-mail', but with Gnus paraphernalia, particularly the
490 Gcc: header for archiving purposes."
492 (let ((buf (current-buffer))
494 (gnus-setup-message 'message
495 (message-mail to subject other-headers continue
496 nil yank-action send-actions))
498 (setq mail-buf (current-buffer))
499 (switch-to-buffer buf)
500 (apply switch-action mail-buf nil)))
501 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
504 (defvar save-selected-window-window)
507 (defun gnus-button-mailto (address)
509 (set-buffer (gnus-copy-article-buffer))
510 (gnus-setup-message 'message
511 (message-reply address))
512 (and (boundp 'save-selected-window-window)
513 (not (window-live-p save-selected-window-window))
514 (setq save-selected-window-window (selected-window))))
517 (defun gnus-button-reply (&optional to-address wide)
518 "Like `message-reply'."
520 (gnus-setup-message 'message
521 (message-reply to-address wide))
522 (and (boundp 'save-selected-window-window)
523 (not (window-live-p save-selected-window-window))
524 (setq save-selected-window-window (selected-window))))
527 (define-mail-user-agent 'gnus-user-agent
528 'gnus-msg-mail 'message-send-and-exit
529 'message-kill-buffer 'message-send-hook)
531 (defun gnus-setup-posting-charset (group)
532 (let ((alist gnus-group-posting-charset-alist)
533 (group (or group ""))
537 (while (setq elem (pop alist))
538 (when (or (and (stringp (car elem))
539 (string-match (car elem) group))
540 (and (functionp (car elem))
541 (funcall (car elem) group))
542 (and (symbolp (car elem))
543 (symbol-value (car elem))))
544 (throw 'found (cons (cadr elem) (caddr elem)))))))))
546 (defun gnus-inews-add-send-actions (winconf buffer article
547 &optional config yanked)
548 (gnus-make-local-hook 'message-sent-hook)
549 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
550 'gnus-inews-do-gcc) nil t)
552 (gnus-make-local-hook 'message-header-hook)
553 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
554 (setq message-post-method
556 (gnus-post-method arg ,gnus-newsgroup-name)))
557 (setq message-user-agent (gnus-message-make-user-agent))
558 (unless message-use-multi-frames
560 `(if (gnus-buffer-exists-p ,buffer)
561 (set-window-configuration ,winconf))
562 'exit 'postpone 'kill))
563 (let ((to-be-marked (cond
566 (lambda (x) (if (listp x) (car x) x)) yanked))
567 (article (if (listp article) article (list article)))
570 `(when (gnus-buffer-exists-p ,buffer)
574 (if (eq config 'forward)
575 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
576 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
579 (put 'gnus-setup-message 'lisp-indent-function 1)
580 (put 'gnus-setup-message 'edebug-form-spec '(form body))
582 ;;; Post news commands of Gnus group mode and summary mode
584 (defun gnus-group-mail (&optional arg)
585 "Start composing a mail.
586 If ARG, use the group under the point to find a posting style.
587 If ARG is 1, prompt for a group name to find the posting style."
589 ;; We can't `let' gnus-newsgroup-name here, since that leads
590 ;; to local variables leaking.
591 (let ((group gnus-newsgroup-name)
592 ;; make sure last viewed article doesn't affect posting styles:
594 (buffer (current-buffer)))
597 (setq gnus-newsgroup-name
599 (if (= 1 (prefix-numeric-value arg))
600 (completing-read "Use posting style of group: "
601 gnus-active-hashtb nil
602 (gnus-read-active-file-p))
603 (gnus-group-group-name))
605 ;; #### see comment in gnus-setup-message -- drv
606 (gnus-setup-message 'message (message-mail)))
609 (setq gnus-newsgroup-name group)))))
611 (defun gnus-group-news (&optional arg)
612 "Start composing a news.
613 If ARG, post to group under point.
614 If ARG is 1, prompt for group name to post to.
616 This function prepares a news even when using mail groups. This is useful
617 for posting messages to mail groups without actually sending them over the
618 network. The corresponding back end must have a 'request-post method."
620 ;; We can't `let' gnus-newsgroup-name here, since that leads
621 ;; to local variables leaking.
622 (let ((group gnus-newsgroup-name)
623 ;; make sure last viewed article doesn't affect posting styles:
625 (buffer (current-buffer)))
628 (setq gnus-newsgroup-name
630 (if (= 1 (prefix-numeric-value arg))
631 (completing-read "Use group: "
632 gnus-active-hashtb nil
633 (gnus-read-active-file-p))
634 (gnus-group-group-name))
636 ;; #### see comment in gnus-setup-message -- drv
637 (gnus-setup-message 'message
638 (message-news (gnus-group-real-name gnus-newsgroup-name))))
641 (setq gnus-newsgroup-name group)))))
643 (defun gnus-group-post-news (&optional arg)
644 "Start composing a message (a news by default).
645 If ARG, post to group under point. If ARG is 1, prompt for group name.
646 Depending on the selected group, the message might be either a mail or
649 ;; Bind this variable here to make message mode hooks work ok.
650 (let ((gnus-newsgroup-name
652 (if (= 1 (prefix-numeric-value arg))
653 (completing-read "Newsgroup: " gnus-active-hashtb nil
654 (gnus-read-active-file-p))
655 (gnus-group-group-name))
657 ;; make sure last viewed article doesn't affect posting styles:
659 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
660 (string= gnus-newsgroup-name ""))))
662 (defun gnus-summary-mail-other-window (&optional arg)
663 "Start composing a mail in another window.
664 Use the posting of the current group by default.
665 If ARG, don't do that. If ARG is 1, prompt for group name to find the
668 ;; We can't `let' gnus-newsgroup-name here, since that leads
669 ;; to local variables leaking.
670 (let ((group gnus-newsgroup-name)
671 ;; make sure last viewed article doesn't affect posting styles:
673 (buffer (current-buffer)))
676 (setq gnus-newsgroup-name
678 (if (= 1 (prefix-numeric-value arg))
679 (completing-read "Use group: "
680 gnus-active-hashtb nil
681 (gnus-read-active-file-p))
683 gnus-newsgroup-name))
684 ;; #### see comment in gnus-setup-message -- drv
685 (gnus-setup-message 'message (message-mail)))
688 (setq gnus-newsgroup-name group)))))
690 (defun gnus-summary-news-other-window (&optional arg)
691 "Start composing a news in another window.
692 Post to the current group by default.
693 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
695 This function prepares a news even when using mail groups. This is useful
696 for posting messages to mail groups without actually sending them over the
697 network. The corresponding back end must have a 'request-post method."
699 ;; We can't `let' gnus-newsgroup-name here, since that leads
700 ;; to local variables leaking.
701 (let ((group gnus-newsgroup-name)
702 ;; make sure last viewed article doesn't affect posting styles:
704 (buffer (current-buffer)))
707 (setq gnus-newsgroup-name
709 (if (= 1 (prefix-numeric-value arg))
710 (completing-read "Use group: "
711 gnus-active-hashtb nil
712 (gnus-read-active-file-p))
714 gnus-newsgroup-name))
715 ;; #### see comment in gnus-setup-message -- drv
716 (gnus-setup-message 'message
718 (message-news (gnus-group-real-name gnus-newsgroup-name))
719 (set (make-local-variable 'gnus-discouraged-post-methods)
721 (car (gnus-find-method-for-group gnus-newsgroup-name))
722 gnus-discouraged-post-methods)))))
725 (setq gnus-newsgroup-name group)))))
727 (defun gnus-summary-post-news (&optional arg)
728 "Start composing a message. Post to the current group by default.
729 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
730 Depending on the selected group, the message might be either a mail or
733 ;; Bind this variable here to make message mode hooks work ok.
734 (let ((gnus-newsgroup-name
736 (if (= 1 (prefix-numeric-value arg))
737 (completing-read "Newsgroup: " gnus-active-hashtb nil
738 (gnus-read-active-file-p))
740 gnus-newsgroup-name))
741 ;; make sure last viewed article doesn't affect posting styles:
743 (gnus-post-news 'post gnus-newsgroup-name)))
746 (defun gnus-summary-followup (yank &optional force-news)
747 "Compose a followup to an article.
748 If prefix argument YANK is non-nil, the original article is yanked
750 YANK is a list of elements, where the car of each element is the
751 article number, and the cdr is the string to be yanked."
753 (list (and current-prefix-arg
754 (gnus-summary-work-articles 1))))
756 (gnus-summary-goto-subject
757 (if (listp (car yank))
760 (save-window-excursion
761 (gnus-summary-select-article))
762 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
763 (gnus-newsgroup-name gnus-newsgroup-name))
765 (gnus-post-news nil gnus-newsgroup-name
766 headers gnus-article-buffer
768 (gnus-summary-handle-replysign)))
770 (defun gnus-summary-followup-with-original (n &optional force-news)
771 "Compose a followup to an article and include the original article.
772 The text in the region will be yanked. If the region isn't
773 active, the entire article will be yanked."
775 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
777 (defun gnus-summary-followup-to-mail (&optional arg)
778 "Followup to the current mail message via news."
780 (list (and current-prefix-arg
781 (gnus-summary-work-articles 1))))
782 (gnus-summary-followup arg t))
784 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
785 "Followup to the current mail message via news."
787 (gnus-summary-followup (gnus-summary-work-articles arg) t))
789 (defun gnus-inews-yank-articles (articles)
790 (let (beg article yank-string
791 (more-than-one (cdr articles))
792 (cur (current-buffer))
795 (while (setq article (pop articles))
796 (when (listp article)
797 (setq yank-string (nth 1 article)
798 article (nth 0 article)))
799 (save-window-excursion
800 (set-buffer gnus-summary-buffer)
801 (gnus-summary-select-article nil nil nil article)
802 (gnus-summary-remove-process-mark article))
804 ;; Gathering references.
806 (setq refs (message-list-references
808 (mail-header-references gnus-current-headers)
809 (mail-header-message-id gnus-current-headers)))
810 (when message-use-multi-frames
811 (when (setq window (get-buffer-window cur t))
812 (select-frame (window-frame window)))))
814 (gnus-copy-article-buffer nil yank-string)
815 (let ((message-reply-buffer gnus-article-copy)
816 (message-reply-headers
817 ;; The headers are decoded.
818 (with-current-buffer gnus-article-copy
820 (nnheader-narrow-to-headers)
821 (nnheader-parse-naked-head)))))
822 (message-yank-original)
823 (setq beg (or beg (mark t))))
828 ;; Replace with the gathered references.
832 (message-narrow-to-headers)
833 (let ((case-fold-search t))
834 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
836 (goto-char (point-max))))
838 (list (or (assq 'References message-header-format-alist)
839 '(References . message-shorten-references)))
840 (list (cons 'References
841 (mapconcat 'identity (nreverse refs) " ")))))
847 (defun gnus-summary-cancel-article (&optional n symp)
848 "Cancel an article you posted.
849 Uses the process-prefix convention. If given the symbolic
850 prefix `a', cancel using the standard posting method; if not
851 post using the current select method."
852 (interactive (gnus-interactive "P\ny"))
853 (let ((message-post-method
855 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
856 (dolist (article (gnus-summary-work-articles n))
857 (when (gnus-summary-select-article t nil nil article)
858 (when (gnus-eval-in-buffer-window gnus-article-buffer
860 (set-buffer gnus-original-article-buffer)
861 (message-cancel-news)))
862 (gnus-summary-mark-as-read article gnus-canceled-mark)
863 (gnus-cache-remove-article 1))
864 (gnus-article-hide-headers-if-wanted))
865 (gnus-summary-remove-process-mark article))))
867 (defun gnus-summary-supersede-article ()
868 "Compose an article that will supersede a previous article.
869 This is done simply by taking the old article and adding a Supersedes
870 header line with the old Message-ID."
872 (let ((article (gnus-summary-article-number)))
873 (gnus-setup-message 'reply-yank
874 (gnus-summary-select-article t)
875 (set-buffer gnus-original-article-buffer)
879 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
881 (set-buffer ,gnus-summary-buffer)
882 (gnus-cache-possibly-remove-article ,article nil nil nil t)
883 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
884 message-send-actions))))
888 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
889 ;; make a copy of the article buffer with all text properties removed
890 ;; this copy is in the buffer gnus-article-copy.
891 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
892 ;; this buffer should be passed to all mail/news reply/post routines.
893 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
895 (set-buffer gnus-article-copy)
896 (set-buffer-multibyte t))
897 (let ((article-buffer (or article-buffer gnus-article-buffer))
899 (if (not (and (get-buffer article-buffer)
900 (gnus-buffer-exists-p article-buffer)))
901 (error "Can't find any article buffer")
903 (set-buffer article-buffer)
904 (let ((gnus-newsgroup-charset (or gnus-article-charset
905 gnus-newsgroup-charset))
906 (gnus-newsgroup-ignored-charsets
907 (or gnus-article-ignored-charsets
908 gnus-newsgroup-ignored-charsets)))
910 ;; Copy over the (displayed) article buffer, delete
911 ;; hidden text and remove text properties.
913 (copy-to-buffer gnus-article-copy (point-min) (point-max))
914 (set-buffer gnus-article-copy)
915 ;; There's invisible and intangible text in T-gnus. Especially,
916 ;; if there is a boundary line (X-Boundary: ------------------),
917 ;; in the end of a header, it will cause a serious problem.
918 (add-text-properties (point-min) (point-max)
919 '(invisible nil intangible nil))
922 (delete-region (point) (point-max))
923 (insert yank-string))
924 ;; Encode bitmap smileys to ordinary text.
925 ;; Possibly, the original text might be restored.
926 (static-unless (featurep 'xemacs)
927 (when (featurep 'smiley-mule)
928 (smiley-encode-buffer)))
929 (gnus-article-delete-text-of-type 'annotation)
930 (gnus-remove-text-with-property 'gnus-prev)
931 (gnus-remove-text-with-property 'gnus-next)
932 (gnus-remove-text-with-property 'gnus-decoration)
933 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
936 (static-if (featurep 'xemacs)
937 ;; Revome smiley extents for (possibly) XEmacs 21.1.
939 (buffer-substring-no-properties (point-min)
941 (buffer-substring-no-properties (point-min) (point-max)))
943 ;; Find the original headers.
944 (set-buffer gnus-original-article-buffer)
945 (goto-char (point-min))
946 (while (looking-at message-unix-mail-delimiter)
948 (let ((mail-header-separator ""))
950 end (or (message-goto-body)
951 ;; There may be just a header.
953 ;; Delete the headers from the displayed articles.
954 (set-buffer gnus-article-copy)
955 (let ((mail-header-separator ""))
956 (delete-region (goto-char (point-min))
957 (or (message-goto-body) (point-max))))
958 ;; Insert the original article headers.
959 (insert-buffer-substring gnus-original-article-buffer beg end)
961 (let ((gnus-article-decode-hook
962 (delq 'article-decode-charset
963 (copy-sequence gnus-article-decode-hook))))
964 ;; Needed for T-gnus.
965 (add-hook 'gnus-article-decode-hook
966 'article-decode-encoded-words)
967 (run-hooks 'gnus-article-decode-hook)))))
970 (defun gnus-post-news (post &optional group header article-buffer yank subject
973 (gnus-copy-article-buffer))
974 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
975 (gnus-article-yanked-articles yank)
976 (add-to-list gnus-add-to-list))
977 (gnus-setup-message (cond (yank 'reply-yank)
978 (article-buffer 'reply)
980 (let* ((group (or group gnus-newsgroup-name))
981 (charset (gnus-group-name-charset nil group))
983 to-address to-group mailing-list to-list
986 (setq to-address (gnus-parameter-to-address group)
987 to-group (gnus-group-find-parameter group 'to-group)
988 to-list (gnus-parameter-to-list group)
989 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
990 mailing-list (when gnus-mailing-list-groups
991 (string-match gnus-mailing-list-groups group))
992 group (gnus-group-name-decode (gnus-group-real-name group)
994 (if (or (and to-group
995 (gnus-news-group-p to-group))
998 (and (gnus-news-group-p
999 (or pgroup gnus-newsgroup-name)
1000 (or header gnus-current-article))
1008 (and (not (gnus-virtual-group-p pgroup)) group)))
1009 (set-buffer gnus-article-copy)
1010 (gnus-msg-treat-broken-reply-to)
1011 (message-followup (if (or newsgroup-p force-news)
1012 (if (save-restriction
1013 (article-narrow-to-head)
1014 (message-fetch-field "newsgroups"))
1021 (message-mail (or to-address to-list))
1022 ;; Arrange for mail groups that have no `to-address' to
1023 ;; get that when the user sends off the mail.
1024 (when (and (not to-list)
1027 (push (list 'gnus-inews-add-to-address pgroup)
1028 message-send-actions)))
1029 (set-buffer gnus-article-copy)
1030 (gnus-msg-treat-broken-reply-to)
1031 (message-wide-reply to-address)))
1033 (gnus-inews-yank-articles yank))))))
1035 (defun gnus-msg-treat-broken-reply-to (&optional force)
1036 "Remove the Reply-to header if broken-reply-to."
1038 (gnus-group-find-parameter
1039 gnus-newsgroup-name 'broken-reply-to))
1041 (message-narrow-to-head)
1042 (message-remove-header "reply-to"))))
1044 (defun gnus-post-method (arg group &optional silent)
1045 "Return the posting method based on GROUP and ARG.
1046 If SILENT, don't prompt the user."
1047 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1049 (group-method (gnus-find-method-for-group group)))
1051 ;; If the group-method is nil (which shouldn't happen) we use
1052 ;; the default method.
1053 ((null group-method)
1054 (or (and (listp gnus-post-method) ;If not current/native/nil
1055 (not (listp (car gnus-post-method))) ; and not a list of methods
1056 gnus-post-method) ;then use it.
1058 message-post-method))
1059 ;; We want the inverse of the default
1060 ((and arg (not (eq arg 0)))
1061 (if (eq gnus-post-method 'current)
1064 ;; We query the user for a post method.
1066 (and (listp gnus-post-method)
1067 (listp (car gnus-post-method))))
1069 ;; Collect all methods we know about.
1071 (when (listp gnus-post-method)
1072 (if (listp (car gnus-post-method))
1074 (list gnus-post-method)))
1075 gnus-secondary-select-methods
1076 (mapcar 'cdr gnus-server-alist)
1077 (mapcar 'car gnus-opened-servers)
1078 (list gnus-select-method)
1079 (list group-method)))
1080 method-alist post-methods method)
1081 ;; Weed out all mail methods.
1083 (setq method (gnus-server-get-method "" (pop methods)))
1084 (when (and (or (gnus-method-option-p method 'post)
1085 (gnus-method-option-p method 'post-mail))
1086 (not (member method post-methods)))
1087 (push method post-methods)))
1088 ;; Create a name-method alist.
1092 (if (equal (cadr m) "")
1093 (list (symbol-name (car m)) m)
1094 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1099 (setq gnus-last-posting-server
1101 gnus-last-posting-server)
1102 ;; Just use the last value.
1103 gnus-last-posting-server
1105 "Posting method: " method-alist nil t
1106 (cons (or gnus-last-posting-server "") 0))))
1108 ;; Override normal method.
1109 ((and (eq gnus-post-method 'current)
1110 (not (memq (car group-method) gnus-discouraged-post-methods))
1111 (gnus-get-function group-method 'request-post t))
1114 ;; Use gnus-post-method.
1115 ((listp gnus-post-method) ;A method...
1116 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1118 ;; Use the normal select method (nil or native).
1119 (t gnus-select-method))))
1122 (defun gnus-message-make-user-agent (&optional dummy max-column
1124 "Return a user-agent info. If MAX-COLUMN is specified, the return
1125 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1126 whether a newline should be inserted in front of each product-token;
1127 if the value is t or `hard', it works strictly. Otherwise, if it is
1128 non-nil (e.g. `soft'), it works semi-strictly."
1129 (let ((user-agent (gnus-extended-version)))
1131 (unless (natnump max-column)
1132 (setq max-column 76))
1134 (set-buffer-multibyte t)
1135 (insert (mapconcat 'identity (split-string user-agent) " "))
1136 (goto-char (point-min))
1138 start agent agents width element swidth)
1139 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1140 (setq start (match-beginning 0))
1141 (if (eq (char-after start) ?\()
1145 (push (buffer-substring start (point)) agent))
1147 (push (nreverse agent) agents))
1148 (setq agent (list (match-string 1)))))
1150 (push (nreverse agent) agents))
1151 (setq agents (nreverse agents))
1152 (if (> (+ 12 (string-width (caar agents))) max-column)
1153 (setq user-agent "\n"
1158 (setq agent (car agents)
1159 agents (cdr agents))
1160 (when (and (not bol)
1161 (or (memq newline-product '(t hard))
1162 (and newline-product
1164 (string-width (mapconcat 'identity
1167 (setq user-agent (concat user-agent "\n")
1171 (setq element (car agent)
1172 swidth (string-width element)
1175 (setq user-agent (if (member user-agent '("" "\n"))
1176 (concat user-agent element)
1177 (concat user-agent " " element))
1178 width (+ width 1 swidth)
1180 (if (> (+ width 1 swidth) max-column)
1181 (setq user-agent (concat user-agent "\n " element)
1183 (setq user-agent (concat user-agent " " element)
1184 width (+ width 1 swidth)))))))))
1189 ;;; Gnus Mail Functions
1192 ;;; Mail reply commands of Gnus summary mode
1194 (defun gnus-summary-reply (&optional yank wide very-wide)
1195 "Start composing a mail reply to the current message.
1196 If prefix argument YANK is non-nil, the original article is yanked
1198 If WIDE, make a wide reply.
1199 If VERY-WIDE, make a very wide reply."
1201 (list (and current-prefix-arg
1202 (gnus-summary-work-articles 1))))
1203 ;; Allow user to require confirmation before replying by mail to the
1204 ;; author of a news article (or mail message).
1206 (not (or (gnus-news-group-p gnus-newsgroup-name)
1207 gnus-confirm-treat-mail-like-news))
1208 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1209 (string-match gnus-confirm-mail-reply-to-news
1210 gnus-newsgroup-name))
1211 ((functionp gnus-confirm-mail-reply-to-news)
1212 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1213 (t gnus-confirm-mail-reply-to-news)))
1214 (y-or-n-p "Really reply by mail to article author? "))
1216 (if (listp (car yank))
1219 (gnus-article-reply (or article (gnus-summary-article-number)))
1220 (gnus-article-yanked-articles yank)
1222 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1224 (gnus-summary-goto-subject article))
1225 (gnus-setup-message (if yank 'reply-yank 'reply)
1227 (gnus-summary-select-article)
1228 (dolist (article very-wide)
1229 (gnus-summary-select-article nil nil nil article)
1231 (set-buffer (gnus-copy-article-buffer))
1232 (gnus-msg-treat-broken-reply-to)
1234 (message-narrow-to-head)
1235 (setq headers (concat headers (buffer-string)))))))
1236 (set-buffer (gnus-copy-article-buffer))
1237 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1239 (message-narrow-to-head)
1243 (goto-char (point-max)))
1244 (message-reply nil wide)
1246 (gnus-inews-yank-articles yank))
1247 (gnus-summary-handle-replysign)))))
1249 (defun gnus-summary-handle-replysign ()
1250 "Check the various replysign variables and take action accordingly."
1251 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1252 (let (signed encrypted)
1254 (set-buffer gnus-article-buffer)
1255 (setq signed (memq 'signed gnus-article-wash-types))
1256 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1257 (cond ((and gnus-message-replyencrypt encrypted)
1258 (mml-secure-message mml-default-encrypt-method
1259 (if gnus-message-replysignencrypted
1262 ((and gnus-message-replysign signed)
1263 (mml-secure-message mml-default-sign-method 'sign))))))
1265 (defun gnus-summary-reply-with-original (n &optional wide)
1266 "Start composing a reply mail to the current message.
1267 The original article will be yanked."
1269 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1271 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1272 "Like `gnus-summary-reply' except removing reply-to field.
1273 If prefix argument YANK is non-nil, the original article is yanked
1275 If WIDE, make a wide reply.
1276 If VERY-WIDE, make a very wide reply."
1278 (list (and current-prefix-arg
1279 (gnus-summary-work-articles 1))))
1280 (let ((gnus-msg-force-broken-reply-to t))
1281 (gnus-summary-reply yank wide very-wide)))
1283 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1284 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1285 The original article will be yanked."
1287 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1289 (defun gnus-summary-wide-reply (&optional yank)
1290 "Start composing a wide reply mail to the current message.
1291 If prefix argument YANK is non-nil, the original article is yanked
1294 (list (and current-prefix-arg
1295 (gnus-summary-work-articles 1))))
1296 (gnus-summary-reply yank t))
1298 (defun gnus-summary-wide-reply-with-original (n)
1299 "Start composing a wide reply mail to the current message.
1300 The original article will be yanked.
1301 Uses the process/prefix convention."
1303 (gnus-summary-reply-with-original n t))
1305 (defun gnus-summary-very-wide-reply (&optional yank)
1306 "Start composing a very wide reply mail to the current message.
1307 If prefix argument YANK is non-nil, the original article is yanked
1310 (list (and current-prefix-arg
1311 (gnus-summary-work-articles 1))))
1312 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1314 (defun gnus-summary-very-wide-reply-with-original (n)
1315 "Start composing a very wide reply mail to the current message.
1316 The original article will be yanked."
1319 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1321 (defun gnus-summary-mail-forward (&optional full-headers post)
1322 "Forward the current message(s) to another user.
1323 If process marks exist, forward all marked messages;
1324 If FULL-HEADERS (the prefix), include full headers when forwarding.
1326 Note that this function definition for T-gnus is totally different
1327 from the original Gnus."
1329 (if (cdr (gnus-summary-work-articles nil))
1330 ;; Process marks are given.
1331 (gnus-summary-digest-mail-forward nil post)
1332 ;; No process marks.
1333 (let* ((gnus-article-reply (gnus-summary-article-number))
1334 (gnus-article-yanked-articles (list gnus-article-reply))
1336 (message-included-forward-headers
1337 (if full-headers "" message-included-forward-headers)))
1338 (gnus-setup-message 'forward
1339 (gnus-summary-select-article)
1340 (setq charset default-mime-charset)
1341 (set-buffer gnus-original-article-buffer)
1342 (make-local-variable 'default-mime-charset)
1343 (setq default-mime-charset charset)
1344 (message-forward post)))))
1346 (defun gnus-summary-digest-mail-forward (&optional n post)
1347 "Digests and forwards all articles in this series.
1348 If N is a positive number, forward the N next articles.
1349 If N is a negative number, forward the N previous articles.
1350 If N is nil and any articles have been marked with the process mark,
1351 forward those articles instead.
1352 Optional POST will use news to forward instead of mail."
1354 (let* ((articles (gnus-summary-work-articles n))
1355 (gnus-article-yanked-articles (copy-sequence articles))
1356 (topics "Topics:\n")
1357 subject article frame)
1358 (when (car articles)
1359 (gnus-setup-message 'forward
1360 (gnus-summary-select-article)
1362 (setq articles (sort articles '<)
1363 subject "Digested Articles")
1364 (with-current-buffer gnus-original-article-buffer
1365 (setq subject (message-make-forward-subject))))
1367 (message-news nil subject)
1368 (message-mail nil subject))
1369 (when (and message-use-multi-frames (cdr articles))
1370 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1372 (while (setq article (pop articles))
1373 (save-window-excursion
1374 (set-buffer gnus-summary-buffer)
1375 (gnus-summary-select-article nil nil nil article)
1376 (setq topics (concat topics " "
1377 (mail-header-subject gnus-current-headers)
1379 (gnus-summary-remove-process-mark article))
1381 (select-frame frame))
1382 (insert (mime-make-tag "message" "rfc822") "\n")
1383 (narrow-to-region (point) (point))
1384 (insert-buffer-substring gnus-original-article-buffer)
1386 (article-narrow-to-head)
1387 (message-remove-header message-included-forward-headers t nil t))
1388 (goto-char (point-max))
1394 (mime-edit-enclose-digest-region (point)(mark t))))))
1396 (defun gnus-summary-digest-post-forward (&optional n)
1397 "Digest and forwards all articles in this series to a newsgroup.
1398 If N is a positive number, forward the N next articles.
1399 If N is a negative number, forward the N previous articles.
1400 If N is nil and any articles have been marked with the process mark,
1401 forward those articles instead."
1403 (gnus-summary-digest-mail-forward n t))
1405 (defun gnus-summary-resend-message (address n)
1406 "Resend the current article to ADDRESS."
1408 (list (message-read-from-minibuffer
1409 "Resend message(s) to: "
1410 (when (and gnus-summary-resend-default-address
1411 (gnus-buffer-live-p gnus-original-article-buffer))
1412 ;; If some other article is currently selected, the
1413 ;; initial-contents is wrong. Whatever, it is just the
1414 ;; initial-contents.
1415 (with-current-buffer gnus-original-article-buffer
1416 (nnmail-fetch-field "to"))))
1417 current-prefix-arg))
1418 (dolist (article (gnus-summary-work-articles n))
1419 (gnus-summary-select-article nil nil nil article)
1421 (set-buffer gnus-original-article-buffer)
1422 (message-resend address))
1423 (gnus-summary-mark-article-as-forwarded article)))
1425 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1426 (defun gnus-summary-resend-message-edit ()
1427 "Resend an article that has already been sent.
1428 A new buffer will be created to allow the user to modify body and
1429 contents of the message, and then, everything will happen as when
1430 composing a new message."
1432 (let ((article (gnus-summary-article-number)))
1433 (gnus-setup-message 'reply-yank
1434 (gnus-summary-select-article t)
1435 (set-buffer gnus-original-article-buffer)
1436 (let ((cur (current-buffer))
1437 (to (message-fetch-field "to")))
1438 ;; Get a normal message buffer.
1439 (message-pop-to-buffer (message-buffer-name "Resend" to))
1440 (insert-buffer-substring cur)
1442 ;; T-gnus change: Use MIME-Edit to recompose a message.
1444 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1445 (fset 'mime-edit-decode-single-part-in-buffer
1446 (lambda (&rest args)
1447 (if (let ((content-type (car args)))
1448 (and (eq 'message (mime-content-type-primary-type
1450 (eq 'rfc822 (mime-content-type-subtype
1452 (setcar (cdr args) 'not-decode-text))
1455 (mime-edit-again nil t)
1456 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1457 (message-narrow-to-head-1)
1458 (insert "From: " (message-make-from) "\n")
1459 (while (re-search-forward "^From:" nil t)
1461 (insert "Original-"))
1462 (message-remove-header "^>From[\t ]" t)
1464 ;; Gnus will generate a new one when sending.
1465 (message-remove-header "Message-ID")
1466 (message-remove-header message-ignored-resent-headers t)
1467 ;; Remove unwanted headers.
1468 (goto-char (point-max))
1469 (insert mail-header-separator)
1470 (goto-char (point-min))
1471 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1475 (defun gnus-summary-post-forward (&optional full-headers)
1476 "Forward the current article to a newsgroup.
1477 If FULL-HEADERS (the prefix), include full headers when forwarding."
1479 (gnus-summary-mail-forward full-headers t))
1481 (defvar gnus-nastygram-message
1482 "The following article was inappropriately posted to %s.\n\n"
1483 "Format string to insert in nastygrams.
1484 The current group name will be inserted at \"%s\".")
1486 (defun gnus-summary-mail-nastygram (n)
1487 "Send a nastygram to the author of the current article."
1489 (when (or gnus-expert-user
1491 "Really send a nastygram to the author of the current article? "))
1492 (let ((group gnus-newsgroup-name))
1493 (gnus-summary-reply-with-original n)
1494 (set-buffer gnus-message-buffer)
1496 (insert (format gnus-nastygram-message group))
1497 (message-send-and-exit))))
1499 (defun gnus-summary-mail-crosspost-complaint (n)
1500 "Send a complaint about crossposting to the current article(s)."
1502 (dolist (article (gnus-summary-work-articles n))
1503 (set-buffer gnus-summary-buffer)
1504 (gnus-summary-goto-subject article)
1505 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1506 newsgroups followup-to)
1507 (gnus-summary-select-article)
1508 (set-buffer gnus-original-article-buffer)
1509 (if (and (<= (length (message-tokenize-header
1511 (mail-fetch-field "newsgroups"))
1514 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1515 (not (member group (message-tokenize-header
1516 followup-to ", ")))))
1518 (gnus-message 1 "Followup-to restricted")
1519 (gnus-message 1 "Not a crossposted article"))
1520 (set-buffer gnus-summary-buffer)
1521 (gnus-summary-reply-with-original 1)
1522 (set-buffer gnus-message-buffer)
1524 (insert (format gnus-crosspost-complaint newsgroups group))
1525 (message-goto-subject)
1526 (re-search-forward " *$")
1527 (replace-match " (crosspost notification)" t t)
1528 (gnus-deactivate-mark)
1529 (when (gnus-y-or-n-p "Send this complaint? ")
1530 (message-send-and-exit))))))
1532 (defun gnus-mail-parse-comma-list ()
1535 (skip-chars-forward " ")
1538 (skip-chars-forward "^,")
1543 (narrow-to-region beg (point))
1546 (while (search-forward "\"" nil t)
1550 (skip-chars-forward ",")
1551 (skip-chars-forward "^,"))
1552 (skip-chars-backward " ")
1553 (push (buffer-substring beg (point))
1555 (skip-chars-forward "^,")
1556 (skip-chars-forward ", "))
1559 (defun gnus-inews-add-to-address (group)
1560 (let ((to-address (mail-fetch-field "to")))
1561 (when (and to-address
1563 ;; This mail group doesn't have a `to-list', so we add one
1565 (when (gnus-y-or-n-p
1566 (format "Do you want to add this as `to-list': %s? " to-address))
1567 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1569 (defun gnus-put-message ()
1570 "Put the current message in some group and return to Gnus."
1572 (let ((reply gnus-article-reply)
1573 (winconf gnus-prev-winconf)
1574 (group gnus-newsgroup-name))
1576 (not (gnus-group-read-only-p group)))
1577 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1579 (when (gnus-group-entry group)
1580 (error "No such group: %s" group))
1584 (message-narrow-to-headers)
1585 (let ((gnus-deletable-headers nil))
1586 (message-generate-headers
1587 (if (message-news-p)
1588 message-required-news-headers
1589 message-required-mail-headers)))
1590 (goto-char (point-max))
1591 (if (string-match " " group)
1592 (insert "Gcc: \"" group "\"\n")
1593 (insert "Gcc: " group "\n"))
1596 (when (and (get-buffer gnus-group-buffer)
1597 (gnus-buffer-exists-p (car-safe reply))
1599 (set-buffer (car reply))
1600 (gnus-summary-mark-article-as-replied (cdr reply)))
1602 (set-window-configuration winconf))))
1604 (defun gnus-article-mail (yank)
1605 "Send a reply to the address near point.
1606 If YANK is non-nil, include the original article."
1610 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1611 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1613 (gnus-msg-mail address)
1615 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1617 (defvar nntp-server-type)
1619 "Send a bug report to the Gnus maintainers."
1621 (unless (gnus-alive-p)
1622 (error "Gnus has been shut down"))
1623 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1624 (unless (message-mail-user-agent)
1625 (message-pop-to-buffer "*Gnus Bug*")
1626 (delete-other-windows)
1627 (when gnus-bug-create-help-buffer
1628 (switch-to-buffer "*Gnus Help Bug*")
1630 (insert gnus-bug-message)
1631 (goto-char (point-min))
1633 (set-buffer "*Gnus Bug*")))
1634 (let ((message-this-is-mail t))
1635 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1636 (when gnus-bug-create-help-buffer
1637 (push `(gnus-bug-kill-buffer) message-send-actions))
1638 (goto-char (point-min))
1639 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1641 (insert gnus-product-name " " gnus-version-number
1642 " (r" gnus-revision-number ") "
1643 "based on " gnus-original-product-name " v"
1644 gnus-original-version-number "\n"
1645 (emacs-version) "\n")
1646 (when (and (boundp 'nntp-server-type)
1647 (stringp nntp-server-type))
1648 (insert nntp-server-type))
1649 (insert "\n\n\n\n\n")
1650 (let (mime-content-types)
1651 (mime-edit-insert-tag
1652 "application" "emacs-lisp"
1653 "\nContent-Disposition: inline\nContent-Description: User settings"))
1654 (insert (with-temp-buffer
1657 (let (mime-content-types)
1658 (mime-edit-insert-tag "text" "plain"))
1659 (goto-char (point-min))
1660 (search-forward "Subject: " nil t)
1663 (defun gnus-bug-kill-buffer ()
1664 (when (get-buffer "*Gnus Help Bug*")
1665 (kill-buffer "*Gnus Help Bug*")))
1667 (defun gnus-summary-yank-message (buffer n)
1668 "Yank the current article into a composed message."
1670 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1671 current-prefix-arg))
1672 (when (gnus-buffer-live-p buffer)
1673 (let ((summary-frame (selected-frame))
1674 (message-frame (when (static-if (featurep 'xemacs)
1675 (device-on-window-system-p)
1677 (let ((window (get-buffer-window buffer t)))
1679 (window-frame window)))))
1680 (separator (concat "^" (regexp-quote mail-header-separator)
1682 (gnus-summary-iterate n
1683 (gnus-summary-select-article)
1684 (gnus-copy-article-buffer)
1685 (when (frame-live-p message-frame)
1686 (raise-frame message-frame)
1687 (select-frame message-frame))
1688 (with-current-buffer buffer
1689 (when (save-excursion
1691 (let (case-fold-search)
1692 (and (not (re-search-backward separator nil t))
1693 (re-search-forward separator nil t))))
1694 (goto-char (match-end 0)))
1695 (message-yank-buffer gnus-article-copy))
1696 (select-frame summary-frame))
1697 (when (frame-live-p message-frame)
1698 (select-frame message-frame)))))
1700 (defun gnus-debug ()
1701 "Attempts to go through the Gnus source file and report what variables have been changed.
1702 The source file has to be in the Emacs load path."
1704 (let ((files gnus-debug-files)
1706 file expr olist sym)
1707 (gnus-message 4 "Please wait while we snoop your variables...")
1708 ;; Go through all the files looking for non-default values for variables.
1711 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1714 (when (and (setq file (locate-library (pop files)))
1715 (file-exists-p file))
1716 (insert-file-contents file)
1717 (goto-char (point-min))
1718 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1719 (gnus-message 4 "Malformed sources in file %s" file)
1720 (narrow-to-region (point-min) (point))
1721 (goto-char (point-min))
1722 (while (setq expr (ignore-errors (read (current-buffer))))
1724 (and (memq (car expr) '(defvar defcustom defvoo))
1725 (stringp (nth 3 expr))
1726 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1727 (or (not (boundp (nth 1 expr)))
1728 (not (equal (eval (nth 2 expr))
1729 (symbol-value (nth 1 expr)))))
1730 (push (nth 1 expr) olist)))))))
1731 (kill-buffer (current-buffer)))
1732 (when (setq olist (nreverse olist))
1733 (insert ";----------------- Environment follows ------------------\n\n"))
1735 (if (boundp (car olist))
1739 ,(if (or (consp (setq sym (symbol-value (car olist))))
1741 (not (or (eq sym nil)
1743 (list 'quote (symbol-value (car olist)))
1744 (symbol-value (car olist))))))
1745 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1746 (setq olist (cdr olist)))
1747 ;; Remove any control chars - they seem to cause trouble for some
1748 ;; mailers. (Byte-compiled output from the stuff above.)
1750 (while (re-search-forward (string-as-multibyte
1751 "[\000-\010\013-\037\200-\237]") nil t)
1752 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1754 ;; Break MIME tags purposely.
1756 (while (re-search-forward mime-edit-tag-regexp nil t)
1757 (goto-char (1+ (match-beginning 0)))
1760 ;;; Treatment of rejected articles.
1763 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1764 "Re-mail the current message.
1765 This only makes sense if the current message is a bounce message that
1766 contains some mail you have written which has been bounced back to
1768 If FETCH, try to fetch the article that this is a reply to, if indeed
1771 (gnus-summary-select-article t)
1772 (set-buffer gnus-original-article-buffer)
1773 (gnus-setup-message 'compose-bounce
1774 (let* ((references (mail-fetch-field "references"))
1775 (parent (and references (gnus-parent-id references))))
1777 ;; If there are references, we fetch the article we answered to.
1779 (gnus-summary-refer-article parent)
1780 (gnus-summary-show-all-headers)))))
1784 (defun gnus-inews-group-method (group)
1786 ;; If the group doesn't exist, we assume
1787 ;; it's an archive group...
1788 ((and (null (gnus-get-info group))
1789 (eq (car (gnus-server-to-method gnus-message-archive-method))
1790 (car (gnus-server-to-method (gnus-group-method group)))))
1791 gnus-message-archive-method)
1793 ((gnus-info-method (gnus-get-info group))
1794 (gnus-info-method (gnus-get-info group)))
1796 (t (gnus-server-to-method (gnus-group-method group)))))
1798 ;; Do Gcc handling, which copied the message over to some group.
1799 (defun gnus-inews-do-gcc (&optional gcc)
1803 (message-narrow-to-headers)
1804 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1805 (coding-system-for-write 'raw-text)
1806 groups group method group-art
1807 mml-externalize-attachments)
1809 (message-remove-header "gcc")
1811 (setq groups (message-unquote-tokens
1812 (message-tokenize-header gcc " ,")))
1813 ;; Copy the article over to some group(s).
1814 (while (setq group (pop groups))
1815 (unless (gnus-check-server
1816 (setq method (gnus-inews-group-method group)))
1817 (error "Can't open server %s" (if (stringp method) method
1819 (unless (gnus-request-group group nil method)
1820 (gnus-request-create-group group method))
1821 (setq mml-externalize-attachments
1822 (if (stringp gnus-gcc-externalize-attachments)
1823 (string-match gnus-gcc-externalize-attachments group)
1824 gnus-gcc-externalize-attachments))
1826 (nnheader-set-temp-buffer " *acc*")
1827 (insert-buffer-substring message-encoding-buffer)
1828 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1829 (goto-char (point-min))
1830 (when (re-search-forward
1831 (concat "^" (regexp-quote mail-header-separator) "$")
1833 (replace-match "" t t ))
1834 (when (or (not (gnus-check-backend-function
1835 'request-accept-article group))
1836 (not (setq group-art
1837 (gnus-request-accept-article
1838 group method t t))))
1839 (gnus-message 1 "Couldn't store article in group %s: %s"
1840 group (gnus-status-message method)))
1841 (when (and group-art
1842 ;; FIXME: Should gcc-mark-as-read work when
1843 ;; Gnus is not running?
1845 (or gnus-gcc-mark-as-read
1847 (boundp 'gnus-inews-mark-gcc-as-read)
1848 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1849 (gnus-group-mark-article-read group (cdr group-art)))
1850 (kill-buffer (current-buffer)))))))))
1852 (defun gnus-inews-insert-gcc ()
1853 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1856 (message-narrow-to-headers)
1857 (let* ((group gnus-outgoing-message-group)
1861 ((or (stringp group) (list group))
1866 (if (string-match " " gcc)
1867 (concat "\"" gcc "\"")
1869 (mapconcat (lambda (group)
1870 (if (string-match " " group)
1871 (concat "\"" group "\"")
1876 (defun gnus-inews-insert-archive-gcc (&optional group)
1877 "Insert the Gcc to say where the article is to be archived."
1878 (let* ((var gnus-message-archive-group)
1879 (group (or group gnus-newsgroup-name ""))
1881 (and gnus-newsgroup-name
1882 (not (equal gnus-newsgroup-name ""))
1883 (gnus-group-find-parameter
1884 gnus-newsgroup-name 'gcc-self)))
1888 ((null gnus-message-archive-method)
1892 ;; Just a single group.
1895 ;; We don't want this.
1897 ((and (listp var) (stringp (car var)))
1898 ;; A list of groups.
1902 (funcall var group))
1904 ;; An alist of regexps/functions/forms.
1909 ((stringp (caar var))
1911 (when (string-match (caar var) group)
1913 ((functionp (car var))
1915 (funcall (car var) group))
1917 (eval (car var)))))))
1918 (setq var (cdr var)))
1921 (when (or groups gcc-self-val)
1922 (when (stringp groups)
1923 (setq groups (list groups)))
1926 (message-narrow-to-headers)
1927 (goto-char (point-max))
1930 ;; Use the `gcc-self' param value instead.
1933 (if (stringp gcc-self-val)
1934 (if (string-match " " gcc-self-val)
1935 (concat "\"" gcc-self-val "\"")
1937 ;; In nndoc groups, we use the parent group name
1938 ;; instead of the current group.
1939 (let ((group (or (gnus-group-find-parameter
1940 gnus-newsgroup-name 'parent-group)
1942 (if (string-match " " group)
1943 (concat "\"" group "\"")
1945 (if (not (eq gcc-self-val 'none))
1947 (gnus-delete-line)))
1948 ;; Use the list of groups.
1949 (while (setq name (pop groups))
1950 (let ((str (if (string-match ":" name)
1952 (gnus-group-prefixed-name
1953 name gnus-message-archive-method))))
1954 (insert (if (string-match " " str)
1955 (concat "\"" str "\"")
1961 (defun gnus-mailing-list-followup-to ()
1962 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1963 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1964 (list-post (gnus-fetch-original-field "list-post")))
1965 (when (and list-post
1966 (string-match "mailto:\\([^>]+\\)" list-post))
1967 (setq list-post (match-string 1 list-post)))
1973 (defun gnus-configure-posting-styles (&optional group-name)
1974 "Configure posting styles according to `gnus-posting-styles'."
1975 (unless gnus-inhibit-posting-styles
1976 (let ((group (or group-name gnus-newsgroup-name ""))
1977 (styles gnus-posting-styles)
1978 style match attribute results
1980 ;; If the group has a posting-style parameter, add it at the end with a
1981 ;; regexp matching everything, to be sure it takes precedence over all
1983 (when gnus-newsgroup-name
1984 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1986 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1987 ;; Go through all styles and look for matches.
1988 (dolist (style styles)
1989 (setq match (pop style))
1990 (goto-char (point-min))
1993 ;; Regexp string match on the group name.
1994 (string-match match group))
1996 ;; Obsolete format of header match.
1997 (and (gnus-buffer-live-p gnus-article-copy)
1998 (with-current-buffer gnus-article-copy
2000 (nnheader-narrow-to-headers)
2001 (let ((header (message-fetch-field (pop style))))
2003 (string-match (pop style) header)))))))
2004 ((or (symbolp match)
2008 ;; Function to be called.
2011 ;; Variable to be checked.
2012 (symbol-value match))))
2015 ((eq (car match) 'header)
2016 ;; New format of header match.
2017 (and (gnus-buffer-live-p gnus-article-copy)
2018 (with-current-buffer gnus-article-copy
2020 (nnheader-narrow-to-headers)
2021 (let ((header (message-fetch-field (nth 1 match))))
2023 (string-match (nth 2 match) header)))))))
2025 ;; This is a form to be evaled.
2027 ;; We have a match, so we set the variables.
2028 (setq style (gnus-configure-posting-style style nil))
2029 (dolist (attribute style)
2030 (setq results (delq (assoc (car attribute) results) results))
2031 (push attribute results))))
2032 ;; Now we have all the styles, so we insert them.
2033 (setq name (assq 'name results)
2034 address (assq 'address results))
2035 (setq results (delq name (delq address results)))
2036 (gnus-make-local-hook 'message-setup-hook)
2037 (setq results (sort results (lambda (x y)
2038 (string-lessp (car x) (car y)))))
2039 (dolist (result results)
2040 (add-hook 'message-setup-hook
2042 ((eq 'eval (car result))
2044 ((eq 'body (car result))
2048 (insert ,(cdr result)))))
2049 ((eq 'signature (car result))
2050 (set (make-local-variable 'message-signature) nil)
2051 (set (make-local-variable 'message-signature-file) nil)
2052 (if (not (cdr result))
2056 (let ((message-signature ,(cdr result)))
2057 (when message-signature
2058 (message-insert-signature)))))))
2061 (if (symbolp (car result))
2062 (capitalize (symbol-name (car result)))
2066 (message-remove-header ,header)
2067 (let ((value ,(cdr result)))
2070 (insert ,header ": " value)
2072 (insert "\n")))))))))
2074 (when (or name address)
2075 (add-hook 'message-setup-hook
2077 (set (make-local-variable 'user-mail-address)
2078 ,(or (cdr address) user-mail-address))
2079 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2081 ,(or (cdr address) user-mail-address)))
2083 (message-remove-header "From")
2085 (insert "From: " (message-make-from) "\n"))))
2088 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2089 (defun gnus-configure-posting-style (style stack)
2090 "Parse one posting style STYLE and returns the value as an alist."
2091 (let (results element variable filep value v)
2092 (dolist (attribute style)
2093 (setq element (pop attribute)
2098 ((eq (car attribute) ':file)
2101 ((eq (car attribute) :value)
2105 ;; We get the value.
2110 ((or (symbolp value)
2112 (cond ((functionp value)
2115 (symbol-value value))))
2118 ;; Translate obsolescent value.
2120 ((eq element 'signature-file)
2121 (setq element 'signature
2123 ((eq element 'x-face-file)
2124 (setq element 'x-face
2126 ;; Get the contents of file elems.
2128 (setq v (with-temp-buffer
2129 (insert-file-contents v)
2130 (buffer-substring (point-min)
2132 (goto-char (point-max))
2133 (if (zerop (skip-chars-backward "\n"))
2136 (if (eq element 'import)
2138 (if (member v stack)
2139 (error "Circular import of \"%s\"" v))
2141 (nconc (nreverse (gnus-configure-posting-style
2142 (cdr (assoc v gnus-named-posting-styles))
2145 (push (cons element v) results)))
2146 (nreverse results)))
2148 (defun gnus-summary-execute-command-with-posting-style (style command)
2149 "Temporarily select a posting-style named STYLE and execute COMMAND."
2151 (let ((style (completing-read "Posting style: "
2152 gnus-named-posting-styles nil t)))
2156 (format "Command to execute with %s: " style))))))
2157 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2158 (call-interactively command)))
2161 ;;; @ for MIME Edit mode
2164 (defun gnus-maybe-setup-default-charset ()
2166 (and (boundp 'gnus-summary-buffer)
2167 (buffer-live-p gnus-summary-buffer)
2169 (set-buffer gnus-summary-buffer)
2170 default-mime-charset))))
2173 (make-local-variable 'default-mime-charset)
2174 (setq default-mime-charset charset)
2178 ;;; @ for MIME view mode
2181 (defun gnus-following-method (buf)
2182 (gnus-setup-message 'reply-yank
2184 (if (message-news-p)
2186 (message-reply nil 'wide))
2187 (let ((message-reply-buffer buf))
2188 (message-yank-original))
2189 (message-goto-body))
2193 ;;; Allow redefinition of functions.
2199 ;;; gnus-msg.el ends here