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