1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
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 (defcustom gnus-group-posting-charset-alist
105 '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
106 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
107 (message-this-is-mail nil nil)
108 (message-this-is-news nil t))
109 "Alist of regexps and permitted unencoded charsets for posting.
110 Each element of the alist has the form (TEST HEADER BODY-LIST), where
111 TEST is either a regular expression matching the newsgroup header or a
113 HEADER is the charset which may be left unencoded in the header (nil
114 means encode all charsets),
115 BODY-LIST is a list of charsets which may be encoded using 8bit
116 content-transfer encoding in the body, or one of the special values
117 nil (always encode using quoted-printable) or t (always use 8bit).
119 Note that any value other than nil for HEADER infringes some RFCs, so
120 use this option with care."
121 :type '(repeat (list :tag "Permitted unencoded charsets"
123 (regexp :tag "Group")
124 (const :tag "Mail message" :value message-this-is-mail)
125 (const :tag "News article" :value message-this-is-news))
126 (choice :tag "Header"
127 (const :tag "None" nil)
128 (symbol :tag "Charset"))
130 (const :tag "Any" :value t)
131 (const :tag "None" :value nil)
132 (repeat :tag "Charsets"
133 (symbol :tag "Charset")))))
134 :group 'gnus-charset)
136 ;;; Internal variables.
138 (defvar gnus-inhibit-posting-styles nil
139 "Inhibit the use of posting styles.")
141 (defvar gnus-message-buffer "*Mail Gnus*")
142 (defvar gnus-article-copy nil)
143 (defvar gnus-last-posting-server nil)
144 (defvar gnus-message-group-art nil)
146 (defconst gnus-bug-message
147 "Sending a bug report to the Gnus Towers.
148 ========================================
150 The buffer below is a mail buffer. When you press `C-c C-c', it will
151 be sent to the Gnus Bug Exterminators.
153 The thing near the bottom of the buffer is how the environment
154 settings will be included in the mail. Please do not delete that.
155 They will tell the Bug People what your environment is, so that it
156 will be easier to locate the bugs.
158 If you have found a bug that makes Emacs go \"beep\", set
159 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
160 and include the backtrace in your bug report.
162 Please describe the bug in annoying, painstaking detail.
164 Thank you for your help in stamping out bugs.
168 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
169 (autoload 'news-setup "rnewspost")
170 (autoload 'news-reply-mode "rnewspost")
171 (autoload 'rmail-dont-reply-to "mail-utils")
172 (autoload 'rmail-output "rmailout"))
176 ;;; Gnus Posting Functions
179 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
180 "p" gnus-summary-post-news
181 "f" gnus-summary-followup
182 "F" gnus-summary-followup-with-original
183 "c" gnus-summary-cancel-article
184 "s" gnus-summary-supersede-article
185 "r" gnus-summary-reply
186 "y" gnus-summary-yank-message
187 "R" gnus-summary-reply-with-original
188 "w" gnus-summary-wide-reply
189 "W" gnus-summary-wide-reply-with-original
190 "n" gnus-summary-followup-to-mail
191 "N" gnus-summary-followup-to-mail-with-original
192 "m" gnus-summary-mail-other-window
193 "u" gnus-uu-post-news
194 "\M-c" gnus-summary-mail-crosspost-complaint
195 "om" gnus-summary-mail-forward
196 "op" gnus-summary-post-forward
197 "Om" gnus-uu-digest-mail-forward
198 "Op" gnus-uu-digest-post-forward)
200 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
201 "b" gnus-summary-resend-bounced-mail
202 ;; "c" gnus-summary-send-draft
203 "r" gnus-summary-resend-message)
205 ;;; Internal functions.
207 (defvar gnus-article-reply nil)
208 (defmacro gnus-setup-message (config &rest forms)
209 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
210 (buffer (make-symbol "gnus-setup-message-buffer"))
211 (article (make-symbol "gnus-setup-message-article"))
212 (group (make-symbol "gnus-setup-message-group")))
213 `(let ((,winconf (current-window-configuration))
214 (,buffer (buffer-name (current-buffer)))
215 (,article (and gnus-article-reply (gnus-summary-article-number)))
216 (,group gnus-newsgroup-name)
217 (message-header-setup-hook
218 (copy-sequence message-header-setup-hook))
219 (mbl mml-buffer-list)
220 (message-mode-hook (copy-sequence message-mode-hook)))
221 (setq mml-buffer-list nil)
222 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
223 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
224 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
228 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
229 (setq gnus-message-buffer (current-buffer))
230 (set (make-local-variable 'gnus-message-group-art)
231 (cons ,group ,article))
232 (set (make-local-variable 'gnus-newsgroup-name) ,group)
233 (gnus-run-hooks 'gnus-message-setup-hook)
234 (if (eq major-mode 'message-mode)
235 ;; Make mml-buffer-list local.
236 ;; Restore global mml-buffer-list value as mbl.
237 ;; What a hack! -- Shenghuo
238 (let ((mml-buffer-list mml-buffer-list))
239 (setq mml-buffer-list mbl)
240 (make-local-variable 'mml-buffer-list)
241 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
242 (mml-destroy-buffers)
243 (setq mml-buffer-list mbl)))
245 (gnus-configure-windows ,config t)
246 (set-buffer-modified-p nil))))
248 (defun gnus-setup-posting-charset (group)
249 (let ((alist gnus-group-posting-charset-alist)
250 (group (or group ""))
254 (while (setq elem (pop alist))
255 (when (or (and (stringp (car elem))
256 (string-match (car elem) group))
257 (and (gnus-functionp (car elem))
258 (funcall (car elem) group))
259 (and (symbolp (car elem))
260 (symbol-value (car elem))))
261 (throw 'found (cons (cadr elem) (caddr elem)))))))))
263 (defun gnus-inews-add-send-actions (winconf buffer article)
264 (make-local-hook 'message-sent-hook)
265 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
266 (setq message-post-method
268 (gnus-post-method arg ,gnus-newsgroup-name)))
269 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
271 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
273 `(when (gnus-buffer-exists-p ,buffer)
277 `(gnus-summary-mark-article-as-replied ,article))))
280 (put 'gnus-setup-message 'lisp-indent-function 1)
281 (put 'gnus-setup-message 'edebug-form-spec '(form body))
283 ;;; Post news commands of Gnus group mode and summary mode
285 (defun gnus-group-mail (&optional arg)
286 "Start composing a mail.
287 If ARG, use the group under the point to find a posting style.
288 If ARG is 1, prompt for a group name to find the posting style."
290 ;; We can't `let' gnus-newsgroup-name here, since that leads
291 ;; to local variables leaking.
292 (let ((group gnus-newsgroup-name)
293 (buffer (current-buffer)))
296 (setq gnus-newsgroup-name
298 (if (= 1 (prefix-numeric-value arg))
299 (completing-read "Use posting style of group: "
300 gnus-active-hashtb nil
301 (gnus-read-active-file-p))
302 (gnus-group-group-name))
304 (gnus-setup-message 'message (message-mail)))
307 (setq gnus-newsgroup-name group)))))
309 (defun gnus-group-post-news (&optional arg)
310 "Start composing a news message.
311 If ARG, post to the group under point.
312 If ARG is 1, prompt for a group name."
314 ;; Bind this variable here to make message mode hooks work ok.
315 (let ((gnus-newsgroup-name
317 (if (= 1 (prefix-numeric-value arg))
318 (completing-read "Newsgroup: " gnus-active-hashtb nil
319 (gnus-read-active-file-p))
320 (gnus-group-group-name))
322 (gnus-post-news 'post gnus-newsgroup-name)))
324 (defun gnus-summary-post-news ()
325 "Start composing a news message."
327 (gnus-post-news 'post gnus-newsgroup-name))
329 (defun gnus-summary-followup (yank &optional force-news)
330 "Compose a followup to an article.
331 If prefix argument YANK is non-nil, original article is yanked automatically."
333 (list (and current-prefix-arg
334 (gnus-summary-work-articles 1))))
336 (gnus-summary-goto-subject (car yank)))
337 (save-window-excursion
338 (gnus-summary-select-article))
339 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
340 (gnus-newsgroup-name gnus-newsgroup-name))
342 (gnus-post-news nil gnus-newsgroup-name
343 headers gnus-article-buffer
344 yank nil force-news)))
346 (defun gnus-summary-followup-with-original (n &optional force-news)
347 "Compose a followup to an article and include the original article."
349 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
351 (defun gnus-summary-followup-to-mail (&optional arg)
352 "Followup to the current mail message via news."
354 (list (and current-prefix-arg
355 (gnus-summary-work-articles 1))))
356 (gnus-summary-followup arg t))
358 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
359 "Followup to the current mail message via news."
361 (gnus-summary-followup (gnus-summary-work-articles arg) t))
363 (defun gnus-inews-yank-articles (articles)
366 (while (setq article (pop articles))
367 (save-window-excursion
368 (set-buffer gnus-summary-buffer)
369 (gnus-summary-select-article nil nil nil article)
370 (gnus-summary-remove-process-mark article))
371 (gnus-copy-article-buffer)
372 (let ((message-reply-buffer gnus-article-copy)
373 (message-reply-headers gnus-current-headers))
374 (message-yank-original)
375 (setq beg (or beg (mark t))))
381 (defun gnus-summary-cancel-article (&optional n symp)
382 "Cancel an article you posted.
383 Uses the process-prefix convention. If given the symbolic
384 prefix `a', cancel using the standard posting method; if not
385 post using the current select method."
386 (interactive (gnus-interactive "P\ny"))
387 (let ((articles (gnus-summary-work-articles n))
390 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
392 (while (setq article (pop articles))
393 (when (gnus-summary-select-article t nil nil article)
394 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
395 (message-cancel-news))
396 (gnus-summary-mark-as-read article gnus-canceled-mark)
397 (gnus-cache-remove-article 1))
398 (gnus-article-hide-headers-if-wanted))
399 (gnus-summary-remove-process-mark article))))
401 (defun gnus-summary-supersede-article ()
402 "Compose an article that will supersede a previous article.
403 This is done simply by taking the old article and adding a Supersedes
404 header line with the old Message-ID."
406 (let ((article (gnus-summary-article-number)))
407 (gnus-setup-message 'reply-yank
408 (gnus-summary-select-article t)
409 (set-buffer gnus-original-article-buffer)
413 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
415 (set-buffer ,gnus-summary-buffer)
416 (gnus-cache-possibly-remove-article ,article nil nil nil t)
417 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
418 message-send-actions))))
422 (defun gnus-copy-article-buffer (&optional article-buffer)
423 ;; make a copy of the article buffer with all text properties removed
424 ;; this copy is in the buffer gnus-article-copy.
425 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
426 ;; this buffer should be passed to all mail/news reply/post routines.
427 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
429 (set-buffer gnus-article-copy)
430 (mm-enable-multibyte))
431 (let ((article-buffer (or article-buffer gnus-article-buffer))
433 (if (not (and (get-buffer article-buffer)
434 (gnus-buffer-exists-p article-buffer)))
435 (error "Can't find any article buffer")
437 (set-buffer article-buffer)
439 ;; Copy over the (displayed) article buffer, delete
440 ;; hidden text and remove text properties.
442 (copy-to-buffer gnus-article-copy (point-min) (point-max))
443 (set-buffer gnus-article-copy)
444 (gnus-article-delete-text-of-type 'annotation)
445 (gnus-remove-text-with-property 'gnus-prev)
446 (gnus-remove-text-with-property 'gnus-next)
449 (format "%s" (buffer-string))
451 ;; Find the original headers.
452 (set-buffer gnus-original-article-buffer)
453 (goto-char (point-min))
454 (while (looking-at message-unix-mail-delimiter)
457 (setq end (or (search-forward "\n\n" nil t) (point)))
458 ;; Delete the headers from the displayed articles.
459 (set-buffer gnus-article-copy)
460 (delete-region (goto-char (point-min))
461 (or (search-forward "\n\n" nil t) (point-max)))
462 ;; Insert the original article headers.
463 (insert-buffer-substring gnus-original-article-buffer beg end)
464 (article-decode-encoded-words)))
467 (defun gnus-post-news (post &optional group header article-buffer yank subject
470 (gnus-copy-article-buffer))
471 (let ((gnus-article-reply article-buffer)
472 (add-to-list gnus-add-to-list))
473 (gnus-setup-message (cond (yank 'reply-yank)
474 (article-buffer 'reply)
476 (let* ((group (or group gnus-newsgroup-name))
477 (charset (gnus-group-name-charset nil group))
479 to-address to-group mailing-list to-list
482 (setq to-address (gnus-group-find-parameter group 'to-address)
483 to-group (gnus-group-find-parameter group 'to-group)
484 to-list (gnus-group-find-parameter group 'to-list)
485 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
486 mailing-list (when gnus-mailing-list-groups
487 (string-match gnus-mailing-list-groups group))
488 group (gnus-group-name-decode (gnus-group-real-name group)
490 (if (or (and to-group
491 (gnus-news-group-p to-group))
494 (and (gnus-news-group-p
495 (or pgroup gnus-newsgroup-name)
496 (if header (mail-header-number header)
497 gnus-current-article))
503 (message-news (or to-group group))
504 (set-buffer gnus-article-copy)
505 (gnus-msg-treat-broken-reply-to)
506 (message-followup (if (or newsgroup-p force-news) nil to-group)))
510 (message-mail (or to-address to-list))
511 ;; Arrange for mail groups that have no `to-address' to
512 ;; get that when the user sends off the mail.
513 (when (and (not to-list)
516 (push (list 'gnus-inews-add-to-address pgroup)
517 message-send-actions)))
518 (set-buffer gnus-article-copy)
519 (gnus-msg-treat-broken-reply-to)
520 (message-wide-reply to-address)))
522 (gnus-inews-yank-articles yank))))))
524 (defun gnus-msg-treat-broken-reply-to ()
525 "Remove the Reply-to header iff broken-reply-to."
526 (when (gnus-group-find-parameter
527 gnus-newsgroup-name 'broken-reply-to)
529 (message-narrow-to-head)
530 (message-remove-header "reply-to"))))
532 (defun gnus-post-method (arg group &optional silent)
533 "Return the posting method based on GROUP and ARG.
534 If SILENT, don't prompt the user."
535 (let ((group-method (gnus-find-method-for-group group)))
537 ;; If the group-method is nil (which shouldn't happen) we use
538 ;; the default method.
540 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
541 gnus-select-method message-post-method))
542 ;; We want the inverse of the default
543 ((and arg (not (eq arg 0)))
544 (if (eq gnus-post-method 'active)
547 ;; We query the user for a post method.
549 (and gnus-post-method
550 (not (eq gnus-post-method 'current))
551 (listp (car gnus-post-method))))
553 ;; Collect all methods we know about.
555 (when (and gnus-post-method
556 (not (eq gnus-post-method 'current)))
557 (if (listp (car gnus-post-method))
559 (list gnus-post-method)))
560 gnus-secondary-select-methods
561 (mapcar 'cdr gnus-server-alist)
562 (mapcar 'car gnus-opened-servers)
563 (list gnus-select-method)
564 (list group-method)))
565 method-alist post-methods method)
566 ;; Weed out all mail methods.
568 (setq method (gnus-server-get-method "" (pop methods)))
569 (when (and (or (gnus-method-option-p method 'post)
570 (gnus-method-option-p method 'post-mail))
571 (not (member method post-methods)))
572 (push method post-methods)))
573 ;; Create a name-method alist.
577 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
582 (setq gnus-last-posting-server
584 gnus-last-posting-server)
585 ;; Just use the last value.
586 gnus-last-posting-server
588 "Posting method: " method-alist nil t
589 (cons (or gnus-last-posting-server "") 0))))
591 ;; Override normal method.
592 ((and (eq gnus-post-method 'current)
593 (not (eq (car group-method) 'nndraft))
594 (gnus-get-function group-method 'request-post t)
597 ((and gnus-post-method
598 (not (eq gnus-post-method 'current)))
600 ;; Use the normal select method.
601 (t gnus-select-method))))
605 ;; Dummies to avoid byte-compile warning.
606 (defvar nnspool-rejected-article-hook)
607 (defvar xemacs-codename)
609 (defun gnus-extended-version ()
610 "Stringified Gnus version and Emacs version."
613 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
614 " (" gnus-version ")"
617 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
618 (concat "Emacs/" (match-string 1 emacs-version)))
619 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
621 (concat (match-string 1 emacs-version)
622 (format "/%d.%d" emacs-major-version emacs-minor-version)
623 (if (match-beginning 3)
624 (match-string 3 emacs-version)
626 (if (boundp 'xemacs-codename)
627 (concat " (" xemacs-codename ")")
633 ;;; Gnus Mail Functions
636 ;;; Mail reply commands of Gnus summary mode
638 (defun gnus-summary-reply (&optional yank wide)
639 "Start composing a reply mail to the current message.
640 If prefix argument YANK is non-nil, the original article is yanked
643 (list (and current-prefix-arg
644 (gnus-summary-work-articles 1))))
645 ;; Stripping headers should be specified with mail-yank-ignored-headers.
647 (gnus-summary-goto-subject (car yank)))
648 (let ((gnus-article-reply t))
649 (gnus-setup-message (if yank 'reply-yank 'reply)
650 (gnus-summary-select-article)
651 (set-buffer (gnus-copy-article-buffer))
652 (gnus-msg-treat-broken-reply-to)
654 (message-narrow-to-head)
655 (goto-char (point-max)))
656 (mml-quote-region (point) (point-max))
657 (message-reply nil wide)
659 (gnus-inews-yank-articles yank)))))
661 (defun gnus-summary-reply-with-original (n &optional wide)
662 "Start composing a reply mail to the current message.
663 The original article will be yanked."
665 (gnus-summary-reply (gnus-summary-work-articles n) wide))
667 (defun gnus-summary-wide-reply (&optional yank)
668 "Start composing a wide reply mail to the current message.
669 If prefix argument YANK is non-nil, the original article is yanked
672 (list (and current-prefix-arg
673 (gnus-summary-work-articles 1))))
674 (gnus-summary-reply yank t))
676 (defun gnus-summary-wide-reply-with-original (n)
677 "Start composing a wide reply mail to the current message.
678 The original article will be yanked."
680 (gnus-summary-reply-with-original n t))
682 (defun gnus-summary-mail-forward (&optional arg post)
683 "Forward the current message to another user.
684 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
685 if ARG is 1, decode the message and forward directly inline;
686 if ARG is 2, foward message as an rfc822 MIME section;
687 if ARG is 3, decode message and forward as an rfc822 MIME section;
688 if ARG is 4, foward message directly inline;
689 otherwise, use flipped `message-forward-as-mime'.
690 If POST, post instead of mail."
692 (let ((message-forward-as-mime message-forward-as-mime)
693 (message-forward-show-mml message-forward-show-mml))
696 ((eq arg 1) (setq message-forward-as-mime nil
697 message-forward-show-mml t))
698 ((eq arg 2) (setq message-forward-as-mime t
699 message-forward-show-mml nil))
700 ((eq arg 3) (setq message-forward-as-mime t
701 message-forward-show-mml t))
702 ((eq arg 4) (setq message-forward-as-mime nil
703 message-forward-show-mml nil))
704 (t (setq message-forward-as-mime (not message-forward-as-mime))))
705 (gnus-setup-message 'forward
706 (gnus-summary-select-article)
707 (let ((mail-parse-charset gnus-newsgroup-charset)
708 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
711 (set-buffer gnus-original-article-buffer)
712 (mm-with-unibyte-current-buffer
713 (setq text (buffer-string))))
715 (gnus-get-buffer-create
716 (generate-new-buffer-name " *Gnus forward*")))
718 (mm-disable-multibyte)
720 (goto-char (point-min))
721 (when (looking-at "From ")
722 (replace-match "X-From-Line: ") )
723 (when message-forward-show-mml
724 (mm-enable-multibyte)
726 (message-forward post)))))
728 (defun gnus-summary-resend-message (address n)
729 "Resend the current article to ADDRESS."
730 (interactive "sResend message(s) to: \nP")
731 (let ((articles (gnus-summary-work-articles n))
733 (while (setq article (pop articles))
734 (gnus-summary-select-article nil nil nil article)
736 (set-buffer gnus-original-article-buffer)
737 (message-resend address)))))
739 (defun gnus-summary-post-forward (&optional arg)
740 "Forward the current article to a newsgroup.
741 See `gnus-summary-mail-forward' for ARG."
743 (gnus-summary-mail-forward arg t))
745 (defvar gnus-nastygram-message
746 "The following article was inappropriately posted to %s.\n\n"
747 "Format string to insert in nastygrams.
748 The current group name will be inserted at \"%s\".")
750 (defun gnus-summary-mail-nastygram (n)
751 "Send a nastygram to the author of the current article."
753 (when (or gnus-expert-user
755 "Really send a nastygram to the author of the current article? "))
756 (let ((group gnus-newsgroup-name))
757 (gnus-summary-reply-with-original n)
758 (set-buffer gnus-message-buffer)
760 (insert (format gnus-nastygram-message group))
761 (message-send-and-exit))))
763 (defun gnus-summary-mail-crosspost-complaint (n)
764 "Send a complaint about crossposting to the current article(s)."
766 (let ((articles (gnus-summary-work-articles n))
768 (while (setq article (pop articles))
769 (set-buffer gnus-summary-buffer)
770 (gnus-summary-goto-subject article)
771 (let ((group (gnus-group-real-name gnus-newsgroup-name))
772 newsgroups followup-to)
773 (gnus-summary-select-article)
774 (set-buffer gnus-original-article-buffer)
775 (if (and (<= (length (message-tokenize-header
777 (mail-fetch-field "newsgroups"))
780 (or (not (setq followup-to (mail-fetch-field "followup-to")))
781 (not (member group (message-tokenize-header
782 followup-to ", ")))))
784 (gnus-message 1 "Followup-to restricted")
785 (gnus-message 1 "Not a crossposted article"))
786 (set-buffer gnus-summary-buffer)
787 (gnus-summary-reply-with-original 1)
788 (set-buffer gnus-message-buffer)
790 (insert (format gnus-crosspost-complaint newsgroups group))
791 (message-goto-subject)
792 (re-search-forward " *$")
793 (replace-match " (crosspost notification)" t t)
794 (gnus-deactivate-mark)
795 (when (gnus-y-or-n-p "Send this complaint? ")
796 (message-send-and-exit)))))))
798 (defun gnus-summary-mail-other-window ()
799 "Compose mail in other window."
801 (gnus-setup-message 'message
804 (defun gnus-mail-parse-comma-list ()
807 (skip-chars-forward " ")
810 (skip-chars-forward "^,")
815 (narrow-to-region beg (point))
818 (while (search-forward "\"" nil t)
822 (skip-chars-forward ",")
823 (skip-chars-forward "^,"))
824 (skip-chars-backward " ")
825 (push (buffer-substring beg (point))
827 (skip-chars-forward "^,")
828 (skip-chars-forward ", "))
831 (defun gnus-inews-add-to-address (group)
832 (let ((to-address (mail-fetch-field "to")))
833 (when (and to-address
835 ;; This mail group doesn't have a `to-list', so we add one
838 (format "Do you want to add this as `to-list': %s " to-address))
839 (gnus-group-add-parameter group (cons 'to-list to-address))))))
841 (defun gnus-put-message ()
842 "Put the current message in some group and return to Gnus."
844 (let ((reply gnus-article-reply)
845 (winconf gnus-prev-winconf)
846 (group gnus-newsgroup-name))
848 (or (and group (not (gnus-group-read-only-p group)))
849 (setq group (read-string "Put in group: " nil
850 (gnus-writable-groups))))
851 (when (gnus-gethash group gnus-newsrc-hashtb)
852 (error "No such group: %s" group))
857 (message-narrow-to-headers)
858 (let (gnus-deletable-headers)
860 (message-generate-headers message-required-news-headers)
861 (message-generate-headers message-required-mail-headers)))
862 (goto-char (point-max))
863 (insert "Gcc: " group "\n")
868 (when (get-buffer gnus-group-buffer)
869 (when (gnus-buffer-exists-p (car-safe reply))
870 (set-buffer (car reply))
872 (gnus-summary-mark-article-as-replied
875 (set-window-configuration winconf)))))
877 (defun gnus-article-mail (yank)
878 "Send a reply to the address near point.
879 If YANK is non-nil, include the original article."
883 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
884 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
886 (message-reply address)
888 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
890 (defvar nntp-server-type)
892 "Send a bug report to the Gnus maintainers."
894 (unless (gnus-alive-p)
895 (error "Gnus has been shut down"))
896 (gnus-setup-message 'bug
897 (delete-other-windows)
898 (when gnus-bug-create-help-buffer
899 (switch-to-buffer "*Gnus Help Bug*")
901 (insert gnus-bug-message)
902 (goto-char (point-min)))
903 (message-pop-to-buffer "*Gnus Bug*")
904 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
905 (when gnus-bug-create-help-buffer
906 (push `(gnus-bug-kill-buffer) message-send-actions))
907 (goto-char (point-min))
908 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
910 (insert (gnus-version) "\n"
911 (emacs-version) "\n")
912 (when (and (boundp 'nntp-server-type)
913 (stringp nntp-server-type))
914 (insert nntp-server-type))
915 (insert "\n\n\n\n\n")
918 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
920 (setq text (buffer-string)))
921 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
922 (goto-char (point-min))
923 (search-forward "Subject: " nil t)
926 (defun gnus-bug-kill-buffer ()
927 (when (get-buffer "*Gnus Help Bug*")
928 (kill-buffer "*Gnus Help Bug*")))
930 (defun gnus-summary-yank-message (buffer n)
931 "Yank the current article into a composed message."
933 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
935 (gnus-summary-iterate n
936 (let ((gnus-display-mime-function nil)
937 (gnus-inhibit-treatment t))
938 (gnus-summary-select-article))
941 (message-yank-buffer gnus-article-buffer))))
944 "Attempts to go through the Gnus source file and report what variables have been changed.
945 The source file has to be in the Emacs load path."
947 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
948 "gnus-art.el" "gnus-start.el" "gnus-async.el"
949 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
950 "nnmail.el" "message.el"))
953 (gnus-message 4 "Please wait while we snoop your variables...")
955 ;; Go through all the files looking for non-default values for variables.
957 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
960 (when (and (setq file (locate-library (pop files)))
961 (file-exists-p file))
962 (insert-file-contents file)
963 (goto-char (point-min))
964 (if (not (re-search-forward "^;;* *Internal variables" nil t))
965 (gnus-message 4 "Malformed sources in file %s" file)
966 (narrow-to-region (point-min) (point))
967 (goto-char (point-min))
968 (while (setq expr (ignore-errors (read (current-buffer))))
970 (and (or (eq (car expr) 'defvar)
971 (eq (car expr) 'defcustom))
972 (stringp (nth 3 expr))
973 (or (not (boundp (nth 1 expr)))
974 (not (equal (eval (nth 2 expr))
975 (symbol-value (nth 1 expr)))))
976 (push (nth 1 expr) olist)))))))
977 (kill-buffer (current-buffer)))
978 (when (setq olist (nreverse olist))
979 (insert "------------------ Environment follows ------------------\n\n"))
981 (if (boundp (car olist))
983 (pp `(setq ,(car olist)
984 ,(if (or (consp (setq sym (symbol-value (car olist))))
986 (not (or (eq sym nil)
988 (list 'quote (symbol-value (car olist)))
989 (symbol-value (car olist))))
992 (format "(setq %s 'whatever)\n" (car olist))))
993 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
994 (setq olist (cdr olist)))
996 ;; Remove any control chars - they seem to cause trouble for some
997 ;; mailers. (Byte-compiled output from the stuff above.)
999 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1000 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1003 ;;; Treatment of rejected articles.
1006 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1007 "Re-mail the current message.
1008 This only makes sense if the current message is a bounce message than
1009 contains some mail you have written which has been bounced back to
1011 If FETCH, try to fetch the article that this is a reply to, if indeed
1014 (gnus-summary-select-article t)
1015 (set-buffer gnus-original-article-buffer)
1016 (gnus-setup-message 'compose-bounce
1017 (let* ((references (mail-fetch-field "references"))
1018 (parent (and references (gnus-parent-id references))))
1020 ;; If there are references, we fetch the article we answered to.
1022 (gnus-summary-refer-article parent)
1023 (gnus-summary-show-all-headers)))))
1027 ;; Do Gcc handling, which copied the message over to some group.
1028 (defun gnus-inews-do-gcc (&optional gcc)
1030 (when (gnus-alive-p)
1033 (message-narrow-to-headers)
1034 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1035 (cur (current-buffer))
1036 groups group method)
1038 (message-remove-header "gcc")
1040 (setq groups (message-tokenize-header gcc " ,"))
1041 ;; Copy the article over to some group(s).
1042 (while (setq group (pop groups))
1045 (cond ((and (null (gnus-get-info group))
1046 (eq (car gnus-message-archive-method)
1048 (gnus-server-to-method
1049 (gnus-group-method group)))))
1050 ;; If the group doesn't exist, we assume
1051 ;; it's an archive group...
1052 gnus-message-archive-method)
1054 ((gnus-info-method (gnus-get-info group))
1055 (gnus-info-method (gnus-get-info group)))
1057 (t (gnus-group-method group)))))
1058 (gnus-check-server method)
1059 (unless (gnus-request-group group t method)
1060 (gnus-request-create-group group method))
1062 (nnheader-set-temp-buffer " *acc*")
1063 (insert-buffer-substring cur)
1064 (message-encode-message-body)
1066 (message-narrow-to-headers)
1067 (let ((mail-parse-charset message-default-charset)
1068 (rfc2047-header-encoding-alist
1069 (cons '("Newsgroups" . default)
1070 rfc2047-header-encoding-alist)))
1071 (mail-encode-encoded-word-buffer)))
1072 (goto-char (point-min))
1073 (when (re-search-forward
1074 (concat "^" (regexp-quote mail-header-separator) "$")
1076 (replace-match "" t t ))
1077 (unless (gnus-request-accept-article group method t t)
1078 (gnus-message 1 "Couldn't store article in group %s: %s"
1079 group (gnus-status-message method))
1081 (kill-buffer (current-buffer))))))))))
1083 (defun gnus-inews-insert-gcc ()
1084 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1087 (message-narrow-to-headers)
1088 (let* ((group gnus-outgoing-message-group)
1090 ((gnus-functionp group)
1092 ((or (stringp group) (list group))
1096 (if (stringp gcc) gcc
1097 (mapconcat 'identity gcc " "))
1100 (defun gnus-inews-insert-archive-gcc (&optional group)
1101 "Insert the Gcc to say where the article is to be archived."
1102 (let* ((var gnus-message-archive-group)
1103 (group (or group gnus-newsgroup-name ""))
1105 (and gnus-newsgroup-name
1106 (not (equal gnus-newsgroup-name ""))
1107 (gnus-group-find-parameter
1108 gnus-newsgroup-name 'gcc-self)))
1112 ((null gnus-message-archive-method)
1116 ;; Just a single group.
1119 ;; We don't want this.
1121 ((and (listp var) (stringp (car var)))
1122 ;; A list of groups.
1124 ((gnus-functionp var)
1126 (funcall var group))
1128 ;; An alist of regexps/functions/forms.
1133 ((stringp (caar var))
1135 (when (string-match (caar var) group)
1137 ((gnus-functionp (car var))
1139 (funcall (car var) group))
1141 (eval (car var)))))))
1142 (setq var (cdr var)))
1145 (when (or groups gcc-self-val)
1146 (when (stringp groups)
1147 (setq groups (list groups)))
1150 (message-narrow-to-headers)
1151 (goto-char (point-max))
1154 ;; Use the `gcc-self' param value instead.
1157 (if (stringp gcc-self-val)
1160 (if (not (eq gcc-self-val 'none))
1165 ;; Use the list of groups.
1166 (while (setq name (pop groups))
1167 (insert (if (string-match ":" name)
1169 (gnus-group-prefixed-name
1170 name gnus-message-archive-method)))
1177 (defun gnus-configure-posting-styles ()
1178 "Configure posting styles according to `gnus-posting-styles'."
1179 (unless gnus-inhibit-posting-styles
1180 (let ((group (or gnus-newsgroup-name ""))
1181 (styles gnus-posting-styles)
1182 style match variable attribute value v results
1183 filep name address element)
1184 ;; If the group has a posting-style parameter, add it at the end with a
1185 ;; regexp matching everything, to be sure it takes precedence over all
1187 (when gnus-newsgroup-name
1188 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1190 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1191 ;; Go through all styles and look for matches.
1192 (dolist (style styles)
1193 (setq match (pop style))
1194 (goto-char (point-min))
1197 ;; Regexp string match on the group name.
1198 (string-match match group))
1200 (let ((header (message-fetch-field (pop style))))
1202 (string-match (pop style) header))))
1203 ((or (symbolp match)
1204 (gnus-functionp match))
1206 ((gnus-functionp match)
1207 ;; Function to be called.
1210 ;; Variable to be checked.
1211 (symbol-value match))))
1213 ;; This is a form to be evaled.
1215 ;; We have a match, so we set the variables.
1216 (dolist (attribute style)
1217 (setq element (pop attribute)
1222 ((eq (car attribute) :file)
1225 ((eq (car attribute) :value)
1229 ;; We get the value.
1234 ((or (symbolp value)
1235 (gnus-functionp value))
1236 (cond ((gnus-functionp value)
1239 (symbol-value value))))
1242 ;; Translate obsolescent value.
1243 (when (eq element 'signature-file)
1244 (setq element 'signature
1246 ;; Get the contents of file elems.
1248 (setq v (with-temp-buffer
1249 (insert-file-contents v)
1251 (setq results (delq (assoc element results) results))
1252 (push (cons element v) results))))
1253 ;; Now we have all the styles, so we insert them.
1254 (setq name (assq 'name results)
1255 address (assq 'address results))
1256 (setq results (delq name (delq address results)))
1257 (make-local-variable 'message-setup-hook)
1258 (dolist (result results)
1259 (add-hook 'message-setup-hook
1261 ((eq 'eval (car result))
1263 ((eq 'body (car result))
1267 (insert ,(cdr result)))))
1268 ((eq 'signature (car result))
1269 (set (make-local-variable 'message-signature) nil)
1270 (set (make-local-variable 'message-signature-file) nil)
1271 (if (not (cdr result))
1275 (let ((message-signature ,(cdr result)))
1276 (when message-signature
1277 (message-insert-signature)))))))
1280 (if (symbolp (car result))
1281 (capitalize (symbol-name (car result)))
1285 (message-remove-header ,header)
1286 (let ((value ,(cdr result)))
1289 (insert ,header ": " value "\n"))))))))))
1290 (when (or name address)
1291 (add-hook 'message-setup-hook
1293 (set (make-local-variable 'user-mail-address)
1294 ,(or (cdr address) user-mail-address))
1295 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1297 ,(or (cdr address) user-mail-address)))
1299 (message-remove-header "From")
1301 (insert "From: " (message-make-from) "\n")))))))))
1303 ;;; Allow redefinition of functions.
1309 ;;; gnus-msg.el ends here