1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
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', Gnus will use the \"current\" select
41 method when posting. If it is nil (which is the default), Gnus will
42 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 nil nor `native', 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 :type `(choice (const nil)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defvar 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 (defvar gnus-mailing-list-groups nil
69 "*Regexp matching groups that are really mailing lists.
70 This is useful when you're reading a mailing list that has been
71 gatewayed to a newsgroup, and you want to followup to an article in
74 (defvar gnus-add-to-list nil
75 "*If non-nil, add a `to-list' parameter automatically.")
77 (defvar gnus-crosspost-complaint
80 You posted the article below with the following Newsgroups header:
84 The %s group, at least, was an inappropriate recipient
85 of this message. Please trim your Newsgroups header to exclude this
86 group before posting in the future.
91 "Format string to be inserted when complaining about crossposts.
92 The first %s will be replaced by the Newsgroups header;
93 the second with the current group name.")
95 (defvar gnus-message-setup-hook nil
96 "Hook run after setting up a message buffer.")
98 (defvar gnus-bug-create-help-buffer t
99 "*Should we create the *Gnus Help Bug* buffer?")
101 (defvar gnus-posting-styles nil
102 "*Alist of styles to use when posting.")
104 (defvar gnus-inews-mark-gcc-as-read nil
105 "If non-nil, automatically mark Gcc articles as read.")
107 (defcustom gnus-group-posting-charset-alist
108 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
109 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
110 (message-this-is-mail nil nil)
111 (message-this-is-news nil t))
112 "Alist of regexps and permitted unencoded charsets for posting.
113 Each element of the alist has the form (TEST HEADER BODY-LIST), where
114 TEST is either a regular expression matching the newsgroup header or a
116 HEADER is the charset which may be left unencoded in the header (nil
117 means encode all charsets),
118 BODY-LIST is a list of charsets which may be encoded using 8bit
119 content-transfer encoding in the body, or one of the special values
120 nil (always encode using quoted-printable) or t (always use 8bit).
122 Note that any value other than nil for HEADER infringes some RFCs, so
123 use this option with care."
124 :type '(repeat (list :tag "Permitted unencoded charsets"
126 (regexp :tag "Group")
127 (const :tag "Mail message" :value message-this-is-mail)
128 (const :tag "News article" :value message-this-is-news))
129 (choice :tag "Header"
130 (const :tag "None" nil)
131 (symbol :tag "Charset"))
133 (const :tag "Any" :value t)
134 (const :tag "None" :value nil)
135 (repeat :tag "Charsets"
136 (symbol :tag "Charset")))))
137 :group 'gnus-charset)
139 ;;; Internal variables.
141 (defvar gnus-inhibit-posting-styles nil
142 "Inhibit the use of posting styles.")
144 (defvar gnus-message-buffer "*Mail Gnus*")
145 (defvar gnus-article-copy nil)
146 (defvar gnus-check-before-posting nil)
147 (defvar gnus-last-posting-server nil)
148 (defvar gnus-message-group-art nil)
150 (defconst gnus-bug-message
151 "Sending a bug report to the Gnus Towers.
152 ========================================
154 The buffer below is a mail buffer. When you press `C-c C-c', it will
155 be sent to the Gnus Bug Exterminators.
157 The thing near the bottom of the buffer is how the environment
158 settings will be included in the mail. Please do not delete that.
159 They will tell the Bug People what your environment is, so that it
160 will be easier to locate the bugs.
162 If you have found a bug that makes Emacs go \"beep\", set
163 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
164 and include the backtrace in your bug report.
166 Please describe the bug in annoying, painstaking detail.
168 Thank you for your help in stamping out bugs.
172 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
173 (autoload 'news-setup "rnewspost")
174 (autoload 'news-reply-mode "rnewspost")
175 (autoload 'rmail-dont-reply-to "mail-utils")
176 (autoload 'rmail-output "rmailout"))
180 ;;; Gnus Posting Functions
183 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
184 "p" gnus-summary-post-news
185 "f" gnus-summary-followup
186 "F" gnus-summary-followup-with-original
187 "c" gnus-summary-cancel-article
188 "s" gnus-summary-supersede-article
189 "r" gnus-summary-reply
190 "y" gnus-summary-yank-message
191 "R" gnus-summary-reply-with-original
192 "w" gnus-summary-wide-reply
193 "W" gnus-summary-wide-reply-with-original
194 "n" gnus-summary-followup-to-mail
195 "N" gnus-summary-followup-to-mail-with-original
196 "m" gnus-summary-mail-other-window
197 "u" gnus-uu-post-news
198 "\M-c" gnus-summary-mail-crosspost-complaint
199 "om" gnus-summary-mail-forward
200 "op" gnus-summary-post-forward
201 "Om" gnus-uu-digest-mail-forward
202 "Op" gnus-uu-digest-post-forward)
204 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
205 "b" gnus-summary-resend-bounced-mail
206 ;; "c" gnus-summary-send-draft
207 "r" gnus-summary-resend-message)
209 ;;; Internal functions.
211 (defvar gnus-article-reply nil)
212 (defmacro gnus-setup-message (config &rest forms)
213 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
214 (buffer (make-symbol "gnus-setup-message-buffer"))
215 (article (make-symbol "gnus-setup-message-article"))
216 (group (make-symbol "gnus-setup-message-group")))
217 `(let ((,winconf (current-window-configuration))
218 (,buffer (buffer-name (current-buffer)))
219 (,article (and gnus-article-reply (gnus-summary-article-number)))
220 (,group gnus-newsgroup-name)
221 (message-header-setup-hook
222 (copy-sequence message-header-setup-hook))
223 (mbl mml-buffer-list)
224 (message-mode-hook (copy-sequence message-mode-hook)))
225 (setq mml-buffer-list nil)
226 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
227 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
228 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
232 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
233 (gnus-inews-insert-draft-meta-information ,group ,article)
234 (setq gnus-message-buffer (current-buffer))
235 (set (make-local-variable 'gnus-message-group-art)
236 (cons ,group ,article))
237 (set (make-local-variable 'gnus-newsgroup-name) ,group)
238 (gnus-run-hooks 'gnus-message-setup-hook)
239 (if (eq major-mode 'message-mode)
240 (let ((mbl1 mml-buffer-list))
241 (setq mml-buffer-list mbl) ;; Global value
242 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
243 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
244 (mml-destroy-buffers)
245 (setq mml-buffer-list mbl)))
247 (gnus-configure-windows ,config t)
248 (set-buffer-modified-p nil))))
250 (defun gnus-inews-insert-draft-meta-information (group article)
253 (not (string= group ""))
254 (not (message-fetch-field gnus-draft-meta-information-header)))
255 (goto-char (point-min))
256 (insert gnus-draft-meta-information-header ": (\"" group "\" "
257 (if article (number-to-string article) "\"\"") ")\n"))))
260 (defun gnus-msg-mail (&optional to subject other-headers continue
261 switch-action yank-action send-actions)
262 "Start editing a mail message to be sent.
263 Like `message-mail', but with Gnus paraphernalia, particularly the
264 Gcc: header for archiving purposes."
266 (let ((buf (current-buffer))
268 (gnus-setup-message 'message
269 (message-mail to subject other-headers continue
270 nil yank-action send-actions))
272 (setq mail-buf (current-buffer))
273 (switch-to-buffer buf)
274 (apply switch-action mail-buf nil)))
275 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
279 (defun gnus-button-mailto (address)
281 (set-buffer (gnus-copy-article-buffer))
282 (gnus-setup-message 'message
283 (message-reply address)))
286 (defun gnus-button-reply (&optional to-address wide)
287 "Like `message-reply'."
289 (gnus-setup-message 'message
290 (message-reply to-address wide)))
293 (define-mail-user-agent 'gnus-user-agent
294 'gnus-msg-mail 'message-send-and-exit
295 'message-kill-buffer 'message-send-hook)
297 (defun gnus-setup-posting-charset (group)
298 (let ((alist gnus-group-posting-charset-alist)
299 (group (or group ""))
303 (while (setq elem (pop alist))
304 (when (or (and (stringp (car elem))
305 (string-match (car elem) group))
306 (and (gnus-functionp (car elem))
307 (funcall (car elem) group))
308 (and (symbolp (car elem))
309 (symbol-value (car elem))))
310 (throw 'found (cons (cadr elem) (caddr elem)))))))))
312 (defun gnus-inews-add-send-actions (winconf buffer article)
313 (make-local-hook 'message-sent-hook)
314 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
315 'gnus-inews-do-gcc) nil t)
317 (make-local-hook 'message-header-hook)
318 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
319 (setq message-post-method
321 (gnus-post-method arg ,gnus-newsgroup-name)))
322 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
324 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
326 `(when (gnus-buffer-exists-p ,buffer)
330 `(gnus-summary-mark-article-as-replied ,article))))
333 (put 'gnus-setup-message 'lisp-indent-function 1)
334 (put 'gnus-setup-message 'edebug-form-spec '(form body))
336 ;;; Post news commands of Gnus group mode and summary mode
338 (defun gnus-group-mail (&optional arg)
339 "Start composing a mail.
340 If ARG, use the group under the point to find a posting style.
341 If ARG is 1, prompt for a group name to find the posting style."
343 ;; We can't `let' gnus-newsgroup-name here, since that leads
344 ;; to local variables leaking.
345 (let ((group gnus-newsgroup-name)
346 (buffer (current-buffer)))
349 (setq gnus-newsgroup-name
351 (if (= 1 (prefix-numeric-value arg))
352 (completing-read "Use posting style of group: "
353 gnus-active-hashtb nil
354 (gnus-read-active-file-p))
355 (gnus-group-group-name))
357 (gnus-setup-message 'message (message-mail)))
360 (setq gnus-newsgroup-name group)))))
362 (defun gnus-group-post-news (&optional arg)
363 "Start composing a news message.
364 If ARG, post to the group under point.
365 If ARG is 1, prompt for a group name."
367 ;; Bind this variable here to make message mode hooks work ok.
368 (let ((gnus-newsgroup-name
370 (if (= 1 (prefix-numeric-value arg))
371 (completing-read "Newsgroup: " gnus-active-hashtb nil
372 (gnus-read-active-file-p))
373 (gnus-group-group-name))
375 (gnus-post-news 'post gnus-newsgroup-name)))
377 (defun gnus-summary-post-news ()
378 "Start composing a news message."
380 (gnus-post-news 'post gnus-newsgroup-name))
382 (defun gnus-summary-followup (yank &optional force-news)
383 "Compose a followup to an article.
384 If prefix argument YANK is non-nil, original article is yanked automatically."
386 (list (and current-prefix-arg
387 (gnus-summary-work-articles 1))))
389 (gnus-summary-goto-subject (car yank)))
390 (save-window-excursion
391 (gnus-summary-select-article))
392 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
393 (gnus-newsgroup-name gnus-newsgroup-name))
395 (gnus-post-news nil gnus-newsgroup-name
396 headers gnus-article-buffer
397 yank nil force-news)))
399 (defun gnus-summary-followup-with-original (n &optional force-news)
400 "Compose a followup to an article and include the original article."
402 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
404 (defun gnus-summary-followup-to-mail (&optional arg)
405 "Followup to the current mail message via news."
407 (list (and current-prefix-arg
408 (gnus-summary-work-articles 1))))
409 (gnus-summary-followup arg t))
411 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
412 "Followup to the current mail message via news."
414 (gnus-summary-followup (gnus-summary-work-articles arg) t))
416 (defun gnus-inews-yank-articles (articles)
419 (while (setq article (pop articles))
420 (save-window-excursion
421 (set-buffer gnus-summary-buffer)
422 (gnus-summary-select-article nil nil nil article)
423 (gnus-summary-remove-process-mark article))
424 (gnus-copy-article-buffer)
425 (let ((message-reply-buffer gnus-article-copy)
426 (message-reply-headers
427 (with-current-buffer gnus-article-copy
428 ;; The headers are decoded.
429 (nnheader-parse-head t))))
430 (message-yank-original)
431 (setq beg (or beg (mark t))))
437 (defun gnus-summary-cancel-article (&optional n symp)
438 "Cancel an article you posted.
439 Uses the process-prefix convention. If given the symbolic
440 prefix `a', cancel using the standard posting method; if not
441 post using the current select method."
442 (interactive (gnus-interactive "P\ny"))
443 (let ((articles (gnus-summary-work-articles n))
446 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
448 (while (setq article (pop articles))
449 (when (gnus-summary-select-article t nil nil article)
450 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
451 (message-cancel-news))
452 (gnus-summary-mark-as-read article gnus-canceled-mark)
453 (gnus-cache-remove-article 1))
454 (gnus-article-hide-headers-if-wanted))
455 (gnus-summary-remove-process-mark article))))
457 (defun gnus-summary-supersede-article ()
458 "Compose an article that will supersede a previous article.
459 This is done simply by taking the old article and adding a Supersedes
460 header line with the old Message-ID."
462 (let ((article (gnus-summary-article-number)))
463 (gnus-setup-message 'reply-yank
464 (gnus-summary-select-article t)
465 (set-buffer gnus-original-article-buffer)
469 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
471 (set-buffer ,gnus-summary-buffer)
472 (gnus-cache-possibly-remove-article ,article nil nil nil t)
473 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
474 message-send-actions))))
478 (defun gnus-copy-article-buffer (&optional article-buffer)
479 ;; make a copy of the article buffer with all text properties removed
480 ;; this copy is in the buffer gnus-article-copy.
481 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
482 ;; this buffer should be passed to all mail/news reply/post routines.
483 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
485 (set-buffer gnus-article-copy)
486 (mm-enable-multibyte))
487 (let ((article-buffer (or article-buffer gnus-article-buffer))
489 (if (not (and (get-buffer article-buffer)
490 (gnus-buffer-exists-p article-buffer)))
491 (error "Can't find any article buffer")
493 (set-buffer article-buffer)
494 (let ((gnus-newsgroup-charset (or gnus-article-charset
495 gnus-newsgroup-charset))
496 (gnus-newsgroup-ignored-charsets
497 (or gnus-article-ignored-charsets
498 gnus-newsgroup-ignored-charsets)))
500 ;; Copy over the (displayed) article buffer, delete
501 ;; hidden text and remove text properties.
503 (copy-to-buffer gnus-article-copy (point-min) (point-max))
504 (set-buffer gnus-article-copy)
505 (gnus-article-delete-text-of-type 'annotation)
506 (gnus-remove-text-with-property 'gnus-prev)
507 (gnus-remove-text-with-property 'gnus-next)
510 (buffer-substring-no-properties (point-min) (point-max))
512 ;; Find the original headers.
513 (set-buffer gnus-original-article-buffer)
514 (goto-char (point-min))
515 (while (looking-at message-unix-mail-delimiter)
518 (setq end (or (search-forward "\n\n" nil t) (point)))
519 ;; Delete the headers from the displayed articles.
520 (set-buffer gnus-article-copy)
521 (delete-region (goto-char (point-min))
522 (or (search-forward "\n\n" nil t) (point-max)))
523 ;; Insert the original article headers.
524 (insert-buffer-substring gnus-original-article-buffer beg end)
525 (article-decode-encoded-words))))
528 (defun gnus-post-news (post &optional group header article-buffer yank subject
531 (gnus-copy-article-buffer))
532 (let ((gnus-article-reply article-buffer)
533 (add-to-list gnus-add-to-list))
534 (gnus-setup-message (cond (yank 'reply-yank)
535 (article-buffer 'reply)
537 (let* ((group (or group gnus-newsgroup-name))
538 (charset (gnus-group-name-charset nil group))
540 to-address to-group mailing-list to-list
543 (setq to-address (gnus-parameter-to-address group)
544 to-group (gnus-group-find-parameter group 'to-group)
545 to-list (gnus-parameter-to-list group)
546 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
547 mailing-list (when gnus-mailing-list-groups
548 (string-match gnus-mailing-list-groups group))
549 group (gnus-group-name-decode (gnus-group-real-name group)
551 (if (or (and to-group
552 (gnus-news-group-p to-group))
555 (and (gnus-news-group-p
556 (or pgroup gnus-newsgroup-name)
557 (if header (mail-header-number header)
558 gnus-current-article))
564 (message-news (or to-group group))
565 (set-buffer gnus-article-copy)
566 (gnus-msg-treat-broken-reply-to)
567 (message-followup (if (or newsgroup-p force-news) nil to-group)))
571 (message-mail (or to-address to-list))
572 ;; Arrange for mail groups that have no `to-address' to
573 ;; get that when the user sends off the mail.
574 (when (and (not to-list)
577 (push (list 'gnus-inews-add-to-address pgroup)
578 message-send-actions)))
579 (set-buffer gnus-article-copy)
580 (gnus-msg-treat-broken-reply-to)
581 (message-wide-reply to-address)))
583 (gnus-inews-yank-articles yank))))))
585 (defun gnus-msg-treat-broken-reply-to ()
586 "Remove the Reply-to header iff broken-reply-to."
587 (when (gnus-group-find-parameter
588 gnus-newsgroup-name 'broken-reply-to)
590 (message-narrow-to-head)
591 (message-remove-header "reply-to"))))
593 (defun gnus-post-method (arg group &optional silent)
594 "Return the posting method based on GROUP and ARG.
595 If SILENT, don't prompt the user."
596 (let ((group-method (gnus-find-method-for-group group)))
598 ;; If the group-method is nil (which shouldn't happen) we use
599 ;; the default method.
601 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
602 gnus-select-method message-post-method))
603 ;; We want the inverse of the default
604 ((and arg (not (eq arg 0)))
605 (if (eq gnus-post-method 'active)
608 ;; We query the user for a post method.
610 (and gnus-post-method
611 (not (eq gnus-post-method 'current))
612 (listp (car gnus-post-method))))
614 ;; Collect all methods we know about.
616 (when (and gnus-post-method
617 (not (eq gnus-post-method 'current)))
618 (if (listp (car gnus-post-method))
620 (list gnus-post-method)))
621 gnus-secondary-select-methods
622 (mapcar 'cdr gnus-server-alist)
623 (mapcar 'car gnus-opened-servers)
624 (list gnus-select-method)
625 (list group-method)))
626 method-alist post-methods method)
627 ;; Weed out all mail methods.
629 (setq method (gnus-server-get-method "" (pop methods)))
630 (when (and (or (gnus-method-option-p method 'post)
631 (gnus-method-option-p method 'post-mail))
632 (not (member method post-methods)))
633 (push method post-methods)))
634 ;; Create a name-method alist.
638 (if (equal (cadr m) "")
639 (list (symbol-name (car m)) m)
640 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
645 (setq gnus-last-posting-server
647 gnus-last-posting-server)
648 ;; Just use the last value.
649 gnus-last-posting-server
651 "Posting method: " method-alist nil t
652 (cons (or gnus-last-posting-server "") 0))))
654 ;; Override normal method.
655 ((and (eq gnus-post-method 'current)
656 (not (eq (car group-method) 'nndraft))
657 (gnus-get-function group-method 'request-post t)
660 ((and gnus-post-method
661 (not (eq gnus-post-method 'current)))
663 ;; Use the normal select method.
664 (t gnus-select-method))))
668 ;; Dummies to avoid byte-compile warning.
670 (defvar nnspool-rejected-article-hook)
671 (defvar xemacs-codename))
673 (defun gnus-extended-version ()
674 "Stringified Gnus version and Emacs version."
677 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
678 " (" gnus-version ")"
681 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
682 (concat "Emacs/" (match-string 1 emacs-version)))
683 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
685 (concat (match-string 1 emacs-version)
686 (format "/%d.%d" emacs-major-version emacs-minor-version)
687 (if (match-beginning 3)
688 (match-string 3 emacs-version)
690 (if (boundp 'xemacs-codename)
691 (concat " (" xemacs-codename ")")
697 ;;; Gnus Mail Functions
700 ;;; Mail reply commands of Gnus summary mode
702 (defun gnus-summary-reply (&optional yank wide)
703 "Start composing a reply mail to the current message.
704 If prefix argument YANK is non-nil, the original article is yanked
707 (list (and current-prefix-arg
708 (gnus-summary-work-articles 1))))
709 ;; Stripping headers should be specified with mail-yank-ignored-headers.
711 (gnus-summary-goto-subject (car yank)))
712 (let ((gnus-article-reply t))
713 (gnus-setup-message (if yank 'reply-yank 'reply)
714 (gnus-summary-select-article)
715 (set-buffer (gnus-copy-article-buffer))
716 (gnus-msg-treat-broken-reply-to)
718 (message-narrow-to-head)
719 (goto-char (point-max)))
720 (mml-quote-region (point) (point-max))
721 (message-reply nil wide)
723 (gnus-inews-yank-articles yank)))))
725 (defun gnus-summary-reply-with-original (n &optional wide)
726 "Start composing a reply mail to the current message.
727 The original article will be yanked."
729 (gnus-summary-reply (gnus-summary-work-articles n) wide))
731 (defun gnus-summary-wide-reply (&optional yank)
732 "Start composing a wide reply mail to the current message.
733 If prefix argument YANK is non-nil, the original article is yanked
736 (list (and current-prefix-arg
737 (gnus-summary-work-articles 1))))
738 (gnus-summary-reply yank t))
740 (defun gnus-summary-wide-reply-with-original (n)
741 "Start composing a wide reply mail to the current message.
742 The original article will be yanked."
744 (gnus-summary-reply-with-original n t))
746 (defun gnus-summary-mail-forward (&optional arg post)
747 "Forward the current message to another user.
748 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
749 if ARG is 1, decode the message and forward directly inline;
750 if ARG is 2, forward message as an rfc822 MIME section;
751 if ARG is 3, decode message and forward as an rfc822 MIME section;
752 if ARG is 4, forward message directly inline;
753 otherwise, use flipped `message-forward-as-mime'.
754 If POST, post instead of mail."
756 (let ((message-forward-as-mime message-forward-as-mime)
757 (message-forward-show-mml message-forward-show-mml))
760 ((eq arg 1) (setq message-forward-as-mime nil
761 message-forward-show-mml t))
762 ((eq arg 2) (setq message-forward-as-mime t
763 message-forward-show-mml nil))
764 ((eq arg 3) (setq message-forward-as-mime t
765 message-forward-show-mml t))
766 ((eq arg 4) (setq message-forward-as-mime nil
767 message-forward-show-mml nil))
768 (t (setq message-forward-as-mime (not message-forward-as-mime))))
769 (gnus-setup-message 'forward
770 (gnus-summary-select-article)
771 (let ((mail-parse-charset gnus-newsgroup-charset)
772 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
773 (set-buffer gnus-original-article-buffer)
774 (message-forward post)))))
776 (defun gnus-summary-resend-message (address n)
777 "Resend the current article to ADDRESS."
779 (list (message-read-from-minibuffer "Resend message(s) to: ")
781 (let ((articles (gnus-summary-work-articles n))
783 (while (setq article (pop articles))
784 (gnus-summary-select-article nil nil nil article)
786 (set-buffer gnus-original-article-buffer)
787 (message-resend address)))))
789 (defun gnus-summary-post-forward (&optional arg)
790 "Forward the current article to a newsgroup.
791 See `gnus-summary-mail-forward' for ARG."
793 (gnus-summary-mail-forward arg t))
795 (defvar gnus-nastygram-message
796 "The following article was inappropriately posted to %s.\n\n"
797 "Format string to insert in nastygrams.
798 The current group name will be inserted at \"%s\".")
800 (defun gnus-summary-mail-nastygram (n)
801 "Send a nastygram to the author of the current article."
803 (when (or gnus-expert-user
805 "Really send a nastygram to the author of the current article? "))
806 (let ((group gnus-newsgroup-name))
807 (gnus-summary-reply-with-original n)
808 (set-buffer gnus-message-buffer)
810 (insert (format gnus-nastygram-message group))
811 (message-send-and-exit))))
813 (defun gnus-summary-mail-crosspost-complaint (n)
814 "Send a complaint about crossposting to the current article(s)."
816 (let ((articles (gnus-summary-work-articles n))
818 (while (setq article (pop articles))
819 (set-buffer gnus-summary-buffer)
820 (gnus-summary-goto-subject article)
821 (let ((group (gnus-group-real-name gnus-newsgroup-name))
822 newsgroups followup-to)
823 (gnus-summary-select-article)
824 (set-buffer gnus-original-article-buffer)
825 (if (and (<= (length (message-tokenize-header
827 (mail-fetch-field "newsgroups"))
830 (or (not (setq followup-to (mail-fetch-field "followup-to")))
831 (not (member group (message-tokenize-header
832 followup-to ", ")))))
834 (gnus-message 1 "Followup-to restricted")
835 (gnus-message 1 "Not a crossposted article"))
836 (set-buffer gnus-summary-buffer)
837 (gnus-summary-reply-with-original 1)
838 (set-buffer gnus-message-buffer)
840 (insert (format gnus-crosspost-complaint newsgroups group))
841 (message-goto-subject)
842 (re-search-forward " *$")
843 (replace-match " (crosspost notification)" t t)
844 (gnus-deactivate-mark)
845 (when (gnus-y-or-n-p "Send this complaint? ")
846 (message-send-and-exit)))))))
848 (defun gnus-summary-mail-other-window ()
849 "Compose mail in other window."
851 (gnus-setup-message 'message
854 (defun gnus-mail-parse-comma-list ()
857 (skip-chars-forward " ")
860 (skip-chars-forward "^,")
865 (narrow-to-region beg (point))
868 (while (search-forward "\"" nil t)
872 (skip-chars-forward ",")
873 (skip-chars-forward "^,"))
874 (skip-chars-backward " ")
875 (push (buffer-substring beg (point))
877 (skip-chars-forward "^,")
878 (skip-chars-forward ", "))
881 (defun gnus-inews-add-to-address (group)
882 (let ((to-address (mail-fetch-field "to")))
883 (when (and to-address
885 ;; This mail group doesn't have a `to-list', so we add one
888 (format "Do you want to add this as `to-list': %s " to-address))
889 (gnus-group-add-parameter group (cons 'to-list to-address))))))
891 (defun gnus-put-message ()
892 "Put the current message in some group and return to Gnus."
894 (let ((reply gnus-article-reply)
895 (winconf gnus-prev-winconf)
896 (group gnus-newsgroup-name))
898 (or (and group (not (gnus-group-read-only-p group)))
899 (setq group (read-string "Put in group: " nil
900 (gnus-writable-groups))))
901 (when (gnus-gethash group gnus-newsrc-hashtb)
902 (error "No such group: %s" group))
907 (message-narrow-to-headers)
908 (let (gnus-deletable-headers)
910 (message-generate-headers message-required-news-headers)
911 (message-generate-headers message-required-mail-headers)))
912 (goto-char (point-max))
913 (insert "Gcc: " group "\n")
918 (when (get-buffer gnus-group-buffer)
919 (when (gnus-buffer-exists-p (car-safe reply))
920 (set-buffer (car reply))
922 (gnus-summary-mark-article-as-replied
925 (set-window-configuration winconf)))))
927 (defun gnus-article-mail (yank)
928 "Send a reply to the address near point.
929 If YANK is non-nil, include the original article."
933 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
934 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
936 (message-reply address)
938 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
940 (defvar nntp-server-type)
942 "Send a bug report to the Gnus maintainers."
944 (unless (gnus-alive-p)
945 (error "Gnus has been shut down"))
946 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
947 (unless (message-mail-user-agent)
948 (delete-other-windows)
949 (when gnus-bug-create-help-buffer
950 (switch-to-buffer "*Gnus Help Bug*")
952 (insert gnus-bug-message)
953 (goto-char (point-min)))
954 (message-pop-to-buffer "*Gnus Bug*"))
955 (let ((message-this-is-mail t))
956 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
957 (when gnus-bug-create-help-buffer
958 (push `(gnus-bug-kill-buffer) message-send-actions))
959 (goto-char (point-min))
960 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
962 (insert (gnus-version) "\n"
963 (emacs-version) "\n")
964 (when (and (boundp 'nntp-server-type)
965 (stringp nntp-server-type))
966 (insert nntp-server-type))
967 (insert "\n\n\n\n\n")
970 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
972 (setq text (buffer-string)))
973 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
974 (goto-char (point-min))
975 (search-forward "Subject: " nil t)
978 (defun gnus-bug-kill-buffer ()
979 (when (get-buffer "*Gnus Help Bug*")
980 (kill-buffer "*Gnus Help Bug*")))
982 (defun gnus-summary-yank-message (buffer n)
983 "Yank the current article into a composed message."
985 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
987 (gnus-summary-iterate n
988 (let ((gnus-display-mime-function nil)
989 (gnus-inhibit-treatment t))
990 (gnus-summary-select-article))
993 (message-yank-buffer gnus-article-buffer))))
996 "Attempts to go through the Gnus source file and report what variables have been changed.
997 The source file has to be in the Emacs load path."
999 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1000 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1001 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1002 "nnmail.el" "message.el"))
1004 file expr olist sym)
1005 (gnus-message 4 "Please wait while we snoop your variables...")
1007 ;; Go through all the files looking for non-default values for variables.
1009 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1012 (when (and (setq file (locate-library (pop files)))
1013 (file-exists-p file))
1014 (insert-file-contents file)
1015 (goto-char (point-min))
1016 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1017 (gnus-message 4 "Malformed sources in file %s" file)
1018 (narrow-to-region (point-min) (point))
1019 (goto-char (point-min))
1020 (while (setq expr (ignore-errors (read (current-buffer))))
1022 (and (or (eq (car expr) 'defvar)
1023 (eq (car expr) 'defcustom))
1024 (stringp (nth 3 expr))
1025 (or (not (boundp (nth 1 expr)))
1026 (not (equal (eval (nth 2 expr))
1027 (symbol-value (nth 1 expr)))))
1028 (push (nth 1 expr) olist)))))))
1029 (kill-buffer (current-buffer)))
1030 (when (setq olist (nreverse olist))
1031 (insert "------------------ Environment follows ------------------\n\n"))
1033 (if (boundp (car olist))
1035 (pp `(setq ,(car olist)
1036 ,(if (or (consp (setq sym (symbol-value (car olist))))
1038 (not (or (eq sym nil)
1040 (list 'quote (symbol-value (car olist)))
1041 (symbol-value (car olist))))
1044 (format "(setq %s 'whatever)\n" (car olist))))
1045 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1046 (setq olist (cdr olist)))
1048 ;; Remove any control chars - they seem to cause trouble for some
1049 ;; mailers. (Byte-compiled output from the stuff above.)
1051 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1052 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1055 ;;; Treatment of rejected articles.
1058 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1059 "Re-mail the current message.
1060 This only makes sense if the current message is a bounce message than
1061 contains some mail you have written which has been bounced back to
1063 If FETCH, try to fetch the article that this is a reply to, if indeed
1066 (gnus-summary-select-article t)
1067 (set-buffer gnus-original-article-buffer)
1068 (gnus-setup-message 'compose-bounce
1069 (let* ((references (mail-fetch-field "references"))
1070 (parent (and references (gnus-parent-id references))))
1072 ;; If there are references, we fetch the article we answered to.
1074 (gnus-summary-refer-article parent)
1075 (gnus-summary-show-all-headers)))))
1079 (defun gnus-inews-group-method (group)
1080 (cond ((and (null (gnus-get-info group))
1081 (eq (car gnus-message-archive-method)
1083 (gnus-server-to-method
1084 (gnus-group-method group)))))
1085 ;; If the group doesn't exist, we assume
1086 ;; it's an archive group...
1087 gnus-message-archive-method)
1089 ((gnus-info-method (gnus-get-info group))
1090 (gnus-info-method (gnus-get-info group)))
1092 (t (gnus-group-method group))))
1094 ;; Do Gcc handling, which copied the message over to some group.
1095 (defun gnus-inews-do-gcc (&optional gcc)
1097 (when (gnus-alive-p)
1100 (message-narrow-to-headers)
1101 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1102 (cur (current-buffer))
1103 groups group method group-art)
1105 (message-remove-header "gcc")
1107 (setq groups (message-unquote-tokens
1108 (message-tokenize-header gcc " ,")))
1109 ;; Copy the article over to some group(s).
1110 (while (setq group (pop groups))
1112 (setq method (gnus-inews-group-method group)))
1113 (unless (gnus-request-group group t method)
1114 (gnus-request-create-group group method))
1116 (nnheader-set-temp-buffer " *acc*")
1117 (insert-buffer-substring cur)
1118 (message-encode-message-body)
1120 (message-narrow-to-headers)
1121 (let ((mail-parse-charset message-default-charset)
1122 (rfc2047-header-encoding-alist
1123 (cons '("Newsgroups" . default)
1124 rfc2047-header-encoding-alist)))
1125 (mail-encode-encoded-word-buffer)))
1126 (goto-char (point-min))
1127 (when (re-search-forward
1128 (concat "^" (regexp-quote mail-header-separator) "$")
1130 (replace-match "" t t ))
1131 (unless (setq group-art
1132 (gnus-request-accept-article group method t t))
1133 (gnus-message 1 "Couldn't store article in group %s: %s"
1134 group (gnus-status-message method))
1136 (when (and group-art gnus-inews-mark-gcc-as-read)
1137 (let ((active (gnus-active group)))
1139 (if (< (cdr active) (cdr group-art))
1140 (gnus-set-active group (cons (car active)
1142 (gnus-activate-group group)))
1143 (let ((buffer (gnus-summary-buffer-name group))
1144 (mark gnus-read-mark)
1145 (article (cdr group-art)))
1149 (with-current-buffer buffer
1150 (when gnus-newsgroup-prepared
1151 (when (and gnus-newsgroup-auto-expire
1152 (memq mark gnus-auto-expirable-marks))
1153 (setq mark gnus-expirable-mark))
1154 (setq mark (gnus-request-update-mark
1155 group article mark))
1156 (gnus-mark-article-as-read article mark)
1157 (setq gnus-newsgroup-active (gnus-active group))
1159 (gnus-group-make-articles-read group
1161 (when (gnus-group-auto-expirable-p group)
1162 (gnus-add-marked-articles
1163 group 'expire (list article))))))
1164 (kill-buffer (current-buffer))))))))))
1166 (defun gnus-inews-insert-gcc ()
1167 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1170 (message-narrow-to-headers)
1171 (let* ((group gnus-outgoing-message-group)
1173 ((gnus-functionp group)
1175 ((or (stringp group) (list group))
1179 (if (stringp gcc) gcc
1180 (mapconcat 'identity gcc " "))
1183 (defun gnus-inews-insert-archive-gcc (&optional group)
1184 "Insert the Gcc to say where the article is to be archived."
1185 (let* ((var gnus-message-archive-group)
1186 (group (or group gnus-newsgroup-name ""))
1188 (and gnus-newsgroup-name
1189 (not (equal gnus-newsgroup-name ""))
1190 (gnus-group-find-parameter
1191 gnus-newsgroup-name 'gcc-self)))
1195 ((null gnus-message-archive-method)
1199 ;; Just a single group.
1202 ;; We don't want this.
1204 ((and (listp var) (stringp (car var)))
1205 ;; A list of groups.
1207 ((gnus-functionp var)
1209 (funcall var group))
1211 ;; An alist of regexps/functions/forms.
1216 ((stringp (caar var))
1218 (when (string-match (caar var) group)
1220 ((gnus-functionp (car var))
1222 (funcall (car var) group))
1224 (eval (car var)))))))
1225 (setq var (cdr var)))
1228 (when (or groups gcc-self-val)
1229 (when (stringp groups)
1230 (setq groups (list groups)))
1233 (message-narrow-to-headers)
1234 (goto-char (point-max))
1237 ;; Use the `gcc-self' param value instead.
1240 (if (stringp gcc-self-val)
1243 (if (not (eq gcc-self-val 'none))
1248 ;; Use the list of groups.
1249 (while (setq name (pop groups))
1250 (insert (if (string-match ":" name)
1252 (gnus-group-prefixed-name
1253 name gnus-message-archive-method)))
1260 (defun gnus-configure-posting-styles ()
1261 "Configure posting styles according to `gnus-posting-styles'."
1262 (unless gnus-inhibit-posting-styles
1263 (let ((group (or gnus-newsgroup-name ""))
1264 (styles gnus-posting-styles)
1265 style match variable attribute value v results
1266 filep name address element)
1267 ;; If the group has a posting-style parameter, add it at the end with a
1268 ;; regexp matching everything, to be sure it takes precedence over all
1270 (when gnus-newsgroup-name
1271 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1273 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1274 ;; Go through all styles and look for matches.
1275 (dolist (style styles)
1276 (setq match (pop style))
1277 (goto-char (point-min))
1280 ;; Regexp string match on the group name.
1281 (string-match match group))
1283 (and (gnus-buffer-live-p gnus-article-copy)
1284 (with-current-buffer gnus-article-copy
1285 (let ((header (message-fetch-field (pop style))))
1287 (string-match (pop style) header))))))
1288 ((or (symbolp match)
1289 (gnus-functionp match))
1291 ((gnus-functionp match)
1292 ;; Function to be called.
1295 ;; Variable to be checked.
1296 (symbol-value match))))
1298 ;; This is a form to be evaled.
1300 ;; We have a match, so we set the variables.
1301 (dolist (attribute style)
1302 (setq element (pop attribute)
1307 ((eq (car attribute) :file)
1310 ((eq (car attribute) :value)
1314 ;; We get the value.
1319 ((or (symbolp value)
1320 (gnus-functionp value))
1321 (cond ((gnus-functionp value)
1324 (symbol-value value))))
1327 ;; Translate obsolescent value.
1328 (when (eq element 'signature-file)
1329 (setq element 'signature
1331 ;; Get the contents of file elems.
1333 (setq v (with-temp-buffer
1334 (insert-file-contents v)
1336 (setq results (delq (assoc element results) results))
1337 (push (cons element v) results))))
1338 ;; Now we have all the styles, so we insert them.
1339 (setq name (assq 'name results)
1340 address (assq 'address results))
1341 (setq results (delq name (delq address results)))
1342 (make-local-variable 'message-setup-hook)
1343 (dolist (result results)
1344 (add-hook 'message-setup-hook
1346 ((eq 'eval (car result))
1348 ((eq 'body (car result))
1352 (insert ,(cdr result)))))
1353 ((eq 'signature (car result))
1354 (set (make-local-variable 'message-signature) nil)
1355 (set (make-local-variable 'message-signature-file) nil)
1356 (if (not (cdr result))
1360 (let ((message-signature ,(cdr result)))
1361 (when message-signature
1362 (message-insert-signature)))))))
1365 (if (symbolp (car result))
1366 (capitalize (symbol-name (car result)))
1370 (message-remove-header ,header)
1371 (let ((value ,(cdr result)))
1374 (insert ,header ": " value "\n"))))))))))
1375 (when (or name address)
1376 (add-hook 'message-setup-hook
1378 (set (make-local-variable 'user-mail-address)
1379 ,(or (cdr address) user-mail-address))
1380 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1382 ,(or (cdr address) user-mail-address)))
1384 (message-remove-header "From")
1386 (insert "From: " (message-make-from) "\n")))))))))
1388 ;;; Allow redefinition of functions.
1394 ;;; gnus-msg.el ends here