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