1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
6 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 ;; Boston, MA 02110-1301, USA.
35 (eval-when-compile (require 'cl))
36 (eval-when-compile (require 'static))
44 (defcustom gnus-post-method 'current
45 "*Preferred method for posting USENET news.
47 If this variable is `current' (which is the default), Gnus will use
48 the \"current\" select method when posting. If it is `native', Gnus
49 will use the native select method when posting.
51 This method will not be used in mail groups and the like, only in
54 If not `native' nor `current', the value must be a valid method as discussed
55 in the documentation of `gnus-select-method'. It can also be a list of
56 methods. If that is the case, the user will be queried for what select
57 method to use when posting."
58 :group 'gnus-group-foreign
59 :link '(custom-manual "(gnus)Posting Server")
60 :type `(choice (const native)
62 (sexp :tag "Methods" ,gnus-select-method)))
64 (defcustom gnus-outgoing-message-group nil
65 "*All outgoing messages will be put in this group.
66 If you want to store all your outgoing mail and articles in the group
67 \"nnml:archive\", you set this variable to that value. This variable
68 can also be a list of group names.
70 If you want to have greater control over what group to put each
71 message in, you can set this variable to a function that checks the
72 current newsgroup name and then returns a suitable group name (or list
75 :type '(choice (const nil)
78 (repeat :tag "List of groups" (string :tag "Group"))))
80 (defcustom gnus-mailing-list-groups nil
81 "*If non-nil a regexp matching groups that are really mailing lists.
82 This is useful when you're reading a mailing list that has been
83 gatewayed to a newsgroup, and you want to followup to an article in
86 :type '(choice (regexp)
89 (defcustom gnus-add-to-list nil
90 "*If non-nil, add a `to-list' parameter automatically."
94 (defcustom gnus-crosspost-complaint
97 You posted the article below with the following Newsgroups header:
101 The %s group, at least, was an inappropriate recipient
102 of this message. Please trim your Newsgroups header to exclude this
103 group before posting in the future.
108 "Format string to be inserted when complaining about crossposts.
109 The first %s will be replaced by the Newsgroups header;
110 the second with the current group name."
114 (defcustom gnus-message-setup-hook nil
115 "Hook run after setting up a message buffer."
119 (defcustom gnus-bug-create-help-buffer t
120 "*Should we create the *Gnus Help Bug* buffer?"
124 (defcustom gnus-posting-styles nil
125 "*Alist of styles to use when posting.
126 See Info node `(gnus)Posting Styles'."
128 :link '(custom-manual "(gnus)Posting Styles")
129 :type '(repeat (cons (choice (regexp)
132 (string :tag "Header")
133 (regexp :tag "Regexp"))
137 (choice (const signature)
138 (const signature-file)
146 (string :tag "Header"))
152 (defcustom gnus-named-posting-styles nil
153 "Alist mapping names to the user-defined posting styles."
155 :type '(repeat (cons string
157 (choice (const signature)
158 (const signature-file)
166 (string :tag "Header"))
172 (defcustom gnus-gcc-mark-as-read nil
173 "If non-nil, automatically mark Gcc articles as read."
178 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
179 'gnus-gcc-mark-as-read)
181 (defcustom gnus-gcc-externalize-attachments nil
182 "Should local-file attachments be included as external parts in Gcc copies?
183 If it is `all', attach files as external parts;
184 if a regexp and matches the Gcc group name, attach files as external parts;
185 if nil, attach files as normal parts."
188 :type '(choice (const nil :tag "None")
189 (const all :tag "Any")
190 (string :tag "Regexp")))
192 (gnus-define-group-parameter
193 posting-charset-alist
196 "Return the permitted unencoded charsets for posting of GROUP."
197 :variable gnus-group-posting-charset-alist
199 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
200 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
201 (message-this-is-mail nil nil)
202 (message-this-is-news nil t))
204 "Alist of regexps and permitted unencoded charsets for posting.
205 Each element of the alist has the form (TEST HEADER BODY-LIST), where
206 TEST is either a regular expression matching the newsgroup header or a
208 HEADER is the charset which may be left unencoded in the header (nil
209 means encode all charsets),
210 BODY-LIST is a list of charsets which may be encoded using 8bit
211 content-transfer encoding in the body, or one of the special values
212 nil (always encode using quoted-printable) or t (always use 8bit).
214 Note that any value other than nil for HEADER infringes some RFCs, so
215 use this option with care."
216 :variable-group gnus-charset
218 '(repeat (list :tag "Permitted unencoded charsets"
220 (regexp :tag "Group")
221 (const :tag "Mail message" :value message-this-is-mail)
222 (const :tag "News article" :value message-this-is-news))
223 (choice :tag "Header"
224 (const :tag "None" nil)
225 (symbol :tag "Charset"))
227 (const :tag "Any" :value t)
228 (const :tag "None" :value nil)
229 (repeat :tag "Charsets"
230 (symbol :tag "Charset")))))
231 :parameter-type '(choice :tag "Permitted unencoded charsets"
234 :parameter-document "\
235 List of charsets that are permitted to be unencoded.")
237 (defcustom gnus-debug-files
238 '("gnus.el" "gnus-sum.el" "gnus-group.el"
239 "gnus-art.el" "gnus-start.el" "gnus-async.el"
240 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
241 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
242 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
243 "Files whose variables will be reported in `gnus-bug'."
246 :type '(repeat (string :tag "File")))
248 (defcustom gnus-debug-exclude-variables
249 '(mm-mime-mule-charset-alist
250 nnmail-split-fancy message-minibuffer-local-map)
251 "Variables that should not be reported in `gnus-bug'."
254 :type '(repeat (symbol :tag "Variable")))
256 (defcustom gnus-discouraged-post-methods
257 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
258 "A list of back ends that are not used in \"real\" newsgroups.
259 This variable is used only when `gnus-post-method' is `current'."
261 :group 'gnus-group-foreign
262 :type '(repeat (symbol :tag "Back end")))
264 (defcustom gnus-message-replysign
266 "Automatically sign replies to signed messages.
267 See also the `mml-default-sign-method' variable."
271 (defcustom gnus-message-replyencrypt
273 "Automatically encrypt replies to encrypted messages.
274 See also the `mml-default-encrypt-method' variable."
278 (defcustom gnus-message-replysignencrypted
280 "Setting this causes automatically encrypted messages to also be signed."
284 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
285 (not gnus-expert-user))
286 "If non-nil, Gnus requests confirmation when replying to news.
287 This is done because new users often reply by mistake when reading
289 This can also be a function receiving the group name as the only
290 parameter which should return non-nil iff a confirmation is needed, or
291 a regexp, in which case a confirmation is asked for iff the group name
295 :type '(choice (const :tag "No" nil)
297 (regexp :tag "Iff group matches regexp")
298 (function :tag "Iff function evaluates to non-nil")))
300 (defcustom gnus-confirm-treat-mail-like-news
302 "If non-nil, Gnus will treat mail like news with regard to confirmation
303 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
304 for fine-tuning this.
305 If nil, Gnus will never ask for confirmation if replying to mail."
310 (defcustom gnus-summary-resend-default-address t
311 "If non-nil, Gnus tries to suggest a default address to resend to.
312 If nil, the address field will always be empty after invoking
313 `gnus-summary-resend-message'."
318 ;;; Internal variables.
320 (defvar gnus-inhibit-posting-styles nil
321 "Inhibit the use of posting styles.")
323 (defvar gnus-article-yanked-articles nil)
324 (defvar gnus-message-buffer "*Mail Gnus*")
325 (defvar gnus-article-copy nil)
326 (defvar gnus-check-before-posting nil)
327 (defvar gnus-last-posting-server nil)
328 (defvar gnus-message-group-art nil)
330 (defvar gnus-msg-force-broken-reply-to nil)
332 (defconst gnus-bug-message
333 (format "Sending a bug report to the Gnus Towers.
334 ========================================
336 This gnus is the %s%s.
337 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
338 Developers. (the addresses below are mailing list addresses)
340 ========================================
342 The buffer below is a mail buffer. When you press `C-c C-c', it will
343 be sent to the Gnus Bug Exterminators.
345 The thing near the bottom of the buffer is how the environment
346 settings will be included in the mail. Please do not delete that.
347 They will tell the Bug People what your environment is, so that it
348 will be easier to locate the bugs.
350 If you have found a bug that makes Emacs go \"beep\", set
351 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
352 and include the backtrace in your bug report.
354 Please describe the bug in annoying, painstaking detail.
356 Thank you for your help in stamping out bugs.
359 (if (string= gnus-product-name "Semi-gnus")
361 ", a modified version of Semi-gnus")))
364 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
368 ;;; Gnus Posting Functions
371 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
372 "p" gnus-summary-post-news
373 "i" gnus-summary-news-other-window
374 "f" gnus-summary-followup
375 "F" gnus-summary-followup-with-original
376 "c" gnus-summary-cancel-article
377 "s" gnus-summary-supersede-article
378 "r" gnus-summary-reply
379 "y" gnus-summary-yank-message
380 "R" gnus-summary-reply-with-original
381 "w" gnus-summary-wide-reply
382 "W" gnus-summary-wide-reply-with-original
383 "v" gnus-summary-very-wide-reply
384 "V" gnus-summary-very-wide-reply-with-original
385 "n" gnus-summary-followup-to-mail
386 "N" gnus-summary-followup-to-mail-with-original
387 "m" gnus-summary-mail-other-window
388 "u" gnus-uu-post-news
389 "\M-c" gnus-summary-mail-crosspost-complaint
390 "Br" gnus-summary-reply-broken-reply-to
391 "BR" gnus-summary-reply-broken-reply-to-with-original
392 "om" gnus-summary-mail-forward
393 "op" gnus-summary-post-forward
394 "Om" gnus-summary-digest-mail-forward
395 "Op" gnus-summary-digest-post-forward
396 "P" gnus-summary-execute-command-with-posting-style)
398 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
399 "b" gnus-summary-resend-bounced-mail
400 ;; "c" gnus-summary-send-draft
401 "r" gnus-summary-resend-message
402 "e" gnus-summary-resend-message-edit)
404 ;;; Internal functions.
406 (defun gnus-inews-make-draft (articles)
408 (gnus-inews-make-draft-meta-information
409 ,gnus-newsgroup-name ',articles)))
411 (defvar gnus-article-reply nil)
412 (defmacro gnus-setup-message (config &rest forms)
413 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
414 (buffer (make-symbol "gnus-setup-message-buffer"))
415 (article (make-symbol "gnus-setup-message-article"))
416 (yanked (make-symbol "gnus-setup-yanked-articles"))
417 (group (make-symbol "gnus-setup-message-group")))
418 `(let ((,winconf (current-window-configuration))
419 (,buffer (buffer-name (current-buffer)))
420 (,article gnus-article-reply)
421 (,yanked gnus-article-yanked-articles)
422 (,group gnus-newsgroup-name)
423 (message-header-setup-hook
424 (copy-sequence message-header-setup-hook))
425 (message-mode-hook (copy-sequence message-mode-hook))
426 (message-startup-parameter-alist
427 '((reply-buffer . gnus-copy-article-buffer)
428 (original-buffer . gnus-original-article-buffer)
429 (user-agent . Gnus))))
430 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
431 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
432 ;; #### FIXME: for a reason that I did not manage to identify yet,
433 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
434 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
435 ;; After evaluation of @forms below, it gets the value we actually want
436 ;; to override, and the posting styles are used. For that reason, I've
437 ;; added an optional argument to `gnus-configure-posting-styles' to
438 ;; make sure that the correct value for the group name is used. -- drv
439 (add-hook 'message-mode-hook
440 (if (memq ,config '(reply-yank reply))
442 (gnus-configure-posting-styles ,group))
444 ;; There may be an old " *gnus article copy*" buffer.
445 (let (gnus-article-copy)
446 (gnus-configure-posting-styles ,group)))))
447 (gnus-pull ',(intern gnus-draft-meta-information-header)
448 message-required-headers)
450 (not (string= ,group "")))
452 (intern gnus-draft-meta-information-header)
453 (gnus-inews-make-draft (or ,yanked ,article)))
454 message-required-headers))
458 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
460 (setq gnus-message-buffer (current-buffer))
461 (set (make-local-variable 'gnus-message-group-art)
462 (cons ,group ,article))
463 (set (make-local-variable 'gnus-newsgroup-name) ,group)
464 (gnus-maybe-setup-default-charset)
465 (gnus-run-hooks 'gnus-message-setup-hook))
466 (message-hide-headers)
468 (gnus-configure-windows ,config t)
469 (run-hooks 'post-command-hook)
470 (set-buffer-modified-p nil))))
472 (defun gnus-inews-make-draft-meta-information (group articles)
473 (when (numberp articles)
474 (setq articles (list articles)))
475 (concat "(\"" group "\""
489 (defun gnus-msg-mail (&optional to subject other-headers continue
490 switch-action yank-action send-actions)
491 "Start editing a mail message to be sent.
492 Like `message-mail', but with Gnus paraphernalia, particularly the
493 Gcc: header for archiving purposes."
495 (let ((buf (current-buffer))
497 (gnus-setup-message 'message
498 (message-mail to subject other-headers continue
499 nil yank-action send-actions))
501 (setq mail-buf (current-buffer))
502 (switch-to-buffer buf)
503 (apply switch-action mail-buf nil)))
504 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
508 (defun gnus-button-mailto (address)
510 (set-buffer (gnus-copy-article-buffer))
511 (gnus-setup-message 'message
512 (message-reply address)))
515 (defun gnus-button-reply (&optional to-address wide)
516 "Like `message-reply'."
518 (gnus-setup-message 'message
519 (message-reply to-address wide)))
522 (define-mail-user-agent 'gnus-user-agent
523 'gnus-msg-mail 'message-send-and-exit
524 'message-kill-buffer 'message-send-hook)
526 (defun gnus-setup-posting-charset (group)
527 (let ((alist gnus-group-posting-charset-alist)
528 (group (or group ""))
532 (while (setq elem (pop alist))
533 (when (or (and (stringp (car elem))
534 (string-match (car elem) group))
535 (and (functionp (car elem))
536 (funcall (car elem) group))
537 (and (symbolp (car elem))
538 (symbol-value (car elem))))
539 (throw 'found (cons (cadr elem) (caddr elem)))))))))
541 (defun gnus-inews-add-send-actions (winconf buffer article
542 &optional config yanked)
543 (gnus-make-local-hook 'message-sent-hook)
544 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
545 'gnus-inews-do-gcc) nil t)
547 (gnus-make-local-hook 'message-header-hook)
548 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
549 (setq message-post-method
550 `(lambda (&optional arg)
551 (gnus-post-method arg ,gnus-newsgroup-name)))
552 (setq message-user-agent (gnus-message-make-user-agent))
553 (unless message-use-multi-frames
555 `(if (gnus-buffer-exists-p ,buffer)
556 (set-window-configuration ,winconf))
557 'exit 'postpone 'kill))
558 (let ((to-be-marked (cond
561 (lambda (x) (if (listp x) (car x) x)) yanked))
562 (article (if (listp article) article (list article)))
565 `(when (gnus-buffer-exists-p ,buffer)
569 (if (eq config 'forward)
570 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
571 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
574 (put 'gnus-setup-message 'lisp-indent-function 1)
575 (put 'gnus-setup-message 'edebug-form-spec '(form body))
577 ;;; Post news commands of Gnus group mode and summary mode
579 (defun gnus-group-mail (&optional arg)
580 "Start composing a mail.
581 If ARG, use the group under the point to find a posting style.
582 If ARG is 1, prompt for a group name to find the posting style."
584 ;; We can't `let' gnus-newsgroup-name here, since that leads
585 ;; to local variables leaking.
586 (let ((group gnus-newsgroup-name)
587 ;; make sure last viewed article doesn't affect posting styles:
589 (buffer (current-buffer)))
592 (setq gnus-newsgroup-name
594 (if (= 1 (prefix-numeric-value arg))
595 (completing-read "Use posting style of group: "
596 gnus-active-hashtb nil
597 (gnus-read-active-file-p))
598 (gnus-group-group-name))
600 ;; #### see comment in gnus-setup-message -- drv
601 (gnus-setup-message 'message (message-mail)))
604 (setq gnus-newsgroup-name group)))))
606 (defun gnus-group-news (&optional arg)
607 "Start composing a news.
608 If ARG, post to group under point.
609 If ARG is 1, prompt for group name to post to.
611 This function prepares a news even when using mail groups. This is useful
612 for posting messages to mail groups without actually sending them over the
613 network. The corresponding back end must have a 'request-post method."
615 ;; We can't `let' gnus-newsgroup-name here, since that leads
616 ;; to local variables leaking.
617 (let ((group gnus-newsgroup-name)
618 ;; make sure last viewed article doesn't affect posting styles:
620 (buffer (current-buffer)))
623 (setq gnus-newsgroup-name
625 (if (= 1 (prefix-numeric-value arg))
626 (completing-read "Use group: "
627 gnus-active-hashtb nil
628 (gnus-read-active-file-p))
629 (gnus-group-group-name))
631 ;; #### see comment in gnus-setup-message -- drv
632 (gnus-setup-message 'message
633 (message-news (gnus-group-real-name gnus-newsgroup-name))))
636 (setq gnus-newsgroup-name group)))))
638 (defun gnus-group-post-news (&optional arg)
639 "Start composing a message (a news by default).
640 If ARG, post to group under point. If ARG is 1, prompt for group name.
641 Depending on the selected group, the message might be either a mail or
644 ;; Bind this variable here to make message mode hooks work ok.
645 (let ((gnus-newsgroup-name
647 (if (= 1 (prefix-numeric-value arg))
648 (completing-read "Newsgroup: " gnus-active-hashtb nil
649 (gnus-read-active-file-p))
650 (gnus-group-group-name))
652 ;; make sure last viewed article doesn't affect posting styles:
654 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
655 (string= gnus-newsgroup-name ""))))
657 (defun gnus-summary-mail-other-window (&optional arg)
658 "Start composing a mail in another window.
659 Use the posting of the current group by default.
660 If ARG, don't do that. If ARG is 1, prompt for group name to find the
663 ;; We can't `let' gnus-newsgroup-name here, since that leads
664 ;; to local variables leaking.
665 (let ((group gnus-newsgroup-name)
666 ;; make sure last viewed article doesn't affect posting styles:
668 (buffer (current-buffer)))
671 (setq gnus-newsgroup-name
673 (if (= 1 (prefix-numeric-value arg))
674 (completing-read "Use group: "
675 gnus-active-hashtb nil
676 (gnus-read-active-file-p))
678 gnus-newsgroup-name))
679 ;; #### see comment in gnus-setup-message -- drv
680 (gnus-setup-message 'message (message-mail)))
683 (setq gnus-newsgroup-name group)))))
685 (defun gnus-summary-news-other-window (&optional arg)
686 "Start composing a news in another window.
687 Post to the current group by default.
688 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
690 This function prepares a news even when using mail groups. This is useful
691 for posting messages to mail groups without actually sending them over the
692 network. The corresponding back end must have a 'request-post method."
694 ;; We can't `let' gnus-newsgroup-name here, since that leads
695 ;; to local variables leaking.
696 (let ((group gnus-newsgroup-name)
697 ;; make sure last viewed article doesn't affect posting styles:
699 (buffer (current-buffer)))
702 (setq gnus-newsgroup-name
704 (if (= 1 (prefix-numeric-value arg))
705 (completing-read "Use group: "
706 gnus-active-hashtb nil
707 (gnus-read-active-file-p))
709 gnus-newsgroup-name))
710 ;; #### see comment in gnus-setup-message -- drv
711 (gnus-setup-message 'message
713 (message-news (gnus-group-real-name gnus-newsgroup-name))
714 (set (make-local-variable 'gnus-discouraged-post-methods)
716 (car (gnus-find-method-for-group gnus-newsgroup-name))
717 gnus-discouraged-post-methods)))))
720 (setq gnus-newsgroup-name group)))))
722 (defun gnus-summary-post-news (&optional arg)
723 "Start composing a message. Post to the current group by default.
724 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
725 Depending on the selected group, the message might be either a mail or
728 ;; Bind this variable here to make message mode hooks work ok.
729 (let ((gnus-newsgroup-name
731 (if (= 1 (prefix-numeric-value arg))
732 (completing-read "Newsgroup: " gnus-active-hashtb nil
733 (gnus-read-active-file-p))
735 gnus-newsgroup-name))
736 ;; make sure last viewed article doesn't affect posting styles:
738 (gnus-post-news 'post gnus-newsgroup-name)))
741 (defun gnus-summary-followup (yank &optional force-news)
742 "Compose a followup to an article.
743 If prefix argument YANK is non-nil, the original article is yanked
745 YANK is a list of elements, where the car of each element is the
746 article number, and the cdr is the string to be yanked."
748 (list (and current-prefix-arg
749 (gnus-summary-work-articles 1))))
751 (gnus-summary-goto-subject
752 (if (listp (car yank))
755 (save-window-excursion
756 (gnus-summary-select-article))
757 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
758 (gnus-newsgroup-name gnus-newsgroup-name))
760 (gnus-post-news nil gnus-newsgroup-name
761 headers gnus-article-buffer
763 (gnus-summary-handle-replysign)))
765 (defun gnus-summary-followup-with-original (n &optional force-news)
766 "Compose a followup to an article and include the original article.
767 The text in the region will be yanked. If the region isn't
768 active, the entire article will be yanked."
770 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
772 (defun gnus-summary-followup-to-mail (&optional arg)
773 "Followup to the current mail message via news."
775 (list (and current-prefix-arg
776 (gnus-summary-work-articles 1))))
777 (gnus-summary-followup arg t))
779 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
780 "Followup to the current mail message via news."
782 (gnus-summary-followup (gnus-summary-work-articles arg) t))
784 (defun gnus-inews-yank-articles (articles)
785 (let (beg article yank-string
786 (more-than-one (cdr articles))
787 (cur (current-buffer))
790 (while (setq article (pop articles))
791 (when (listp article)
792 (setq yank-string (nth 1 article)
793 article (nth 0 article)))
794 (save-window-excursion
795 (set-buffer gnus-summary-buffer)
796 (gnus-summary-select-article nil nil nil article)
797 (gnus-summary-remove-process-mark article))
799 ;; Gathering references.
801 (setq refs (message-list-references
803 (mail-header-references gnus-current-headers)
804 (mail-header-message-id gnus-current-headers)))
805 (when message-use-multi-frames
806 (when (setq window (get-buffer-window cur t))
807 (select-frame (window-frame window)))))
809 (gnus-copy-article-buffer nil yank-string)
810 (let ((message-reply-buffer gnus-article-copy)
811 (message-reply-headers
812 ;; The headers are decoded.
813 (with-current-buffer gnus-article-copy
815 (nnheader-narrow-to-headers)
816 (nnheader-parse-naked-head)))))
817 (message-yank-original)
818 (setq beg (or beg (mark t))))
823 ;; Replace with the gathered references.
827 (message-narrow-to-headers)
828 (let ((case-fold-search t))
829 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
831 (goto-char (point-max))))
833 (list (or (assq 'References message-header-format-alist)
834 '(References . message-shorten-references)))
835 (list (cons 'References
836 (mapconcat 'identity (nreverse refs) " ")))))
842 (defun gnus-summary-cancel-article (&optional n symp)
843 "Cancel an article you posted.
844 Uses the process-prefix convention. If given the symbolic
845 prefix `a', cancel using the standard posting method; if not
846 post using the current select method."
847 (interactive (gnus-interactive "P\ny"))
848 (let ((message-post-method
850 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
851 (dolist (article (gnus-summary-work-articles n))
852 (when (gnus-summary-select-article t nil nil article)
853 (when (gnus-eval-in-buffer-window gnus-article-buffer
855 (set-buffer gnus-original-article-buffer)
856 (message-cancel-news)))
857 (gnus-summary-mark-as-read article gnus-canceled-mark)
858 (gnus-cache-remove-article 1))
859 (gnus-article-hide-headers-if-wanted))
860 (gnus-summary-remove-process-mark article))))
862 (defun gnus-summary-supersede-article ()
863 "Compose an article that will supersede a previous article.
864 This is done simply by taking the old article and adding a Supersedes
865 header line with the old Message-ID."
867 (let ((article (gnus-summary-article-number)))
868 (gnus-setup-message 'reply-yank
869 (gnus-summary-select-article t)
870 (set-buffer gnus-original-article-buffer)
874 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
876 (set-buffer ,gnus-summary-buffer)
877 (gnus-cache-possibly-remove-article ,article nil nil nil t)
878 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
879 message-send-actions))))
883 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
884 ;; make a copy of the article buffer with all text properties removed
885 ;; this copy is in the buffer gnus-article-copy.
886 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
887 ;; this buffer should be passed to all mail/news reply/post routines.
888 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
890 (set-buffer gnus-article-copy)
891 (set-buffer-multibyte t))
892 (let ((article-buffer (or article-buffer gnus-article-buffer))
894 (if (not (and (get-buffer article-buffer)
895 (gnus-buffer-exists-p article-buffer)))
896 (error "Can't find any article buffer")
898 (set-buffer article-buffer)
899 (let ((gnus-newsgroup-charset (or gnus-article-charset
900 gnus-newsgroup-charset))
901 (gnus-newsgroup-ignored-charsets
902 (or gnus-article-ignored-charsets
903 gnus-newsgroup-ignored-charsets)))
905 ;; Copy over the (displayed) article buffer, delete
906 ;; hidden text and remove text properties.
908 (copy-to-buffer gnus-article-copy (point-min) (point-max))
909 (set-buffer gnus-article-copy)
910 ;; There's invisible and intangible text in T-gnus. Especially,
911 ;; if there is a boundary line (X-Boundary: ------------------),
912 ;; in the end of a header, it will cause a serious problem.
913 (add-text-properties (point-min) (point-max)
914 '(invisible nil intangible nil))
917 (delete-region (point) (point-max))
918 (insert yank-string))
919 ;; Encode bitmap smileys to ordinary text.
920 ;; Possibly, the original text might be restored.
921 (static-unless (featurep 'xemacs)
922 (when (featurep 'smiley-mule)
923 (smiley-encode-buffer)))
924 (gnus-article-delete-text-of-type 'annotation)
925 (gnus-remove-text-with-property 'gnus-prev)
926 (gnus-remove-text-with-property 'gnus-next)
927 (gnus-remove-text-with-property 'gnus-decoration)
930 (static-if (featurep 'xemacs)
931 ;; Revome smiley extents for (possibly) XEmacs 21.1.
933 (buffer-substring-no-properties (point-min)
935 (buffer-substring-no-properties (point-min) (point-max)))
937 ;; Find the original headers.
938 (set-buffer gnus-original-article-buffer)
939 (goto-char (point-min))
940 (while (looking-at message-unix-mail-delimiter)
942 (let ((mail-header-separator ""))
944 end (or (message-goto-body)
945 ;; There may be just a header.
947 ;; Delete the headers from the displayed articles.
948 (set-buffer gnus-article-copy)
949 (let ((mail-header-separator ""))
950 (delete-region (goto-char (point-min))
951 (or (message-goto-body) (point-max))))
952 ;; Insert the original article headers.
953 (insert-buffer-substring gnus-original-article-buffer beg end)
955 (let ((gnus-article-decode-hook
956 (delq 'article-decode-charset
957 (copy-sequence gnus-article-decode-hook))))
958 ;; Needed for T-gnus.
959 (add-hook 'gnus-article-decode-hook
960 'article-decode-encoded-words)
961 (run-hooks 'gnus-article-decode-hook)))))
964 (defun gnus-post-news (post &optional group header article-buffer yank subject
967 (gnus-copy-article-buffer))
968 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
969 (gnus-article-yanked-articles yank)
970 (add-to-list gnus-add-to-list))
971 (gnus-setup-message (cond (yank 'reply-yank)
972 (article-buffer 'reply)
974 (let* ((group (or group gnus-newsgroup-name))
975 (charset (gnus-group-name-charset nil group))
977 to-address to-group mailing-list to-list
980 (setq to-address (gnus-parameter-to-address group)
981 to-group (gnus-group-find-parameter group 'to-group)
982 to-list (gnus-parameter-to-list group)
983 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
984 mailing-list (when gnus-mailing-list-groups
985 (string-match gnus-mailing-list-groups group))
986 group (gnus-group-name-decode (gnus-group-real-name group)
988 (if (or (and to-group
989 (gnus-news-group-p to-group))
992 (and (gnus-news-group-p
993 (or pgroup gnus-newsgroup-name)
994 (or header gnus-current-article))
1002 (and (not (gnus-virtual-group-p pgroup)) group)))
1003 (set-buffer gnus-article-copy)
1004 (gnus-msg-treat-broken-reply-to)
1005 (message-followup (if (or newsgroup-p force-news)
1006 (if (save-restriction
1007 (article-narrow-to-head)
1008 (message-fetch-field "newsgroups"))
1015 (message-mail (or to-address to-list))
1016 ;; Arrange for mail groups that have no `to-address' to
1017 ;; get that when the user sends off the mail.
1018 (when (and (not to-list)
1021 (push (list 'gnus-inews-add-to-address pgroup)
1022 message-send-actions)))
1023 (set-buffer gnus-article-copy)
1024 (gnus-msg-treat-broken-reply-to)
1025 (message-wide-reply to-address)))
1027 (gnus-inews-yank-articles yank))))))
1029 (defun gnus-msg-treat-broken-reply-to (&optional force)
1030 "Remove the Reply-to header if broken-reply-to."
1032 (gnus-group-find-parameter
1033 gnus-newsgroup-name 'broken-reply-to))
1035 (message-narrow-to-head)
1036 (message-remove-header "reply-to"))))
1038 (defun gnus-post-method (arg group &optional silent)
1039 "Return the posting method based on GROUP and ARG.
1040 If SILENT, don't prompt the user."
1041 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1043 (group-method (gnus-find-method-for-group group)))
1045 ;; If the group-method is nil (which shouldn't happen) we use
1046 ;; the default method.
1047 ((null group-method)
1048 (or (and (listp gnus-post-method) ;If not current/native/nil
1049 (not (listp (car gnus-post-method))) ; and not a list of methods
1050 gnus-post-method) ;then use it.
1052 message-post-method))
1053 ;; We want the inverse of the default
1054 ((and arg (not (eq arg 0)))
1055 (if (eq gnus-post-method 'current)
1058 ;; We query the user for a post method.
1060 (and (listp gnus-post-method)
1061 (listp (car gnus-post-method))))
1063 ;; Collect all methods we know about.
1065 (when (listp gnus-post-method)
1066 (if (listp (car gnus-post-method))
1068 (list gnus-post-method)))
1069 gnus-secondary-select-methods
1070 (mapcar 'cdr gnus-server-alist)
1071 (mapcar 'car gnus-opened-servers)
1072 (list gnus-select-method)
1073 (list group-method)))
1074 method-alist post-methods method)
1075 ;; Weed out all mail methods.
1077 (setq method (gnus-server-get-method "" (pop methods)))
1078 (when (and (or (gnus-method-option-p method 'post)
1079 (gnus-method-option-p method 'post-mail))
1080 (not (member method post-methods)))
1081 (push method post-methods)))
1082 ;; Create a name-method alist.
1086 (if (equal (cadr m) "")
1087 (list (symbol-name (car m)) m)
1088 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1093 (setq gnus-last-posting-server
1095 gnus-last-posting-server)
1096 ;; Just use the last value.
1097 gnus-last-posting-server
1099 "Posting method: " method-alist nil t
1100 (cons (or gnus-last-posting-server "") 0))))
1102 ;; Override normal method.
1103 ((and (eq gnus-post-method 'current)
1104 (not (memq (car group-method) gnus-discouraged-post-methods))
1105 (gnus-get-function group-method 'request-post t))
1108 ;; Use gnus-post-method.
1109 ((listp gnus-post-method) ;A method...
1110 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1112 ;; Use the normal select method (nil or native).
1113 (t gnus-select-method))))
1116 (defun gnus-message-make-user-agent (&optional dummy max-column
1118 "Return a user-agent info. If MAX-COLUMN is specified, the return
1119 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1120 whether a newline should be inserted in front of each product-token;
1121 if the value is t or `hard', it works strictly. Otherwise, if it is
1122 non-nil (e.g. `soft'), it works semi-strictly."
1123 (let ((user-agent (gnus-extended-version)))
1125 (unless (natnump max-column)
1126 (setq max-column 76))
1128 (set-buffer-multibyte t)
1129 (insert (mapconcat 'identity (split-string user-agent) " "))
1130 (goto-char (point-min))
1132 start agent agents width element swidth)
1133 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1134 (setq start (match-beginning 0))
1135 (if (eq (char-after start) ?\()
1139 (push (buffer-substring start (point)) agent))
1141 (push (nreverse agent) agents))
1142 (setq agent (list (match-string 1)))))
1144 (push (nreverse agent) agents))
1145 (setq agents (nreverse agents))
1146 (if (> (+ 12 (string-width (caar agents))) max-column)
1147 (setq user-agent "\n"
1152 (setq agent (car agents)
1153 agents (cdr agents))
1154 (when (and (not bol)
1155 (or (memq newline-product '(t hard))
1156 (and newline-product
1158 (string-width (mapconcat 'identity
1161 (setq user-agent (concat user-agent "\n")
1165 (setq element (car agent)
1166 swidth (string-width element)
1169 (setq user-agent (if (member user-agent '("" "\n"))
1170 (concat user-agent element)
1171 (concat user-agent " " element))
1172 width (+ width 1 swidth)
1174 (if (> (+ width 1 swidth) max-column)
1175 (setq user-agent (concat user-agent "\n " element)
1177 (setq user-agent (concat user-agent " " element)
1178 width (+ width 1 swidth)))))))))
1183 ;;; Gnus Mail Functions
1186 ;;; Mail reply commands of Gnus summary mode
1188 (defun gnus-summary-reply (&optional yank wide very-wide)
1189 "Start composing a mail reply to the current message.
1190 If prefix argument YANK is non-nil, the original article is yanked
1192 If WIDE, make a wide reply.
1193 If VERY-WIDE, make a very wide reply."
1195 (list (and current-prefix-arg
1196 (gnus-summary-work-articles 1))))
1197 ;; Allow user to require confirmation before replying by mail to the
1198 ;; author of a news article (or mail message).
1200 (not (or (gnus-news-group-p gnus-newsgroup-name)
1201 gnus-confirm-treat-mail-like-news))
1202 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1203 (string-match gnus-confirm-mail-reply-to-news
1204 gnus-newsgroup-name))
1205 ((functionp gnus-confirm-mail-reply-to-news)
1206 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1207 (t gnus-confirm-mail-reply-to-news)))
1208 (y-or-n-p "Really reply by mail to article author? "))
1210 (if (listp (car yank))
1213 (gnus-article-reply (or article (gnus-summary-article-number)))
1214 (gnus-article-yanked-articles yank)
1216 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1218 (gnus-summary-goto-subject article))
1219 (gnus-setup-message (if yank 'reply-yank 'reply)
1221 (gnus-summary-select-article)
1222 (dolist (article very-wide)
1223 (gnus-summary-select-article nil nil nil article)
1225 (set-buffer (gnus-copy-article-buffer))
1226 (gnus-msg-treat-broken-reply-to)
1228 (message-narrow-to-head)
1229 (setq headers (concat headers (buffer-string)))))))
1230 (set-buffer (gnus-copy-article-buffer))
1231 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1233 (message-narrow-to-head)
1237 (goto-char (point-max)))
1238 (message-reply nil wide)
1240 (gnus-inews-yank-articles yank))
1241 (gnus-summary-handle-replysign)))))
1243 (defun gnus-summary-handle-replysign ()
1244 "Check the various replysign variables and take action accordingly."
1245 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1246 (let (signed encrypted)
1248 (set-buffer gnus-article-buffer)
1249 (setq signed (memq 'signed gnus-article-wash-types))
1250 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1251 (cond ((and gnus-message-replyencrypt encrypted)
1252 (mml-secure-message mml-default-encrypt-method
1253 (if gnus-message-replysignencrypted
1256 ((and gnus-message-replysign signed)
1257 (mml-secure-message mml-default-sign-method 'sign))))))
1259 (defun gnus-summary-reply-with-original (n &optional wide)
1260 "Start composing a reply mail to the current message.
1261 The original article will be yanked."
1263 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1265 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1266 "Like `gnus-summary-reply' except removing reply-to field.
1267 If prefix argument YANK is non-nil, the original article is yanked
1269 If WIDE, make a wide reply.
1270 If VERY-WIDE, make a very wide reply."
1272 (list (and current-prefix-arg
1273 (gnus-summary-work-articles 1))))
1274 (let ((gnus-msg-force-broken-reply-to t))
1275 (gnus-summary-reply yank wide very-wide)))
1277 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1278 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1279 The original article will be yanked."
1281 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1283 (defun gnus-summary-wide-reply (&optional yank)
1284 "Start composing a wide reply mail to the current message.
1285 If prefix argument YANK is non-nil, the original article is yanked
1288 (list (and current-prefix-arg
1289 (gnus-summary-work-articles 1))))
1290 (gnus-summary-reply yank t))
1292 (defun gnus-summary-wide-reply-with-original (n)
1293 "Start composing a wide reply mail to the current message.
1294 The original article will be yanked.
1295 Uses the process/prefix convention."
1297 (gnus-summary-reply-with-original n t))
1299 (defun gnus-summary-very-wide-reply (&optional yank)
1300 "Start composing a very wide reply mail to the current message.
1301 If prefix argument YANK is non-nil, the original article is yanked
1304 (list (and current-prefix-arg
1305 (gnus-summary-work-articles 1))))
1306 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1308 (defun gnus-summary-very-wide-reply-with-original (n)
1309 "Start composing a very wide reply mail to the current message.
1310 The original article will be yanked."
1313 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1315 (defun gnus-summary-mail-forward (&optional full-headers post)
1316 "Forward the current message(s) to another user.
1317 If process marks exist, forward all marked messages;
1318 If FULL-HEADERS (the prefix), include full headers when forwarding.
1320 Note that this function definition for T-gnus is totally different
1321 from the original Gnus."
1323 (if (cdr (gnus-summary-work-articles nil))
1324 ;; Process marks are given.
1325 (gnus-summary-digest-mail-forward nil post)
1326 ;; No process marks.
1327 (let* ((gnus-article-reply (gnus-summary-article-number))
1328 (gnus-article-yanked-articles (list gnus-article-reply))
1330 (message-included-forward-headers
1331 (if full-headers "" message-included-forward-headers)))
1332 (gnus-setup-message 'forward
1333 (gnus-summary-select-article)
1334 (setq charset default-mime-charset)
1335 (set-buffer gnus-original-article-buffer)
1336 (make-local-variable 'default-mime-charset)
1337 (setq default-mime-charset charset)
1338 (message-forward post)))))
1340 (defun gnus-summary-digest-mail-forward (&optional n post)
1341 "Digests and forwards all articles in this series.
1342 If N is a positive number, forward the N next articles.
1343 If N is a negative number, forward the N previous articles.
1344 If N is nil and any articles have been marked with the process mark,
1345 forward those articles instead.
1346 Optional POST will use news to forward instead of mail."
1348 (let* ((articles (gnus-summary-work-articles n))
1349 (gnus-article-yanked-articles (copy-sequence articles))
1350 (topics "Topics:\n")
1351 subject article frame)
1352 (when (car articles)
1353 (gnus-setup-message 'forward
1354 (gnus-summary-select-article)
1356 (setq articles (sort articles '<)
1357 subject "Digested Articles")
1358 (with-current-buffer gnus-original-article-buffer
1359 (setq subject (message-make-forward-subject))))
1361 (message-news nil subject)
1362 (message-mail nil subject))
1363 (when (and message-use-multi-frames (cdr articles))
1364 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1366 (while (setq article (pop articles))
1367 (save-window-excursion
1368 (set-buffer gnus-summary-buffer)
1369 (gnus-summary-select-article nil nil nil article)
1370 (setq topics (concat topics " "
1371 (mail-header-subject gnus-current-headers)
1373 (gnus-summary-remove-process-mark article))
1375 (select-frame frame))
1376 (insert (mime-make-tag "message" "rfc822") "\n")
1377 (narrow-to-region (point) (point))
1378 (insert-buffer-substring gnus-original-article-buffer)
1380 (article-narrow-to-head)
1381 (message-remove-header message-included-forward-headers t nil t))
1382 (goto-char (point-max))
1388 (mime-edit-enclose-digest-region (point)(mark t))))))
1390 (defun gnus-summary-digest-post-forward (&optional n)
1391 "Digest and forwards all articles in this series to a newsgroup.
1392 If N is a positive number, forward the N next articles.
1393 If N is a negative number, forward the N previous articles.
1394 If N is nil and any articles have been marked with the process mark,
1395 forward those articles instead."
1397 (gnus-summary-digest-mail-forward n t))
1399 (defun gnus-summary-resend-message (address n)
1400 "Resend the current article to ADDRESS."
1402 (list (message-read-from-minibuffer
1403 "Resend message(s) to: "
1404 (when (and gnus-summary-resend-default-address
1405 (gnus-buffer-live-p gnus-original-article-buffer))
1406 ;; If some other article is currently selected, the
1407 ;; initial-contents is wrong. Whatever, it is just the
1408 ;; initial-contents.
1409 (with-current-buffer gnus-original-article-buffer
1410 (nnmail-fetch-field "to"))))
1411 current-prefix-arg))
1412 (dolist (article (gnus-summary-work-articles n))
1413 (gnus-summary-select-article nil nil nil article)
1415 (set-buffer gnus-original-article-buffer)
1416 (message-resend address))
1417 (gnus-summary-mark-article-as-forwarded article)))
1419 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1420 (defun gnus-summary-resend-message-edit ()
1421 "Resend an article that has already been sent.
1422 A new buffer will be created to allow the user to modify body and
1423 contents of the message, and then, everything will happen as when
1424 composing a new message."
1426 (let ((article (gnus-summary-article-number)))
1427 (gnus-setup-message 'reply-yank
1428 (gnus-summary-select-article t)
1429 (set-buffer gnus-original-article-buffer)
1430 (let ((cur (current-buffer))
1431 (to (message-fetch-field "to")))
1432 ;; Get a normal message buffer.
1433 (message-pop-to-buffer (message-buffer-name "Resend" to))
1434 (insert-buffer-substring cur)
1436 ;; T-gnus change: Use MIME-Edit to recompose a message.
1438 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1439 (fset 'mime-edit-decode-single-part-in-buffer
1440 (lambda (&rest args)
1441 (if (let ((content-type (car args)))
1442 (and (eq 'message (mime-content-type-primary-type
1444 (eq 'rfc822 (mime-content-type-subtype
1446 (setcar (cdr args) 'not-decode-text))
1449 (mime-edit-again nil t)
1450 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1451 (message-narrow-to-head-1)
1452 (insert "From: " (message-make-from) "\n")
1453 (while (re-search-forward "^From:" nil t)
1455 (insert "Original-"))
1456 (message-remove-header "^>From[\t ]" t)
1458 ;; Gnus will generate a new one when sending.
1459 (message-remove-header "Message-ID")
1460 (message-remove-header message-ignored-resent-headers t)
1461 ;; Remove unwanted headers.
1462 (goto-char (point-max))
1463 (insert mail-header-separator)
1464 (goto-char (point-min))
1465 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1469 (defun gnus-summary-post-forward (&optional full-headers)
1470 "Forward the current article to a newsgroup.
1471 If FULL-HEADERS (the prefix), include full headers when forwarding."
1473 (gnus-summary-mail-forward full-headers t))
1475 (defvar gnus-nastygram-message
1476 "The following article was inappropriately posted to %s.\n\n"
1477 "Format string to insert in nastygrams.
1478 The current group name will be inserted at \"%s\".")
1480 (defun gnus-summary-mail-nastygram (n)
1481 "Send a nastygram to the author of the current article."
1483 (when (or gnus-expert-user
1485 "Really send a nastygram to the author of the current article? "))
1486 (let ((group gnus-newsgroup-name))
1487 (gnus-summary-reply-with-original n)
1488 (set-buffer gnus-message-buffer)
1490 (insert (format gnus-nastygram-message group))
1491 (message-send-and-exit))))
1493 (defun gnus-summary-mail-crosspost-complaint (n)
1494 "Send a complaint about crossposting to the current article(s)."
1496 (dolist (article (gnus-summary-work-articles n))
1497 (set-buffer gnus-summary-buffer)
1498 (gnus-summary-goto-subject article)
1499 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1500 newsgroups followup-to)
1501 (gnus-summary-select-article)
1502 (set-buffer gnus-original-article-buffer)
1503 (if (and (<= (length (message-tokenize-header
1505 (mail-fetch-field "newsgroups"))
1508 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1509 (not (member group (message-tokenize-header
1510 followup-to ", ")))))
1512 (gnus-message 1 "Followup-to restricted")
1513 (gnus-message 1 "Not a crossposted article"))
1514 (set-buffer gnus-summary-buffer)
1515 (gnus-summary-reply-with-original 1)
1516 (set-buffer gnus-message-buffer)
1518 (insert (format gnus-crosspost-complaint newsgroups group))
1519 (message-goto-subject)
1520 (re-search-forward " *$")
1521 (replace-match " (crosspost notification)" t t)
1522 (gnus-deactivate-mark)
1523 (when (gnus-y-or-n-p "Send this complaint? ")
1524 (message-send-and-exit))))))
1526 (defun gnus-mail-parse-comma-list ()
1529 (skip-chars-forward " ")
1532 (skip-chars-forward "^,")
1537 (narrow-to-region beg (point))
1540 (while (search-forward "\"" nil t)
1544 (skip-chars-forward ",")
1545 (skip-chars-forward "^,"))
1546 (skip-chars-backward " ")
1547 (push (buffer-substring beg (point))
1549 (skip-chars-forward "^,")
1550 (skip-chars-forward ", "))
1553 (defun gnus-inews-add-to-address (group)
1554 (let ((to-address (mail-fetch-field "to")))
1555 (when (and to-address
1557 ;; This mail group doesn't have a `to-list', so we add one
1559 (when (gnus-y-or-n-p
1560 (format "Do you want to add this as `to-list': %s? " to-address))
1561 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1563 (defun gnus-put-message ()
1564 "Put the current message in some group and return to Gnus."
1566 (let ((reply gnus-article-reply)
1567 (winconf gnus-prev-winconf)
1568 (group gnus-newsgroup-name))
1570 (not (gnus-group-read-only-p group)))
1571 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1573 (when (gnus-group-entry group)
1574 (error "No such group: %s" group))
1578 (message-narrow-to-headers)
1579 (let ((gnus-deletable-headers nil))
1580 (message-generate-headers
1581 (if (message-news-p)
1582 message-required-news-headers
1583 message-required-mail-headers)))
1584 (goto-char (point-max))
1585 (if (string-match " " group)
1586 (insert "Gcc: \"" group "\"\n")
1587 (insert "Gcc: " group "\n"))
1590 (when (and (get-buffer gnus-group-buffer)
1591 (gnus-buffer-exists-p (car-safe reply))
1593 (set-buffer (car reply))
1594 (gnus-summary-mark-article-as-replied (cdr reply)))
1596 (set-window-configuration winconf))))
1598 (defun gnus-article-mail (yank)
1599 "Send a reply to the address near point.
1600 If YANK is non-nil, include the original article."
1604 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1605 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1607 (gnus-msg-mail address)
1609 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1611 (defvar nntp-server-type)
1613 "Send a bug report to the Gnus maintainers."
1615 (unless (gnus-alive-p)
1616 (error "Gnus has been shut down"))
1617 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1618 (unless (message-mail-user-agent)
1619 (message-pop-to-buffer "*Gnus Bug*")
1620 (delete-other-windows)
1621 (when gnus-bug-create-help-buffer
1622 (switch-to-buffer "*Gnus Help Bug*")
1624 (insert gnus-bug-message)
1625 (goto-char (point-min))
1627 (set-buffer "*Gnus Bug*")))
1628 (let ((message-this-is-mail t))
1629 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1630 (when gnus-bug-create-help-buffer
1631 (push `(gnus-bug-kill-buffer) message-send-actions))
1632 (goto-char (point-min))
1633 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1635 (insert gnus-product-name " " gnus-version-number
1636 " (r" gnus-revision-number ") "
1637 "based on " gnus-original-product-name " v"
1638 gnus-original-version-number "\n"
1639 (emacs-version) "\n")
1640 (when (and (boundp 'nntp-server-type)
1641 (stringp nntp-server-type))
1642 (insert nntp-server-type))
1643 (insert "\n\n\n\n\n")
1644 (let (mime-content-types)
1645 (mime-edit-insert-tag
1646 "application" "emacs-lisp"
1647 "\nContent-Disposition: inline\nContent-Description: User settings"))
1648 (insert (with-temp-buffer
1651 (let (mime-content-types)
1652 (mime-edit-insert-tag "text" "plain"))
1653 (goto-char (point-min))
1654 (search-forward "Subject: " nil t)
1657 (defun gnus-bug-kill-buffer ()
1658 (when (get-buffer "*Gnus Help Bug*")
1659 (kill-buffer "*Gnus Help Bug*")))
1661 (defun gnus-summary-yank-message (buffer n)
1662 "Yank the current article into a composed message."
1664 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1665 current-prefix-arg))
1666 (when (gnus-buffer-live-p buffer)
1667 (let ((summary-frame (selected-frame))
1668 (message-frame (when (static-if (featurep 'xemacs)
1669 (device-on-window-system-p)
1671 (let ((window (get-buffer-window buffer t)))
1673 (window-frame window)))))
1674 (separator (concat "^" (regexp-quote mail-header-separator)
1676 (gnus-summary-iterate n
1677 (gnus-summary-select-article)
1678 (gnus-copy-article-buffer)
1679 (when (frame-live-p message-frame)
1680 (raise-frame message-frame)
1681 (select-frame message-frame))
1682 (with-current-buffer buffer
1683 (when (save-excursion
1685 (let (case-fold-search)
1686 (and (not (re-search-backward separator nil t))
1687 (re-search-forward separator nil t))))
1688 (goto-char (match-end 0)))
1689 (message-yank-buffer gnus-article-copy))
1690 (select-frame summary-frame))
1691 (when (frame-live-p message-frame)
1692 (select-frame message-frame)))))
1694 (defun gnus-debug ()
1695 "Attempts to go through the Gnus source file and report what variables have been changed.
1696 The source file has to be in the Emacs load path."
1698 (let ((files gnus-debug-files)
1700 file expr olist sym)
1701 (gnus-message 4 "Please wait while we snoop your variables...")
1702 ;; Go through all the files looking for non-default values for variables.
1705 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1708 (when (and (setq file (locate-library (pop files)))
1709 (file-exists-p file))
1710 (insert-file-contents file)
1711 (goto-char (point-min))
1712 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1713 (gnus-message 4 "Malformed sources in file %s" file)
1714 (narrow-to-region (point-min) (point))
1715 (goto-char (point-min))
1716 (while (setq expr (ignore-errors (read (current-buffer))))
1718 (and (memq (car expr) '(defvar defcustom defvoo))
1719 (stringp (nth 3 expr))
1720 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1721 (or (not (boundp (nth 1 expr)))
1722 (not (equal (eval (nth 2 expr))
1723 (symbol-value (nth 1 expr)))))
1724 (push (nth 1 expr) olist)))))))
1725 (kill-buffer (current-buffer)))
1726 (when (setq olist (nreverse olist))
1727 (insert ";----------------- Environment follows ------------------\n\n"))
1729 (if (boundp (car olist))
1733 ,(if (or (consp (setq sym (symbol-value (car olist))))
1735 (not (or (eq sym nil)
1737 (list 'quote (symbol-value (car olist)))
1738 (symbol-value (car olist))))))
1739 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1740 (setq olist (cdr olist)))
1741 ;; Remove any control chars - they seem to cause trouble for some
1742 ;; mailers. (Byte-compiled output from the stuff above.)
1744 (while (re-search-forward (string-as-multibyte
1745 "[\000-\010\013-\037\200-\237]") nil t)
1746 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1748 ;; Break MIME tags purposely.
1750 (while (re-search-forward mime-edit-tag-regexp nil t)
1751 (goto-char (1+ (match-beginning 0)))
1754 ;;; Treatment of rejected articles.
1757 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1758 "Re-mail the current message.
1759 This only makes sense if the current message is a bounce message that
1760 contains some mail you have written which has been bounced back to
1762 If FETCH, try to fetch the article that this is a reply to, if indeed
1765 (gnus-summary-select-article t)
1766 (set-buffer gnus-original-article-buffer)
1767 (gnus-setup-message 'compose-bounce
1768 (let* ((references (mail-fetch-field "references"))
1769 (parent (and references (gnus-parent-id references))))
1771 ;; If there are references, we fetch the article we answered to.
1773 (gnus-summary-refer-article parent)
1774 (gnus-summary-show-all-headers)))))
1778 (defun gnus-inews-group-method (group)
1780 ;; If the group doesn't exist, we assume
1781 ;; it's an archive group...
1782 ((and (null (gnus-get-info group))
1783 (eq (car (gnus-server-to-method gnus-message-archive-method))
1784 (car (gnus-server-to-method (gnus-group-method group)))))
1785 gnus-message-archive-method)
1787 ((gnus-info-method (gnus-get-info group))
1788 (gnus-info-method (gnus-get-info group)))
1790 (t (gnus-server-to-method (gnus-group-method group)))))
1792 ;; Do Gcc handling, which copied the message over to some group.
1793 (defun gnus-inews-do-gcc (&optional gcc)
1797 (message-narrow-to-headers)
1798 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1799 (coding-system-for-write 'raw-text)
1800 groups group method group-art
1801 mml-externalize-attachments)
1803 (message-remove-header "gcc")
1805 (setq groups (message-unquote-tokens
1806 (message-tokenize-header gcc " ,")))
1807 ;; Copy the article over to some group(s).
1808 (while (setq group (pop groups))
1809 (unless (gnus-check-server
1810 (setq method (gnus-inews-group-method group)))
1811 (error "Can't open server %s" (if (stringp method) method
1813 (unless (gnus-request-group group nil method)
1814 (gnus-request-create-group group method))
1815 (setq mml-externalize-attachments
1816 (if (stringp gnus-gcc-externalize-attachments)
1817 (string-match gnus-gcc-externalize-attachments group)
1818 gnus-gcc-externalize-attachments))
1820 (nnheader-set-temp-buffer " *acc*")
1821 (insert-buffer-substring message-encoding-buffer)
1822 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1823 (goto-char (point-min))
1824 (when (re-search-forward
1825 (concat "^" (regexp-quote mail-header-separator) "$")
1827 (replace-match "" t t ))
1828 (when (or (not (gnus-check-backend-function
1829 'request-accept-article group))
1830 (not (setq group-art
1831 (gnus-request-accept-article
1832 group method t t))))
1833 (gnus-message 1 "Couldn't store article in group %s: %s"
1834 group (gnus-status-message method)))
1835 (when (and group-art
1836 ;; FIXME: Should gcc-mark-as-read work when
1837 ;; Gnus is not running?
1839 (or gnus-gcc-mark-as-read
1841 (boundp 'gnus-inews-mark-gcc-as-read)
1842 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1843 (gnus-group-mark-article-read group (cdr group-art)))
1844 (kill-buffer (current-buffer)))))))))
1846 (defun gnus-inews-insert-gcc ()
1847 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1850 (message-narrow-to-headers)
1851 (let* ((group gnus-outgoing-message-group)
1855 ((or (stringp group) (listp group))
1860 (if (string-match " " gcc)
1861 (concat "\"" gcc "\"")
1863 (mapconcat (lambda (group)
1864 (if (string-match " " group)
1865 (concat "\"" group "\"")
1870 (defun gnus-inews-insert-archive-gcc (&optional group)
1871 "Insert the Gcc to say where the article is to be archived."
1872 (let* ((var gnus-message-archive-group)
1873 (group (or group gnus-newsgroup-name ""))
1875 (and gnus-newsgroup-name
1876 (not (equal gnus-newsgroup-name ""))
1877 (gnus-group-find-parameter
1878 gnus-newsgroup-name 'gcc-self)))
1882 ((null gnus-message-archive-method)
1886 ;; Just a single group.
1889 ;; We don't want this.
1891 ((and (listp var) (stringp (car var)))
1892 ;; A list of groups.
1896 (funcall var group))
1898 ;; An alist of regexps/functions/forms.
1903 ((stringp (caar var))
1905 (when (string-match (caar var) group)
1907 ((functionp (car var))
1909 (funcall (car var) group))
1911 (eval (car var)))))))
1912 (setq var (cdr var)))
1915 (when (or groups gcc-self-val)
1916 (when (stringp groups)
1917 (setq groups (list groups)))
1920 (message-narrow-to-headers)
1921 (goto-char (point-max))
1924 ;; Use the `gcc-self' param value instead.
1927 (if (stringp gcc-self-val)
1928 (if (string-match " " gcc-self-val)
1929 (concat "\"" gcc-self-val "\"")
1931 ;; In nndoc groups, we use the parent group name
1932 ;; instead of the current group.
1933 (let ((group (or (gnus-group-find-parameter
1934 gnus-newsgroup-name 'parent-group)
1936 (if (string-match " " group)
1937 (concat "\"" group "\"")
1939 (if (not (eq gcc-self-val 'none))
1941 (gnus-delete-line)))
1942 ;; Use the list of groups.
1943 (while (setq name (pop groups))
1944 (let ((str (if (string-match ":" name)
1946 (gnus-group-prefixed-name
1947 name gnus-message-archive-method))))
1948 (insert (if (string-match " " str)
1949 (concat "\"" str "\"")
1955 (defun gnus-mailing-list-followup-to ()
1956 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1957 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1958 (list-post (gnus-fetch-original-field "list-post")))
1959 (when (and list-post
1960 (string-match "mailto:\\([^>]+\\)" list-post))
1961 (setq list-post (match-string 1 list-post)))
1967 (defun gnus-configure-posting-styles (&optional group-name)
1968 "Configure posting styles according to `gnus-posting-styles'."
1969 (unless gnus-inhibit-posting-styles
1970 (let ((group (or group-name gnus-newsgroup-name ""))
1971 (styles gnus-posting-styles)
1972 style match attribute results
1974 ;; If the group has a posting-style parameter, add it at the end with a
1975 ;; regexp matching everything, to be sure it takes precedence over all
1977 (when gnus-newsgroup-name
1978 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1980 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1981 ;; Go through all styles and look for matches.
1982 (dolist (style styles)
1983 (setq match (pop style))
1984 (goto-char (point-min))
1987 ;; Regexp string match on the group name.
1988 (string-match match group))
1990 ;; Obsolete format of header match.
1991 (and (gnus-buffer-live-p gnus-article-copy)
1992 (with-current-buffer gnus-article-copy
1994 (nnheader-narrow-to-headers)
1995 (let ((header (message-fetch-field (pop style))))
1997 (string-match (pop style) header)))))))
1998 ((or (symbolp match)
2002 ;; Function to be called.
2005 ;; Variable to be checked.
2006 (symbol-value match))))
2009 ((eq (car match) 'header)
2010 ;; New format of header match.
2011 (and (gnus-buffer-live-p gnus-article-copy)
2012 (with-current-buffer gnus-article-copy
2014 (nnheader-narrow-to-headers)
2015 (let ((header (message-fetch-field (nth 1 match))))
2017 (string-match (nth 2 match) header)))))))
2019 ;; This is a form to be evaled.
2021 ;; We have a match, so we set the variables.
2022 (setq style (gnus-configure-posting-style style nil))
2023 (dolist (attribute style)
2024 (setq results (delq (assoc (car attribute) results) results))
2025 (push attribute results))))
2026 ;; Now we have all the styles, so we insert them.
2027 (setq name (assq 'name results)
2028 address (assq 'address results))
2029 (setq results (delq name (delq address results)))
2030 (gnus-make-local-hook 'message-setup-hook)
2031 (setq results (sort results (lambda (x y)
2032 (string-lessp (car x) (car y)))))
2033 (dolist (result results)
2034 (add-hook 'message-setup-hook
2036 ((eq 'eval (car result))
2038 ((eq 'body (car result))
2042 (insert ,(cdr result)))))
2043 ((eq 'signature (car result))
2044 (set (make-local-variable 'message-signature) nil)
2045 (set (make-local-variable 'message-signature-file) nil)
2046 (if (not (cdr result))
2050 (let ((message-signature ,(cdr result)))
2051 (when message-signature
2052 (message-insert-signature)))))))
2055 (if (symbolp (car result))
2056 (capitalize (symbol-name (car result)))
2060 (message-remove-header ,header)
2061 (let ((value ,(cdr result)))
2064 (insert ,header ": " value)
2066 (insert "\n")))))))))
2068 (when (or name address)
2069 (add-hook 'message-setup-hook
2071 (set (make-local-variable 'user-mail-address)
2072 ,(or (cdr address) user-mail-address))
2073 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2075 ,(or (cdr address) user-mail-address)))
2077 (message-remove-header "From")
2079 (insert "From: " (message-make-from) "\n"))))
2082 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2083 (defun gnus-configure-posting-style (style stack)
2084 "Parse one posting style STYLE and returns the value as an alist."
2085 (let (results element variable filep value v)
2086 (dolist (attribute style)
2087 (setq element (pop attribute)
2092 ((eq (car attribute) ':file)
2095 ((eq (car attribute) :value)
2099 ;; We get the value.
2104 ((or (symbolp value)
2106 (cond ((functionp value)
2109 (symbol-value value))))
2112 ;; Translate obsolescent value.
2114 ((eq element 'signature-file)
2115 (setq element 'signature
2117 ((eq element 'x-face-file)
2118 (setq element 'x-face
2120 ;; Get the contents of file elems.
2122 (setq v (with-temp-buffer
2123 (insert-file-contents v)
2124 (buffer-substring (point-min)
2126 (goto-char (point-max))
2127 (if (zerop (skip-chars-backward "\n"))
2130 (if (eq element 'import)
2132 (if (member v stack)
2133 (error "Circular import of \"%s\"" v))
2135 (nconc (nreverse (gnus-configure-posting-style
2136 (cdr (assoc v gnus-named-posting-styles))
2139 (push (cons element v) results)))
2140 (nreverse results)))
2142 (defun gnus-summary-execute-command-with-posting-style (style command)
2143 "Temporarily select a posting-style named STYLE and execute COMMAND."
2145 (let ((style (completing-read "Posting style: "
2146 gnus-named-posting-styles nil t)))
2150 (format "Command to execute with %s: " style))))))
2151 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2152 (call-interactively command)))
2155 ;;; @ for MIME Edit mode
2158 (defun gnus-maybe-setup-default-charset ()
2160 (and (boundp 'gnus-summary-buffer)
2161 (buffer-live-p gnus-summary-buffer)
2163 (set-buffer gnus-summary-buffer)
2164 default-mime-charset))))
2167 (make-local-variable 'default-mime-charset)
2168 (setq default-mime-charset charset)
2172 ;;; @ for MIME view mode
2175 (defun gnus-following-method (buf)
2176 (gnus-setup-message 'reply-yank
2178 (if (message-news-p)
2180 (message-reply nil 'wide))
2181 (let ((message-reply-buffer buf))
2182 (message-yank-original))
2183 (message-goto-body))
2187 ;;; Allow redefinition of functions.
2193 ;;; gnus-msg.el ends here