New directory
[bpt/emacs.git] / lisp / gnus / gnus-msg.el
CommitLineData
eec82323 1;;; gnus-msg.el --- mail and post interface for Gnus
16409b0b
GM
2;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3;; Free Software Foundation, Inc.
eec82323
LMI
4
5;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6748645f 6;; Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
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)
14;; any later version.
15
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.
20
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.
25
26;;; Commentary:
27
28;;; Code:
29
249ffa67
RS
30(eval-when-compile (require 'cl))
31
eec82323
LMI
32(require 'gnus)
33(require 'gnus-ems)
34(require 'message)
35(require 'gnus-art)
36
16409b0b 37(defcustom gnus-post-method 'current
eec82323 38 "*Preferred method for posting USENET news.
eec82323 39
e818c17f
SZ
40If this variable is `current' (which is the default), Gnus will use
41the \"current\" select method when posting. If it is `native', Gnus
42will use the native select method when posting.
6748645f
LMI
43
44This method will not be used in mail groups and the like, only in
45\"real\" newsgroups.
46
e818c17f 47If not `native' nor `current', the value must be a valid method as discussed
16409b0b
GM
48in the documentation of `gnus-select-method'. It can also be a list of
49methods. If that is the case, the user will be queried for what select
6748645f
LMI
50method to use when posting."
51 :group 'gnus-group-foreign
e818c17f
SZ
52 :link '(custom-manual "(gnus)Posting Server")
53 :type `(choice (const native)
54 (const current)
6748645f 55 (sexp :tag "Methods" ,gnus-select-method)))
eec82323
LMI
56
57(defvar gnus-outgoing-message-group nil
58 "*All outgoing messages will be put in this group.
59If 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
61can also be a list of group names.
62
63If you want to have greater control over what group to put each
64message in, you can set this variable to a function that checks the
65current newsgroup name and then returns a suitable group name (or list
66of names).")
67
68(defvar gnus-mailing-list-groups nil
69 "*Regexp matching groups that are really mailing lists.
70This is useful when you're reading a mailing list that has been
71gatewayed to a newsgroup, and you want to followup to an article in
72the group.")
73
74(defvar gnus-add-to-list nil
75 "*If non-nil, add a `to-list' parameter automatically.")
76
eec82323
LMI
77(defvar gnus-crosspost-complaint
78 "Hi,
79
80You posted the article below with the following Newsgroups header:
81
82Newsgroups: %s
83
84The %s group, at least, was an inappropriate recipient
85of this message. Please trim your Newsgroups header to exclude this
86group before posting in the future.
87
88Thank you.
89
90"
91 "Format string to be inserted when complaining about crossposts.
92The first %s will be replaced by the Newsgroups header;
93the second with the current group name.")
94
95(defvar gnus-message-setup-hook nil
96 "Hook run after setting up a message buffer.")
97
6748645f
LMI
98(defvar gnus-bug-create-help-buffer t
99 "*Should we create the *Gnus Help Bug* buffer?")
100
101(defvar gnus-posting-styles nil
102 "*Alist of styles to use when posting.")
103
16409b0b 104(defcustom gnus-group-posting-charset-alist
25fc4fd5 105 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
16409b0b
GM
106 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
107 (message-this-is-mail nil nil)
108 (message-this-is-news nil t))
109 "Alist of regexps and permitted unencoded charsets for posting.
110Each element of the alist has the form (TEST HEADER BODY-LIST), where
111TEST is either a regular expression matching the newsgroup header or a
112variable to query,
113HEADER is the charset which may be left unencoded in the header (nil
114means encode all charsets),
115BODY-LIST is a list of charsets which may be encoded using 8bit
116content-transfer encoding in the body, or one of the special values
117nil (always encode using quoted-printable) or t (always use 8bit).
118
119Note that any value other than nil for HEADER infringes some RFCs, so
120use this option with care."
121 :type '(repeat (list :tag "Permitted unencoded charsets"
122 (choice :tag "Where"
123 (regexp :tag "Group")
124 (const :tag "Mail message" :value message-this-is-mail)
125 (const :tag "News article" :value message-this-is-news))
126 (choice :tag "Header"
127 (const :tag "None" nil)
128 (symbol :tag "Charset"))
129 (choice :tag "Body"
130 (const :tag "Any" :value t)
131 (const :tag "None" :value nil)
132 (repeat :tag "Charsets"
133 (symbol :tag "Charset")))))
134 :group 'gnus-charset)
6748645f 135
eec82323
LMI
136;;; Internal variables.
137
6748645f
LMI
138(defvar gnus-inhibit-posting-styles nil
139 "Inhibit the use of posting styles.")
140
eec82323
LMI
141(defvar gnus-message-buffer "*Mail Gnus*")
142(defvar gnus-article-copy nil)
143(defvar gnus-last-posting-server nil)
6748645f 144(defvar gnus-message-group-art nil)
eec82323
LMI
145
146(defconst gnus-bug-message
147 "Sending a bug report to the Gnus Towers.
148========================================
149
150The buffer below is a mail buffer. When you press `C-c C-c', it will
151be sent to the Gnus Bug Exterminators.
152
16409b0b
GM
153The thing near the bottom of the buffer is how the environment
154settings will be included in the mail. Please do not delete that.
155They will tell the Bug People what your environment is, so that it
156will be easier to locate the bugs.
eec82323
LMI
157
158If you have found a bug that makes Emacs go \"beep\", set
159debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
160and include the backtrace in your bug report.
161
162Please describe the bug in annoying, painstaking detail.
163
164Thank you for your help in stamping out bugs.
165")
166
167(eval-and-compile
168 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
eec82323
LMI
169 (autoload 'rmail-dont-reply-to "mail-utils")
170 (autoload 'rmail-output "rmailout"))
171
172\f
173;;;
174;;; Gnus Posting Functions
175;;;
176
177(gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
178 "p" gnus-summary-post-news
179 "f" gnus-summary-followup
180 "F" gnus-summary-followup-with-original
181 "c" gnus-summary-cancel-article
182 "s" gnus-summary-supersede-article
183 "r" gnus-summary-reply
16409b0b 184 "y" gnus-summary-yank-message
eec82323
LMI
185 "R" gnus-summary-reply-with-original
186 "w" gnus-summary-wide-reply
187 "W" gnus-summary-wide-reply-with-original
188 "n" gnus-summary-followup-to-mail
189 "N" gnus-summary-followup-to-mail-with-original
190 "m" gnus-summary-mail-other-window
191 "u" gnus-uu-post-news
192 "\M-c" gnus-summary-mail-crosspost-complaint
193 "om" gnus-summary-mail-forward
194 "op" gnus-summary-post-forward
195 "Om" gnus-uu-digest-mail-forward
196 "Op" gnus-uu-digest-post-forward)
197
198(gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
199 "b" gnus-summary-resend-bounced-mail
200 ;; "c" gnus-summary-send-draft
201 "r" gnus-summary-resend-message)
202
203;;; Internal functions.
204
205(defvar gnus-article-reply nil)
206(defmacro gnus-setup-message (config &rest forms)
6748645f
LMI
207 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
208 (buffer (make-symbol "gnus-setup-message-buffer"))
209 (article (make-symbol "gnus-setup-message-article"))
210 (group (make-symbol "gnus-setup-message-group")))
eec82323
LMI
211 `(let ((,winconf (current-window-configuration))
212 (,buffer (buffer-name (current-buffer)))
213 (,article (and gnus-article-reply (gnus-summary-article-number)))
6748645f 214 (,group gnus-newsgroup-name)
eec82323 215 (message-header-setup-hook
6748645f 216 (copy-sequence message-header-setup-hook))
16409b0b 217 (mbl mml-buffer-list)
6748645f 218 (message-mode-hook (copy-sequence message-mode-hook)))
16409b0b 219 (setq mml-buffer-list nil)
eec82323
LMI
220 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
221 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
6748645f 222 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
eec82323 223 (unwind-protect
6748645f
LMI
224 (progn
225 ,@forms)
eec82323
LMI
226 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
227 (setq gnus-message-buffer (current-buffer))
6748645f
LMI
228 (set (make-local-variable 'gnus-message-group-art)
229 (cons ,group ,article))
16409b0b
GM
230 (set (make-local-variable 'gnus-newsgroup-name) ,group)
231 (gnus-run-hooks 'gnus-message-setup-hook)
232 (if (eq major-mode 'message-mode)
25fc4fd5
SZ
233 (let ((mbl1 mml-buffer-list))
234 (setq mml-buffer-list mbl) ;; Global value
235 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
6553d8f2 236 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
16409b0b
GM
237 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
238 (mml-destroy-buffers)
239 (setq mml-buffer-list mbl)))
6748645f 240 (gnus-add-buffer)
eec82323
LMI
241 (gnus-configure-windows ,config t)
242 (set-buffer-modified-p nil))))
243
25fc4fd5
SZ
244;;;###autoload
245(defun gnus-msg-mail (&rest args)
246 "Start editing a mail message to be sent.
247Like `message-mail', but with Gnus paraphernalia, particularly the
248Gcc: header for archiving purposes."
249 (interactive)
250 (gnus-setup-message 'message
251 (apply 'message-mail args))
252 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
253 t)
254
255;;;###autoload
256(define-mail-user-agent 'gnus-user-agent
257 'gnus-msg-mail 'message-send-and-exit
258 'message-kill-buffer 'message-send-hook)
259
16409b0b
GM
260(defun gnus-setup-posting-charset (group)
261 (let ((alist gnus-group-posting-charset-alist)
262 (group (or group ""))
263 elem)
264 (when group
265 (catch 'found
266 (while (setq elem (pop alist))
267 (when (or (and (stringp (car elem))
268 (string-match (car elem) group))
269 (and (gnus-functionp (car elem))
270 (funcall (car elem) group))
271 (and (symbolp (car elem))
272 (symbol-value (car elem))))
273 (throw 'found (cons (cadr elem) (caddr elem)))))))))
274
eec82323
LMI
275(defun gnus-inews-add-send-actions (winconf buffer article)
276 (make-local-hook 'message-sent-hook)
0342aa5b
DL
277 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
278 'gnus-inews-do-gcc) nil t)
279 (when gnus-agent
280 (make-local-hook 'message-header-hook)
281 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
eec82323
LMI
282 (setq message-post-method
283 `(lambda (arg)
284 (gnus-post-method arg ,gnus-newsgroup-name)))
285 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
286 (message-add-action
287 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
288 (message-add-action
6748645f 289 `(when (gnus-buffer-exists-p ,buffer)
eec82323 290 (save-excursion
6748645f 291 (set-buffer ,buffer)
eec82323
LMI
292 ,(when article
293 `(gnus-summary-mark-article-as-replied ,article))))
294 'send))
295
296(put 'gnus-setup-message 'lisp-indent-function 1)
297(put 'gnus-setup-message 'edebug-form-spec '(form body))
298
299;;; Post news commands of Gnus group mode and summary mode
300
16409b0b
GM
301(defun gnus-group-mail (&optional arg)
302 "Start composing a mail.
303If ARG, use the group under the point to find a posting style.
304If ARG is 1, prompt for a group name to find the posting style."
305 (interactive "P")
306 ;; We can't `let' gnus-newsgroup-name here, since that leads
307 ;; to local variables leaking.
308 (let ((group gnus-newsgroup-name)
309 (buffer (current-buffer)))
310 (unwind-protect
311 (progn
312 (setq gnus-newsgroup-name
313 (if arg
314 (if (= 1 (prefix-numeric-value arg))
315 (completing-read "Use posting style of group: "
316 gnus-active-hashtb nil
317 (gnus-read-active-file-p))
318 (gnus-group-group-name))
319 ""))
320 (gnus-setup-message 'message (message-mail)))
321 (save-excursion
322 (set-buffer buffer)
323 (setq gnus-newsgroup-name group)))))
eec82323
LMI
324
325(defun gnus-group-post-news (&optional arg)
326 "Start composing a news message.
327If ARG, post to the group under point.
328If ARG is 1, prompt for a group name."
329 (interactive "P")
6748645f 330 ;; Bind this variable here to make message mode hooks work ok.
eec82323
LMI
331 (let ((gnus-newsgroup-name
332 (if arg
333 (if (= 1 (prefix-numeric-value arg))
334 (completing-read "Newsgroup: " gnus-active-hashtb nil
335 (gnus-read-active-file-p))
336 (gnus-group-group-name))
337 "")))
338 (gnus-post-news 'post gnus-newsgroup-name)))
339
340(defun gnus-summary-post-news ()
341 "Start composing a news message."
342 (interactive)
eec82323
LMI
343 (gnus-post-news 'post gnus-newsgroup-name))
344
345(defun gnus-summary-followup (yank &optional force-news)
346 "Compose a followup to an article.
347If prefix argument YANK is non-nil, original article is yanked automatically."
348 (interactive
349 (list (and current-prefix-arg
350 (gnus-summary-work-articles 1))))
eec82323
LMI
351 (when yank
352 (gnus-summary-goto-subject (car yank)))
353 (save-window-excursion
354 (gnus-summary-select-article))
355 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
356 (gnus-newsgroup-name gnus-newsgroup-name))
357 ;; Send a followup.
358 (gnus-post-news nil gnus-newsgroup-name
359 headers gnus-article-buffer
360 yank nil force-news)))
361
362(defun gnus-summary-followup-with-original (n &optional force-news)
363 "Compose a followup to an article and include the original article."
364 (interactive "P")
365 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
366
367(defun gnus-summary-followup-to-mail (&optional arg)
368 "Followup to the current mail message via news."
369 (interactive
370 (list (and current-prefix-arg
371 (gnus-summary-work-articles 1))))
372 (gnus-summary-followup arg t))
373
374(defun gnus-summary-followup-to-mail-with-original (&optional arg)
375 "Followup to the current mail message via news."
376 (interactive "P")
377 (gnus-summary-followup (gnus-summary-work-articles arg) t))
378
379(defun gnus-inews-yank-articles (articles)
380 (let (beg article)
381 (message-goto-body)
382 (while (setq article (pop articles))
383 (save-window-excursion
384 (set-buffer gnus-summary-buffer)
385 (gnus-summary-select-article nil nil nil article)
386 (gnus-summary-remove-process-mark article))
387 (gnus-copy-article-buffer)
388 (let ((message-reply-buffer gnus-article-copy)
389 (message-reply-headers gnus-current-headers))
390 (message-yank-original)
391 (setq beg (or beg (mark t))))
392 (when articles
393 (insert "\n")))
394 (push-mark)
395 (goto-char beg)))
396
6748645f
LMI
397(defun gnus-summary-cancel-article (&optional n symp)
398 "Cancel an article you posted.
399Uses the process-prefix convention. If given the symbolic
400prefix `a', cancel using the standard posting method; if not
401post using the current select method."
402 (interactive (gnus-interactive "P\ny"))
eec82323
LMI
403 (let ((articles (gnus-summary-work-articles n))
404 (message-post-method
405 `(lambda (arg)
6748645f 406 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
eec82323
LMI
407 article)
408 (while (setq article (pop articles))
409 (when (gnus-summary-select-article t nil nil article)
410 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
411 (message-cancel-news))
412 (gnus-summary-mark-as-read article gnus-canceled-mark)
413 (gnus-cache-remove-article 1))
414 (gnus-article-hide-headers-if-wanted))
415 (gnus-summary-remove-process-mark article))))
416
417(defun gnus-summary-supersede-article ()
418 "Compose an article that will supersede a previous article.
419This is done simply by taking the old article and adding a Supersedes
420header line with the old Message-ID."
421 (interactive)
eec82323
LMI
422 (let ((article (gnus-summary-article-number)))
423 (gnus-setup-message 'reply-yank
424 (gnus-summary-select-article t)
425 (set-buffer gnus-original-article-buffer)
426 (message-supersede)
427 (push
428 `((lambda ()
6748645f 429 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
eec82323 430 (save-excursion
6748645f 431 (set-buffer ,gnus-summary-buffer)
eec82323
LMI
432 (gnus-cache-possibly-remove-article ,article nil nil nil t)
433 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
434 message-send-actions))))
25fc4fd5 435
eec82323
LMI
436\f
437
438(defun gnus-copy-article-buffer (&optional article-buffer)
439 ;; make a copy of the article buffer with all text properties removed
440 ;; this copy is in the buffer gnus-article-copy.
441 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
442 ;; this buffer should be passed to all mail/news reply/post routines.
6748645f 443 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
16409b0b
GM
444 (save-excursion
445 (set-buffer gnus-article-copy)
446 (mm-enable-multibyte))
eec82323 447 (let ((article-buffer (or article-buffer gnus-article-buffer))
6748645f 448 end beg)
eec82323 449 (if (not (and (get-buffer article-buffer)
6748645f 450 (gnus-buffer-exists-p article-buffer)))
eec82323
LMI
451 (error "Can't find any article buffer")
452 (save-excursion
453 (set-buffer article-buffer)
454 (save-restriction
455 ;; Copy over the (displayed) article buffer, delete
456 ;; hidden text and remove text properties.
457 (widen)
458 (copy-to-buffer gnus-article-copy (point-min) (point-max))
459 (set-buffer gnus-article-copy)
460 (gnus-article-delete-text-of-type 'annotation)
461 (gnus-remove-text-with-property 'gnus-prev)
462 (gnus-remove-text-with-property 'gnus-next)
463 (insert
464 (prog1
16409b0b 465 (buffer-substring-no-properties (point-min) (point-max))
eec82323
LMI
466 (erase-buffer)))
467 ;; Find the original headers.
468 (set-buffer gnus-original-article-buffer)
469 (goto-char (point-min))
470 (while (looking-at message-unix-mail-delimiter)
471 (forward-line 1))
472 (setq beg (point))
473 (setq end (or (search-forward "\n\n" nil t) (point)))
474 ;; Delete the headers from the displayed articles.
475 (set-buffer gnus-article-copy)
476 (delete-region (goto-char (point-min))
16409b0b 477 (or (search-forward "\n\n" nil t) (point-max)))
eec82323
LMI
478 ;; Insert the original article headers.
479 (insert-buffer-substring gnus-original-article-buffer beg end)
16409b0b 480 (article-decode-encoded-words)))
eec82323
LMI
481 gnus-article-copy)))
482
483(defun gnus-post-news (post &optional group header article-buffer yank subject
484 force-news)
485 (when article-buffer
486 (gnus-copy-article-buffer))
487 (let ((gnus-article-reply article-buffer)
488 (add-to-list gnus-add-to-list))
489 (gnus-setup-message (cond (yank 'reply-yank)
490 (article-buffer 'reply)
491 (t 'message))
492 (let* ((group (or group gnus-newsgroup-name))
16409b0b 493 (charset (gnus-group-name-charset nil group))
eec82323
LMI
494 (pgroup group)
495 to-address to-group mailing-list to-list
496 newsgroup-p)
497 (when group
498 (setq to-address (gnus-group-find-parameter group 'to-address)
499 to-group (gnus-group-find-parameter group 'to-group)
500 to-list (gnus-group-find-parameter group 'to-list)
501 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
502 mailing-list (when gnus-mailing-list-groups
503 (string-match gnus-mailing-list-groups group))
16409b0b
GM
504 group (gnus-group-name-decode (gnus-group-real-name group)
505 charset)))
eec82323
LMI
506 (if (or (and to-group
507 (gnus-news-group-p to-group))
508 newsgroup-p
509 force-news
510 (and (gnus-news-group-p
511 (or pgroup gnus-newsgroup-name)
512 (if header (mail-header-number header)
513 gnus-current-article))
514 (not mailing-list)
515 (not to-list)
516 (not to-address)))
517 ;; This is news.
518 (if post
519 (message-news (or to-group group))
520 (set-buffer gnus-article-copy)
6748645f 521 (gnus-msg-treat-broken-reply-to)
eec82323
LMI
522 (message-followup (if (or newsgroup-p force-news) nil to-group)))
523 ;; The is mail.
524 (if post
525 (progn
526 (message-mail (or to-address to-list))
527 ;; Arrange for mail groups that have no `to-address' to
528 ;; get that when the user sends off the mail.
529 (when (and (not to-list)
530 (not to-address)
531 add-to-list)
532 (push (list 'gnus-inews-add-to-address pgroup)
533 message-send-actions)))
534 (set-buffer gnus-article-copy)
6748645f
LMI
535 (gnus-msg-treat-broken-reply-to)
536 (message-wide-reply to-address)))
eec82323
LMI
537 (when yank
538 (gnus-inews-yank-articles yank))))))
539
6748645f 540(defun gnus-msg-treat-broken-reply-to ()
8f688cb0 541 "Remove the Reply-to header if broken-reply-to."
6748645f
LMI
542 (when (gnus-group-find-parameter
543 gnus-newsgroup-name 'broken-reply-to)
544 (save-restriction
545 (message-narrow-to-head)
546 (message-remove-header "reply-to"))))
547
eec82323
LMI
548(defun gnus-post-method (arg group &optional silent)
549 "Return the posting method based on GROUP and ARG.
550If SILENT, don't prompt the user."
551 (let ((group-method (gnus-find-method-for-group group)))
552 (cond
553 ;; If the group-method is nil (which shouldn't happen) we use
554 ;; the default method.
555 ((null group-method)
6748645f 556 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
16409b0b 557 gnus-select-method message-post-method))
6748645f 558 ;; We want the inverse of the default
eec82323 559 ((and arg (not (eq arg 0)))
6748645f
LMI
560 (if (eq gnus-post-method 'active)
561 gnus-select-method
562 group-method))
eec82323
LMI
563 ;; We query the user for a post method.
564 ((or arg
565 (and gnus-post-method
6748645f 566 (not (eq gnus-post-method 'current))
eec82323
LMI
567 (listp (car gnus-post-method))))
568 (let* ((methods
569 ;; Collect all methods we know about.
570 (append
6748645f
LMI
571 (when (and gnus-post-method
572 (not (eq gnus-post-method 'current)))
eec82323
LMI
573 (if (listp (car gnus-post-method))
574 gnus-post-method
575 (list gnus-post-method)))
576 gnus-secondary-select-methods
6748645f 577 (mapcar 'cdr gnus-server-alist)
16409b0b 578 (mapcar 'car gnus-opened-servers)
eec82323
LMI
579 (list gnus-select-method)
580 (list group-method)))
581 method-alist post-methods method)
582 ;; Weed out all mail methods.
583 (while methods
584 (setq method (gnus-server-get-method "" (pop methods)))
16409b0b
GM
585 (when (and (or (gnus-method-option-p method 'post)
586 (gnus-method-option-p method 'post-mail))
587 (not (member method post-methods)))
eec82323
LMI
588 (push method post-methods)))
589 ;; Create a name-method alist.
590 (setq method-alist
591 (mapcar
592 (lambda (m)
593 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
594 post-methods))
595 ;; Query the user.
596 (cadr
597 (assoc
598 (setq gnus-last-posting-server
599 (if (and silent
600 gnus-last-posting-server)
601 ;; Just use the last value.
602 gnus-last-posting-server
603 (completing-read
604 "Posting method: " method-alist nil t
605 (cons (or gnus-last-posting-server "") 0))))
606 method-alist))))
607 ;; Override normal method.
6748645f
LMI
608 ((and (eq gnus-post-method 'current)
609 (not (eq (car group-method) 'nndraft))
16409b0b 610 (gnus-get-function group-method 'request-post t)
6748645f 611 (not arg))
16409b0b 612 group-method)
6748645f
LMI
613 ((and gnus-post-method
614 (not (eq gnus-post-method 'current)))
eec82323
LMI
615 gnus-post-method)
616 ;; Use the normal select method.
617 (t gnus-select-method))))
618
eec82323
LMI
619\f
620
16409b0b 621;; Dummies to avoid byte-compile warning.
4faaa994
DL
622(eval-when-compile
623 (defvar nnspool-rejected-article-hook)
624 (defvar xemacs-codename))
eec82323 625
eec82323 626(defun gnus-extended-version ()
6748645f 627 "Stringified Gnus version and Emacs version."
eec82323
LMI
628 (interactive)
629 (concat
16409b0b
GM
630 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
631 " (" gnus-version ")"
632 " "
eec82323 633 (cond
16409b0b
GM
634 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
635 (concat "Emacs/" (match-string 1 emacs-version)))
eec82323
LMI
636 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
637 emacs-version)
16409b0b
GM
638 (concat (match-string 1 emacs-version)
639 (format "/%d.%d" emacs-major-version emacs-minor-version)
eec82323 640 (if (match-beginning 3)
16409b0b 641 (match-string 3 emacs-version)
a8151ef7
LMI
642 "")
643 (if (boundp 'xemacs-codename)
16409b0b
GM
644 (concat " (" xemacs-codename ")")
645 "")))
eec82323
LMI
646 (t emacs-version))))
647
eec82323
LMI
648\f
649;;;
650;;; Gnus Mail Functions
651;;;
652
653;;; Mail reply commands of Gnus summary mode
654
655(defun gnus-summary-reply (&optional yank wide)
656 "Start composing a reply mail to the current message.
657If prefix argument YANK is non-nil, the original article is yanked
658automatically."
659 (interactive
660 (list (and current-prefix-arg
661 (gnus-summary-work-articles 1))))
662 ;; Stripping headers should be specified with mail-yank-ignored-headers.
eec82323
LMI
663 (when yank
664 (gnus-summary-goto-subject (car yank)))
665 (let ((gnus-article-reply t))
666 (gnus-setup-message (if yank 'reply-yank 'reply)
667 (gnus-summary-select-article)
668 (set-buffer (gnus-copy-article-buffer))
6748645f 669 (gnus-msg-treat-broken-reply-to)
16409b0b
GM
670 (save-restriction
671 (message-narrow-to-head)
672 (goto-char (point-max)))
673 (mml-quote-region (point) (point-max))
6748645f 674 (message-reply nil wide)
eec82323
LMI
675 (when yank
676 (gnus-inews-yank-articles yank)))))
677
678(defun gnus-summary-reply-with-original (n &optional wide)
679 "Start composing a reply mail to the current message.
680The original article will be yanked."
681 (interactive "P")
682 (gnus-summary-reply (gnus-summary-work-articles n) wide))
683
684(defun gnus-summary-wide-reply (&optional yank)
685 "Start composing a wide reply mail to the current message.
686If prefix argument YANK is non-nil, the original article is yanked
687automatically."
688 (interactive
689 (list (and current-prefix-arg
690 (gnus-summary-work-articles 1))))
691 (gnus-summary-reply yank t))
692
693(defun gnus-summary-wide-reply-with-original (n)
694 "Start composing a wide reply mail to the current message.
695The original article will be yanked."
696 (interactive "P")
697 (gnus-summary-reply-with-original n t))
698
16409b0b 699(defun gnus-summary-mail-forward (&optional arg post)
a1506d29 700 "Forward the current message to another user.
16409b0b
GM
701If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
702if ARG is 1, decode the message and forward directly inline;
25fc4fd5 703if ARG is 2, forward message as an rfc822 MIME section;
16409b0b 704if ARG is 3, decode message and forward as an rfc822 MIME section;
25fc4fd5 705if ARG is 4, forward message directly inline;
16409b0b
GM
706otherwise, use flipped `message-forward-as-mime'.
707If POST, post instead of mail."
eec82323 708 (interactive "P")
16409b0b
GM
709 (let ((message-forward-as-mime message-forward-as-mime)
710 (message-forward-show-mml message-forward-show-mml))
a1506d29 711 (cond
16409b0b
GM
712 ((null arg))
713 ((eq arg 1) (setq message-forward-as-mime nil
714 message-forward-show-mml t))
715 ((eq arg 2) (setq message-forward-as-mime t
716 message-forward-show-mml nil))
717 ((eq arg 3) (setq message-forward-as-mime t
718 message-forward-show-mml t))
719 ((eq arg 4) (setq message-forward-as-mime nil
720 message-forward-show-mml nil))
721 (t (setq message-forward-as-mime (not message-forward-as-mime))))
722 (gnus-setup-message 'forward
723 (gnus-summary-select-article)
724 (let ((mail-parse-charset gnus-newsgroup-charset)
158d6e07
SZ
725 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
726 (set-buffer gnus-original-article-buffer)
16409b0b 727 (message-forward post)))))
eec82323
LMI
728
729(defun gnus-summary-resend-message (address n)
730 "Resend the current article to ADDRESS."
731 (interactive "sResend message(s) to: \nP")
732 (let ((articles (gnus-summary-work-articles n))
733 article)
734 (while (setq article (pop articles))
735 (gnus-summary-select-article nil nil nil article)
736 (save-excursion
737 (set-buffer gnus-original-article-buffer)
738 (message-resend address)))))
739
16409b0b 740(defun gnus-summary-post-forward (&optional arg)
eec82323 741 "Forward the current article to a newsgroup.
16409b0b 742See `gnus-summary-mail-forward' for ARG."
eec82323 743 (interactive "P")
16409b0b 744 (gnus-summary-mail-forward arg t))
eec82323
LMI
745
746(defvar gnus-nastygram-message
747 "The following article was inappropriately posted to %s.\n\n"
748 "Format string to insert in nastygrams.
749The current group name will be inserted at \"%s\".")
750
751(defun gnus-summary-mail-nastygram (n)
752 "Send a nastygram to the author of the current article."
753 (interactive "P")
754 (when (or gnus-expert-user
755 (gnus-y-or-n-p
756 "Really send a nastygram to the author of the current article? "))
757 (let ((group gnus-newsgroup-name))
758 (gnus-summary-reply-with-original n)
759 (set-buffer gnus-message-buffer)
760 (message-goto-body)
761 (insert (format gnus-nastygram-message group))
762 (message-send-and-exit))))
763
764(defun gnus-summary-mail-crosspost-complaint (n)
765 "Send a complaint about crossposting to the current article(s)."
766 (interactive "P")
767 (let ((articles (gnus-summary-work-articles n))
768 article)
769 (while (setq article (pop articles))
770 (set-buffer gnus-summary-buffer)
771 (gnus-summary-goto-subject article)
772 (let ((group (gnus-group-real-name gnus-newsgroup-name))
773 newsgroups followup-to)
774 (gnus-summary-select-article)
775 (set-buffer gnus-original-article-buffer)
776 (if (and (<= (length (message-tokenize-header
16409b0b
GM
777 (setq newsgroups
778 (mail-fetch-field "newsgroups"))
eec82323
LMI
779 ", "))
780 1)
781 (or (not (setq followup-to (mail-fetch-field "followup-to")))
782 (not (member group (message-tokenize-header
783 followup-to ", ")))))
784 (if followup-to
785 (gnus-message 1 "Followup-to restricted")
786 (gnus-message 1 "Not a crossposted article"))
787 (set-buffer gnus-summary-buffer)
788 (gnus-summary-reply-with-original 1)
789 (set-buffer gnus-message-buffer)
790 (message-goto-body)
791 (insert (format gnus-crosspost-complaint newsgroups group))
792 (message-goto-subject)
793 (re-search-forward " *$")
794 (replace-match " (crosspost notification)" t t)
6748645f 795 (gnus-deactivate-mark)
eec82323
LMI
796 (when (gnus-y-or-n-p "Send this complaint? ")
797 (message-send-and-exit)))))))
798
799(defun gnus-summary-mail-other-window ()
800 "Compose mail in other window."
801 (interactive)
802 (gnus-setup-message 'message
803 (message-mail)))
804
805(defun gnus-mail-parse-comma-list ()
806 (let (accumulated
807 beg)
808 (skip-chars-forward " ")
809 (while (not (eobp))
810 (setq beg (point))
811 (skip-chars-forward "^,")
812 (while (zerop
813 (save-excursion
814 (save-restriction
815 (let ((i 0))
816 (narrow-to-region beg (point))
817 (goto-char beg)
818 (logand (progn
819 (while (search-forward "\"" nil t)
820 (incf i))
821 (if (zerop i) 2 i))
822 2)))))
823 (skip-chars-forward ",")
824 (skip-chars-forward "^,"))
825 (skip-chars-backward " ")
826 (push (buffer-substring beg (point))
827 accumulated)
828 (skip-chars-forward "^,")
829 (skip-chars-forward ", "))
830 accumulated))
831
832(defun gnus-inews-add-to-address (group)
833 (let ((to-address (mail-fetch-field "to")))
834 (when (and to-address
835 (gnus-alive-p))
836 ;; This mail group doesn't have a `to-list', so we add one
837 ;; here. Magic!
838 (when (gnus-y-or-n-p
839 (format "Do you want to add this as `to-list': %s " to-address))
840 (gnus-group-add-parameter group (cons 'to-list to-address))))))
841
842(defun gnus-put-message ()
843 "Put the current message in some group and return to Gnus."
844 (interactive)
845 (let ((reply gnus-article-reply)
846 (winconf gnus-prev-winconf)
847 (group gnus-newsgroup-name))
848
849 (or (and group (not (gnus-group-read-only-p group)))
850 (setq group (read-string "Put in group: " nil
851 (gnus-writable-groups))))
852 (when (gnus-gethash group gnus-newsrc-hashtb)
853 (error "No such group: %s" group))
854
855 (save-excursion
856 (save-restriction
857 (widen)
858 (message-narrow-to-headers)
859 (let (gnus-deletable-headers)
860 (if (message-news-p)
861 (message-generate-headers message-required-news-headers)
862 (message-generate-headers message-required-mail-headers)))
863 (goto-char (point-max))
864 (insert "Gcc: " group "\n")
865 (widen)))
866
867 (gnus-inews-do-gcc)
868
869 (when (get-buffer gnus-group-buffer)
870 (when (gnus-buffer-exists-p (car-safe reply))
871 (set-buffer (car reply))
872 (and (cdr reply)
873 (gnus-summary-mark-article-as-replied
874 (cdr reply))))
875 (when winconf
876 (set-window-configuration winconf)))))
877
878(defun gnus-article-mail (yank)
879 "Send a reply to the address near point.
880If YANK is non-nil, include the original article."
881 (interactive "P")
882 (let ((address
883 (buffer-substring
884 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
885 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
886 (when address
887 (message-reply address)
888 (when yank
889 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
890
891(defvar nntp-server-type)
892(defun gnus-bug ()
893 "Send a bug report to the Gnus maintainers."
894 (interactive)
895 (unless (gnus-alive-p)
896 (error "Gnus has been shut down"))
88818fbe
SZ
897 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
898 (unless (message-mail-user-agent)
899 (delete-other-windows)
900 (when gnus-bug-create-help-buffer
901 (switch-to-buffer "*Gnus Help Bug*")
902 (erase-buffer)
903 (insert gnus-bug-message)
904 (goto-char (point-min)))
905 (message-pop-to-buffer "*Gnus Bug*"))
906 (let ((message-this-is-mail t))
907 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
6748645f
LMI
908 (when gnus-bug-create-help-buffer
909 (push `(gnus-bug-kill-buffer) message-send-actions))
eec82323
LMI
910 (goto-char (point-min))
911 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
912 (forward-line 1)
6748645f
LMI
913 (insert (gnus-version) "\n"
914 (emacs-version) "\n")
eec82323
LMI
915 (when (and (boundp 'nntp-server-type)
916 (stringp nntp-server-type))
917 (insert nntp-server-type))
918 (insert "\n\n\n\n\n")
16409b0b
GM
919 (let (text)
920 (save-excursion
921 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
922 (gnus-debug)
923 (setq text (buffer-string)))
924 (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
eec82323
LMI
925 (goto-char (point-min))
926 (search-forward "Subject: " nil t)
927 (message "")))
928
929(defun gnus-bug-kill-buffer ()
930 (when (get-buffer "*Gnus Help Bug*")
931 (kill-buffer "*Gnus Help Bug*")))
932
16409b0b
GM
933(defun gnus-summary-yank-message (buffer n)
934 "Yank the current article into a composed message."
935 (interactive
936 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
937 current-prefix-arg))
938 (gnus-summary-iterate n
939 (let ((gnus-display-mime-function nil)
940 (gnus-inhibit-treatment t))
941 (gnus-summary-select-article))
942 (save-excursion
943 (set-buffer buffer)
944 (message-yank-buffer gnus-article-buffer))))
945
eec82323
LMI
946(defun gnus-debug ()
947 "Attempts to go through the Gnus source file and report what variables have been changed.
948The source file has to be in the Emacs load path."
949 (interactive)
950 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
951 "gnus-art.el" "gnus-start.el" "gnus-async.el"
952 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
953 "nnmail.el" "message.el"))
6748645f 954 (point (point))
eec82323
LMI
955 file expr olist sym)
956 (gnus-message 4 "Please wait while we snoop your variables...")
957 (sit-for 0)
958 ;; Go through all the files looking for non-default values for variables.
959 (save-excursion
6748645f 960 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
eec82323
LMI
961 (while files
962 (erase-buffer)
963 (when (and (setq file (locate-library (pop files)))
964 (file-exists-p file))
965 (insert-file-contents file)
966 (goto-char (point-min))
967 (if (not (re-search-forward "^;;* *Internal variables" nil t))
968 (gnus-message 4 "Malformed sources in file %s" file)
969 (narrow-to-region (point-min) (point))
970 (goto-char (point-min))
971 (while (setq expr (ignore-errors (read (current-buffer))))
972 (ignore-errors
973 (and (or (eq (car expr) 'defvar)
974 (eq (car expr) 'defcustom))
975 (stringp (nth 3 expr))
976 (or (not (boundp (nth 1 expr)))
977 (not (equal (eval (nth 2 expr))
978 (symbol-value (nth 1 expr)))))
979 (push (nth 1 expr) olist)))))))
980 (kill-buffer (current-buffer)))
981 (when (setq olist (nreverse olist))
982 (insert "------------------ Environment follows ------------------\n\n"))
983 (while olist
984 (if (boundp (car olist))
985 (condition-case ()
986 (pp `(setq ,(car olist)
987 ,(if (or (consp (setq sym (symbol-value (car olist))))
988 (and (symbolp sym)
989 (not (or (eq sym nil)
990 (eq sym t)))))
991 (list 'quote (symbol-value (car olist)))
992 (symbol-value (car olist))))
993 (current-buffer))
994 (error
995 (format "(setq %s 'whatever)\n" (car olist))))
996 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
997 (setq olist (cdr olist)))
998 (insert "\n\n")
6748645f 999 ;; Remove any control chars - they seem to cause trouble for some
eec82323 1000 ;; mailers. (Byte-compiled output from the stuff above.)
6748645f
LMI
1001 (goto-char point)
1002 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1003 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1004 t t))))
eec82323
LMI
1005
1006;;; Treatment of rejected articles.
1007;;; Bounced mail.
1008
1009(defun gnus-summary-resend-bounced-mail (&optional fetch)
1010 "Re-mail the current message.
1011This only makes sense if the current message is a bounce message than
1012contains some mail you have written which has been bounced back to
1013you.
1014If FETCH, try to fetch the article that this is a reply to, if indeed
1015this is a reply."
1016 (interactive "P")
1017 (gnus-summary-select-article t)
1018 (set-buffer gnus-original-article-buffer)
1019 (gnus-setup-message 'compose-bounce
1020 (let* ((references (mail-fetch-field "references"))
1021 (parent (and references (gnus-parent-id references))))
1022 (message-bounce)
1023 ;; If there are references, we fetch the article we answered to.
1024 (and fetch parent
1025 (gnus-summary-refer-article parent)
1026 (gnus-summary-show-all-headers)))))
1027
1028;;; Gcc handling.
1029
0342aa5b
DL
1030(defun gnus-inews-group-method (group)
1031 (cond ((and (null (gnus-get-info group))
1032 (eq (car gnus-message-archive-method)
1033 (car
1034 (gnus-server-to-method
1035 (gnus-group-method group)))))
1036 ;; If the group doesn't exist, we assume
1037 ;; it's an archive group...
1038 gnus-message-archive-method)
1039 ;; Use the method.
1040 ((gnus-info-method (gnus-get-info group))
1041 (gnus-info-method (gnus-get-info group)))
1042 ;; Find the method.
1043 (t (gnus-group-method group))))
1044
eec82323
LMI
1045;; Do Gcc handling, which copied the message over to some group.
1046(defun gnus-inews-do-gcc (&optional gcc)
1047 (interactive)
1048 (when (gnus-alive-p)
1049 (save-excursion
1050 (save-restriction
1051 (message-narrow-to-headers)
1052 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1053 (cur (current-buffer))
1054 groups group method)
1055 (when gcc
1056 (message-remove-header "gcc")
1057 (widen)
16409b0b
GM
1058 (setq groups (message-unquote-tokens
1059 (message-tokenize-header gcc " ,")))
eec82323
LMI
1060 ;; Copy the article over to some group(s).
1061 (while (setq group (pop groups))
1062 (gnus-check-server
0342aa5b 1063 (setq method (gnus-inews-group-method group)))
eec82323
LMI
1064 (unless (gnus-request-group group t method)
1065 (gnus-request-create-group group method))
1066 (save-excursion
1067 (nnheader-set-temp-buffer " *acc*")
1068 (insert-buffer-substring cur)
16409b0b
GM
1069 (message-encode-message-body)
1070 (save-restriction
1071 (message-narrow-to-headers)
1072 (let ((mail-parse-charset message-default-charset)
1073 (rfc2047-header-encoding-alist
1074 (cons '("Newsgroups" . default)
1075 rfc2047-header-encoding-alist)))
1076 (mail-encode-encoded-word-buffer)))
eec82323
LMI
1077 (goto-char (point-min))
1078 (when (re-search-forward
1079 (concat "^" (regexp-quote mail-header-separator) "$")
1080 nil t)
1081 (replace-match "" t t ))
16409b0b 1082 (unless (gnus-request-accept-article group method t t)
eec82323
LMI
1083 (gnus-message 1 "Couldn't store article in group %s: %s"
1084 group (gnus-status-message method))
1085 (sit-for 2))
1086 (kill-buffer (current-buffer))))))))))
1087
1088(defun gnus-inews-insert-gcc ()
1089 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1090 (save-excursion
1091 (save-restriction
1092 (message-narrow-to-headers)
1093 (let* ((group gnus-outgoing-message-group)
1094 (gcc (cond
1095 ((gnus-functionp group)
1096 (funcall group))
1097 ((or (stringp group) (list group))
1098 group))))
1099 (when gcc
1100 (insert "Gcc: "
1101 (if (stringp gcc) gcc
1102 (mapconcat 'identity gcc " "))
1103 "\n"))))))
1104
1105(defun gnus-inews-insert-archive-gcc (&optional group)
1106 "Insert the Gcc to say where the article is to be archived."
1107 (let* ((var gnus-message-archive-group)
1108 (group (or group gnus-newsgroup-name ""))
6748645f
LMI
1109 (gcc-self-val
1110 (and gnus-newsgroup-name
16409b0b 1111 (not (equal gnus-newsgroup-name ""))
6748645f
LMI
1112 (gnus-group-find-parameter
1113 gnus-newsgroup-name 'gcc-self)))
16409b0b 1114 result
eec82323
LMI
1115 (groups
1116 (cond
1117 ((null gnus-message-archive-method)
1118 ;; Ignore.
1119 nil)
1120 ((stringp var)
1121 ;; Just a single group.
1122 (list var))
1123 ((null var)
1124 ;; We don't want this.
1125 nil)
1126 ((and (listp var) (stringp (car var)))
1127 ;; A list of groups.
1128 var)
1129 ((gnus-functionp var)
1130 ;; A function.
1131 (funcall var group))
1132 (t
1133 ;; An alist of regexps/functions/forms.
1134 (while (and var
1135 (not
1136 (setq result
1137 (cond
1138 ((stringp (caar var))
1139 ;; Regexp.
1140 (when (string-match (caar var) group)
1141 (cdar var)))
1142 ((gnus-functionp (car var))
1143 ;; Function.
1144 (funcall (car var) group))
1145 (t
1146 (eval (car var)))))))
1147 (setq var (cdr var)))
1148 result)))
1149 name)
6748645f 1150 (when (or groups gcc-self-val)
eec82323
LMI
1151 (when (stringp groups)
1152 (setq groups (list groups)))
1153 (save-excursion
1154 (save-restriction
1155 (message-narrow-to-headers)
1156 (goto-char (point-max))
1157 (insert "Gcc: ")
6748645f
LMI
1158 (if gcc-self-val
1159 ;; Use the `gcc-self' param value instead.
eec82323
LMI
1160 (progn
1161 (insert
1162 (if (stringp gcc-self-val)
1163 gcc-self-val
1164 group))
1165 (if (not (eq gcc-self-val 'none))
1166 (insert "\n")
1167 (progn
1168 (beginning-of-line)
1169 (kill-line))))
6748645f 1170 ;; Use the list of groups.
eec82323
LMI
1171 (while (setq name (pop groups))
1172 (insert (if (string-match ":" name)
1173 name
1174 (gnus-group-prefixed-name
1175 name gnus-message-archive-method)))
1176 (when groups
1177 (insert " ")))
1178 (insert "\n")))))))
1179
6748645f
LMI
1180;;; Posting styles.
1181
6748645f
LMI
1182(defun gnus-configure-posting-styles ()
1183 "Configure posting styles according to `gnus-posting-styles'."
1184 (unless gnus-inhibit-posting-styles
16409b0b
GM
1185 (let ((group (or gnus-newsgroup-name ""))
1186 (styles gnus-posting-styles)
1187 style match variable attribute value v results
1188 filep name address element)
1189 ;; If the group has a posting-style parameter, add it at the end with a
1190 ;; regexp matching everything, to be sure it takes precedence over all
1191 ;; the others.
1192 (when gnus-newsgroup-name
1193 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1194 (when tmp-style
1195 (setq styles (append styles (list (cons ".*" tmp-style)))))))
6748645f 1196 ;; Go through all styles and look for matches.
16409b0b
GM
1197 (dolist (style styles)
1198 (setq match (pop style))
1199 (goto-char (point-min))
1200 (when (cond
1201 ((stringp match)
1202 ;; Regexp string match on the group name.
1203 (string-match match group))
1204 ((eq match 'header)
1205 (let ((header (message-fetch-field (pop style))))
1206 (and header
1207 (string-match (pop style) header))))
1208 ((or (symbolp match)
1209 (gnus-functionp match))
1210 (cond
1211 ((gnus-functionp match)
1212 ;; Function to be called.
1213 (funcall match))
1214 ((boundp match)
1215 ;; Variable to be checked.
1216 (symbol-value match))))
1217 ((listp match)
1218 ;; This is a form to be evaled.
1219 (eval match)))
6748645f 1220 ;; We have a match, so we set the variables.
16409b0b
GM
1221 (dolist (attribute style)
1222 (setq element (pop attribute)
1223 variable nil
1224 filep nil)
1225 (setq value
1226 (cond
1227 ((eq (car attribute) :file)
1228 (setq filep t)
1229 (cadr attribute))
1230 ((eq (car attribute) :value)
1231 (cadr attribute))
1232 (t
1233 (car attribute))))
1234 ;; We get the value.
1235 (setq v
1236 (cond
1237 ((stringp value)
1238 value)
1239 ((or (symbolp value)
1240 (gnus-functionp value))
1241 (cond ((gnus-functionp value)
1242 (funcall value))
1243 ((boundp value)
1244 (symbol-value value))))
1245 ((listp value)
1246 (eval value))))
1247 ;; Translate obsolescent value.
1248 (when (eq element 'signature-file)
1249 (setq element 'signature
1250 filep t))
1251 ;; Get the contents of file elems.
1252 (when (and filep v)
1253 (setq v (with-temp-buffer
1254 (insert-file-contents v)
1255 (buffer-string))))
1256 (setq results (delq (assoc element results) results))
1257 (push (cons element v) results))))
1258 ;; Now we have all the styles, so we insert them.
1259 (setq name (assq 'name results)
1260 address (assq 'address results))
1261 (setq results (delq name (delq address results)))
1262 (make-local-variable 'message-setup-hook)
1263 (dolist (result results)
1264 (add-hook 'message-setup-hook
1265 (cond
1266 ((eq 'eval (car result))
1267 'ignore)
1268 ((eq 'body (car result))
1269 `(lambda ()
1270 (save-excursion
1271 (message-goto-body)
1272 (insert ,(cdr result)))))
1273 ((eq 'signature (car result))
1274 (set (make-local-variable 'message-signature) nil)
1275 (set (make-local-variable 'message-signature-file) nil)
1276 (if (not (cdr result))
1277 'ignore
1278 `(lambda ()
1279 (save-excursion
1280 (let ((message-signature ,(cdr result)))
1281 (when message-signature
1282 (message-insert-signature)))))))
1283 (t
1284 (let ((header
1285 (if (symbolp (car result))
1286 (capitalize (symbol-name (car result)))
1287 (car result))))
1288 `(lambda ()
1289 (save-excursion
1290 (message-remove-header ,header)
1291 (let ((value ,(cdr result)))
1292 (when value
1293 (message-goto-eoh)
1294 (insert ,header ": " value "\n"))))))))))
1295 (when (or name address)
1296 (add-hook 'message-setup-hook
1297 `(lambda ()
1298 (set (make-local-variable 'user-mail-address)
1299 ,(or (cdr address) user-mail-address))
1300 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1301 (user-mail-address
1302 ,(or (cdr address) user-mail-address)))
1303 (save-excursion
1304 (message-remove-header "From")
1305 (message-goto-eoh)
1306 (insert "From: " (message-make-from) "\n")))))))))
eec82323
LMI
1307
1308;;; Allow redefinition of functions.
1309
1310(gnus-ems-redefine)
1311
1312(provide 'gnus-msg)
1313
1314;;; gnus-msg.el ends here