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