1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
43 (defcustom gnus-post-method 'current
44 "*Preferred method for posting USENET news.
46 If this variable is `current' (which is the default), Gnus will use
47 the \"current\" select method when posting. If it is `native', Gnus
48 will use the native select method when posting.
50 This method will not be used in mail groups and the like, only in
53 If not `native' nor `current', the value must be a valid method as discussed
54 in the documentation of `gnus-select-method'. It can also be a list of
55 methods. If that is the case, the user will be queried for what select
56 method to use when posting."
57 :group 'gnus-group-foreign
58 :link '(custom-manual "(gnus)Posting Server")
59 :type `(choice (const native)
61 (sexp :tag "Methods" ,gnus-select-method)))
63 (defcustom gnus-outgoing-message-group nil
64 "*All outgoing messages will be put in this group.
65 If you want to store all your outgoing mail and articles in the group
66 \"nnml:archive\", you set this variable to that value. This variable
67 can also be a list of group names.
69 If you want to have greater control over what group to put each
70 message in, you can set this variable to a function that checks the
71 current newsgroup name and then returns a suitable group name (or list
74 :type '(choice (string :tag "Group")
77 (defcustom gnus-mailing-list-groups nil
78 "*If non-nil a regexp matching groups that are really mailing lists.
79 This is useful when you're reading a mailing list that has been
80 gatewayed to a newsgroup, and you want to followup to an article in
83 :type '(choice (regexp)
86 (defcustom gnus-add-to-list nil
87 "*If non-nil, add a `to-list' parameter automatically."
91 (defcustom gnus-crosspost-complaint
94 You posted the article below with the following Newsgroups header:
98 The %s group, at least, was an inappropriate recipient
99 of this message. Please trim your Newsgroups header to exclude this
100 group before posting in the future.
105 "Format string to be inserted when complaining about crossposts.
106 The first %s will be replaced by the Newsgroups header;
107 the second with the current group name."
111 (defcustom gnus-message-setup-hook nil
112 "Hook run after setting up a message buffer."
116 (defcustom gnus-bug-create-help-buffer t
117 "*Should we create the *Gnus Help Bug* buffer?"
121 (defcustom gnus-posting-styles nil
122 "*Alist of styles to use when posting.
123 See Info node `(gnus)Posting Styles'."
125 :link '(custom-manual "(gnus)Posting Styles")
126 :type '(repeat (cons (choice (regexp)
129 (string :tag "Header")
130 (regexp :tag "Regexp"))
134 (choice (const signature)
135 (const signature-file)
143 (string :tag "Header"))
149 (defcustom gnus-named-posting-styles nil
150 "Alist mapping names to the user-defined posting styles."
152 :type '(repeat (cons string
154 (choice (const signature)
155 (const signature-file)
163 (string :tag "Header"))
169 (defcustom gnus-gcc-mark-as-read nil
170 "If non-nil, automatically mark Gcc articles as read."
175 (defvar gnus-inews-mark-gcc-as-read nil
176 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
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 encryped messages to also be signed."
284 (defcustom gnus-confirm-mail-reply-to-news nil
285 "If non-nil, Gnus requests confirmation when replying to news.
286 This is done because new users often reply by mistake when reading
288 This can also be a function receiving the group name as the only
289 parameter which should return non-nil iff a confirmation is needed, or
290 a regexp, in which case a confirmation is asked for iff the group name
293 :type '(choice (const :tag "No" nil)
295 (regexp :tag "Iff group matches regexp")
296 (function :tag "Iff function evaluates to non-nil")))
298 (defcustom gnus-confirm-treat-mail-like-news
300 "If non-nil, Gnus will treat mail like news with regard to confirmation
301 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
302 for fine-tuning this.
303 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'."
314 (defcustom gnus-user-agent 'emacs-gnus-type
315 "Which information should be exposed in the User-Agent header.
317 It can be one of the symbols `gnus' \(show only Gnus version\), `emacs-gnus'
318 \(show only Emacs and Gnus versions\), `emacs-gnus-config' \(same as
319 `emacs-gnus' plus system configuration\), `emacs-gnus-type' \(same as
320 `emacs-gnus' plus system type\) or a custom string. If you set it to a
321 string, be sure to use a valid format, see RFC 2616."
324 (item :tag "Show Gnus and Emacs versions and system type"
326 (item :tag "Show Gnus and Emacs versions and system configuration"
328 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
329 (item :tag "Show only Gnus version" gnus)
330 (string :tag "Other")))
332 ;;; Internal variables.
334 (defvar gnus-inhibit-posting-styles nil
335 "Inhibit the use of posting styles.")
337 (defvar gnus-article-yanked-articles nil)
338 (defvar gnus-message-buffer "*Mail Gnus*")
339 (defvar gnus-article-copy nil)
340 (defvar gnus-check-before-posting nil)
341 (defvar gnus-last-posting-server nil)
342 (defvar gnus-message-group-art nil)
344 (defvar gnus-msg-force-broken-reply-to nil)
346 (defconst gnus-bug-message
347 (format "Sending a bug report to the Gnus Towers.
348 ========================================
350 This gnus is the %s%s.
351 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
352 Developers. (the addresses below are mailing list addresses)
354 ========================================
356 The buffer below is a mail buffer. When you press `C-c C-c', it will
357 be sent to the Gnus Bug Exterminators.
359 The thing near the bottom of the buffer is how the environment
360 settings will be included in the mail. Please do not delete that.
361 They will tell the Bug People what your environment is, so that it
362 will be easier to locate the bugs.
364 If you have found a bug that makes Emacs go \"beep\", set
365 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
366 and include the backtrace in your bug report.
368 Please describe the bug in annoying, painstaking detail.
370 Thank you for your help in stamping out bugs.
373 (if (string= gnus-product-name "Semi-gnus")
375 ", a modified version of Semi-gnus")))
378 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
379 (autoload 'news-setup "rnewspost")
380 (autoload 'news-reply-mode "rnewspost")
381 (autoload 'rmail-dont-reply-to "mail-utils")
382 (autoload 'rmail-output "rmailout"))
386 ;;; Gnus Posting Functions
389 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
390 "p" gnus-summary-post-news
391 "i" gnus-summary-news-other-window
392 "f" gnus-summary-followup
393 "F" gnus-summary-followup-with-original
394 "c" gnus-summary-cancel-article
395 "s" gnus-summary-supersede-article
396 "r" gnus-summary-reply
397 "y" gnus-summary-yank-message
398 "R" gnus-summary-reply-with-original
399 "w" gnus-summary-wide-reply
400 "W" gnus-summary-wide-reply-with-original
401 "v" gnus-summary-very-wide-reply
402 "V" gnus-summary-very-wide-reply-with-original
403 "n" gnus-summary-followup-to-mail
404 "N" gnus-summary-followup-to-mail-with-original
405 "m" gnus-summary-mail-other-window
406 "u" gnus-uu-post-news
407 "\M-c" gnus-summary-mail-crosspost-complaint
408 "Br" gnus-summary-reply-broken-reply-to
409 "BR" gnus-summary-reply-broken-reply-to-with-original
410 "om" gnus-summary-mail-forward
411 "op" gnus-summary-post-forward
412 "Om" gnus-summary-digest-mail-forward
413 "Op" gnus-summary-digest-post-forward
414 "P" gnus-summary-execute-command-with-posting-style)
416 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
417 "b" gnus-summary-resend-bounced-mail
418 ;; "c" gnus-summary-send-draft
419 "r" gnus-summary-resend-message
420 "e" gnus-summary-resend-message-edit)
422 ;;; Internal functions.
424 (defun gnus-inews-make-draft ()
426 (gnus-inews-make-draft-meta-information
427 ,gnus-newsgroup-name ',gnus-article-reply)))
429 (defvar gnus-article-reply nil)
430 (defmacro gnus-setup-message (config &rest forms)
431 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
432 (buffer (make-symbol "gnus-setup-message-buffer"))
433 (article (make-symbol "gnus-setup-message-article"))
434 (yanked (make-symbol "gnus-setup-yanked-articles"))
435 (group (make-symbol "gnus-setup-message-group")))
436 `(let ((,winconf (current-window-configuration))
437 (,buffer (buffer-name (current-buffer)))
438 (,article gnus-article-reply)
439 (,yanked gnus-article-yanked-articles)
440 (,group gnus-newsgroup-name)
441 (message-header-setup-hook
442 (copy-sequence message-header-setup-hook))
443 (message-mode-hook (copy-sequence message-mode-hook))
444 (message-startup-parameter-alist
445 '((reply-buffer . gnus-copy-article-buffer)
446 (original-buffer . gnus-original-article-buffer)
447 (user-agent . Gnus))))
448 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
449 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
450 ;; #### FIXME: for a reason that I did not manage to identify yet,
451 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
452 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
453 ;; After evaluation of @forms below, it gets the value we actually want
454 ;; to override, and the posting styles are used. For that reason, I've
455 ;; added an optional argument to `gnus-configure-posting-styles' to
456 ;; make sure that the correct value for the group name is used. -- drv
457 (add-hook 'message-mode-hook
459 (gnus-configure-posting-styles ,group)))
460 (gnus-pull ',(intern gnus-draft-meta-information-header)
461 message-required-headers)
463 (not (string= ,group "")))
465 (intern gnus-draft-meta-information-header)
466 (gnus-inews-make-draft))
467 message-required-headers))
471 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
473 (setq gnus-message-buffer (current-buffer))
474 (set (make-local-variable 'gnus-message-group-art)
475 (cons ,group ,article))
476 (set (make-local-variable 'gnus-newsgroup-name) ,group)
477 (gnus-maybe-setup-default-charset)
478 (gnus-run-hooks 'gnus-message-setup-hook))
480 (gnus-configure-windows ,config t)
481 (run-hooks 'post-command-hook)
482 (set-buffer-modified-p nil))))
484 (defun gnus-inews-make-draft-meta-information (group article)
485 (concat "(\"" group "\" "
486 (if article (number-to-string
493 (defun gnus-msg-mail (&optional to subject other-headers continue
494 switch-action yank-action send-actions)
495 "Start editing a mail message to be sent.
496 Like `message-mail', but with Gnus paraphernalia, particularly the
497 Gcc: header for archiving purposes."
499 (let ((buf (current-buffer))
501 (gnus-setup-message 'message
502 (message-mail to subject other-headers continue
503 nil yank-action send-actions))
505 (setq mail-buf (current-buffer))
506 (switch-to-buffer buf)
507 (apply switch-action mail-buf nil)))
508 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
511 (defvar save-selected-window-window)
514 (defun gnus-button-mailto (address)
516 (set-buffer (gnus-copy-article-buffer))
517 (gnus-setup-message 'message
518 (message-reply address))
519 (and (boundp 'save-selected-window-window)
520 (not (window-live-p save-selected-window-window))
521 (setq save-selected-window-window (selected-window))))
524 (defun gnus-button-reply (&optional to-address wide)
525 "Like `message-reply'."
527 (gnus-setup-message 'message
528 (message-reply to-address wide))
529 (and (boundp 'save-selected-window-window)
530 (not (window-live-p save-selected-window-window))
531 (setq save-selected-window-window (selected-window))))
534 (define-mail-user-agent 'gnus-user-agent
535 'gnus-msg-mail 'message-send-and-exit
536 'message-kill-buffer 'message-send-hook)
538 (defun gnus-setup-posting-charset (group)
539 (let ((alist gnus-group-posting-charset-alist)
540 (group (or group ""))
544 (while (setq elem (pop alist))
545 (when (or (and (stringp (car elem))
546 (string-match (car elem) group))
547 (and (gnus-functionp (car elem))
548 (funcall (car elem) group))
549 (and (symbolp (car elem))
550 (symbol-value (car elem))))
551 (throw 'found (cons (cadr elem) (caddr elem)))))))))
553 (defun gnus-inews-add-send-actions (winconf buffer article
554 &optional config yanked)
555 (make-local-hook 'message-sent-hook)
556 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
557 'gnus-inews-do-gcc) nil t)
559 (make-local-hook 'message-header-hook)
560 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
561 (setq message-post-method
563 (gnus-post-method arg ,gnus-newsgroup-name)))
564 (setq message-user-agent (gnus-extended-version))
565 (unless message-use-multi-frames
567 `(if (gnus-buffer-exists-p ,buffer)
568 (set-window-configuration ,winconf))
569 'exit 'postpone 'kill))
570 (let ((to-be-marked (cond
572 (article (if (listp article) article (list article)))
575 `(when (gnus-buffer-exists-p ,buffer)
579 (if (eq config 'forward)
580 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
581 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
584 (put 'gnus-setup-message 'lisp-indent-function 1)
585 (put 'gnus-setup-message 'edebug-form-spec '(form body))
587 ;;; Post news commands of Gnus group mode and summary mode
589 (defun gnus-group-mail (&optional arg)
590 "Start composing a mail.
591 If ARG, use the group under the point to find a posting style.
592 If ARG is 1, prompt for a group name to find the posting style."
594 ;; We can't `let' gnus-newsgroup-name here, since that leads
595 ;; to local variables leaking.
596 (let ((group gnus-newsgroup-name)
597 ;; make sure last viewed article doesn't affect posting styles:
599 (buffer (current-buffer)))
602 (setq gnus-newsgroup-name
604 (if (= 1 (prefix-numeric-value arg))
605 (completing-read "Use posting style of group: "
606 gnus-active-hashtb nil
607 (gnus-read-active-file-p))
608 (gnus-group-group-name))
610 ;; #### see comment in gnus-setup-message -- drv
611 (gnus-setup-message 'message (message-mail)))
614 (setq gnus-newsgroup-name group)))))
616 (defun gnus-group-news (&optional arg)
617 "Start composing a news.
618 If ARG, post to group under point.
619 If ARG is 1, prompt for group name to post to.
621 This function prepares a news even when using mail groups. This is useful
622 for posting messages to mail groups without actually sending them over the
623 network. The corresponding backend must have a 'request-post method."
625 ;; We can't `let' gnus-newsgroup-name here, since that leads
626 ;; to local variables leaking.
627 (let ((group gnus-newsgroup-name)
628 ;; make sure last viewed article doesn't affect posting styles:
630 (buffer (current-buffer)))
633 (setq gnus-newsgroup-name
635 (if (= 1 (prefix-numeric-value arg))
636 (completing-read "Use group: "
637 gnus-active-hashtb nil
638 (gnus-read-active-file-p))
639 (gnus-group-group-name))
641 ;; #### see comment in gnus-setup-message -- drv
642 (gnus-setup-message 'message
643 (message-news (gnus-group-real-name gnus-newsgroup-name))))
646 (setq gnus-newsgroup-name group)))))
648 (defun gnus-group-post-news (&optional arg)
649 "Start composing a message (a news by default).
650 If ARG, post to group under point. If ARG is 1, prompt for group name.
651 Depending on the selected group, the message might be either a mail or
654 ;; Bind this variable here to make message mode hooks work ok.
655 (let ((gnus-newsgroup-name
657 (if (= 1 (prefix-numeric-value arg))
658 (completing-read "Newsgroup: " gnus-active-hashtb nil
659 (gnus-read-active-file-p))
660 (gnus-group-group-name))
662 ;; make sure last viewed article doesn't affect posting styles:
664 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
665 (string= gnus-newsgroup-name ""))))
667 (defun gnus-summary-mail-other-window (&optional arg)
668 "Start composing a mail in another window.
669 Use the posting of the current group by default.
670 If ARG, don't do that. If ARG is 1, prompt for group name to find the
673 ;; We can't `let' gnus-newsgroup-name here, since that leads
674 ;; to local variables leaking.
675 (let ((group gnus-newsgroup-name)
676 ;; make sure last viewed article doesn't affect posting styles:
678 (buffer (current-buffer)))
681 (setq gnus-newsgroup-name
683 (if (= 1 (prefix-numeric-value arg))
684 (completing-read "Use group: "
685 gnus-active-hashtb nil
686 (gnus-read-active-file-p))
688 gnus-newsgroup-name))
689 ;; #### see comment in gnus-setup-message -- drv
690 (gnus-setup-message 'message (message-mail)))
693 (setq gnus-newsgroup-name group)))))
695 (defun gnus-summary-news-other-window (&optional arg)
696 "Start composing a news in another window.
697 Post to the current group by default.
698 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
700 This function prepares a news even when using mail groups. This is useful
701 for posting messages to mail groups without actually sending them over the
702 network. The corresponding backend must have a 'request-post method."
704 ;; We can't `let' gnus-newsgroup-name here, since that leads
705 ;; to local variables leaking.
706 (let ((group gnus-newsgroup-name)
707 ;; make sure last viewed article doesn't affect posting styles:
709 (buffer (current-buffer)))
712 (setq gnus-newsgroup-name
714 (if (= 1 (prefix-numeric-value arg))
715 (completing-read "Use group: "
716 gnus-active-hashtb nil
717 (gnus-read-active-file-p))
719 gnus-newsgroup-name))
720 ;; #### see comment in gnus-setup-message -- drv
721 (gnus-setup-message 'message
722 (message-news (gnus-group-real-name gnus-newsgroup-name))))
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 two following numbers is the region to be
754 (list (and current-prefix-arg
755 (gnus-summary-work-articles 1))))
757 (gnus-summary-goto-subject
758 (if (listp (car yank))
761 (save-window-excursion
762 (gnus-summary-select-article))
763 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
764 (gnus-newsgroup-name gnus-newsgroup-name))
766 (gnus-post-news nil gnus-newsgroup-name
767 headers gnus-article-buffer
769 (gnus-summary-handle-replysign)))
771 (defun gnus-summary-followup-with-original (n &optional force-news)
772 "Compose a followup to an article and include the original article."
774 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
776 (defun gnus-summary-followup-to-mail (&optional arg)
777 "Followup to the current mail message via news."
779 (list (and current-prefix-arg
780 (gnus-summary-work-articles 1))))
781 (gnus-summary-followup arg t))
783 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
784 "Followup to the current mail message via news."
786 (gnus-summary-followup (gnus-summary-work-articles arg) t))
788 (defun gnus-inews-yank-articles (articles)
789 (let (beg article yank-string
790 (more-than-one (cdr articles))
791 (cur (current-buffer))
794 (while (setq article (pop articles))
795 (when (listp article)
796 (setq yank-string (nth 1 article)
797 article (nth 0 article)))
798 (save-window-excursion
799 (set-buffer gnus-summary-buffer)
800 (gnus-summary-select-article nil nil nil article)
801 (gnus-summary-remove-process-mark article))
803 ;; Gathering references.
805 (setq refs (message-list-references
807 (mail-header-references gnus-current-headers)
808 (mail-header-message-id gnus-current-headers)))
809 (when message-use-multi-frames
810 (when (setq window (get-buffer-window cur t))
811 (select-frame (window-frame window)))))
813 (gnus-copy-article-buffer nil yank-string)
814 (let ((message-reply-buffer gnus-article-copy)
815 (message-reply-headers
816 ;; The headers are decoded.
817 (with-current-buffer gnus-article-copy
819 (nnheader-narrow-to-headers)
820 (nnheader-parse-naked-head)))))
821 (message-yank-original)
822 (setq beg (or beg (mark t))))
827 ;; Replace with the gathered references.
831 (message-narrow-to-headers)
832 (let ((case-fold-search t))
833 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
835 (goto-char (point-max))))
837 (list (or (assq 'References message-header-format-alist)
838 '(References . message-shorten-references)))
839 (list (cons 'References
840 (mapconcat 'identity (nreverse refs) " "))))
841 (backward-delete-char 1))
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 ((articles (gnus-summary-work-articles n))
856 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
858 (while (setq article (pop articles))
859 (when (gnus-summary-select-article t nil nil article)
860 (when (gnus-eval-in-buffer-window gnus-article-buffer
862 (set-buffer gnus-original-article-buffer)
863 (message-cancel-news)))
864 (gnus-summary-mark-as-read article gnus-canceled-mark)
865 (gnus-cache-remove-article 1))
866 (gnus-article-hide-headers-if-wanted))
867 (gnus-summary-remove-process-mark article))))
869 (defun gnus-summary-supersede-article ()
870 "Compose an article that will supersede a previous article.
871 This is done simply by taking the old article and adding a Supersedes
872 header line with the old Message-ID."
874 (let ((article (gnus-summary-article-number)))
875 (gnus-setup-message 'reply-yank
876 (gnus-summary-select-article t)
877 (set-buffer gnus-original-article-buffer)
881 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
883 (set-buffer ,gnus-summary-buffer)
884 (gnus-cache-possibly-remove-article ,article nil nil nil t)
885 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
886 message-send-actions))))
890 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
891 ;; make a copy of the article buffer with all text properties removed
892 ;; this copy is in the buffer gnus-article-copy.
893 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
894 ;; this buffer should be passed to all mail/news reply/post routines.
895 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
897 (set-buffer gnus-article-copy)
898 (set-buffer-multibyte t))
899 (let ((article-buffer (or article-buffer gnus-article-buffer))
901 (if (not (and (get-buffer article-buffer)
902 (gnus-buffer-exists-p article-buffer)))
903 (error "Can't find any article buffer")
905 (set-buffer article-buffer)
906 (let ((gnus-newsgroup-charset (or gnus-article-charset
907 gnus-newsgroup-charset))
908 (gnus-newsgroup-ignored-charsets
909 (or gnus-article-ignored-charsets
910 gnus-newsgroup-ignored-charsets)))
912 ;; Copy over the (displayed) article buffer, delete
913 ;; hidden text and remove text properties.
915 (copy-to-buffer gnus-article-copy (point-min) (point-max))
916 (set-buffer gnus-article-copy)
917 ;; There's invisible and intangible text in T-gnus. Especially,
918 ;; if there is a boundary line (X-Boundary: ------------------),
919 ;; in the end of a header, it will cause a serious problem.
920 (add-text-properties (point-min) (point-max)
921 '(invisible nil intangible nil))
924 (delete-region (point) (point-max))
925 (insert yank-string))
926 ;; Encode bitmap smileys to ordinary text.
927 ;; Possibly, the original text might be restored.
928 (static-unless (featurep 'xemacs)
929 (when (featurep 'smiley-mule)
930 (smiley-encode-buffer)))
931 (gnus-article-delete-text-of-type 'annotation)
932 (gnus-remove-text-with-property 'gnus-prev)
933 (gnus-remove-text-with-property 'gnus-next)
934 (gnus-remove-text-with-property 'gnus-decoration)
935 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
938 (static-if (featurep 'xemacs)
939 ;; Revome smiley extents for (possibly) XEmacs 21.1.
941 (buffer-substring-no-properties (point-min)
943 (buffer-substring-no-properties (point-min) (point-max)))
945 ;; Find the original headers.
946 (set-buffer gnus-original-article-buffer)
947 (goto-char (point-min))
948 (while (looking-at message-unix-mail-delimiter)
950 (let ((mail-header-separator ""))
952 end (or (message-goto-body)
953 ;; There may be just a header.
955 ;; Delete the headers from the displayed articles.
956 (set-buffer gnus-article-copy)
957 (let ((mail-header-separator ""))
958 (delete-region (goto-char (point-min))
959 (or (message-goto-body) (point-max))))
960 ;; Insert the original article headers.
961 (insert-buffer-substring gnus-original-article-buffer beg end)
963 (let ((gnus-article-decode-hook
964 (delq 'article-decode-charset
965 (copy-sequence gnus-article-decode-hook))))
966 ;; Needed for T-gnus.
967 (add-hook 'gnus-article-decode-hook
968 'article-decode-encoded-words)
969 (run-hooks 'gnus-article-decode-hook)))))
972 (defun gnus-post-news (post &optional group header article-buffer yank subject
975 (gnus-copy-article-buffer))
976 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
977 (gnus-article-yanked-articles yank)
978 (add-to-list gnus-add-to-list))
979 (gnus-setup-message (cond (yank 'reply-yank)
980 (article-buffer 'reply)
982 (let* ((group (or group gnus-newsgroup-name))
983 (charset (gnus-group-name-charset nil group))
985 to-address to-group mailing-list to-list
988 (setq to-address (gnus-parameter-to-address group)
989 to-group (gnus-group-find-parameter group 'to-group)
990 to-list (gnus-parameter-to-list group)
991 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
992 mailing-list (when gnus-mailing-list-groups
993 (string-match gnus-mailing-list-groups group))
994 group (gnus-group-name-decode (gnus-group-real-name group)
996 (if (or (and to-group
997 (gnus-news-group-p to-group))
1000 (and (gnus-news-group-p
1001 (or pgroup gnus-newsgroup-name)
1002 (or header gnus-current-article))
1008 (message-news (or to-group 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 include-mime-info max-column
1124 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1125 variable `mime-edit-user-agent-value' is bound, the value will be
1126 included in the return value. If MAX-COLUMN is specified, the return
1127 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1128 whether a newline should be inserted in front of each product-token.
1129 If the value is t or `hard', it works strictly. Otherwise, if it is
1130 non-nil (e.g. `soft'), it works semi-strictly.
1132 Here is an example of how to use this function:
1134 \(add-hook 'gnus-message-setup-hook
1136 (setq message-user-agent nil)
1139 (message-narrow-to-headers)
1140 (goto-char (point-max))
1141 (insert \"User-Agent: \"
1142 (gnus-message-make-user-agent t 76 'soft)
1145 (let ((user-agent (if (and include-mime-info
1146 (boundp 'mime-edit-user-agent-value))
1147 (concat (gnus-extended-version)
1149 mime-edit-user-agent-value)
1150 (gnus-extended-version))))
1152 (unless (natnump max-column)
1153 (setq max-column 76))
1155 (set-buffer-multibyte t)
1156 (insert (mapconcat 'identity (split-string user-agent) " "))
1157 (goto-char (point-min))
1159 start agent agents width element swidth)
1160 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1161 (setq start (match-beginning 0))
1162 (if (eq (char-after start) ?\()
1166 (push (buffer-substring start (point)) agent))
1168 (push (nreverse agent) agents))
1169 (setq agent (list (match-string 1)))))
1171 (push (nreverse agent) agents))
1172 (setq agents (nreverse agents))
1173 (if (> (+ 12 (string-width (caar agents))) max-column)
1174 (setq user-agent "\n"
1179 (setq agent (car agents)
1180 agents (cdr agents))
1181 (when (and (not bol)
1182 (or (memq newline-product '(t hard))
1183 (and newline-product
1185 (string-width (mapconcat 'identity
1188 (setq user-agent (concat user-agent "\n")
1192 (setq element (car agent)
1193 swidth (string-width element)
1196 (setq user-agent (if (member user-agent '("" "\n"))
1197 (concat user-agent element)
1198 (concat user-agent " " element))
1199 width (+ width 1 swidth)
1201 (if (> (+ width 1 swidth) max-column)
1202 (setq user-agent (concat user-agent "\n " element)
1204 (setq user-agent (concat user-agent " " element)
1205 width (+ width 1 swidth)))))))))
1210 ;;; Gnus Mail Functions
1213 ;;; Mail reply commands of Gnus summary mode
1215 (defun gnus-summary-reply (&optional yank wide very-wide)
1216 "Start composing a mail reply to the current message.
1217 If prefix argument YANK is non-nil, the original article is yanked
1219 If WIDE, make a wide reply.
1220 If VERY-WIDE, make a very wide reply."
1222 (list (and current-prefix-arg
1223 (gnus-summary-work-articles 1))))
1224 ;; Allow user to require confirmation before replying by mail to the
1225 ;; author of a news article (or mail message).
1227 (not (or (gnus-news-group-p gnus-newsgroup-name)
1228 gnus-confirm-treat-mail-like-news))
1229 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1230 (string-match gnus-confirm-mail-reply-to-news
1231 gnus-newsgroup-name))
1232 ((functionp gnus-confirm-mail-reply-to-news)
1233 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1234 (t gnus-confirm-mail-reply-to-news)))
1235 (y-or-n-p "Really reply by mail to article author? "))
1237 (if (listp (car yank))
1240 (gnus-article-reply (or article (gnus-summary-article-number)))
1241 (gnus-article-yanked-articles yank)
1243 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1245 (gnus-summary-goto-subject article))
1246 (gnus-setup-message (if yank 'reply-yank 'reply)
1248 (gnus-summary-select-article)
1249 (dolist (article very-wide)
1250 (gnus-summary-select-article nil nil nil article)
1252 (set-buffer (gnus-copy-article-buffer))
1253 (gnus-msg-treat-broken-reply-to)
1255 (message-narrow-to-head)
1256 (setq headers (concat headers (buffer-string)))))))
1257 (set-buffer (gnus-copy-article-buffer))
1258 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1260 (message-narrow-to-head)
1264 (goto-char (point-max)))
1265 (message-reply nil wide)
1267 (gnus-inews-yank-articles yank))
1268 (gnus-summary-handle-replysign)))))
1270 (defun gnus-summary-handle-replysign ()
1271 "Check the various replysign variables and take action accordingly."
1272 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1273 (let (signed encrypted)
1275 (set-buffer gnus-article-buffer)
1276 (setq signed (memq 'signed gnus-article-wash-types))
1277 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1278 (cond ((and gnus-message-replyencrypt encrypted)
1279 (mml-secure-message mml-default-encrypt-method
1280 (if gnus-message-replysignencrypted
1283 ((and gnus-message-replysign signed)
1284 (mml-secure-message mml-default-sign-method 'sign))))))
1286 (defun gnus-summary-reply-with-original (n &optional wide)
1287 "Start composing a reply mail to the current message.
1288 The original article will be yanked."
1290 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1292 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1293 "Like `gnus-summary-reply' except removing reply-to field.
1294 If prefix argument YANK is non-nil, the original article is yanked
1296 If WIDE, make a wide reply.
1297 If VERY-WIDE, make a very wide reply."
1299 (list (and current-prefix-arg
1300 (gnus-summary-work-articles 1))))
1301 (let ((gnus-msg-force-broken-reply-to t))
1302 (gnus-summary-reply yank wide very-wide)))
1304 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1305 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1306 The original article will be yanked."
1308 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1310 (defun gnus-summary-wide-reply (&optional yank)
1311 "Start composing a wide reply mail to the current message.
1312 If prefix argument YANK is non-nil, the original article is yanked
1315 (list (and current-prefix-arg
1316 (gnus-summary-work-articles 1))))
1317 (gnus-summary-reply yank t))
1319 (defun gnus-summary-wide-reply-with-original (n)
1320 "Start composing a wide reply mail to the current message.
1321 The original article will be yanked."
1323 (gnus-summary-reply-with-original n t))
1325 (defun gnus-summary-very-wide-reply (&optional yank)
1326 "Start composing a very wide reply mail to the current message.
1327 If prefix argument YANK is non-nil, the original article is yanked
1330 (list (and current-prefix-arg
1331 (gnus-summary-work-articles 1))))
1332 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1334 (defun gnus-summary-very-wide-reply-with-original (n)
1335 "Start composing a very wide reply mail to the current message.
1336 The original article will be yanked."
1339 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1341 (defun gnus-summary-mail-forward (&optional full-headers post)
1342 "Forward the current message(s) to another user.
1343 If process marks exist, forward all marked messages;
1344 If FULL-HEADERS (the prefix), include full headers when forwarding.
1346 Note that this function definition for T-gnus is totally different
1347 from the original Gnus."
1349 (if (cdr (gnus-summary-work-articles nil))
1350 ;; Process marks are given.
1351 (gnus-summary-digest-mail-forward nil post)
1352 ;; No process marks.
1353 (let* ((gnus-article-reply (gnus-summary-article-number))
1354 (gnus-article-yanked-articles (list gnus-article-reply))
1356 (message-included-forward-headers
1357 (if full-headers "" message-included-forward-headers)))
1358 (gnus-setup-message 'forward
1359 (gnus-summary-select-article)
1360 (setq charset default-mime-charset)
1361 (set-buffer gnus-original-article-buffer)
1362 (make-local-variable 'default-mime-charset)
1363 (setq default-mime-charset charset)
1364 (message-forward post)))))
1366 (defun gnus-summary-digest-mail-forward (&optional n post)
1367 "Digests and forwards all articles in this series.
1368 If N is a positive number, forward the N next articles.
1369 If N is a negative number, forward the N previous articles.
1370 If N is nil and any articles have been marked with the process mark,
1371 forward those articles instead.
1372 Optional POST will use news to forward instead of mail."
1374 (let* ((articles (gnus-summary-work-articles n))
1375 (gnus-article-yanked-articles (copy-sequence articles))
1376 (topics "Topics:\n")
1377 subject article frame)
1378 (when (car articles)
1379 (gnus-setup-message 'forward
1380 (gnus-summary-select-article)
1382 (setq articles (sort articles '<)
1383 subject "Digested Articles")
1384 (with-current-buffer gnus-original-article-buffer
1385 (setq subject (message-make-forward-subject))))
1387 (message-news nil subject)
1388 (message-mail nil subject))
1389 (when (and message-use-multi-frames (cdr articles))
1390 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1392 (while (setq article (pop articles))
1393 (save-window-excursion
1394 (set-buffer gnus-summary-buffer)
1395 (gnus-summary-select-article nil nil nil article)
1396 (setq topics (concat topics " "
1397 (mail-header-subject gnus-current-headers)
1399 (gnus-summary-remove-process-mark article))
1401 (select-frame frame))
1402 (insert (mime-make-tag "message" "rfc822") "\n")
1403 (narrow-to-region (point) (point))
1404 (insert-buffer-substring gnus-original-article-buffer)
1406 (article-narrow-to-head)
1407 (message-remove-header message-included-forward-headers t nil t))
1408 (goto-char (point-max))
1414 (mime-edit-enclose-digest-region (point)(mark t))))))
1416 (defun gnus-summary-digest-post-forward (&optional n)
1417 "Digest and forwards all articles in this series to a newsgroup.
1418 If N is a positive number, forward the N next articles.
1419 If N is a negative number, forward the N previous articles.
1420 If N is nil and any articles have been marked with the process mark,
1421 forward those articles instead."
1423 (gnus-summary-digest-mail-forward n t))
1425 (defun gnus-summary-resend-message (address n)
1426 "Resend the current article to ADDRESS."
1428 (list (message-read-from-minibuffer
1429 "Resend message(s) to: "
1430 (when (and gnus-summary-resend-default-address
1431 (gnus-buffer-live-p gnus-original-article-buffer))
1432 ;; If some other article is currently selected, the
1433 ;; initial-contents is wrong. Whatever, it is just the
1434 ;; initial-contents.
1435 (with-current-buffer gnus-original-article-buffer
1436 (nnmail-fetch-field "to"))))
1437 current-prefix-arg))
1438 (let ((articles (gnus-summary-work-articles n))
1440 (while (setq article (pop articles))
1441 (gnus-summary-select-article nil nil nil article)
1443 (set-buffer gnus-original-article-buffer)
1444 (message-resend address))
1445 (gnus-summary-mark-article-as-forwarded article))))
1447 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1448 (defun gnus-summary-resend-message-edit ()
1449 "Resend an article that has already been sent.
1450 A new buffer will be created to allow the user to modify body and
1451 contents of the message, and then, everything will happen as when
1452 composing a new message."
1454 (let ((article (gnus-summary-article-number)))
1455 (gnus-setup-message 'reply-yank
1456 (gnus-summary-select-article t)
1457 (set-buffer gnus-original-article-buffer)
1458 (let ((cur (current-buffer))
1459 (to (message-fetch-field "to")))
1460 ;; Get a normal message buffer.
1461 (message-pop-to-buffer (message-buffer-name "Resend" to))
1462 (insert-buffer-substring cur)
1464 ;; T-gnus change: Use MIME-Edit to recompose a message.
1466 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1467 (fset 'mime-edit-decode-single-part-in-buffer
1468 (lambda (&rest args)
1469 (if (let ((content-type (car args)))
1470 (and (eq 'message (mime-content-type-primary-type
1472 (eq 'rfc822 (mime-content-type-subtype
1474 (setcar (cdr args) 'not-decode-text))
1477 (mime-edit-again nil t)
1478 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1479 (message-narrow-to-head-1)
1480 (insert "From: " (message-make-from) "\n")
1481 (while (re-search-forward "^From:" nil t)
1483 (insert "Original-"))
1484 (message-remove-header "^>From[\t ]" t)
1486 ;; Gnus will generate a new one when sending.
1487 (message-remove-header "Message-ID")
1488 (message-remove-header message-ignored-resent-headers t)
1489 ;; Remove unwanted headers.
1490 (goto-char (point-max))
1491 (insert mail-header-separator)
1492 (goto-char (point-min))
1493 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1497 (defun gnus-summary-post-forward (&optional full-headers)
1498 "Forward the current article to a newsgroup.
1499 If FULL-HEADERS (the prefix), include full headers when forwarding."
1501 (gnus-summary-mail-forward full-headers t))
1503 (defvar gnus-nastygram-message
1504 "The following article was inappropriately posted to %s.\n\n"
1505 "Format string to insert in nastygrams.
1506 The current group name will be inserted at \"%s\".")
1508 (defun gnus-summary-mail-nastygram (n)
1509 "Send a nastygram to the author of the current article."
1511 (when (or gnus-expert-user
1513 "Really send a nastygram to the author of the current article? "))
1514 (let ((group gnus-newsgroup-name))
1515 (gnus-summary-reply-with-original n)
1516 (set-buffer gnus-message-buffer)
1518 (insert (format gnus-nastygram-message group))
1519 (message-send-and-exit))))
1521 (defun gnus-summary-mail-crosspost-complaint (n)
1522 "Send a complaint about crossposting to the current article(s)."
1524 (let ((articles (gnus-summary-work-articles n))
1526 (while (setq article (pop articles))
1527 (set-buffer gnus-summary-buffer)
1528 (gnus-summary-goto-subject article)
1529 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1530 newsgroups followup-to)
1531 (gnus-summary-select-article)
1532 (set-buffer gnus-original-article-buffer)
1533 (if (and (<= (length (message-tokenize-header
1535 (mail-fetch-field "newsgroups"))
1538 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1539 (not (member group (message-tokenize-header
1540 followup-to ", ")))))
1542 (gnus-message 1 "Followup-to restricted")
1543 (gnus-message 1 "Not a crossposted article"))
1544 (set-buffer gnus-summary-buffer)
1545 (gnus-summary-reply-with-original 1)
1546 (set-buffer gnus-message-buffer)
1548 (insert (format gnus-crosspost-complaint newsgroups group))
1549 (message-goto-subject)
1550 (re-search-forward " *$")
1551 (replace-match " (crosspost notification)" t t)
1552 (gnus-deactivate-mark)
1553 (when (gnus-y-or-n-p "Send this complaint? ")
1554 (message-send-and-exit)))))))
1556 (defun gnus-mail-parse-comma-list ()
1559 (skip-chars-forward " ")
1562 (skip-chars-forward "^,")
1567 (narrow-to-region beg (point))
1570 (while (search-forward "\"" nil t)
1574 (skip-chars-forward ",")
1575 (skip-chars-forward "^,"))
1576 (skip-chars-backward " ")
1577 (push (buffer-substring beg (point))
1579 (skip-chars-forward "^,")
1580 (skip-chars-forward ", "))
1583 (defun gnus-inews-add-to-address (group)
1584 (let ((to-address (mail-fetch-field "to")))
1585 (when (and to-address
1587 ;; This mail group doesn't have a `to-list', so we add one
1589 (when (gnus-y-or-n-p
1590 (format "Do you want to add this as `to-list': %s " to-address))
1591 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1593 (defun gnus-put-message ()
1594 "Put the current message in some group and return to Gnus."
1596 (let ((reply gnus-article-reply)
1597 (winconf gnus-prev-winconf)
1598 (group gnus-newsgroup-name))
1600 (not (gnus-group-read-only-p group)))
1601 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1603 (when (gnus-gethash group gnus-newsrc-hashtb)
1604 (error "No such group: %s" group))
1608 (message-narrow-to-headers)
1609 (let ((gnus-deletable-headers nil))
1610 (message-generate-headers
1611 (if (message-news-p)
1612 message-required-news-headers
1613 message-required-mail-headers)))
1614 (goto-char (point-max))
1615 (if (string-match " " group)
1616 (insert "Gcc: \"" group "\"\n")
1617 (insert "Gcc: " group "\n"))
1620 (when (and (get-buffer gnus-group-buffer)
1621 (gnus-buffer-exists-p (car-safe reply))
1623 (set-buffer (car reply))
1624 (gnus-summary-mark-article-as-replied (cdr reply)))
1626 (set-window-configuration winconf))))
1628 (defun gnus-article-mail (yank)
1629 "Send a reply to the address near point.
1630 If YANK is non-nil, include the original article."
1634 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1635 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1637 (gnus-msg-mail address)
1639 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1641 (defvar nntp-server-type)
1643 "Send a bug report to the Gnus maintainers."
1645 (unless (gnus-alive-p)
1646 (error "Gnus has been shut down"))
1647 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1648 (unless (message-mail-user-agent)
1649 (message-pop-to-buffer "*Gnus Bug*")
1650 (delete-other-windows)
1651 (when gnus-bug-create-help-buffer
1652 (switch-to-buffer "*Gnus Help Bug*")
1654 (insert gnus-bug-message)
1655 (goto-char (point-min))
1657 (set-buffer "*Gnus Bug*")))
1658 (let ((message-this-is-mail t))
1659 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1660 (when gnus-bug-create-help-buffer
1661 (push `(gnus-bug-kill-buffer) message-send-actions))
1662 (goto-char (point-min))
1663 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1665 (insert gnus-product-name " " gnus-version-number
1666 " (r" gnus-revision-number ") "
1667 "based on " gnus-original-product-name " v"
1668 gnus-original-version-number "\n"
1669 (emacs-version) "\n")
1670 (when (and (boundp 'nntp-server-type)
1671 (stringp nntp-server-type))
1672 (insert nntp-server-type))
1673 (insert "\n\n\n\n\n")
1674 (let (mime-content-types)
1675 (mime-edit-insert-tag
1676 "application" "emacs-lisp"
1677 "\nContent-Disposition: inline\nContent-Description: User settings"))
1678 (insert (with-temp-buffer
1681 (let (mime-content-types)
1682 (mime-edit-insert-tag "text" "plain"))
1683 (goto-char (point-min))
1684 (search-forward "Subject: " nil t)
1687 (defun gnus-bug-kill-buffer ()
1688 (when (get-buffer "*Gnus Help Bug*")
1689 (kill-buffer "*Gnus Help Bug*")))
1691 (defun gnus-summary-yank-message (buffer n)
1692 "Yank the current article into a composed message."
1694 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1695 current-prefix-arg))
1696 (when (gnus-buffer-live-p buffer)
1697 (let ((summary-frame (selected-frame))
1698 (message-frame (when (static-if (featurep 'xemacs)
1699 (device-on-window-system-p)
1701 (let ((window (get-buffer-window buffer t)))
1703 (window-frame window)))))
1704 (separator (concat "^" (regexp-quote mail-header-separator)
1706 (gnus-summary-iterate n
1707 (gnus-summary-select-article)
1708 (gnus-copy-article-buffer)
1709 (when (frame-live-p message-frame)
1710 (raise-frame message-frame)
1711 (select-frame message-frame))
1712 (with-current-buffer buffer
1713 (when (save-excursion
1715 (let (case-fold-search)
1716 (and (not (re-search-backward separator nil t))
1717 (re-search-forward separator nil t))))
1718 (goto-char (match-end 0)))
1719 (message-yank-buffer gnus-article-copy))
1720 (select-frame summary-frame))
1721 (when (frame-live-p message-frame)
1722 (select-frame message-frame)))))
1724 (defun gnus-debug ()
1725 "Attempts to go through the Gnus source file and report what variables have been changed.
1726 The source file has to be in the Emacs load path."
1728 (let ((files gnus-debug-files)
1730 file expr olist sym)
1731 (gnus-message 4 "Please wait while we snoop your variables...")
1732 ;; Go through all the files looking for non-default values for variables.
1735 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1738 (when (and (setq file (locate-library (pop files)))
1739 (file-exists-p file))
1740 (insert-file-contents file)
1741 (goto-char (point-min))
1742 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1743 (gnus-message 4 "Malformed sources in file %s" file)
1744 (narrow-to-region (point-min) (point))
1745 (goto-char (point-min))
1746 (while (setq expr (ignore-errors (read (current-buffer))))
1748 (and (memq (car expr) '(defvar defcustom defvoo))
1749 (stringp (nth 3 expr))
1750 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1751 (or (not (boundp (nth 1 expr)))
1752 (not (equal (eval (nth 2 expr))
1753 (symbol-value (nth 1 expr)))))
1754 (push (nth 1 expr) olist)))))))
1755 (kill-buffer (current-buffer)))
1756 (when (setq olist (nreverse olist))
1757 (insert ";----------------- Environment follows ------------------\n\n"))
1759 (if (boundp (car olist))
1761 (pp `(setq ,(car olist)
1762 ,(if (or (consp (setq sym (symbol-value (car olist))))
1764 (not (or (eq sym nil)
1766 (list 'quote (symbol-value (car olist)))
1767 (symbol-value (car olist))))
1769 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1770 (setq olist (cdr olist)))
1771 ;; Remove any control chars - they seem to cause trouble for some
1772 ;; mailers. (Byte-compiled output from the stuff above.)
1774 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1775 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1777 ;; Break MIME tags purposely.
1779 (while (re-search-forward mime-edit-tag-regexp nil t)
1780 (goto-char (1+ (match-beginning 0)))
1783 ;;; Treatment of rejected articles.
1786 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1787 "Re-mail the current message.
1788 This only makes sense if the current message is a bounce message than
1789 contains some mail you have written which has been bounced back to
1791 If FETCH, try to fetch the article that this is a reply to, if indeed
1794 (gnus-summary-select-article t)
1795 (set-buffer gnus-original-article-buffer)
1796 (gnus-setup-message 'compose-bounce
1797 (let* ((references (mail-fetch-field "references"))
1798 (parent (and references (gnus-parent-id references))))
1800 ;; If there are references, we fetch the article we answered to.
1802 (gnus-summary-refer-article parent)
1803 (gnus-summary-show-all-headers)))))
1807 (defun gnus-inews-group-method (group)
1809 ;; If the group doesn't exist, we assume
1810 ;; it's an archive group...
1811 ((and (null (gnus-get-info group))
1812 (eq (car (gnus-server-to-method gnus-message-archive-method))
1813 (car (gnus-server-to-method (gnus-group-method group)))))
1814 gnus-message-archive-method)
1816 ((gnus-info-method (gnus-get-info group))
1817 (gnus-info-method (gnus-get-info group)))
1819 (t (gnus-server-to-method (gnus-group-method group)))))
1821 ;; Do Gcc handling, which copied the message over to some group.
1822 (defun gnus-inews-do-gcc (&optional gcc)
1826 (message-narrow-to-headers)
1827 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1828 (coding-system-for-write 'raw-text)
1829 (output-coding-system 'raw-text)
1830 groups group method group-art
1831 mml-externalize-attachments)
1833 (message-remove-header "gcc")
1835 (setq groups (message-unquote-tokens
1836 (message-tokenize-header gcc " ,")))
1837 ;; Copy the article over to some group(s).
1838 (while (setq group (pop groups))
1839 (unless (gnus-check-server
1840 (setq method (gnus-inews-group-method group)))
1841 (error "Can't open server %s" (if (stringp method) method
1843 (unless (gnus-request-group group nil method)
1844 (gnus-request-create-group group method))
1845 (setq mml-externalize-attachments
1846 (if (stringp gnus-gcc-externalize-attachments)
1847 (string-match gnus-gcc-externalize-attachments group)
1848 gnus-gcc-externalize-attachments))
1850 (nnheader-set-temp-buffer " *acc*")
1851 (insert-buffer-substring message-encoding-buffer)
1852 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1853 (goto-char (point-min))
1854 (when (re-search-forward
1855 (concat "^" (regexp-quote mail-header-separator) "$")
1857 (replace-match "" t t ))
1858 (unless (setq group-art
1859 (gnus-request-accept-article group method t t))
1860 (gnus-message 1 "Couldn't store article in group %s: %s"
1861 group (gnus-status-message method))
1863 (when (and group-art
1864 ;; FIXME: Should gcc-mark-as-read work when
1865 ;; Gnus is not running?
1867 (or gnus-gcc-mark-as-read
1868 gnus-inews-mark-gcc-as-read))
1869 (gnus-group-mark-article-read group (cdr group-art)))
1870 (kill-buffer (current-buffer)))))))))
1872 (defun gnus-inews-insert-gcc ()
1873 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1876 (message-narrow-to-headers)
1877 (let* ((group gnus-outgoing-message-group)
1879 ((gnus-functionp group)
1881 ((or (stringp group) (list group))
1886 (if (string-match " " gcc)
1887 (concat "\"" gcc "\"")
1889 (mapconcat (lambda (group)
1890 (if (string-match " " group)
1891 (concat "\"" group "\"")
1896 (defun gnus-inews-insert-archive-gcc (&optional group)
1897 "Insert the Gcc to say where the article is to be archived."
1898 (let* ((var gnus-message-archive-group)
1899 (group (or group gnus-newsgroup-name ""))
1901 (and gnus-newsgroup-name
1902 (not (equal gnus-newsgroup-name ""))
1903 (gnus-group-find-parameter
1904 gnus-newsgroup-name 'gcc-self)))
1908 ((null gnus-message-archive-method)
1912 ;; Just a single group.
1915 ;; We don't want this.
1917 ((and (listp var) (stringp (car var)))
1918 ;; A list of groups.
1920 ((gnus-functionp var)
1922 (funcall var group))
1924 ;; An alist of regexps/functions/forms.
1929 ((stringp (caar var))
1931 (when (string-match (caar var) group)
1933 ((gnus-functionp (car var))
1935 (funcall (car var) group))
1937 (eval (car var)))))))
1938 (setq var (cdr var)))
1941 (when (or groups gcc-self-val)
1942 (when (stringp groups)
1943 (setq groups (list groups)))
1946 (message-narrow-to-headers)
1947 (goto-char (point-max))
1950 ;; Use the `gcc-self' param value instead.
1953 (if (stringp gcc-self-val)
1954 (if (string-match " " gcc-self-val)
1955 (concat "\"" gcc-self-val "\"")
1957 (if (string-match " " group)
1958 (concat "\"" group "\"")
1960 (if (not (eq gcc-self-val 'none))
1962 (gnus-delete-line)))
1963 ;; Use the list of groups.
1964 (while (setq name (pop groups))
1965 (let ((str (if (string-match ":" name)
1967 (gnus-group-prefixed-name
1968 name gnus-message-archive-method))))
1969 (insert (if (string-match " " str)
1970 (concat "\"" str "\"")
1976 (defun gnus-mailing-list-followup-to ()
1977 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1978 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1979 (list-post (gnus-fetch-original-field "list-post")))
1980 (when (and list-post
1981 (string-match "mailto:\\([^>]+\\)" list-post))
1982 (setq list-post (match-string 1 list-post)))
1988 (defun gnus-configure-posting-styles (&optional group-name)
1989 "Configure posting styles according to `gnus-posting-styles'."
1990 (unless gnus-inhibit-posting-styles
1991 (let ((group (or group-name gnus-newsgroup-name ""))
1992 (styles gnus-posting-styles)
1993 style match attribute results
1995 ;; If the group has a posting-style parameter, add it at the end with a
1996 ;; regexp matching everything, to be sure it takes precedence over all
1998 (when gnus-newsgroup-name
1999 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
2001 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2002 ;; Go through all styles and look for matches.
2003 (dolist (style styles)
2004 (setq match (pop style))
2005 (goto-char (point-min))
2008 ;; Regexp string match on the group name.
2009 (string-match match group))
2011 ;; Obsolete format of header match.
2012 (and (gnus-buffer-live-p gnus-article-copy)
2013 (with-current-buffer gnus-article-copy
2014 (let ((header (message-fetch-field (pop style))))
2016 (string-match (pop style) header))))))
2017 ((or (symbolp match)
2018 (gnus-functionp match))
2020 ((gnus-functionp match)
2021 ;; Function to be called.
2024 ;; Variable to be checked.
2025 (symbol-value match))))
2028 ((eq (car match) 'header)
2029 ;; New format of header match.
2030 (and (gnus-buffer-live-p gnus-article-copy)
2031 (with-current-buffer gnus-article-copy
2032 (let ((header (message-fetch-field (nth 1 match))))
2034 (string-match (nth 2 match) header))))))
2036 ;; This is a form to be evaled.
2038 ;; We have a match, so we set the variables.
2039 (setq style (gnus-configure-posting-style style nil))
2040 (dolist (attribute style)
2041 (setq results (delq (assoc (car attribute) results) results))
2042 (push attribute results))))
2043 ;; Now we have all the styles, so we insert them.
2044 (setq name (assq 'name results)
2045 address (assq 'address results))
2046 (setq results (delq name (delq address results)))
2047 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2048 (make-local-hook 'message-setup-hook)
2049 (setq results (sort results (lambda (x y)
2050 (string-lessp (car x) (car y)))))
2051 (dolist (result results)
2052 (add-hook 'message-setup-hook
2054 ((eq 'eval (car result))
2056 ((eq 'body (car result))
2060 (insert ,(cdr result)))))
2061 ((eq 'signature (car result))
2062 (set (make-local-variable 'message-signature) nil)
2063 (set (make-local-variable 'message-signature-file) nil)
2064 (if (not (cdr result))
2068 (let ((message-signature ,(cdr result)))
2069 (when message-signature
2070 (message-insert-signature)))))))
2073 (if (symbolp (car result))
2074 (capitalize (symbol-name (car result)))
2078 (message-remove-header ,header)
2079 (let ((value ,(cdr result)))
2082 (insert ,header ": " value)
2084 (insert "\n")))))))))
2086 (when (or name address)
2087 (add-hook 'message-setup-hook
2089 (set (make-local-variable 'user-mail-address)
2090 ,(or (cdr address) user-mail-address))
2091 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2093 ,(or (cdr address) user-mail-address)))
2095 (message-remove-header "From")
2097 (insert "From: " (message-make-from) "\n"))))
2100 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2101 (defun gnus-configure-posting-style (style stack)
2102 "Parse one posting style STYLE and returns the value as an alist."
2103 (let (results element variable filep value v)
2104 (dolist (attribute style)
2105 (setq element (pop attribute)
2110 ((eq (car attribute) ':file)
2113 ((eq (car attribute) :value)
2117 ;; We get the value.
2122 ((or (symbolp value)
2123 (gnus-functionp value))
2124 (cond ((gnus-functionp value)
2127 (symbol-value value))))
2130 ;; Translate obsolescent value.
2132 ((eq element 'signature-file)
2133 (setq element 'signature
2135 ((eq element 'x-face-file)
2136 (setq element 'x-face
2138 ;; Get the contents of file elems.
2140 (setq v (with-temp-buffer
2141 (insert-file-contents v)
2142 (goto-char (point-max))
2146 (if (eq element 'import)
2148 (if (member v stack)
2149 (error "Circular import of \"%s\"" v))
2151 (nconc (nreverse (gnus-configure-posting-style
2152 (cdr (assoc v gnus-named-posting-styles))
2155 (push (cons element v) results)))
2156 (nreverse results)))
2158 (defun gnus-summary-execute-command-with-posting-style (style command)
2159 "Temporarily select a posting-style named STYLE and execute COMMAND."
2161 (let ((style (completing-read "Posting style: "
2162 gnus-named-posting-styles nil t)))
2166 (format "Command to execute with %s: " style))))))
2167 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2168 (call-interactively command)))
2171 ;;; @ for MIME Edit mode
2174 (defun gnus-maybe-setup-default-charset ()
2176 (and (boundp 'gnus-summary-buffer)
2177 (buffer-live-p gnus-summary-buffer)
2179 (set-buffer gnus-summary-buffer)
2180 default-mime-charset))))
2183 (make-local-variable 'default-mime-charset)
2184 (setq default-mime-charset charset)
2188 ;;; @ for MIME view mode
2191 (defun gnus-following-method (buf)
2192 (gnus-setup-message 'reply-yank
2194 (if (message-news-p)
2196 (message-reply nil 'wide))
2197 (let ((message-reply-buffer buf))
2198 (message-yank-original))
2199 (message-goto-body))
2203 ;;; Allow redefinition of functions.
2209 ;;; gnus-msg.el ends here