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