1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995-2000 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 'current
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 select method when posting.
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\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
105 (message-this-is-mail nil nil)
106 (message-this-is-news nil t))
107 "Alist of regexps and permitted unencoded charsets for posting.
108 Each element of the alist has the form (TEST HEADER BODY-LIST), where
109 TEST is either a regular expression matching the newsgroup header or a
111 HEADER is the charset which may be left unencoded in the header (nil
112 means encode all charsets),
113 BODY-LIST is a list of charsets which may be encoded using 8bit
114 content-transfer encoding in the body, or one of the special values
115 nil (always encode using quoted-printable) or t (always use 8bit).
117 Note that any value other tha nil for HEADER infringes some RFCs, so
118 use this option with care."
119 :type '(repeat (list :tag "Permitted unencoded charsets"
121 (regexp :tag "Group")
122 (const :tag "Mail message" :value message-this-is-mail)
123 (const :tag "News article" :value message-this-is-news))
124 (choice :tag "Header"
125 (const :tag "None" nil)
126 (symbol :tag "Charset"))
128 (const :tag "Any" :value t)
129 (const :tag "None" :value nil)
130 (repeat :tag "Charsets"
131 (symbol :tag "Charset")))))
132 :group 'gnus-charset)
134 ;;; Internal variables.
136 (defvar gnus-inhibit-posting-styles nil
137 "Inhibit the use of posting styles.")
139 (defvar gnus-message-buffer "*Mail Gnus*")
140 (defvar gnus-article-copy nil)
141 (defvar gnus-last-posting-server nil)
142 (defvar gnus-message-group-art nil)
144 (defconst gnus-bug-message
145 "Sending a bug report to the Gnus Towers.
146 ========================================
148 The buffer below is a mail buffer. When you press `C-c C-c', it will
149 be sent to the Gnus Bug Exterminators.
151 The thing near the bottom of the buffer is how the environment
152 settings will be included in the mail. Please do not delete that.
153 They will tell the Bug People what your environment is, so that it
154 will be easier to locate the bugs.
156 If you have found a bug that makes Emacs go \"beep\", set
157 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
158 and include the backtrace in your bug report.
160 Please describe the bug in annoying, painstaking detail.
162 Thank you for your help in stamping out bugs.
166 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
167 (autoload 'news-setup "rnewspost")
168 (autoload 'news-reply-mode "rnewspost")
169 (autoload 'rmail-dont-reply-to "mail-utils")
170 (autoload 'rmail-output "rmailout"))
174 ;;; Gnus Posting Functions
177 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
178 "p" gnus-summary-post-news
179 "f" gnus-summary-followup
180 "F" gnus-summary-followup-with-original
181 "c" gnus-summary-cancel-article
182 "s" gnus-summary-supersede-article
183 "r" gnus-summary-reply
184 "y" gnus-summary-yank-message
185 "R" gnus-summary-reply-with-original
186 "w" gnus-summary-wide-reply
187 "W" gnus-summary-wide-reply-with-original
188 "n" gnus-summary-followup-to-mail
189 "N" gnus-summary-followup-to-mail-with-original
190 "m" gnus-summary-mail-other-window
191 "u" gnus-uu-post-news
192 "\M-c" gnus-summary-mail-crosspost-complaint
193 "om" gnus-summary-mail-forward
194 "op" gnus-summary-post-forward
195 "Om" gnus-uu-digest-mail-forward
196 "Op" gnus-uu-digest-post-forward)
198 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
199 "b" gnus-summary-resend-bounced-mail
200 ;; "c" gnus-summary-send-draft
201 "r" gnus-summary-resend-message)
203 ;;; Internal functions.
205 (defvar gnus-article-reply nil)
206 (defmacro gnus-setup-message (config &rest forms)
207 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
208 (buffer (make-symbol "gnus-setup-message-buffer"))
209 (article (make-symbol "gnus-setup-message-article"))
210 (group (make-symbol "gnus-setup-message-group")))
211 `(let ((,winconf (current-window-configuration))
212 (,buffer (buffer-name (current-buffer)))
213 (,article (and gnus-article-reply (gnus-summary-article-number)))
214 (,group gnus-newsgroup-name)
215 (message-header-setup-hook
216 (copy-sequence message-header-setup-hook))
217 (message-mode-hook (copy-sequence message-mode-hook)))
218 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
219 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
220 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
224 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
225 (setq gnus-message-buffer (current-buffer))
226 (set (make-local-variable 'gnus-message-group-art)
227 (cons ,group ,article))
228 (set (make-local-variable 'gnus-newsgroup-name) ,group)
229 (gnus-run-hooks 'gnus-message-setup-hook))
231 (gnus-configure-windows ,config t)
232 (set-buffer-modified-p nil))))
234 (defun gnus-setup-posting-charset (group)
235 (let ((alist gnus-group-posting-charset-alist)
236 (group (or group ""))
240 (while (setq elem (pop alist))
241 (when (or (and (stringp (car elem))
242 (string-match (car elem) group))
243 (and (gnus-functionp (car elem))
244 (funcall (car elem) group))
245 (and (symbolp (car elem))
246 (symbol-value (car elem))))
247 (throw 'found (cons (cadr elem) (caddr elem)))))))))
249 (defun gnus-inews-add-send-actions (winconf buffer article)
250 (make-local-hook 'message-sent-hook)
251 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
252 (setq message-post-method
254 (gnus-post-method arg ,gnus-newsgroup-name)))
255 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
257 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
259 `(when (gnus-buffer-exists-p ,buffer)
263 `(gnus-summary-mark-article-as-replied ,article))))
266 (put 'gnus-setup-message 'lisp-indent-function 1)
267 (put 'gnus-setup-message 'edebug-form-spec '(form body))
269 ;;; Post news commands of Gnus group mode and summary mode
271 (defun gnus-group-mail (&optional arg)
272 "Start composing a mail.
273 If ARG, use the group under the point to find a posting style.
274 If ARG is 1, prompt for a group name to find the posting style."
276 ;; We can't `let' gnus-newsgroup-name here, since that leads
277 ;; to local variables leaking.
278 (let ((group gnus-newsgroup-name)
279 (buffer (current-buffer)))
282 (setq gnus-newsgroup-name
284 (if (= 1 (prefix-numeric-value arg))
285 (completing-read "Use posting style of group: "
286 gnus-active-hashtb nil
287 (gnus-read-active-file-p))
288 (gnus-group-group-name))
290 (gnus-setup-message 'message (message-mail)))
293 (setq gnus-newsgroup-name group)))))
295 (defun gnus-group-post-news (&optional arg)
296 "Start composing a news message.
297 If ARG, post to the group under point.
298 If ARG is 1, prompt for a group name."
300 ;; Bind this variable here to make message mode hooks work ok.
301 (let ((gnus-newsgroup-name
303 (if (= 1 (prefix-numeric-value arg))
304 (completing-read "Newsgroup: " gnus-active-hashtb nil
305 (gnus-read-active-file-p))
306 (gnus-group-group-name))
308 (gnus-post-news 'post gnus-newsgroup-name)))
310 (defun gnus-summary-post-news ()
311 "Start composing a news message."
313 (gnus-post-news 'post gnus-newsgroup-name))
315 (defun gnus-summary-followup (yank &optional force-news)
316 "Compose a followup to an article.
317 If prefix argument YANK is non-nil, original article is yanked automatically."
319 (list (and current-prefix-arg
320 (gnus-summary-work-articles 1))))
322 (gnus-summary-goto-subject (car yank)))
323 (save-window-excursion
324 (gnus-summary-select-article))
325 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
326 (gnus-newsgroup-name gnus-newsgroup-name))
328 (gnus-post-news nil gnus-newsgroup-name
329 headers gnus-article-buffer
330 yank nil force-news)))
332 (defun gnus-summary-followup-with-original (n &optional force-news)
333 "Compose a followup to an article and include the original article."
335 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
337 (defun gnus-summary-followup-to-mail (&optional arg)
338 "Followup to the current mail message via news."
340 (list (and current-prefix-arg
341 (gnus-summary-work-articles 1))))
342 (gnus-summary-followup arg t))
344 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
345 "Followup to the current mail message via news."
347 (gnus-summary-followup (gnus-summary-work-articles arg) t))
349 (defun gnus-inews-yank-articles (articles)
352 (while (setq article (pop articles))
353 (save-window-excursion
354 (set-buffer gnus-summary-buffer)
355 (gnus-summary-select-article nil nil nil article)
356 (gnus-summary-remove-process-mark article))
357 (gnus-copy-article-buffer)
358 (let ((message-reply-buffer gnus-article-copy)
359 (message-reply-headers gnus-current-headers))
360 (message-yank-original)
361 (setq beg (or beg (mark t))))
367 (defun gnus-summary-cancel-article (&optional n symp)
368 "Cancel an article you posted.
369 Uses the process-prefix convention. If given the symbolic
370 prefix `a', cancel using the standard posting method; if not
371 post using the current select method."
372 (interactive (gnus-interactive "P\ny"))
373 (let ((articles (gnus-summary-work-articles n))
376 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
378 (while (setq article (pop articles))
379 (when (gnus-summary-select-article t nil nil article)
380 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
381 (message-cancel-news))
382 (gnus-summary-mark-as-read article gnus-canceled-mark)
383 (gnus-cache-remove-article 1))
384 (gnus-article-hide-headers-if-wanted))
385 (gnus-summary-remove-process-mark article))))
387 (defun gnus-summary-supersede-article ()
388 "Compose an article that will supersede a previous article.
389 This is done simply by taking the old article and adding a Supersedes
390 header line with the old Message-ID."
392 (let ((article (gnus-summary-article-number)))
393 (gnus-setup-message 'reply-yank
394 (gnus-summary-select-article t)
395 (set-buffer gnus-original-article-buffer)
399 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
401 (set-buffer ,gnus-summary-buffer)
402 (gnus-cache-possibly-remove-article ,article nil nil nil t)
403 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
404 message-send-actions))))
408 (defun gnus-copy-article-buffer (&optional article-buffer)
409 ;; make a copy of the article buffer with all text properties removed
410 ;; this copy is in the buffer gnus-article-copy.
411 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
412 ;; this buffer should be passed to all mail/news reply/post routines.
413 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
415 (set-buffer gnus-article-copy)
416 (mm-enable-multibyte))
417 (let ((article-buffer (or article-buffer gnus-article-buffer))
419 (if (not (and (get-buffer article-buffer)
420 (gnus-buffer-exists-p article-buffer)))
421 (error "Can't find any article buffer")
423 (set-buffer article-buffer)
425 ;; Copy over the (displayed) article buffer, delete
426 ;; hidden text and remove text properties.
428 (copy-to-buffer gnus-article-copy (point-min) (point-max))
429 (set-buffer gnus-article-copy)
430 (gnus-article-delete-text-of-type 'annotation)
431 (gnus-remove-text-with-property 'gnus-prev)
432 (gnus-remove-text-with-property 'gnus-next)
435 (format "%s" (buffer-string))
437 ;; Find the original headers.
438 (set-buffer gnus-original-article-buffer)
439 (goto-char (point-min))
440 (while (looking-at message-unix-mail-delimiter)
443 (setq end (or (search-forward "\n\n" nil t) (point)))
444 ;; Delete the headers from the displayed articles.
445 (set-buffer gnus-article-copy)
446 (delete-region (goto-char (point-min))
447 (or (search-forward "\n\n" nil t) (point-max)))
448 ;; Insert the original article headers.
449 (insert-buffer-substring gnus-original-article-buffer beg end)
450 (article-decode-encoded-words)))
453 (defun gnus-post-news (post &optional group header article-buffer yank subject
456 (gnus-copy-article-buffer))
457 (let ((gnus-article-reply article-buffer)
458 (add-to-list gnus-add-to-list))
459 (gnus-setup-message (cond (yank 'reply-yank)
460 (article-buffer 'reply)
462 (let* ((group (or group gnus-newsgroup-name))
464 to-address to-group mailing-list to-list
467 (setq to-address (gnus-group-find-parameter group 'to-address)
468 to-group (gnus-group-find-parameter group 'to-group)
469 to-list (gnus-group-find-parameter group 'to-list)
470 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
471 mailing-list (when gnus-mailing-list-groups
472 (string-match gnus-mailing-list-groups group))
473 group (gnus-group-real-name group)))
474 (if (or (and to-group
475 (gnus-news-group-p to-group))
478 (and (gnus-news-group-p
479 (or pgroup gnus-newsgroup-name)
480 (if header (mail-header-number header)
481 gnus-current-article))
487 (message-news (or to-group group))
488 (set-buffer gnus-article-copy)
489 (gnus-msg-treat-broken-reply-to)
490 (message-followup (if (or newsgroup-p force-news) nil to-group)))
494 (message-mail (or to-address to-list))
495 ;; Arrange for mail groups that have no `to-address' to
496 ;; get that when the user sends off the mail.
497 (when (and (not to-list)
500 (push (list 'gnus-inews-add-to-address pgroup)
501 message-send-actions)))
502 (set-buffer gnus-article-copy)
503 (gnus-msg-treat-broken-reply-to)
504 (message-wide-reply to-address)))
506 (gnus-inews-yank-articles yank))))))
508 (defun gnus-msg-treat-broken-reply-to ()
509 "Remove the Reply-to header iff broken-reply-to."
510 (when (gnus-group-find-parameter
511 gnus-newsgroup-name 'broken-reply-to)
513 (message-narrow-to-head)
514 (message-remove-header "reply-to"))))
516 (defun gnus-post-method (arg group &optional silent)
517 "Return the posting method based on GROUP and ARG.
518 If SILENT, don't prompt the user."
519 (let ((group-method (gnus-find-method-for-group group)))
521 ;; If the group-method is nil (which shouldn't happen) we use
522 ;; the default method.
524 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
525 gnus-select-method message-post-method))
526 ;; We want the inverse of the default
527 ((and arg (not (eq arg 0)))
528 (if (eq gnus-post-method 'active)
531 ;; We query the user for a post method.
533 (and gnus-post-method
534 (not (eq gnus-post-method 'current))
535 (listp (car gnus-post-method))))
537 ;; Collect all methods we know about.
539 (when (and gnus-post-method
540 (not (eq gnus-post-method 'current)))
541 (if (listp (car gnus-post-method))
543 (list gnus-post-method)))
544 gnus-secondary-select-methods
545 (mapcar 'cdr gnus-server-alist)
546 (mapcar 'car gnus-opened-servers)
547 (list gnus-select-method)
548 (list group-method)))
549 method-alist post-methods method)
550 ;; Weed out all mail methods.
552 (setq method (gnus-server-get-method "" (pop methods)))
553 (when (and (or (gnus-method-option-p method 'post)
554 (gnus-method-option-p method 'post-mail))
555 (not (member method post-methods)))
556 (push method post-methods)))
557 ;; Create a name-method alist.
561 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
566 (setq gnus-last-posting-server
568 gnus-last-posting-server)
569 ;; Just use the last value.
570 gnus-last-posting-server
572 "Posting method: " method-alist nil t
573 (cons (or gnus-last-posting-server "") 0))))
575 ;; Override normal method.
576 ((and (eq gnus-post-method 'current)
577 (not (eq (car group-method) 'nndraft))
578 (gnus-get-function group-method 'request-post t)
581 ((and gnus-post-method
582 (not (eq gnus-post-method 'current)))
584 ;; Use the normal select method.
585 (t gnus-select-method))))
589 ;; Dummies to avoid byte-compile warning.
590 (defvar nnspool-rejected-article-hook)
591 (defvar xemacs-codename)
593 (defun gnus-extended-version ()
594 "Stringified Gnus version and Emacs version."
597 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
598 " (" gnus-version ")"
601 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
602 (concat "Emacs/" (match-string 1 emacs-version)))
603 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
605 (concat (match-string 1 emacs-version)
606 (format "/%d.%d" emacs-major-version emacs-minor-version)
607 (if (match-beginning 3)
608 (match-string 3 emacs-version)
610 (if (boundp 'xemacs-codename)
611 (concat " (" xemacs-codename ")")
617 ;;; Gnus Mail Functions
620 ;;; Mail reply commands of Gnus summary mode
622 (defun gnus-summary-reply (&optional yank wide)
623 "Start composing a reply mail to the current message.
624 If prefix argument YANK is non-nil, the original article is yanked
627 (list (and current-prefix-arg
628 (gnus-summary-work-articles 1))))
629 ;; Stripping headers should be specified with mail-yank-ignored-headers.
631 (gnus-summary-goto-subject (car yank)))
632 (let ((gnus-article-reply t))
633 (gnus-setup-message (if yank 'reply-yank 'reply)
634 (gnus-summary-select-article)
635 (set-buffer (gnus-copy-article-buffer))
636 (gnus-msg-treat-broken-reply-to)
637 (message-reply nil wide)
639 (gnus-inews-yank-articles yank)))))
641 (defun gnus-summary-reply-with-original (n &optional wide)
642 "Start composing a reply mail to the current message.
643 The original article will be yanked."
645 (gnus-summary-reply (gnus-summary-work-articles n) wide))
647 (defun gnus-summary-wide-reply (&optional yank)
648 "Start composing a wide reply mail to the current message.
649 If prefix argument YANK is non-nil, the original article is yanked
652 (list (and current-prefix-arg
653 (gnus-summary-work-articles 1))))
654 (gnus-summary-reply yank t))
656 (defun gnus-summary-wide-reply-with-original (n)
657 "Start composing a wide reply mail to the current message.
658 The original article will be yanked."
660 (gnus-summary-reply-with-original n t))
662 (defun gnus-summary-mail-forward (&optional not-used post)
663 "Forward the current message to another user.
664 If POST, post instead of mail."
666 (gnus-setup-message 'forward
667 (gnus-summary-select-article)
670 (set-buffer gnus-original-article-buffer)
671 (setq text (buffer-string)))
672 (set-buffer (gnus-get-buffer-create
673 (generate-new-buffer-name " *Gnus forward*")))
676 (goto-char (point-min))
677 (when (looking-at "From ")
678 (replace-match "X-From-Line: ") )
679 (run-hooks 'gnus-article-decode-hook)
680 (message-forward post))))
682 (defun gnus-summary-resend-message (address n)
683 "Resend the current article to ADDRESS."
684 (interactive "sResend message(s) to: \nP")
685 (let ((articles (gnus-summary-work-articles n))
687 (while (setq article (pop articles))
688 (gnus-summary-select-article nil nil nil article)
690 (set-buffer gnus-original-article-buffer)
691 (message-resend address)))))
693 (defun gnus-summary-post-forward (&optional full-headers)
694 "Forward the current article to a newsgroup.
695 If FULL-HEADERS (the prefix), include full headers when forwarding."
697 (gnus-summary-mail-forward full-headers t))
699 (defvar gnus-nastygram-message
700 "The following article was inappropriately posted to %s.\n\n"
701 "Format string to insert in nastygrams.
702 The current group name will be inserted at \"%s\".")
704 (defun gnus-summary-mail-nastygram (n)
705 "Send a nastygram to the author of the current article."
707 (when (or gnus-expert-user
709 "Really send a nastygram to the author of the current article? "))
710 (let ((group gnus-newsgroup-name))
711 (gnus-summary-reply-with-original n)
712 (set-buffer gnus-message-buffer)
714 (insert (format gnus-nastygram-message group))
715 (message-send-and-exit))))
717 (defun gnus-summary-mail-crosspost-complaint (n)
718 "Send a complaint about crossposting to the current article(s)."
720 (let ((articles (gnus-summary-work-articles n))
722 (while (setq article (pop articles))
723 (set-buffer gnus-summary-buffer)
724 (gnus-summary-goto-subject article)
725 (let ((group (gnus-group-real-name gnus-newsgroup-name))
726 newsgroups followup-to)
727 (gnus-summary-select-article)
728 (set-buffer gnus-original-article-buffer)
729 (if (and (<= (length (message-tokenize-header
731 (mail-fetch-field "newsgroups"))
734 (or (not (setq followup-to (mail-fetch-field "followup-to")))
735 (not (member group (message-tokenize-header
736 followup-to ", ")))))
738 (gnus-message 1 "Followup-to restricted")
739 (gnus-message 1 "Not a crossposted article"))
740 (set-buffer gnus-summary-buffer)
741 (gnus-summary-reply-with-original 1)
742 (set-buffer gnus-message-buffer)
744 (insert (format gnus-crosspost-complaint newsgroups group))
745 (message-goto-subject)
746 (re-search-forward " *$")
747 (replace-match " (crosspost notification)" t t)
748 (gnus-deactivate-mark)
749 (when (gnus-y-or-n-p "Send this complaint? ")
750 (message-send-and-exit)))))))
752 (defun gnus-summary-mail-other-window ()
753 "Compose mail in other window."
755 (gnus-setup-message 'message
758 (defun gnus-mail-parse-comma-list ()
761 (skip-chars-forward " ")
764 (skip-chars-forward "^,")
769 (narrow-to-region beg (point))
772 (while (search-forward "\"" nil t)
776 (skip-chars-forward ",")
777 (skip-chars-forward "^,"))
778 (skip-chars-backward " ")
779 (push (buffer-substring beg (point))
781 (skip-chars-forward "^,")
782 (skip-chars-forward ", "))
785 (defun gnus-inews-add-to-address (group)
786 (let ((to-address (mail-fetch-field "to")))
787 (when (and to-address
789 ;; This mail group doesn't have a `to-list', so we add one
792 (format "Do you want to add this as `to-list': %s " to-address))
793 (gnus-group-add-parameter group (cons 'to-list to-address))))))
795 (defun gnus-put-message ()
796 "Put the current message in some group and return to Gnus."
798 (let ((reply gnus-article-reply)
799 (winconf gnus-prev-winconf)
800 (group gnus-newsgroup-name))
802 (or (and group (not (gnus-group-read-only-p group)))
803 (setq group (read-string "Put in group: " nil
804 (gnus-writable-groups))))
805 (when (gnus-gethash group gnus-newsrc-hashtb)
806 (error "No such group: %s" group))
811 (message-narrow-to-headers)
812 (let (gnus-deletable-headers)
814 (message-generate-headers message-required-news-headers)
815 (message-generate-headers message-required-mail-headers)))
816 (goto-char (point-max))
817 (insert "Gcc: " group "\n")
822 (when (get-buffer gnus-group-buffer)
823 (when (gnus-buffer-exists-p (car-safe reply))
824 (set-buffer (car reply))
826 (gnus-summary-mark-article-as-replied
829 (set-window-configuration winconf)))))
831 (defun gnus-article-mail (yank)
832 "Send a reply to the address near point.
833 If YANK is non-nil, include the original article."
837 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
838 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
840 (message-reply address)
842 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
844 (defvar nntp-server-type)
846 "Send a bug report to the Gnus maintainers."
848 (unless (gnus-alive-p)
849 (error "Gnus has been shut down"))
850 (gnus-setup-message 'bug
851 (delete-other-windows)
852 (when gnus-bug-create-help-buffer
853 (switch-to-buffer "*Gnus Help Bug*")
855 (insert gnus-bug-message)
856 (goto-char (point-min)))
857 (message-pop-to-buffer "*Gnus Bug*")
858 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
859 (when gnus-bug-create-help-buffer
860 (push `(gnus-bug-kill-buffer) message-send-actions))
861 (goto-char (point-min))
862 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
864 (insert (gnus-version) "\n"
865 (emacs-version) "\n")
866 (when (and (boundp 'nntp-server-type)
867 (stringp nntp-server-type))
868 (insert nntp-server-type))
869 (insert "\n\n\n\n\n")
871 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
873 (insert "<#part type=application/x-emacs-lisp buffer=\" *gnus environment info*\" disposition=inline description=\"User settings\"><#/part>")
874 (goto-char (point-min))
875 (search-forward "Subject: " nil t)
878 (defun gnus-bug-kill-buffer ()
879 (when (get-buffer "*Gnus Help Bug*")
880 (kill-buffer "*Gnus Help Bug*")))
882 (defun gnus-summary-yank-message (buffer n)
883 "Yank the current article into a composed message."
885 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
887 (gnus-summary-iterate n
888 (let ((gnus-display-mime-function nil)
889 (gnus-inhibit-treatment t))
890 (gnus-summary-select-article))
893 (message-yank-buffer gnus-article-buffer))))
896 "Attempts to go through the Gnus source file and report what variables have been changed.
897 The source file has to be in the Emacs load path."
899 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
900 "gnus-art.el" "gnus-start.el" "gnus-async.el"
901 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
902 "nnmail.el" "message.el"))
905 (gnus-message 4 "Please wait while we snoop your variables...")
907 ;; Go through all the files looking for non-default values for variables.
909 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
912 (when (and (setq file (locate-library (pop files)))
913 (file-exists-p file))
914 (insert-file-contents file)
915 (goto-char (point-min))
916 (if (not (re-search-forward "^;;* *Internal variables" nil t))
917 (gnus-message 4 "Malformed sources in file %s" file)
918 (narrow-to-region (point-min) (point))
919 (goto-char (point-min))
920 (while (setq expr (ignore-errors (read (current-buffer))))
922 (and (or (eq (car expr) 'defvar)
923 (eq (car expr) 'defcustom))
924 (stringp (nth 3 expr))
925 (or (not (boundp (nth 1 expr)))
926 (not (equal (eval (nth 2 expr))
927 (symbol-value (nth 1 expr)))))
928 (push (nth 1 expr) olist)))))))
929 (kill-buffer (current-buffer)))
930 (when (setq olist (nreverse olist))
931 (insert "------------------ Environment follows ------------------\n\n"))
933 (if (boundp (car olist))
935 (pp `(setq ,(car olist)
936 ,(if (or (consp (setq sym (symbol-value (car olist))))
938 (not (or (eq sym nil)
940 (list 'quote (symbol-value (car olist)))
941 (symbol-value (car olist))))
944 (format "(setq %s 'whatever)\n" (car olist))))
945 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
946 (setq olist (cdr olist)))
948 ;; Remove any control chars - they seem to cause trouble for some
949 ;; mailers. (Byte-compiled output from the stuff above.)
951 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
952 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
955 ;;; Treatment of rejected articles.
958 (defun gnus-summary-resend-bounced-mail (&optional fetch)
959 "Re-mail the current message.
960 This only makes sense if the current message is a bounce message than
961 contains some mail you have written which has been bounced back to
963 If FETCH, try to fetch the article that this is a reply to, if indeed
966 (gnus-summary-select-article t)
967 (set-buffer gnus-original-article-buffer)
968 (gnus-setup-message 'compose-bounce
969 (let* ((references (mail-fetch-field "references"))
970 (parent (and references (gnus-parent-id references))))
972 ;; If there are references, we fetch the article we answered to.
974 (gnus-summary-refer-article parent)
975 (gnus-summary-show-all-headers)))))
979 ;; Do Gcc handling, which copied the message over to some group.
980 (defun gnus-inews-do-gcc (&optional gcc)
985 (message-narrow-to-headers)
986 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
987 (cur (current-buffer))
990 (message-remove-header "gcc")
992 (setq groups (message-tokenize-header gcc " ,"))
993 ;; Copy the article over to some group(s).
994 (while (setq group (pop groups))
997 (cond ((and (null (gnus-get-info group))
998 (eq (car gnus-message-archive-method)
1000 (gnus-server-to-method
1001 (gnus-group-method group)))))
1002 ;; If the group doesn't exist, we assume
1003 ;; it's an archive group...
1004 gnus-message-archive-method)
1006 ((gnus-info-method (gnus-get-info group))
1007 (gnus-info-method (gnus-get-info group)))
1009 (t (gnus-group-method group)))))
1010 (gnus-check-server method)
1011 (unless (gnus-request-group group t method)
1012 (gnus-request-create-group group method))
1014 (nnheader-set-temp-buffer " *acc*")
1015 (insert-buffer-substring cur)
1016 (message-encode-message-body)
1018 (message-narrow-to-headers)
1019 (mail-encode-encoded-word-buffer))
1020 (goto-char (point-min))
1021 (when (re-search-forward
1022 (concat "^" (regexp-quote mail-header-separator) "$")
1024 (replace-match "" t t ))
1025 (unless (gnus-request-accept-article group method t t)
1026 (gnus-message 1 "Couldn't store article in group %s: %s"
1027 group (gnus-status-message method))
1029 (kill-buffer (current-buffer))))))))))
1031 (defun gnus-inews-insert-gcc ()
1032 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1035 (message-narrow-to-headers)
1036 (let* ((group gnus-outgoing-message-group)
1038 ((gnus-functionp group)
1040 ((or (stringp group) (list group))
1044 (if (stringp gcc) gcc
1045 (mapconcat 'identity gcc " "))
1048 (defun gnus-inews-insert-archive-gcc (&optional group)
1049 "Insert the Gcc to say where the article is to be archived."
1050 (let* ((var gnus-message-archive-group)
1051 (group (or group gnus-newsgroup-name ""))
1053 (and gnus-newsgroup-name
1054 (not (equal gnus-newsgroup-name ""))
1055 (gnus-group-find-parameter
1056 gnus-newsgroup-name 'gcc-self)))
1060 ((null gnus-message-archive-method)
1064 ;; Just a single group.
1067 ;; We don't want this.
1069 ((and (listp var) (stringp (car var)))
1070 ;; A list of groups.
1072 ((gnus-functionp var)
1074 (funcall var group))
1076 ;; An alist of regexps/functions/forms.
1081 ((stringp (caar var))
1083 (when (string-match (caar var) group)
1085 ((gnus-functionp (car var))
1087 (funcall (car var) group))
1089 (eval (car var)))))))
1090 (setq var (cdr var)))
1093 (when (or groups gcc-self-val)
1094 (when (stringp groups)
1095 (setq groups (list groups)))
1098 (message-narrow-to-headers)
1099 (goto-char (point-max))
1102 ;; Use the `gcc-self' param value instead.
1105 (if (stringp gcc-self-val)
1108 (if (not (eq gcc-self-val 'none))
1113 ;; Use the list of groups.
1114 (while (setq name (pop groups))
1115 (insert (if (string-match ":" name)
1117 (gnus-group-prefixed-name
1118 name gnus-message-archive-method)))
1125 (defun gnus-configure-posting-styles ()
1126 "Configure posting styles according to `gnus-posting-styles'."
1127 (unless gnus-inhibit-posting-styles
1128 (let ((group (or gnus-newsgroup-name ""))
1129 (styles gnus-posting-styles)
1130 style match variable attribute value v results
1131 filep name address element)
1132 ;; If the group has a posting-style parameter, add it at the end with a
1133 ;; regexp matching everything, to be sure it takes precedence over all
1135 (when gnus-newsgroup-name
1136 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1138 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1139 ;; Go through all styles and look for matches.
1140 (dolist (style styles)
1141 (setq match (pop style))
1142 (goto-char (point-min))
1145 ;; Regexp string match on the group name.
1146 (string-match match group))
1148 (let ((header (message-fetch-field (pop style))))
1150 (string-match (pop style) header))))
1151 ((or (symbolp match)
1152 (gnus-functionp match))
1154 ((gnus-functionp match)
1155 ;; Function to be called.
1158 ;; Variable to be checked.
1159 (symbol-value match))))
1161 ;; This is a form to be evaled.
1163 ;; We have a match, so we set the variables.
1164 (dolist (attribute style)
1165 (setq element (pop attribute)
1170 ((eq (car attribute) :file)
1173 ((eq (car attribute) :value)
1177 ;; We get the value.
1182 ((or (symbolp value)
1183 (gnus-functionp value))
1184 (cond ((gnus-functionp value)
1187 (symbol-value value))))
1190 ;; Translate obsolescent value.
1191 (when (eq element 'signature-file)
1192 (setq element 'signature
1194 ;; Get the contents of file elems.
1196 (setq v (with-temp-buffer
1197 (insert-file-contents v)
1199 (setq results (delq (assoc element results) results))
1200 (push (cons element v) results))))
1201 ;; Now we have all the styles, so we insert them.
1202 (setq name (assq 'name results)
1203 address (assq 'address results))
1204 (setq results (delq name (delq address results)))
1205 (make-local-variable 'message-setup-hook)
1206 (dolist (result results)
1208 (add-hook 'message-setup-hook
1210 ((eq 'eval (car result))
1212 ((eq 'body (car result))
1216 (insert ,(cdr result)))))
1217 ((eq 'signature (car result))
1218 (set (make-local-variable 'message-signature) nil)
1219 (set (make-local-variable 'message-signature-file) nil)
1220 (if (not (cdr result))
1224 (let ((message-signature ,(cdr result)))
1225 (when message-signature
1226 (message-insert-signature)))))))
1229 (if (symbolp (car result))
1230 (capitalize (symbol-name (car result)))
1234 (message-remove-header ,header)
1236 (insert ,header ": " ,(cdr result) "\n")))))))))
1237 (when (or name address)
1238 (add-hook 'message-setup-hook
1240 (set (make-local-variable 'user-mail-address)
1241 ,(or (cdr address) user-mail-address))
1242 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1244 ,(or (cdr address) user-mail-address)))
1246 (message-remove-header "From")
1248 (insert "From: " (message-make-from) "\n")))))))))
1250 ;;; Allow redefinition of functions.
1256 ;;; gnus-msg.el ends here