1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
42 (defcustom gnus-post-method 'current
43 "*Preferred method for posting USENET news.
45 If this variable is `current', Gnus will use the \"current\" select
46 method when posting. If it is nil (which is the default), Gnus will
47 use the native select method when posting.
49 This method will not be used in mail groups and the like, only in
52 If not nil nor `native', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'. It can also be a list of
54 methods. If that is the case, the user will be queried for what select
55 method to use when posting."
56 :group 'gnus-group-foreign
57 :type `(choice (const nil)
60 (sexp :tag "Methods" ,gnus-select-method)))
62 (defvar gnus-outgoing-message-group nil
63 "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value. This variable
66 can also be a list of group names.
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
73 (defvar gnus-mailing-list-groups nil
74 "*Regexp matching groups that are really mailing lists.
75 This is useful when you're reading a mailing list that has been
76 gatewayed to a newsgroup, and you want to followup to an article in
79 (defvar gnus-add-to-list nil
80 "*If non-nil, add a `to-list' parameter automatically.")
82 (defvar gnus-crosspost-complaint
85 You posted the article below with the following Newsgroups header:
89 The %s group, at least, was an inappropriate recipient
90 of this message. Please trim your Newsgroups header to exclude this
91 group before posting in the future.
96 "Format string to be inserted when complaining about crossposts.
97 The first %s will be replaced by the Newsgroups header;
98 the second with the current group name.")
100 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
101 "Hook run after setting up a message buffer.")
103 (defvar gnus-bug-create-help-buffer t
104 "*Should we create the *Gnus Help Bug* buffer?")
106 (defvar gnus-posting-styles nil
107 "*Alist of styles to use when posting.")
109 (defcustom gnus-group-posting-charset-alist
110 '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
111 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
112 (message-this-is-mail nil nil)
113 (message-this-is-news nil t))
114 "Alist of regexps and permitted unencoded charsets for posting.
115 Each element of the alist has the form (TEST HEADER BODY-LIST), where
116 TEST is either a regular expression matching the newsgroup header or a
118 HEADER is the charset which may be left unencoded in the header (nil
119 means encode all charsets),
120 BODY-LIST is a list of charsets which may be encoded using 8bit
121 content-transfer encoding in the body, or one of the special values
122 nil (always encode using quoted-printable) or t (always use 8bit).
124 Note that any value other than nil for HEADER infringes some RFCs, so
125 use this option with care."
126 :type '(repeat (list :tag "Permitted unencoded charsets"
128 (regexp :tag "Group")
129 (const :tag "Mail message" :value message-this-is-mail)
130 (const :tag "News article" :value message-this-is-news))
131 (choice :tag "Header"
132 (const :tag "None" nil)
133 (symbol :tag "Charset"))
135 (const :tag "Any" :value t)
136 (const :tag "None" :value nil)
137 (repeat :tag "Charsets"
138 (symbol :tag "Charset")))))
139 :group 'gnus-charset)
141 ;;; Internal variables.
143 (defvar gnus-inhibit-posting-styles nil
144 "Inhibit the use of posting styles.")
146 (defvar gnus-message-buffer "*Mail Gnus*")
147 (defvar gnus-article-copy nil)
148 (defvar gnus-last-posting-server nil)
149 (defvar gnus-message-group-art nil)
151 (defconst gnus-bug-message
152 (format "Sending a bug report to the Gnus Towers.
153 ========================================
155 This gnus is the %s%s.
156 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
157 Developers. (the addresses below are mailing list addresses)
159 ========================================
161 The buffer below is a mail buffer. When you press `C-c C-c', it will
162 be sent to the Gnus Bug Exterminators.
164 The thing near the bottom of the buffer is how the environment
165 settings will be included in the mail. Please do not delete that.
166 They will tell the Bug People what your environment is, so that it
167 will be easier to locate the bugs.
169 If you have found a bug that makes Emacs go \"beep\", set
170 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
171 and include the backtrace in your bug report.
173 Please describe the bug in annoying, painstaking detail.
175 Thank you for your help in stamping out bugs.
178 (if (string= gnus-product-name "Semi-gnus")
180 ", a modified version of Semi-gnus")))
183 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
184 (autoload 'news-setup "rnewspost")
185 (autoload 'news-reply-mode "rnewspost")
186 (autoload 'rmail-dont-reply-to "mail-utils")
187 (autoload 'rmail-output "rmailout"))
191 ;;; Gnus Posting Functions
194 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
195 "p" gnus-summary-post-news
196 "f" gnus-summary-followup
197 "F" gnus-summary-followup-with-original
198 "c" gnus-summary-cancel-article
199 "s" gnus-summary-supersede-article
200 "r" gnus-summary-reply
201 "y" gnus-summary-yank-message
202 "R" gnus-summary-reply-with-original
203 "w" gnus-summary-wide-reply
204 "W" gnus-summary-wide-reply-with-original
205 "n" gnus-summary-followup-to-mail
206 "N" gnus-summary-followup-to-mail-with-original
207 "m" gnus-summary-mail-other-window
208 "u" gnus-uu-post-news
209 "\M-c" gnus-summary-mail-crosspost-complaint
210 "om" gnus-summary-mail-forward
211 "op" gnus-summary-post-forward
212 "Om" gnus-uu-digest-mail-forward
213 "Op" gnus-uu-digest-post-forward)
215 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
216 "b" gnus-summary-resend-bounced-mail
217 ;; "c" gnus-summary-send-draft
218 "r" gnus-summary-resend-message)
221 (defun gnus-msg-mail (&rest args)
222 "Start editing a mail message to be sent.
223 Like `message-mail', but with Gnus paraphernalia, particularly the
224 the Gcc: header for archiving purposes."
226 (gnus-setup-message 'message
227 (apply 'message-mail args)))
230 (define-mail-user-agent 'gnus-user-agent
231 'gnus-msg-mail 'message-send-and-exit
232 'message-kill-buffer 'message-send-hook)
234 ;;; Internal functions.
236 (defvar gnus-article-reply nil)
237 (defmacro gnus-setup-message (config &rest forms)
238 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
239 (buffer (make-symbol "gnus-setup-message-buffer"))
240 (article (make-symbol "gnus-setup-message-article"))
241 (group (make-symbol "gnus-setup-message-group")))
242 `(let ((,winconf (current-window-configuration))
243 (,buffer (buffer-name (current-buffer)))
244 (,article (and gnus-article-reply (gnus-summary-article-number)))
245 (,group gnus-newsgroup-name)
246 (message-header-setup-hook
247 (copy-sequence message-header-setup-hook))
248 (message-mode-hook (copy-sequence message-mode-hook))
249 (message-startup-parameter-alist
250 '((reply-buffer . gnus-copy-article-buffer)
251 (original-buffer . gnus-original-article-buffer)
252 (user-agent . Gnus))))
253 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
254 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
255 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
259 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
260 (setq gnus-message-buffer (current-buffer))
261 (set (make-local-variable 'gnus-message-group-art)
262 (cons ,group ,article))
263 (set (make-local-variable 'gnus-newsgroup-name) ,group)
264 (gnus-run-hooks 'gnus-message-setup-hook))
266 (gnus-configure-windows ,config t)
267 (set-buffer-modified-p nil))))
269 (defun gnus-setup-posting-charset (group)
270 (let ((alist gnus-group-posting-charset-alist)
271 (group (or group ""))
275 (while (setq elem (pop alist))
276 (when (or (and (stringp (car elem))
277 (string-match (car elem) group))
278 (and (gnus-functionp (car elem))
279 (funcall (car elem) group))
280 (and (symbolp (car elem))
281 (symbol-value (car elem))))
282 (throw 'found (cons (cadr elem) (caddr elem)))))))))
284 (defun gnus-inews-add-send-actions (winconf buffer article)
285 (make-local-hook 'message-sent-hook)
286 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
287 (setq message-post-method
289 (gnus-post-method arg ,gnus-newsgroup-name)))
290 (setq message-user-agent (gnus-extended-version))
291 (when (not message-use-multi-frames)
293 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
295 `(when (gnus-buffer-exists-p ,buffer)
299 `(gnus-summary-mark-article-as-replied ,article))))
302 (put 'gnus-setup-message 'lisp-indent-function 1)
303 (put 'gnus-setup-message 'edebug-form-spec '(form body))
305 ;;; Post news commands of Gnus group mode and summary mode
307 (defun gnus-group-mail (&optional arg)
308 "Start composing a mail.
309 If ARG, use the group under the point to find a posting style.
310 If ARG is 1, prompt for a group name to find the posting style."
312 ;; We can't `let' gnus-newsgroup-name here, since that leads
313 ;; to local variables leaking.
314 (let ((group gnus-newsgroup-name)
315 (buffer (current-buffer)))
318 (setq gnus-newsgroup-name
320 (if (= 1 (prefix-numeric-value arg))
321 (completing-read "Use posting style of group: "
322 gnus-active-hashtb nil
323 (gnus-read-active-file-p))
324 (gnus-group-group-name))
326 (gnus-setup-message 'message (message-mail)))
329 (setq gnus-newsgroup-name group)))))
331 (defun gnus-group-post-news (&optional arg)
332 "Start composing a news message.
333 If ARG, post to the group under point.
334 If ARG is 1, prompt for a group name."
336 ;; Bind this variable here to make message mode hooks work ok.
337 (let ((gnus-newsgroup-name
339 (if (= 1 (prefix-numeric-value arg))
340 (completing-read "Newsgroup: " gnus-active-hashtb nil
341 (gnus-read-active-file-p))
342 (gnus-group-group-name))
344 (gnus-post-news 'post gnus-newsgroup-name)))
346 (defun gnus-summary-post-news ()
347 "Start composing a news message."
349 (gnus-post-news 'post gnus-newsgroup-name))
351 (defun gnus-summary-followup (yank &optional force-news)
352 "Compose a followup to an article.
353 If prefix argument YANK is non-nil, original article is yanked automatically."
355 (list (and current-prefix-arg
356 (gnus-summary-work-articles 1))))
358 (gnus-summary-goto-subject (car yank)))
359 (save-window-excursion
360 (gnus-summary-select-article))
361 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
362 (gnus-newsgroup-name gnus-newsgroup-name))
364 (gnus-post-news nil gnus-newsgroup-name
365 headers gnus-article-buffer
366 yank nil force-news)))
368 (defun gnus-summary-followup-with-original (n &optional force-news)
369 "Compose a followup to an article and include the original article."
371 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
373 (defun gnus-summary-followup-to-mail (&optional arg)
374 "Followup to the current mail message via news."
376 (list (and current-prefix-arg
377 (gnus-summary-work-articles 1))))
378 (gnus-summary-followup arg t))
380 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
381 "Followup to the current mail message via news."
383 (gnus-summary-followup (gnus-summary-work-articles arg) t))
385 (defun gnus-inews-yank-articles (articles)
386 (let* ((more-than-one (cdr articles))
387 (frame (when (and message-use-multi-frames more-than-one)
388 (window-frame (get-buffer-window (current-buffer)))))
391 (while (setq article (pop articles))
392 (save-window-excursion
393 (set-buffer gnus-summary-buffer)
394 (gnus-summary-select-article nil nil nil article)
395 (gnus-summary-remove-process-mark article))
397 (select-frame frame))
399 ;; Gathering references.
401 (setq refs (message-list-references
403 (mail-header-references gnus-current-headers)
404 (mail-header-message-id gnus-current-headers))))
406 (gnus-copy-article-buffer)
407 (let ((message-reply-buffer gnus-article-copy)
408 (message-reply-headers gnus-current-headers))
409 (message-yank-original)
410 (setq beg (or beg (mark t))))
415 ;; Replace with the gathered references.
419 (message-narrow-to-headers)
420 (let ((case-fold-search t))
421 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
423 (goto-char (point-max))))
425 (list (or (assq 'References message-header-format-alist)
426 '(References . message-shorten-references)))
427 (list (cons 'References
428 (mapconcat 'identity (nreverse refs) " "))))
429 (backward-delete-char 1))
435 (defun gnus-summary-cancel-article (&optional n symp)
436 "Cancel an article you posted.
437 Uses the process-prefix convention. If given the symbolic
438 prefix `a', cancel using the standard posting method; if not
439 post using the current select method."
440 (interactive (gnus-interactive "P\ny"))
441 (let ((articles (gnus-summary-work-articles n))
444 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
446 (while (setq article (pop articles))
447 (when (gnus-summary-select-article t nil nil article)
448 (when (gnus-eval-in-buffer-window gnus-article-buffer
450 (set-buffer 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-message-setup-hook '(gnus-maybe-setup-default-charset)))
464 (gnus-setup-message 'reply-yank
465 (gnus-summary-select-article t)
466 (set-buffer gnus-original-article-buffer)
470 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
472 (set-buffer ,gnus-summary-buffer)
473 (gnus-cache-possibly-remove-article ,article nil nil nil t)
474 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
475 message-send-actions))))
479 (defun gnus-copy-article-buffer (&optional article-buffer)
480 ;; make a copy of the article buffer with all text properties removed
481 ;; this copy is in the buffer gnus-article-copy.
482 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
483 ;; this buffer should be passed to all mail/news reply/post routines.
484 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
485 (let ((article-buffer (or article-buffer gnus-article-buffer))
487 (if (not (and (get-buffer article-buffer)
488 (gnus-buffer-exists-p article-buffer)))
489 (error "Can't find any article buffer")
491 (set-buffer article-buffer)
493 ;; Copy over the (displayed) article buffer, delete
494 ;; hidden text and remove text properties.
496 (let ((inhibit-read-only t))
497 (copy-to-buffer gnus-article-copy (point-min) (point-max))
498 (set-buffer gnus-article-copy)
499 (gnus-article-delete-text-of-type 'annotation)
500 (gnus-remove-text-with-property 'gnus-prev)
501 (gnus-remove-text-with-property 'gnus-next)
502 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
505 (buffer-substring-no-properties (point-min) (point-max))
507 ;; Find the original headers.
508 (set-buffer gnus-original-article-buffer)
509 (goto-char (point-min))
510 (while (looking-at message-unix-mail-delimiter)
513 (setq end (or (search-forward "\n\n" nil t) (point)))
514 ;; Delete the headers from the displayed articles.
515 (set-buffer gnus-article-copy)
516 (delete-region (goto-char (point-min))
517 (or (search-forward "\n\n" nil t) (point-max)))
518 ;; Encode bitmap smileys to ordinary text.
519 (static-unless (featurep 'xemacs)
520 (when (featurep 'smiley-mule)
521 (smiley-encode-buffer)))
522 ;; Insert the original article headers.
523 (insert-buffer-substring gnus-original-article-buffer beg end)
524 (article-decode-encoded-words)))
527 (defun gnus-post-news (post &optional group header article-buffer yank subject
530 (gnus-copy-article-buffer))
531 (let ((gnus-article-reply article-buffer)
532 (add-to-list gnus-add-to-list))
533 (gnus-setup-message (cond (yank 'reply-yank)
534 (article-buffer 'reply)
536 (let* ((group (or group gnus-newsgroup-name))
537 (charset (gnus-group-name-charset nil group))
539 to-address to-group mailing-list to-list
542 (setq to-address (gnus-group-find-parameter group 'to-address)
543 to-group (gnus-group-find-parameter group 'to-group)
544 to-list (gnus-group-find-parameter group 'to-list)
545 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
546 mailing-list (when gnus-mailing-list-groups
547 (string-match gnus-mailing-list-groups group))
548 group (gnus-group-name-decode (gnus-group-real-name group)
550 (if (or (and to-group
551 (gnus-news-group-p to-group))
554 (and (gnus-news-group-p
555 (or pgroup gnus-newsgroup-name)
556 (if header (mail-header-number header)
557 gnus-current-article))
563 (message-news (or to-group group))
564 (set-buffer gnus-article-copy)
565 (gnus-msg-treat-broken-reply-to)
566 (message-followup (if (or newsgroup-p force-news) nil to-group)))
570 (message-mail (or to-address to-list))
571 ;; Arrange for mail groups that have no `to-address' to
572 ;; get that when the user sends off the mail.
573 (when (and (not to-list)
576 (push (list 'gnus-inews-add-to-address pgroup)
577 message-send-actions)))
578 (set-buffer gnus-article-copy)
579 (gnus-msg-treat-broken-reply-to)
580 (message-wide-reply to-address)))
582 (gnus-inews-yank-articles yank))))))
584 (defun gnus-msg-treat-broken-reply-to ()
585 "Remove the Reply-to header iff broken-reply-to."
586 (when (gnus-group-find-parameter
587 gnus-newsgroup-name 'broken-reply-to)
589 (message-narrow-to-head)
590 (message-remove-header "reply-to"))))
592 (defun gnus-post-method (arg group &optional silent)
593 "Return the posting method based on GROUP and ARG.
594 If SILENT, don't prompt the user."
595 (let ((group-method (gnus-find-method-for-group group)))
597 ;; If the group-method is nil (which shouldn't happen) we use
598 ;; the default method.
600 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
601 gnus-select-method message-post-method))
602 ;; We want the inverse of the default
603 ((and arg (not (eq arg 0)))
604 (if (eq gnus-post-method 'active)
607 ;; We query the user for a post method.
609 (and gnus-post-method
610 (not (eq gnus-post-method 'current))
611 (listp (car gnus-post-method))))
613 ;; Collect all methods we know about.
615 (when (and gnus-post-method
616 (not (eq gnus-post-method 'current)))
617 (if (listp (car gnus-post-method))
619 (list gnus-post-method)))
620 gnus-secondary-select-methods
621 (mapcar 'cdr gnus-server-alist)
622 (mapcar 'car gnus-opened-servers)
623 (list gnus-select-method)
624 (list group-method)))
625 method-alist post-methods method)
626 ;; Weed out all mail methods.
628 (setq method (gnus-server-get-method "" (pop methods)))
629 (when (and (or (gnus-method-option-p method 'post)
630 (gnus-method-option-p method 'post-mail))
631 (not (member method post-methods)))
632 (push method post-methods)))
633 ;; Create a name-method alist.
637 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
642 (setq gnus-last-posting-server
644 gnus-last-posting-server)
645 ;; Just use the last value.
646 gnus-last-posting-server
648 "Posting method: " method-alist nil t
649 (cons (or gnus-last-posting-server "") 0))))
651 ;; Override normal method.
652 ((and (eq gnus-post-method 'current)
653 (not (eq (car group-method) 'nndraft))
654 (gnus-get-function group-method 'request-post t)
657 ((and gnus-post-method
658 (not (eq gnus-post-method 'current)))
660 ;; Use the normal select method.
661 (t gnus-select-method))))
665 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
666 "Return user-agent info.
667 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
668 `mime-edit-user-agent-value' exists, the return value will include it.
669 MAX-COLUMN the optional second argument if it is specified, the return value
670 will be folded up in the proper way."
671 (let ((user-agent (if (and include-mime-info
672 (boundp 'mime-edit-user-agent-value))
673 (concat (gnus-extended-version)
675 mime-edit-user-agent-value)
676 (gnus-extended-version))))
679 (unless (natnump max-column) (setq max-column 76))
681 (insert " " user-agent)
683 (while (re-search-forward "[\n\t ]+" nil t)
686 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
687 (while (eq ?\( (char-after (point)))
689 (skip-chars-forward " "))
690 (skip-chars-backward " ")
691 (if (> (current-column) max-column)
693 (if (or (not boundary) (eq ?\n (char-after boundary)))
695 (setq boundary (point))
702 (setq boundary (point))))
703 (buffer-substring 13 (point-max))))
708 ;;; Gnus Mail Functions
711 ;;; Mail reply commands of Gnus summary mode
713 (defun gnus-summary-reply (&optional yank wide)
714 "Start composing a reply mail to the current message.
715 If prefix argument YANK is non-nil, the original article is yanked
718 (list (and current-prefix-arg
719 (gnus-summary-work-articles 1))))
720 ;; Stripping headers should be specified with mail-yank-ignored-headers.
722 (gnus-summary-goto-subject (car yank)))
723 (let ((gnus-article-reply t))
724 (gnus-setup-message (if yank 'reply-yank 'reply)
725 (gnus-summary-select-article)
726 (set-buffer (gnus-copy-article-buffer))
727 (gnus-msg-treat-broken-reply-to)
728 (message-reply nil wide)
730 (gnus-inews-yank-articles yank)))))
732 (defun gnus-summary-reply-with-original (n &optional wide)
733 "Start composing a reply mail to the current message.
734 The original article will be yanked."
736 (gnus-summary-reply (gnus-summary-work-articles n) wide))
738 (defun gnus-summary-wide-reply (&optional yank)
739 "Start composing a wide reply mail to the current message.
740 If prefix argument YANK is non-nil, the original article is yanked
743 (list (and current-prefix-arg
744 (gnus-summary-work-articles 1))))
745 (gnus-summary-reply yank t))
747 (defun gnus-summary-wide-reply-with-original (n)
748 "Start composing a wide reply mail to the current message.
749 The original article will be yanked."
751 (gnus-summary-reply-with-original n t))
753 (defun gnus-summary-mail-forward (&optional full-headers post)
754 "Forward the current message to another user.
755 If FULL-HEADERS (the prefix), include full headers when forwarding."
757 (gnus-setup-message 'forward
758 (gnus-summary-select-article)
759 (let ((charset default-mime-charset))
760 (set-buffer gnus-original-article-buffer)
761 (make-local-variable 'default-mime-charset)
762 (setq default-mime-charset charset)
764 (let ((message-included-forward-headers
765 (if full-headers "" message-included-forward-headers)))
766 (message-forward post))))
768 ;;;;; XXX: generate Subject and ``Topics''?
769 ;;(defun gnus-summary-mail-digest (&optional n post)
770 ;; "Digests and forwards all articles in this series."
772 ;; (let ((subject "Digested Articles")
773 ;; (articles (gnus-summary-work-articles n))
775 ;; (gnus-setup-message 'forward
776 ;; (gnus-summary-select-article)
777 ;; (if post (message-news nil subject) (message-mail nil subject))
778 ;; (when (and message-use-multi-frames (cdr articles))
779 ;; (setq frame (window-frame (get-buffer-window (current-buffer)))))
780 ;; (message-goto-body)
781 ;; (while (setq article (pop articles))
782 ;; (save-window-excursion
783 ;; (set-buffer gnus-summary-buffer)
784 ;; (gnus-summary-select-article nil nil nil article)
785 ;; (gnus-summary-remove-process-mark article))
787 ;; (select-frame frame))
788 ;; (insert (mime-make-tag "message" "rfc822") "\n")
789 ;; (insert-buffer-substring gnus-original-article-buffer))
791 ;; (message-goto-body)
792 ;; (mime-edit-enclose-digest-region (point)(mark t)))))
794 ;;(defun gnus-summary-post-digest (&optional n)
795 ;; "Digest and forwards all articles in this series to a newsgroup."
797 ;; (gnus-summary-mail-digest n t))
799 (defun gnus-summary-resend-message (address n)
800 "Resend the current article to ADDRESS."
801 (interactive "sResend message(s) to: \nP")
802 (let ((articles (gnus-summary-work-articles n))
804 (while (setq article (pop articles))
805 (gnus-summary-select-article nil nil nil article)
807 (set-buffer gnus-original-article-buffer)
808 (message-resend address)))))
810 (defun gnus-summary-post-forward (&optional full-headers)
811 "Forward the current article to a newsgroup.
812 If FULL-HEADERS (the prefix), include full headers when forwarding."
814 (gnus-summary-mail-forward full-headers t))
816 (defvar gnus-nastygram-message
817 "The following article was inappropriately posted to %s.\n\n"
818 "Format string to insert in nastygrams.
819 The current group name will be inserted at \"%s\".")
821 (defun gnus-summary-mail-nastygram (n)
822 "Send a nastygram to the author of the current article."
824 (when (or gnus-expert-user
826 "Really send a nastygram to the author of the current article? "))
827 (let ((group gnus-newsgroup-name))
828 (gnus-summary-reply-with-original n)
829 (set-buffer gnus-message-buffer)
831 (insert (format gnus-nastygram-message group))
832 (message-send-and-exit))))
834 (defun gnus-summary-mail-crosspost-complaint (n)
835 "Send a complaint about crossposting to the current article(s)."
837 (let ((articles (gnus-summary-work-articles n))
839 (while (setq article (pop articles))
840 (set-buffer gnus-summary-buffer)
841 (gnus-summary-goto-subject article)
842 (let ((group (gnus-group-real-name gnus-newsgroup-name))
843 newsgroups followup-to)
844 (gnus-summary-select-article)
845 (set-buffer gnus-original-article-buffer)
846 (if (and (<= (length (message-tokenize-header
848 (mail-fetch-field "newsgroups"))
851 (or (not (setq followup-to (mail-fetch-field "followup-to")))
852 (not (member group (message-tokenize-header
853 followup-to ", ")))))
855 (gnus-message 1 "Followup-to restricted")
856 (gnus-message 1 "Not a crossposted article"))
857 (set-buffer gnus-summary-buffer)
858 (gnus-summary-reply-with-original 1)
859 (set-buffer gnus-message-buffer)
861 (insert (format gnus-crosspost-complaint newsgroups group))
862 (message-goto-subject)
863 (re-search-forward " *$")
864 (replace-match " (crosspost notification)" t t)
865 (gnus-deactivate-mark)
866 (when (gnus-y-or-n-p "Send this complaint? ")
867 (message-send-and-exit)))))))
869 (defun gnus-summary-mail-other-window ()
870 "Compose mail in other window."
872 (gnus-setup-message 'message
875 (defun gnus-mail-parse-comma-list ()
878 (skip-chars-forward " ")
881 (skip-chars-forward "^,")
886 (narrow-to-region beg (point))
889 (while (search-forward "\"" nil t)
893 (skip-chars-forward ",")
894 (skip-chars-forward "^,"))
895 (skip-chars-backward " ")
896 (push (buffer-substring beg (point))
898 (skip-chars-forward "^,")
899 (skip-chars-forward ", "))
902 (defun gnus-inews-add-to-address (group)
903 (let ((to-address (mail-fetch-field "to")))
904 (when (and to-address
906 ;; This mail group doesn't have a `to-list', so we add one
909 (format "Do you want to add this as `to-list': %s " to-address))
910 (gnus-group-add-parameter group (cons 'to-list to-address))))))
912 (defun gnus-put-message ()
913 "Put the current message in some group and return to Gnus."
915 (let ((reply gnus-article-reply)
916 (winconf gnus-prev-winconf)
917 (group gnus-newsgroup-name))
919 (or (and group (not (gnus-group-read-only-p group)))
920 (setq group (read-string "Put in group: " nil
921 (gnus-writable-groups))))
922 (when (gnus-gethash group gnus-newsrc-hashtb)
923 (error "No such group: %s" group))
928 (message-narrow-to-headers)
929 (let (gnus-deletable-headers)
931 (message-generate-headers message-required-news-headers)
932 (message-generate-headers message-required-mail-headers)))
933 (goto-char (point-max))
934 (insert "Gcc: " group "\n")
939 (when (get-buffer gnus-group-buffer)
940 (when (gnus-buffer-exists-p (car-safe reply))
941 (set-buffer (car reply))
943 (gnus-summary-mark-article-as-replied
946 (set-window-configuration winconf)))))
948 (defun gnus-article-mail (yank)
949 "Send a reply to the address near point.
950 If YANK is non-nil, include the original article."
954 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
955 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
957 (message-reply address)
959 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
961 (defvar nntp-server-type)
963 "Send a bug report to the Gnus maintainers."
965 (unless (gnus-alive-p)
966 (error "Gnus has been shut down"))
967 (gnus-setup-message 'bug
968 (delete-other-windows)
969 (when gnus-bug-create-help-buffer
970 (switch-to-buffer "*Gnus Help Bug*")
972 (insert gnus-bug-message)
973 (goto-char (point-min)))
974 (message-pop-to-buffer "*Gnus Bug*")
975 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
976 (when gnus-bug-create-help-buffer
977 (push `(gnus-bug-kill-buffer) message-send-actions))
978 (goto-char (point-min))
979 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
981 (insert gnus-product-name " " gnus-version-number
982 " (r" gnus-revision-number ") "
983 "based on " gnus-original-product-name " v"
984 gnus-original-version-number "\n"
985 (emacs-version) "\n")
986 (when (and (boundp 'nntp-server-type)
987 (stringp nntp-server-type))
988 (insert nntp-server-type))
989 (insert "\n\n\n\n\n")
990 (let (mime-content-types)
991 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
992 (insert (with-temp-buffer
995 (let (mime-content-types)
996 (mime-edit-insert-tag "text" "plain"))
997 (goto-char (point-min))
998 (search-forward "Subject: " nil t)
1001 (defun gnus-bug-kill-buffer ()
1002 (when (get-buffer "*Gnus Help Bug*")
1003 (kill-buffer "*Gnus Help Bug*")))
1005 (defun gnus-summary-yank-message (buffer n)
1006 "Yank the current article into a composed message."
1008 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1009 current-prefix-arg))
1010 (when (gnus-buffer-live-p buffer)
1011 (let ((summary-frame (selected-frame))
1012 (message-frame (when (static-if (featurep 'xemacs)
1013 (device-on-window-system-p)
1015 (let ((window (get-buffer-window buffer t)))
1017 (window-frame window)))))
1018 (separator (concat "^" (regexp-quote mail-header-separator)
1020 (gnus-summary-iterate n
1021 (gnus-summary-select-article)
1022 (gnus-copy-article-buffer)
1023 (when (frame-live-p message-frame)
1024 (raise-frame message-frame)
1025 (select-frame message-frame))
1026 (with-current-buffer buffer
1027 (when (save-excursion
1029 (let (case-fold-search)
1030 (and (not (re-search-backward separator nil t))
1031 (re-search-forward separator nil t))))
1032 (goto-char (match-end 0)))
1033 (message-yank-buffer gnus-article-copy))
1034 (select-frame summary-frame))
1035 (when (frame-live-p message-frame)
1036 (select-frame message-frame)))))
1038 (defun gnus-debug ()
1039 "Attempts to go through the Gnus source file and report what variables have been changed.
1040 The source file has to be in the Emacs load path."
1042 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1043 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1044 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1045 "nnmail.el" "nntp.el" "message.el"))
1047 file expr olist sym)
1048 (gnus-message 4 "Please wait while we snoop your variables...")
1050 ;; Go through all the files looking for non-default values for variables.
1052 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1055 (when (and (setq file (locate-library (pop files)))
1056 (file-exists-p file))
1057 (insert-file-contents file)
1058 (goto-char (point-min))
1059 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1060 (gnus-message 4 "Malformed sources in file %s" file)
1061 (narrow-to-region (point-min) (point))
1062 (goto-char (point-min))
1063 (while (setq expr (ignore-errors (read (current-buffer))))
1065 (and (memq (car expr) '(defvar defcustom defvoo))
1066 (stringp (nth 3 expr))
1067 (or (not (boundp (nth 1 expr)))
1068 (not (equal (eval (nth 2 expr))
1069 (symbol-value (nth 1 expr)))))
1070 (push (nth 1 expr) olist)))))))
1071 (kill-buffer (current-buffer)))
1072 (when (setq olist (nreverse olist))
1073 (insert ";----------------- Environment follows ------------------\n\n"))
1075 (if (boundp (car olist))
1077 (pp `(setq ,(car olist)
1078 ,(if (or (consp (setq sym (symbol-value (car olist))))
1080 (not (or (eq sym nil)
1082 (list 'quote (symbol-value (car olist)))
1083 (symbol-value (car olist))))
1086 (format "(setq %s 'whatever)\n" (car olist))))
1087 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1088 (setq olist (cdr olist)))
1089 ;; Remove any control chars - they seem to cause trouble for some
1090 ;; mailers. (Byte-compiled output from the stuff above.)
1092 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1093 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1095 ;; Break MIME tags purposely.
1097 (while (re-search-forward mime-edit-tag-regexp nil t)
1098 (goto-char (1+ (match-beginning 0)))
1101 ;;; Treatment of rejected articles.
1104 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1105 "Re-mail the current message.
1106 This only makes sense if the current message is a bounce message than
1107 contains some mail you have written which has been bounced back to
1109 If FETCH, try to fetch the article that this is a reply to, if indeed
1112 (gnus-summary-select-article t)
1113 (set-buffer gnus-original-article-buffer)
1114 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1115 (gnus-setup-message 'compose-bounce
1116 (let* ((references (mail-fetch-field "references"))
1117 (parent (and references (gnus-parent-id references))))
1119 ;; If there are references, we fetch the article we answered to.
1121 (gnus-summary-refer-article parent)
1122 (gnus-summary-show-all-headers))))))
1126 ;; Do Gcc handling, which copied the message over to some group.
1127 (defun gnus-inews-do-gcc (&optional gcc)
1129 (when (gnus-alive-p)
1132 (message-narrow-to-headers)
1133 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1134 (coding-system-for-write 'raw-text)
1135 (output-coding-system 'raw-text)
1136 groups group method)
1138 (message-remove-header "gcc")
1140 (setq groups (message-unquote-tokens
1141 (message-tokenize-header gcc " ,")))
1142 ;; Copy the article over to some group(s).
1143 (while (setq group (pop groups))
1146 (cond ((and (null (gnus-get-info group))
1147 (eq (car gnus-message-archive-method)
1149 (gnus-server-to-method
1150 (gnus-group-method group)))))
1151 ;; If the group doesn't exist, we assume
1152 ;; it's an archive group...
1153 gnus-message-archive-method)
1155 ((gnus-info-method (gnus-get-info group))
1156 (gnus-info-method (gnus-get-info group)))
1158 (t (gnus-group-method group)))))
1159 (gnus-check-server method)
1160 (unless (gnus-request-group group t method)
1161 (gnus-request-create-group group method))
1163 (nnheader-set-temp-buffer " *acc*")
1164 (insert-buffer-substring message-encoding-buffer)
1165 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1166 (goto-char (point-min))
1167 (when (re-search-forward
1168 (concat "^" (regexp-quote mail-header-separator) "$")
1170 (replace-match "" t t ))
1171 (unless (gnus-request-accept-article group method t t)
1172 (gnus-message 1 "Couldn't store article in group %s: %s"
1173 group (gnus-status-message method))
1175 (kill-buffer (current-buffer))))))))))
1177 (defun gnus-inews-insert-gcc ()
1178 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1181 (message-narrow-to-headers)
1182 (let* ((group gnus-outgoing-message-group)
1184 ((gnus-functionp group)
1186 ((or (stringp group) (list group))
1190 (if (stringp gcc) gcc
1191 (mapconcat 'identity gcc " "))
1194 (defun gnus-inews-insert-archive-gcc (&optional group)
1195 "Insert the Gcc to say where the article is to be archived."
1196 (let* ((var gnus-message-archive-group)
1197 (group (or group gnus-newsgroup-name ""))
1199 (and gnus-newsgroup-name
1200 (not (equal gnus-newsgroup-name ""))
1201 (gnus-group-find-parameter
1202 gnus-newsgroup-name 'gcc-self)))
1206 ((null gnus-message-archive-method)
1210 ;; Just a single group.
1213 ;; We don't want this.
1215 ((and (listp var) (stringp (car var)))
1216 ;; A list of groups.
1218 ((gnus-functionp var)
1220 (funcall var group))
1222 ;; An alist of regexps/functions/forms.
1227 ((stringp (caar var))
1229 (when (string-match (caar var) group)
1231 ((gnus-functionp (car var))
1233 (funcall (car var) group))
1235 (eval (car var)))))))
1236 (setq var (cdr var)))
1239 (when (or groups gcc-self-val)
1240 (when (stringp groups)
1241 (setq groups (list groups)))
1244 (message-narrow-to-headers)
1245 (goto-char (point-max))
1248 ;; Use the `gcc-self' param value instead.
1251 (if (stringp gcc-self-val)
1254 (if (not (eq gcc-self-val 'none))
1259 ;; Use the list of groups.
1260 (while (setq name (pop groups))
1261 (insert (if (string-match ":" name)
1263 (gnus-group-prefixed-name
1264 name gnus-message-archive-method)))
1271 (defun gnus-configure-posting-styles ()
1272 "Configure posting styles according to `gnus-posting-styles'."
1273 (unless gnus-inhibit-posting-styles
1274 (let ((group (or gnus-newsgroup-name ""))
1275 (styles gnus-posting-styles)
1276 style match variable attribute value v results
1277 filep name address element)
1278 ;; If the group has a posting-style parameter, add it at the end with a
1279 ;; regexp matching everything, to be sure it takes precedence over all
1281 (when gnus-newsgroup-name
1282 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1284 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1285 ;; Go through all styles and look for matches.
1286 (dolist (style styles)
1287 (setq match (pop style))
1288 (goto-char (point-min))
1291 ;; Regexp string match on the group name.
1292 (string-match match group))
1294 (let ((header (message-fetch-field (pop style))))
1296 (string-match (pop style) header))))
1297 ((or (symbolp match)
1298 (gnus-functionp match))
1300 ((gnus-functionp match)
1301 ;; Function to be called.
1304 ;; Variable to be checked.
1305 (symbol-value match))))
1307 ;; This is a form to be evaled.
1309 ;; We have a match, so we set the variables.
1310 (dolist (attribute style)
1311 (setq element (pop attribute)
1316 ((eq (car attribute) ':file)
1319 ((eq (car attribute) :value)
1323 ;; We get the value.
1328 ((or (symbolp value)
1329 (gnus-functionp value))
1330 (cond ((gnus-functionp value)
1333 (symbol-value value))))
1336 ;; Translate obsolescent value.
1337 (when (eq element 'signature-file)
1338 (setq element 'signature
1340 ;; Get the contents of file elems.
1342 (setq v (with-temp-buffer
1343 (insert-file-contents v)
1345 (setq results (delq (assoc element results) results))
1346 (push (cons element v) results))))
1347 ;; Now we have all the styles, so we insert them.
1348 (setq name (assq 'name results)
1349 address (assq 'address results))
1350 (setq results (delq name (delq address results)))
1351 (make-local-variable 'message-setup-hook)
1352 (dolist (result results)
1353 (add-hook 'message-setup-hook
1355 ((eq 'eval (car result))
1357 ((eq 'body (car result))
1361 (insert ,(cdr result)))))
1362 ((eq 'signature (car result))
1363 (set (make-local-variable 'message-signature) nil)
1364 (set (make-local-variable 'message-signature-file) nil)
1365 (if (not (cdr result))
1369 (let ((message-signature ,(cdr result)))
1370 (when message-signature
1371 (message-insert-signature)))))))
1374 (if (symbolp (car result))
1375 (capitalize (symbol-name (car result)))
1379 (message-remove-header ,header)
1380 (let ((value ,(cdr result)))
1383 (insert ,header ": " value "\n"))))))))))
1384 (when (or name address)
1385 (add-hook 'message-setup-hook
1387 (set (make-local-variable 'user-mail-address)
1388 ,(or (cdr address) user-mail-address))
1389 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1391 ,(or (cdr address) user-mail-address)))
1393 (message-remove-header "From")
1395 (insert "From: " (message-make-from) "\n")))))))))
1398 ;;; @ for MIME Edit mode
1401 (defun gnus-maybe-setup-default-charset ()
1403 (and (boundp 'gnus-summary-buffer)
1404 (buffer-live-p gnus-summary-buffer)
1406 (set-buffer gnus-summary-buffer)
1407 default-mime-charset))))
1410 (make-local-variable 'default-mime-charset)
1411 (setq default-mime-charset charset)
1415 ;;; @ for MIME view mode
1418 (defun gnus-following-method (buf)
1419 (gnus-setup-message 'reply-yank
1421 (if (message-news-p)
1423 (message-reply nil 'wide))
1424 (let ((message-reply-buffer buf))
1425 (message-yank-original))
1426 (message-goto-body))
1430 ;;; Allow redefinition of functions.
1436 ;;; gnus-msg.el ends here