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 (defvar gnus-inews-mark-gcc-as-read nil
110 "If non-nil, automatically mark Gcc articles as read.")
112 (defcustom gnus-group-posting-charset-alist
113 '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
114 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
115 (message-this-is-mail nil nil)
116 (message-this-is-news nil t))
117 "Alist of regexps and permitted unencoded charsets for posting.
118 Each element of the alist has the form (TEST HEADER BODY-LIST), where
119 TEST is either a regular expression matching the newsgroup header or a
121 HEADER is the charset which may be left unencoded in the header (nil
122 means encode all charsets),
123 BODY-LIST is a list of charsets which may be encoded using 8bit
124 content-transfer encoding in the body, or one of the special values
125 nil (always encode using quoted-printable) or t (always use 8bit).
127 Note that any value other than nil for HEADER infringes some RFCs, so
128 use this option with care."
129 :type '(repeat (list :tag "Permitted unencoded charsets"
131 (regexp :tag "Group")
132 (const :tag "Mail message" :value message-this-is-mail)
133 (const :tag "News article" :value message-this-is-news))
134 (choice :tag "Header"
135 (const :tag "None" nil)
136 (symbol :tag "Charset"))
138 (const :tag "Any" :value t)
139 (const :tag "None" :value nil)
140 (repeat :tag "Charsets"
141 (symbol :tag "Charset")))))
142 :group 'gnus-charset)
144 ;;; Internal variables.
146 (defvar gnus-inhibit-posting-styles nil
147 "Inhibit the use of posting styles.")
149 (defvar gnus-message-buffer "*Mail Gnus*")
150 (defvar gnus-article-copy nil)
151 (defvar gnus-last-posting-server nil)
152 (defvar gnus-message-group-art nil)
154 (defconst gnus-bug-message
155 (format "Sending a bug report to the Gnus Towers.
156 ========================================
158 This gnus is the %s%s.
159 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
160 Developers. (the addresses below are mailing list addresses)
162 ========================================
164 The buffer below is a mail buffer. When you press `C-c C-c', it will
165 be sent to the Gnus Bug Exterminators.
167 The thing near the bottom of the buffer is how the environment
168 settings will be included in the mail. Please do not delete that.
169 They will tell the Bug People what your environment is, so that it
170 will be easier to locate the bugs.
172 If you have found a bug that makes Emacs go \"beep\", set
173 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
174 and include the backtrace in your bug report.
176 Please describe the bug in annoying, painstaking detail.
178 Thank you for your help in stamping out bugs.
181 (if (string= gnus-product-name "Semi-gnus")
183 ", a modified version of Semi-gnus")))
186 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
187 (autoload 'news-setup "rnewspost")
188 (autoload 'news-reply-mode "rnewspost")
189 (autoload 'rmail-dont-reply-to "mail-utils")
190 (autoload 'rmail-output "rmailout"))
194 ;;; Gnus Posting Functions
197 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
198 "p" gnus-summary-post-news
199 "f" gnus-summary-followup
200 "F" gnus-summary-followup-with-original
201 "c" gnus-summary-cancel-article
202 "s" gnus-summary-supersede-article
203 "r" gnus-summary-reply
204 "y" gnus-summary-yank-message
205 "R" gnus-summary-reply-with-original
206 "w" gnus-summary-wide-reply
207 "W" gnus-summary-wide-reply-with-original
208 "n" gnus-summary-followup-to-mail
209 "N" gnus-summary-followup-to-mail-with-original
210 "m" gnus-summary-mail-other-window
211 "u" gnus-uu-post-news
212 "\M-c" gnus-summary-mail-crosspost-complaint
213 "om" gnus-summary-mail-forward
214 "op" gnus-summary-post-forward
215 "Om" gnus-uu-digest-mail-forward
216 "Op" gnus-uu-digest-post-forward)
218 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
219 "b" gnus-summary-resend-bounced-mail
220 ;; "c" gnus-summary-send-draft
221 "r" gnus-summary-resend-message)
223 ;;; Internal functions.
225 (defvar gnus-article-reply nil)
226 (defmacro gnus-setup-message (config &rest forms)
227 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
228 (buffer (make-symbol "gnus-setup-message-buffer"))
229 (article (make-symbol "gnus-setup-message-article"))
230 (group (make-symbol "gnus-setup-message-group")))
231 `(let ((,winconf (current-window-configuration))
232 (,buffer (buffer-name (current-buffer)))
233 (,article (and gnus-article-reply (gnus-summary-article-number)))
234 (,group gnus-newsgroup-name)
235 (message-header-setup-hook
236 (copy-sequence message-header-setup-hook))
237 (message-mode-hook (copy-sequence message-mode-hook))
238 (message-startup-parameter-alist
239 '((reply-buffer . gnus-copy-article-buffer)
240 (original-buffer . gnus-original-article-buffer)
241 (user-agent . Gnus))))
242 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
243 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
244 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
248 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
249 (setq gnus-message-buffer (current-buffer))
250 (set (make-local-variable 'gnus-message-group-art)
251 (cons ,group ,article))
252 (set (make-local-variable 'gnus-newsgroup-name) ,group)
253 (gnus-run-hooks 'gnus-message-setup-hook))
255 (gnus-configure-windows ,config t)
256 (set-buffer-modified-p nil))))
259 (defun gnus-msg-mail (&rest args)
260 "Start editing a mail message to be sent.
261 Like `message-mail', but with Gnus paraphernalia, particularly the
262 the Gcc: header for archiving purposes."
264 (gnus-setup-message 'message
265 (apply 'message-mail args)))
268 (define-mail-user-agent 'gnus-user-agent
269 'gnus-msg-mail 'message-send-and-exit
270 'message-kill-buffer 'message-send-hook)
272 (defun gnus-setup-posting-charset (group)
273 (let ((alist gnus-group-posting-charset-alist)
274 (group (or group ""))
278 (while (setq elem (pop alist))
279 (when (or (and (stringp (car elem))
280 (string-match (car elem) group))
281 (and (gnus-functionp (car elem))
282 (funcall (car elem) group))
283 (and (symbolp (car elem))
284 (symbol-value (car elem))))
285 (throw 'found (cons (cadr elem) (caddr elem)))))))))
287 (defun gnus-inews-add-send-actions (winconf buffer article)
288 (make-local-hook 'message-sent-hook)
289 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
290 'gnus-inews-do-gcc) nil t)
292 (make-local-hook 'message-header-hook)
293 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
294 (setq message-post-method
296 (gnus-post-method arg ,gnus-newsgroup-name)))
297 (setq message-user-agent (gnus-extended-version))
298 (when (not message-use-multi-frames)
300 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
302 `(when (gnus-buffer-exists-p ,buffer)
306 `(gnus-summary-mark-article-as-replied ,article))))
309 (put 'gnus-setup-message 'lisp-indent-function 1)
310 (put 'gnus-setup-message 'edebug-form-spec '(form body))
312 ;;; Post news commands of Gnus group mode and summary mode
314 (defun gnus-group-mail (&optional arg)
315 "Start composing a mail.
316 If ARG, use the group under the point to find a posting style.
317 If ARG is 1, prompt for a group name to find the posting style."
319 ;; We can't `let' gnus-newsgroup-name here, since that leads
320 ;; to local variables leaking.
321 (let ((group gnus-newsgroup-name)
322 (buffer (current-buffer)))
325 (setq gnus-newsgroup-name
327 (if (= 1 (prefix-numeric-value arg))
328 (completing-read "Use posting style of group: "
329 gnus-active-hashtb nil
330 (gnus-read-active-file-p))
331 (gnus-group-group-name))
333 (gnus-setup-message 'message (message-mail)))
336 (setq gnus-newsgroup-name group)))))
338 (defun gnus-group-post-news (&optional arg)
339 "Start composing a news message.
340 If ARG, post to the group under point.
341 If ARG is 1, prompt for a group name."
343 ;; Bind this variable here to make message mode hooks work ok.
344 (let ((gnus-newsgroup-name
346 (if (= 1 (prefix-numeric-value arg))
347 (completing-read "Newsgroup: " gnus-active-hashtb nil
348 (gnus-read-active-file-p))
349 (gnus-group-group-name))
351 (gnus-post-news 'post gnus-newsgroup-name)))
353 (defun gnus-summary-post-news ()
354 "Start composing a news message."
356 (gnus-post-news 'post gnus-newsgroup-name))
358 (defun gnus-summary-followup (yank &optional force-news)
359 "Compose a followup to an article.
360 If prefix argument YANK is non-nil, original article is yanked automatically."
362 (list (and current-prefix-arg
363 (gnus-summary-work-articles 1))))
365 (gnus-summary-goto-subject (car yank)))
366 (save-window-excursion
367 (gnus-summary-select-article))
368 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
369 (gnus-newsgroup-name gnus-newsgroup-name))
371 (gnus-post-news nil gnus-newsgroup-name
372 headers gnus-article-buffer
373 yank nil force-news)))
375 (defun gnus-summary-followup-with-original (n &optional force-news)
376 "Compose a followup to an article and include the original article."
378 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
380 (defun gnus-summary-followup-to-mail (&optional arg)
381 "Followup to the current mail message via news."
383 (list (and current-prefix-arg
384 (gnus-summary-work-articles 1))))
385 (gnus-summary-followup arg t))
387 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
388 "Followup to the current mail message via news."
390 (gnus-summary-followup (gnus-summary-work-articles arg) t))
392 (defun gnus-inews-yank-articles (articles)
393 (let* ((more-than-one (cdr articles))
394 (frame (when (and message-use-multi-frames more-than-one)
395 (window-frame (get-buffer-window (current-buffer)))))
398 (while (setq article (pop articles))
399 (save-window-excursion
400 (set-buffer gnus-summary-buffer)
401 (gnus-summary-select-article nil nil nil article)
402 (gnus-summary-remove-process-mark article))
404 (select-frame frame))
406 ;; Gathering references.
408 (setq refs (message-list-references
410 (mail-header-references gnus-current-headers)
411 (mail-header-message-id gnus-current-headers))))
413 (gnus-copy-article-buffer)
414 (let ((message-reply-buffer gnus-article-copy)
415 (message-reply-headers gnus-current-headers))
416 (message-yank-original)
417 (setq beg (or beg (mark t))))
422 ;; Replace with the gathered references.
426 (message-narrow-to-headers)
427 (let ((case-fold-search t))
428 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
430 (goto-char (point-max))))
432 (list (or (assq 'References message-header-format-alist)
433 '(References . message-shorten-references)))
434 (list (cons 'References
435 (mapconcat 'identity (nreverse refs) " "))))
436 (backward-delete-char 1))
442 (defun gnus-summary-cancel-article (&optional n symp)
443 "Cancel an article you posted.
444 Uses the process-prefix convention. If given the symbolic
445 prefix `a', cancel using the standard posting method; if not
446 post using the current select method."
447 (interactive (gnus-interactive "P\ny"))
448 (let ((articles (gnus-summary-work-articles n))
451 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
453 (while (setq article (pop articles))
454 (when (gnus-summary-select-article t nil nil article)
455 (when (gnus-eval-in-buffer-window gnus-article-buffer
457 (set-buffer gnus-original-article-buffer)
458 (message-cancel-news)))
459 (gnus-summary-mark-as-read article gnus-canceled-mark)
460 (gnus-cache-remove-article 1))
461 (gnus-article-hide-headers-if-wanted))
462 (gnus-summary-remove-process-mark article))))
464 (defun gnus-summary-supersede-article ()
465 "Compose an article that will supersede a previous article.
466 This is done simply by taking the old article and adding a Supersedes
467 header line with the old Message-ID."
469 (let ((article (gnus-summary-article-number))
470 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
471 (gnus-setup-message 'reply-yank
472 (gnus-summary-select-article t)
473 (set-buffer gnus-original-article-buffer)
477 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
479 (set-buffer ,gnus-summary-buffer)
480 (gnus-cache-possibly-remove-article ,article nil nil nil t)
481 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
482 message-send-actions))))
486 (defun gnus-copy-article-buffer (&optional article-buffer)
487 ;; make a copy of the article buffer with all text properties removed
488 ;; this copy is in the buffer gnus-article-copy.
489 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
490 ;; this buffer should be passed to all mail/news reply/post routines.
491 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
492 (let ((article-buffer (or article-buffer gnus-article-buffer))
494 (if (not (and (get-buffer article-buffer)
495 (gnus-buffer-exists-p article-buffer)))
496 (error "Can't find any article buffer")
498 (set-buffer article-buffer)
499 (let ((gnus-newsgroup-charset (or gnus-article-charset
500 gnus-newsgroup-charset))
501 (gnus-newsgroup-ignored-charsets
502 (or gnus-article-ignored-charsets
503 gnus-newsgroup-ignored-charsets)))
505 ;; Copy over the (displayed) article buffer, delete
506 ;; hidden text and remove text properties.
508 (let ((inhibit-read-only t))
509 (copy-to-buffer gnus-article-copy (point-min) (point-max))
510 (set-buffer gnus-article-copy)
511 ;; Encode bitmap smileys to ordinary text.
512 ;; Possibly, the original text might be restored.
513 (static-unless (featurep 'xemacs)
514 (when (featurep 'smiley-mule)
515 (smiley-encode-buffer)))
516 (gnus-article-delete-text-of-type 'annotation)
517 (gnus-remove-text-with-property 'gnus-prev)
518 (gnus-remove-text-with-property 'gnus-next)
519 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
522 (buffer-substring-no-properties (point-min) (point-max))
524 ;; Find the original headers.
525 (set-buffer gnus-original-article-buffer)
526 (goto-char (point-min))
527 (while (looking-at message-unix-mail-delimiter)
530 (setq end (or (search-forward "\n\n" nil t) (point)))
531 ;; Delete the headers from the displayed articles.
532 (set-buffer gnus-article-copy)
533 (delete-region (goto-char (point-min))
534 (or (search-forward "\n\n" nil t) (point-max)))
535 ;; Insert the original article headers.
536 (insert-buffer-substring gnus-original-article-buffer beg end)
537 (article-decode-encoded-words))))
540 (defun gnus-post-news (post &optional group header article-buffer yank subject
543 (gnus-copy-article-buffer))
544 (let ((gnus-article-reply article-buffer)
545 (add-to-list gnus-add-to-list))
546 (gnus-setup-message (cond (yank 'reply-yank)
547 (article-buffer 'reply)
549 (let* ((group (or group gnus-newsgroup-name))
550 (charset (gnus-group-name-charset nil group))
552 to-address to-group mailing-list to-list
555 (setq to-address (gnus-group-find-parameter group 'to-address)
556 to-group (gnus-group-find-parameter group 'to-group)
557 to-list (gnus-group-find-parameter group 'to-list)
558 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
559 mailing-list (when gnus-mailing-list-groups
560 (string-match gnus-mailing-list-groups group))
561 group (gnus-group-name-decode (gnus-group-real-name group)
563 (if (or (and to-group
564 (gnus-news-group-p to-group))
567 (and (gnus-news-group-p
568 (or pgroup gnus-newsgroup-name)
569 (if header (mail-header-number header)
570 gnus-current-article))
576 (message-news (or to-group group))
577 (set-buffer gnus-article-copy)
578 (gnus-msg-treat-broken-reply-to)
579 (message-followup (if (or newsgroup-p force-news) nil to-group)))
583 (message-mail (or to-address to-list))
584 ;; Arrange for mail groups that have no `to-address' to
585 ;; get that when the user sends off the mail.
586 (when (and (not to-list)
589 (push (list 'gnus-inews-add-to-address pgroup)
590 message-send-actions)))
591 (set-buffer gnus-article-copy)
592 (gnus-msg-treat-broken-reply-to)
593 (message-wide-reply to-address)))
595 (gnus-inews-yank-articles yank))))))
597 (defun gnus-msg-treat-broken-reply-to ()
598 "Remove the Reply-to header iff broken-reply-to."
599 (when (gnus-group-find-parameter
600 gnus-newsgroup-name 'broken-reply-to)
602 (message-narrow-to-head)
603 (message-remove-header "reply-to"))))
605 (defun gnus-post-method (arg group &optional silent)
606 "Return the posting method based on GROUP and ARG.
607 If SILENT, don't prompt the user."
608 (let ((group-method (gnus-find-method-for-group group)))
610 ;; If the group-method is nil (which shouldn't happen) we use
611 ;; the default method.
613 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
614 gnus-select-method message-post-method))
615 ;; We want the inverse of the default
616 ((and arg (not (eq arg 0)))
617 (if (eq gnus-post-method 'active)
620 ;; We query the user for a post method.
622 (and gnus-post-method
623 (not (eq gnus-post-method 'current))
624 (listp (car gnus-post-method))))
626 ;; Collect all methods we know about.
628 (when (and gnus-post-method
629 (not (eq gnus-post-method 'current)))
630 (if (listp (car gnus-post-method))
632 (list gnus-post-method)))
633 gnus-secondary-select-methods
634 (mapcar 'cdr gnus-server-alist)
635 (mapcar 'car gnus-opened-servers)
636 (list gnus-select-method)
637 (list group-method)))
638 method-alist post-methods method)
639 ;; Weed out all mail methods.
641 (setq method (gnus-server-get-method "" (pop methods)))
642 (when (and (or (gnus-method-option-p method 'post)
643 (gnus-method-option-p method 'post-mail))
644 (not (member method post-methods)))
645 (push method post-methods)))
646 ;; Create a name-method alist.
650 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
655 (setq gnus-last-posting-server
657 gnus-last-posting-server)
658 ;; Just use the last value.
659 gnus-last-posting-server
661 "Posting method: " method-alist nil t
662 (cons (or gnus-last-posting-server "") 0))))
664 ;; Override normal method.
665 ((and (eq gnus-post-method 'current)
666 (not (eq (car group-method) 'nndraft))
667 (gnus-get-function group-method 'request-post t)
670 ((and gnus-post-method
671 (not (eq gnus-post-method 'current)))
673 ;; Use the normal select method.
674 (t gnus-select-method))))
678 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
679 "Return user-agent info.
680 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
681 `mime-edit-user-agent-value' exists, the return value will include it.
682 MAX-COLUMN the optional second argument if it is specified, the return value
683 will be folded up in the proper way."
684 (let ((user-agent (if (and include-mime-info
685 (boundp 'mime-edit-user-agent-value))
686 (concat (gnus-extended-version)
688 mime-edit-user-agent-value)
689 (gnus-extended-version))))
692 (unless (natnump max-column) (setq max-column 76))
694 (insert " " user-agent)
696 (while (re-search-forward "[\n\t ]+" nil t)
699 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
700 (while (eq ?\( (char-after (point)))
702 (skip-chars-forward " "))
703 (skip-chars-backward " ")
704 (if (> (current-column) max-column)
706 (if (or (not boundary) (eq ?\n (char-after boundary)))
708 (setq boundary (point))
715 (setq boundary (point))))
716 (buffer-substring 13 (point-max))))
721 ;;; Gnus Mail Functions
724 ;;; Mail reply commands of Gnus summary mode
726 (defun gnus-summary-reply (&optional yank wide)
727 "Start composing a reply mail to the current message.
728 If prefix argument YANK is non-nil, the original article is yanked
731 (list (and current-prefix-arg
732 (gnus-summary-work-articles 1))))
733 ;; Stripping headers should be specified with mail-yank-ignored-headers.
735 (gnus-summary-goto-subject (car yank)))
736 (let ((gnus-article-reply t))
737 (gnus-setup-message (if yank 'reply-yank 'reply)
738 (gnus-summary-select-article)
739 (set-buffer (gnus-copy-article-buffer))
740 (gnus-msg-treat-broken-reply-to)
741 (message-reply nil wide)
743 (gnus-inews-yank-articles yank)))))
745 (defun gnus-summary-reply-with-original (n &optional wide)
746 "Start composing a reply mail to the current message.
747 The original article will be yanked."
749 (gnus-summary-reply (gnus-summary-work-articles n) wide))
751 (defun gnus-summary-wide-reply (&optional yank)
752 "Start composing a wide reply mail to the current message.
753 If prefix argument YANK is non-nil, the original article is yanked
756 (list (and current-prefix-arg
757 (gnus-summary-work-articles 1))))
758 (gnus-summary-reply yank t))
760 (defun gnus-summary-wide-reply-with-original (n)
761 "Start composing a wide reply mail to the current message.
762 The original article will be yanked."
764 (gnus-summary-reply-with-original n t))
766 (defun gnus-summary-mail-forward (&optional full-headers post)
767 "Forward the current message to another user.
768 If FULL-HEADERS (the prefix), include full headers when forwarding."
770 (gnus-setup-message 'forward
771 (gnus-summary-select-article)
772 (let ((charset default-mime-charset))
773 (set-buffer gnus-original-article-buffer)
774 (make-local-variable 'default-mime-charset)
775 (setq default-mime-charset charset)
777 (let ((message-included-forward-headers
778 (if full-headers "" message-included-forward-headers)))
779 (message-forward post))))
781 ;;;;; XXX: generate Subject and ``Topics''?
782 ;;(defun gnus-summary-mail-digest (&optional n post)
783 ;; "Digests and forwards all articles in this series."
785 ;; (let ((subject "Digested Articles")
786 ;; (articles (gnus-summary-work-articles n))
788 ;; (gnus-setup-message 'forward
789 ;; (gnus-summary-select-article)
790 ;; (if post (message-news nil subject) (message-mail nil subject))
791 ;; (when (and message-use-multi-frames (cdr articles))
792 ;; (setq frame (window-frame (get-buffer-window (current-buffer)))))
793 ;; (message-goto-body)
794 ;; (while (setq article (pop articles))
795 ;; (save-window-excursion
796 ;; (set-buffer gnus-summary-buffer)
797 ;; (gnus-summary-select-article nil nil nil article)
798 ;; (gnus-summary-remove-process-mark article))
800 ;; (select-frame frame))
801 ;; (insert (mime-make-tag "message" "rfc822") "\n")
802 ;; (insert-buffer-substring gnus-original-article-buffer))
804 ;; (message-goto-body)
805 ;; (mime-edit-enclose-digest-region (point)(mark t)))))
807 ;;(defun gnus-summary-post-digest (&optional n)
808 ;; "Digest and forwards all articles in this series to a newsgroup."
810 ;; (gnus-summary-mail-digest n t))
812 (defun gnus-summary-resend-message (address n)
813 "Resend the current article to ADDRESS."
814 (interactive "sResend message(s) to: \nP")
815 (let ((articles (gnus-summary-work-articles n))
817 (while (setq article (pop articles))
818 (gnus-summary-select-article nil nil nil article)
820 (set-buffer gnus-original-article-buffer)
821 (message-resend address)))))
823 (defun gnus-summary-post-forward (&optional full-headers)
824 "Forward the current article to a newsgroup.
825 If FULL-HEADERS (the prefix), include full headers when forwarding."
827 (gnus-summary-mail-forward full-headers t))
829 (defvar gnus-nastygram-message
830 "The following article was inappropriately posted to %s.\n\n"
831 "Format string to insert in nastygrams.
832 The current group name will be inserted at \"%s\".")
834 (defun gnus-summary-mail-nastygram (n)
835 "Send a nastygram to the author of the current article."
837 (when (or gnus-expert-user
839 "Really send a nastygram to the author of the current article? "))
840 (let ((group gnus-newsgroup-name))
841 (gnus-summary-reply-with-original n)
842 (set-buffer gnus-message-buffer)
844 (insert (format gnus-nastygram-message group))
845 (message-send-and-exit))))
847 (defun gnus-summary-mail-crosspost-complaint (n)
848 "Send a complaint about crossposting to the current article(s)."
850 (let ((articles (gnus-summary-work-articles n))
852 (while (setq article (pop articles))
853 (set-buffer gnus-summary-buffer)
854 (gnus-summary-goto-subject article)
855 (let ((group (gnus-group-real-name gnus-newsgroup-name))
856 newsgroups followup-to)
857 (gnus-summary-select-article)
858 (set-buffer gnus-original-article-buffer)
859 (if (and (<= (length (message-tokenize-header
861 (mail-fetch-field "newsgroups"))
864 (or (not (setq followup-to (mail-fetch-field "followup-to")))
865 (not (member group (message-tokenize-header
866 followup-to ", ")))))
868 (gnus-message 1 "Followup-to restricted")
869 (gnus-message 1 "Not a crossposted article"))
870 (set-buffer gnus-summary-buffer)
871 (gnus-summary-reply-with-original 1)
872 (set-buffer gnus-message-buffer)
874 (insert (format gnus-crosspost-complaint newsgroups group))
875 (message-goto-subject)
876 (re-search-forward " *$")
877 (replace-match " (crosspost notification)" t t)
878 (gnus-deactivate-mark)
879 (when (gnus-y-or-n-p "Send this complaint? ")
880 (message-send-and-exit)))))))
882 (defun gnus-summary-mail-other-window ()
883 "Compose mail in other window."
885 (gnus-setup-message 'message
888 (defun gnus-mail-parse-comma-list ()
891 (skip-chars-forward " ")
894 (skip-chars-forward "^,")
899 (narrow-to-region beg (point))
902 (while (search-forward "\"" nil t)
906 (skip-chars-forward ",")
907 (skip-chars-forward "^,"))
908 (skip-chars-backward " ")
909 (push (buffer-substring beg (point))
911 (skip-chars-forward "^,")
912 (skip-chars-forward ", "))
915 (defun gnus-inews-add-to-address (group)
916 (let ((to-address (mail-fetch-field "to")))
917 (when (and to-address
919 ;; This mail group doesn't have a `to-list', so we add one
922 (format "Do you want to add this as `to-list': %s " to-address))
923 (gnus-group-add-parameter group (cons 'to-list to-address))))))
925 (defun gnus-put-message ()
926 "Put the current message in some group and return to Gnus."
928 (let ((reply gnus-article-reply)
929 (winconf gnus-prev-winconf)
930 (group gnus-newsgroup-name))
932 (or (and group (not (gnus-group-read-only-p group)))
933 (setq group (read-string "Put in group: " nil
934 (gnus-writable-groups))))
935 (when (gnus-gethash group gnus-newsrc-hashtb)
936 (error "No such group: %s" group))
941 (message-narrow-to-headers)
942 (let (gnus-deletable-headers)
944 (message-generate-headers message-required-news-headers)
945 (message-generate-headers message-required-mail-headers)))
946 (goto-char (point-max))
947 (insert "Gcc: " group "\n")
952 (when (get-buffer gnus-group-buffer)
953 (when (gnus-buffer-exists-p (car-safe reply))
954 (set-buffer (car reply))
956 (gnus-summary-mark-article-as-replied
959 (set-window-configuration winconf)))))
961 (defun gnus-article-mail (yank)
962 "Send a reply to the address near point.
963 If YANK is non-nil, include the original article."
967 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
968 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
970 (message-reply address)
972 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
974 (defvar nntp-server-type)
976 "Send a bug report to the Gnus maintainers."
978 (unless (gnus-alive-p)
979 (error "Gnus has been shut down"))
980 (gnus-setup-message 'bug
981 (delete-other-windows)
982 (when gnus-bug-create-help-buffer
983 (switch-to-buffer "*Gnus Help Bug*")
985 (insert gnus-bug-message)
986 (goto-char (point-min)))
987 (message-pop-to-buffer "*Gnus Bug*")
988 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
989 (when gnus-bug-create-help-buffer
990 (push `(gnus-bug-kill-buffer) message-send-actions))
991 (goto-char (point-min))
992 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
994 (insert gnus-product-name " " gnus-version-number
995 " (r" gnus-revision-number ") "
996 "based on " gnus-original-product-name " v"
997 gnus-original-version-number "\n"
998 (emacs-version) "\n")
999 (when (and (boundp 'nntp-server-type)
1000 (stringp nntp-server-type))
1001 (insert nntp-server-type))
1002 (insert "\n\n\n\n\n")
1003 (let (mime-content-types)
1004 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
1005 (insert (with-temp-buffer
1008 (let (mime-content-types)
1009 (mime-edit-insert-tag "text" "plain"))
1010 (goto-char (point-min))
1011 (search-forward "Subject: " nil t)
1014 (defun gnus-bug-kill-buffer ()
1015 (when (get-buffer "*Gnus Help Bug*")
1016 (kill-buffer "*Gnus Help Bug*")))
1018 (defun gnus-summary-yank-message (buffer n)
1019 "Yank the current article into a composed message."
1021 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1022 current-prefix-arg))
1023 (when (gnus-buffer-live-p buffer)
1024 (let ((summary-frame (selected-frame))
1025 (message-frame (when (static-if (featurep 'xemacs)
1026 (device-on-window-system-p)
1028 (let ((window (get-buffer-window buffer t)))
1030 (window-frame window)))))
1031 (separator (concat "^" (regexp-quote mail-header-separator)
1033 (gnus-summary-iterate n
1034 (gnus-summary-select-article)
1035 (gnus-copy-article-buffer)
1036 (when (frame-live-p message-frame)
1037 (raise-frame message-frame)
1038 (select-frame message-frame))
1039 (with-current-buffer buffer
1040 (when (save-excursion
1042 (let (case-fold-search)
1043 (and (not (re-search-backward separator nil t))
1044 (re-search-forward separator nil t))))
1045 (goto-char (match-end 0)))
1046 (message-yank-buffer gnus-article-copy))
1047 (select-frame summary-frame))
1048 (when (frame-live-p message-frame)
1049 (select-frame message-frame)))))
1051 (defun gnus-debug ()
1052 "Attempts to go through the Gnus source file and report what variables have been changed.
1053 The source file has to be in the Emacs load path."
1055 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1056 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1057 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1058 "nnmail.el" "nntp.el" "message.el"))
1060 file expr olist sym)
1061 (gnus-message 4 "Please wait while we snoop your variables...")
1063 ;; Go through all the files looking for non-default values for variables.
1065 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1068 (when (and (setq file (locate-library (pop files)))
1069 (file-exists-p file))
1070 (insert-file-contents file)
1071 (goto-char (point-min))
1072 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1073 (gnus-message 4 "Malformed sources in file %s" file)
1074 (narrow-to-region (point-min) (point))
1075 (goto-char (point-min))
1076 (while (setq expr (ignore-errors (read (current-buffer))))
1078 (and (memq (car expr) '(defvar defcustom defvoo))
1079 (stringp (nth 3 expr))
1080 (or (not (boundp (nth 1 expr)))
1081 (not (equal (eval (nth 2 expr))
1082 (symbol-value (nth 1 expr)))))
1083 (push (nth 1 expr) olist)))))))
1084 (kill-buffer (current-buffer)))
1085 (when (setq olist (nreverse olist))
1086 (insert ";----------------- Environment follows ------------------\n\n"))
1088 (if (boundp (car olist))
1090 (pp `(setq ,(car olist)
1091 ,(if (or (consp (setq sym (symbol-value (car olist))))
1093 (not (or (eq sym nil)
1095 (list 'quote (symbol-value (car olist)))
1096 (symbol-value (car olist))))
1099 (format "(setq %s 'whatever)\n" (car olist))))
1100 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1101 (setq olist (cdr olist)))
1102 ;; Remove any control chars - they seem to cause trouble for some
1103 ;; mailers. (Byte-compiled output from the stuff above.)
1105 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1106 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1108 ;; Break MIME tags purposely.
1110 (while (re-search-forward mime-edit-tag-regexp nil t)
1111 (goto-char (1+ (match-beginning 0)))
1114 ;;; Treatment of rejected articles.
1117 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1118 "Re-mail the current message.
1119 This only makes sense if the current message is a bounce message than
1120 contains some mail you have written which has been bounced back to
1122 If FETCH, try to fetch the article that this is a reply to, if indeed
1125 (gnus-summary-select-article t)
1126 (set-buffer gnus-original-article-buffer)
1127 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1128 (gnus-setup-message 'compose-bounce
1129 (let* ((references (mail-fetch-field "references"))
1130 (parent (and references (gnus-parent-id references))))
1132 ;; If there are references, we fetch the article we answered to.
1134 (gnus-summary-refer-article parent)
1135 (gnus-summary-show-all-headers))))))
1139 (defun gnus-inews-group-method (group)
1140 (cond ((and (null (gnus-get-info group))
1141 (eq (car gnus-message-archive-method)
1143 (gnus-server-to-method
1144 (gnus-group-method group)))))
1145 ;; If the group doesn't exist, we assume
1146 ;; it's an archive group...
1147 gnus-message-archive-method)
1149 ((gnus-info-method (gnus-get-info group))
1150 (gnus-info-method (gnus-get-info group)))
1152 (t (gnus-group-method group))))
1154 ;; Do Gcc handling, which copied the message over to some group.
1155 (defun gnus-inews-do-gcc (&optional gcc)
1157 (when (gnus-alive-p)
1160 (message-narrow-to-headers)
1161 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1162 (coding-system-for-write 'raw-text)
1163 (output-coding-system 'raw-text)
1164 groups group method group-art)
1166 (message-remove-header "gcc")
1168 (setq groups (message-unquote-tokens
1169 (message-tokenize-header gcc " ,")))
1170 ;; Copy the article over to some group(s).
1171 (while (setq group (pop groups))
1173 (setq method (gnus-inews-group-method group)))
1174 (unless (gnus-request-group group t method)
1175 (gnus-request-create-group group method))
1177 (nnheader-set-temp-buffer " *acc*")
1178 (insert-buffer-substring message-encoding-buffer)
1179 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1180 (goto-char (point-min))
1181 (when (re-search-forward
1182 (concat "^" (regexp-quote mail-header-separator) "$")
1184 (replace-match "" t t ))
1185 (unless (setq group-art
1186 (gnus-request-accept-article group method t t))
1187 (gnus-message 1 "Couldn't store article in group %s: %s"
1188 group (gnus-status-message method))
1190 (when (and group-art gnus-inews-mark-gcc-as-read)
1191 (let ((active (gnus-active group)))
1193 (if (< (cdr active) (cdr group-art))
1194 (gnus-set-active group (cons (car active)
1196 (gnus-activate-group group)))
1197 (let ((buffer (concat "*Summary " group "*"))
1198 (mark gnus-read-mark)
1199 (article (cdr group-art)))
1203 (with-current-buffer buffer
1204 (when gnus-newsgroup-prepared
1205 (when (and gnus-newsgroup-auto-expire
1206 (memq mark gnus-auto-expirable-marks))
1207 (setq mark gnus-expirable-mark))
1208 (setq mark (gnus-request-update-mark
1209 group article mark))
1210 (gnus-mark-article-as-read article mark)
1211 (setq gnus-newsgroup-active (gnus-active group))
1213 (gnus-group-make-articles-read group
1215 (kill-buffer (current-buffer))))))))))
1217 (defun gnus-inews-insert-gcc ()
1218 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1221 (message-narrow-to-headers)
1222 (let* ((group gnus-outgoing-message-group)
1224 ((gnus-functionp group)
1226 ((or (stringp group) (list group))
1230 (if (stringp gcc) gcc
1231 (mapconcat 'identity gcc " "))
1234 (defun gnus-inews-insert-archive-gcc (&optional group)
1235 "Insert the Gcc to say where the article is to be archived."
1236 (let* ((var gnus-message-archive-group)
1237 (group (or group gnus-newsgroup-name ""))
1239 (and gnus-newsgroup-name
1240 (not (equal gnus-newsgroup-name ""))
1241 (gnus-group-find-parameter
1242 gnus-newsgroup-name 'gcc-self)))
1246 ((null gnus-message-archive-method)
1250 ;; Just a single group.
1253 ;; We don't want this.
1255 ((and (listp var) (stringp (car var)))
1256 ;; A list of groups.
1258 ((gnus-functionp var)
1260 (funcall var group))
1262 ;; An alist of regexps/functions/forms.
1267 ((stringp (caar var))
1269 (when (string-match (caar var) group)
1271 ((gnus-functionp (car var))
1273 (funcall (car var) group))
1275 (eval (car var)))))))
1276 (setq var (cdr var)))
1279 (when (or groups gcc-self-val)
1280 (when (stringp groups)
1281 (setq groups (list groups)))
1284 (message-narrow-to-headers)
1285 (goto-char (point-max))
1288 ;; Use the `gcc-self' param value instead.
1291 (if (stringp gcc-self-val)
1294 (if (not (eq gcc-self-val 'none))
1299 ;; Use the list of groups.
1300 (while (setq name (pop groups))
1301 (insert (if (string-match ":" name)
1303 (gnus-group-prefixed-name
1304 name gnus-message-archive-method)))
1311 (defun gnus-configure-posting-styles ()
1312 "Configure posting styles according to `gnus-posting-styles'."
1313 (unless gnus-inhibit-posting-styles
1314 (let ((group (or gnus-newsgroup-name ""))
1315 (styles gnus-posting-styles)
1316 style match variable attribute value v results
1317 filep name address element)
1318 ;; If the group has a posting-style parameter, add it at the end with a
1319 ;; regexp matching everything, to be sure it takes precedence over all
1321 (when gnus-newsgroup-name
1322 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1324 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1325 ;; Go through all styles and look for matches.
1326 (dolist (style styles)
1327 (setq match (pop style))
1328 (goto-char (point-min))
1331 ;; Regexp string match on the group name.
1332 (string-match match group))
1334 (let ((header (message-fetch-field (pop style))))
1336 (string-match (pop style) header))))
1337 ((or (symbolp match)
1338 (gnus-functionp match))
1340 ((gnus-functionp match)
1341 ;; Function to be called.
1344 ;; Variable to be checked.
1345 (symbol-value match))))
1347 ;; This is a form to be evaled.
1349 ;; We have a match, so we set the variables.
1350 (dolist (attribute style)
1351 (setq element (pop attribute)
1356 ((eq (car attribute) ':file)
1359 ((eq (car attribute) :value)
1363 ;; We get the value.
1368 ((or (symbolp value)
1369 (gnus-functionp value))
1370 (cond ((gnus-functionp value)
1373 (symbol-value value))))
1376 ;; Translate obsolescent value.
1377 (when (eq element 'signature-file)
1378 (setq element 'signature
1380 ;; Get the contents of file elems.
1382 (setq v (with-temp-buffer
1383 (insert-file-contents v)
1385 (setq results (delq (assoc element results) results))
1386 (push (cons element v) results))))
1387 ;; Now we have all the styles, so we insert them.
1388 (setq name (assq 'name results)
1389 address (assq 'address results))
1390 (setq results (delq name (delq address results)))
1391 (make-local-variable 'message-setup-hook)
1392 (dolist (result results)
1393 (add-hook 'message-setup-hook
1395 ((eq 'eval (car result))
1397 ((eq 'body (car result))
1401 (insert ,(cdr result)))))
1402 ((eq 'signature (car result))
1403 (set (make-local-variable 'message-signature) nil)
1404 (set (make-local-variable 'message-signature-file) nil)
1405 (if (not (cdr result))
1409 (let ((message-signature ,(cdr result)))
1410 (when message-signature
1411 (message-insert-signature)))))))
1414 (if (symbolp (car result))
1415 (capitalize (symbol-name (car result)))
1419 (message-remove-header ,header)
1420 (let ((value ,(cdr result)))
1423 (insert ,header ": " value "\n"))))))))))
1424 (when (or name address)
1425 (add-hook 'message-setup-hook
1427 (set (make-local-variable 'user-mail-address)
1428 ,(or (cdr address) user-mail-address))
1429 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1431 ,(or (cdr address) user-mail-address)))
1433 (message-remove-header "From")
1435 (insert "From: " (message-make-from) "\n")))))))))
1438 ;;; @ for MIME Edit mode
1441 (defun gnus-maybe-setup-default-charset ()
1443 (and (boundp 'gnus-summary-buffer)
1444 (buffer-live-p gnus-summary-buffer)
1446 (set-buffer gnus-summary-buffer)
1447 default-mime-charset))))
1450 (make-local-variable 'default-mime-charset)
1451 (setq default-mime-charset charset)
1455 ;;; @ for MIME view mode
1458 (defun gnus-following-method (buf)
1459 (gnus-setup-message 'reply-yank
1461 (if (message-news-p)
1463 (message-reply nil 'wide))
1464 (let ((message-reply-buffer buf))
1465 (message-yank-original))
1466 (message-goto-body))
1470 ;;; Allow redefinition of functions.
1476 ;;; gnus-msg.el ends here