gnus-msg.el (gnus-msg-mail): Ensure that gnus-newsgroup-name is a string so that...
[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
482                                 return-action)
483   "Start editing a mail message to be sent.
484 Like `message-mail', but with Gnus paraphernalia, particularly the
485 Gcc: header for archiving purposes.
486 If Gnus isn't running, a plain `message-mail' setup is used
487 instead."
488   (interactive)
489   (if (not (gnus-alive-p))
490       (message-mail to subject other-headers continue
491                     nil yank-action send-actions return-action)
492     (let ((buf (current-buffer))
493           (gnus-newsgroup-name (or gnus-newsgroup-name ""))
494           mail-buf)
495       (gnus-setup-message 'message
496         (message-mail to subject other-headers continue
497                       nil yank-action send-actions return-action))
498       (when switch-action
499         (setq mail-buf (current-buffer))
500         (switch-to-buffer buf)
501         (apply switch-action mail-buf nil))
502       ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
503       t)))
504
505 ;;;###autoload
506 (defun gnus-button-mailto (address)
507   "Mail to ADDRESS."
508   (set-buffer (gnus-copy-article-buffer))
509   (gnus-setup-message 'message
510     (message-reply address)))
511
512 ;;;###autoload
513 (defun gnus-button-reply (&optional to-address wide)
514   "Like `message-reply'."
515   (interactive)
516   (gnus-setup-message 'message
517     (message-reply to-address wide)))
518
519 ;;;###autoload
520 (define-mail-user-agent 'gnus-user-agent
521   'gnus-msg-mail 'message-send-and-exit
522   'message-kill-buffer 'message-send-hook)
523
524 (defun gnus-setup-posting-charset (group)
525   (let ((alist gnus-group-posting-charset-alist)
526         (group (or group ""))
527         elem)
528     (when group
529       (catch 'found
530         (while (setq elem (pop alist))
531           (when (or (and (stringp (car elem))
532                          (string-match (car elem) group))
533                     (and (functionp (car elem))
534                          (funcall (car elem) group))
535                     (and (symbolp (car elem))
536                          (symbol-value (car elem))))
537             (throw 'found (cons (cadr elem) (caddr elem)))))))))
538
539 (defun gnus-inews-add-send-actions (winconf buffer article
540                                             &optional config yanked
541                                             winconf-name)
542   (gnus-make-local-hook 'message-sent-hook)
543   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
544                                  'gnus-inews-do-gcc) nil t)
545   (when gnus-agent
546     (gnus-make-local-hook 'message-header-hook)
547     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
548   (setq message-post-method
549         `(lambda (&optional arg)
550            (gnus-post-method arg ,gnus-newsgroup-name)))
551   (message-add-action
552    `(progn
553       (setq gnus-current-window-configuration ',winconf-name)
554       (when (gnus-buffer-exists-p ,buffer)
555         (set-window-configuration ,winconf)))
556    'exit 'postpone 'kill)
557   (let ((to-be-marked (cond
558                        (yanked
559                         (mapcar
560                          (lambda (x) (if (listp x) (car x) x)) yanked))
561                        (article (if (listp article) article (list article)))
562                        (t nil))))
563     (message-add-action
564      `(when (gnus-buffer-exists-p ,buffer)
565         (with-current-buffer ,buffer
566           ,(when to-be-marked
567              (if (eq config 'forward)
568                  `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
569                `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
570      'send)))
571
572 (put 'gnus-setup-message 'lisp-indent-function 1)
573 (put 'gnus-setup-message 'edebug-form-spec '(form body))
574
575 ;;; Post news commands of Gnus group mode and summary mode
576
577 (defun gnus-group-mail (&optional arg)
578   "Start composing a mail.
579 If ARG, use the group under the point to find a posting style.
580 If ARG is 1, prompt for a group name to find the posting style."
581   (interactive "P")
582   ;; We can't `let' gnus-newsgroup-name here, since that leads
583   ;; to local variables leaking.
584   (let ((group gnus-newsgroup-name)
585         ;; make sure last viewed article doesn't affect posting styles:
586         (gnus-article-copy)
587         (buffer (current-buffer)))
588     (unwind-protect
589         (progn
590           (setq gnus-newsgroup-name
591                 (if arg
592                     (if (= 1 (prefix-numeric-value arg))
593                         (gnus-group-completing-read
594                          "Use posting style of group"
595                          nil (gnus-read-active-file-p))
596                       (gnus-group-group-name))
597                   ""))
598           ;; #### see comment in gnus-setup-message -- drv
599           (gnus-setup-message 'message (message-mail)))
600       (with-current-buffer buffer
601         (setq gnus-newsgroup-name group)))))
602
603 (defun gnus-group-news (&optional arg)
604   "Start composing a news.
605 If ARG, post to group under point.
606 If ARG is 1, prompt for group name to post to.
607
608 This function prepares a news even when using mail groups.  This is useful
609 for posting messages to mail groups without actually sending them over the
610 network.  The corresponding back end must have a 'request-post method."
611   (interactive "P")
612   ;; We can't `let' gnus-newsgroup-name here, since that leads
613   ;; to local variables leaking.
614   (let ((group gnus-newsgroup-name)
615         ;; make sure last viewed article doesn't affect posting styles:
616         (gnus-article-copy)
617         (buffer (current-buffer)))
618     (unwind-protect
619         (progn
620           (setq gnus-newsgroup-name
621                 (if arg
622                     (if (= 1 (prefix-numeric-value arg))
623                         (gnus-group-completing-read "Use group"
624                                                     nil
625                                                     (gnus-read-active-file-p))
626                       (gnus-group-group-name))
627                   ""))
628           ;; #### see comment in gnus-setup-message -- drv
629           (gnus-setup-message 'message
630             (message-news (gnus-group-real-name gnus-newsgroup-name))))
631       (with-current-buffer buffer
632         (setq gnus-newsgroup-name group)))))
633
634 (defun gnus-group-post-news (&optional arg)
635   "Start composing a message (a news by default).
636 If ARG, post to group under point.  If ARG is 1, prompt for group name.
637 Depending on the selected group, the message might be either a mail or
638 a news."
639   (interactive "P")
640   ;; Bind this variable here to make message mode hooks work ok.
641   (let ((gnus-newsgroup-name
642          (if arg
643              (if (= 1 (prefix-numeric-value arg))
644                  (gnus-group-completing-read "Newsgroup" nil
645                                              (gnus-read-active-file-p))
646                (or (gnus-group-group-name) ""))
647            ""))
648         ;; make sure last viewed article doesn't affect posting styles:
649         (gnus-article-copy))
650     (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
651                     (string= gnus-newsgroup-name ""))))
652
653 (defun gnus-summary-mail-other-window (&optional arg)
654   "Start composing a mail in another window.
655 Use the posting of the current group by default.
656 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
657 posting style."
658   (interactive "P")
659   ;; We can't `let' gnus-newsgroup-name here, since that leads
660   ;; to local variables leaking.
661   (let ((group gnus-newsgroup-name)
662         ;; make sure last viewed article doesn't affect posting styles:
663         (gnus-article-copy)
664         (buffer (current-buffer)))
665     (unwind-protect
666         (progn
667           (setq gnus-newsgroup-name
668                 (if arg
669                     (if (= 1 (prefix-numeric-value arg))
670                         (gnus-group-completing-read "Use group"
671                                                     nil
672                                                     (gnus-read-active-file-p))
673                       "")
674                   gnus-newsgroup-name))
675           ;; #### see comment in gnus-setup-message -- drv
676           (gnus-setup-message 'message (message-mail)))
677       (with-current-buffer buffer
678         (setq gnus-newsgroup-name group)))))
679
680 (defun gnus-summary-news-other-window (&optional arg)
681   "Start composing a news in another window.
682 Post to the current group by default.
683 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
684
685 This function prepares a news even when using mail groups.  This is useful
686 for posting messages to mail groups without actually sending them over the
687 network.  The corresponding back end must have a 'request-post method."
688   (interactive "P")
689   ;; We can't `let' gnus-newsgroup-name here, since that leads
690   ;; to local variables leaking.
691   (let ((group gnus-newsgroup-name)
692         ;; make sure last viewed article doesn't affect posting styles:
693         (gnus-article-copy)
694         (buffer (current-buffer)))
695     (unwind-protect
696         (progn
697           (setq gnus-newsgroup-name
698                 (if arg
699                     (if (= 1 (prefix-numeric-value arg))
700                         (gnus-group-completing-read "Use group"
701                                                     nil
702                                                     (gnus-read-active-file-p))
703                       "")
704                   gnus-newsgroup-name))
705           ;; #### see comment in gnus-setup-message -- drv
706           (gnus-setup-message 'message
707             (progn
708               (message-news (gnus-group-real-name gnus-newsgroup-name))
709               (set (make-local-variable 'gnus-discouraged-post-methods)
710                    (remove
711                     (car (gnus-find-method-for-group gnus-newsgroup-name))
712                     gnus-discouraged-post-methods)))))
713       (with-current-buffer buffer
714         (setq gnus-newsgroup-name group)))))
715
716 (defun gnus-summary-post-news (&optional arg)
717   "Start composing a message.  Post to the current group by default.
718 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
719 Depending on the selected group, the message might be either a mail or
720 a news."
721   (interactive "P")
722   ;; Bind this variable here to make message mode hooks work ok.
723   (let ((gnus-newsgroup-name
724          (if arg
725              (if (= 1 (prefix-numeric-value arg))
726                  (gnus-group-completing-read "Newsgroup" nil
727                                              (gnus-read-active-file-p))
728                "")
729            gnus-newsgroup-name))
730         ;; make sure last viewed article doesn't affect posting styles:
731         (gnus-article-copy))
732     (gnus-post-news 'post gnus-newsgroup-name)))
733
734
735 (defun gnus-summary-followup (yank &optional force-news)
736   "Compose a followup to an article.
737 If prefix argument YANK is non-nil, the original article is yanked
738 automatically.
739 YANK is a list of elements, where the car of each element is the
740 article number, and the cdr is the string to be yanked."
741   (interactive
742    (list (and current-prefix-arg
743               (gnus-summary-work-articles 1))))
744   (when yank
745     (gnus-summary-goto-subject
746      (if (listp (car yank))
747          (caar yank)
748        (car yank))))
749   (save-window-excursion
750     (gnus-summary-select-article))
751   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
752         (gnus-newsgroup-name gnus-newsgroup-name))
753     ;; Send a followup.
754     (gnus-post-news nil gnus-newsgroup-name
755                     headers gnus-article-buffer
756                     yank nil force-news)
757     (gnus-summary-handle-replysign)))
758
759 (defun gnus-summary-followup-with-original (n &optional force-news)
760   "Compose a followup to an article and include the original article.
761 The text in the region will be yanked.  If the region isn't
762 active, the entire article will be yanked."
763   (interactive "P")
764   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
765
766 (defun gnus-summary-followup-to-mail (&optional arg)
767   "Followup to the current mail message via news."
768   (interactive
769    (list (and current-prefix-arg
770               (gnus-summary-work-articles 1))))
771   (gnus-summary-followup arg t))
772
773 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
774   "Followup to the current mail message via news."
775   (interactive "P")
776   (gnus-summary-followup (gnus-summary-work-articles arg) t))
777
778 (defun gnus-inews-yank-articles (articles)
779   (let (beg article yank-string)
780     (message-goto-body)
781     (while (setq article (pop articles))
782       (when (listp article)
783         (setq yank-string (nth 1 article)
784               article (nth 0 article)))
785       (save-window-excursion
786         (set-buffer gnus-summary-buffer)
787         (gnus-summary-select-article nil nil nil article)
788         (gnus-summary-remove-process-mark article))
789       (gnus-copy-article-buffer nil yank-string)
790       (let ((message-reply-buffer gnus-article-copy)
791             (message-reply-headers
792              ;; The headers are decoded.
793              (with-current-buffer gnus-article-copy
794                (save-restriction
795                  (nnheader-narrow-to-headers)
796                  (nnheader-parse-naked-head)))))
797         (message-yank-original)
798         (message-exchange-point-and-mark)
799         (setq beg (or beg (mark t))))
800       (when articles
801         (insert "\n")))
802     (push-mark)
803     (goto-char beg)))
804
805 (defun gnus-summary-cancel-article (&optional n symp)
806   "Cancel an article you posted.
807 Uses the process-prefix convention.  If given the symbolic
808 prefix `a', cancel using the standard posting method; if not
809 post using the current select method."
810   (interactive (gnus-interactive "P\ny"))
811   (let ((message-post-method
812          `(lambda (arg)
813             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
814     (dolist (article (gnus-summary-work-articles n))
815       (when (gnus-summary-select-article t nil nil article)
816         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
817                 (message-cancel-news))
818           (gnus-summary-mark-as-read article gnus-canceled-mark)
819           (gnus-cache-remove-article 1))
820         (gnus-article-hide-headers-if-wanted))
821       (gnus-summary-remove-process-mark article))))
822
823 (defun gnus-summary-supersede-article ()
824   "Compose an article that will supersede a previous article.
825 This is done simply by taking the old article and adding a Supersedes
826 header line with the old Message-ID."
827   (interactive)
828   (let ((article (gnus-summary-article-number))
829         (mail-parse-charset gnus-newsgroup-charset))
830     (gnus-setup-message 'reply-yank
831       (gnus-summary-select-article t)
832       (set-buffer gnus-original-article-buffer)
833       (message-supersede)
834       (push
835        `((lambda ()
836            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
837              (with-current-buffer ,gnus-summary-buffer
838                (gnus-cache-possibly-remove-article ,article nil nil nil t)
839                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
840        message-send-actions)
841       ;; Add Gcc header.
842       (gnus-inews-insert-gcc))))
843
844 \f
845
846 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
847   ;; make a copy of the article buffer with all text properties removed
848   ;; this copy is in the buffer gnus-article-copy.
849   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
850   ;; this buffer should be passed to all mail/news reply/post routines.
851   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
852   (with-current-buffer gnus-article-copy
853     (mm-enable-multibyte))
854   (let ((article-buffer (or article-buffer gnus-article-buffer))
855         end beg)
856     (if (not (and (get-buffer article-buffer)
857                   (gnus-buffer-exists-p article-buffer)))
858         (error "Can't find any article buffer")
859       (with-current-buffer article-buffer
860         (let ((gnus-newsgroup-charset (or gnus-article-charset
861                                           gnus-newsgroup-charset))
862               (gnus-newsgroup-ignored-charsets
863                (or gnus-article-ignored-charsets
864                    gnus-newsgroup-ignored-charsets)))
865           (save-restriction
866             ;; Copy over the (displayed) article buffer, delete
867             ;; hidden text and remove text properties.
868             (widen)
869             (copy-to-buffer gnus-article-copy (point-min) (point-max))
870             (set-buffer gnus-article-copy)
871             (when yank-string
872               (message-goto-body)
873               (delete-region (point) (point-max))
874               (insert yank-string))
875             (gnus-article-delete-text-of-type 'annotation)
876             (gnus-article-delete-text-of-type 'multipart)
877             (gnus-remove-text-with-property 'gnus-prev)
878             (gnus-remove-text-with-property 'gnus-next)
879             (gnus-remove-text-with-property 'gnus-decoration)
880             (insert
881              (prog1
882                  (buffer-substring-no-properties (point-min) (point-max))
883                (erase-buffer)))
884             ;; Find the original headers.
885             (set-buffer gnus-original-article-buffer)
886             (goto-char (point-min))
887             (while (looking-at message-unix-mail-delimiter)
888               (forward-line 1))
889             (let ((mail-header-separator ""))
890               (setq beg (point)
891                     end (or (message-goto-body)
892                             ;; There may be just a header.
893                             (point-max))))
894             ;; Delete the headers from the displayed articles.
895             (set-buffer gnus-article-copy)
896             (let ((mail-header-separator ""))
897               (delete-region (goto-char (point-min))
898                              (or (message-goto-body) (point-max))))
899             ;; Insert the original article headers.
900             (insert-buffer-substring gnus-original-article-buffer beg end)
901             ;; Decode charsets.
902             (let ((gnus-article-decode-hook
903                    (delq 'article-decode-charset
904                          (copy-sequence gnus-article-decode-hook)))
905                   (rfc2047-quote-decoded-words-containing-tspecials t))
906               (run-hooks 'gnus-article-decode-hook)))))
907       gnus-article-copy)))
908
909 (defun gnus-post-news (post &optional group header article-buffer yank subject
910                             force-news)
911   (when article-buffer
912     (gnus-copy-article-buffer))
913   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
914         (gnus-article-yanked-articles yank)
915         (add-to-list gnus-add-to-list))
916     (gnus-setup-message (cond (yank 'reply-yank)
917                               (article-buffer 'reply)
918                               (t 'message))
919       (let* ((group (or group gnus-newsgroup-name))
920              (charset (gnus-group-name-charset nil group))
921              (pgroup group)
922              to-address to-group mailing-list to-list
923              newsgroup-p)
924         (when group
925           (setq to-address (gnus-parameter-to-address group)
926                 to-group (gnus-group-find-parameter group 'to-group)
927                 to-list (gnus-parameter-to-list group)
928                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
929                 mailing-list (when gnus-mailing-list-groups
930                                (string-match gnus-mailing-list-groups group))
931                 group (gnus-group-name-decode (gnus-group-real-name group)
932                                               charset)))
933         (if (or (and to-group
934                      (gnus-news-group-p to-group))
935                 newsgroup-p
936                 force-news
937                 (and (gnus-news-group-p
938                       (or pgroup gnus-newsgroup-name)
939                       (or header gnus-current-article))
940                      (not mailing-list)
941                      (not to-list)
942                      (not to-address)))
943             ;; This is news.
944             (if post
945                 (message-news
946                  (or to-group
947                      (and (not (gnus-virtual-group-p pgroup)) group)))
948               (set-buffer gnus-article-copy)
949               (gnus-msg-treat-broken-reply-to)
950               (message-followup (if (or newsgroup-p force-news)
951                                     (if (save-restriction
952                                           (article-narrow-to-head)
953                                           (message-fetch-field "newsgroups"))
954                                         nil
955                                       "")
956                                   to-group)))
957           ;; The is mail.
958           (if post
959               (progn
960                 (message-mail (or to-address to-list))
961                 ;; Arrange for mail groups that have no `to-address' to
962                 ;; get that when the user sends off the mail.
963                 (when (and (not to-list)
964                            (not to-address)
965                            add-to-list)
966                   (push (list 'gnus-inews-add-to-address pgroup)
967                         message-send-actions)))
968             (set-buffer gnus-article-copy)
969             (gnus-msg-treat-broken-reply-to)
970             (message-wide-reply to-address)))
971         (when yank
972           (gnus-inews-yank-articles yank))))))
973
974 (defun gnus-msg-treat-broken-reply-to (&optional force)
975   "Remove the Reply-to header if broken-reply-to."
976   (when (or force
977             (gnus-group-find-parameter
978              gnus-newsgroup-name 'broken-reply-to))
979     (save-restriction
980       (message-narrow-to-head)
981       (message-remove-header "reply-to"))))
982
983 (defun gnus-post-method (arg group &optional silent)
984   "Return the posting method based on GROUP and ARG.
985 If SILENT, don't prompt the user."
986   (let ((gnus-post-method (or (gnus-parameter-post-method group)
987                               gnus-post-method))
988         (group-method (gnus-find-method-for-group group)))
989     (cond
990      ;; If the group-method is nil (which shouldn't happen) we use
991      ;; the default method.
992      ((null group-method)
993       (or (and (listp gnus-post-method) ;If not current/native/nil
994                (not (listp (car gnus-post-method))) ; and not a list of methods
995                gnus-post-method)        ;then use it.
996           gnus-select-method
997           message-post-method))
998      ;; We want the inverse of the default
999      ((and arg (not (eq arg 0)))
1000       (if (eq gnus-post-method 'current)
1001           gnus-select-method
1002         group-method))
1003      ;; We query the user for a post method.
1004      ((or arg
1005           (and (listp gnus-post-method)
1006                (listp (car gnus-post-method))))
1007       (let* ((methods
1008               ;; Collect all methods we know about.
1009               (append
1010                (when (listp gnus-post-method)
1011                  (if (listp (car gnus-post-method))
1012                      gnus-post-method
1013                    (list gnus-post-method)))
1014                gnus-secondary-select-methods
1015                (mapcar 'cdr gnus-server-alist)
1016                (mapcar 'car gnus-opened-servers)
1017                (list gnus-select-method)
1018                (list group-method)))
1019              method-alist post-methods method)
1020         ;; Weed out all mail methods.
1021         (while methods
1022           (setq method (gnus-server-get-method "" (pop methods)))
1023           (when (and (or (gnus-method-option-p method 'post)
1024                          (gnus-method-option-p method 'post-mail))
1025                      (not (member method post-methods)))
1026             (push method post-methods)))
1027         ;; Create a name-method alist.
1028         (setq method-alist
1029               (mapcar
1030                (lambda (m)
1031                  (if (equal (cadr m) "")
1032                      (list (symbol-name (car m)) m)
1033                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1034                post-methods))
1035         ;; Query the user.
1036         (cadr
1037          (assoc
1038           (setq gnus-last-posting-server
1039                 (if (and silent
1040                          gnus-last-posting-server)
1041                     ;; Just use the last value.
1042                     gnus-last-posting-server
1043                   (gnus-completing-read
1044                    "Posting method" (mapcar 'car method-alist) t
1045                    (cons (or gnus-last-posting-server "") 0))))
1046           method-alist))))
1047      ;; Override normal method.
1048      ((and (eq gnus-post-method 'current)
1049            (not (memq (car group-method) gnus-discouraged-post-methods))
1050            (gnus-get-function group-method 'request-post t))
1051       (assert (not arg))
1052       group-method)
1053      ;; Use gnus-post-method.
1054      ((listp gnus-post-method)          ;A method...
1055       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1056       gnus-post-method)
1057      ;; Use the normal select method (nil or native).
1058      (t gnus-select-method))))
1059
1060 \f
1061
1062 (defun gnus-extended-version ()
1063   "Stringified Gnus version and Emacs version.
1064 See the variable `gnus-user-agent'."
1065   (interactive)
1066   (if (stringp gnus-user-agent)
1067       gnus-user-agent
1068     ;; `gnus-user-agent' is a list:
1069     (let* ((float-output-format nil)
1070            (gnus-v
1071             (when (memq 'gnus gnus-user-agent)
1072               (concat "Gnus/"
1073                       (prin1-to-string (gnus-continuum-version gnus-version) t)
1074                       " (" gnus-version ")")))
1075            (emacs-v (gnus-emacs-version)))
1076       (concat gnus-v (when (and gnus-v emacs-v) " ")
1077               emacs-v))))
1078
1079 \f
1080 ;;;
1081 ;;; Gnus Mail Functions
1082 ;;;
1083
1084 ;;; Mail reply commands of Gnus summary mode
1085
1086 (defun gnus-summary-reply (&optional yank wide very-wide)
1087   "Start composing a mail reply to the current message.
1088 If prefix argument YANK is non-nil, the original article is yanked
1089 automatically.
1090 If WIDE, make a wide reply.
1091 If VERY-WIDE, make a very wide reply."
1092   (interactive
1093    (list (and current-prefix-arg
1094               (gnus-summary-work-articles 1))))
1095   ;; Allow user to require confirmation before replying by mail to the
1096   ;; author of a news article (or mail message).
1097   (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1098                      gnus-confirm-treat-mail-like-news))
1099             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1100                         (string-match gnus-confirm-mail-reply-to-news
1101                                       gnus-newsgroup-name))
1102                        ((functionp gnus-confirm-mail-reply-to-news)
1103                         (funcall gnus-confirm-mail-reply-to-news
1104                                  gnus-newsgroup-name))
1105                        (t gnus-confirm-mail-reply-to-news)))
1106             (if (or wide very-wide)
1107                 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1108                   ;; wide replies.
1109               (y-or-n-p "Really reply by mail to article author? ")))
1110     (let* ((article
1111             (if (listp (car yank))
1112                 (caar yank)
1113               (car yank)))
1114            (gnus-article-reply (or article (gnus-summary-article-number)))
1115            (gnus-article-yanked-articles yank)
1116            (headers ""))
1117       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1118       (when yank
1119         (gnus-summary-goto-subject article))
1120       (gnus-setup-message (if yank 'reply-yank 'reply)
1121         (if (not very-wide)
1122             (gnus-summary-select-article)
1123           (dolist (article very-wide)
1124             (gnus-summary-select-article nil nil nil article)
1125             (with-current-buffer (gnus-copy-article-buffer)
1126               (gnus-msg-treat-broken-reply-to)
1127               (save-restriction
1128                 (message-narrow-to-head)
1129                 (setq headers (concat headers (buffer-string)))))))
1130         (set-buffer (gnus-copy-article-buffer))
1131         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1132         (save-restriction
1133           (message-narrow-to-head)
1134           (when very-wide
1135             (erase-buffer)
1136             (insert headers))
1137           (goto-char (point-max)))
1138         (mml-quote-region (point) (point-max))
1139         (message-reply nil wide)
1140         (when yank
1141           (gnus-inews-yank-articles yank))
1142         (gnus-summary-handle-replysign)))))
1143
1144 (defun gnus-summary-handle-replysign ()
1145   "Check the various replysign variables and take action accordingly."
1146   (when (or gnus-message-replysign gnus-message-replyencrypt)
1147     (let (signed encrypted)
1148       (with-current-buffer gnus-article-buffer
1149         (setq signed (memq 'signed gnus-article-wash-types))
1150         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1151       (cond ((and gnus-message-replyencrypt encrypted)
1152              (mml-secure-message mml-default-encrypt-method
1153                                  (if gnus-message-replysignencrypted
1154                                      'signencrypt
1155                                    'encrypt)))
1156             ((and gnus-message-replysign signed)
1157              (mml-secure-message mml-default-sign-method 'sign))))))
1158
1159 (defun gnus-summary-reply-with-original (n &optional wide)
1160   "Start composing a reply mail to the current message.
1161 The original article will be yanked."
1162   (interactive "P")
1163   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1164
1165 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1166   "Start composing a reply mail to the current message.
1167 The reply goes only to the mailing list.
1168 The original article will be yanked."
1169   (interactive "P")
1170   (let ((message-reply-to-function
1171          (lambda nil
1172            `((To . ,(gnus-mailing-list-followup-to))))))
1173     (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1174
1175 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1176   "Like `gnus-summary-reply' except removing reply-to field.
1177 If prefix argument YANK is non-nil, the original article is yanked
1178 automatically.
1179 If WIDE, make a wide reply.
1180 If VERY-WIDE, make a very wide reply."
1181   (interactive
1182    (list (and current-prefix-arg
1183               (gnus-summary-work-articles 1))))
1184   (let ((gnus-msg-force-broken-reply-to t))
1185     (gnus-summary-reply yank wide very-wide)))
1186
1187 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1188   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1189 The original article will be yanked."
1190   (interactive "P")
1191   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1192
1193 (defun gnus-summary-wide-reply (&optional yank)
1194   "Start composing a wide reply mail to the current message.
1195 If prefix argument YANK is non-nil, the original article is yanked
1196 automatically."
1197   (interactive
1198    (list (and current-prefix-arg
1199               (gnus-summary-work-articles 1))))
1200   (gnus-summary-reply yank t))
1201
1202 (defun gnus-summary-wide-reply-with-original (n)
1203   "Start composing a wide reply mail to the current message.
1204 The original article will be yanked.
1205 Uses the process/prefix convention."
1206   (interactive "P")
1207   (gnus-summary-reply-with-original n t))
1208
1209 (defun gnus-summary-very-wide-reply (&optional yank)
1210   "Start composing a very wide reply mail to the current message.
1211 If prefix argument YANK is non-nil, the original article is yanked
1212 automatically."
1213   (interactive
1214    (list (and current-prefix-arg
1215               (gnus-summary-work-articles 1))))
1216   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1217
1218 (defun gnus-summary-very-wide-reply-with-original (n)
1219   "Start composing a very wide reply mail to the current message.
1220 The original article will be yanked."
1221   (interactive "P")
1222   (gnus-summary-reply
1223    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1224
1225 (defun gnus-summary-mail-forward (&optional arg post)
1226   "Forward the current message(s) to another user.
1227 If process marks exist, forward all marked messages;
1228 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1229 if ARG is 1, decode the message and forward directly inline;
1230 if ARG is 2, forward message as an rfc822 MIME section;
1231 if ARG is 3, decode message and forward as an rfc822 MIME section;
1232 if ARG is 4, forward message directly inline;
1233 otherwise, use flipped `message-forward-as-mime'.
1234 If POST, post instead of mail.
1235 For the \"inline\" alternatives, also see the variable
1236 `message-forward-ignored-headers'."
1237   (interactive "P")
1238   (if (cdr (gnus-summary-work-articles nil))
1239       ;; Process marks are given.
1240       (gnus-uu-digest-mail-forward nil post)
1241     ;; No process marks.
1242     (let ((message-forward-as-mime message-forward-as-mime)
1243           (message-forward-show-mml message-forward-show-mml))
1244       (cond
1245        ((null arg))
1246        ((eq arg 1)
1247         (setq message-forward-as-mime nil
1248               message-forward-show-mml t))
1249        ((eq arg 2)
1250         (setq message-forward-as-mime t
1251               message-forward-show-mml nil))
1252        ((eq arg 3)
1253         (setq message-forward-as-mime t
1254               message-forward-show-mml t))
1255        ((eq arg 4)
1256         (setq message-forward-as-mime nil
1257               message-forward-show-mml nil))
1258        (t
1259         (setq message-forward-as-mime (not message-forward-as-mime))))
1260       (let* ((gnus-article-reply (gnus-summary-article-number))
1261              (gnus-article-yanked-articles (list gnus-article-reply)))
1262         (gnus-setup-message 'forward
1263           (gnus-summary-select-article)
1264           (let ((mail-parse-charset
1265                  (or (and (gnus-buffer-live-p gnus-article-buffer)
1266                           (with-current-buffer gnus-article-buffer
1267                             gnus-article-charset))
1268                      gnus-newsgroup-charset))
1269                 (mail-parse-ignored-charsets
1270                  gnus-newsgroup-ignored-charsets))
1271             (set-buffer gnus-original-article-buffer)
1272             (message-forward post)))))))
1273
1274 (defun gnus-summary-resend-message (address n)
1275   "Resend the current article to ADDRESS."
1276   (interactive
1277    (list (message-read-from-minibuffer
1278           "Resend message(s) to: "
1279           (when (and gnus-summary-resend-default-address
1280                      (gnus-buffer-live-p gnus-original-article-buffer))
1281             ;; If some other article is currently selected, the
1282             ;; initial-contents is wrong. Whatever, it is just the
1283             ;; initial-contents.
1284             (with-current-buffer gnus-original-article-buffer
1285               (nnmail-fetch-field "to"))))
1286          current-prefix-arg))
1287   (dolist (article (gnus-summary-work-articles n))
1288     (gnus-summary-select-article nil nil nil article)
1289     (with-current-buffer gnus-original-article-buffer
1290       (let ((gnus-gcc-externalize-attachments nil))
1291         (message-resend address)))
1292     (gnus-summary-mark-article-as-forwarded article)))
1293
1294 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1295 (defun gnus-summary-resend-message-edit ()
1296   "Resend an article that has already been sent.
1297 A new buffer will be created to allow the user to modify body and
1298 contents of the message, and then, everything will happen as when
1299 composing a new message."
1300   (interactive)
1301   (let ((mail-parse-charset gnus-newsgroup-charset))
1302     (gnus-setup-message 'reply-yank
1303       (gnus-summary-select-article t)
1304       (set-buffer gnus-original-article-buffer)
1305       (let ((cur (current-buffer))
1306             (to (message-fetch-field "to")))
1307         ;; Get a normal message buffer.
1308         (message-pop-to-buffer (message-buffer-name "Resend" to))
1309         (insert-buffer-substring cur)
1310         (mime-to-mml)
1311         (message-narrow-to-head-1)
1312         ;; Gnus will generate a new one when sending.
1313         (message-remove-header "Message-ID")
1314         ;; Remove unwanted headers.
1315         (message-remove-header message-ignored-resent-headers t)
1316         (goto-char (point-max))
1317         (insert mail-header-separator)
1318         ;; Add Gcc header.
1319         (gnus-inews-insert-gcc)
1320         (goto-char (point-min))
1321         (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1322           (forward-char 1))
1323         (widen)))))
1324
1325 (defun gnus-summary-post-forward (&optional arg)
1326   "Forward the current article to a newsgroup.
1327 See `gnus-summary-mail-forward' for ARG."
1328   (interactive "P")
1329   (gnus-summary-mail-forward arg t))
1330
1331 (defun gnus-summary-mail-crosspost-complaint (n)
1332   "Send a complaint about crossposting to the current article(s)."
1333   (interactive "P")
1334   (dolist (article (gnus-summary-work-articles n))
1335     (set-buffer gnus-summary-buffer)
1336     (gnus-summary-goto-subject article)
1337     (let ((group (gnus-group-real-name gnus-newsgroup-name))
1338           newsgroups followup-to)
1339       (gnus-summary-select-article)
1340       (set-buffer gnus-original-article-buffer)
1341       (if (and (<= (length (message-tokenize-header
1342                             (setq newsgroups
1343                                   (mail-fetch-field "newsgroups"))
1344                             ", "))
1345                    1)
1346                (or (not (setq followup-to (mail-fetch-field "followup-to")))
1347                    (not (member group (message-tokenize-header
1348                                        followup-to ", ")))))
1349           (if followup-to
1350               (gnus-message 1 "Followup-to restricted")
1351             (gnus-message 1 "Not a crossposted article"))
1352         (set-buffer gnus-summary-buffer)
1353         (gnus-summary-reply-with-original 1)
1354         (set-buffer gnus-message-buffer)
1355         (message-goto-body)
1356         (insert (format gnus-crosspost-complaint newsgroups group))
1357         (message-goto-subject)
1358         (re-search-forward " *$")
1359         (replace-match " (crosspost notification)" t t)
1360         (gnus-deactivate-mark)
1361         (when (gnus-y-or-n-p "Send this complaint? ")
1362           (message-send-and-exit))))))
1363
1364 (defun gnus-mail-parse-comma-list ()
1365   (let (accumulated
1366         beg)
1367     (skip-chars-forward " ")
1368     (while (not (eobp))
1369       (setq beg (point))
1370       (skip-chars-forward "^,")
1371       (while (zerop
1372               (save-excursion
1373                 (save-restriction
1374                   (let ((i 0))
1375                     (narrow-to-region beg (point))
1376                     (goto-char beg)
1377                     (logand (progn
1378                               (while (search-forward "\"" nil t)
1379                                 (incf i))
1380                               (if (zerop i) 2 i))
1381                             2)))))
1382         (skip-chars-forward ",")
1383         (skip-chars-forward "^,"))
1384       (skip-chars-backward " ")
1385       (push (buffer-substring beg (point))
1386             accumulated)
1387       (skip-chars-forward "^,")
1388       (skip-chars-forward ", "))
1389     accumulated))
1390
1391 (defun gnus-inews-add-to-address (group)
1392   (let ((to-address (mail-fetch-field "to")))
1393     (when (and to-address
1394                (gnus-alive-p))
1395       ;; This mail group doesn't have a `to-list', so we add one
1396       ;; here.  Magic!
1397       (when (gnus-y-or-n-p
1398              (format "Do you want to add this as `to-list': %s? " to-address))
1399         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1400
1401 (defun gnus-put-message ()
1402   "Put the current message in some group and return to Gnus."
1403   (interactive)
1404   (let ((reply gnus-article-reply)
1405         (winconf gnus-prev-winconf)
1406         (group gnus-newsgroup-name))
1407     (unless (and group
1408                  (not (gnus-group-read-only-p group)))
1409       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1410
1411     (when (gnus-group-entry group)
1412       (error "No such group: %s" group))
1413     (save-excursion
1414       (save-restriction
1415         (widen)
1416         (message-narrow-to-headers)
1417         (let ((gnus-deletable-headers nil))
1418           (message-generate-headers
1419            (if (message-news-p)
1420                message-required-news-headers
1421              message-required-mail-headers)))
1422         (goto-char (point-max))
1423         (if (string-match " " group)
1424             (insert "Gcc: \"" group "\"\n")
1425           (insert "Gcc: " group "\n"))
1426         (widen)))
1427     (gnus-inews-do-gcc)
1428     (when (and (get-buffer gnus-group-buffer)
1429                (gnus-buffer-exists-p (car-safe reply))
1430                (cdr reply))
1431       (set-buffer (car reply))
1432       (gnus-summary-mark-article-as-replied (cdr reply)))
1433     (when winconf
1434       (set-window-configuration winconf))))
1435
1436 (defun gnus-article-mail (yank)
1437   "Send a reply to the address near point.
1438 If YANK is non-nil, include the original article."
1439   (interactive "P")
1440   (let ((address
1441          (buffer-substring
1442           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1443           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1444     (when address
1445       (gnus-msg-mail address)
1446       (when yank
1447         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1448
1449 (defvar nntp-server-type)
1450 (defun gnus-bug ()
1451   "Send a bug report to the Gnus maintainers."
1452   (interactive)
1453   (unless (gnus-alive-p)
1454     (error "Gnus has been shut down"))
1455   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1456     (unless (message-mail-user-agent)
1457       (when gnus-bug-create-help-buffer
1458         (switch-to-buffer "*Gnus Help Bug*")
1459         (erase-buffer)
1460         (insert gnus-bug-message)
1461         (goto-char (point-min)))
1462       (message-pop-to-buffer "*Gnus Bug*"))
1463     (let ((message-this-is-mail t))
1464       (message-setup `((To . ,gnus-maintainer)
1465                        (Subject . "")
1466                        (X-Debbugs-Package
1467                         . ,(format "%s" gnus-bug-package))
1468                        (X-Debbugs-Version
1469                         . ,(format "%s" (gnus-continuum-version))))))
1470     (when gnus-bug-create-help-buffer
1471       (push `(gnus-bug-kill-buffer) message-send-actions))
1472     (goto-char (point-min))
1473     (message-goto-body)
1474     (insert "\n\n\n\n\n")
1475     (insert (gnus-version) "\n"
1476             (emacs-version) "\n")
1477     (when (and (boundp 'nntp-server-type)
1478                (stringp nntp-server-type))
1479       (insert nntp-server-type))
1480     (goto-char (point-min))
1481     (search-forward "Subject: " nil t)
1482     (message "")))
1483
1484 (defun gnus-bug-kill-buffer ()
1485   (when (get-buffer "*Gnus Help Bug*")
1486     (kill-buffer "*Gnus Help Bug*")))
1487
1488 (defun gnus-summary-yank-message (buffer n)
1489   "Yank the current article into a composed message."
1490   (interactive
1491    (list (gnus-completing-read "Buffer" (message-buffers) t)
1492          current-prefix-arg))
1493   (gnus-summary-iterate n
1494     (let ((gnus-inhibit-treatment t))
1495       (gnus-summary-select-article))
1496     (with-current-buffer buffer
1497       (message-yank-buffer gnus-article-buffer))))
1498
1499 ;;; Treatment of rejected articles.
1500 ;;; Bounced mail.
1501
1502 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1503   "Re-mail the current message.
1504 This only makes sense if the current message is a bounce message that
1505 contains some mail you have written which has been bounced back to
1506 you.
1507 If FETCH, try to fetch the article that this is a reply to, if indeed
1508 this is a reply."
1509   (interactive "P")
1510   (gnus-summary-select-article t)
1511   (let (summary-buffer parent)
1512     (if fetch
1513         (progn
1514           (setq summary-buffer (current-buffer))
1515           (set-buffer gnus-original-article-buffer)
1516           (article-goto-body)
1517           (when (re-search-forward "^References:\n?" nil t)
1518             (while (memq (char-after) '(?\t ? ))
1519               (forward-line 1))
1520             (skip-chars-backward "\t\n ")
1521             (setq parent
1522                   (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1523       (set-buffer gnus-original-article-buffer))
1524     (gnus-setup-message 'compose-bounce
1525       (message-bounce)
1526       ;; Add Gcc header.
1527       (gnus-inews-insert-gcc)
1528       ;; If there are references, we fetch the article we answered to.
1529       (when parent
1530         (with-current-buffer summary-buffer
1531           (gnus-summary-refer-article parent)
1532           (gnus-summary-show-all-headers))))))
1533
1534 ;;; Gcc handling.
1535
1536 (defun gnus-inews-group-method (group)
1537   (cond
1538    ;; If the group doesn't exist, we assume
1539    ;; it's an archive group...
1540    ((and (null (gnus-get-info group))
1541          (eq (car (gnus-server-to-method gnus-message-archive-method))
1542              (car (gnus-server-to-method (gnus-group-method group)))))
1543     gnus-message-archive-method)
1544    ;; Use the method.
1545    ((gnus-info-method (gnus-get-info group))
1546     (gnus-info-method (gnus-get-info group)))
1547    ;; Find the method.
1548    (t (gnus-server-to-method (gnus-group-method group)))))
1549
1550 ;; Do Gcc handling, which copied the message over to some group.
1551 (defun gnus-inews-do-gcc (&optional gcc)
1552   (interactive)
1553   (save-excursion
1554     (save-restriction
1555       (message-narrow-to-headers)
1556       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1557             (cur (current-buffer))
1558             groups group method group-art options
1559             mml-externalize-attachments)
1560         (when gcc
1561           (message-remove-header "gcc")
1562           (widen)
1563           (setq groups (message-unquote-tokens
1564                         (message-tokenize-header gcc " ,")))
1565           ;; Copy the article over to some group(s).
1566           (while (setq group (pop groups))
1567             (setq method (gnus-inews-group-method group)
1568                   group (mm-encode-coding-string
1569                          group
1570                          (gnus-group-name-charset method group)))
1571             (unless (gnus-check-server method)
1572               (error "Can't open server %s" (if (stringp method) method
1573                                               (car method))))
1574             (unless (gnus-request-group group t method)
1575               (gnus-request-create-group group method))
1576             (setq mml-externalize-attachments
1577                   (if (stringp gnus-gcc-externalize-attachments)
1578                       (string-match gnus-gcc-externalize-attachments group)
1579                     gnus-gcc-externalize-attachments))
1580             (save-excursion
1581               (nnheader-set-temp-buffer " *acc*")
1582               (setq message-options (with-current-buffer cur message-options))
1583               (insert-buffer-substring cur)
1584               (message-encode-message-body)
1585               (save-restriction
1586                 (message-narrow-to-headers)
1587                 (let* ((mail-parse-charset message-default-charset)
1588                        (newsgroups-field (save-restriction
1589                                            (message-narrow-to-headers-or-head)
1590                                            (message-fetch-field "Newsgroups")))
1591                        (followup-field (save-restriction
1592                                          (message-narrow-to-headers-or-head)
1593                                          (message-fetch-field "Followup-To")))
1594                        ;; BUG: We really need to get the charset for
1595                        ;; each name in the Newsgroups and Followup-To
1596                        ;; lines to allow crossposting between group
1597                        ;; names with incompatible character sets.
1598                        ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1599                        (group-field-charset
1600                         (gnus-group-name-charset
1601                          method (or newsgroups-field "")))
1602                        (followup-field-charset
1603                         (gnus-group-name-charset
1604                          method (or followup-field "")))
1605                        (rfc2047-header-encoding-alist
1606                         (append
1607                          (when group-field-charset
1608                            (list (cons "Newsgroups" group-field-charset)))
1609                          (when followup-field-charset
1610                            (list (cons "Followup-To" followup-field-charset)))
1611                          rfc2047-header-encoding-alist)))
1612                   (mail-encode-encoded-word-buffer)))
1613               (goto-char (point-min))
1614               (when (re-search-forward
1615                      (concat "^" (regexp-quote mail-header-separator) "$")
1616                      nil t)
1617                 (replace-match "" t t ))
1618               (when (or (not (gnus-check-backend-function
1619                               'request-accept-article group))
1620                         (not (setq group-art
1621                                    (gnus-request-accept-article
1622                                     group method t t))))
1623                 (gnus-message 1 "Couldn't store article in group %s: %s"
1624                               group (gnus-status-message method)))
1625               (when (stringp method)
1626                 (setq method (gnus-server-to-method method)))
1627               (when (and (listp method)
1628                          (gnus-native-method-p method))
1629                 (setq group (gnus-group-short-name group)))
1630               (when (and group-art
1631                          ;; FIXME: Should gcc-mark-as-read work when
1632                          ;; Gnus is not running?
1633                          (gnus-alive-p)
1634                          (or gnus-gcc-mark-as-read
1635                              (and
1636                               (boundp 'gnus-inews-mark-gcc-as-read)
1637                               (symbol-value 'gnus-inews-mark-gcc-as-read))))
1638                 (gnus-group-mark-article-read group (cdr group-art)))
1639               (setq options message-options)
1640               (with-current-buffer cur (setq message-options options))
1641               (kill-buffer (current-buffer)))))))))
1642
1643 (defun gnus-inews-insert-gcc (&optional group)
1644   "Insert the Gcc to say where the article is to be archived."
1645   (let* ((group (or group gnus-newsgroup-name))
1646          (group (when group (gnus-group-decoded-name group)))
1647          (var (or gnus-outgoing-message-group gnus-message-archive-group))
1648          (gcc-self-val
1649           (and group (gnus-group-find-parameter group 'gcc-self)))
1650          result
1651          (groups
1652           (cond
1653            ((null gnus-message-archive-method)
1654             ;; Ignore.
1655             nil)
1656            ((stringp var)
1657             ;; Just a single group.
1658             (list var))
1659            ((null var)
1660             ;; We don't want this.
1661             nil)
1662            ((and (listp var) (stringp (car var)))
1663             ;; A list of groups.
1664             var)
1665            ((functionp var)
1666             ;; A function.
1667             (funcall var group))
1668            (group
1669             ;; An alist of regexps/functions/forms.
1670             (while (and var
1671                         (not
1672                          (setq result
1673                                (cond
1674                                 ((and group
1675                                       (stringp (caar var)))
1676                                  ;; Regexp.
1677                                  (when (string-match (caar var) group)
1678                                    (cdar var)))
1679                                 ((and group
1680                                       (functionp (car var)))
1681                                  ;; Function.
1682                                  (funcall (car var) group))
1683                                 (t
1684                                  (eval (car var)))))))
1685               (setq var (cdr var)))
1686             result)))
1687          name)
1688     (when (or groups gcc-self-val)
1689       (when (stringp groups)
1690         (setq groups (list groups)))
1691       (save-excursion
1692         (save-restriction
1693           (message-narrow-to-headers)
1694           (goto-char (point-max))
1695           (insert "Gcc: ")
1696           (if gcc-self-val
1697               ;; Use the `gcc-self' param value instead.
1698               (progn
1699                 (insert
1700                  (if (stringp gcc-self-val)
1701                      (if (string-match " " gcc-self-val)
1702                          (concat "\"" gcc-self-val "\"")
1703                        gcc-self-val)
1704                    ;; In nndoc groups, we use the parent group name
1705                    ;; instead of the current group.
1706                    (let ((group (or (gnus-group-find-parameter
1707                                      gnus-newsgroup-name 'parent-group)
1708                                     group)))
1709                      (if (string-match " " group)
1710                          (concat "\"" group "\"")
1711                        group))))
1712                 (if (not (eq gcc-self-val 'none))
1713                     (insert "\n")
1714                   (gnus-delete-line)))
1715             ;; Use the list of groups.
1716             (while (setq name (pop groups))
1717               (let ((str (if (string-match ":" name)
1718                              name
1719                            (gnus-group-prefixed-name
1720                             name gnus-message-archive-method))))
1721                 (insert (if (string-match " " str)
1722                             (concat "\"" str "\"")
1723                           str)))
1724               (when groups
1725                 (insert " ")))
1726             (insert "\n")))))))
1727
1728 (defun gnus-mailing-list-followup-to ()
1729   "Look at the headers in the current buffer and return a Mail-Followup-To address."
1730   (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1731         (list-post (gnus-fetch-original-field "list-post")))
1732     (when (and list-post
1733                (string-match "mailto:\\([^>]+\\)" list-post))
1734       (setq list-post (match-string 1 list-post)))
1735     (or list-post
1736         x-been-there)))
1737
1738 ;;; Posting styles.
1739
1740 (defun gnus-configure-posting-styles (&optional group-name)
1741   "Configure posting styles according to `gnus-posting-styles'."
1742   (unless gnus-inhibit-posting-styles
1743     (let ((group (or group-name gnus-newsgroup-name ""))
1744           (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1745                       (with-current-buffer gnus-summary-buffer
1746                         gnus-posting-styles)
1747                     gnus-posting-styles))
1748           style match attribute value v results
1749           filep name address element)
1750       ;; If the group has a posting-style parameter, add it at the end with a
1751       ;; regexp matching everything, to be sure it takes precedence over all
1752       ;; the others.
1753       (when gnus-newsgroup-name
1754         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1755           (when tmp-style
1756             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1757       ;; Go through all styles and look for matches.
1758       (dolist (style styles)
1759         (setq match (pop style))
1760         (goto-char (point-min))
1761         (when (cond
1762                ((stringp match)
1763                 ;; Regexp string match on the group name.
1764                 (string-match match group))
1765                ((eq match 'header)
1766                 ;; Obsolete format of header match.
1767                 (and (gnus-buffer-live-p gnus-article-copy)
1768                      (with-current-buffer gnus-article-copy
1769                        (save-restriction
1770                          (nnheader-narrow-to-headers)
1771                          (let ((header (message-fetch-field (pop style))))
1772                            (and header
1773                                 (string-match (pop style) header)))))))
1774                ((or (symbolp match)
1775                     (functionp match))
1776                 (cond
1777                  ((functionp match)
1778                   ;; Function to be called.
1779                   (funcall match))
1780                  ((boundp match)
1781                   ;; Variable to be checked.
1782                   (symbol-value match))))
1783                ((listp match)
1784                 (cond
1785                  ((eq (car match) 'header)
1786                   ;; New format of header match.
1787                   (and (gnus-buffer-live-p gnus-article-copy)
1788                        (with-current-buffer gnus-article-copy
1789                          (save-restriction
1790                            (nnheader-narrow-to-headers)
1791                            (let ((header (message-fetch-field (nth 1 match))))
1792                              (and header
1793                                   (string-match (nth 2 match) header)))))))
1794                  (t
1795                   ;; This is a form to be evalled.
1796                   (eval match)))))
1797           ;; We have a match, so we set the variables.
1798           (dolist (attribute style)
1799             (setq element (pop attribute)
1800                   filep nil)
1801             (setq value
1802                   (cond
1803                    ((eq (car attribute) :file)
1804                     (setq filep t)
1805                     (cadr attribute))
1806                    ((eq (car attribute) :value)
1807                     (cadr attribute))
1808                    (t
1809                     (car attribute))))
1810             ;; We get the value.
1811             (setq v
1812                   (cond
1813                    ((stringp value)
1814                     (if (and (stringp match)
1815                              (gnus-string-match-p "\\\\[&[:digit:]]" value)
1816                              (match-beginning 1))
1817                         (gnus-match-substitute-replacement value nil nil group)
1818                       value))
1819                    ((or (symbolp value)
1820                         (functionp value))
1821                     (cond ((functionp value)
1822                            (funcall value))
1823                           ((boundp value)
1824                            (symbol-value value))))
1825                    ((listp value)
1826                     (eval value))))
1827             ;; Translate obsolescent value.
1828             (cond
1829              ((eq element 'signature-file)
1830               (setq element 'signature
1831                     filep t))
1832              ((eq element 'x-face-file)
1833               (setq element 'x-face
1834                     filep t)))
1835             ;; Post-processing for the signature posting-style:
1836             (and (eq element 'signature) filep
1837                  message-signature-directory
1838                  ;; don't actually use the signature directory
1839                  ;; if message-signature-file contains a path.
1840                  (not (file-name-directory v))
1841                  (setq v (nnheader-concat message-signature-directory v)))
1842             ;; Get the contents of file elems.
1843             (when (and filep v)
1844               (setq v (with-temp-buffer
1845                         (insert-file-contents v)
1846                         (buffer-substring
1847                          (point-min)
1848                          (progn
1849                            (goto-char (point-max))
1850                            (if (zerop (skip-chars-backward "\n"))
1851                                (point)
1852                              (1+ (point))))))))
1853             (setq results (delq (assoc element results) results))
1854             (push (cons element v) results))))
1855       ;; Now we have all the styles, so we insert them.
1856       (setq name (assq 'name results)
1857             address (assq 'address results))
1858       (setq results (delq name (delq address results)))
1859       (gnus-make-local-hook 'message-setup-hook)
1860       (setq results (sort results (lambda (x y)
1861                                     (string-lessp (car x) (car y)))))
1862       (dolist (result results)
1863         (add-hook 'message-setup-hook
1864                   (cond
1865                    ((eq 'eval (car result))
1866                     'ignore)
1867                    ((eq 'body (car result))
1868                     `(lambda ()
1869                        (save-excursion
1870                          (message-goto-body)
1871                          (insert ,(cdr result)))))
1872                    ((eq 'signature (car result))
1873                     (set (make-local-variable 'message-signature) nil)
1874                     (set (make-local-variable 'message-signature-file) nil)
1875                     (if (not (cdr result))
1876                         'ignore
1877                       `(lambda ()
1878                          (save-excursion
1879                            (let ((message-signature ,(cdr result)))
1880                              (when message-signature
1881                                (message-insert-signature)))))))
1882                    (t
1883                     (let ((header
1884                            (if (symbolp (car result))
1885                                (capitalize (symbol-name (car result)))
1886                              (car result))))
1887                       `(lambda ()
1888                          (save-excursion
1889                            (message-remove-header ,header)
1890                            (let ((value ,(cdr result)))
1891                              (when value
1892                                (message-goto-eoh)
1893                                (insert ,header ": " value)
1894                                (unless (bolp)
1895                                  (insert "\n")))))))))
1896                   nil 'local))
1897       (when (or name address)
1898         (add-hook 'message-setup-hook
1899                   `(lambda ()
1900                      (set (make-local-variable 'user-mail-address)
1901                           ,(or (cdr address) user-mail-address))
1902                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1903                            (user-mail-address
1904                             ,(or (cdr address) user-mail-address)))
1905                        (save-excursion
1906                          (message-remove-header "From")
1907                          (message-goto-eoh)
1908                          (insert "From: " (message-make-from) "\n"))))
1909                   nil 'local)))))
1910
1911 ;;; Allow redefinition of functions.
1912
1913 (gnus-ems-redefine)
1914
1915 (provide 'gnus-msg)
1916
1917 ;;; gnus-msg.el ends here