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 replys to signed messages.
265 See also the `mml-default-sign-method' variable."
269 (defcustom gnus-message-replyencrypt
271 "Automatically encrypt replys 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
289 (defcustom gnus-summary-resend-default-address t
290 "If non-nil, Gnus tries to suggest a default address to resend to.
291 If nil, the address field will always be empty after invoking
292 `gnus-summary-resend-message'."
296 ;;; Internal variables.
298 (defvar gnus-inhibit-posting-styles nil
299 "Inhibit the use of posting styles.")
301 (defvar gnus-article-yanked-articles nil)
302 (defvar gnus-message-buffer "*Mail Gnus*")
303 (defvar gnus-article-copy nil)
304 (defvar gnus-check-before-posting nil)
305 (defvar gnus-last-posting-server nil)
306 (defvar gnus-message-group-art nil)
308 (defvar gnus-msg-force-broken-reply-to nil)
310 (defconst gnus-bug-message
311 (format "Sending a bug report to the Gnus Towers.
312 ========================================
314 This gnus is the %s%s.
315 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
316 Developers. (the addresses below are mailing list addresses)
318 ========================================
320 The buffer below is a mail buffer. When you press `C-c C-c', it will
321 be sent to the Gnus Bug Exterminators.
323 The thing near the bottom of the buffer is how the environment
324 settings will be included in the mail. Please do not delete that.
325 They will tell the Bug People what your environment is, so that it
326 will be easier to locate the bugs.
328 If you have found a bug that makes Emacs go \"beep\", set
329 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
330 and include the backtrace in your bug report.
332 Please describe the bug in annoying, painstaking detail.
334 Thank you for your help in stamping out bugs.
337 (if (string= gnus-product-name "Semi-gnus")
339 ", a modified version of Semi-gnus")))
342 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
343 (autoload 'news-setup "rnewspost")
344 (autoload 'news-reply-mode "rnewspost")
345 (autoload 'rmail-dont-reply-to "mail-utils")
346 (autoload 'rmail-output "rmailout"))
350 ;;; Gnus Posting Functions
353 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
354 "p" gnus-summary-post-news
355 "i" gnus-summary-news-other-window
356 "f" gnus-summary-followup
357 "F" gnus-summary-followup-with-original
358 "c" gnus-summary-cancel-article
359 "s" gnus-summary-supersede-article
360 "r" gnus-summary-reply
361 "y" gnus-summary-yank-message
362 "R" gnus-summary-reply-with-original
363 "w" gnus-summary-wide-reply
364 "W" gnus-summary-wide-reply-with-original
365 "v" gnus-summary-very-wide-reply
366 "V" gnus-summary-very-wide-reply-with-original
367 "n" gnus-summary-followup-to-mail
368 "N" gnus-summary-followup-to-mail-with-original
369 "m" gnus-summary-mail-other-window
370 "u" gnus-uu-post-news
371 "\M-c" gnus-summary-mail-crosspost-complaint
372 "Br" gnus-summary-reply-broken-reply-to
373 "BR" gnus-summary-reply-broken-reply-to-with-original
374 "om" gnus-summary-mail-forward
375 "op" gnus-summary-post-forward
376 "Om" gnus-summary-digest-mail-forward
377 "Op" gnus-summary-digest-post-forward
378 "P" gnus-summary-execute-command-with-posting-style)
380 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
381 "b" gnus-summary-resend-bounced-mail
382 ;; "c" gnus-summary-send-draft
383 "r" gnus-summary-resend-message
384 "e" gnus-summary-resend-message-edit)
386 ;;; Internal functions.
388 (defun gnus-inews-make-draft ()
390 (gnus-inews-make-draft-meta-information
391 ,gnus-newsgroup-name ',gnus-article-reply)))
393 (defvar gnus-article-reply nil)
394 (defmacro gnus-setup-message (config &rest forms)
395 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
396 (buffer (make-symbol "gnus-setup-message-buffer"))
397 (article (make-symbol "gnus-setup-message-article"))
398 (yanked (make-symbol "gnus-setup-yanked-articles"))
399 (group (make-symbol "gnus-setup-message-group")))
400 `(let ((,winconf (current-window-configuration))
401 (,buffer (buffer-name (current-buffer)))
402 (,article gnus-article-reply)
403 (,yanked gnus-article-yanked-articles)
404 (,group gnus-newsgroup-name)
405 (message-header-setup-hook
406 (copy-sequence message-header-setup-hook))
407 (message-mode-hook (copy-sequence message-mode-hook))
408 (message-startup-parameter-alist
409 '((reply-buffer . gnus-copy-article-buffer)
410 (original-buffer . gnus-original-article-buffer)
411 (user-agent . Gnus))))
412 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
413 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
414 ;; #### FIXME: for a reason that I did not manage to identify yet,
415 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
416 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
417 ;; After evaluation of @forms below, it gets the value we actually want
418 ;; to override, and the posting styles are used. For that reason, I've
419 ;; added an optional argument to `gnus-configure-posting-styles' to
420 ;; make sure that the correct value for the group name is used. -- drv
421 (add-hook 'message-mode-hook
423 (gnus-configure-posting-styles ,group)))
424 (gnus-pull ',(intern gnus-draft-meta-information-header)
425 message-required-headers)
427 (not (string= ,group "")))
429 (intern gnus-draft-meta-information-header)
430 (gnus-inews-make-draft))
431 message-required-headers))
435 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
437 (setq gnus-message-buffer (current-buffer))
438 (set (make-local-variable 'gnus-message-group-art)
439 (cons ,group ,article))
440 (set (make-local-variable 'gnus-newsgroup-name) ,group)
441 (gnus-maybe-setup-default-charset)
442 (gnus-run-hooks 'gnus-message-setup-hook))
444 (gnus-configure-windows ,config t)
445 (run-hooks 'post-command-hook)
446 (set-buffer-modified-p nil))))
448 (defun gnus-inews-make-draft-meta-information (group article)
449 (concat "(\"" group "\" "
450 (if article (number-to-string
457 (defun gnus-msg-mail (&optional to subject other-headers continue
458 switch-action yank-action send-actions)
459 "Start editing a mail message to be sent.
460 Like `message-mail', but with Gnus paraphernalia, particularly the
461 Gcc: header for archiving purposes."
463 (let ((buf (current-buffer))
465 (gnus-setup-message 'message
466 (message-mail to subject other-headers continue
467 nil yank-action send-actions))
469 (setq mail-buf (current-buffer))
470 (switch-to-buffer buf)
471 (apply switch-action mail-buf nil)))
472 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
475 (defvar save-selected-window-window)
478 (defun gnus-button-mailto (address)
480 (set-buffer (gnus-copy-article-buffer))
481 (gnus-setup-message 'message
482 (message-reply address))
483 (and (boundp 'save-selected-window-window)
484 (not (window-live-p save-selected-window-window))
485 (setq save-selected-window-window (selected-window))))
488 (defun gnus-button-reply (&optional to-address wide)
489 "Like `message-reply'."
491 (gnus-setup-message 'message
492 (message-reply to-address wide))
493 (and (boundp 'save-selected-window-window)
494 (not (window-live-p save-selected-window-window))
495 (setq save-selected-window-window (selected-window))))
498 (define-mail-user-agent 'gnus-user-agent
499 'gnus-msg-mail 'message-send-and-exit
500 'message-kill-buffer 'message-send-hook)
502 (defun gnus-setup-posting-charset (group)
503 (let ((alist gnus-group-posting-charset-alist)
504 (group (or group ""))
508 (while (setq elem (pop alist))
509 (when (or (and (stringp (car elem))
510 (string-match (car elem) group))
511 (and (gnus-functionp (car elem))
512 (funcall (car elem) group))
513 (and (symbolp (car elem))
514 (symbol-value (car elem))))
515 (throw 'found (cons (cadr elem) (caddr elem)))))))))
517 (defun gnus-inews-add-send-actions (winconf buffer article
518 &optional config yanked)
519 (make-local-hook 'message-sent-hook)
520 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
521 'gnus-inews-do-gcc) nil t)
523 (make-local-hook 'message-header-hook)
524 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
525 (setq message-post-method
527 (gnus-post-method arg ,gnus-newsgroup-name)))
528 (setq message-user-agent (gnus-extended-version))
529 (when (not message-use-multi-frames)
531 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
533 `(when (gnus-buffer-exists-p ,buffer)
537 (if (eq config 'forward)
538 `(gnus-summary-mark-article-as-forwarded ',yanked)
539 `(gnus-summary-mark-article-as-replied ',yanked)))))
542 (put 'gnus-setup-message 'lisp-indent-function 1)
543 (put 'gnus-setup-message 'edebug-form-spec '(form body))
545 ;;; Post news commands of Gnus group mode and summary mode
547 (defun gnus-group-mail (&optional arg)
548 "Start composing a mail.
549 If ARG, use the group under the point to find a posting style.
550 If ARG is 1, prompt for a group name to find the posting style."
552 ;; We can't `let' gnus-newsgroup-name here, since that leads
553 ;; to local variables leaking.
554 (let ((group gnus-newsgroup-name)
555 ;; make sure last viewed article doesn't affect posting styles:
557 (buffer (current-buffer)))
560 (setq gnus-newsgroup-name
562 (if (= 1 (prefix-numeric-value arg))
563 (completing-read "Use posting style of group: "
564 gnus-active-hashtb nil
565 (gnus-read-active-file-p))
566 (gnus-group-group-name))
568 ;; #### see comment in gnus-setup-message -- drv
569 (gnus-setup-message 'message (message-mail)))
572 (setq gnus-newsgroup-name group)))))
574 (defun gnus-group-news (&optional arg)
575 "Start composing a news.
576 If ARG, post to group under point.
577 If ARG is 1, prompt for group name to post to.
579 This function prepares a news even when using mail groups. This is useful
580 for posting messages to mail groups without actually sending them over the
581 network. The corresponding backend must have a 'request-post method."
583 ;; We can't `let' gnus-newsgroup-name here, since that leads
584 ;; to local variables leaking.
585 (let ((group gnus-newsgroup-name)
586 ;; make sure last viewed article doesn't affect posting styles:
588 (buffer (current-buffer)))
591 (setq gnus-newsgroup-name
593 (if (= 1 (prefix-numeric-value arg))
594 (completing-read "Use group: "
595 gnus-active-hashtb nil
596 (gnus-read-active-file-p))
597 (gnus-group-group-name))
599 ;; #### see comment in gnus-setup-message -- drv
600 (gnus-setup-message 'message
601 (message-news (gnus-group-real-name gnus-newsgroup-name))))
604 (setq gnus-newsgroup-name group)))))
606 (defun gnus-group-post-news (&optional arg)
607 "Start composing a message (a news by default).
608 If ARG, post to group under point. If ARG is 1, prompt for group name.
609 Depending on the selected group, the message might be either a mail or
612 ;; Bind this variable here to make message mode hooks work ok.
613 (let ((gnus-newsgroup-name
615 (if (= 1 (prefix-numeric-value arg))
616 (completing-read "Newsgroup: " gnus-active-hashtb nil
617 (gnus-read-active-file-p))
618 (gnus-group-group-name))
620 ;; make sure last viewed article doesn't affect posting styles:
622 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
623 (string= gnus-newsgroup-name ""))))
625 (defun gnus-summary-mail-other-window (&optional arg)
626 "Start composing a mail in another window.
627 Use the posting of the current group by default.
628 If ARG, don't do that. If ARG is 1, prompt for group name to find the
631 ;; We can't `let' gnus-newsgroup-name here, since that leads
632 ;; to local variables leaking.
633 (let ((group gnus-newsgroup-name)
634 ;; make sure last viewed article doesn't affect posting styles:
636 (buffer (current-buffer)))
639 (setq gnus-newsgroup-name
641 (if (= 1 (prefix-numeric-value arg))
642 (completing-read "Use group: "
643 gnus-active-hashtb nil
644 (gnus-read-active-file-p))
646 gnus-newsgroup-name))
647 ;; #### see comment in gnus-setup-message -- drv
648 (gnus-setup-message 'message (message-mail)))
651 (setq gnus-newsgroup-name group)))))
653 (defun gnus-summary-news-other-window (&optional arg)
654 "Start composing a news in another window.
655 Post to the current group by default.
656 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
658 This function prepares a news even when using mail groups. This is useful
659 for posting messages to mail groups without actually sending them over the
660 network. The corresponding backend must have a 'request-post method."
662 ;; We can't `let' gnus-newsgroup-name here, since that leads
663 ;; to local variables leaking.
664 (let ((group gnus-newsgroup-name)
665 ;; make sure last viewed article doesn't affect posting styles:
667 (buffer (current-buffer)))
670 (setq gnus-newsgroup-name
672 (if (= 1 (prefix-numeric-value arg))
673 (completing-read "Use group: "
674 gnus-active-hashtb nil
675 (gnus-read-active-file-p))
677 gnus-newsgroup-name))
678 ;; #### see comment in gnus-setup-message -- drv
679 (gnus-setup-message 'message
680 (message-news (gnus-group-real-name gnus-newsgroup-name))))
683 (setq gnus-newsgroup-name group)))))
685 (defun gnus-summary-post-news (&optional arg)
686 "Start composing a message. Post to the current group by default.
687 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
688 Depending on the selected group, the message might be either a mail or
691 ;; Bind this variable here to make message mode hooks work ok.
692 (let ((gnus-newsgroup-name
694 (if (= 1 (prefix-numeric-value arg))
695 (completing-read "Newsgroup: " gnus-active-hashtb nil
696 (gnus-read-active-file-p))
698 gnus-newsgroup-name))
699 ;; make sure last viewed article doesn't affect posting styles:
701 (gnus-post-news 'post gnus-newsgroup-name)))
704 (defun gnus-summary-followup (yank &optional force-news)
705 "Compose a followup to an article.
706 If prefix argument YANK is non-nil, the original article is yanked
708 YANK is a list of elements, where the car of each element is the
709 article number, and the two following numbers is the region to be
712 (list (and current-prefix-arg
713 (gnus-summary-work-articles 1))))
715 (gnus-summary-goto-subject
716 (if (listp (car yank))
719 (save-window-excursion
720 (gnus-summary-select-article))
721 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
722 (gnus-newsgroup-name gnus-newsgroup-name))
724 (gnus-post-news nil gnus-newsgroup-name
725 headers gnus-article-buffer
727 (gnus-summary-handle-replysign)))
729 (defun gnus-summary-followup-with-original (n &optional force-news)
730 "Compose a followup to an article and include the original article."
732 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
734 (defun gnus-summary-followup-to-mail (&optional arg)
735 "Followup to the current mail message via news."
737 (list (and current-prefix-arg
738 (gnus-summary-work-articles 1))))
739 (gnus-summary-followup arg t))
741 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
742 "Followup to the current mail message via news."
744 (gnus-summary-followup (gnus-summary-work-articles arg) t))
746 (defun gnus-inews-yank-articles (articles)
747 (let (beg article yank-string
748 (more-than-one (cdr articles))
749 (cur (current-buffer))
752 (while (setq article (pop articles))
753 (when (listp article)
754 (setq yank-string (nth 1 article)
755 article (nth 0 article)))
756 (save-window-excursion
757 (set-buffer gnus-summary-buffer)
758 (gnus-summary-select-article nil nil nil article)
759 (gnus-summary-remove-process-mark article))
761 ;; Gathering references.
763 (setq refs (message-list-references
765 (mail-header-references gnus-current-headers)
766 (mail-header-message-id gnus-current-headers)))
767 (when message-use-multi-frames
768 (when (setq window (get-buffer-window cur t))
769 (select-frame (window-frame window)))))
771 (gnus-copy-article-buffer nil yank-string)
772 (let ((message-reply-buffer gnus-article-copy)
773 (message-reply-headers
774 ;; The headers are decoded.
775 (with-current-buffer gnus-article-copy
777 (nnheader-narrow-to-headers)
778 (nnheader-parse-naked-head)))))
779 (message-yank-original)
780 (setq beg (or beg (mark t))))
785 ;; Replace with the gathered references.
789 (message-narrow-to-headers)
790 (let ((case-fold-search t))
791 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
793 (goto-char (point-max))))
795 (list (or (assq 'References message-header-format-alist)
796 '(References . message-shorten-references)))
797 (list (cons 'References
798 (mapconcat 'identity (nreverse refs) " "))))
799 (backward-delete-char 1))
805 (defun gnus-summary-cancel-article (&optional n symp)
806 "Cancel an article you posted.
807 Uses the process-prefix convention. If given the symbolic
808 prefix `a', cancel using the standard posting method; if not
809 post using the current select method."
810 (interactive (gnus-interactive "P\ny"))
811 (let ((articles (gnus-summary-work-articles n))
814 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
816 (while (setq article (pop articles))
817 (when (gnus-summary-select-article t nil nil article)
818 (when (gnus-eval-in-buffer-window gnus-article-buffer
820 (set-buffer gnus-original-article-buffer)
821 (message-cancel-news)))
822 (gnus-summary-mark-as-read article gnus-canceled-mark)
823 (gnus-cache-remove-article 1))
824 (gnus-article-hide-headers-if-wanted))
825 (gnus-summary-remove-process-mark article))))
827 (defun gnus-summary-supersede-article ()
828 "Compose an article that will supersede a previous article.
829 This is done simply by taking the old article and adding a Supersedes
830 header line with the old Message-ID."
832 (let ((article (gnus-summary-article-number)))
833 (gnus-setup-message 'reply-yank
834 (gnus-summary-select-article t)
835 (set-buffer gnus-original-article-buffer)
839 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
841 (set-buffer ,gnus-summary-buffer)
842 (gnus-cache-possibly-remove-article ,article nil nil nil t)
843 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
844 message-send-actions))))
848 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
849 ;; make a copy of the article buffer with all text properties removed
850 ;; this copy is in the buffer gnus-article-copy.
851 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
852 ;; this buffer should be passed to all mail/news reply/post routines.
853 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
855 (set-buffer gnus-article-copy)
856 (set-buffer-multibyte t))
857 (let ((article-buffer (or article-buffer gnus-article-buffer))
859 (if (not (and (get-buffer article-buffer)
860 (gnus-buffer-exists-p article-buffer)))
861 (error "Can't find any article buffer")
863 (set-buffer article-buffer)
864 (let ((gnus-newsgroup-charset (or gnus-article-charset
865 gnus-newsgroup-charset))
866 (gnus-newsgroup-ignored-charsets
867 (or gnus-article-ignored-charsets
868 gnus-newsgroup-ignored-charsets)))
870 ;; Copy over the (displayed) article buffer, delete
871 ;; hidden text and remove text properties.
873 (copy-to-buffer gnus-article-copy (point-min) (point-max))
874 (set-buffer gnus-article-copy)
875 ;; There's invisible and intangible text in T-gnus. Especially,
876 ;; if there is a boundary line (X-Boundary: ------------------),
877 ;; in the end of a header, it will cause a serious problem.
878 (add-text-properties (point-min) (point-max)
879 '(invisible nil intangible nil))
882 (delete-region (point) (point-max))
883 (insert yank-string))
884 ;; Encode bitmap smileys to ordinary text.
885 ;; Possibly, the original text might be restored.
886 (static-unless (featurep 'xemacs)
887 (when (featurep 'smiley-mule)
888 (smiley-encode-buffer)))
889 (gnus-article-delete-text-of-type 'annotation)
890 (gnus-remove-text-with-property 'gnus-prev)
891 (gnus-remove-text-with-property 'gnus-next)
892 (gnus-remove-text-with-property 'gnus-decoration)
893 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
896 (static-if (featurep 'xemacs)
897 ;; Revome smiley extents for (possibly) XEmacs 21.1.
899 (buffer-substring-no-properties (point-min)
901 (buffer-substring-no-properties (point-min) (point-max)))
903 ;; Find the original headers.
904 (set-buffer gnus-original-article-buffer)
905 (goto-char (point-min))
906 (while (looking-at message-unix-mail-delimiter)
908 (let ((mail-header-separator ""))
910 end (or (message-goto-body) beg)))
911 ;; Delete the headers from the displayed articles.
912 (set-buffer gnus-article-copy)
913 (let ((mail-header-separator ""))
914 (delete-region (goto-char (point-min))
915 (or (message-goto-body) (point-max))))
916 ;; Insert the original article headers.
917 (insert-buffer-substring gnus-original-article-buffer beg end)
919 (let ((gnus-article-decode-hook
920 (delq 'article-decode-charset
921 (copy-sequence gnus-article-decode-hook))))
922 ;; Needed for T-gnus.
923 (add-hook 'gnus-article-decode-hook
924 'article-decode-encoded-words)
925 (run-hooks 'gnus-article-decode-hook)))))
928 (defun gnus-post-news (post &optional group header article-buffer yank subject
931 (gnus-copy-article-buffer))
932 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
933 (gnus-article-yanked-articles yank)
934 (add-to-list gnus-add-to-list))
935 (gnus-setup-message (cond (yank 'reply-yank)
936 (article-buffer 'reply)
938 (let* ((group (or group gnus-newsgroup-name))
939 (charset (gnus-group-name-charset nil group))
941 to-address to-group mailing-list to-list
944 (setq to-address (gnus-parameter-to-address group)
945 to-group (gnus-group-find-parameter group 'to-group)
946 to-list (gnus-parameter-to-list group)
947 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
948 mailing-list (when gnus-mailing-list-groups
949 (string-match gnus-mailing-list-groups group))
950 group (gnus-group-name-decode (gnus-group-real-name group)
952 (if (or (and to-group
953 (gnus-news-group-p to-group))
956 (and (gnus-news-group-p
957 (or pgroup gnus-newsgroup-name)
958 (or header gnus-current-article))
964 (message-news (or to-group group))
965 (set-buffer gnus-article-copy)
966 (gnus-msg-treat-broken-reply-to)
967 (message-followup (if (or newsgroup-p force-news)
968 (if (save-restriction
969 (article-narrow-to-head)
970 (message-fetch-field "newsgroups"))
977 (message-mail (or to-address to-list))
978 ;; Arrange for mail groups that have no `to-address' to
979 ;; get that when the user sends off the mail.
980 (when (and (not to-list)
983 (push (list 'gnus-inews-add-to-address pgroup)
984 message-send-actions)))
985 (set-buffer gnus-article-copy)
986 (gnus-msg-treat-broken-reply-to)
987 (message-wide-reply to-address)))
989 (gnus-inews-yank-articles yank))))))
991 (defun gnus-msg-treat-broken-reply-to (&optional force)
992 "Remove the Reply-to header if broken-reply-to."
994 (gnus-group-find-parameter
995 gnus-newsgroup-name 'broken-reply-to))
997 (message-narrow-to-head)
998 (message-remove-header "reply-to"))))
1000 (defun gnus-post-method (arg group &optional silent)
1001 "Return the posting method based on GROUP and ARG.
1002 If SILENT, don't prompt the user."
1003 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1005 (group-method (gnus-find-method-for-group group)))
1007 ;; If the group-method is nil (which shouldn't happen) we use
1008 ;; the default method.
1009 ((null group-method)
1010 (or (and (listp gnus-post-method) ;If not current/native/nil
1011 (not (listp (car gnus-post-method))) ; and not a list of methods
1012 gnus-post-method) ;then use it.
1014 message-post-method))
1015 ;; We want the inverse of the default
1016 ((and arg (not (eq arg 0)))
1017 (if (eq gnus-post-method 'current)
1020 ;; We query the user for a post method.
1022 (and (listp gnus-post-method)
1023 (listp (car gnus-post-method))))
1025 ;; Collect all methods we know about.
1027 (when (listp gnus-post-method)
1028 (if (listp (car gnus-post-method))
1030 (list gnus-post-method)))
1031 gnus-secondary-select-methods
1032 (mapcar 'cdr gnus-server-alist)
1033 (mapcar 'car gnus-opened-servers)
1034 (list gnus-select-method)
1035 (list group-method)))
1036 method-alist post-methods method)
1037 ;; Weed out all mail methods.
1039 (setq method (gnus-server-get-method "" (pop methods)))
1040 (when (and (or (gnus-method-option-p method 'post)
1041 (gnus-method-option-p method 'post-mail))
1042 (not (member method post-methods)))
1043 (push method post-methods)))
1044 ;; Create a name-method alist.
1048 (if (equal (cadr m) "")
1049 (list (symbol-name (car m)) m)
1050 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1055 (setq gnus-last-posting-server
1057 gnus-last-posting-server)
1058 ;; Just use the last value.
1059 gnus-last-posting-server
1061 "Posting method: " method-alist nil t
1062 (cons (or gnus-last-posting-server "") 0))))
1064 ;; Override normal method.
1065 ((and (eq gnus-post-method 'current)
1066 (not (memq (car group-method) gnus-discouraged-post-methods))
1067 (gnus-get-function group-method 'request-post t))
1070 ;; Use gnus-post-method.
1071 ((listp gnus-post-method) ;A method...
1072 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1074 ;; Use the normal select method (nil or native).
1075 (t gnus-select-method))))
1078 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1080 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1081 variable `mime-edit-user-agent-value' is bound, the value will be
1082 included in the return value. If MAX-COLUMN is specified, the return
1083 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1084 whether a newline should be inserted in front of each product-token.
1085 If the value is t or `hard', it works strictly. Otherwise, if it is
1086 non-nil (e.g. `soft'), it works semi-strictly.
1088 Here is an example of how to use this function:
1090 \(add-hook 'gnus-message-setup-hook
1092 (setq message-user-agent nil)
1095 (message-narrow-to-headers)
1096 (goto-char (point-max))
1097 (insert \"User-Agent: \"
1098 (gnus-message-make-user-agent t 76 'soft)
1101 (let ((user-agent (if (and include-mime-info
1102 (boundp 'mime-edit-user-agent-value))
1103 (concat (gnus-extended-version)
1105 mime-edit-user-agent-value)
1106 (gnus-extended-version))))
1108 (unless (natnump max-column)
1109 (setq max-column 76))
1111 (set-buffer-multibyte t)
1112 (insert (mapconcat 'identity (split-string user-agent) " "))
1113 (goto-char (point-min))
1115 start agent agents width element swidth)
1116 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1117 (setq start (match-beginning 0))
1118 (if (eq (char-after start) ?\()
1122 (push (buffer-substring start (point)) agent))
1124 (push (nreverse agent) agents))
1125 (setq agent (list (match-string 1)))))
1127 (push (nreverse agent) agents))
1128 (setq agents (nreverse agents))
1129 (if (> (+ 12 (string-width (caar agents))) max-column)
1130 (setq user-agent "\n"
1135 (setq agent (car agents)
1136 agents (cdr agents))
1137 (when (and (not bol)
1138 (or (memq newline-product '(t hard))
1139 (and newline-product
1141 (string-width (mapconcat 'identity
1144 (setq user-agent (concat user-agent "\n")
1148 (setq element (car agent)
1149 swidth (string-width element)
1152 (setq user-agent (if (member user-agent '("" "\n"))
1153 (concat user-agent element)
1154 (concat user-agent " " element))
1155 width (+ width 1 swidth)
1157 (if (> (+ width 1 swidth) max-column)
1158 (setq user-agent (concat user-agent "\n " element)
1160 (setq user-agent (concat user-agent " " element)
1161 width (+ width 1 swidth)))))))))
1166 ;;; Gnus Mail Functions
1169 ;;; Mail reply commands of Gnus summary mode
1171 (defun gnus-summary-reply (&optional yank wide very-wide)
1172 "Start composing a mail reply to the current message.
1173 If prefix argument YANK is non-nil, the original article is yanked
1175 If WIDE, make a wide reply.
1176 If VERY-WIDE, make a very wide reply."
1178 (list (and current-prefix-arg
1179 (gnus-summary-work-articles 1))))
1180 ;; Allow user to require confirmation before replying by mail to the
1181 ;; author of a news article.
1182 (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1183 (not gnus-confirm-mail-reply-to-news)
1184 (y-or-n-p "Really reply by mail to article author? "))
1186 (if (listp (car yank))
1189 (gnus-article-reply (or article (gnus-summary-article-number)))
1190 (gnus-article-yanked-articles yank)
1192 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1194 (gnus-summary-goto-subject article))
1195 (gnus-setup-message (if yank 'reply-yank 'reply)
1197 (gnus-summary-select-article)
1198 (dolist (article very-wide)
1199 (gnus-summary-select-article nil nil nil article)
1201 (set-buffer (gnus-copy-article-buffer))
1202 (gnus-msg-treat-broken-reply-to)
1204 (message-narrow-to-head)
1205 (setq headers (concat headers (buffer-string)))))))
1206 (set-buffer (gnus-copy-article-buffer))
1207 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1209 (message-narrow-to-head)
1213 (goto-char (point-max)))
1214 (message-reply nil wide)
1216 (gnus-inews-yank-articles yank))
1217 (gnus-summary-handle-replysign)))))
1219 (defun gnus-summary-handle-replysign ()
1220 "Check the various replysign variables and take action accordingly."
1221 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1222 (let (signed encrypted)
1224 (set-buffer gnus-article-buffer)
1225 (setq signed (memq 'signed gnus-article-wash-types))
1226 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1227 (cond ((and gnus-message-replyencrypt encrypted)
1228 (mml-secure-message mml-default-encrypt-method
1229 (if gnus-message-replysignencrypted
1232 ((and gnus-message-replysign signed)
1233 (mml-secure-message mml-default-sign-method 'sign))))))
1235 (defun gnus-summary-reply-with-original (n &optional wide)
1236 "Start composing a reply mail to the current message.
1237 The original article will be yanked."
1239 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1241 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1242 "Like `gnus-summary-reply' except removing reply-to field.
1243 If prefix argument YANK is non-nil, the original article is yanked
1245 If WIDE, make a wide reply.
1246 If VERY-WIDE, make a very wide reply."
1248 (list (and current-prefix-arg
1249 (gnus-summary-work-articles 1))))
1250 (let ((gnus-msg-force-broken-reply-to t))
1251 (gnus-summary-reply yank wide very-wide)))
1253 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1254 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1255 The original article will be yanked."
1257 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1259 (defun gnus-summary-wide-reply (&optional yank)
1260 "Start composing a wide reply mail to the current message.
1261 If prefix argument YANK is non-nil, the original article is yanked
1264 (list (and current-prefix-arg
1265 (gnus-summary-work-articles 1))))
1266 (gnus-summary-reply yank t))
1268 (defun gnus-summary-wide-reply-with-original (n)
1269 "Start composing a wide reply mail to the current message.
1270 The original article will be yanked."
1272 (gnus-summary-reply-with-original n t))
1274 (defun gnus-summary-very-wide-reply (&optional yank)
1275 "Start composing a very wide reply mail to the current message.
1276 If prefix argument YANK is non-nil, the original article is yanked
1279 (list (and current-prefix-arg
1280 (gnus-summary-work-articles 1))))
1281 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1283 (defun gnus-summary-very-wide-reply-with-original (n)
1284 "Start composing a very wide reply mail to the current message.
1285 The original article will be yanked."
1288 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1290 (defun gnus-summary-mail-forward (&optional full-headers post)
1291 "Forward the current message(s) to another user.
1292 If process marks exist, forward all marked messages;
1293 If FULL-HEADERS (the prefix), include full headers when forwarding.
1295 Note that this function definition for T-gnus is totally different
1296 from the original Gnus."
1298 (if (cdr (gnus-summary-work-articles nil))
1299 ;; Process marks are given.
1300 (gnus-summary-digest-mail-forward nil post)
1301 ;; No process marks.
1302 (let* ((gnus-article-reply (gnus-summary-article-number))
1303 (gnus-article-yanked-articles (list (list gnus-article-reply)))
1305 (message-included-forward-headers
1306 (if full-headers "" message-included-forward-headers)))
1307 (gnus-setup-message 'forward
1308 (gnus-summary-select-article)
1309 (setq charset default-mime-charset)
1310 (set-buffer gnus-original-article-buffer)
1311 (make-local-variable 'default-mime-charset)
1312 (setq default-mime-charset charset)
1313 (message-forward post)))))
1315 (defun gnus-summary-digest-mail-forward (&optional n post)
1316 "Digests and forwards all articles in this series.
1317 If N is a positive number, forward the N next articles.
1318 If N is a negative number, forward the N previous articles.
1319 If N is nil and any articles have been marked with the process mark,
1320 forward those articles instead.
1321 Optional POST will use news to forward instead of mail."
1323 (let ((articles (gnus-summary-work-articles n))
1324 (topics "Topics:\n")
1325 subject article frame)
1326 (when (car articles)
1327 (gnus-setup-message 'forward
1328 (gnus-summary-select-article)
1330 (setq articles (sort articles '<)
1331 subject "Digested Articles")
1332 (with-current-buffer gnus-original-article-buffer
1333 (setq subject (message-make-forward-subject))))
1335 (message-news nil subject)
1336 (message-mail nil subject))
1337 (when (and message-use-multi-frames (cdr articles))
1338 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1340 (while (setq article (pop articles))
1341 (save-window-excursion
1342 (set-buffer gnus-summary-buffer)
1343 (gnus-summary-select-article nil nil nil article)
1344 (setq topics (concat topics " "
1345 (mail-header-subject gnus-current-headers)
1347 (gnus-summary-remove-process-mark article))
1349 (select-frame frame))
1350 (insert (mime-make-tag "message" "rfc822") "\n")
1351 (narrow-to-region (point) (point))
1352 (insert-buffer-substring gnus-original-article-buffer)
1354 (article-narrow-to-head)
1355 (message-remove-header message-included-forward-headers t nil t))
1356 (goto-char (point-max))
1362 (mime-edit-enclose-digest-region (point)(mark t))))))
1364 (defun gnus-summary-digest-post-forward (&optional n)
1365 "Digest and forwards all articles in this series to a newsgroup.
1366 If N is a positive number, forward the N next articles.
1367 If N is a negative number, forward the N previous articles.
1368 If N is nil and any articles have been marked with the process mark,
1369 forward those articles instead."
1371 (gnus-summary-digest-mail-forward n t))
1373 (defun gnus-summary-resend-message (address n)
1374 "Resend the current article to ADDRESS."
1376 (list (message-read-from-minibuffer
1377 "Resend message(s) to: "
1378 (when (and gnus-summary-resend-default-address
1379 (gnus-buffer-live-p gnus-original-article-buffer))
1380 ;; If some other article is currently selected, the
1381 ;; initial-contents is wrong. Whatever, it is just the
1382 ;; initial-contents.
1383 (with-current-buffer gnus-original-article-buffer
1384 (nnmail-fetch-field "to"))))
1385 current-prefix-arg))
1386 (let ((articles (gnus-summary-work-articles n))
1388 (while (setq article (pop articles))
1389 (gnus-summary-select-article nil nil nil article)
1391 (set-buffer gnus-original-article-buffer)
1392 (message-resend address))
1393 (gnus-summary-mark-article-as-forwarded article))))
1395 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1396 (defun gnus-summary-resend-message-edit ()
1397 "Resend an article that has already been sent.
1398 A new buffer will be created to allow the user to modify body and
1399 contents of the message, and then, everything will happen as when
1400 composing a new message."
1402 (let ((article (gnus-summary-article-number)))
1403 (gnus-setup-message 'reply-yank
1404 (gnus-summary-select-article t)
1405 (set-buffer gnus-original-article-buffer)
1406 (let ((cur (current-buffer))
1407 (to (message-fetch-field "to")))
1408 ;; Get a normal message buffer.
1409 (message-pop-to-buffer (message-buffer-name "Resend" to))
1410 (insert-buffer-substring cur)
1412 ;; T-gnus change: Use MIME-Edit to recompose a message.
1414 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1415 (fset 'mime-edit-decode-single-part-in-buffer
1416 (lambda (&rest args)
1417 (if (let ((content-type (car args)))
1418 (and (eq 'message (mime-content-type-primary-type
1420 (eq 'rfc822 (mime-content-type-subtype
1422 (setcar (cdr args) 'not-decode-text))
1425 (mime-edit-again nil t)
1426 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1427 (message-narrow-to-head-1)
1428 (insert "From: " (message-make-from) "\n")
1429 (while (re-search-forward "^From:" nil t)
1431 (insert "Original-"))
1432 (message-remove-header "^>From[\t ]" t)
1434 ;; Gnus will generate a new one when sending.
1435 (message-remove-header "Message-ID")
1436 (message-remove-header message-ignored-resent-headers t)
1437 ;; Remove unwanted headers.
1438 (goto-char (point-max))
1439 (insert mail-header-separator)
1440 (goto-char (point-min))
1441 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1445 (defun gnus-summary-post-forward (&optional full-headers)
1446 "Forward the current article to a newsgroup.
1447 If FULL-HEADERS (the prefix), include full headers when forwarding."
1449 (gnus-summary-mail-forward full-headers t))
1451 (defvar gnus-nastygram-message
1452 "The following article was inappropriately posted to %s.\n\n"
1453 "Format string to insert in nastygrams.
1454 The current group name will be inserted at \"%s\".")
1456 (defun gnus-summary-mail-nastygram (n)
1457 "Send a nastygram to the author of the current article."
1459 (when (or gnus-expert-user
1461 "Really send a nastygram to the author of the current article? "))
1462 (let ((group gnus-newsgroup-name))
1463 (gnus-summary-reply-with-original n)
1464 (set-buffer gnus-message-buffer)
1466 (insert (format gnus-nastygram-message group))
1467 (message-send-and-exit))))
1469 (defun gnus-summary-mail-crosspost-complaint (n)
1470 "Send a complaint about crossposting to the current article(s)."
1472 (let ((articles (gnus-summary-work-articles n))
1474 (while (setq article (pop articles))
1475 (set-buffer gnus-summary-buffer)
1476 (gnus-summary-goto-subject article)
1477 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1478 newsgroups followup-to)
1479 (gnus-summary-select-article)
1480 (set-buffer gnus-original-article-buffer)
1481 (if (and (<= (length (message-tokenize-header
1483 (mail-fetch-field "newsgroups"))
1486 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1487 (not (member group (message-tokenize-header
1488 followup-to ", ")))))
1490 (gnus-message 1 "Followup-to restricted")
1491 (gnus-message 1 "Not a crossposted article"))
1492 (set-buffer gnus-summary-buffer)
1493 (gnus-summary-reply-with-original 1)
1494 (set-buffer gnus-message-buffer)
1496 (insert (format gnus-crosspost-complaint newsgroups group))
1497 (message-goto-subject)
1498 (re-search-forward " *$")
1499 (replace-match " (crosspost notification)" t t)
1500 (gnus-deactivate-mark)
1501 (when (gnus-y-or-n-p "Send this complaint? ")
1502 (message-send-and-exit)))))))
1504 (defun gnus-mail-parse-comma-list ()
1507 (skip-chars-forward " ")
1510 (skip-chars-forward "^,")
1515 (narrow-to-region beg (point))
1518 (while (search-forward "\"" nil t)
1522 (skip-chars-forward ",")
1523 (skip-chars-forward "^,"))
1524 (skip-chars-backward " ")
1525 (push (buffer-substring beg (point))
1527 (skip-chars-forward "^,")
1528 (skip-chars-forward ", "))
1531 (defun gnus-inews-add-to-address (group)
1532 (let ((to-address (mail-fetch-field "to")))
1533 (when (and to-address
1535 ;; This mail group doesn't have a `to-list', so we add one
1537 (when (gnus-y-or-n-p
1538 (format "Do you want to add this as `to-list': %s " to-address))
1539 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1541 (defun gnus-put-message ()
1542 "Put the current message in some group and return to Gnus."
1544 (let ((reply gnus-article-reply)
1545 (winconf gnus-prev-winconf)
1546 (group gnus-newsgroup-name))
1548 (not (gnus-group-read-only-p group)))
1549 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1551 (when (gnus-gethash group gnus-newsrc-hashtb)
1552 (error "No such group: %s" group))
1556 (message-narrow-to-headers)
1557 (let ((gnus-deletable-headers nil))
1558 (message-generate-headers
1559 (if (message-news-p)
1560 message-required-news-headers
1561 message-required-mail-headers)))
1562 (goto-char (point-max))
1563 (if (string-match " " group)
1564 (insert "Gcc: \"" group "\"\n")
1565 (insert "Gcc: " group "\n"))
1568 (when (and (get-buffer gnus-group-buffer)
1569 (gnus-buffer-exists-p (car-safe reply))
1571 (set-buffer (car reply))
1572 (gnus-summary-mark-article-as-replied (cdr reply)))
1574 (set-window-configuration winconf))))
1576 (defun gnus-article-mail (yank)
1577 "Send a reply to the address near point.
1578 If YANK is non-nil, include the original article."
1582 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1583 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1585 (gnus-msg-mail address)
1587 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1589 (defvar nntp-server-type)
1591 "Send a bug report to the Gnus maintainers."
1593 (unless (gnus-alive-p)
1594 (error "Gnus has been shut down"))
1595 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1596 (unless (message-mail-user-agent)
1597 (message-pop-to-buffer "*Gnus Bug*")
1598 (delete-other-windows)
1599 (when gnus-bug-create-help-buffer
1600 (switch-to-buffer "*Gnus Help Bug*")
1602 (insert gnus-bug-message)
1603 (goto-char (point-min))
1605 (set-buffer "*Gnus Bug*")))
1606 (let ((message-this-is-mail t))
1607 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1608 (when gnus-bug-create-help-buffer
1609 (push `(gnus-bug-kill-buffer) message-send-actions))
1610 (goto-char (point-min))
1611 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1613 (insert gnus-product-name " " gnus-version-number
1614 " (r" gnus-revision-number ") "
1615 "based on " gnus-original-product-name " v"
1616 gnus-original-version-number "\n"
1617 (emacs-version) "\n")
1618 (when (and (boundp 'nntp-server-type)
1619 (stringp nntp-server-type))
1620 (insert nntp-server-type))
1621 (insert "\n\n\n\n\n")
1622 (let (mime-content-types)
1623 (mime-edit-insert-tag
1624 "application" "emacs-lisp"
1625 "\nContent-Disposition: inline\nContent-Description: User settings"))
1626 (insert (with-temp-buffer
1629 (let (mime-content-types)
1630 (mime-edit-insert-tag "text" "plain"))
1631 (goto-char (point-min))
1632 (search-forward "Subject: " nil t)
1635 (defun gnus-bug-kill-buffer ()
1636 (when (get-buffer "*Gnus Help Bug*")
1637 (kill-buffer "*Gnus Help Bug*")))
1639 (defun gnus-summary-yank-message (buffer n)
1640 "Yank the current article into a composed message."
1642 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1643 current-prefix-arg))
1644 (when (gnus-buffer-live-p buffer)
1645 (let ((summary-frame (selected-frame))
1646 (message-frame (when (static-if (featurep 'xemacs)
1647 (device-on-window-system-p)
1649 (let ((window (get-buffer-window buffer t)))
1651 (window-frame window)))))
1652 (separator (concat "^" (regexp-quote mail-header-separator)
1654 (gnus-summary-iterate n
1655 (gnus-summary-select-article)
1656 (gnus-copy-article-buffer)
1657 (when (frame-live-p message-frame)
1658 (raise-frame message-frame)
1659 (select-frame message-frame))
1660 (with-current-buffer buffer
1661 (when (save-excursion
1663 (let (case-fold-search)
1664 (and (not (re-search-backward separator nil t))
1665 (re-search-forward separator nil t))))
1666 (goto-char (match-end 0)))
1667 (message-yank-buffer gnus-article-copy))
1668 (select-frame summary-frame))
1669 (when (frame-live-p message-frame)
1670 (select-frame message-frame)))))
1672 (defun gnus-debug ()
1673 "Attempts to go through the Gnus source file and report what variables have been changed.
1674 The source file has to be in the Emacs load path."
1676 (let ((files gnus-debug-files)
1678 file expr olist sym)
1679 (gnus-message 4 "Please wait while we snoop your variables...")
1680 ;; Go through all the files looking for non-default values for variables.
1683 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1686 (when (and (setq file (locate-library (pop files)))
1687 (file-exists-p file))
1688 (insert-file-contents file)
1689 (goto-char (point-min))
1690 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1691 (gnus-message 4 "Malformed sources in file %s" file)
1692 (narrow-to-region (point-min) (point))
1693 (goto-char (point-min))
1694 (while (setq expr (ignore-errors (read (current-buffer))))
1696 (and (memq (car expr) '(defvar defcustom defvoo))
1697 (stringp (nth 3 expr))
1698 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1699 (or (not (boundp (nth 1 expr)))
1700 (not (equal (eval (nth 2 expr))
1701 (symbol-value (nth 1 expr)))))
1702 (push (nth 1 expr) olist)))))))
1703 (kill-buffer (current-buffer)))
1704 (when (setq olist (nreverse olist))
1705 (insert ";----------------- Environment follows ------------------\n\n"))
1707 (if (boundp (car olist))
1709 (pp `(setq ,(car olist)
1710 ,(if (or (consp (setq sym (symbol-value (car olist))))
1712 (not (or (eq sym nil)
1714 (list 'quote (symbol-value (car olist)))
1715 (symbol-value (car olist))))
1717 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1718 (setq olist (cdr olist)))
1719 ;; Remove any control chars - they seem to cause trouble for some
1720 ;; mailers. (Byte-compiled output from the stuff above.)
1722 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1723 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1725 ;; Break MIME tags purposely.
1727 (while (re-search-forward mime-edit-tag-regexp nil t)
1728 (goto-char (1+ (match-beginning 0)))
1731 ;;; Treatment of rejected articles.
1734 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1735 "Re-mail the current message.
1736 This only makes sense if the current message is a bounce message than
1737 contains some mail you have written which has been bounced back to
1739 If FETCH, try to fetch the article that this is a reply to, if indeed
1742 (gnus-summary-select-article t)
1743 (set-buffer gnus-original-article-buffer)
1744 (gnus-setup-message 'compose-bounce
1745 (let* ((references (mail-fetch-field "references"))
1746 (parent (and references (gnus-parent-id references))))
1748 ;; If there are references, we fetch the article we answered to.
1750 (gnus-summary-refer-article parent)
1751 (gnus-summary-show-all-headers)))))
1755 (defun gnus-inews-group-method (group)
1757 ;; If the group doesn't exist, we assume
1758 ;; it's an archive group...
1759 ((and (null (gnus-get-info group))
1760 (eq (car (gnus-server-to-method gnus-message-archive-method))
1761 (car (gnus-server-to-method (gnus-group-method group)))))
1762 gnus-message-archive-method)
1764 ((gnus-info-method (gnus-get-info group))
1765 (gnus-info-method (gnus-get-info group)))
1767 (t (gnus-server-to-method (gnus-group-method group)))))
1769 ;; Do Gcc handling, which copied the message over to some group.
1770 (defun gnus-inews-do-gcc (&optional gcc)
1774 (message-narrow-to-headers)
1775 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1776 (coding-system-for-write 'raw-text)
1777 (output-coding-system 'raw-text)
1778 groups group method group-art
1779 mml-externalize-attachments)
1781 (message-remove-header "gcc")
1783 (setq groups (message-unquote-tokens
1784 (message-tokenize-header gcc " ,")))
1785 ;; Copy the article over to some group(s).
1786 (while (setq group (pop groups))
1787 (unless (gnus-check-server
1788 (setq method (gnus-inews-group-method group)))
1789 (error "Can't open server %s" (if (stringp method) method
1791 (unless (gnus-request-group group nil method)
1792 (gnus-request-create-group group method))
1793 (setq mml-externalize-attachments
1794 (if (stringp gnus-gcc-externalize-attachments)
1795 (string-match gnus-gcc-externalize-attachments group)
1796 gnus-gcc-externalize-attachments))
1798 (nnheader-set-temp-buffer " *acc*")
1799 (insert-buffer-substring message-encoding-buffer)
1800 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1801 (goto-char (point-min))
1802 (when (re-search-forward
1803 (concat "^" (regexp-quote mail-header-separator) "$")
1805 (replace-match "" t t ))
1806 (unless (setq group-art
1807 (gnus-request-accept-article group method t t))
1808 (gnus-message 1 "Couldn't store article in group %s: %s"
1809 group (gnus-status-message method))
1811 (when (and group-art
1813 (or gnus-gcc-mark-as-read
1814 gnus-inews-mark-gcc-as-read))
1815 (gnus-group-mark-article-read group (cdr group-art)))
1816 (kill-buffer (current-buffer)))))))))
1818 (defun gnus-inews-insert-gcc ()
1819 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1822 (message-narrow-to-headers)
1823 (let* ((group gnus-outgoing-message-group)
1825 ((gnus-functionp group)
1827 ((or (stringp group) (list group))
1832 (if (string-match " " gcc)
1833 (concat "\"" gcc "\"")
1835 (mapconcat (lambda (group)
1836 (if (string-match " " group)
1837 (concat "\"" group "\"")
1842 (defun gnus-inews-insert-archive-gcc (&optional group)
1843 "Insert the Gcc to say where the article is to be archived."
1844 (let* ((var gnus-message-archive-group)
1845 (group (or group gnus-newsgroup-name ""))
1847 (and gnus-newsgroup-name
1848 (not (equal gnus-newsgroup-name ""))
1849 (gnus-group-find-parameter
1850 gnus-newsgroup-name 'gcc-self)))
1854 ((null gnus-message-archive-method)
1858 ;; Just a single group.
1861 ;; We don't want this.
1863 ((and (listp var) (stringp (car var)))
1864 ;; A list of groups.
1866 ((gnus-functionp var)
1868 (funcall var group))
1870 ;; An alist of regexps/functions/forms.
1875 ((stringp (caar var))
1877 (when (string-match (caar var) group)
1879 ((gnus-functionp (car var))
1881 (funcall (car var) group))
1883 (eval (car var)))))))
1884 (setq var (cdr var)))
1887 (when (or groups gcc-self-val)
1888 (when (stringp groups)
1889 (setq groups (list groups)))
1892 (message-narrow-to-headers)
1893 (goto-char (point-max))
1896 ;; Use the `gcc-self' param value instead.
1899 (if (stringp gcc-self-val)
1900 (if (string-match " " gcc-self-val)
1901 (concat "\"" gcc-self-val "\"")
1903 (if (string-match " " group)
1904 (concat "\"" group "\"")
1906 (if (not (eq gcc-self-val 'none))
1911 ;; Use the list of groups.
1912 (while (setq name (pop groups))
1913 (let ((str (if (string-match ":" name)
1915 (gnus-group-prefixed-name
1916 name gnus-message-archive-method))))
1917 (insert (if (string-match " " str)
1918 (concat "\"" str "\"")
1926 (defun gnus-configure-posting-styles (&optional group-name)
1927 "Configure posting styles according to `gnus-posting-styles'."
1928 (unless gnus-inhibit-posting-styles
1929 (let ((group (or group-name gnus-newsgroup-name ""))
1930 (styles gnus-posting-styles)
1931 style match attribute results
1933 ;; If the group has a posting-style parameter, add it at the end with a
1934 ;; regexp matching everything, to be sure it takes precedence over all
1936 (when gnus-newsgroup-name
1937 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1939 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1940 ;; Go through all styles and look for matches.
1941 (dolist (style styles)
1942 (setq match (pop style))
1943 (goto-char (point-min))
1946 ;; Regexp string match on the group name.
1947 (string-match match group))
1949 ;; Obsolete format of header match.
1950 (and (gnus-buffer-live-p gnus-article-copy)
1951 (with-current-buffer gnus-article-copy
1952 (let ((header (message-fetch-field (pop style))))
1954 (string-match (pop style) header))))))
1955 ((or (symbolp match)
1956 (gnus-functionp match))
1958 ((gnus-functionp match)
1959 ;; Function to be called.
1962 ;; Variable to be checked.
1963 (symbol-value match))))
1966 ((eq (car match) 'header)
1967 ;; New format of header match.
1968 (and (gnus-buffer-live-p gnus-article-copy)
1969 (with-current-buffer gnus-article-copy
1970 (let ((header (message-fetch-field (nth 1 match))))
1972 (string-match (nth 2 match) header))))))
1974 ;; This is a form to be evaled.
1976 ;; We have a match, so we set the variables.
1977 (setq style (gnus-configure-posting-style style nil))
1978 (dolist (attribute style)
1979 (setq results (delq (assoc (car attribute) results) results))
1980 (push attribute results))))
1981 ;; Now we have all the styles, so we insert them.
1982 (setq name (assq 'name results)
1983 address (assq 'address results))
1984 (setq results (delq name (delq address results)))
1985 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1986 (make-local-hook 'message-setup-hook)
1987 (setq results (sort results (lambda (x y)
1988 (string-lessp (car x) (car y)))))
1989 (dolist (result results)
1990 (add-hook 'message-setup-hook
1992 ((eq 'eval (car result))
1994 ((eq 'body (car result))
1998 (insert ,(cdr result)))))
1999 ((eq 'signature (car result))
2000 (set (make-local-variable 'message-signature) nil)
2001 (set (make-local-variable 'message-signature-file) nil)
2002 (if (not (cdr result))
2006 (let ((message-signature ,(cdr result)))
2007 (when message-signature
2008 (message-insert-signature)))))))
2011 (if (symbolp (car result))
2012 (capitalize (symbol-name (car result)))
2016 (message-remove-header ,header)
2017 (let ((value ,(cdr result)))
2020 (insert ,header ": " value)
2022 (insert "\n")))))))))
2024 (when (or name address)
2025 (add-hook 'message-setup-hook
2027 (set (make-local-variable 'user-mail-address)
2028 ,(or (cdr address) user-mail-address))
2029 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2031 ,(or (cdr address) user-mail-address)))
2033 (message-remove-header "From")
2035 (insert "From: " (message-make-from) "\n"))))
2038 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2039 (defun gnus-configure-posting-style (style stack)
2040 "Parse one posting style STYLE and returns the value as an alist."
2041 (let (results element variable filep value v)
2042 (dolist (attribute style)
2043 (setq element (pop attribute)
2048 ((eq (car attribute) ':file)
2051 ((eq (car attribute) :value)
2055 ;; We get the value.
2060 ((or (symbolp value)
2061 (gnus-functionp value))
2062 (cond ((gnus-functionp value)
2065 (symbol-value value))))
2068 ;; Translate obsolescent value.
2070 ((eq element 'signature-file)
2071 (setq element 'signature
2073 ((eq element 'x-face-file)
2074 (setq element 'x-face
2076 ;; Get the contents of file elems.
2078 (setq v (with-temp-buffer
2079 (insert-file-contents v)
2080 (goto-char (point-max))
2084 (if (eq element 'import)
2086 (if (member v stack)
2087 (error "Circular import of \"%s\"" v))
2089 (nconc (nreverse (gnus-configure-posting-style
2090 (cdr (assoc v gnus-named-posting-styles))
2093 (push (cons element v) results)))
2094 (nreverse results)))
2096 (defun gnus-summary-execute-command-with-posting-style (style command)
2097 "Temporarily select a posting-style named STYLE and execute COMMAND."
2099 (let ((style (completing-read "Posting style: "
2100 gnus-named-posting-styles nil t)))
2104 (format "Command to execute with %s: " style))))))
2105 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2106 (call-interactively command)))
2109 ;;; @ for MIME Edit mode
2112 (defun gnus-maybe-setup-default-charset ()
2114 (and (boundp 'gnus-summary-buffer)
2115 (buffer-live-p gnus-summary-buffer)
2117 (set-buffer gnus-summary-buffer)
2118 default-mime-charset))))
2121 (make-local-variable 'default-mime-charset)
2122 (setq default-mime-charset charset)
2126 ;;; @ for MIME view mode
2129 (defun gnus-following-method (buf)
2130 (gnus-setup-message 'reply-yank
2132 (if (message-news-p)
2134 (message-reply nil 'wide))
2135 (let ((message-reply-buffer buf))
2136 (message-yank-original))
2137 (message-goto-body))
2141 ;;; Allow redefinition of functions.
2147 ;;; gnus-msg.el ends here