gnus-msg.el (gnus-summary-resend-message-insert-gcc): Assume that gnus-gcc-self-resen...
[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     (dolist (article (gnus-summary-work-articles n))
846       (when (gnus-summary-select-article t nil nil article)
847         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
848                 (message-cancel-news))
849           (gnus-summary-mark-as-read article gnus-canceled-mark)
850           (gnus-cache-remove-article 1))
851         (gnus-article-hide-headers-if-wanted))
852       (gnus-summary-remove-process-mark article))))
853
854 (defun gnus-summary-supersede-article ()
855   "Compose an article that will supersede a previous article.
856 This is done simply by taking the old article and adding a Supersedes
857 header line with the old Message-ID."
858   (interactive)
859   (let ((article (gnus-summary-article-number))
860         (mail-parse-charset gnus-newsgroup-charset))
861     (gnus-setup-message 'reply-yank
862       (gnus-summary-select-article t)
863       (set-buffer gnus-original-article-buffer)
864       (message-supersede)
865       (push
866        `((lambda ()
867            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
868              (with-current-buffer ,gnus-summary-buffer
869                (gnus-cache-possibly-remove-article ,article nil nil nil t)
870                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
871        message-send-actions)
872       ;; Add Gcc header.
873       (gnus-inews-insert-gcc))))
874
875 \f
876
877 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
878   ;; make a copy of the article buffer with all text properties removed
879   ;; this copy is in the buffer gnus-article-copy.
880   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
881   ;; this buffer should be passed to all mail/news reply/post routines.
882   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
883   (with-current-buffer gnus-article-copy
884     (mm-enable-multibyte))
885   (let ((article-buffer (or article-buffer gnus-article-buffer))
886         end beg)
887     (if (not (and (get-buffer article-buffer)
888                   (gnus-buffer-exists-p article-buffer)))
889         (error "Can't find any article buffer")
890       (with-current-buffer article-buffer
891         (let ((gnus-newsgroup-charset (or gnus-article-charset
892                                           gnus-newsgroup-charset))
893               (gnus-newsgroup-ignored-charsets
894                (or gnus-article-ignored-charsets
895                    gnus-newsgroup-ignored-charsets)))
896           (save-restriction
897             ;; Copy over the (displayed) article buffer, delete
898             ;; hidden text and remove text properties.
899             (widen)
900             (copy-to-buffer gnus-article-copy (point-min) (point-max))
901             (set-buffer gnus-article-copy)
902             (when yank-string
903               (message-goto-body)
904               (delete-region (point) (point-max))
905               (insert yank-string))
906             (gnus-article-delete-text-of-type 'annotation)
907             (gnus-article-delete-text-of-type 'multipart)
908             (gnus-remove-text-with-property 'gnus-prev)
909             (gnus-remove-text-with-property 'gnus-next)
910             (gnus-remove-text-with-property 'gnus-decoration)
911             (insert
912              (prog1
913                  (buffer-substring-no-properties (point-min) (point-max))
914                (erase-buffer)))
915             ;; Find the original headers.
916             (set-buffer gnus-original-article-buffer)
917             (goto-char (point-min))
918             (while (looking-at message-unix-mail-delimiter)
919               (forward-line 1))
920             (let ((mail-header-separator ""))
921               (setq beg (point)
922                     end (or (message-goto-body)
923                             ;; There may be just a header.
924                             (point-max))))
925             ;; Delete the headers from the displayed articles.
926             (set-buffer gnus-article-copy)
927             (let ((mail-header-separator ""))
928               (delete-region (goto-char (point-min))
929                              (or (message-goto-body) (point-max))))
930             ;; Insert the original article headers.
931             (insert-buffer-substring gnus-original-article-buffer beg end)
932             ;; Decode charsets.
933             (let ((gnus-article-decode-hook
934                    (delq 'article-decode-charset
935                          (copy-sequence gnus-article-decode-hook)))
936                   (rfc2047-quote-decoded-words-containing-tspecials t))
937               (run-hooks 'gnus-article-decode-hook)))))
938       gnus-article-copy)))
939
940 (defun gnus-post-news (post &optional group header article-buffer yank subject
941                             force-news)
942   (when article-buffer
943     (gnus-copy-article-buffer))
944   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
945         (gnus-article-yanked-articles yank)
946         (add-to-list gnus-add-to-list))
947     (gnus-setup-message (cond (yank 'reply-yank)
948                               (article-buffer 'reply)
949                               (t 'message))
950       (let* ((group (or group gnus-newsgroup-name))
951              (charset (gnus-group-name-charset nil group))
952              (pgroup group)
953              to-address to-group mailing-list to-list
954              newsgroup-p)
955         (when group
956           (setq to-address (gnus-parameter-to-address group)
957                 to-group (gnus-group-find-parameter group 'to-group)
958                 to-list (gnus-parameter-to-list group)
959                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
960                 mailing-list (when gnus-mailing-list-groups
961                                (string-match gnus-mailing-list-groups group))
962                 group (gnus-group-name-decode (gnus-group-real-name group)
963                                               charset)))
964         (if (or (and to-group
965                      (gnus-news-group-p to-group))
966                 newsgroup-p
967                 force-news
968                 (and (gnus-news-group-p
969                       (or pgroup gnus-newsgroup-name)
970                       (or header gnus-current-article))
971                      (not mailing-list)
972                      (not to-list)
973                      (not to-address)))
974             ;; This is news.
975             (if post
976                 (message-news
977                  (or to-group
978                      (and (not (gnus-virtual-group-p pgroup)) group)))
979               (set-buffer gnus-article-copy)
980               (gnus-msg-treat-broken-reply-to)
981               (message-followup (if (or newsgroup-p force-news)
982                                     (if (save-restriction
983                                           (article-narrow-to-head)
984                                           (message-fetch-field "newsgroups"))
985                                         nil
986                                       "")
987                                   to-group)))
988           ;; The is mail.
989           (if post
990               (progn
991                 (message-mail (or to-address to-list))
992                 ;; Arrange for mail groups that have no `to-address' to
993                 ;; get that when the user sends off the mail.
994                 (when (and (not to-list)
995                            (not to-address)
996                            add-to-list)
997                   (push (list 'gnus-inews-add-to-address pgroup)
998                         message-send-actions)))
999             (set-buffer gnus-article-copy)
1000             (gnus-msg-treat-broken-reply-to)
1001             (message-wide-reply to-address)))
1002         (when yank
1003           (gnus-inews-yank-articles yank))))))
1004
1005 (defun gnus-msg-treat-broken-reply-to (&optional force)
1006   "Remove the Reply-to header if broken-reply-to."
1007   (when (or force
1008             (gnus-group-find-parameter
1009              gnus-newsgroup-name 'broken-reply-to))
1010     (save-restriction
1011       (message-narrow-to-head)
1012       (message-remove-header "reply-to"))))
1013
1014 (defun gnus-post-method (arg group &optional silent)
1015   "Return the posting method based on GROUP and ARG.
1016 If SILENT, don't prompt the user."
1017   (let ((gnus-post-method (or (gnus-parameter-post-method group)
1018                               gnus-post-method))
1019         (group-method (gnus-find-method-for-group group)))
1020     (cond
1021      ;; If the group-method is nil (which shouldn't happen) we use
1022      ;; the default method.
1023      ((null group-method)
1024       (or (and (listp gnus-post-method) ;If not current/native/nil
1025                (not (listp (car gnus-post-method))) ; and not a list of methods
1026                gnus-post-method)        ;then use it.
1027           gnus-select-method
1028           message-post-method))
1029      ;; We want the inverse of the default
1030      ((and arg (not (eq arg 0)))
1031       (if (eq gnus-post-method 'current)
1032           gnus-select-method
1033         group-method))
1034      ;; We query the user for a post method.
1035      ((or arg
1036           (and (listp gnus-post-method)
1037                (listp (car gnus-post-method))))
1038       (let* ((methods
1039               ;; Collect all methods we know about.
1040               (append
1041                (when (listp gnus-post-method)
1042                  (if (listp (car gnus-post-method))
1043                      gnus-post-method
1044                    (list gnus-post-method)))
1045                gnus-secondary-select-methods
1046                (mapcar 'cdr gnus-server-alist)
1047                (mapcar 'car gnus-opened-servers)
1048                (list gnus-select-method)
1049                (list group-method)))
1050              method-alist post-methods method)
1051         ;; Weed out all mail methods.
1052         (while methods
1053           (setq method (gnus-server-get-method "" (pop methods)))
1054           (when (and (or (gnus-method-option-p method 'post)
1055                          (gnus-method-option-p method 'post-mail))
1056                      (not (member method post-methods)))
1057             (push method post-methods)))
1058         ;; Create a name-method alist.
1059         (setq method-alist
1060               (mapcar
1061                (lambda (m)
1062                  (if (equal (cadr m) "")
1063                      (list (symbol-name (car m)) m)
1064                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1065                post-methods))
1066         ;; Query the user.
1067         (cadr
1068          (assoc
1069           (setq gnus-last-posting-server
1070                 (if (and silent
1071                          gnus-last-posting-server)
1072                     ;; Just use the last value.
1073                     gnus-last-posting-server
1074                   (gnus-completing-read
1075                    "Posting method" (mapcar 'car method-alist) t
1076                    (cons (or gnus-last-posting-server "") 0))))
1077           method-alist))))
1078      ;; Override normal method.
1079      ((and (eq gnus-post-method 'current)
1080            (not (memq (car group-method) gnus-discouraged-post-methods))
1081            (gnus-get-function group-method 'request-post t))
1082       (assert (not arg))
1083       group-method)
1084      ;; Use gnus-post-method.
1085      ((listp gnus-post-method)          ;A method...
1086       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1087       gnus-post-method)
1088      ;; Use the normal select method (nil or native).
1089      (t gnus-select-method))))
1090
1091 \f
1092
1093 (defun gnus-extended-version ()
1094   "Stringified Gnus version and Emacs version.
1095 See the variable `gnus-user-agent'."
1096   (interactive)
1097   (if (stringp gnus-user-agent)
1098       gnus-user-agent
1099     ;; `gnus-user-agent' is a list:
1100     (let* ((float-output-format nil)
1101            (gnus-v
1102             (when (memq 'gnus gnus-user-agent)
1103               (concat "Gnus/"
1104                       (prin1-to-string (gnus-continuum-version gnus-version) t)
1105                       " (" gnus-version ")")))
1106            (emacs-v (gnus-emacs-version)))
1107       (concat gnus-v (when (and gnus-v emacs-v) " ")
1108               emacs-v))))
1109
1110 \f
1111 ;;;
1112 ;;; Gnus Mail Functions
1113 ;;;
1114
1115 ;;; Mail reply commands of Gnus summary mode
1116
1117 (defun gnus-summary-reply (&optional yank wide very-wide)
1118   "Start composing a mail reply to the current message.
1119 If prefix argument YANK is non-nil, the original article is yanked
1120 automatically.
1121 If WIDE, make a wide reply.
1122 If VERY-WIDE, make a very wide reply."
1123   (interactive
1124    (list (and current-prefix-arg
1125               (gnus-summary-work-articles 1))))
1126   ;; Allow user to require confirmation before replying by mail to the
1127   ;; author of a news article (or mail message).
1128   (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1129                      gnus-confirm-treat-mail-like-news))
1130             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1131                         (string-match gnus-confirm-mail-reply-to-news
1132                                       gnus-newsgroup-name))
1133                        ((functionp gnus-confirm-mail-reply-to-news)
1134                         (funcall gnus-confirm-mail-reply-to-news
1135                                  gnus-newsgroup-name))
1136                        (t gnus-confirm-mail-reply-to-news)))
1137             (if (or wide very-wide)
1138                 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1139                   ;; wide replies.
1140               (y-or-n-p "Really reply by mail to article author? ")))
1141     (let* ((article
1142             (if (listp (car yank))
1143                 (caar yank)
1144               (car yank)))
1145            (gnus-article-reply (or article (gnus-summary-article-number)))
1146            (gnus-article-yanked-articles yank)
1147            (headers ""))
1148       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1149       (when yank
1150         (gnus-summary-goto-subject article))
1151       (gnus-setup-message (if yank 'reply-yank 'reply)
1152         (if (not very-wide)
1153             (gnus-summary-select-article)
1154           (dolist (article very-wide)
1155             (gnus-summary-select-article nil nil nil article)
1156             (with-current-buffer (gnus-copy-article-buffer)
1157               (gnus-msg-treat-broken-reply-to)
1158               (save-restriction
1159                 (message-narrow-to-head)
1160                 (setq headers (concat headers (buffer-string)))))))
1161         (set-buffer (gnus-copy-article-buffer))
1162         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1163         (save-restriction
1164           (message-narrow-to-head)
1165           (when very-wide
1166             (erase-buffer)
1167             (insert headers))
1168           (goto-char (point-max)))
1169         (mml-quote-region (point) (point-max))
1170         (message-reply nil wide)
1171         (when yank
1172           (gnus-inews-yank-articles yank))
1173         (gnus-summary-handle-replysign)))))
1174
1175 (defun gnus-summary-handle-replysign ()
1176   "Check the various replysign variables and take action accordingly."
1177   (when (or gnus-message-replysign gnus-message-replyencrypt)
1178     (let (signed encrypted)
1179       (with-current-buffer gnus-article-buffer
1180         (setq signed (memq 'signed gnus-article-wash-types))
1181         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1182       (cond ((and gnus-message-replyencrypt encrypted)
1183              (mml-secure-message mml-default-encrypt-method
1184                                  (if gnus-message-replysignencrypted
1185                                      'signencrypt
1186                                    'encrypt)))
1187             ((and gnus-message-replysign signed)
1188              (mml-secure-message mml-default-sign-method 'sign))))))
1189
1190 (defun gnus-summary-reply-with-original (n &optional wide)
1191   "Start composing a reply mail to the current message.
1192 The original article will be yanked."
1193   (interactive "P")
1194   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1195
1196 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1197   "Start composing a reply mail to the current message.
1198 The reply goes only to the mailing list.
1199 The original article will be yanked."
1200   (interactive "P")
1201   (let ((message-reply-to-function
1202          (lambda nil
1203            `((To . ,(gnus-mailing-list-followup-to))))))
1204     (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1205
1206 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1207   "Like `gnus-summary-reply' except removing reply-to field.
1208 If prefix argument YANK is non-nil, the original article is yanked
1209 automatically.
1210 If WIDE, make a wide reply.
1211 If VERY-WIDE, make a very wide reply."
1212   (interactive
1213    (list (and current-prefix-arg
1214               (gnus-summary-work-articles 1))))
1215   (let ((gnus-msg-force-broken-reply-to t))
1216     (gnus-summary-reply yank wide very-wide)))
1217
1218 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1219   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1220 The original article will be yanked."
1221   (interactive "P")
1222   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1223
1224 (defun gnus-summary-wide-reply (&optional yank)
1225   "Start composing a wide reply mail to the current message.
1226 If prefix argument YANK is non-nil, the original article is yanked
1227 automatically."
1228   (interactive
1229    (list (and current-prefix-arg
1230               (gnus-summary-work-articles 1))))
1231   (gnus-summary-reply yank t))
1232
1233 (defun gnus-summary-wide-reply-with-original (n)
1234   "Start composing a wide reply mail to the current message.
1235 The original article will be yanked.
1236 Uses the process/prefix convention."
1237   (interactive "P")
1238   (gnus-summary-reply-with-original n t))
1239
1240 (defun gnus-summary-very-wide-reply (&optional yank)
1241   "Start composing a very wide reply mail to the current message.
1242 If prefix argument YANK is non-nil, the original article is yanked
1243 automatically."
1244   (interactive
1245    (list (and current-prefix-arg
1246               (gnus-summary-work-articles 1))))
1247   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1248
1249 (defun gnus-summary-very-wide-reply-with-original (n)
1250   "Start composing a very wide reply mail to the current message.
1251 The original article will be yanked."
1252   (interactive "P")
1253   (gnus-summary-reply
1254    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1255
1256 (defun gnus-summary-mail-forward (&optional arg post)
1257   "Forward the current message(s) to another user.
1258 If process marks exist, forward all marked messages;
1259 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1260 if ARG is 1, decode the message and forward directly inline;
1261 if ARG is 2, forward message as an rfc822 MIME section;
1262 if ARG is 3, decode message and forward as an rfc822 MIME section;
1263 if ARG is 4, forward message directly inline;
1264 otherwise, use flipped `message-forward-as-mime'.
1265 If POST, post instead of mail.
1266 For the \"inline\" alternatives, also see the variable
1267 `message-forward-ignored-headers'."
1268   (interactive "P")
1269   (if (cdr (gnus-summary-work-articles nil))
1270       ;; Process marks are given.
1271       (gnus-uu-digest-mail-forward nil post)
1272     ;; No process marks.
1273     (let ((message-forward-as-mime message-forward-as-mime)
1274           (message-forward-show-mml message-forward-show-mml))
1275       (cond
1276        ((null arg))
1277        ((eq arg 1)
1278         (setq message-forward-as-mime nil
1279               message-forward-show-mml t))
1280        ((eq arg 2)
1281         (setq message-forward-as-mime t
1282               message-forward-show-mml nil))
1283        ((eq arg 3)
1284         (setq message-forward-as-mime t
1285               message-forward-show-mml t))
1286        ((eq arg 4)
1287         (setq message-forward-as-mime nil
1288               message-forward-show-mml nil))
1289        (t
1290         (setq message-forward-as-mime (not message-forward-as-mime))))
1291       (let* ((gnus-article-reply (gnus-summary-article-number))
1292              (gnus-article-yanked-articles (list gnus-article-reply)))
1293         (gnus-setup-message 'forward
1294           (gnus-summary-select-article)
1295           (let ((mail-parse-charset
1296                  (or (and (gnus-buffer-live-p gnus-article-buffer)
1297                           (with-current-buffer gnus-article-buffer
1298                             gnus-article-charset))
1299                      gnus-newsgroup-charset))
1300                 (mail-parse-ignored-charsets
1301                  gnus-newsgroup-ignored-charsets))
1302             (set-buffer gnus-original-article-buffer)
1303             (message-forward post)))))))
1304
1305 (defun gnus-summary-resend-message-insert-gcc ()
1306   "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1307   (gnus-inews-insert-gcc)
1308   (let ((gcc (mapcar
1309               (lambda (group)
1310                 (mm-encode-coding-string
1311                  group
1312                  (gnus-group-name-charset (gnus-inews-group-method group)
1313                                           group)))
1314               (message-unquote-tokens
1315                (message-tokenize-header (mail-fetch-field "gcc" nil t)
1316                                         " ,"))))
1317         (self (with-current-buffer gnus-summary-buffer
1318                 gnus-gcc-self-resent-messages)))
1319     (message-remove-header "gcc")
1320     (when gcc
1321       (goto-char (point-max))
1322       (cond ((eq self 'none))
1323             ((eq self t)
1324              (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1325             ((stringp self)
1326              (insert "Gcc: "
1327                      (mm-encode-coding-string
1328                       (if (string-match " " self)
1329                           (concat "\"" self "\"")
1330                         self)
1331                       (gnus-group-name-charset (gnus-inews-group-method self)
1332                                                self))
1333                      "\n"))
1334             ((null self)
1335              (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1336             ((eq self 'no-gcc-self)
1337              (when (setq gcc (delete
1338                               gnus-newsgroup-name
1339                               (delete (concat "\"" gnus-newsgroup-name "\"")
1340                                       gcc)))
1341                (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1342
1343 (defun gnus-summary-resend-message (address n)
1344   "Resend the current article to ADDRESS."
1345   (interactive
1346    (list (message-read-from-minibuffer
1347           "Resend message(s) to: "
1348           (when (and gnus-summary-resend-default-address
1349                      (gnus-buffer-live-p gnus-original-article-buffer))
1350             ;; If some other article is currently selected, the
1351             ;; initial-contents is wrong. Whatever, it is just the
1352             ;; initial-contents.
1353             (with-current-buffer gnus-original-article-buffer
1354               (nnmail-fetch-field "to"))))
1355          current-prefix-arg))
1356   (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1357         (message-sent-hook (copy-sequence message-sent-hook)))
1358     ;; `gnus-summary-resend-message-insert-gcc' must run last.
1359     (add-hook 'message-header-setup-hook
1360               'gnus-summary-resend-message-insert-gcc t)
1361     (add-hook 'message-sent-hook
1362               `(lambda ()
1363                  (let ((rfc2047-encode-encoded-words nil))
1364                    ,(if gnus-agent
1365                         '(gnus-agent-possibly-do-gcc)
1366                       '(gnus-inews-do-gcc)))))
1367     (dolist (article (gnus-summary-work-articles n))
1368       (gnus-summary-select-article nil nil nil article)
1369       (with-current-buffer gnus-original-article-buffer
1370         (let ((gnus-gcc-externalize-attachments nil)
1371               (message-inhibit-body-encoding t))
1372           (message-resend address)))
1373       (gnus-summary-mark-article-as-forwarded article))))
1374
1375 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1376 (defun gnus-summary-resend-message-edit ()
1377   "Resend an article that has already been sent.
1378 A new buffer will be created to allow the user to modify body and
1379 contents of the message, and then, everything will happen as when
1380 composing a new message."
1381   (interactive)
1382   (let ((mail-parse-charset gnus-newsgroup-charset))
1383     (gnus-setup-message 'reply-yank
1384       (gnus-summary-select-article t)
1385       (set-buffer gnus-original-article-buffer)
1386       (let ((cur (current-buffer))
1387             (to (message-fetch-field "to")))
1388         ;; Get a normal message buffer.
1389         (message-pop-to-buffer (message-buffer-name "Resend" to))
1390         (insert-buffer-substring cur)
1391         (mime-to-mml)
1392         (message-narrow-to-head-1)
1393         ;; Gnus will generate a new one when sending.
1394         (message-remove-header "Message-ID")
1395         ;; Remove unwanted headers.
1396         (message-remove-header message-ignored-resent-headers t)
1397         (goto-char (point-max))
1398         (insert mail-header-separator)
1399         ;; Add Gcc header.
1400         (gnus-inews-insert-gcc)
1401         (goto-char (point-min))
1402         (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1403           (forward-char 1))
1404         (widen)))))
1405
1406 (defun gnus-summary-post-forward (&optional arg)
1407   "Forward the current article to a newsgroup.
1408 See `gnus-summary-mail-forward' for ARG."
1409   (interactive "P")
1410   (gnus-summary-mail-forward arg t))
1411
1412 (defun gnus-summary-mail-crosspost-complaint (n)
1413   "Send a complaint about crossposting to the current article(s)."
1414   (interactive "P")
1415   (dolist (article (gnus-summary-work-articles n))
1416     (set-buffer gnus-summary-buffer)
1417     (gnus-summary-goto-subject article)
1418     (let ((group (gnus-group-real-name gnus-newsgroup-name))
1419           newsgroups followup-to)
1420       (gnus-summary-select-article)
1421       (set-buffer gnus-original-article-buffer)
1422       (if (and (<= (length (message-tokenize-header
1423                             (setq newsgroups
1424                                   (mail-fetch-field "newsgroups"))
1425                             ", "))
1426                    1)
1427                (or (not (setq followup-to (mail-fetch-field "followup-to")))
1428                    (not (member group (message-tokenize-header
1429                                        followup-to ", ")))))
1430           (if followup-to
1431               (gnus-message 1 "Followup-to restricted")
1432             (gnus-message 1 "Not a crossposted article"))
1433         (set-buffer gnus-summary-buffer)
1434         (gnus-summary-reply-with-original 1)
1435         (set-buffer gnus-message-buffer)
1436         (message-goto-body)
1437         (insert (format gnus-crosspost-complaint newsgroups group))
1438         (message-goto-subject)
1439         (re-search-forward " *$")
1440         (replace-match " (crosspost notification)" t t)
1441         (gnus-deactivate-mark)
1442         (when (gnus-y-or-n-p "Send this complaint? ")
1443           (message-send-and-exit))))))
1444
1445 (defun gnus-mail-parse-comma-list ()
1446   (let (accumulated
1447         beg)
1448     (skip-chars-forward " ")
1449     (while (not (eobp))
1450       (setq beg (point))
1451       (skip-chars-forward "^,")
1452       (while (zerop
1453               (save-excursion
1454                 (save-restriction
1455                   (let ((i 0))
1456                     (narrow-to-region beg (point))
1457                     (goto-char beg)
1458                     (logand (progn
1459                               (while (search-forward "\"" nil t)
1460                                 (incf i))
1461                               (if (zerop i) 2 i))
1462                             2)))))
1463         (skip-chars-forward ",")
1464         (skip-chars-forward "^,"))
1465       (skip-chars-backward " ")
1466       (push (buffer-substring beg (point))
1467             accumulated)
1468       (skip-chars-forward "^,")
1469       (skip-chars-forward ", "))
1470     accumulated))
1471
1472 (defun gnus-inews-add-to-address (group)
1473   (let ((to-address (mail-fetch-field "to")))
1474     (when (and to-address
1475                (gnus-alive-p))
1476       ;; This mail group doesn't have a `to-list', so we add one
1477       ;; here.  Magic!
1478       (when (gnus-y-or-n-p
1479              (format "Do you want to add this as `to-list': %s? " to-address))
1480         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1481
1482 (defun gnus-put-message ()
1483   "Put the current message in some group and return to Gnus."
1484   (interactive)
1485   (let ((reply gnus-article-reply)
1486         (winconf gnus-prev-winconf)
1487         (group gnus-newsgroup-name))
1488     (unless (and group
1489                  (not (gnus-group-read-only-p group)))
1490       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1491
1492     (when (gnus-group-entry group)
1493       (error "No such group: %s" group))
1494     (save-excursion
1495       (save-restriction
1496         (widen)
1497         (message-narrow-to-headers)
1498         (let ((gnus-deletable-headers nil))
1499           (message-generate-headers
1500            (if (message-news-p)
1501                message-required-news-headers
1502              message-required-mail-headers)))
1503         (goto-char (point-max))
1504         (if (string-match " " group)
1505             (insert "Gcc: \"" group "\"\n")
1506           (insert "Gcc: " group "\n"))
1507         (widen)))
1508     (gnus-inews-do-gcc)
1509     (when (and (get-buffer gnus-group-buffer)
1510                (gnus-buffer-exists-p (car-safe reply))
1511                (cdr reply))
1512       (set-buffer (car reply))
1513       (gnus-summary-mark-article-as-replied (cdr reply)))
1514     (when winconf
1515       (set-window-configuration winconf))))
1516
1517 (defun gnus-article-mail (yank)
1518   "Send a reply to the address near point.
1519 If YANK is non-nil, include the original article."
1520   (interactive "P")
1521   (let ((address
1522          (buffer-substring
1523           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1524           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1525     (when address
1526       (gnus-msg-mail address)
1527       (when yank
1528         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1529
1530 (defvar nntp-server-type)
1531 (defun gnus-bug ()
1532   "Send a bug report to the Gnus maintainers."
1533   (interactive)
1534   (unless (gnus-alive-p)
1535     (error "Gnus has been shut down"))
1536   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1537     (unless (message-mail-user-agent)
1538       (when gnus-bug-create-help-buffer
1539         (switch-to-buffer "*Gnus Help Bug*")
1540         (erase-buffer)
1541         (insert gnus-bug-message)
1542         (goto-char (point-min)))
1543       (message-pop-to-buffer "*Gnus Bug*"))
1544     (let ((message-this-is-mail t))
1545       (message-setup `((To . ,gnus-maintainer)
1546                        (Subject . "")
1547                        (X-Debbugs-Package
1548                         . ,(format "%s" gnus-bug-package))
1549                        (X-Debbugs-Version
1550                         . ,(format "%s" (gnus-continuum-version))))))
1551     (when gnus-bug-create-help-buffer
1552       (push `(gnus-bug-kill-buffer) message-send-actions))
1553     (goto-char (point-min))
1554     (message-goto-body)
1555     (insert "\n\n\n\n\n")
1556     (insert (gnus-version) "\n"
1557             (emacs-version) "\n")
1558     (when (and (boundp 'nntp-server-type)
1559                (stringp nntp-server-type))
1560       (insert nntp-server-type))
1561     (goto-char (point-min))
1562     (search-forward "Subject: " nil t)
1563     (message "")))
1564
1565 (defun gnus-bug-kill-buffer ()
1566   (when (get-buffer "*Gnus Help Bug*")
1567     (kill-buffer "*Gnus Help Bug*")))
1568
1569 (defun gnus-summary-yank-message (buffer n)
1570   "Yank the current article into a composed message."
1571   (interactive
1572    (list (gnus-completing-read "Buffer" (message-buffers) t)
1573          current-prefix-arg))
1574   (gnus-summary-iterate n
1575     (let ((gnus-inhibit-treatment t))
1576       (gnus-summary-select-article))
1577     (with-current-buffer buffer
1578       (message-yank-buffer gnus-article-buffer))))
1579
1580 ;;; Treatment of rejected articles.
1581 ;;; Bounced mail.
1582
1583 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1584   "Re-mail the current message.
1585 This only makes sense if the current message is a bounce message that
1586 contains some mail you have written which has been bounced back to
1587 you.
1588 If FETCH, try to fetch the article that this is a reply to, if indeed
1589 this is a reply."
1590   (interactive "P")
1591   (gnus-summary-select-article t)
1592   (let (summary-buffer parent)
1593     (if fetch
1594         (progn
1595           (setq summary-buffer (current-buffer))
1596           (set-buffer gnus-original-article-buffer)
1597           (article-goto-body)
1598           (when (re-search-forward "^References:\n?" nil t)
1599             (while (memq (char-after) '(?\t ? ))
1600               (forward-line 1))
1601             (skip-chars-backward "\t\n ")
1602             (setq parent
1603                   (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1604       (set-buffer gnus-original-article-buffer))
1605     (gnus-setup-message 'compose-bounce
1606       (message-bounce)
1607       ;; Add Gcc header.
1608       (gnus-inews-insert-gcc)
1609       ;; If there are references, we fetch the article we answered to.
1610       (when parent
1611         (with-current-buffer summary-buffer
1612           (gnus-summary-refer-article parent)
1613           (gnus-summary-show-all-headers))))))
1614
1615 ;;; Gcc handling.
1616
1617 (defun gnus-inews-group-method (group)
1618   (cond
1619    ;; If the group doesn't exist, we assume
1620    ;; it's an archive group...
1621    ((and (null (gnus-get-info group))
1622          (eq (car (gnus-server-to-method gnus-message-archive-method))
1623              (car (gnus-server-to-method (gnus-group-method group)))))
1624     gnus-message-archive-method)
1625    ;; Use the method.
1626    ((gnus-info-method (gnus-get-info group))
1627     (gnus-info-method (gnus-get-info group)))
1628    ;; Find the method.
1629    (t (gnus-server-to-method (gnus-group-method group)))))
1630
1631 ;; Do Gcc handling, which copied the message over to some group.
1632 (defun gnus-inews-do-gcc (&optional gcc)
1633   (interactive)
1634   (save-excursion
1635     (save-restriction
1636       (message-narrow-to-headers)
1637       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1638             (cur (current-buffer))
1639             groups group method group-art options
1640             mml-externalize-attachments)
1641         (when gcc
1642           (message-remove-header "gcc")
1643           (widen)
1644           (setq groups (message-unquote-tokens
1645                         (message-tokenize-header gcc " ,")))
1646           ;; Copy the article over to some group(s).
1647           (while (setq group (pop groups))
1648             (setq method (gnus-inews-group-method group)
1649                   group (mm-encode-coding-string
1650                          group
1651                          (gnus-group-name-charset method group)))
1652             (unless (gnus-check-server method)
1653               (error "Can't open server %s" (if (stringp method) method
1654                                               (car method))))
1655             (unless (gnus-request-group group t method)
1656               (gnus-request-create-group group method))
1657             (setq mml-externalize-attachments
1658                   (if (stringp gnus-gcc-externalize-attachments)
1659                       (string-match gnus-gcc-externalize-attachments group)
1660                     gnus-gcc-externalize-attachments))
1661             (save-excursion
1662               (nnheader-set-temp-buffer " *acc*")
1663               (setq message-options (with-current-buffer cur message-options))
1664               (insert-buffer-substring cur)
1665               (run-hooks 'gnus-gcc-pre-body-encode-hook)
1666               (message-encode-message-body)
1667               (run-hooks 'gnus-gcc-post-body-encode-hook)
1668               (save-restriction
1669                 (message-narrow-to-headers)
1670                 (let* ((mail-parse-charset message-default-charset)
1671                        (newsgroups-field (save-restriction
1672                                            (message-narrow-to-headers-or-head)
1673                                            (message-fetch-field "Newsgroups")))
1674                        (followup-field (save-restriction
1675                                          (message-narrow-to-headers-or-head)
1676                                          (message-fetch-field "Followup-To")))
1677                        ;; BUG: We really need to get the charset for
1678                        ;; each name in the Newsgroups and Followup-To
1679                        ;; lines to allow crossposting between group
1680                        ;; names with incompatible character sets.
1681                        ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1682                        (group-field-charset
1683                         (gnus-group-name-charset
1684                          method (or newsgroups-field "")))
1685                        (followup-field-charset
1686                         (gnus-group-name-charset
1687                          method (or followup-field "")))
1688                        (rfc2047-header-encoding-alist
1689                         (append
1690                          (when group-field-charset
1691                            (list (cons "Newsgroups" group-field-charset)))
1692                          (when followup-field-charset
1693                            (list (cons "Followup-To" followup-field-charset)))
1694                          rfc2047-header-encoding-alist)))
1695                   (mail-encode-encoded-word-buffer)))
1696               (goto-char (point-min))
1697               (when (re-search-forward
1698                      (concat "^" (regexp-quote mail-header-separator) "$")
1699                      nil t)
1700                 (replace-match "" t t ))
1701               (when (or (not (gnus-check-backend-function
1702                               'request-accept-article group))
1703                         (not (setq group-art
1704                                    (gnus-request-accept-article
1705                                     group method t t))))
1706                 (gnus-message 1 "Couldn't store article in group %s: %s"
1707                               group (gnus-status-message method)))
1708               (when (stringp method)
1709                 (setq method (gnus-server-to-method method)))
1710               (when (and (listp method)
1711                          (gnus-native-method-p method))
1712                 (setq group (gnus-group-short-name group)))
1713               (when (and group-art
1714                          ;; FIXME: Should gcc-mark-as-read work when
1715                          ;; Gnus is not running?
1716                          (gnus-alive-p))
1717                 (if (or gnus-gcc-mark-as-read
1718                         (and (boundp 'gnus-inews-mark-gcc-as-read)
1719                              (symbol-value 'gnus-inews-mark-gcc-as-read)))
1720                     (gnus-group-mark-article-read group (cdr group-art))
1721                   (with-current-buffer gnus-group-buffer
1722                     (let ((gnus-group-marked (list group))
1723                           (gnus-get-new-news-hook nil)
1724                           (inhibit-read-only t))
1725                       (gnus-group-get-new-news-this-group nil t)))))
1726               (setq options message-options)
1727               (with-current-buffer cur (setq message-options options))
1728               (kill-buffer (current-buffer)))))))))
1729
1730 (defun gnus-inews-insert-gcc (&optional group)
1731   "Insert the Gcc to say where the article is to be archived."
1732   (let* ((group (or group gnus-newsgroup-name))
1733          (group (when group (gnus-group-decoded-name group)))
1734          (var (or gnus-outgoing-message-group gnus-message-archive-group))
1735          (gcc-self-val
1736           (and group (gnus-group-find-parameter group 'gcc-self)))
1737          result
1738          (groups
1739           (cond
1740            ((null gnus-message-archive-method)
1741             ;; Ignore.
1742             nil)
1743            ((stringp var)
1744             ;; Just a single group.
1745             (list var))
1746            ((null var)
1747             ;; We don't want this.
1748             nil)
1749            ((and (listp var) (stringp (car var)))
1750             ;; A list of groups.
1751             var)
1752            ((functionp var)
1753             ;; A function.
1754             (funcall var group))
1755            (t
1756             ;; An alist of regexps/functions/forms.
1757             (while (and var
1758                         (not
1759                          (setq result
1760                                (cond
1761                                 ((stringp (caar var))
1762                                  ;; Regexp.
1763                                  (when (string-match (caar var) group)
1764                                    (cdar var)))
1765                                 ((functionp (car var))
1766                                  ;; Function.
1767                                  (funcall (car var) group))
1768                                 (t
1769                                  (eval (car var)))))))
1770               (setq var (cdr var)))
1771             result)))
1772          name)
1773     (when (or groups gcc-self-val)
1774       (when (stringp groups)
1775         (setq groups (list groups)))
1776       (save-excursion
1777         (save-restriction
1778           (message-narrow-to-headers)
1779           (goto-char (point-max))
1780           (insert "Gcc: ")
1781           (if gcc-self-val
1782               ;; Use the `gcc-self' param value instead.
1783               (progn
1784                 (insert
1785                  (if (stringp gcc-self-val)
1786                      (if (string-match " " gcc-self-val)
1787                          (concat "\"" gcc-self-val "\"")
1788                        gcc-self-val)
1789                    ;; In nndoc groups, we use the parent group name
1790                    ;; instead of the current group.
1791                    (let ((group (or (gnus-group-find-parameter
1792                                      gnus-newsgroup-name 'parent-group)
1793                                     group)))
1794                      (if (string-match " " group)
1795                          (concat "\"" group "\"")
1796                        group))))
1797                 (if (not (eq gcc-self-val 'none))
1798                     (insert "\n")
1799                   (gnus-delete-line)))
1800             ;; Use the list of groups.
1801             (while (setq name (pop groups))
1802               (let ((str (if (string-match ":" name)
1803                              name
1804                            (gnus-group-prefixed-name
1805                             name gnus-message-archive-method))))
1806                 (insert (if (string-match " " str)
1807                             (concat "\"" str "\"")
1808                           str)))
1809               (when groups
1810                 (insert " ")))
1811             (insert "\n")))))))
1812
1813 (defun gnus-mailing-list-followup-to ()
1814   "Look at the headers in the current buffer and return a Mail-Followup-To address."
1815   (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1816         (list-post (gnus-fetch-original-field "list-post")))
1817     (when (and list-post
1818                (string-match "mailto:\\([^>]+\\)" list-post))
1819       (setq list-post (match-string 1 list-post)))
1820     (or list-post
1821         x-been-there)))
1822
1823 ;;; Posting styles.
1824
1825 (defun gnus-configure-posting-styles (&optional group-name)
1826   "Configure posting styles according to `gnus-posting-styles'."
1827   (unless gnus-inhibit-posting-styles
1828     (let ((group (or group-name gnus-newsgroup-name ""))
1829           (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1830                       (with-current-buffer gnus-summary-buffer
1831                         gnus-posting-styles)
1832                     gnus-posting-styles))
1833           style match attribute value v results
1834           filep name address element)
1835       ;; If the group has a posting-style parameter, add it at the end with a
1836       ;; regexp matching everything, to be sure it takes precedence over all
1837       ;; the others.
1838       (when gnus-newsgroup-name
1839         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1840           (when tmp-style
1841             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1842       ;; Go through all styles and look for matches.
1843       (dolist (style styles)
1844         (setq match (pop style))
1845         (goto-char (point-min))
1846         (when (cond
1847                ((stringp match)
1848                 ;; Regexp string match on the group name.
1849                 (string-match match group))
1850                ((eq match 'header)
1851                 ;; Obsolete format of header match.
1852                 (and (gnus-buffer-live-p gnus-article-copy)
1853                      (with-current-buffer gnus-article-copy
1854                        (save-restriction
1855                          (nnheader-narrow-to-headers)
1856                          (let ((header (message-fetch-field (pop style))))
1857                            (and header
1858                                 (string-match (pop style) header)))))))
1859                ((or (symbolp match)
1860                     (functionp match))
1861                 (cond
1862                  ((functionp match)
1863                   ;; Function to be called.
1864                   (funcall match))
1865                  ((boundp match)
1866                   ;; Variable to be checked.
1867                   (symbol-value match))))
1868                ((listp match)
1869                 (cond
1870                  ((eq (car match) 'header)
1871                   ;; New format of header match.
1872                   (and (gnus-buffer-live-p gnus-article-copy)
1873                        (with-current-buffer gnus-article-copy
1874                          (save-restriction
1875                            (nnheader-narrow-to-headers)
1876                            (let ((header (message-fetch-field (nth 1 match))))
1877                              (and header
1878                                   (string-match (nth 2 match) header)))))))
1879                  (t
1880                   ;; This is a form to be evalled.
1881                   (eval match)))))
1882           ;; We have a match, so we set the variables.
1883           (dolist (attribute style)
1884             (setq element (pop attribute)
1885                   filep nil)
1886             (setq value
1887                   (cond
1888                    ((eq (car attribute) :file)
1889                     (setq filep t)
1890                     (cadr attribute))
1891                    ((eq (car attribute) :value)
1892                     (cadr attribute))
1893                    (t
1894                     (car attribute))))
1895             ;; We get the value.
1896             (setq v
1897                   (cond
1898                    ((stringp value)
1899                     (if (and (stringp match)
1900                              (gnus-string-match-p "\\\\[&[:digit:]]" value)
1901                              (match-beginning 1))
1902                         (gnus-match-substitute-replacement value nil nil group)
1903                       value))
1904                    ((or (symbolp value)
1905                         (functionp value))
1906                     (cond ((functionp value)
1907                            (funcall value))
1908                           ((boundp value)
1909                            (symbol-value value))))
1910                    ((listp value)
1911                     (eval value))))
1912             ;; Translate obsolescent value.
1913             (cond
1914              ((eq element 'signature-file)
1915               (setq element 'signature
1916                     filep t))
1917              ((eq element 'x-face-file)
1918               (setq element 'x-face
1919                     filep t)))
1920             ;; Post-processing for the signature posting-style:
1921             (and (eq element 'signature) filep
1922                  message-signature-directory
1923                  ;; don't actually use the signature directory
1924                  ;; if message-signature-file contains a path.
1925                  (not (file-name-directory v))
1926                  (setq v (nnheader-concat message-signature-directory v)))
1927             ;; Get the contents of file elems.
1928             (when (and filep v)
1929               (setq v (with-temp-buffer
1930                         (insert-file-contents v)
1931                         (buffer-substring
1932                          (point-min)
1933                          (progn
1934                            (goto-char (point-max))
1935                            (if (zerop (skip-chars-backward "\n"))
1936                                (point)
1937                              (1+ (point))))))))
1938             (setq results (delq (assoc element results) results))
1939             (push (cons element v) results))))
1940       ;; Now we have all the styles, so we insert them.
1941       (setq name (assq 'name results)
1942             address (assq 'address results))
1943       (setq results (delq name (delq address results)))
1944       (gnus-make-local-hook 'message-setup-hook)
1945       (setq results (sort results (lambda (x y)
1946                                     (string-lessp (car x) (car y)))))
1947       (dolist (result results)
1948         (add-hook 'message-setup-hook
1949                   (cond
1950                    ((eq 'eval (car result))
1951                     'ignore)
1952                    ((eq 'body (car result))
1953                     `(lambda ()
1954                        (save-excursion
1955                          (message-goto-body)
1956                          (insert ,(cdr result)))))
1957                    ((eq 'signature (car result))
1958                     (set (make-local-variable 'message-signature) nil)
1959                     (set (make-local-variable 'message-signature-file) nil)
1960                     (if (not (cdr result))
1961                         'ignore
1962                       `(lambda ()
1963                          (save-excursion
1964                            (let ((message-signature ,(cdr result)))
1965                              (when message-signature
1966                                (message-insert-signature)))))))
1967                    (t
1968                     (let ((header
1969                            (if (symbolp (car result))
1970                                (capitalize (symbol-name (car result)))
1971                              (car result))))
1972                       `(lambda ()
1973                          (save-excursion
1974                            (message-remove-header ,header)
1975                            (let ((value ,(cdr result)))
1976                              (when value
1977                                (message-goto-eoh)
1978                                (insert ,header ": " value)
1979                                (unless (bolp)
1980                                  (insert "\n")))))))))
1981                   nil 'local))
1982       (when (or name address)
1983         (add-hook 'message-setup-hook
1984                   `(lambda ()
1985                      (set (make-local-variable 'user-mail-address)
1986                           ,(or (cdr address) user-mail-address))
1987                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1988                            (user-mail-address
1989                             ,(or (cdr address) user-mail-address)))
1990                        (save-excursion
1991                          (message-remove-header "From")
1992                          (message-goto-eoh)
1993                          (insert "From: " (message-make-from) "\n"))))
1994                   nil 'local)))))
1995
1996 ;;; Allow redefinition of functions.
1997
1998 (gnus-ems-redefine)
1999
2000 (provide 'gnus-msg)
2001
2002 ;;; gnus-msg.el ends here