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\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" 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-check-before-posting nil)
152 (defvar gnus-last-posting-server nil)
153 (defvar gnus-message-group-art nil)
155 (defconst gnus-bug-message
156 (format "Sending a bug report to the Gnus Towers.
157 ========================================
159 This gnus is the %s%s.
160 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
161 Developers. (the addresses below are mailing list addresses)
163 ========================================
165 The buffer below is a mail buffer. When you press `C-c C-c', it will
166 be sent to the Gnus Bug Exterminators.
168 The thing near the bottom of the buffer is how the environment
169 settings will be included in the mail. Please do not delete that.
170 They will tell the Bug People what your environment is, so that it
171 will be easier to locate the bugs.
173 If you have found a bug that makes Emacs go \"beep\", set
174 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
175 and include the backtrace in your bug report.
177 Please describe the bug in annoying, painstaking detail.
179 Thank you for your help in stamping out bugs.
182 (if (string= gnus-product-name "Semi-gnus")
184 ", a modified version of Semi-gnus")))
187 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
188 (autoload 'news-setup "rnewspost")
189 (autoload 'news-reply-mode "rnewspost")
190 (autoload 'rmail-dont-reply-to "mail-utils")
191 (autoload 'rmail-output "rmailout"))
195 ;;; Gnus Posting Functions
198 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
199 "p" gnus-summary-post-news
200 "f" gnus-summary-followup
201 "F" gnus-summary-followup-with-original
202 "c" gnus-summary-cancel-article
203 "s" gnus-summary-supersede-article
204 "r" gnus-summary-reply
205 "y" gnus-summary-yank-message
206 "R" gnus-summary-reply-with-original
207 "w" gnus-summary-wide-reply
208 "W" gnus-summary-wide-reply-with-original
209 "n" gnus-summary-followup-to-mail
210 "N" gnus-summary-followup-to-mail-with-original
211 "m" gnus-summary-mail-other-window
212 "u" gnus-uu-post-news
213 "\M-c" gnus-summary-mail-crosspost-complaint
214 "om" gnus-summary-mail-forward
215 "op" gnus-summary-post-forward
216 "Om" gnus-uu-digest-mail-forward
217 "Op" gnus-uu-digest-post-forward)
219 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
220 "b" gnus-summary-resend-bounced-mail
221 ;; "c" gnus-summary-send-draft
222 "r" gnus-summary-resend-message)
224 ;;; Internal functions.
226 (defvar gnus-article-reply nil)
227 (defmacro gnus-setup-message (config &rest forms)
228 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
229 (buffer (make-symbol "gnus-setup-message-buffer"))
230 (article (make-symbol "gnus-setup-message-article"))
231 (group (make-symbol "gnus-setup-message-group")))
232 `(let ((,winconf (current-window-configuration))
233 (,buffer (buffer-name (current-buffer)))
234 (,article (and gnus-article-reply (gnus-summary-article-number)))
235 (,group gnus-newsgroup-name)
236 (message-header-setup-hook
237 (copy-sequence message-header-setup-hook))
238 (message-mode-hook (copy-sequence message-mode-hook))
239 (message-startup-parameter-alist
240 '((reply-buffer . gnus-copy-article-buffer)
241 (original-buffer . gnus-original-article-buffer)
242 (user-agent . Gnus))))
243 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
244 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
245 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
249 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
250 (setq gnus-message-buffer (current-buffer))
251 (set (make-local-variable 'gnus-message-group-art)
252 (cons ,group ,article))
253 (set (make-local-variable 'gnus-newsgroup-name) ,group)
254 (gnus-run-hooks 'gnus-message-setup-hook))
256 (gnus-configure-windows ,config t)
257 (set-buffer-modified-p nil))))
260 (defun gnus-msg-mail (&rest args)
261 "Start editing a mail message to be sent.
262 Like `message-mail', but with Gnus paraphernalia, particularly the
263 Gcc: header for archiving purposes."
265 (gnus-setup-message 'message
266 (apply 'message-mail args))
267 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
271 (define-mail-user-agent 'gnus-user-agent
272 'gnus-msg-mail 'message-send-and-exit
273 'message-kill-buffer 'message-send-hook)
275 (defun gnus-setup-posting-charset (group)
276 (let ((alist gnus-group-posting-charset-alist)
277 (group (or group ""))
281 (while (setq elem (pop alist))
282 (when (or (and (stringp (car elem))
283 (string-match (car elem) group))
284 (and (gnus-functionp (car elem))
285 (funcall (car elem) group))
286 (and (symbolp (car elem))
287 (symbol-value (car elem))))
288 (throw 'found (cons (cadr elem) (caddr elem)))))))))
290 (defun gnus-inews-add-send-actions (winconf buffer article)
291 (make-local-hook 'message-sent-hook)
292 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
293 'gnus-inews-do-gcc) nil t)
295 (make-local-hook 'message-header-hook)
296 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
297 (setq message-post-method
299 (gnus-post-method arg ,gnus-newsgroup-name)))
300 (setq message-user-agent (gnus-extended-version))
301 (when (not message-use-multi-frames)
303 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
305 `(when (gnus-buffer-exists-p ,buffer)
309 `(gnus-summary-mark-article-as-replied ,article))))
312 (put 'gnus-setup-message 'lisp-indent-function 1)
313 (put 'gnus-setup-message 'edebug-form-spec '(form body))
315 ;;; Post news commands of Gnus group mode and summary mode
317 (defun gnus-group-mail (&optional arg)
318 "Start composing a mail.
319 If ARG, use the group under the point to find a posting style.
320 If ARG is 1, prompt for a group name to find the posting style."
322 ;; We can't `let' gnus-newsgroup-name here, since that leads
323 ;; to local variables leaking.
324 (let ((group gnus-newsgroup-name)
325 (buffer (current-buffer)))
328 (setq gnus-newsgroup-name
330 (if (= 1 (prefix-numeric-value arg))
331 (completing-read "Use posting style of group: "
332 gnus-active-hashtb nil
333 (gnus-read-active-file-p))
334 (gnus-group-group-name))
336 (gnus-setup-message 'message (message-mail)))
339 (setq gnus-newsgroup-name group)))))
341 (defun gnus-group-post-news (&optional arg)
342 "Start composing a news message.
343 If ARG, post to the group under point.
344 If ARG is 1, prompt for a group name."
346 ;; Bind this variable here to make message mode hooks work ok.
347 (let ((gnus-newsgroup-name
349 (if (= 1 (prefix-numeric-value arg))
350 (completing-read "Newsgroup: " gnus-active-hashtb nil
351 (gnus-read-active-file-p))
352 (gnus-group-group-name))
354 (gnus-post-news 'post gnus-newsgroup-name)))
356 (defun gnus-summary-post-news ()
357 "Start composing a news message."
359 (gnus-post-news 'post gnus-newsgroup-name))
361 (defun gnus-summary-followup (yank &optional force-news)
362 "Compose a followup to an article.
363 If prefix argument YANK is non-nil, original article is yanked automatically."
365 (list (and current-prefix-arg
366 (gnus-summary-work-articles 1))))
368 (gnus-summary-goto-subject (car yank)))
369 (save-window-excursion
370 (gnus-summary-select-article))
371 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
372 (gnus-newsgroup-name gnus-newsgroup-name))
374 (gnus-post-news nil gnus-newsgroup-name
375 headers gnus-article-buffer
376 yank nil force-news)))
378 (defun gnus-summary-followup-with-original (n &optional force-news)
379 "Compose a followup to an article and include the original article."
381 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
383 (defun gnus-summary-followup-to-mail (&optional arg)
384 "Followup to the current mail message via news."
386 (list (and current-prefix-arg
387 (gnus-summary-work-articles 1))))
388 (gnus-summary-followup arg t))
390 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
391 "Followup to the current mail message via news."
393 (gnus-summary-followup (gnus-summary-work-articles arg) t))
395 (defun gnus-inews-yank-articles (articles)
396 (let* ((more-than-one (cdr articles))
397 (frame (when (and message-use-multi-frames more-than-one)
398 (window-frame (get-buffer-window (current-buffer)))))
401 (while (setq article (pop articles))
402 (save-window-excursion
403 (set-buffer gnus-summary-buffer)
404 (gnus-summary-select-article nil nil nil article)
405 (gnus-summary-remove-process-mark article))
407 (select-frame frame))
409 ;; Gathering references.
411 (setq refs (message-list-references
413 (mail-header-references gnus-current-headers)
414 (mail-header-message-id gnus-current-headers))))
416 (gnus-copy-article-buffer)
417 (let ((message-reply-buffer gnus-article-copy)
418 (message-reply-headers gnus-current-headers))
419 (message-yank-original)
420 (setq beg (or beg (mark t))))
425 ;; Replace with the gathered references.
429 (message-narrow-to-headers)
430 (let ((case-fold-search t))
431 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
433 (goto-char (point-max))))
435 (list (or (assq 'References message-header-format-alist)
436 '(References . message-shorten-references)))
437 (list (cons 'References
438 (mapconcat 'identity (nreverse refs) " "))))
439 (backward-delete-char 1))
445 (defun gnus-summary-cancel-article (&optional n symp)
446 "Cancel an article you posted.
447 Uses the process-prefix convention. If given the symbolic
448 prefix `a', cancel using the standard posting method; if not
449 post using the current select method."
450 (interactive (gnus-interactive "P\ny"))
451 (let ((articles (gnus-summary-work-articles n))
454 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
456 (while (setq article (pop articles))
457 (when (gnus-summary-select-article t nil nil article)
458 (when (gnus-eval-in-buffer-window gnus-article-buffer
460 (set-buffer gnus-original-article-buffer)
461 (message-cancel-news)))
462 (gnus-summary-mark-as-read article gnus-canceled-mark)
463 (gnus-cache-remove-article 1))
464 (gnus-article-hide-headers-if-wanted))
465 (gnus-summary-remove-process-mark article))))
467 (defun gnus-summary-supersede-article ()
468 "Compose an article that will supersede a previous article.
469 This is done simply by taking the old article and adding a Supersedes
470 header line with the old Message-ID."
472 (let ((article (gnus-summary-article-number))
473 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
474 (gnus-setup-message 'reply-yank
475 (gnus-summary-select-article t)
476 (set-buffer gnus-original-article-buffer)
480 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
482 (set-buffer ,gnus-summary-buffer)
483 (gnus-cache-possibly-remove-article ,article nil nil nil t)
484 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
485 message-send-actions))))
489 (defun gnus-copy-article-buffer (&optional article-buffer)
490 ;; make a copy of the article buffer with all text properties removed
491 ;; this copy is in the buffer gnus-article-copy.
492 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
493 ;; this buffer should be passed to all mail/news reply/post routines.
494 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
495 (let ((article-buffer (or article-buffer gnus-article-buffer))
497 (if (not (and (get-buffer article-buffer)
498 (gnus-buffer-exists-p article-buffer)))
499 (error "Can't find any article buffer")
501 (set-buffer article-buffer)
502 (let ((gnus-newsgroup-charset (or gnus-article-charset
503 gnus-newsgroup-charset))
504 (gnus-newsgroup-ignored-charsets
505 (or gnus-article-ignored-charsets
506 gnus-newsgroup-ignored-charsets)))
508 ;; Copy over the (displayed) article buffer, delete
509 ;; hidden text and remove text properties.
511 (let ((inhibit-read-only t))
512 (copy-to-buffer gnus-article-copy (point-min) (point-max))
513 (set-buffer gnus-article-copy)
514 ;; Encode bitmap smileys to ordinary text.
515 ;; Possibly, the original text might be restored.
516 (static-unless (featurep 'xemacs)
517 (when (featurep 'smiley-mule)
518 (smiley-encode-buffer)))
519 (gnus-article-delete-text-of-type 'annotation)
520 (gnus-remove-text-with-property 'gnus-prev)
521 (gnus-remove-text-with-property 'gnus-next)
522 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
525 (buffer-substring-no-properties (point-min) (point-max))
527 ;; Find the original headers.
528 (set-buffer gnus-original-article-buffer)
529 (goto-char (point-min))
530 (while (looking-at message-unix-mail-delimiter)
533 (setq end (or (search-forward "\n\n" nil t) (point)))
534 ;; Delete the headers from the displayed articles.
535 (set-buffer gnus-article-copy)
536 (delete-region (goto-char (point-min))
537 (or (search-forward "\n\n" nil t) (point-max)))
538 ;; Insert the original article headers.
539 (insert-buffer-substring gnus-original-article-buffer beg end)
540 (article-decode-encoded-words))))
543 (defun gnus-post-news (post &optional group header article-buffer yank subject
546 (gnus-copy-article-buffer))
547 (let ((gnus-article-reply article-buffer)
548 (add-to-list gnus-add-to-list))
549 (gnus-setup-message (cond (yank 'reply-yank)
550 (article-buffer 'reply)
552 (let* ((group (or group gnus-newsgroup-name))
553 (charset (gnus-group-name-charset nil group))
555 to-address to-group mailing-list to-list
558 (setq to-address (gnus-group-find-parameter group 'to-address)
559 to-group (gnus-group-find-parameter group 'to-group)
560 to-list (gnus-group-find-parameter group 'to-list)
561 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
562 mailing-list (when gnus-mailing-list-groups
563 (string-match gnus-mailing-list-groups group))
564 group (gnus-group-name-decode (gnus-group-real-name group)
566 (if (or (and to-group
567 (gnus-news-group-p to-group))
570 (and (gnus-news-group-p
571 (or pgroup gnus-newsgroup-name)
572 (if header (mail-header-number header)
573 gnus-current-article))
579 (message-news (or to-group group))
580 (set-buffer gnus-article-copy)
581 (gnus-msg-treat-broken-reply-to)
582 (message-followup (if (or newsgroup-p force-news) nil to-group)))
586 (message-mail (or to-address to-list))
587 ;; Arrange for mail groups that have no `to-address' to
588 ;; get that when the user sends off the mail.
589 (when (and (not to-list)
592 (push (list 'gnus-inews-add-to-address pgroup)
593 message-send-actions)))
594 (set-buffer gnus-article-copy)
595 (gnus-msg-treat-broken-reply-to)
596 (message-wide-reply to-address)))
598 (gnus-inews-yank-articles yank))))))
600 (defun gnus-msg-treat-broken-reply-to ()
601 "Remove the Reply-to header iff broken-reply-to."
602 (when (gnus-group-find-parameter
603 gnus-newsgroup-name 'broken-reply-to)
605 (message-narrow-to-head)
606 (message-remove-header "reply-to"))))
608 (defun gnus-post-method (arg group &optional silent)
609 "Return the posting method based on GROUP and ARG.
610 If SILENT, don't prompt the user."
611 (let ((group-method (gnus-find-method-for-group group)))
613 ;; If the group-method is nil (which shouldn't happen) we use
614 ;; the default method.
616 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
617 gnus-select-method message-post-method))
618 ;; We want the inverse of the default
619 ((and arg (not (eq arg 0)))
620 (if (eq gnus-post-method 'active)
623 ;; We query the user for a post method.
625 (and gnus-post-method
626 (not (eq gnus-post-method 'current))
627 (listp (car gnus-post-method))))
629 ;; Collect all methods we know about.
631 (when (and gnus-post-method
632 (not (eq gnus-post-method 'current)))
633 (if (listp (car gnus-post-method))
635 (list gnus-post-method)))
636 gnus-secondary-select-methods
637 (mapcar 'cdr gnus-server-alist)
638 (mapcar 'car gnus-opened-servers)
639 (list gnus-select-method)
640 (list group-method)))
641 method-alist post-methods method)
642 ;; Weed out all mail methods.
644 (setq method (gnus-server-get-method "" (pop methods)))
645 (when (and (or (gnus-method-option-p method 'post)
646 (gnus-method-option-p method 'post-mail))
647 (not (member method post-methods)))
648 (push method post-methods)))
649 ;; Create a name-method alist.
653 (if (equal (cadr m) "")
654 (list (symbol-name (car m)) m)
655 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
660 (setq gnus-last-posting-server
662 gnus-last-posting-server)
663 ;; Just use the last value.
664 gnus-last-posting-server
666 "Posting method: " method-alist nil t
667 (cons (or gnus-last-posting-server "") 0))))
669 ;; Override normal method.
670 ((and (eq gnus-post-method 'current)
671 (not (eq (car group-method) 'nndraft))
672 (gnus-get-function group-method 'request-post t)
675 ((and gnus-post-method
676 (not (eq gnus-post-method 'current)))
678 ;; Use the normal select method.
679 (t gnus-select-method))))
683 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
684 "Return user-agent info.
685 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
686 `mime-edit-user-agent-value' exists, the return value will include it.
687 MAX-COLUMN the optional second argument if it is specified, the return value
688 will be folded up in the proper way."
689 (let ((user-agent (if (and include-mime-info
690 (boundp 'mime-edit-user-agent-value))
691 (concat (gnus-extended-version)
693 mime-edit-user-agent-value)
694 (gnus-extended-version))))
697 (unless (natnump max-column) (setq max-column 76))
699 (insert " " user-agent)
701 (while (re-search-forward "[\n\t ]+" nil t)
704 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
705 (while (eq ?\( (char-after (point)))
707 (skip-chars-forward " "))
708 (skip-chars-backward " ")
709 (if (> (current-column) max-column)
711 (if (or (not boundary) (eq ?\n (char-after boundary)))
713 (setq boundary (point))
720 (setq boundary (point))))
721 (buffer-substring 13 (point-max))))
726 ;;; Gnus Mail Functions
729 ;;; Mail reply commands of Gnus summary mode
731 (defun gnus-summary-reply (&optional yank wide)
732 "Start composing a reply mail to the current message.
733 If prefix argument YANK is non-nil, the original article is yanked
736 (list (and current-prefix-arg
737 (gnus-summary-work-articles 1))))
738 ;; Stripping headers should be specified with mail-yank-ignored-headers.
740 (gnus-summary-goto-subject (car yank)))
741 (let ((gnus-article-reply t))
742 (gnus-setup-message (if yank 'reply-yank 'reply)
743 (gnus-summary-select-article)
744 (set-buffer (gnus-copy-article-buffer))
745 (gnus-msg-treat-broken-reply-to)
746 (message-reply nil wide)
748 (gnus-inews-yank-articles yank)))))
750 (defun gnus-summary-reply-with-original (n &optional wide)
751 "Start composing a reply mail to the current message.
752 The original article will be yanked."
754 (gnus-summary-reply (gnus-summary-work-articles n) wide))
756 (defun gnus-summary-wide-reply (&optional yank)
757 "Start composing a wide reply mail to the current message.
758 If prefix argument YANK is non-nil, the original article is yanked
761 (list (and current-prefix-arg
762 (gnus-summary-work-articles 1))))
763 (gnus-summary-reply yank t))
765 (defun gnus-summary-wide-reply-with-original (n)
766 "Start composing a wide reply mail to the current message.
767 The original article will be yanked."
769 (gnus-summary-reply-with-original n t))
771 (defun gnus-summary-mail-forward (&optional full-headers post)
772 "Forward the current message to another user.
773 If FULL-HEADERS (the prefix), include full headers when forwarding."
775 (gnus-setup-message 'forward
776 (gnus-summary-select-article)
777 (let ((charset default-mime-charset))
778 (set-buffer gnus-original-article-buffer)
779 (make-local-variable 'default-mime-charset)
780 (setq default-mime-charset charset))
781 (let ((message-included-forward-headers
782 (if full-headers "" message-included-forward-headers)))
783 (message-forward post))))
785 ;;;;; XXX: generate Subject and ``Topics''?
786 ;;(defun gnus-summary-mail-digest (&optional n post)
787 ;; "Digests and forwards all articles in this series."
789 ;; (let ((subject "Digested Articles")
790 ;; (articles (gnus-summary-work-articles n))
792 ;; (gnus-setup-message 'forward
793 ;; (gnus-summary-select-article)
794 ;; (if post (message-news nil subject) (message-mail nil subject))
795 ;; (when (and message-use-multi-frames (cdr articles))
796 ;; (setq frame (window-frame (get-buffer-window (current-buffer)))))
797 ;; (message-goto-body)
798 ;; (while (setq article (pop articles))
799 ;; (save-window-excursion
800 ;; (set-buffer gnus-summary-buffer)
801 ;; (gnus-summary-select-article nil nil nil article)
802 ;; (gnus-summary-remove-process-mark article))
804 ;; (select-frame frame))
805 ;; (insert (mime-make-tag "message" "rfc822") "\n")
806 ;; (insert-buffer-substring gnus-original-article-buffer))
808 ;; (message-goto-body)
809 ;; (mime-edit-enclose-digest-region (point)(mark t)))))
811 ;;(defun gnus-summary-post-digest (&optional n)
812 ;; "Digest and forwards all articles in this series to a newsgroup."
814 ;; (gnus-summary-mail-digest n t))
816 (defun gnus-summary-resend-message (address n)
817 "Resend the current article to ADDRESS."
818 (interactive "sResend message(s) to: \nP")
819 (let ((articles (gnus-summary-work-articles n))
821 (while (setq article (pop articles))
822 (gnus-summary-select-article nil nil nil article)
824 (set-buffer gnus-original-article-buffer)
825 (message-resend address)))))
827 (defun gnus-summary-post-forward (&optional full-headers)
828 "Forward the current article to a newsgroup.
829 If FULL-HEADERS (the prefix), include full headers when forwarding."
831 (gnus-summary-mail-forward full-headers t))
833 (defvar gnus-nastygram-message
834 "The following article was inappropriately posted to %s.\n\n"
835 "Format string to insert in nastygrams.
836 The current group name will be inserted at \"%s\".")
838 (defun gnus-summary-mail-nastygram (n)
839 "Send a nastygram to the author of the current article."
841 (when (or gnus-expert-user
843 "Really send a nastygram to the author of the current article? "))
844 (let ((group gnus-newsgroup-name))
845 (gnus-summary-reply-with-original n)
846 (set-buffer gnus-message-buffer)
848 (insert (format gnus-nastygram-message group))
849 (message-send-and-exit))))
851 (defun gnus-summary-mail-crosspost-complaint (n)
852 "Send a complaint about crossposting to the current article(s)."
854 (let ((articles (gnus-summary-work-articles n))
856 (while (setq article (pop articles))
857 (set-buffer gnus-summary-buffer)
858 (gnus-summary-goto-subject article)
859 (let ((group (gnus-group-real-name gnus-newsgroup-name))
860 newsgroups followup-to)
861 (gnus-summary-select-article)
862 (set-buffer gnus-original-article-buffer)
863 (if (and (<= (length (message-tokenize-header
865 (mail-fetch-field "newsgroups"))
868 (or (not (setq followup-to (mail-fetch-field "followup-to")))
869 (not (member group (message-tokenize-header
870 followup-to ", ")))))
872 (gnus-message 1 "Followup-to restricted")
873 (gnus-message 1 "Not a crossposted article"))
874 (set-buffer gnus-summary-buffer)
875 (gnus-summary-reply-with-original 1)
876 (set-buffer gnus-message-buffer)
878 (insert (format gnus-crosspost-complaint newsgroups group))
879 (message-goto-subject)
880 (re-search-forward " *$")
881 (replace-match " (crosspost notification)" t t)
882 (gnus-deactivate-mark)
883 (when (gnus-y-or-n-p "Send this complaint? ")
884 (message-send-and-exit)))))))
886 (defun gnus-summary-mail-other-window ()
887 "Compose mail in other window."
889 (gnus-setup-message 'message
892 (defun gnus-mail-parse-comma-list ()
895 (skip-chars-forward " ")
898 (skip-chars-forward "^,")
903 (narrow-to-region beg (point))
906 (while (search-forward "\"" nil t)
910 (skip-chars-forward ",")
911 (skip-chars-forward "^,"))
912 (skip-chars-backward " ")
913 (push (buffer-substring beg (point))
915 (skip-chars-forward "^,")
916 (skip-chars-forward ", "))
919 (defun gnus-inews-add-to-address (group)
920 (let ((to-address (mail-fetch-field "to")))
921 (when (and to-address
923 ;; This mail group doesn't have a `to-list', so we add one
926 (format "Do you want to add this as `to-list': %s " to-address))
927 (gnus-group-add-parameter group (cons 'to-list to-address))))))
929 (defun gnus-put-message ()
930 "Put the current message in some group and return to Gnus."
932 (let ((reply gnus-article-reply)
933 (winconf gnus-prev-winconf)
934 (group gnus-newsgroup-name))
936 (or (and group (not (gnus-group-read-only-p group)))
937 (setq group (read-string "Put in group: " nil
938 (gnus-writable-groups))))
939 (when (gnus-gethash group gnus-newsrc-hashtb)
940 (error "No such group: %s" group))
945 (message-narrow-to-headers)
946 (let (gnus-deletable-headers)
948 (message-generate-headers message-required-news-headers)
949 (message-generate-headers message-required-mail-headers)))
950 (goto-char (point-max))
951 (insert "Gcc: " group "\n")
956 (when (get-buffer gnus-group-buffer)
957 (when (gnus-buffer-exists-p (car-safe reply))
958 (set-buffer (car reply))
960 (gnus-summary-mark-article-as-replied
963 (set-window-configuration winconf)))))
965 (defun gnus-article-mail (yank)
966 "Send a reply to the address near point.
967 If YANK is non-nil, include the original article."
971 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
972 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
974 (message-reply address)
976 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
978 (defvar nntp-server-type)
980 "Send a bug report to the Gnus maintainers."
982 (unless (gnus-alive-p)
983 (error "Gnus has been shut down"))
984 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
985 (unless (message-mail-user-agent)
986 (delete-other-windows)
987 (when gnus-bug-create-help-buffer
988 (switch-to-buffer "*Gnus Help Bug*")
990 (insert gnus-bug-message)
991 (goto-char (point-min)))
992 (message-pop-to-buffer "*Gnus Bug*"))
993 (let ((message-this-is-mail t))
994 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
995 (when gnus-bug-create-help-buffer
996 (push `(gnus-bug-kill-buffer) message-send-actions))
997 (goto-char (point-min))
998 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1000 (insert gnus-product-name " " gnus-version-number
1001 " (r" gnus-revision-number ") "
1002 "based on " gnus-original-product-name " v"
1003 gnus-original-version-number "\n"
1004 (emacs-version) "\n")
1005 (when (and (boundp 'nntp-server-type)
1006 (stringp nntp-server-type))
1007 (insert nntp-server-type))
1008 (insert "\n\n\n\n\n")
1009 (let (mime-content-types)
1010 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
1011 (insert (with-temp-buffer
1014 (let (mime-content-types)
1015 (mime-edit-insert-tag "text" "plain"))
1016 (goto-char (point-min))
1017 (search-forward "Subject: " nil t)
1020 (defun gnus-bug-kill-buffer ()
1021 (when (get-buffer "*Gnus Help Bug*")
1022 (kill-buffer "*Gnus Help Bug*")))
1024 (defun gnus-summary-yank-message (buffer n)
1025 "Yank the current article into a composed message."
1027 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1028 current-prefix-arg))
1029 (when (gnus-buffer-live-p buffer)
1030 (let ((summary-frame (selected-frame))
1031 (message-frame (when (static-if (featurep 'xemacs)
1032 (device-on-window-system-p)
1034 (let ((window (get-buffer-window buffer t)))
1036 (window-frame window)))))
1037 (separator (concat "^" (regexp-quote mail-header-separator)
1039 (gnus-summary-iterate n
1040 (gnus-summary-select-article)
1041 (gnus-copy-article-buffer)
1042 (when (frame-live-p message-frame)
1043 (raise-frame message-frame)
1044 (select-frame message-frame))
1045 (with-current-buffer buffer
1046 (when (save-excursion
1048 (let (case-fold-search)
1049 (and (not (re-search-backward separator nil t))
1050 (re-search-forward separator nil t))))
1051 (goto-char (match-end 0)))
1052 (message-yank-buffer gnus-article-copy))
1053 (select-frame summary-frame))
1054 (when (frame-live-p message-frame)
1055 (select-frame message-frame)))))
1057 (defun gnus-debug ()
1058 "Attempts to go through the Gnus source file and report what variables have been changed.
1059 The source file has to be in the Emacs load path."
1061 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1062 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1063 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1064 "nnmail.el" "nntp.el" "message.el"))
1066 file expr olist sym)
1067 (gnus-message 4 "Please wait while we snoop your variables...")
1069 ;; Go through all the files looking for non-default values for variables.
1071 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1074 (when (and (setq file (locate-library (pop files)))
1075 (file-exists-p file))
1076 (insert-file-contents file)
1077 (goto-char (point-min))
1078 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1079 (gnus-message 4 "Malformed sources in file %s" file)
1080 (narrow-to-region (point-min) (point))
1081 (goto-char (point-min))
1082 (while (setq expr (ignore-errors (read (current-buffer))))
1084 (and (memq (car expr) '(defvar defcustom defvoo))
1085 (stringp (nth 3 expr))
1086 (or (not (boundp (nth 1 expr)))
1087 (not (equal (eval (nth 2 expr))
1088 (symbol-value (nth 1 expr)))))
1089 (push (nth 1 expr) olist)))))))
1090 (kill-buffer (current-buffer)))
1091 (when (setq olist (nreverse olist))
1092 (insert ";----------------- Environment follows ------------------\n\n"))
1094 (if (boundp (car olist))
1096 (pp `(setq ,(car olist)
1097 ,(if (or (consp (setq sym (symbol-value (car olist))))
1099 (not (or (eq sym nil)
1101 (list 'quote (symbol-value (car olist)))
1102 (symbol-value (car olist))))
1105 (format "(setq %s 'whatever)\n" (car olist))))
1106 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1107 (setq olist (cdr olist)))
1108 ;; Remove any control chars - they seem to cause trouble for some
1109 ;; mailers. (Byte-compiled output from the stuff above.)
1111 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1112 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1114 ;; Break MIME tags purposely.
1116 (while (re-search-forward mime-edit-tag-regexp nil t)
1117 (goto-char (1+ (match-beginning 0)))
1120 ;;; Treatment of rejected articles.
1123 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1124 "Re-mail the current message.
1125 This only makes sense if the current message is a bounce message than
1126 contains some mail you have written which has been bounced back to
1128 If FETCH, try to fetch the article that this is a reply to, if indeed
1131 (gnus-summary-select-article t)
1132 (set-buffer gnus-original-article-buffer)
1133 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1134 (gnus-setup-message 'compose-bounce
1135 (let* ((references (mail-fetch-field "references"))
1136 (parent (and references (gnus-parent-id references))))
1138 ;; If there are references, we fetch the article we answered to.
1140 (gnus-summary-refer-article parent)
1141 (gnus-summary-show-all-headers))))))
1145 (defun gnus-inews-group-method (group)
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))))
1160 ;; Do Gcc handling, which copied the message over to some group.
1161 (defun gnus-inews-do-gcc (&optional gcc)
1163 (when (gnus-alive-p)
1166 (message-narrow-to-headers)
1167 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1168 (coding-system-for-write 'raw-text)
1169 (output-coding-system 'raw-text)
1170 groups group method group-art)
1172 (message-remove-header "gcc")
1174 (setq groups (message-unquote-tokens
1175 (message-tokenize-header gcc " ,")))
1176 ;; Copy the article over to some group(s).
1177 (while (setq group (pop groups))
1179 (setq method (gnus-inews-group-method group)))
1180 (unless (gnus-request-group group t method)
1181 (gnus-request-create-group group method))
1183 (nnheader-set-temp-buffer " *acc*")
1184 (insert-buffer-substring message-encoding-buffer)
1185 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1186 (goto-char (point-min))
1187 (when (re-search-forward
1188 (concat "^" (regexp-quote mail-header-separator) "$")
1190 (replace-match "" t t ))
1191 (unless (setq group-art
1192 (gnus-request-accept-article group method t t))
1193 (gnus-message 1 "Couldn't store article in group %s: %s"
1194 group (gnus-status-message method))
1196 (when (and group-art gnus-inews-mark-gcc-as-read)
1197 (let ((active (gnus-active group)))
1199 (if (< (cdr active) (cdr group-art))
1200 (gnus-set-active group (cons (car active)
1202 (gnus-activate-group group)))
1203 (let ((buffer (concat "*Summary " group "*"))
1204 (mark gnus-read-mark)
1205 (article (cdr group-art)))
1209 (with-current-buffer buffer
1210 (when gnus-newsgroup-prepared
1211 (when (and gnus-newsgroup-auto-expire
1212 (memq mark gnus-auto-expirable-marks))
1213 (setq mark gnus-expirable-mark))
1214 (setq mark (gnus-request-update-mark
1215 group article mark))
1216 (gnus-mark-article-as-read article mark)
1217 (setq gnus-newsgroup-active (gnus-active group))
1219 (gnus-group-make-articles-read group
1221 (when (gnus-group-auto-expirable-p group)
1222 (gnus-add-marked-articles
1223 group 'expire (list article))))))
1224 (kill-buffer (current-buffer))))))))))
1226 (defun gnus-inews-insert-gcc ()
1227 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1230 (message-narrow-to-headers)
1231 (let* ((group gnus-outgoing-message-group)
1233 ((gnus-functionp group)
1235 ((or (stringp group) (list group))
1239 (if (stringp gcc) gcc
1240 (mapconcat 'identity gcc " "))
1243 (defun gnus-inews-insert-archive-gcc (&optional group)
1244 "Insert the Gcc to say where the article is to be archived."
1245 (let* ((var gnus-message-archive-group)
1246 (group (or group gnus-newsgroup-name ""))
1248 (and gnus-newsgroup-name
1249 (not (equal gnus-newsgroup-name ""))
1250 (gnus-group-find-parameter
1251 gnus-newsgroup-name 'gcc-self)))
1255 ((null gnus-message-archive-method)
1259 ;; Just a single group.
1262 ;; We don't want this.
1264 ((and (listp var) (stringp (car var)))
1265 ;; A list of groups.
1267 ((gnus-functionp var)
1269 (funcall var group))
1271 ;; An alist of regexps/functions/forms.
1276 ((stringp (caar var))
1278 (when (string-match (caar var) group)
1280 ((gnus-functionp (car var))
1282 (funcall (car var) group))
1284 (eval (car var)))))))
1285 (setq var (cdr var)))
1288 (when (or groups gcc-self-val)
1289 (when (stringp groups)
1290 (setq groups (list groups)))
1293 (message-narrow-to-headers)
1294 (goto-char (point-max))
1297 ;; Use the `gcc-self' param value instead.
1300 (if (stringp gcc-self-val)
1303 (if (not (eq gcc-self-val 'none))
1308 ;; Use the list of groups.
1309 (while (setq name (pop groups))
1310 (insert (if (string-match ":" name)
1312 (gnus-group-prefixed-name
1313 name gnus-message-archive-method)))
1320 (defun gnus-configure-posting-styles ()
1321 "Configure posting styles according to `gnus-posting-styles'."
1322 (unless gnus-inhibit-posting-styles
1323 (let ((group (or gnus-newsgroup-name ""))
1324 (styles gnus-posting-styles)
1325 style match variable attribute value v results
1326 filep name address element)
1327 ;; If the group has a posting-style parameter, add it at the end with a
1328 ;; regexp matching everything, to be sure it takes precedence over all
1330 (when gnus-newsgroup-name
1331 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1333 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1334 ;; Go through all styles and look for matches.
1335 (dolist (style styles)
1336 (setq match (pop style))
1337 (goto-char (point-min))
1340 ;; Regexp string match on the group name.
1341 (string-match match group))
1343 (let ((header (message-fetch-field (pop style))))
1345 (string-match (pop style) header))))
1346 ((or (symbolp match)
1347 (gnus-functionp match))
1349 ((gnus-functionp match)
1350 ;; Function to be called.
1353 ;; Variable to be checked.
1354 (symbol-value match))))
1356 ;; This is a form to be evaled.
1358 ;; We have a match, so we set the variables.
1359 (dolist (attribute style)
1360 (setq element (pop attribute)
1365 ((eq (car attribute) ':file)
1368 ((eq (car attribute) :value)
1372 ;; We get the value.
1377 ((or (symbolp value)
1378 (gnus-functionp value))
1379 (cond ((gnus-functionp value)
1382 (symbol-value value))))
1385 ;; Translate obsolescent value.
1386 (when (eq element 'signature-file)
1387 (setq element 'signature
1389 ;; Get the contents of file elems.
1391 (setq v (with-temp-buffer
1392 (insert-file-contents v)
1394 (setq results (delq (assoc element results) results))
1395 (push (cons element v) results))))
1396 ;; Now we have all the styles, so we insert them.
1397 (setq name (assq 'name results)
1398 address (assq 'address results))
1399 (setq results (delq name (delq address results)))
1400 (make-local-variable 'message-setup-hook)
1401 (dolist (result results)
1402 (add-hook 'message-setup-hook
1404 ((eq 'eval (car result))
1406 ((eq 'body (car result))
1410 (insert ,(cdr result)))))
1411 ((eq 'signature (car result))
1412 (set (make-local-variable 'message-signature) nil)
1413 (set (make-local-variable 'message-signature-file) nil)
1414 (if (not (cdr result))
1418 (let ((message-signature ,(cdr result)))
1419 (when message-signature
1420 (message-insert-signature)))))))
1423 (if (symbolp (car result))
1424 (capitalize (symbol-name (car result)))
1428 (message-remove-header ,header)
1429 (let ((value ,(cdr result)))
1432 (insert ,header ": " value "\n"))))))))))
1433 (when (or name address)
1434 (add-hook 'message-setup-hook
1436 (set (make-local-variable 'user-mail-address)
1437 ,(or (cdr address) user-mail-address))
1438 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1440 ,(or (cdr address) user-mail-address)))
1442 (message-remove-header "From")
1444 (insert "From: " (message-make-from) "\n")))))))))
1447 ;;; @ for MIME Edit mode
1450 (defun gnus-maybe-setup-default-charset ()
1452 (and (boundp 'gnus-summary-buffer)
1453 (buffer-live-p gnus-summary-buffer)
1455 (set-buffer gnus-summary-buffer)
1456 default-mime-charset))))
1459 (make-local-variable 'default-mime-charset)
1460 (setq default-mime-charset charset)
1464 ;;; @ for MIME view mode
1467 (defun gnus-following-method (buf)
1468 (gnus-setup-message 'reply-yank
1470 (if (message-news-p)
1472 (message-reply nil 'wide))
1473 (let ((message-reply-buffer buf))
1474 (message-yank-original))
1475 (message-goto-body))
1479 ;;; Allow redefinition of functions.
1485 ;;; gnus-msg.el ends here