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
286 This can also be a function receiving the group name as the only
287 parameter which should return non-nil iff a confirmation is needed, or
288 a regexp, in which case a confirmation is asked for iff the group name
291 :type '(choice (const :tag "No" nil)
293 (regexp :tag "Iff group matches regexp")
294 (function :tag "Iff function evaluates to non-nil")))
296 (defcustom gnus-confirm-treat-mail-like-news
298 "If non-nil, Gnus will treat mail like news with regard to confirmation
299 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
300 for fine-tuning this.
301 If nil, Gnus will never ask for confirmation if replying to mail."
305 (defcustom gnus-summary-resend-default-address t
306 "If non-nil, Gnus tries to suggest a default address to resend to.
307 If nil, the address field will always be empty after invoking
308 `gnus-summary-resend-message'."
312 ;;; Internal variables.
314 (defvar gnus-inhibit-posting-styles nil
315 "Inhibit the use of posting styles.")
317 (defvar gnus-article-yanked-articles nil)
318 (defvar gnus-message-buffer "*Mail Gnus*")
319 (defvar gnus-article-copy nil)
320 (defvar gnus-check-before-posting nil)
321 (defvar gnus-last-posting-server nil)
322 (defvar gnus-message-group-art nil)
324 (defvar gnus-msg-force-broken-reply-to nil)
326 (defconst gnus-bug-message
327 (format "Sending a bug report to the Gnus Towers.
328 ========================================
330 This gnus is the %s%s.
331 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
332 Developers. (the addresses below are mailing list addresses)
334 ========================================
336 The buffer below is a mail buffer. When you press `C-c C-c', it will
337 be sent to the Gnus Bug Exterminators.
339 The thing near the bottom of the buffer is how the environment
340 settings will be included in the mail. Please do not delete that.
341 They will tell the Bug People what your environment is, so that it
342 will be easier to locate the bugs.
344 If you have found a bug that makes Emacs go \"beep\", set
345 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
346 and include the backtrace in your bug report.
348 Please describe the bug in annoying, painstaking detail.
350 Thank you for your help in stamping out bugs.
353 (if (string= gnus-product-name "Semi-gnus")
355 ", a modified version of Semi-gnus")))
358 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
359 (autoload 'news-setup "rnewspost")
360 (autoload 'news-reply-mode "rnewspost")
361 (autoload 'rmail-dont-reply-to "mail-utils")
362 (autoload 'rmail-output "rmailout"))
366 ;;; Gnus Posting Functions
369 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
370 "p" gnus-summary-post-news
371 "i" gnus-summary-news-other-window
372 "f" gnus-summary-followup
373 "F" gnus-summary-followup-with-original
374 "c" gnus-summary-cancel-article
375 "s" gnus-summary-supersede-article
376 "r" gnus-summary-reply
377 "y" gnus-summary-yank-message
378 "R" gnus-summary-reply-with-original
379 "w" gnus-summary-wide-reply
380 "W" gnus-summary-wide-reply-with-original
381 "v" gnus-summary-very-wide-reply
382 "V" gnus-summary-very-wide-reply-with-original
383 "n" gnus-summary-followup-to-mail
384 "N" gnus-summary-followup-to-mail-with-original
385 "m" gnus-summary-mail-other-window
386 "u" gnus-uu-post-news
387 "\M-c" gnus-summary-mail-crosspost-complaint
388 "Br" gnus-summary-reply-broken-reply-to
389 "BR" gnus-summary-reply-broken-reply-to-with-original
390 "om" gnus-summary-mail-forward
391 "op" gnus-summary-post-forward
392 "Om" gnus-summary-digest-mail-forward
393 "Op" gnus-summary-digest-post-forward
394 "P" gnus-summary-execute-command-with-posting-style)
396 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
397 "b" gnus-summary-resend-bounced-mail
398 ;; "c" gnus-summary-send-draft
399 "r" gnus-summary-resend-message
400 "e" gnus-summary-resend-message-edit)
402 ;;; Internal functions.
404 (defun gnus-inews-make-draft ()
406 (gnus-inews-make-draft-meta-information
407 ,gnus-newsgroup-name ',gnus-article-reply)))
409 (defvar gnus-article-reply nil)
410 (defmacro gnus-setup-message (config &rest forms)
411 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
412 (buffer (make-symbol "gnus-setup-message-buffer"))
413 (article (make-symbol "gnus-setup-message-article"))
414 (yanked (make-symbol "gnus-setup-yanked-articles"))
415 (group (make-symbol "gnus-setup-message-group")))
416 `(let ((,winconf (current-window-configuration))
417 (,buffer (buffer-name (current-buffer)))
418 (,article gnus-article-reply)
419 (,yanked gnus-article-yanked-articles)
420 (,group gnus-newsgroup-name)
421 (message-header-setup-hook
422 (copy-sequence message-header-setup-hook))
423 (message-mode-hook (copy-sequence message-mode-hook))
424 (message-startup-parameter-alist
425 '((reply-buffer . gnus-copy-article-buffer)
426 (original-buffer . gnus-original-article-buffer)
427 (user-agent . Gnus))))
428 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
429 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
430 ;; #### FIXME: for a reason that I did not manage to identify yet,
431 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
432 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
433 ;; After evaluation of @forms below, it gets the value we actually want
434 ;; to override, and the posting styles are used. For that reason, I've
435 ;; added an optional argument to `gnus-configure-posting-styles' to
436 ;; make sure that the correct value for the group name is used. -- drv
437 (add-hook 'message-mode-hook
439 (gnus-configure-posting-styles ,group)))
440 (gnus-pull ',(intern gnus-draft-meta-information-header)
441 message-required-headers)
443 (not (string= ,group "")))
445 (intern gnus-draft-meta-information-header)
446 (gnus-inews-make-draft))
447 message-required-headers))
451 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
453 (setq gnus-message-buffer (current-buffer))
454 (set (make-local-variable 'gnus-message-group-art)
455 (cons ,group ,article))
456 (set (make-local-variable 'gnus-newsgroup-name) ,group)
457 (gnus-maybe-setup-default-charset)
458 (gnus-run-hooks 'gnus-message-setup-hook))
460 (gnus-configure-windows ,config t)
461 (run-hooks 'post-command-hook)
462 (set-buffer-modified-p nil))))
464 (defun gnus-inews-make-draft-meta-information (group article)
465 (concat "(\"" group "\" "
466 (if article (number-to-string
473 (defun gnus-msg-mail (&optional to subject other-headers continue
474 switch-action yank-action send-actions)
475 "Start editing a mail message to be sent.
476 Like `message-mail', but with Gnus paraphernalia, particularly the
477 Gcc: header for archiving purposes."
479 (let ((buf (current-buffer))
481 (gnus-setup-message 'message
482 (message-mail to subject other-headers continue
483 nil yank-action send-actions))
485 (setq mail-buf (current-buffer))
486 (switch-to-buffer buf)
487 (apply switch-action mail-buf nil)))
488 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
491 (defvar save-selected-window-window)
494 (defun gnus-button-mailto (address)
496 (set-buffer (gnus-copy-article-buffer))
497 (gnus-setup-message 'message
498 (message-reply address))
499 (and (boundp 'save-selected-window-window)
500 (not (window-live-p save-selected-window-window))
501 (setq save-selected-window-window (selected-window))))
504 (defun gnus-button-reply (&optional to-address wide)
505 "Like `message-reply'."
507 (gnus-setup-message 'message
508 (message-reply to-address wide))
509 (and (boundp 'save-selected-window-window)
510 (not (window-live-p save-selected-window-window))
511 (setq save-selected-window-window (selected-window))))
514 (define-mail-user-agent 'gnus-user-agent
515 'gnus-msg-mail 'message-send-and-exit
516 'message-kill-buffer 'message-send-hook)
518 (defun gnus-setup-posting-charset (group)
519 (let ((alist gnus-group-posting-charset-alist)
520 (group (or group ""))
524 (while (setq elem (pop alist))
525 (when (or (and (stringp (car elem))
526 (string-match (car elem) group))
527 (and (gnus-functionp (car elem))
528 (funcall (car elem) group))
529 (and (symbolp (car elem))
530 (symbol-value (car elem))))
531 (throw 'found (cons (cadr elem) (caddr elem)))))))))
533 (defun gnus-inews-add-send-actions (winconf buffer article
534 &optional config yanked)
535 (make-local-hook 'message-sent-hook)
536 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
537 'gnus-inews-do-gcc) nil t)
539 (make-local-hook 'message-header-hook)
540 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
541 (setq message-post-method
543 (gnus-post-method arg ,gnus-newsgroup-name)))
544 (setq message-user-agent (gnus-extended-version))
545 (when (not message-use-multi-frames)
547 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
548 (let ((to-be-marked (cond
550 (article (if (listp article) article (list article)))
553 `(when (gnus-buffer-exists-p ,buffer)
557 (if (eq config 'forward)
558 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
559 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
562 (put 'gnus-setup-message 'lisp-indent-function 1)
563 (put 'gnus-setup-message 'edebug-form-spec '(form body))
565 ;;; Post news commands of Gnus group mode and summary mode
567 (defun gnus-group-mail (&optional arg)
568 "Start composing a mail.
569 If ARG, use the group under the point to find a posting style.
570 If ARG is 1, prompt for a group name to find the posting style."
572 ;; We can't `let' gnus-newsgroup-name here, since that leads
573 ;; to local variables leaking.
574 (let ((group gnus-newsgroup-name)
575 ;; make sure last viewed article doesn't affect posting styles:
577 (buffer (current-buffer)))
580 (setq gnus-newsgroup-name
582 (if (= 1 (prefix-numeric-value arg))
583 (completing-read "Use posting style of group: "
584 gnus-active-hashtb nil
585 (gnus-read-active-file-p))
586 (gnus-group-group-name))
588 ;; #### see comment in gnus-setup-message -- drv
589 (gnus-setup-message 'message (message-mail)))
592 (setq gnus-newsgroup-name group)))))
594 (defun gnus-group-news (&optional arg)
595 "Start composing a news.
596 If ARG, post to group under point.
597 If ARG is 1, prompt for group name to post to.
599 This function prepares a news even when using mail groups. This is useful
600 for posting messages to mail groups without actually sending them over the
601 network. The corresponding backend must have a 'request-post method."
603 ;; We can't `let' gnus-newsgroup-name here, since that leads
604 ;; to local variables leaking.
605 (let ((group gnus-newsgroup-name)
606 ;; make sure last viewed article doesn't affect posting styles:
608 (buffer (current-buffer)))
611 (setq gnus-newsgroup-name
613 (if (= 1 (prefix-numeric-value arg))
614 (completing-read "Use group: "
615 gnus-active-hashtb nil
616 (gnus-read-active-file-p))
617 (gnus-group-group-name))
619 ;; #### see comment in gnus-setup-message -- drv
620 (gnus-setup-message 'message
621 (message-news (gnus-group-real-name gnus-newsgroup-name))))
624 (setq gnus-newsgroup-name group)))))
626 (defun gnus-group-post-news (&optional arg)
627 "Start composing a message (a news by default).
628 If ARG, post to group under point. If ARG is 1, prompt for group name.
629 Depending on the selected group, the message might be either a mail or
632 ;; Bind this variable here to make message mode hooks work ok.
633 (let ((gnus-newsgroup-name
635 (if (= 1 (prefix-numeric-value arg))
636 (completing-read "Newsgroup: " gnus-active-hashtb nil
637 (gnus-read-active-file-p))
638 (gnus-group-group-name))
640 ;; make sure last viewed article doesn't affect posting styles:
642 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
643 (string= gnus-newsgroup-name ""))))
645 (defun gnus-summary-mail-other-window (&optional arg)
646 "Start composing a mail in another window.
647 Use the posting of the current group by default.
648 If ARG, don't do that. If ARG is 1, prompt for group name to find the
651 ;; We can't `let' gnus-newsgroup-name here, since that leads
652 ;; to local variables leaking.
653 (let ((group gnus-newsgroup-name)
654 ;; make sure last viewed article doesn't affect posting styles:
656 (buffer (current-buffer)))
659 (setq gnus-newsgroup-name
661 (if (= 1 (prefix-numeric-value arg))
662 (completing-read "Use group: "
663 gnus-active-hashtb nil
664 (gnus-read-active-file-p))
666 gnus-newsgroup-name))
667 ;; #### see comment in gnus-setup-message -- drv
668 (gnus-setup-message 'message (message-mail)))
671 (setq gnus-newsgroup-name group)))))
673 (defun gnus-summary-news-other-window (&optional arg)
674 "Start composing a news in another window.
675 Post to the current group by default.
676 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
678 This function prepares a news even when using mail groups. This is useful
679 for posting messages to mail groups without actually sending them over the
680 network. The corresponding backend must have a 'request-post method."
682 ;; We can't `let' gnus-newsgroup-name here, since that leads
683 ;; to local variables leaking.
684 (let ((group gnus-newsgroup-name)
685 ;; make sure last viewed article doesn't affect posting styles:
687 (buffer (current-buffer)))
690 (setq gnus-newsgroup-name
692 (if (= 1 (prefix-numeric-value arg))
693 (completing-read "Use group: "
694 gnus-active-hashtb nil
695 (gnus-read-active-file-p))
697 gnus-newsgroup-name))
698 ;; #### see comment in gnus-setup-message -- drv
699 (gnus-setup-message 'message
700 (message-news (gnus-group-real-name gnus-newsgroup-name))))
703 (setq gnus-newsgroup-name group)))))
705 (defun gnus-summary-post-news (&optional arg)
706 "Start composing a message. Post to the current group by default.
707 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
708 Depending on the selected group, the message might be either a mail or
711 ;; Bind this variable here to make message mode hooks work ok.
712 (let ((gnus-newsgroup-name
714 (if (= 1 (prefix-numeric-value arg))
715 (completing-read "Newsgroup: " gnus-active-hashtb nil
716 (gnus-read-active-file-p))
718 gnus-newsgroup-name))
719 ;; make sure last viewed article doesn't affect posting styles:
721 (gnus-post-news 'post gnus-newsgroup-name)))
724 (defun gnus-summary-followup (yank &optional force-news)
725 "Compose a followup to an article.
726 If prefix argument YANK is non-nil, the original article is yanked
728 YANK is a list of elements, where the car of each element is the
729 article number, and the two following numbers is the region to be
732 (list (and current-prefix-arg
733 (gnus-summary-work-articles 1))))
735 (gnus-summary-goto-subject
736 (if (listp (car yank))
739 (save-window-excursion
740 (gnus-summary-select-article))
741 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
742 (gnus-newsgroup-name gnus-newsgroup-name))
744 (gnus-post-news nil gnus-newsgroup-name
745 headers gnus-article-buffer
747 (gnus-summary-handle-replysign)))
749 (defun gnus-summary-followup-with-original (n &optional force-news)
750 "Compose a followup to an article and include the original article."
752 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
754 (defun gnus-summary-followup-to-mail (&optional arg)
755 "Followup to the current mail message via news."
757 (list (and current-prefix-arg
758 (gnus-summary-work-articles 1))))
759 (gnus-summary-followup arg t))
761 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
762 "Followup to the current mail message via news."
764 (gnus-summary-followup (gnus-summary-work-articles arg) t))
766 (defun gnus-inews-yank-articles (articles)
767 (let (beg article yank-string
768 (more-than-one (cdr articles))
769 (cur (current-buffer))
772 (while (setq article (pop articles))
773 (when (listp article)
774 (setq yank-string (nth 1 article)
775 article (nth 0 article)))
776 (save-window-excursion
777 (set-buffer gnus-summary-buffer)
778 (gnus-summary-select-article nil nil nil article)
779 (gnus-summary-remove-process-mark article))
781 ;; Gathering references.
783 (setq refs (message-list-references
785 (mail-header-references gnus-current-headers)
786 (mail-header-message-id gnus-current-headers)))
787 (when message-use-multi-frames
788 (when (setq window (get-buffer-window cur t))
789 (select-frame (window-frame window)))))
791 (gnus-copy-article-buffer nil yank-string)
792 (let ((message-reply-buffer gnus-article-copy)
793 (message-reply-headers
794 ;; The headers are decoded.
795 (with-current-buffer gnus-article-copy
797 (nnheader-narrow-to-headers)
798 (nnheader-parse-naked-head)))))
799 (message-yank-original)
800 (setq beg (or beg (mark t))))
805 ;; Replace with the gathered references.
809 (message-narrow-to-headers)
810 (let ((case-fold-search t))
811 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
813 (goto-char (point-max))))
815 (list (or (assq 'References message-header-format-alist)
816 '(References . message-shorten-references)))
817 (list (cons 'References
818 (mapconcat 'identity (nreverse refs) " "))))
819 (backward-delete-char 1))
825 (defun gnus-summary-cancel-article (&optional n symp)
826 "Cancel an article you posted.
827 Uses the process-prefix convention. If given the symbolic
828 prefix `a', cancel using the standard posting method; if not
829 post using the current select method."
830 (interactive (gnus-interactive "P\ny"))
831 (let ((articles (gnus-summary-work-articles n))
834 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
836 (while (setq article (pop articles))
837 (when (gnus-summary-select-article t nil nil article)
838 (when (gnus-eval-in-buffer-window gnus-article-buffer
840 (set-buffer gnus-original-article-buffer)
841 (message-cancel-news)))
842 (gnus-summary-mark-as-read article gnus-canceled-mark)
843 (gnus-cache-remove-article 1))
844 (gnus-article-hide-headers-if-wanted))
845 (gnus-summary-remove-process-mark article))))
847 (defun gnus-summary-supersede-article ()
848 "Compose an article that will supersede a previous article.
849 This is done simply by taking the old article and adding a Supersedes
850 header line with the old Message-ID."
852 (let ((article (gnus-summary-article-number)))
853 (gnus-setup-message 'reply-yank
854 (gnus-summary-select-article t)
855 (set-buffer gnus-original-article-buffer)
859 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
861 (set-buffer ,gnus-summary-buffer)
862 (gnus-cache-possibly-remove-article ,article nil nil nil t)
863 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
864 message-send-actions))))
868 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
869 ;; make a copy of the article buffer with all text properties removed
870 ;; this copy is in the buffer gnus-article-copy.
871 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
872 ;; this buffer should be passed to all mail/news reply/post routines.
873 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
875 (set-buffer gnus-article-copy)
876 (set-buffer-multibyte t))
877 (let ((article-buffer (or article-buffer gnus-article-buffer))
879 (if (not (and (get-buffer article-buffer)
880 (gnus-buffer-exists-p article-buffer)))
881 (error "Can't find any article buffer")
883 (set-buffer article-buffer)
884 (let ((gnus-newsgroup-charset (or gnus-article-charset
885 gnus-newsgroup-charset))
886 (gnus-newsgroup-ignored-charsets
887 (or gnus-article-ignored-charsets
888 gnus-newsgroup-ignored-charsets)))
890 ;; Copy over the (displayed) article buffer, delete
891 ;; hidden text and remove text properties.
893 (copy-to-buffer gnus-article-copy (point-min) (point-max))
894 (set-buffer gnus-article-copy)
895 ;; There's invisible and intangible text in T-gnus. Especially,
896 ;; if there is a boundary line (X-Boundary: ------------------),
897 ;; in the end of a header, it will cause a serious problem.
898 (add-text-properties (point-min) (point-max)
899 '(invisible nil intangible nil))
902 (delete-region (point) (point-max))
903 (insert yank-string))
904 ;; Encode bitmap smileys to ordinary text.
905 ;; Possibly, the original text might be restored.
906 (static-unless (featurep 'xemacs)
907 (when (featurep 'smiley-mule)
908 (smiley-encode-buffer)))
909 (gnus-article-delete-text-of-type 'annotation)
910 (gnus-remove-text-with-property 'gnus-prev)
911 (gnus-remove-text-with-property 'gnus-next)
912 (gnus-remove-text-with-property 'gnus-decoration)
913 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
916 (static-if (featurep 'xemacs)
917 ;; Revome smiley extents for (possibly) XEmacs 21.1.
919 (buffer-substring-no-properties (point-min)
921 (buffer-substring-no-properties (point-min) (point-max)))
923 ;; Find the original headers.
924 (set-buffer gnus-original-article-buffer)
925 (goto-char (point-min))
926 (while (looking-at message-unix-mail-delimiter)
928 (let ((mail-header-separator ""))
930 end (or (message-goto-body) beg)))
931 ;; Delete the headers from the displayed articles.
932 (set-buffer gnus-article-copy)
933 (let ((mail-header-separator ""))
934 (delete-region (goto-char (point-min))
935 (or (message-goto-body) (point-max))))
936 ;; Insert the original article headers.
937 (insert-buffer-substring gnus-original-article-buffer beg end)
939 (let ((gnus-article-decode-hook
940 (delq 'article-decode-charset
941 (copy-sequence gnus-article-decode-hook))))
942 ;; Needed for T-gnus.
943 (add-hook 'gnus-article-decode-hook
944 'article-decode-encoded-words)
945 (run-hooks 'gnus-article-decode-hook)))))
948 (defun gnus-post-news (post &optional group header article-buffer yank subject
951 (gnus-copy-article-buffer))
952 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
953 (gnus-article-yanked-articles yank)
954 (add-to-list gnus-add-to-list))
955 (gnus-setup-message (cond (yank 'reply-yank)
956 (article-buffer 'reply)
958 (let* ((group (or group gnus-newsgroup-name))
959 (charset (gnus-group-name-charset nil group))
961 to-address to-group mailing-list to-list
964 (setq to-address (gnus-parameter-to-address group)
965 to-group (gnus-group-find-parameter group 'to-group)
966 to-list (gnus-parameter-to-list group)
967 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
968 mailing-list (when gnus-mailing-list-groups
969 (string-match gnus-mailing-list-groups group))
970 group (gnus-group-name-decode (gnus-group-real-name group)
972 (if (or (and to-group
973 (gnus-news-group-p to-group))
976 (and (gnus-news-group-p
977 (or pgroup gnus-newsgroup-name)
978 (or header gnus-current-article))
984 (message-news (or to-group group))
985 (set-buffer gnus-article-copy)
986 (gnus-msg-treat-broken-reply-to)
987 (message-followup (if (or newsgroup-p force-news)
988 (if (save-restriction
989 (article-narrow-to-head)
990 (message-fetch-field "newsgroups"))
997 (message-mail (or to-address to-list))
998 ;; Arrange for mail groups that have no `to-address' to
999 ;; get that when the user sends off the mail.
1000 (when (and (not to-list)
1003 (push (list 'gnus-inews-add-to-address pgroup)
1004 message-send-actions)))
1005 (set-buffer gnus-article-copy)
1006 (gnus-msg-treat-broken-reply-to)
1007 (message-wide-reply to-address)))
1009 (gnus-inews-yank-articles yank))))))
1011 (defun gnus-msg-treat-broken-reply-to (&optional force)
1012 "Remove the Reply-to header if broken-reply-to."
1014 (gnus-group-find-parameter
1015 gnus-newsgroup-name 'broken-reply-to))
1017 (message-narrow-to-head)
1018 (message-remove-header "reply-to"))))
1020 (defun gnus-post-method (arg group &optional silent)
1021 "Return the posting method based on GROUP and ARG.
1022 If SILENT, don't prompt the user."
1023 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1025 (group-method (gnus-find-method-for-group group)))
1027 ;; If the group-method is nil (which shouldn't happen) we use
1028 ;; the default method.
1029 ((null group-method)
1030 (or (and (listp gnus-post-method) ;If not current/native/nil
1031 (not (listp (car gnus-post-method))) ; and not a list of methods
1032 gnus-post-method) ;then use it.
1034 message-post-method))
1035 ;; We want the inverse of the default
1036 ((and arg (not (eq arg 0)))
1037 (if (eq gnus-post-method 'current)
1040 ;; We query the user for a post method.
1042 (and (listp gnus-post-method)
1043 (listp (car gnus-post-method))))
1045 ;; Collect all methods we know about.
1047 (when (listp gnus-post-method)
1048 (if (listp (car gnus-post-method))
1050 (list gnus-post-method)))
1051 gnus-secondary-select-methods
1052 (mapcar 'cdr gnus-server-alist)
1053 (mapcar 'car gnus-opened-servers)
1054 (list gnus-select-method)
1055 (list group-method)))
1056 method-alist post-methods method)
1057 ;; Weed out all mail methods.
1059 (setq method (gnus-server-get-method "" (pop methods)))
1060 (when (and (or (gnus-method-option-p method 'post)
1061 (gnus-method-option-p method 'post-mail))
1062 (not (member method post-methods)))
1063 (push method post-methods)))
1064 ;; Create a name-method alist.
1068 (if (equal (cadr m) "")
1069 (list (symbol-name (car m)) m)
1070 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1075 (setq gnus-last-posting-server
1077 gnus-last-posting-server)
1078 ;; Just use the last value.
1079 gnus-last-posting-server
1081 "Posting method: " method-alist nil t
1082 (cons (or gnus-last-posting-server "") 0))))
1084 ;; Override normal method.
1085 ((and (eq gnus-post-method 'current)
1086 (not (memq (car group-method) gnus-discouraged-post-methods))
1087 (gnus-get-function group-method 'request-post t))
1090 ;; Use gnus-post-method.
1091 ((listp gnus-post-method) ;A method...
1092 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1094 ;; Use the normal select method (nil or native).
1095 (t gnus-select-method))))
1098 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1100 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1101 variable `mime-edit-user-agent-value' is bound, the value will be
1102 included in the return value. If MAX-COLUMN is specified, the return
1103 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1104 whether a newline should be inserted in front of each product-token.
1105 If the value is t or `hard', it works strictly. Otherwise, if it is
1106 non-nil (e.g. `soft'), it works semi-strictly.
1108 Here is an example of how to use this function:
1110 \(add-hook 'gnus-message-setup-hook
1112 (setq message-user-agent nil)
1115 (message-narrow-to-headers)
1116 (goto-char (point-max))
1117 (insert \"User-Agent: \"
1118 (gnus-message-make-user-agent t 76 'soft)
1121 (let ((user-agent (if (and include-mime-info
1122 (boundp 'mime-edit-user-agent-value))
1123 (concat (gnus-extended-version)
1125 mime-edit-user-agent-value)
1126 (gnus-extended-version))))
1128 (unless (natnump max-column)
1129 (setq max-column 76))
1131 (set-buffer-multibyte t)
1132 (insert (mapconcat 'identity (split-string user-agent) " "))
1133 (goto-char (point-min))
1135 start agent agents width element swidth)
1136 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1137 (setq start (match-beginning 0))
1138 (if (eq (char-after start) ?\()
1142 (push (buffer-substring start (point)) agent))
1144 (push (nreverse agent) agents))
1145 (setq agent (list (match-string 1)))))
1147 (push (nreverse agent) agents))
1148 (setq agents (nreverse agents))
1149 (if (> (+ 12 (string-width (caar agents))) max-column)
1150 (setq user-agent "\n"
1155 (setq agent (car agents)
1156 agents (cdr agents))
1157 (when (and (not bol)
1158 (or (memq newline-product '(t hard))
1159 (and newline-product
1161 (string-width (mapconcat 'identity
1164 (setq user-agent (concat user-agent "\n")
1168 (setq element (car agent)
1169 swidth (string-width element)
1172 (setq user-agent (if (member user-agent '("" "\n"))
1173 (concat user-agent element)
1174 (concat user-agent " " element))
1175 width (+ width 1 swidth)
1177 (if (> (+ width 1 swidth) max-column)
1178 (setq user-agent (concat user-agent "\n " element)
1180 (setq user-agent (concat user-agent " " element)
1181 width (+ width 1 swidth)))))))))
1186 ;;; Gnus Mail Functions
1189 ;;; Mail reply commands of Gnus summary mode
1191 (defun gnus-summary-reply (&optional yank wide very-wide)
1192 "Start composing a mail reply to the current message.
1193 If prefix argument YANK is non-nil, the original article is yanked
1195 If WIDE, make a wide reply.
1196 If VERY-WIDE, make a very wide reply."
1198 (list (and current-prefix-arg
1199 (gnus-summary-work-articles 1))))
1200 ;; Allow user to require confirmation before replying by mail to the
1201 ;; author of a news article (or mail message).
1203 (not (or (gnus-news-group-p gnus-newsgroup-name)
1204 gnus-confirm-treat-mail-like-news))
1205 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1206 (string-match gnus-confirm-mail-reply-to-news
1207 gnus-newsgroup-name))
1208 ((functionp gnus-confirm-mail-reply-to-news)
1209 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1210 (t gnus-confirm-mail-reply-to-news)))
1211 (y-or-n-p "Really reply by mail to article author? "))
1213 (if (listp (car yank))
1216 (gnus-article-reply (or article (gnus-summary-article-number)))
1217 (gnus-article-yanked-articles yank)
1219 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1221 (gnus-summary-goto-subject article))
1222 (gnus-setup-message (if yank 'reply-yank 'reply)
1224 (gnus-summary-select-article)
1225 (dolist (article very-wide)
1226 (gnus-summary-select-article nil nil nil article)
1228 (set-buffer (gnus-copy-article-buffer))
1229 (gnus-msg-treat-broken-reply-to)
1231 (message-narrow-to-head)
1232 (setq headers (concat headers (buffer-string)))))))
1233 (set-buffer (gnus-copy-article-buffer))
1234 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1236 (message-narrow-to-head)
1240 (goto-char (point-max)))
1241 (message-reply nil wide)
1243 (gnus-inews-yank-articles yank))
1244 (gnus-summary-handle-replysign)))))
1246 (defun gnus-summary-handle-replysign ()
1247 "Check the various replysign variables and take action accordingly."
1248 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1249 (let (signed encrypted)
1251 (set-buffer gnus-article-buffer)
1252 (setq signed (memq 'signed gnus-article-wash-types))
1253 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1254 (cond ((and gnus-message-replyencrypt encrypted)
1255 (mml-secure-message mml-default-encrypt-method
1256 (if gnus-message-replysignencrypted
1259 ((and gnus-message-replysign signed)
1260 (mml-secure-message mml-default-sign-method 'sign))))))
1262 (defun gnus-summary-reply-with-original (n &optional wide)
1263 "Start composing a reply mail to the current message.
1264 The original article will be yanked."
1266 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1268 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1269 "Like `gnus-summary-reply' except removing reply-to field.
1270 If prefix argument YANK is non-nil, the original article is yanked
1272 If WIDE, make a wide reply.
1273 If VERY-WIDE, make a very wide reply."
1275 (list (and current-prefix-arg
1276 (gnus-summary-work-articles 1))))
1277 (let ((gnus-msg-force-broken-reply-to t))
1278 (gnus-summary-reply yank wide very-wide)))
1280 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1281 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1282 The original article will be yanked."
1284 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1286 (defun gnus-summary-wide-reply (&optional yank)
1287 "Start composing a wide reply mail to the current message.
1288 If prefix argument YANK is non-nil, the original article is yanked
1291 (list (and current-prefix-arg
1292 (gnus-summary-work-articles 1))))
1293 (gnus-summary-reply yank t))
1295 (defun gnus-summary-wide-reply-with-original (n)
1296 "Start composing a wide reply mail to the current message.
1297 The original article will be yanked."
1299 (gnus-summary-reply-with-original n t))
1301 (defun gnus-summary-very-wide-reply (&optional yank)
1302 "Start composing a very wide reply mail to the current message.
1303 If prefix argument YANK is non-nil, the original article is yanked
1306 (list (and current-prefix-arg
1307 (gnus-summary-work-articles 1))))
1308 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1310 (defun gnus-summary-very-wide-reply-with-original (n)
1311 "Start composing a very wide reply mail to the current message.
1312 The original article will be yanked."
1315 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1317 (defun gnus-summary-mail-forward (&optional full-headers post)
1318 "Forward the current message(s) to another user.
1319 If process marks exist, forward all marked messages;
1320 If FULL-HEADERS (the prefix), include full headers when forwarding.
1322 Note that this function definition for T-gnus is totally different
1323 from the original Gnus."
1325 (if (cdr (gnus-summary-work-articles nil))
1326 ;; Process marks are given.
1327 (gnus-summary-digest-mail-forward nil post)
1328 ;; No process marks.
1329 (let* ((gnus-article-reply (gnus-summary-article-number))
1330 (gnus-article-yanked-articles (list (list gnus-article-reply)))
1332 (message-included-forward-headers
1333 (if full-headers "" message-included-forward-headers)))
1334 (gnus-setup-message 'forward
1335 (gnus-summary-select-article)
1336 (setq charset default-mime-charset)
1337 (set-buffer gnus-original-article-buffer)
1338 (make-local-variable 'default-mime-charset)
1339 (setq default-mime-charset charset)
1340 (message-forward post)))))
1342 (defun gnus-summary-digest-mail-forward (&optional n post)
1343 "Digests and forwards all articles in this series.
1344 If N is a positive number, forward the N next articles.
1345 If N is a negative number, forward the N previous articles.
1346 If N is nil and any articles have been marked with the process mark,
1347 forward those articles instead.
1348 Optional POST will use news to forward instead of mail."
1350 (let ((articles (gnus-summary-work-articles n))
1351 (topics "Topics:\n")
1352 subject article frame)
1353 (when (car articles)
1354 (gnus-setup-message 'forward
1355 (gnus-summary-select-article)
1357 (setq articles (sort articles '<)
1358 subject "Digested Articles")
1359 (with-current-buffer gnus-original-article-buffer
1360 (setq subject (message-make-forward-subject))))
1362 (message-news nil subject)
1363 (message-mail nil subject))
1364 (when (and message-use-multi-frames (cdr articles))
1365 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1367 (while (setq article (pop articles))
1368 (save-window-excursion
1369 (set-buffer gnus-summary-buffer)
1370 (gnus-summary-select-article nil nil nil article)
1371 (setq topics (concat topics " "
1372 (mail-header-subject gnus-current-headers)
1374 (gnus-summary-remove-process-mark article))
1376 (select-frame frame))
1377 (insert (mime-make-tag "message" "rfc822") "\n")
1378 (narrow-to-region (point) (point))
1379 (insert-buffer-substring gnus-original-article-buffer)
1381 (article-narrow-to-head)
1382 (message-remove-header message-included-forward-headers t nil t))
1383 (goto-char (point-max))
1389 (mime-edit-enclose-digest-region (point)(mark t))))))
1391 (defun gnus-summary-digest-post-forward (&optional n)
1392 "Digest and forwards all articles in this series to a newsgroup.
1393 If N is a positive number, forward the N next articles.
1394 If N is a negative number, forward the N previous articles.
1395 If N is nil and any articles have been marked with the process mark,
1396 forward those articles instead."
1398 (gnus-summary-digest-mail-forward n t))
1400 (defun gnus-summary-resend-message (address n)
1401 "Resend the current article to ADDRESS."
1403 (list (message-read-from-minibuffer
1404 "Resend message(s) to: "
1405 (when (and gnus-summary-resend-default-address
1406 (gnus-buffer-live-p gnus-original-article-buffer))
1407 ;; If some other article is currently selected, the
1408 ;; initial-contents is wrong. Whatever, it is just the
1409 ;; initial-contents.
1410 (with-current-buffer gnus-original-article-buffer
1411 (nnmail-fetch-field "to"))))
1412 current-prefix-arg))
1413 (let ((articles (gnus-summary-work-articles n))
1415 (while (setq article (pop articles))
1416 (gnus-summary-select-article nil nil nil article)
1418 (set-buffer gnus-original-article-buffer)
1419 (message-resend address))
1420 (gnus-summary-mark-article-as-forwarded article))))
1422 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1423 (defun gnus-summary-resend-message-edit ()
1424 "Resend an article that has already been sent.
1425 A new buffer will be created to allow the user to modify body and
1426 contents of the message, and then, everything will happen as when
1427 composing a new message."
1429 (let ((article (gnus-summary-article-number)))
1430 (gnus-setup-message 'reply-yank
1431 (gnus-summary-select-article t)
1432 (set-buffer gnus-original-article-buffer)
1433 (let ((cur (current-buffer))
1434 (to (message-fetch-field "to")))
1435 ;; Get a normal message buffer.
1436 (message-pop-to-buffer (message-buffer-name "Resend" to))
1437 (insert-buffer-substring cur)
1439 ;; T-gnus change: Use MIME-Edit to recompose a message.
1441 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1442 (fset 'mime-edit-decode-single-part-in-buffer
1443 (lambda (&rest args)
1444 (if (let ((content-type (car args)))
1445 (and (eq 'message (mime-content-type-primary-type
1447 (eq 'rfc822 (mime-content-type-subtype
1449 (setcar (cdr args) 'not-decode-text))
1452 (mime-edit-again nil t)
1453 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1454 (message-narrow-to-head-1)
1455 (insert "From: " (message-make-from) "\n")
1456 (while (re-search-forward "^From:" nil t)
1458 (insert "Original-"))
1459 (message-remove-header "^>From[\t ]" t)
1461 ;; Gnus will generate a new one when sending.
1462 (message-remove-header "Message-ID")
1463 (message-remove-header message-ignored-resent-headers t)
1464 ;; Remove unwanted headers.
1465 (goto-char (point-max))
1466 (insert mail-header-separator)
1467 (goto-char (point-min))
1468 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1472 (defun gnus-summary-post-forward (&optional full-headers)
1473 "Forward the current article to a newsgroup.
1474 If FULL-HEADERS (the prefix), include full headers when forwarding."
1476 (gnus-summary-mail-forward full-headers t))
1478 (defvar gnus-nastygram-message
1479 "The following article was inappropriately posted to %s.\n\n"
1480 "Format string to insert in nastygrams.
1481 The current group name will be inserted at \"%s\".")
1483 (defun gnus-summary-mail-nastygram (n)
1484 "Send a nastygram to the author of the current article."
1486 (when (or gnus-expert-user
1488 "Really send a nastygram to the author of the current article? "))
1489 (let ((group gnus-newsgroup-name))
1490 (gnus-summary-reply-with-original n)
1491 (set-buffer gnus-message-buffer)
1493 (insert (format gnus-nastygram-message group))
1494 (message-send-and-exit))))
1496 (defun gnus-summary-mail-crosspost-complaint (n)
1497 "Send a complaint about crossposting to the current article(s)."
1499 (let ((articles (gnus-summary-work-articles n))
1501 (while (setq article (pop articles))
1502 (set-buffer gnus-summary-buffer)
1503 (gnus-summary-goto-subject article)
1504 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1505 newsgroups followup-to)
1506 (gnus-summary-select-article)
1507 (set-buffer gnus-original-article-buffer)
1508 (if (and (<= (length (message-tokenize-header
1510 (mail-fetch-field "newsgroups"))
1513 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1514 (not (member group (message-tokenize-header
1515 followup-to ", ")))))
1517 (gnus-message 1 "Followup-to restricted")
1518 (gnus-message 1 "Not a crossposted article"))
1519 (set-buffer gnus-summary-buffer)
1520 (gnus-summary-reply-with-original 1)
1521 (set-buffer gnus-message-buffer)
1523 (insert (format gnus-crosspost-complaint newsgroups group))
1524 (message-goto-subject)
1525 (re-search-forward " *$")
1526 (replace-match " (crosspost notification)" t t)
1527 (gnus-deactivate-mark)
1528 (when (gnus-y-or-n-p "Send this complaint? ")
1529 (message-send-and-exit)))))))
1531 (defun gnus-mail-parse-comma-list ()
1534 (skip-chars-forward " ")
1537 (skip-chars-forward "^,")
1542 (narrow-to-region beg (point))
1545 (while (search-forward "\"" nil t)
1549 (skip-chars-forward ",")
1550 (skip-chars-forward "^,"))
1551 (skip-chars-backward " ")
1552 (push (buffer-substring beg (point))
1554 (skip-chars-forward "^,")
1555 (skip-chars-forward ", "))
1558 (defun gnus-inews-add-to-address (group)
1559 (let ((to-address (mail-fetch-field "to")))
1560 (when (and to-address
1562 ;; This mail group doesn't have a `to-list', so we add one
1564 (when (gnus-y-or-n-p
1565 (format "Do you want to add this as `to-list': %s " to-address))
1566 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1568 (defun gnus-put-message ()
1569 "Put the current message in some group and return to Gnus."
1571 (let ((reply gnus-article-reply)
1572 (winconf gnus-prev-winconf)
1573 (group gnus-newsgroup-name))
1575 (not (gnus-group-read-only-p group)))
1576 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1578 (when (gnus-gethash group gnus-newsrc-hashtb)
1579 (error "No such group: %s" group))
1583 (message-narrow-to-headers)
1584 (let ((gnus-deletable-headers nil))
1585 (message-generate-headers
1586 (if (message-news-p)
1587 message-required-news-headers
1588 message-required-mail-headers)))
1589 (goto-char (point-max))
1590 (if (string-match " " group)
1591 (insert "Gcc: \"" group "\"\n")
1592 (insert "Gcc: " group "\n"))
1595 (when (and (get-buffer gnus-group-buffer)
1596 (gnus-buffer-exists-p (car-safe reply))
1598 (set-buffer (car reply))
1599 (gnus-summary-mark-article-as-replied (cdr reply)))
1601 (set-window-configuration winconf))))
1603 (defun gnus-article-mail (yank)
1604 "Send a reply to the address near point.
1605 If YANK is non-nil, include the original article."
1609 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1610 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1612 (gnus-msg-mail address)
1614 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1616 (defvar nntp-server-type)
1618 "Send a bug report to the Gnus maintainers."
1620 (unless (gnus-alive-p)
1621 (error "Gnus has been shut down"))
1622 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1623 (unless (message-mail-user-agent)
1624 (message-pop-to-buffer "*Gnus Bug*")
1625 (delete-other-windows)
1626 (when gnus-bug-create-help-buffer
1627 (switch-to-buffer "*Gnus Help Bug*")
1629 (insert gnus-bug-message)
1630 (goto-char (point-min))
1632 (set-buffer "*Gnus Bug*")))
1633 (let ((message-this-is-mail t))
1634 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1635 (when gnus-bug-create-help-buffer
1636 (push `(gnus-bug-kill-buffer) message-send-actions))
1637 (goto-char (point-min))
1638 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1640 (insert gnus-product-name " " gnus-version-number
1641 " (r" gnus-revision-number ") "
1642 "based on " gnus-original-product-name " v"
1643 gnus-original-version-number "\n"
1644 (emacs-version) "\n")
1645 (when (and (boundp 'nntp-server-type)
1646 (stringp nntp-server-type))
1647 (insert nntp-server-type))
1648 (insert "\n\n\n\n\n")
1649 (let (mime-content-types)
1650 (mime-edit-insert-tag
1651 "application" "emacs-lisp"
1652 "\nContent-Disposition: inline\nContent-Description: User settings"))
1653 (insert (with-temp-buffer
1656 (let (mime-content-types)
1657 (mime-edit-insert-tag "text" "plain"))
1658 (goto-char (point-min))
1659 (search-forward "Subject: " nil t)
1662 (defun gnus-bug-kill-buffer ()
1663 (when (get-buffer "*Gnus Help Bug*")
1664 (kill-buffer "*Gnus Help Bug*")))
1666 (defun gnus-summary-yank-message (buffer n)
1667 "Yank the current article into a composed message."
1669 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1670 current-prefix-arg))
1671 (when (gnus-buffer-live-p buffer)
1672 (let ((summary-frame (selected-frame))
1673 (message-frame (when (static-if (featurep 'xemacs)
1674 (device-on-window-system-p)
1676 (let ((window (get-buffer-window buffer t)))
1678 (window-frame window)))))
1679 (separator (concat "^" (regexp-quote mail-header-separator)
1681 (gnus-summary-iterate n
1682 (gnus-summary-select-article)
1683 (gnus-copy-article-buffer)
1684 (when (frame-live-p message-frame)
1685 (raise-frame message-frame)
1686 (select-frame message-frame))
1687 (with-current-buffer buffer
1688 (when (save-excursion
1690 (let (case-fold-search)
1691 (and (not (re-search-backward separator nil t))
1692 (re-search-forward separator nil t))))
1693 (goto-char (match-end 0)))
1694 (message-yank-buffer gnus-article-copy))
1695 (select-frame summary-frame))
1696 (when (frame-live-p message-frame)
1697 (select-frame message-frame)))))
1699 (defun gnus-debug ()
1700 "Attempts to go through the Gnus source file and report what variables have been changed.
1701 The source file has to be in the Emacs load path."
1703 (let ((files gnus-debug-files)
1705 file expr olist sym)
1706 (gnus-message 4 "Please wait while we snoop your variables...")
1707 ;; Go through all the files looking for non-default values for variables.
1710 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1713 (when (and (setq file (locate-library (pop files)))
1714 (file-exists-p file))
1715 (insert-file-contents file)
1716 (goto-char (point-min))
1717 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1718 (gnus-message 4 "Malformed sources in file %s" file)
1719 (narrow-to-region (point-min) (point))
1720 (goto-char (point-min))
1721 (while (setq expr (ignore-errors (read (current-buffer))))
1723 (and (memq (car expr) '(defvar defcustom defvoo))
1724 (stringp (nth 3 expr))
1725 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1726 (or (not (boundp (nth 1 expr)))
1727 (not (equal (eval (nth 2 expr))
1728 (symbol-value (nth 1 expr)))))
1729 (push (nth 1 expr) olist)))))))
1730 (kill-buffer (current-buffer)))
1731 (when (setq olist (nreverse olist))
1732 (insert ";----------------- Environment follows ------------------\n\n"))
1734 (if (boundp (car olist))
1736 (pp `(setq ,(car olist)
1737 ,(if (or (consp (setq sym (symbol-value (car olist))))
1739 (not (or (eq sym nil)
1741 (list 'quote (symbol-value (car olist)))
1742 (symbol-value (car olist))))
1744 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1745 (setq olist (cdr olist)))
1746 ;; Remove any control chars - they seem to cause trouble for some
1747 ;; mailers. (Byte-compiled output from the stuff above.)
1749 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1750 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1752 ;; Break MIME tags purposely.
1754 (while (re-search-forward mime-edit-tag-regexp nil t)
1755 (goto-char (1+ (match-beginning 0)))
1758 ;;; Treatment of rejected articles.
1761 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1762 "Re-mail the current message.
1763 This only makes sense if the current message is a bounce message than
1764 contains some mail you have written which has been bounced back to
1766 If FETCH, try to fetch the article that this is a reply to, if indeed
1769 (gnus-summary-select-article t)
1770 (set-buffer gnus-original-article-buffer)
1771 (gnus-setup-message 'compose-bounce
1772 (let* ((references (mail-fetch-field "references"))
1773 (parent (and references (gnus-parent-id references))))
1775 ;; If there are references, we fetch the article we answered to.
1777 (gnus-summary-refer-article parent)
1778 (gnus-summary-show-all-headers)))))
1782 (defun gnus-inews-group-method (group)
1784 ;; If the group doesn't exist, we assume
1785 ;; it's an archive group...
1786 ((and (null (gnus-get-info group))
1787 (eq (car (gnus-server-to-method gnus-message-archive-method))
1788 (car (gnus-server-to-method (gnus-group-method group)))))
1789 gnus-message-archive-method)
1791 ((gnus-info-method (gnus-get-info group))
1792 (gnus-info-method (gnus-get-info group)))
1794 (t (gnus-server-to-method (gnus-group-method group)))))
1796 ;; Do Gcc handling, which copied the message over to some group.
1797 (defun gnus-inews-do-gcc (&optional gcc)
1801 (message-narrow-to-headers)
1802 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1803 (coding-system-for-write 'raw-text)
1804 (output-coding-system 'raw-text)
1805 groups group method group-art
1806 mml-externalize-attachments)
1808 (message-remove-header "gcc")
1810 (setq groups (message-unquote-tokens
1811 (message-tokenize-header gcc " ,")))
1812 ;; Copy the article over to some group(s).
1813 (while (setq group (pop groups))
1814 (unless (gnus-check-server
1815 (setq method (gnus-inews-group-method group)))
1816 (error "Can't open server %s" (if (stringp method) method
1818 (unless (gnus-request-group group nil method)
1819 (gnus-request-create-group group method))
1820 (setq mml-externalize-attachments
1821 (if (stringp gnus-gcc-externalize-attachments)
1822 (string-match gnus-gcc-externalize-attachments group)
1823 gnus-gcc-externalize-attachments))
1825 (nnheader-set-temp-buffer " *acc*")
1826 (insert-buffer-substring message-encoding-buffer)
1827 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1828 (goto-char (point-min))
1829 (when (re-search-forward
1830 (concat "^" (regexp-quote mail-header-separator) "$")
1832 (replace-match "" t t ))
1833 (unless (setq group-art
1834 (gnus-request-accept-article group method t t))
1835 (gnus-message 1 "Couldn't store article in group %s: %s"
1836 group (gnus-status-message method))
1838 (when (and group-art
1840 (or gnus-gcc-mark-as-read
1841 gnus-inews-mark-gcc-as-read))
1842 (gnus-group-mark-article-read group (cdr group-art)))
1843 (kill-buffer (current-buffer)))))))))
1845 (defun gnus-inews-insert-gcc ()
1846 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1849 (message-narrow-to-headers)
1850 (let* ((group gnus-outgoing-message-group)
1852 ((gnus-functionp group)
1854 ((or (stringp group) (list group))
1859 (if (string-match " " gcc)
1860 (concat "\"" gcc "\"")
1862 (mapconcat (lambda (group)
1863 (if (string-match " " group)
1864 (concat "\"" group "\"")
1869 (defun gnus-inews-insert-archive-gcc (&optional group)
1870 "Insert the Gcc to say where the article is to be archived."
1871 (let* ((var gnus-message-archive-group)
1872 (group (or group gnus-newsgroup-name ""))
1874 (and gnus-newsgroup-name
1875 (not (equal gnus-newsgroup-name ""))
1876 (gnus-group-find-parameter
1877 gnus-newsgroup-name 'gcc-self)))
1881 ((null gnus-message-archive-method)
1885 ;; Just a single group.
1888 ;; We don't want this.
1890 ((and (listp var) (stringp (car var)))
1891 ;; A list of groups.
1893 ((gnus-functionp var)
1895 (funcall var group))
1897 ;; An alist of regexps/functions/forms.
1902 ((stringp (caar var))
1904 (when (string-match (caar var) group)
1906 ((gnus-functionp (car var))
1908 (funcall (car var) group))
1910 (eval (car var)))))))
1911 (setq var (cdr var)))
1914 (when (or groups gcc-self-val)
1915 (when (stringp groups)
1916 (setq groups (list groups)))
1919 (message-narrow-to-headers)
1920 (goto-char (point-max))
1923 ;; Use the `gcc-self' param value instead.
1926 (if (stringp gcc-self-val)
1927 (if (string-match " " gcc-self-val)
1928 (concat "\"" gcc-self-val "\"")
1930 (if (string-match " " group)
1931 (concat "\"" group "\"")
1933 (if (not (eq gcc-self-val 'none))
1938 ;; Use the list of groups.
1939 (while (setq name (pop groups))
1940 (let ((str (if (string-match ":" name)
1942 (gnus-group-prefixed-name
1943 name gnus-message-archive-method))))
1944 (insert (if (string-match " " str)
1945 (concat "\"" str "\"")
1953 (defun gnus-configure-posting-styles (&optional group-name)
1954 "Configure posting styles according to `gnus-posting-styles'."
1955 (unless gnus-inhibit-posting-styles
1956 (let ((group (or group-name gnus-newsgroup-name ""))
1957 (styles gnus-posting-styles)
1958 style match attribute results
1960 ;; If the group has a posting-style parameter, add it at the end with a
1961 ;; regexp matching everything, to be sure it takes precedence over all
1963 (when gnus-newsgroup-name
1964 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1966 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1967 ;; Go through all styles and look for matches.
1968 (dolist (style styles)
1969 (setq match (pop style))
1970 (goto-char (point-min))
1973 ;; Regexp string match on the group name.
1974 (string-match match group))
1976 ;; Obsolete format of header match.
1977 (and (gnus-buffer-live-p gnus-article-copy)
1978 (with-current-buffer gnus-article-copy
1979 (let ((header (message-fetch-field (pop style))))
1981 (string-match (pop style) header))))))
1982 ((or (symbolp match)
1983 (gnus-functionp match))
1985 ((gnus-functionp match)
1986 ;; Function to be called.
1989 ;; Variable to be checked.
1990 (symbol-value match))))
1993 ((eq (car match) 'header)
1994 ;; New format of header match.
1995 (and (gnus-buffer-live-p gnus-article-copy)
1996 (with-current-buffer gnus-article-copy
1997 (let ((header (message-fetch-field (nth 1 match))))
1999 (string-match (nth 2 match) header))))))
2001 ;; This is a form to be evaled.
2003 ;; We have a match, so we set the variables.
2004 (setq style (gnus-configure-posting-style style nil))
2005 (dolist (attribute style)
2006 (setq results (delq (assoc (car attribute) results) results))
2007 (push attribute results))))
2008 ;; Now we have all the styles, so we insert them.
2009 (setq name (assq 'name results)
2010 address (assq 'address results))
2011 (setq results (delq name (delq address results)))
2012 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2013 (make-local-hook 'message-setup-hook)
2014 (setq results (sort results (lambda (x y)
2015 (string-lessp (car x) (car y)))))
2016 (dolist (result results)
2017 (add-hook 'message-setup-hook
2019 ((eq 'eval (car result))
2021 ((eq 'body (car result))
2025 (insert ,(cdr result)))))
2026 ((eq 'signature (car result))
2027 (set (make-local-variable 'message-signature) nil)
2028 (set (make-local-variable 'message-signature-file) nil)
2029 (if (not (cdr result))
2033 (let ((message-signature ,(cdr result)))
2034 (when message-signature
2035 (message-insert-signature)))))))
2038 (if (symbolp (car result))
2039 (capitalize (symbol-name (car result)))
2043 (message-remove-header ,header)
2044 (let ((value ,(cdr result)))
2047 (insert ,header ": " value)
2049 (insert "\n")))))))))
2051 (when (or name address)
2052 (add-hook 'message-setup-hook
2054 (set (make-local-variable 'user-mail-address)
2055 ,(or (cdr address) user-mail-address))
2056 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2058 ,(or (cdr address) user-mail-address)))
2060 (message-remove-header "From")
2062 (insert "From: " (message-make-from) "\n"))))
2065 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2066 (defun gnus-configure-posting-style (style stack)
2067 "Parse one posting style STYLE and returns the value as an alist."
2068 (let (results element variable filep value v)
2069 (dolist (attribute style)
2070 (setq element (pop attribute)
2075 ((eq (car attribute) ':file)
2078 ((eq (car attribute) :value)
2082 ;; We get the value.
2087 ((or (symbolp value)
2088 (gnus-functionp value))
2089 (cond ((gnus-functionp value)
2092 (symbol-value value))))
2095 ;; Translate obsolescent value.
2097 ((eq element 'signature-file)
2098 (setq element 'signature
2100 ((eq element 'x-face-file)
2101 (setq element 'x-face
2103 ;; Get the contents of file elems.
2105 (setq v (with-temp-buffer
2106 (insert-file-contents v)
2107 (goto-char (point-max))
2111 (if (eq element 'import)
2113 (if (member v stack)
2114 (error "Circular import of \"%s\"" v))
2116 (nconc (nreverse (gnus-configure-posting-style
2117 (cdr (assoc v gnus-named-posting-styles))
2120 (push (cons element v) results)))
2121 (nreverse results)))
2123 (defun gnus-summary-execute-command-with-posting-style (style command)
2124 "Temporarily select a posting-style named STYLE and execute COMMAND."
2126 (let ((style (completing-read "Posting style: "
2127 gnus-named-posting-styles nil t)))
2131 (format "Command to execute with %s: " style))))))
2132 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2133 (call-interactively command)))
2136 ;;; @ for MIME Edit mode
2139 (defun gnus-maybe-setup-default-charset ()
2141 (and (boundp 'gnus-summary-buffer)
2142 (buffer-live-p gnus-summary-buffer)
2144 (set-buffer gnus-summary-buffer)
2145 default-mime-charset))))
2148 (make-local-variable 'default-mime-charset)
2149 (setq default-mime-charset charset)
2153 ;;; @ for MIME view mode
2156 (defun gnus-following-method (buf)
2157 (gnus-setup-message 'reply-yank
2159 (if (message-news-p)
2161 (message-reply nil 'wide))
2162 (let ((message-reply-buffer buf))
2163 (message-yank-original))
2164 (message-goto-body))
2168 ;;; Allow redefinition of functions.
2174 ;;; gnus-msg.el ends here