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-version-expose-system nil
313 "If non-nil, `system-configuration' is exposed in `gnus-extended-version'.
314 Note that this variable is ineffective in T-gnus."
318 ;;; Internal variables.
320 (defvar gnus-inhibit-posting-styles nil
321 "Inhibit the use of posting styles.")
323 (defvar gnus-article-yanked-articles nil)
324 (defvar gnus-message-buffer "*Mail Gnus*")
325 (defvar gnus-article-copy nil)
326 (defvar gnus-check-before-posting nil)
327 (defvar gnus-last-posting-server nil)
328 (defvar gnus-message-group-art nil)
330 (defvar gnus-msg-force-broken-reply-to nil)
332 (defconst gnus-bug-message
333 (format "Sending a bug report to the Gnus Towers.
334 ========================================
336 This gnus is the %s%s.
337 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
338 Developers. (the addresses below are mailing list addresses)
340 ========================================
342 The buffer below is a mail buffer. When you press `C-c C-c', it will
343 be sent to the Gnus Bug Exterminators.
345 The thing near the bottom of the buffer is how the environment
346 settings will be included in the mail. Please do not delete that.
347 They will tell the Bug People what your environment is, so that it
348 will be easier to locate the bugs.
350 If you have found a bug that makes Emacs go \"beep\", set
351 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
352 and include the backtrace in your bug report.
354 Please describe the bug in annoying, painstaking detail.
356 Thank you for your help in stamping out bugs.
359 (if (string= gnus-product-name "Semi-gnus")
361 ", a modified version of Semi-gnus")))
364 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
365 (autoload 'news-setup "rnewspost")
366 (autoload 'news-reply-mode "rnewspost")
367 (autoload 'rmail-dont-reply-to "mail-utils")
368 (autoload 'rmail-output "rmailout"))
372 ;;; Gnus Posting Functions
375 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
376 "p" gnus-summary-post-news
377 "i" gnus-summary-news-other-window
378 "f" gnus-summary-followup
379 "F" gnus-summary-followup-with-original
380 "c" gnus-summary-cancel-article
381 "s" gnus-summary-supersede-article
382 "r" gnus-summary-reply
383 "y" gnus-summary-yank-message
384 "R" gnus-summary-reply-with-original
385 "w" gnus-summary-wide-reply
386 "W" gnus-summary-wide-reply-with-original
387 "v" gnus-summary-very-wide-reply
388 "V" gnus-summary-very-wide-reply-with-original
389 "n" gnus-summary-followup-to-mail
390 "N" gnus-summary-followup-to-mail-with-original
391 "m" gnus-summary-mail-other-window
392 "u" gnus-uu-post-news
393 "\M-c" gnus-summary-mail-crosspost-complaint
394 "Br" gnus-summary-reply-broken-reply-to
395 "BR" gnus-summary-reply-broken-reply-to-with-original
396 "om" gnus-summary-mail-forward
397 "op" gnus-summary-post-forward
398 "Om" gnus-summary-digest-mail-forward
399 "Op" gnus-summary-digest-post-forward
400 "P" gnus-summary-execute-command-with-posting-style)
402 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
403 "b" gnus-summary-resend-bounced-mail
404 ;; "c" gnus-summary-send-draft
405 "r" gnus-summary-resend-message
406 "e" gnus-summary-resend-message-edit)
408 ;;; Internal functions.
410 (defun gnus-inews-make-draft ()
412 (gnus-inews-make-draft-meta-information
413 ,gnus-newsgroup-name ',gnus-article-reply)))
415 (defvar gnus-article-reply nil)
416 (defmacro gnus-setup-message (config &rest forms)
417 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
418 (buffer (make-symbol "gnus-setup-message-buffer"))
419 (article (make-symbol "gnus-setup-message-article"))
420 (yanked (make-symbol "gnus-setup-yanked-articles"))
421 (group (make-symbol "gnus-setup-message-group")))
422 `(let ((,winconf (current-window-configuration))
423 (,buffer (buffer-name (current-buffer)))
424 (,article gnus-article-reply)
425 (,yanked gnus-article-yanked-articles)
426 (,group gnus-newsgroup-name)
427 (message-header-setup-hook
428 (copy-sequence message-header-setup-hook))
429 (message-mode-hook (copy-sequence message-mode-hook))
430 (message-startup-parameter-alist
431 '((reply-buffer . gnus-copy-article-buffer)
432 (original-buffer . gnus-original-article-buffer)
433 (user-agent . Gnus))))
434 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
435 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
436 ;; #### FIXME: for a reason that I did not manage to identify yet,
437 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
438 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
439 ;; After evaluation of @forms below, it gets the value we actually want
440 ;; to override, and the posting styles are used. For that reason, I've
441 ;; added an optional argument to `gnus-configure-posting-styles' to
442 ;; make sure that the correct value for the group name is used. -- drv
443 (add-hook 'message-mode-hook
445 (gnus-configure-posting-styles ,group)))
446 (gnus-pull ',(intern gnus-draft-meta-information-header)
447 message-required-headers)
449 (not (string= ,group "")))
451 (intern gnus-draft-meta-information-header)
452 (gnus-inews-make-draft))
453 message-required-headers))
457 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
459 (setq gnus-message-buffer (current-buffer))
460 (set (make-local-variable 'gnus-message-group-art)
461 (cons ,group ,article))
462 (set (make-local-variable 'gnus-newsgroup-name) ,group)
463 (gnus-maybe-setup-default-charset)
464 (gnus-run-hooks 'gnus-message-setup-hook))
466 (gnus-configure-windows ,config t)
467 (run-hooks 'post-command-hook)
468 (set-buffer-modified-p nil))))
470 (defun gnus-inews-make-draft-meta-information (group article)
471 (concat "(\"" group "\" "
472 (if article (number-to-string
479 (defun gnus-msg-mail (&optional to subject other-headers continue
480 switch-action yank-action send-actions)
481 "Start editing a mail message to be sent.
482 Like `message-mail', but with Gnus paraphernalia, particularly the
483 Gcc: header for archiving purposes."
485 (let ((buf (current-buffer))
487 (gnus-setup-message 'message
488 (message-mail to subject other-headers continue
489 nil yank-action send-actions))
491 (setq mail-buf (current-buffer))
492 (switch-to-buffer buf)
493 (apply switch-action mail-buf nil)))
494 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
497 (defvar save-selected-window-window)
500 (defun gnus-button-mailto (address)
502 (set-buffer (gnus-copy-article-buffer))
503 (gnus-setup-message 'message
504 (message-reply address))
505 (and (boundp 'save-selected-window-window)
506 (not (window-live-p save-selected-window-window))
507 (setq save-selected-window-window (selected-window))))
510 (defun gnus-button-reply (&optional to-address wide)
511 "Like `message-reply'."
513 (gnus-setup-message 'message
514 (message-reply to-address wide))
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 (define-mail-user-agent 'gnus-user-agent
521 'gnus-msg-mail 'message-send-and-exit
522 'message-kill-buffer 'message-send-hook)
524 (defun gnus-setup-posting-charset (group)
525 (let ((alist gnus-group-posting-charset-alist)
526 (group (or group ""))
530 (while (setq elem (pop alist))
531 (when (or (and (stringp (car elem))
532 (string-match (car elem) group))
533 (and (gnus-functionp (car elem))
534 (funcall (car elem) group))
535 (and (symbolp (car elem))
536 (symbol-value (car elem))))
537 (throw 'found (cons (cadr elem) (caddr elem)))))))))
539 (defun gnus-inews-add-send-actions (winconf buffer article
540 &optional config yanked)
541 (make-local-hook 'message-sent-hook)
542 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
543 'gnus-inews-do-gcc) nil t)
545 (make-local-hook 'message-header-hook)
546 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
547 (setq message-post-method
549 (gnus-post-method arg ,gnus-newsgroup-name)))
550 (setq message-user-agent (gnus-extended-version))
551 (when (not message-use-multi-frames)
553 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
554 (let ((to-be-marked (cond
556 (article (if (listp article) article (list article)))
559 `(when (gnus-buffer-exists-p ,buffer)
563 (if (eq config 'forward)
564 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
565 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
568 (put 'gnus-setup-message 'lisp-indent-function 1)
569 (put 'gnus-setup-message 'edebug-form-spec '(form body))
571 ;;; Post news commands of Gnus group mode and summary mode
573 (defun gnus-group-mail (&optional arg)
574 "Start composing a mail.
575 If ARG, use the group under the point to find a posting style.
576 If ARG is 1, prompt for a group name to find the posting style."
578 ;; We can't `let' gnus-newsgroup-name here, since that leads
579 ;; to local variables leaking.
580 (let ((group gnus-newsgroup-name)
581 ;; make sure last viewed article doesn't affect posting styles:
583 (buffer (current-buffer)))
586 (setq gnus-newsgroup-name
588 (if (= 1 (prefix-numeric-value arg))
589 (completing-read "Use posting style of group: "
590 gnus-active-hashtb nil
591 (gnus-read-active-file-p))
592 (gnus-group-group-name))
594 ;; #### see comment in gnus-setup-message -- drv
595 (gnus-setup-message 'message (message-mail)))
598 (setq gnus-newsgroup-name group)))))
600 (defun gnus-group-news (&optional arg)
601 "Start composing a news.
602 If ARG, post to group under point.
603 If ARG is 1, prompt for group name to post to.
605 This function prepares a news even when using mail groups. This is useful
606 for posting messages to mail groups without actually sending them over the
607 network. The corresponding backend must have a 'request-post method."
609 ;; We can't `let' gnus-newsgroup-name here, since that leads
610 ;; to local variables leaking.
611 (let ((group gnus-newsgroup-name)
612 ;; make sure last viewed article doesn't affect posting styles:
614 (buffer (current-buffer)))
617 (setq gnus-newsgroup-name
619 (if (= 1 (prefix-numeric-value arg))
620 (completing-read "Use group: "
621 gnus-active-hashtb nil
622 (gnus-read-active-file-p))
623 (gnus-group-group-name))
625 ;; #### see comment in gnus-setup-message -- drv
626 (gnus-setup-message 'message
627 (message-news (gnus-group-real-name gnus-newsgroup-name))))
630 (setq gnus-newsgroup-name group)))))
632 (defun gnus-group-post-news (&optional arg)
633 "Start composing a message (a news by default).
634 If ARG, post to group under point. If ARG is 1, prompt for group name.
635 Depending on the selected group, the message might be either a mail or
638 ;; Bind this variable here to make message mode hooks work ok.
639 (let ((gnus-newsgroup-name
641 (if (= 1 (prefix-numeric-value arg))
642 (completing-read "Newsgroup: " gnus-active-hashtb nil
643 (gnus-read-active-file-p))
644 (gnus-group-group-name))
646 ;; make sure last viewed article doesn't affect posting styles:
648 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
649 (string= gnus-newsgroup-name ""))))
651 (defun gnus-summary-mail-other-window (&optional arg)
652 "Start composing a mail in another window.
653 Use the posting of the current group by default.
654 If ARG, don't do that. If ARG is 1, prompt for group name to find the
657 ;; We can't `let' gnus-newsgroup-name here, since that leads
658 ;; to local variables leaking.
659 (let ((group gnus-newsgroup-name)
660 ;; make sure last viewed article doesn't affect posting styles:
662 (buffer (current-buffer)))
665 (setq gnus-newsgroup-name
667 (if (= 1 (prefix-numeric-value arg))
668 (completing-read "Use group: "
669 gnus-active-hashtb nil
670 (gnus-read-active-file-p))
672 gnus-newsgroup-name))
673 ;; #### see comment in gnus-setup-message -- drv
674 (gnus-setup-message 'message (message-mail)))
677 (setq gnus-newsgroup-name group)))))
679 (defun gnus-summary-news-other-window (&optional arg)
680 "Start composing a news in another window.
681 Post to the current group by default.
682 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
684 This function prepares a news even when using mail groups. This is useful
685 for posting messages to mail groups without actually sending them over the
686 network. The corresponding backend must have a 'request-post method."
688 ;; We can't `let' gnus-newsgroup-name here, since that leads
689 ;; to local variables leaking.
690 (let ((group gnus-newsgroup-name)
691 ;; make sure last viewed article doesn't affect posting styles:
693 (buffer (current-buffer)))
696 (setq gnus-newsgroup-name
698 (if (= 1 (prefix-numeric-value arg))
699 (completing-read "Use group: "
700 gnus-active-hashtb nil
701 (gnus-read-active-file-p))
703 gnus-newsgroup-name))
704 ;; #### see comment in gnus-setup-message -- drv
705 (gnus-setup-message 'message
706 (message-news (gnus-group-real-name gnus-newsgroup-name))))
709 (setq gnus-newsgroup-name group)))))
711 (defun gnus-summary-post-news (&optional arg)
712 "Start composing a message. Post to the current group by default.
713 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
714 Depending on the selected group, the message might be either a mail or
717 ;; Bind this variable here to make message mode hooks work ok.
718 (let ((gnus-newsgroup-name
720 (if (= 1 (prefix-numeric-value arg))
721 (completing-read "Newsgroup: " gnus-active-hashtb nil
722 (gnus-read-active-file-p))
724 gnus-newsgroup-name))
725 ;; make sure last viewed article doesn't affect posting styles:
727 (gnus-post-news 'post gnus-newsgroup-name)))
730 (defun gnus-summary-followup (yank &optional force-news)
731 "Compose a followup to an article.
732 If prefix argument YANK is non-nil, the original article is yanked
734 YANK is a list of elements, where the car of each element is the
735 article number, and the two following numbers is the region to be
738 (list (and current-prefix-arg
739 (gnus-summary-work-articles 1))))
741 (gnus-summary-goto-subject
742 (if (listp (car yank))
745 (save-window-excursion
746 (gnus-summary-select-article))
747 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
748 (gnus-newsgroup-name gnus-newsgroup-name))
750 (gnus-post-news nil gnus-newsgroup-name
751 headers gnus-article-buffer
753 (gnus-summary-handle-replysign)))
755 (defun gnus-summary-followup-with-original (n &optional force-news)
756 "Compose a followup to an article and include the original article."
758 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
760 (defun gnus-summary-followup-to-mail (&optional arg)
761 "Followup to the current mail message via news."
763 (list (and current-prefix-arg
764 (gnus-summary-work-articles 1))))
765 (gnus-summary-followup arg t))
767 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
768 "Followup to the current mail message via news."
770 (gnus-summary-followup (gnus-summary-work-articles arg) t))
772 (defun gnus-inews-yank-articles (articles)
773 (let (beg article yank-string
774 (more-than-one (cdr articles))
775 (cur (current-buffer))
778 (while (setq article (pop articles))
779 (when (listp article)
780 (setq yank-string (nth 1 article)
781 article (nth 0 article)))
782 (save-window-excursion
783 (set-buffer gnus-summary-buffer)
784 (gnus-summary-select-article nil nil nil article)
785 (gnus-summary-remove-process-mark article))
787 ;; Gathering references.
789 (setq refs (message-list-references
791 (mail-header-references gnus-current-headers)
792 (mail-header-message-id gnus-current-headers)))
793 (when message-use-multi-frames
794 (when (setq window (get-buffer-window cur t))
795 (select-frame (window-frame window)))))
797 (gnus-copy-article-buffer nil yank-string)
798 (let ((message-reply-buffer gnus-article-copy)
799 (message-reply-headers
800 ;; The headers are decoded.
801 (with-current-buffer gnus-article-copy
803 (nnheader-narrow-to-headers)
804 (nnheader-parse-naked-head)))))
805 (message-yank-original)
806 (setq beg (or beg (mark t))))
811 ;; Replace with the gathered references.
815 (message-narrow-to-headers)
816 (let ((case-fold-search t))
817 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
819 (goto-char (point-max))))
821 (list (or (assq 'References message-header-format-alist)
822 '(References . message-shorten-references)))
823 (list (cons 'References
824 (mapconcat 'identity (nreverse refs) " "))))
825 (backward-delete-char 1))
831 (defun gnus-summary-cancel-article (&optional n symp)
832 "Cancel an article you posted.
833 Uses the process-prefix convention. If given the symbolic
834 prefix `a', cancel using the standard posting method; if not
835 post using the current select method."
836 (interactive (gnus-interactive "P\ny"))
837 (let ((articles (gnus-summary-work-articles n))
840 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
842 (while (setq article (pop articles))
843 (when (gnus-summary-select-article t nil nil article)
844 (when (gnus-eval-in-buffer-window gnus-article-buffer
846 (set-buffer gnus-original-article-buffer)
847 (message-cancel-news)))
848 (gnus-summary-mark-as-read article gnus-canceled-mark)
849 (gnus-cache-remove-article 1))
850 (gnus-article-hide-headers-if-wanted))
851 (gnus-summary-remove-process-mark article))))
853 (defun gnus-summary-supersede-article ()
854 "Compose an article that will supersede a previous article.
855 This is done simply by taking the old article and adding a Supersedes
856 header line with the old Message-ID."
858 (let ((article (gnus-summary-article-number)))
859 (gnus-setup-message 'reply-yank
860 (gnus-summary-select-article t)
861 (set-buffer gnus-original-article-buffer)
865 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
867 (set-buffer ,gnus-summary-buffer)
868 (gnus-cache-possibly-remove-article ,article nil nil nil t)
869 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
870 message-send-actions))))
874 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
875 ;; make a copy of the article buffer with all text properties removed
876 ;; this copy is in the buffer gnus-article-copy.
877 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
878 ;; this buffer should be passed to all mail/news reply/post routines.
879 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
881 (set-buffer gnus-article-copy)
882 (set-buffer-multibyte t))
883 (let ((article-buffer (or article-buffer gnus-article-buffer))
885 (if (not (and (get-buffer article-buffer)
886 (gnus-buffer-exists-p article-buffer)))
887 (error "Can't find any article buffer")
889 (set-buffer article-buffer)
890 (let ((gnus-newsgroup-charset (or gnus-article-charset
891 gnus-newsgroup-charset))
892 (gnus-newsgroup-ignored-charsets
893 (or gnus-article-ignored-charsets
894 gnus-newsgroup-ignored-charsets)))
896 ;; Copy over the (displayed) article buffer, delete
897 ;; hidden text and remove text properties.
899 (copy-to-buffer gnus-article-copy (point-min) (point-max))
900 (set-buffer gnus-article-copy)
901 ;; There's invisible and intangible text in T-gnus. Especially,
902 ;; if there is a boundary line (X-Boundary: ------------------),
903 ;; in the end of a header, it will cause a serious problem.
904 (add-text-properties (point-min) (point-max)
905 '(invisible nil intangible nil))
908 (delete-region (point) (point-max))
909 (insert yank-string))
910 ;; Encode bitmap smileys to ordinary text.
911 ;; Possibly, the original text might be restored.
912 (static-unless (featurep 'xemacs)
913 (when (featurep 'smiley-mule)
914 (smiley-encode-buffer)))
915 (gnus-article-delete-text-of-type 'annotation)
916 (gnus-remove-text-with-property 'gnus-prev)
917 (gnus-remove-text-with-property 'gnus-next)
918 (gnus-remove-text-with-property 'gnus-decoration)
919 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
922 (static-if (featurep 'xemacs)
923 ;; Revome smiley extents for (possibly) XEmacs 21.1.
925 (buffer-substring-no-properties (point-min)
927 (buffer-substring-no-properties (point-min) (point-max)))
929 ;; Find the original headers.
930 (set-buffer gnus-original-article-buffer)
931 (goto-char (point-min))
932 (while (looking-at message-unix-mail-delimiter)
934 (let ((mail-header-separator ""))
936 end (or (message-goto-body)
937 ;; There may be just a header.
939 ;; Delete the headers from the displayed articles.
940 (set-buffer gnus-article-copy)
941 (let ((mail-header-separator ""))
942 (delete-region (goto-char (point-min))
943 (or (message-goto-body) (point-max))))
944 ;; Insert the original article headers.
945 (insert-buffer-substring gnus-original-article-buffer beg end)
947 (let ((gnus-article-decode-hook
948 (delq 'article-decode-charset
949 (copy-sequence gnus-article-decode-hook))))
950 ;; Needed for T-gnus.
951 (add-hook 'gnus-article-decode-hook
952 'article-decode-encoded-words)
953 (run-hooks 'gnus-article-decode-hook)))))
956 (defun gnus-post-news (post &optional group header article-buffer yank subject
959 (gnus-copy-article-buffer))
960 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
961 (gnus-article-yanked-articles yank)
962 (add-to-list gnus-add-to-list))
963 (gnus-setup-message (cond (yank 'reply-yank)
964 (article-buffer 'reply)
966 (let* ((group (or group gnus-newsgroup-name))
967 (charset (gnus-group-name-charset nil group))
969 to-address to-group mailing-list to-list
972 (setq to-address (gnus-parameter-to-address group)
973 to-group (gnus-group-find-parameter group 'to-group)
974 to-list (gnus-parameter-to-list group)
975 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
976 mailing-list (when gnus-mailing-list-groups
977 (string-match gnus-mailing-list-groups group))
978 group (gnus-group-name-decode (gnus-group-real-name group)
980 (if (or (and to-group
981 (gnus-news-group-p to-group))
984 (and (gnus-news-group-p
985 (or pgroup gnus-newsgroup-name)
986 (or header gnus-current-article))
992 (message-news (or to-group group))
993 (set-buffer gnus-article-copy)
994 (gnus-msg-treat-broken-reply-to)
995 (message-followup (if (or newsgroup-p force-news)
996 (if (save-restriction
997 (article-narrow-to-head)
998 (message-fetch-field "newsgroups"))
1005 (message-mail (or to-address to-list))
1006 ;; Arrange for mail groups that have no `to-address' to
1007 ;; get that when the user sends off the mail.
1008 (when (and (not to-list)
1011 (push (list 'gnus-inews-add-to-address pgroup)
1012 message-send-actions)))
1013 (set-buffer gnus-article-copy)
1014 (gnus-msg-treat-broken-reply-to)
1015 (message-wide-reply to-address)))
1017 (gnus-inews-yank-articles yank))))))
1019 (defun gnus-msg-treat-broken-reply-to (&optional force)
1020 "Remove the Reply-to header if broken-reply-to."
1022 (gnus-group-find-parameter
1023 gnus-newsgroup-name 'broken-reply-to))
1025 (message-narrow-to-head)
1026 (message-remove-header "reply-to"))))
1028 (defun gnus-post-method (arg group &optional silent)
1029 "Return the posting method based on GROUP and ARG.
1030 If SILENT, don't prompt the user."
1031 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1033 (group-method (gnus-find-method-for-group group)))
1035 ;; If the group-method is nil (which shouldn't happen) we use
1036 ;; the default method.
1037 ((null group-method)
1038 (or (and (listp gnus-post-method) ;If not current/native/nil
1039 (not (listp (car gnus-post-method))) ; and not a list of methods
1040 gnus-post-method) ;then use it.
1042 message-post-method))
1043 ;; We want the inverse of the default
1044 ((and arg (not (eq arg 0)))
1045 (if (eq gnus-post-method 'current)
1048 ;; We query the user for a post method.
1050 (and (listp gnus-post-method)
1051 (listp (car gnus-post-method))))
1053 ;; Collect all methods we know about.
1055 (when (listp gnus-post-method)
1056 (if (listp (car gnus-post-method))
1058 (list gnus-post-method)))
1059 gnus-secondary-select-methods
1060 (mapcar 'cdr gnus-server-alist)
1061 (mapcar 'car gnus-opened-servers)
1062 (list gnus-select-method)
1063 (list group-method)))
1064 method-alist post-methods method)
1065 ;; Weed out all mail methods.
1067 (setq method (gnus-server-get-method "" (pop methods)))
1068 (when (and (or (gnus-method-option-p method 'post)
1069 (gnus-method-option-p method 'post-mail))
1070 (not (member method post-methods)))
1071 (push method post-methods)))
1072 ;; Create a name-method alist.
1076 (if (equal (cadr m) "")
1077 (list (symbol-name (car m)) m)
1078 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1083 (setq gnus-last-posting-server
1085 gnus-last-posting-server)
1086 ;; Just use the last value.
1087 gnus-last-posting-server
1089 "Posting method: " method-alist nil t
1090 (cons (or gnus-last-posting-server "") 0))))
1092 ;; Override normal method.
1093 ((and (eq gnus-post-method 'current)
1094 (not (memq (car group-method) gnus-discouraged-post-methods))
1095 (gnus-get-function group-method 'request-post t))
1098 ;; Use gnus-post-method.
1099 ((listp gnus-post-method) ;A method...
1100 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1102 ;; Use the normal select method (nil or native).
1103 (t gnus-select-method))))
1106 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1108 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
1109 variable `mime-edit-user-agent-value' is bound, the value will be
1110 included in the return value. If MAX-COLUMN is specified, the return
1111 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
1112 whether a newline should be inserted in front of each product-token.
1113 If the value is t or `hard', it works strictly. Otherwise, if it is
1114 non-nil (e.g. `soft'), it works semi-strictly.
1116 Here is an example of how to use this function:
1118 \(add-hook 'gnus-message-setup-hook
1120 (setq message-user-agent nil)
1123 (message-narrow-to-headers)
1124 (goto-char (point-max))
1125 (insert \"User-Agent: \"
1126 (gnus-message-make-user-agent t 76 'soft)
1129 (let ((user-agent (if (and include-mime-info
1130 (boundp 'mime-edit-user-agent-value))
1131 (concat (gnus-extended-version)
1133 mime-edit-user-agent-value)
1134 (gnus-extended-version))))
1136 (unless (natnump max-column)
1137 (setq max-column 76))
1139 (set-buffer-multibyte t)
1140 (insert (mapconcat 'identity (split-string user-agent) " "))
1141 (goto-char (point-min))
1143 start agent agents width element swidth)
1144 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1145 (setq start (match-beginning 0))
1146 (if (eq (char-after start) ?\()
1150 (push (buffer-substring start (point)) agent))
1152 (push (nreverse agent) agents))
1153 (setq agent (list (match-string 1)))))
1155 (push (nreverse agent) agents))
1156 (setq agents (nreverse agents))
1157 (if (> (+ 12 (string-width (caar agents))) max-column)
1158 (setq user-agent "\n"
1163 (setq agent (car agents)
1164 agents (cdr agents))
1165 (when (and (not bol)
1166 (or (memq newline-product '(t hard))
1167 (and newline-product
1169 (string-width (mapconcat 'identity
1172 (setq user-agent (concat user-agent "\n")
1176 (setq element (car agent)
1177 swidth (string-width element)
1180 (setq user-agent (if (member user-agent '("" "\n"))
1181 (concat user-agent element)
1182 (concat user-agent " " element))
1183 width (+ width 1 swidth)
1185 (if (> (+ width 1 swidth) max-column)
1186 (setq user-agent (concat user-agent "\n " element)
1188 (setq user-agent (concat user-agent " " element)
1189 width (+ width 1 swidth)))))))))
1194 ;;; Gnus Mail Functions
1197 ;;; Mail reply commands of Gnus summary mode
1199 (defun gnus-summary-reply (&optional yank wide very-wide)
1200 "Start composing a mail reply to the current message.
1201 If prefix argument YANK is non-nil, the original article is yanked
1203 If WIDE, make a wide reply.
1204 If VERY-WIDE, make a very wide reply."
1206 (list (and current-prefix-arg
1207 (gnus-summary-work-articles 1))))
1208 ;; Allow user to require confirmation before replying by mail to the
1209 ;; author of a news article (or mail message).
1211 (not (or (gnus-news-group-p gnus-newsgroup-name)
1212 gnus-confirm-treat-mail-like-news))
1213 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1214 (string-match gnus-confirm-mail-reply-to-news
1215 gnus-newsgroup-name))
1216 ((functionp gnus-confirm-mail-reply-to-news)
1217 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1218 (t gnus-confirm-mail-reply-to-news)))
1219 (y-or-n-p "Really reply by mail to article author? "))
1221 (if (listp (car yank))
1224 (gnus-article-reply (or article (gnus-summary-article-number)))
1225 (gnus-article-yanked-articles yank)
1227 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1229 (gnus-summary-goto-subject article))
1230 (gnus-setup-message (if yank 'reply-yank 'reply)
1232 (gnus-summary-select-article)
1233 (dolist (article very-wide)
1234 (gnus-summary-select-article nil nil nil article)
1236 (set-buffer (gnus-copy-article-buffer))
1237 (gnus-msg-treat-broken-reply-to)
1239 (message-narrow-to-head)
1240 (setq headers (concat headers (buffer-string)))))))
1241 (set-buffer (gnus-copy-article-buffer))
1242 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1244 (message-narrow-to-head)
1248 (goto-char (point-max)))
1249 (message-reply nil wide)
1251 (gnus-inews-yank-articles yank))
1252 (gnus-summary-handle-replysign)))))
1254 (defun gnus-summary-handle-replysign ()
1255 "Check the various replysign variables and take action accordingly."
1256 (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1257 (let (signed encrypted)
1259 (set-buffer gnus-article-buffer)
1260 (setq signed (memq 'signed gnus-article-wash-types))
1261 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1262 (cond ((and gnus-message-replyencrypt encrypted)
1263 (mml-secure-message mml-default-encrypt-method
1264 (if gnus-message-replysignencrypted
1267 ((and gnus-message-replysign signed)
1268 (mml-secure-message mml-default-sign-method 'sign))))))
1270 (defun gnus-summary-reply-with-original (n &optional wide)
1271 "Start composing a reply mail to the current message.
1272 The original article will be yanked."
1274 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1276 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1277 "Like `gnus-summary-reply' except removing reply-to field.
1278 If prefix argument YANK is non-nil, the original article is yanked
1280 If WIDE, make a wide reply.
1281 If VERY-WIDE, make a very wide reply."
1283 (list (and current-prefix-arg
1284 (gnus-summary-work-articles 1))))
1285 (let ((gnus-msg-force-broken-reply-to t))
1286 (gnus-summary-reply yank wide very-wide)))
1288 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1289 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1290 The original article will be yanked."
1292 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1294 (defun gnus-summary-wide-reply (&optional yank)
1295 "Start composing a wide reply mail to the current message.
1296 If prefix argument YANK is non-nil, the original article is yanked
1299 (list (and current-prefix-arg
1300 (gnus-summary-work-articles 1))))
1301 (gnus-summary-reply yank t))
1303 (defun gnus-summary-wide-reply-with-original (n)
1304 "Start composing a wide reply mail to the current message.
1305 The original article will be yanked."
1307 (gnus-summary-reply-with-original n t))
1309 (defun gnus-summary-very-wide-reply (&optional yank)
1310 "Start composing a very wide reply mail to the current message.
1311 If prefix argument YANK is non-nil, the original article is yanked
1314 (list (and current-prefix-arg
1315 (gnus-summary-work-articles 1))))
1316 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1318 (defun gnus-summary-very-wide-reply-with-original (n)
1319 "Start composing a very wide reply mail to the current message.
1320 The original article will be yanked."
1323 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1325 (defun gnus-summary-mail-forward (&optional full-headers post)
1326 "Forward the current message(s) to another user.
1327 If process marks exist, forward all marked messages;
1328 If FULL-HEADERS (the prefix), include full headers when forwarding.
1330 Note that this function definition for T-gnus is totally different
1331 from the original Gnus."
1333 (if (cdr (gnus-summary-work-articles nil))
1334 ;; Process marks are given.
1335 (gnus-summary-digest-mail-forward nil post)
1336 ;; No process marks.
1337 (let* ((gnus-article-reply (gnus-summary-article-number))
1338 (gnus-article-yanked-articles (list gnus-article-reply))
1340 (message-included-forward-headers
1341 (if full-headers "" message-included-forward-headers)))
1342 (gnus-setup-message 'forward
1343 (gnus-summary-select-article)
1344 (setq charset default-mime-charset)
1345 (set-buffer gnus-original-article-buffer)
1346 (make-local-variable 'default-mime-charset)
1347 (setq default-mime-charset charset)
1348 (message-forward post)))))
1350 (defun gnus-summary-digest-mail-forward (&optional n post)
1351 "Digests and forwards all articles in this series.
1352 If N is a positive number, forward the N next articles.
1353 If N is a negative number, forward the N previous articles.
1354 If N is nil and any articles have been marked with the process mark,
1355 forward those articles instead.
1356 Optional POST will use news to forward instead of mail."
1358 (let* ((articles (gnus-summary-work-articles n))
1359 (gnus-article-yanked-articles (copy-sequence articles))
1360 (topics "Topics:\n")
1361 subject article frame)
1362 (when (car articles)
1363 (gnus-setup-message 'forward
1364 (gnus-summary-select-article)
1366 (setq articles (sort articles '<)
1367 subject "Digested Articles")
1368 (with-current-buffer gnus-original-article-buffer
1369 (setq subject (message-make-forward-subject))))
1371 (message-news nil subject)
1372 (message-mail nil subject))
1373 (when (and message-use-multi-frames (cdr articles))
1374 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1376 (while (setq article (pop articles))
1377 (save-window-excursion
1378 (set-buffer gnus-summary-buffer)
1379 (gnus-summary-select-article nil nil nil article)
1380 (setq topics (concat topics " "
1381 (mail-header-subject gnus-current-headers)
1383 (gnus-summary-remove-process-mark article))
1385 (select-frame frame))
1386 (insert (mime-make-tag "message" "rfc822") "\n")
1387 (narrow-to-region (point) (point))
1388 (insert-buffer-substring gnus-original-article-buffer)
1390 (article-narrow-to-head)
1391 (message-remove-header message-included-forward-headers t nil t))
1392 (goto-char (point-max))
1398 (mime-edit-enclose-digest-region (point)(mark t))))))
1400 (defun gnus-summary-digest-post-forward (&optional n)
1401 "Digest and forwards all articles in this series to a newsgroup.
1402 If N is a positive number, forward the N next articles.
1403 If N is a negative number, forward the N previous articles.
1404 If N is nil and any articles have been marked with the process mark,
1405 forward those articles instead."
1407 (gnus-summary-digest-mail-forward n t))
1409 (defun gnus-summary-resend-message (address n)
1410 "Resend the current article to ADDRESS."
1412 (list (message-read-from-minibuffer
1413 "Resend message(s) to: "
1414 (when (and gnus-summary-resend-default-address
1415 (gnus-buffer-live-p gnus-original-article-buffer))
1416 ;; If some other article is currently selected, the
1417 ;; initial-contents is wrong. Whatever, it is just the
1418 ;; initial-contents.
1419 (with-current-buffer gnus-original-article-buffer
1420 (nnmail-fetch-field "to"))))
1421 current-prefix-arg))
1422 (let ((articles (gnus-summary-work-articles n))
1424 (while (setq article (pop articles))
1425 (gnus-summary-select-article nil nil nil article)
1427 (set-buffer gnus-original-article-buffer)
1428 (message-resend address))
1429 (gnus-summary-mark-article-as-forwarded article))))
1431 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1432 (defun gnus-summary-resend-message-edit ()
1433 "Resend an article that has already been sent.
1434 A new buffer will be created to allow the user to modify body and
1435 contents of the message, and then, everything will happen as when
1436 composing a new message."
1438 (let ((article (gnus-summary-article-number)))
1439 (gnus-setup-message 'reply-yank
1440 (gnus-summary-select-article t)
1441 (set-buffer gnus-original-article-buffer)
1442 (let ((cur (current-buffer))
1443 (to (message-fetch-field "to")))
1444 ;; Get a normal message buffer.
1445 (message-pop-to-buffer (message-buffer-name "Resend" to))
1446 (insert-buffer-substring cur)
1448 ;; T-gnus change: Use MIME-Edit to recompose a message.
1450 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1451 (fset 'mime-edit-decode-single-part-in-buffer
1452 (lambda (&rest args)
1453 (if (let ((content-type (car args)))
1454 (and (eq 'message (mime-content-type-primary-type
1456 (eq 'rfc822 (mime-content-type-subtype
1458 (setcar (cdr args) 'not-decode-text))
1461 (mime-edit-again nil t)
1462 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1463 (message-narrow-to-head-1)
1464 (insert "From: " (message-make-from) "\n")
1465 (while (re-search-forward "^From:" nil t)
1467 (insert "Original-"))
1468 (message-remove-header "^>From[\t ]" t)
1470 ;; Gnus will generate a new one when sending.
1471 (message-remove-header "Message-ID")
1472 (message-remove-header message-ignored-resent-headers t)
1473 ;; Remove unwanted headers.
1474 (goto-char (point-max))
1475 (insert mail-header-separator)
1476 (goto-char (point-min))
1477 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1481 (defun gnus-summary-post-forward (&optional full-headers)
1482 "Forward the current article to a newsgroup.
1483 If FULL-HEADERS (the prefix), include full headers when forwarding."
1485 (gnus-summary-mail-forward full-headers t))
1487 (defvar gnus-nastygram-message
1488 "The following article was inappropriately posted to %s.\n\n"
1489 "Format string to insert in nastygrams.
1490 The current group name will be inserted at \"%s\".")
1492 (defun gnus-summary-mail-nastygram (n)
1493 "Send a nastygram to the author of the current article."
1495 (when (or gnus-expert-user
1497 "Really send a nastygram to the author of the current article? "))
1498 (let ((group gnus-newsgroup-name))
1499 (gnus-summary-reply-with-original n)
1500 (set-buffer gnus-message-buffer)
1502 (insert (format gnus-nastygram-message group))
1503 (message-send-and-exit))))
1505 (defun gnus-summary-mail-crosspost-complaint (n)
1506 "Send a complaint about crossposting to the current article(s)."
1508 (let ((articles (gnus-summary-work-articles n))
1510 (while (setq article (pop articles))
1511 (set-buffer gnus-summary-buffer)
1512 (gnus-summary-goto-subject article)
1513 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1514 newsgroups followup-to)
1515 (gnus-summary-select-article)
1516 (set-buffer gnus-original-article-buffer)
1517 (if (and (<= (length (message-tokenize-header
1519 (mail-fetch-field "newsgroups"))
1522 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1523 (not (member group (message-tokenize-header
1524 followup-to ", ")))))
1526 (gnus-message 1 "Followup-to restricted")
1527 (gnus-message 1 "Not a crossposted article"))
1528 (set-buffer gnus-summary-buffer)
1529 (gnus-summary-reply-with-original 1)
1530 (set-buffer gnus-message-buffer)
1532 (insert (format gnus-crosspost-complaint newsgroups group))
1533 (message-goto-subject)
1534 (re-search-forward " *$")
1535 (replace-match " (crosspost notification)" t t)
1536 (gnus-deactivate-mark)
1537 (when (gnus-y-or-n-p "Send this complaint? ")
1538 (message-send-and-exit)))))))
1540 (defun gnus-mail-parse-comma-list ()
1543 (skip-chars-forward " ")
1546 (skip-chars-forward "^,")
1551 (narrow-to-region beg (point))
1554 (while (search-forward "\"" nil t)
1558 (skip-chars-forward ",")
1559 (skip-chars-forward "^,"))
1560 (skip-chars-backward " ")
1561 (push (buffer-substring beg (point))
1563 (skip-chars-forward "^,")
1564 (skip-chars-forward ", "))
1567 (defun gnus-inews-add-to-address (group)
1568 (let ((to-address (mail-fetch-field "to")))
1569 (when (and to-address
1571 ;; This mail group doesn't have a `to-list', so we add one
1573 (when (gnus-y-or-n-p
1574 (format "Do you want to add this as `to-list': %s " to-address))
1575 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1577 (defun gnus-put-message ()
1578 "Put the current message in some group and return to Gnus."
1580 (let ((reply gnus-article-reply)
1581 (winconf gnus-prev-winconf)
1582 (group gnus-newsgroup-name))
1584 (not (gnus-group-read-only-p group)))
1585 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1587 (when (gnus-gethash group gnus-newsrc-hashtb)
1588 (error "No such group: %s" group))
1592 (message-narrow-to-headers)
1593 (let ((gnus-deletable-headers nil))
1594 (message-generate-headers
1595 (if (message-news-p)
1596 message-required-news-headers
1597 message-required-mail-headers)))
1598 (goto-char (point-max))
1599 (if (string-match " " group)
1600 (insert "Gcc: \"" group "\"\n")
1601 (insert "Gcc: " group "\n"))
1604 (when (and (get-buffer gnus-group-buffer)
1605 (gnus-buffer-exists-p (car-safe reply))
1607 (set-buffer (car reply))
1608 (gnus-summary-mark-article-as-replied (cdr reply)))
1610 (set-window-configuration winconf))))
1612 (defun gnus-article-mail (yank)
1613 "Send a reply to the address near point.
1614 If YANK is non-nil, include the original article."
1618 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1619 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1621 (gnus-msg-mail address)
1623 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1625 (defvar nntp-server-type)
1627 "Send a bug report to the Gnus maintainers."
1629 (unless (gnus-alive-p)
1630 (error "Gnus has been shut down"))
1631 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1632 (unless (message-mail-user-agent)
1633 (message-pop-to-buffer "*Gnus Bug*")
1634 (delete-other-windows)
1635 (when gnus-bug-create-help-buffer
1636 (switch-to-buffer "*Gnus Help Bug*")
1638 (insert gnus-bug-message)
1639 (goto-char (point-min))
1641 (set-buffer "*Gnus Bug*")))
1642 (let ((message-this-is-mail t))
1643 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1644 (when gnus-bug-create-help-buffer
1645 (push `(gnus-bug-kill-buffer) message-send-actions))
1646 (goto-char (point-min))
1647 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1649 (insert gnus-product-name " " gnus-version-number
1650 " (r" gnus-revision-number ") "
1651 "based on " gnus-original-product-name " v"
1652 gnus-original-version-number "\n"
1653 (emacs-version) "\n")
1654 (when (and (boundp 'nntp-server-type)
1655 (stringp nntp-server-type))
1656 (insert nntp-server-type))
1657 (insert "\n\n\n\n\n")
1658 (let (mime-content-types)
1659 (mime-edit-insert-tag
1660 "application" "emacs-lisp"
1661 "\nContent-Disposition: inline\nContent-Description: User settings"))
1662 (insert (with-temp-buffer
1665 (let (mime-content-types)
1666 (mime-edit-insert-tag "text" "plain"))
1667 (goto-char (point-min))
1668 (search-forward "Subject: " nil t)
1671 (defun gnus-bug-kill-buffer ()
1672 (when (get-buffer "*Gnus Help Bug*")
1673 (kill-buffer "*Gnus Help Bug*")))
1675 (defun gnus-summary-yank-message (buffer n)
1676 "Yank the current article into a composed message."
1678 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1679 current-prefix-arg))
1680 (when (gnus-buffer-live-p buffer)
1681 (let ((summary-frame (selected-frame))
1682 (message-frame (when (static-if (featurep 'xemacs)
1683 (device-on-window-system-p)
1685 (let ((window (get-buffer-window buffer t)))
1687 (window-frame window)))))
1688 (separator (concat "^" (regexp-quote mail-header-separator)
1690 (gnus-summary-iterate n
1691 (gnus-summary-select-article)
1692 (gnus-copy-article-buffer)
1693 (when (frame-live-p message-frame)
1694 (raise-frame message-frame)
1695 (select-frame message-frame))
1696 (with-current-buffer buffer
1697 (when (save-excursion
1699 (let (case-fold-search)
1700 (and (not (re-search-backward separator nil t))
1701 (re-search-forward separator nil t))))
1702 (goto-char (match-end 0)))
1703 (message-yank-buffer gnus-article-copy))
1704 (select-frame summary-frame))
1705 (when (frame-live-p message-frame)
1706 (select-frame message-frame)))))
1708 (defun gnus-debug ()
1709 "Attempts to go through the Gnus source file and report what variables have been changed.
1710 The source file has to be in the Emacs load path."
1712 (let ((files gnus-debug-files)
1714 file expr olist sym)
1715 (gnus-message 4 "Please wait while we snoop your variables...")
1716 ;; Go through all the files looking for non-default values for variables.
1719 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1722 (when (and (setq file (locate-library (pop files)))
1723 (file-exists-p file))
1724 (insert-file-contents file)
1725 (goto-char (point-min))
1726 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1727 (gnus-message 4 "Malformed sources in file %s" file)
1728 (narrow-to-region (point-min) (point))
1729 (goto-char (point-min))
1730 (while (setq expr (ignore-errors (read (current-buffer))))
1732 (and (memq (car expr) '(defvar defcustom defvoo))
1733 (stringp (nth 3 expr))
1734 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1735 (or (not (boundp (nth 1 expr)))
1736 (not (equal (eval (nth 2 expr))
1737 (symbol-value (nth 1 expr)))))
1738 (push (nth 1 expr) olist)))))))
1739 (kill-buffer (current-buffer)))
1740 (when (setq olist (nreverse olist))
1741 (insert ";----------------- Environment follows ------------------\n\n"))
1743 (if (boundp (car olist))
1745 (pp `(setq ,(car olist)
1746 ,(if (or (consp (setq sym (symbol-value (car olist))))
1748 (not (or (eq sym nil)
1750 (list 'quote (symbol-value (car olist)))
1751 (symbol-value (car olist))))
1753 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1754 (setq olist (cdr olist)))
1755 ;; Remove any control chars - they seem to cause trouble for some
1756 ;; mailers. (Byte-compiled output from the stuff above.)
1758 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1759 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1761 ;; Break MIME tags purposely.
1763 (while (re-search-forward mime-edit-tag-regexp nil t)
1764 (goto-char (1+ (match-beginning 0)))
1767 ;;; Treatment of rejected articles.
1770 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1771 "Re-mail the current message.
1772 This only makes sense if the current message is a bounce message than
1773 contains some mail you have written which has been bounced back to
1775 If FETCH, try to fetch the article that this is a reply to, if indeed
1778 (gnus-summary-select-article t)
1779 (set-buffer gnus-original-article-buffer)
1780 (gnus-setup-message 'compose-bounce
1781 (let* ((references (mail-fetch-field "references"))
1782 (parent (and references (gnus-parent-id references))))
1784 ;; If there are references, we fetch the article we answered to.
1786 (gnus-summary-refer-article parent)
1787 (gnus-summary-show-all-headers)))))
1791 (defun gnus-inews-group-method (group)
1793 ;; If the group doesn't exist, we assume
1794 ;; it's an archive group...
1795 ((and (null (gnus-get-info group))
1796 (eq (car (gnus-server-to-method gnus-message-archive-method))
1797 (car (gnus-server-to-method (gnus-group-method group)))))
1798 gnus-message-archive-method)
1800 ((gnus-info-method (gnus-get-info group))
1801 (gnus-info-method (gnus-get-info group)))
1803 (t (gnus-server-to-method (gnus-group-method group)))))
1805 ;; Do Gcc handling, which copied the message over to some group.
1806 (defun gnus-inews-do-gcc (&optional gcc)
1810 (message-narrow-to-headers)
1811 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1812 (coding-system-for-write 'raw-text)
1813 (output-coding-system 'raw-text)
1814 groups group method group-art
1815 mml-externalize-attachments)
1817 (message-remove-header "gcc")
1819 (setq groups (message-unquote-tokens
1820 (message-tokenize-header gcc " ,")))
1821 ;; Copy the article over to some group(s).
1822 (while (setq group (pop groups))
1823 (unless (gnus-check-server
1824 (setq method (gnus-inews-group-method group)))
1825 (error "Can't open server %s" (if (stringp method) method
1827 (unless (gnus-request-group group nil method)
1828 (gnus-request-create-group group method))
1829 (setq mml-externalize-attachments
1830 (if (stringp gnus-gcc-externalize-attachments)
1831 (string-match gnus-gcc-externalize-attachments group)
1832 gnus-gcc-externalize-attachments))
1834 (nnheader-set-temp-buffer " *acc*")
1835 (insert-buffer-substring message-encoding-buffer)
1836 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1837 (goto-char (point-min))
1838 (when (re-search-forward
1839 (concat "^" (regexp-quote mail-header-separator) "$")
1841 (replace-match "" t t ))
1842 (unless (setq group-art
1843 (gnus-request-accept-article group method t t))
1844 (gnus-message 1 "Couldn't store article in group %s: %s"
1845 group (gnus-status-message method))
1847 (when (and group-art
1848 ;; FIXME: Should gcc-mark-as-read work when
1849 ;; Gnus is not running?
1851 (or gnus-gcc-mark-as-read
1852 gnus-inews-mark-gcc-as-read))
1853 (gnus-group-mark-article-read group (cdr group-art)))
1854 (kill-buffer (current-buffer)))))))))
1856 (defun gnus-inews-insert-gcc ()
1857 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1860 (message-narrow-to-headers)
1861 (let* ((group gnus-outgoing-message-group)
1863 ((gnus-functionp group)
1865 ((or (stringp group) (list group))
1870 (if (string-match " " gcc)
1871 (concat "\"" gcc "\"")
1873 (mapconcat (lambda (group)
1874 (if (string-match " " group)
1875 (concat "\"" group "\"")
1880 (defun gnus-inews-insert-archive-gcc (&optional group)
1881 "Insert the Gcc to say where the article is to be archived."
1882 (let* ((var gnus-message-archive-group)
1883 (group (or group gnus-newsgroup-name ""))
1885 (and gnus-newsgroup-name
1886 (not (equal gnus-newsgroup-name ""))
1887 (gnus-group-find-parameter
1888 gnus-newsgroup-name 'gcc-self)))
1892 ((null gnus-message-archive-method)
1896 ;; Just a single group.
1899 ;; We don't want this.
1901 ((and (listp var) (stringp (car var)))
1902 ;; A list of groups.
1904 ((gnus-functionp var)
1906 (funcall var group))
1908 ;; An alist of regexps/functions/forms.
1913 ((stringp (caar var))
1915 (when (string-match (caar var) group)
1917 ((gnus-functionp (car var))
1919 (funcall (car var) group))
1921 (eval (car var)))))))
1922 (setq var (cdr var)))
1925 (when (or groups gcc-self-val)
1926 (when (stringp groups)
1927 (setq groups (list groups)))
1930 (message-narrow-to-headers)
1931 (goto-char (point-max))
1934 ;; Use the `gcc-self' param value instead.
1937 (if (stringp gcc-self-val)
1938 (if (string-match " " gcc-self-val)
1939 (concat "\"" gcc-self-val "\"")
1941 (if (string-match " " group)
1942 (concat "\"" group "\"")
1944 (if (not (eq gcc-self-val 'none))
1949 ;; Use the list of groups.
1950 (while (setq name (pop groups))
1951 (let ((str (if (string-match ":" name)
1953 (gnus-group-prefixed-name
1954 name gnus-message-archive-method))))
1955 (insert (if (string-match " " str)
1956 (concat "\"" str "\"")
1962 (defun gnus-mailing-list-followup-to ()
1963 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1964 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1965 (list-post (gnus-fetch-original-field "list-post")))
1966 (when (and list-post
1967 (string-match "mailto:\\([^>]+\\)" list-post))
1968 (setq list-post (match-string 1 list-post)))
1974 (defun gnus-configure-posting-styles (&optional group-name)
1975 "Configure posting styles according to `gnus-posting-styles'."
1976 (unless gnus-inhibit-posting-styles
1977 (let ((group (or group-name gnus-newsgroup-name ""))
1978 (styles gnus-posting-styles)
1979 style match attribute results
1981 ;; If the group has a posting-style parameter, add it at the end with a
1982 ;; regexp matching everything, to be sure it takes precedence over all
1984 (when gnus-newsgroup-name
1985 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1987 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1988 ;; Go through all styles and look for matches.
1989 (dolist (style styles)
1990 (setq match (pop style))
1991 (goto-char (point-min))
1994 ;; Regexp string match on the group name.
1995 (string-match match group))
1997 ;; Obsolete format of header match.
1998 (and (gnus-buffer-live-p gnus-article-copy)
1999 (with-current-buffer gnus-article-copy
2000 (let ((header (message-fetch-field (pop style))))
2002 (string-match (pop style) header))))))
2003 ((or (symbolp match)
2004 (gnus-functionp match))
2006 ((gnus-functionp match)
2007 ;; Function to be called.
2010 ;; Variable to be checked.
2011 (symbol-value match))))
2014 ((eq (car match) 'header)
2015 ;; New format of header match.
2016 (and (gnus-buffer-live-p gnus-article-copy)
2017 (with-current-buffer gnus-article-copy
2018 (let ((header (message-fetch-field (nth 1 match))))
2020 (string-match (nth 2 match) header))))))
2022 ;; This is a form to be evaled.
2024 ;; We have a match, so we set the variables.
2025 (setq style (gnus-configure-posting-style style nil))
2026 (dolist (attribute style)
2027 (setq results (delq (assoc (car attribute) results) results))
2028 (push attribute results))))
2029 ;; Now we have all the styles, so we insert them.
2030 (setq name (assq 'name results)
2031 address (assq 'address results))
2032 (setq results (delq name (delq address results)))
2033 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
2034 (make-local-hook 'message-setup-hook)
2035 (setq results (sort results (lambda (x y)
2036 (string-lessp (car x) (car y)))))
2037 (dolist (result results)
2038 (add-hook 'message-setup-hook
2040 ((eq 'eval (car result))
2042 ((eq 'body (car result))
2046 (insert ,(cdr result)))))
2047 ((eq 'signature (car result))
2048 (set (make-local-variable 'message-signature) nil)
2049 (set (make-local-variable 'message-signature-file) nil)
2050 (if (not (cdr result))
2054 (let ((message-signature ,(cdr result)))
2055 (when message-signature
2056 (message-insert-signature)))))))
2059 (if (symbolp (car result))
2060 (capitalize (symbol-name (car result)))
2064 (message-remove-header ,header)
2065 (let ((value ,(cdr result)))
2068 (insert ,header ": " value)
2070 (insert "\n")))))))))
2072 (when (or name address)
2073 (add-hook 'message-setup-hook
2075 (set (make-local-variable 'user-mail-address)
2076 ,(or (cdr address) user-mail-address))
2077 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2079 ,(or (cdr address) user-mail-address)))
2081 (message-remove-header "From")
2083 (insert "From: " (message-make-from) "\n"))))
2086 ;; splitted from gnus-configure-posting-styles to allow recursive traversal.
2087 (defun gnus-configure-posting-style (style stack)
2088 "Parse one posting style STYLE and returns the value as an alist."
2089 (let (results element variable filep value v)
2090 (dolist (attribute style)
2091 (setq element (pop attribute)
2096 ((eq (car attribute) ':file)
2099 ((eq (car attribute) :value)
2103 ;; We get the value.
2108 ((or (symbolp value)
2109 (gnus-functionp value))
2110 (cond ((gnus-functionp value)
2113 (symbol-value value))))
2116 ;; Translate obsolescent value.
2118 ((eq element 'signature-file)
2119 (setq element 'signature
2121 ((eq element 'x-face-file)
2122 (setq element 'x-face
2124 ;; Get the contents of file elems.
2126 (setq v (with-temp-buffer
2127 (insert-file-contents v)
2128 (goto-char (point-max))
2132 (if (eq element 'import)
2134 (if (member v stack)
2135 (error "Circular import of \"%s\"" v))
2137 (nconc (nreverse (gnus-configure-posting-style
2138 (cdr (assoc v gnus-named-posting-styles))
2141 (push (cons element v) results)))
2142 (nreverse results)))
2144 (defun gnus-summary-execute-command-with-posting-style (style command)
2145 "Temporarily select a posting-style named STYLE and execute COMMAND."
2147 (let ((style (completing-read "Posting style: "
2148 gnus-named-posting-styles nil t)))
2152 (format "Command to execute with %s: " style))))))
2153 (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
2154 (call-interactively command)))
2157 ;;; @ for MIME Edit mode
2160 (defun gnus-maybe-setup-default-charset ()
2162 (and (boundp 'gnus-summary-buffer)
2163 (buffer-live-p gnus-summary-buffer)
2165 (set-buffer gnus-summary-buffer)
2166 default-mime-charset))))
2169 (make-local-variable 'default-mime-charset)
2170 (setq default-mime-charset charset)
2174 ;;; @ for MIME view mode
2177 (defun gnus-following-method (buf)
2178 (gnus-setup-message 'reply-yank
2180 (if (message-news-p)
2182 (message-reply nil 'wide))
2183 (let ((message-reply-buffer buf))
2184 (message-yank-original))
2185 (message-goto-body))
2189 ;;; Allow redefinition of functions.
2195 ;;; gnus-msg.el ends here