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 tha 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-summary-mail-digest
213 "Op" gnus-summary-post-digest)
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)
220 ;;; Internal functions.
222 (defvar gnus-article-reply nil)
223 (defmacro gnus-setup-message (config &rest forms)
224 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
225 (buffer (make-symbol "gnus-setup-message-buffer"))
226 (article (make-symbol "gnus-setup-message-article"))
227 (group (make-symbol "gnus-setup-message-group")))
228 `(let ((,winconf (current-window-configuration))
229 (,buffer (buffer-name (current-buffer)))
230 (,article (and gnus-article-reply (gnus-summary-article-number)))
231 (,group gnus-newsgroup-name)
232 (message-header-setup-hook
233 (copy-sequence message-header-setup-hook))
234 (message-mode-hook (copy-sequence message-mode-hook))
235 (message-startup-parameter-alist
236 '((reply-buffer . gnus-copy-article-buffer)
237 (original-buffer . gnus-original-article-buffer)
238 (user-agent . Gnus))))
239 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
240 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
241 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
245 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
246 (setq gnus-message-buffer (current-buffer))
247 (set (make-local-variable 'gnus-message-group-art)
248 (cons ,group ,article))
249 (set (make-local-variable 'gnus-newsgroup-name) ,group)
250 (gnus-run-hooks 'gnus-message-setup-hook))
252 (gnus-configure-windows ,config t)
253 (set-buffer-modified-p nil))))
255 (defun gnus-setup-posting-charset (group)
256 (let ((alist gnus-group-posting-charset-alist)
257 (group (or group ""))
261 (while (setq elem (pop alist))
262 (when (or (and (stringp (car elem))
263 (string-match (car elem) group))
264 (and (gnus-functionp (car elem))
265 (funcall (car elem) group))
266 (and (symbolp (car elem))
267 (symbol-value (car elem))))
268 (throw 'found (cons (cadr elem) (caddr elem)))))))))
270 (defun gnus-inews-add-send-actions (winconf buffer article)
271 (make-local-hook 'message-sent-hook)
272 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
273 (setq message-post-method
275 (gnus-post-method arg ,gnus-newsgroup-name)))
276 (setq message-user-agent (gnus-extended-version))
277 (when (not message-use-multi-frames)
279 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
281 `(when (gnus-buffer-exists-p ,buffer)
285 `(gnus-summary-mark-article-as-replied ,article))))
288 (put 'gnus-setup-message 'lisp-indent-function 1)
289 (put 'gnus-setup-message 'edebug-form-spec '(form body))
291 ;;; Post news commands of Gnus group mode and summary mode
293 (defun gnus-group-mail (&optional arg)
294 "Start composing a mail.
295 If ARG, use the group under the point to find a posting style.
296 If ARG is 1, prompt for a group name to find the posting style."
298 ;; We can't `let' gnus-newsgroup-name here, since that leads
299 ;; to local variables leaking.
300 (let ((group gnus-newsgroup-name)
301 (buffer (current-buffer)))
304 (setq gnus-newsgroup-name
306 (if (= 1 (prefix-numeric-value arg))
307 (completing-read "Use posting style of group: "
308 gnus-active-hashtb nil
309 (gnus-read-active-file-p))
310 (gnus-group-group-name))
312 (gnus-setup-message 'message (message-mail)))
315 (setq gnus-newsgroup-name group)))))
317 (defun gnus-group-post-news (&optional arg)
318 "Start composing a news message.
319 If ARG, post to the group under point.
320 If ARG is 1, prompt for a group name."
322 ;; Bind this variable here to make message mode hooks work ok.
323 (let ((gnus-newsgroup-name
325 (if (= 1 (prefix-numeric-value arg))
326 (completing-read "Newsgroup: " gnus-active-hashtb nil
327 (gnus-read-active-file-p))
328 (gnus-group-group-name))
330 (gnus-post-news 'post gnus-newsgroup-name)))
332 (defun gnus-summary-post-news ()
333 "Start composing a news message."
335 (gnus-post-news 'post gnus-newsgroup-name))
337 (defun gnus-summary-followup (yank &optional force-news)
338 "Compose a followup to an article.
339 If prefix argument YANK is non-nil, original article is yanked automatically."
341 (list (and current-prefix-arg
342 (gnus-summary-work-articles 1))))
344 (gnus-summary-goto-subject (car yank)))
345 (save-window-excursion
346 (gnus-summary-select-article))
347 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
348 (gnus-newsgroup-name gnus-newsgroup-name))
350 (gnus-post-news nil gnus-newsgroup-name
351 headers gnus-article-buffer
352 yank nil force-news)))
354 (defun gnus-summary-followup-with-original (n &optional force-news)
355 "Compose a followup to an article and include the original article."
357 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
359 (defun gnus-summary-followup-to-mail (&optional arg)
360 "Followup to the current mail message via news."
362 (list (and current-prefix-arg
363 (gnus-summary-work-articles 1))))
364 (gnus-summary-followup arg t))
366 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
367 "Followup to the current mail message via news."
369 (gnus-summary-followup (gnus-summary-work-articles arg) t))
371 (defun gnus-inews-yank-articles (articles)
372 (let* ((more-than-one (cdr articles))
373 (frame (when (and message-use-multi-frames more-than-one)
374 (window-frame (get-buffer-window (current-buffer)))))
377 (while (setq article (pop articles))
378 (save-window-excursion
379 (set-buffer gnus-summary-buffer)
380 (gnus-summary-select-article nil nil nil article)
381 (gnus-summary-remove-process-mark article))
383 (select-frame frame))
385 ;; Gathering references.
387 (setq refs (message-list-references
389 (mail-header-references gnus-current-headers)
390 (mail-header-message-id gnus-current-headers))))
392 (gnus-copy-article-buffer)
393 (let ((message-reply-buffer gnus-article-copy)
394 (message-reply-headers gnus-current-headers))
395 (message-yank-original)
396 (setq beg (or beg (mark t))))
401 ;; Replace with the gathered references.
405 (message-narrow-to-headers)
406 (let ((case-fold-search t))
407 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
409 (goto-char (point-max))))
411 (list (or (assq 'References message-header-format-alist)
412 '(References . message-shorten-references)))
413 (list (cons 'References
414 (mapconcat 'identity (nreverse refs) " "))))
415 (backward-delete-char 1))
421 (defun gnus-summary-cancel-article (&optional n symp)
422 "Cancel an article you posted.
423 Uses the process-prefix convention. If given the symbolic
424 prefix `a', cancel using the standard posting method; if not
425 post using the current select method."
426 (interactive (gnus-interactive "P\ny"))
427 (let ((articles (gnus-summary-work-articles n))
430 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
432 (while (setq article (pop articles))
433 (when (gnus-summary-select-article t nil nil article)
434 (when (gnus-eval-in-buffer-window gnus-article-buffer
436 (set-buffer gnus-original-article-buffer)
437 (message-cancel-news)))
438 (gnus-summary-mark-as-read article gnus-canceled-mark)
439 (gnus-cache-remove-article 1))
440 (gnus-article-hide-headers-if-wanted))
441 (gnus-summary-remove-process-mark article))))
443 (defun gnus-summary-supersede-article ()
444 "Compose an article that will supersede a previous article.
445 This is done simply by taking the old article and adding a Supersedes
446 header line with the old Message-ID."
448 (let ((article (gnus-summary-article-number))
449 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
450 (gnus-setup-message 'reply-yank
451 (gnus-summary-select-article t)
452 (set-buffer gnus-original-article-buffer)
456 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
458 (set-buffer ,gnus-summary-buffer)
459 (gnus-cache-possibly-remove-article ,article nil nil nil t)
460 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
461 message-send-actions))))
465 (defun gnus-copy-article-buffer (&optional article-buffer)
466 ;; make a copy of the article buffer with all text properties removed
467 ;; this copy is in the buffer gnus-article-copy.
468 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
469 ;; this buffer should be passed to all mail/news reply/post routines.
470 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
471 (let ((article-buffer (or article-buffer gnus-article-buffer))
473 (if (not (and (get-buffer article-buffer)
474 (gnus-buffer-exists-p article-buffer)))
475 (error "Can't find any article buffer")
477 (set-buffer article-buffer)
479 ;; Copy over the (displayed) article buffer, delete
480 ;; hidden text and remove text properties.
482 (let ((inhibit-read-only t))
483 (copy-to-buffer gnus-article-copy (point-min) (point-max))
484 (set-buffer gnus-article-copy)
485 (gnus-article-delete-text-of-type 'annotation)
486 (gnus-remove-text-with-property 'gnus-prev)
487 (gnus-remove-text-with-property 'gnus-next)
488 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
491 (format "%s" (buffer-string))
494 ;; Find the original headers.
495 (set-buffer gnus-original-article-buffer)
496 (goto-char (point-min))
497 (while (looking-at message-unix-mail-delimiter)
500 (setq end (or (search-forward "\n\n" nil t) (point)))
501 ;; Delete the headers from the displayed articles.
502 (set-buffer gnus-article-copy)
503 (delete-region (goto-char (point-min))
504 (or (search-forward "\n\n" nil t) (point-max)))
505 ;; Encode bitmap smileys to ordinary text.
506 (static-unless (featurep 'xemacs)
507 (when (featurep 'smiley-mule)
508 (smiley-encode-buffer)))
509 ;; Insert the original article headers.
510 (insert-buffer-substring gnus-original-article-buffer beg end)
511 (article-decode-encoded-words)))
514 (defun gnus-post-news (post &optional group header article-buffer yank subject
517 (gnus-copy-article-buffer))
518 (let ((gnus-article-reply article-buffer)
519 (add-to-list gnus-add-to-list))
520 (gnus-setup-message (cond (yank 'reply-yank)
521 (article-buffer 'reply)
523 (let* ((group (or group gnus-newsgroup-name))
525 to-address to-group mailing-list to-list
528 (setq to-address (gnus-group-find-parameter group 'to-address)
529 to-group (gnus-group-find-parameter group 'to-group)
530 to-list (gnus-group-find-parameter group 'to-list)
531 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
532 mailing-list (when gnus-mailing-list-groups
533 (string-match gnus-mailing-list-groups group))
534 group (gnus-group-real-name group)))
535 (if (or (and to-group
536 (gnus-news-group-p to-group))
539 (and (gnus-news-group-p
540 (or pgroup gnus-newsgroup-name)
541 (if header (mail-header-number header)
542 gnus-current-article))
548 (message-news (or to-group group))
549 (set-buffer gnus-article-copy)
550 (gnus-msg-treat-broken-reply-to)
551 (message-followup (if (or newsgroup-p force-news) nil to-group)))
555 (message-mail (or to-address to-list))
556 ;; Arrange for mail groups that have no `to-address' to
557 ;; get that when the user sends off the mail.
558 (when (and (not to-list)
561 (push (list 'gnus-inews-add-to-address pgroup)
562 message-send-actions)))
563 (set-buffer gnus-article-copy)
564 (gnus-msg-treat-broken-reply-to)
565 (message-wide-reply to-address)))
567 (gnus-inews-yank-articles yank))))))
569 (defun gnus-msg-treat-broken-reply-to ()
570 "Remove the Reply-to header iff broken-reply-to."
571 (when (gnus-group-find-parameter
572 gnus-newsgroup-name 'broken-reply-to)
574 (message-narrow-to-head)
575 (message-remove-header "reply-to"))))
577 (defun gnus-post-method (arg group &optional silent)
578 "Return the posting method based on GROUP and ARG.
579 If SILENT, don't prompt the user."
580 (let ((group-method (gnus-find-method-for-group group)))
582 ;; If the group-method is nil (which shouldn't happen) we use
583 ;; the default method.
585 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
586 gnus-select-method message-post-method))
587 ;; We want the inverse of the default
588 ((and arg (not (eq arg 0)))
589 (if (eq gnus-post-method 'active)
592 ;; We query the user for a post method.
594 (and gnus-post-method
595 (not (eq gnus-post-method 'current))
596 (listp (car gnus-post-method))))
598 ;; Collect all methods we know about.
600 (when (and gnus-post-method
601 (not (eq gnus-post-method 'current)))
602 (if (listp (car gnus-post-method))
604 (list gnus-post-method)))
605 gnus-secondary-select-methods
606 (mapcar 'cdr gnus-server-alist)
607 (mapcar 'car gnus-opened-servers)
608 (list gnus-select-method)
609 (list group-method)))
610 method-alist post-methods method)
611 ;; Weed out all mail methods.
613 (setq method (gnus-server-get-method "" (pop methods)))
614 (when (and (or (gnus-method-option-p method 'post)
615 (gnus-method-option-p method 'post-mail))
616 (not (member method post-methods)))
617 (push method post-methods)))
618 ;; Create a name-method alist.
622 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
627 (setq gnus-last-posting-server
629 gnus-last-posting-server)
630 ;; Just use the last value.
631 gnus-last-posting-server
633 "Posting method: " method-alist nil t
634 (cons (or gnus-last-posting-server "") 0))))
636 ;; Override normal method.
637 ((and (eq gnus-post-method 'current)
638 (not (eq (car group-method) 'nndraft))
639 (gnus-get-function group-method 'request-post t)
642 ((and gnus-post-method
643 (not (eq gnus-post-method 'current)))
645 ;; Use the normal select method.
646 (t gnus-select-method))))
650 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
651 "Return user-agent info.
652 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
653 `mime-edit-user-agent-value' exists, the return value will include it.
654 MAX-COLUMN the optional second argument if it is specified, the return value
655 will be folded up in the proper way."
656 (let ((user-agent (if (and include-mime-info
657 (boundp 'mime-edit-user-agent-value))
658 (concat (gnus-extended-version)
660 mime-edit-user-agent-value)
661 (gnus-extended-version))))
664 (unless (natnump max-column) (setq max-column 76))
666 (insert " " user-agent)
668 (while (re-search-forward "[\n\t ]+" nil t)
671 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
672 (while (eq ?\( (char-after (point)))
674 (skip-chars-forward " "))
675 (skip-chars-backward " ")
676 (if (> (current-column) max-column)
678 (if (or (not boundary) (eq ?\n (char-after boundary)))
680 (setq boundary (point))
687 (setq boundary (point))))
688 (buffer-substring 13 (point-max))))
693 ;;; Gnus Mail Functions
696 ;;; Mail reply commands of Gnus summary mode
698 (defun gnus-summary-reply (&optional yank wide)
699 "Start composing a reply mail to the current message.
700 If prefix argument YANK is non-nil, the original article is yanked
703 (list (and current-prefix-arg
704 (gnus-summary-work-articles 1))))
705 ;; Stripping headers should be specified with mail-yank-ignored-headers.
707 (gnus-summary-goto-subject (car yank)))
708 (let ((gnus-article-reply t))
709 (gnus-setup-message (if yank 'reply-yank 'reply)
710 (gnus-summary-select-article)
711 (set-buffer (gnus-copy-article-buffer))
712 (gnus-msg-treat-broken-reply-to)
713 (message-reply nil wide)
715 (gnus-inews-yank-articles yank)))))
717 (defun gnus-summary-reply-with-original (n &optional wide)
718 "Start composing a reply mail to the current message.
719 The original article will be yanked."
721 (gnus-summary-reply (gnus-summary-work-articles n) wide))
723 (defun gnus-summary-wide-reply (&optional yank)
724 "Start composing a wide reply mail to the current message.
725 If prefix argument YANK is non-nil, the original article is yanked
728 (list (and current-prefix-arg
729 (gnus-summary-work-articles 1))))
730 (gnus-summary-reply yank t))
732 (defun gnus-summary-wide-reply-with-original (n)
733 "Start composing a wide reply mail to the current message.
734 The original article will be yanked."
736 (gnus-summary-reply-with-original n t))
738 (defun gnus-summary-mail-forward (&optional full-headers post)
739 "Forward the current message to another user.
740 If FULL-HEADERS (the prefix), include full headers when forwarding."
742 (gnus-setup-message 'forward
743 (gnus-summary-select-article)
744 (let ((charset default-mime-charset))
745 (set-buffer gnus-original-article-buffer)
746 (make-local-variable 'default-mime-charset)
747 (setq default-mime-charset charset)
749 (let ((message-included-forward-headers
750 (if full-headers "" message-included-forward-headers)))
751 (message-forward post))))
753 ;;; XXX: generate Subject and ``Topics''?
754 (defun gnus-summary-mail-digest (&optional n post)
755 "Digests and forwards all articles in this series."
757 (let ((subject "Digested Articles")
758 (articles (gnus-summary-work-articles n))
760 (gnus-setup-message 'forward
761 (gnus-summary-select-article)
762 (if post (message-news nil subject) (message-mail nil subject))
763 (when (and message-use-multi-frames (cdr articles))
764 (setq frame (window-frame (get-buffer-window (current-buffer)))))
766 (while (setq article (pop articles))
767 (save-window-excursion
768 (set-buffer gnus-summary-buffer)
769 (gnus-summary-select-article nil nil nil article)
770 (gnus-summary-remove-process-mark article))
772 (select-frame frame))
773 (insert (mime-make-tag "message" "rfc822") "\n")
774 (insert-buffer-substring gnus-original-article-buffer))
777 (mime-edit-enclose-digest-region (point)(mark t)))))
779 (defun gnus-summary-post-digest (&optional n)
780 "Digest and forwards all articles in this series to a newsgroup."
782 (gnus-summary-mail-digest n t))
784 (defun gnus-summary-resend-message (address n)
785 "Resend the current article to ADDRESS."
786 (interactive "sResend message(s) to: \nP")
787 (let ((articles (gnus-summary-work-articles n))
789 (while (setq article (pop articles))
790 (gnus-summary-select-article nil nil nil article)
792 (set-buffer gnus-original-article-buffer)
793 (message-resend address)))))
795 (defun gnus-summary-post-forward (&optional full-headers)
796 "Forward the current article to a newsgroup.
797 If FULL-HEADERS (the prefix), include full headers when forwarding."
799 (gnus-summary-mail-forward full-headers t))
801 (defvar gnus-nastygram-message
802 "The following article was inappropriately posted to %s.\n\n"
803 "Format string to insert in nastygrams.
804 The current group name will be inserted at \"%s\".")
806 (defun gnus-summary-mail-nastygram (n)
807 "Send a nastygram to the author of the current article."
809 (when (or gnus-expert-user
811 "Really send a nastygram to the author of the current article? "))
812 (let ((group gnus-newsgroup-name))
813 (gnus-summary-reply-with-original n)
814 (set-buffer gnus-message-buffer)
816 (insert (format gnus-nastygram-message group))
817 (message-send-and-exit))))
819 (defun gnus-summary-mail-crosspost-complaint (n)
820 "Send a complaint about crossposting to the current article(s)."
822 (let ((articles (gnus-summary-work-articles n))
824 (while (setq article (pop articles))
825 (set-buffer gnus-summary-buffer)
826 (gnus-summary-goto-subject article)
827 (let ((group (gnus-group-real-name gnus-newsgroup-name))
828 newsgroups followup-to)
829 (gnus-summary-select-article)
830 (set-buffer gnus-original-article-buffer)
831 (if (and (<= (length (message-tokenize-header
833 (mail-fetch-field "newsgroups"))
836 (or (not (setq followup-to (mail-fetch-field "followup-to")))
837 (not (member group (message-tokenize-header
838 followup-to ", ")))))
840 (gnus-message 1 "Followup-to restricted")
841 (gnus-message 1 "Not a crossposted article"))
842 (set-buffer gnus-summary-buffer)
843 (gnus-summary-reply-with-original 1)
844 (set-buffer gnus-message-buffer)
846 (insert (format gnus-crosspost-complaint newsgroups group))
847 (message-goto-subject)
848 (re-search-forward " *$")
849 (replace-match " (crosspost notification)" t t)
850 (gnus-deactivate-mark)
851 (when (gnus-y-or-n-p "Send this complaint? ")
852 (message-send-and-exit)))))))
854 (defun gnus-summary-mail-other-window ()
855 "Compose mail in other window."
857 (gnus-setup-message 'message
860 (defun gnus-mail-parse-comma-list ()
863 (skip-chars-forward " ")
866 (skip-chars-forward "^,")
871 (narrow-to-region beg (point))
874 (while (search-forward "\"" nil t)
878 (skip-chars-forward ",")
879 (skip-chars-forward "^,"))
880 (skip-chars-backward " ")
881 (push (buffer-substring beg (point))
883 (skip-chars-forward "^,")
884 (skip-chars-forward ", "))
887 (defun gnus-inews-add-to-address (group)
888 (let ((to-address (mail-fetch-field "to")))
889 (when (and to-address
891 ;; This mail group doesn't have a `to-list', so we add one
894 (format "Do you want to add this as `to-list': %s " to-address))
895 (gnus-group-add-parameter group (cons 'to-list to-address))))))
897 (defun gnus-put-message ()
898 "Put the current message in some group and return to Gnus."
900 (let ((reply gnus-article-reply)
901 (winconf gnus-prev-winconf)
902 (group gnus-newsgroup-name))
904 (or (and group (not (gnus-group-read-only-p group)))
905 (setq group (read-string "Put in group: " nil
906 (gnus-writable-groups))))
907 (when (gnus-gethash group gnus-newsrc-hashtb)
908 (error "No such group: %s" group))
913 (message-narrow-to-headers)
914 (let (gnus-deletable-headers)
916 (message-generate-headers message-required-news-headers)
917 (message-generate-headers message-required-mail-headers)))
918 (goto-char (point-max))
919 (insert "Gcc: " group "\n")
924 (when (get-buffer gnus-group-buffer)
925 (when (gnus-buffer-exists-p (car-safe reply))
926 (set-buffer (car reply))
928 (gnus-summary-mark-article-as-replied
931 (set-window-configuration winconf)))))
933 (defun gnus-article-mail (yank)
934 "Send a reply to the address near point.
935 If YANK is non-nil, include the original article."
939 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
940 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
942 (message-reply address)
944 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
946 (defvar nntp-server-type)
948 "Send a bug report to the Gnus maintainers."
950 (unless (gnus-alive-p)
951 (error "Gnus has been shut down"))
952 (gnus-setup-message 'bug
953 (delete-other-windows)
954 (when gnus-bug-create-help-buffer
955 (switch-to-buffer "*Gnus Help Bug*")
957 (insert gnus-bug-message)
958 (goto-char (point-min)))
959 (message-pop-to-buffer "*Gnus Bug*")
960 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
961 (when gnus-bug-create-help-buffer
962 (push `(gnus-bug-kill-buffer) message-send-actions))
963 (goto-char (point-min))
964 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
966 (insert gnus-product-name " " gnus-version-number
967 " (r" gnus-revision-number ") "
968 "based on " gnus-original-product-name " v"
969 gnus-original-version-number "\n"
970 (emacs-version) "\n")
971 (when (and (boundp 'nntp-server-type)
972 (stringp nntp-server-type))
973 (insert nntp-server-type))
974 (insert "\n\n\n\n\n")
975 (let (mime-content-types)
976 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
977 (insert (with-temp-buffer
980 (let (mime-content-types)
981 (mime-edit-insert-tag "text" "plain"))
982 (goto-char (point-min))
983 (search-forward "Subject: " nil t)
986 (defun gnus-bug-kill-buffer ()
987 (when (get-buffer "*Gnus Help Bug*")
988 (kill-buffer "*Gnus Help Bug*")))
990 (defun gnus-summary-yank-message (buffer n)
991 "Yank the current article into a composed message."
993 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
995 (when (gnus-buffer-live-p buffer)
996 (let ((summary-frame (selected-frame))
997 (message-frame (when (static-if (featurep 'xemacs)
998 (device-on-window-system-p)
1000 (let ((window (get-buffer-window buffer t)))
1002 (window-frame window)))))
1003 (separator (concat "^" (regexp-quote mail-header-separator)
1005 (gnus-summary-iterate n
1006 (gnus-summary-select-article)
1007 (gnus-copy-article-buffer)
1008 (when (frame-live-p message-frame)
1009 (raise-frame message-frame)
1010 (select-frame message-frame))
1011 (with-current-buffer buffer
1012 (when (save-excursion
1014 (let (case-fold-search)
1015 (and (not (re-search-backward separator nil t))
1016 (re-search-forward separator nil t))))
1017 (goto-char (match-end 0)))
1018 (message-yank-buffer gnus-article-copy))
1019 (select-frame summary-frame))
1020 (when (frame-live-p message-frame)
1021 (select-frame message-frame)))))
1023 (defun gnus-debug ()
1024 "Attempts to go through the Gnus source file and report what variables have been changed.
1025 The source file has to be in the Emacs load path."
1027 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1028 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1029 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1030 "nnmail.el" "nntp.el" "message.el"))
1032 file expr olist sym)
1033 (gnus-message 4 "Please wait while we snoop your variables...")
1035 ;; Go through all the files looking for non-default values for variables.
1037 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1040 (when (and (setq file (locate-library (pop files)))
1041 (file-exists-p file))
1042 (insert-file-contents file)
1043 (goto-char (point-min))
1044 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1045 (gnus-message 4 "Malformed sources in file %s" file)
1046 (narrow-to-region (point-min) (point))
1047 (goto-char (point-min))
1048 (while (setq expr (ignore-errors (read (current-buffer))))
1050 (and (memq (car expr) '(defvar defcustom defvoo))
1051 (stringp (nth 3 expr))
1052 (or (not (boundp (nth 1 expr)))
1053 (not (equal (eval (nth 2 expr))
1054 (symbol-value (nth 1 expr)))))
1055 (push (nth 1 expr) olist)))))))
1056 (kill-buffer (current-buffer)))
1057 (when (setq olist (nreverse olist))
1058 (insert ";----------------- Environment follows ------------------\n\n"))
1060 (if (boundp (car olist))
1062 (pp `(setq ,(car olist)
1063 ,(if (or (consp (setq sym (symbol-value (car olist))))
1065 (not (or (eq sym nil)
1067 (list 'quote (symbol-value (car olist)))
1068 (symbol-value (car olist))))
1071 (format "(setq %s 'whatever)\n" (car olist))))
1072 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1073 (setq olist (cdr olist)))
1074 ;; Remove any control chars - they seem to cause trouble for some
1075 ;; mailers. (Byte-compiled output from the stuff above.)
1077 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1078 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1080 ;; Break MIME tags purposely.
1082 (while (re-search-forward mime-edit-tag-regexp nil t)
1083 (goto-char (1+ (match-beginning 0)))
1086 ;;; Treatment of rejected articles.
1089 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1090 "Re-mail the current message.
1091 This only makes sense if the current message is a bounce message than
1092 contains some mail you have written which has been bounced back to
1094 If FETCH, try to fetch the article that this is a reply to, if indeed
1097 (gnus-summary-select-article t)
1098 (set-buffer gnus-original-article-buffer)
1099 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1100 (gnus-setup-message 'compose-bounce
1101 (let* ((references (mail-fetch-field "references"))
1102 (parent (and references (gnus-parent-id references))))
1104 ;; If there are references, we fetch the article we answered to.
1106 (gnus-summary-refer-article parent)
1107 (gnus-summary-show-all-headers))))))
1111 ;; Do Gcc handling, which copied the message over to some group.
1112 (defun gnus-inews-do-gcc (&optional gcc)
1114 (when (gnus-alive-p)
1117 (message-narrow-to-headers)
1118 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1119 (coding-system-for-write 'raw-text)
1120 (output-coding-system 'raw-text)
1121 groups group method)
1123 (message-remove-header "gcc")
1125 (setq groups (message-tokenize-header gcc " ,"))
1126 ;; Copy the article over to some group(s).
1127 (while (setq group (pop groups))
1130 (cond ((and (null (gnus-get-info group))
1131 (eq (car gnus-message-archive-method)
1133 (gnus-server-to-method
1134 (gnus-group-method group)))))
1135 ;; If the group doesn't exist, we assume
1136 ;; it's an archive group...
1137 gnus-message-archive-method)
1139 ((gnus-info-method (gnus-get-info group))
1140 (gnus-info-method (gnus-get-info group)))
1142 (t (gnus-group-method group)))))
1143 (gnus-check-server method)
1144 (unless (gnus-request-group group t method)
1145 (gnus-request-create-group group method))
1147 (nnheader-set-temp-buffer " *acc*")
1148 (insert-buffer-substring message-encoding-buffer)
1149 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1150 (goto-char (point-min))
1151 (when (re-search-forward
1152 (concat "^" (regexp-quote mail-header-separator) "$")
1154 (replace-match "" t t ))
1155 (unless (gnus-request-accept-article group method t t)
1156 (gnus-message 1 "Couldn't store article in group %s: %s"
1157 group (gnus-status-message method))
1159 (kill-buffer (current-buffer))))))))))
1161 (defun gnus-inews-insert-gcc ()
1162 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1165 (message-narrow-to-headers)
1166 (let* ((group gnus-outgoing-message-group)
1168 ((gnus-functionp group)
1170 ((or (stringp group) (list group))
1174 (if (stringp gcc) gcc
1175 (mapconcat 'identity gcc " "))
1178 (defun gnus-inews-insert-archive-gcc (&optional group)
1179 "Insert the Gcc to say where the article is to be archived."
1180 (let* ((var gnus-message-archive-group)
1181 (group (or group gnus-newsgroup-name ""))
1183 (and gnus-newsgroup-name
1184 (not (equal gnus-newsgroup-name ""))
1185 (gnus-group-find-parameter
1186 gnus-newsgroup-name 'gcc-self)))
1190 ((null gnus-message-archive-method)
1194 ;; Just a single group.
1197 ;; We don't want this.
1199 ((and (listp var) (stringp (car var)))
1200 ;; A list of groups.
1202 ((gnus-functionp var)
1204 (funcall var group))
1206 ;; An alist of regexps/functions/forms.
1211 ((stringp (caar var))
1213 (when (string-match (caar var) group)
1215 ((gnus-functionp (car var))
1217 (funcall (car var) group))
1219 (eval (car var)))))))
1220 (setq var (cdr var)))
1223 (when (or groups gcc-self-val)
1224 (when (stringp groups)
1225 (setq groups (list groups)))
1228 (message-narrow-to-headers)
1229 (goto-char (point-max))
1232 ;; Use the `gcc-self' param value instead.
1235 (if (stringp gcc-self-val)
1238 (if (not (eq gcc-self-val 'none))
1243 ;; Use the list of groups.
1244 (while (setq name (pop groups))
1245 (insert (if (string-match ":" name)
1247 (gnus-group-prefixed-name
1248 name gnus-message-archive-method)))
1255 (defun gnus-configure-posting-styles ()
1256 "Configure posting styles according to `gnus-posting-styles'."
1257 (unless gnus-inhibit-posting-styles
1258 (let ((group (or gnus-newsgroup-name ""))
1259 (styles gnus-posting-styles)
1260 style match variable attribute value v results
1261 filep name address element)
1262 ;; If the group has a posting-style parameter, add it at the end with a
1263 ;; regexp matching everything, to be sure it takes precedence over all
1265 (when gnus-newsgroup-name
1266 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1268 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1269 ;; Go through all styles and look for matches.
1270 (dolist (style styles)
1271 (setq match (pop style))
1272 (goto-char (point-min))
1275 ;; Regexp string match on the group name.
1276 (string-match match group))
1278 (let ((header (message-fetch-field (pop style))))
1280 (string-match (pop style) header))))
1281 ((or (symbolp match)
1282 (gnus-functionp match))
1284 ((gnus-functionp match)
1285 ;; Function to be called.
1288 ;; Variable to be checked.
1289 (symbol-value match))))
1291 ;; This is a form to be evaled.
1293 ;; We have a match, so we set the variables.
1294 (dolist (attribute style)
1295 (setq element (pop attribute)
1300 ((eq (car attribute) ':file)
1303 ((eq (car attribute) :value)
1307 ;; We get the value.
1312 ((or (symbolp value)
1313 (gnus-functionp value))
1314 (cond ((gnus-functionp value)
1317 (symbol-value value))))
1320 ;; Translate obsolescent value.
1321 (when (eq element 'signature-file)
1322 (setq element 'signature
1324 ;; Get the contents of file elems.
1326 (setq v (with-temp-buffer
1327 (insert-file-contents v)
1329 (setq results (delq (assoc element results) results))
1330 (push (cons element v) results))))
1331 ;; Now we have all the styles, so we insert them.
1332 (setq name (assq 'name results)
1333 address (assq 'address results))
1334 (setq results (delq name (delq address results)))
1335 (make-local-variable 'message-setup-hook)
1336 (dolist (result results)
1337 (add-hook 'message-setup-hook
1339 ((eq 'eval (car result))
1341 ((eq 'body (car result))
1345 (insert ,(cdr result)))))
1346 ((eq 'signature (car result))
1347 (set (make-local-variable 'message-signature) nil)
1348 (set (make-local-variable 'message-signature-file) nil)
1349 (if (not (cdr result))
1353 (let ((message-signature ,(cdr result)))
1354 (when message-signature
1355 (message-insert-signature)))))))
1358 (if (symbolp (car result))
1359 (capitalize (symbol-name (car result)))
1363 (message-remove-header ,header)
1364 (let ((value ,(cdr result)))
1367 (insert ,header ": " value "\n"))))))))))
1368 (when (or name address)
1369 (add-hook 'message-setup-hook
1371 (set (make-local-variable 'user-mail-address)
1372 ,(or (cdr address) user-mail-address))
1373 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1375 ,(or (cdr address) user-mail-address)))
1377 (message-remove-header "From")
1379 (insert "From: " (message-make-from) "\n")))))))))
1382 ;;; @ for MIME Edit mode
1385 (defun gnus-maybe-setup-default-charset ()
1387 (and (boundp 'gnus-summary-buffer)
1388 (buffer-live-p gnus-summary-buffer)
1390 (set-buffer gnus-summary-buffer)
1391 default-mime-charset))))
1394 (make-local-variable 'default-mime-charset)
1395 (setq default-mime-charset charset)
1399 ;;; @ for MIME view mode
1402 (defun gnus-following-method (buf)
1403 (gnus-setup-message 'reply-yank
1405 (if (message-news-p)
1407 (message-reply nil 'wide))
1408 (let ((message-reply-buffer buf))
1409 (message-yank-original))
1410 (message-goto-body))
1414 ;;; Allow redefinition of functions.
1420 ;;; gnus-msg.el ends here