1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
42 (defcustom gnus-post-method 'current
43 "*Preferred method for posting USENET news.
45 If this variable is `current' (which is the default), Gnus will use
46 the \"current\" select method when posting. If it is `native', Gnus
47 will use the native select method when posting.
49 This method will not be used in mail groups and the like, only in
52 If not `native' nor `current', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'. It can also be a list of
54 methods. If that is the case, the user will be queried for what select
55 method to use when posting."
56 :group 'gnus-group-foreign
57 :link '(custom-manual "(gnus)Posting Server")
58 :type `(choice (const native)
60 (sexp :tag "Methods" ,gnus-select-method)))
62 (defcustom gnus-outgoing-message-group nil
63 "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value. This variable
66 can also be a list of group names.
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
73 :type '(choice (string :tag "Group")
76 (defcustom gnus-mailing-list-groups nil
77 "*Regexp matching groups that are really mailing lists.
78 This is useful when you're reading a mailing list that has been
79 gatewayed to a newsgroup, and you want to followup to an article in
84 (defcustom gnus-add-to-list nil
85 "*If non-nil, add a `to-list' parameter automatically."
89 (defcustom gnus-crosspost-complaint
92 You posted the article below with the following Newsgroups header:
96 The %s group, at least, was an inappropriate recipient
97 of this message. Please trim your Newsgroups header to exclude this
98 group before posting in the future.
103 "Format string to be inserted when complaining about crossposts.
104 The first %s will be replaced by the Newsgroups header;
105 the second with the current group name."
109 (defcustom gnus-message-setup-hook nil
110 "Hook run after setting up a message buffer."
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :link '(custom-manual "(gnus)Posting Styles")
124 :type '(repeat (cons (choice (regexp)
127 (string :tag "Header")
128 (regexp :tag "Regexp"))
132 (choice (const signature)
133 (const signature-file)
141 (string :tag "Header"))
147 (defcustom gnus-named-posting-styles nil
148 "Alist mapping names to the user-defined posting styles."
150 :type '(repeat (cons string
152 (choice (const signature)
153 (const signature-file)
161 (string :tag "Header"))
167 (defcustom gnus-gcc-mark-as-read nil
168 "If non-nil, automatically mark Gcc articles as read."
173 (defvar gnus-inews-mark-gcc-as-read nil
174 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
176 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
177 'gnus-gcc-mark-as-read)
179 (defcustom gnus-gcc-externalize-attachments nil
180 "Should local-file attachments be included as external parts in Gcc copies?
181 If it is `all', attach files as external parts;
182 if a regexp and matches the Gcc group name, attach files as external parts;
183 if nil, attach files as normal parts."
186 :type '(choice (const nil :tag "None")
187 (const all :tag "Any")
188 (string :tag "Regexp")))
190 (gnus-define-group-parameter
191 posting-charset-alist
194 "Return the permitted unencoded charsets for posting of GROUP."
195 :variable gnus-group-posting-charset-alist
197 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
198 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
199 (message-this-is-mail nil nil)
200 (message-this-is-news nil t))
202 "Alist of regexps and permitted unencoded charsets for posting.
203 Each element of the alist has the form (TEST HEADER BODY-LIST), where
204 TEST is either a regular expression matching the newsgroup header or a
206 HEADER is the charset which may be left unencoded in the header (nil
207 means encode all charsets),
208 BODY-LIST is a list of charsets which may be encoded using 8bit
209 content-transfer encoding in the body, or one of the special values
210 nil (always encode using quoted-printable) or t (always use 8bit).
212 Note that any value other than nil for HEADER infringes some RFCs, so
213 use this option with care."
214 :variable-group gnus-charset
216 '(repeat (list :tag "Permitted unencoded charsets"
218 (regexp :tag "Group")
219 (const :tag "Mail message" :value message-this-is-mail)
220 (const :tag "News article" :value message-this-is-news))
221 (choice :tag "Header"
222 (const :tag "None" nil)
223 (symbol :tag "Charset"))
225 (const :tag "Any" :value t)
226 (const :tag "None" :value nil)
227 (repeat :tag "Charsets"
228 (symbol :tag "Charset")))))
229 :parameter-type '(choice :tag "Permitted unencoded charsets"
232 :parameter-document "\
233 List of charsets that are permitted to be unencoded.")
235 (defcustom gnus-debug-files
236 '("gnus.el" "gnus-sum.el" "gnus-group.el"
237 "gnus-art.el" "gnus-start.el" "gnus-async.el"
238 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
239 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
240 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
241 "Files whose variables will be reported in `gnus-bug'."
244 :type '(repeat (string :tag "File")))
246 (defcustom gnus-debug-exclude-variables
247 '(mm-mime-mule-charset-alist
248 nnmail-split-fancy message-minibuffer-local-map)
249 "Variables that should not be reported in `gnus-bug'."
252 :type '(repeat (symbol :tag "Variable")))
254 (defcustom gnus-discouraged-post-methods
255 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
256 "A list of back ends that are not used in \"real\" newsgroups.
257 This variable is used only when `gnus-post-method' is `current'."
259 :group 'gnus-group-foreign
260 :type '(repeat (symbol :tag "Back end")))
262 (defcustom gnus-message-replysign
264 "Automatically sign replies to signed messages.
265 See also the `mml-default-sign-method' variable."
269 (defcustom gnus-message-replyencrypt
271 "Automatically encrypt replies to encrypted messages.
272 See also the `mml-default-encrypt-method' variable."
276 (defcustom gnus-message-replysignencrypted
278 "Setting this causes automatically encryped messages to also be signed."
282 (defcustom gnus-confirm-mail-reply-to-news nil
283 "If non-nil, Gnus requests confirmation when replying to news.
284 This is done because new users often reply by mistake when reading
286 This can also be a function receiving the group name as the only
287 parameter which should return non-nil iff a confirmation is needed, or
288 a regexp, in which case a confirmation is asked for iff the group name
291 :type '(choice (const :tag "No" nil)
293 (regexp :tag "Iff group matches regexp")
294 (function :tag "Iff function evaluates to non-nil")))
296 (defcustom gnus-confirm-treat-mail-like-news
298 "If non-nil, Gnus will treat mail like news with regard to confirmation
299 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
300 for fine-tuning this.
301 If nil, Gnus will never ask for confirmation if replying to mail."
305 (defcustom gnus-summary-resend-default-address t
306 "If non-nil, Gnus tries to suggest a default address to resend to.
307 If nil, the address field will always be empty after invoking
308 `gnus-summary-resend-message'."
312 (defcustom gnus-user-agent 'full
313 "Which information should be exposed in the User-Agent header.
315 It can be one of the symbols `full' \(show full information, i.e. Emacs and
316 Gnus version and system configuration\), `emacs-gnus' \(show only Emacs and
317 Gnus version\), `emacs-gnus-type' \(same as `emacs-gnus' plus system type\),
318 `gnus' \(show only Gnus version\) or a custom string. If you set it to a
319 string, be sure to use a valid format, see RFC 2616."
321 :type '(choice (item :tag "Show full info" full)
322 (item :tag "Show Gnus and Emacs versions and system type"
324 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
325 (item :tag "Show only Gnus version" gnus)
326 (string :tag "Other")))
328 ;;; Internal variables.
330 (defvar gnus-inhibit-posting-styles nil
331 "Inhibit the use of posting styles.")
333 (defvar gnus-article-yanked-articles nil)
334 (defvar gnus-message-buffer "*Mail Gnus*")
335 (defvar gnus-article-copy nil)
336 (defvar gnus-check-before-posting nil)
337 (defvar gnus-last-posting-server nil)
338 (defvar gnus-message-group-art nil)
340 (defvar gnus-msg-force-broken-reply-to nil)
342 (defconst gnus-bug-message
343 (format "Sending a bug report to the Gnus Towers.
344 ========================================
346 This gnus is the %s%s.
347 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
348 Developers. (the addresses below are mailing list addresses)
350 ========================================
352 The buffer below is a mail buffer. When you press `C-c C-c', it will
353 be sent to the Gnus Bug Exterminators.
355 The thing near the bottom of the buffer is how the environment
356 settings will be included in the mail. Please do not delete that.
357 They will tell the Bug People what your environment is, so that it
358 will be easier to locate the bugs.
360 If you have found a bug that makes Emacs go \"beep\", set
361 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
362 and include the backtrace in your bug report.
364 Please describe the bug in annoying, painstaking detail.
366 Thank you for your help in stamping out bugs.
369 (if (string= gnus-product-name "Semi-gnus")
371 ", a modified version of Semi-gnus")))
374 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
375 (autoload 'news-setup "rnewspost")
376 (autoload 'news-reply-mode "rnewspost")
377 (autoload 'rmail-dont-reply-to "mail-utils")
378 (autoload 'rmail-output "rmailout"))
382 ;;; Gnus Posting Functions
385 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
386 "p" gnus-summary-post-news
387 "i" gnus-summary-news-other-window
388 "f" gnus-summary-followup
389 "F" gnus-summary-followup-with-original
390 "c" gnus-summary-cancel-article
391 "s" gnus-summary-supersede-article
392 "r" gnus-summary-reply
393 "y" gnus-summary-yank-message
394 "R" gnus-summary-reply-with-original
395 "w" gnus-summary-wide-reply
396 "W" gnus-summary-wide-reply-with-original
397 "v" gnus-summary-very-wide-reply
398 "V" gnus-summary-very-wide-reply-with-original
399 "n" gnus-summary-followup-to-mail
400 "N" gnus-summary-followup-to-mail-with-original
401 "m" gnus-summary-mail-other-window
402 "u" gnus-uu-post-news
403 "\M-c" gnus-summary-mail-crosspost-complaint
404 "Br" gnus-summary-reply-broken-reply-to
405 "BR" gnus-summary-reply-broken-reply-to-with-original
406 "om" gnus-summary-mail-forward
407 "op" gnus-summary-post-forward
408 "Om" gnus-summary-digest-mail-forward
409 "Op" gnus-summary-digest-post-forward
410 "P" gnus-summary-execute-command-with-posting-style)
412 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
413 "b" gnus-summary-resend-bounced-mail
414 ;; "c" gnus-summary-send-draft
415 "r" gnus-summary-resend-message
416 "e" gnus-summary-resend-message-edit)
418 ;;; Internal functions.
420 (defun gnus-inews-make-draft ()
422 (gnus-inews-make-draft-meta-information
423 ,gnus-newsgroup-name ',gnus-article-reply)))
425 (defvar gnus-article-reply nil)
426 (defmacro gnus-setup-message (config &rest forms)
427 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
428 (buffer (make-symbol "gnus-setup-message-buffer"))
429 (article (make-symbol "gnus-setup-message-article"))
430 (yanked (make-symbol "gnus-setup-yanked-articles"))
431 (group (make-symbol "gnus-setup-message-group")))
432 `(let ((,winconf (current-window-configuration))
433 (,buffer (buffer-name (current-buffer)))
434 (,article gnus-article-reply)
435 (,yanked gnus-article-yanked-articles)
436 (,group gnus-newsgroup-name)
437 (message-header-setup-hook
438 (copy-sequence message-header-setup-hook))
439 (message-mode-hook (copy-sequence message-mode-hook))
440 (message-startup-parameter-alist
441 '((reply-buffer . gnus-copy-article-buffer)
442 (original-buffer . gnus-original-article-buffer)
443 (user-agent . Gnus))))
444 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
445 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
446 ;; #### FIXME: for a reason that I did not manage to identify yet,
447 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
448 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
449 ;; After evaluation of @forms below, it gets the value we actually want
450 ;; to override, and the posting styles are used. For that reason, I've
451 ;; added an optional argument to `gnus-configure-posting-styles' to
452 ;; make sure that the correct value for the group name is used. -- drv
453 (add-hook 'message-mode-hook
455 (gnus-configure-posting-styles ,group)))
456 (gnus-pull ',(intern gnus-draft-meta-information-header)
457 message-required-headers)
459 (not (string= ,group "")))
461 (intern gnus-draft-meta-information-header)
462 (gnus-inews-make-draft))
463 message-required-headers))
467 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
469 (setq gnus-message-buffer (current-buffer))
470 (set (make-local-variable 'gnus-message-group-art)
471 (cons ,group ,article))
472 (set (make-local-variable 'gnus-newsgroup-name) ,group)
473 (gnus-maybe-setup-default-charset)
474 (gnus-run-hooks 'gnus-message-setup-hook))
476 (gnus-configure-windows ,config t)
477 (run-hooks 'post-command-hook)
478 (set-buffer-modified-p nil))))
480 (defun gnus-inews-make-draft-meta-information (group article)
481 (concat "(\"" group "\" "
482 (if article (number-to-string
489 (defun gnus-msg-mail (&optional to subject other-headers continue
490 switch-action yank-action send-actions)
491 "Start editing a mail message to be sent.
492 Like `message-mail', but with Gnus paraphernalia, particularly the
493 Gcc: header for archiving purposes."
495 (let ((buf (current-buffer))
497 (gnus-setup-message 'message
498 (message-mail to subject other-headers continue
499 nil yank-action send-actions))
501 (setq mail-buf (current-buffer))
502 (switch-to-buffer buf)
503 (apply switch-action mail-buf nil)))
504 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
507 (defvar save-selected-window-window)
510 (defun gnus-button-mailto (address)
512 (set-buffer (gnus-copy-article-buffer))
513 (gnus-setup-message 'message
514 (message-reply address))
515 (and (boundp 'save-selected-window-window)
516 (not (window-live-p save-selected-window-window))
517 (setq save-selected-window-window (selected-window))))
520 (defun gnus-button-reply (&optional to-address wide)
521 "Like `message-reply'."
523 (gnus-setup-message 'message
524 (message-reply to-address wide))
525 (and (boundp 'save-selected-window-window)
526 (not (window-live-p save-selected-window-window))
527 (setq save-selected-window-window (selected-window))))
530 (define-mail-user-agent 'gnus-user-agent
531 'gnus-msg-mail 'message-send-and-exit
532 'message-kill-buffer 'message-send-hook)
534 (defun gnus-setup-posting-charset (group)
535 (let ((alist gnus-group-posting-charset-alist)
536 (group (or group ""))
540 (while (setq elem (pop alist))
541 (when (or (and (stringp (car elem))
542 (string-match (car elem) group))
543 (and (gnus-functionp (car elem))
544 (funcall (car elem) group))
545 (and (symbolp (car elem))
546 (symbol-value (car elem))))
547 (throw 'found (cons (cadr elem) (caddr elem)))))))))
549 (defun gnus-inews-add-send-actions (winconf buffer article
550 &optional config yanked)
551 (make-local-hook 'message-sent-hook)
552 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
553 'gnus-inews-do-gcc) nil t)
555 (make-local-hook 'message-header-hook)
556 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
557 (setq message-post-method
559 (gnus-post-method arg ,gnus-newsgroup-name)))
560 (setq message-user-agent (gnus-extended-version))
561 (when (not message-use-multi-frames)
563 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
564 (let ((to-be-marked (cond
566 (article (if (listp article) article (list article)))
569 `(when (gnus-buffer-exists-p ,buffer)
573 (if (eq config 'forward)
574 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
575 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
578 (put 'gnus-setup-message 'lisp-indent-function 1)
579 (put 'gnus-setup-message 'edebug-form-spec '(form body))
581 ;;; Post news commands of Gnus group mode and summary mode
583 (defun gnus-group-mail (&optional arg)
584 "Start composing a mail.
585 If ARG, use the group under the point to find a posting style.
586 If ARG is 1, prompt for a group name to find the posting style."
588 ;; We can't `let' gnus-newsgroup-name here, since that leads
589 ;; to local variables leaking.
590 (let ((group gnus-newsgroup-name)
591 ;; make sure last viewed article doesn't affect posting styles:
593 (buffer (current-buffer)))
596 (setq gnus-newsgroup-name
598 (if (= 1 (prefix-numeric-value arg))
599 (completing-read "Use posting style of group: "
600 gnus-active-hashtb nil
601 (gnus-read-active-file-p))
602 (gnus-group-group-name))
604 ;; #### see comment in gnus-setup-message -- drv
605 (gnus-setup-message 'message (message-mail)))
608 (setq gnus-newsgroup-name group)))))
610 (defun gnus-group-news (&optional arg)
611 "Start composing a news.
612 If ARG, post to group under point.
613 If ARG is 1, prompt for group name to post to.
615 This function prepares a news even when using mail groups. This is useful
616 for posting messages to mail groups without actually sending them over the
617 network. The corresponding backend must have a 'request-post method."
619 ;; We can't `let' gnus-newsgroup-name here, since that leads
620 ;; to local variables leaking.
621 (let ((group gnus-newsgroup-name)
622 ;; make sure last viewed article doesn't affect posting styles:
624 (buffer (current-buffer)))
627 (setq gnus-newsgroup-name
629 (if (= 1 (prefix-numeric-value arg))
630 (completing-read "Use group: "
631 gnus-active-hashtb nil
632 (gnus-read-active-file-p))
633 (gnus-group-group-name))
635 ;; #### see comment in gnus-setup-message -- drv
636 (gnus-setup-message 'message
637 (message-news (gnus-group-real-name gnus-newsgroup-name))))
640 (setq gnus-newsgroup-name group)))))
642 (defun gnus-group-post-news (&optional arg)
643 "Start composing a message (a news by default).
644 If ARG, post to group under point. If ARG is 1, prompt for group name.
645 Depending on the selected group, the message might be either a mail or
648 ;; Bind this variable here to make message mode hooks work ok.
649 (let ((gnus-newsgroup-name
651 (if (= 1 (prefix-numeric-value arg))
652 (completing-read "Newsgroup: " gnus-active-hashtb nil
653 (gnus-read-active-file-p))
654 (gnus-group-group-name))
656 ;; make sure last viewed article doesn't affect posting styles:
658 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
659 (string= gnus-newsgroup-name ""))))
661 (defun gnus-summary-mail-other-window (&optional arg)
662 "Start composing a mail in another window.
663 Use the posting of the current group by default.
664 If ARG, don't do that. If ARG is 1, prompt for group name to find the
667 ;; We can't `let' gnus-newsgroup-name here, since that leads
668 ;; to local variables leaking.
669 (let ((group gnus-newsgroup-name)
670 ;; make sure last viewed article doesn't affect posting styles:
672 (buffer (current-buffer)))
675 (setq gnus-newsgroup-name
677 (if (= 1 (prefix-numeric-value arg))
678 (completing-read "Use group: "
679 gnus-active-hashtb nil
680 (gnus-read-active-file-p))
682 gnus-newsgroup-name))
683 ;; #### see comment in gnus-setup-message -- drv
684 (gnus-setup-message 'message (message-mail)))
687 (setq gnus-newsgroup-name group)))))
689 (defun gnus-summary-news-other-window (&optional arg)
690 "Start composing a news in another window.
691 Post to the current group by default.
692 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
694 This function prepares a news even when using mail groups. This is useful
695 for posting messages to mail groups without actually sending them over the
696 network. The corresponding backend must have a 'request-post method."
698 ;; We can't `let' gnus-newsgroup-name here, since that leads
699 ;; to local variables leaking.
700 (let ((group gnus-newsgroup-name)
701 ;; make sure last viewed article doesn't affect posting styles:
703 (buffer (current-buffer)))
706 (setq gnus-newsgroup-name
708 (if (= 1 (prefix-numeric-value arg))
709 (completing-read "Use group: "
710 gnus-active-hashtb nil
711 (gnus-read-active-file-p))
713 gnus-newsgroup-name))
714 ;; #### see comment in gnus-setup-message -- drv
715 (gnus-setup-message 'message
716 (message-news (gnus-group-real-name gnus-newsgroup-name))))
719 (setq gnus-newsgroup-name group)))))
721 (defun gnus-summary-post-news (&optional arg)
722 "Start composing a message. Post to the current group by default.
723 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
724 Depending on the selected group, the message might be either a mail or
727 ;; Bind this variable here to make message mode hooks work ok.
728 (let ((gnus-newsgroup-name
730 (if (= 1 (prefix-numeric-value arg))
731 (completing-read "Newsgroup: " gnus-active-hashtb nil
732 (gnus-read-active-file-p))
734 gnus-newsgroup-name))
735 ;; make sure last viewed article doesn't affect posting styles:
737 (gnus-post-news 'post gnus-newsgroup-name)))
740 (defun gnus-summary-followup (yank &optional force-news)
741 "Compose a followup to an article.
742 If prefix argument YANK is non-nil, the original article is yanked
744 YANK is a list of elements, where the car of each element is the
745 article number, and the two following numbers is the region to be
748 (list (and current-prefix-arg
749 (gnus-summary-work-articles 1))))
751 (gnus-summary-goto-subject
752 (if (listp (car yank))
755 (save-window-excursion
756 (gnus-summary-select-article))
757 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
758 (gnus-newsgroup-name gnus-newsgroup-name))
760 (gnus-post-news nil gnus-newsgroup-name
761 headers gnus-article-buffer
763 (gnus-summary-handle-replysign)))
765 (defun gnus-summary-followup-with-original (n &optional force-news)
766 "Compose a followup to an article and include the original article."
768 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
770 (defun gnus-summary-followup-to-mail (&optional arg)
771 "Followup to the current mail message via news."
773 (list (and current-prefix-arg
774 (gnus-summary-work-articles 1))))
775 (gnus-summary-followup arg t))
777 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
778 "Followup to the current mail message via news."
780 (gnus-summary-followup (gnus-summary-work-articles arg) t))
782 (defun gnus-inews-yank-articles (articles)
783 (let (beg article yank-string
784 (more-than-one (cdr articles))
785 (cur (current-buffer))
788 (while (setq article (pop articles))
789 (when (listp article)
790 (setq yank-string (nth 1 article)
791 article (nth 0 article)))
792 (save-window-excursion
793 (set-buffer gnus-summary-buffer)
794 (gnus-summary-select-article nil nil nil article)
795 (gnus-summary-remove-process-mark article))
797 ;; Gathering references.
799 (setq refs (message-list-references
801 (mail-header-references gnus-current-headers)
802 (mail-header-message-id gnus-current-headers)))
803 (when message-use-multi-frames
804 (when (setq window (get-buffer-window cur t))
805 (select-frame (window-frame window)))))
807 (gnus-copy-article-buffer nil yank-string)
808 (let ((message-reply-buffer gnus-article-copy)
809 (message-reply-headers
810 ;; The headers are decoded.
811 (with-current-buffer gnus-article-copy
813 (nnheader-narrow-to-headers)
814 (nnheader-parse-naked-head)))))
815 (message-yank-original)
816 (setq beg (or beg (mark t))))
821 ;; Replace with the gathered references.
825 (message-narrow-to-headers)
826 (let ((case-fold-search t))
827 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
829 (goto-char (point-max))))
831 (list (or (assq 'References message-header-format-alist)
832 '(References . message-shorten-references)))
833 (list (cons 'References
834 (mapconcat 'identity (nreverse refs) " "))))
835 (backward-delete-char 1))
841 (defun gnus-summary-cancel-article (&optional n symp)
842 "Cancel an article you posted.
843 Uses the process-prefix convention. If given the symbolic
844 prefix `a', cancel using the standard posting method; if not
845 post using the current select method."
846 (interactive (gnus-interactive "P\ny"))
847 (let ((articles (gnus-summary-work-articles n))
850 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
852 (while (setq article (pop articles))
853 (when (gnus-summary-select-article t nil nil article)
854 (when (gnus-eval-in-buffer-window gnus-article-buffer
856 (set-buffer gnus-original-article-buffer)
857 (message-cancel-news)))
858 (gnus-summary-mark-as-read article gnus-canceled-mark)
859 (gnus-cache-remove-article 1))
860 (gnus-article-hide-headers-if-wanted))
861 (gnus-summary-remove-process-mark article))))
863 (defun gnus-summary-supersede-article ()
864 "Compose an article that will supersede a previous article.
865 This is done simply by taking the old article and adding a Supersedes
866 header line with the old Message-ID."
868 (let ((article (gnus-summary-article-number)))
869 (gnus-setup-message 'reply-yank
870 (gnus-summary-select-article t)
871 (set-buffer gnus-original-article-buffer)
875 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
877 (set-buffer ,gnus-summary-buffer)
878 (gnus-cache-possibly-remove-article ,article nil nil nil t)
879 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
880 message-send-actions))))
884 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
885 ;; make a copy of the article buffer with all text properties removed
886 ;; this copy is in the buffer gnus-article-copy.
887 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
888 ;; this buffer should be passed to all mail/news reply/post routines.
889 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
891 (set-buffer gnus-article-copy)
892 (set-buffer-multibyte t))
893 (let ((article-buffer (or article-buffer gnus-article-buffer))
895 (if (not (and (get-buffer article-buffer)
896 (gnus-buffer-exists-p article-buffer)))
897 (error "Can't find any article buffer")
899 (set-buffer article-buffer)
900 (let ((gnus-newsgroup-charset (or gnus-article-charset
901 gnus-newsgroup-charset))
902 (gnus-newsgroup-ignored-charsets
903 (or gnus-article-ignored-charsets
904 gnus-newsgroup-ignored-charsets)))
906 ;; Copy over the (displayed) article buffer, delete
907 ;; hidden text and remove text properties.
909 (copy-to-buffer gnus-article-copy (point-min) (point-max))
910 (set-buffer gnus-article-copy)
911 ;; There's invisible and intangible text in T-gnus. Especially,
912 ;; if there is a boundary line (X-Boundary: ------------------),
913 ;; in the end of a header, it will cause a serious problem.
914 (add-text-properties (point-min) (point-max)
915 '(invisible nil intangible nil))
918 (delete-region (point) (point-max))
919 (insert yank-string))
920 ;; Encode bitmap smileys to ordinary text.
921 ;; Possibly, the original text might be restored.
922 (static-unless (featurep 'xemacs)
923 (when (featurep 'smiley-mule)
924 (smiley-encode-buffer)))
925 (gnus-article-delete-text-of-type 'annotation)
926 (gnus-remove-text-with-property 'gnus-prev)
927 (gnus-remove-text-with-property 'gnus-next)
928 (gnus-remove-text-with-property 'gnus-decoration)
929 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
932 (static-if (featurep 'xemacs)
933 ;; Revome smiley extents for (possibly) XEmacs 21.1.
935 (buffer-substring-no-properties (point-min)
937 (buffer-substring-no-properties (point-min) (point-max)))
939 ;; Find the original headers.
940 (set-buffer gnus-original-article-buffer)
941 (goto-char (point-min))
942 (while (looking-at message-unix-mail-delimiter)
944 (let ((mail-header-separator ""))
946 end (or (message-goto-body)
947 ;; There may be just a header.
949 ;; Delete the headers from the displayed articles.
950 (set-buffer gnus-article-copy)
951 (let ((mail-header-separator ""))
952 (delete-region (goto-char (point-min))
953 (or (message-goto-body) (point-max))))
954 ;; Insert the original article headers.
955 (insert-buffer-substring gnus-original-article-buffer beg end)
957 (let ((gnus-article-decode-hook
958 (delq 'article-decode-charset
959 (copy-sequence gnus-article-decode-hook))))
960 ;; Needed for T-gnus.
961 (add-hook 'gnus-article-decode-hook
962 'article-decode-encoded-words)
963 (run-hooks 'gnus-article-decode-hook)))))
966 (defun gnus-post-news (post &optional group header article-buffer yank subject
969 (gnus-copy-article-buffer))
970 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
971 (gnus-article-yanked-articles yank)
972 (add-to-list gnus-add-to-list))
973 (gnus-setup-message (cond (yank 'reply-yank)
974 (article-buffer 'reply)
976 (let* ((group (or group gnus-newsgroup-name))
977 (charset (gnus-group-name-charset nil group))
979 to-address to-group mailing-list to-list
982 (setq to-address (gnus-parameter-to-address group)
983 to-group (gnus-group-find-parameter group 'to-group)
984 to-list (gnus-parameter-to-list group)
985 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
986 mailing-list (when gnus-mailing-list-groups
987 (string-match gnus-mailing-list-groups group))
988 group (gnus-group-name-decode (gnus-group-real-name group)
990 (if (or (and to-group
991 (gnus-news-group-p to-group))
994 (and (gnus-news-group-p
995 (or pgroup gnus-newsgroup-name)
996 (or header gnus-current-article))
1002 (message-news (or to-group group))
1003 (set-buffer gnus-article-copy)
1004 (gnus-msg-treat-broken-reply-to)
1005 (message-followup (if (or newsgroup-p force-news)
1006 (if (save-restriction
1007 (article-narrow-to-head)
1008 (message-fetch-field "newsgroups"))
1015 (message-mail (or to-address to-list))
1016 ;; Arrange for mail groups that have no `to-address' to
1017 ;; get that when the user sends off the mail.
1018 (when (and (not to-list)
1021 (push (list 'gnus-inews-add-to-address pgroup)
1022 message-send-actions)))
1023 (set-buffer gnus-article-copy)
1024 (gnus-msg-treat-broken-reply-to)
1025 (message-wide-reply to-address)))
1027 (gnus-inews-yank-articles yank))))))
1029 (defun gnus-msg-treat-broken-reply-to (&optional force)
1030 "Remove the Reply-to header if broken-reply-to."
1032 (gnus-group-find-parameter
1033 gnus-newsgroup-name 'broken-reply-to))
1035 (message-narrow-to-head)
1036 (message-remove-header "reply-to"))))
1038 (defun gnus-post-method (arg group &optional silent)
1039 "Return the posting method based on GROUP and ARG.
1040 If SILENT, don't prompt the user."
1041 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1043 (group-method (gnus-find-method-for-group group)))
1045 ;; If the group-method is nil (which shouldn't happen) we use
1046 ;; the default method.
1047 ((null group-method)
1048 (or (and (listp gnus-post-method) ;If not current/native/nil
1049 (not (listp (car gnus-post-method))) ; and not a list of methods
1050 gnus-post-method) ;then use it.
1052 message-post-method))
1053 ;; We want the inverse of the default
1054 ((and arg (not (eq arg 0)))
1055 (if (eq gnus-post-method 'current)
1058 ;; We query the user for a post method.
1060 (and (listp gnus-post-method)
1061 (listp (car gnus-post-method))))
1063 ;; Collect all methods we know about.
1065 (when (listp gnus-post-method)
1066 (if (listp (car gnus-post-method))
1068 (list gnus-post-method)))
1069 gnus-secondary-select-methods
1070 (mapcar 'cdr gnus-server-alist)
1071 (mapcar 'car gnus-opened-servers)
1072 (list gnus-select-method)
1073 (list group-method)))
1074 method-alist post-methods method)
1075 ;; Weed out all mail methods.
1077 (setq method (gnus-server-get-method "" (pop methods)))
1078 (when (and (or (gnus-method-option-p method 'post)
1079 (gnus-method-option-p method 'post-mail))
1080 (not (member method post-methods)))
1081 (push method post-methods)))
1082 ;; Create a name-method alist.
1086 (if (equal (cadr m) "")
1087 (list (symbol-name (car m)) m)
1088 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1093 (setq gnus-last-posting-server
1095 gnus-last-posting-server)
1096 ;; Just use the last value.
1097 gnus-last-posting-server
1099 "Posting method: " method-alist nil t
1100 (cons (or gnus-last-posting-server "") 0))))
1102 ;; Override normal method.
1103 ((and (eq gnus-post-method 'current)
1104 (not (memq (car group-method) gnus-discouraged-post-methods))
1105 (gnus-get-function group-method 'request-post t))
1108 ;; Use gnus-post-method.
1109 ((listp gnus-post-method) ;A method...
1110 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1112 ;; Use the normal select method (nil or native).
1113 (t gnus-select-method))))
1116 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1118 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1119 variable `mime-edit-user-agent-value' is bound, the value will be
1120 included in the return value. If MAX-COLUMN is specified, the return
1121 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1122 whether a newline should be inserted in front of each product-token.
1123 If the value is t or `hard', it works strictly. Otherwise, if it is
1124 non-nil (e.g. `soft'), it works semi-strictly.
1126 Here is an example of how to use this function:
1128 \(add-hook 'gnus-message-setup-hook
1130 (setq message-user-agent nil)
1133 (message-narrow-to-headers)
1134 (goto-char (point-max))
1135 (insert \"User-Agent: \"
1136 (gnus-message-make-user-agent t 76 'soft)
1139 (let ((user-agent (if (and include-mime-info
1140 (boundp 'mime-edit-user-agent-value))
1141 (concat (gnus-extended-version)
1143 mime-edit-user-agent-value)
1144 (gnus-extended-version))))
1146 (unless (natnump max-column)
1147 (setq max-column 76))
1149 (set-buffer-multibyte t)
1150 (insert (mapconcat 'identity (split-string user-agent) " "))
1151 (goto-char (point-min))
1153 start agent agents width element swidth)
1154 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1155 (setq start (match-beginning 0))
1156 (if (eq (char-after start) ?\()
1160 (push (buffer-substring start (point)) agent))
1162 (push (nreverse agent) agents))
1163 (setq agent (list (match-string 1)))))
1165 (push (nreverse agent) agents))
1166 (setq agents (nreverse agents))
1167 (if (> (+ 12 (string-width (caar agents))) max-column)
1168 (setq user-agent "\n"
1173 (setq agent (car agents)
1174 agents (cdr agents))
1175 (when (and (not bol)
1176 (or (memq newline-product '(t hard))
1177 (and newline-product
1179 (string-width (mapconcat 'identity
1182 (setq user-agent (concat user-agent "\n")
1186 (setq element (car agent)
1187 swidth (string-width element)
1190 (setq user-agent (if (member user-agent '("" "\n"))
1191 (concat user-agent element)
1192 (concat user-agent " " element))
1193 width (+ width 1 swidth)
1195 (if (> (+ width 1 swidth) max-column)
1196 (setq user-agent (concat user-agent "\n " element)
1198 (setq user-agent (concat user-agent " " element)
1199 width (+ width 1 swidth)))))))))
1204 ;;; Gnus Mail Functions
1207 ;;; Mail reply commands of Gnus summary mode
1209 (defun gnus-summary-reply (&optional yank wide very-wide)
1210 "Start composing a mail reply to the current message.
1211 If prefix argument YANK is non-nil, the original article is yanked
1213 If WIDE, make a wide reply.
1214 If VERY-WIDE, make a very wide reply."
1216 (list (and current-prefix-arg
1217 (gnus-summary-work-articles 1))))
1218 ;; Allow user to require confirmation before replying by mail to the
1219 ;; author of a news article (or mail message).
1221 (not (or (gnus-news-group-p gnus-newsgroup-name)
1222 gnus-confirm-treat-mail-like-news))
1223 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1224 (string-match gnus-confirm-mail-reply-to-news
1225 gnus-newsgroup-name))
1226 ((functionp gnus-confirm-mail-reply-to-news)
1227 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1228 (t gnus-confirm-mail-reply-to-news)))
1229 (y-or-n-p "Really reply by mail to article author? "))
1231 (if (listp (car yank))
1234 (gnus-article-reply (or article (gnus-summary-article-number)))
1235 (gnus-article-yanked-articles yank)
1237 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1239 (gnus-summary-goto-subject article))
1240 (gnus-setup-message (if yank 'reply-yank 'reply)
1242 (gnus-summary-select-article)
1243 (dolist (article very-wide)
1244 (gnus-summary-select-article nil nil nil article)
1246 (set-buffer (gnus-copy-article-buffer))
1247 (gnus-msg-treat-broken-reply-to)
1249 (message-narrow-to-head)
1250 (setq headers (concat headers (buffer-string)))))))
1251 (set-buffer (gnus-copy-article-buffer))
1252 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1254 (message-narrow-to-head)
1258 (goto-char (point-max)))
1259 (message-reply nil wide)
1261 (gnus-inews-yank-articles yank))
1262 (gnus-summary-handle-replysign)))))
1264 (defun gnus-summary-handle-replysign ()
1265 "Check the various replysign variables and take action accordingly."
1266 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1267 (let (signed encrypted)
1269 (set-buffer gnus-article-buffer)
1270 (setq signed (memq 'signed gnus-article-wash-types))
1271 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1272 (cond ((and gnus-message-replyencrypt encrypted)
1273 (mml-secure-message mml-default-encrypt-method
1274 (if gnus-message-replysignencrypted
1277 ((and gnus-message-replysign signed)
1278 (mml-secure-message mml-default-sign-method 'sign))))))
1280 (defun gnus-summary-reply-with-original (n &optional wide)
1281 "Start composing a reply mail to the current message.
1282 The original article will be yanked."
1284 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1286 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1287 "Like `gnus-summary-reply' except removing reply-to field.
1288 If prefix argument YANK is non-nil, the original article is yanked
1290 If WIDE, make a wide reply.
1291 If VERY-WIDE, make a very wide reply."
1293 (list (and current-prefix-arg
1294 (gnus-summary-work-articles 1))))
1295 (let ((gnus-msg-force-broken-reply-to t))
1296 (gnus-summary-reply yank wide very-wide)))
1298 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1299 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1300 The original article will be yanked."
1302 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1304 (defun gnus-summary-wide-reply (&optional yank)
1305 "Start composing a wide reply mail to the current message.
1306 If prefix argument YANK is non-nil, the original article is yanked
1309 (list (and current-prefix-arg
1310 (gnus-summary-work-articles 1))))
1311 (gnus-summary-reply yank t))
1313 (defun gnus-summary-wide-reply-with-original (n)
1314 "Start composing a wide reply mail to the current message.
1315 The original article will be yanked."
1317 (gnus-summary-reply-with-original n t))
1319 (defun gnus-summary-very-wide-reply (&optional yank)
1320 "Start composing a very wide reply mail to the current message.
1321 If prefix argument YANK is non-nil, the original article is yanked
1324 (list (and current-prefix-arg
1325 (gnus-summary-work-articles 1))))
1326 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1328 (defun gnus-summary-very-wide-reply-with-original (n)
1329 "Start composing a very wide reply mail to the current message.
1330 The original article will be yanked."
1333 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1335 (defun gnus-summary-mail-forward (&optional full-headers post)
1336 "Forward the current message(s) to another user.
1337 If process marks exist, forward all marked messages;
1338 If FULL-HEADERS (the prefix), include full headers when forwarding.
1340 Note that this function definition for T-gnus is totally different
1341 from the original Gnus."
1343 (if (cdr (gnus-summary-work-articles nil))
1344 ;; Process marks are given.
1345 (gnus-summary-digest-mail-forward nil post)
1346 ;; No process marks.
1347 (let* ((gnus-article-reply (gnus-summary-article-number))
1348 (gnus-article-yanked-articles (list gnus-article-reply))
1350 (message-included-forward-headers
1351 (if full-headers "" message-included-forward-headers)))
1352 (gnus-setup-message 'forward
1353 (gnus-summary-select-article)
1354 (setq charset default-mime-charset)
1355 (set-buffer gnus-original-article-buffer)
1356 (make-local-variable 'default-mime-charset)
1357 (setq default-mime-charset charset)
1358 (message-forward post)))))
1360 (defun gnus-summary-digest-mail-forward (&optional n post)
1361 "Digests and forwards all articles in this series.
1362 If N is a positive number, forward the N next articles.
1363 If N is a negative number, forward the N previous articles.
1364 If N is nil and any articles have been marked with the process mark,
1365 forward those articles instead.
1366 Optional POST will use news to forward instead of mail."
1368 (let* ((articles (gnus-summary-work-articles n))
1369 (gnus-article-yanked-articles (copy-sequence articles))
1370 (topics "Topics:\n")
1371 subject article frame)
1372 (when (car articles)
1373 (gnus-setup-message 'forward
1374 (gnus-summary-select-article)
1376 (setq articles (sort articles '<)
1377 subject "Digested Articles")
1378 (with-current-buffer gnus-original-article-buffer
1379 (setq subject (message-make-forward-subject))))
1381 (message-news nil subject)
1382 (message-mail nil subject))
1383 (when (and message-use-multi-frames (cdr articles))
1384 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1386 (while (setq article (pop articles))
1387 (save-window-excursion
1388 (set-buffer gnus-summary-buffer)
1389 (gnus-summary-select-article nil nil nil article)
1390 (setq topics (concat topics " "
1391 (mail-header-subject gnus-current-headers)
1393 (gnus-summary-remove-process-mark article))
1395 (select-frame frame))
1396 (insert (mime-make-tag "message" "rfc822") "\n")
1397 (narrow-to-region (point) (point))
1398 (insert-buffer-substring gnus-original-article-buffer)
1400 (article-narrow-to-head)
1401 (message-remove-header message-included-forward-headers t nil t))
1402 (goto-char (point-max))
1408 (mime-edit-enclose-digest-region (point)(mark t))))))
1410 (defun gnus-summary-digest-post-forward (&optional n)
1411 "Digest and forwards all articles in this series to a newsgroup.
1412 If N is a positive number, forward the N next articles.
1413 If N is a negative number, forward the N previous articles.
1414 If N is nil and any articles have been marked with the process mark,
1415 forward those articles instead."
1417 (gnus-summary-digest-mail-forward n t))
1419 (defun gnus-summary-resend-message (address n)
1420 "Resend the current article to ADDRESS."
1422 (list (message-read-from-minibuffer
1423 "Resend message(s) to: "
1424 (when (and gnus-summary-resend-default-address
1425 (gnus-buffer-live-p gnus-original-article-buffer))
1426 ;; If some other article is currently selected, the
1427 ;; initial-contents is wrong. Whatever, it is just the
1428 ;; initial-contents.
1429 (with-current-buffer gnus-original-article-buffer
1430 (nnmail-fetch-field "to"))))
1431 current-prefix-arg))
1432 (let ((articles (gnus-summary-work-articles n))
1434 (while (setq article (pop articles))
1435 (gnus-summary-select-article nil nil nil article)
1437 (set-buffer gnus-original-article-buffer)
1438 (message-resend address))
1439 (gnus-summary-mark-article-as-forwarded article))))
1441 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1442 (defun gnus-summary-resend-message-edit ()
1443 "Resend an article that has already been sent.
1444 A new buffer will be created to allow the user to modify body and
1445 contents of the message, and then, everything will happen as when
1446 composing a new message."
1448 (let ((article (gnus-summary-article-number)))
1449 (gnus-setup-message 'reply-yank
1450 (gnus-summary-select-article t)
1451 (set-buffer gnus-original-article-buffer)
1452 (let ((cur (current-buffer))
1453 (to (message-fetch-field "to")))
1454 ;; Get a normal message buffer.
1455 (message-pop-to-buffer (message-buffer-name "Resend" to))
1456 (insert-buffer-substring cur)
1458 ;; T-gnus change: Use MIME-Edit to recompose a message.
1460 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1461 (fset 'mime-edit-decode-single-part-in-buffer
1462 (lambda (&rest args)
1463 (if (let ((content-type (car args)))
1464 (and (eq 'message (mime-content-type-primary-type
1466 (eq 'rfc822 (mime-content-type-subtype
1468 (setcar (cdr args) 'not-decode-text))
1471 (mime-edit-again nil t)
1472 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1473 (message-narrow-to-head-1)
1474 (insert "From: " (message-make-from) "\n")
1475 (while (re-search-forward "^From:" nil t)
1477 (insert "Original-"))
1478 (message-remove-header "^>From[\t ]" t)
1480 ;; Gnus will generate a new one when sending.
1481 (message-remove-header "Message-ID")
1482 (message-remove-header message-ignored-resent-headers t)
1483 ;; Remove unwanted headers.
1484 (goto-char (point-max))
1485 (insert mail-header-separator)
1486 (goto-char (point-min))
1487 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1491 (defun gnus-summary-post-forward (&optional full-headers)
1492 "Forward the current article to a newsgroup.
1493 If FULL-HEADERS (the prefix), include full headers when forwarding."
1495 (gnus-summary-mail-forward full-headers t))
1497 (defvar gnus-nastygram-message
1498 "The following article was inappropriately posted to %s.\n\n"
1499 "Format string to insert in nastygrams.
1500 The current group name will be inserted at \"%s\".")
1502 (defun gnus-summary-mail-nastygram (n)
1503 "Send a nastygram to the author of the current article."
1505 (when (or gnus-expert-user
1507 "Really send a nastygram to the author of the current article? "))
1508 (let ((group gnus-newsgroup-name))
1509 (gnus-summary-reply-with-original n)
1510 (set-buffer gnus-message-buffer)
1512 (insert (format gnus-nastygram-message group))
1513 (message-send-and-exit))))
1515 (defun gnus-summary-mail-crosspost-complaint (n)
1516 "Send a complaint about crossposting to the current article(s)."
1518 (let ((articles (gnus-summary-work-articles n))
1520 (while (setq article (pop articles))
1521 (set-buffer gnus-summary-buffer)
1522 (gnus-summary-goto-subject article)
1523 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1524 newsgroups followup-to)
1525 (gnus-summary-select-article)
1526 (set-buffer gnus-original-article-buffer)
1527 (if (and (<= (length (message-tokenize-header
1529 (mail-fetch-field "newsgroups"))
1532 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1533 (not (member group (message-tokenize-header
1534 followup-to ", ")))))
1536 (gnus-message 1 "Followup-to restricted")
1537 (gnus-message 1 "Not a crossposted article"))
1538 (set-buffer gnus-summary-buffer)
1539 (gnus-summary-reply-with-original 1)
1540 (set-buffer gnus-message-buffer)
1542 (insert (format gnus-crosspost-complaint newsgroups group))
1543 (message-goto-subject)
1544 (re-search-forward " *$")
1545 (replace-match " (crosspost notification)" t t)
1546 (gnus-deactivate-mark)
1547 (when (gnus-y-or-n-p "Send this complaint? ")
1548 (message-send-and-exit)))))))
1550 (defun gnus-mail-parse-comma-list ()
1553 (skip-chars-forward " ")
1556 (skip-chars-forward "^,")
1561 (narrow-to-region beg (point))
1564 (while (search-forward "\"" nil t)
1568 (skip-chars-forward ",")
1569 (skip-chars-forward "^,"))
1570 (skip-chars-backward " ")
1571 (push (buffer-substring beg (point))
1573 (skip-chars-forward "^,")
1574 (skip-chars-forward ", "))
1577 (defun gnus-inews-add-to-address (group)
1578 (let ((to-address (mail-fetch-field "to")))
1579 (when (and to-address
1581 ;; This mail group doesn't have a `to-list', so we add one
1583 (when (gnus-y-or-n-p
1584 (format "Do you want to add this as `to-list': %s " to-address))
1585 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1587 (defun gnus-put-message ()
1588 "Put the current message in some group and return to Gnus."
1590 (let ((reply gnus-article-reply)
1591 (winconf gnus-prev-winconf)
1592 (group gnus-newsgroup-name))
1594 (not (gnus-group-read-only-p group)))
1595 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1597 (when (gnus-gethash group gnus-newsrc-hashtb)
1598 (error "No such group: %s" group))
1602 (message-narrow-to-headers)
1603 (let ((gnus-deletable-headers nil))
1604 (message-generate-headers
1605 (if (message-news-p)
1606 message-required-news-headers
1607 message-required-mail-headers)))
1608 (goto-char (point-max))
1609 (if (string-match " " group)
1610 (insert "Gcc: \"" group "\"\n")
1611 (insert "Gcc: " group "\n"))
1614 (when (and (get-buffer gnus-group-buffer)
1615 (gnus-buffer-exists-p (car-safe reply))
1617 (set-buffer (car reply))
1618 (gnus-summary-mark-article-as-replied (cdr reply)))
1620 (set-window-configuration winconf))))
1622 (defun gnus-article-mail (yank)
1623 "Send a reply to the address near point.
1624 If YANK is non-nil, include the original article."
1628 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1629 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1631 (gnus-msg-mail address)
1633 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1635 (defvar nntp-server-type)
1637 "Send a bug report to the Gnus maintainers."
1639 (unless (gnus-alive-p)
1640 (error "Gnus has been shut down"))
1641 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1642 (unless (message-mail-user-agent)
1643 (message-pop-to-buffer "*Gnus Bug*")
1644 (delete-other-windows)
1645 (when gnus-bug-create-help-buffer
1646 (switch-to-buffer "*Gnus Help Bug*")
1648 (insert gnus-bug-message)
1649 (goto-char (point-min))
1651 (set-buffer "*Gnus Bug*")))
1652 (let ((message-this-is-mail t))
1653 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1654 (when gnus-bug-create-help-buffer
1655 (push `(gnus-bug-kill-buffer) message-send-actions))
1656 (goto-char (point-min))
1657 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1659 (insert gnus-product-name " " gnus-version-number
1660 " (r" gnus-revision-number ") "
1661 "based on " gnus-original-product-name " v"
1662 gnus-original-version-number "\n"
1663 (emacs-version) "\n")
1664 (when (and (boundp 'nntp-server-type)
1665 (stringp nntp-server-type))
1666 (insert nntp-server-type))
1667 (insert "\n\n\n\n\n")
1668 (let (mime-content-types)
1669 (mime-edit-insert-tag
1670 "application" "emacs-lisp"
1671 "\nContent-Disposition: inline\nContent-Description: User settings"))
1672 (insert (with-temp-buffer
1675 (let (mime-content-types)
1676 (mime-edit-insert-tag "text" "plain"))
1677 (goto-char (point-min))
1678 (search-forward "Subject: " nil t)
1681 (defun gnus-bug-kill-buffer ()
1682 (when (get-buffer "*Gnus Help Bug*")
1683 (kill-buffer "*Gnus Help Bug*")))
1685 (defun gnus-summary-yank-message (buffer n)
1686 "Yank the current article into a composed message."
1688 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1689 current-prefix-arg))
1690 (when (gnus-buffer-live-p buffer)
1691 (let ((summary-frame (selected-frame))
1692 (message-frame (when (static-if (featurep 'xemacs)
1693 (device-on-window-system-p)
1695 (let ((window (get-buffer-window buffer t)))
1697 (window-frame window)))))
1698 (separator (concat "^" (regexp-quote mail-header-separator)
1700 (gnus-summary-iterate n
1701 (gnus-summary-select-article)
1702 (gnus-copy-article-buffer)
1703 (when (frame-live-p message-frame)
1704 (raise-frame message-frame)
1705 (select-frame message-frame))
1706 (with-current-buffer buffer
1707 (when (save-excursion
1709 (let (case-fold-search)
1710 (and (not (re-search-backward separator nil t))
1711 (re-search-forward separator nil t))))
1712 (goto-char (match-end 0)))
1713 (message-yank-buffer gnus-article-copy))
1714 (select-frame summary-frame))
1715 (when (frame-live-p message-frame)
1716 (select-frame message-frame)))))
1718 (defun gnus-debug ()
1719 "Attempts to go through the Gnus source file and report what variables have been changed.
1720 The source file has to be in the Emacs load path."
1722 (let ((files gnus-debug-files)
1724 file expr olist sym)
1725 (gnus-message 4 "Please wait while we snoop your variables...")
1726 ;; Go through all the files looking for non-default values for variables.
1729 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1732 (when (and (setq file (locate-library (pop files)))
1733 (file-exists-p file))
1734 (insert-file-contents file)
1735 (goto-char (point-min))
1736 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1737 (gnus-message 4 "Malformed sources in file %s" file)
1738 (narrow-to-region (point-min) (point))
1739 (goto-char (point-min))
1740 (while (setq expr (ignore-errors (read (current-buffer))))
1742 (and (memq (car expr) '(defvar defcustom defvoo))
1743 (stringp (nth 3 expr))
1744 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1745 (or (not (boundp (nth 1 expr)))
1746 (not (equal (eval (nth 2 expr))
1747 (symbol-value (nth 1 expr)))))
1748 (push (nth 1 expr) olist)))))))
1749 (kill-buffer (current-buffer)))
1750 (when (setq olist (nreverse olist))
1751 (insert ";----------------- Environment follows ------------------\n\n"))
1753 (if (boundp (car olist))
1755 (pp `(setq ,(car olist)
1756 ,(if (or (consp (setq sym (symbol-value (car olist))))
1758 (not (or (eq sym nil)
1760 (list 'quote (symbol-value (car olist)))
1761 (symbol-value (car olist))))
1763 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1764 (setq olist (cdr olist)))
1765 ;; Remove any control chars - they seem to cause trouble for some
1766 ;; mailers. (Byte-compiled output from the stuff above.)
1768 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1769 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1771 ;; Break MIME tags purposely.
1773 (while (re-search-forward mime-edit-tag-regexp nil t)
1774 (goto-char (1+ (match-beginning 0)))
1777 ;;; Treatment of rejected articles.
1780 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1781 "Re-mail the current message.
1782 This only makes sense if the current message is a bounce message than
1783 contains some mail you have written which has been bounced back to
1785 If FETCH, try to fetch the article that this is a reply to, if indeed
1788 (gnus-summary-select-article t)
1789 (set-buffer gnus-original-article-buffer)
1790 (gnus-setup-message 'compose-bounce
1791 (let* ((references (mail-fetch-field "references"))
1792 (parent (and references (gnus-parent-id references))))
1794 ;; If there are references, we fetch the article we answered to.
1796 (gnus-summary-refer-article parent)
1797 (gnus-summary-show-all-headers)))))
1801 (defun gnus-inews-group-method (group)
1803 ;; If the group doesn't exist, we assume
1804 ;; it's an archive group...
1805 ((and (null (gnus-get-info group))
1806 (eq (car (gnus-server-to-method gnus-message-archive-method))
1807 (car (gnus-server-to-method (gnus-group-method group)))))
1808 gnus-message-archive-method)
1810 ((gnus-info-method (gnus-get-info group))
1811 (gnus-info-method (gnus-get-info group)))
1813 (t (gnus-server-to-method (gnus-group-method group)))))
1815 ;; Do Gcc handling, which copied the message over to some group.
1816 (defun gnus-inews-do-gcc (&optional gcc)
1820 (message-narrow-to-headers)
1821 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1822 (coding-system-for-write 'raw-text)
1823 (output-coding-system 'raw-text)
1824 groups group method group-art
1825 mml-externalize-attachments)
1827 (message-remove-header "gcc")
1829 (setq groups (message-unquote-tokens
1830 (message-tokenize-header gcc " ,")))
1831 ;; Copy the article over to some group(s).
1832 (while (setq group (pop groups))
1833 (unless (gnus-check-server
1834 (setq method (gnus-inews-group-method group)))
1835 (error "Can't open server %s" (if (stringp method) method
1837 (unless (gnus-request-group group nil method)
1838 (gnus-request-create-group group method))
1839 (setq mml-externalize-attachments
1840 (if (stringp gnus-gcc-externalize-attachments)
1841 (string-match gnus-gcc-externalize-attachments group)
1842 gnus-gcc-externalize-attachments))
1844 (nnheader-set-temp-buffer " *acc*")
1845 (insert-buffer-substring message-encoding-buffer)
1846 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1847 (goto-char (point-min))
1848 (when (re-search-forward
1849 (concat "^" (regexp-quote mail-header-separator) "$")
1851 (replace-match "" t t ))
1852 (unless (setq group-art
1853 (gnus-request-accept-article group method t t))
1854 (gnus-message 1 "Couldn't store article in group %s: %s"
1855 group (gnus-status-message method))
1857 (when (and group-art
1858 ;; FIXME: Should gcc-mark-as-read work when
1859 ;; Gnus is not running?
1861 (or gnus-gcc-mark-as-read
1862 gnus-inews-mark-gcc-as-read))
1863 (gnus-group-mark-article-read group (cdr group-art)))
1864 (kill-buffer (current-buffer)))))))))
1866 (defun gnus-inews-insert-gcc ()
1867 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1870 (message-narrow-to-headers)
1871 (let* ((group gnus-outgoing-message-group)
1873 ((gnus-functionp group)
1875 ((or (stringp group) (list group))
1880 (if (string-match " " gcc)
1881 (concat "\"" gcc "\"")
1883 (mapconcat (lambda (group)
1884 (if (string-match " " group)
1885 (concat "\"" group "\"")
1890 (defun gnus-inews-insert-archive-gcc (&optional group)
1891 "Insert the Gcc to say where the article is to be archived."
1892 (let* ((var gnus-message-archive-group)
1893 (group (or group gnus-newsgroup-name ""))
1895 (and gnus-newsgroup-name
1896 (not (equal gnus-newsgroup-name ""))
1897 (gnus-group-find-parameter
1898 gnus-newsgroup-name 'gcc-self)))
1902 ((null gnus-message-archive-method)
1906 ;; Just a single group.
1909 ;; We don't want this.
1911 ((and (listp var) (stringp (car var)))
1912 ;; A list of groups.
1914 ((gnus-functionp var)
1916 (funcall var group))
1918 ;; An alist of regexps/functions/forms.
1923 ((stringp (caar var))
1925 (when (string-match (caar var) group)
1927 ((gnus-functionp (car var))
1929 (funcall (car var) group))
1931 (eval (car var)))))))
1932 (setq var (cdr var)))
1935 (when (or groups gcc-self-val)
1936 (when (stringp groups)
1937 (setq groups (list groups)))
1940 (message-narrow-to-headers)
1941 (goto-char (point-max))
1944 ;; Use the `gcc-self' param value instead.
1947 (if (stringp gcc-self-val)
1948 (if (string-match " " gcc-self-val)
1949 (concat "\"" gcc-self-val "\"")
1951 (if (string-match " " group)
1952 (concat "\"" group "\"")
1954 (if (not (eq gcc-self-val 'none))
1959 ;; Use the list of groups.
1960 (while (setq name (pop groups))
1961 (let ((str (if (string-match ":" name)
1963 (gnus-group-prefixed-name
1964 name gnus-message-archive-method))))
1965 (insert (if (string-match " " str)
1966 (concat "\"" str "\"")
1972 (defun gnus-mailing-list-followup-to ()
1973 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1974 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1975 (list-post (gnus-fetch-original-field "list-post")))
1976 (when (and list-post
1977 (string-match "mailto:\\([^>]+\\)" list-post))
1978 (setq list-post (match-string 1 list-post)))
1984 (defun gnus-configure-posting-styles (&optional group-name)
1985 "Configure posting styles according to `gnus-posting-styles'."
1986 (unless gnus-inhibit-posting-styles
1987 (let ((group (or group-name gnus-newsgroup-name ""))
1988 (styles gnus-posting-styles)
1989 style match attribute results
1991 ;; If the group has a posting-style parameter, add it at the end with a
1992 ;; regexp matching everything, to be sure it takes precedence over all
1994 (when gnus-newsgroup-name
1995 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1997 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1998 ;; Go through all styles and look for matches.
1999 (dolist (style styles)
2000 (setq match (pop style))
2001 (goto-char (point-min))
2004 ;; Regexp string match on the group name.
2005 (string-match match group))
2007 ;; Obsolete format of header match.
2008 (and (gnus-buffer-live-p gnus-article-copy)
2009 (with-current-buffer gnus-article-copy
2010 (let ((header (message-fetch-field (pop style))))
2012 (string-match (pop style) header))))))
2013 ((or (symbolp match)
2014 (gnus-functionp match))
2016 ((gnus-functionp match)
2017 ;; Function to be called.
2020 ;; Variable to be checked.
2021 (symbol-value match))))
2024 ((eq (car match) 'header)
2025 ;; New format of header match.
2026 (and (gnus-buffer-live-p gnus-article-copy)
2027 (with-current-buffer gnus-article-copy
2028 (let ((header (message-fetch-field (nth 1 match))))
2030 (string-match (nth 2 match) header))))))
2032 ;; This is a form to be evaled.
2034 ;; We have a match, so we set the variables.
2035 (setq style (gnus-configure-posting-style style nil))
2036 (dolist (attribute style)
2037 (setq results (delq (assoc (car attribute) results) results))
2038 (push attribute results))))
2039 ;; Now we have all the styles, so we insert them.
2040 (setq name (assq 'name results)
2041 address (assq 'address results))
2042 (setq results (delq name (delq address results)))
2043 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2044 (make-local-hook 'message-setup-hook)
2045 (setq results (sort results (lambda (x y)
2046 (string-lessp (car x) (car y)))))
2047 (dolist (result results)
2048 (add-hook 'message-setup-hook
2050 ((eq 'eval (car result))
2052 ((eq 'body (car result))
2056 (insert ,(cdr result)))))
2057 ((eq 'signature (car result))
2058 (set (make-local-variable 'message-signature) nil)
2059 (set (make-local-variable 'message-signature-file) nil)
2060 (if (not (cdr result))
2064 (let ((message-signature ,(cdr result)))
2065 (when message-signature
2066 (message-insert-signature)))))))
2069 (if (symbolp (car result))
2070 (capitalize (symbol-name (car result)))
2074 (message-remove-header ,header)
2075 (let ((value ,(cdr result)))
2078 (insert ,header ": " value)
2080 (insert "\n")))))))))
2082 (when (or name address)
2083 (add-hook 'message-setup-hook
2085 (set (make-local-variable 'user-mail-address)
2086 ,(or (cdr address) user-mail-address))
2087 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2089 ,(or (cdr address) user-mail-address)))
2091 (message-remove-header "From")
2093 (insert "From: " (message-make-from) "\n"))))
2096 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2097 (defun gnus-configure-posting-style (style stack)
2098 "Parse one posting style STYLE and returns the value as an alist."
2099 (let (results element variable filep value v)
2100 (dolist (attribute style)
2101 (setq element (pop attribute)
2106 ((eq (car attribute) ':file)
2109 ((eq (car attribute) :value)
2113 ;; We get the value.
2118 ((or (symbolp value)
2119 (gnus-functionp value))
2120 (cond ((gnus-functionp value)
2123 (symbol-value value))))
2126 ;; Translate obsolescent value.
2128 ((eq element 'signature-file)
2129 (setq element 'signature
2131 ((eq element 'x-face-file)
2132 (setq element 'x-face
2134 ;; Get the contents of file elems.
2136 (setq v (with-temp-buffer
2137 (insert-file-contents v)
2138 (goto-char (point-max))
2142 (if (eq element 'import)
2144 (if (member v stack)
2145 (error "Circular import of \"%s\"" v))
2147 (nconc (nreverse (gnus-configure-posting-style
2148 (cdr (assoc v gnus-named-posting-styles))
2151 (push (cons element v) results)))
2152 (nreverse results)))
2154 (defun gnus-summary-execute-command-with-posting-style (style command)
2155 "Temporarily select a posting-style named STYLE and execute COMMAND."
2157 (let ((style (completing-read "Posting style: "
2158 gnus-named-posting-styles nil t)))
2162 (format "Command to execute with %s: " style))))))
2163 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2164 (call-interactively command)))
2167 ;;; @ for MIME Edit mode
2170 (defun gnus-maybe-setup-default-charset ()
2172 (and (boundp 'gnus-summary-buffer)
2173 (buffer-live-p gnus-summary-buffer)
2175 (set-buffer gnus-summary-buffer)
2176 default-mime-charset))))
2179 (make-local-variable 'default-mime-charset)
2180 (setq default-mime-charset charset)
2184 ;;; @ for MIME view mode
2187 (defun gnus-following-method (buf)
2188 (gnus-setup-message 'reply-yank
2190 (if (message-news-p)
2192 (message-reply nil 'wide))
2193 (let ((message-reply-buffer buf))
2194 (message-yank-original))
2195 (message-goto-body))
2199 ;;; Allow redefinition of functions.
2205 ;;; gnus-msg.el ends here