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))
42 (defcustom gnus-post-method 'current
43 "*Preferred method for posting USENET news.
45 If this variable is `current' (which is the default), Gnus will use
46 the \"current\" select method when posting. If it is `native', Gnus
47 will use the native select method when posting.
49 This method will not be used in mail groups and the like, only in
52 If not `native' nor `current', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'. It can also be a list of
54 methods. If that is the case, the user will be queried for what select
55 method to use when posting."
56 :group 'gnus-group-foreign
57 :link '(custom-manual "(gnus)Posting Server")
58 :type `(choice (const native)
60 (sexp :tag "Methods" ,gnus-select-method)))
62 (defcustom gnus-outgoing-message-group nil
63 "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value. This variable
66 can also be a list of group names.
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
73 :type '(choice (string :tag "Group")
76 (defcustom gnus-mailing-list-groups nil
77 "*Regexp matching groups that are really mailing lists.
78 This is useful when you're reading a mailing list that has been
79 gatewayed to a newsgroup, and you want to followup to an article in
84 (defcustom gnus-add-to-list nil
85 "*If non-nil, add a `to-list' parameter automatically."
89 (defcustom gnus-crosspost-complaint
92 You posted the article below with the following Newsgroups header:
96 The %s group, at least, was an inappropriate recipient
97 of this message. Please trim your Newsgroups header to exclude this
98 group before posting in the future.
103 "Format string to be inserted when complaining about crossposts.
104 The first %s will be replaced by the Newsgroups header;
105 the second with the current group name."
109 (defcustom gnus-message-setup-hook nil
110 "Hook run after setting up a message buffer."
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :link '(custom-manual "(gnus)Posting Styles")
124 :type '(repeat (cons (choice (regexp)
127 (string :tag "Header")
128 (regexp :tag "Regexp"))
132 (choice (const signature)
133 (const signature-file)
141 (string :tag "Header"))
147 (defcustom gnus-named-posting-styles nil
148 "Alist mapping names to the user-defined posting styles."
150 :type '(repeat (cons string
152 (choice (const signature)
153 (const signature-file)
161 (string :tag "Header"))
167 (defcustom gnus-gcc-mark-as-read nil
168 "If non-nil, automatically mark Gcc articles as read."
173 (defvar gnus-inews-mark-gcc-as-read nil
174 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
176 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
177 'gnus-gcc-mark-as-read)
179 (defcustom gnus-gcc-externalize-attachments nil
180 "Should local-file attachments be included as external parts in Gcc copies?
181 If it is `all', attach files as external parts;
182 if a regexp and matches the Gcc group name, attach files as external parts;
183 if nil, attach files as normal parts."
186 :type '(choice (const nil :tag "None")
187 (const all :tag "Any")
188 (string :tag "Regexp")))
190 (gnus-define-group-parameter
191 posting-charset-alist
194 "Return the permitted unencoded charsets for posting of GROUP."
195 :variable gnus-group-posting-charset-alist
197 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
198 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
199 (message-this-is-mail nil nil)
200 (message-this-is-news nil t))
202 "Alist of regexps and permitted unencoded charsets for posting.
203 Each element of the alist has the form (TEST HEADER BODY-LIST), where
204 TEST is either a regular expression matching the newsgroup header or a
206 HEADER is the charset which may be left unencoded in the header (nil
207 means encode all charsets),
208 BODY-LIST is a list of charsets which may be encoded using 8bit
209 content-transfer encoding in the body, or one of the special values
210 nil (always encode using quoted-printable) or t (always use 8bit).
212 Note that any value other than nil for HEADER infringes some RFCs, so
213 use this option with care."
214 :variable-group gnus-charset
216 '(repeat (list :tag "Permitted unencoded charsets"
218 (regexp :tag "Group")
219 (const :tag "Mail message" :value message-this-is-mail)
220 (const :tag "News article" :value message-this-is-news))
221 (choice :tag "Header"
222 (const :tag "None" nil)
223 (symbol :tag "Charset"))
225 (const :tag "Any" :value t)
226 (const :tag "None" :value nil)
227 (repeat :tag "Charsets"
228 (symbol :tag "Charset")))))
229 :parameter-type '(choice :tag "Permitted unencoded charsets"
232 :parameter-document "\
233 List of charsets that are permitted to be unencoded.")
235 (defcustom gnus-debug-files
236 '("gnus.el" "gnus-sum.el" "gnus-group.el"
237 "gnus-art.el" "gnus-start.el" "gnus-async.el"
238 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
239 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
240 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
241 "Files whose variables will be reported in `gnus-bug'."
244 :type '(repeat (string :tag "File")))
246 (defcustom gnus-debug-exclude-variables
247 '(mm-mime-mule-charset-alist
248 nnmail-split-fancy message-minibuffer-local-map)
249 "Variables that should not be reported in `gnus-bug'."
252 :type '(repeat (symbol :tag "Variable")))
254 (defcustom gnus-discouraged-post-methods
255 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
256 "A list of back ends that are not used in \"real\" newsgroups.
257 This variable is used only when `gnus-post-method' is `current'."
259 :group 'gnus-group-foreign
260 :type '(repeat (symbol :tag "Back end")))
262 (defcustom gnus-message-replysign
264 "Automatically sign replies to signed messages.
265 See also the `mml-default-sign-method' variable."
269 (defcustom gnus-message-replyencrypt
271 "Automatically encrypt replies to encrypted messages.
272 See also the `mml-default-encrypt-method' variable."
276 (defcustom gnus-message-replysignencrypted
278 "Setting this causes automatically encryped messages to also be signed."
282 (defcustom gnus-confirm-mail-reply-to-news nil
283 "If non-nil, Gnus requests confirmation when replying to news.
284 This is done because new users often reply by mistake when reading
286 This can also be a function receiving the group name as the only
287 parameter which should return non-nil iff a confirmation is needed, or
288 a regexp, in which case a confirmation is asked for iff the group name
291 :type '(choice (const :tag "No" nil)
293 (regexp :tag "Iff group matches regexp")
294 (function :tag "Iff function evaluates to non-nil")))
296 (defcustom gnus-confirm-treat-mail-like-news
298 "If non-nil, Gnus will treat mail like news with regard to confirmation
299 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
300 for fine-tuning this.
301 If nil, Gnus will never ask for confirmation if replying to mail."
305 (defcustom gnus-summary-resend-default-address t
306 "If non-nil, Gnus tries to suggest a default address to resend to.
307 If nil, the address field will always be empty after invoking
308 `gnus-summary-resend-message'."
312 (defcustom gnus-user-agent 'emacs-gnus-type
313 "Which information should be exposed in the User-Agent header.
315 It can be one of the symbols `gnus' \(show only Gnus version\) `emacs-gnus'
316 \(show only Emacs and Gnus versions\), `emacs-gnus-config' \(same as
317 `emacs-gnus' plus system configuration\), `emacs-gnus-type' \(same as
318 `emacs-gnus' plus system type\) or a custom string. If you set it to a
319 string, be sure to use a valid format, see RFC 2616."
322 (item :tag "Show Gnus and Emacs versions and system type"
324 (item :tag "Show Gnus and Emacs versions and system configuration"
326 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
327 (item :tag "Show only Gnus version" gnus)
328 (string :tag "Other")))
330 ;;; Internal variables.
332 (defvar gnus-inhibit-posting-styles nil
333 "Inhibit the use of posting styles.")
335 (defvar gnus-article-yanked-articles nil)
336 (defvar gnus-message-buffer "*Mail Gnus*")
337 (defvar gnus-article-copy nil)
338 (defvar gnus-check-before-posting nil)
339 (defvar gnus-last-posting-server nil)
340 (defvar gnus-message-group-art nil)
342 (defvar gnus-msg-force-broken-reply-to nil)
344 (defconst gnus-bug-message
345 (format "Sending a bug report to the Gnus Towers.
346 ========================================
348 This gnus is the %s%s.
349 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
350 Developers. (the addresses below are mailing list addresses)
352 ========================================
354 The buffer below is a mail buffer. When you press `C-c C-c', it will
355 be sent to the Gnus Bug Exterminators.
357 The thing near the bottom of the buffer is how the environment
358 settings will be included in the mail. Please do not delete that.
359 They will tell the Bug People what your environment is, so that it
360 will be easier to locate the bugs.
362 If you have found a bug that makes Emacs go \"beep\", set
363 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
364 and include the backtrace in your bug report.
366 Please describe the bug in annoying, painstaking detail.
368 Thank you for your help in stamping out bugs.
371 (if (string= gnus-product-name "Semi-gnus")
373 ", a modified version of Semi-gnus")))
376 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
377 (autoload 'news-setup "rnewspost")
378 (autoload 'news-reply-mode "rnewspost")
379 (autoload 'rmail-dont-reply-to "mail-utils")
380 (autoload 'rmail-output "rmailout"))
384 ;;; Gnus Posting Functions
387 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
388 "p" gnus-summary-post-news
389 "i" gnus-summary-news-other-window
390 "f" gnus-summary-followup
391 "F" gnus-summary-followup-with-original
392 "c" gnus-summary-cancel-article
393 "s" gnus-summary-supersede-article
394 "r" gnus-summary-reply
395 "y" gnus-summary-yank-message
396 "R" gnus-summary-reply-with-original
397 "w" gnus-summary-wide-reply
398 "W" gnus-summary-wide-reply-with-original
399 "v" gnus-summary-very-wide-reply
400 "V" gnus-summary-very-wide-reply-with-original
401 "n" gnus-summary-followup-to-mail
402 "N" gnus-summary-followup-to-mail-with-original
403 "m" gnus-summary-mail-other-window
404 "u" gnus-uu-post-news
405 "\M-c" gnus-summary-mail-crosspost-complaint
406 "Br" gnus-summary-reply-broken-reply-to
407 "BR" gnus-summary-reply-broken-reply-to-with-original
408 "om" gnus-summary-mail-forward
409 "op" gnus-summary-post-forward
410 "Om" gnus-summary-digest-mail-forward
411 "Op" gnus-summary-digest-post-forward
412 "P" gnus-summary-execute-command-with-posting-style)
414 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
415 "b" gnus-summary-resend-bounced-mail
416 ;; "c" gnus-summary-send-draft
417 "r" gnus-summary-resend-message
418 "e" gnus-summary-resend-message-edit)
420 ;;; Internal functions.
422 (defun gnus-inews-make-draft ()
424 (gnus-inews-make-draft-meta-information
425 ,gnus-newsgroup-name ',gnus-article-reply)))
427 (defvar gnus-article-reply nil)
428 (defmacro gnus-setup-message (config &rest forms)
429 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
430 (buffer (make-symbol "gnus-setup-message-buffer"))
431 (article (make-symbol "gnus-setup-message-article"))
432 (yanked (make-symbol "gnus-setup-yanked-articles"))
433 (group (make-symbol "gnus-setup-message-group")))
434 `(let ((,winconf (current-window-configuration))
435 (,buffer (buffer-name (current-buffer)))
436 (,article gnus-article-reply)
437 (,yanked gnus-article-yanked-articles)
438 (,group gnus-newsgroup-name)
439 (message-header-setup-hook
440 (copy-sequence message-header-setup-hook))
441 (message-mode-hook (copy-sequence message-mode-hook))
442 (message-startup-parameter-alist
443 '((reply-buffer . gnus-copy-article-buffer)
444 (original-buffer . gnus-original-article-buffer)
445 (user-agent . Gnus))))
446 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
447 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
448 ;; #### FIXME: for a reason that I did not manage to identify yet,
449 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
450 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
451 ;; After evaluation of @forms below, it gets the value we actually want
452 ;; to override, and the posting styles are used. For that reason, I've
453 ;; added an optional argument to `gnus-configure-posting-styles' to
454 ;; make sure that the correct value for the group name is used. -- drv
455 (add-hook 'message-mode-hook
457 (gnus-configure-posting-styles ,group)))
458 (gnus-pull ',(intern gnus-draft-meta-information-header)
459 message-required-headers)
461 (not (string= ,group "")))
463 (intern gnus-draft-meta-information-header)
464 (gnus-inews-make-draft))
465 message-required-headers))
469 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
471 (setq gnus-message-buffer (current-buffer))
472 (set (make-local-variable 'gnus-message-group-art)
473 (cons ,group ,article))
474 (set (make-local-variable 'gnus-newsgroup-name) ,group)
475 (gnus-maybe-setup-default-charset)
476 (gnus-run-hooks 'gnus-message-setup-hook))
478 (gnus-configure-windows ,config t)
479 (run-hooks 'post-command-hook)
480 (set-buffer-modified-p nil))))
482 (defun gnus-inews-make-draft-meta-information (group article)
483 (concat "(\"" group "\" "
484 (if article (number-to-string
491 (defun gnus-msg-mail (&optional to subject other-headers continue
492 switch-action yank-action send-actions)
493 "Start editing a mail message to be sent.
494 Like `message-mail', but with Gnus paraphernalia, particularly the
495 Gcc: header for archiving purposes."
497 (let ((buf (current-buffer))
499 (gnus-setup-message 'message
500 (message-mail to subject other-headers continue
501 nil yank-action send-actions))
503 (setq mail-buf (current-buffer))
504 (switch-to-buffer buf)
505 (apply switch-action mail-buf nil)))
506 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
509 (defvar save-selected-window-window)
512 (defun gnus-button-mailto (address)
514 (set-buffer (gnus-copy-article-buffer))
515 (gnus-setup-message 'message
516 (message-reply address))
517 (and (boundp 'save-selected-window-window)
518 (not (window-live-p save-selected-window-window))
519 (setq save-selected-window-window (selected-window))))
522 (defun gnus-button-reply (&optional to-address wide)
523 "Like `message-reply'."
525 (gnus-setup-message 'message
526 (message-reply to-address wide))
527 (and (boundp 'save-selected-window-window)
528 (not (window-live-p save-selected-window-window))
529 (setq save-selected-window-window (selected-window))))
532 (define-mail-user-agent 'gnus-user-agent
533 'gnus-msg-mail 'message-send-and-exit
534 'message-kill-buffer 'message-send-hook)
536 (defun gnus-setup-posting-charset (group)
537 (let ((alist gnus-group-posting-charset-alist)
538 (group (or group ""))
542 (while (setq elem (pop alist))
543 (when (or (and (stringp (car elem))
544 (string-match (car elem) group))
545 (and (gnus-functionp (car elem))
546 (funcall (car elem) group))
547 (and (symbolp (car elem))
548 (symbol-value (car elem))))
549 (throw 'found (cons (cadr elem) (caddr elem)))))))))
551 (defun gnus-inews-add-send-actions (winconf buffer article
552 &optional config yanked)
553 (make-local-hook 'message-sent-hook)
554 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
555 'gnus-inews-do-gcc) nil t)
557 (make-local-hook 'message-header-hook)
558 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
559 (setq message-post-method
561 (gnus-post-method arg ,gnus-newsgroup-name)))
562 (setq message-user-agent (gnus-extended-version))
563 (when (not message-use-multi-frames)
565 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
566 (let ((to-be-marked (cond
568 (article (if (listp article) article (list article)))
571 `(when (gnus-buffer-exists-p ,buffer)
575 (if (eq config 'forward)
576 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
577 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
580 (put 'gnus-setup-message 'lisp-indent-function 1)
581 (put 'gnus-setup-message 'edebug-form-spec '(form body))
583 ;;; Post news commands of Gnus group mode and summary mode
585 (defun gnus-group-mail (&optional arg)
586 "Start composing a mail.
587 If ARG, use the group under the point to find a posting style.
588 If ARG is 1, prompt for a group name to find the posting style."
590 ;; We can't `let' gnus-newsgroup-name here, since that leads
591 ;; to local variables leaking.
592 (let ((group gnus-newsgroup-name)
593 ;; make sure last viewed article doesn't affect posting styles:
595 (buffer (current-buffer)))
598 (setq gnus-newsgroup-name
600 (if (= 1 (prefix-numeric-value arg))
601 (completing-read "Use posting style of group: "
602 gnus-active-hashtb nil
603 (gnus-read-active-file-p))
604 (gnus-group-group-name))
606 ;; #### see comment in gnus-setup-message -- drv
607 (gnus-setup-message 'message (message-mail)))
610 (setq gnus-newsgroup-name group)))))
612 (defun gnus-group-news (&optional arg)
613 "Start composing a news.
614 If ARG, post to group under point.
615 If ARG is 1, prompt for group name to post to.
617 This function prepares a news even when using mail groups. This is useful
618 for posting messages to mail groups without actually sending them over the
619 network. The corresponding backend must have a 'request-post method."
621 ;; We can't `let' gnus-newsgroup-name here, since that leads
622 ;; to local variables leaking.
623 (let ((group gnus-newsgroup-name)
624 ;; make sure last viewed article doesn't affect posting styles:
626 (buffer (current-buffer)))
629 (setq gnus-newsgroup-name
631 (if (= 1 (prefix-numeric-value arg))
632 (completing-read "Use group: "
633 gnus-active-hashtb nil
634 (gnus-read-active-file-p))
635 (gnus-group-group-name))
637 ;; #### see comment in gnus-setup-message -- drv
638 (gnus-setup-message 'message
639 (message-news (gnus-group-real-name gnus-newsgroup-name))))
642 (setq gnus-newsgroup-name group)))))
644 (defun gnus-group-post-news (&optional arg)
645 "Start composing a message (a news by default).
646 If ARG, post to group under point. If ARG is 1, prompt for group name.
647 Depending on the selected group, the message might be either a mail or
650 ;; Bind this variable here to make message mode hooks work ok.
651 (let ((gnus-newsgroup-name
653 (if (= 1 (prefix-numeric-value arg))
654 (completing-read "Newsgroup: " gnus-active-hashtb nil
655 (gnus-read-active-file-p))
656 (gnus-group-group-name))
658 ;; make sure last viewed article doesn't affect posting styles:
660 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
661 (string= gnus-newsgroup-name ""))))
663 (defun gnus-summary-mail-other-window (&optional arg)
664 "Start composing a mail in another window.
665 Use the posting of the current group by default.
666 If ARG, don't do that. If ARG is 1, prompt for group name to find the
669 ;; We can't `let' gnus-newsgroup-name here, since that leads
670 ;; to local variables leaking.
671 (let ((group gnus-newsgroup-name)
672 ;; make sure last viewed article doesn't affect posting styles:
674 (buffer (current-buffer)))
677 (setq gnus-newsgroup-name
679 (if (= 1 (prefix-numeric-value arg))
680 (completing-read "Use group: "
681 gnus-active-hashtb nil
682 (gnus-read-active-file-p))
684 gnus-newsgroup-name))
685 ;; #### see comment in gnus-setup-message -- drv
686 (gnus-setup-message 'message (message-mail)))
689 (setq gnus-newsgroup-name group)))))
691 (defun gnus-summary-news-other-window (&optional arg)
692 "Start composing a news in another window.
693 Post to the current group by default.
694 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
696 This function prepares a news even when using mail groups. This is useful
697 for posting messages to mail groups without actually sending them over the
698 network. The corresponding backend must have a 'request-post method."
700 ;; We can't `let' gnus-newsgroup-name here, since that leads
701 ;; to local variables leaking.
702 (let ((group gnus-newsgroup-name)
703 ;; make sure last viewed article doesn't affect posting styles:
705 (buffer (current-buffer)))
708 (setq gnus-newsgroup-name
710 (if (= 1 (prefix-numeric-value arg))
711 (completing-read "Use group: "
712 gnus-active-hashtb nil
713 (gnus-read-active-file-p))
715 gnus-newsgroup-name))
716 ;; #### see comment in gnus-setup-message -- drv
717 (gnus-setup-message 'message
718 (message-news (gnus-group-real-name gnus-newsgroup-name))))
721 (setq gnus-newsgroup-name group)))))
723 (defun gnus-summary-post-news (&optional arg)
724 "Start composing a message. Post to the current group by default.
725 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
726 Depending on the selected group, the message might be either a mail or
729 ;; Bind this variable here to make message mode hooks work ok.
730 (let ((gnus-newsgroup-name
732 (if (= 1 (prefix-numeric-value arg))
733 (completing-read "Newsgroup: " gnus-active-hashtb nil
734 (gnus-read-active-file-p))
736 gnus-newsgroup-name))
737 ;; make sure last viewed article doesn't affect posting styles:
739 (gnus-post-news 'post gnus-newsgroup-name)))
742 (defun gnus-summary-followup (yank &optional force-news)
743 "Compose a followup to an article.
744 If prefix argument YANK is non-nil, the original article is yanked
746 YANK is a list of elements, where the car of each element is the
747 article number, and the two following numbers is the region to be
750 (list (and current-prefix-arg
751 (gnus-summary-work-articles 1))))
753 (gnus-summary-goto-subject
754 (if (listp (car yank))
757 (save-window-excursion
758 (gnus-summary-select-article))
759 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
760 (gnus-newsgroup-name gnus-newsgroup-name))
762 (gnus-post-news nil gnus-newsgroup-name
763 headers gnus-article-buffer
765 (gnus-summary-handle-replysign)))
767 (defun gnus-summary-followup-with-original (n &optional force-news)
768 "Compose a followup to an article and include the original article."
770 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
772 (defun gnus-summary-followup-to-mail (&optional arg)
773 "Followup to the current mail message via news."
775 (list (and current-prefix-arg
776 (gnus-summary-work-articles 1))))
777 (gnus-summary-followup arg t))
779 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
780 "Followup to the current mail message via news."
782 (gnus-summary-followup (gnus-summary-work-articles arg) t))
784 (defun gnus-inews-yank-articles (articles)
785 (let (beg article yank-string
786 (more-than-one (cdr articles))
787 (cur (current-buffer))
790 (while (setq article (pop articles))
791 (when (listp article)
792 (setq yank-string (nth 1 article)
793 article (nth 0 article)))
794 (save-window-excursion
795 (set-buffer gnus-summary-buffer)
796 (gnus-summary-select-article nil nil nil article)
797 (gnus-summary-remove-process-mark article))
799 ;; Gathering references.
801 (setq refs (message-list-references
803 (mail-header-references gnus-current-headers)
804 (mail-header-message-id gnus-current-headers)))
805 (when message-use-multi-frames
806 (when (setq window (get-buffer-window cur t))
807 (select-frame (window-frame window)))))
809 (gnus-copy-article-buffer nil yank-string)
810 (let ((message-reply-buffer gnus-article-copy)
811 (message-reply-headers
812 ;; The headers are decoded.
813 (with-current-buffer gnus-article-copy
815 (nnheader-narrow-to-headers)
816 (nnheader-parse-naked-head)))))
817 (message-yank-original)
818 (setq beg (or beg (mark t))))
823 ;; Replace with the gathered references.
827 (message-narrow-to-headers)
828 (let ((case-fold-search t))
829 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
831 (goto-char (point-max))))
833 (list (or (assq 'References message-header-format-alist)
834 '(References . message-shorten-references)))
835 (list (cons 'References
836 (mapconcat 'identity (nreverse refs) " "))))
837 (backward-delete-char 1))
843 (defun gnus-summary-cancel-article (&optional n symp)
844 "Cancel an article you posted.
845 Uses the process-prefix convention. If given the symbolic
846 prefix `a', cancel using the standard posting method; if not
847 post using the current select method."
848 (interactive (gnus-interactive "P\ny"))
849 (let ((articles (gnus-summary-work-articles n))
852 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
854 (while (setq article (pop articles))
855 (when (gnus-summary-select-article t nil nil article)
856 (when (gnus-eval-in-buffer-window gnus-article-buffer
858 (set-buffer gnus-original-article-buffer)
859 (message-cancel-news)))
860 (gnus-summary-mark-as-read article gnus-canceled-mark)
861 (gnus-cache-remove-article 1))
862 (gnus-article-hide-headers-if-wanted))
863 (gnus-summary-remove-process-mark article))))
865 (defun gnus-summary-supersede-article ()
866 "Compose an article that will supersede a previous article.
867 This is done simply by taking the old article and adding a Supersedes
868 header line with the old Message-ID."
870 (let ((article (gnus-summary-article-number)))
871 (gnus-setup-message 'reply-yank
872 (gnus-summary-select-article t)
873 (set-buffer gnus-original-article-buffer)
877 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
879 (set-buffer ,gnus-summary-buffer)
880 (gnus-cache-possibly-remove-article ,article nil nil nil t)
881 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
882 message-send-actions))))
886 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
887 ;; make a copy of the article buffer with all text properties removed
888 ;; this copy is in the buffer gnus-article-copy.
889 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
890 ;; this buffer should be passed to all mail/news reply/post routines.
891 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
893 (set-buffer gnus-article-copy)
894 (set-buffer-multibyte t))
895 (let ((article-buffer (or article-buffer gnus-article-buffer))
897 (if (not (and (get-buffer article-buffer)
898 (gnus-buffer-exists-p article-buffer)))
899 (error "Can't find any article buffer")
901 (set-buffer article-buffer)
902 (let ((gnus-newsgroup-charset (or gnus-article-charset
903 gnus-newsgroup-charset))
904 (gnus-newsgroup-ignored-charsets
905 (or gnus-article-ignored-charsets
906 gnus-newsgroup-ignored-charsets)))
908 ;; Copy over the (displayed) article buffer, delete
909 ;; hidden text and remove text properties.
911 (copy-to-buffer gnus-article-copy (point-min) (point-max))
912 (set-buffer gnus-article-copy)
913 ;; There's invisible and intangible text in T-gnus. Especially,
914 ;; if there is a boundary line (X-Boundary: ------------------),
915 ;; in the end of a header, it will cause a serious problem.
916 (add-text-properties (point-min) (point-max)
917 '(invisible nil intangible nil))
920 (delete-region (point) (point-max))
921 (insert yank-string))
922 ;; Encode bitmap smileys to ordinary text.
923 ;; Possibly, the original text might be restored.
924 (static-unless (featurep 'xemacs)
925 (when (featurep 'smiley-mule)
926 (smiley-encode-buffer)))
927 (gnus-article-delete-text-of-type 'annotation)
928 (gnus-remove-text-with-property 'gnus-prev)
929 (gnus-remove-text-with-property 'gnus-next)
930 (gnus-remove-text-with-property 'gnus-decoration)
931 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
934 (static-if (featurep 'xemacs)
935 ;; Revome smiley extents for (possibly) XEmacs 21.1.
937 (buffer-substring-no-properties (point-min)
939 (buffer-substring-no-properties (point-min) (point-max)))
941 ;; Find the original headers.
942 (set-buffer gnus-original-article-buffer)
943 (goto-char (point-min))
944 (while (looking-at message-unix-mail-delimiter)
946 (let ((mail-header-separator ""))
948 end (or (message-goto-body)
949 ;; There may be just a header.
951 ;; Delete the headers from the displayed articles.
952 (set-buffer gnus-article-copy)
953 (let ((mail-header-separator ""))
954 (delete-region (goto-char (point-min))
955 (or (message-goto-body) (point-max))))
956 ;; Insert the original article headers.
957 (insert-buffer-substring gnus-original-article-buffer beg end)
959 (let ((gnus-article-decode-hook
960 (delq 'article-decode-charset
961 (copy-sequence gnus-article-decode-hook))))
962 ;; Needed for T-gnus.
963 (add-hook 'gnus-article-decode-hook
964 'article-decode-encoded-words)
965 (run-hooks 'gnus-article-decode-hook)))))
968 (defun gnus-post-news (post &optional group header article-buffer yank subject
971 (gnus-copy-article-buffer))
972 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
973 (gnus-article-yanked-articles yank)
974 (add-to-list gnus-add-to-list))
975 (gnus-setup-message (cond (yank 'reply-yank)
976 (article-buffer 'reply)
978 (let* ((group (or group gnus-newsgroup-name))
979 (charset (gnus-group-name-charset nil group))
981 to-address to-group mailing-list to-list
984 (setq to-address (gnus-parameter-to-address group)
985 to-group (gnus-group-find-parameter group 'to-group)
986 to-list (gnus-parameter-to-list group)
987 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
988 mailing-list (when gnus-mailing-list-groups
989 (string-match gnus-mailing-list-groups group))
990 group (gnus-group-name-decode (gnus-group-real-name group)
992 (if (or (and to-group
993 (gnus-news-group-p to-group))
996 (and (gnus-news-group-p
997 (or pgroup gnus-newsgroup-name)
998 (or header gnus-current-article))
1004 (message-news (or to-group group))
1005 (set-buffer gnus-article-copy)
1006 (gnus-msg-treat-broken-reply-to)
1007 (message-followup (if (or newsgroup-p force-news)
1008 (if (save-restriction
1009 (article-narrow-to-head)
1010 (message-fetch-field "newsgroups"))
1017 (message-mail (or to-address to-list))
1018 ;; Arrange for mail groups that have no `to-address' to
1019 ;; get that when the user sends off the mail.
1020 (when (and (not to-list)
1023 (push (list 'gnus-inews-add-to-address pgroup)
1024 message-send-actions)))
1025 (set-buffer gnus-article-copy)
1026 (gnus-msg-treat-broken-reply-to)
1027 (message-wide-reply to-address)))
1029 (gnus-inews-yank-articles yank))))))
1031 (defun gnus-msg-treat-broken-reply-to (&optional force)
1032 "Remove the Reply-to header if broken-reply-to."
1034 (gnus-group-find-parameter
1035 gnus-newsgroup-name 'broken-reply-to))
1037 (message-narrow-to-head)
1038 (message-remove-header "reply-to"))))
1040 (defun gnus-post-method (arg group &optional silent)
1041 "Return the posting method based on GROUP and ARG.
1042 If SILENT, don't prompt the user."
1043 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1045 (group-method (gnus-find-method-for-group group)))
1047 ;; If the group-method is nil (which shouldn't happen) we use
1048 ;; the default method.
1049 ((null group-method)
1050 (or (and (listp gnus-post-method) ;If not current/native/nil
1051 (not (listp (car gnus-post-method))) ; and not a list of methods
1052 gnus-post-method) ;then use it.
1054 message-post-method))
1055 ;; We want the inverse of the default
1056 ((and arg (not (eq arg 0)))
1057 (if (eq gnus-post-method 'current)
1060 ;; We query the user for a post method.
1062 (and (listp gnus-post-method)
1063 (listp (car gnus-post-method))))
1065 ;; Collect all methods we know about.
1067 (when (listp gnus-post-method)
1068 (if (listp (car gnus-post-method))
1070 (list gnus-post-method)))
1071 gnus-secondary-select-methods
1072 (mapcar 'cdr gnus-server-alist)
1073 (mapcar 'car gnus-opened-servers)
1074 (list gnus-select-method)
1075 (list group-method)))
1076 method-alist post-methods method)
1077 ;; Weed out all mail methods.
1079 (setq method (gnus-server-get-method "" (pop methods)))
1080 (when (and (or (gnus-method-option-p method 'post)
1081 (gnus-method-option-p method 'post-mail))
1082 (not (member method post-methods)))
1083 (push method post-methods)))
1084 ;; Create a name-method alist.
1088 (if (equal (cadr m) "")
1089 (list (symbol-name (car m)) m)
1090 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1095 (setq gnus-last-posting-server
1097 gnus-last-posting-server)
1098 ;; Just use the last value.
1099 gnus-last-posting-server
1101 "Posting method: " method-alist nil t
1102 (cons (or gnus-last-posting-server "") 0))))
1104 ;; Override normal method.
1105 ((and (eq gnus-post-method 'current)
1106 (not (memq (car group-method) gnus-discouraged-post-methods))
1107 (gnus-get-function group-method 'request-post t))
1110 ;; Use gnus-post-method.
1111 ((listp gnus-post-method) ;A method...
1112 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1114 ;; Use the normal select method (nil or native).
1115 (t gnus-select-method))))
1118 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1120 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1121 variable `mime-edit-user-agent-value' is bound, the value will be
1122 included in the return value. If MAX-COLUMN is specified, the return
1123 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1124 whether a newline should be inserted in front of each product-token.
1125 If the value is t or `hard', it works strictly. Otherwise, if it is
1126 non-nil (e.g. `soft'), it works semi-strictly.
1128 Here is an example of how to use this function:
1130 \(add-hook 'gnus-message-setup-hook
1132 (setq message-user-agent nil)
1135 (message-narrow-to-headers)
1136 (goto-char (point-max))
1137 (insert \"User-Agent: \"
1138 (gnus-message-make-user-agent t 76 'soft)
1141 (let ((user-agent (if (and include-mime-info
1142 (boundp 'mime-edit-user-agent-value))
1143 (concat (gnus-extended-version)
1145 mime-edit-user-agent-value)
1146 (gnus-extended-version))))
1148 (unless (natnump max-column)
1149 (setq max-column 76))
1151 (set-buffer-multibyte t)
1152 (insert (mapconcat 'identity (split-string user-agent) " "))
1153 (goto-char (point-min))
1155 start agent agents width element swidth)
1156 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1157 (setq start (match-beginning 0))
1158 (if (eq (char-after start) ?\()
1162 (push (buffer-substring start (point)) agent))
1164 (push (nreverse agent) agents))
1165 (setq agent (list (match-string 1)))))
1167 (push (nreverse agent) agents))
1168 (setq agents (nreverse agents))
1169 (if (> (+ 12 (string-width (caar agents))) max-column)
1170 (setq user-agent "\n"
1175 (setq agent (car agents)
1176 agents (cdr agents))
1177 (when (and (not bol)
1178 (or (memq newline-product '(t hard))
1179 (and newline-product
1181 (string-width (mapconcat 'identity
1184 (setq user-agent (concat user-agent "\n")
1188 (setq element (car agent)
1189 swidth (string-width element)
1192 (setq user-agent (if (member user-agent '("" "\n"))
1193 (concat user-agent element)
1194 (concat user-agent " " element))
1195 width (+ width 1 swidth)
1197 (if (> (+ width 1 swidth) max-column)
1198 (setq user-agent (concat user-agent "\n " element)
1200 (setq user-agent (concat user-agent " " element)
1201 width (+ width 1 swidth)))))))))
1206 ;;; Gnus Mail Functions
1209 ;;; Mail reply commands of Gnus summary mode
1211 (defun gnus-summary-reply (&optional yank wide very-wide)
1212 "Start composing a mail reply to the current message.
1213 If prefix argument YANK is non-nil, the original article is yanked
1215 If WIDE, make a wide reply.
1216 If VERY-WIDE, make a very wide reply."
1218 (list (and current-prefix-arg
1219 (gnus-summary-work-articles 1))))
1220 ;; Allow user to require confirmation before replying by mail to the
1221 ;; author of a news article (or mail message).
1223 (not (or (gnus-news-group-p gnus-newsgroup-name)
1224 gnus-confirm-treat-mail-like-news))
1225 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1226 (string-match gnus-confirm-mail-reply-to-news
1227 gnus-newsgroup-name))
1228 ((functionp gnus-confirm-mail-reply-to-news)
1229 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1230 (t gnus-confirm-mail-reply-to-news)))
1231 (y-or-n-p "Really reply by mail to article author? "))
1233 (if (listp (car yank))
1236 (gnus-article-reply (or article (gnus-summary-article-number)))
1237 (gnus-article-yanked-articles yank)
1239 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1241 (gnus-summary-goto-subject article))
1242 (gnus-setup-message (if yank 'reply-yank 'reply)
1244 (gnus-summary-select-article)
1245 (dolist (article very-wide)
1246 (gnus-summary-select-article nil nil nil article)
1248 (set-buffer (gnus-copy-article-buffer))
1249 (gnus-msg-treat-broken-reply-to)
1251 (message-narrow-to-head)
1252 (setq headers (concat headers (buffer-string)))))))
1253 (set-buffer (gnus-copy-article-buffer))
1254 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1256 (message-narrow-to-head)
1260 (goto-char (point-max)))
1261 (message-reply nil wide)
1263 (gnus-inews-yank-articles yank))
1264 (gnus-summary-handle-replysign)))))
1266 (defun gnus-summary-handle-replysign ()
1267 "Check the various replysign variables and take action accordingly."
1268 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1269 (let (signed encrypted)
1271 (set-buffer gnus-article-buffer)
1272 (setq signed (memq 'signed gnus-article-wash-types))
1273 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1274 (cond ((and gnus-message-replyencrypt encrypted)
1275 (mml-secure-message mml-default-encrypt-method
1276 (if gnus-message-replysignencrypted
1279 ((and gnus-message-replysign signed)
1280 (mml-secure-message mml-default-sign-method 'sign))))))
1282 (defun gnus-summary-reply-with-original (n &optional wide)
1283 "Start composing a reply mail to the current message.
1284 The original article will be yanked."
1286 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1288 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1289 "Like `gnus-summary-reply' except removing reply-to field.
1290 If prefix argument YANK is non-nil, the original article is yanked
1292 If WIDE, make a wide reply.
1293 If VERY-WIDE, make a very wide reply."
1295 (list (and current-prefix-arg
1296 (gnus-summary-work-articles 1))))
1297 (let ((gnus-msg-force-broken-reply-to t))
1298 (gnus-summary-reply yank wide very-wide)))
1300 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1301 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1302 The original article will be yanked."
1304 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1306 (defun gnus-summary-wide-reply (&optional yank)
1307 "Start composing a wide reply mail to the current message.
1308 If prefix argument YANK is non-nil, the original article is yanked
1311 (list (and current-prefix-arg
1312 (gnus-summary-work-articles 1))))
1313 (gnus-summary-reply yank t))
1315 (defun gnus-summary-wide-reply-with-original (n)
1316 "Start composing a wide reply mail to the current message.
1317 The original article will be yanked."
1319 (gnus-summary-reply-with-original n t))
1321 (defun gnus-summary-very-wide-reply (&optional yank)
1322 "Start composing a very wide reply mail to the current message.
1323 If prefix argument YANK is non-nil, the original article is yanked
1326 (list (and current-prefix-arg
1327 (gnus-summary-work-articles 1))))
1328 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1330 (defun gnus-summary-very-wide-reply-with-original (n)
1331 "Start composing a very wide reply mail to the current message.
1332 The original article will be yanked."
1335 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1337 (defun gnus-summary-mail-forward (&optional full-headers post)
1338 "Forward the current message(s) to another user.
1339 If process marks exist, forward all marked messages;
1340 If FULL-HEADERS (the prefix), include full headers when forwarding.
1342 Note that this function definition for T-gnus is totally different
1343 from the original Gnus."
1345 (if (cdr (gnus-summary-work-articles nil))
1346 ;; Process marks are given.
1347 (gnus-summary-digest-mail-forward nil post)
1348 ;; No process marks.
1349 (let* ((gnus-article-reply (gnus-summary-article-number))
1350 (gnus-article-yanked-articles (list gnus-article-reply))
1352 (message-included-forward-headers
1353 (if full-headers "" message-included-forward-headers)))
1354 (gnus-setup-message 'forward
1355 (gnus-summary-select-article)
1356 (setq charset default-mime-charset)
1357 (set-buffer gnus-original-article-buffer)
1358 (make-local-variable 'default-mime-charset)
1359 (setq default-mime-charset charset)
1360 (message-forward post)))))
1362 (defun gnus-summary-digest-mail-forward (&optional n post)
1363 "Digests and forwards all articles in this series.
1364 If N is a positive number, forward the N next articles.
1365 If N is a negative number, forward the N previous articles.
1366 If N is nil and any articles have been marked with the process mark,
1367 forward those articles instead.
1368 Optional POST will use news to forward instead of mail."
1370 (let* ((articles (gnus-summary-work-articles n))
1371 (gnus-article-yanked-articles (copy-sequence articles))
1372 (topics "Topics:\n")
1373 subject article frame)
1374 (when (car articles)
1375 (gnus-setup-message 'forward
1376 (gnus-summary-select-article)
1378 (setq articles (sort articles '<)
1379 subject "Digested Articles")
1380 (with-current-buffer gnus-original-article-buffer
1381 (setq subject (message-make-forward-subject))))
1383 (message-news nil subject)
1384 (message-mail nil subject))
1385 (when (and message-use-multi-frames (cdr articles))
1386 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1388 (while (setq article (pop articles))
1389 (save-window-excursion
1390 (set-buffer gnus-summary-buffer)
1391 (gnus-summary-select-article nil nil nil article)
1392 (setq topics (concat topics " "
1393 (mail-header-subject gnus-current-headers)
1395 (gnus-summary-remove-process-mark article))
1397 (select-frame frame))
1398 (insert (mime-make-tag "message" "rfc822") "\n")
1399 (narrow-to-region (point) (point))
1400 (insert-buffer-substring gnus-original-article-buffer)
1402 (article-narrow-to-head)
1403 (message-remove-header message-included-forward-headers t nil t))
1404 (goto-char (point-max))
1410 (mime-edit-enclose-digest-region (point)(mark t))))))
1412 (defun gnus-summary-digest-post-forward (&optional n)
1413 "Digest and forwards all articles in this series to a newsgroup.
1414 If N is a positive number, forward the N next articles.
1415 If N is a negative number, forward the N previous articles.
1416 If N is nil and any articles have been marked with the process mark,
1417 forward those articles instead."
1419 (gnus-summary-digest-mail-forward n t))
1421 (defun gnus-summary-resend-message (address n)
1422 "Resend the current article to ADDRESS."
1424 (list (message-read-from-minibuffer
1425 "Resend message(s) to: "
1426 (when (and gnus-summary-resend-default-address
1427 (gnus-buffer-live-p gnus-original-article-buffer))
1428 ;; If some other article is currently selected, the
1429 ;; initial-contents is wrong. Whatever, it is just the
1430 ;; initial-contents.
1431 (with-current-buffer gnus-original-article-buffer
1432 (nnmail-fetch-field "to"))))
1433 current-prefix-arg))
1434 (let ((articles (gnus-summary-work-articles n))
1436 (while (setq article (pop articles))
1437 (gnus-summary-select-article nil nil nil article)
1439 (set-buffer gnus-original-article-buffer)
1440 (message-resend address))
1441 (gnus-summary-mark-article-as-forwarded article))))
1443 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1444 (defun gnus-summary-resend-message-edit ()
1445 "Resend an article that has already been sent.
1446 A new buffer will be created to allow the user to modify body and
1447 contents of the message, and then, everything will happen as when
1448 composing a new message."
1450 (let ((article (gnus-summary-article-number)))
1451 (gnus-setup-message 'reply-yank
1452 (gnus-summary-select-article t)
1453 (set-buffer gnus-original-article-buffer)
1454 (let ((cur (current-buffer))
1455 (to (message-fetch-field "to")))
1456 ;; Get a normal message buffer.
1457 (message-pop-to-buffer (message-buffer-name "Resend" to))
1458 (insert-buffer-substring cur)
1460 ;; T-gnus change: Use MIME-Edit to recompose a message.
1462 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1463 (fset 'mime-edit-decode-single-part-in-buffer
1464 (lambda (&rest args)
1465 (if (let ((content-type (car args)))
1466 (and (eq 'message (mime-content-type-primary-type
1468 (eq 'rfc822 (mime-content-type-subtype
1470 (setcar (cdr args) 'not-decode-text))
1473 (mime-edit-again nil t)
1474 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1475 (message-narrow-to-head-1)
1476 (insert "From: " (message-make-from) "\n")
1477 (while (re-search-forward "^From:" nil t)
1479 (insert "Original-"))
1480 (message-remove-header "^>From[\t ]" t)
1482 ;; Gnus will generate a new one when sending.
1483 (message-remove-header "Message-ID")
1484 (message-remove-header message-ignored-resent-headers t)
1485 ;; Remove unwanted headers.
1486 (goto-char (point-max))
1487 (insert mail-header-separator)
1488 (goto-char (point-min))
1489 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1493 (defun gnus-summary-post-forward (&optional full-headers)
1494 "Forward the current article to a newsgroup.
1495 If FULL-HEADERS (the prefix), include full headers when forwarding."
1497 (gnus-summary-mail-forward full-headers t))
1499 (defvar gnus-nastygram-message
1500 "The following article was inappropriately posted to %s.\n\n"
1501 "Format string to insert in nastygrams.
1502 The current group name will be inserted at \"%s\".")
1504 (defun gnus-summary-mail-nastygram (n)
1505 "Send a nastygram to the author of the current article."
1507 (when (or gnus-expert-user
1509 "Really send a nastygram to the author of the current article? "))
1510 (let ((group gnus-newsgroup-name))
1511 (gnus-summary-reply-with-original n)
1512 (set-buffer gnus-message-buffer)
1514 (insert (format gnus-nastygram-message group))
1515 (message-send-and-exit))))
1517 (defun gnus-summary-mail-crosspost-complaint (n)
1518 "Send a complaint about crossposting to the current article(s)."
1520 (let ((articles (gnus-summary-work-articles n))
1522 (while (setq article (pop articles))
1523 (set-buffer gnus-summary-buffer)
1524 (gnus-summary-goto-subject article)
1525 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1526 newsgroups followup-to)
1527 (gnus-summary-select-article)
1528 (set-buffer gnus-original-article-buffer)
1529 (if (and (<= (length (message-tokenize-header
1531 (mail-fetch-field "newsgroups"))
1534 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1535 (not (member group (message-tokenize-header
1536 followup-to ", ")))))
1538 (gnus-message 1 "Followup-to restricted")
1539 (gnus-message 1 "Not a crossposted article"))
1540 (set-buffer gnus-summary-buffer)
1541 (gnus-summary-reply-with-original 1)
1542 (set-buffer gnus-message-buffer)
1544 (insert (format gnus-crosspost-complaint newsgroups group))
1545 (message-goto-subject)
1546 (re-search-forward " *$")
1547 (replace-match " (crosspost notification)" t t)
1548 (gnus-deactivate-mark)
1549 (when (gnus-y-or-n-p "Send this complaint? ")
1550 (message-send-and-exit)))))))
1552 (defun gnus-mail-parse-comma-list ()
1555 (skip-chars-forward " ")
1558 (skip-chars-forward "^,")
1563 (narrow-to-region beg (point))
1566 (while (search-forward "\"" nil t)
1570 (skip-chars-forward ",")
1571 (skip-chars-forward "^,"))
1572 (skip-chars-backward " ")
1573 (push (buffer-substring beg (point))
1575 (skip-chars-forward "^,")
1576 (skip-chars-forward ", "))
1579 (defun gnus-inews-add-to-address (group)
1580 (let ((to-address (mail-fetch-field "to")))
1581 (when (and to-address
1583 ;; This mail group doesn't have a `to-list', so we add one
1585 (when (gnus-y-or-n-p
1586 (format "Do you want to add this as `to-list': %s " to-address))
1587 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1589 (defun gnus-put-message ()
1590 "Put the current message in some group and return to Gnus."
1592 (let ((reply gnus-article-reply)
1593 (winconf gnus-prev-winconf)
1594 (group gnus-newsgroup-name))
1596 (not (gnus-group-read-only-p group)))
1597 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1599 (when (gnus-gethash group gnus-newsrc-hashtb)
1600 (error "No such group: %s" group))
1604 (message-narrow-to-headers)
1605 (let ((gnus-deletable-headers nil))
1606 (message-generate-headers
1607 (if (message-news-p)
1608 message-required-news-headers
1609 message-required-mail-headers)))
1610 (goto-char (point-max))
1611 (if (string-match " " group)
1612 (insert "Gcc: \"" group "\"\n")
1613 (insert "Gcc: " group "\n"))
1616 (when (and (get-buffer gnus-group-buffer)
1617 (gnus-buffer-exists-p (car-safe reply))
1619 (set-buffer (car reply))
1620 (gnus-summary-mark-article-as-replied (cdr reply)))
1622 (set-window-configuration winconf))))
1624 (defun gnus-article-mail (yank)
1625 "Send a reply to the address near point.
1626 If YANK is non-nil, include the original article."
1630 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1631 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1633 (gnus-msg-mail address)
1635 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1637 (defvar nntp-server-type)
1639 "Send a bug report to the Gnus maintainers."
1641 (unless (gnus-alive-p)
1642 (error "Gnus has been shut down"))
1643 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1644 (unless (message-mail-user-agent)
1645 (message-pop-to-buffer "*Gnus Bug*")
1646 (delete-other-windows)
1647 (when gnus-bug-create-help-buffer
1648 (switch-to-buffer "*Gnus Help Bug*")
1650 (insert gnus-bug-message)
1651 (goto-char (point-min))
1653 (set-buffer "*Gnus Bug*")))
1654 (let ((message-this-is-mail t))
1655 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1656 (when gnus-bug-create-help-buffer
1657 (push `(gnus-bug-kill-buffer) message-send-actions))
1658 (goto-char (point-min))
1659 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1661 (insert gnus-product-name " " gnus-version-number
1662 " (r" gnus-revision-number ") "
1663 "based on " gnus-original-product-name " v"
1664 gnus-original-version-number "\n"
1665 (emacs-version) "\n")
1666 (when (and (boundp 'nntp-server-type)
1667 (stringp nntp-server-type))
1668 (insert nntp-server-type))
1669 (insert "\n\n\n\n\n")
1670 (let (mime-content-types)
1671 (mime-edit-insert-tag
1672 "application" "emacs-lisp"
1673 "\nContent-Disposition: inline\nContent-Description: User settings"))
1674 (insert (with-temp-buffer
1677 (let (mime-content-types)
1678 (mime-edit-insert-tag "text" "plain"))
1679 (goto-char (point-min))
1680 (search-forward "Subject: " nil t)
1683 (defun gnus-bug-kill-buffer ()
1684 (when (get-buffer "*Gnus Help Bug*")
1685 (kill-buffer "*Gnus Help Bug*")))
1687 (defun gnus-summary-yank-message (buffer n)
1688 "Yank the current article into a composed message."
1690 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1691 current-prefix-arg))
1692 (when (gnus-buffer-live-p buffer)
1693 (let ((summary-frame (selected-frame))
1694 (message-frame (when (static-if (featurep 'xemacs)
1695 (device-on-window-system-p)
1697 (let ((window (get-buffer-window buffer t)))
1699 (window-frame window)))))
1700 (separator (concat "^" (regexp-quote mail-header-separator)
1702 (gnus-summary-iterate n
1703 (gnus-summary-select-article)
1704 (gnus-copy-article-buffer)
1705 (when (frame-live-p message-frame)
1706 (raise-frame message-frame)
1707 (select-frame message-frame))
1708 (with-current-buffer buffer
1709 (when (save-excursion
1711 (let (case-fold-search)
1712 (and (not (re-search-backward separator nil t))
1713 (re-search-forward separator nil t))))
1714 (goto-char (match-end 0)))
1715 (message-yank-buffer gnus-article-copy))
1716 (select-frame summary-frame))
1717 (when (frame-live-p message-frame)
1718 (select-frame message-frame)))))
1720 (defun gnus-debug ()
1721 "Attempts to go through the Gnus source file and report what variables have been changed.
1722 The source file has to be in the Emacs load path."
1724 (let ((files gnus-debug-files)
1726 file expr olist sym)
1727 (gnus-message 4 "Please wait while we snoop your variables...")
1728 ;; Go through all the files looking for non-default values for variables.
1731 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1734 (when (and (setq file (locate-library (pop files)))
1735 (file-exists-p file))
1736 (insert-file-contents file)
1737 (goto-char (point-min))
1738 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1739 (gnus-message 4 "Malformed sources in file %s" file)
1740 (narrow-to-region (point-min) (point))
1741 (goto-char (point-min))
1742 (while (setq expr (ignore-errors (read (current-buffer))))
1744 (and (memq (car expr) '(defvar defcustom defvoo))
1745 (stringp (nth 3 expr))
1746 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1747 (or (not (boundp (nth 1 expr)))
1748 (not (equal (eval (nth 2 expr))
1749 (symbol-value (nth 1 expr)))))
1750 (push (nth 1 expr) olist)))))))
1751 (kill-buffer (current-buffer)))
1752 (when (setq olist (nreverse olist))
1753 (insert ";----------------- Environment follows ------------------\n\n"))
1755 (if (boundp (car olist))
1757 (pp `(setq ,(car olist)
1758 ,(if (or (consp (setq sym (symbol-value (car olist))))
1760 (not (or (eq sym nil)
1762 (list 'quote (symbol-value (car olist)))
1763 (symbol-value (car olist))))
1765 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1766 (setq olist (cdr olist)))
1767 ;; Remove any control chars - they seem to cause trouble for some
1768 ;; mailers. (Byte-compiled output from the stuff above.)
1770 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1771 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1773 ;; Break MIME tags purposely.
1775 (while (re-search-forward mime-edit-tag-regexp nil t)
1776 (goto-char (1+ (match-beginning 0)))
1779 ;;; Treatment of rejected articles.
1782 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1783 "Re-mail the current message.
1784 This only makes sense if the current message is a bounce message than
1785 contains some mail you have written which has been bounced back to
1787 If FETCH, try to fetch the article that this is a reply to, if indeed
1790 (gnus-summary-select-article t)
1791 (set-buffer gnus-original-article-buffer)
1792 (gnus-setup-message 'compose-bounce
1793 (let* ((references (mail-fetch-field "references"))
1794 (parent (and references (gnus-parent-id references))))
1796 ;; If there are references, we fetch the article we answered to.
1798 (gnus-summary-refer-article parent)
1799 (gnus-summary-show-all-headers)))))
1803 (defun gnus-inews-group-method (group)
1805 ;; If the group doesn't exist, we assume
1806 ;; it's an archive group...
1807 ((and (null (gnus-get-info group))
1808 (eq (car (gnus-server-to-method gnus-message-archive-method))
1809 (car (gnus-server-to-method (gnus-group-method group)))))
1810 gnus-message-archive-method)
1812 ((gnus-info-method (gnus-get-info group))
1813 (gnus-info-method (gnus-get-info group)))
1815 (t (gnus-server-to-method (gnus-group-method group)))))
1817 ;; Do Gcc handling, which copied the message over to some group.
1818 (defun gnus-inews-do-gcc (&optional gcc)
1822 (message-narrow-to-headers)
1823 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1824 (coding-system-for-write 'raw-text)
1825 (output-coding-system 'raw-text)
1826 groups group method group-art
1827 mml-externalize-attachments)
1829 (message-remove-header "gcc")
1831 (setq groups (message-unquote-tokens
1832 (message-tokenize-header gcc " ,")))
1833 ;; Copy the article over to some group(s).
1834 (while (setq group (pop groups))
1835 (unless (gnus-check-server
1836 (setq method (gnus-inews-group-method group)))
1837 (error "Can't open server %s" (if (stringp method) method
1839 (unless (gnus-request-group group nil method)
1840 (gnus-request-create-group group method))
1841 (setq mml-externalize-attachments
1842 (if (stringp gnus-gcc-externalize-attachments)
1843 (string-match gnus-gcc-externalize-attachments group)
1844 gnus-gcc-externalize-attachments))
1846 (nnheader-set-temp-buffer " *acc*")
1847 (insert-buffer-substring message-encoding-buffer)
1848 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1849 (goto-char (point-min))
1850 (when (re-search-forward
1851 (concat "^" (regexp-quote mail-header-separator) "$")
1853 (replace-match "" t t ))
1854 (unless (setq group-art
1855 (gnus-request-accept-article group method t t))
1856 (gnus-message 1 "Couldn't store article in group %s: %s"
1857 group (gnus-status-message method))
1859 (when (and group-art
1860 ;; FIXME: Should gcc-mark-as-read work when
1861 ;; Gnus is not running?
1863 (or gnus-gcc-mark-as-read
1864 gnus-inews-mark-gcc-as-read))
1865 (gnus-group-mark-article-read group (cdr group-art)))
1866 (kill-buffer (current-buffer)))))))))
1868 (defun gnus-inews-insert-gcc ()
1869 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1872 (message-narrow-to-headers)
1873 (let* ((group gnus-outgoing-message-group)
1875 ((gnus-functionp group)
1877 ((or (stringp group) (list group))
1882 (if (string-match " " gcc)
1883 (concat "\"" gcc "\"")
1885 (mapconcat (lambda (group)
1886 (if (string-match " " group)
1887 (concat "\"" group "\"")
1892 (defun gnus-inews-insert-archive-gcc (&optional group)
1893 "Insert the Gcc to say where the article is to be archived."
1894 (let* ((var gnus-message-archive-group)
1895 (group (or group gnus-newsgroup-name ""))
1897 (and gnus-newsgroup-name
1898 (not (equal gnus-newsgroup-name ""))
1899 (gnus-group-find-parameter
1900 gnus-newsgroup-name 'gcc-self)))
1904 ((null gnus-message-archive-method)
1908 ;; Just a single group.
1911 ;; We don't want this.
1913 ((and (listp var) (stringp (car var)))
1914 ;; A list of groups.
1916 ((gnus-functionp var)
1918 (funcall var group))
1920 ;; An alist of regexps/functions/forms.
1925 ((stringp (caar var))
1927 (when (string-match (caar var) group)
1929 ((gnus-functionp (car var))
1931 (funcall (car var) group))
1933 (eval (car var)))))))
1934 (setq var (cdr var)))
1937 (when (or groups gcc-self-val)
1938 (when (stringp groups)
1939 (setq groups (list groups)))
1942 (message-narrow-to-headers)
1943 (goto-char (point-max))
1946 ;; Use the `gcc-self' param value instead.
1949 (if (stringp gcc-self-val)
1950 (if (string-match " " gcc-self-val)
1951 (concat "\"" gcc-self-val "\"")
1953 (if (string-match " " group)
1954 (concat "\"" group "\"")
1956 (if (not (eq gcc-self-val 'none))
1961 ;; Use the list of groups.
1962 (while (setq name (pop groups))
1963 (let ((str (if (string-match ":" name)
1965 (gnus-group-prefixed-name
1966 name gnus-message-archive-method))))
1967 (insert (if (string-match " " str)
1968 (concat "\"" str "\"")
1974 (defun gnus-mailing-list-followup-to ()
1975 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1976 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1977 (list-post (gnus-fetch-original-field "list-post")))
1978 (when (and list-post
1979 (string-match "mailto:\\([^>]+\\)" list-post))
1980 (setq list-post (match-string 1 list-post)))
1986 (defun gnus-configure-posting-styles (&optional group-name)
1987 "Configure posting styles according to `gnus-posting-styles'."
1988 (unless gnus-inhibit-posting-styles
1989 (let ((group (or group-name gnus-newsgroup-name ""))
1990 (styles gnus-posting-styles)
1991 style match attribute results
1993 ;; If the group has a posting-style parameter, add it at the end with a
1994 ;; regexp matching everything, to be sure it takes precedence over all
1996 (when gnus-newsgroup-name
1997 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1999 (setq styles (append styles (list (cons ".*" tmp-style)))))))
2000 ;; Go through all styles and look for matches.
2001 (dolist (style styles)
2002 (setq match (pop style))
2003 (goto-char (point-min))
2006 ;; Regexp string match on the group name.
2007 (string-match match group))
2009 ;; Obsolete format of header match.
2010 (and (gnus-buffer-live-p gnus-article-copy)
2011 (with-current-buffer gnus-article-copy
2012 (let ((header (message-fetch-field (pop style))))
2014 (string-match (pop style) header))))))
2015 ((or (symbolp match)
2016 (gnus-functionp match))
2018 ((gnus-functionp match)
2019 ;; Function to be called.
2022 ;; Variable to be checked.
2023 (symbol-value match))))
2026 ((eq (car match) 'header)
2027 ;; New format of header match.
2028 (and (gnus-buffer-live-p gnus-article-copy)
2029 (with-current-buffer gnus-article-copy
2030 (let ((header (message-fetch-field (nth 1 match))))
2032 (string-match (nth 2 match) header))))))
2034 ;; This is a form to be evaled.
2036 ;; We have a match, so we set the variables.
2037 (setq style (gnus-configure-posting-style style nil))
2038 (dolist (attribute style)
2039 (setq results (delq (assoc (car attribute) results) results))
2040 (push attribute results))))
2041 ;; Now we have all the styles, so we insert them.
2042 (setq name (assq 'name results)
2043 address (assq 'address results))
2044 (setq results (delq name (delq address results)))
2045 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2046 (make-local-hook 'message-setup-hook)
2047 (setq results (sort results (lambda (x y)
2048 (string-lessp (car x) (car y)))))
2049 (dolist (result results)
2050 (add-hook 'message-setup-hook
2052 ((eq 'eval (car result))
2054 ((eq 'body (car result))
2058 (insert ,(cdr result)))))
2059 ((eq 'signature (car result))
2060 (set (make-local-variable 'message-signature) nil)
2061 (set (make-local-variable 'message-signature-file) nil)
2062 (if (not (cdr result))
2066 (let ((message-signature ,(cdr result)))
2067 (when message-signature
2068 (message-insert-signature)))))))
2071 (if (symbolp (car result))
2072 (capitalize (symbol-name (car result)))
2076 (message-remove-header ,header)
2077 (let ((value ,(cdr result)))
2080 (insert ,header ": " value)
2082 (insert "\n")))))))))
2084 (when (or name address)
2085 (add-hook 'message-setup-hook
2087 (set (make-local-variable 'user-mail-address)
2088 ,(or (cdr address) user-mail-address))
2089 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2091 ,(or (cdr address) user-mail-address)))
2093 (message-remove-header "From")
2095 (insert "From: " (message-make-from) "\n"))))
2098 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2099 (defun gnus-configure-posting-style (style stack)
2100 "Parse one posting style STYLE and returns the value as an alist."
2101 (let (results element variable filep value v)
2102 (dolist (attribute style)
2103 (setq element (pop attribute)
2108 ((eq (car attribute) ':file)
2111 ((eq (car attribute) :value)
2115 ;; We get the value.
2120 ((or (symbolp value)
2121 (gnus-functionp value))
2122 (cond ((gnus-functionp value)
2125 (symbol-value value))))
2128 ;; Translate obsolescent value.
2130 ((eq element 'signature-file)
2131 (setq element 'signature
2133 ((eq element 'x-face-file)
2134 (setq element 'x-face
2136 ;; Get the contents of file elems.
2138 (setq v (with-temp-buffer
2139 (insert-file-contents v)
2140 (goto-char (point-max))
2144 (if (eq element 'import)
2146 (if (member v stack)
2147 (error "Circular import of \"%s\"" v))
2149 (nconc (nreverse (gnus-configure-posting-style
2150 (cdr (assoc v gnus-named-posting-styles))
2153 (push (cons element v) results)))
2154 (nreverse results)))
2156 (defun gnus-summary-execute-command-with-posting-style (style command)
2157 "Temporarily select a posting-style named STYLE and execute COMMAND."
2159 (let ((style (completing-read "Posting style: "
2160 gnus-named-posting-styles nil t)))
2164 (format "Command to execute with %s: " style))))))
2165 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2166 (call-interactively command)))
2169 ;;; @ for MIME Edit mode
2172 (defun gnus-maybe-setup-default-charset ()
2174 (and (boundp 'gnus-summary-buffer)
2175 (buffer-live-p gnus-summary-buffer)
2177 (set-buffer gnus-summary-buffer)
2178 default-mime-charset))))
2181 (make-local-variable 'default-mime-charset)
2182 (setq default-mime-charset charset)
2186 ;;; @ for MIME view mode
2189 (defun gnus-following-method (buf)
2190 (gnus-setup-message 'reply-yank
2192 (if (message-news-p)
2194 (message-reply nil 'wide))
2195 (let ((message-reply-buffer buf))
2196 (message-yank-original))
2197 (message-goto-body))
2201 ;;; Allow redefinition of functions.
2207 ;;; gnus-msg.el ends here