1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
37 (defcustom gnus-post-method 'current
38 "*Preferred method for posting USENET news.
40 If this variable is `current' (which is the default), Gnus will use
41 the \"current\" select method when posting. If it is nil, Gnus will
42 use the native select method when posting.
44 This method will not be used in mail groups and the like, only in
47 If not nil nor `native', the value must be a valid method as discussed
48 in the documentation of `gnus-select-method'. It can also be a list of
49 methods. If that is the case, the user will be queried for what select
50 method to use when posting."
51 :group 'gnus-group-foreign
52 :type `(choice (const nil)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defvar gnus-outgoing-message-group nil
58 "*All outgoing messages will be put in this group.
59 If you want to store all your outgoing mail and articles in the group
60 \"nnml:archive\", you set this variable to that value. This variable
61 can also be a list of group names.
63 If you want to have greater control over what group to put each
64 message in, you can set this variable to a function that checks the
65 current newsgroup name and then returns a suitable group name (or list
68 (defvar gnus-mailing-list-groups nil
69 "*Regexp matching groups that are really mailing lists.
70 This is useful when you're reading a mailing list that has been
71 gatewayed to a newsgroup, and you want to followup to an article in
74 (defvar gnus-add-to-list nil
75 "*If non-nil, add a `to-list' parameter automatically.")
77 (defvar gnus-crosspost-complaint
80 You posted the article below with the following Newsgroups header:
84 The %s group, at least, was an inappropriate recipient
85 of this message. Please trim your Newsgroups header to exclude this
86 group before posting in the future.
91 "Format string to be inserted when complaining about crossposts.
92 The first %s will be replaced by the Newsgroups header;
93 the second with the current group name.")
95 (defvar gnus-message-setup-hook nil
96 "Hook run after setting up a message buffer.")
98 (defvar gnus-bug-create-help-buffer t
99 "*Should we create the *Gnus Help Bug* buffer?")
101 (defvar gnus-posting-styles nil
102 "*Alist of styles to use when posting.")
104 (defvar gnus-inews-mark-gcc-as-read nil
105 "If non-nil, automatically mark Gcc articles as read.")
107 (defcustom gnus-group-posting-charset-alist
108 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
109 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
110 (message-this-is-mail nil nil)
111 (message-this-is-news nil t))
112 "Alist of regexps and permitted unencoded charsets for posting.
113 Each element of the alist has the form (TEST HEADER BODY-LIST), where
114 TEST is either a regular expression matching the newsgroup header or a
116 HEADER is the charset which may be left unencoded in the header (nil
117 means encode all charsets),
118 BODY-LIST is a list of charsets which may be encoded using 8bit
119 content-transfer encoding in the body, or one of the special values
120 nil (always encode using quoted-printable) or t (always use 8bit).
122 Note that any value other than nil for HEADER infringes some RFCs, so
123 use this option with care."
124 :type '(repeat (list :tag "Permitted unencoded charsets"
126 (regexp :tag "Group")
127 (const :tag "Mail message" :value message-this-is-mail)
128 (const :tag "News article" :value message-this-is-news))
129 (choice :tag "Header"
130 (const :tag "None" nil)
131 (symbol :tag "Charset"))
133 (const :tag "Any" :value t)
134 (const :tag "None" :value nil)
135 (repeat :tag "Charsets"
136 (symbol :tag "Charset")))))
137 :group 'gnus-charset)
139 ;;; Internal variables.
141 (defvar gnus-inhibit-posting-styles nil
142 "Inhibit the use of posting styles.")
144 (defvar gnus-message-buffer "*Mail Gnus*")
145 (defvar gnus-article-copy nil)
146 (defvar gnus-check-before-posting nil)
147 (defvar gnus-last-posting-server nil)
148 (defvar gnus-message-group-art nil)
150 (defvar gnus-msg-force-broken-reply-to nil)
152 (defconst gnus-bug-message
153 "Sending a bug report to the Gnus Towers.
154 ========================================
156 The buffer below is a mail buffer. When you press `C-c C-c', it will
157 be sent to the Gnus Bug Exterminators.
159 The thing near the bottom of the buffer is how the environment
160 settings will be included in the mail. Please do not delete that.
161 They will tell the Bug People what your environment is, so that it
162 will be easier to locate the bugs.
164 If you have found a bug that makes Emacs go \"beep\", set
165 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
166 and include the backtrace in your bug report.
168 Please describe the bug in annoying, painstaking detail.
170 Thank you for your help in stamping out bugs.
174 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
175 (autoload 'news-setup "rnewspost")
176 (autoload 'news-reply-mode "rnewspost")
177 (autoload 'rmail-dont-reply-to "mail-utils")
178 (autoload 'rmail-output "rmailout"))
182 ;;; Gnus Posting Functions
185 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
186 "p" gnus-summary-post-news
187 "f" gnus-summary-followup
188 "F" gnus-summary-followup-with-original
189 "c" gnus-summary-cancel-article
190 "s" gnus-summary-supersede-article
191 "r" gnus-summary-reply
192 "y" gnus-summary-yank-message
193 "R" gnus-summary-reply-with-original
194 "w" gnus-summary-wide-reply
195 "W" gnus-summary-wide-reply-with-original
196 "v" gnus-summary-very-wide-reply
197 "W" gnus-summary-very-wide-reply-with-original
198 "n" gnus-summary-followup-to-mail
199 "N" gnus-summary-followup-to-mail-with-original
200 "m" gnus-summary-mail-other-window
201 "u" gnus-uu-post-news
202 "\M-c" gnus-summary-mail-crosspost-complaint
203 "Br" gnus-summary-reply-broken-reply-to
204 "BR" gnus-summary-reply-broken-reply-to-with-original
205 "om" gnus-summary-mail-forward
206 "op" gnus-summary-post-forward
207 "Om" gnus-uu-digest-mail-forward
208 "Op" gnus-uu-digest-post-forward)
210 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
211 "b" gnus-summary-resend-bounced-mail
212 ;; "c" gnus-summary-send-draft
213 "r" gnus-summary-resend-message)
215 ;;; Internal functions.
217 (defvar gnus-article-reply nil)
218 (defmacro gnus-setup-message (config &rest forms)
219 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
220 (buffer (make-symbol "gnus-setup-message-buffer"))
221 (article (make-symbol "gnus-setup-message-article"))
222 (group (make-symbol "gnus-setup-message-group")))
223 `(let ((,winconf (current-window-configuration))
224 (,buffer (buffer-name (current-buffer)))
225 (,article gnus-article-reply)
226 (,group gnus-newsgroup-name)
227 (message-header-setup-hook
228 (copy-sequence message-header-setup-hook))
229 (mbl mml-buffer-list)
230 (message-mode-hook (copy-sequence message-mode-hook)))
231 (setq mml-buffer-list nil)
232 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
233 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
234 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
238 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
239 (gnus-inews-insert-draft-meta-information ,group ,article)
240 (setq gnus-message-buffer (current-buffer))
241 (set (make-local-variable 'gnus-message-group-art)
242 (cons ,group ,article))
243 (set (make-local-variable 'gnus-newsgroup-name) ,group)
244 (gnus-run-hooks 'gnus-message-setup-hook)
245 (if (eq major-mode 'message-mode)
246 (let ((mbl1 mml-buffer-list))
247 (setq mml-buffer-list mbl) ;; Global value
248 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
249 ;; LOCAL argument of add-hook differs between GNU Emacs
250 ;; and XEmacs. make-local-hook makes sure they are local.
251 (make-local-hook 'kill-buffer-hook)
252 (make-local-hook 'change-major-mode-hook)
253 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
254 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
255 (mml-destroy-buffers)
256 (setq mml-buffer-list mbl)))
258 (gnus-configure-windows ,config t)
259 (set-buffer-modified-p nil))))
261 (defun gnus-inews-insert-draft-meta-information (group article)
264 (not (string= group ""))
265 (not (message-fetch-field gnus-draft-meta-information-header)))
266 (goto-char (point-min))
267 (insert gnus-draft-meta-information-header ": (\"" group "\" "
268 (if article (number-to-string
275 (defun gnus-msg-mail (&optional to subject other-headers continue
276 switch-action yank-action send-actions)
277 "Start editing a mail message to be sent.
278 Like `message-mail', but with Gnus paraphernalia, particularly the
279 Gcc: header for archiving purposes."
281 (let ((buf (current-buffer))
283 (gnus-setup-message 'message
284 (message-mail to subject other-headers continue
285 nil yank-action send-actions))
287 (setq mail-buf (current-buffer))
288 (switch-to-buffer buf)
289 (apply switch-action mail-buf nil)))
290 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
294 (defun gnus-button-mailto (address)
296 (set-buffer (gnus-copy-article-buffer))
297 (gnus-setup-message 'message
298 (message-reply address)))
301 (defun gnus-button-reply (&optional to-address wide)
302 "Like `message-reply'."
304 (gnus-setup-message 'message
305 (message-reply to-address wide)))
308 (define-mail-user-agent 'gnus-user-agent
309 'gnus-msg-mail 'message-send-and-exit
310 'message-kill-buffer 'message-send-hook)
312 (defun gnus-setup-posting-charset (group)
313 (let ((alist gnus-group-posting-charset-alist)
314 (group (or group ""))
318 (while (setq elem (pop alist))
319 (when (or (and (stringp (car elem))
320 (string-match (car elem) group))
321 (and (gnus-functionp (car elem))
322 (funcall (car elem) group))
323 (and (symbolp (car elem))
324 (symbol-value (car elem))))
325 (throw 'found (cons (cadr elem) (caddr elem)))))))))
327 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
328 (make-local-hook 'message-sent-hook)
329 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
330 'gnus-inews-do-gcc) nil t)
332 (make-local-hook 'message-header-hook)
333 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
334 (setq message-post-method
336 (gnus-post-method arg ,gnus-newsgroup-name)))
337 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
339 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
341 `(when (gnus-buffer-exists-p ,buffer)
345 (if (eq config 'forward)
346 `(gnus-summary-mark-article-as-forwarded ',article)
347 `(gnus-summary-mark-article-as-replied ',article)))))
350 (put 'gnus-setup-message 'lisp-indent-function 1)
351 (put 'gnus-setup-message 'edebug-form-spec '(form body))
353 ;;; Post news commands of Gnus group mode and summary mode
355 (defun gnus-group-mail (&optional arg)
356 "Start composing a mail.
357 If ARG, use the group under the point to find a posting style.
358 If ARG is 1, prompt for a group name to find the posting style."
360 ;; We can't `let' gnus-newsgroup-name here, since that leads
361 ;; to local variables leaking.
362 (let ((group gnus-newsgroup-name)
363 (buffer (current-buffer)))
366 (setq gnus-newsgroup-name
368 (if (= 1 (prefix-numeric-value arg))
369 (completing-read "Use posting style of group: "
370 gnus-active-hashtb nil
371 (gnus-read-active-file-p))
372 (gnus-group-group-name))
374 (gnus-setup-message 'message (message-mail)))
377 (setq gnus-newsgroup-name group)))))
379 (defun gnus-group-post-news (&optional arg)
380 "Start composing a news message.
381 If ARG, post to the group under point.
382 If ARG is 1, prompt for a group name."
384 ;; Bind this variable here to make message mode hooks work ok.
385 (let ((gnus-newsgroup-name
387 (if (= 1 (prefix-numeric-value arg))
388 (completing-read "Newsgroup: " gnus-active-hashtb nil
389 (gnus-read-active-file-p))
390 (gnus-group-group-name))
392 (gnus-post-news 'post gnus-newsgroup-name)))
394 (defun gnus-summary-post-news ()
395 "Start composing a news message."
397 (gnus-post-news 'post gnus-newsgroup-name))
399 (defun gnus-summary-followup (yank &optional force-news)
400 "Compose a followup to an article.
401 If prefix argument YANK is non-nil, original article is yanked automatically."
403 (list (and current-prefix-arg
404 (gnus-summary-work-articles 1))))
406 (gnus-summary-goto-subject (car yank)))
407 (save-window-excursion
408 (gnus-summary-select-article))
409 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
410 (gnus-newsgroup-name gnus-newsgroup-name))
412 (gnus-post-news nil gnus-newsgroup-name
413 headers gnus-article-buffer
414 yank nil force-news)))
416 (defun gnus-summary-followup-with-original (n &optional force-news)
417 "Compose a followup to an article and include the original article."
419 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
421 (defun gnus-summary-followup-to-mail (&optional arg)
422 "Followup to the current mail message via news."
424 (list (and current-prefix-arg
425 (gnus-summary-work-articles 1))))
426 (gnus-summary-followup arg t))
428 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
429 "Followup to the current mail message via news."
431 (gnus-summary-followup (gnus-summary-work-articles arg) t))
433 (defun gnus-inews-yank-articles (articles)
436 (while (setq article (pop articles))
437 (save-window-excursion
438 (set-buffer gnus-summary-buffer)
439 (gnus-summary-select-article nil nil nil article)
440 (gnus-summary-remove-process-mark article))
441 (gnus-copy-article-buffer)
442 (let ((message-reply-buffer gnus-article-copy)
443 (message-reply-headers
444 (with-current-buffer gnus-article-copy
445 ;; The headers are decoded.
446 (nnheader-parse-head t))))
447 (message-yank-original)
448 (setq beg (or beg (mark t))))
454 (defun gnus-summary-cancel-article (&optional n symp)
455 "Cancel an article you posted.
456 Uses the process-prefix convention. If given the symbolic
457 prefix `a', cancel using the standard posting method; if not
458 post using the current select method."
459 (interactive (gnus-interactive "P\ny"))
460 (let ((articles (gnus-summary-work-articles n))
463 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
465 (while (setq article (pop articles))
466 (when (gnus-summary-select-article t nil nil article)
467 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
468 (message-cancel-news))
469 (gnus-summary-mark-as-read article gnus-canceled-mark)
470 (gnus-cache-remove-article 1))
471 (gnus-article-hide-headers-if-wanted))
472 (gnus-summary-remove-process-mark article))))
474 (defun gnus-summary-supersede-article ()
475 "Compose an article that will supersede a previous article.
476 This is done simply by taking the old article and adding a Supersedes
477 header line with the old Message-ID."
479 (let ((article (gnus-summary-article-number)))
480 (gnus-setup-message 'reply-yank
481 (gnus-summary-select-article t)
482 (set-buffer gnus-original-article-buffer)
486 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
488 (set-buffer ,gnus-summary-buffer)
489 (gnus-cache-possibly-remove-article ,article nil nil nil t)
490 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
491 message-send-actions))))
495 (defun gnus-copy-article-buffer (&optional article-buffer)
496 ;; make a copy of the article buffer with all text properties removed
497 ;; this copy is in the buffer gnus-article-copy.
498 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
499 ;; this buffer should be passed to all mail/news reply/post routines.
500 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
502 (set-buffer gnus-article-copy)
503 (mm-enable-multibyte))
504 (let ((article-buffer (or article-buffer gnus-article-buffer))
506 (if (not (and (get-buffer article-buffer)
507 (gnus-buffer-exists-p article-buffer)))
508 (error "Can't find any article buffer")
510 (set-buffer article-buffer)
511 (let ((gnus-newsgroup-charset (or gnus-article-charset
512 gnus-newsgroup-charset))
513 (gnus-newsgroup-ignored-charsets
514 (or gnus-article-ignored-charsets
515 gnus-newsgroup-ignored-charsets)))
517 ;; Copy over the (displayed) article buffer, delete
518 ;; hidden text and remove text properties.
520 (copy-to-buffer gnus-article-copy (point-min) (point-max))
521 (set-buffer gnus-article-copy)
522 (gnus-article-delete-text-of-type 'annotation)
523 (gnus-remove-text-with-property 'gnus-prev)
524 (gnus-remove-text-with-property 'gnus-next)
527 (buffer-substring-no-properties (point-min) (point-max))
529 ;; Find the original headers.
530 (set-buffer gnus-original-article-buffer)
531 (goto-char (point-min))
532 (while (looking-at message-unix-mail-delimiter)
535 (setq end (or (message-goto-body) beg))
536 ;; Delete the headers from the displayed articles.
537 (set-buffer gnus-article-copy)
538 (delete-region (goto-char (point-min))
539 (or (message-goto-body) (point-max)))
540 ;; Insert the original article headers.
541 (insert-buffer-substring gnus-original-article-buffer beg end)
542 (article-decode-encoded-words))))
545 (defun gnus-post-news (post &optional group header article-buffer yank subject
548 (gnus-copy-article-buffer))
549 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
550 (add-to-list gnus-add-to-list))
551 (gnus-setup-message (cond (yank 'reply-yank)
552 (article-buffer 'reply)
554 (let* ((group (or group gnus-newsgroup-name))
555 (charset (gnus-group-name-charset nil group))
557 to-address to-group mailing-list to-list
560 (setq to-address (gnus-parameter-to-address group)
561 to-group (gnus-group-find-parameter group 'to-group)
562 to-list (gnus-parameter-to-list group)
563 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
564 mailing-list (when gnus-mailing-list-groups
565 (string-match gnus-mailing-list-groups group))
566 group (gnus-group-name-decode (gnus-group-real-name group)
568 (if (or (and to-group
569 (gnus-news-group-p to-group))
572 (and (gnus-news-group-p
573 (or pgroup gnus-newsgroup-name)
574 (if header (mail-header-number header)
575 gnus-current-article))
581 (message-news (or to-group group))
582 (set-buffer gnus-article-copy)
583 (gnus-msg-treat-broken-reply-to)
584 (message-followup (if (or newsgroup-p force-news)
585 (if (save-restriction
586 (article-narrow-to-head)
587 (message-fetch-field "newsgroups"))
594 (message-mail (or to-address to-list))
595 ;; Arrange for mail groups that have no `to-address' to
596 ;; get that when the user sends off the mail.
597 (when (and (not to-list)
600 (push (list 'gnus-inews-add-to-address pgroup)
601 message-send-actions)))
602 (set-buffer gnus-article-copy)
603 (gnus-msg-treat-broken-reply-to)
604 (message-wide-reply to-address)))
606 (gnus-inews-yank-articles yank))))))
608 (defun gnus-msg-treat-broken-reply-to (&optional force)
609 "Remove the Reply-to header iff broken-reply-to."
611 (gnus-group-find-parameter
612 gnus-newsgroup-name 'broken-reply-to))
614 (message-narrow-to-head)
615 (message-remove-header "reply-to"))))
617 (defun gnus-post-method (arg group &optional silent)
618 "Return the posting method based on GROUP and ARG.
619 If SILENT, don't prompt the user."
620 (let ((group-method (gnus-find-method-for-group group)))
622 ;; If the group-method is nil (which shouldn't happen) we use
623 ;; the default method.
625 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
626 gnus-select-method message-post-method))
627 ;; We want the inverse of the default
628 ((and arg (not (eq arg 0)))
629 (if (eq gnus-post-method 'active)
632 ;; We query the user for a post method.
634 (and gnus-post-method
635 (not (eq gnus-post-method 'current))
636 (listp (car gnus-post-method))))
638 ;; Collect all methods we know about.
640 (when (and gnus-post-method
641 (not (eq gnus-post-method 'current)))
642 (if (listp (car gnus-post-method))
644 (list gnus-post-method)))
645 gnus-secondary-select-methods
646 (mapcar 'cdr gnus-server-alist)
647 (mapcar 'car gnus-opened-servers)
648 (list gnus-select-method)
649 (list group-method)))
650 method-alist post-methods method)
651 ;; Weed out all mail methods.
653 (setq method (gnus-server-get-method "" (pop methods)))
654 (when (and (or (gnus-method-option-p method 'post)
655 (gnus-method-option-p method 'post-mail))
656 (not (member method post-methods)))
657 (push method post-methods)))
658 ;; Create a name-method alist.
662 (if (equal (cadr m) "")
663 (list (symbol-name (car m)) m)
664 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
669 (setq gnus-last-posting-server
671 gnus-last-posting-server)
672 ;; Just use the last value.
673 gnus-last-posting-server
675 "Posting method: " method-alist nil t
676 (cons (or gnus-last-posting-server "") 0))))
678 ;; Override normal method.
679 ((and (eq gnus-post-method 'current)
680 (not (eq (car group-method) 'nndraft))
681 (gnus-get-function group-method 'request-post t)
684 ((and gnus-post-method
685 (not (eq gnus-post-method 'current)))
687 ;; Use the normal select method.
688 (t gnus-select-method))))
692 ;; Dummies to avoid byte-compile warning.
694 (defvar nnspool-rejected-article-hook)
695 (defvar xemacs-codename))
697 (defun gnus-extended-version ()
698 "Stringified Gnus version and Emacs version."
701 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
702 " (" gnus-version ")"
705 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
706 (concat "Emacs/" (match-string 1 emacs-version)))
707 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
709 (concat (match-string 1 emacs-version)
710 (format "/%d.%d" emacs-major-version emacs-minor-version)
711 (if (match-beginning 3)
712 (match-string 3 emacs-version)
714 (if (boundp 'xemacs-codename)
715 (concat " (" xemacs-codename ")")
721 ;;; Gnus Mail Functions
724 ;;; Mail reply commands of Gnus summary mode
726 (defun gnus-summary-reply (&optional yank wide very-wide)
727 "Start composing a mail reply to the current message.
728 If prefix argument YANK is non-nil, the original article is yanked
730 If WIDE, make a wide reply.
731 If VERY-WIDE, make a very wide reply."
733 (list (and current-prefix-arg
734 (gnus-summary-work-articles 1))))
735 ;; Stripping headers should be specified with mail-yank-ignored-headers.
737 (gnus-summary-goto-subject (car yank)))
738 (let ((gnus-article-reply (or yank (gnus-summary-article-number)))
740 (gnus-setup-message (if yank 'reply-yank 'reply)
742 (gnus-summary-select-article)
743 (dolist (article very-wide)
744 (gnus-summary-select-article nil nil nil article)
746 (set-buffer (gnus-copy-article-buffer))
747 (gnus-msg-treat-broken-reply-to)
749 (message-narrow-to-head)
750 (setq headers (concat headers (buffer-string)))))))
751 (set-buffer (gnus-copy-article-buffer))
752 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
754 (message-narrow-to-head)
758 (goto-char (point-max)))
759 (mml-quote-region (point) (point-max))
760 (message-reply nil wide)
762 (gnus-inews-yank-articles yank)))))
764 (defun gnus-summary-reply-with-original (n &optional wide)
765 "Start composing a reply mail to the current message.
766 The original article will be yanked."
768 (gnus-summary-reply (gnus-summary-work-articles n) wide))
770 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
771 "Like `gnus-summary-reply' except removing reply-to field.
772 If prefix argument YANK is non-nil, the original article is yanked
774 If WIDE, make a wide reply.
775 If VERY-WIDE, make a very wide reply."
777 (list (and current-prefix-arg
778 (gnus-summary-work-articles 1))))
779 (let ((gnus-msg-force-broken-reply-to t))
780 (gnus-summary-reply yank wide very-wide)))
782 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
783 "Like `gnus-summary-reply-with-original' except removing reply-to field.
784 The original article will be yanked."
786 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
788 (defun gnus-summary-wide-reply (&optional yank)
789 "Start composing a wide reply mail to the current message.
790 If prefix argument YANK is non-nil, the original article is yanked
793 (list (and current-prefix-arg
794 (gnus-summary-work-articles 1))))
795 (gnus-summary-reply yank t))
797 (defun gnus-summary-wide-reply-with-original (n)
798 "Start composing a wide reply mail to the current message.
799 The original article will be yanked."
801 (gnus-summary-reply-with-original n t))
803 (defun gnus-summary-very-wide-reply (&optional yank)
804 "Start composing a very wide reply mail to the current message.
805 If prefix argument YANK is non-nil, the original article is yanked
808 (list (and current-prefix-arg
809 (gnus-summary-work-articles 1))))
810 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
812 (defun gnus-summary-very-wide-reply-with-original (n)
813 "Start composing a very wide reply mail to the current message.
814 The original article will be yanked."
817 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
819 (defun gnus-summary-mail-forward (&optional arg post)
820 "Forward the current message to another user.
821 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
822 if ARG is 1, decode the message and forward directly inline;
823 if ARG is 2, forward message as an rfc822 MIME section;
824 if ARG is 3, decode message and forward as an rfc822 MIME section;
825 if ARG is 4, forward message directly inline;
826 otherwise, use flipped `message-forward-as-mime'.
827 If POST, post instead of mail."
829 (let ((message-forward-as-mime message-forward-as-mime)
830 (message-forward-show-mml message-forward-show-mml))
834 (setq message-forward-as-mime nil
835 message-forward-show-mml t))
837 (setq message-forward-as-mime t
838 message-forward-show-mml nil))
840 (setq message-forward-as-mime t
841 message-forward-show-mml t))
843 (setq message-forward-as-mime nil
844 message-forward-show-mml nil))
846 (setq message-forward-as-mime (not message-forward-as-mime))))
847 (let ((gnus-article-reply (gnus-summary-article-number)))
848 (gnus-setup-message 'forward
849 (gnus-summary-select-article)
850 (let ((mail-parse-charset gnus-newsgroup-charset)
851 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
852 (set-buffer gnus-original-article-buffer)
853 (message-forward post))))))
855 (defun gnus-summary-resend-message (address n)
856 "Resend the current article to ADDRESS."
858 (list (message-read-from-minibuffer "Resend message(s) to: ")
860 (let ((articles (gnus-summary-work-articles n))
862 (while (setq article (pop articles))
863 (gnus-summary-select-article nil nil nil article)
865 (set-buffer gnus-original-article-buffer)
866 (message-resend address))
867 (gnus-summary-mark-article-as-forwarded article))))
869 (defun gnus-summary-post-forward (&optional arg)
870 "Forward the current article to a newsgroup.
871 See `gnus-summary-mail-forward' for ARG."
873 (gnus-summary-mail-forward arg t))
875 (defvar gnus-nastygram-message
876 "The following article was inappropriately posted to %s.\n\n"
877 "Format string to insert in nastygrams.
878 The current group name will be inserted at \"%s\".")
880 (defun gnus-summary-mail-nastygram (n)
881 "Send a nastygram to the author of the current article."
883 (when (or gnus-expert-user
885 "Really send a nastygram to the author of the current article? "))
886 (let ((group gnus-newsgroup-name))
887 (gnus-summary-reply-with-original n)
888 (set-buffer gnus-message-buffer)
890 (insert (format gnus-nastygram-message group))
891 (message-send-and-exit))))
893 (defun gnus-summary-mail-crosspost-complaint (n)
894 "Send a complaint about crossposting to the current article(s)."
896 (let ((articles (gnus-summary-work-articles n))
898 (while (setq article (pop articles))
899 (set-buffer gnus-summary-buffer)
900 (gnus-summary-goto-subject article)
901 (let ((group (gnus-group-real-name gnus-newsgroup-name))
902 newsgroups followup-to)
903 (gnus-summary-select-article)
904 (set-buffer gnus-original-article-buffer)
905 (if (and (<= (length (message-tokenize-header
907 (mail-fetch-field "newsgroups"))
910 (or (not (setq followup-to (mail-fetch-field "followup-to")))
911 (not (member group (message-tokenize-header
912 followup-to ", ")))))
914 (gnus-message 1 "Followup-to restricted")
915 (gnus-message 1 "Not a crossposted article"))
916 (set-buffer gnus-summary-buffer)
917 (gnus-summary-reply-with-original 1)
918 (set-buffer gnus-message-buffer)
920 (insert (format gnus-crosspost-complaint newsgroups group))
921 (message-goto-subject)
922 (re-search-forward " *$")
923 (replace-match " (crosspost notification)" t t)
924 (gnus-deactivate-mark)
925 (when (gnus-y-or-n-p "Send this complaint? ")
926 (message-send-and-exit)))))))
928 (defun gnus-summary-mail-other-window ()
929 "Compose mail in other window."
931 (gnus-setup-message 'message
934 (defun gnus-mail-parse-comma-list ()
937 (skip-chars-forward " ")
940 (skip-chars-forward "^,")
945 (narrow-to-region beg (point))
948 (while (search-forward "\"" nil t)
952 (skip-chars-forward ",")
953 (skip-chars-forward "^,"))
954 (skip-chars-backward " ")
955 (push (buffer-substring beg (point))
957 (skip-chars-forward "^,")
958 (skip-chars-forward ", "))
961 (defun gnus-inews-add-to-address (group)
962 (let ((to-address (mail-fetch-field "to")))
963 (when (and to-address
965 ;; This mail group doesn't have a `to-list', so we add one
968 (format "Do you want to add this as `to-list': %s " to-address))
969 (gnus-group-add-parameter group (cons 'to-list to-address))))))
971 (defun gnus-put-message ()
972 "Put the current message in some group and return to Gnus."
974 (let ((reply gnus-article-reply)
975 (winconf gnus-prev-winconf)
976 (group gnus-newsgroup-name))
978 (not (gnus-group-read-only-p group)))
979 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
981 (when (gnus-gethash group gnus-newsrc-hashtb)
982 (error "No such group: %s" group))
986 (message-narrow-to-headers)
987 (let ((gnus-deletable-headers nil))
988 (message-generate-headers
990 message-required-news-headers
991 message-required-mail-headers)))
992 (goto-char (point-max))
993 (insert "Gcc: " group "\n")
996 (when (and (get-buffer gnus-group-buffer)
997 (gnus-buffer-exists-p (car-safe reply))
999 (set-buffer (car reply))
1000 (gnus-summary-mark-article-as-replied (cdr reply)))
1002 (set-window-configuration winconf))))
1004 (defun gnus-article-mail (yank)
1005 "Send a reply to the address near point.
1006 If YANK is non-nil, include the original article."
1010 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1011 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1013 (message-reply address)
1015 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1017 (defvar nntp-server-type)
1019 "Send a bug report to the Gnus maintainers."
1021 (unless (gnus-alive-p)
1022 (error "Gnus has been shut down"))
1023 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1024 (unless (message-mail-user-agent)
1025 (delete-other-windows)
1026 (when gnus-bug-create-help-buffer
1027 (switch-to-buffer "*Gnus Help Bug*")
1029 (insert gnus-bug-message)
1030 (goto-char (point-min)))
1031 (message-pop-to-buffer "*Gnus Bug*"))
1032 (let ((message-this-is-mail t))
1033 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1034 (when gnus-bug-create-help-buffer
1035 (push `(gnus-bug-kill-buffer) message-send-actions))
1036 (goto-char (point-min))
1037 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1039 (insert (gnus-version) "\n"
1040 (emacs-version) "\n")
1041 (when (and (boundp 'nntp-server-type)
1042 (stringp nntp-server-type))
1043 (insert nntp-server-type))
1044 (insert "\n\n\n\n\n")
1047 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1050 (setq text (buffer-string)))
1051 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1052 (goto-char (point-min))
1053 (search-forward "Subject: " nil t)
1056 (defun gnus-bug-kill-buffer ()
1057 (when (get-buffer "*Gnus Help Bug*")
1058 (kill-buffer "*Gnus Help Bug*")))
1060 (defun gnus-summary-yank-message (buffer n)
1061 "Yank the current article into a composed message."
1063 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1064 current-prefix-arg))
1065 (gnus-summary-iterate n
1066 (let ((gnus-display-mime-function nil)
1067 (gnus-inhibit-treatment t))
1068 (gnus-summary-select-article))
1071 (message-yank-buffer gnus-article-buffer))))
1073 (defun gnus-debug ()
1074 "Attempts to go through the Gnus source file and report what variables have been changed.
1075 The source file has to be in the Emacs load path."
1077 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1078 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1079 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1080 "nnmail.el" "message.el"))
1082 file expr olist sym)
1083 (gnus-message 4 "Please wait while we snoop your variables...")
1085 ;; Go through all the files looking for non-default values for variables.
1087 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1090 (when (and (setq file (locate-library (pop files)))
1091 (file-exists-p file))
1092 (insert-file-contents file)
1093 (goto-char (point-min))
1094 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1095 (gnus-message 4 "Malformed sources in file %s" file)
1096 (narrow-to-region (point-min) (point))
1097 (goto-char (point-min))
1098 (while (setq expr (ignore-errors (read (current-buffer))))
1100 (and (or (eq (car expr) 'defvar)
1101 (eq (car expr) 'defcustom))
1102 (stringp (nth 3 expr))
1103 (or (not (boundp (nth 1 expr)))
1104 (not (equal (eval (nth 2 expr))
1105 (symbol-value (nth 1 expr)))))
1106 (push (nth 1 expr) olist)))))))
1107 (kill-buffer (current-buffer)))
1108 (when (setq olist (nreverse olist))
1109 (insert "------------------ Environment follows ------------------\n\n"))
1111 (if (boundp (car olist))
1113 (pp `(setq ,(car olist)
1114 ,(if (or (consp (setq sym (symbol-value (car olist))))
1116 (not (or (eq sym nil)
1118 (list 'quote (symbol-value (car olist)))
1119 (symbol-value (car olist))))
1122 (format "(setq %s 'whatever)\n" (car olist))))
1123 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1124 (setq olist (cdr olist)))
1126 ;; Remove any control chars - they seem to cause trouble for some
1127 ;; mailers. (Byte-compiled output from the stuff above.)
1129 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1130 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1133 ;;; Treatment of rejected articles.
1136 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1137 "Re-mail the current message.
1138 This only makes sense if the current message is a bounce message than
1139 contains some mail you have written which has been bounced back to
1141 If FETCH, try to fetch the article that this is a reply to, if indeed
1144 (gnus-summary-select-article t)
1145 (set-buffer gnus-original-article-buffer)
1146 (gnus-setup-message 'compose-bounce
1147 (let* ((references (mail-fetch-field "references"))
1148 (parent (and references (gnus-parent-id references))))
1150 ;; If there are references, we fetch the article we answered to.
1152 (gnus-summary-refer-article parent)
1153 (gnus-summary-show-all-headers)))))
1157 (defun gnus-inews-group-method (group)
1158 (cond ((and (null (gnus-get-info group))
1159 (eq (car gnus-message-archive-method)
1161 (gnus-server-to-method
1162 (gnus-group-method group)))))
1163 ;; If the group doesn't exist, we assume
1164 ;; it's an archive group...
1165 gnus-message-archive-method)
1167 ((gnus-info-method (gnus-get-info group))
1168 (gnus-info-method (gnus-get-info group)))
1170 (t (gnus-group-method group))))
1172 ;; Do Gcc handling, which copied the message over to some group.
1173 (defun gnus-inews-do-gcc (&optional gcc)
1177 (message-narrow-to-headers)
1178 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1179 (cur (current-buffer))
1180 groups group method group-art)
1182 (message-remove-header "gcc")
1184 (setq groups (message-unquote-tokens
1185 (message-tokenize-header gcc " ,")))
1186 ;; Copy the article over to some group(s).
1187 (while (setq group (pop groups))
1189 (setq method (gnus-inews-group-method group)))
1190 (unless (gnus-request-group group nil method)
1191 (gnus-request-create-group group method))
1193 (nnheader-set-temp-buffer " *acc*")
1194 (insert-buffer-substring cur)
1195 (message-encode-message-body)
1197 (message-narrow-to-headers)
1198 (let ((mail-parse-charset message-default-charset)
1199 (rfc2047-header-encoding-alist
1200 (cons '("Newsgroups" . default)
1201 rfc2047-header-encoding-alist)))
1202 (mail-encode-encoded-word-buffer)))
1203 (goto-char (point-min))
1204 (when (re-search-forward
1205 (concat "^" (regexp-quote mail-header-separator) "$")
1207 (replace-match "" t t ))
1208 (unless (setq group-art
1209 (gnus-request-accept-article group method t t))
1210 (gnus-message 1 "Couldn't store article in group %s: %s"
1211 group (gnus-status-message method))
1213 (when (and group-art gnus-inews-mark-gcc-as-read)
1214 (gnus-group-mark-article-read group (cdr group-art)))
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 (and (gnus-buffer-live-p gnus-article-copy)
1335 (with-current-buffer gnus-article-copy
1336 (let ((header (message-fetch-field (pop style))))
1338 (string-match (pop style) header))))))
1339 ((or (symbolp match)
1340 (gnus-functionp match))
1342 ((gnus-functionp match)
1343 ;; Function to be called.
1346 ;; Variable to be checked.
1347 (symbol-value match))))
1349 ;; This is a form to be evaled.
1351 ;; We have a match, so we set the variables.
1352 (dolist (attribute style)
1353 (setq element (pop attribute)
1358 ((eq (car attribute) :file)
1361 ((eq (car attribute) :value)
1365 ;; We get the value.
1370 ((or (symbolp value)
1371 (gnus-functionp value))
1372 (cond ((gnus-functionp value)
1375 (symbol-value value))))
1378 ;; Translate obsolescent value.
1379 (when (eq element 'signature-file)
1380 (setq element 'signature
1382 ;; Get the contents of file elems.
1384 (setq v (with-temp-buffer
1385 (insert-file-contents v)
1387 (setq results (delq (assoc element results) results))
1388 (push (cons element v) results))))
1389 ;; Now we have all the styles, so we insert them.
1390 (setq name (assq 'name results)
1391 address (assq 'address results))
1392 (setq results (delq name (delq address results)))
1393 (make-local-variable 'message-setup-hook)
1394 (dolist (result results)
1395 (add-hook 'message-setup-hook
1397 ((eq 'eval (car result))
1399 ((eq 'body (car result))
1403 (insert ,(cdr result)))))
1404 ((eq 'signature (car result))
1405 (set (make-local-variable 'message-signature) nil)
1406 (set (make-local-variable 'message-signature-file) nil)
1407 (if (not (cdr result))
1411 (let ((message-signature ,(cdr result)))
1412 (when message-signature
1413 (message-insert-signature)))))))
1416 (if (symbolp (car result))
1417 (capitalize (symbol-name (car result)))
1421 (message-remove-header ,header)
1422 (let ((value ,(cdr result)))
1425 (insert ,header ": " value "\n"))))))))))
1426 (when (or name address)
1427 (add-hook 'message-setup-hook
1429 (set (make-local-variable 'user-mail-address)
1430 ,(or (cdr address) user-mail-address))
1431 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1433 ,(or (cdr address) user-mail-address)))
1435 (message-remove-header "From")
1437 (insert "From: " (message-make-from) "\n")))))))))
1439 ;;; Allow redefinition of functions.
1445 ;;; gnus-msg.el ends here