1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
37 (defcustom gnus-post-method 'current
38 "*Preferred method for posting USENET news.
40 If this variable is `current' (which is the default), Gnus will use
41 the \"current\" select method when posting. If it is `native', Gnus
42 will use the native select method when posting.
44 This method will not be used in mail groups and the like, only in
47 If not `native' nor `current', the value must be a valid method as discussed
48 in the documentation of `gnus-select-method'. It can also be a list of
49 methods. If that is the case, the user will be queried for what select
50 method to use when posting."
51 :group 'gnus-group-foreign
52 :link '(custom-manual "(gnus)Posting Server")
53 :type `(choice (const native)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defcustom gnus-outgoing-message-group nil
58 "*All outgoing messages will be put in this group.
59 If you want to store all your outgoing mail and articles in the group
60 \"nnml:archive\", you set this variable to that value. This variable
61 can also be a list of group names.
63 If you want to have greater control over what group to put each
64 message in, you can set this variable to a function that checks the
65 current newsgroup name and then returns a suitable group name (or list
68 :type '(choice (string :tag "Group")
71 (defcustom gnus-mailing-list-groups nil
72 "*Regexp matching groups that are really mailing lists.
73 This is useful when you're reading a mailing list that has been
74 gatewayed to a newsgroup, and you want to followup to an article in
79 (defcustom gnus-add-to-list nil
80 "*If non-nil, add a `to-list' parameter automatically."
84 (defcustom gnus-crosspost-complaint
87 You posted the article below with the following Newsgroups header:
91 The %s group, at least, was an inappropriate recipient
92 of this message. Please trim your Newsgroups header to exclude this
93 group before posting in the future.
98 "Format string to be inserted when complaining about crossposts.
99 The first %s will be replaced by the Newsgroups header;
100 the second with the current group name."
104 (defcustom gnus-message-setup-hook nil
105 "Hook run after setting up a message buffer."
109 (defcustom gnus-bug-create-help-buffer t
110 "*Should we create the *Gnus Help Bug* buffer?"
114 (defcustom gnus-posting-styles nil
115 "*Alist of styles to use when posting.
116 See Info node `(gnus)Posting Styles'."
118 :link '(custom-manual "(gnus)Posting Styles")
119 :type '(repeat (cons (choice (regexp)
122 (string :tag "Header")
123 (regexp :tag "Regexp"))
127 (choice (const signature)
128 (const signature-file)
135 (string :tag "Header"))
141 (defcustom gnus-gcc-mark-as-read nil
142 "If non-nil, automatically mark Gcc articles as read."
147 (defvar gnus-inews-mark-gcc-as-read nil
148 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
150 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
151 'gnus-gcc-mark-as-read)
153 (defcustom gnus-gcc-externalize-attachments nil
154 "Should local-file attachments be included as external parts in Gcc copies?
155 If it is `all', attach files as external parts;
156 if a regexp and matches the Gcc group name, attach files as external parts;
157 If nil, attach files as normal parts."
160 :type '(choice (const nil :tag "None")
161 (const all :tag "Any")
162 (string :tag "Regexp")))
164 (gnus-define-group-parameter
165 posting-charset-alist
168 "Return the permitted unencoded charsets for posting of GROUP."
169 :variable gnus-group-posting-charset-alist
171 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
172 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
173 (message-this-is-mail nil nil)
174 (message-this-is-news nil t))
176 "Alist of regexps and permitted unencoded charsets for posting.
177 Each element of the alist has the form (TEST HEADER BODY-LIST), where
178 TEST is either a regular expression matching the newsgroup header or a
180 HEADER is the charset which may be left unencoded in the header (nil
181 means encode all charsets),
182 BODY-LIST is a list of charsets which may be encoded using 8bit
183 content-transfer encoding in the body, or one of the special values
184 nil (always encode using quoted-printable) or t (always use 8bit).
186 Note that any value other than nil for HEADER infringes some RFCs, so
187 use this option with care."
188 :variable-group gnus-charset
190 '(repeat (list :tag "Permitted unencoded charsets"
192 (regexp :tag "Group")
193 (const :tag "Mail message" :value message-this-is-mail)
194 (const :tag "News article" :value message-this-is-news))
195 (choice :tag "Header"
196 (const :tag "None" nil)
197 (symbol :tag "Charset"))
199 (const :tag "Any" :value t)
200 (const :tag "None" :value nil)
201 (repeat :tag "Charsets"
202 (symbol :tag "Charset")))))
203 :parameter-type '(choice :tag "Permitted unencoded charsets"
206 :parameter-document "\
207 List of charsets that are permitted to be unencoded.")
209 (defcustom gnus-debug-files
210 '("gnus.el" "gnus-sum.el" "gnus-group.el"
211 "gnus-art.el" "gnus-start.el" "gnus-async.el"
212 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
213 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
214 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
215 "Files whose variables will be reported in `gnus-bug'."
218 :type '(repeat (string :tag "File")))
220 (defcustom gnus-debug-exclude-variables
221 '(mm-mime-mule-charset-alist
222 nnmail-split-fancy message-minibuffer-local-map)
223 "Variables that should not be reported in `gnus-bug'."
226 :type '(repeat (symbol :tag "Variable")))
228 (defcustom gnus-discouraged-post-methods
229 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
230 "A list of back ends that are not used in \"real\" newsgroups.
231 This variable is used only when `gnus-post-method' is `current'."
233 :group 'gnus-group-foreign
234 :type '(repeat (symbol :tag "Back end")))
236 (defcustom gnus-message-replysign
238 "Automatically sign replys to signed messages.
239 See also the `mml-default-sign-method' variable."
243 (defcustom gnus-message-replyencrypt
245 "Automatically encrypt replys to encrypted messages.
246 See also the `mml-default-encrypt-method' variable."
250 (defcustom gnus-message-replysignencrypted
252 "Setting this causes automatically encryped messages to also be signed."
256 (defcustom gnus-confirm-mail-reply-to-news nil
257 "If non-nil, Gnus requests confirmation when replying to news.
258 This is done because new users often reply by mistake when reading
263 (defcustom gnus-summary-resend-default-address t
264 "If non-nil, Gnus tries to suggest a default address to resend to.
265 If nil, the address field will always be empty after invoking
266 `gnus-summary-resend-message'."
270 ;;; Internal variables.
272 (defvar gnus-inhibit-posting-styles nil
273 "Inhibit the use of posting styles.")
275 (defvar gnus-article-yanked-articles nil)
276 (defvar gnus-message-buffer "*Mail Gnus*")
277 (defvar gnus-article-copy nil)
278 (defvar gnus-check-before-posting nil)
279 (defvar gnus-last-posting-server nil)
280 (defvar gnus-message-group-art nil)
282 (defvar gnus-msg-force-broken-reply-to nil)
284 (defconst gnus-bug-message
285 "Sending a bug report to the Gnus Towers.
286 ========================================
288 The buffer below is a mail buffer. When you press `C-c C-c', it will
289 be sent to the Gnus Bug Exterminators.
291 The thing near the bottom of the buffer is how the environment
292 settings will be included in the mail. Please do not delete that.
293 They will tell the Bug People what your environment is, so that it
294 will be easier to locate the bugs.
296 If you have found a bug that makes Emacs go \"beep\", set
297 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
298 and include the backtrace in your bug report.
300 Please describe the bug in annoying, painstaking detail.
302 Thank you for your help in stamping out bugs.
306 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
307 (autoload 'news-setup "rnewspost")
308 (autoload 'news-reply-mode "rnewspost")
309 (autoload 'rmail-dont-reply-to "mail-utils")
310 (autoload 'rmail-output "rmailout"))
314 ;;; Gnus Posting Functions
317 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
318 "p" gnus-summary-post-news
319 "i" gnus-summary-news-other-window
320 "f" gnus-summary-followup
321 "F" gnus-summary-followup-with-original
322 "c" gnus-summary-cancel-article
323 "s" gnus-summary-supersede-article
324 "r" gnus-summary-reply
325 "y" gnus-summary-yank-message
326 "R" gnus-summary-reply-with-original
327 "w" gnus-summary-wide-reply
328 "W" gnus-summary-wide-reply-with-original
329 "v" gnus-summary-very-wide-reply
330 "V" gnus-summary-very-wide-reply-with-original
331 "n" gnus-summary-followup-to-mail
332 "N" gnus-summary-followup-to-mail-with-original
333 "m" gnus-summary-mail-other-window
334 "u" gnus-uu-post-news
335 "\M-c" gnus-summary-mail-crosspost-complaint
336 "Br" gnus-summary-reply-broken-reply-to
337 "BR" gnus-summary-reply-broken-reply-to-with-original
338 "om" gnus-summary-mail-forward
339 "op" gnus-summary-post-forward
340 "Om" gnus-uu-digest-mail-forward
341 "Op" gnus-uu-digest-post-forward)
343 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
344 "b" gnus-summary-resend-bounced-mail
345 ;; "c" gnus-summary-send-draft
346 "r" gnus-summary-resend-message
347 "e" gnus-summary-resend-message-edit)
349 ;;; Internal functions.
351 (defvar gnus-article-reply nil)
352 (defmacro gnus-setup-message (config &rest forms)
353 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
354 (buffer (make-symbol "gnus-setup-message-buffer"))
355 (article (make-symbol "gnus-setup-message-article"))
356 (yanked (make-symbol "gnus-setup-yanked-articles"))
357 (group (make-symbol "gnus-setup-message-group")))
358 `(let ((,winconf (current-window-configuration))
359 (,buffer (buffer-name (current-buffer)))
360 (,article gnus-article-reply)
361 (,yanked gnus-article-yanked-articles)
362 (,group gnus-newsgroup-name)
363 (message-header-setup-hook
364 (copy-sequence message-header-setup-hook))
365 (mbl mml-buffer-list)
366 (message-mode-hook (copy-sequence message-mode-hook)))
367 (setq mml-buffer-list nil)
368 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
369 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
370 ;; #### FIXME: for a reason that I did not manage to identify yet,
371 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
372 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
373 ;; After evaluation of @forms below, it gets the value we actually want
374 ;; to override, and the posting styles are used. For that reason, I've
375 ;; added an optional argument to `gnus-configure-posting-styles' to
376 ;; make sure that the correct value for the group name is used. -- drv
377 (add-hook 'message-mode-hook
379 (gnus-configure-posting-styles ,group)))
383 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
385 (gnus-inews-insert-draft-meta-information ,group ,article)
386 (setq gnus-message-buffer (current-buffer))
387 (set (make-local-variable 'gnus-message-group-art)
388 (cons ,group ,article))
389 (set (make-local-variable 'gnus-newsgroup-name) ,group)
390 (gnus-run-hooks 'gnus-message-setup-hook)
391 (if (eq major-mode 'message-mode)
392 (let ((mbl1 mml-buffer-list))
393 (setq mml-buffer-list mbl) ;; Global value
394 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
395 ;; LOCAL argument of add-hook differs between GNU Emacs
396 ;; and XEmacs. make-local-hook makes sure they are local.
397 (make-local-hook 'kill-buffer-hook)
398 (make-local-hook 'change-major-mode-hook)
399 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
400 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
401 (mml-destroy-buffers)
402 (setq mml-buffer-list mbl)))
404 (gnus-configure-windows ,config t)
405 (run-hooks 'post-command-hook)
406 (set-buffer-modified-p nil))))
408 (defun gnus-inews-insert-draft-meta-information (group article)
411 (not (string= group ""))
412 (not (message-fetch-field gnus-draft-meta-information-header)))
413 (goto-char (point-min))
414 (insert gnus-draft-meta-information-header ": (\"" group "\" "
415 (if article (number-to-string
422 (defun gnus-msg-mail (&optional to subject other-headers continue
423 switch-action yank-action send-actions)
424 "Start editing a mail message to be sent.
425 Like `message-mail', but with Gnus paraphernalia, particularly the
426 Gcc: header for archiving purposes."
428 (let ((buf (current-buffer))
430 (gnus-setup-message 'message
431 (message-mail to subject other-headers continue
432 nil yank-action send-actions))
434 (setq mail-buf (current-buffer))
435 (switch-to-buffer buf)
436 (apply switch-action mail-buf nil)))
437 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
440 (defvar save-selected-window-window)
443 (defun gnus-button-mailto (address)
445 (set-buffer (gnus-copy-article-buffer))
446 (gnus-setup-message 'message
447 (message-reply address))
448 (and (boundp 'save-selected-window-window)
449 (not (window-live-p save-selected-window-window))
450 (setq save-selected-window-window (selected-window))))
453 (defun gnus-button-reply (&optional to-address wide)
454 "Like `message-reply'."
456 (gnus-setup-message 'message
457 (message-reply to-address wide))
458 (and (boundp 'save-selected-window-window)
459 (not (window-live-p save-selected-window-window))
460 (setq save-selected-window-window (selected-window))))
463 (define-mail-user-agent 'gnus-user-agent
464 'gnus-msg-mail 'message-send-and-exit
465 'message-kill-buffer 'message-send-hook)
467 (defun gnus-setup-posting-charset (group)
468 (let ((alist gnus-group-posting-charset-alist)
469 (group (or group ""))
473 (while (setq elem (pop alist))
474 (when (or (and (stringp (car elem))
475 (string-match (car elem) group))
476 (and (gnus-functionp (car elem))
477 (funcall (car elem) group))
478 (and (symbolp (car elem))
479 (symbol-value (car elem))))
480 (throw 'found (cons (cadr elem) (caddr elem)))))))))
482 (defun gnus-inews-add-send-actions (winconf buffer article
483 &optional config yanked)
484 (make-local-hook 'message-sent-hook)
485 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
486 'gnus-inews-do-gcc) nil t)
488 (make-local-hook 'message-header-hook)
489 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
490 (setq message-post-method
492 (gnus-post-method arg ,gnus-newsgroup-name)))
493 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
495 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
497 `(when (gnus-buffer-exists-p ,buffer)
501 (if (eq config 'forward)
502 `(gnus-summary-mark-article-as-forwarded ',yanked)
503 `(gnus-summary-mark-article-as-replied ',yanked)))))
506 (put 'gnus-setup-message 'lisp-indent-function 1)
507 (put 'gnus-setup-message 'edebug-form-spec '(form body))
509 ;;; Post news commands of Gnus group mode and summary mode
511 (defun gnus-group-mail (&optional arg)
512 "Start composing a mail.
513 If ARG, use the group under the point to find a posting style.
514 If ARG is 1, prompt for a group name to find the posting style."
516 ;; We can't `let' gnus-newsgroup-name here, since that leads
517 ;; to local variables leaking.
518 (let ((group gnus-newsgroup-name)
519 ;; make sure last viewed article doesn't affect posting styles:
521 (buffer (current-buffer)))
524 (setq gnus-newsgroup-name
526 (if (= 1 (prefix-numeric-value arg))
527 (completing-read "Use posting style of group: "
528 gnus-active-hashtb nil
529 (gnus-read-active-file-p))
530 (gnus-group-group-name))
532 ;; #### see comment in gnus-setup-message -- drv
533 (gnus-setup-message 'message (message-mail)))
536 (setq gnus-newsgroup-name group)))))
538 (defun gnus-group-news (&optional arg)
539 "Start composing a news.
540 If ARG, post to group under point.
541 If ARG is 1, prompt for group name to post to.
543 This function prepares a news even when using mail groups. This is useful
544 for posting messages to mail groups without actually sending them over the
545 network. The corresponding backend must have a 'request-post method."
547 ;; We can't `let' gnus-newsgroup-name here, since that leads
548 ;; to local variables leaking.
549 (let ((group gnus-newsgroup-name)
550 ;; make sure last viewed article doesn't affect posting styles:
552 (buffer (current-buffer)))
555 (setq gnus-newsgroup-name
557 (if (= 1 (prefix-numeric-value arg))
558 (completing-read "Use group: "
559 gnus-active-hashtb nil
560 (gnus-read-active-file-p))
561 (gnus-group-group-name))
563 ;; #### see comment in gnus-setup-message -- drv
564 (gnus-setup-message 'message
565 (message-news (gnus-group-real-name gnus-newsgroup-name))))
568 (setq gnus-newsgroup-name group)))))
570 (defun gnus-group-post-news (&optional arg)
571 "Start composing a message (a news by default).
572 If ARG, post to group under point. If ARG is 1, prompt for group name.
573 Depending on the selected group, the message might be either a mail or
576 ;; Bind this variable here to make message mode hooks work ok.
577 (let ((gnus-newsgroup-name
579 (if (= 1 (prefix-numeric-value arg))
580 (completing-read "Newsgroup: " gnus-active-hashtb nil
581 (gnus-read-active-file-p))
582 (gnus-group-group-name))
584 ;; make sure last viewed article doesn't affect posting styles:
586 (gnus-post-news 'post gnus-newsgroup-name)))
588 (defun gnus-summary-mail-other-window (&optional arg)
589 "Start composing a mail in another window.
590 Use the posting of the current group by default.
591 If ARG, don't do that. If ARG is 1, prompt for group name to find the
594 ;; We can't `let' gnus-newsgroup-name here, since that leads
595 ;; to local variables leaking.
596 (let ((group gnus-newsgroup-name)
597 ;; make sure last viewed article doesn't affect posting styles:
599 (buffer (current-buffer)))
602 (setq gnus-newsgroup-name
604 (if (= 1 (prefix-numeric-value arg))
605 (completing-read "Use group: "
606 gnus-active-hashtb nil
607 (gnus-read-active-file-p))
609 gnus-newsgroup-name))
610 ;; #### see comment in gnus-setup-message -- drv
611 (gnus-setup-message 'message (message-mail)))
614 (setq gnus-newsgroup-name group)))))
616 (defun gnus-summary-news-other-window (&optional arg)
617 "Start composing a news in another window.
618 Post to the current group by default.
619 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
621 This function prepares a news even when using mail groups. This is useful
622 for posting messages to mail groups without actually sending them over the
623 network. The corresponding backend must have a 'request-post method."
625 ;; We can't `let' gnus-newsgroup-name here, since that leads
626 ;; to local variables leaking.
627 (let ((group gnus-newsgroup-name)
628 ;; make sure last viewed article doesn't affect posting styles:
630 (buffer (current-buffer)))
633 (setq gnus-newsgroup-name
635 (if (= 1 (prefix-numeric-value arg))
636 (completing-read "Use group: "
637 gnus-active-hashtb nil
638 (gnus-read-active-file-p))
640 gnus-newsgroup-name))
641 ;; #### see comment in gnus-setup-message -- drv
642 (gnus-setup-message 'message
643 (message-news (gnus-group-real-name gnus-newsgroup-name))))
646 (setq gnus-newsgroup-name group)))))
648 (defun gnus-summary-post-news (&optional arg)
649 "Start composing a message. Post to the current group by default.
650 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
651 Depending on the selected group, the message might be either a mail or
654 ;; Bind this variable here to make message mode hooks work ok.
655 (let ((gnus-newsgroup-name
657 (if (= 1 (prefix-numeric-value arg))
658 (completing-read "Newsgroup: " gnus-active-hashtb nil
659 (gnus-read-active-file-p))
661 gnus-newsgroup-name))
662 ;; make sure last viewed article doesn't affect posting styles:
664 (gnus-post-news 'post gnus-newsgroup-name)))
667 (defun gnus-summary-followup (yank &optional force-news)
668 "Compose a followup to an article.
669 If prefix argument YANK is non-nil, the original article is yanked
671 YANK is a list of elements, where the car of each element is the
672 article number, and the two following numbers is the region to be
675 (list (and current-prefix-arg
676 (gnus-summary-work-articles 1))))
678 (gnus-summary-goto-subject
679 (if (listp (car yank))
682 (save-window-excursion
683 (gnus-summary-select-article))
684 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
685 (gnus-newsgroup-name gnus-newsgroup-name))
687 (gnus-post-news nil gnus-newsgroup-name
688 headers gnus-article-buffer
690 (gnus-summary-handle-replysign)))
692 (defun gnus-summary-followup-with-original (n &optional force-news)
693 "Compose a followup to an article and include the original article."
695 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
697 (defun gnus-summary-followup-to-mail (&optional arg)
698 "Followup to the current mail message via news."
700 (list (and current-prefix-arg
701 (gnus-summary-work-articles 1))))
702 (gnus-summary-followup arg t))
704 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
705 "Followup to the current mail message via news."
707 (gnus-summary-followup (gnus-summary-work-articles arg) t))
709 (defun gnus-inews-yank-articles (articles)
710 (let (beg article yank-string)
712 (while (setq article (pop articles))
713 (when (listp article)
714 (setq yank-string (nth 1 article)
715 article (nth 0 article)))
716 (save-window-excursion
717 (set-buffer gnus-summary-buffer)
718 (gnus-summary-select-article nil nil nil article)
719 (gnus-summary-remove-process-mark article))
720 (gnus-copy-article-buffer nil yank-string)
721 (let ((message-reply-buffer gnus-article-copy)
722 (message-reply-headers
723 ;; The headers are decoded.
724 (with-current-buffer gnus-article-copy
726 (nnheader-narrow-to-headers)
727 (nnheader-parse-naked-head)))))
728 (message-yank-original)
729 (setq beg (or beg (mark t))))
735 (defun gnus-summary-cancel-article (&optional n symp)
736 "Cancel an article you posted.
737 Uses the process-prefix convention. If given the symbolic
738 prefix `a', cancel using the standard posting method; if not
739 post using the current select method."
740 (interactive (gnus-interactive "P\ny"))
741 (let ((articles (gnus-summary-work-articles n))
744 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
746 (while (setq article (pop articles))
747 (when (gnus-summary-select-article t nil nil article)
748 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
749 (message-cancel-news))
750 (gnus-summary-mark-as-read article gnus-canceled-mark)
751 (gnus-cache-remove-article 1))
752 (gnus-article-hide-headers-if-wanted))
753 (gnus-summary-remove-process-mark article))))
755 (defun gnus-summary-supersede-article ()
756 "Compose an article that will supersede a previous article.
757 This is done simply by taking the old article and adding a Supersedes
758 header line with the old Message-ID."
760 (let ((article (gnus-summary-article-number)))
761 (gnus-setup-message 'reply-yank
762 (gnus-summary-select-article t)
763 (set-buffer gnus-original-article-buffer)
767 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
769 (set-buffer ,gnus-summary-buffer)
770 (gnus-cache-possibly-remove-article ,article nil nil nil t)
771 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
772 message-send-actions))))
776 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
777 ;; make a copy of the article buffer with all text properties removed
778 ;; this copy is in the buffer gnus-article-copy.
779 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
780 ;; this buffer should be passed to all mail/news reply/post routines.
781 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
783 (set-buffer gnus-article-copy)
784 (mm-enable-multibyte))
785 (let ((article-buffer (or article-buffer gnus-article-buffer))
787 (if (not (and (get-buffer article-buffer)
788 (gnus-buffer-exists-p article-buffer)))
789 (error "Can't find any article buffer")
791 (set-buffer article-buffer)
792 (let ((gnus-newsgroup-charset (or gnus-article-charset
793 gnus-newsgroup-charset))
794 (gnus-newsgroup-ignored-charsets
795 (or gnus-article-ignored-charsets
796 gnus-newsgroup-ignored-charsets)))
798 ;; Copy over the (displayed) article buffer, delete
799 ;; hidden text and remove text properties.
801 (copy-to-buffer gnus-article-copy (point-min) (point-max))
802 (set-buffer gnus-article-copy)
805 (delete-region (point) (point-max))
806 (insert yank-string))
807 (gnus-article-delete-text-of-type 'annotation)
808 (gnus-remove-text-with-property 'gnus-prev)
809 (gnus-remove-text-with-property 'gnus-next)
810 (gnus-remove-text-with-property 'gnus-decoration)
813 (buffer-substring-no-properties (point-min) (point-max))
815 ;; Find the original headers.
816 (set-buffer gnus-original-article-buffer)
817 (goto-char (point-min))
818 (while (looking-at message-unix-mail-delimiter)
820 (let ((mail-header-separator ""))
822 end (or (message-goto-body) beg)))
823 ;; Delete the headers from the displayed articles.
824 (set-buffer gnus-article-copy)
825 (let ((mail-header-separator ""))
826 (delete-region (goto-char (point-min))
827 (or (message-goto-body) (point-max))))
828 ;; Insert the original article headers.
829 (insert-buffer-substring gnus-original-article-buffer beg end)
831 (let ((gnus-article-decode-hook
832 (delq 'article-decode-charset
833 (copy-sequence gnus-article-decode-hook))))
834 (run-hooks 'gnus-article-decode-hook)))))
837 (defun gnus-post-news (post &optional group header article-buffer yank subject
840 (gnus-copy-article-buffer))
841 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
842 (gnus-article-yanked-articles yank)
843 (add-to-list gnus-add-to-list))
844 (gnus-setup-message (cond (yank 'reply-yank)
845 (article-buffer 'reply)
847 (let* ((group (or group gnus-newsgroup-name))
848 (charset (gnus-group-name-charset nil group))
850 to-address to-group mailing-list to-list
853 (setq to-address (gnus-parameter-to-address group)
854 to-group (gnus-group-find-parameter group 'to-group)
855 to-list (gnus-parameter-to-list group)
856 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
857 mailing-list (when gnus-mailing-list-groups
858 (string-match gnus-mailing-list-groups group))
859 group (gnus-group-name-decode (gnus-group-real-name group)
861 (if (or (and to-group
862 (gnus-news-group-p to-group))
865 (and (gnus-news-group-p
866 (or pgroup gnus-newsgroup-name)
867 (or header gnus-current-article))
873 (message-news (or to-group group))
874 (set-buffer gnus-article-copy)
875 (gnus-msg-treat-broken-reply-to)
876 (message-followup (if (or newsgroup-p force-news)
877 (if (save-restriction
878 (article-narrow-to-head)
879 (message-fetch-field "newsgroups"))
886 (message-mail (or to-address to-list))
887 ;; Arrange for mail groups that have no `to-address' to
888 ;; get that when the user sends off the mail.
889 (when (and (not to-list)
892 (push (list 'gnus-inews-add-to-address pgroup)
893 message-send-actions)))
894 (set-buffer gnus-article-copy)
895 (gnus-msg-treat-broken-reply-to)
896 (message-wide-reply to-address)))
898 (gnus-inews-yank-articles yank))))))
900 (defun gnus-msg-treat-broken-reply-to (&optional force)
901 "Remove the Reply-to header if broken-reply-to."
903 (gnus-group-find-parameter
904 gnus-newsgroup-name 'broken-reply-to))
906 (message-narrow-to-head)
907 (message-remove-header "reply-to"))))
909 (defun gnus-post-method (arg group &optional silent)
910 "Return the posting method based on GROUP and ARG.
911 If SILENT, don't prompt the user."
912 (let ((gnus-post-method (or (gnus-parameter-post-method group)
914 (group-method (gnus-find-method-for-group group)))
916 ;; If the group-method is nil (which shouldn't happen) we use
917 ;; the default method.
919 (or (and (listp gnus-post-method) ;If not current/native/nil
920 (not (listp (car gnus-post-method))) ; and not a list of methods
921 gnus-post-method) ;then use it.
923 message-post-method))
924 ;; We want the inverse of the default
925 ((and arg (not (eq arg 0)))
926 (if (eq gnus-post-method 'current)
929 ;; We query the user for a post method.
931 (and (listp gnus-post-method)
932 (listp (car gnus-post-method))))
934 ;; Collect all methods we know about.
936 (when (listp gnus-post-method)
937 (if (listp (car gnus-post-method))
939 (list gnus-post-method)))
940 gnus-secondary-select-methods
941 (mapcar 'cdr gnus-server-alist)
942 (mapcar 'car gnus-opened-servers)
943 (list gnus-select-method)
944 (list group-method)))
945 method-alist post-methods method)
946 ;; Weed out all mail methods.
948 (setq method (gnus-server-get-method "" (pop methods)))
949 (when (and (or (gnus-method-option-p method 'post)
950 (gnus-method-option-p method 'post-mail))
951 (not (member method post-methods)))
952 (push method post-methods)))
953 ;; Create a name-method alist.
957 (if (equal (cadr m) "")
958 (list (symbol-name (car m)) m)
959 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
964 (setq gnus-last-posting-server
966 gnus-last-posting-server)
967 ;; Just use the last value.
968 gnus-last-posting-server
970 "Posting method: " method-alist nil t
971 (cons (or gnus-last-posting-server "") 0))))
973 ;; Override normal method.
974 ((and (eq gnus-post-method 'current)
975 (not (memq (car group-method) gnus-discouraged-post-methods))
976 (gnus-get-function group-method 'request-post t))
979 ;; Use gnus-post-method.
980 ((listp gnus-post-method) ;A method...
981 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
983 ;; Use the normal select method (nil or native).
984 (t gnus-select-method))))
988 ;; Dummies to avoid byte-compile warning.
990 (defvar nnspool-rejected-article-hook)
991 (defvar xemacs-codename))
993 (defun gnus-extended-version ()
994 "Stringified Gnus version and Emacs version."
997 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
998 " (" gnus-version ")"
1001 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1002 (concat "Emacs/" (match-string 1 emacs-version)
1003 " (" system-configuration ")"))
1004 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1006 (concat (match-string 1 emacs-version)
1007 (format "/%d.%d" emacs-major-version emacs-minor-version)
1008 (if (match-beginning 3)
1009 (match-string 3 emacs-version)
1011 (if (boundp 'xemacs-codename)
1012 (concat " (" xemacs-codename ", " system-configuration ")")
1014 (t emacs-version))))
1018 ;;; Gnus Mail Functions
1021 ;;; Mail reply commands of Gnus summary mode
1023 (defun gnus-summary-reply (&optional yank wide very-wide)
1024 "Start composing a mail reply to the current message.
1025 If prefix argument YANK is non-nil, the original article is yanked
1027 If WIDE, make a wide reply.
1028 If VERY-WIDE, make a very wide reply."
1030 (list (and current-prefix-arg
1031 (gnus-summary-work-articles 1))))
1032 ;; Allow user to require confirmation before replying by mail to the
1033 ;; author of a news article.
1034 (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1035 (not gnus-confirm-mail-reply-to-news)
1036 (y-or-n-p "Really reply by mail to article author? "))
1038 (if (listp (car yank))
1041 (gnus-article-reply (or article (gnus-summary-article-number)))
1042 (gnus-article-yanked-articles yank)
1044 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1046 (gnus-summary-goto-subject article))
1047 (gnus-setup-message (if yank 'reply-yank 'reply)
1049 (gnus-summary-select-article)
1050 (dolist (article very-wide)
1051 (gnus-summary-select-article nil nil nil article)
1053 (set-buffer (gnus-copy-article-buffer))
1054 (gnus-msg-treat-broken-reply-to)
1056 (message-narrow-to-head)
1057 (setq headers (concat headers (buffer-string)))))))
1058 (set-buffer (gnus-copy-article-buffer))
1059 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1061 (message-narrow-to-head)
1065 (goto-char (point-max)))
1066 (mml-quote-region (point) (point-max))
1067 (message-reply nil wide)
1069 (gnus-inews-yank-articles yank))
1070 (gnus-summary-handle-replysign)))))
1072 (defun gnus-summary-handle-replysign ()
1073 "Check the various replysign variables and take action accordingly."
1074 (when (or gnus-message-replysign gnus-message-replyencrypt)
1075 (let (signed encrypted)
1077 (set-buffer gnus-article-buffer)
1078 (setq signed (memq 'signed gnus-article-wash-types))
1079 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1080 (cond ((and gnus-message-replyencrypt encrypted)
1081 (mml-secure-message mml-default-encrypt-method
1082 (if gnus-message-replysignencrypted
1085 ((and gnus-message-replysign signed)
1086 (mml-secure-message mml-default-sign-method 'sign))))))
1088 (defun gnus-summary-reply-with-original (n &optional wide)
1089 "Start composing a reply mail to the current message.
1090 The original article will be yanked."
1092 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1094 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1095 "Like `gnus-summary-reply' except removing reply-to field.
1096 If prefix argument YANK is non-nil, the original article is yanked
1098 If WIDE, make a wide reply.
1099 If VERY-WIDE, make a very wide reply."
1101 (list (and current-prefix-arg
1102 (gnus-summary-work-articles 1))))
1103 (let ((gnus-msg-force-broken-reply-to t))
1104 (gnus-summary-reply yank wide very-wide)))
1106 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1107 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1108 The original article will be yanked."
1110 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1112 (defun gnus-summary-wide-reply (&optional yank)
1113 "Start composing a wide reply mail to the current message.
1114 If prefix argument YANK is non-nil, the original article is yanked
1117 (list (and current-prefix-arg
1118 (gnus-summary-work-articles 1))))
1119 (gnus-summary-reply yank t))
1121 (defun gnus-summary-wide-reply-with-original (n)
1122 "Start composing a wide reply mail to the current message.
1123 The original article will be yanked."
1125 (gnus-summary-reply-with-original n t))
1127 (defun gnus-summary-very-wide-reply (&optional yank)
1128 "Start composing a very wide reply mail to the current message.
1129 If prefix argument YANK is non-nil, the original article is yanked
1132 (list (and current-prefix-arg
1133 (gnus-summary-work-articles 1))))
1134 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1136 (defun gnus-summary-very-wide-reply-with-original (n)
1137 "Start composing a very wide reply mail to the current message.
1138 The original article will be yanked."
1141 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1143 (defun gnus-summary-mail-forward (&optional arg post)
1144 "Forward the current message(s) to another user.
1145 If process marks exist, forward all marked messages;
1146 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1147 if ARG is 1, decode the message and forward directly inline;
1148 if ARG is 2, forward message as an rfc822 MIME section;
1149 if ARG is 3, decode message and forward as an rfc822 MIME section;
1150 if ARG is 4, forward message directly inline;
1151 otherwise, use flipped `message-forward-as-mime'.
1152 If POST, post instead of mail.
1153 For the `inline' alternatives, also see the variable
1154 `message-forward-ignored-headers'."
1156 (if (null (cdr (gnus-summary-work-articles nil)))
1157 (let ((message-forward-as-mime message-forward-as-mime)
1158 (message-forward-show-mml message-forward-show-mml))
1162 (setq message-forward-as-mime nil
1163 message-forward-show-mml t))
1165 (setq message-forward-as-mime t
1166 message-forward-show-mml nil))
1168 (setq message-forward-as-mime t
1169 message-forward-show-mml t))
1171 (setq message-forward-as-mime nil
1172 message-forward-show-mml nil))
1174 (setq message-forward-as-mime (not message-forward-as-mime))))
1175 (let* ((gnus-article-reply (gnus-summary-article-number))
1176 (gnus-article-yanked-articles (list (list gnus-article-reply))))
1177 (gnus-setup-message 'forward
1178 (gnus-summary-select-article)
1179 (let ((mail-parse-charset
1180 (or (and (gnus-buffer-live-p gnus-article-buffer)
1181 (with-current-buffer gnus-article-buffer
1182 gnus-article-charset))
1183 gnus-newsgroup-charset))
1184 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
1185 (set-buffer gnus-original-article-buffer)
1186 (message-forward post)))))
1187 (gnus-uu-digest-mail-forward arg post)))
1189 (defun gnus-summary-resend-message (address n)
1190 "Resend the current article to ADDRESS."
1192 (list (message-read-from-minibuffer
1193 "Resend message(s) to: "
1194 (when (and gnus-summary-resend-default-address
1195 (gnus-buffer-live-p gnus-original-article-buffer))
1196 ;; If some other article is currently selected, the
1197 ;; initial-contents is wrong. Whatever, it is just the
1198 ;; initial-contents.
1199 (with-current-buffer gnus-original-article-buffer
1200 (nnmail-fetch-field "to"))))
1201 current-prefix-arg))
1202 (let ((articles (gnus-summary-work-articles n))
1204 (while (setq article (pop articles))
1205 (gnus-summary-select-article nil nil nil article)
1207 (set-buffer gnus-original-article-buffer)
1208 (message-resend address))
1209 (gnus-summary-mark-article-as-forwarded article))))
1211 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1212 (defun gnus-summary-resend-message-edit ()
1213 "Resend an article that has already been sent.
1214 A new buffer will be created to allow the user to modify body and
1215 contents of the message, and then, everything will happen as when
1216 composing a new message."
1218 (let ((article (gnus-summary-article-number)))
1219 (gnus-setup-message 'reply-yank
1220 (gnus-summary-select-article t)
1221 (set-buffer gnus-original-article-buffer)
1222 (let ((cur (current-buffer))
1223 (to (message-fetch-field "to")))
1224 ;; Get a normal message buffer.
1225 (message-pop-to-buffer (message-buffer-name "Resend" to))
1226 (insert-buffer-substring cur)
1228 (message-narrow-to-head-1)
1229 ;; Gnus will generate a new one when sending.
1230 (message-remove-header "Message-ID")
1231 (message-remove-header message-ignored-resent-headers t)
1232 ;; Remove unwanted headers.
1233 (goto-char (point-max))
1234 (insert mail-header-separator)
1235 (goto-char (point-min))
1236 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1240 (defun gnus-summary-post-forward (&optional arg)
1241 "Forward the current article to a newsgroup.
1242 See `gnus-summary-mail-forward' for ARG."
1244 (gnus-summary-mail-forward arg t))
1246 (defvar gnus-nastygram-message
1247 "The following article was inappropriately posted to %s.\n\n"
1248 "Format string to insert in nastygrams.
1249 The current group name will be inserted at \"%s\".")
1251 (defun gnus-summary-mail-nastygram (n)
1252 "Send a nastygram to the author of the current article."
1254 (when (or gnus-expert-user
1256 "Really send a nastygram to the author of the current article? "))
1257 (let ((group gnus-newsgroup-name))
1258 (gnus-summary-reply-with-original n)
1259 (set-buffer gnus-message-buffer)
1261 (insert (format gnus-nastygram-message group))
1262 (message-send-and-exit))))
1264 (defun gnus-summary-mail-crosspost-complaint (n)
1265 "Send a complaint about crossposting to the current article(s)."
1267 (let ((articles (gnus-summary-work-articles n))
1269 (while (setq article (pop articles))
1270 (set-buffer gnus-summary-buffer)
1271 (gnus-summary-goto-subject article)
1272 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1273 newsgroups followup-to)
1274 (gnus-summary-select-article)
1275 (set-buffer gnus-original-article-buffer)
1276 (if (and (<= (length (message-tokenize-header
1278 (mail-fetch-field "newsgroups"))
1281 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1282 (not (member group (message-tokenize-header
1283 followup-to ", ")))))
1285 (gnus-message 1 "Followup-to restricted")
1286 (gnus-message 1 "Not a crossposted article"))
1287 (set-buffer gnus-summary-buffer)
1288 (gnus-summary-reply-with-original 1)
1289 (set-buffer gnus-message-buffer)
1291 (insert (format gnus-crosspost-complaint newsgroups group))
1292 (message-goto-subject)
1293 (re-search-forward " *$")
1294 (replace-match " (crosspost notification)" t t)
1295 (gnus-deactivate-mark)
1296 (when (gnus-y-or-n-p "Send this complaint? ")
1297 (message-send-and-exit)))))))
1299 (defun gnus-mail-parse-comma-list ()
1302 (skip-chars-forward " ")
1305 (skip-chars-forward "^,")
1310 (narrow-to-region beg (point))
1313 (while (search-forward "\"" nil t)
1317 (skip-chars-forward ",")
1318 (skip-chars-forward "^,"))
1319 (skip-chars-backward " ")
1320 (push (buffer-substring beg (point))
1322 (skip-chars-forward "^,")
1323 (skip-chars-forward ", "))
1326 (defun gnus-inews-add-to-address (group)
1327 (let ((to-address (mail-fetch-field "to")))
1328 (when (and to-address
1330 ;; This mail group doesn't have a `to-list', so we add one
1332 (when (gnus-y-or-n-p
1333 (format "Do you want to add this as `to-list': %s " to-address))
1334 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1336 (defun gnus-put-message ()
1337 "Put the current message in some group and return to Gnus."
1339 (let ((reply gnus-article-reply)
1340 (winconf gnus-prev-winconf)
1341 (group gnus-newsgroup-name))
1343 (not (gnus-group-read-only-p group)))
1344 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1346 (when (gnus-gethash group gnus-newsrc-hashtb)
1347 (error "No such group: %s" group))
1351 (message-narrow-to-headers)
1352 (let ((gnus-deletable-headers nil))
1353 (message-generate-headers
1354 (if (message-news-p)
1355 message-required-news-headers
1356 message-required-mail-headers)))
1357 (goto-char (point-max))
1358 (if (string-match " " group)
1359 (insert "Gcc: \"" group "\"\n")
1360 (insert "Gcc: " group "\n"))
1363 (when (and (get-buffer gnus-group-buffer)
1364 (gnus-buffer-exists-p (car-safe reply))
1366 (set-buffer (car reply))
1367 (gnus-summary-mark-article-as-replied (cdr reply)))
1369 (set-window-configuration winconf))))
1371 (defun gnus-article-mail (yank)
1372 "Send a reply to the address near point.
1373 If YANK is non-nil, include the original article."
1377 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1378 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1380 (gnus-msg-mail address)
1382 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1384 (defvar nntp-server-type)
1386 "Send a bug report to the Gnus maintainers."
1388 (unless (gnus-alive-p)
1389 (error "Gnus has been shut down"))
1390 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1391 (unless (message-mail-user-agent)
1392 (delete-other-windows)
1393 (when gnus-bug-create-help-buffer
1394 (switch-to-buffer "*Gnus Help Bug*")
1396 (insert gnus-bug-message)
1397 (goto-char (point-min)))
1398 (message-pop-to-buffer "*Gnus Bug*"))
1399 (let ((message-this-is-mail t))
1400 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1401 (when gnus-bug-create-help-buffer
1402 (push `(gnus-bug-kill-buffer) message-send-actions))
1403 (goto-char (point-min))
1404 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1406 (insert (gnus-version) "\n"
1407 (emacs-version) "\n")
1408 (when (and (boundp 'nntp-server-type)
1409 (stringp nntp-server-type))
1410 (insert nntp-server-type))
1411 (insert "\n\n\n\n\n")
1414 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1417 (setq text (buffer-string)))
1418 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1419 (goto-char (point-min))
1420 (search-forward "Subject: " nil t)
1423 (defun gnus-bug-kill-buffer ()
1424 (when (get-buffer "*Gnus Help Bug*")
1425 (kill-buffer "*Gnus Help Bug*")))
1427 (defun gnus-summary-yank-message (buffer n)
1428 "Yank the current article into a composed message."
1430 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1431 current-prefix-arg))
1432 (gnus-summary-iterate n
1433 (let ((gnus-display-mime-function nil)
1434 (gnus-inhibit-treatment t))
1435 (gnus-summary-select-article))
1438 (message-yank-buffer gnus-article-buffer))))
1440 (defun gnus-debug ()
1441 "Attempts to go through the Gnus source file and report what variables have been changed.
1442 The source file has to be in the Emacs load path."
1444 (let ((files gnus-debug-files)
1446 file expr olist sym)
1447 (gnus-message 4 "Please wait while we snoop your variables...")
1449 ;; Go through all the files looking for non-default values for variables.
1451 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1454 (when (and (setq file (locate-library (pop files)))
1455 (file-exists-p file))
1456 (insert-file-contents file)
1457 (goto-char (point-min))
1458 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1459 (gnus-message 4 "Malformed sources in file %s" file)
1460 (narrow-to-region (point-min) (point))
1461 (goto-char (point-min))
1462 (while (setq expr (ignore-errors (read (current-buffer))))
1464 (and (or (eq (car expr) 'defvar)
1465 (eq (car expr) 'defcustom))
1466 (stringp (nth 3 expr))
1467 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1468 (or (not (boundp (nth 1 expr)))
1469 (not (equal (eval (nth 2 expr))
1470 (symbol-value (nth 1 expr)))))
1471 (push (nth 1 expr) olist)))))))
1472 (kill-buffer (current-buffer)))
1473 (when (setq olist (nreverse olist))
1474 (insert "------------------ Environment follows ------------------\n\n"))
1476 (if (boundp (car olist))
1478 (pp `(setq ,(car olist)
1479 ,(if (or (consp (setq sym (symbol-value (car olist))))
1481 (not (or (eq sym nil)
1483 (list 'quote (symbol-value (car olist)))
1484 (symbol-value (car olist))))
1487 (format "(setq %s 'whatever)\n" (car olist))))
1488 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1489 (setq olist (cdr olist)))
1491 ;; Remove any control chars - they seem to cause trouble for some
1492 ;; mailers. (Byte-compiled output from the stuff above.)
1494 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1495 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1498 ;;; Treatment of rejected articles.
1501 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1502 "Re-mail the current message.
1503 This only makes sense if the current message is a bounce message than
1504 contains some mail you have written which has been bounced back to
1506 If FETCH, try to fetch the article that this is a reply to, if indeed
1509 (gnus-summary-select-article t)
1510 (set-buffer gnus-original-article-buffer)
1511 (gnus-setup-message 'compose-bounce
1512 (let* ((references (mail-fetch-field "references"))
1513 (parent (and references (gnus-parent-id references))))
1515 ;; If there are references, we fetch the article we answered to.
1517 (gnus-summary-refer-article parent)
1518 (gnus-summary-show-all-headers)))))
1522 (defun gnus-inews-group-method (group)
1524 ;; If the group doesn't exist, we assume
1525 ;; it's an archive group...
1526 ((and (null (gnus-get-info group))
1527 (eq (car (gnus-server-to-method gnus-message-archive-method))
1528 (car (gnus-server-to-method (gnus-group-method group)))))
1529 gnus-message-archive-method)
1531 ((gnus-info-method (gnus-get-info group))
1532 (gnus-info-method (gnus-get-info group)))
1534 (t (gnus-server-to-method (gnus-group-method group)))))
1536 ;; Do Gcc handling, which copied the message over to some group.
1537 (defun gnus-inews-do-gcc (&optional gcc)
1541 (message-narrow-to-headers)
1542 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1543 (cur (current-buffer))
1544 groups group method group-art
1545 mml-externalize-attachments)
1547 (message-remove-header "gcc")
1549 (setq groups (message-unquote-tokens
1550 (message-tokenize-header gcc " ,")))
1551 ;; Copy the article over to some group(s).
1552 (while (setq group (pop groups))
1553 (unless (gnus-check-server
1554 (setq method (gnus-inews-group-method group)))
1555 (error "Can't open server %s" (if (stringp method) method
1557 (unless (gnus-request-group group nil method)
1558 (gnus-request-create-group group method))
1559 (setq mml-externalize-attachments
1560 (if (stringp gnus-gcc-externalize-attachments)
1561 (string-match gnus-gcc-externalize-attachments group)
1562 gnus-gcc-externalize-attachments))
1564 (nnheader-set-temp-buffer " *acc*")
1565 (insert-buffer-substring cur)
1566 (message-encode-message-body)
1568 (message-narrow-to-headers)
1569 (let* ((mail-parse-charset message-default-charset)
1570 (newsgroups-field (save-restriction
1571 (message-narrow-to-headers-or-head)
1572 (message-fetch-field "Newsgroups")))
1573 (followup-field (save-restriction
1574 (message-narrow-to-headers-or-head)
1575 (message-fetch-field "Followup-To")))
1576 ;; BUG: We really need to get the charset for
1577 ;; each name in the Newsgroups and Followup-To
1578 ;; lines to allow crossposting between group
1579 ;; namess with incompatible character sets.
1580 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1581 (group-field-charset
1582 (gnus-group-name-charset
1583 method (or newsgroups-field "")))
1584 (followup-field-charset
1585 (gnus-group-name-charset
1586 method (or followup-field "")))
1587 (rfc2047-header-encoding-alist
1589 (when group-field-charset
1590 (list (cons "Newsgroups" group-field-charset)))
1591 (when followup-field-charset
1592 (list (cons "Followup-To" followup-field-charset)))
1593 rfc2047-header-encoding-alist)))
1594 (mail-encode-encoded-word-buffer)))
1595 (goto-char (point-min))
1596 (when (re-search-forward
1597 (concat "^" (regexp-quote mail-header-separator) "$")
1599 (replace-match "" t t ))
1600 (unless (setq group-art
1601 (gnus-request-accept-article group method t t))
1602 (gnus-message 1 "Couldn't store article in group %s: %s"
1603 group (gnus-status-message method))
1605 (when (and group-art
1606 (or gnus-gcc-mark-as-read
1607 gnus-inews-mark-gcc-as-read))
1608 (gnus-group-mark-article-read group (cdr group-art)))
1609 (kill-buffer (current-buffer)))))))))
1611 (defun gnus-inews-insert-gcc ()
1612 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1615 (message-narrow-to-headers)
1616 (let* ((group gnus-outgoing-message-group)
1618 ((gnus-functionp group)
1620 ((or (stringp group) (list group))
1625 (if (string-match " " gcc)
1626 (concat "\"" gcc "\"")
1628 (mapconcat (lambda (group)
1629 (if (string-match " " group)
1630 (concat "\"" group "\"")
1635 (defun gnus-inews-insert-archive-gcc (&optional group)
1636 "Insert the Gcc to say where the article is to be archived."
1637 (let* ((var gnus-message-archive-group)
1638 (group (or group gnus-newsgroup-name ""))
1640 (and gnus-newsgroup-name
1641 (not (equal gnus-newsgroup-name ""))
1642 (gnus-group-find-parameter
1643 gnus-newsgroup-name 'gcc-self)))
1647 ((null gnus-message-archive-method)
1651 ;; Just a single group.
1654 ;; We don't want this.
1656 ((and (listp var) (stringp (car var)))
1657 ;; A list of groups.
1659 ((gnus-functionp var)
1661 (funcall var group))
1663 ;; An alist of regexps/functions/forms.
1668 ((stringp (caar var))
1670 (when (string-match (caar var) group)
1672 ((gnus-functionp (car var))
1674 (funcall (car var) group))
1676 (eval (car var)))))))
1677 (setq var (cdr var)))
1680 (when (or groups gcc-self-val)
1681 (when (stringp groups)
1682 (setq groups (list groups)))
1685 (message-narrow-to-headers)
1686 (goto-char (point-max))
1689 ;; Use the `gcc-self' param value instead.
1692 (if (stringp gcc-self-val)
1693 (if (string-match " " gcc-self-val)
1694 (concat "\"" gcc-self-val "\"")
1696 (if (string-match " " group)
1697 (concat "\"" group "\"")
1699 (if (not (eq gcc-self-val 'none))
1704 ;; Use the list of groups.
1705 (while (setq name (pop groups))
1706 (let ((str (if (string-match ":" name)
1708 (gnus-group-prefixed-name
1709 name gnus-message-archive-method))))
1710 (insert (if (string-match " " str)
1711 (concat "\"" str "\"")
1719 (defun gnus-configure-posting-styles (&optional group-name)
1720 "Configure posting styles according to `gnus-posting-styles'."
1721 (unless gnus-inhibit-posting-styles
1722 (let ((group (or group-name gnus-newsgroup-name ""))
1723 (styles gnus-posting-styles)
1724 style match variable attribute value v results
1725 filep name address element)
1726 ;; If the group has a posting-style parameter, add it at the end with a
1727 ;; regexp matching everything, to be sure it takes precedence over all
1729 (when gnus-newsgroup-name
1730 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1732 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1733 ;; Go through all styles and look for matches.
1734 (dolist (style styles)
1735 (setq match (pop style))
1736 (goto-char (point-min))
1739 ;; Regexp string match on the group name.
1740 (string-match match group))
1742 ;; Obsolete format of header match.
1743 (and (gnus-buffer-live-p gnus-article-copy)
1744 (with-current-buffer gnus-article-copy
1745 (let ((header (message-fetch-field (pop style))))
1747 (string-match (pop style) header))))))
1748 ((or (symbolp match)
1749 (gnus-functionp match))
1751 ((gnus-functionp match)
1752 ;; Function to be called.
1755 ;; Variable to be checked.
1756 (symbol-value match))))
1759 ((eq (car match) 'header)
1760 ;; New format of header match.
1761 (and (gnus-buffer-live-p gnus-article-copy)
1762 (with-current-buffer gnus-article-copy
1763 (let ((header (message-fetch-field (nth 1 match))))
1765 (string-match (nth 2 match) header))))))
1767 ;; This is a form to be evaled.
1769 ;; We have a match, so we set the variables.
1770 (dolist (attribute style)
1771 (setq element (pop attribute)
1776 ((eq (car attribute) :file)
1779 ((eq (car attribute) :value)
1783 ;; We get the value.
1788 ((or (symbolp value)
1789 (gnus-functionp value))
1790 (cond ((gnus-functionp value)
1793 (symbol-value value))))
1796 ;; Translate obsolescent value.
1798 ((eq element 'signature-file)
1799 (setq element 'signature
1801 ((eq element 'x-face-file)
1802 (setq element 'x-face
1804 ;; Get the contents of file elems.
1806 (setq v (with-temp-buffer
1807 (insert-file-contents v)
1808 (goto-char (point-max))
1812 (setq results (delq (assoc element results) results))
1813 (push (cons element v) results))))
1814 ;; Now we have all the styles, so we insert them.
1815 (setq name (assq 'name results)
1816 address (assq 'address results))
1817 (setq results (delq name (delq address results)))
1818 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1819 (make-local-hook 'message-setup-hook)
1820 (setq results (sort results (lambda (x y)
1821 (string-lessp (car x) (car y)))))
1822 (dolist (result results)
1823 (add-hook 'message-setup-hook
1825 ((eq 'eval (car result))
1827 ((eq 'body (car result))
1831 (insert ,(cdr result)))))
1832 ((eq 'signature (car result))
1833 (set (make-local-variable 'message-signature) nil)
1834 (set (make-local-variable 'message-signature-file) nil)
1835 (if (not (cdr result))
1839 (let ((message-signature ,(cdr result)))
1840 (when message-signature
1841 (message-insert-signature)))))))
1844 (if (symbolp (car result))
1845 (capitalize (symbol-name (car result)))
1849 (message-remove-header ,header)
1850 (let ((value ,(cdr result)))
1853 (insert ,header ": " value "\n"))))))))
1855 (when (or name address)
1856 (add-hook 'message-setup-hook
1858 (set (make-local-variable 'user-mail-address)
1859 ,(or (cdr address) user-mail-address))
1860 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1862 ,(or (cdr address) user-mail-address)))
1864 (message-remove-header "From")
1866 (insert "From: " (message-make-from) "\n"))))
1869 ;;; Allow redefinition of functions.
1875 ;;; gnus-msg.el ends here