1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
36 (defcustom gnus-post-method nil
37 "*Preferred method for posting USENET news.
39 If this variable is `current', Gnus will use the \"current\" select
40 method when posting. If it is nil (which is the default), Gnus will
41 use the native posting method of the server.
43 This method will not be used in mail groups and the like, only in
46 If not nil nor `native', the value must be a valid method as discussed
47 in the documentation of `gnus-select-method'. It can also be a list of
48 methods. If that is the case, the user will be queried for what select
49 method to use when posting."
50 :group 'gnus-group-foreign
51 :type `(choice (const nil)
54 (sexp :tag "Methods" ,gnus-select-method)))
56 (defvar gnus-outgoing-message-group nil
57 "*All outgoing messages will be put in this group.
58 If you want to store all your outgoing mail and articles in the group
59 \"nnml:archive\", you set this variable to that value. This variable
60 can also be a list of group names.
62 If you want to have greater control over what group to put each
63 message in, you can set this variable to a function that checks the
64 current newsgroup name and then returns a suitable group name (or list
67 (defvar gnus-mailing-list-groups nil
68 "*Regexp matching groups that are really mailing lists.
69 This is useful when you're reading a mailing list that has been
70 gatewayed to a newsgroup, and you want to followup to an article in
73 (defvar gnus-add-to-list nil
74 "*If non-nil, add a `to-list' parameter automatically.")
76 (defvar gnus-crosspost-complaint
79 You posted the article below with the following Newsgroups header:
83 The %s group, at least, was an inappropriate recipient
84 of this message. Please trim your Newsgroups header to exclude this
85 group before posting in the future.
90 "Format string to be inserted when complaining about crossposts.
91 The first %s will be replaced by the Newsgroups header;
92 the second with the current group name.")
94 (defvar gnus-message-setup-hook nil
95 "Hook run after setting up a message buffer.")
97 (defvar gnus-bug-create-help-buffer t
98 "*Should we create the *Gnus Help Bug* buffer?")
100 (defvar gnus-posting-styles nil
101 "*Alist of styles to use when posting.")
103 (defcustom gnus-group-posting-charset-alist
104 '(("^no\\." iso-8859-1)
105 (message-this-is-mail nil)
107 (message-this-is-news iso-8859-1))
108 "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
109 :type '(repeat (list (regexp :tag "Group")
110 (symbol :tag "Charset")))
111 :group 'gnus-charset)
113 ;;; Internal variables.
115 (defvar gnus-inhibit-posting-styles nil
116 "Inhibit the use of posting styles.")
118 (defvar gnus-message-buffer "*Mail Gnus*")
119 (defvar gnus-article-copy nil)
120 (defvar gnus-last-posting-server nil)
121 (defvar gnus-message-group-art nil)
123 (defconst gnus-bug-message
124 "Sending a bug report to the Gnus Towers.
125 ========================================
127 The buffer below is a mail buffer. When you press `C-c C-c', it will
128 be sent to the Gnus Bug Exterminators.
130 The thing near the bottom of the buffer is how the environment
131 settings will be included in the mail. Please do not delete that.
132 They will tell the Bug People what your environment is, so that it
133 will be easier to locate the bugs.
135 If you have found a bug that makes Emacs go \"beep\", set
136 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
137 and include the backtrace in your bug report.
139 Please describe the bug in annoying, painstaking detail.
141 Thank you for your help in stamping out bugs.
145 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
146 (autoload 'news-setup "rnewspost")
147 (autoload 'news-reply-mode "rnewspost")
148 (autoload 'rmail-dont-reply-to "mail-utils")
149 (autoload 'rmail-output "rmailout"))
153 ;;; Gnus Posting Functions
156 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
157 "p" gnus-summary-post-news
158 "f" gnus-summary-followup
159 "F" gnus-summary-followup-with-original
160 "c" gnus-summary-cancel-article
161 "s" gnus-summary-supersede-article
162 "r" gnus-summary-reply
163 "R" gnus-summary-reply-with-original
164 "w" gnus-summary-wide-reply
165 "W" gnus-summary-wide-reply-with-original
166 "n" gnus-summary-followup-to-mail
167 "N" gnus-summary-followup-to-mail-with-original
168 "m" gnus-summary-mail-other-window
169 "u" gnus-uu-post-news
170 "\M-c" gnus-summary-mail-crosspost-complaint
171 "om" gnus-summary-mail-forward
172 "op" gnus-summary-post-forward
173 "Om" gnus-uu-digest-mail-forward
174 "Op" gnus-uu-digest-post-forward)
176 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
177 "b" gnus-summary-resend-bounced-mail
178 ;; "c" gnus-summary-send-draft
179 "r" gnus-summary-resend-message)
181 ;;; Internal functions.
183 (defvar gnus-article-reply nil)
184 (defmacro gnus-setup-message (config &rest forms)
185 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
186 (buffer (make-symbol "gnus-setup-message-buffer"))
187 (article (make-symbol "gnus-setup-message-article"))
188 (group (make-symbol "gnus-setup-message-group")))
189 `(let ((,winconf (current-window-configuration))
190 (,buffer (buffer-name (current-buffer)))
191 (,article (and gnus-article-reply (gnus-summary-article-number)))
192 (,group gnus-newsgroup-name)
193 (message-header-setup-hook
194 (copy-sequence message-header-setup-hook))
195 (message-mode-hook (copy-sequence message-mode-hook)))
196 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
197 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
198 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
202 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
203 (setq gnus-message-buffer (current-buffer))
204 (set (make-local-variable 'gnus-message-group-art)
205 (cons ,group ,article))
206 (set (make-local-variable 'gnus-newsgroup-name) ,group)
207 (set (make-local-variable 'message-posting-charset)
208 (gnus-setup-posting-charset ,group))
209 (gnus-run-hooks 'gnus-message-setup-hook))
211 (gnus-configure-windows ,config t)
212 (set-buffer-modified-p nil))))
214 (defun gnus-setup-posting-charset (group)
215 (let ((alist gnus-group-posting-charset-alist)
216 (group (or group ""))
220 (while (setq elem (pop alist))
221 (when (or (and (stringp (car elem))
222 (string-match (car elem) group))
223 (and (gnus-functionp (car elem))
224 (funcall (car elem) group))
225 (and (symbolp (car elem))
226 (symbol-value (car elem))))
227 (throw 'found (cadr elem))))))))
229 (defun gnus-inews-add-send-actions (winconf buffer article)
230 (make-local-hook 'message-sent-hook)
231 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
232 (setq message-post-method
234 (gnus-post-method arg ,gnus-newsgroup-name)))
235 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
237 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
239 `(when (gnus-buffer-exists-p ,buffer)
243 `(gnus-summary-mark-article-as-replied ,article))))
246 (put 'gnus-setup-message 'lisp-indent-function 1)
247 (put 'gnus-setup-message 'edebug-form-spec '(form body))
249 ;;; Post news commands of Gnus group mode and summary mode
251 (defun gnus-group-mail (&optional arg)
252 "Start composing a mail.
253 If ARG, use the group under the point to find a posting style.
254 If ARG is 1, prompt for a group name to find the posting style."
256 ;; We can't `let' gnus-newsgroup-name here, since that leads
257 ;; to local variables leaking.
258 (let ((group gnus-newsgroup-name)
259 (buffer (current-buffer)))
262 (setq gnus-newsgroup-name
264 (if (= 1 (prefix-numeric-value arg))
265 (completing-read "Use posting style of group: "
266 gnus-active-hashtb nil
267 (gnus-read-active-file-p))
268 (gnus-group-group-name))
270 (gnus-setup-message 'message (message-mail)))
273 (setq gnus-newsgroup-name group)))))
275 (defun gnus-group-post-news (&optional arg)
276 "Start composing a news message.
277 If ARG, post to the group under point.
278 If ARG is 1, prompt for a group name."
280 ;; Bind this variable here to make message mode hooks work ok.
281 (let ((gnus-newsgroup-name
283 (if (= 1 (prefix-numeric-value arg))
284 (completing-read "Newsgroup: " gnus-active-hashtb nil
285 (gnus-read-active-file-p))
286 (gnus-group-group-name))
288 (gnus-post-news 'post gnus-newsgroup-name)))
290 (defun gnus-summary-post-news ()
291 "Start composing a news message."
293 (gnus-post-news 'post gnus-newsgroup-name))
295 (defun gnus-summary-followup (yank &optional force-news)
296 "Compose a followup to an article.
297 If prefix argument YANK is non-nil, original article is yanked automatically."
299 (list (and current-prefix-arg
300 (gnus-summary-work-articles 1))))
302 (gnus-summary-goto-subject (car yank)))
303 (save-window-excursion
304 (gnus-summary-select-article))
305 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
306 (gnus-newsgroup-name gnus-newsgroup-name))
308 (gnus-post-news nil gnus-newsgroup-name
309 headers gnus-article-buffer
310 yank nil force-news)))
312 (defun gnus-summary-followup-with-original (n &optional force-news)
313 "Compose a followup to an article and include the original article."
315 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
317 (defun gnus-summary-followup-to-mail (&optional arg)
318 "Followup to the current mail message via news."
320 (list (and current-prefix-arg
321 (gnus-summary-work-articles 1))))
322 (gnus-summary-followup arg t))
324 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
325 "Followup to the current mail message via news."
327 (gnus-summary-followup (gnus-summary-work-articles arg) t))
329 (defun gnus-inews-yank-articles (articles)
332 (while (setq article (pop articles))
333 (save-window-excursion
334 (set-buffer gnus-summary-buffer)
335 (gnus-summary-select-article nil nil nil article)
336 (gnus-summary-remove-process-mark article))
337 (gnus-copy-article-buffer)
338 (let ((message-reply-buffer gnus-article-copy)
339 (message-reply-headers gnus-current-headers))
340 (message-yank-original)
341 (setq beg (or beg (mark t))))
347 (defun gnus-summary-cancel-article (&optional n symp)
348 "Cancel an article you posted.
349 Uses the process-prefix convention. If given the symbolic
350 prefix `a', cancel using the standard posting method; if not
351 post using the current select method."
352 (interactive (gnus-interactive "P\ny"))
353 (let ((articles (gnus-summary-work-articles n))
356 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
358 (while (setq article (pop articles))
359 (when (gnus-summary-select-article t nil nil article)
360 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
361 (message-cancel-news))
362 (gnus-summary-mark-as-read article gnus-canceled-mark)
363 (gnus-cache-remove-article 1))
364 (gnus-article-hide-headers-if-wanted))
365 (gnus-summary-remove-process-mark article))))
367 (defun gnus-summary-supersede-article ()
368 "Compose an article that will supersede a previous article.
369 This is done simply by taking the old article and adding a Supersedes
370 header line with the old Message-ID."
372 (let ((article (gnus-summary-article-number)))
373 (gnus-setup-message 'reply-yank
374 (gnus-summary-select-article t)
375 (set-buffer gnus-original-article-buffer)
379 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
381 (set-buffer ,gnus-summary-buffer)
382 (gnus-cache-possibly-remove-article ,article nil nil nil t)
383 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
384 message-send-actions))))
388 (defun gnus-copy-article-buffer (&optional article-buffer)
389 ;; make a copy of the article buffer with all text properties removed
390 ;; this copy is in the buffer gnus-article-copy.
391 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
392 ;; this buffer should be passed to all mail/news reply/post routines.
393 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
395 (set-buffer gnus-article-copy)
396 (mm-enable-multibyte))
397 (let ((article-buffer (or article-buffer gnus-article-buffer))
399 (if (not (and (get-buffer article-buffer)
400 (gnus-buffer-exists-p article-buffer)))
401 (error "Can't find any article buffer")
403 (set-buffer article-buffer)
405 ;; Copy over the (displayed) article buffer, delete
406 ;; hidden text and remove text properties.
408 (copy-to-buffer gnus-article-copy (point-min) (point-max))
409 (set-buffer gnus-article-copy)
410 (gnus-article-delete-text-of-type 'annotation)
411 (gnus-remove-text-with-property 'gnus-prev)
412 (gnus-remove-text-with-property 'gnus-next)
415 (format "%s" (buffer-string))
417 ;; Find the original headers.
418 (set-buffer gnus-original-article-buffer)
419 (goto-char (point-min))
420 (while (looking-at message-unix-mail-delimiter)
423 (setq end (or (search-forward "\n\n" nil t) (point)))
424 ;; Delete the headers from the displayed articles.
425 (set-buffer gnus-article-copy)
426 (delete-region (goto-char (point-min))
427 (or (search-forward "\n\n" nil t) (point-max)))
428 ;; Insert the original article headers.
429 (insert-buffer-substring gnus-original-article-buffer beg end)
430 (article-decode-encoded-words)))
433 (defun gnus-post-news (post &optional group header article-buffer yank subject
436 (gnus-copy-article-buffer))
437 (let ((gnus-article-reply article-buffer)
438 (add-to-list gnus-add-to-list))
439 (gnus-setup-message (cond (yank 'reply-yank)
440 (article-buffer 'reply)
442 (let* ((group (or group gnus-newsgroup-name))
444 to-address to-group mailing-list to-list
447 (setq to-address (gnus-group-find-parameter group 'to-address)
448 to-group (gnus-group-find-parameter group 'to-group)
449 to-list (gnus-group-find-parameter group 'to-list)
450 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
451 mailing-list (when gnus-mailing-list-groups
452 (string-match gnus-mailing-list-groups group))
453 group (gnus-group-real-name group)))
454 (if (or (and to-group
455 (gnus-news-group-p to-group))
458 (and (gnus-news-group-p
459 (or pgroup gnus-newsgroup-name)
460 (if header (mail-header-number header)
461 gnus-current-article))
467 (message-news (or to-group group))
468 (set-buffer gnus-article-copy)
469 (gnus-msg-treat-broken-reply-to)
470 (message-followup (if (or newsgroup-p force-news) nil to-group)))
474 (message-mail (or to-address to-list))
475 ;; Arrange for mail groups that have no `to-address' to
476 ;; get that when the user sends off the mail.
477 (when (and (not to-list)
480 (push (list 'gnus-inews-add-to-address pgroup)
481 message-send-actions)))
482 (set-buffer gnus-article-copy)
483 (gnus-msg-treat-broken-reply-to)
484 (message-wide-reply to-address)))
486 (gnus-inews-yank-articles yank))))))
488 (defun gnus-msg-treat-broken-reply-to ()
489 "Remove the Reply-to header iff broken-reply-to."
490 (when (gnus-group-find-parameter
491 gnus-newsgroup-name 'broken-reply-to)
493 (message-narrow-to-head)
494 (message-remove-header "reply-to"))))
496 (defun gnus-post-method (arg group &optional silent)
497 "Return the posting method based on GROUP and ARG.
498 If SILENT, don't prompt the user."
499 (let ((group-method (gnus-find-method-for-group group)))
501 ;; If the group-method is nil (which shouldn't happen) we use
502 ;; the default method.
504 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
505 gnus-select-method message-post-method))
506 ;; We want the inverse of the default
507 ((and arg (not (eq arg 0)))
508 (if (eq gnus-post-method 'active)
511 ;; We query the user for a post method.
513 (and gnus-post-method
514 (not (eq gnus-post-method 'current))
515 (listp (car gnus-post-method))))
517 ;; Collect all methods we know about.
519 (when (and gnus-post-method
520 (not (eq gnus-post-method 'current)))
521 (if (listp (car gnus-post-method))
523 (list gnus-post-method)))
524 gnus-secondary-select-methods
525 (mapcar 'cdr gnus-server-alist)
526 (mapcar 'car gnus-opened-servers)
527 (list gnus-select-method)
528 (list group-method)))
529 method-alist post-methods method)
530 ;; Weed out all mail methods.
532 (setq method (gnus-server-get-method "" (pop methods)))
533 (when (and (or (gnus-method-option-p method 'post)
534 (gnus-method-option-p method 'post-mail))
535 (not (member method post-methods)))
536 (push method post-methods)))
537 ;; Create a name-method alist.
541 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
546 (setq gnus-last-posting-server
548 gnus-last-posting-server)
549 ;; Just use the last value.
550 gnus-last-posting-server
552 "Posting method: " method-alist nil t
553 (cons (or gnus-last-posting-server "") 0))))
555 ;; Override normal method.
556 ((and (eq gnus-post-method 'current)
557 (not (eq (car group-method) 'nndraft))
560 ((and gnus-post-method
561 (not (eq gnus-post-method 'current)))
563 ;; Use the normal select method.
564 (t gnus-select-method))))
568 ;; Dummies to avoid byte-compile warning.
569 (defvar nnspool-rejected-article-hook)
570 (defvar xemacs-codename)
572 (defun gnus-extended-version ()
573 "Stringified Gnus version and Emacs version."
576 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
577 " (" gnus-version ")"
580 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
581 (concat "Emacs/" (match-string 1 emacs-version)))
582 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
584 (concat (match-string 1 emacs-version)
585 (format "/%d.%d" emacs-major-version emacs-minor-version)
586 (if (match-beginning 3)
587 (match-string 3 emacs-version)
589 (if (boundp 'xemacs-codename)
590 (concat " (" xemacs-codename ")")
596 ;;; Gnus Mail Functions
599 ;;; Mail reply commands of Gnus summary mode
601 (defun gnus-summary-reply (&optional yank wide)
602 "Start composing a reply mail to the current message.
603 If prefix argument YANK is non-nil, the original article is yanked
606 (list (and current-prefix-arg
607 (gnus-summary-work-articles 1))))
608 ;; Stripping headers should be specified with mail-yank-ignored-headers.
610 (gnus-summary-goto-subject (car yank)))
611 (let ((gnus-article-reply t))
612 (gnus-setup-message (if yank 'reply-yank 'reply)
613 (gnus-summary-select-article)
614 (set-buffer (gnus-copy-article-buffer))
615 (gnus-msg-treat-broken-reply-to)
616 (message-reply nil wide)
618 (gnus-inews-yank-articles yank)))))
620 (defun gnus-summary-reply-with-original (n &optional wide)
621 "Start composing a reply mail to the current message.
622 The original article will be yanked."
624 (gnus-summary-reply (gnus-summary-work-articles n) wide))
626 (defun gnus-summary-wide-reply (&optional yank)
627 "Start composing a wide reply mail to the current message.
628 If prefix argument YANK is non-nil, the original article is yanked
631 (list (and current-prefix-arg
632 (gnus-summary-work-articles 1))))
633 (gnus-summary-reply yank t))
635 (defun gnus-summary-wide-reply-with-original (n)
636 "Start composing a wide reply mail to the current message.
637 The original article will be yanked."
639 (gnus-summary-reply-with-original n t))
641 (defun gnus-summary-mail-forward (&optional not-used post)
642 "Forward the current message to another user.
643 If POST, post instead of mail."
645 (gnus-setup-message 'forward
646 (gnus-summary-select-article)
649 (set-buffer gnus-original-article-buffer)
650 (setq text (buffer-string)))
651 (set-buffer (gnus-get-buffer-create
652 (generate-new-buffer-name " *Gnus forward*")))
655 (run-hooks 'gnus-article-decode-hook)
656 (message-forward post))))
658 (defun gnus-summary-resend-message (address n)
659 "Resend the current article to ADDRESS."
660 (interactive "sResend message(s) to: \nP")
661 (let ((articles (gnus-summary-work-articles n))
663 (while (setq article (pop articles))
664 (gnus-summary-select-article nil nil nil article)
666 (set-buffer gnus-original-article-buffer)
667 (message-resend address)))))
669 (defun gnus-summary-post-forward (&optional full-headers)
670 "Forward the current article to a newsgroup.
671 If FULL-HEADERS (the prefix), include full headers when forwarding."
673 (gnus-summary-mail-forward full-headers t))
675 (defvar gnus-nastygram-message
676 "The following article was inappropriately posted to %s.\n\n"
677 "Format string to insert in nastygrams.
678 The current group name will be inserted at \"%s\".")
680 (defun gnus-summary-mail-nastygram (n)
681 "Send a nastygram to the author of the current article."
683 (when (or gnus-expert-user
685 "Really send a nastygram to the author of the current article? "))
686 (let ((group gnus-newsgroup-name))
687 (gnus-summary-reply-with-original n)
688 (set-buffer gnus-message-buffer)
690 (insert (format gnus-nastygram-message group))
691 (message-send-and-exit))))
693 (defun gnus-summary-mail-crosspost-complaint (n)
694 "Send a complaint about crossposting to the current article(s)."
696 (let ((articles (gnus-summary-work-articles n))
698 (while (setq article (pop articles))
699 (set-buffer gnus-summary-buffer)
700 (gnus-summary-goto-subject article)
701 (let ((group (gnus-group-real-name gnus-newsgroup-name))
702 newsgroups followup-to)
703 (gnus-summary-select-article)
704 (set-buffer gnus-original-article-buffer)
705 (if (and (<= (length (message-tokenize-header
707 (mail-fetch-field "newsgroups"))
710 (or (not (setq followup-to (mail-fetch-field "followup-to")))
711 (not (member group (message-tokenize-header
712 followup-to ", ")))))
714 (gnus-message 1 "Followup-to restricted")
715 (gnus-message 1 "Not a crossposted article"))
716 (set-buffer gnus-summary-buffer)
717 (gnus-summary-reply-with-original 1)
718 (set-buffer gnus-message-buffer)
720 (insert (format gnus-crosspost-complaint newsgroups group))
721 (message-goto-subject)
722 (re-search-forward " *$")
723 (replace-match " (crosspost notification)" t t)
724 (gnus-deactivate-mark)
725 (when (gnus-y-or-n-p "Send this complaint? ")
726 (message-send-and-exit)))))))
728 (defun gnus-summary-mail-other-window ()
729 "Compose mail in other window."
731 (gnus-setup-message 'message
734 (defun gnus-mail-parse-comma-list ()
737 (skip-chars-forward " ")
740 (skip-chars-forward "^,")
745 (narrow-to-region beg (point))
748 (while (search-forward "\"" nil t)
752 (skip-chars-forward ",")
753 (skip-chars-forward "^,"))
754 (skip-chars-backward " ")
755 (push (buffer-substring beg (point))
757 (skip-chars-forward "^,")
758 (skip-chars-forward ", "))
761 (defun gnus-inews-add-to-address (group)
762 (let ((to-address (mail-fetch-field "to")))
763 (when (and to-address
765 ;; This mail group doesn't have a `to-list', so we add one
768 (format "Do you want to add this as `to-list': %s " to-address))
769 (gnus-group-add-parameter group (cons 'to-list to-address))))))
771 (defun gnus-put-message ()
772 "Put the current message in some group and return to Gnus."
774 (let ((reply gnus-article-reply)
775 (winconf gnus-prev-winconf)
776 (group gnus-newsgroup-name))
778 (or (and group (not (gnus-group-read-only-p group)))
779 (setq group (read-string "Put in group: " nil
780 (gnus-writable-groups))))
781 (when (gnus-gethash group gnus-newsrc-hashtb)
782 (error "No such group: %s" group))
787 (message-narrow-to-headers)
788 (let (gnus-deletable-headers)
790 (message-generate-headers message-required-news-headers)
791 (message-generate-headers message-required-mail-headers)))
792 (goto-char (point-max))
793 (insert "Gcc: " group "\n")
798 (when (get-buffer gnus-group-buffer)
799 (when (gnus-buffer-exists-p (car-safe reply))
800 (set-buffer (car reply))
802 (gnus-summary-mark-article-as-replied
805 (set-window-configuration winconf)))))
807 (defun gnus-article-mail (yank)
808 "Send a reply to the address near point.
809 If YANK is non-nil, include the original article."
813 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
814 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
816 (message-reply address)
818 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
820 (defvar nntp-server-type)
822 "Send a bug report to the Gnus maintainers."
824 (unless (gnus-alive-p)
825 (error "Gnus has been shut down"))
826 (gnus-setup-message 'bug
827 (delete-other-windows)
828 (when gnus-bug-create-help-buffer
829 (switch-to-buffer "*Gnus Help Bug*")
831 (insert gnus-bug-message)
832 (goto-char (point-min)))
833 (message-pop-to-buffer "*Gnus Bug*")
834 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
835 (when gnus-bug-create-help-buffer
836 (push `(gnus-bug-kill-buffer) message-send-actions))
837 (goto-char (point-min))
838 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
840 (insert (gnus-version) "\n"
841 (emacs-version) "\n")
842 (when (and (boundp 'nntp-server-type)
843 (stringp nntp-server-type))
844 (insert nntp-server-type))
845 (insert "\n\n\n\n\n")
847 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
849 (insert "<#part type=application/x-emacs-lisp buffer=\" *gnus environment info*\" disposition=inline description=\"User settings\"><#/part>")
850 (goto-char (point-min))
851 (search-forward "Subject: " nil t)
854 (defun gnus-bug-kill-buffer ()
855 (when (get-buffer "*Gnus Help Bug*")
856 (kill-buffer "*Gnus Help Bug*")))
859 "Attempts to go through the Gnus source file and report what variables have been changed.
860 The source file has to be in the Emacs load path."
862 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
863 "gnus-art.el" "gnus-start.el" "gnus-async.el"
864 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
865 "nnmail.el" "message.el"))
868 (gnus-message 4 "Please wait while we snoop your variables...")
870 ;; Go through all the files looking for non-default values for variables.
872 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
875 (when (and (setq file (locate-library (pop files)))
876 (file-exists-p file))
877 (insert-file-contents file)
878 (goto-char (point-min))
879 (if (not (re-search-forward "^;;* *Internal variables" nil t))
880 (gnus-message 4 "Malformed sources in file %s" file)
881 (narrow-to-region (point-min) (point))
882 (goto-char (point-min))
883 (while (setq expr (ignore-errors (read (current-buffer))))
885 (and (or (eq (car expr) 'defvar)
886 (eq (car expr) 'defcustom))
887 (stringp (nth 3 expr))
888 (or (not (boundp (nth 1 expr)))
889 (not (equal (eval (nth 2 expr))
890 (symbol-value (nth 1 expr)))))
891 (push (nth 1 expr) olist)))))))
892 (kill-buffer (current-buffer)))
893 (when (setq olist (nreverse olist))
894 (insert "------------------ Environment follows ------------------\n\n"))
896 (if (boundp (car olist))
898 (pp `(setq ,(car olist)
899 ,(if (or (consp (setq sym (symbol-value (car olist))))
901 (not (or (eq sym nil)
903 (list 'quote (symbol-value (car olist)))
904 (symbol-value (car olist))))
907 (format "(setq %s 'whatever)\n" (car olist))))
908 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
909 (setq olist (cdr olist)))
911 ;; Remove any control chars - they seem to cause trouble for some
912 ;; mailers. (Byte-compiled output from the stuff above.)
914 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
915 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
918 ;;; Treatment of rejected articles.
921 (defun gnus-summary-resend-bounced-mail (&optional fetch)
922 "Re-mail the current message.
923 This only makes sense if the current message is a bounce message than
924 contains some mail you have written which has been bounced back to
926 If FETCH, try to fetch the article that this is a reply to, if indeed
929 (gnus-summary-select-article t)
930 (set-buffer gnus-original-article-buffer)
931 (gnus-setup-message 'compose-bounce
932 (let* ((references (mail-fetch-field "references"))
933 (parent (and references (gnus-parent-id references))))
935 ;; If there are references, we fetch the article we answered to.
937 (gnus-summary-refer-article parent)
938 (gnus-summary-show-all-headers)))))
942 ;; Do Gcc handling, which copied the message over to some group.
943 (defun gnus-inews-do-gcc (&optional gcc)
948 (message-narrow-to-headers)
949 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
950 (cur (current-buffer))
953 (message-remove-header "gcc")
955 (setq groups (message-tokenize-header gcc " ,"))
956 ;; Copy the article over to some group(s).
957 (while (setq group (pop groups))
960 (cond ((and (null (gnus-get-info group))
961 (eq (car gnus-message-archive-method)
963 (gnus-server-to-method
964 (gnus-group-method group)))))
965 ;; If the group doesn't exist, we assume
966 ;; it's an archive group...
967 gnus-message-archive-method)
969 ((gnus-info-method (gnus-get-info group))
970 (gnus-info-method (gnus-get-info group)))
972 (t (gnus-group-method group)))))
973 (gnus-check-server method)
974 (unless (gnus-request-group group t method)
975 (gnus-request-create-group group method))
977 (nnheader-set-temp-buffer " *acc*")
978 (insert-buffer-substring cur)
979 (message-encode-message-body)
981 (message-narrow-to-headers)
982 (mail-encode-encoded-word-buffer))
983 (goto-char (point-min))
984 (when (re-search-forward
985 (concat "^" (regexp-quote mail-header-separator) "$")
987 (replace-match "" t t ))
988 (unless (gnus-request-accept-article group method t t)
989 (gnus-message 1 "Couldn't store article in group %s: %s"
990 group (gnus-status-message method))
992 (kill-buffer (current-buffer))))))))))
994 (defun gnus-inews-insert-gcc ()
995 "Insert Gcc headers based on `gnus-outgoing-message-group'."
998 (message-narrow-to-headers)
999 (let* ((group gnus-outgoing-message-group)
1001 ((gnus-functionp group)
1003 ((or (stringp group) (list group))
1007 (if (stringp gcc) gcc
1008 (mapconcat 'identity gcc " "))
1011 (defun gnus-inews-insert-archive-gcc (&optional group)
1012 "Insert the Gcc to say where the article is to be archived."
1013 (let* ((var gnus-message-archive-group)
1014 (group (or group gnus-newsgroup-name ""))
1016 (and gnus-newsgroup-name
1017 (gnus-group-find-parameter
1018 gnus-newsgroup-name 'gcc-self)))
1022 ((null gnus-message-archive-method)
1026 ;; Just a single group.
1029 ;; We don't want this.
1031 ((and (listp var) (stringp (car var)))
1032 ;; A list of groups.
1034 ((gnus-functionp var)
1036 (funcall var group))
1038 ;; An alist of regexps/functions/forms.
1043 ((stringp (caar var))
1045 (when (string-match (caar var) group)
1047 ((gnus-functionp (car var))
1049 (funcall (car var) group))
1051 (eval (car var)))))))
1052 (setq var (cdr var)))
1055 (when (or groups gcc-self-val)
1056 (when (stringp groups)
1057 (setq groups (list groups)))
1060 (message-narrow-to-headers)
1061 (goto-char (point-max))
1064 ;; Use the `gcc-self' param value instead.
1067 (if (stringp gcc-self-val)
1070 (if (not (eq gcc-self-val 'none))
1075 ;; Use the list of groups.
1076 (while (setq name (pop groups))
1077 (insert (if (string-match ":" name)
1079 (gnus-group-prefixed-name
1080 name gnus-message-archive-method)))
1087 (defun gnus-configure-posting-styles ()
1088 "Configure posting styles according to `gnus-posting-styles'."
1089 (unless gnus-inhibit-posting-styles
1090 (let ((group (or gnus-newsgroup-name ""))
1091 (styles gnus-posting-styles)
1092 style match variable attribute value v styles results
1093 filep name address element)
1094 ;; If the group has a posting-style parameter, add it at the end with a
1095 ;; regexp matching everything, to be sure it takes precedence over all
1097 (when gnus-newsgroup-name
1098 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1100 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1101 ;; Go through all styles and look for matches.
1102 (dolist (style styles)
1103 (setq match (pop style))
1106 ;; Regexp string match on the group name.
1107 (string-match match gnus-newsgroup-name))
1108 ((or (symbolp match)
1109 (gnus-functionp match))
1111 ((gnus-functionp match)
1112 ;; Function to be called.
1115 ;; Variable to be checked.
1116 (symbol-value match))))
1118 ;; This is a form to be evaled.
1120 ;; We have a match, so we set the variables.
1121 (dolist (attribute style)
1122 (setq element (pop attribute)
1127 ((eq (car attribute) :file)
1130 ((eq (car attribute) :value)
1134 ;; We get the value.
1139 ((or (symbolp value)
1140 (gnus-functionp value))
1141 (cond ((gnus-functionp value)
1144 (symbol-value value))))
1147 ;; Translate obsolescent value.
1148 (when (eq element 'signature-file)
1149 (setq element 'signature
1151 ;; Get the contents of file elems.
1153 (setq v (with-temp-buffer
1154 (insert-file-contents v)
1156 (setq results (delq (assoc element results) results))
1159 ;; Now we have all the styles, so we insert them.
1160 (setq name (assq 'name results)
1161 address (assq 'address results))
1162 (setq results (delq name (delq address results)))
1163 (make-local-variable 'message-setup-hook)
1164 (dolist (result results)
1166 (add-hook 'message-setup-hook
1168 ((eq 'body (car result))
1172 (insert ,(cdr result)))))
1173 ((eq 'signature (car result))
1174 (set (make-local-variable 'message-signature) nil)
1175 (set (make-local-variable 'message-signature-file) nil)
1178 (let ((message-signature ,(cdr result)))
1179 (message-insert-signature)))))
1182 (if (symbolp (car result))
1183 (capitalize (symbol-name (car result)))
1187 (message-remove-header ,header)
1189 (insert ,header ": " ,(cdr result) "\n")))))))))
1190 (when (or name address)
1191 (add-hook 'message-setup-hook
1193 (let ((user-full-name ,(or (cdr name) user-full-name))
1195 ,(or (cdr address) user-mail-address)))
1197 (message-remove-header "From")
1199 (insert "From: " (message-make-from) "\n")))))))))
1201 ;;; Allow redefinition of functions.
1207 ;;; gnus-msg.el ends here