1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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 :type '(repeat (cons (choice (regexp)
126 (string :tag "Header")
127 (regexp :tag "Regexp"))
131 (choice (const signature)
132 (const signature-file)
140 (string :tag "Header"))
146 (defcustom gnus-named-posting-styles nil
147 "Alist mapping names to the user-defined posting styles."
149 :type '(repeat (cons string
151 (choice (const signature)
152 (const signature-file)
160 (string :tag "Header"))
166 (defcustom gnus-gcc-mark-as-read nil
167 "If non-nil, automatically mark Gcc articles as read."
172 (defvar gnus-inews-mark-gcc-as-read nil
173 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
175 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
176 'gnus-gcc-mark-as-read)
178 (defcustom gnus-gcc-externalize-attachments nil
179 "Should local-file attachments be included as external parts in Gcc copies?
180 If it is `all', attach files as external parts;
181 if a regexp and matches the Gcc group name, attach files as external parts;
182 If nil, attach files as normal parts."
185 :type '(choice (const nil :tag "None")
186 (const all :tag "Any")
187 (string :tag "Regexp")))
189 (gnus-define-group-parameter
190 posting-charset-alist
193 "Return the permitted unencoded charsets for posting of GROUP."
194 :variable gnus-group-posting-charset-alist
196 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
197 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
198 (message-this-is-mail nil nil)
199 (message-this-is-news nil t))
201 "Alist of regexps and permitted unencoded charsets for posting.
202 Each element of the alist has the form (TEST HEADER BODY-LIST), where
203 TEST is either a regular expression matching the newsgroup header or a
205 HEADER is the charset which may be left unencoded in the header (nil
206 means encode all charsets),
207 BODY-LIST is a list of charsets which may be encoded using 8bit
208 content-transfer encoding in the body, or one of the special values
209 nil (always encode using quoted-printable) or t (always use 8bit).
211 Note that any value other than nil for HEADER infringes some RFCs, so
212 use this option with care."
213 :variable-group gnus-charset
215 '(repeat (list :tag "Permitted unencoded charsets"
217 (regexp :tag "Group")
218 (const :tag "Mail message" :value message-this-is-mail)
219 (const :tag "News article" :value message-this-is-news))
220 (choice :tag "Header"
221 (const :tag "None" nil)
222 (symbol :tag "Charset"))
224 (const :tag "Any" :value t)
225 (const :tag "None" :value nil)
226 (repeat :tag "Charsets"
227 (symbol :tag "Charset")))))
228 :parameter-type '(choice :tag "Permitted unencoded charsets"
231 :parameter-document "\
232 List of charsets that are permitted to be unencoded.")
234 (defcustom gnus-debug-files
235 '("gnus.el" "gnus-sum.el" "gnus-group.el"
236 "gnus-art.el" "gnus-start.el" "gnus-async.el"
237 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
238 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
239 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
240 "Files whose variables will be reported in `gnus-bug'."
243 :type '(repeat (string :tag "File")))
245 (defcustom gnus-debug-exclude-variables
246 '(mm-mime-mule-charset-alist
247 nnmail-split-fancy message-minibuffer-local-map)
248 "Variables that should not be reported in `gnus-bug'."
251 :type '(repeat (symbol :tag "Variable")))
253 (defcustom gnus-discouraged-post-methods
254 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
255 "A list of back ends that are not used in \"real\" newsgroups.
256 This variable is used only when `gnus-post-method' is `current'."
258 :group 'gnus-group-foreign
259 :type '(repeat (symbol :tag "Back end")))
261 (defcustom gnus-message-replysign
263 "Automatically sign replys to signed messages.
264 See also the `mml-default-sign-method' variable."
268 (defcustom gnus-message-replyencrypt
270 "Automatically encrypt replys to encrypted messages.
271 See also the `mml-default-encrypt-method' variable."
275 (defcustom gnus-message-replysignencrypted
277 "Setting this causes automatically encryped messages to also be signed."
281 (defcustom gnus-confirm-mail-reply-to-news nil
282 "If non-nil, Gnus requests confirmation when replying to news.
283 This is done because new users often reply by mistake when reading
288 (defcustom gnus-summary-resend-default-address t
289 "If non-nil, Gnus tries to suggest a default address to resend to.
290 If nil, the address field will always be empty after invoking
291 `gnus-summary-resend-message'."
295 ;;; Internal variables.
297 (defvar gnus-inhibit-posting-styles nil
298 "Inhibit the use of posting styles.")
300 (defvar gnus-message-buffer "*Mail Gnus*")
301 (defvar gnus-article-copy nil)
302 (defvar gnus-check-before-posting nil)
303 (defvar gnus-last-posting-server nil)
304 (defvar gnus-message-group-art nil)
306 (defvar gnus-msg-force-broken-reply-to nil)
308 (defconst gnus-bug-message
309 (format "Sending a bug report to the Gnus Towers.
310 ========================================
312 This gnus is the %s%s.
313 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
314 Developers. (the addresses below are mailing list addresses)
316 ========================================
318 The buffer below is a mail buffer. When you press `C-c C-c', it will
319 be sent to the Gnus Bug Exterminators.
321 The thing near the bottom of the buffer is how the environment
322 settings will be included in the mail. Please do not delete that.
323 They will tell the Bug People what your environment is, so that it
324 will be easier to locate the bugs.
326 If you have found a bug that makes Emacs go \"beep\", set
327 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
328 and include the backtrace in your bug report.
330 Please describe the bug in annoying, painstaking detail.
332 Thank you for your help in stamping out bugs.
335 (if (string= gnus-product-name "Semi-gnus")
337 ", a modified version of Semi-gnus")))
340 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
341 (autoload 'news-setup "rnewspost")
342 (autoload 'news-reply-mode "rnewspost")
343 (autoload 'rmail-dont-reply-to "mail-utils")
344 (autoload 'rmail-output "rmailout"))
348 ;;; Gnus Posting Functions
351 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
352 "p" gnus-summary-post-news
353 "i" gnus-summary-news-other-window
354 "f" gnus-summary-followup
355 "F" gnus-summary-followup-with-original
356 "c" gnus-summary-cancel-article
357 "s" gnus-summary-supersede-article
358 "r" gnus-summary-reply
359 "y" gnus-summary-yank-message
360 "R" gnus-summary-reply-with-original
361 "w" gnus-summary-wide-reply
362 "W" gnus-summary-wide-reply-with-original
363 "v" gnus-summary-very-wide-reply
364 "V" gnus-summary-very-wide-reply-with-original
365 "n" gnus-summary-followup-to-mail
366 "N" gnus-summary-followup-to-mail-with-original
367 "m" gnus-summary-mail-other-window
368 "u" gnus-uu-post-news
369 "\M-c" gnus-summary-mail-crosspost-complaint
370 "Br" gnus-summary-reply-broken-reply-to
371 "BR" gnus-summary-reply-broken-reply-to-with-original
372 "om" gnus-summary-mail-forward
373 "op" gnus-summary-post-forward
374 "Om" gnus-summary-digest-mail-forward
375 "Op" gnus-summary-digest-post-forward
376 "P" gnus-summary-execute-command-with-posting-style)
378 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
379 "b" gnus-summary-resend-bounced-mail
380 ;; "c" gnus-summary-send-draft
381 "r" gnus-summary-resend-message
382 "e" gnus-summary-resend-message-edit)
384 ;;; Internal functions.
386 (defvar gnus-article-reply nil)
387 (defmacro gnus-setup-message (config &rest forms)
388 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
389 (buffer (make-symbol "gnus-setup-message-buffer"))
390 (article (make-symbol "gnus-setup-message-article"))
391 (group (make-symbol "gnus-setup-message-group")))
392 `(let ((,winconf (current-window-configuration))
393 (,buffer (buffer-name (current-buffer)))
394 (,article gnus-article-reply)
395 (,group gnus-newsgroup-name)
396 (message-header-setup-hook
397 (copy-sequence message-header-setup-hook))
398 (message-mode-hook (copy-sequence message-mode-hook))
399 (message-startup-parameter-alist
400 '((reply-buffer . gnus-copy-article-buffer)
401 (original-buffer . gnus-original-article-buffer)
402 (user-agent . Gnus))))
403 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
404 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
405 ;; #### FIXME: for a reason that I did not manage to identify yet,
406 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
407 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
408 ;; After evaluation of @forms below, it gets the value we actually want
409 ;; to override, and the posting styles are used. For that reason, I've
410 ;; added an optional argument to `gnus-configure-posting-styles' to
411 ;; make sure that the correct value for the group name is used. -- drv
412 (add-hook 'message-mode-hook
414 (gnus-configure-posting-styles ,group)))
418 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
419 (gnus-inews-insert-draft-meta-information ,group ,article)
420 (setq gnus-message-buffer (current-buffer))
421 (set (make-local-variable 'gnus-message-group-art)
422 (cons ,group ,article))
423 (set (make-local-variable 'gnus-newsgroup-name) ,group)
424 (gnus-maybe-setup-default-charset)
425 (gnus-run-hooks 'gnus-message-setup-hook))
427 (gnus-configure-windows ,config t)
428 (run-hooks 'post-command-hook)
429 (set-buffer-modified-p nil))))
431 (defun gnus-inews-insert-draft-meta-information (group article)
434 (not (string= group ""))
435 (not (message-fetch-field gnus-draft-meta-information-header)))
436 (goto-char (point-min))
437 (insert gnus-draft-meta-information-header ": (\"" group "\" "
438 (if article (number-to-string
445 (defun gnus-msg-mail (&optional to subject other-headers continue
446 switch-action yank-action send-actions)
447 "Start editing a mail message to be sent.
448 Like `message-mail', but with Gnus paraphernalia, particularly the
449 Gcc: header for archiving purposes."
451 (let ((buf (current-buffer))
453 (gnus-setup-message 'message
454 (message-mail to subject other-headers continue
455 nil yank-action send-actions))
457 (setq mail-buf (current-buffer))
458 (switch-to-buffer buf)
459 (apply switch-action mail-buf nil)))
460 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
463 (defvar save-selected-window-window)
466 (defun gnus-button-mailto (address)
468 (set-buffer (gnus-copy-article-buffer))
469 (gnus-setup-message 'message
470 (message-reply address))
471 (and (boundp 'save-selected-window-window)
472 (not (window-live-p save-selected-window-window))
473 (setq save-selected-window-window (selected-window))))
476 (defun gnus-button-reply (&optional to-address wide)
477 "Like `message-reply'."
479 (gnus-setup-message 'message
480 (message-reply to-address wide))
481 (and (boundp 'save-selected-window-window)
482 (not (window-live-p save-selected-window-window))
483 (setq save-selected-window-window (selected-window))))
486 (define-mail-user-agent 'gnus-user-agent
487 'gnus-msg-mail 'message-send-and-exit
488 'message-kill-buffer 'message-send-hook)
490 (defun gnus-setup-posting-charset (group)
491 (let ((alist gnus-group-posting-charset-alist)
492 (group (or group ""))
496 (while (setq elem (pop alist))
497 (when (or (and (stringp (car elem))
498 (string-match (car elem) group))
499 (and (gnus-functionp (car elem))
500 (funcall (car elem) group))
501 (and (symbolp (car elem))
502 (symbol-value (car elem))))
503 (throw 'found (cons (cadr elem) (caddr elem)))))))))
505 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
506 (make-local-hook 'message-sent-hook)
507 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
508 'gnus-inews-do-gcc) nil t)
510 (make-local-hook 'message-header-hook)
511 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
512 (setq message-post-method
514 (gnus-post-method arg ,gnus-newsgroup-name)))
515 (setq message-user-agent (gnus-extended-version))
516 (when (not message-use-multi-frames)
518 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
520 `(when (gnus-buffer-exists-p ,buffer)
524 (if (eq config 'forward)
525 `(gnus-summary-mark-article-as-forwarded ',article)
526 `(gnus-summary-mark-article-as-replied ',article)))))
529 (put 'gnus-setup-message 'lisp-indent-function 1)
530 (put 'gnus-setup-message 'edebug-form-spec '(form body))
532 ;;; Post news commands of Gnus group mode and summary mode
534 (defun gnus-group-mail (&optional arg)
535 "Start composing a mail.
536 If ARG, use the group under the point to find a posting style.
537 If ARG is 1, prompt for a group name to find the posting style."
539 ;; We can't `let' gnus-newsgroup-name here, since that leads
540 ;; to local variables leaking.
541 (let ((group gnus-newsgroup-name)
542 ;; make sure last viewed article doesn't affect posting styles:
544 (buffer (current-buffer)))
547 (setq gnus-newsgroup-name
549 (if (= 1 (prefix-numeric-value arg))
550 (completing-read "Use posting style of group: "
551 gnus-active-hashtb nil
552 (gnus-read-active-file-p))
553 (gnus-group-group-name))
555 ;; #### see comment in gnus-setup-message -- drv
556 (gnus-setup-message 'message (message-mail)))
559 (setq gnus-newsgroup-name group)))))
561 (defun gnus-group-news (&optional arg)
562 "Start composing a news.
563 If ARG, post to group under point.
564 If ARG is 1, prompt for group name to post to.
566 This function prepares a news even when using mail groups. This is useful
567 for posting messages to mail groups without actually sending them over the
568 network. The corresponding backend must have a 'request-post method."
570 ;; We can't `let' gnus-newsgroup-name here, since that leads
571 ;; to local variables leaking.
572 (let ((group gnus-newsgroup-name)
573 ;; make sure last viewed article doesn't affect posting styles:
575 (buffer (current-buffer)))
578 (setq gnus-newsgroup-name
580 (if (= 1 (prefix-numeric-value arg))
581 (completing-read "Use group: "
582 gnus-active-hashtb nil
583 (gnus-read-active-file-p))
584 (gnus-group-group-name))
586 ;; #### see comment in gnus-setup-message -- drv
587 (gnus-setup-message 'message
588 (message-news (gnus-group-real-name gnus-newsgroup-name))))
591 (setq gnus-newsgroup-name group)))))
593 (defun gnus-group-post-news (&optional arg)
594 "Start composing a message (a news by default).
595 If ARG, post to group under point. If ARG is 1, prompt for group name.
596 Depending on the selected group, the message might be either a mail or
599 ;; Bind this variable here to make message mode hooks work ok.
600 (let ((gnus-newsgroup-name
602 (if (= 1 (prefix-numeric-value arg))
603 (completing-read "Newsgroup: " gnus-active-hashtb nil
604 (gnus-read-active-file-p))
605 (gnus-group-group-name))
607 ;; make sure last viewed article doesn't affect posting styles:
609 (gnus-post-news 'post gnus-newsgroup-name)))
611 (defun gnus-summary-mail-other-window (&optional arg)
612 "Start composing a mail in another window.
613 Use the posting of the current group by default.
614 If ARG, don't do that. If ARG is 1, prompt for group name to find the
617 ;; We can't `let' gnus-newsgroup-name here, since that leads
618 ;; to local variables leaking.
619 (let ((group gnus-newsgroup-name)
620 ;; make sure last viewed article doesn't affect posting styles:
622 (buffer (current-buffer)))
625 (setq gnus-newsgroup-name
627 (if (= 1 (prefix-numeric-value arg))
628 (completing-read "Use group: "
629 gnus-active-hashtb nil
630 (gnus-read-active-file-p))
632 gnus-newsgroup-name))
633 ;; #### see comment in gnus-setup-message -- drv
634 (gnus-setup-message 'message (message-mail)))
637 (setq gnus-newsgroup-name group)))))
639 (defun gnus-summary-news-other-window (&optional arg)
640 "Start composing a news in another window.
641 Post to the current group by default.
642 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
644 This function prepares a news even when using mail groups. This is useful
645 for posting messages to mail groups without actually sending them over the
646 network. The corresponding backend must have a 'request-post method."
648 ;; We can't `let' gnus-newsgroup-name here, since that leads
649 ;; to local variables leaking.
650 (let ((group gnus-newsgroup-name)
651 ;; make sure last viewed article doesn't affect posting styles:
653 (buffer (current-buffer)))
656 (setq gnus-newsgroup-name
658 (if (= 1 (prefix-numeric-value arg))
659 (completing-read "Use group: "
660 gnus-active-hashtb nil
661 (gnus-read-active-file-p))
663 gnus-newsgroup-name))
664 ;; #### see comment in gnus-setup-message -- drv
665 (gnus-setup-message 'message
666 (message-news (gnus-group-real-name gnus-newsgroup-name))))
669 (setq gnus-newsgroup-name group)))))
671 (defun gnus-summary-post-news (&optional arg)
672 "Start composing a message. Post to the current group by default.
673 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
674 Depending on the selected group, the message might be either a mail or
677 ;; Bind this variable here to make message mode hooks work ok.
678 (let ((gnus-newsgroup-name
680 (if (= 1 (prefix-numeric-value arg))
681 (completing-read "Newsgroup: " gnus-active-hashtb nil
682 (gnus-read-active-file-p))
684 gnus-newsgroup-name))
685 ;; make sure last viewed article doesn't affect posting styles:
687 (gnus-post-news 'post gnus-newsgroup-name)))
690 (defun gnus-summary-followup (yank &optional force-news)
691 "Compose a followup to an article.
692 If prefix argument YANK is non-nil, the original article is yanked
694 YANK is a list of elements, where the car of each element is the
695 article number, and the two following numbers is the region to be
698 (list (and current-prefix-arg
699 (gnus-summary-work-articles 1))))
701 (gnus-summary-goto-subject
702 (if (listp (car yank))
705 (save-window-excursion
706 (gnus-summary-select-article))
707 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
708 (gnus-newsgroup-name gnus-newsgroup-name))
710 (gnus-post-news nil gnus-newsgroup-name
711 headers gnus-article-buffer
713 (gnus-summary-handle-replysign)))
715 (defun gnus-summary-followup-with-original (n &optional force-news)
716 "Compose a followup to an article and include the original article."
718 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
720 (defun gnus-summary-followup-to-mail (&optional arg)
721 "Followup to the current mail message via news."
723 (list (and current-prefix-arg
724 (gnus-summary-work-articles 1))))
725 (gnus-summary-followup arg t))
727 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
728 "Followup to the current mail message via news."
730 (gnus-summary-followup (gnus-summary-work-articles arg) t))
732 (defun gnus-inews-yank-articles (articles)
733 (let (beg article yank-string
734 (more-than-one (cdr articles))
735 (cur (current-buffer))
738 (while (setq article (pop articles))
739 (when (listp article)
740 (setq yank-string (nth 1 article)
741 article (nth 0 article)))
742 (save-window-excursion
743 (set-buffer gnus-summary-buffer)
744 (gnus-summary-select-article nil nil nil article)
745 (gnus-summary-remove-process-mark article))
747 ;; Gathering references.
749 (setq refs (message-list-references
751 (mail-header-references gnus-current-headers)
752 (mail-header-message-id gnus-current-headers)))
753 (when message-use-multi-frames
754 (when (setq window (get-buffer-window cur t))
755 (select-frame (window-frame window)))))
757 (gnus-copy-article-buffer nil yank-string)
758 (let ((message-reply-buffer gnus-article-copy)
759 (message-reply-headers
760 ;; The headers are decoded.
761 (with-current-buffer gnus-article-copy
763 (nnheader-narrow-to-headers)
764 (ietf-drums-unfold-fws)
765 (nnheader-parse-head t)))))
766 (message-yank-original)
767 (setq beg (or beg (mark t))))
772 ;; Replace with the gathered references.
776 (message-narrow-to-headers)
777 (let ((case-fold-search t))
778 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
780 (goto-char (point-max))))
782 (list (or (assq 'References message-header-format-alist)
783 '(References . message-shorten-references)))
784 (list (cons 'References
785 (mapconcat 'identity (nreverse refs) " "))))
786 (backward-delete-char 1))
792 (defun gnus-summary-cancel-article (&optional n symp)
793 "Cancel an article you posted.
794 Uses the process-prefix convention. If given the symbolic
795 prefix `a', cancel using the standard posting method; if not
796 post using the current select method."
797 (interactive (gnus-interactive "P\ny"))
798 (let ((articles (gnus-summary-work-articles n))
801 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
803 (while (setq article (pop articles))
804 (when (gnus-summary-select-article t nil nil article)
805 (when (gnus-eval-in-buffer-window gnus-article-buffer
807 (set-buffer gnus-original-article-buffer)
808 (message-cancel-news)))
809 (gnus-summary-mark-as-read article gnus-canceled-mark)
810 (gnus-cache-remove-article 1))
811 (gnus-article-hide-headers-if-wanted))
812 (gnus-summary-remove-process-mark article))))
814 (defun gnus-summary-supersede-article ()
815 "Compose an article that will supersede a previous article.
816 This is done simply by taking the old article and adding a Supersedes
817 header line with the old Message-ID."
819 (let ((article (gnus-summary-article-number)))
820 (gnus-setup-message 'reply-yank
821 (gnus-summary-select-article t)
822 (set-buffer gnus-original-article-buffer)
826 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
828 (set-buffer ,gnus-summary-buffer)
829 (gnus-cache-possibly-remove-article ,article nil nil nil t)
830 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
831 message-send-actions))))
835 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
836 ;; make a copy of the article buffer with all text properties removed
837 ;; this copy is in the buffer gnus-article-copy.
838 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
839 ;; this buffer should be passed to all mail/news reply/post routines.
840 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
842 (set-buffer gnus-article-copy)
843 (set-buffer-multibyte t))
844 (let ((article-buffer (or article-buffer gnus-article-buffer))
846 (if (not (and (get-buffer article-buffer)
847 (gnus-buffer-exists-p article-buffer)))
848 (error "Can't find any article buffer")
850 (set-buffer article-buffer)
851 (let ((gnus-newsgroup-charset (or gnus-article-charset
852 gnus-newsgroup-charset))
853 (gnus-newsgroup-ignored-charsets
854 (or gnus-article-ignored-charsets
855 gnus-newsgroup-ignored-charsets)))
857 ;; Copy over the (displayed) article buffer, delete
858 ;; hidden text and remove text properties.
860 (copy-to-buffer gnus-article-copy (point-min) (point-max))
861 (set-buffer gnus-article-copy)
862 ;; There's invisible and intangible text in T-gnus. Especially,
863 ;; if there is a boundary line (X-Boundary: ------------------),
864 ;; in the end of a header, it will cause a serious problem.
865 (add-text-properties (point-min) (point-max)
866 '(invisible nil intangible nil))
869 (delete-region (point) (point-max))
870 (insert yank-string))
871 ;; Encode bitmap smileys to ordinary text.
872 ;; Possibly, the original text might be restored.
873 (static-unless (featurep 'xemacs)
874 (when (featurep 'smiley-mule)
875 (smiley-encode-buffer)))
876 (gnus-article-delete-text-of-type 'annotation)
877 (gnus-remove-text-with-property 'gnus-prev)
878 (gnus-remove-text-with-property 'gnus-next)
879 (gnus-remove-text-with-property 'gnus-decoration)
880 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
883 (static-if (featurep 'xemacs)
884 ;; Revome smiley extents for (possibly) XEmacs 21.1.
886 (buffer-substring-no-properties (point-min)
888 (buffer-substring-no-properties (point-min) (point-max)))
890 ;; Find the original headers.
891 (set-buffer gnus-original-article-buffer)
892 (goto-char (point-min))
893 (while (looking-at message-unix-mail-delimiter)
895 (let ((mail-header-separator ""))
897 end (or (message-goto-body) beg)))
898 ;; Delete the headers from the displayed articles.
899 (set-buffer gnus-article-copy)
900 (let ((mail-header-separator ""))
901 (delete-region (goto-char (point-min))
902 (or (message-goto-body) (point-max))))
903 ;; Insert the original article headers.
904 (insert-buffer-substring gnus-original-article-buffer beg end)
906 (let ((gnus-article-decode-hook
907 (delq 'article-decode-charset
908 (copy-sequence gnus-article-decode-hook))))
909 ;; Needed for T-gnus.
910 (add-hook 'gnus-article-decode-hook
911 'article-decode-encoded-words)
912 (run-hooks 'gnus-article-decode-hook)))))
915 (defun gnus-post-news (post &optional group header article-buffer yank subject
918 (gnus-copy-article-buffer))
919 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
920 (add-to-list gnus-add-to-list))
921 (gnus-setup-message (cond (yank 'reply-yank)
922 (article-buffer 'reply)
924 (let* ((group (or group gnus-newsgroup-name))
925 (charset (gnus-group-name-charset nil group))
927 to-address to-group mailing-list to-list
930 (setq to-address (gnus-parameter-to-address group)
931 to-group (gnus-group-find-parameter group 'to-group)
932 to-list (gnus-parameter-to-list group)
933 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
934 mailing-list (when gnus-mailing-list-groups
935 (string-match gnus-mailing-list-groups group))
936 group (gnus-group-name-decode (gnus-group-real-name group)
938 (if (or (and to-group
939 (gnus-news-group-p to-group))
942 (and (gnus-news-group-p
943 (or pgroup gnus-newsgroup-name)
944 (or header gnus-current-article))
950 (message-news (or to-group group))
951 (set-buffer gnus-article-copy)
952 (gnus-msg-treat-broken-reply-to)
953 (message-followup (if (or newsgroup-p force-news)
954 (if (save-restriction
955 (article-narrow-to-head)
956 (message-fetch-field "newsgroups"))
963 (message-mail (or to-address to-list))
964 ;; Arrange for mail groups that have no `to-address' to
965 ;; get that when the user sends off the mail.
966 (when (and (not to-list)
969 (push (list 'gnus-inews-add-to-address pgroup)
970 message-send-actions)))
971 (set-buffer gnus-article-copy)
972 (gnus-msg-treat-broken-reply-to)
973 (message-wide-reply to-address)))
975 (gnus-inews-yank-articles yank))))))
977 (defun gnus-msg-treat-broken-reply-to (&optional force)
978 "Remove the Reply-to header iff broken-reply-to."
980 (gnus-group-find-parameter
981 gnus-newsgroup-name 'broken-reply-to))
983 (message-narrow-to-head)
984 (message-remove-header "reply-to"))))
986 (defun gnus-post-method (arg group &optional silent)
987 "Return the posting method based on GROUP and ARG.
988 If SILENT, don't prompt the user."
989 (let ((gnus-post-method (or (gnus-parameter-post-method group)
991 (group-method (gnus-find-method-for-group group)))
993 ;; If the group-method is nil (which shouldn't happen) we use
994 ;; the default method.
996 (or (and (listp gnus-post-method) ;If not current/native/nil
997 (not (listp (car gnus-post-method))) ; and not a list of methods
998 gnus-post-method) ;then use it.
1000 message-post-method))
1001 ;; We want the inverse of the default
1002 ((and arg (not (eq arg 0)))
1003 (if (eq gnus-post-method 'current)
1006 ;; We query the user for a post method.
1008 (and (listp gnus-post-method)
1009 (listp (car gnus-post-method))))
1011 ;; Collect all methods we know about.
1013 (when (listp gnus-post-method)
1014 (if (listp (car gnus-post-method))
1016 (list gnus-post-method)))
1017 gnus-secondary-select-methods
1018 (mapcar 'cdr gnus-server-alist)
1019 (mapcar 'car gnus-opened-servers)
1020 (list gnus-select-method)
1021 (list group-method)))
1022 method-alist post-methods method)
1023 ;; Weed out all mail methods.
1025 (setq method (gnus-server-get-method "" (pop methods)))
1026 (when (and (or (gnus-method-option-p method 'post)
1027 (gnus-method-option-p method 'post-mail))
1028 (not (member method post-methods)))
1029 (push method post-methods)))
1030 ;; Create a name-method alist.
1034 (if (equal (cadr m) "")
1035 (list (symbol-name (car m)) m)
1036 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1041 (setq gnus-last-posting-server
1043 gnus-last-posting-server)
1044 ;; Just use the last value.
1045 gnus-last-posting-server
1047 "Posting method: " method-alist nil t
1048 (cons (or gnus-last-posting-server "") 0))))
1050 ;; Override normal method.
1051 ((and (eq gnus-post-method 'current)
1052 (not (memq (car group-method) gnus-discouraged-post-methods))
1053 (gnus-get-function group-method 'request-post t))
1056 ;; Use gnus-post-method.
1057 ((listp gnus-post-method) ;A method...
1058 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1060 ;; Use the normal select method (nil or native).
1061 (t gnus-select-method))))
1064 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1066 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1067 variable `mime-edit-user-agent-value' is bound, the value will be
1068 included in the return value. If MAX-COLUMN is specified, the return
1069 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1070 whether a newline should be inserted in front of each product-token.
1071 If the value is t or `hard', it works strictly. Otherwise, if it is
1072 non-nil (e.g. `soft'), it works semi-strictly.
1074 Here is an example of how to use this function:
1076 \(add-hook 'gnus-message-setup-hook
1078 (setq message-user-agent nil)
1081 (message-narrow-to-headers)
1082 (goto-char (point-max))
1083 (insert \"User-Agent: \"
1084 (gnus-message-make-user-agent t 76 'soft)
1087 (let ((user-agent (if (and include-mime-info
1088 (boundp 'mime-edit-user-agent-value))
1089 (concat (gnus-extended-version)
1091 mime-edit-user-agent-value)
1092 (gnus-extended-version))))
1094 (unless (natnump max-column)
1095 (setq max-column 76))
1097 (set-buffer-multibyte t)
1098 (insert (mapconcat 'identity (split-string user-agent) " "))
1099 (goto-char (point-min))
1101 start agent agents width element swidth)
1102 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1103 (setq start (match-beginning 0))
1104 (if (eq (char-after start) ?\()
1108 (push (buffer-substring start (point)) agent))
1110 (push (nreverse agent) agents))
1111 (setq agent (list (match-string 1)))))
1113 (push (nreverse agent) agents))
1114 (setq agents (nreverse agents))
1115 (if (> (+ 12 (string-width (caar agents))) max-column)
1116 (setq user-agent "\n"
1121 (setq agent (car agents)
1122 agents (cdr agents))
1123 (when (and (not bol)
1124 (or (memq newline-product '(t hard))
1125 (and newline-product
1127 (string-width (mapconcat 'identity
1130 (setq user-agent (concat user-agent "\n")
1134 (setq element (car agent)
1135 swidth (string-width element)
1138 (setq user-agent (if (member user-agent '("" "\n"))
1139 (concat user-agent element)
1140 (concat user-agent " " element))
1141 width (+ width 1 swidth)
1143 (if (> (+ width 1 swidth) max-column)
1144 (setq user-agent (concat user-agent "\n " element)
1146 (setq user-agent (concat user-agent " " element)
1147 width (+ width 1 swidth)))))))))
1152 ;;; Gnus Mail Functions
1155 ;;; Mail reply commands of Gnus summary mode
1157 (defun gnus-summary-reply (&optional yank wide very-wide)
1158 "Start composing a mail reply to the current message.
1159 If prefix argument YANK is non-nil, the original article is yanked
1161 If WIDE, make a wide reply.
1162 If VERY-WIDE, make a very wide reply."
1164 (list (and current-prefix-arg
1165 (gnus-summary-work-articles 1))))
1166 ;; Allow user to require confirmation before replying by mail to the
1167 ;; author of a news article.
1168 (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1169 (not gnus-confirm-mail-reply-to-news)
1170 (y-or-n-p "Really reply by mail to article author? "))
1172 (if (listp (car yank))
1175 (gnus-article-reply (or article (gnus-summary-article-number)))
1177 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1179 (gnus-summary-goto-subject article))
1180 (gnus-setup-message (if yank 'reply-yank 'reply)
1182 (gnus-summary-select-article)
1183 (dolist (article very-wide)
1184 (gnus-summary-select-article nil nil nil article)
1186 (set-buffer (gnus-copy-article-buffer))
1187 (gnus-msg-treat-broken-reply-to)
1189 (message-narrow-to-head)
1190 (setq headers (concat headers (buffer-string)))))))
1191 (set-buffer (gnus-copy-article-buffer))
1192 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1194 (message-narrow-to-head)
1198 (goto-char (point-max)))
1199 (message-reply nil wide)
1201 (gnus-inews-yank-articles yank))
1202 (gnus-summary-handle-replysign)))))
1204 (defun gnus-summary-handle-replysign ()
1205 "Check the various replysign variables and take action accordingly."
1206 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1207 (let (signed encrypted)
1209 (set-buffer gnus-article-buffer)
1210 (setq signed (memq 'signed gnus-article-wash-types))
1211 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1212 (cond ((and gnus-message-replyencrypt encrypted)
1213 (mml-secure-message mml-default-encrypt-method
1214 (if gnus-message-replysignencrypted
1217 ((and gnus-message-replysign signed)
1218 (mml-secure-message mml-default-sign-method 'sign))))))
1220 (defun gnus-summary-reply-with-original (n &optional wide)
1221 "Start composing a reply mail to the current message.
1222 The original article will be yanked."
1224 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1226 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1227 "Like `gnus-summary-reply' except removing reply-to field.
1228 If prefix argument YANK is non-nil, the original article is yanked
1230 If WIDE, make a wide reply.
1231 If VERY-WIDE, make a very wide reply."
1233 (list (and current-prefix-arg
1234 (gnus-summary-work-articles 1))))
1235 (let ((gnus-msg-force-broken-reply-to t))
1236 (gnus-summary-reply yank wide very-wide)))
1238 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1239 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1240 The original article will be yanked."
1242 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1244 (defun gnus-summary-wide-reply (&optional yank)
1245 "Start composing a wide reply mail to the current message.
1246 If prefix argument YANK is non-nil, the original article is yanked
1249 (list (and current-prefix-arg
1250 (gnus-summary-work-articles 1))))
1251 (gnus-summary-reply yank t))
1253 (defun gnus-summary-wide-reply-with-original (n)
1254 "Start composing a wide reply mail to the current message.
1255 The original article will be yanked."
1257 (gnus-summary-reply-with-original n t))
1259 (defun gnus-summary-very-wide-reply (&optional yank)
1260 "Start composing a very 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 (gnus-summary-work-articles yank)))
1268 (defun gnus-summary-very-wide-reply-with-original (n)
1269 "Start composing a very wide reply mail to the current message.
1270 The original article will be yanked."
1273 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1275 (defun gnus-summary-mail-forward (&optional full-headers post)
1276 "Forward the current message(s) to another user.
1277 If process marks exist, forward all marked messages;
1278 If FULL-HEADERS (the prefix), include full headers when forwarding.
1280 Note that this function definition for T-gnus is totally different
1281 from the original Gnus."
1283 (if (null (cdr (gnus-summary-work-articles nil)))
1284 (gnus-setup-message 'forward
1285 (gnus-summary-select-article)
1286 (let ((charset default-mime-charset))
1287 (set-buffer gnus-original-article-buffer)
1288 (make-local-variable 'default-mime-charset)
1289 (setq default-mime-charset charset))
1290 (let ((message-included-forward-headers
1291 (if full-headers "" message-included-forward-headers)))
1292 (message-forward post)))
1293 (gnus-summary-digest-mail-forward nil post)))
1295 (defun gnus-summary-digest-mail-forward (&optional n post)
1296 "Digests and forwards all articles in this series.
1297 If N is a positive number, forward the N next articles.
1298 If N is a negative number, forward the N previous articles.
1299 If N is nil and any articles have been marked with the process mark,
1300 forward those articles instead.
1301 Optional POST will use news to forward instead of mail."
1303 (let ((articles (gnus-summary-work-articles n))
1304 (topics "Topics:\n")
1305 subject article frame)
1306 (when (car articles)
1307 (gnus-setup-message 'forward
1308 (gnus-summary-select-article)
1310 (setq articles (sort articles '<)
1311 subject "Digested Articles")
1312 (with-current-buffer gnus-original-article-buffer
1313 (setq subject (message-make-forward-subject))))
1315 (message-news nil subject)
1316 (message-mail nil subject))
1317 (when (and message-use-multi-frames (cdr articles))
1318 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1320 (while (setq article (pop articles))
1321 (save-window-excursion
1322 (set-buffer gnus-summary-buffer)
1323 (gnus-summary-select-article nil nil nil article)
1324 (setq topics (concat topics " "
1325 (mail-header-subject gnus-current-headers)
1327 (gnus-summary-remove-process-mark article))
1329 (select-frame frame))
1330 (insert (mime-make-tag "message" "rfc822") "\n")
1331 (narrow-to-region (point) (point))
1332 (insert-buffer-substring gnus-original-article-buffer)
1334 (article-narrow-to-head)
1335 (message-remove-header message-included-forward-headers t nil t))
1336 (goto-char (point-max))
1342 (mime-edit-enclose-digest-region (point)(mark t))))))
1344 (defun gnus-summary-digest-post-forward (&optional n)
1345 "Digest and forwards all articles in this series to a newsgroup.
1346 If N is a positive number, forward the N next articles.
1347 If N is a negative number, forward the N previous articles.
1348 If N is nil and any articles have been marked with the process mark,
1349 forward those articles instead."
1351 (gnus-summary-digest-mail-forward n t))
1353 (defun gnus-summary-resend-message (address n)
1354 "Resend the current article to ADDRESS."
1356 (list (message-read-from-minibuffer
1357 "Resend message(s) to: "
1358 (when (and gnus-summary-resend-default-address
1359 (gnus-buffer-live-p gnus-original-article-buffer))
1360 ;; If some other article is currently selected, the
1361 ;; initial-contents is wrong. Whatever, it is just the
1362 ;; initial-contents.
1363 (with-current-buffer gnus-original-article-buffer
1364 (nnmail-fetch-field "to"))))
1365 current-prefix-arg))
1366 (let ((articles (gnus-summary-work-articles n))
1368 (while (setq article (pop articles))
1369 (gnus-summary-select-article nil nil nil article)
1371 (set-buffer gnus-original-article-buffer)
1372 (message-resend address))
1373 (gnus-summary-mark-article-as-forwarded article))))
1375 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1376 (defun gnus-summary-resend-message-edit ()
1377 "Resend an article that has already been sent.
1378 A new buffer will be created to allow the user to modify body and
1379 contents of the message, and then, everything will happen as when
1380 composing a new message."
1382 (let ((article (gnus-summary-article-number)))
1383 (gnus-setup-message 'reply-yank
1384 (gnus-summary-select-article t)
1385 (set-buffer gnus-original-article-buffer)
1386 (let ((cur (current-buffer))
1387 (to (message-fetch-field "to")))
1388 ;; Get a normal message buffer.
1389 (message-pop-to-buffer (message-buffer-name "Resend" to))
1390 (insert-buffer-substring cur)
1392 ;; T-gnus change: Use MIME-Edit to recompose a message.
1394 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1395 (fset 'mime-edit-decode-single-part-in-buffer
1396 (lambda (&rest args)
1397 (if (let ((content-type (car args)))
1398 (and (eq 'message (mime-content-type-primary-type
1400 (eq 'rfc822 (mime-content-type-subtype
1402 (setcar (cdr args) 'not-decode-text))
1405 (mime-edit-again nil t)
1406 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1407 (message-narrow-to-head-1)
1408 (insert "From: " (message-make-from) "\n")
1409 (while (re-search-forward "^From:" nil t)
1411 (insert "Original-"))
1412 (message-remove-header "^>From[\t ]" t)
1414 ;; Gnus will generate a new one when sending.
1415 (message-remove-header "Message-ID")
1416 (message-remove-header message-ignored-resent-headers t)
1417 ;; Remove unwanted headers.
1418 (goto-char (point-max))
1419 (insert mail-header-separator)
1420 (goto-char (point-min))
1421 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1425 (defun gnus-summary-post-forward (&optional full-headers)
1426 "Forward the current article to a newsgroup.
1427 If FULL-HEADERS (the prefix), include full headers when forwarding."
1429 (gnus-summary-mail-forward full-headers t))
1431 (defvar gnus-nastygram-message
1432 "The following article was inappropriately posted to %s.\n\n"
1433 "Format string to insert in nastygrams.
1434 The current group name will be inserted at \"%s\".")
1436 (defun gnus-summary-mail-nastygram (n)
1437 "Send a nastygram to the author of the current article."
1439 (when (or gnus-expert-user
1441 "Really send a nastygram to the author of the current article? "))
1442 (let ((group gnus-newsgroup-name))
1443 (gnus-summary-reply-with-original n)
1444 (set-buffer gnus-message-buffer)
1446 (insert (format gnus-nastygram-message group))
1447 (message-send-and-exit))))
1449 (defun gnus-summary-mail-crosspost-complaint (n)
1450 "Send a complaint about crossposting to the current article(s)."
1452 (let ((articles (gnus-summary-work-articles n))
1454 (while (setq article (pop articles))
1455 (set-buffer gnus-summary-buffer)
1456 (gnus-summary-goto-subject article)
1457 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1458 newsgroups followup-to)
1459 (gnus-summary-select-article)
1460 (set-buffer gnus-original-article-buffer)
1461 (if (and (<= (length (message-tokenize-header
1463 (mail-fetch-field "newsgroups"))
1466 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1467 (not (member group (message-tokenize-header
1468 followup-to ", ")))))
1470 (gnus-message 1 "Followup-to restricted")
1471 (gnus-message 1 "Not a crossposted article"))
1472 (set-buffer gnus-summary-buffer)
1473 (gnus-summary-reply-with-original 1)
1474 (set-buffer gnus-message-buffer)
1476 (insert (format gnus-crosspost-complaint newsgroups group))
1477 (message-goto-subject)
1478 (re-search-forward " *$")
1479 (replace-match " (crosspost notification)" t t)
1480 (gnus-deactivate-mark)
1481 (when (gnus-y-or-n-p "Send this complaint? ")
1482 (message-send-and-exit)))))))
1484 (defun gnus-mail-parse-comma-list ()
1487 (skip-chars-forward " ")
1490 (skip-chars-forward "^,")
1495 (narrow-to-region beg (point))
1498 (while (search-forward "\"" nil t)
1502 (skip-chars-forward ",")
1503 (skip-chars-forward "^,"))
1504 (skip-chars-backward " ")
1505 (push (buffer-substring beg (point))
1507 (skip-chars-forward "^,")
1508 (skip-chars-forward ", "))
1511 (defun gnus-inews-add-to-address (group)
1512 (let ((to-address (mail-fetch-field "to")))
1513 (when (and to-address
1515 ;; This mail group doesn't have a `to-list', so we add one
1517 (when (gnus-y-or-n-p
1518 (format "Do you want to add this as `to-list': %s " to-address))
1519 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1521 (defun gnus-put-message ()
1522 "Put the current message in some group and return to Gnus."
1524 (let ((reply gnus-article-reply)
1525 (winconf gnus-prev-winconf)
1526 (group gnus-newsgroup-name))
1528 (not (gnus-group-read-only-p group)))
1529 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1531 (when (gnus-gethash group gnus-newsrc-hashtb)
1532 (error "No such group: %s" group))
1536 (message-narrow-to-headers)
1537 (let ((gnus-deletable-headers nil))
1538 (message-generate-headers
1539 (if (message-news-p)
1540 message-required-news-headers
1541 message-required-mail-headers)))
1542 (goto-char (point-max))
1543 (if (string-match " " group)
1544 (insert "Gcc: \"" group "\"\n")
1545 (insert "Gcc: " group "\n"))
1548 (when (and (get-buffer gnus-group-buffer)
1549 (gnus-buffer-exists-p (car-safe reply))
1551 (set-buffer (car reply))
1552 (gnus-summary-mark-article-as-replied (cdr reply)))
1554 (set-window-configuration winconf))))
1556 (defun gnus-article-mail (yank)
1557 "Send a reply to the address near point.
1558 If YANK is non-nil, include the original article."
1562 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1563 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1565 (gnus-msg-mail address)
1567 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1569 (defvar nntp-server-type)
1571 "Send a bug report to the Gnus maintainers."
1573 (unless (gnus-alive-p)
1574 (error "Gnus has been shut down"))
1575 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1576 (unless (message-mail-user-agent)
1577 (message-pop-to-buffer "*Gnus Bug*")
1578 (delete-other-windows)
1579 (when gnus-bug-create-help-buffer
1580 (switch-to-buffer "*Gnus Help Bug*")
1582 (insert gnus-bug-message)
1583 (goto-char (point-min))
1585 (set-buffer "*Gnus Bug*")))
1586 (let ((message-this-is-mail t))
1587 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1588 (when gnus-bug-create-help-buffer
1589 (push `(gnus-bug-kill-buffer) message-send-actions))
1590 (goto-char (point-min))
1591 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1593 (insert gnus-product-name " " gnus-version-number
1594 " (r" gnus-revision-number ") "
1595 "based on " gnus-original-product-name " v"
1596 gnus-original-version-number "\n"
1597 (emacs-version) "\n")
1598 (when (and (boundp 'nntp-server-type)
1599 (stringp nntp-server-type))
1600 (insert nntp-server-type))
1601 (insert "\n\n\n\n\n")
1602 (let (mime-content-types)
1603 (mime-edit-insert-tag
1604 "application" "emacs-lisp"
1605 "\nContent-Disposition: inline\nContent-Description: User settings"))
1606 (insert (with-temp-buffer
1609 (let (mime-content-types)
1610 (mime-edit-insert-tag "text" "plain"))
1611 (goto-char (point-min))
1612 (search-forward "Subject: " nil t)
1615 (defun gnus-bug-kill-buffer ()
1616 (when (get-buffer "*Gnus Help Bug*")
1617 (kill-buffer "*Gnus Help Bug*")))
1619 (defun gnus-summary-yank-message (buffer n)
1620 "Yank the current article into a composed message."
1622 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1623 current-prefix-arg))
1624 (when (gnus-buffer-live-p buffer)
1625 (let ((summary-frame (selected-frame))
1626 (message-frame (when (static-if (featurep 'xemacs)
1627 (device-on-window-system-p)
1629 (let ((window (get-buffer-window buffer t)))
1631 (window-frame window)))))
1632 (separator (concat "^" (regexp-quote mail-header-separator)
1634 (gnus-summary-iterate n
1635 (gnus-summary-select-article)
1636 (gnus-copy-article-buffer)
1637 (when (frame-live-p message-frame)
1638 (raise-frame message-frame)
1639 (select-frame message-frame))
1640 (with-current-buffer buffer
1641 (when (save-excursion
1643 (let (case-fold-search)
1644 (and (not (re-search-backward separator nil t))
1645 (re-search-forward separator nil t))))
1646 (goto-char (match-end 0)))
1647 (message-yank-buffer gnus-article-copy))
1648 (select-frame summary-frame))
1649 (when (frame-live-p message-frame)
1650 (select-frame message-frame)))))
1652 (defun gnus-debug ()
1653 "Attempts to go through the Gnus source file and report what variables have been changed.
1654 The source file has to be in the Emacs load path."
1656 (let ((files gnus-debug-files)
1658 file expr olist sym)
1659 (gnus-message 4 "Please wait while we snoop your variables...")
1660 ;; Go through all the files looking for non-default values for variables.
1663 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1666 (when (and (setq file (locate-library (pop files)))
1667 (file-exists-p file))
1668 (insert-file-contents file)
1669 (goto-char (point-min))
1670 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1671 (gnus-message 4 "Malformed sources in file %s" file)
1672 (narrow-to-region (point-min) (point))
1673 (goto-char (point-min))
1674 (while (setq expr (ignore-errors (read (current-buffer))))
1676 (and (memq (car expr) '(defvar defcustom defvoo))
1677 (stringp (nth 3 expr))
1678 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1679 (or (not (boundp (nth 1 expr)))
1680 (not (equal (eval (nth 2 expr))
1681 (symbol-value (nth 1 expr)))))
1682 (push (nth 1 expr) olist)))))))
1683 (kill-buffer (current-buffer)))
1684 (when (setq olist (nreverse olist))
1685 (insert ";----------------- Environment follows ------------------\n\n"))
1687 (if (boundp (car olist))
1689 (pp `(setq ,(car olist)
1690 ,(if (or (consp (setq sym (symbol-value (car olist))))
1692 (not (or (eq sym nil)
1694 (list 'quote (symbol-value (car olist)))
1695 (symbol-value (car olist))))
1698 (format "(setq %s 'whatever)\n" (car olist))))
1699 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1700 (setq olist (cdr olist)))
1701 ;; Remove any control chars - they seem to cause trouble for some
1702 ;; mailers. (Byte-compiled output from the stuff above.)
1704 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1705 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1707 ;; Break MIME tags purposely.
1709 (while (re-search-forward mime-edit-tag-regexp nil t)
1710 (goto-char (1+ (match-beginning 0)))
1713 ;;; Treatment of rejected articles.
1716 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1717 "Re-mail the current message.
1718 This only makes sense if the current message is a bounce message than
1719 contains some mail you have written which has been bounced back to
1721 If FETCH, try to fetch the article that this is a reply to, if indeed
1724 (gnus-summary-select-article t)
1725 (set-buffer gnus-original-article-buffer)
1726 (gnus-setup-message 'compose-bounce
1727 (let* ((references (mail-fetch-field "references"))
1728 (parent (and references (gnus-parent-id references))))
1730 ;; If there are references, we fetch the article we answered to.
1732 (gnus-summary-refer-article parent)
1733 (gnus-summary-show-all-headers)))))
1737 (defun gnus-inews-group-method (group)
1739 ;; If the group doesn't exist, we assume
1740 ;; it's an archive group...
1741 ((and (null (gnus-get-info group))
1742 (eq (car (gnus-server-to-method gnus-message-archive-method))
1743 (car (gnus-server-to-method (gnus-group-method group)))))
1744 gnus-message-archive-method)
1746 ((gnus-info-method (gnus-get-info group))
1747 (gnus-info-method (gnus-get-info group)))
1749 (t (gnus-server-to-method (gnus-group-method group)))))
1751 ;; Do Gcc handling, which copied the message over to some group.
1752 (defun gnus-inews-do-gcc (&optional gcc)
1756 (message-narrow-to-headers)
1757 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1758 (coding-system-for-write 'raw-text)
1759 (output-coding-system 'raw-text)
1760 groups group method group-art
1761 mml-externalize-attachments)
1763 (message-remove-header "gcc")
1765 (setq groups (message-unquote-tokens
1766 (message-tokenize-header gcc " ,")))
1767 ;; Copy the article over to some group(s).
1768 (while (setq group (pop groups))
1769 (unless (gnus-check-server
1770 (setq method (gnus-inews-group-method group)))
1771 (error "Can't open server %s" (if (stringp method) method
1773 (unless (gnus-request-group group nil method)
1774 (gnus-request-create-group group method))
1775 (setq mml-externalize-attachments
1776 (if (stringp gnus-gcc-externalize-attachments)
1777 (string-match gnus-gcc-externalize-attachments group)
1778 gnus-gcc-externalize-attachments))
1780 (nnheader-set-temp-buffer " *acc*")
1781 (insert-buffer-substring message-encoding-buffer)
1782 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1783 (goto-char (point-min))
1784 (when (re-search-forward
1785 (concat "^" (regexp-quote mail-header-separator) "$")
1787 (replace-match "" t t ))
1788 (unless (setq group-art
1789 (gnus-request-accept-article group method t t))
1790 (gnus-message 1 "Couldn't store article in group %s: %s"
1791 group (gnus-status-message method))
1793 (when (and group-art
1794 (or gnus-gcc-mark-as-read
1795 gnus-inews-mark-gcc-as-read))
1796 (gnus-group-mark-article-read group (cdr group-art)))
1797 (kill-buffer (current-buffer)))))))))
1799 (defun gnus-inews-insert-gcc ()
1800 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1803 (message-narrow-to-headers)
1804 (let* ((group gnus-outgoing-message-group)
1806 ((gnus-functionp group)
1808 ((or (stringp group) (list group))
1813 (if (string-match " " gcc)
1814 (concat "\"" gcc "\"")
1816 (mapconcat (lambda (group)
1817 (if (string-match " " group)
1818 (concat "\"" group "\"")
1823 (defun gnus-inews-insert-archive-gcc (&optional group)
1824 "Insert the Gcc to say where the article is to be archived."
1825 (let* ((var gnus-message-archive-group)
1826 (group (or group gnus-newsgroup-name ""))
1828 (and gnus-newsgroup-name
1829 (not (equal gnus-newsgroup-name ""))
1830 (gnus-group-find-parameter
1831 gnus-newsgroup-name 'gcc-self)))
1835 ((null gnus-message-archive-method)
1839 ;; Just a single group.
1842 ;; We don't want this.
1844 ((and (listp var) (stringp (car var)))
1845 ;; A list of groups.
1847 ((gnus-functionp var)
1849 (funcall var group))
1851 ;; An alist of regexps/functions/forms.
1856 ((stringp (caar var))
1858 (when (string-match (caar var) group)
1860 ((gnus-functionp (car var))
1862 (funcall (car var) group))
1864 (eval (car var)))))))
1865 (setq var (cdr var)))
1868 (when (or groups gcc-self-val)
1869 (when (stringp groups)
1870 (setq groups (list groups)))
1873 (message-narrow-to-headers)
1874 (goto-char (point-max))
1877 ;; Use the `gcc-self' param value instead.
1880 (if (stringp gcc-self-val)
1881 (if (string-match " " gcc-self-val)
1882 (concat "\"" gcc-self-val "\"")
1884 (if (string-match " " group)
1885 (concat "\"" group "\"")
1887 (if (not (eq gcc-self-val 'none))
1892 ;; Use the list of groups.
1893 (while (setq name (pop groups))
1894 (let ((str (if (string-match ":" name)
1896 (gnus-group-prefixed-name
1897 name gnus-message-archive-method))))
1898 (insert (if (string-match " " str)
1899 (concat "\"" str "\"")
1907 (defun gnus-configure-posting-styles (&optional group-name)
1908 "Configure posting styles according to `gnus-posting-styles'."
1909 (unless gnus-inhibit-posting-styles
1910 (let ((group (or group-name gnus-newsgroup-name ""))
1911 (styles gnus-posting-styles)
1912 style match attribute results
1914 ;; If the group has a posting-style parameter, add it at the end with a
1915 ;; regexp matching everything, to be sure it takes precedence over all
1917 (when gnus-newsgroup-name
1918 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1920 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1921 ;; Go through all styles and look for matches.
1922 (dolist (style styles)
1923 (setq match (pop style))
1924 (goto-char (point-min))
1927 ;; Regexp string match on the group name.
1928 (string-match match group))
1930 ;; Obsolete format of header match.
1931 (and (gnus-buffer-live-p gnus-article-copy)
1932 (with-current-buffer gnus-article-copy
1933 (let ((header (message-fetch-field (pop style))))
1935 (string-match (pop style) header))))))
1936 ((or (symbolp match)
1937 (gnus-functionp match))
1939 ((gnus-functionp match)
1940 ;; Function to be called.
1943 ;; Variable to be checked.
1944 (symbol-value match))))
1947 ((eq (car match) 'header)
1948 ;; New format of header match.
1949 (and (gnus-buffer-live-p gnus-article-copy)
1950 (with-current-buffer gnus-article-copy
1951 (let ((header (message-fetch-field (nth 1 match))))
1953 (string-match (nth 2 match) header))))))
1955 ;; This is a form to be evaled.
1957 ;; We have a match, so we set the variables.
1958 (setq style (gnus-configure-posting-style style nil))
1959 (dolist (attribute style)
1960 (setq results (delq (assoc (car attribute) results) results))
1961 (push attribute results))))
1962 ;; Now we have all the styles, so we insert them.
1963 (setq name (assq 'name results)
1964 address (assq 'address results))
1965 (setq results (delq name (delq address results)))
1966 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1967 (make-local-hook 'message-setup-hook)
1968 (dolist (result results)
1969 (add-hook 'message-setup-hook
1971 ((eq 'eval (car result))
1973 ((eq 'body (car result))
1977 (insert ,(cdr result)))))
1978 ((eq 'signature (car result))
1979 (set (make-local-variable 'message-signature) nil)
1980 (set (make-local-variable 'message-signature-file) nil)
1981 (if (not (cdr result))
1985 (let ((message-signature ,(cdr result)))
1986 (when message-signature
1987 (message-insert-signature)))))))
1990 (if (symbolp (car result))
1991 (capitalize (symbol-name (car result)))
1995 (message-remove-header ,header)
1996 (let ((value ,(cdr result)))
1999 (insert ,header ": " value "\n"))))))))
2001 (when (or name address)
2002 (add-hook 'message-setup-hook
2004 (set (make-local-variable 'user-mail-address)
2005 ,(or (cdr address) user-mail-address))
2006 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2008 ,(or (cdr address) user-mail-address)))
2010 (message-remove-header "From")
2012 (insert "From: " (message-make-from) "\n"))))
2015 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2016 (defun gnus-configure-posting-style (style stack)
2017 "Parse one posting style STYLE and returns the value as an alist."
2018 (let (results element variable filep value v)
2019 (dolist (attribute style)
2020 (setq element (pop attribute)
2025 ((eq (car attribute) ':file)
2028 ((eq (car attribute) :value)
2032 ;; We get the value.
2037 ((or (symbolp value)
2038 (gnus-functionp value))
2039 (cond ((gnus-functionp value)
2042 (symbol-value value))))
2045 ;; Translate obsolescent value.
2047 ((eq element 'signature-file)
2048 (setq element 'signature
2050 ((eq element 'x-face-file)
2051 (setq element 'x-face
2053 ;; Get the contents of file elems.
2055 (setq v (with-temp-buffer
2056 (insert-file-contents v)
2057 (goto-char (point-max))
2061 (if (eq element 'import)
2063 (if (member v stack)
2064 (error "Circular import of \"%s\"" v))
2066 (nconc (nreverse (gnus-configure-posting-style
2067 (cdr (assoc v gnus-named-posting-styles))
2070 (push (cons element v) results)))
2071 (nreverse results)))
2073 (defun gnus-summary-execute-command-with-posting-style (style command)
2074 "Temporarily select a posting-style named STYLE and execute COMMAND."
2076 (let ((style (completing-read "Posting style: "
2077 gnus-named-posting-styles nil t)))
2081 (format "Command to execute with %s: " style))))))
2082 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2083 (call-interactively command)))
2086 ;;; @ for MIME Edit mode
2089 (defun gnus-maybe-setup-default-charset ()
2091 (and (boundp 'gnus-summary-buffer)
2092 (buffer-live-p gnus-summary-buffer)
2094 (set-buffer gnus-summary-buffer)
2095 default-mime-charset))))
2098 (make-local-variable 'default-mime-charset)
2099 (setq default-mime-charset charset)
2103 ;;; @ for MIME view mode
2106 (defun gnus-following-method (buf)
2107 (gnus-setup-message 'reply-yank
2109 (if (message-news-p)
2111 (message-reply nil 'wide))
2112 (let ((message-reply-buffer buf))
2113 (message-yank-original))
2114 (message-goto-body))
2118 ;;; Allow redefinition of functions.
2124 ;;; gnus-msg.el ends here