* fns.c (Fcompare_strings): Doc fix.
[emacs.git] / lisp / gnus / gnus-msg.el
blob77bb6281bc4f490146033806568d0b0457beb6f6
1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2012 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 (defvar gnus-article-reply nil)
419 (defmacro gnus-setup-message (config &rest forms)
420 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
421 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
422 (buffer (make-symbol "gnus-setup-message-buffer"))
423 (article (make-symbol "gnus-setup-message-article"))
424 (yanked (make-symbol "gnus-setup-yanked-articles"))
425 (group (make-symbol "gnus-setup-message-group")))
426 `(let ((,winconf (current-window-configuration))
427 (,winconf-name gnus-current-window-configuration)
428 (,buffer (buffer-name (current-buffer)))
429 (,article gnus-article-reply)
430 (,yanked gnus-article-yanked-articles)
431 (,group gnus-newsgroup-name)
432 (message-header-setup-hook
433 (copy-sequence message-header-setup-hook))
434 (mbl mml-buffer-list)
435 (message-mode-hook (copy-sequence message-mode-hook)))
436 (setq mml-buffer-list nil)
437 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
438 ;; message-newsreader and message-mailer were formerly set in
439 ;; gnus-inews-add-send-actions, but this is too late when
440 ;; message-generate-headers-first is used. --ansel
441 (add-hook 'message-mode-hook
442 (lambda nil
443 (setq message-newsreader
444 (setq message-mailer (gnus-extended-version)))))
445 ;; #### FIXME: for a reason that I did not manage to identify yet,
446 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
447 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
448 ;; After evaluation of @forms below, it gets the value we actually want
449 ;; to override, and the posting styles are used. For that reason, I've
450 ;; added an optional argument to `gnus-configure-posting-styles' to
451 ;; make sure that the correct value for the group name is used. -- drv
452 (add-hook 'message-mode-hook
453 (if (memq ,config '(reply-yank reply))
454 (lambda ()
455 (gnus-configure-posting-styles ,group))
456 (lambda ()
457 ;; There may be an old " *gnus article copy*" buffer.
458 (let (gnus-article-copy)
459 (gnus-configure-posting-styles ,group)))))
460 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
461 message-required-headers)
462 (when (and ,group
463 (not (string= ,group "")))
464 (push (cons
465 (intern gnus-draft-meta-information-header)
466 (gnus-inews-make-draft (or ,yanked ,article)))
467 message-required-headers))
468 (unwind-protect
469 (progn
470 ,@forms)
471 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
472 ,yanked ,winconf-name)
473 (setq gnus-message-buffer (current-buffer))
474 (set (make-local-variable 'gnus-message-group-art)
475 (cons ,group ,article))
476 (set (make-local-variable 'gnus-newsgroup-name) ,group)
477 ;; Enable highlighting of different citation levels
478 (when gnus-message-highlight-citation
479 (gnus-message-citation-mode 1))
480 (gnus-run-hooks 'gnus-message-setup-hook)
481 (if (eq major-mode 'message-mode)
482 (let ((mbl1 mml-buffer-list))
483 (setq mml-buffer-list mbl) ;; Global value
484 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
485 (gnus-make-local-hook 'kill-buffer-hook)
486 (gnus-make-local-hook 'change-major-mode-hook)
487 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
488 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
489 (mml-destroy-buffers)
490 (setq mml-buffer-list mbl)))
491 (message-hide-headers)
492 (gnus-add-buffer)
493 (gnus-configure-windows ,config t)
494 (run-hooks 'post-command-hook)
495 (set-buffer-modified-p nil))))
497 (defun gnus-inews-make-draft-meta-information (group articles)
498 (when (numberp articles)
499 (setq articles (list articles)))
500 (concat "(\"" group "\""
501 (if articles
502 (concat " "
503 (mapconcat
504 (lambda (elem)
505 (number-to-string
506 (if (consp elem)
507 (car elem)
508 elem)))
509 articles " "))
511 ")"))
513 ;;;###autoload
514 (defun gnus-msg-mail (&optional to subject other-headers continue
515 switch-action yank-action send-actions
516 return-action)
517 "Start editing a mail message to be sent.
518 Like `message-mail', but with Gnus paraphernalia, particularly the
519 Gcc: header for archiving purposes.
520 If Gnus isn't running, a plain `message-mail' setup is used
521 instead."
522 (interactive)
523 (if (not (gnus-alive-p))
524 (progn
525 (message "Gnus not running; using plain Message mode")
526 (message-mail to subject other-headers continue
527 nil yank-action send-actions return-action))
528 (let ((buf (current-buffer))
529 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
530 mail-buf)
531 (gnus-setup-message 'message
532 (message-mail to subject other-headers continue
533 nil yank-action send-actions return-action))
534 (when switch-action
535 (setq mail-buf (current-buffer))
536 (switch-to-buffer buf)
537 (apply switch-action mail-buf nil))
538 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
539 t)))
541 ;;;###autoload
542 (defun gnus-button-mailto (address)
543 "Mail to ADDRESS."
544 (set-buffer (gnus-copy-article-buffer))
545 (gnus-setup-message 'message
546 (message-reply address)))
548 ;;;###autoload
549 (defun gnus-button-reply (&optional to-address wide)
550 "Like `message-reply'."
551 (interactive)
552 (gnus-setup-message 'message
553 (message-reply to-address wide)))
555 ;;;###autoload
556 (define-mail-user-agent 'gnus-user-agent
557 'gnus-msg-mail 'message-send-and-exit
558 'message-kill-buffer 'message-send-hook)
560 (defun gnus-setup-posting-charset (group)
561 (let ((alist gnus-group-posting-charset-alist)
562 (group (or group ""))
563 elem)
564 (when group
565 (catch 'found
566 (while (setq elem (pop alist))
567 (when (or (and (stringp (car elem))
568 (string-match (car elem) group))
569 (and (functionp (car elem))
570 (funcall (car elem) group))
571 (and (symbolp (car elem))
572 (symbol-value (car elem))))
573 (throw 'found (cons (cadr elem) (caddr elem)))))))))
575 (defun gnus-inews-add-send-actions (winconf buffer article
576 &optional config yanked
577 winconf-name)
578 (gnus-make-local-hook 'message-sent-hook)
579 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
580 'gnus-inews-do-gcc) nil t)
581 (when gnus-agent
582 (gnus-make-local-hook 'message-header-hook)
583 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
584 (setq message-post-method
585 `(lambda (&optional arg)
586 (gnus-post-method arg ,gnus-newsgroup-name)))
587 (message-add-action
588 `(progn
589 (setq gnus-current-window-configuration ',winconf-name)
590 (when (gnus-buffer-exists-p ,buffer)
591 (set-window-configuration ,winconf)))
592 'exit 'postpone 'kill)
593 (let ((to-be-marked (cond
594 (yanked
595 (mapcar
596 (lambda (x) (if (listp x) (car x) x)) yanked))
597 (article (if (listp article) article (list article)))
598 (t nil))))
599 (message-add-action
600 `(when (gnus-buffer-exists-p ,buffer)
601 (with-current-buffer ,buffer
602 ,(when to-be-marked
603 (if (eq config 'forward)
604 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
605 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
606 'send)))
608 (put 'gnus-setup-message 'lisp-indent-function 1)
609 (put 'gnus-setup-message 'edebug-form-spec '(form body))
611 ;;; Post news commands of Gnus group mode and summary mode
613 (defun gnus-group-mail (&optional arg)
614 "Start composing a mail.
615 If ARG, use the group under the point to find a posting style.
616 If ARG is 1, prompt for a group name to find the posting style."
617 (interactive "P")
618 ;; We can't `let' gnus-newsgroup-name here, since that leads
619 ;; to local variables leaking.
620 (let ((group gnus-newsgroup-name)
621 ;; make sure last viewed article doesn't affect posting styles:
622 (gnus-article-copy)
623 (buffer (current-buffer)))
624 (unwind-protect
625 (progn
626 (setq gnus-newsgroup-name
627 (if arg
628 (if (= 1 (prefix-numeric-value arg))
629 (gnus-group-completing-read
630 "Use posting style of group"
631 nil (gnus-read-active-file-p))
632 (gnus-group-group-name))
633 ""))
634 ;; #### see comment in gnus-setup-message -- drv
635 (gnus-setup-message 'message (message-mail)))
636 (with-current-buffer buffer
637 (setq gnus-newsgroup-name group)))))
639 (defun gnus-group-news (&optional arg)
640 "Start composing a news.
641 If ARG, post to group under point.
642 If ARG is 1, prompt for group name to post to.
644 This function prepares a news even when using mail groups. This is useful
645 for posting messages to mail groups without actually sending them over the
646 network. The corresponding back end must have a 'request-post method."
647 (interactive "P")
648 ;; We can't `let' gnus-newsgroup-name here, since that leads
649 ;; to local variables leaking.
650 (let ((group gnus-newsgroup-name)
651 ;; make sure last viewed article doesn't affect posting styles:
652 (gnus-article-copy)
653 (buffer (current-buffer)))
654 (unwind-protect
655 (progn
656 (setq gnus-newsgroup-name
657 (if arg
658 (if (= 1 (prefix-numeric-value arg))
659 (gnus-group-completing-read "Use group"
661 (gnus-read-active-file-p))
662 (gnus-group-group-name))
663 ""))
664 ;; #### see comment in gnus-setup-message -- drv
665 (gnus-setup-message 'message
666 (message-news (gnus-group-real-name gnus-newsgroup-name))))
667 (with-current-buffer buffer
668 (setq gnus-newsgroup-name group)))))
670 (defun gnus-group-post-news (&optional arg)
671 "Start composing a message (a news by default).
672 If ARG, post to group under point. If ARG is 1, prompt for group name.
673 Depending on the selected group, the message might be either a mail or
674 a news."
675 (interactive "P")
676 ;; Bind this variable here to make message mode hooks work ok.
677 (let ((gnus-newsgroup-name
678 (if arg
679 (if (= 1 (prefix-numeric-value arg))
680 (gnus-group-completing-read "Newsgroup" nil
681 (gnus-read-active-file-p))
682 (or (gnus-group-group-name) ""))
683 ""))
684 ;; make sure last viewed article doesn't affect posting styles:
685 (gnus-article-copy))
686 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
687 (string= gnus-newsgroup-name ""))))
689 (defun gnus-summary-mail-other-window (&optional arg)
690 "Start composing a mail in another window.
691 Use the posting of the current group by default.
692 If ARG, don't do that. If ARG is 1, prompt for group name to find the
693 posting style."
694 (interactive "P")
695 ;; We can't `let' gnus-newsgroup-name here, since that leads
696 ;; to local variables leaking.
697 (let ((group gnus-newsgroup-name)
698 ;; make sure last viewed article doesn't affect posting styles:
699 (gnus-article-copy)
700 (buffer (current-buffer)))
701 (unwind-protect
702 (progn
703 (setq gnus-newsgroup-name
704 (if arg
705 (if (= 1 (prefix-numeric-value arg))
706 (gnus-group-completing-read "Use group"
708 (gnus-read-active-file-p))
710 gnus-newsgroup-name))
711 ;; #### see comment in gnus-setup-message -- drv
712 (gnus-setup-message 'message (message-mail)))
713 (with-current-buffer buffer
714 (setq gnus-newsgroup-name group)))))
716 (defun gnus-summary-news-other-window (&optional arg)
717 "Start composing a news in another window.
718 Post to the current group by default.
719 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
721 This function prepares a news even when using mail groups. This is useful
722 for posting messages to mail groups without actually sending them over the
723 network. The corresponding back end must have a 'request-post method."
724 (interactive "P")
725 ;; We can't `let' gnus-newsgroup-name here, since that leads
726 ;; to local variables leaking.
727 (let ((group gnus-newsgroup-name)
728 ;; make sure last viewed article doesn't affect posting styles:
729 (gnus-article-copy)
730 (buffer (current-buffer)))
731 (unwind-protect
732 (progn
733 (setq gnus-newsgroup-name
734 (if arg
735 (if (= 1 (prefix-numeric-value arg))
736 (gnus-group-completing-read "Use group"
738 (gnus-read-active-file-p))
740 gnus-newsgroup-name))
741 ;; #### see comment in gnus-setup-message -- drv
742 (gnus-setup-message 'message
743 (progn
744 (message-news (gnus-group-real-name gnus-newsgroup-name))
745 (set (make-local-variable 'gnus-discouraged-post-methods)
746 (remove
747 (car (gnus-find-method-for-group gnus-newsgroup-name))
748 gnus-discouraged-post-methods)))))
749 (with-current-buffer buffer
750 (setq gnus-newsgroup-name group)))))
752 (defun gnus-summary-post-news (&optional arg)
753 "Start composing a message. Post to the current group by default.
754 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
755 Depending on the selected group, the message might be either a mail or
756 a news."
757 (interactive "P")
758 ;; Bind this variable here to make message mode hooks work ok.
759 (let ((gnus-newsgroup-name
760 (if arg
761 (if (= 1 (prefix-numeric-value arg))
762 (gnus-group-completing-read "Newsgroup" nil
763 (gnus-read-active-file-p))
765 gnus-newsgroup-name))
766 ;; make sure last viewed article doesn't affect posting styles:
767 (gnus-article-copy))
768 (gnus-post-news 'post gnus-newsgroup-name)))
771 (defun gnus-summary-followup (yank &optional force-news)
772 "Compose a followup to an article.
773 If prefix argument YANK is non-nil, the original article is yanked
774 automatically.
775 YANK is a list of elements, where the car of each element is the
776 article number, and the cdr is the string to be yanked."
777 (interactive
778 (list (and current-prefix-arg
779 (gnus-summary-work-articles 1))))
780 (when yank
781 (gnus-summary-goto-subject
782 (if (listp (car yank))
783 (caar yank)
784 (car yank))))
785 (save-window-excursion
786 (gnus-summary-select-article))
787 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
788 (gnus-newsgroup-name gnus-newsgroup-name))
789 ;; Send a followup.
790 (gnus-post-news nil gnus-newsgroup-name
791 headers gnus-article-buffer
792 yank nil force-news)
793 (gnus-summary-handle-replysign)))
795 (defun gnus-summary-followup-with-original (n &optional force-news)
796 "Compose a followup to an article and include the original article.
797 The text in the region will be yanked. If the region isn't
798 active, the entire article will be yanked."
799 (interactive "P")
800 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
802 (defun gnus-summary-followup-to-mail (&optional arg)
803 "Followup to the current mail message via news."
804 (interactive
805 (list (and current-prefix-arg
806 (gnus-summary-work-articles 1))))
807 (gnus-summary-followup arg t))
809 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
810 "Followup to the current mail message via news."
811 (interactive "P")
812 (gnus-summary-followup (gnus-summary-work-articles arg) t))
814 (defun gnus-inews-yank-articles (articles)
815 (let (beg article yank-string)
816 (message-goto-body)
817 (while (setq article (pop articles))
818 (when (listp article)
819 (setq yank-string (nth 1 article)
820 article (nth 0 article)))
821 (save-window-excursion
822 (set-buffer gnus-summary-buffer)
823 (gnus-summary-select-article nil nil nil article)
824 (gnus-summary-remove-process-mark article))
825 (gnus-copy-article-buffer nil yank-string)
826 (let ((message-reply-buffer gnus-article-copy)
827 (message-reply-headers
828 ;; The headers are decoded.
829 (with-current-buffer gnus-article-copy
830 (save-restriction
831 (nnheader-narrow-to-headers)
832 (nnheader-parse-naked-head)))))
833 (message-yank-original)
834 (message-exchange-point-and-mark)
835 (setq beg (or beg (mark t))))
836 (when articles
837 (insert "\n")))
838 (push-mark)
839 (goto-char beg)))
841 (defun gnus-summary-cancel-article (&optional n symp)
842 "Cancel an article you posted.
843 Uses the process-prefix convention. If given the symbolic
844 prefix `a', cancel using the standard posting method; if not
845 post using the current select method."
846 (interactive (gnus-interactive "P\ny"))
847 (let ((message-post-method
848 `(lambda (arg)
849 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
850 (user-mail-address user-mail-address))
851 (dolist (article (gnus-summary-work-articles n))
852 (when (gnus-summary-select-article t nil nil article)
853 ;; Pretend that we're doing a followup so that we can see what
854 ;; the From header would have ended up being.
855 (save-window-excursion
856 (save-excursion
857 (gnus-summary-followup nil)
858 (let ((from (message-fetch-field "from")))
859 (when from
860 (setq user-mail-address
861 (car (mail-header-parse-address from)))))
862 (kill-buffer (current-buffer))))
863 ;; Now cancel the article using the From header we got.
864 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
865 (message-cancel-news))
866 (gnus-summary-mark-as-read article gnus-canceled-mark)
867 (gnus-cache-remove-article 1))
868 (gnus-article-hide-headers-if-wanted))
869 (gnus-summary-remove-process-mark article))))
871 (defun gnus-summary-supersede-article ()
872 "Compose an article that will supersede a previous article.
873 This is done simply by taking the old article and adding a Supersedes
874 header line with the old Message-ID."
875 (interactive)
876 (let ((article (gnus-summary-article-number))
877 (mail-parse-charset gnus-newsgroup-charset))
878 (gnus-setup-message 'reply-yank
879 (gnus-summary-select-article t)
880 (set-buffer gnus-original-article-buffer)
881 (message-supersede)
882 (push
883 `((lambda ()
884 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
885 (with-current-buffer ,gnus-summary-buffer
886 (gnus-cache-possibly-remove-article ,article nil nil nil t)
887 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
888 message-send-actions)
889 ;; Add Gcc header.
890 (gnus-inews-insert-gcc))))
894 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
895 ;; make a copy of the article buffer with all text properties removed
896 ;; this copy is in the buffer gnus-article-copy.
897 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
898 ;; this buffer should be passed to all mail/news reply/post routines.
899 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
900 (with-current-buffer gnus-article-copy
901 (mm-enable-multibyte))
902 (let ((article-buffer (or article-buffer gnus-article-buffer))
903 end beg)
904 (if (not (and (get-buffer article-buffer)
905 (gnus-buffer-exists-p article-buffer)))
906 (error "Can't find any article buffer")
907 (with-current-buffer article-buffer
908 (let ((gnus-newsgroup-charset (or gnus-article-charset
909 gnus-newsgroup-charset))
910 (gnus-newsgroup-ignored-charsets
911 (or gnus-article-ignored-charsets
912 gnus-newsgroup-ignored-charsets)))
913 (save-restriction
914 ;; Copy over the (displayed) article buffer, delete
915 ;; hidden text and remove text properties.
916 (widen)
917 (copy-to-buffer gnus-article-copy (point-min) (point-max))
918 (set-buffer gnus-article-copy)
919 (when yank-string
920 (message-goto-body)
921 (delete-region (point) (point-max))
922 (insert yank-string))
923 (gnus-article-delete-text-of-type 'annotation)
924 (gnus-article-delete-text-of-type 'multipart)
925 (gnus-remove-text-with-property 'gnus-prev)
926 (gnus-remove-text-with-property 'gnus-next)
927 (gnus-remove-text-with-property 'gnus-decoration)
928 (insert
929 (prog1
930 (buffer-substring-no-properties (point-min) (point-max))
931 (erase-buffer)))
932 ;; Find the original headers.
933 (set-buffer gnus-original-article-buffer)
934 (goto-char (point-min))
935 (while (looking-at message-unix-mail-delimiter)
936 (forward-line 1))
937 (let ((mail-header-separator ""))
938 (setq beg (point)
939 end (or (message-goto-body)
940 ;; There may be just a header.
941 (point-max))))
942 ;; Delete the headers from the displayed articles.
943 (set-buffer gnus-article-copy)
944 (let ((mail-header-separator ""))
945 (delete-region (goto-char (point-min))
946 (or (message-goto-body) (point-max))))
947 ;; Insert the original article headers.
948 (insert-buffer-substring gnus-original-article-buffer beg end)
949 ;; Decode charsets.
950 (let ((gnus-article-decode-hook
951 (delq 'article-decode-charset
952 (copy-sequence gnus-article-decode-hook)))
953 (rfc2047-quote-decoded-words-containing-tspecials t))
954 (run-hooks 'gnus-article-decode-hook)))))
955 gnus-article-copy)))
957 (defun gnus-post-news (post &optional group header article-buffer yank subject
958 force-news)
959 (when article-buffer
960 (gnus-copy-article-buffer))
961 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
962 (gnus-article-yanked-articles yank)
963 (add-to-list gnus-add-to-list))
964 (gnus-setup-message (cond (yank 'reply-yank)
965 (article-buffer 'reply)
966 (t 'message))
967 (let* ((group (or group gnus-newsgroup-name))
968 (charset (gnus-group-name-charset nil group))
969 (pgroup group)
970 to-address to-group mailing-list to-list
971 newsgroup-p)
972 (when group
973 (setq to-address (gnus-parameter-to-address group)
974 to-group (gnus-group-find-parameter group 'to-group)
975 to-list (gnus-parameter-to-list group)
976 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
977 mailing-list (when gnus-mailing-list-groups
978 (string-match gnus-mailing-list-groups group))
979 group (gnus-group-name-decode (gnus-group-real-name group)
980 charset)))
981 (if (or (and to-group
982 (gnus-news-group-p to-group))
983 newsgroup-p
984 force-news
985 (and (gnus-news-group-p
986 (or pgroup gnus-newsgroup-name)
987 (or header gnus-current-article))
988 (not mailing-list)
989 (not to-list)
990 (not to-address)))
991 ;; This is news.
992 (if post
993 (message-news
994 (or to-group
995 (and (not (gnus-virtual-group-p pgroup)) group)))
996 (set-buffer gnus-article-copy)
997 (gnus-msg-treat-broken-reply-to)
998 (message-followup (if (or newsgroup-p force-news)
999 (if (save-restriction
1000 (article-narrow-to-head)
1001 (message-fetch-field "newsgroups"))
1004 to-group)))
1005 ;; The is mail.
1006 (if post
1007 (progn
1008 (message-mail (or to-address to-list))
1009 ;; Arrange for mail groups that have no `to-address' to
1010 ;; get that when the user sends off the mail.
1011 (when (and (not to-list)
1012 (not to-address)
1013 add-to-list)
1014 (push (list 'gnus-inews-add-to-address pgroup)
1015 message-send-actions)))
1016 (set-buffer gnus-article-copy)
1017 (gnus-msg-treat-broken-reply-to)
1018 (message-wide-reply to-address)))
1019 (when yank
1020 (gnus-inews-yank-articles yank))))))
1022 (defun gnus-msg-treat-broken-reply-to (&optional force)
1023 "Remove the Reply-to header if broken-reply-to."
1024 (when (or force
1025 (gnus-group-find-parameter
1026 gnus-newsgroup-name 'broken-reply-to))
1027 (save-restriction
1028 (message-narrow-to-head)
1029 (message-remove-header "reply-to"))))
1031 (defun gnus-post-method (arg group &optional silent)
1032 "Return the posting method based on GROUP and ARG.
1033 If SILENT, don't prompt the user."
1034 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1035 gnus-post-method))
1036 (group-method (gnus-find-method-for-group group)))
1037 (cond
1038 ;; If the group-method is nil (which shouldn't happen) we use
1039 ;; the default method.
1040 ((null group-method)
1041 (or (and (listp gnus-post-method) ;If not current/native/nil
1042 (not (listp (car gnus-post-method))) ; and not a list of methods
1043 gnus-post-method) ;then use it.
1044 gnus-select-method
1045 message-post-method))
1046 ;; We want the inverse of the default
1047 ((and arg (not (eq arg 0)))
1048 (if (eq gnus-post-method 'current)
1049 gnus-select-method
1050 group-method))
1051 ;; We query the user for a post method.
1052 ((or arg
1053 (and (listp gnus-post-method)
1054 (listp (car gnus-post-method))))
1055 (let* ((methods
1056 ;; Collect all methods we know about.
1057 (append
1058 (when (listp gnus-post-method)
1059 (if (listp (car gnus-post-method))
1060 gnus-post-method
1061 (list gnus-post-method)))
1062 gnus-secondary-select-methods
1063 (mapcar 'cdr gnus-server-alist)
1064 (mapcar 'car gnus-opened-servers)
1065 (list gnus-select-method)
1066 (list group-method)))
1067 method-alist post-methods method)
1068 ;; Weed out all mail methods.
1069 (while methods
1070 (setq method (gnus-server-get-method "" (pop methods)))
1071 (when (and (or (gnus-method-option-p method 'post)
1072 (gnus-method-option-p method 'post-mail))
1073 (not (member method post-methods)))
1074 (push method post-methods)))
1075 ;; Create a name-method alist.
1076 (setq method-alist
1077 (mapcar
1078 (lambda (m)
1079 (if (equal (cadr m) "")
1080 (list (symbol-name (car m)) m)
1081 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1082 post-methods))
1083 ;; Query the user.
1084 (cadr
1085 (assoc
1086 (setq gnus-last-posting-server
1087 (if (and silent
1088 gnus-last-posting-server)
1089 ;; Just use the last value.
1090 gnus-last-posting-server
1091 (gnus-completing-read
1092 "Posting method" (mapcar 'car method-alist) t
1093 (cons (or gnus-last-posting-server "") 0))))
1094 method-alist))))
1095 ;; Override normal method.
1096 ((and (eq gnus-post-method 'current)
1097 (not (memq (car group-method) gnus-discouraged-post-methods))
1098 (gnus-get-function group-method 'request-post t))
1099 (assert (not arg))
1100 group-method)
1101 ;; Use gnus-post-method.
1102 ((listp gnus-post-method) ;A method...
1103 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1104 gnus-post-method)
1105 ;; Use the normal select method (nil or native).
1106 (t gnus-select-method))))
1110 (defun gnus-extended-version ()
1111 "Stringified Gnus version and Emacs version.
1112 See the variable `gnus-user-agent'."
1113 (interactive)
1114 (if (stringp gnus-user-agent)
1115 gnus-user-agent
1116 ;; `gnus-user-agent' is a list:
1117 (let* ((float-output-format nil)
1118 (gnus-v
1119 (when (memq 'gnus gnus-user-agent)
1120 (concat "Gnus/"
1121 (prin1-to-string (gnus-continuum-version gnus-version) t)
1122 " (" gnus-version ")")))
1123 (emacs-v (gnus-emacs-version)))
1124 (concat gnus-v (when (and gnus-v emacs-v) " ")
1125 emacs-v))))
1129 ;;; Gnus Mail Functions
1132 ;;; Mail reply commands of Gnus summary mode
1134 (defun gnus-summary-reply (&optional yank wide very-wide)
1135 "Start composing a mail reply to the current message.
1136 If prefix argument YANK is non-nil, the original article is yanked
1137 automatically.
1138 If WIDE, make a wide reply.
1139 If VERY-WIDE, make a very wide reply."
1140 (interactive
1141 (list (and current-prefix-arg
1142 (gnus-summary-work-articles 1))))
1143 ;; Allow user to require confirmation before replying by mail to the
1144 ;; author of a news article (or mail message).
1145 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1146 gnus-confirm-treat-mail-like-news))
1147 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1148 (string-match gnus-confirm-mail-reply-to-news
1149 gnus-newsgroup-name))
1150 ((functionp gnus-confirm-mail-reply-to-news)
1151 (funcall gnus-confirm-mail-reply-to-news
1152 gnus-newsgroup-name))
1153 (t gnus-confirm-mail-reply-to-news)))
1154 (if (or wide very-wide)
1155 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1156 ;; wide replies.
1157 (y-or-n-p "Really reply by mail to article author? ")))
1158 (let* ((article
1159 (if (listp (car yank))
1160 (caar yank)
1161 (car yank)))
1162 (gnus-article-reply (or article (gnus-summary-article-number)))
1163 (gnus-article-yanked-articles yank)
1164 (headers ""))
1165 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1166 (when yank
1167 (gnus-summary-goto-subject article))
1168 (gnus-setup-message (if yank 'reply-yank 'reply)
1169 (if (not very-wide)
1170 (gnus-summary-select-article)
1171 (dolist (article very-wide)
1172 (gnus-summary-select-article nil nil nil article)
1173 (with-current-buffer (gnus-copy-article-buffer)
1174 (gnus-msg-treat-broken-reply-to)
1175 (save-restriction
1176 (message-narrow-to-head)
1177 (setq headers (concat headers (buffer-string)))))))
1178 (set-buffer (gnus-copy-article-buffer))
1179 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1180 (save-restriction
1181 (message-narrow-to-head)
1182 (when very-wide
1183 (erase-buffer)
1184 (insert headers))
1185 (goto-char (point-max)))
1186 (mml-quote-region (point) (point-max))
1187 (message-reply nil wide)
1188 (when yank
1189 (gnus-inews-yank-articles yank))
1190 (gnus-summary-handle-replysign)))))
1192 (defun gnus-summary-handle-replysign ()
1193 "Check the various replysign variables and take action accordingly."
1194 (when (or gnus-message-replysign gnus-message-replyencrypt)
1195 (let (signed encrypted)
1196 (with-current-buffer gnus-article-buffer
1197 (setq signed (memq 'signed gnus-article-wash-types))
1198 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1199 (cond ((and gnus-message-replyencrypt encrypted)
1200 (mml-secure-message mml-default-encrypt-method
1201 (if gnus-message-replysignencrypted
1202 'signencrypt
1203 'encrypt)))
1204 ((and gnus-message-replysign signed)
1205 (mml-secure-message mml-default-sign-method 'sign))))))
1207 (defun gnus-summary-reply-with-original (n &optional wide)
1208 "Start composing a reply mail to the current message.
1209 The original article will be yanked."
1210 (interactive "P")
1211 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1213 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1214 "Start composing a reply mail to the current message.
1215 The reply goes only to the mailing list.
1216 The original article will be yanked."
1217 (interactive "P")
1218 (let ((message-reply-to-function
1219 (lambda nil
1220 `((To . ,(gnus-mailing-list-followup-to))))))
1221 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1223 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1224 "Like `gnus-summary-reply' except removing reply-to field.
1225 If prefix argument YANK is non-nil, the original article is yanked
1226 automatically.
1227 If WIDE, make a wide reply.
1228 If VERY-WIDE, make a very wide reply."
1229 (interactive
1230 (list (and current-prefix-arg
1231 (gnus-summary-work-articles 1))))
1232 (let ((gnus-msg-force-broken-reply-to t))
1233 (gnus-summary-reply yank wide very-wide)))
1235 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1236 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1237 The original article will be yanked."
1238 (interactive "P")
1239 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1241 (defun gnus-summary-wide-reply (&optional yank)
1242 "Start composing a wide reply mail to the current message.
1243 If prefix argument YANK is non-nil, the original article is yanked
1244 automatically."
1245 (interactive
1246 (list (and current-prefix-arg
1247 (gnus-summary-work-articles 1))))
1248 (gnus-summary-reply yank t))
1250 (defun gnus-summary-wide-reply-with-original (n)
1251 "Start composing a wide reply mail to the current message.
1252 The original article will be yanked.
1253 Uses the process/prefix convention."
1254 (interactive "P")
1255 (gnus-summary-reply-with-original n t))
1257 (defun gnus-summary-very-wide-reply (&optional yank)
1258 "Start composing a very 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 (gnus-summary-work-articles yank)))
1266 (defun gnus-summary-very-wide-reply-with-original (n)
1267 "Start composing a very wide reply mail to the current message.
1268 The original article will be yanked."
1269 (interactive "P")
1270 (gnus-summary-reply
1271 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1273 (defun gnus-summary-mail-forward (&optional arg post)
1274 "Forward the current message(s) to another user.
1275 If process marks exist, forward all marked messages;
1276 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1277 if ARG is 1, decode the message and forward directly inline;
1278 if ARG is 2, forward message as an rfc822 MIME section;
1279 if ARG is 3, decode message and forward as an rfc822 MIME section;
1280 if ARG is 4, forward message directly inline;
1281 otherwise, use flipped `message-forward-as-mime'.
1282 If POST, post instead of mail.
1283 For the \"inline\" alternatives, also see the variable
1284 `message-forward-ignored-headers'."
1285 (interactive "P")
1286 (if (cdr (gnus-summary-work-articles nil))
1287 ;; Process marks are given.
1288 (gnus-uu-digest-mail-forward nil post)
1289 ;; No process marks.
1290 (let ((message-forward-as-mime message-forward-as-mime)
1291 (message-forward-show-mml message-forward-show-mml))
1292 (cond
1293 ((null arg))
1294 ((eq arg 1)
1295 (setq message-forward-as-mime nil
1296 message-forward-show-mml t))
1297 ((eq arg 2)
1298 (setq message-forward-as-mime t
1299 message-forward-show-mml nil))
1300 ((eq arg 3)
1301 (setq message-forward-as-mime t
1302 message-forward-show-mml t))
1303 ((eq arg 4)
1304 (setq message-forward-as-mime nil
1305 message-forward-show-mml nil))
1307 (setq message-forward-as-mime (not message-forward-as-mime))))
1308 (let* ((gnus-article-reply (gnus-summary-article-number))
1309 (gnus-article-yanked-articles (list gnus-article-reply)))
1310 (gnus-setup-message 'forward
1311 (gnus-summary-select-article)
1312 (let ((mail-parse-charset
1313 (or (and (gnus-buffer-live-p gnus-article-buffer)
1314 (with-current-buffer gnus-article-buffer
1315 gnus-article-charset))
1316 gnus-newsgroup-charset))
1317 (mail-parse-ignored-charsets
1318 gnus-newsgroup-ignored-charsets))
1319 (set-buffer gnus-original-article-buffer)
1320 (message-forward post)))))))
1322 (defun gnus-summary-resend-message-insert-gcc ()
1323 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1324 (gnus-inews-insert-gcc)
1325 (let ((gcc (mapcar
1326 (lambda (group)
1327 (mm-encode-coding-string
1328 group
1329 (gnus-group-name-charset (gnus-inews-group-method group)
1330 group)))
1331 (message-unquote-tokens
1332 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1333 " ,"))))
1334 (self (with-current-buffer gnus-summary-buffer
1335 gnus-gcc-self-resent-messages)))
1336 (message-remove-header "gcc")
1337 (when gcc
1338 (goto-char (point-max))
1339 (cond ((eq self 'none))
1340 ((eq self t)
1341 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1342 ((stringp self)
1343 (insert "Gcc: "
1344 (mm-encode-coding-string
1345 (if (string-match " " self)
1346 (concat "\"" self "\"")
1347 self)
1348 (gnus-group-name-charset (gnus-inews-group-method self)
1349 self))
1350 "\n"))
1351 ((null self)
1352 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1353 ((eq self 'no-gcc-self)
1354 (when (setq gcc (delete
1355 gnus-newsgroup-name
1356 (delete (concat "\"" gnus-newsgroup-name "\"")
1357 gcc)))
1358 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1360 (defun gnus-summary-resend-message (address n)
1361 "Resend the current article to ADDRESS."
1362 (interactive
1363 (list (message-read-from-minibuffer
1364 "Resend message(s) to: "
1365 (when (and gnus-summary-resend-default-address
1366 (gnus-buffer-live-p gnus-original-article-buffer))
1367 ;; If some other article is currently selected, the
1368 ;; initial-contents is wrong. Whatever, it is just the
1369 ;; initial-contents.
1370 (with-current-buffer gnus-original-article-buffer
1371 (nnmail-fetch-field "to"))))
1372 current-prefix-arg))
1373 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1374 (message-sent-hook (copy-sequence message-sent-hook))
1375 ;; Honor posting-style for `name' and `address' in Resent-From header.
1376 (styles (gnus-group-find-parameter gnus-newsgroup-name
1377 'posting-style t))
1378 (user-full-name user-full-name)
1379 (user-mail-address user-mail-address)
1380 tem)
1381 (dolist (style styles)
1382 (when (stringp (cadr style))
1383 (setcdr style (list (mm-decode-coding-string (cadr style) 'utf-8)))))
1384 (dolist (style (if styles
1385 (append gnus-posting-styles (list (cons ".*" styles)))
1386 gnus-posting-styles))
1387 (when (string-match (pop style) gnus-newsgroup-name)
1388 (when (setq tem (cadr (assq 'name style)))
1389 (setq user-full-name tem))
1390 (when (setq tem (cadr (assq 'address style)))
1391 (setq user-mail-address tem))))
1392 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1393 (add-hook 'message-header-setup-hook
1394 'gnus-summary-resend-message-insert-gcc t)
1395 (add-hook 'message-sent-hook
1396 `(lambda ()
1397 (let ((rfc2047-encode-encoded-words nil))
1398 ,(if gnus-agent
1399 '(gnus-agent-possibly-do-gcc)
1400 '(gnus-inews-do-gcc)))))
1401 (dolist (article (gnus-summary-work-articles n))
1402 (gnus-summary-select-article nil nil nil article)
1403 (with-current-buffer gnus-original-article-buffer
1404 (let ((gnus-gcc-externalize-attachments nil)
1405 (message-inhibit-body-encoding t))
1406 (message-resend address)))
1407 (gnus-summary-mark-article-as-forwarded article))))
1409 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1410 (defun gnus-summary-resend-message-edit ()
1411 "Resend an article that has already been sent.
1412 A new buffer will be created to allow the user to modify body and
1413 contents of the message, and then, everything will happen as when
1414 composing a new message."
1415 (interactive)
1416 (let ((mail-parse-charset gnus-newsgroup-charset))
1417 (gnus-setup-message 'reply-yank
1418 (gnus-summary-select-article t)
1419 (set-buffer gnus-original-article-buffer)
1420 (let ((cur (current-buffer))
1421 (to (message-fetch-field "to")))
1422 ;; Get a normal message buffer.
1423 (message-pop-to-buffer (message-buffer-name "Resend" to))
1424 (insert-buffer-substring cur)
1425 (mime-to-mml)
1426 (message-narrow-to-head-1)
1427 ;; Gnus will generate a new one when sending.
1428 (message-remove-header "Message-ID")
1429 ;; Remove unwanted headers.
1430 (message-remove-header message-ignored-resent-headers t)
1431 (goto-char (point-max))
1432 (insert mail-header-separator)
1433 ;; Add Gcc header.
1434 (gnus-inews-insert-gcc)
1435 (goto-char (point-min))
1436 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1437 (forward-char 1))
1438 (widen)))))
1440 (defun gnus-summary-post-forward (&optional arg)
1441 "Forward the current article to a newsgroup.
1442 See `gnus-summary-mail-forward' for ARG."
1443 (interactive "P")
1444 (gnus-summary-mail-forward arg t))
1446 (defun gnus-summary-mail-crosspost-complaint (n)
1447 "Send a complaint about crossposting to the current article(s)."
1448 (interactive "P")
1449 (dolist (article (gnus-summary-work-articles n))
1450 (set-buffer gnus-summary-buffer)
1451 (gnus-summary-goto-subject article)
1452 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1453 newsgroups followup-to)
1454 (gnus-summary-select-article)
1455 (set-buffer gnus-original-article-buffer)
1456 (if (and (<= (length (message-tokenize-header
1457 (setq newsgroups
1458 (mail-fetch-field "newsgroups"))
1459 ", "))
1461 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1462 (not (member group (message-tokenize-header
1463 followup-to ", ")))))
1464 (if followup-to
1465 (gnus-message 1 "Followup-to restricted")
1466 (gnus-message 1 "Not a crossposted article"))
1467 (set-buffer gnus-summary-buffer)
1468 (gnus-summary-reply-with-original 1)
1469 (set-buffer gnus-message-buffer)
1470 (message-goto-body)
1471 (insert (format gnus-crosspost-complaint newsgroups group))
1472 (message-goto-subject)
1473 (re-search-forward " *$")
1474 (replace-match " (crosspost notification)" t t)
1475 (gnus-deactivate-mark)
1476 (when (gnus-y-or-n-p "Send this complaint? ")
1477 (message-send-and-exit))))))
1479 (defun gnus-inews-add-to-address (group)
1480 (let ((to-address (mail-fetch-field "to")))
1481 (when (and to-address
1482 (gnus-alive-p))
1483 ;; This mail group doesn't have a `to-list', so we add one
1484 ;; here. Magic!
1485 (when (gnus-y-or-n-p
1486 (format "Do you want to add this as `to-list': %s? " to-address))
1487 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1489 (defun gnus-article-mail (yank)
1490 "Send a reply to the address near point.
1491 If YANK is non-nil, include the original article."
1492 (interactive "P")
1493 (let ((address
1494 (buffer-substring
1495 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1496 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1497 (when address
1498 (gnus-msg-mail address)
1499 (when yank
1500 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1502 (defvar nntp-server-type)
1503 (defun gnus-bug ()
1504 "Send a bug report to the Gnus maintainers."
1505 (interactive)
1506 (unless (gnus-alive-p)
1507 (error "Gnus has been shut down"))
1508 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1509 (unless (message-mail-user-agent)
1510 (when gnus-bug-create-help-buffer
1511 (switch-to-buffer "*Gnus Help Bug*")
1512 (erase-buffer)
1513 (insert gnus-bug-message)
1514 (goto-char (point-min)))
1515 (message-pop-to-buffer "*Gnus Bug*"))
1516 (let ((message-this-is-mail t))
1517 (message-setup `((To . ,gnus-maintainer)
1518 (Subject . "")
1519 (X-Debbugs-Package
1520 . ,(format "%s" gnus-bug-package))
1521 (X-Debbugs-Version
1522 . ,(format "%s" (gnus-continuum-version))))))
1523 (when gnus-bug-create-help-buffer
1524 (push `(gnus-bug-kill-buffer) message-send-actions))
1525 (goto-char (point-min))
1526 (message-goto-body)
1527 (insert "\n\n\n\n\n")
1528 (insert (gnus-version) "\n"
1529 (emacs-version) "\n")
1530 (when (and (boundp 'nntp-server-type)
1531 (stringp nntp-server-type))
1532 (insert nntp-server-type))
1533 (goto-char (point-min))
1534 (search-forward "Subject: " nil t)
1535 (message "")))
1537 (defun gnus-bug-kill-buffer ()
1538 (when (get-buffer "*Gnus Help Bug*")
1539 (kill-buffer "*Gnus Help Bug*")))
1541 (defun gnus-summary-yank-message (buffer n)
1542 "Yank the current article into a composed message."
1543 (interactive
1544 (list (gnus-completing-read "Buffer" (message-buffers) t)
1545 current-prefix-arg))
1546 (gnus-summary-iterate n
1547 (let ((gnus-inhibit-treatment t))
1548 (gnus-summary-select-article))
1549 (with-current-buffer buffer
1550 (message-yank-buffer gnus-article-buffer))))
1552 ;;; Treatment of rejected articles.
1553 ;;; Bounced mail.
1555 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1556 "Re-mail the current message.
1557 This only makes sense if the current message is a bounce message that
1558 contains some mail you have written which has been bounced back to
1559 you.
1560 If FETCH, try to fetch the article that this is a reply to, if indeed
1561 this is a reply."
1562 (interactive "P")
1563 (gnus-summary-select-article t)
1564 (let (summary-buffer parent)
1565 (if fetch
1566 (progn
1567 (setq summary-buffer (current-buffer))
1568 (set-buffer gnus-original-article-buffer)
1569 (article-goto-body)
1570 (when (re-search-forward "^References:\n?" nil t)
1571 (while (memq (char-after) '(?\t ? ))
1572 (forward-line 1))
1573 (skip-chars-backward "\t\n ")
1574 (setq parent
1575 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1576 (set-buffer gnus-original-article-buffer))
1577 (gnus-setup-message 'compose-bounce
1578 (message-bounce)
1579 ;; Add Gcc header.
1580 (gnus-inews-insert-gcc)
1581 ;; If there are references, we fetch the article we answered to.
1582 (when parent
1583 (with-current-buffer summary-buffer
1584 (gnus-summary-refer-article parent)
1585 (gnus-summary-show-all-headers))))))
1587 ;;; Gcc handling.
1589 (defun gnus-inews-group-method (group)
1590 (cond
1591 ;; If the group doesn't exist, we assume
1592 ;; it's an archive group...
1593 ((and (null (gnus-get-info group))
1594 (eq (car (gnus-server-to-method gnus-message-archive-method))
1595 (car (gnus-server-to-method (gnus-group-method group)))))
1596 gnus-message-archive-method)
1597 ;; Use the method.
1598 ((gnus-info-method (gnus-get-info group))
1599 (gnus-info-method (gnus-get-info group)))
1600 ;; Find the method.
1601 (t (gnus-server-to-method (gnus-group-method group)))))
1603 ;; Do Gcc handling, which copied the message over to some group.
1604 (defun gnus-inews-do-gcc (&optional gcc)
1605 (interactive)
1606 (save-excursion
1607 (save-restriction
1608 (message-narrow-to-headers)
1609 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1610 (cur (current-buffer))
1611 groups group method group-art options
1612 mml-externalize-attachments)
1613 (when gcc
1614 (message-remove-header "gcc")
1615 (widen)
1616 (setq groups (message-unquote-tokens
1617 (message-tokenize-header gcc " ,")))
1618 ;; Copy the article over to some group(s).
1619 (while (setq group (pop groups))
1620 (setq method (gnus-inews-group-method group)
1621 group (mm-encode-coding-string
1622 group
1623 (gnus-group-name-charset method group)))
1624 (unless (gnus-check-server method)
1625 (error "Can't open server %s" (if (stringp method) method
1626 (car method))))
1627 (unless (gnus-request-group group t method)
1628 (gnus-request-create-group group method))
1629 (setq mml-externalize-attachments
1630 (if (stringp gnus-gcc-externalize-attachments)
1631 (string-match gnus-gcc-externalize-attachments group)
1632 gnus-gcc-externalize-attachments))
1633 (save-excursion
1634 (nnheader-set-temp-buffer " *acc*")
1635 (setq message-options (with-current-buffer cur message-options))
1636 (insert-buffer-substring cur)
1637 (run-hooks 'gnus-gcc-pre-body-encode-hook)
1638 (message-encode-message-body)
1639 (run-hooks 'gnus-gcc-post-body-encode-hook)
1640 (save-restriction
1641 (message-narrow-to-headers)
1642 (let* ((mail-parse-charset message-default-charset)
1643 (newsgroups-field (save-restriction
1644 (message-narrow-to-headers-or-head)
1645 (message-fetch-field "Newsgroups")))
1646 (followup-field (save-restriction
1647 (message-narrow-to-headers-or-head)
1648 (message-fetch-field "Followup-To")))
1649 ;; BUG: We really need to get the charset for
1650 ;; each name in the Newsgroups and Followup-To
1651 ;; lines to allow crossposting between group
1652 ;; names with incompatible character sets.
1653 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1654 (group-field-charset
1655 (gnus-group-name-charset
1656 method (or newsgroups-field "")))
1657 (followup-field-charset
1658 (gnus-group-name-charset
1659 method (or followup-field "")))
1660 (rfc2047-header-encoding-alist
1661 (append
1662 (when group-field-charset
1663 (list (cons "Newsgroups" group-field-charset)))
1664 (when followup-field-charset
1665 (list (cons "Followup-To" followup-field-charset)))
1666 rfc2047-header-encoding-alist)))
1667 (mail-encode-encoded-word-buffer)))
1668 (goto-char (point-min))
1669 (when (re-search-forward
1670 (concat "^" (regexp-quote mail-header-separator) "$")
1671 nil t)
1672 (replace-match "" t t ))
1673 (when (or (not (gnus-check-backend-function
1674 'request-accept-article group))
1675 (not (setq group-art
1676 (gnus-request-accept-article
1677 group method t t))))
1678 (gnus-message 1 "Couldn't store article in group %s: %s"
1679 group (gnus-status-message method)))
1680 (when (stringp method)
1681 (setq method (gnus-server-to-method method)))
1682 (when (and (listp method)
1683 (gnus-native-method-p method))
1684 (setq group (gnus-group-short-name group)))
1685 (when (and group-art
1686 ;; FIXME: Should gcc-mark-as-read work when
1687 ;; Gnus is not running?
1688 (gnus-alive-p))
1689 (if (or gnus-gcc-mark-as-read
1690 (and (boundp 'gnus-inews-mark-gcc-as-read)
1691 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1692 (gnus-group-mark-article-read group (cdr group-art))
1693 (with-current-buffer gnus-group-buffer
1694 (let ((gnus-group-marked (list group))
1695 (gnus-get-new-news-hook nil)
1696 (inhibit-read-only t))
1697 (gnus-group-get-new-news-this-group nil t)))))
1698 (setq options message-options)
1699 (with-current-buffer cur (setq message-options options))
1700 (kill-buffer (current-buffer)))))))))
1702 (defun gnus-inews-insert-gcc (&optional group)
1703 "Insert the Gcc to say where the article is to be archived."
1704 (let* ((group (or group gnus-newsgroup-name))
1705 (group (when group (gnus-group-decoded-name group)))
1706 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1707 (gcc-self-val
1708 (and group (gnus-group-find-parameter group 'gcc-self)))
1709 result
1710 (groups
1711 (cond
1712 ((null gnus-message-archive-method)
1713 ;; Ignore.
1714 nil)
1715 ((stringp var)
1716 ;; Just a single group.
1717 (list var))
1718 ((null var)
1719 ;; We don't want this.
1720 nil)
1721 ((and (listp var) (stringp (car var)))
1722 ;; A list of groups.
1723 var)
1724 ((functionp var)
1725 ;; A function.
1726 (funcall var group))
1727 (group
1728 ;; An alist of regexps/functions/forms.
1729 (while (and var
1730 (not
1731 (setq result
1732 (cond
1733 ((and group
1734 (stringp (caar var)))
1735 ;; Regexp.
1736 (when (string-match (caar var) group)
1737 (cdar var)))
1738 ((and group
1739 (functionp (car var)))
1740 ;; Function.
1741 (funcall (car var) group))
1743 (eval (car var)))))))
1744 (setq var (cdr var)))
1745 result)))
1746 name)
1747 (when (or groups gcc-self-val)
1748 (when (stringp groups)
1749 (setq groups (list groups)))
1750 (save-excursion
1751 (save-restriction
1752 (message-narrow-to-headers)
1753 (goto-char (point-max))
1754 (insert "Gcc: ")
1755 (if gcc-self-val
1756 ;; Use the `gcc-self' param value instead.
1757 (progn
1758 (insert
1759 (if (stringp gcc-self-val)
1760 (if (string-match " " gcc-self-val)
1761 (concat "\"" gcc-self-val "\"")
1762 gcc-self-val)
1763 ;; In nndoc groups, we use the parent group name
1764 ;; instead of the current group.
1765 (let ((group (or (gnus-group-find-parameter
1766 gnus-newsgroup-name 'parent-group)
1767 group)))
1768 (if (string-match " " group)
1769 (concat "\"" group "\"")
1770 group))))
1771 (if (not (eq gcc-self-val 'none))
1772 (insert "\n")
1773 (gnus-delete-line)))
1774 ;; Use the list of groups.
1775 (while (setq name (pop groups))
1776 (let ((str (if (string-match ":" name)
1777 name
1778 (gnus-group-prefixed-name
1779 name gnus-message-archive-method))))
1780 (insert (if (string-match " " str)
1781 (concat "\"" str "\"")
1782 str)))
1783 (when groups
1784 (insert " ")))
1785 (insert "\n")))))))
1787 (defun gnus-mailing-list-followup-to ()
1788 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1789 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1790 (list-post (gnus-fetch-original-field "list-post")))
1791 (when (and list-post
1792 (string-match "mailto:\\([^>]+\\)" list-post))
1793 (setq list-post (match-string 1 list-post)))
1794 (or list-post
1795 x-been-there)))
1797 ;;; Posting styles.
1799 (defun gnus-configure-posting-styles (&optional group-name)
1800 "Configure posting styles according to `gnus-posting-styles'."
1801 (unless gnus-inhibit-posting-styles
1802 (let ((group (or group-name gnus-newsgroup-name ""))
1803 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1804 (with-current-buffer gnus-summary-buffer
1805 gnus-posting-styles)
1806 gnus-posting-styles))
1807 style match attribute value v results
1808 filep name address element)
1809 ;; If the group has a posting-style parameter, add it at the end with a
1810 ;; regexp matching everything, to be sure it takes precedence over all
1811 ;; the others.
1812 (when gnus-newsgroup-name
1813 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1814 (when tmp-style
1815 (dolist (style tmp-style)
1816 (when (stringp (cadr style))
1817 (setcdr style (list (mm-decode-coding-string (cadr style)
1818 'utf-8)))))
1819 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1820 ;; Go through all styles and look for matches.
1821 (dolist (style styles)
1822 (setq match (pop style))
1823 (goto-char (point-min))
1824 (when (cond
1825 ((stringp match)
1826 ;; Regexp string match on the group name.
1827 (string-match match group))
1828 ((eq match 'header)
1829 ;; Obsolete format of header match.
1830 (and (gnus-buffer-live-p gnus-article-copy)
1831 (with-current-buffer gnus-article-copy
1832 (save-restriction
1833 (nnheader-narrow-to-headers)
1834 (let ((header (message-fetch-field (pop style))))
1835 (and header
1836 (string-match (pop style) header)))))))
1837 ((or (symbolp match)
1838 (functionp match))
1839 (cond
1840 ((functionp match)
1841 ;; Function to be called.
1842 (funcall match))
1843 ((boundp match)
1844 ;; Variable to be checked.
1845 (symbol-value match))))
1846 ((listp match)
1847 (cond
1848 ((eq (car match) 'header)
1849 ;; New format of header match.
1850 (and (gnus-buffer-live-p gnus-article-copy)
1851 (with-current-buffer gnus-article-copy
1852 (save-restriction
1853 (nnheader-narrow-to-headers)
1854 (let ((header (message-fetch-field (nth 1 match))))
1855 (and header
1856 (string-match (nth 2 match) header)))))))
1858 ;; This is a form to be evalled.
1859 (eval match)))))
1860 ;; We have a match, so we set the variables.
1861 (dolist (attribute style)
1862 (setq element (pop attribute)
1863 filep nil)
1864 (setq value
1865 (cond
1866 ((eq (car attribute) :file)
1867 (setq filep t)
1868 (cadr attribute))
1869 ((eq (car attribute) :value)
1870 (cadr attribute))
1872 (car attribute))))
1873 ;; We get the value.
1874 (setq v
1875 (cond
1876 ((stringp value)
1877 (if (and (stringp match)
1878 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1879 (match-beginning 1))
1880 (gnus-match-substitute-replacement value nil nil group)
1881 value))
1882 ((or (symbolp value)
1883 (functionp value))
1884 (cond ((functionp value)
1885 (funcall value))
1886 ((boundp value)
1887 (symbol-value value))))
1888 ((listp value)
1889 (eval value))))
1890 ;; Translate obsolescent value.
1891 (cond
1892 ((eq element 'signature-file)
1893 (setq element 'signature
1894 filep t))
1895 ((eq element 'x-face-file)
1896 (setq element 'x-face
1897 filep t)))
1898 ;; Post-processing for the signature posting-style:
1899 (and (eq element 'signature) filep
1900 message-signature-directory
1901 ;; don't actually use the signature directory
1902 ;; if message-signature-file contains a path.
1903 (not (file-name-directory v))
1904 (setq v (nnheader-concat message-signature-directory v)))
1905 ;; Get the contents of file elems.
1906 (when (and filep v)
1907 (setq v (with-temp-buffer
1908 (insert-file-contents v)
1909 (buffer-substring
1910 (point-min)
1911 (progn
1912 (goto-char (point-max))
1913 (if (zerop (skip-chars-backward "\n"))
1914 (point)
1915 (1+ (point))))))))
1916 (setq results (delq (assoc element results) results))
1917 (push (cons element v) results))))
1918 ;; Now we have all the styles, so we insert them.
1919 (setq name (assq 'name results)
1920 address (assq 'address results))
1921 (setq results (delq name (delq address results)))
1922 (gnus-make-local-hook 'message-setup-hook)
1923 (setq results (sort results (lambda (x y)
1924 (string-lessp (car x) (car y)))))
1925 (dolist (result results)
1926 (add-hook 'message-setup-hook
1927 (cond
1928 ((eq 'eval (car result))
1929 'ignore)
1930 ((eq 'body (car result))
1931 `(lambda ()
1932 (save-excursion
1933 (message-goto-body)
1934 (insert ,(cdr result)))))
1935 ((eq 'signature (car result))
1936 (set (make-local-variable 'message-signature) nil)
1937 (set (make-local-variable 'message-signature-file) nil)
1938 (if (not (cdr result))
1939 'ignore
1940 `(lambda ()
1941 (save-excursion
1942 (let ((message-signature ,(cdr result)))
1943 (when message-signature
1944 (message-insert-signature)))))))
1946 (let ((header
1947 (if (symbolp (car result))
1948 (capitalize (symbol-name (car result)))
1949 (car result))))
1950 `(lambda ()
1951 (save-excursion
1952 (message-remove-header ,header)
1953 (let ((value ,(cdr result)))
1954 (when value
1955 (message-goto-eoh)
1956 (insert ,header ": " value)
1957 (unless (bolp)
1958 (insert "\n")))))))))
1959 nil 'local))
1960 (when (or name address)
1961 (add-hook 'message-setup-hook
1962 `(lambda ()
1963 (set (make-local-variable 'user-mail-address)
1964 ,(or (cdr address) user-mail-address))
1965 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1966 (user-mail-address
1967 ,(or (cdr address) user-mail-address)))
1968 (save-excursion
1969 (message-remove-header "From")
1970 (message-goto-eoh)
1971 (insert "From: " (message-make-from) "\n"))))
1972 nil 'local)))))
1974 ;;; Allow redefinition of functions.
1976 (gnus-ems-redefine)
1978 (provide 'gnus-msg)
1980 ;;; gnus-msg.el ends here