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', Gnus will use the \"current\" select
41 method when posting. If it is nil (which is the default), 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 (defconst gnus-bug-message
151 "Sending a bug report to the Gnus Towers.
152 ========================================
154 The buffer below is a mail buffer. When you press `C-c C-c', it will
155 be sent to the Gnus Bug Exterminators.
157 The thing near the bottom of the buffer is how the environment
158 settings will be included in the mail. Please do not delete that.
159 They will tell the Bug People what your environment is, so that it
160 will be easier to locate the bugs.
162 If you have found a bug that makes Emacs go \"beep\", set
163 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
164 and include the backtrace in your bug report.
166 Please describe the bug in annoying, painstaking detail.
168 Thank you for your help in stamping out bugs.
172 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
173 (autoload 'news-setup "rnewspost")
174 (autoload 'news-reply-mode "rnewspost")
175 (autoload 'rmail-dont-reply-to "mail-utils")
176 (autoload 'rmail-output "rmailout"))
180 ;;; Gnus Posting Functions
183 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
184 "p" gnus-summary-post-news
185 "f" gnus-summary-followup
186 "F" gnus-summary-followup-with-original
187 "c" gnus-summary-cancel-article
188 "s" gnus-summary-supersede-article
189 "r" gnus-summary-reply
190 "y" gnus-summary-yank-message
191 "R" gnus-summary-reply-with-original
192 "w" gnus-summary-wide-reply
193 "W" gnus-summary-wide-reply-with-original
194 "n" gnus-summary-followup-to-mail
195 "N" gnus-summary-followup-to-mail-with-original
196 "m" gnus-summary-mail-other-window
197 "u" gnus-uu-post-news
198 "\M-c" gnus-summary-mail-crosspost-complaint
199 "om" gnus-summary-mail-forward
200 "op" gnus-summary-post-forward
201 "Om" gnus-uu-digest-mail-forward
202 "Op" gnus-uu-digest-post-forward)
204 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
205 "b" gnus-summary-resend-bounced-mail
206 ;; "c" gnus-summary-send-draft
207 "r" gnus-summary-resend-message)
209 ;;; Internal functions.
211 (defvar gnus-article-reply nil)
212 (defmacro gnus-setup-message (config &rest forms)
213 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
214 (buffer (make-symbol "gnus-setup-message-buffer"))
215 (article (make-symbol "gnus-setup-message-article"))
216 (group (make-symbol "gnus-setup-message-group")))
217 `(let ((,winconf (current-window-configuration))
218 (,buffer (buffer-name (current-buffer)))
219 (,article (and gnus-article-reply (gnus-summary-article-number)))
220 (,group gnus-newsgroup-name)
221 (message-header-setup-hook
222 (copy-sequence message-header-setup-hook))
223 (mbl mml-buffer-list)
224 (message-mode-hook (copy-sequence message-mode-hook)))
225 (setq mml-buffer-list nil)
226 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
227 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
228 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
232 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
233 (gnus-inews-insert-draft-meta-information ,group ,article)
234 (setq gnus-message-buffer (current-buffer))
235 (set (make-local-variable 'gnus-message-group-art)
236 (cons ,group ,article))
237 (set (make-local-variable 'gnus-newsgroup-name) ,group)
238 (gnus-run-hooks 'gnus-message-setup-hook)
239 (if (eq major-mode 'message-mode)
240 (let ((mbl1 mml-buffer-list))
241 (setq mml-buffer-list mbl) ;; Global value
242 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
243 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
244 (mml-destroy-buffers)
245 (setq mml-buffer-list mbl)))
247 (gnus-configure-windows ,config t)
248 (set-buffer-modified-p nil))))
250 (defun gnus-inews-insert-draft-meta-information (group article)
253 (not (string= group ""))
254 (not (message-fetch-field gnus-draft-meta-information-header)))
255 (goto-char (point-min))
256 (insert gnus-draft-meta-information-header ": (\"" group "\" "
257 (if article (number-to-string article) "\"\"") ")\n"))))
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 (defun gnus-button-mailto (address)
273 (set-buffer (gnus-copy-article-buffer))
274 (gnus-setup-message 'message
275 (message-reply address)))
278 (defun gnus-button-reply (&optional to-address wide)
279 "Like `message-reply'."
281 (gnus-setup-message 'message
282 (message-reply to-address wide)))
285 (define-mail-user-agent 'gnus-user-agent
286 'gnus-msg-mail 'message-send-and-exit
287 'message-kill-buffer 'message-send-hook)
289 (defun gnus-setup-posting-charset (group)
290 (let ((alist gnus-group-posting-charset-alist)
291 (group (or group ""))
295 (while (setq elem (pop alist))
296 (when (or (and (stringp (car elem))
297 (string-match (car elem) group))
298 (and (gnus-functionp (car elem))
299 (funcall (car elem) group))
300 (and (symbolp (car elem))
301 (symbol-value (car elem))))
302 (throw 'found (cons (cadr elem) (caddr elem)))))))))
304 (defun gnus-inews-add-send-actions (winconf buffer article)
305 (make-local-hook 'message-sent-hook)
306 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
307 'gnus-inews-do-gcc) nil t)
309 (make-local-hook 'message-header-hook)
310 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
311 (setq message-post-method
313 (gnus-post-method arg ,gnus-newsgroup-name)))
314 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
316 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
318 `(when (gnus-buffer-exists-p ,buffer)
322 `(gnus-summary-mark-article-as-replied ,article))))
325 (put 'gnus-setup-message 'lisp-indent-function 1)
326 (put 'gnus-setup-message 'edebug-form-spec '(form body))
328 ;;; Post news commands of Gnus group mode and summary mode
330 (defun gnus-group-mail (&optional arg)
331 "Start composing a mail.
332 If ARG, use the group under the point to find a posting style.
333 If ARG is 1, prompt for a group name to find the posting style."
335 ;; We can't `let' gnus-newsgroup-name here, since that leads
336 ;; to local variables leaking.
337 (let ((group gnus-newsgroup-name)
338 (buffer (current-buffer)))
341 (setq gnus-newsgroup-name
343 (if (= 1 (prefix-numeric-value arg))
344 (completing-read "Use posting style of group: "
345 gnus-active-hashtb nil
346 (gnus-read-active-file-p))
347 (gnus-group-group-name))
349 (gnus-setup-message 'message (message-mail)))
352 (setq gnus-newsgroup-name group)))))
354 (defun gnus-group-post-news (&optional arg)
355 "Start composing a news message.
356 If ARG, post to the group under point.
357 If ARG is 1, prompt for a group name."
359 ;; Bind this variable here to make message mode hooks work ok.
360 (let ((gnus-newsgroup-name
362 (if (= 1 (prefix-numeric-value arg))
363 (completing-read "Newsgroup: " gnus-active-hashtb nil
364 (gnus-read-active-file-p))
365 (gnus-group-group-name))
367 (gnus-post-news 'post gnus-newsgroup-name)))
369 (defun gnus-summary-post-news ()
370 "Start composing a news message."
372 (gnus-post-news 'post gnus-newsgroup-name))
374 (defun gnus-summary-followup (yank &optional force-news)
375 "Compose a followup to an article.
376 If prefix argument YANK is non-nil, original article is yanked automatically."
378 (list (and current-prefix-arg
379 (gnus-summary-work-articles 1))))
381 (gnus-summary-goto-subject (car yank)))
382 (save-window-excursion
383 (gnus-summary-select-article))
384 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
385 (gnus-newsgroup-name gnus-newsgroup-name))
387 (gnus-post-news nil gnus-newsgroup-name
388 headers gnus-article-buffer
389 yank nil force-news)))
391 (defun gnus-summary-followup-with-original (n &optional force-news)
392 "Compose a followup to an article and include the original article."
394 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
396 (defun gnus-summary-followup-to-mail (&optional arg)
397 "Followup to the current mail message via news."
399 (list (and current-prefix-arg
400 (gnus-summary-work-articles 1))))
401 (gnus-summary-followup arg t))
403 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
404 "Followup to the current mail message via news."
406 (gnus-summary-followup (gnus-summary-work-articles arg) t))
408 (defun gnus-inews-yank-articles (articles)
411 (while (setq article (pop articles))
412 (save-window-excursion
413 (set-buffer gnus-summary-buffer)
414 (gnus-summary-select-article nil nil nil article)
415 (gnus-summary-remove-process-mark article))
416 (gnus-copy-article-buffer)
417 (let ((message-reply-buffer gnus-article-copy)
418 (message-reply-headers
419 (with-current-buffer gnus-article-copy
420 ;; The headers are decoded.
421 (nnheader-parse-head t))))
422 (message-yank-original)
423 (setq beg (or beg (mark t))))
429 (defun gnus-summary-cancel-article (&optional n symp)
430 "Cancel an article you posted.
431 Uses the process-prefix convention. If given the symbolic
432 prefix `a', cancel using the standard posting method; if not
433 post using the current select method."
434 (interactive (gnus-interactive "P\ny"))
435 (let ((articles (gnus-summary-work-articles n))
438 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
440 (while (setq article (pop articles))
441 (when (gnus-summary-select-article t nil nil article)
442 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
443 (message-cancel-news))
444 (gnus-summary-mark-as-read article gnus-canceled-mark)
445 (gnus-cache-remove-article 1))
446 (gnus-article-hide-headers-if-wanted))
447 (gnus-summary-remove-process-mark article))))
449 (defun gnus-summary-supersede-article ()
450 "Compose an article that will supersede a previous article.
451 This is done simply by taking the old article and adding a Supersedes
452 header line with the old Message-ID."
454 (let ((article (gnus-summary-article-number)))
455 (gnus-setup-message 'reply-yank
456 (gnus-summary-select-article t)
457 (set-buffer gnus-original-article-buffer)
461 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
463 (set-buffer ,gnus-summary-buffer)
464 (gnus-cache-possibly-remove-article ,article nil nil nil t)
465 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
466 message-send-actions))))
470 (defun gnus-copy-article-buffer (&optional article-buffer)
471 ;; make a copy of the article buffer with all text properties removed
472 ;; this copy is in the buffer gnus-article-copy.
473 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
474 ;; this buffer should be passed to all mail/news reply/post routines.
475 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
477 (set-buffer gnus-article-copy)
478 (mm-enable-multibyte))
479 (let ((article-buffer (or article-buffer gnus-article-buffer))
481 (if (not (and (get-buffer article-buffer)
482 (gnus-buffer-exists-p article-buffer)))
483 (error "Can't find any article buffer")
485 (set-buffer article-buffer)
486 (let ((gnus-newsgroup-charset (or gnus-article-charset
487 gnus-newsgroup-charset))
488 (gnus-newsgroup-ignored-charsets
489 (or gnus-article-ignored-charsets
490 gnus-newsgroup-ignored-charsets)))
492 ;; Copy over the (displayed) article buffer, delete
493 ;; hidden text and remove text properties.
495 (copy-to-buffer gnus-article-copy (point-min) (point-max))
496 (set-buffer gnus-article-copy)
497 (gnus-article-delete-text-of-type 'annotation)
498 (gnus-remove-text-with-property 'gnus-prev)
499 (gnus-remove-text-with-property 'gnus-next)
502 (buffer-substring-no-properties (point-min) (point-max))
504 ;; Find the original headers.
505 (set-buffer gnus-original-article-buffer)
506 (goto-char (point-min))
507 (while (looking-at message-unix-mail-delimiter)
510 (setq end (or (search-forward "\n\n" nil t) (point)))
511 ;; Delete the headers from the displayed articles.
512 (set-buffer gnus-article-copy)
513 (delete-region (goto-char (point-min))
514 (or (search-forward "\n\n" nil t) (point-max)))
515 ;; Insert the original article headers.
516 (insert-buffer-substring gnus-original-article-buffer beg end)
517 (article-decode-encoded-words))))
520 (defun gnus-post-news (post &optional group header article-buffer yank subject
523 (gnus-copy-article-buffer))
524 (let ((gnus-article-reply article-buffer)
525 (add-to-list gnus-add-to-list))
526 (gnus-setup-message (cond (yank 'reply-yank)
527 (article-buffer 'reply)
529 (let* ((group (or group gnus-newsgroup-name))
530 (charset (gnus-group-name-charset nil group))
532 to-address to-group mailing-list to-list
535 (setq to-address (gnus-group-find-parameter group 'to-address)
536 to-group (gnus-group-find-parameter group 'to-group)
537 to-list (gnus-group-find-parameter group 'to-list)
538 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
539 mailing-list (when gnus-mailing-list-groups
540 (string-match gnus-mailing-list-groups group))
541 group (gnus-group-name-decode (gnus-group-real-name group)
543 (if (or (and to-group
544 (gnus-news-group-p to-group))
547 (and (gnus-news-group-p
548 (or pgroup gnus-newsgroup-name)
549 (if header (mail-header-number header)
550 gnus-current-article))
556 (message-news (or to-group group))
557 (set-buffer gnus-article-copy)
558 (gnus-msg-treat-broken-reply-to)
559 (message-followup (if (or newsgroup-p force-news) nil to-group)))
563 (message-mail (or to-address to-list))
564 ;; Arrange for mail groups that have no `to-address' to
565 ;; get that when the user sends off the mail.
566 (when (and (not to-list)
569 (push (list 'gnus-inews-add-to-address pgroup)
570 message-send-actions)))
571 (set-buffer gnus-article-copy)
572 (gnus-msg-treat-broken-reply-to)
573 (message-wide-reply to-address)))
575 (gnus-inews-yank-articles yank))))))
577 (defun gnus-msg-treat-broken-reply-to ()
578 "Remove the Reply-to header iff broken-reply-to."
579 (when (gnus-group-find-parameter
580 gnus-newsgroup-name 'broken-reply-to)
582 (message-narrow-to-head)
583 (message-remove-header "reply-to"))))
585 (defun gnus-post-method (arg group &optional silent)
586 "Return the posting method based on GROUP and ARG.
587 If SILENT, don't prompt the user."
588 (let ((group-method (gnus-find-method-for-group group)))
590 ;; If the group-method is nil (which shouldn't happen) we use
591 ;; the default method.
593 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
594 gnus-select-method message-post-method))
595 ;; We want the inverse of the default
596 ((and arg (not (eq arg 0)))
597 (if (eq gnus-post-method 'active)
600 ;; We query the user for a post method.
602 (and gnus-post-method
603 (not (eq gnus-post-method 'current))
604 (listp (car gnus-post-method))))
606 ;; Collect all methods we know about.
608 (when (and gnus-post-method
609 (not (eq gnus-post-method 'current)))
610 (if (listp (car gnus-post-method))
612 (list gnus-post-method)))
613 gnus-secondary-select-methods
614 (mapcar 'cdr gnus-server-alist)
615 (mapcar 'car gnus-opened-servers)
616 (list gnus-select-method)
617 (list group-method)))
618 method-alist post-methods method)
619 ;; Weed out all mail methods.
621 (setq method (gnus-server-get-method "" (pop methods)))
622 (when (and (or (gnus-method-option-p method 'post)
623 (gnus-method-option-p method 'post-mail))
624 (not (member method post-methods)))
625 (push method post-methods)))
626 ;; Create a name-method alist.
630 (if (equal (cadr m) "")
631 (list (symbol-name (car m)) m)
632 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
637 (setq gnus-last-posting-server
639 gnus-last-posting-server)
640 ;; Just use the last value.
641 gnus-last-posting-server
643 "Posting method: " method-alist nil t
644 (cons (or gnus-last-posting-server "") 0))))
646 ;; Override normal method.
647 ((and (eq gnus-post-method 'current)
648 (not (eq (car group-method) 'nndraft))
649 (gnus-get-function group-method 'request-post t)
652 ((and gnus-post-method
653 (not (eq gnus-post-method 'current)))
655 ;; Use the normal select method.
656 (t gnus-select-method))))
660 ;; Dummies to avoid byte-compile warning.
662 (defvar nnspool-rejected-article-hook)
663 (defvar xemacs-codename))
665 (defun gnus-extended-version ()
666 "Stringified Gnus version and Emacs version."
669 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
670 " (" gnus-version ")"
673 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
674 (concat "Emacs/" (match-string 1 emacs-version)))
675 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
677 (concat (match-string 1 emacs-version)
678 (format "/%d.%d" emacs-major-version emacs-minor-version)
679 (if (match-beginning 3)
680 (match-string 3 emacs-version)
682 (if (boundp 'xemacs-codename)
683 (concat " (" xemacs-codename ")")
689 ;;; Gnus Mail Functions
692 ;;; Mail reply commands of Gnus summary mode
694 (defun gnus-summary-reply (&optional yank wide)
695 "Start composing a reply mail to the current message.
696 If prefix argument YANK is non-nil, the original article is yanked
699 (list (and current-prefix-arg
700 (gnus-summary-work-articles 1))))
701 ;; Stripping headers should be specified with mail-yank-ignored-headers.
703 (gnus-summary-goto-subject (car yank)))
704 (let ((gnus-article-reply t))
705 (gnus-setup-message (if yank 'reply-yank 'reply)
706 (gnus-summary-select-article)
707 (set-buffer (gnus-copy-article-buffer))
708 (gnus-msg-treat-broken-reply-to)
710 (message-narrow-to-head)
711 (goto-char (point-max)))
712 (mml-quote-region (point) (point-max))
713 (message-reply nil wide)
715 (gnus-inews-yank-articles yank)))))
717 (defun gnus-summary-reply-with-original (n &optional wide)
718 "Start composing a reply mail to the current message.
719 The original article will be yanked."
721 (gnus-summary-reply (gnus-summary-work-articles n) wide))
723 (defun gnus-summary-wide-reply (&optional yank)
724 "Start composing a wide reply mail to the current message.
725 If prefix argument YANK is non-nil, the original article is yanked
728 (list (and current-prefix-arg
729 (gnus-summary-work-articles 1))))
730 (gnus-summary-reply yank t))
732 (defun gnus-summary-wide-reply-with-original (n)
733 "Start composing a wide reply mail to the current message.
734 The original article will be yanked."
736 (gnus-summary-reply-with-original n t))
738 (defun gnus-summary-mail-forward (&optional arg post)
739 "Forward the current message to another user.
740 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
741 if ARG is 1, decode the message and forward directly inline;
742 if ARG is 2, forward message as an rfc822 MIME section;
743 if ARG is 3, decode message and forward as an rfc822 MIME section;
744 if ARG is 4, forward message directly inline;
745 otherwise, use flipped `message-forward-as-mime'.
746 If POST, post instead of mail."
748 (let ((message-forward-as-mime message-forward-as-mime)
749 (message-forward-show-mml message-forward-show-mml))
752 ((eq arg 1) (setq message-forward-as-mime nil
753 message-forward-show-mml t))
754 ((eq arg 2) (setq message-forward-as-mime t
755 message-forward-show-mml nil))
756 ((eq arg 3) (setq message-forward-as-mime t
757 message-forward-show-mml t))
758 ((eq arg 4) (setq message-forward-as-mime nil
759 message-forward-show-mml nil))
760 (t (setq message-forward-as-mime (not message-forward-as-mime))))
761 (gnus-setup-message 'forward
762 (gnus-summary-select-article)
763 (let ((mail-parse-charset gnus-newsgroup-charset)
764 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
765 (set-buffer gnus-original-article-buffer)
766 (message-forward post)))))
768 (defun gnus-summary-resend-message (address n)
769 "Resend the current article to ADDRESS."
771 (list (message-read-from-minibuffer "Resend message(s) to: ")
773 (let ((articles (gnus-summary-work-articles n))
775 (while (setq article (pop articles))
776 (gnus-summary-select-article nil nil nil article)
778 (set-buffer gnus-original-article-buffer)
779 (message-resend address)))))
781 (defun gnus-summary-post-forward (&optional arg)
782 "Forward the current article to a newsgroup.
783 See `gnus-summary-mail-forward' for ARG."
785 (gnus-summary-mail-forward arg t))
787 (defvar gnus-nastygram-message
788 "The following article was inappropriately posted to %s.\n\n"
789 "Format string to insert in nastygrams.
790 The current group name will be inserted at \"%s\".")
792 (defun gnus-summary-mail-nastygram (n)
793 "Send a nastygram to the author of the current article."
795 (when (or gnus-expert-user
797 "Really send a nastygram to the author of the current article? "))
798 (let ((group gnus-newsgroup-name))
799 (gnus-summary-reply-with-original n)
800 (set-buffer gnus-message-buffer)
802 (insert (format gnus-nastygram-message group))
803 (message-send-and-exit))))
805 (defun gnus-summary-mail-crosspost-complaint (n)
806 "Send a complaint about crossposting to the current article(s)."
808 (let ((articles (gnus-summary-work-articles n))
810 (while (setq article (pop articles))
811 (set-buffer gnus-summary-buffer)
812 (gnus-summary-goto-subject article)
813 (let ((group (gnus-group-real-name gnus-newsgroup-name))
814 newsgroups followup-to)
815 (gnus-summary-select-article)
816 (set-buffer gnus-original-article-buffer)
817 (if (and (<= (length (message-tokenize-header
819 (mail-fetch-field "newsgroups"))
822 (or (not (setq followup-to (mail-fetch-field "followup-to")))
823 (not (member group (message-tokenize-header
824 followup-to ", ")))))
826 (gnus-message 1 "Followup-to restricted")
827 (gnus-message 1 "Not a crossposted article"))
828 (set-buffer gnus-summary-buffer)
829 (gnus-summary-reply-with-original 1)
830 (set-buffer gnus-message-buffer)
832 (insert (format gnus-crosspost-complaint newsgroups group))
833 (message-goto-subject)
834 (re-search-forward " *$")
835 (replace-match " (crosspost notification)" t t)
836 (gnus-deactivate-mark)
837 (when (gnus-y-or-n-p "Send this complaint? ")
838 (message-send-and-exit)))))))
840 (defun gnus-summary-mail-other-window ()
841 "Compose mail in other window."
843 (gnus-setup-message 'message
846 (defun gnus-mail-parse-comma-list ()
849 (skip-chars-forward " ")
852 (skip-chars-forward "^,")
857 (narrow-to-region beg (point))
860 (while (search-forward "\"" nil t)
864 (skip-chars-forward ",")
865 (skip-chars-forward "^,"))
866 (skip-chars-backward " ")
867 (push (buffer-substring beg (point))
869 (skip-chars-forward "^,")
870 (skip-chars-forward ", "))
873 (defun gnus-inews-add-to-address (group)
874 (let ((to-address (mail-fetch-field "to")))
875 (when (and to-address
877 ;; This mail group doesn't have a `to-list', so we add one
880 (format "Do you want to add this as `to-list': %s " to-address))
881 (gnus-group-add-parameter group (cons 'to-list to-address))))))
883 (defun gnus-put-message ()
884 "Put the current message in some group and return to Gnus."
886 (let ((reply gnus-article-reply)
887 (winconf gnus-prev-winconf)
888 (group gnus-newsgroup-name))
890 (or (and group (not (gnus-group-read-only-p group)))
891 (setq group (read-string "Put in group: " nil
892 (gnus-writable-groups))))
893 (when (gnus-gethash group gnus-newsrc-hashtb)
894 (error "No such group: %s" group))
899 (message-narrow-to-headers)
900 (let (gnus-deletable-headers)
902 (message-generate-headers message-required-news-headers)
903 (message-generate-headers message-required-mail-headers)))
904 (goto-char (point-max))
905 (insert "Gcc: " group "\n")
910 (when (get-buffer gnus-group-buffer)
911 (when (gnus-buffer-exists-p (car-safe reply))
912 (set-buffer (car reply))
914 (gnus-summary-mark-article-as-replied
917 (set-window-configuration winconf)))))
919 (defun gnus-article-mail (yank)
920 "Send a reply to the address near point.
921 If YANK is non-nil, include the original article."
925 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
926 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
928 (message-reply address)
930 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
932 (defvar nntp-server-type)
934 "Send a bug report to the Gnus maintainers."
936 (unless (gnus-alive-p)
937 (error "Gnus has been shut down"))
938 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
939 (unless (message-mail-user-agent)
940 (delete-other-windows)
941 (when gnus-bug-create-help-buffer
942 (switch-to-buffer "*Gnus Help Bug*")
944 (insert gnus-bug-message)
945 (goto-char (point-min)))
946 (message-pop-to-buffer "*Gnus Bug*"))
947 (let ((message-this-is-mail t))
948 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
949 (when gnus-bug-create-help-buffer
950 (push `(gnus-bug-kill-buffer) message-send-actions))
951 (goto-char (point-min))
952 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
954 (insert (gnus-version) "\n"
955 (emacs-version) "\n")
956 (when (and (boundp 'nntp-server-type)
957 (stringp nntp-server-type))
958 (insert nntp-server-type))
959 (insert "\n\n\n\n\n")
962 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
964 (setq text (buffer-string)))
965 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
966 (goto-char (point-min))
967 (search-forward "Subject: " nil t)
970 (defun gnus-bug-kill-buffer ()
971 (when (get-buffer "*Gnus Help Bug*")
972 (kill-buffer "*Gnus Help Bug*")))
974 (defun gnus-summary-yank-message (buffer n)
975 "Yank the current article into a composed message."
977 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
979 (gnus-summary-iterate n
980 (let ((gnus-display-mime-function nil)
981 (gnus-inhibit-treatment t))
982 (gnus-summary-select-article))
985 (message-yank-buffer gnus-article-buffer))))
988 "Attempts to go through the Gnus source file and report what variables have been changed.
989 The source file has to be in the Emacs load path."
991 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
992 "gnus-art.el" "gnus-start.el" "gnus-async.el"
993 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
994 "nnmail.el" "message.el"))
997 (gnus-message 4 "Please wait while we snoop your variables...")
999 ;; Go through all the files looking for non-default values for variables.
1001 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1004 (when (and (setq file (locate-library (pop files)))
1005 (file-exists-p file))
1006 (insert-file-contents file)
1007 (goto-char (point-min))
1008 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1009 (gnus-message 4 "Malformed sources in file %s" file)
1010 (narrow-to-region (point-min) (point))
1011 (goto-char (point-min))
1012 (while (setq expr (ignore-errors (read (current-buffer))))
1014 (and (or (eq (car expr) 'defvar)
1015 (eq (car expr) 'defcustom))
1016 (stringp (nth 3 expr))
1017 (or (not (boundp (nth 1 expr)))
1018 (not (equal (eval (nth 2 expr))
1019 (symbol-value (nth 1 expr)))))
1020 (push (nth 1 expr) olist)))))))
1021 (kill-buffer (current-buffer)))
1022 (when (setq olist (nreverse olist))
1023 (insert "------------------ Environment follows ------------------\n\n"))
1025 (if (boundp (car olist))
1027 (pp `(setq ,(car olist)
1028 ,(if (or (consp (setq sym (symbol-value (car olist))))
1030 (not (or (eq sym nil)
1032 (list 'quote (symbol-value (car olist)))
1033 (symbol-value (car olist))))
1036 (format "(setq %s 'whatever)\n" (car olist))))
1037 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1038 (setq olist (cdr olist)))
1040 ;; Remove any control chars - they seem to cause trouble for some
1041 ;; mailers. (Byte-compiled output from the stuff above.)
1043 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1044 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1047 ;;; Treatment of rejected articles.
1050 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1051 "Re-mail the current message.
1052 This only makes sense if the current message is a bounce message than
1053 contains some mail you have written which has been bounced back to
1055 If FETCH, try to fetch the article that this is a reply to, if indeed
1058 (gnus-summary-select-article t)
1059 (set-buffer gnus-original-article-buffer)
1060 (gnus-setup-message 'compose-bounce
1061 (let* ((references (mail-fetch-field "references"))
1062 (parent (and references (gnus-parent-id references))))
1064 ;; If there are references, we fetch the article we answered to.
1066 (gnus-summary-refer-article parent)
1067 (gnus-summary-show-all-headers)))))
1071 (defun gnus-inews-group-method (group)
1072 (cond ((and (null (gnus-get-info group))
1073 (eq (car gnus-message-archive-method)
1075 (gnus-server-to-method
1076 (gnus-group-method group)))))
1077 ;; If the group doesn't exist, we assume
1078 ;; it's an archive group...
1079 gnus-message-archive-method)
1081 ((gnus-info-method (gnus-get-info group))
1082 (gnus-info-method (gnus-get-info group)))
1084 (t (gnus-group-method group))))
1086 ;; Do Gcc handling, which copied the message over to some group.
1087 (defun gnus-inews-do-gcc (&optional gcc)
1089 (when (gnus-alive-p)
1092 (message-narrow-to-headers)
1093 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1094 (cur (current-buffer))
1095 groups group method group-art)
1097 (message-remove-header "gcc")
1099 (setq groups (message-unquote-tokens
1100 (message-tokenize-header gcc " ,")))
1101 ;; Copy the article over to some group(s).
1102 (while (setq group (pop groups))
1104 (setq method (gnus-inews-group-method group)))
1105 (unless (gnus-request-group group t method)
1106 (gnus-request-create-group group method))
1108 (nnheader-set-temp-buffer " *acc*")
1109 (insert-buffer-substring cur)
1110 (message-encode-message-body)
1112 (message-narrow-to-headers)
1113 (let ((mail-parse-charset message-default-charset)
1114 (rfc2047-header-encoding-alist
1115 (cons '("Newsgroups" . default)
1116 rfc2047-header-encoding-alist)))
1117 (mail-encode-encoded-word-buffer)))
1118 (goto-char (point-min))
1119 (when (re-search-forward
1120 (concat "^" (regexp-quote mail-header-separator) "$")
1122 (replace-match "" t t ))
1123 (unless (setq group-art
1124 (gnus-request-accept-article group method t t))
1125 (gnus-message 1 "Couldn't store article in group %s: %s"
1126 group (gnus-status-message method))
1128 (when (and group-art gnus-inews-mark-gcc-as-read)
1129 (let ((active (gnus-active group)))
1131 (if (< (cdr active) (cdr group-art))
1132 (gnus-set-active group (cons (car active)
1134 (gnus-activate-group group)))
1135 (let ((buffer (gnus-summary-buffer-name group))
1136 (mark gnus-read-mark)
1137 (article (cdr group-art)))
1141 (with-current-buffer buffer
1142 (when gnus-newsgroup-prepared
1143 (when (and gnus-newsgroup-auto-expire
1144 (memq mark gnus-auto-expirable-marks))
1145 (setq mark gnus-expirable-mark))
1146 (setq mark (gnus-request-update-mark
1147 group article mark))
1148 (gnus-mark-article-as-read article mark)
1149 (setq gnus-newsgroup-active (gnus-active group))
1151 (gnus-group-make-articles-read group
1153 (when (gnus-group-auto-expirable-p group)
1154 (gnus-add-marked-articles
1155 group 'expire (list article))))))
1156 (kill-buffer (current-buffer))))))))))
1158 (defun gnus-inews-insert-gcc ()
1159 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1162 (message-narrow-to-headers)
1163 (let* ((group gnus-outgoing-message-group)
1165 ((gnus-functionp group)
1167 ((or (stringp group) (list group))
1171 (if (stringp gcc) gcc
1172 (mapconcat 'identity gcc " "))
1175 (defun gnus-inews-insert-archive-gcc (&optional group)
1176 "Insert the Gcc to say where the article is to be archived."
1177 (let* ((var gnus-message-archive-group)
1178 (group (or group gnus-newsgroup-name ""))
1180 (and gnus-newsgroup-name
1181 (not (equal gnus-newsgroup-name ""))
1182 (gnus-group-find-parameter
1183 gnus-newsgroup-name 'gcc-self)))
1187 ((null gnus-message-archive-method)
1191 ;; Just a single group.
1194 ;; We don't want this.
1196 ((and (listp var) (stringp (car var)))
1197 ;; A list of groups.
1199 ((gnus-functionp var)
1201 (funcall var group))
1203 ;; An alist of regexps/functions/forms.
1208 ((stringp (caar var))
1210 (when (string-match (caar var) group)
1212 ((gnus-functionp (car var))
1214 (funcall (car var) group))
1216 (eval (car var)))))))
1217 (setq var (cdr var)))
1220 (when (or groups gcc-self-val)
1221 (when (stringp groups)
1222 (setq groups (list groups)))
1225 (message-narrow-to-headers)
1226 (goto-char (point-max))
1229 ;; Use the `gcc-self' param value instead.
1232 (if (stringp gcc-self-val)
1235 (if (not (eq gcc-self-val 'none))
1240 ;; Use the list of groups.
1241 (while (setq name (pop groups))
1242 (insert (if (string-match ":" name)
1244 (gnus-group-prefixed-name
1245 name gnus-message-archive-method)))
1252 (defun gnus-configure-posting-styles ()
1253 "Configure posting styles according to `gnus-posting-styles'."
1254 (unless gnus-inhibit-posting-styles
1255 (let ((group (or gnus-newsgroup-name ""))
1256 (styles gnus-posting-styles)
1257 style match variable attribute value v results
1258 filep name address element)
1259 ;; If the group has a posting-style parameter, add it at the end with a
1260 ;; regexp matching everything, to be sure it takes precedence over all
1262 (when gnus-newsgroup-name
1263 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1265 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1266 ;; Go through all styles and look for matches.
1267 (dolist (style styles)
1268 (setq match (pop style))
1269 (goto-char (point-min))
1272 ;; Regexp string match on the group name.
1273 (string-match match group))
1275 (let ((header (message-fetch-field (pop style))))
1277 (string-match (pop style) header))))
1278 ((or (symbolp match)
1279 (gnus-functionp match))
1281 ((gnus-functionp match)
1282 ;; Function to be called.
1285 ;; Variable to be checked.
1286 (symbol-value match))))
1288 ;; This is a form to be evaled.
1290 ;; We have a match, so we set the variables.
1291 (dolist (attribute style)
1292 (setq element (pop attribute)
1297 ((eq (car attribute) :file)
1300 ((eq (car attribute) :value)
1304 ;; We get the value.
1309 ((or (symbolp value)
1310 (gnus-functionp value))
1311 (cond ((gnus-functionp value)
1314 (symbol-value value))))
1317 ;; Translate obsolescent value.
1318 (when (eq element 'signature-file)
1319 (setq element 'signature
1321 ;; Get the contents of file elems.
1323 (setq v (with-temp-buffer
1324 (insert-file-contents v)
1326 (setq results (delq (assoc element results) results))
1327 (push (cons element v) results))))
1328 ;; Now we have all the styles, so we insert them.
1329 (setq name (assq 'name results)
1330 address (assq 'address results))
1331 (setq results (delq name (delq address results)))
1332 (make-local-variable 'message-setup-hook)
1333 (dolist (result results)
1334 (add-hook 'message-setup-hook
1336 ((eq 'eval (car result))
1338 ((eq 'body (car result))
1342 (insert ,(cdr result)))))
1343 ((eq 'signature (car result))
1344 (set (make-local-variable 'message-signature) nil)
1345 (set (make-local-variable 'message-signature-file) nil)
1346 (if (not (cdr result))
1350 (let ((message-signature ,(cdr result)))
1351 (when message-signature
1352 (message-insert-signature)))))))
1355 (if (symbolp (car result))
1356 (capitalize (symbol-name (car result)))
1360 (message-remove-header ,header)
1361 (let ((value ,(cdr result)))
1364 (insert ,header ": " value "\n"))))))))))
1365 (when (or name address)
1366 (add-hook 'message-setup-hook
1368 (set (make-local-variable 'user-mail-address)
1369 ,(or (cdr address) user-mail-address))
1370 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1372 ,(or (cdr address) user-mail-address)))
1374 (message-remove-header "From")
1376 (insert "From: " (message-make-from) "\n")))))))))
1378 ;;; Allow redefinition of functions.
1384 ;;; gnus-msg.el ends here