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