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