1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
42 (defcustom gnus-post-method 'current
43 "*Preferred method for posting USENET news.
45 If this variable is `current' (which is the default), Gnus will use
46 the \"current\" select method when posting. If it is `native', Gnus
47 will use the native select method when posting.
49 This method will not be used in mail groups and the like, only in
52 If not `native' nor `current', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'. It can also be a list of
54 methods. If that is the case, the user will be queried for what select
55 method to use when posting."
56 :group 'gnus-group-foreign
57 :link '(custom-manual "(gnus)Posting Server")
58 :type `(choice (const native)
60 (sexp :tag "Methods" ,gnus-select-method)))
62 (defcustom gnus-outgoing-message-group nil
63 "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value. This variable
66 can also be a list of group names.
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
73 :type '(choice (string :tag "Group")
76 (defcustom gnus-mailing-list-groups nil
77 "*Regexp matching groups that are really mailing lists.
78 This is useful when you're reading a mailing list that has been
79 gatewayed to a newsgroup, and you want to followup to an article in
84 (defcustom gnus-add-to-list nil
85 "*If non-nil, add a `to-list' parameter automatically."
89 (defcustom gnus-crosspost-complaint
92 You posted the article below with the following Newsgroups header:
96 The %s group, at least, was an inappropriate recipient
97 of this message. Please trim your Newsgroups header to exclude this
98 group before posting in the future.
103 "Format string to be inserted when complaining about crossposts.
104 The first %s will be replaced by the Newsgroups header;
105 the second with the current group name."
109 (defcustom gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
110 "Hook run after setting up a message buffer."
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :type '(repeat (cons (choice (regexp)
126 (string :tag "Header")
127 (regexp :tag "Regexp"))
131 (choice (const signature)
132 (const signature-file)
138 (string :tag "Header"))
144 (defcustom gnus-gcc-mark-as-read nil
145 "If non-nil, automatically mark Gcc articles as read."
150 (defvar gnus-inews-mark-gcc-as-read nil
151 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
153 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
154 'gnus-gcc-mark-as-read)
156 (defcustom gnus-gcc-externalize-attachments nil
157 "Should local-file attachments be included as external parts in Gcc copies?
158 If it is `all', attach files as external parts;
159 if a regexp and matches the Gcc group name, attach files as external parts;
160 If nil, attach files as normal parts."
163 :type '(choice (const nil :tag "None")
164 (const all :tag "Any")
165 (string :tag "Regexp")))
167 (defcustom gnus-group-posting-charset-alist
168 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
169 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
170 (message-this-is-mail nil nil)
171 (message-this-is-news nil t))
172 "Alist of regexps and permitted unencoded charsets for posting.
173 Each element of the alist has the form (TEST HEADER BODY-LIST), where
174 TEST is either a regular expression matching the newsgroup header or a
176 HEADER is the charset which may be left unencoded in the header (nil
177 means encode all charsets),
178 BODY-LIST is a list of charsets which may be encoded using 8bit
179 content-transfer encoding in the body, or one of the special values
180 nil (always encode using quoted-printable) or t (always use 8bit).
182 Note that any value other than nil for HEADER infringes some RFCs, so
183 use this option with care."
184 :type '(repeat (list :tag "Permitted unencoded charsets"
186 (regexp :tag "Group")
187 (const :tag "Mail message"
188 :value message-this-is-mail)
189 (const :tag "News article"
190 :value message-this-is-news))
191 (choice :tag "Header"
192 (const :tag "None" nil)
193 (symbol :tag "Charset"))
195 (const :tag "Any" :value t)
196 (const :tag "None" :value nil)
197 (repeat :tag "Charsets"
198 (symbol :tag "Charset")))))
199 :group 'gnus-charset)
201 (defcustom gnus-debug-files
202 '("gnus.el" "gnus-sum.el" "gnus-group.el"
203 "gnus-art.el" "gnus-start.el" "gnus-async.el"
204 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
205 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
206 "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
207 "Files whose variables will be reported in `gnus-bug'."
210 :type '(repeat (string :tag "File")))
212 (defcustom gnus-debug-exclude-variables
213 '(mm-mime-mule-charset-alist
214 nnmail-split-fancy message-minibuffer-local-map)
215 "Variables that should not be reported in `gnus-bug'."
218 :type '(repeat (symbol :tab "Variable")))
220 ;;; Internal variables.
222 (defvar gnus-inhibit-posting-styles nil
223 "Inhibit the use of posting styles.")
225 (defvar gnus-message-buffer "*Mail Gnus*")
226 (defvar gnus-article-copy nil)
227 (defvar gnus-check-before-posting nil)
228 (defvar gnus-last-posting-server nil)
229 (defvar gnus-message-group-art nil)
231 (defvar gnus-msg-force-broken-reply-to nil)
233 (defconst gnus-bug-message
234 (format "Sending a bug report to the Gnus Towers.
235 ========================================
237 This gnus is the %s%s.
238 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
239 Developers. (the addresses below are mailing list addresses)
241 ========================================
243 The buffer below is a mail buffer. When you press `C-c C-c', it will
244 be sent to the Gnus Bug Exterminators.
246 The thing near the bottom of the buffer is how the environment
247 settings will be included in the mail. Please do not delete that.
248 They will tell the Bug People what your environment is, so that it
249 will be easier to locate the bugs.
251 If you have found a bug that makes Emacs go \"beep\", set
252 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
253 and include the backtrace in your bug report.
255 Please describe the bug in annoying, painstaking detail.
257 Thank you for your help in stamping out bugs.
260 (if (string= gnus-product-name "Semi-gnus")
262 ", a modified version of Semi-gnus")))
265 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
266 (autoload 'news-setup "rnewspost")
267 (autoload 'news-reply-mode "rnewspost")
268 (autoload 'rmail-dont-reply-to "mail-utils")
269 (autoload 'rmail-output "rmailout"))
273 ;;; Gnus Posting Functions
276 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
277 "p" gnus-summary-post-news
278 "i" gnus-summary-news-other-window
279 "f" gnus-summary-followup
280 "F" gnus-summary-followup-with-original
281 "c" gnus-summary-cancel-article
282 "s" gnus-summary-supersede-article
283 "r" gnus-summary-reply
284 "y" gnus-summary-yank-message
285 "R" gnus-summary-reply-with-original
286 "w" gnus-summary-wide-reply
287 "W" gnus-summary-wide-reply-with-original
288 "v" gnus-summary-very-wide-reply
289 "V" gnus-summary-very-wide-reply-with-original
290 "n" gnus-summary-followup-to-mail
291 "N" gnus-summary-followup-to-mail-with-original
292 "m" gnus-summary-mail-other-window
293 "u" gnus-uu-post-news
294 "\M-c" gnus-summary-mail-crosspost-complaint
295 "Br" gnus-summary-reply-broken-reply-to
296 "BR" gnus-summary-reply-broken-reply-to-with-original
297 "om" gnus-summary-mail-forward
298 "op" gnus-summary-post-forward
299 "Om" gnus-summary-digest-mail-forward
300 "Op" gnus-summary-digest-post-forward)
302 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
303 "b" gnus-summary-resend-bounced-mail
304 ;; "c" gnus-summary-send-draft
305 "r" gnus-summary-resend-message)
307 ;;; Internal functions.
309 (defvar gnus-article-reply nil)
310 (defmacro gnus-setup-message (config &rest forms)
311 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
312 (buffer (make-symbol "gnus-setup-message-buffer"))
313 (article (make-symbol "gnus-setup-message-article"))
314 (group (make-symbol "gnus-setup-message-group")))
315 `(let ((,winconf (current-window-configuration))
316 (,buffer (buffer-name (current-buffer)))
317 (,article gnus-article-reply)
318 (,group gnus-newsgroup-name)
319 (message-header-setup-hook
320 (copy-sequence message-header-setup-hook))
321 (message-mode-hook (copy-sequence message-mode-hook))
322 (message-startup-parameter-alist
323 '((reply-buffer . gnus-copy-article-buffer)
324 (original-buffer . gnus-original-article-buffer)
325 (user-agent . Gnus))))
326 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
327 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
328 ;; #### FIXME: for a reason that I did not manage to identify yet,
329 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
330 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
331 ;; After evaluation of @forms below, it gets the value we actually want
332 ;; to override, and the posting styles are used. For that reason, I've
333 ;; added an optional argument to `gnus-configure-posting-styles' to
334 ;; make sure that the correct value for the group name is used. -- drv
335 (add-hook 'message-mode-hook
337 (gnus-configure-posting-styles ,group)))
341 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
342 (gnus-inews-insert-draft-meta-information ,group ,article)
343 (setq gnus-message-buffer (current-buffer))
344 (set (make-local-variable 'gnus-message-group-art)
345 (cons ,group ,article))
346 (set (make-local-variable 'gnus-newsgroup-name) ,group)
347 (gnus-run-hooks 'gnus-message-setup-hook))
349 (gnus-configure-windows ,config t)
350 (run-hooks 'post-command-hook)
351 (set-buffer-modified-p nil))))
353 (defun gnus-inews-insert-draft-meta-information (group article)
356 (not (string= group ""))
357 (not (message-fetch-field gnus-draft-meta-information-header)))
358 (goto-char (point-min))
359 (insert gnus-draft-meta-information-header ": (\"" group "\" "
360 (if article (number-to-string
367 (defun gnus-msg-mail (&optional to subject other-headers continue
368 switch-action yank-action send-actions)
369 "Start editing a mail message to be sent.
370 Like `message-mail', but with Gnus paraphernalia, particularly the
371 Gcc: header for archiving purposes."
373 (let ((buf (current-buffer))
375 (gnus-setup-message 'message
376 (message-mail to subject other-headers continue
377 nil yank-action send-actions))
379 (setq mail-buf (current-buffer))
380 (switch-to-buffer buf)
381 (apply switch-action mail-buf nil)))
382 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
385 (defvar save-selected-window-window)
388 (defun gnus-button-mailto (address)
390 (set-buffer (gnus-copy-article-buffer))
391 (gnus-setup-message 'message
392 (message-reply address))
393 (and (boundp 'save-selected-window-window)
394 (not (window-live-p save-selected-window-window))
395 (setq save-selected-window-window (selected-window))))
398 (defun gnus-button-reply (&optional to-address wide)
399 "Like `message-reply'."
401 (gnus-setup-message 'message
402 (message-reply to-address wide))
403 (and (boundp 'save-selected-window-window)
404 (not (window-live-p save-selected-window-window))
405 (setq save-selected-window-window (selected-window))))
408 (define-mail-user-agent 'gnus-user-agent
409 'gnus-msg-mail 'message-send-and-exit
410 'message-kill-buffer 'message-send-hook)
412 (defun gnus-setup-posting-charset (group)
413 (let ((alist gnus-group-posting-charset-alist)
414 (group (or group ""))
418 (while (setq elem (pop alist))
419 (when (or (and (stringp (car elem))
420 (string-match (car elem) group))
421 (and (gnus-functionp (car elem))
422 (funcall (car elem) group))
423 (and (symbolp (car elem))
424 (symbol-value (car elem))))
425 (throw 'found (cons (cadr elem) (caddr elem)))))))))
427 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
428 (make-local-hook 'message-sent-hook)
429 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
430 'gnus-inews-do-gcc) nil t)
432 (make-local-hook 'message-header-hook)
433 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
434 (setq message-post-method
436 (gnus-post-method arg ,gnus-newsgroup-name)))
437 (setq message-user-agent (gnus-extended-version))
438 (when (not message-use-multi-frames)
440 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
442 `(when (gnus-buffer-exists-p ,buffer)
446 (if (eq config 'forward)
447 `(gnus-summary-mark-article-as-forwarded ',article)
448 `(gnus-summary-mark-article-as-replied ',article)))))
451 (put 'gnus-setup-message 'lisp-indent-function 1)
452 (put 'gnus-setup-message 'edebug-form-spec '(form body))
454 ;;; Post news commands of Gnus group mode and summary mode
456 (defun gnus-group-mail (&optional arg)
457 "Start composing a mail.
458 If ARG, use the group under the point to find a posting style.
459 If ARG is 1, prompt for a group name to find the posting style."
461 ;; We can't `let' gnus-newsgroup-name here, since that leads
462 ;; to local variables leaking.
463 (let ((group gnus-newsgroup-name)
464 (buffer (current-buffer)))
467 (setq gnus-newsgroup-name
469 (if (= 1 (prefix-numeric-value arg))
470 (completing-read "Use posting style of group: "
471 gnus-active-hashtb nil
472 (gnus-read-active-file-p))
473 (gnus-group-group-name))
475 ;; #### see comment in gnus-setup-message -- drv
476 (gnus-setup-message 'message (message-mail)))
479 (setq gnus-newsgroup-name group)))))
481 (defun gnus-group-news (&optional arg)
482 "Start composing a news.
483 If ARG, post to group under point.
484 If ARG is 1, prompt for group name to post to.
486 This function prepares a news even when using mail groups. This is useful
487 for posting messages to mail groups without actually sending them over the
488 network. The corresponding backend must have a 'request-post method."
490 ;; We can't `let' gnus-newsgroup-name here, since that leads
491 ;; to local variables leaking.
492 (let ((group gnus-newsgroup-name)
493 (buffer (current-buffer)))
496 (setq gnus-newsgroup-name
498 (if (= 1 (prefix-numeric-value arg))
499 (completing-read "Use group: "
500 gnus-active-hashtb nil
501 (gnus-read-active-file-p))
502 (gnus-group-group-name))
504 ;; #### see comment in gnus-setup-message -- drv
505 (gnus-setup-message 'message
506 (message-news (gnus-group-real-name gnus-newsgroup-name))))
509 (setq gnus-newsgroup-name group)))))
511 (defun gnus-group-post-news (&optional arg)
512 "Start composing a message (a news by default).
513 If ARG, post to group under point. If ARG is 1, prompt for group name.
514 Depending on the selected group, the message might be either a mail or
517 ;; Bind this variable here to make message mode hooks work ok.
518 (let ((gnus-newsgroup-name
520 (if (= 1 (prefix-numeric-value arg))
521 (completing-read "Newsgroup: " gnus-active-hashtb nil
522 (gnus-read-active-file-p))
523 (gnus-group-group-name))
525 (gnus-post-news 'post gnus-newsgroup-name)))
527 (defun gnus-summary-mail-other-window (&optional arg)
528 "Start composing a mail in another window.
529 Use the posting of the current group by default.
530 If ARG, don't do that. If ARG is 1, prompt for group name to find the
533 ;; We can't `let' gnus-newsgroup-name here, since that leads
534 ;; to local variables leaking.
535 (let ((group gnus-newsgroup-name)
536 (buffer (current-buffer)))
539 (setq gnus-newsgroup-name
541 (if (= 1 (prefix-numeric-value arg))
542 (completing-read "Use group: "
543 gnus-active-hashtb nil
544 (gnus-read-active-file-p))
546 gnus-newsgroup-name))
547 ;; #### see comment in gnus-setup-message -- drv
548 (gnus-setup-message 'message (message-mail)))
551 (setq gnus-newsgroup-name group)))))
553 (defun gnus-summary-news-other-window (&optional arg)
554 "Start composing a news in another window.
555 Post to the current group by default.
556 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
558 This function prepares a news even when using mail groups. This is useful
559 for posting messages to mail groups without actually sending them over the
560 network. The corresponding backend must have a 'request-post method."
562 ;; We can't `let' gnus-newsgroup-name here, since that leads
563 ;; to local variables leaking.
564 (let ((group gnus-newsgroup-name)
565 (buffer (current-buffer)))
568 (setq gnus-newsgroup-name
570 (if (= 1 (prefix-numeric-value arg))
571 (completing-read "Use group: "
572 gnus-active-hashtb nil
573 (gnus-read-active-file-p))
575 gnus-newsgroup-name))
576 ;; #### see comment in gnus-setup-message -- drv
577 (gnus-setup-message 'message
578 (message-news (gnus-group-real-name gnus-newsgroup-name))))
581 (setq gnus-newsgroup-name group)))))
583 (defun gnus-summary-post-news (&optional arg)
584 "Start composing a message. Post to the current group by default.
585 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
586 Depending on the selected group, the message might be either a mail or
589 ;; Bind this variable here to make message mode hooks work ok.
590 (let ((gnus-newsgroup-name
592 (if (= 1 (prefix-numeric-value arg))
593 (completing-read "Newsgroup: " gnus-active-hashtb nil
594 (gnus-read-active-file-p))
596 gnus-newsgroup-name)))
597 (gnus-post-news 'post gnus-newsgroup-name)))
600 (defun gnus-summary-followup (yank &optional force-news)
601 "Compose a followup to an article.
602 If prefix argument YANK is non-nil, the original article is yanked
604 YANK is a list of elements, where the car of each element is the
605 article number, and the two following numbers is the region to be
608 (list (and current-prefix-arg
609 (gnus-summary-work-articles 1))))
611 (gnus-summary-goto-subject
612 (if (listp (car yank))
615 (save-window-excursion
616 (gnus-summary-select-article))
617 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
618 (gnus-newsgroup-name gnus-newsgroup-name))
620 (gnus-post-news nil gnus-newsgroup-name
621 headers gnus-article-buffer
622 yank nil force-news)))
624 (defun gnus-summary-followup-with-original (n &optional force-news)
625 "Compose a followup to an article and include the original article."
627 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
629 (defun gnus-summary-followup-to-mail (&optional arg)
630 "Followup to the current mail message via news."
632 (list (and current-prefix-arg
633 (gnus-summary-work-articles 1))))
634 (gnus-summary-followup arg t))
636 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
637 "Followup to the current mail message via news."
639 (gnus-summary-followup (gnus-summary-work-articles arg) t))
641 (defun gnus-inews-yank-articles (articles)
642 (let (beg article yank-string
643 (more-than-one (cdr articles))
644 (cur (current-buffer))
647 (while (setq article (pop articles))
648 (when (listp article)
649 (setq yank-string (nth 1 article)
650 article (nth 0 article)))
651 (save-window-excursion
652 (set-buffer gnus-summary-buffer)
653 (gnus-summary-select-article nil nil nil article)
654 (gnus-summary-remove-process-mark article))
656 ;; Gathering references.
658 (setq refs (message-list-references
660 (mail-header-references gnus-current-headers)
661 (mail-header-message-id gnus-current-headers)))
662 (when message-use-multi-frames
663 (when (setq window (get-buffer-window cur t))
664 (select-frame (window-frame window)))))
666 (gnus-copy-article-buffer nil yank-string)
667 (let ((message-reply-buffer gnus-article-copy)
668 (message-reply-headers
669 ;; The headers are decoded.
670 (with-current-buffer gnus-article-copy
671 (nnheader-parse-head t))))
672 (message-yank-original)
673 (setq beg (or beg (mark t))))
678 ;; Replace with the gathered references.
682 (message-narrow-to-headers)
683 (let ((case-fold-search t))
684 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
686 (goto-char (point-max))))
688 (list (or (assq 'References message-header-format-alist)
689 '(References . message-shorten-references)))
690 (list (cons 'References
691 (mapconcat 'identity (nreverse refs) " "))))
692 (backward-delete-char 1))
698 (defun gnus-summary-cancel-article (&optional n symp)
699 "Cancel an article you posted.
700 Uses the process-prefix convention. If given the symbolic
701 prefix `a', cancel using the standard posting method; if not
702 post using the current select method."
703 (interactive (gnus-interactive "P\ny"))
704 (let ((articles (gnus-summary-work-articles n))
707 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
709 (while (setq article (pop articles))
710 (when (gnus-summary-select-article t nil nil article)
711 (when (gnus-eval-in-buffer-window gnus-article-buffer
713 (set-buffer gnus-original-article-buffer)
714 (message-cancel-news)))
715 (gnus-summary-mark-as-read article gnus-canceled-mark)
716 (gnus-cache-remove-article 1))
717 (gnus-article-hide-headers-if-wanted))
718 (gnus-summary-remove-process-mark article))))
720 (defun gnus-summary-supersede-article ()
721 "Compose an article that will supersede a previous article.
722 This is done simply by taking the old article and adding a Supersedes
723 header line with the old Message-ID."
725 (let ((article (gnus-summary-article-number))
726 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
727 (gnus-setup-message 'reply-yank
728 (gnus-summary-select-article t)
729 (set-buffer gnus-original-article-buffer)
733 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
735 (set-buffer ,gnus-summary-buffer)
736 (gnus-cache-possibly-remove-article ,article nil nil nil t)
737 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
738 message-send-actions))))
742 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
743 ;; make a copy of the article buffer with all text properties removed
744 ;; this copy is in the buffer gnus-article-copy.
745 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
746 ;; this buffer should be passed to all mail/news reply/post routines.
747 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
748 (let ((article-buffer (or article-buffer gnus-article-buffer))
750 (if (not (and (get-buffer article-buffer)
751 (gnus-buffer-exists-p article-buffer)))
752 (error "Can't find any article buffer")
754 (set-buffer article-buffer)
755 (let ((gnus-newsgroup-charset (or gnus-article-charset
756 gnus-newsgroup-charset))
757 (gnus-newsgroup-ignored-charsets
758 (or gnus-article-ignored-charsets
759 gnus-newsgroup-ignored-charsets)))
761 ;; Copy over the (displayed) article buffer, delete
762 ;; hidden text and remove text properties.
764 (let ((inhibit-read-only t))
765 (copy-to-buffer gnus-article-copy (point-min) (point-max))
766 (set-buffer gnus-article-copy)
769 (delete-region (point) (point-max))
770 (insert yank-string))
771 ;; Encode bitmap smileys to ordinary text.
772 ;; Possibly, the original text might be restored.
773 (static-unless (featurep 'xemacs)
774 (when (featurep 'smiley-mule)
775 (smiley-encode-buffer)))
776 (gnus-article-delete-text-of-type 'annotation)
777 (gnus-remove-text-with-property 'gnus-prev)
778 (gnus-remove-text-with-property 'gnus-next)
779 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
782 (static-if (featurep 'xemacs)
783 ;; Revome smiley extents for (possibly) XEmacs 21.1.
785 (buffer-substring-no-properties (point-min)
787 (buffer-substring-no-properties (point-min) (point-max)))
789 ;; Find the original headers.
790 (set-buffer gnus-original-article-buffer)
791 (goto-char (point-min))
792 (while (looking-at message-unix-mail-delimiter)
795 end (or (message-goto-body) beg))
796 ;; Delete the headers from the displayed articles.
797 (set-buffer gnus-article-copy)
798 (delete-region (goto-char (point-min))
799 (or (message-goto-body) (point-max)))
800 ;; Insert the original article headers.
801 (insert-buffer-substring gnus-original-article-buffer beg end)
803 (let ((gnus-article-decode-hook
804 (delq 'article-decode-charset
805 (copy-sequence gnus-article-decode-hook))))
806 ;; Needed for T-gnus.
807 (add-hook 'gnus-article-decode-hook
808 'article-decode-encoded-words)
809 (run-hooks 'gnus-article-decode-hook)))))
812 (defun gnus-post-news (post &optional group header article-buffer yank subject
815 (gnus-copy-article-buffer))
816 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
817 (add-to-list gnus-add-to-list))
818 (gnus-setup-message (cond (yank 'reply-yank)
819 (article-buffer 'reply)
821 (let* ((group (or group gnus-newsgroup-name))
822 (charset (gnus-group-name-charset nil group))
824 to-address to-group mailing-list to-list
827 (setq to-address (gnus-parameter-to-address group)
828 to-group (gnus-group-find-parameter group 'to-group)
829 to-list (gnus-parameter-to-list group)
830 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
831 mailing-list (when gnus-mailing-list-groups
832 (string-match gnus-mailing-list-groups group))
833 group (gnus-group-name-decode (gnus-group-real-name group)
835 (if (or (and to-group
836 (gnus-news-group-p to-group))
839 (and (gnus-news-group-p
840 (or pgroup gnus-newsgroup-name)
841 (or header gnus-current-article))
847 (message-news (or to-group group))
848 (set-buffer gnus-article-copy)
849 (gnus-msg-treat-broken-reply-to)
850 (message-followup (if (or newsgroup-p force-news)
851 (if (save-restriction
852 (article-narrow-to-head)
853 (message-fetch-field "newsgroups"))
860 (message-mail (or to-address to-list))
861 ;; Arrange for mail groups that have no `to-address' to
862 ;; get that when the user sends off the mail.
863 (when (and (not to-list)
866 (push (list 'gnus-inews-add-to-address pgroup)
867 message-send-actions)))
868 (set-buffer gnus-article-copy)
869 (gnus-msg-treat-broken-reply-to)
870 (message-wide-reply to-address)))
872 (gnus-inews-yank-articles yank))))))
874 (defun gnus-msg-treat-broken-reply-to (&optional force)
875 "Remove the Reply-to header iff broken-reply-to."
877 (gnus-group-find-parameter
878 gnus-newsgroup-name 'broken-reply-to))
880 (message-narrow-to-head)
881 (message-remove-header "reply-to"))))
883 (defun gnus-post-method (arg group &optional silent)
884 "Return the posting method based on GROUP and ARG.
885 If SILENT, don't prompt the user."
886 (let ((gnus-post-method (or (gnus-parameter-post-method group)
888 (group-method (gnus-find-method-for-group group)))
890 ;; If the group-method is nil (which shouldn't happen) we use
891 ;; the default method.
893 (or (and (listp gnus-post-method) ;If not current/native/nil
894 (not (listp (car gnus-post-method))) ; and not a list of methods
895 gnus-post-method) ;then use it.
897 message-post-method))
898 ;; We want the inverse of the default
899 ((and arg (not (eq arg 0)))
900 (if (eq gnus-post-method 'current)
903 ;; We query the user for a post method.
905 (and (listp gnus-post-method)
906 (listp (car gnus-post-method))))
908 ;; Collect all methods we know about.
910 (when (listp gnus-post-method)
911 (if (listp (car gnus-post-method))
913 (list gnus-post-method)))
914 gnus-secondary-select-methods
915 (mapcar 'cdr gnus-server-alist)
916 (mapcar 'car gnus-opened-servers)
917 (list gnus-select-method)
918 (list group-method)))
919 method-alist post-methods method)
920 ;; Weed out all mail methods.
922 (setq method (gnus-server-get-method "" (pop methods)))
923 (when (and (or (gnus-method-option-p method 'post)
924 (gnus-method-option-p method 'post-mail))
925 (not (member method post-methods)))
926 (push method post-methods)))
927 ;; Create a name-method alist.
931 (if (equal (cadr m) "")
932 (list (symbol-name (car m)) m)
933 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
938 (setq gnus-last-posting-server
940 gnus-last-posting-server)
941 ;; Just use the last value.
942 gnus-last-posting-server
944 "Posting method: " method-alist nil t
945 (cons (or gnus-last-posting-server "") 0))))
947 ;; Override normal method.
948 ((and (eq gnus-post-method 'current)
949 (not (eq (car group-method) 'nndraft))
950 (gnus-get-function group-method 'request-post t))
953 ;; Use gnus-post-method.
954 ((listp gnus-post-method) ;A method...
955 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
957 ;; Use the normal select method (nil or native).
958 (t gnus-select-method))))
961 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
963 "Return a user-agent info. If INCLUDE-MIME-INFO is non-nil and the
964 variable `mime-edit-user-agent-value' is bound, the value will be
965 included in the return value. If MAX-COLUMN is specified, the return
966 value will be folded up as it were filled. NEWLINE-PRODUCT specifies
967 whether a newline should be inserted in front of each product-token.
968 If the value is t or `hard', it works strictly. Otherwise, if it is
969 non-nil (e.g. `soft'), it works semi-strictly.
971 Here is an example of how to use this function:
973 \(add-hook 'gnus-message-setup-hook
975 (setq message-user-agent nil)
978 (message-narrow-to-headers)
979 (goto-char (point-max))
980 (insert \"User-Agent: \"
981 (gnus-message-make-user-agent t 76 'soft)
984 (let ((user-agent (if (and include-mime-info
985 (boundp 'mime-edit-user-agent-value))
986 (concat (gnus-extended-version)
988 mime-edit-user-agent-value)
989 (gnus-extended-version))))
991 (unless (natnump max-column)
992 (setq max-column 76))
994 (set-buffer-multibyte t)
995 (insert (mapconcat 'identity (split-string user-agent) " "))
996 (goto-char (point-min))
998 start agent agents width element swidth)
999 (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1000 (setq start (match-beginning 0))
1001 (if (eq (char-after start) ?\()
1005 (push (buffer-substring start (point)) agent))
1007 (push (nreverse agent) agents))
1008 (setq agent (list (match-string 1)))))
1010 (push (nreverse agent) agents))
1011 (setq agents (nreverse agents))
1012 (if (> (+ 12 (string-width (caar agents))) max-column)
1013 (setq user-agent "\n"
1018 (setq agent (car agents)
1019 agents (cdr agents))
1020 (when (and (not bol)
1021 (or (memq newline-product '(t hard))
1022 (and newline-product
1024 (string-width (mapconcat 'identity
1027 (setq user-agent (concat user-agent "\n")
1031 (setq element (car agent)
1032 swidth (string-width element)
1035 (setq user-agent (if (member user-agent '("" "\n"))
1036 (concat user-agent element)
1037 (concat user-agent " " element))
1038 width (+ width 1 swidth)
1040 (if (> (+ width 1 swidth) max-column)
1041 (setq user-agent (concat user-agent "\n " element)
1043 (setq user-agent (concat user-agent " " element)
1044 width (+ width 1 swidth)))))))))
1049 ;;; Gnus Mail Functions
1052 ;;; Mail reply commands of Gnus summary mode
1054 (defun gnus-summary-reply (&optional yank wide very-wide)
1055 "Start composing a mail reply to the current message.
1056 If prefix argument YANK is non-nil, the original article is yanked
1058 If WIDE, make a wide reply.
1059 If VERY-WIDE, make a very wide reply."
1061 (list (and current-prefix-arg
1062 (gnus-summary-work-articles 1))))
1064 (if (listp (car yank))
1067 (gnus-article-reply (or article (gnus-summary-article-number)))
1069 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1071 (gnus-summary-goto-subject article))
1072 (gnus-setup-message (if yank 'reply-yank 'reply)
1074 (gnus-summary-select-article)
1075 (dolist (article very-wide)
1076 (gnus-summary-select-article nil nil nil article)
1078 (set-buffer (gnus-copy-article-buffer))
1079 (gnus-msg-treat-broken-reply-to)
1081 (message-narrow-to-head)
1082 (setq headers (concat headers (buffer-string)))))))
1083 (set-buffer (gnus-copy-article-buffer))
1084 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1086 (message-narrow-to-head)
1090 (goto-char (point-max)))
1091 (message-reply nil wide)
1093 (gnus-inews-yank-articles yank)))))
1095 (defun gnus-summary-reply-with-original (n &optional wide)
1096 "Start composing a reply mail to the current message.
1097 The original article will be yanked."
1099 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1101 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1102 "Like `gnus-summary-reply' except removing reply-to field.
1103 If prefix argument YANK is non-nil, the original article is yanked
1105 If WIDE, make a wide reply.
1106 If VERY-WIDE, make a very wide reply."
1108 (list (and current-prefix-arg
1109 (gnus-summary-work-articles 1))))
1110 (let ((gnus-msg-force-broken-reply-to t))
1111 (gnus-summary-reply yank wide very-wide)))
1113 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1114 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1115 The original article will be yanked."
1117 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1119 (defun gnus-summary-wide-reply (&optional yank)
1120 "Start composing a wide reply mail to the current message.
1121 If prefix argument YANK is non-nil, the original article is yanked
1124 (list (and current-prefix-arg
1125 (gnus-summary-work-articles 1))))
1126 (gnus-summary-reply yank t))
1128 (defun gnus-summary-wide-reply-with-original (n)
1129 "Start composing a wide reply mail to the current message.
1130 The original article will be yanked."
1132 (gnus-summary-reply-with-original n t))
1134 (defun gnus-summary-very-wide-reply (&optional yank)
1135 "Start composing a very wide reply mail to the current message.
1136 If prefix argument YANK is non-nil, the original article is yanked
1139 (list (and current-prefix-arg
1140 (gnus-summary-work-articles 1))))
1141 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1143 (defun gnus-summary-very-wide-reply-with-original (n)
1144 "Start composing a very wide reply mail to the current message.
1145 The original article will be yanked."
1148 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1150 (defun gnus-summary-mail-forward (&optional full-headers post)
1151 "Forward the current message(s) to another user.
1152 If process marks exist, forward all marked messages;
1153 If FULL-HEADERS (the prefix), include full headers when forwarding."
1155 (if (null (cdr (gnus-summary-work-articles nil)))
1156 (gnus-setup-message 'forward
1157 (gnus-summary-select-article)
1158 (let ((charset default-mime-charset))
1159 (set-buffer gnus-original-article-buffer)
1160 (make-local-variable 'default-mime-charset)
1161 (setq default-mime-charset charset))
1162 (let ((message-included-forward-headers
1163 (if full-headers "" message-included-forward-headers)))
1164 (message-forward post)))
1165 (gnus-summary-digest-mail-forward nil post)))
1167 (defun gnus-summary-digest-mail-forward (&optional n post)
1168 "Digests and forwards all articles in this series.
1169 If N is a positive number, forward the N next articles.
1170 If N is a negative number, forward the N previous articles.
1171 If N is nil and any articles have been marked with the process mark,
1172 forward those articles instead.
1173 Optional POST will use news to forward instead of mail."
1175 (let ((articles (gnus-summary-work-articles n))
1176 (topics "Topics:\n")
1177 subject article frame)
1178 (when (car articles)
1179 (gnus-setup-message 'forward
1180 (gnus-summary-select-article)
1182 (setq articles (sort articles '<)
1183 subject "Digested Articles")
1184 (with-current-buffer gnus-original-article-buffer
1185 (setq subject (message-make-forward-subject))))
1187 (message-news nil subject)
1188 (message-mail nil subject))
1189 (when (and message-use-multi-frames (cdr articles))
1190 (setq frame (window-frame (get-buffer-window (current-buffer)))))
1192 (while (setq article (pop articles))
1193 (save-window-excursion
1194 (set-buffer gnus-summary-buffer)
1195 (gnus-summary-select-article nil nil nil article)
1196 (setq topics (concat topics " "
1197 (mail-header-subject gnus-current-headers)
1199 (gnus-summary-remove-process-mark article))
1201 (select-frame frame))
1202 (insert (mime-make-tag "message" "rfc822") "\n")
1203 (narrow-to-region (point) (point))
1204 (insert-buffer-substring gnus-original-article-buffer)
1206 (article-narrow-to-head)
1207 (message-remove-header message-included-forward-headers t nil t))
1208 (goto-char (point-max))
1214 (mime-edit-enclose-digest-region (point)(mark t))))))
1216 (defun gnus-summary-digest-post-forward (&optional n)
1217 "Digest and forwards all articles in this series to a newsgroup.
1218 If N is a positive number, forward the N next articles.
1219 If N is a negative number, forward the N previous articles.
1220 If N is nil and any articles have been marked with the process mark,
1221 forward those articles instead."
1223 (gnus-summary-digest-mail-forward n t))
1225 (defun gnus-summary-resend-message (address n)
1226 "Resend the current article to ADDRESS."
1228 (list (message-read-from-minibuffer
1229 "Resend message(s) to: "
1230 (when (gnus-buffer-live-p gnus-original-article-buffer)
1231 ;; If some other article is currently selected, the
1232 ;; initial-contents is wrong. Whatever, it is just the
1233 ;; initial-contents.
1234 (with-current-buffer gnus-original-article-buffer
1235 (nnmail-fetch-field "to"))))
1236 current-prefix-arg))
1237 (let ((articles (gnus-summary-work-articles n))
1239 (while (setq article (pop articles))
1240 (gnus-summary-select-article nil nil nil article)
1242 (set-buffer gnus-original-article-buffer)
1243 (message-resend address))
1244 (gnus-summary-mark-article-as-forwarded article))))
1246 (defun gnus-summary-post-forward (&optional full-headers)
1247 "Forward the current article to a newsgroup.
1248 If FULL-HEADERS (the prefix), include full headers when forwarding."
1250 (gnus-summary-mail-forward full-headers t))
1252 (defvar gnus-nastygram-message
1253 "The following article was inappropriately posted to %s.\n\n"
1254 "Format string to insert in nastygrams.
1255 The current group name will be inserted at \"%s\".")
1257 (defun gnus-summary-mail-nastygram (n)
1258 "Send a nastygram to the author of the current article."
1260 (when (or gnus-expert-user
1262 "Really send a nastygram to the author of the current article? "))
1263 (let ((group gnus-newsgroup-name))
1264 (gnus-summary-reply-with-original n)
1265 (set-buffer gnus-message-buffer)
1267 (insert (format gnus-nastygram-message group))
1268 (message-send-and-exit))))
1270 (defun gnus-summary-mail-crosspost-complaint (n)
1271 "Send a complaint about crossposting to the current article(s)."
1273 (let ((articles (gnus-summary-work-articles n))
1275 (while (setq article (pop articles))
1276 (set-buffer gnus-summary-buffer)
1277 (gnus-summary-goto-subject article)
1278 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1279 newsgroups followup-to)
1280 (gnus-summary-select-article)
1281 (set-buffer gnus-original-article-buffer)
1282 (if (and (<= (length (message-tokenize-header
1284 (mail-fetch-field "newsgroups"))
1287 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1288 (not (member group (message-tokenize-header
1289 followup-to ", ")))))
1291 (gnus-message 1 "Followup-to restricted")
1292 (gnus-message 1 "Not a crossposted article"))
1293 (set-buffer gnus-summary-buffer)
1294 (gnus-summary-reply-with-original 1)
1295 (set-buffer gnus-message-buffer)
1297 (insert (format gnus-crosspost-complaint newsgroups group))
1298 (message-goto-subject)
1299 (re-search-forward " *$")
1300 (replace-match " (crosspost notification)" t t)
1301 (gnus-deactivate-mark)
1302 (when (gnus-y-or-n-p "Send this complaint? ")
1303 (message-send-and-exit)))))))
1305 (defun gnus-mail-parse-comma-list ()
1308 (skip-chars-forward " ")
1311 (skip-chars-forward "^,")
1316 (narrow-to-region beg (point))
1319 (while (search-forward "\"" nil t)
1323 (skip-chars-forward ",")
1324 (skip-chars-forward "^,"))
1325 (skip-chars-backward " ")
1326 (push (buffer-substring beg (point))
1328 (skip-chars-forward "^,")
1329 (skip-chars-forward ", "))
1332 (defun gnus-inews-add-to-address (group)
1333 (let ((to-address (mail-fetch-field "to")))
1334 (when (and to-address
1336 ;; This mail group doesn't have a `to-list', so we add one
1338 (when (gnus-y-or-n-p
1339 (format "Do you want to add this as `to-list': %s " to-address))
1340 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1342 (defun gnus-put-message ()
1343 "Put the current message in some group and return to Gnus."
1345 (let ((reply gnus-article-reply)
1346 (winconf gnus-prev-winconf)
1347 (group gnus-newsgroup-name))
1349 (not (gnus-group-read-only-p group)))
1350 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1352 (when (gnus-gethash group gnus-newsrc-hashtb)
1353 (error "No such group: %s" group))
1357 (message-narrow-to-headers)
1358 (let ((gnus-deletable-headers nil))
1359 (message-generate-headers
1360 (if (message-news-p)
1361 message-required-news-headers
1362 message-required-mail-headers)))
1363 (goto-char (point-max))
1364 (insert "Gcc: " group "\n")
1367 (when (and (get-buffer gnus-group-buffer)
1368 (gnus-buffer-exists-p (car-safe reply))
1370 (set-buffer (car reply))
1371 (gnus-summary-mark-article-as-replied (cdr reply)))
1373 (set-window-configuration winconf))))
1375 (defun gnus-article-mail (yank)
1376 "Send a reply to the address near point.
1377 If YANK is non-nil, include the original article."
1381 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1382 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1384 (message-reply address)
1386 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1388 (defvar nntp-server-type)
1390 "Send a bug report to the Gnus maintainers."
1392 (unless (gnus-alive-p)
1393 (error "Gnus has been shut down"))
1394 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1395 (unless (message-mail-user-agent)
1396 (message-pop-to-buffer "*Gnus Bug*")
1397 (delete-other-windows)
1398 (when gnus-bug-create-help-buffer
1399 (switch-to-buffer "*Gnus Help Bug*")
1401 (insert gnus-bug-message)
1402 (goto-char (point-min))
1404 (set-buffer "*Gnus Bug*")))
1405 (let ((message-this-is-mail t))
1406 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1407 (when gnus-bug-create-help-buffer
1408 (push `(gnus-bug-kill-buffer) message-send-actions))
1409 (goto-char (point-min))
1410 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1412 (insert gnus-product-name " " gnus-version-number
1413 " (r" gnus-revision-number ") "
1414 "based on " gnus-original-product-name " v"
1415 gnus-original-version-number "\n"
1416 (emacs-version) "\n")
1417 (when (and (boundp 'nntp-server-type)
1418 (stringp nntp-server-type))
1419 (insert nntp-server-type))
1420 (insert "\n\n\n\n\n")
1421 (let (mime-content-types)
1422 (mime-edit-insert-tag
1423 "application" "emacs-lisp"
1424 "\nContent-Disposition: inline\nContent-Description: User settings"))
1425 (insert (with-temp-buffer
1428 (let (mime-content-types)
1429 (mime-edit-insert-tag "text" "plain"))
1430 (goto-char (point-min))
1431 (search-forward "Subject: " nil t)
1434 (defun gnus-bug-kill-buffer ()
1435 (when (get-buffer "*Gnus Help Bug*")
1436 (kill-buffer "*Gnus Help Bug*")))
1438 (defun gnus-summary-yank-message (buffer n)
1439 "Yank the current article into a composed message."
1441 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1442 current-prefix-arg))
1443 (when (gnus-buffer-live-p buffer)
1444 (let ((summary-frame (selected-frame))
1445 (message-frame (when (static-if (featurep 'xemacs)
1446 (device-on-window-system-p)
1448 (let ((window (get-buffer-window buffer t)))
1450 (window-frame window)))))
1451 (separator (concat "^" (regexp-quote mail-header-separator)
1453 (gnus-summary-iterate n
1454 (gnus-summary-select-article)
1455 (gnus-copy-article-buffer)
1456 (when (frame-live-p message-frame)
1457 (raise-frame message-frame)
1458 (select-frame message-frame))
1459 (with-current-buffer buffer
1460 (when (save-excursion
1462 (let (case-fold-search)
1463 (and (not (re-search-backward separator nil t))
1464 (re-search-forward separator nil t))))
1465 (goto-char (match-end 0)))
1466 (message-yank-buffer gnus-article-copy))
1467 (select-frame summary-frame))
1468 (when (frame-live-p message-frame)
1469 (select-frame message-frame)))))
1471 (defun gnus-debug ()
1472 "Attempts to go through the Gnus source file and report what variables have been changed.
1473 The source file has to be in the Emacs load path."
1475 (let ((files gnus-debug-files)
1477 file expr olist sym)
1478 (gnus-message 4 "Please wait while we snoop your variables...")
1479 ;; Go through all the files looking for non-default values for variables.
1482 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1485 (when (and (setq file (locate-library (pop files)))
1486 (file-exists-p file))
1487 (insert-file-contents file)
1488 (goto-char (point-min))
1489 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1490 (gnus-message 4 "Malformed sources in file %s" file)
1491 (narrow-to-region (point-min) (point))
1492 (goto-char (point-min))
1493 (while (setq expr (ignore-errors (read (current-buffer))))
1495 (and (memq (car expr) '(defvar defcustom defvoo))
1496 (stringp (nth 3 expr))
1497 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1498 (or (not (boundp (nth 1 expr)))
1499 (not (equal (eval (nth 2 expr))
1500 (symbol-value (nth 1 expr)))))
1501 (push (nth 1 expr) olist)))))))
1502 (kill-buffer (current-buffer)))
1503 (when (setq olist (nreverse olist))
1504 (insert ";----------------- Environment follows ------------------\n\n"))
1506 (if (boundp (car olist))
1508 (pp `(setq ,(car olist)
1509 ,(if (or (consp (setq sym (symbol-value (car olist))))
1511 (not (or (eq sym nil)
1513 (list 'quote (symbol-value (car olist)))
1514 (symbol-value (car olist))))
1517 (format "(setq %s 'whatever)\n" (car olist))))
1518 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1519 (setq olist (cdr olist)))
1520 ;; Remove any control chars - they seem to cause trouble for some
1521 ;; mailers. (Byte-compiled output from the stuff above.)
1523 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1524 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1526 ;; Break MIME tags purposely.
1528 (while (re-search-forward mime-edit-tag-regexp nil t)
1529 (goto-char (1+ (match-beginning 0)))
1532 ;;; Treatment of rejected articles.
1535 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1536 "Re-mail the current message.
1537 This only makes sense if the current message is a bounce message than
1538 contains some mail you have written which has been bounced back to
1540 If FETCH, try to fetch the article that this is a reply to, if indeed
1543 (gnus-summary-select-article t)
1544 (set-buffer gnus-original-article-buffer)
1545 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1546 (gnus-setup-message 'compose-bounce
1547 (let* ((references (mail-fetch-field "references"))
1548 (parent (and references (gnus-parent-id references))))
1550 ;; If there are references, we fetch the article we answered to.
1552 (gnus-summary-refer-article parent)
1553 (gnus-summary-show-all-headers))))))
1557 (defun gnus-inews-group-method (group)
1559 ;; If the group doesn't exist, we assume
1560 ;; it's an archive group...
1561 ((and (null (gnus-get-info group))
1562 (eq (car (gnus-server-to-method gnus-message-archive-method))
1563 (car (gnus-server-to-method (gnus-group-method group)))))
1564 gnus-message-archive-method)
1566 ((gnus-info-method (gnus-get-info group))
1567 (gnus-info-method (gnus-get-info group)))
1569 (t (gnus-server-to-method (gnus-group-method group)))))
1571 ;; Do Gcc handling, which copied the message over to some group.
1572 (defun gnus-inews-do-gcc (&optional gcc)
1576 (message-narrow-to-headers)
1577 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1578 (coding-system-for-write 'raw-text)
1579 (output-coding-system 'raw-text)
1580 groups group method group-art
1581 mml-externalize-attachments)
1583 (message-remove-header "gcc")
1585 (setq groups (message-unquote-tokens
1586 (message-tokenize-header gcc " ,")))
1587 ;; Copy the article over to some group(s).
1588 (while (setq group (pop groups))
1589 (unless (gnus-check-server
1590 (setq method (gnus-inews-group-method group)))
1591 (error "Can't open server %s" (if (stringp method) method
1593 (unless (gnus-request-group group nil method)
1594 (gnus-request-create-group group method))
1595 (setq mml-externalize-attachments
1596 (if (stringp gnus-gcc-externalize-attachments)
1597 (string-match gnus-gcc-externalize-attachments group)
1598 gnus-gcc-externalize-attachments))
1600 (nnheader-set-temp-buffer " *acc*")
1601 (insert-buffer-substring message-encoding-buffer)
1602 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1603 (goto-char (point-min))
1604 (when (re-search-forward
1605 (concat "^" (regexp-quote mail-header-separator) "$")
1607 (replace-match "" t t ))
1608 (unless (setq group-art
1609 (gnus-request-accept-article group method t t))
1610 (gnus-message 1 "Couldn't store article in group %s: %s"
1611 group (gnus-status-message method))
1613 (when (and group-art
1614 (or gnus-gcc-mark-as-read
1615 gnus-inews-mark-gcc-as-read))
1616 (gnus-group-mark-article-read group (cdr group-art)))
1617 (kill-buffer (current-buffer)))))))))
1619 (defun gnus-inews-insert-gcc ()
1620 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1623 (message-narrow-to-headers)
1624 (let* ((group gnus-outgoing-message-group)
1626 ((gnus-functionp group)
1628 ((or (stringp group) (list group))
1632 (if (stringp gcc) gcc
1633 (mapconcat 'identity gcc " "))
1636 (defun gnus-inews-insert-archive-gcc (&optional group)
1637 "Insert the Gcc to say where the article is to be archived."
1638 (let* ((var gnus-message-archive-group)
1639 (group (or group gnus-newsgroup-name ""))
1641 (and gnus-newsgroup-name
1642 (not (equal gnus-newsgroup-name ""))
1643 (gnus-group-find-parameter
1644 gnus-newsgroup-name 'gcc-self)))
1648 ((null gnus-message-archive-method)
1652 ;; Just a single group.
1655 ;; We don't want this.
1657 ((and (listp var) (stringp (car var)))
1658 ;; A list of groups.
1660 ((gnus-functionp var)
1662 (funcall var group))
1664 ;; An alist of regexps/functions/forms.
1669 ((stringp (caar var))
1671 (when (string-match (caar var) group)
1673 ((gnus-functionp (car var))
1675 (funcall (car var) group))
1677 (eval (car var)))))))
1678 (setq var (cdr var)))
1681 (when (or groups gcc-self-val)
1682 (when (stringp groups)
1683 (setq groups (list groups)))
1686 (message-narrow-to-headers)
1687 (goto-char (point-max))
1690 ;; Use the `gcc-self' param value instead.
1693 (if (stringp gcc-self-val)
1696 (if (not (eq gcc-self-val 'none))
1701 ;; Use the list of groups.
1702 (while (setq name (pop groups))
1703 (insert (if (string-match ":" name)
1705 (gnus-group-prefixed-name
1706 name gnus-message-archive-method)))
1713 (defun gnus-configure-posting-styles (&optional group-name)
1714 "Configure posting styles according to `gnus-posting-styles'."
1715 (unless gnus-inhibit-posting-styles
1716 (let ((group (or group-name gnus-newsgroup-name ""))
1717 (styles gnus-posting-styles)
1718 style match variable attribute value v results
1719 filep name address element)
1720 ;; If the group has a posting-style parameter, add it at the end with a
1721 ;; regexp matching everything, to be sure it takes precedence over all
1723 (when gnus-newsgroup-name
1724 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1726 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1727 ;; Go through all styles and look for matches.
1728 (dolist (style styles)
1729 (setq match (pop style))
1730 (goto-char (point-min))
1733 ;; Regexp string match on the group name.
1734 (string-match match group))
1736 ;; Obsolete format of header match.
1737 (and (gnus-buffer-live-p gnus-article-copy)
1738 (with-current-buffer gnus-article-copy
1739 (let ((header (message-fetch-field (pop style))))
1741 (string-match (pop style) header))))))
1742 ((or (symbolp match)
1743 (gnus-functionp match))
1745 ((gnus-functionp match)
1746 ;; Function to be called.
1749 ;; Variable to be checked.
1750 (symbol-value match))))
1753 ((eq (car match) 'header)
1754 ;; New format of header match.
1755 (and (gnus-buffer-live-p gnus-article-copy)
1756 (with-current-buffer gnus-article-copy
1757 (let ((header (message-fetch-field (nth 1 match))))
1759 (string-match (nth 2 match) header))))))
1761 ;; This is a form to be evaled.
1763 ;; We have a match, so we set the variables.
1764 (dolist (attribute style)
1765 (setq element (pop attribute)
1770 ((eq (car attribute) ':file)
1773 ((eq (car attribute) :value)
1777 ;; We get the value.
1782 ((or (symbolp value)
1783 (gnus-functionp value))
1784 (cond ((gnus-functionp value)
1787 (symbol-value value))))
1790 ;; Translate obsolescent value.
1791 (when (eq element 'signature-file)
1792 (setq element 'signature
1794 ;; Get the contents of file elems.
1796 (setq v (with-temp-buffer
1797 (insert-file-contents v)
1799 (setq results (delq (assoc element results) results))
1800 (push (cons element v) results))))
1801 ;; Now we have all the styles, so we insert them.
1802 (setq name (assq 'name results)
1803 address (assq 'address results))
1804 (setq results (delq name (delq address results)))
1805 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1806 (make-local-hook 'message-setup-hook)
1807 (dolist (result results)
1808 (add-hook 'message-setup-hook
1810 ((eq 'eval (car result))
1812 ((eq 'body (car result))
1816 (insert ,(cdr result)))))
1817 ((eq 'signature (car result))
1818 (set (make-local-variable 'message-signature) nil)
1819 (set (make-local-variable 'message-signature-file) nil)
1820 (if (not (cdr result))
1824 (let ((message-signature ,(cdr result)))
1825 (when message-signature
1826 (message-insert-signature)))))))
1829 (if (symbolp (car result))
1830 (capitalize (symbol-name (car result)))
1834 (message-remove-header ,header)
1835 (let ((value ,(cdr result)))
1838 (insert ,header ": " value "\n"))))))))
1840 (when (or name address)
1841 (add-hook 'message-setup-hook
1843 (set (make-local-variable 'user-mail-address)
1844 ,(or (cdr address) user-mail-address))
1845 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1847 ,(or (cdr address) user-mail-address)))
1849 (message-remove-header "From")
1851 (insert "From: " (message-make-from) "\n"))))
1855 ;;; @ for MIME Edit mode
1858 (defun gnus-maybe-setup-default-charset ()
1860 (and (boundp 'gnus-summary-buffer)
1861 (buffer-live-p gnus-summary-buffer)
1863 (set-buffer gnus-summary-buffer)
1864 default-mime-charset))))
1867 (make-local-variable 'default-mime-charset)
1868 (setq default-mime-charset charset)
1872 ;;; @ for MIME view mode
1875 (defun gnus-following-method (buf)
1876 (gnus-setup-message 'reply-yank
1878 (if (message-news-p)
1880 (message-reply nil 'wide))
1881 (let ((message-reply-buffer buf))
1882 (message-yank-original))
1883 (message-goto-body))
1887 ;;; Allow redefinition of functions.
1893 ;;; gnus-msg.el ends here