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