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