* imap.el: Add compiler directives.
[gnus] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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 (require 'gnus-util)
37
38 (defcustom gnus-post-method 'current
39   "*Preferred method for posting USENET news.
40
41 If this variable is `current' (which is the default), Gnus will use
42 the \"current\" select method when posting.  If it is `native', Gnus
43 will use the native select method when posting.
44
45 This method will not be used in mail groups and the like, only in
46 \"real\" newsgroups.
47
48 If not `native' nor `current', the value must be a valid method as discussed
49 in the documentation of `gnus-select-method'.  It can also be a list of
50 methods.  If that is the case, the user will be queried for what select
51 method to use when posting."
52   :group 'gnus-group-foreign
53   :link '(custom-manual "(gnus)Posting Server")
54   :type `(choice (const native)
55                  (const current)
56                  (sexp :tag "Methods" ,gnus-select-method)))
57
58 (defcustom gnus-outgoing-message-group nil
59   "*All outgoing messages will be put in this group.
60 If you want to store all your outgoing mail and articles in the group
61 \"nnml:archive\", you set this variable to that value.  This variable
62 can also be a list of group names.
63
64 If you want to have greater control over what group to put each
65 message in, you can set this variable to a function that checks the
66 current newsgroup name and then returns a suitable group name (or list
67 of names)."
68   :group 'gnus-message
69   :type '(choice (string :tag "Group")
70                  (function)))
71
72 (defcustom gnus-mailing-list-groups nil
73   "*If non-nil a regexp matching groups that are really mailing lists.
74 This is useful when you're reading a mailing list that has been
75 gatewayed to a newsgroup, and you want to followup to an article in
76 the group."
77   :group 'gnus-message
78   :type '(choice (regexp)
79                  (const nil)))
80
81 (defcustom gnus-add-to-list nil
82   "*If non-nil, add a `to-list' parameter automatically."
83   :group 'gnus-message
84   :type 'boolean)
85
86 (defcustom gnus-crosspost-complaint
87   "Hi,
88
89 You posted the article below with the following Newsgroups header:
90
91 Newsgroups: %s
92
93 The %s group, at least, was an inappropriate recipient
94 of this message.  Please trim your Newsgroups header to exclude this
95 group before posting in the future.
96
97 Thank you.
98
99 "
100   "Format string to be inserted when complaining about crossposts.
101 The first %s will be replaced by the Newsgroups header;
102 the second with the current group name."
103   :group 'gnus-message
104   :type 'string)
105
106 (defcustom gnus-message-setup-hook nil
107   "Hook run after setting up a message buffer."
108   :group 'gnus-message
109   :type 'hook)
110
111 (defcustom gnus-bug-create-help-buffer t
112   "*Should we create the *Gnus Help Bug* buffer?"
113   :group 'gnus-message
114   :type 'boolean)
115
116 (defcustom gnus-posting-styles nil
117   "*Alist of styles to use when posting.
118 See Info node `(gnus)Posting Styles'."
119   :group 'gnus-message
120   :link '(custom-manual "(gnus)Posting Styles")
121   :type '(repeat (cons (choice (regexp)
122                                (variable)
123                                (list (const header)
124                                      (string :tag "Header")
125                                      (regexp :tag "Regexp"))
126                                (function)
127                                (sexp))
128                        (repeat (list
129                                 (choice (const signature)
130                                         (const signature-file)
131                                         (const organization)
132                                         (const address)
133                                         (const x-face-file)
134                                         (const name)
135                                         (const body)
136                                         (symbol)
137                                         (string :tag "Header"))
138                                 (choice (string)
139                                         (function)
140                                         (variable)
141                                         (sexp)))))))
142
143 (defcustom gnus-gcc-mark-as-read nil
144   "If non-nil, automatically mark Gcc articles as read."
145   :version "21.1"
146   :group 'gnus-message
147   :type 'boolean)
148
149 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
150                         'gnus-gcc-mark-as-read)
151
152 (defcustom gnus-gcc-externalize-attachments nil
153   "Should local-file attachments be included as external parts in Gcc copies?
154 If it is `all', attach files as external parts;
155 if a regexp and matches the Gcc group name, attach files as external parts;
156 if nil, attach files as normal parts."
157   :version "21.1"
158   :group 'gnus-message
159   :type '(choice (const nil :tag "None")
160                  (const all :tag "Any")
161                  (string :tag "Regexp")))
162
163 (gnus-define-group-parameter
164  posting-charset-alist
165  :type list
166  :function-document
167  "Return the permitted unencoded charsets for posting of GROUP."
168  :variable gnus-group-posting-charset-alist
169  :variable-default
170   '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
171     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
172     (message-this-is-mail nil nil)
173     (message-this-is-news nil t))
174  :variable-document
175   "Alist of regexps and permitted unencoded charsets for posting.
176 Each element of the alist has the form (TEST HEADER BODY-LIST), where
177 TEST is either a regular expression matching the newsgroup header or a
178 variable to query,
179 HEADER is the charset which may be left unencoded in the header (nil
180 means encode all charsets),
181 BODY-LIST is a list of charsets which may be encoded using 8bit
182 content-transfer encoding in the body, or one of the special values
183 nil (always encode using quoted-printable) or t (always use 8bit).
184
185 Note that any value other than nil for HEADER infringes some RFCs, so
186 use this option with care."
187  :variable-group gnus-charset
188  :variable-type
189  '(repeat (list :tag "Permitted unencoded charsets"
190                 (choice :tag "Where"
191                         (regexp :tag "Group")
192                         (const :tag "Mail message" :value message-this-is-mail)
193                         (const :tag "News article" :value message-this-is-news))
194                 (choice :tag "Header"
195                         (const :tag "None" nil)
196                         (symbol :tag "Charset"))
197                 (choice :tag "Body"
198                         (const :tag "Any" :value t)
199                         (const :tag "None" :value nil)
200                         (repeat :tag "Charsets"
201                                 (symbol :tag "Charset")))))
202  :parameter-type '(choice :tag "Permitted unencoded charsets"
203                           :value nil
204                           (repeat (symbol)))
205  :parameter-document       "\
206 List of charsets that are permitted to be unencoded.")
207
208 (defcustom gnus-debug-files
209   '("gnus.el" "gnus-sum.el" "gnus-group.el"
210     "gnus-art.el" "gnus-start.el" "gnus-async.el"
211     "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
212     "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
213     "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
214   "Files whose variables will be reported in `gnus-bug'."
215   :version "21.1"
216   :group 'gnus-message
217   :type '(repeat (string :tag "File")))
218
219 (defcustom gnus-debug-exclude-variables
220   '(mm-mime-mule-charset-alist
221     nnmail-split-fancy message-minibuffer-local-map)
222   "Variables that should not be reported in `gnus-bug'."
223   :version "21.1"
224   :group 'gnus-message
225   :type '(repeat (symbol :tag "Variable")))
226
227 (defcustom gnus-discouraged-post-methods
228   '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
229   "A list of back ends that are not used in \"real\" newsgroups.
230 This variable is used only when `gnus-post-method' is `current'."
231   :version "21.3"
232   :group 'gnus-group-foreign
233   :type '(repeat (symbol :tag "Back end")))
234
235 (defcustom gnus-message-replysign
236   nil
237   "Automatically sign replies to signed messages.
238 See also the `mml-default-sign-method' variable."
239   :group 'gnus-message
240   :type 'boolean)
241
242 (defcustom gnus-message-replyencrypt
243   nil
244   "Automatically encrypt replies to encrypted messages.
245 See also the `mml-default-encrypt-method' variable."
246   :group 'gnus-message
247   :type 'boolean)
248
249 (defcustom gnus-message-replysignencrypted
250   t
251   "Setting this causes automatically encrypted messages to also be signed."
252   :group 'gnus-message
253   :type 'boolean)
254
255 (defcustom gnus-confirm-mail-reply-to-news nil
256   "If non-nil, Gnus requests confirmation when replying to news.
257 This is done because new users often reply by mistake when reading
258 news.
259 This can also be a function receiving the group name as the only
260 parameter which should return non-nil iff a confirmation is needed, or
261 a regexp, in which case a confirmation is asked for iff the group name
262 matches the regexp."
263   :group 'gnus-message
264   :type '(choice (const :tag "No" nil)
265                  (const :tag "Yes" t)
266                  (regexp :tag "Iff group matches regexp")
267                  (function :tag "Iff function evaluates to non-nil")))
268
269 (defcustom gnus-confirm-treat-mail-like-news
270   nil
271   "If non-nil, Gnus will treat mail like news with regard to confirmation
272 when replying by mail.  See the `gnus-confirm-mail-reply-to-news' variable
273 for fine-tuning this.
274 If nil, Gnus will never ask for confirmation if replying to mail."
275   :group 'gnus-message
276   :type 'boolean)
277
278 (defcustom gnus-summary-resend-default-address t
279   "If non-nil, Gnus tries to suggest a default address to resend to.
280 If nil, the address field will always be empty after invoking
281 `gnus-summary-resend-message'."
282   :group 'gnus-message
283   :type 'boolean)
284
285 ;;; Internal variables.
286
287 (defvar gnus-inhibit-posting-styles nil
288   "Inhibit the use of posting styles.")
289
290 (defvar gnus-article-yanked-articles nil)
291 (defvar gnus-message-buffer "*Mail Gnus*")
292 (defvar gnus-article-copy nil)
293 (defvar gnus-check-before-posting nil)
294 (defvar gnus-last-posting-server nil)
295 (defvar gnus-message-group-art nil)
296
297 (defvar gnus-msg-force-broken-reply-to nil)
298
299 (defconst gnus-bug-message
300   "Sending a bug report to the Gnus Towers.
301 ========================================
302
303 The buffer below is a mail buffer.  When you press `C-c C-c', it will
304 be sent to the Gnus Bug Exterminators.
305
306 The thing near the bottom of the buffer is how the environment
307 settings will be included in the mail.  Please do not delete that.
308 They will tell the Bug People what your environment is, so that it
309 will be easier to locate the bugs.
310
311 If you have found a bug that makes Emacs go \"beep\", set
312 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
313 and include the backtrace in your bug report.
314
315 Please describe the bug in annoying, painstaking detail.
316
317 Thank you for your help in stamping out bugs.
318 ")
319
320 (eval-and-compile
321   (autoload 'gnus-uu-post-news "gnus-uu" nil t))
322
323 \f
324 ;;;
325 ;;; Gnus Posting Functions
326 ;;;
327
328 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
329   "p" gnus-summary-post-news
330   "i" gnus-summary-news-other-window
331   "f" gnus-summary-followup
332   "F" gnus-summary-followup-with-original
333   "c" gnus-summary-cancel-article
334   "s" gnus-summary-supersede-article
335   "r" gnus-summary-reply
336   "y" gnus-summary-yank-message
337   "R" gnus-summary-reply-with-original
338   "w" gnus-summary-wide-reply
339   "W" gnus-summary-wide-reply-with-original
340   "v" gnus-summary-very-wide-reply
341   "V" gnus-summary-very-wide-reply-with-original
342   "n" gnus-summary-followup-to-mail
343   "N" gnus-summary-followup-to-mail-with-original
344   "m" gnus-summary-mail-other-window
345   "u" gnus-uu-post-news
346   "\M-c" gnus-summary-mail-crosspost-complaint
347   "Br" gnus-summary-reply-broken-reply-to
348   "BR" gnus-summary-reply-broken-reply-to-with-original
349   "om" gnus-summary-mail-forward
350   "op" gnus-summary-post-forward
351   "Om" gnus-uu-digest-mail-forward
352   "Op" gnus-uu-digest-post-forward)
353
354 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
355   "b" gnus-summary-resend-bounced-mail
356   ;; "c" gnus-summary-send-draft
357   "r" gnus-summary-resend-message
358   "e" gnus-summary-resend-message-edit)
359
360 ;;; Internal functions.
361
362 (defun gnus-inews-make-draft ()
363   `(lambda ()
364      (gnus-inews-make-draft-meta-information
365       ,gnus-newsgroup-name ',gnus-article-reply)))
366
367 (defvar gnus-article-reply nil)
368 (defmacro gnus-setup-message (config &rest forms)
369   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
370         (buffer (make-symbol "gnus-setup-message-buffer"))
371         (article (make-symbol "gnus-setup-message-article"))
372         (yanked (make-symbol "gnus-setup-yanked-articles"))
373         (group (make-symbol "gnus-setup-message-group")))
374     `(let ((,winconf (current-window-configuration))
375            (,buffer (buffer-name (current-buffer)))
376            (,article gnus-article-reply)
377            (,yanked gnus-article-yanked-articles)
378            (,group gnus-newsgroup-name)
379            (message-header-setup-hook
380             (copy-sequence message-header-setup-hook))
381            (mbl mml-buffer-list)
382            (message-mode-hook (copy-sequence message-mode-hook)))
383        (setq mml-buffer-list nil)
384        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
385        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
386        ;; #### FIXME: for a reason that I did not manage to identify yet,
387        ;; the variable `gnus-newsgroup-name' does not honor a dynamically
388        ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
389        ;; After evaluation of @forms below, it gets the value we actually want
390        ;; to override, and the posting styles are used. For that reason, I've
391        ;; added an optional argument to `gnus-configure-posting-styles' to
392        ;; make sure that the correct value for the group name is used. -- drv
393        (add-hook 'message-mode-hook
394                  (if (memq ,config '(reply-yank reply))
395                      (lambda ()
396                        (gnus-configure-posting-styles ,group))
397                    (lambda ()
398                      ;; There may be an old " *gnus article copy*" buffer.
399                      (let (gnus-article-copy)
400                        (gnus-configure-posting-styles ,group)))))
401        (gnus-pull ',(intern gnus-draft-meta-information-header)
402                   message-required-headers)
403        (when (and ,group
404                   (not (string= ,group "")))
405          (push (cons
406                 (intern gnus-draft-meta-information-header)
407                 (gnus-inews-make-draft))
408                message-required-headers))
409        (unwind-protect
410            (progn
411              ,@forms)
412          (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
413                                       ,yanked)
414          (setq gnus-message-buffer (current-buffer))
415          (set (make-local-variable 'gnus-message-group-art)
416               (cons ,group ,article))
417          (set (make-local-variable 'gnus-newsgroup-name) ,group)
418          (gnus-run-hooks 'gnus-message-setup-hook)
419          (if (eq major-mode 'message-mode)
420              (let ((mbl1 mml-buffer-list))
421                (setq mml-buffer-list mbl)  ;; Global value
422                (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
423                (gnus-make-local-hook 'kill-buffer-hook)
424                (gnus-make-local-hook 'change-major-mode-hook)
425                (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
426                (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
427            (mml-destroy-buffers)
428            (setq mml-buffer-list mbl)))
429        (message-hide-headers)
430        (gnus-add-buffer)
431        (gnus-configure-windows ,config t)
432        (run-hooks 'post-command-hook)
433        (set-buffer-modified-p nil))))
434
435 (defun gnus-inews-make-draft-meta-information (group article)
436   (concat "(\"" group "\" "
437           (if article (number-to-string
438                        (if (listp article)
439                            (car article)
440                          article)) "\"\"")
441           ")"))
442
443 ;;;###autoload
444 (defun gnus-msg-mail (&optional to subject other-headers continue
445                                 switch-action yank-action send-actions)
446   "Start editing a mail message to be sent.
447 Like `message-mail', but with Gnus paraphernalia, particularly the
448 Gcc: header for archiving purposes."
449   (interactive)
450   (let ((buf (current-buffer))
451         mail-buf)
452     (gnus-setup-message 'message
453       (message-mail to subject other-headers continue
454                     nil yank-action send-actions))
455     (when switch-action
456       (setq mail-buf (current-buffer))
457       (switch-to-buffer buf)
458       (apply switch-action mail-buf nil)))
459   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
460   t)
461
462 (defvar save-selected-window-window)
463
464 ;;;###autoload
465 (defun gnus-button-mailto (address)
466   "Mail to ADDRESS."
467   (set-buffer (gnus-copy-article-buffer))
468   (gnus-setup-message 'message
469     (message-reply address))
470   (and (boundp 'save-selected-window-window)
471        (not (window-live-p save-selected-window-window))
472        (setq save-selected-window-window (selected-window))))
473
474 ;;;###autoload
475 (defun gnus-button-reply (&optional to-address wide)
476   "Like `message-reply'."
477   (interactive)
478   (gnus-setup-message 'message
479     (message-reply to-address wide))
480   (and (boundp 'save-selected-window-window)
481        (not (window-live-p save-selected-window-window))
482        (setq save-selected-window-window (selected-window))))
483
484 ;;;###autoload
485 (define-mail-user-agent 'gnus-user-agent
486   'gnus-msg-mail 'message-send-and-exit
487   'message-kill-buffer 'message-send-hook)
488
489 (defun gnus-setup-posting-charset (group)
490   (let ((alist gnus-group-posting-charset-alist)
491         (group (or group ""))
492         elem)
493     (when group
494       (catch 'found
495         (while (setq elem (pop alist))
496           (when (or (and (stringp (car elem))
497                          (string-match (car elem) group))
498                     (and (functionp (car elem))
499                          (funcall (car elem) group))
500                     (and (symbolp (car elem))
501                          (symbol-value (car elem))))
502             (throw 'found (cons (cadr elem) (caddr elem)))))))))
503
504 (defun gnus-inews-add-send-actions (winconf buffer article
505                                             &optional config yanked)
506   (gnus-make-local-hook 'message-sent-hook)
507   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
508                                  'gnus-inews-do-gcc) nil t)
509   (when gnus-agent
510     (gnus-make-local-hook 'message-header-hook)
511     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
512   (setq message-post-method
513         `(lambda (arg)
514            (gnus-post-method arg ,gnus-newsgroup-name)))
515   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
516   (message-add-action
517    `(when (gnus-buffer-exists-p ,buffer)
518       (set-window-configuration ,winconf))
519    'exit 'postpone 'kill)
520   (let ((to-be-marked (cond
521                        (yanked
522                         (mapcar
523                          (lambda (x) (if (listp x) (car x) x)) yanked))
524                        (article (if (listp article) article (list article)))
525                        (t nil))))
526     (message-add-action
527      `(when (gnus-buffer-exists-p ,buffer)
528         (save-excursion
529           (set-buffer ,buffer)
530           ,(when to-be-marked
531              (if (eq config 'forward)
532                  `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
533                `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
534      'send)))
535
536 (put 'gnus-setup-message 'lisp-indent-function 1)
537 (put 'gnus-setup-message 'edebug-form-spec '(form body))
538
539 ;;; Post news commands of Gnus group mode and summary mode
540
541 (defun gnus-group-mail (&optional arg)
542   "Start composing a mail.
543 If ARG, use the group under the point to find a posting style.
544 If ARG is 1, prompt for a group name to find the posting style."
545   (interactive "P")
546   ;; We can't `let' gnus-newsgroup-name here, since that leads
547   ;; to local variables leaking.
548   (let ((group gnus-newsgroup-name)
549         ;; make sure last viewed article doesn't affect posting styles:
550         (gnus-article-copy)
551         (buffer (current-buffer)))
552     (unwind-protect
553         (progn
554           (setq gnus-newsgroup-name
555                 (if arg
556                     (if (= 1 (prefix-numeric-value arg))
557                         (completing-read "Use posting style of group: "
558                                          gnus-active-hashtb nil
559                                          (gnus-read-active-file-p))
560                       (gnus-group-group-name))
561                   ""))
562           ;; #### see comment in gnus-setup-message -- drv
563           (gnus-setup-message 'message (message-mail)))
564       (save-excursion
565         (set-buffer buffer)
566         (setq gnus-newsgroup-name group)))))
567
568 (defun gnus-group-news (&optional arg)
569   "Start composing a news.
570 If ARG, post to group under point.
571 If ARG is 1, prompt for group name to post to.
572
573 This function prepares a news even when using mail groups.  This is useful
574 for posting messages to mail groups without actually sending them over the
575 network.  The corresponding back end must have a 'request-post method."
576   (interactive "P")
577   ;; We can't `let' gnus-newsgroup-name here, since that leads
578   ;; to local variables leaking.
579   (let ((group gnus-newsgroup-name)
580         ;; make sure last viewed article doesn't affect posting styles:
581         (gnus-article-copy)
582         (buffer (current-buffer)))
583     (unwind-protect
584         (progn
585           (setq gnus-newsgroup-name
586                 (if arg
587                     (if (= 1 (prefix-numeric-value arg))
588                         (completing-read "Use group: "
589                                          gnus-active-hashtb nil
590                                          (gnus-read-active-file-p))
591                       (gnus-group-group-name))
592                   ""))
593           ;; #### see comment in gnus-setup-message -- drv
594           (gnus-setup-message 'message
595             (message-news (gnus-group-real-name gnus-newsgroup-name))))
596       (save-excursion
597         (set-buffer buffer)
598         (setq gnus-newsgroup-name group)))))
599
600 (defun gnus-group-post-news (&optional arg)
601   "Start composing a message (a news by default).
602 If ARG, post to group under point.  If ARG is 1, prompt for group name.
603 Depending on the selected group, the message might be either a mail or
604 a news."
605   (interactive "P")
606   ;; Bind this variable here to make message mode hooks work ok.
607   (let ((gnus-newsgroup-name
608          (if arg
609              (if (= 1 (prefix-numeric-value arg))
610                  (completing-read "Newsgroup: " gnus-active-hashtb nil
611                                   (gnus-read-active-file-p))
612                (gnus-group-group-name))
613            ""))
614         ;; make sure last viewed article doesn't affect posting styles:
615         (gnus-article-copy))
616     (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
617                     (string= gnus-newsgroup-name ""))))
618
619 (defun gnus-summary-mail-other-window (&optional arg)
620   "Start composing a mail in another window.
621 Use the posting of the current group by default.
622 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
623 posting style."
624   (interactive "P")
625   ;; We can't `let' gnus-newsgroup-name here, since that leads
626   ;; to local variables leaking.
627   (let ((group gnus-newsgroup-name)
628         ;; make sure last viewed article doesn't affect posting styles:
629         (gnus-article-copy)
630         (buffer (current-buffer)))
631     (unwind-protect
632         (progn
633           (setq gnus-newsgroup-name
634                 (if arg
635                     (if (= 1 (prefix-numeric-value arg))
636                         (completing-read "Use group: "
637                                          gnus-active-hashtb nil
638                                          (gnus-read-active-file-p))
639                       "")
640                   gnus-newsgroup-name))
641           ;; #### see comment in gnus-setup-message -- drv
642           (gnus-setup-message 'message (message-mail)))
643       (save-excursion
644         (set-buffer buffer)
645         (setq gnus-newsgroup-name group)))))
646
647 (defun gnus-summary-news-other-window (&optional arg)
648   "Start composing a news in another window.
649 Post to the current group by default.
650 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
651
652 This function prepares a news even when using mail groups.  This is useful
653 for posting messages to mail groups without actually sending them over the
654 network.  The corresponding back end must have a 'request-post method."
655   (interactive "P")
656   ;; We can't `let' gnus-newsgroup-name here, since that leads
657   ;; to local variables leaking.
658   (let ((group gnus-newsgroup-name)
659         ;; make sure last viewed article doesn't affect posting styles:
660         (gnus-article-copy)
661         (buffer (current-buffer)))
662     (unwind-protect
663         (progn
664           (setq gnus-newsgroup-name
665                 (if arg
666                     (if (= 1 (prefix-numeric-value arg))
667                         (completing-read "Use group: "
668                                          gnus-active-hashtb nil
669                                          (gnus-read-active-file-p))
670                       "")
671                   gnus-newsgroup-name))
672           ;; #### see comment in gnus-setup-message -- drv
673           (gnus-setup-message 'message
674             (progn
675               (message-news (gnus-group-real-name gnus-newsgroup-name))
676               (set (make-local-variable 'gnus-discouraged-post-methods)
677                    (remove
678                     (car (gnus-find-method-for-group gnus-newsgroup-name))
679                     gnus-discouraged-post-methods)))))
680       (save-excursion
681         (set-buffer buffer)
682         (setq gnus-newsgroup-name group)))))
683
684 (defun gnus-summary-post-news (&optional arg)
685   "Start composing a message.  Post to the current group by default.
686 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
687 Depending on the selected group, the message might be either a mail or
688 a news."
689   (interactive "P")
690   ;; Bind this variable here to make message mode hooks work ok.
691   (let ((gnus-newsgroup-name
692          (if arg
693              (if (= 1 (prefix-numeric-value arg))
694                  (completing-read "Newsgroup: " gnus-active-hashtb nil
695                                   (gnus-read-active-file-p))
696                "")
697            gnus-newsgroup-name))
698         ;; make sure last viewed article doesn't affect posting styles:
699         (gnus-article-copy))
700     (gnus-post-news 'post gnus-newsgroup-name)))
701
702
703 (defun gnus-summary-followup (yank &optional force-news)
704   "Compose a followup to an article.
705 If prefix argument YANK is non-nil, the original article is yanked
706 automatically.
707 YANK is a list of elements, where the car of each element is the
708 article number, and the cdr is the string to be yanked."
709   (interactive
710    (list (and current-prefix-arg
711               (gnus-summary-work-articles 1))))
712   (when yank
713     (gnus-summary-goto-subject
714      (if (listp (car yank))
715          (caar yank)
716        (car yank))))
717   (save-window-excursion
718     (gnus-summary-select-article))
719   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
720         (gnus-newsgroup-name gnus-newsgroup-name))
721     ;; Send a followup.
722     (gnus-post-news nil gnus-newsgroup-name
723                     headers gnus-article-buffer
724                     yank nil force-news)
725     (gnus-summary-handle-replysign)))
726
727 (defun gnus-summary-followup-with-original (n &optional force-news)
728   "Compose a followup to an article and include the original article."
729   (interactive "P")
730   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
731
732 (defun gnus-summary-followup-to-mail (&optional arg)
733   "Followup to the current mail message via news."
734   (interactive
735    (list (and current-prefix-arg
736               (gnus-summary-work-articles 1))))
737   (gnus-summary-followup arg t))
738
739 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
740   "Followup to the current mail message via news."
741   (interactive "P")
742   (gnus-summary-followup (gnus-summary-work-articles arg) t))
743
744 (defun gnus-inews-yank-articles (articles)
745   (let (beg article yank-string)
746     (message-goto-body)
747     (while (setq article (pop articles))
748       (when (listp article)
749         (setq yank-string (nth 1 article)
750               article (nth 0 article)))
751       (save-window-excursion
752         (set-buffer gnus-summary-buffer)
753         (gnus-summary-select-article nil nil nil article)
754         (gnus-summary-remove-process-mark article))
755       (gnus-copy-article-buffer nil yank-string)
756       (let ((message-reply-buffer gnus-article-copy)
757             (message-reply-headers
758              ;; The headers are decoded.
759              (with-current-buffer gnus-article-copy
760                (save-restriction
761                  (nnheader-narrow-to-headers)
762                  (nnheader-parse-naked-head)))))
763         (message-yank-original)
764         (setq beg (or beg (mark t))))
765       (when articles
766         (insert "\n")))
767     (push-mark)
768     (goto-char beg)))
769
770 (defun gnus-summary-cancel-article (&optional n symp)
771   "Cancel an article you posted.
772 Uses the process-prefix convention.  If given the symbolic
773 prefix `a', cancel using the standard posting method; if not
774 post using the current select method."
775   (interactive (gnus-interactive "P\ny"))
776   (let ((articles (gnus-summary-work-articles n))
777         (message-post-method
778          `(lambda (arg)
779             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
780         article)
781     (while (setq article (pop articles))
782       (when (gnus-summary-select-article t nil nil article)
783         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
784                 (message-cancel-news))
785           (gnus-summary-mark-as-read article gnus-canceled-mark)
786           (gnus-cache-remove-article 1))
787         (gnus-article-hide-headers-if-wanted))
788       (gnus-summary-remove-process-mark article))))
789
790 (defun gnus-summary-supersede-article ()
791   "Compose an article that will supersede a previous article.
792 This is done simply by taking the old article and adding a Supersedes
793 header line with the old Message-ID."
794   (interactive)
795   (let ((article (gnus-summary-article-number)))
796     (gnus-setup-message 'reply-yank
797       (gnus-summary-select-article t)
798       (set-buffer gnus-original-article-buffer)
799       (message-supersede)
800       (push
801        `((lambda ()
802            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
803              (save-excursion
804                (set-buffer ,gnus-summary-buffer)
805                (gnus-cache-possibly-remove-article ,article nil nil nil t)
806                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
807        message-send-actions))))
808
809 \f
810
811 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
812   ;; make a copy of the article buffer with all text properties removed
813   ;; this copy is in the buffer gnus-article-copy.
814   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
815   ;; this buffer should be passed to all mail/news reply/post routines.
816   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
817   (save-excursion
818     (set-buffer gnus-article-copy)
819     (mm-enable-multibyte))
820   (let ((article-buffer (or article-buffer gnus-article-buffer))
821         end beg)
822     (if (not (and (get-buffer article-buffer)
823                   (gnus-buffer-exists-p article-buffer)))
824         (error "Can't find any article buffer")
825       (save-excursion
826         (set-buffer article-buffer)
827         (let ((gnus-newsgroup-charset (or gnus-article-charset
828                                           gnus-newsgroup-charset))
829               (gnus-newsgroup-ignored-charsets
830                (or gnus-article-ignored-charsets
831                    gnus-newsgroup-ignored-charsets)))
832           (save-restriction
833             ;; Copy over the (displayed) article buffer, delete
834             ;; hidden text and remove text properties.
835             (widen)
836             (copy-to-buffer gnus-article-copy (point-min) (point-max))
837             (set-buffer gnus-article-copy)
838             (when yank-string
839               (message-goto-body)
840               (delete-region (point) (point-max))
841               (insert yank-string))
842             (gnus-article-delete-text-of-type 'annotation)
843             (gnus-remove-text-with-property 'gnus-prev)
844             (gnus-remove-text-with-property 'gnus-next)
845             (gnus-remove-text-with-property 'gnus-decoration)
846             (insert
847              (prog1
848                  (buffer-substring-no-properties (point-min) (point-max))
849                (erase-buffer)))
850             ;; Find the original headers.
851             (set-buffer gnus-original-article-buffer)
852             (goto-char (point-min))
853             (while (looking-at message-unix-mail-delimiter)
854               (forward-line 1))
855             (let ((mail-header-separator ""))
856               (setq beg (point)
857                     end (or (message-goto-body)
858                             ;; There may be just a header.
859                             (point-max))))
860             ;; Delete the headers from the displayed articles.
861             (set-buffer gnus-article-copy)
862             (let ((mail-header-separator ""))
863               (delete-region (goto-char (point-min))
864                              (or (message-goto-body) (point-max))))
865             ;; Insert the original article headers.
866             (insert-buffer-substring gnus-original-article-buffer beg end)
867             ;; Decode charsets.
868             (let ((gnus-article-decode-hook
869                    (delq 'article-decode-charset
870                          (copy-sequence gnus-article-decode-hook))))
871               (run-hooks 'gnus-article-decode-hook)))))
872       gnus-article-copy)))
873
874 (defun gnus-post-news (post &optional group header article-buffer yank subject
875                             force-news)
876   (when article-buffer
877     (gnus-copy-article-buffer))
878   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
879         (gnus-article-yanked-articles yank)
880         (add-to-list gnus-add-to-list))
881     (gnus-setup-message (cond (yank 'reply-yank)
882                               (article-buffer 'reply)
883                               (t 'message))
884       (let* ((group (or group gnus-newsgroup-name))
885              (charset (gnus-group-name-charset nil group))
886              (pgroup group)
887              to-address to-group mailing-list to-list
888              newsgroup-p)
889         (when group
890           (setq to-address (gnus-parameter-to-address group)
891                 to-group (gnus-group-find-parameter group 'to-group)
892                 to-list (gnus-parameter-to-list group)
893                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
894                 mailing-list (when gnus-mailing-list-groups
895                                (string-match gnus-mailing-list-groups group))
896                 group (gnus-group-name-decode (gnus-group-real-name group)
897                                               charset)))
898         (if (or (and to-group
899                      (gnus-news-group-p to-group))
900                 newsgroup-p
901                 force-news
902                 (and (gnus-news-group-p
903                       (or pgroup gnus-newsgroup-name)
904                       (or header gnus-current-article))
905                      (not mailing-list)
906                      (not to-list)
907                      (not to-address)))
908             ;; This is news.
909             (if post
910                 (message-news
911                  (or to-group
912                      (and (not (gnus-virtual-group-p pgroup)) group)))
913               (set-buffer gnus-article-copy)
914               (gnus-msg-treat-broken-reply-to)
915               (message-followup (if (or newsgroup-p force-news)
916                                     (if (save-restriction
917                                           (article-narrow-to-head)
918                                           (message-fetch-field "newsgroups"))
919                                         nil
920                                       "")
921                                   to-group)))
922           ;; The is mail.
923           (if post
924               (progn
925                 (message-mail (or to-address to-list))
926                 ;; Arrange for mail groups that have no `to-address' to
927                 ;; get that when the user sends off the mail.
928                 (when (and (not to-list)
929                            (not to-address)
930                            add-to-list)
931                   (push (list 'gnus-inews-add-to-address pgroup)
932                         message-send-actions)))
933             (set-buffer gnus-article-copy)
934             (gnus-msg-treat-broken-reply-to)
935             (message-wide-reply to-address)))
936         (when yank
937           (gnus-inews-yank-articles yank))))))
938
939 (defun gnus-msg-treat-broken-reply-to (&optional force)
940   "Remove the Reply-to header if broken-reply-to."
941   (when (or force
942             (gnus-group-find-parameter
943              gnus-newsgroup-name 'broken-reply-to))
944     (save-restriction
945       (message-narrow-to-head)
946       (message-remove-header "reply-to"))))
947
948 (defun gnus-post-method (arg group &optional silent)
949   "Return the posting method based on GROUP and ARG.
950 If SILENT, don't prompt the user."
951   (let ((gnus-post-method (or (gnus-parameter-post-method group)
952                               gnus-post-method))
953         (group-method (gnus-find-method-for-group group)))
954     (cond
955      ;; If the group-method is nil (which shouldn't happen) we use
956      ;; the default method.
957      ((null group-method)
958       (or (and (listp gnus-post-method) ;If not current/native/nil
959                (not (listp (car gnus-post-method))) ; and not a list of methods
960                gnus-post-method)        ;then use it.
961           gnus-select-method
962           message-post-method))
963      ;; We want the inverse of the default
964      ((and arg (not (eq arg 0)))
965       (if (eq gnus-post-method 'current)
966           gnus-select-method
967         group-method))
968      ;; We query the user for a post method.
969      ((or arg
970           (and (listp gnus-post-method)
971                (listp (car gnus-post-method))))
972       (let* ((methods
973               ;; Collect all methods we know about.
974               (append
975                (when (listp gnus-post-method)
976                  (if (listp (car gnus-post-method))
977                      gnus-post-method
978                    (list gnus-post-method)))
979                gnus-secondary-select-methods
980                (mapcar 'cdr gnus-server-alist)
981                (mapcar 'car gnus-opened-servers)
982                (list gnus-select-method)
983                (list group-method)))
984              method-alist post-methods method)
985         ;; Weed out all mail methods.
986         (while methods
987           (setq method (gnus-server-get-method "" (pop methods)))
988           (when (and (or (gnus-method-option-p method 'post)
989                          (gnus-method-option-p method 'post-mail))
990                      (not (member method post-methods)))
991             (push method post-methods)))
992         ;; Create a name-method alist.
993         (setq method-alist
994               (mapcar
995                (lambda (m)
996                  (if (equal (cadr m) "")
997                      (list (symbol-name (car m)) m)
998                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
999                post-methods))
1000         ;; Query the user.
1001         (cadr
1002          (assoc
1003           (setq gnus-last-posting-server
1004                 (if (and silent
1005                          gnus-last-posting-server)
1006                     ;; Just use the last value.
1007                     gnus-last-posting-server
1008                   (completing-read
1009                    "Posting method: " method-alist nil t
1010                    (cons (or gnus-last-posting-server "") 0))))
1011           method-alist))))
1012      ;; Override normal method.
1013      ((and (eq gnus-post-method 'current)
1014            (not (memq (car group-method) gnus-discouraged-post-methods))
1015            (gnus-get-function group-method 'request-post t))
1016       (assert (not arg))
1017       group-method)
1018      ;; Use gnus-post-method.
1019      ((listp gnus-post-method)          ;A method...
1020       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1021       gnus-post-method)
1022      ;; Use the normal select method (nil or native).
1023      (t gnus-select-method))))
1024
1025 \f
1026
1027 (defun gnus-extended-version ()
1028   "Stringified Gnus version and Emacs version.
1029 See the variable `gnus-user-agent'."
1030   (interactive)
1031   (let* ((float-output-format nil)
1032          (gnus-v
1033           (concat "Gnus/"
1034                   (prin1-to-string (gnus-continuum-version gnus-version) t)
1035                   " (" gnus-version ")"))
1036          (emacs-v (gnus-emacs-version)))
1037     (if (stringp gnus-user-agent)
1038         gnus-user-agent
1039       (concat gnus-v
1040               (when emacs-v
1041                 (concat " " emacs-v))))))
1042
1043 \f
1044 ;;;
1045 ;;; Gnus Mail Functions
1046 ;;;
1047
1048 ;;; Mail reply commands of Gnus summary mode
1049
1050 (defun gnus-summary-reply (&optional yank wide very-wide)
1051   "Start composing a mail reply to the current message.
1052 If prefix argument YANK is non-nil, the original article is yanked
1053 automatically.
1054 If WIDE, make a wide reply.
1055 If VERY-WIDE, make a very wide reply."
1056   (interactive
1057    (list (and current-prefix-arg
1058               (gnus-summary-work-articles 1))))
1059   ;; Allow user to require confirmation before replying by mail to the
1060   ;; author of a news article (or mail message).
1061   (when (or
1062             (not (or (gnus-news-group-p gnus-newsgroup-name)
1063                      gnus-confirm-treat-mail-like-news))
1064             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1065                         (string-match gnus-confirm-mail-reply-to-news
1066                                       gnus-newsgroup-name))
1067                        ((functionp gnus-confirm-mail-reply-to-news)
1068                         (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1069                        (t gnus-confirm-mail-reply-to-news)))
1070             (y-or-n-p "Really reply by mail to article author? "))
1071     (let* ((article
1072             (if (listp (car yank))
1073                 (caar yank)
1074               (car yank)))
1075            (gnus-article-reply (or article (gnus-summary-article-number)))
1076            (gnus-article-yanked-articles yank)
1077            (headers ""))
1078       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1079       (when yank
1080         (gnus-summary-goto-subject article))
1081       (gnus-setup-message (if yank 'reply-yank 'reply)
1082         (if (not very-wide)
1083             (gnus-summary-select-article)
1084           (dolist (article very-wide)
1085             (gnus-summary-select-article nil nil nil article)
1086             (save-excursion
1087               (set-buffer (gnus-copy-article-buffer))
1088               (gnus-msg-treat-broken-reply-to)
1089               (save-restriction
1090                 (message-narrow-to-head)
1091                 (setq headers (concat headers (buffer-string)))))))
1092         (set-buffer (gnus-copy-article-buffer))
1093         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1094         (save-restriction
1095           (message-narrow-to-head)
1096           (when very-wide
1097             (erase-buffer)
1098             (insert headers))
1099           (goto-char (point-max)))
1100         (mml-quote-region (point) (point-max))
1101         (message-reply nil wide)
1102         (when yank
1103           (gnus-inews-yank-articles yank))
1104         (gnus-summary-handle-replysign)))))
1105
1106 (defun gnus-summary-handle-replysign ()
1107   "Check the various replysign variables and take action accordingly."
1108   (when (or gnus-message-replysign gnus-message-replyencrypt)
1109     (let (signed encrypted)
1110       (save-excursion
1111         (set-buffer gnus-article-buffer)
1112         (setq signed (memq 'signed gnus-article-wash-types))
1113         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1114       (cond ((and gnus-message-replyencrypt encrypted)
1115              (mml-secure-message mml-default-encrypt-method
1116                                  (if gnus-message-replysignencrypted
1117                                      'signencrypt
1118                                    'encrypt)))
1119             ((and gnus-message-replysign signed)
1120              (mml-secure-message mml-default-sign-method 'sign))))))
1121
1122 (defun gnus-summary-reply-with-original (n &optional wide)
1123   "Start composing a reply mail to the current message.
1124 The original article will be yanked."
1125   (interactive "P")
1126   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1127
1128 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1129   "Like `gnus-summary-reply' except removing reply-to field.
1130 If prefix argument YANK is non-nil, the original article is yanked
1131 automatically.
1132 If WIDE, make a wide reply.
1133 If VERY-WIDE, make a very wide reply."
1134   (interactive
1135    (list (and current-prefix-arg
1136               (gnus-summary-work-articles 1))))
1137   (let ((gnus-msg-force-broken-reply-to t))
1138     (gnus-summary-reply yank wide very-wide)))
1139
1140 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1141   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1142 The original article will be yanked."
1143   (interactive "P")
1144   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1145
1146 (defun gnus-summary-wide-reply (&optional yank)
1147   "Start composing a wide reply mail to the current message.
1148 If prefix argument YANK is non-nil, the original article is yanked
1149 automatically."
1150   (interactive
1151    (list (and current-prefix-arg
1152               (gnus-summary-work-articles 1))))
1153   (gnus-summary-reply yank t))
1154
1155 (defun gnus-summary-wide-reply-with-original (n)
1156   "Start composing a wide reply mail to the current message.
1157 The original article will be yanked.
1158 Uses the process/prefix convention."
1159   (interactive "P")
1160   (gnus-summary-reply-with-original n t))
1161
1162 (defun gnus-summary-very-wide-reply (&optional yank)
1163   "Start composing a very wide reply mail to the current message.
1164 If prefix argument YANK is non-nil, the original article is yanked
1165 automatically."
1166   (interactive
1167    (list (and current-prefix-arg
1168               (gnus-summary-work-articles 1))))
1169   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1170
1171 (defun gnus-summary-very-wide-reply-with-original (n)
1172   "Start composing a very wide reply mail to the current message.
1173 The original article will be yanked."
1174   (interactive "P")
1175   (gnus-summary-reply
1176    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1177
1178 (defun gnus-summary-mail-forward (&optional arg post)
1179   "Forward the current message(s) to another user.
1180 If process marks exist, forward all marked messages;
1181 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1182 if ARG is 1, decode the message and forward directly inline;
1183 if ARG is 2, forward message as an rfc822 MIME section;
1184 if ARG is 3, decode message and forward as an rfc822 MIME section;
1185 if ARG is 4, forward message directly inline;
1186 otherwise, use flipped `message-forward-as-mime'.
1187 If POST, post instead of mail.
1188 For the `inline' alternatives, also see the variable
1189 `message-forward-ignored-headers'."
1190   (interactive "P")
1191   (if (cdr (gnus-summary-work-articles nil))
1192       ;; Process marks are given.
1193       (gnus-uu-digest-mail-forward arg post)
1194     ;; No process marks.
1195     (let ((message-forward-as-mime message-forward-as-mime)
1196           (message-forward-show-mml message-forward-show-mml))
1197       (cond
1198        ((null arg))
1199        ((eq arg 1)
1200         (setq message-forward-as-mime nil
1201               message-forward-show-mml t))
1202        ((eq arg 2)
1203         (setq message-forward-as-mime t
1204               message-forward-show-mml nil))
1205        ((eq arg 3)
1206         (setq message-forward-as-mime t
1207               message-forward-show-mml t))
1208        ((eq arg 4)
1209         (setq message-forward-as-mime nil
1210               message-forward-show-mml nil))
1211        (t
1212         (setq message-forward-as-mime (not message-forward-as-mime))))
1213       (let* ((gnus-article-reply (gnus-summary-article-number))
1214              (gnus-article-yanked-articles (list gnus-article-reply)))
1215         (gnus-setup-message 'forward
1216           (gnus-summary-select-article)
1217           (let ((mail-parse-charset
1218                  (or (and (gnus-buffer-live-p gnus-article-buffer)
1219                           (with-current-buffer gnus-article-buffer
1220                             gnus-article-charset))
1221                      gnus-newsgroup-charset))
1222                 (mail-parse-ignored-charsets
1223                  gnus-newsgroup-ignored-charsets))
1224             (set-buffer gnus-original-article-buffer)
1225             (message-forward post)))))))
1226
1227 (defun gnus-summary-resend-message (address n)
1228   "Resend the current article to ADDRESS."
1229   (interactive
1230    (list (message-read-from-minibuffer
1231           "Resend message(s) to: "
1232           (when (and gnus-summary-resend-default-address
1233                      (gnus-buffer-live-p gnus-original-article-buffer))
1234             ;; If some other article is currently selected, the
1235             ;; initial-contents is wrong. Whatever, it is just the
1236             ;; initial-contents.
1237             (with-current-buffer gnus-original-article-buffer
1238               (nnmail-fetch-field "to"))))
1239          current-prefix-arg))
1240   (let ((articles (gnus-summary-work-articles n))
1241         article)
1242     (while (setq article (pop articles))
1243       (gnus-summary-select-article nil nil nil article)
1244       (save-excursion
1245         (set-buffer gnus-original-article-buffer)
1246         (message-resend address))
1247       (gnus-summary-mark-article-as-forwarded article))))
1248
1249 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1250 (defun gnus-summary-resend-message-edit ()
1251   "Resend an article that has already been sent.
1252 A new buffer will be created to allow the user to modify body and
1253 contents of the message, and then, everything will happen as when
1254 composing a new message."
1255   (interactive)
1256   (let ((article (gnus-summary-article-number)))
1257     (gnus-setup-message 'reply-yank
1258       (gnus-summary-select-article t)
1259       (set-buffer gnus-original-article-buffer)
1260       (let ((cur (current-buffer))
1261             (to (message-fetch-field "to")))
1262         ;; Get a normal message buffer.
1263         (message-pop-to-buffer (message-buffer-name "Resend" to))
1264         (insert-buffer-substring cur)
1265         (mime-to-mml)
1266         (message-narrow-to-head-1)
1267         ;; Gnus will generate a new one when sending.
1268         (message-remove-header "Message-ID")
1269         (message-remove-header message-ignored-resent-headers t)
1270         ;; Remove unwanted headers.
1271         (goto-char (point-max))
1272         (insert mail-header-separator)
1273         (goto-char (point-min))
1274         (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1275           (forward-char 1))
1276         (widen)))))
1277
1278 (defun gnus-summary-post-forward (&optional arg)
1279   "Forward the current article to a newsgroup.
1280 See `gnus-summary-mail-forward' for ARG."
1281   (interactive "P")
1282   (gnus-summary-mail-forward arg t))
1283
1284 (defvar gnus-nastygram-message
1285   "The following article was inappropriately posted to %s.\n\n"
1286   "Format string to insert in nastygrams.
1287 The current group name will be inserted at \"%s\".")
1288
1289 (defun gnus-summary-mail-nastygram (n)
1290   "Send a nastygram to the author of the current article."
1291   (interactive "P")
1292   (when (or gnus-expert-user
1293             (gnus-y-or-n-p
1294              "Really send a nastygram to the author of the current article? "))
1295     (let ((group gnus-newsgroup-name))
1296       (gnus-summary-reply-with-original n)
1297       (set-buffer gnus-message-buffer)
1298       (message-goto-body)
1299       (insert (format gnus-nastygram-message group))
1300       (message-send-and-exit))))
1301
1302 (defun gnus-summary-mail-crosspost-complaint (n)
1303   "Send a complaint about crossposting to the current article(s)."
1304   (interactive "P")
1305   (let ((articles (gnus-summary-work-articles n))
1306         article)
1307     (while (setq article (pop articles))
1308       (set-buffer gnus-summary-buffer)
1309       (gnus-summary-goto-subject article)
1310       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1311             newsgroups followup-to)
1312         (gnus-summary-select-article)
1313         (set-buffer gnus-original-article-buffer)
1314         (if (and (<= (length (message-tokenize-header
1315                               (setq newsgroups
1316                                     (mail-fetch-field "newsgroups"))
1317                               ", "))
1318                      1)
1319                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1320                      (not (member group (message-tokenize-header
1321                                          followup-to ", ")))))
1322             (if followup-to
1323                 (gnus-message 1 "Followup-to restricted")
1324               (gnus-message 1 "Not a crossposted article"))
1325           (set-buffer gnus-summary-buffer)
1326           (gnus-summary-reply-with-original 1)
1327           (set-buffer gnus-message-buffer)
1328           (message-goto-body)
1329           (insert (format gnus-crosspost-complaint newsgroups group))
1330           (message-goto-subject)
1331           (re-search-forward " *$")
1332           (replace-match " (crosspost notification)" t t)
1333           (gnus-deactivate-mark)
1334           (when (gnus-y-or-n-p "Send this complaint? ")
1335             (message-send-and-exit)))))))
1336
1337 (defun gnus-mail-parse-comma-list ()
1338   (let (accumulated
1339         beg)
1340     (skip-chars-forward " ")
1341     (while (not (eobp))
1342       (setq beg (point))
1343       (skip-chars-forward "^,")
1344       (while (zerop
1345               (save-excursion
1346                 (save-restriction
1347                   (let ((i 0))
1348                     (narrow-to-region beg (point))
1349                     (goto-char beg)
1350                     (logand (progn
1351                               (while (search-forward "\"" nil t)
1352                                 (incf i))
1353                               (if (zerop i) 2 i))
1354                             2)))))
1355         (skip-chars-forward ",")
1356         (skip-chars-forward "^,"))
1357       (skip-chars-backward " ")
1358       (push (buffer-substring beg (point))
1359             accumulated)
1360       (skip-chars-forward "^,")
1361       (skip-chars-forward ", "))
1362     accumulated))
1363
1364 (defun gnus-inews-add-to-address (group)
1365   (let ((to-address (mail-fetch-field "to")))
1366     (when (and to-address
1367                (gnus-alive-p))
1368       ;; This mail group doesn't have a `to-list', so we add one
1369       ;; here.  Magic!
1370       (when (gnus-y-or-n-p
1371              (format "Do you want to add this as `to-list': %s? " to-address))
1372         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1373
1374 (defun gnus-put-message ()
1375   "Put the current message in some group and return to Gnus."
1376   (interactive)
1377   (let ((reply gnus-article-reply)
1378         (winconf gnus-prev-winconf)
1379         (group gnus-newsgroup-name))
1380     (unless (and group
1381                  (not (gnus-group-read-only-p group)))
1382       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1383
1384     (when (gnus-group-entry group)
1385       (error "No such group: %s" group))
1386     (save-excursion
1387       (save-restriction
1388         (widen)
1389         (message-narrow-to-headers)
1390         (let ((gnus-deletable-headers nil))
1391           (message-generate-headers
1392            (if (message-news-p)
1393                message-required-news-headers
1394              message-required-mail-headers)))
1395         (goto-char (point-max))
1396         (if (string-match " " group)
1397             (insert "Gcc: \"" group "\"\n")
1398           (insert "Gcc: " group "\n"))
1399         (widen)))
1400     (gnus-inews-do-gcc)
1401     (when (and (get-buffer gnus-group-buffer)
1402                (gnus-buffer-exists-p (car-safe reply))
1403                (cdr reply))
1404       (set-buffer (car reply))
1405       (gnus-summary-mark-article-as-replied (cdr reply)))
1406     (when winconf
1407       (set-window-configuration winconf))))
1408
1409 (defun gnus-article-mail (yank)
1410   "Send a reply to the address near point.
1411 If YANK is non-nil, include the original article."
1412   (interactive "P")
1413   (let ((address
1414          (buffer-substring
1415           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1416           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1417     (when address
1418       (gnus-msg-mail address)
1419       (when yank
1420         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1421
1422 (defvar nntp-server-type)
1423 (defun gnus-bug ()
1424   "Send a bug report to the Gnus maintainers."
1425   (interactive)
1426   (unless (gnus-alive-p)
1427     (error "Gnus has been shut down"))
1428   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1429     (unless (message-mail-user-agent)
1430       (delete-other-windows)
1431       (when gnus-bug-create-help-buffer
1432         (switch-to-buffer "*Gnus Help Bug*")
1433         (erase-buffer)
1434         (insert gnus-bug-message)
1435         (goto-char (point-min)))
1436       (message-pop-to-buffer "*Gnus Bug*"))
1437     (let ((message-this-is-mail t))
1438       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1439     (when gnus-bug-create-help-buffer
1440       (push `(gnus-bug-kill-buffer) message-send-actions))
1441     (goto-char (point-min))
1442     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1443     (forward-line 1)
1444     (insert (gnus-version) "\n"
1445             (emacs-version) "\n")
1446     (when (and (boundp 'nntp-server-type)
1447                (stringp nntp-server-type))
1448       (insert nntp-server-type))
1449     (insert "\n\n\n\n\n")
1450     (let (text)
1451       (save-excursion
1452         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1453         (erase-buffer)
1454         (gnus-debug)
1455         (setq text (buffer-string)))
1456       (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1457     (goto-char (point-min))
1458     (search-forward "Subject: " nil t)
1459     (message "")))
1460
1461 (defun gnus-bug-kill-buffer ()
1462   (when (get-buffer "*Gnus Help Bug*")
1463     (kill-buffer "*Gnus Help Bug*")))
1464
1465 (defun gnus-summary-yank-message (buffer n)
1466   "Yank the current article into a composed message."
1467   (interactive
1468    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1469          current-prefix-arg))
1470   (gnus-summary-iterate n
1471     (let ((gnus-inhibit-treatment t))
1472       (gnus-summary-select-article))
1473     (save-excursion
1474       (set-buffer buffer)
1475       (message-yank-buffer gnus-article-buffer))))
1476
1477 (defun gnus-debug ()
1478   "Attempts to go through the Gnus source file and report what variables have been changed.
1479 The source file has to be in the Emacs load path."
1480   (interactive)
1481   (let ((files gnus-debug-files)
1482         (point (point))
1483         file expr olist sym)
1484     (gnus-message 4 "Please wait while we snoop your variables...")
1485     (sit-for 0)
1486     ;; Go through all the files looking for non-default values for variables.
1487     (save-excursion
1488       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1489       (while files
1490         (erase-buffer)
1491         (when (and (setq file (locate-library (pop files)))
1492                    (file-exists-p file))
1493           (insert-file-contents file)
1494           (goto-char (point-min))
1495           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1496               (gnus-message 4 "Malformed sources in file %s" file)
1497             (narrow-to-region (point-min) (point))
1498             (goto-char (point-min))
1499             (while (setq expr (ignore-errors (read (current-buffer))))
1500               (ignore-errors
1501                 (and (or (eq (car expr) 'defvar)
1502                          (eq (car expr) 'defcustom))
1503                      (stringp (nth 3 expr))
1504                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1505                      (or (not (boundp (nth 1 expr)))
1506                          (not (equal (eval (nth 2 expr))
1507                                      (symbol-value (nth 1 expr)))))
1508                      (push (nth 1 expr) olist)))))))
1509       (kill-buffer (current-buffer)))
1510     (when (setq olist (nreverse olist))
1511       (insert "------------------ Environment follows ------------------\n\n"))
1512     (while olist
1513       (if (boundp (car olist))
1514           (ignore-errors
1515             (pp `(setq ,(car olist)
1516                        ,(if (or (consp (setq sym (symbol-value (car olist))))
1517                                 (and (symbolp sym)
1518                                      (not (or (eq sym nil)
1519                                               (eq sym t)))))
1520                             (list 'quote (symbol-value (car olist)))
1521                           (symbol-value (car olist))))
1522                 (current-buffer)))
1523         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1524       (setq olist (cdr olist)))
1525     (insert "\n\n")
1526     ;; Remove any control chars - they seem to cause trouble for some
1527     ;; mailers.  (Byte-compiled output from the stuff above.)
1528     (goto-char point)
1529     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1530       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1531                      t t))))
1532
1533 ;;; Treatment of rejected articles.
1534 ;;; Bounced mail.
1535
1536 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1537   "Re-mail the current message.
1538 This only makes sense if the current message is a bounce message that
1539 contains some mail you have written which has been bounced back to
1540 you.
1541 If FETCH, try to fetch the article that this is a reply to, if indeed
1542 this is a reply."
1543   (interactive "P")
1544   (gnus-summary-select-article t)
1545   (set-buffer gnus-original-article-buffer)
1546   (gnus-setup-message 'compose-bounce
1547     (let* ((references (mail-fetch-field "references"))
1548            (parent (and references (gnus-parent-id references))))
1549       (message-bounce)
1550       ;; If there are references, we fetch the article we answered to.
1551       (and fetch parent
1552            (gnus-summary-refer-article parent)
1553            (gnus-summary-show-all-headers)))))
1554
1555 ;;; Gcc handling.
1556
1557 (defun gnus-inews-group-method (group)
1558   (cond
1559    ;; If the group doesn't exist, we assume
1560    ;; it's an archive group...
1561    ((and (null (gnus-get-info group))
1562          (eq (car (gnus-server-to-method gnus-message-archive-method))
1563              (car (gnus-server-to-method (gnus-group-method group)))))
1564     gnus-message-archive-method)
1565    ;; Use the method.
1566    ((gnus-info-method (gnus-get-info group))
1567     (gnus-info-method (gnus-get-info group)))
1568    ;; Find the method.
1569    (t (gnus-server-to-method (gnus-group-method group)))))
1570
1571 ;; Do Gcc handling, which copied the message over to some group.
1572 (defun gnus-inews-do-gcc (&optional gcc)
1573   (interactive)
1574   (save-excursion
1575     (save-restriction
1576       (message-narrow-to-headers)
1577       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1578             (cur (current-buffer))
1579             groups group method group-art
1580             mml-externalize-attachments)
1581         (when gcc
1582           (message-remove-header "gcc")
1583           (widen)
1584           (setq groups (message-unquote-tokens
1585                         (message-tokenize-header gcc " ,")))
1586           ;; Copy the article over to some group(s).
1587           (while (setq group (pop groups))
1588             (unless (gnus-check-server
1589                      (setq method (gnus-inews-group-method group)))
1590               (error "Can't open server %s" (if (stringp method) method
1591                                               (car method))))
1592             (unless (gnus-request-group group nil method)
1593               (gnus-request-create-group group method))
1594             (setq mml-externalize-attachments
1595                   (if (stringp gnus-gcc-externalize-attachments)
1596                       (string-match gnus-gcc-externalize-attachments group)
1597                     gnus-gcc-externalize-attachments))
1598             (save-excursion
1599               (nnheader-set-temp-buffer " *acc*")
1600               (insert-buffer-substring cur)
1601               (message-encode-message-body)
1602               (save-restriction
1603                 (message-narrow-to-headers)
1604                 (let* ((mail-parse-charset message-default-charset)
1605                        (newsgroups-field (save-restriction
1606                                            (message-narrow-to-headers-or-head)
1607                                            (message-fetch-field "Newsgroups")))
1608                        (followup-field (save-restriction
1609                                          (message-narrow-to-headers-or-head)
1610                                          (message-fetch-field "Followup-To")))
1611                        ;; BUG: We really need to get the charset for
1612                        ;; each name in the Newsgroups and Followup-To
1613                        ;; lines to allow crossposting between group
1614                        ;; namess with incompatible character sets.
1615                        ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1616                        (group-field-charset
1617                         (gnus-group-name-charset
1618                          method (or newsgroups-field "")))
1619                        (followup-field-charset
1620                         (gnus-group-name-charset
1621                          method (or followup-field "")))
1622                        (rfc2047-header-encoding-alist
1623                         (append
1624                          (when group-field-charset
1625                            (list (cons "Newsgroups" group-field-charset)))
1626                          (when followup-field-charset
1627                            (list (cons "Followup-To" followup-field-charset)))
1628                          rfc2047-header-encoding-alist)))
1629                   (mail-encode-encoded-word-buffer)))
1630               (goto-char (point-min))
1631               (when (re-search-forward
1632                      (concat "^" (regexp-quote mail-header-separator) "$")
1633                      nil t)
1634                 (replace-match "" t t ))
1635               (when (or (gnus-group-read-only-p group)
1636                         (not (setq group-art
1637                                    (gnus-request-accept-article
1638                                     group method t t))))
1639                 (gnus-message 1 "Couldn't store article in group %s: %s"
1640                               group (gnus-status-message method)))
1641               (when (and group-art
1642                          ;; FIXME: Should gcc-mark-as-read work when
1643                          ;; Gnus is not running?
1644                          (gnus-alive-p)
1645                          (or gnus-gcc-mark-as-read
1646                              (and
1647                               (boundp 'gnus-inews-mark-gcc-as-read)
1648                               (symbol-value 'gnus-inews-mark-gcc-as-read))))
1649                 (gnus-group-mark-article-read group (cdr group-art)))
1650               (kill-buffer (current-buffer)))))))))
1651
1652 (defun gnus-inews-insert-gcc ()
1653   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1654   (save-excursion
1655     (save-restriction
1656       (message-narrow-to-headers)
1657       (let* ((group gnus-outgoing-message-group)
1658              (gcc (cond
1659                    ((functionp group)
1660                     (funcall group))
1661                    ((or (stringp group) (list group))
1662                     group))))
1663         (when gcc
1664           (insert "Gcc: "
1665                   (if (stringp gcc)
1666                       (if (string-match " " gcc)
1667                           (concat "\"" gcc "\"")
1668                         gcc)
1669                     (mapconcat (lambda (group)
1670                                  (if (string-match " " group)
1671                                      (concat "\"" group "\"")
1672                                    group))
1673                                gcc " "))
1674                   "\n"))))))
1675
1676 (defun gnus-inews-insert-archive-gcc (&optional group)
1677   "Insert the Gcc to say where the article is to be archived."
1678   (let* ((var gnus-message-archive-group)
1679          (group (or group gnus-newsgroup-name ""))
1680          (gcc-self-val
1681           (and gnus-newsgroup-name
1682                (not (equal gnus-newsgroup-name ""))
1683                (gnus-group-find-parameter
1684                 gnus-newsgroup-name 'gcc-self)))
1685          result
1686          (groups
1687           (cond
1688            ((null gnus-message-archive-method)
1689             ;; Ignore.
1690             nil)
1691            ((stringp var)
1692             ;; Just a single group.
1693             (list var))
1694            ((null var)
1695             ;; We don't want this.
1696             nil)
1697            ((and (listp var) (stringp (car var)))
1698             ;; A list of groups.
1699             var)
1700            ((functionp var)
1701             ;; A function.
1702             (funcall var group))
1703            (t
1704             ;; An alist of regexps/functions/forms.
1705             (while (and var
1706                         (not
1707                          (setq result
1708                                (cond
1709                                 ((stringp (caar var))
1710                                  ;; Regexp.
1711                                  (when (string-match (caar var) group)
1712                                    (cdar var)))
1713                                 ((functionp (car var))
1714                                  ;; Function.
1715                                  (funcall (car var) group))
1716                                 (t
1717                                  (eval (car var)))))))
1718               (setq var (cdr var)))
1719             result)))
1720          name)
1721     (when (or groups gcc-self-val)
1722       (when (stringp groups)
1723         (setq groups (list groups)))
1724       (save-excursion
1725         (save-restriction
1726           (message-narrow-to-headers)
1727           (goto-char (point-max))
1728           (insert "Gcc: ")
1729           (if gcc-self-val
1730               ;; Use the `gcc-self' param value instead.
1731               (progn
1732                 (insert
1733                  (if (stringp gcc-self-val)
1734                      (if (string-match " " gcc-self-val)
1735                          (concat "\"" gcc-self-val "\"")
1736                        gcc-self-val)
1737                    ;; In nndoc groups, we use the parent group name
1738                    ;; instead of the current group.
1739                    (let ((group (or (gnus-group-find-parameter
1740                                      gnus-newsgroup-name 'parent-group)
1741                                     group)))
1742                      (if (string-match " " group)
1743                          (concat "\"" group "\"")
1744                        group))))
1745                 (if (not (eq gcc-self-val 'none))
1746                     (insert "\n")
1747                   (gnus-delete-line)))
1748             ;; Use the list of groups.
1749             (while (setq name (pop groups))
1750               (let ((str (if (string-match ":" name)
1751                              name
1752                            (gnus-group-prefixed-name
1753                             name gnus-message-archive-method))))
1754                 (insert (if (string-match " " str)
1755                             (concat "\"" str "\"")
1756                           str)))
1757               (when groups
1758                 (insert " ")))
1759             (insert "\n")))))))
1760
1761 (defun gnus-mailing-list-followup-to ()
1762   "Look at the headers in the current buffer and return a Mail-Followup-To address."
1763   (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1764         (list-post (gnus-fetch-original-field "list-post")))
1765     (when (and list-post
1766                (string-match "mailto:\\([^>]+\\)" list-post))
1767       (setq list-post (match-string 1 list-post)))
1768     (or list-post
1769         x-been-there)))
1770
1771 ;;; Posting styles.
1772
1773 (defun gnus-configure-posting-styles (&optional group-name)
1774   "Configure posting styles according to `gnus-posting-styles'."
1775   (unless gnus-inhibit-posting-styles
1776     (let ((group (or group-name gnus-newsgroup-name ""))
1777           (styles gnus-posting-styles)
1778           style match attribute value v results
1779           filep name address element)
1780       ;; If the group has a posting-style parameter, add it at the end with a
1781       ;; regexp matching everything, to be sure it takes precedence over all
1782       ;; the others.
1783       (when gnus-newsgroup-name
1784         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1785           (when tmp-style
1786             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1787       ;; Go through all styles and look for matches.
1788       (dolist (style styles)
1789         (setq match (pop style))
1790         (goto-char (point-min))
1791         (when (cond
1792                ((stringp match)
1793                 ;; Regexp string match on the group name.
1794                 (string-match match group))
1795                ((eq match 'header)
1796                 ;; Obsolete format of header match.
1797                 (and (gnus-buffer-live-p gnus-article-copy)
1798                      (with-current-buffer gnus-article-copy
1799                        (let ((header (message-fetch-field (pop style))))
1800                          (and header
1801                               (string-match (pop style) header))))))
1802                ((or (symbolp match)
1803                     (functionp match))
1804                 (cond
1805                  ((functionp match)
1806                   ;; Function to be called.
1807                   (funcall match))
1808                  ((boundp match)
1809                   ;; Variable to be checked.
1810                   (symbol-value match))))
1811                ((listp match)
1812                 (cond
1813                  ((eq (car match) 'header)
1814                   ;; New format of header match.
1815                   (and (gnus-buffer-live-p gnus-article-copy)
1816                        (with-current-buffer gnus-article-copy
1817                          (let ((header (message-fetch-field (nth 1 match))))
1818                            (and header
1819                                 (string-match (nth 2 match) header))))))
1820                  (t
1821                   ;; This is a form to be evaled.
1822                   (eval match)))))
1823           ;; We have a match, so we set the variables.
1824           (dolist (attribute style)
1825             (setq element (pop attribute)
1826                   filep nil)
1827             (setq value
1828                   (cond
1829                    ((eq (car attribute) :file)
1830                     (setq filep t)
1831                     (cadr attribute))
1832                    ((eq (car attribute) :value)
1833                     (cadr attribute))
1834                    (t
1835                     (car attribute))))
1836             ;; We get the value.
1837             (setq v
1838                   (cond
1839                    ((stringp value)
1840                     value)
1841                    ((or (symbolp value)
1842                         (functionp value))
1843                     (cond ((functionp value)
1844                            (funcall value))
1845                           ((boundp value)
1846                            (symbol-value value))))
1847                    ((listp value)
1848                     (eval value))))
1849             ;; Translate obsolescent value.
1850             (cond
1851              ((eq element 'signature-file)
1852               (setq element 'signature
1853                     filep t))
1854              ((eq element 'x-face-file)
1855               (setq element 'x-face
1856                     filep t)))
1857             ;; Get the contents of file elems.
1858             (when (and filep v)
1859               (setq v (with-temp-buffer
1860                         (insert-file-contents v)
1861                         (goto-char (point-max))
1862                         (while (bolp)
1863                           (delete-char -1))
1864                         (buffer-string))))
1865             (setq results (delq (assoc element results) results))
1866             (push (cons element v) results))))
1867       ;; Now we have all the styles, so we insert them.
1868       (setq name (assq 'name results)
1869             address (assq 'address results))
1870       (setq results (delq name (delq address results)))
1871       (gnus-make-local-hook 'message-setup-hook)
1872       (setq results (sort results (lambda (x y)
1873                                     (string-lessp (car x) (car y)))))
1874       (dolist (result results)
1875         (add-hook 'message-setup-hook
1876                   (cond
1877                    ((eq 'eval (car result))
1878                     'ignore)
1879                    ((eq 'body (car result))
1880                     `(lambda ()
1881                        (save-excursion
1882                          (message-goto-body)
1883                          (insert ,(cdr result)))))
1884                    ((eq 'signature (car result))
1885                     (set (make-local-variable 'message-signature) nil)
1886                     (set (make-local-variable 'message-signature-file) nil)
1887                     (if (not (cdr result))
1888                         'ignore
1889                       `(lambda ()
1890                          (save-excursion
1891                            (let ((message-signature ,(cdr result)))
1892                              (when message-signature
1893                                (message-insert-signature)))))))
1894                    (t
1895                     (let ((header
1896                            (if (symbolp (car result))
1897                                (capitalize (symbol-name (car result)))
1898                              (car result))))
1899                       `(lambda ()
1900                          (save-excursion
1901                            (message-remove-header ,header)
1902                            (let ((value ,(cdr result)))
1903                              (when value
1904                                (message-goto-eoh)
1905                                (insert ,header ": " value)
1906                                (unless (bolp)
1907                                  (insert "\n")))))))))
1908                   nil 'local))
1909       (when (or name address)
1910         (add-hook 'message-setup-hook
1911                   `(lambda ()
1912                      (set (make-local-variable 'user-mail-address)
1913                           ,(or (cdr address) user-mail-address))
1914                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1915                            (user-mail-address
1916                             ,(or (cdr address) user-mail-address)))
1917                        (save-excursion
1918                          (message-remove-header "From")
1919                          (message-goto-eoh)
1920                          (insert "From: " (message-make-from) "\n"))))
1921                   nil 'local)))))
1922
1923 ;;; Allow redefinition of functions.
1924
1925 (gnus-ems-redefine)
1926
1927 (provide 'gnus-msg)
1928
1929 ;;; gnus-msg.el ends here