1 ;;; gnus-msg.el --- mail and post interface for 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>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
37 (defcustom gnus-post-method 'current
38 "*Preferred method for posting USENET news.
40 If this variable is `current' (which is the default), Gnus will use
41 the \"current\" select method when posting. If it is `native', Gnus
42 will 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 `native' nor `current', 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 :link '(custom-manual "(gnus)Posting Server")
53 :type `(choice (const native)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defcustom 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 :type '(choice (string :tag "Group")
71 (defcustom gnus-mailing-list-groups nil
72 "*Regexp matching groups that are really mailing lists.
73 This is useful when you're reading a mailing list that has been
74 gatewayed to a newsgroup, and you want to followup to an article in
79 (defcustom gnus-add-to-list nil
80 "*If non-nil, add a `to-list' parameter automatically."
84 (defcustom gnus-crosspost-complaint
87 You posted the article below with the following Newsgroups header:
91 The %s group, at least, was an inappropriate recipient
92 of this message. Please trim your Newsgroups header to exclude this
93 group before posting in the future.
98 "Format string to be inserted when complaining about crossposts.
99 The first %s will be replaced by the Newsgroups header;
100 the second with the current group name."
104 (defcustom gnus-message-setup-hook nil
105 "Hook run after setting up a message buffer."
109 (defcustom gnus-bug-create-help-buffer t
110 "*Should we create the *Gnus Help Bug* buffer?"
114 (defcustom gnus-posting-styles nil
115 "*Alist of styles to use when posting.
116 See Info node `(gnus)Posting Styles'."
118 :type '(repeat (cons (choice (regexp)
121 (string :tag "Header")
122 (regexp :tag "Regexp"))
126 (choice (const signature)
127 (const signature-file)
133 (string :tag "Header"))
139 (defcustom gnus-gcc-mark-as-read nil
140 "If non-nil, automatically mark Gcc articles as read."
145 (defvar gnus-inews-mark-gcc-as-read nil
146 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
148 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
149 'gnus-gcc-mark-as-read)
151 (defcustom gnus-gcc-externalize-attachments nil
152 "Should local-file attachments be included as external parts in Gcc copies?
153 If it is `all', attach files as external parts;
154 if a regexp and matches the Gcc group name, attach files as external parts;
155 If nil, attach files as normal parts."
158 :type '(choice (const nil :tag "None")
159 (const all :tag "Any")
160 (string :tag "Regexp")))
162 (defcustom gnus-group-posting-charset-alist
163 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
164 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
165 (message-this-is-mail nil nil)
166 (message-this-is-news nil t))
167 "Alist of regexps and permitted unencoded charsets for posting.
168 Each element of the alist has the form (TEST HEADER BODY-LIST), where
169 TEST is either a regular expression matching the newsgroup header or a
171 HEADER is the charset which may be left unencoded in the header (nil
172 means encode all charsets),
173 BODY-LIST is a list of charsets which may be encoded using 8bit
174 content-transfer encoding in the body, or one of the special values
175 nil (always encode using quoted-printable) or t (always use 8bit).
177 Note that any value other than nil for HEADER infringes some RFCs, so
178 use this option with care."
179 :type '(repeat (list :tag "Permitted unencoded charsets"
181 (regexp :tag "Group")
182 (const :tag "Mail message" :value message-this-is-mail)
183 (const :tag "News article" :value message-this-is-news))
184 (choice :tag "Header"
185 (const :tag "None" nil)
186 (symbol :tag "Charset"))
188 (const :tag "Any" :value t)
189 (const :tag "None" :value nil)
190 (repeat :tag "Charsets"
191 (symbol :tag "Charset")))))
192 :group 'gnus-charset)
194 (defcustom gnus-debug-files
195 '("gnus.el" "gnus-sum.el" "gnus-group.el"
196 "gnus-art.el" "gnus-start.el" "gnus-async.el"
197 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
198 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
199 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
200 "Files whose variables will be reported in `gnus-bug'."
203 :type '(repeat (string :tag "File")))
205 (defcustom gnus-debug-exclude-variables
206 '(mm-mime-mule-charset-alist
207 nnmail-split-fancy message-minibuffer-local-map)
208 "Variables that should not be reported in `gnus-bug'."
211 :type '(repeat (symbol :tab "Variable")))
213 ;;; Internal variables.
215 (defvar gnus-inhibit-posting-styles nil
216 "Inhibit the use of posting styles.")
218 (defvar gnus-message-buffer "*Mail Gnus*")
219 (defvar gnus-article-copy nil)
220 (defvar gnus-check-before-posting nil)
221 (defvar gnus-last-posting-server nil)
222 (defvar gnus-message-group-art nil)
224 (defvar gnus-msg-force-broken-reply-to nil)
226 (defconst gnus-bug-message
227 "Sending a bug report to the Gnus Towers.
228 ========================================
230 The buffer below is a mail buffer. When you press `C-c C-c', it will
231 be sent to the Gnus Bug Exterminators.
233 The thing near the bottom of the buffer is how the environment
234 settings will be included in the mail. Please do not delete that.
235 They will tell the Bug People what your environment is, so that it
236 will be easier to locate the bugs.
238 If you have found a bug that makes Emacs go \"beep\", set
239 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
240 and include the backtrace in your bug report.
242 Please describe the bug in annoying, painstaking detail.
244 Thank you for your help in stamping out bugs.
248 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
249 (autoload 'news-setup "rnewspost")
250 (autoload 'news-reply-mode "rnewspost")
251 (autoload 'rmail-dont-reply-to "mail-utils")
252 (autoload 'rmail-output "rmailout"))
256 ;;; Gnus Posting Functions
259 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
260 "p" gnus-summary-post-news
261 "i" gnus-summary-news-other-window
262 "f" gnus-summary-followup
263 "F" gnus-summary-followup-with-original
264 "c" gnus-summary-cancel-article
265 "s" gnus-summary-supersede-article
266 "r" gnus-summary-reply
267 "y" gnus-summary-yank-message
268 "R" gnus-summary-reply-with-original
269 "w" gnus-summary-wide-reply
270 "W" gnus-summary-wide-reply-with-original
271 "v" gnus-summary-very-wide-reply
272 "V" gnus-summary-very-wide-reply-with-original
273 "n" gnus-summary-followup-to-mail
274 "N" gnus-summary-followup-to-mail-with-original
275 "m" gnus-summary-mail-other-window
276 "u" gnus-uu-post-news
277 "\M-c" gnus-summary-mail-crosspost-complaint
278 "Br" gnus-summary-reply-broken-reply-to
279 "BR" gnus-summary-reply-broken-reply-to-with-original
280 "om" gnus-summary-mail-forward
281 "op" gnus-summary-post-forward
282 "Om" gnus-uu-digest-mail-forward
283 "Op" gnus-uu-digest-post-forward)
285 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
286 "b" gnus-summary-resend-bounced-mail
287 ;; "c" gnus-summary-send-draft
288 "r" gnus-summary-resend-message)
290 ;;; Internal functions.
292 (defvar gnus-article-reply nil)
293 (defmacro gnus-setup-message (config &rest forms)
294 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
295 (buffer (make-symbol "gnus-setup-message-buffer"))
296 (article (make-symbol "gnus-setup-message-article"))
297 (group (make-symbol "gnus-setup-message-group")))
298 `(let ((,winconf (current-window-configuration))
299 (,buffer (buffer-name (current-buffer)))
300 (,article gnus-article-reply)
301 (,group gnus-newsgroup-name)
302 (message-header-setup-hook
303 (copy-sequence message-header-setup-hook))
304 (mbl mml-buffer-list)
305 (message-mode-hook (copy-sequence message-mode-hook)))
306 (setq mml-buffer-list nil)
307 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
308 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
309 ;; #### FIXME: for a reason that I did not manage to identify yet,
310 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
311 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
312 ;; After evaluation of @forms below, it gets the value we actually want
313 ;; to override, and the posting styles are used. For that reason, I've
314 ;; added an optional argument to `gnus-configure-posting-styles' to
315 ;; make sure that the correct value for the group name is used. -- drv
316 (add-hook 'message-mode-hook
318 (gnus-configure-posting-styles ,group)))
322 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
323 (gnus-inews-insert-draft-meta-information ,group ,article)
324 (setq gnus-message-buffer (current-buffer))
325 (set (make-local-variable 'gnus-message-group-art)
326 (cons ,group ,article))
327 (set (make-local-variable 'gnus-newsgroup-name) ,group)
328 (gnus-run-hooks 'gnus-message-setup-hook)
329 (if (eq major-mode 'message-mode)
330 (let ((mbl1 mml-buffer-list))
331 (setq mml-buffer-list mbl) ;; Global value
332 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
333 ;; LOCAL argument of add-hook differs between GNU Emacs
334 ;; and XEmacs. make-local-hook makes sure they are local.
335 (make-local-hook 'kill-buffer-hook)
336 (make-local-hook 'change-major-mode-hook)
337 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
338 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
339 (mml-destroy-buffers)
340 (setq mml-buffer-list mbl)))
342 (gnus-configure-windows ,config t)
343 (run-hooks 'post-command-hook)
344 (set-buffer-modified-p nil))))
346 (defun gnus-inews-insert-draft-meta-information (group article)
349 (not (string= group ""))
350 (not (message-fetch-field gnus-draft-meta-information-header)))
351 (goto-char (point-min))
352 (insert gnus-draft-meta-information-header ": (\"" group "\" "
353 (if article (number-to-string
360 (defun gnus-msg-mail (&optional to subject other-headers continue
361 switch-action yank-action send-actions)
362 "Start editing a mail message to be sent.
363 Like `message-mail', but with Gnus paraphernalia, particularly the
364 Gcc: header for archiving purposes."
366 (let ((buf (current-buffer))
368 (gnus-setup-message 'message
369 (message-mail to subject other-headers continue
370 nil yank-action send-actions))
372 (setq mail-buf (current-buffer))
373 (switch-to-buffer buf)
374 (apply switch-action mail-buf nil)))
375 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
378 (defvar save-selected-window-window)
381 (defun gnus-button-mailto (address)
383 (set-buffer (gnus-copy-article-buffer))
384 (gnus-setup-message 'message
385 (message-reply address))
386 (and (boundp 'save-selected-window-window)
387 (not (window-live-p save-selected-window-window))
388 (setq save-selected-window-window (selected-window))))
391 (defun gnus-button-reply (&optional to-address wide)
392 "Like `message-reply'."
394 (gnus-setup-message 'message
395 (message-reply to-address wide))
396 (and (boundp 'save-selected-window-window)
397 (not (window-live-p save-selected-window-window))
398 (setq save-selected-window-window (selected-window))))
401 (define-mail-user-agent 'gnus-user-agent
402 'gnus-msg-mail 'message-send-and-exit
403 'message-kill-buffer 'message-send-hook)
405 (defun gnus-setup-posting-charset (group)
406 (let ((alist gnus-group-posting-charset-alist)
407 (group (or group ""))
411 (while (setq elem (pop alist))
412 (when (or (and (stringp (car elem))
413 (string-match (car elem) group))
414 (and (gnus-functionp (car elem))
415 (funcall (car elem) group))
416 (and (symbolp (car elem))
417 (symbol-value (car elem))))
418 (throw 'found (cons (cadr elem) (caddr elem)))))))))
420 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
421 (make-local-hook 'message-sent-hook)
422 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
423 'gnus-inews-do-gcc) nil t)
425 (make-local-hook 'message-header-hook)
426 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
427 (setq message-post-method
429 (gnus-post-method arg ,gnus-newsgroup-name)))
430 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
432 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
434 `(when (gnus-buffer-exists-p ,buffer)
438 (if (eq config 'forward)
439 `(gnus-summary-mark-article-as-forwarded ',article)
440 `(gnus-summary-mark-article-as-replied ',article)))))
443 (put 'gnus-setup-message 'lisp-indent-function 1)
444 (put 'gnus-setup-message 'edebug-form-spec '(form body))
446 ;;; Post news commands of Gnus group mode and summary mode
448 (defun gnus-group-mail (&optional arg)
449 "Start composing a mail.
450 If ARG, use the group under the point to find a posting style.
451 If ARG is 1, prompt for a group name to find the posting style."
453 ;; We can't `let' gnus-newsgroup-name here, since that leads
454 ;; to local variables leaking.
455 (let ((group gnus-newsgroup-name)
456 (buffer (current-buffer)))
459 (setq gnus-newsgroup-name
461 (if (= 1 (prefix-numeric-value arg))
462 (completing-read "Use posting style of group: "
463 gnus-active-hashtb nil
464 (gnus-read-active-file-p))
465 (gnus-group-group-name))
467 ;; #### see comment in gnus-setup-message -- drv
468 (gnus-setup-message 'message (message-mail)))
471 (setq gnus-newsgroup-name group)))))
473 (defun gnus-group-news (&optional arg)
474 "Start composing a news.
475 If ARG, post to group under point.
476 If ARG is 1, prompt for group name to post to.
478 This function prepares a news even when using mail groups. This is useful
479 for posting messages to mail groups without actually sending them over the
480 network. The corresponding backend must have a 'request-post method."
482 ;; We can't `let' gnus-newsgroup-name here, since that leads
483 ;; to local variables leaking.
484 (let ((group gnus-newsgroup-name)
485 (buffer (current-buffer)))
488 (setq gnus-newsgroup-name
490 (if (= 1 (prefix-numeric-value arg))
491 (completing-read "Use group: "
492 gnus-active-hashtb nil
493 (gnus-read-active-file-p))
494 (gnus-group-group-name))
496 ;; #### see comment in gnus-setup-message -- drv
497 (gnus-setup-message 'message
498 (message-news (gnus-group-real-name gnus-newsgroup-name))))
501 (setq gnus-newsgroup-name group)))))
503 (defun gnus-group-post-news (&optional arg)
504 "Start composing a message (a news by default).
505 If ARG, post to group under point. If ARG is 1, prompt for group name.
506 Depending on the selected group, the message might be either a mail or
509 ;; Bind this variable here to make message mode hooks work ok.
510 (let ((gnus-newsgroup-name
512 (if (= 1 (prefix-numeric-value arg))
513 (completing-read "Newsgroup: " gnus-active-hashtb nil
514 (gnus-read-active-file-p))
515 (gnus-group-group-name))
517 (gnus-post-news 'post gnus-newsgroup-name)))
519 (defun gnus-summary-mail-other-window (&optional arg)
520 "Start composing a mail in another window.
521 Use the posting of the current group by default.
522 If ARG, don't do that. If ARG is 1, prompt for group name to find the
525 ;; We can't `let' gnus-newsgroup-name here, since that leads
526 ;; to local variables leaking.
527 (let ((group gnus-newsgroup-name)
528 (buffer (current-buffer)))
531 (setq gnus-newsgroup-name
533 (if (= 1 (prefix-numeric-value arg))
534 (completing-read "Use group: "
535 gnus-active-hashtb nil
536 (gnus-read-active-file-p))
538 gnus-newsgroup-name))
539 ;; #### see comment in gnus-setup-message -- drv
540 (gnus-setup-message 'message (message-mail)))
543 (setq gnus-newsgroup-name group)))))
545 (defun gnus-summary-news-other-window (&optional arg)
546 "Start composing a news in another window.
547 Post to the current group by default.
548 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
550 This function prepares a news even when using mail groups. This is useful
551 for posting messages to mail groups without actually sending them over the
552 network. The corresponding backend must have a 'request-post method."
554 ;; We can't `let' gnus-newsgroup-name here, since that leads
555 ;; to local variables leaking.
556 (let ((group gnus-newsgroup-name)
557 (buffer (current-buffer)))
560 (setq gnus-newsgroup-name
562 (if (= 1 (prefix-numeric-value arg))
563 (completing-read "Use group: "
564 gnus-active-hashtb nil
565 (gnus-read-active-file-p))
567 gnus-newsgroup-name))
568 ;; #### see comment in gnus-setup-message -- drv
569 (gnus-setup-message 'message
570 (message-news (gnus-group-real-name gnus-newsgroup-name))))
573 (setq gnus-newsgroup-name group)))))
575 (defun gnus-summary-post-news (&optional arg)
576 "Start composing a message. Post to the current group by default.
577 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
578 Depending on the selected group, the message might be either a mail or
581 ;; Bind this variable here to make message mode hooks work ok.
582 (let ((gnus-newsgroup-name
584 (if (= 1 (prefix-numeric-value arg))
585 (completing-read "Newsgroup: " gnus-active-hashtb nil
586 (gnus-read-active-file-p))
588 gnus-newsgroup-name)))
589 (gnus-post-news 'post gnus-newsgroup-name)))
592 (defun gnus-summary-followup (yank &optional force-news)
593 "Compose a followup to an article.
594 If prefix argument YANK is non-nil, the original article is yanked
596 YANK is a list of elements, where the car of each element is the
597 article number, and the two following numbers is the region to be
600 (list (and current-prefix-arg
601 (gnus-summary-work-articles 1))))
603 (gnus-summary-goto-subject
604 (if (listp (car yank))
607 (save-window-excursion
608 (gnus-summary-select-article))
609 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
610 (gnus-newsgroup-name gnus-newsgroup-name))
612 (gnus-post-news nil gnus-newsgroup-name
613 headers gnus-article-buffer
614 yank nil force-news)))
616 (defun gnus-summary-followup-with-original (n &optional force-news)
617 "Compose a followup to an article and include the original article."
619 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
621 (defun gnus-summary-followup-to-mail (&optional arg)
622 "Followup to the current mail message via news."
624 (list (and current-prefix-arg
625 (gnus-summary-work-articles 1))))
626 (gnus-summary-followup arg t))
628 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
629 "Followup to the current mail message via news."
631 (gnus-summary-followup (gnus-summary-work-articles arg) t))
633 (defun gnus-inews-yank-articles (articles)
634 (let (beg article yank-string)
636 (while (setq article (pop articles))
637 (when (listp article)
638 (setq yank-string (nth 1 article)
639 article (nth 0 article)))
640 (save-window-excursion
641 (set-buffer gnus-summary-buffer)
642 (gnus-summary-select-article nil nil nil article)
643 (gnus-summary-remove-process-mark article))
644 (gnus-copy-article-buffer nil yank-string)
645 (let ((message-reply-buffer gnus-article-copy)
646 (message-reply-headers
647 ;; The headers are decoded.
648 (with-current-buffer gnus-article-copy
649 (nnheader-parse-head t))))
650 (message-yank-original)
651 (setq beg (or beg (mark t))))
657 (defun gnus-summary-cancel-article (&optional n symp)
658 "Cancel an article you posted.
659 Uses the process-prefix convention. If given the symbolic
660 prefix `a', cancel using the standard posting method; if not
661 post using the current select method."
662 (interactive (gnus-interactive "P\ny"))
663 (let ((articles (gnus-summary-work-articles n))
666 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
668 (while (setq article (pop articles))
669 (when (gnus-summary-select-article t nil nil article)
670 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
671 (message-cancel-news))
672 (gnus-summary-mark-as-read article gnus-canceled-mark)
673 (gnus-cache-remove-article 1))
674 (gnus-article-hide-headers-if-wanted))
675 (gnus-summary-remove-process-mark article))))
677 (defun gnus-summary-supersede-article ()
678 "Compose an article that will supersede a previous article.
679 This is done simply by taking the old article and adding a Supersedes
680 header line with the old Message-ID."
682 (let ((article (gnus-summary-article-number)))
683 (gnus-setup-message 'reply-yank
684 (gnus-summary-select-article t)
685 (set-buffer gnus-original-article-buffer)
689 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
691 (set-buffer ,gnus-summary-buffer)
692 (gnus-cache-possibly-remove-article ,article nil nil nil t)
693 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
694 message-send-actions))))
698 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
699 ;; make a copy of the article buffer with all text properties removed
700 ;; this copy is in the buffer gnus-article-copy.
701 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
702 ;; this buffer should be passed to all mail/news reply/post routines.
703 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
705 (set-buffer gnus-article-copy)
706 (mm-enable-multibyte))
707 (let ((article-buffer (or article-buffer gnus-article-buffer))
709 (if (not (and (get-buffer article-buffer)
710 (gnus-buffer-exists-p article-buffer)))
711 (error "Can't find any article buffer")
713 (set-buffer article-buffer)
714 (let ((gnus-newsgroup-charset (or gnus-article-charset
715 gnus-newsgroup-charset))
716 (gnus-newsgroup-ignored-charsets
717 (or gnus-article-ignored-charsets
718 gnus-newsgroup-ignored-charsets)))
720 ;; Copy over the (displayed) article buffer, delete
721 ;; hidden text and remove text properties.
723 (copy-to-buffer gnus-article-copy (point-min) (point-max))
724 (set-buffer gnus-article-copy)
727 (delete-region (point) (point-max))
728 (insert yank-string))
729 (gnus-article-delete-text-of-type 'annotation)
730 (gnus-remove-text-with-property 'gnus-prev)
731 (gnus-remove-text-with-property 'gnus-next)
734 (buffer-substring-no-properties (point-min) (point-max))
736 ;; Find the original headers.
737 (set-buffer gnus-original-article-buffer)
738 (goto-char (point-min))
739 (while (looking-at message-unix-mail-delimiter)
742 end (or (message-goto-body) beg))
743 ;; Delete the headers from the displayed articles.
744 (set-buffer gnus-article-copy)
745 (delete-region (goto-char (point-min))
746 (or (message-goto-body) (point-max)))
747 ;; Insert the original article headers.
748 (insert-buffer-substring gnus-original-article-buffer beg end)
750 (let ((gnus-article-decode-hook
751 (delq 'article-decode-charset
752 (copy-sequence gnus-article-decode-hook))))
753 (run-hooks 'gnus-article-decode-hook)))))
756 (defun gnus-post-news (post &optional group header article-buffer yank subject
759 (gnus-copy-article-buffer))
760 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
761 (add-to-list gnus-add-to-list))
762 (gnus-setup-message (cond (yank 'reply-yank)
763 (article-buffer 'reply)
765 (let* ((group (or group gnus-newsgroup-name))
766 (charset (gnus-group-name-charset nil group))
768 to-address to-group mailing-list to-list
771 (setq to-address (gnus-parameter-to-address group)
772 to-group (gnus-group-find-parameter group 'to-group)
773 to-list (gnus-parameter-to-list group)
774 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
775 mailing-list (when gnus-mailing-list-groups
776 (string-match gnus-mailing-list-groups group))
777 group (gnus-group-name-decode (gnus-group-real-name group)
779 (if (or (and to-group
780 (gnus-news-group-p to-group))
783 (and (gnus-news-group-p
784 (or pgroup gnus-newsgroup-name)
785 (or header gnus-current-article))
791 (message-news (or to-group group))
792 (set-buffer gnus-article-copy)
793 (gnus-msg-treat-broken-reply-to)
794 (message-followup (if (or newsgroup-p force-news)
795 (if (save-restriction
796 (article-narrow-to-head)
797 (message-fetch-field "newsgroups"))
804 (message-mail (or to-address to-list))
805 ;; Arrange for mail groups that have no `to-address' to
806 ;; get that when the user sends off the mail.
807 (when (and (not to-list)
810 (push (list 'gnus-inews-add-to-address pgroup)
811 message-send-actions)))
812 (set-buffer gnus-article-copy)
813 (gnus-msg-treat-broken-reply-to)
814 (message-wide-reply to-address)))
816 (gnus-inews-yank-articles yank))))))
818 (defun gnus-msg-treat-broken-reply-to (&optional force)
819 "Remove the Reply-to header iff broken-reply-to."
821 (gnus-group-find-parameter
822 gnus-newsgroup-name 'broken-reply-to))
824 (message-narrow-to-head)
825 (message-remove-header "reply-to"))))
827 (defun gnus-post-method (arg group &optional silent)
828 "Return the posting method based on GROUP and ARG.
829 If SILENT, don't prompt the user."
830 (let ((gnus-post-method (or (gnus-parameter-post-method group)
832 (group-method (gnus-find-method-for-group group)))
834 ;; If the group-method is nil (which shouldn't happen) we use
835 ;; the default method.
837 (or (and (listp gnus-post-method) ;If not current/native/nil
838 (not (listp (car gnus-post-method))) ; and not a list of methods
839 gnus-post-method) ;then use it.
841 message-post-method))
842 ;; We want the inverse of the default
843 ((and arg (not (eq arg 0)))
844 (if (eq gnus-post-method 'current)
847 ;; We query the user for a post method.
849 (and (listp gnus-post-method)
850 (listp (car gnus-post-method))))
852 ;; Collect all methods we know about.
854 (when (listp gnus-post-method)
855 (if (listp (car gnus-post-method))
857 (list gnus-post-method)))
858 gnus-secondary-select-methods
859 (mapcar 'cdr gnus-server-alist)
860 (mapcar 'car gnus-opened-servers)
861 (list gnus-select-method)
862 (list group-method)))
863 method-alist post-methods method)
864 ;; Weed out all mail methods.
866 (setq method (gnus-server-get-method "" (pop methods)))
867 (when (and (or (gnus-method-option-p method 'post)
868 (gnus-method-option-p method 'post-mail))
869 (not (member method post-methods)))
870 (push method post-methods)))
871 ;; Create a name-method alist.
875 (if (equal (cadr m) "")
876 (list (symbol-name (car m)) m)
877 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
882 (setq gnus-last-posting-server
884 gnus-last-posting-server)
885 ;; Just use the last value.
886 gnus-last-posting-server
888 "Posting method: " method-alist nil t
889 (cons (or gnus-last-posting-server "") 0))))
891 ;; Override normal method.
892 ((and (eq gnus-post-method 'current)
893 (not (eq (car group-method) 'nndraft))
894 (gnus-get-function group-method 'request-post t))
897 ;; Use gnus-post-method.
898 ((listp gnus-post-method) ;A method...
899 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
901 ;; Use the normal select method (nil or native).
902 (t gnus-select-method))))
906 ;; Dummies to avoid byte-compile warning.
908 (defvar nnspool-rejected-article-hook)
909 (defvar xemacs-codename))
911 (defun gnus-extended-version ()
912 "Stringified Gnus version and Emacs version."
915 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
916 " (" gnus-version ")"
919 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
920 (concat "Emacs/" (match-string 1 emacs-version)
921 " (" system-configuration ")"))
922 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
924 (concat (match-string 1 emacs-version)
925 (format "/%d.%d" emacs-major-version emacs-minor-version)
926 (if (match-beginning 3)
927 (match-string 3 emacs-version)
929 (if (boundp 'xemacs-codename)
930 (concat " (" xemacs-codename ", " system-configuration ")")
936 ;;; Gnus Mail Functions
939 ;;; Mail reply commands of Gnus summary mode
941 (defun gnus-summary-reply (&optional yank wide very-wide)
942 "Start composing a mail reply to the current message.
943 If prefix argument YANK is non-nil, the original article is yanked
945 If WIDE, make a wide reply.
946 If VERY-WIDE, make a very wide reply."
948 (list (and current-prefix-arg
949 (gnus-summary-work-articles 1))))
951 (if (listp (car yank))
954 (gnus-article-reply (or article (gnus-summary-article-number)))
956 ;; Stripping headers should be specified with mail-yank-ignored-headers.
958 (gnus-summary-goto-subject article))
959 (gnus-setup-message (if yank 'reply-yank 'reply)
961 (gnus-summary-select-article)
962 (dolist (article very-wide)
963 (gnus-summary-select-article nil nil nil article)
965 (set-buffer (gnus-copy-article-buffer))
966 (gnus-msg-treat-broken-reply-to)
968 (message-narrow-to-head)
969 (setq headers (concat headers (buffer-string)))))))
970 (set-buffer (gnus-copy-article-buffer))
971 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
973 (message-narrow-to-head)
977 (goto-char (point-max)))
978 (mml-quote-region (point) (point-max))
979 (message-reply nil wide)
981 (gnus-inews-yank-articles yank)))))
983 (defun gnus-summary-reply-with-original (n &optional wide)
984 "Start composing a reply mail to the current message.
985 The original article will be yanked."
987 (gnus-summary-reply (gnus-summary-work-articles n) wide))
989 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
990 "Like `gnus-summary-reply' except removing reply-to field.
991 If prefix argument YANK is non-nil, the original article is yanked
993 If WIDE, make a wide reply.
994 If VERY-WIDE, make a very wide reply."
996 (list (and current-prefix-arg
997 (gnus-summary-work-articles 1))))
998 (let ((gnus-msg-force-broken-reply-to t))
999 (gnus-summary-reply yank wide very-wide)))
1001 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1002 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1003 The original article will be yanked."
1005 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1007 (defun gnus-summary-wide-reply (&optional yank)
1008 "Start composing a wide reply mail to the current message.
1009 If prefix argument YANK is non-nil, the original article is yanked
1012 (list (and current-prefix-arg
1013 (gnus-summary-work-articles 1))))
1014 (gnus-summary-reply yank t))
1016 (defun gnus-summary-wide-reply-with-original (n)
1017 "Start composing a wide reply mail to the current message.
1018 The original article will be yanked."
1020 (gnus-summary-reply-with-original n t))
1022 (defun gnus-summary-very-wide-reply (&optional yank)
1023 "Start composing a very wide reply mail to the current message.
1024 If prefix argument YANK is non-nil, the original article is yanked
1027 (list (and current-prefix-arg
1028 (gnus-summary-work-articles 1))))
1029 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1031 (defun gnus-summary-very-wide-reply-with-original (n)
1032 "Start composing a very wide reply mail to the current message.
1033 The original article will be yanked."
1036 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1038 (defun gnus-summary-mail-forward (&optional arg post)
1039 "Forward the current message(s) to another user.
1040 If process marks exist, forward all marked messages;
1041 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1042 if ARG is 1, decode the message and forward directly inline;
1043 if ARG is 2, forward message as an rfc822 MIME section;
1044 if ARG is 3, decode message and forward as an rfc822 MIME section;
1045 if ARG is 4, forward message directly inline;
1046 otherwise, use flipped `message-forward-as-mime'.
1047 If POST, post instead of mail.
1048 For the `inline' alternatives, also see the variable
1049 `message-forward-ignored-headers'."
1051 (if (null (cdr (gnus-summary-work-articles nil)))
1052 (let ((message-forward-as-mime message-forward-as-mime)
1053 (message-forward-show-mml message-forward-show-mml))
1057 (setq message-forward-as-mime nil
1058 message-forward-show-mml t))
1060 (setq message-forward-as-mime t
1061 message-forward-show-mml nil))
1063 (setq message-forward-as-mime t
1064 message-forward-show-mml t))
1066 (setq message-forward-as-mime nil
1067 message-forward-show-mml nil))
1069 (setq message-forward-as-mime (not message-forward-as-mime))))
1070 (let ((gnus-article-reply (gnus-summary-article-number)))
1071 (gnus-setup-message 'forward
1072 (gnus-summary-select-article)
1073 (let ((mail-parse-charset
1074 (or (and (gnus-buffer-live-p gnus-article-buffer)
1075 (with-current-buffer gnus-article-buffer
1076 gnus-article-charset))
1077 gnus-newsgroup-charset))
1078 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
1079 (set-buffer gnus-original-article-buffer)
1080 (message-forward post)))))
1081 (gnus-uu-digest-mail-forward arg post)))
1083 (defun gnus-summary-resend-message (address n)
1084 "Resend the current article to ADDRESS."
1086 (list (message-read-from-minibuffer
1087 "Resend message(s) to: "
1088 (when (gnus-buffer-live-p gnus-original-article-buffer)
1089 ;; If some other article is currently selected, the
1090 ;; initial-contents is wrong. Whatever, it is just the
1091 ;; initial-contents.
1092 (with-current-buffer gnus-original-article-buffer
1093 (nnmail-fetch-field "to"))))
1094 current-prefix-arg))
1095 (let ((articles (gnus-summary-work-articles n))
1097 (while (setq article (pop articles))
1098 (gnus-summary-select-article nil nil nil article)
1100 (set-buffer gnus-original-article-buffer)
1101 (message-resend address))
1102 (gnus-summary-mark-article-as-forwarded article))))
1104 (defun gnus-summary-post-forward (&optional arg)
1105 "Forward the current article to a newsgroup.
1106 See `gnus-summary-mail-forward' for ARG."
1108 (gnus-summary-mail-forward arg t))
1110 (defvar gnus-nastygram-message
1111 "The following article was inappropriately posted to %s.\n\n"
1112 "Format string to insert in nastygrams.
1113 The current group name will be inserted at \"%s\".")
1115 (defun gnus-summary-mail-nastygram (n)
1116 "Send a nastygram to the author of the current article."
1118 (when (or gnus-expert-user
1120 "Really send a nastygram to the author of the current article? "))
1121 (let ((group gnus-newsgroup-name))
1122 (gnus-summary-reply-with-original n)
1123 (set-buffer gnus-message-buffer)
1125 (insert (format gnus-nastygram-message group))
1126 (message-send-and-exit))))
1128 (defun gnus-summary-mail-crosspost-complaint (n)
1129 "Send a complaint about crossposting to the current article(s)."
1131 (let ((articles (gnus-summary-work-articles n))
1133 (while (setq article (pop articles))
1134 (set-buffer gnus-summary-buffer)
1135 (gnus-summary-goto-subject article)
1136 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1137 newsgroups followup-to)
1138 (gnus-summary-select-article)
1139 (set-buffer gnus-original-article-buffer)
1140 (if (and (<= (length (message-tokenize-header
1142 (mail-fetch-field "newsgroups"))
1145 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1146 (not (member group (message-tokenize-header
1147 followup-to ", ")))))
1149 (gnus-message 1 "Followup-to restricted")
1150 (gnus-message 1 "Not a crossposted article"))
1151 (set-buffer gnus-summary-buffer)
1152 (gnus-summary-reply-with-original 1)
1153 (set-buffer gnus-message-buffer)
1155 (insert (format gnus-crosspost-complaint newsgroups group))
1156 (message-goto-subject)
1157 (re-search-forward " *$")
1158 (replace-match " (crosspost notification)" t t)
1159 (gnus-deactivate-mark)
1160 (when (gnus-y-or-n-p "Send this complaint? ")
1161 (message-send-and-exit)))))))
1163 (defun gnus-mail-parse-comma-list ()
1166 (skip-chars-forward " ")
1169 (skip-chars-forward "^,")
1174 (narrow-to-region beg (point))
1177 (while (search-forward "\"" nil t)
1181 (skip-chars-forward ",")
1182 (skip-chars-forward "^,"))
1183 (skip-chars-backward " ")
1184 (push (buffer-substring beg (point))
1186 (skip-chars-forward "^,")
1187 (skip-chars-forward ", "))
1190 (defun gnus-inews-add-to-address (group)
1191 (let ((to-address (mail-fetch-field "to")))
1192 (when (and to-address
1194 ;; This mail group doesn't have a `to-list', so we add one
1196 (when (gnus-y-or-n-p
1197 (format "Do you want to add this as `to-list': %s " to-address))
1198 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1200 (defun gnus-put-message ()
1201 "Put the current message in some group and return to Gnus."
1203 (let ((reply gnus-article-reply)
1204 (winconf gnus-prev-winconf)
1205 (group gnus-newsgroup-name))
1207 (not (gnus-group-read-only-p group)))
1208 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1210 (when (gnus-gethash group gnus-newsrc-hashtb)
1211 (error "No such group: %s" group))
1215 (message-narrow-to-headers)
1216 (let ((gnus-deletable-headers nil))
1217 (message-generate-headers
1218 (if (message-news-p)
1219 message-required-news-headers
1220 message-required-mail-headers)))
1221 (goto-char (point-max))
1222 (insert "Gcc: " group "\n")
1225 (when (and (get-buffer gnus-group-buffer)
1226 (gnus-buffer-exists-p (car-safe reply))
1228 (set-buffer (car reply))
1229 (gnus-summary-mark-article-as-replied (cdr reply)))
1231 (set-window-configuration winconf))))
1233 (defun gnus-article-mail (yank)
1234 "Send a reply to the address near point.
1235 If YANK is non-nil, include the original article."
1239 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1240 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1242 (message-reply address)
1244 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1246 (defvar nntp-server-type)
1248 "Send a bug report to the Gnus maintainers."
1250 (unless (gnus-alive-p)
1251 (error "Gnus has been shut down"))
1252 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1253 (unless (message-mail-user-agent)
1254 (delete-other-windows)
1255 (when gnus-bug-create-help-buffer
1256 (switch-to-buffer "*Gnus Help Bug*")
1258 (insert gnus-bug-message)
1259 (goto-char (point-min)))
1260 (message-pop-to-buffer "*Gnus Bug*"))
1261 (let ((message-this-is-mail t))
1262 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1263 (when gnus-bug-create-help-buffer
1264 (push `(gnus-bug-kill-buffer) message-send-actions))
1265 (goto-char (point-min))
1266 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1268 (insert (gnus-version) "\n"
1269 (emacs-version) "\n")
1270 (when (and (boundp 'nntp-server-type)
1271 (stringp nntp-server-type))
1272 (insert nntp-server-type))
1273 (insert "\n\n\n\n\n")
1276 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1279 (setq text (buffer-string)))
1280 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1281 (goto-char (point-min))
1282 (search-forward "Subject: " nil t)
1285 (defun gnus-bug-kill-buffer ()
1286 (when (get-buffer "*Gnus Help Bug*")
1287 (kill-buffer "*Gnus Help Bug*")))
1289 (defun gnus-summary-yank-message (buffer n)
1290 "Yank the current article into a composed message."
1292 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1293 current-prefix-arg))
1294 (gnus-summary-iterate n
1295 (let ((gnus-display-mime-function nil)
1296 (gnus-inhibit-treatment t))
1297 (gnus-summary-select-article))
1300 (message-yank-buffer gnus-article-buffer))))
1302 (defun gnus-debug ()
1303 "Attempts to go through the Gnus source file and report what variables have been changed.
1304 The source file has to be in the Emacs load path."
1306 (let ((files gnus-debug-files)
1308 file expr olist sym)
1309 (gnus-message 4 "Please wait while we snoop your variables...")
1311 ;; Go through all the files looking for non-default values for variables.
1313 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1316 (when (and (setq file (locate-library (pop files)))
1317 (file-exists-p file))
1318 (insert-file-contents file)
1319 (goto-char (point-min))
1320 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1321 (gnus-message 4 "Malformed sources in file %s" file)
1322 (narrow-to-region (point-min) (point))
1323 (goto-char (point-min))
1324 (while (setq expr (ignore-errors (read (current-buffer))))
1326 (and (or (eq (car expr) 'defvar)
1327 (eq (car expr) 'defcustom))
1328 (stringp (nth 3 expr))
1329 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1330 (or (not (boundp (nth 1 expr)))
1331 (not (equal (eval (nth 2 expr))
1332 (symbol-value (nth 1 expr)))))
1333 (push (nth 1 expr) olist)))))))
1334 (kill-buffer (current-buffer)))
1335 (when (setq olist (nreverse olist))
1336 (insert "------------------ Environment follows ------------------\n\n"))
1338 (if (boundp (car olist))
1340 (pp `(setq ,(car olist)
1341 ,(if (or (consp (setq sym (symbol-value (car olist))))
1343 (not (or (eq sym nil)
1345 (list 'quote (symbol-value (car olist)))
1346 (symbol-value (car olist))))
1349 (format "(setq %s 'whatever)\n" (car olist))))
1350 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1351 (setq olist (cdr olist)))
1353 ;; Remove any control chars - they seem to cause trouble for some
1354 ;; mailers. (Byte-compiled output from the stuff above.)
1356 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1357 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1360 ;;; Treatment of rejected articles.
1363 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1364 "Re-mail the current message.
1365 This only makes sense if the current message is a bounce message than
1366 contains some mail you have written which has been bounced back to
1368 If FETCH, try to fetch the article that this is a reply to, if indeed
1371 (gnus-summary-select-article t)
1372 (set-buffer gnus-original-article-buffer)
1373 (gnus-setup-message 'compose-bounce
1374 (let* ((references (mail-fetch-field "references"))
1375 (parent (and references (gnus-parent-id references))))
1377 ;; If there are references, we fetch the article we answered to.
1379 (gnus-summary-refer-article parent)
1380 (gnus-summary-show-all-headers)))))
1384 (defun gnus-inews-group-method (group)
1386 ;; If the group doesn't exist, we assume
1387 ;; it's an archive group...
1388 ((and (null (gnus-get-info group))
1389 (eq (car (gnus-server-to-method gnus-message-archive-method))
1390 (car (gnus-server-to-method (gnus-group-method group)))))
1391 gnus-message-archive-method)
1393 ((gnus-info-method (gnus-get-info group))
1394 (gnus-info-method (gnus-get-info group)))
1396 (t (gnus-server-to-method (gnus-group-method group)))))
1398 ;; Do Gcc handling, which copied the message over to some group.
1399 (defun gnus-inews-do-gcc (&optional gcc)
1403 (message-narrow-to-headers)
1404 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1405 (cur (current-buffer))
1406 groups group method group-art
1407 mml-externalize-attachments)
1409 (message-remove-header "gcc")
1411 (setq groups (message-unquote-tokens
1412 (message-tokenize-header gcc " ,")))
1413 ;; Copy the article over to some group(s).
1414 (while (setq group (pop groups))
1415 (unless (gnus-check-server
1416 (setq method (gnus-inews-group-method group)))
1417 (error "Can't open server %s" (if (stringp method) method
1419 (unless (gnus-request-group group nil method)
1420 (gnus-request-create-group group method))
1421 (setq mml-externalize-attachments
1422 (if (stringp gnus-gcc-externalize-attachments)
1423 (string-match gnus-gcc-externalize-attachments group)
1424 gnus-gcc-externalize-attachments))
1426 (nnheader-set-temp-buffer " *acc*")
1427 (insert-buffer-substring cur)
1428 (message-encode-message-body)
1430 (message-narrow-to-headers)
1431 (let* ((mail-parse-charset message-default-charset)
1432 (newsgroups-field (save-restriction
1433 (message-narrow-to-headers-or-head)
1434 (message-fetch-field "Newsgroups")))
1435 (followup-field (save-restriction
1436 (message-narrow-to-headers-or-head)
1437 (message-fetch-field "Followup-To")))
1438 ;; BUG: We really need to get the charset for
1439 ;; each name in the Newsgroups and Followup-To
1440 ;; lines to allow crossposting between group
1441 ;; namess with incompatible character sets.
1442 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1443 (group-field-charset
1444 (gnus-group-name-charset
1445 method (or newsgroups-field "")))
1446 (followup-field-charset
1447 (gnus-group-name-charset
1448 method (or followup-field "")))
1449 (rfc2047-header-encoding-alist
1451 (when group-field-charset
1452 (list (cons "Newsgroups" group-field-charset)))
1453 (when followup-field-charset
1454 (list (cons "Followup-To" followup-field-charset)))
1455 rfc2047-header-encoding-alist)))
1456 (mail-encode-encoded-word-buffer)))
1457 (goto-char (point-min))
1458 (when (re-search-forward
1459 (concat "^" (regexp-quote mail-header-separator) "$")
1461 (replace-match "" t t ))
1462 (unless (setq group-art
1463 (gnus-request-accept-article group method t t))
1464 (gnus-message 1 "Couldn't store article in group %s: %s"
1465 group (gnus-status-message method))
1467 (when (and group-art
1468 (or gnus-gcc-mark-as-read
1469 gnus-inews-mark-gcc-as-read))
1470 (gnus-group-mark-article-read group (cdr group-art)))
1471 (kill-buffer (current-buffer)))))))))
1473 (defun gnus-inews-insert-gcc ()
1474 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1477 (message-narrow-to-headers)
1478 (let* ((group gnus-outgoing-message-group)
1480 ((gnus-functionp group)
1482 ((or (stringp group) (list group))
1486 (if (stringp gcc) gcc
1487 (mapconcat 'identity gcc " "))
1490 (defun gnus-inews-insert-archive-gcc (&optional group)
1491 "Insert the Gcc to say where the article is to be archived."
1492 (let* ((var gnus-message-archive-group)
1493 (group (or group gnus-newsgroup-name ""))
1495 (and gnus-newsgroup-name
1496 (not (equal gnus-newsgroup-name ""))
1497 (gnus-group-find-parameter
1498 gnus-newsgroup-name 'gcc-self)))
1502 ((null gnus-message-archive-method)
1506 ;; Just a single group.
1509 ;; We don't want this.
1511 ((and (listp var) (stringp (car var)))
1512 ;; A list of groups.
1514 ((gnus-functionp var)
1516 (funcall var group))
1518 ;; An alist of regexps/functions/forms.
1523 ((stringp (caar var))
1525 (when (string-match (caar var) group)
1527 ((gnus-functionp (car var))
1529 (funcall (car var) group))
1531 (eval (car var)))))))
1532 (setq var (cdr var)))
1535 (when (or groups gcc-self-val)
1536 (when (stringp groups)
1537 (setq groups (list groups)))
1540 (message-narrow-to-headers)
1541 (goto-char (point-max))
1544 ;; Use the `gcc-self' param value instead.
1547 (if (stringp gcc-self-val)
1550 (if (not (eq gcc-self-val 'none))
1555 ;; Use the list of groups.
1556 (while (setq name (pop groups))
1557 (insert (if (string-match ":" name)
1559 (gnus-group-prefixed-name
1560 name gnus-message-archive-method)))
1567 (defun gnus-configure-posting-styles (&optional group-name)
1568 "Configure posting styles according to `gnus-posting-styles'."
1569 (unless gnus-inhibit-posting-styles
1570 (let ((group (or group-name gnus-newsgroup-name ""))
1571 (styles gnus-posting-styles)
1572 style match variable attribute value v results
1573 filep name address element)
1574 ;; If the group has a posting-style parameter, add it at the end with a
1575 ;; regexp matching everything, to be sure it takes precedence over all
1577 (when gnus-newsgroup-name
1578 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1580 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1581 ;; Go through all styles and look for matches.
1582 (dolist (style styles)
1583 (setq match (pop style))
1584 (goto-char (point-min))
1587 ;; Regexp string match on the group name.
1588 (string-match match group))
1590 ;; Obsolete format of header match.
1591 (and (gnus-buffer-live-p gnus-article-copy)
1592 (with-current-buffer gnus-article-copy
1593 (let ((header (message-fetch-field (pop style))))
1595 (string-match (pop style) header))))))
1596 ((or (symbolp match)
1597 (gnus-functionp match))
1599 ((gnus-functionp match)
1600 ;; Function to be called.
1603 ;; Variable to be checked.
1604 (symbol-value match))))
1607 ((eq (car match) 'header)
1608 ;; New format of header match.
1609 (and (gnus-buffer-live-p gnus-article-copy)
1610 (with-current-buffer gnus-article-copy
1611 (let ((header (message-fetch-field (nth 1 match))))
1613 (string-match (nth 2 match) header))))))
1615 ;; This is a form to be evaled.
1617 ;; We have a match, so we set the variables.
1618 (dolist (attribute style)
1619 (setq element (pop attribute)
1624 ((eq (car attribute) :file)
1627 ((eq (car attribute) :value)
1631 ;; We get the value.
1636 ((or (symbolp value)
1637 (gnus-functionp value))
1638 (cond ((gnus-functionp value)
1641 (symbol-value value))))
1644 ;; Translate obsolescent value.
1645 (when (eq element 'signature-file)
1646 (setq element 'signature
1648 ;; Get the contents of file elems.
1650 (setq v (with-temp-buffer
1651 (insert-file-contents v)
1653 (setq results (delq (assoc element results) results))
1654 (push (cons element v) results))))
1655 ;; Now we have all the styles, so we insert them.
1656 (setq name (assq 'name results)
1657 address (assq 'address results))
1658 (setq results (delq name (delq address results)))
1659 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1660 (make-local-hook 'message-setup-hook)
1661 (dolist (result results)
1662 (add-hook 'message-setup-hook
1664 ((eq 'eval (car result))
1666 ((eq 'body (car result))
1670 (insert ,(cdr result)))))
1671 ((eq 'signature (car result))
1672 (set (make-local-variable 'message-signature) nil)
1673 (set (make-local-variable 'message-signature-file) nil)
1674 (if (not (cdr result))
1678 (let ((message-signature ,(cdr result)))
1679 (when message-signature
1680 (message-insert-signature)))))))
1683 (if (symbolp (car result))
1684 (capitalize (symbol-name (car result)))
1688 (message-remove-header ,header)
1689 (let ((value ,(cdr result)))
1692 (insert ,header ": " value "\n"))))))))
1694 (when (or name address)
1695 (add-hook 'message-setup-hook
1697 (set (make-local-variable 'user-mail-address)
1698 ,(or (cdr address) user-mail-address))
1699 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1701 ,(or (cdr address) user-mail-address)))
1703 (message-remove-header "From")
1705 (insert "From: " (message-make-from) "\n"))))
1708 ;;; Allow redefinition of functions.
1714 ;;; gnus-msg.el ends here