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 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
250 (mml-destroy-buffers)
251 (setq mml-buffer-list mbl)))
253 (gnus-configure-windows ,config t)
254 (set-buffer-modified-p nil))))
256 (defun gnus-inews-insert-draft-meta-information (group article)
259 (not (string= group ""))
260 (not (message-fetch-field gnus-draft-meta-information-header)))
261 (goto-char (point-min))
262 (insert gnus-draft-meta-information-header ": (\"" group "\" "
263 (if article (number-to-string
270 (defun gnus-msg-mail (&optional to subject other-headers continue
271 switch-action yank-action send-actions)
272 "Start editing a mail message to be sent.
273 Like `message-mail', but with Gnus paraphernalia, particularly the
274 Gcc: header for archiving purposes."
276 (let ((buf (current-buffer))
278 (gnus-setup-message 'message
279 (message-mail to subject other-headers continue
280 nil yank-action send-actions))
282 (setq mail-buf (current-buffer))
283 (switch-to-buffer buf)
284 (apply switch-action mail-buf nil)))
285 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
289 (defun gnus-button-mailto (address)
291 (set-buffer (gnus-copy-article-buffer))
292 (gnus-setup-message 'message
293 (message-reply address)))
296 (defun gnus-button-reply (&optional to-address wide)
297 "Like `message-reply'."
299 (gnus-setup-message 'message
300 (message-reply to-address wide)))
303 (define-mail-user-agent 'gnus-user-agent
304 'gnus-msg-mail 'message-send-and-exit
305 'message-kill-buffer 'message-send-hook)
307 (defun gnus-setup-posting-charset (group)
308 (let ((alist gnus-group-posting-charset-alist)
309 (group (or group ""))
313 (while (setq elem (pop alist))
314 (when (or (and (stringp (car elem))
315 (string-match (car elem) group))
316 (and (gnus-functionp (car elem))
317 (funcall (car elem) group))
318 (and (symbolp (car elem))
319 (symbol-value (car elem))))
320 (throw 'found (cons (cadr elem) (caddr elem)))))))))
322 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
323 (make-local-hook 'message-sent-hook)
324 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
325 'gnus-inews-do-gcc) nil t)
327 (make-local-hook 'message-header-hook)
328 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
329 (setq message-post-method
331 (gnus-post-method arg ,gnus-newsgroup-name)))
332 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
334 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
336 `(when (gnus-buffer-exists-p ,buffer)
340 (if (eq config 'forward)
341 `(gnus-summary-mark-article-as-forwarded ',article)
342 `(gnus-summary-mark-article-as-replied ',article)))))
345 (put 'gnus-setup-message 'lisp-indent-function 1)
346 (put 'gnus-setup-message 'edebug-form-spec '(form body))
348 ;;; Post news commands of Gnus group mode and summary mode
350 (defun gnus-group-mail (&optional arg)
351 "Start composing a mail.
352 If ARG, use the group under the point to find a posting style.
353 If ARG is 1, prompt for a group name to find the posting style."
355 ;; We can't `let' gnus-newsgroup-name here, since that leads
356 ;; to local variables leaking.
357 (let ((group gnus-newsgroup-name)
358 (buffer (current-buffer)))
361 (setq gnus-newsgroup-name
363 (if (= 1 (prefix-numeric-value arg))
364 (completing-read "Use posting style of group: "
365 gnus-active-hashtb nil
366 (gnus-read-active-file-p))
367 (gnus-group-group-name))
369 (gnus-setup-message 'message (message-mail)))
372 (setq gnus-newsgroup-name group)))))
374 (defun gnus-group-post-news (&optional arg)
375 "Start composing a news message.
376 If ARG, post to the group under point.
377 If ARG is 1, prompt for a group name."
379 ;; Bind this variable here to make message mode hooks work ok.
380 (let ((gnus-newsgroup-name
382 (if (= 1 (prefix-numeric-value arg))
383 (completing-read "Newsgroup: " gnus-active-hashtb nil
384 (gnus-read-active-file-p))
385 (gnus-group-group-name))
387 (gnus-post-news 'post gnus-newsgroup-name)))
389 (defun gnus-summary-post-news ()
390 "Start composing a news message."
392 (gnus-post-news 'post gnus-newsgroup-name))
394 (defun gnus-summary-followup (yank &optional force-news)
395 "Compose a followup to an article.
396 If prefix argument YANK is non-nil, original article is yanked automatically."
398 (list (and current-prefix-arg
399 (gnus-summary-work-articles 1))))
401 (gnus-summary-goto-subject (car yank)))
402 (save-window-excursion
403 (gnus-summary-select-article))
404 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
405 (gnus-newsgroup-name gnus-newsgroup-name))
407 (gnus-post-news nil gnus-newsgroup-name
408 headers gnus-article-buffer
409 yank nil force-news)))
411 (defun gnus-summary-followup-with-original (n &optional force-news)
412 "Compose a followup to an article and include the original article."
414 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
416 (defun gnus-summary-followup-to-mail (&optional arg)
417 "Followup to the current mail message via news."
419 (list (and current-prefix-arg
420 (gnus-summary-work-articles 1))))
421 (gnus-summary-followup arg t))
423 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
424 "Followup to the current mail message via news."
426 (gnus-summary-followup (gnus-summary-work-articles arg) t))
428 (defun gnus-inews-yank-articles (articles)
431 (while (setq article (pop articles))
432 (save-window-excursion
433 (set-buffer gnus-summary-buffer)
434 (gnus-summary-select-article nil nil nil article)
435 (gnus-summary-remove-process-mark article))
436 (gnus-copy-article-buffer)
437 (let ((message-reply-buffer gnus-article-copy)
438 (message-reply-headers
439 (with-current-buffer gnus-article-copy
440 ;; The headers are decoded.
441 (nnheader-parse-head t))))
442 (message-yank-original)
443 (setq beg (or beg (mark t))))
449 (defun gnus-summary-cancel-article (&optional n symp)
450 "Cancel an article you posted.
451 Uses the process-prefix convention. If given the symbolic
452 prefix `a', cancel using the standard posting method; if not
453 post using the current select method."
454 (interactive (gnus-interactive "P\ny"))
455 (let ((articles (gnus-summary-work-articles n))
458 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
460 (while (setq article (pop articles))
461 (when (gnus-summary-select-article t nil nil article)
462 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
463 (message-cancel-news))
464 (gnus-summary-mark-as-read article gnus-canceled-mark)
465 (gnus-cache-remove-article 1))
466 (gnus-article-hide-headers-if-wanted))
467 (gnus-summary-remove-process-mark article))))
469 (defun gnus-summary-supersede-article ()
470 "Compose an article that will supersede a previous article.
471 This is done simply by taking the old article and adding a Supersedes
472 header line with the old Message-ID."
474 (let ((article (gnus-summary-article-number)))
475 (gnus-setup-message 'reply-yank
476 (gnus-summary-select-article t)
477 (set-buffer gnus-original-article-buffer)
481 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
483 (set-buffer ,gnus-summary-buffer)
484 (gnus-cache-possibly-remove-article ,article nil nil nil t)
485 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
486 message-send-actions))))
490 (defun gnus-copy-article-buffer (&optional article-buffer)
491 ;; make a copy of the article buffer with all text properties removed
492 ;; this copy is in the buffer gnus-article-copy.
493 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
494 ;; this buffer should be passed to all mail/news reply/post routines.
495 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
497 (set-buffer gnus-article-copy)
498 (mm-enable-multibyte))
499 (let ((article-buffer (or article-buffer gnus-article-buffer))
501 (if (not (and (get-buffer article-buffer)
502 (gnus-buffer-exists-p article-buffer)))
503 (error "Can't find any article buffer")
505 (set-buffer article-buffer)
506 (let ((gnus-newsgroup-charset (or gnus-article-charset
507 gnus-newsgroup-charset))
508 (gnus-newsgroup-ignored-charsets
509 (or gnus-article-ignored-charsets
510 gnus-newsgroup-ignored-charsets)))
512 ;; Copy over the (displayed) article buffer, delete
513 ;; hidden text and remove text properties.
515 (copy-to-buffer gnus-article-copy (point-min) (point-max))
516 (set-buffer gnus-article-copy)
517 (gnus-article-delete-text-of-type 'annotation)
518 (gnus-remove-text-with-property 'gnus-prev)
519 (gnus-remove-text-with-property 'gnus-next)
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 (message-goto-body) beg))
531 ;; Delete the headers from the displayed articles.
532 (set-buffer gnus-article-copy)
533 (delete-region (goto-char (point-min))
534 (or (message-goto-body) (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 (and article-buffer (gnus-summary-article-number)))
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-parameter-to-address group)
556 to-group (gnus-group-find-parameter group 'to-group)
557 to-list (gnus-parameter-to-list group)
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)
580 (if (save-restriction
581 (article-narrow-to-head)
582 (message-fetch-field "newsgroups"))
589 (message-mail (or to-address to-list))
590 ;; Arrange for mail groups that have no `to-address' to
591 ;; get that when the user sends off the mail.
592 (when (and (not to-list)
595 (push (list 'gnus-inews-add-to-address pgroup)
596 message-send-actions)))
597 (set-buffer gnus-article-copy)
598 (gnus-msg-treat-broken-reply-to)
599 (message-wide-reply to-address)))
601 (gnus-inews-yank-articles yank))))))
603 (defun gnus-msg-treat-broken-reply-to (&optional force)
604 "Remove the Reply-to header iff broken-reply-to."
606 (gnus-group-find-parameter
607 gnus-newsgroup-name 'broken-reply-to))
609 (message-narrow-to-head)
610 (message-remove-header "reply-to"))))
612 (defun gnus-post-method (arg group &optional silent)
613 "Return the posting method based on GROUP and ARG.
614 If SILENT, don't prompt the user."
615 (let ((group-method (gnus-find-method-for-group group)))
617 ;; If the group-method is nil (which shouldn't happen) we use
618 ;; the default method.
620 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
621 gnus-select-method message-post-method))
622 ;; We want the inverse of the default
623 ((and arg (not (eq arg 0)))
624 (if (eq gnus-post-method 'active)
627 ;; We query the user for a post method.
629 (and gnus-post-method
630 (not (eq gnus-post-method 'current))
631 (listp (car gnus-post-method))))
633 ;; Collect all methods we know about.
635 (when (and gnus-post-method
636 (not (eq gnus-post-method 'current)))
637 (if (listp (car gnus-post-method))
639 (list gnus-post-method)))
640 gnus-secondary-select-methods
641 (mapcar 'cdr gnus-server-alist)
642 (mapcar 'car gnus-opened-servers)
643 (list gnus-select-method)
644 (list group-method)))
645 method-alist post-methods method)
646 ;; Weed out all mail methods.
648 (setq method (gnus-server-get-method "" (pop methods)))
649 (when (and (or (gnus-method-option-p method 'post)
650 (gnus-method-option-p method 'post-mail))
651 (not (member method post-methods)))
652 (push method post-methods)))
653 ;; Create a name-method alist.
657 (if (equal (cadr m) "")
658 (list (symbol-name (car m)) m)
659 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
664 (setq gnus-last-posting-server
666 gnus-last-posting-server)
667 ;; Just use the last value.
668 gnus-last-posting-server
670 "Posting method: " method-alist nil t
671 (cons (or gnus-last-posting-server "") 0))))
673 ;; Override normal method.
674 ((and (eq gnus-post-method 'current)
675 (not (eq (car group-method) 'nndraft))
676 (gnus-get-function group-method 'request-post t)
679 ((and gnus-post-method
680 (not (eq gnus-post-method 'current)))
682 ;; Use the normal select method.
683 (t gnus-select-method))))
687 ;; Dummies to avoid byte-compile warning.
689 (defvar nnspool-rejected-article-hook)
690 (defvar xemacs-codename))
692 (defun gnus-extended-version ()
693 "Stringified Gnus version and Emacs version."
696 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
697 " (" gnus-version ")"
700 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
701 (concat "Emacs/" (match-string 1 emacs-version)))
702 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
704 (concat (match-string 1 emacs-version)
705 (format "/%d.%d" emacs-major-version emacs-minor-version)
706 (if (match-beginning 3)
707 (match-string 3 emacs-version)
709 (if (boundp 'xemacs-codename)
710 (concat " (" xemacs-codename ")")
716 ;;; Gnus Mail Functions
719 ;;; Mail reply commands of Gnus summary mode
721 (defun gnus-summary-reply (&optional yank wide very-wide)
722 "Start composing a mail reply to the current message.
723 If prefix argument YANK is non-nil, the original article is yanked
725 If WIDE, make a wide reply.
726 If VERY-WIDE, make a very wide reply."
728 (list (and current-prefix-arg
729 (gnus-summary-work-articles 1))))
730 ;; Stripping headers should be specified with mail-yank-ignored-headers.
732 (gnus-summary-goto-subject (car yank)))
733 (let ((gnus-article-reply (or yank (gnus-summary-article-number)))
735 (gnus-setup-message (if yank 'reply-yank 'reply)
737 (gnus-summary-select-article)
738 (dolist (article very-wide)
739 (gnus-summary-select-article nil nil nil article)
741 (set-buffer (gnus-copy-article-buffer))
742 (gnus-msg-treat-broken-reply-to)
744 (message-narrow-to-head)
745 (setq headers (concat headers (buffer-string)))))))
746 (set-buffer (gnus-copy-article-buffer))
747 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
749 (message-narrow-to-head)
753 (goto-char (point-max)))
754 (mml-quote-region (point) (point-max))
755 (message-reply nil wide)
757 (gnus-inews-yank-articles yank)))))
759 (defun gnus-summary-reply-with-original (n &optional wide)
760 "Start composing a reply mail to the current message.
761 The original article will be yanked."
763 (gnus-summary-reply (gnus-summary-work-articles n) wide))
765 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
766 "Like `gnus-summary-reply' except removing reply-to field.
767 If prefix argument YANK is non-nil, the original article is yanked
769 If WIDE, make a wide reply.
770 If VERY-WIDE, make a very wide reply."
772 (list (and current-prefix-arg
773 (gnus-summary-work-articles 1))))
774 (let ((gnus-msg-force-broken-reply-to t))
775 (gnus-summary-reply yank wide very-wide)))
777 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
778 "Like `gnus-summary-reply-with-original' except removing reply-to field.
779 The original article will be yanked."
781 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
783 (defun gnus-summary-wide-reply (&optional yank)
784 "Start composing a wide reply mail to the current message.
785 If prefix argument YANK is non-nil, the original article is yanked
788 (list (and current-prefix-arg
789 (gnus-summary-work-articles 1))))
790 (gnus-summary-reply yank t))
792 (defun gnus-summary-wide-reply-with-original (n)
793 "Start composing a wide reply mail to the current message.
794 The original article will be yanked."
796 (gnus-summary-reply-with-original n t))
798 (defun gnus-summary-very-wide-reply (&optional yank)
799 "Start composing a very wide reply mail to the current message.
800 If prefix argument YANK is non-nil, the original article is yanked
803 (list (and current-prefix-arg
804 (gnus-summary-work-articles 1))))
805 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
807 (defun gnus-summary-very-wide-reply-with-original (n)
808 "Start composing a very wide reply mail to the current message.
809 The original article will be yanked."
812 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
814 (defun gnus-summary-mail-forward (&optional arg post)
815 "Forward the current message to another user.
816 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
817 if ARG is 1, decode the message and forward directly inline;
818 if ARG is 2, forward message as an rfc822 MIME section;
819 if ARG is 3, decode message and forward as an rfc822 MIME section;
820 if ARG is 4, forward message directly inline;
821 otherwise, use flipped `message-forward-as-mime'.
822 If POST, post instead of mail."
824 (let ((message-forward-as-mime message-forward-as-mime)
825 (message-forward-show-mml message-forward-show-mml))
829 (setq message-forward-as-mime nil
830 message-forward-show-mml t))
832 (setq message-forward-as-mime t
833 message-forward-show-mml nil))
835 (setq message-forward-as-mime t
836 message-forward-show-mml t))
838 (setq message-forward-as-mime nil
839 message-forward-show-mml nil))
841 (setq message-forward-as-mime (not message-forward-as-mime))))
842 (let ((gnus-article-reply (gnus-summary-article-number)))
843 (gnus-setup-message 'forward
844 (gnus-summary-select-article)
845 (let ((mail-parse-charset gnus-newsgroup-charset)
846 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
847 (set-buffer gnus-original-article-buffer)
848 (message-forward post))))))
850 (defun gnus-summary-resend-message (address n)
851 "Resend the current article to ADDRESS."
853 (list (message-read-from-minibuffer "Resend message(s) to: ")
855 (let ((articles (gnus-summary-work-articles n))
857 (while (setq article (pop articles))
858 (gnus-summary-select-article nil nil nil article)
860 (set-buffer gnus-original-article-buffer)
861 (message-resend address))
862 (gnus-summary-mark-article-as-forwarded article))))
864 (defun gnus-summary-post-forward (&optional arg)
865 "Forward the current article to a newsgroup.
866 See `gnus-summary-mail-forward' for ARG."
868 (gnus-summary-mail-forward arg t))
870 (defvar gnus-nastygram-message
871 "The following article was inappropriately posted to %s.\n\n"
872 "Format string to insert in nastygrams.
873 The current group name will be inserted at \"%s\".")
875 (defun gnus-summary-mail-nastygram (n)
876 "Send a nastygram to the author of the current article."
878 (when (or gnus-expert-user
880 "Really send a nastygram to the author of the current article? "))
881 (let ((group gnus-newsgroup-name))
882 (gnus-summary-reply-with-original n)
883 (set-buffer gnus-message-buffer)
885 (insert (format gnus-nastygram-message group))
886 (message-send-and-exit))))
888 (defun gnus-summary-mail-crosspost-complaint (n)
889 "Send a complaint about crossposting to the current article(s)."
891 (let ((articles (gnus-summary-work-articles n))
893 (while (setq article (pop articles))
894 (set-buffer gnus-summary-buffer)
895 (gnus-summary-goto-subject article)
896 (let ((group (gnus-group-real-name gnus-newsgroup-name))
897 newsgroups followup-to)
898 (gnus-summary-select-article)
899 (set-buffer gnus-original-article-buffer)
900 (if (and (<= (length (message-tokenize-header
902 (mail-fetch-field "newsgroups"))
905 (or (not (setq followup-to (mail-fetch-field "followup-to")))
906 (not (member group (message-tokenize-header
907 followup-to ", ")))))
909 (gnus-message 1 "Followup-to restricted")
910 (gnus-message 1 "Not a crossposted article"))
911 (set-buffer gnus-summary-buffer)
912 (gnus-summary-reply-with-original 1)
913 (set-buffer gnus-message-buffer)
915 (insert (format gnus-crosspost-complaint newsgroups group))
916 (message-goto-subject)
917 (re-search-forward " *$")
918 (replace-match " (crosspost notification)" t t)
919 (gnus-deactivate-mark)
920 (when (gnus-y-or-n-p "Send this complaint? ")
921 (message-send-and-exit)))))))
923 (defun gnus-summary-mail-other-window ()
924 "Compose mail in other window."
926 (gnus-setup-message 'message
929 (defun gnus-mail-parse-comma-list ()
932 (skip-chars-forward " ")
935 (skip-chars-forward "^,")
940 (narrow-to-region beg (point))
943 (while (search-forward "\"" nil t)
947 (skip-chars-forward ",")
948 (skip-chars-forward "^,"))
949 (skip-chars-backward " ")
950 (push (buffer-substring beg (point))
952 (skip-chars-forward "^,")
953 (skip-chars-forward ", "))
956 (defun gnus-inews-add-to-address (group)
957 (let ((to-address (mail-fetch-field "to")))
958 (when (and to-address
960 ;; This mail group doesn't have a `to-list', so we add one
963 (format "Do you want to add this as `to-list': %s " to-address))
964 (gnus-group-add-parameter group (cons 'to-list to-address))))))
966 (defun gnus-put-message ()
967 "Put the current message in some group and return to Gnus."
969 (let ((reply gnus-article-reply)
970 (winconf gnus-prev-winconf)
971 (group gnus-newsgroup-name))
973 (not (gnus-group-read-only-p group)))
974 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
976 (when (gnus-gethash group gnus-newsrc-hashtb)
977 (error "No such group: %s" group))
981 (message-narrow-to-headers)
982 (let ((gnus-deletable-headers nil))
983 (message-generate-headers
985 message-required-news-headers
986 message-required-mail-headers)))
987 (goto-char (point-max))
988 (insert "Gcc: " group "\n")
991 (when (and (get-buffer gnus-group-buffer)
992 (gnus-buffer-exists-p (car-safe reply))
994 (set-buffer (car reply))
995 (gnus-summary-mark-article-as-replied (cdr reply)))
997 (set-window-configuration winconf))))
999 (defun gnus-article-mail (yank)
1000 "Send a reply to the address near point.
1001 If YANK is non-nil, include the original article."
1005 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1006 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1008 (message-reply address)
1010 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1012 (defvar nntp-server-type)
1014 "Send a bug report to the Gnus maintainers."
1016 (unless (gnus-alive-p)
1017 (error "Gnus has been shut down"))
1018 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1019 (unless (message-mail-user-agent)
1020 (delete-other-windows)
1021 (when gnus-bug-create-help-buffer
1022 (switch-to-buffer "*Gnus Help Bug*")
1024 (insert gnus-bug-message)
1025 (goto-char (point-min)))
1026 (message-pop-to-buffer "*Gnus Bug*"))
1027 (let ((message-this-is-mail t))
1028 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1029 (when gnus-bug-create-help-buffer
1030 (push `(gnus-bug-kill-buffer) message-send-actions))
1031 (goto-char (point-min))
1032 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1034 (insert (gnus-version) "\n"
1035 (emacs-version) "\n")
1036 (when (and (boundp 'nntp-server-type)
1037 (stringp nntp-server-type))
1038 (insert nntp-server-type))
1039 (insert "\n\n\n\n\n")
1042 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1045 (setq text (buffer-string)))
1046 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1047 (goto-char (point-min))
1048 (search-forward "Subject: " nil t)
1051 (defun gnus-bug-kill-buffer ()
1052 (when (get-buffer "*Gnus Help Bug*")
1053 (kill-buffer "*Gnus Help Bug*")))
1055 (defun gnus-summary-yank-message (buffer n)
1056 "Yank the current article into a composed message."
1058 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1059 current-prefix-arg))
1060 (gnus-summary-iterate n
1061 (let ((gnus-display-mime-function nil)
1062 (gnus-inhibit-treatment t))
1063 (gnus-summary-select-article))
1066 (message-yank-buffer gnus-article-buffer))))
1068 (defun gnus-debug ()
1069 "Attempts to go through the Gnus source file and report what variables have been changed.
1070 The source file has to be in the Emacs load path."
1072 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1073 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1074 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1075 "nnmail.el" "message.el"))
1077 file expr olist sym)
1078 (gnus-message 4 "Please wait while we snoop your variables...")
1080 ;; Go through all the files looking for non-default values for variables.
1082 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1085 (when (and (setq file (locate-library (pop files)))
1086 (file-exists-p file))
1087 (insert-file-contents file)
1088 (goto-char (point-min))
1089 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1090 (gnus-message 4 "Malformed sources in file %s" file)
1091 (narrow-to-region (point-min) (point))
1092 (goto-char (point-min))
1093 (while (setq expr (ignore-errors (read (current-buffer))))
1095 (and (or (eq (car expr) 'defvar)
1096 (eq (car expr) 'defcustom))
1097 (stringp (nth 3 expr))
1098 (or (not (boundp (nth 1 expr)))
1099 (not (equal (eval (nth 2 expr))
1100 (symbol-value (nth 1 expr)))))
1101 (push (nth 1 expr) olist)))))))
1102 (kill-buffer (current-buffer)))
1103 (when (setq olist (nreverse olist))
1104 (insert "------------------ Environment follows ------------------\n\n"))
1106 (if (boundp (car olist))
1108 (pp `(setq ,(car olist)
1109 ,(if (or (consp (setq sym (symbol-value (car olist))))
1111 (not (or (eq sym nil)
1113 (list 'quote (symbol-value (car olist)))
1114 (symbol-value (car olist))))
1117 (format "(setq %s 'whatever)\n" (car olist))))
1118 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1119 (setq olist (cdr olist)))
1121 ;; Remove any control chars - they seem to cause trouble for some
1122 ;; mailers. (Byte-compiled output from the stuff above.)
1124 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1125 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1128 ;;; Treatment of rejected articles.
1131 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1132 "Re-mail the current message.
1133 This only makes sense if the current message is a bounce message than
1134 contains some mail you have written which has been bounced back to
1136 If FETCH, try to fetch the article that this is a reply to, if indeed
1139 (gnus-summary-select-article t)
1140 (set-buffer gnus-original-article-buffer)
1141 (gnus-setup-message 'compose-bounce
1142 (let* ((references (mail-fetch-field "references"))
1143 (parent (and references (gnus-parent-id references))))
1145 ;; If there are references, we fetch the article we answered to.
1147 (gnus-summary-refer-article parent)
1148 (gnus-summary-show-all-headers)))))
1152 (defun gnus-inews-group-method (group)
1153 (cond ((and (null (gnus-get-info group))
1154 (eq (car gnus-message-archive-method)
1156 (gnus-server-to-method
1157 (gnus-group-method group)))))
1158 ;; If the group doesn't exist, we assume
1159 ;; it's an archive group...
1160 gnus-message-archive-method)
1162 ((gnus-info-method (gnus-get-info group))
1163 (gnus-info-method (gnus-get-info group)))
1165 (t (gnus-group-method group))))
1167 ;; Do Gcc handling, which copied the message over to some group.
1168 (defun gnus-inews-do-gcc (&optional gcc)
1172 (message-narrow-to-headers)
1173 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1174 (cur (current-buffer))
1175 groups group method group-art)
1177 (message-remove-header "gcc")
1179 (setq groups (message-unquote-tokens
1180 (message-tokenize-header gcc " ,")))
1181 ;; Copy the article over to some group(s).
1182 (while (setq group (pop groups))
1184 (setq method (gnus-inews-group-method group)))
1185 (unless (gnus-request-group group nil method)
1186 (gnus-request-create-group group method))
1188 (nnheader-set-temp-buffer " *acc*")
1189 (insert-buffer-substring cur)
1190 (message-encode-message-body)
1192 (message-narrow-to-headers)
1193 (let ((mail-parse-charset message-default-charset)
1194 (rfc2047-header-encoding-alist
1195 (cons '("Newsgroups" . default)
1196 rfc2047-header-encoding-alist)))
1197 (mail-encode-encoded-word-buffer)))
1198 (goto-char (point-min))
1199 (when (re-search-forward
1200 (concat "^" (regexp-quote mail-header-separator) "$")
1202 (replace-match "" t t ))
1203 (unless (setq group-art
1204 (gnus-request-accept-article group method t t))
1205 (gnus-message 1 "Couldn't store article in group %s: %s"
1206 group (gnus-status-message method))
1208 (when (and group-art gnus-inews-mark-gcc-as-read)
1209 (gnus-group-mark-article-read group (cdr group-art)))
1210 (kill-buffer (current-buffer)))))))))
1212 (defun gnus-inews-insert-gcc ()
1213 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1216 (message-narrow-to-headers)
1217 (let* ((group gnus-outgoing-message-group)
1219 ((gnus-functionp group)
1221 ((or (stringp group) (list group))
1225 (if (stringp gcc) gcc
1226 (mapconcat 'identity gcc " "))
1229 (defun gnus-inews-insert-archive-gcc (&optional group)
1230 "Insert the Gcc to say where the article is to be archived."
1231 (let* ((var gnus-message-archive-group)
1232 (group (or group gnus-newsgroup-name ""))
1234 (and gnus-newsgroup-name
1235 (not (equal gnus-newsgroup-name ""))
1236 (gnus-group-find-parameter
1237 gnus-newsgroup-name 'gcc-self)))
1241 ((null gnus-message-archive-method)
1245 ;; Just a single group.
1248 ;; We don't want this.
1250 ((and (listp var) (stringp (car var)))
1251 ;; A list of groups.
1253 ((gnus-functionp var)
1255 (funcall var group))
1257 ;; An alist of regexps/functions/forms.
1262 ((stringp (caar var))
1264 (when (string-match (caar var) group)
1266 ((gnus-functionp (car var))
1268 (funcall (car var) group))
1270 (eval (car var)))))))
1271 (setq var (cdr var)))
1274 (when (or groups gcc-self-val)
1275 (when (stringp groups)
1276 (setq groups (list groups)))
1279 (message-narrow-to-headers)
1280 (goto-char (point-max))
1283 ;; Use the `gcc-self' param value instead.
1286 (if (stringp gcc-self-val)
1289 (if (not (eq gcc-self-val 'none))
1294 ;; Use the list of groups.
1295 (while (setq name (pop groups))
1296 (insert (if (string-match ":" name)
1298 (gnus-group-prefixed-name
1299 name gnus-message-archive-method)))
1306 (defun gnus-configure-posting-styles ()
1307 "Configure posting styles according to `gnus-posting-styles'."
1308 (unless gnus-inhibit-posting-styles
1309 (let ((group (or gnus-newsgroup-name ""))
1310 (styles gnus-posting-styles)
1311 style match variable attribute value v results
1312 filep name address element)
1313 ;; If the group has a posting-style parameter, add it at the end with a
1314 ;; regexp matching everything, to be sure it takes precedence over all
1316 (when gnus-newsgroup-name
1317 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1319 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1320 ;; Go through all styles and look for matches.
1321 (dolist (style styles)
1322 (setq match (pop style))
1323 (goto-char (point-min))
1326 ;; Regexp string match on the group name.
1327 (string-match match group))
1329 (and (gnus-buffer-live-p gnus-article-copy)
1330 (with-current-buffer gnus-article-copy
1331 (let ((header (message-fetch-field (pop style))))
1333 (string-match (pop style) header))))))
1334 ((or (symbolp match)
1335 (gnus-functionp match))
1337 ((gnus-functionp match)
1338 ;; Function to be called.
1341 ;; Variable to be checked.
1342 (symbol-value match))))
1344 ;; This is a form to be evaled.
1346 ;; We have a match, so we set the variables.
1347 (dolist (attribute style)
1348 (setq element (pop attribute)
1353 ((eq (car attribute) :file)
1356 ((eq (car attribute) :value)
1360 ;; We get the value.
1365 ((or (symbolp value)
1366 (gnus-functionp value))
1367 (cond ((gnus-functionp value)
1370 (symbol-value value))))
1373 ;; Translate obsolescent value.
1374 (when (eq element 'signature-file)
1375 (setq element 'signature
1377 ;; Get the contents of file elems.
1379 (setq v (with-temp-buffer
1380 (insert-file-contents v)
1382 (setq results (delq (assoc element results) results))
1383 (push (cons element v) results))))
1384 ;; Now we have all the styles, so we insert them.
1385 (setq name (assq 'name results)
1386 address (assq 'address results))
1387 (setq results (delq name (delq address results)))
1388 (make-local-variable 'message-setup-hook)
1389 (dolist (result results)
1390 (add-hook 'message-setup-hook
1392 ((eq 'eval (car result))
1394 ((eq 'body (car result))
1398 (insert ,(cdr result)))))
1399 ((eq 'signature (car result))
1400 (set (make-local-variable 'message-signature) nil)
1401 (set (make-local-variable 'message-signature-file) nil)
1402 (if (not (cdr result))
1406 (let ((message-signature ,(cdr result)))
1407 (when message-signature
1408 (message-insert-signature)))))))
1411 (if (symbolp (car result))
1412 (capitalize (symbol-name (car result)))
1416 (message-remove-header ,header)
1417 (let ((value ,(cdr result)))
1420 (insert ,header ": " value "\n"))))))))))
1421 (when (or name address)
1422 (add-hook 'message-setup-hook
1424 (set (make-local-variable 'user-mail-address)
1425 ,(or (cdr address) user-mail-address))
1426 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1428 ,(or (cdr address) user-mail-address)))
1430 (message-remove-header "From")
1432 (insert "From: " (message-make-from) "\n")))))))))
1434 ;;; Allow redefinition of functions.
1440 ;;; gnus-msg.el ends here