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