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