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