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