1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2015 Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
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/>.
28 (eval-when-compile (require 'cl
))
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
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
)
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
67 :type
'(choice (const nil
)
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
80 :type
'(choice (regexp)
83 (defcustom gnus-add-to-list nil
84 "*If non-nil, add a `to-list' parameter automatically."
88 (defcustom gnus-crosspost-complaint
91 You posted the article below with the following Newsgroups header:
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.
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."
108 (defcustom gnus-message-setup-hook nil
109 "Hook run after setting up a message buffer."
111 :options
'(message-remove-blank-cited-lines)
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :link
'(custom-manual "(gnus)Posting Styles")
124 :type
'(repeat (cons (choice (regexp)
127 (string :tag
"Header")
128 (regexp :tag
"Regexp"))
132 (choice (const signature
)
133 (const signature-file
)
140 (string :tag
"Header"))
146 (defcustom gnus-gcc-mark-as-read nil
147 "If non-nil, automatically mark Gcc articles as read."
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."
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."
179 :type
'(choice (const none
) (const t
) string
(const nil
)
180 (const no-gcc-self
)))
182 (gnus-define-group-parameter
183 posting-charset-alist
186 "Return the permitted unencoded charsets for posting of GROUP."
187 :variable gnus-group-posting-charset-alist
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
))
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
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
208 '(repeat (list :tag
"Permitted unencoded charsets"
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"))
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"
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'."
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'."
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'."
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."
261 (defcustom gnus-message-replyencrypt t
262 "Automatically encrypt replies to encrypted messages.
263 See also the `mml-default-encrypt-method' variable."
268 (defcustom gnus-message-replysignencrypted
270 "Setting this causes automatically encrypted messages to also be signed."
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
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
283 :version
"23.1" ;; No Gnus (default changed)
285 :type
'(choice (const :tag
"No" nil
)
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."
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'."
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
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."
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."
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)
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
)
436 (nnir-article-number (or (car-safe gnus-article-reply
)
439 (,yanked gnus-article-yanked-articles
)
440 (,group
(if (and (gnus-nnir-group-p gnus-newsgroup-name
)
442 (nnir-article-group (or (car-safe gnus-article-reply
)
444 gnus-newsgroup-name
))
445 (message-header-setup-hook
446 (copy-sequence message-header-setup-hook
))
447 (mbl mml-buffer-list
)
448 (message-mode-hook (copy-sequence message-mode-hook
)))
449 (setq mml-buffer-list nil
)
450 (add-hook 'message-header-setup-hook
(lambda ()
451 (gnus-inews-insert-gcc ,group
)))
452 ;; message-newsreader and message-mailer were formerly set in
453 ;; gnus-inews-add-send-actions, but this is too late when
454 ;; message-generate-headers-first is used. --ansel
455 (add-hook 'message-mode-hook
457 (setq message-newsreader
458 (setq message-mailer
(gnus-extended-version)))))
459 ;; #### FIXME: for a reason that I did not manage to identify yet,
460 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
461 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
462 ;; After evaluation of @forms below, it gets the value we actually want
463 ;; to override, and the posting styles are used. For that reason, I've
464 ;; added an optional argument to `gnus-configure-posting-styles' to
465 ;; make sure that the correct value for the group name is used. -- drv
466 (add-hook 'message-mode-hook
467 (if (memq ,config
'(reply-yank reply
))
469 (gnus-configure-posting-styles ,group
))
471 ;; There may be an old " *gnus article copy*" buffer.
472 (let (gnus-article-copy)
473 (gnus-configure-posting-styles ,group
)))))
474 (gnus-alist-pull ',(intern gnus-draft-meta-information-header
)
475 message-required-headers
)
477 (not (string= ,group
"")))
479 (intern gnus-draft-meta-information-header
)
480 (gnus-inews-make-draft (or ,yanked
,article
)))
481 message-required-headers
))
485 (gnus-inews-add-send-actions ,winconf
,buffer
,article
,config
486 ,yanked
,winconf-name
)
487 (setq gnus-message-buffer
(current-buffer))
488 (set (make-local-variable 'gnus-message-group-art
)
489 (cons ,group
,article
))
490 (set (make-local-variable 'gnus-newsgroup-name
) ,group
)
491 ;; Enable highlighting of different citation levels
492 (when gnus-message-highlight-citation
493 (gnus-message-citation-mode 1))
494 (gnus-run-hooks 'gnus-message-setup-hook
)
495 (if (eq major-mode
'message-mode
)
496 (let ((mbl1 mml-buffer-list
))
497 (setq mml-buffer-list mbl
) ;; Global value
498 (set (make-local-variable 'mml-buffer-list
) mbl1
);; Local value
499 (gnus-make-local-hook 'kill-buffer-hook
)
500 (gnus-make-local-hook 'change-major-mode-hook
)
501 (add-hook 'change-major-mode-hook
'mml-destroy-buffers nil t
)
502 (add-hook 'kill-buffer-hook
'mml-destroy-buffers t t
))
503 (mml-destroy-buffers)
504 (setq mml-buffer-list mbl
)))
505 (message-hide-headers)
507 (gnus-configure-windows ,config t
)
508 (run-hooks 'post-command-hook
)
509 (set-buffer-modified-p nil
))))
511 (defun gnus-inews-make-draft-meta-information (group articles
)
512 (when (numberp articles
)
513 (setq articles
(list articles
)))
514 (concat "(\"" group
"\""
528 (defun gnus-msg-mail (&optional to subject other-headers continue
529 switch-action yank-action send-actions
531 "Start editing a mail message to be sent.
532 Like `message-mail', but with Gnus paraphernalia, particularly the
533 Gcc: header for archiving purposes.
534 If Gnus isn't running, a plain `message-mail' setup is used
537 (if (not (gnus-alive-p))
539 (message "Gnus not running; using plain Message mode")
540 (message-mail to subject other-headers continue
541 nil yank-action send-actions return-action
))
542 (let ((buf (current-buffer))
543 ;; Don't use posting styles corresponding to any existing group.
544 (group-name gnus-newsgroup-name
)
548 (setq gnus-newsgroup-name
"")
549 (gnus-setup-message 'message
550 (message-mail to subject other-headers continue
551 nil yank-action send-actions return-action
)))
552 (setq gnus-newsgroup-name group-name
))
554 (setq mail-buf
(current-buffer))
555 (switch-to-buffer buf
)
556 (apply switch-action mail-buf nil
))
557 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
561 (defun gnus-button-mailto (address)
563 (set-buffer (gnus-copy-article-buffer))
564 (gnus-setup-message 'message
565 (message-reply address
)))
568 (defun gnus-button-reply (&optional to-address wide
)
569 "Like `message-reply'."
571 (gnus-setup-message 'message
572 (message-reply to-address wide
)))
575 (define-mail-user-agent 'gnus-user-agent
576 'gnus-msg-mail
'message-send-and-exit
577 'message-kill-buffer
'message-send-hook
)
579 (defun gnus-setup-posting-charset (group)
580 (let ((alist gnus-group-posting-charset-alist
)
581 (group (or group
""))
585 (while (setq elem
(pop alist
))
586 (when (or (and (stringp (car elem
))
587 (string-match (car elem
) group
))
588 (and (functionp (car elem
))
589 (funcall (car elem
) group
))
590 (and (symbolp (car elem
))
591 (symbol-value (car elem
))))
592 (throw 'found
(cons (cadr elem
) (caddr elem
)))))))))
594 (defun gnus-inews-add-send-actions (winconf buffer article
595 &optional config yanked
597 (gnus-make-local-hook 'message-sent-hook
)
598 (add-hook 'message-sent-hook
(if gnus-agent
'gnus-agent-possibly-do-gcc
599 'gnus-inews-do-gcc
) nil t
)
601 (gnus-make-local-hook 'message-header-hook
)
602 (add-hook 'message-header-hook
'gnus-agent-possibly-save-gcc nil t
))
603 (setq message-post-method
604 `(lambda (&optional arg
)
605 (gnus-post-method arg
,gnus-newsgroup-name
)))
608 (setq gnus-current-window-configuration
',winconf-name
)
609 (when (gnus-buffer-exists-p ,buffer
)
610 (set-window-configuration ,winconf
)))
611 'exit
'postpone
'kill
)
612 (let ((to-be-marked (cond
615 (lambda (x) (if (listp x
) (car x
) x
)) yanked
))
616 (article (if (listp article
) article
(list article
)))
619 `(when (gnus-buffer-exists-p ,buffer
)
620 (with-current-buffer ,buffer
622 (if (eq config
'forward
)
623 `(gnus-summary-mark-article-as-forwarded ',to-be-marked
)
624 `(gnus-summary-mark-article-as-replied ',to-be-marked
)))))
627 (put 'gnus-setup-message
'lisp-indent-function
1)
628 (put 'gnus-setup-message
'edebug-form-spec
'(form body
))
630 ;;; Post news commands of Gnus group mode and summary mode
632 (defun gnus-group-mail (&optional arg
)
633 "Start composing a mail.
634 If ARG, use the group under the point to find a posting style.
635 If ARG is 1, prompt for a group name to find the posting style."
637 ;; We can't `let' gnus-newsgroup-name here, since that leads
638 ;; to local variables leaking.
639 (let ((group gnus-newsgroup-name
)
640 ;; make sure last viewed article doesn't affect posting styles:
642 (buffer (current-buffer)))
645 (setq gnus-newsgroup-name
647 (if (= 1 (prefix-numeric-value arg
))
648 (gnus-group-completing-read
649 "Use posting style of group"
650 nil
(gnus-read-active-file-p))
651 (gnus-group-group-name))
653 ;; #### see comment in gnus-setup-message -- drv
654 (gnus-setup-message 'message
(message-mail)))
655 (with-current-buffer buffer
656 (setq gnus-newsgroup-name group
)))))
658 (defun gnus-group-news (&optional arg
)
659 "Start composing a news.
660 If ARG, post to group under point.
661 If ARG is 1, prompt for group name to post to.
663 This function prepares a news even when using mail groups. This is useful
664 for posting messages to mail groups without actually sending them over the
665 network. The corresponding back end must have a 'request-post method."
667 ;; We can't `let' gnus-newsgroup-name here, since that leads
668 ;; to local variables leaking.
669 (let ((group gnus-newsgroup-name
)
670 ;; make sure last viewed article doesn't affect posting styles:
672 (buffer (current-buffer)))
675 (setq gnus-newsgroup-name
677 (if (= 1 (prefix-numeric-value arg
))
678 (gnus-group-completing-read "Use group"
680 (gnus-read-active-file-p))
681 (gnus-group-group-name))
683 ;; #### see comment in gnus-setup-message -- drv
684 (gnus-setup-message 'message
685 (message-news (gnus-group-real-name gnus-newsgroup-name
))))
686 (with-current-buffer buffer
687 (setq gnus-newsgroup-name group
)))))
689 (defun gnus-group-post-news (&optional arg
)
690 "Start composing a message (a news by default).
691 If ARG, post to group under point. If ARG is 1, prompt for group name.
692 Depending on the selected group, the message might be either a mail or
695 ;; Bind this variable here to make message mode hooks work ok.
696 (let ((gnus-newsgroup-name
698 (if (= 1 (prefix-numeric-value arg
))
699 (gnus-group-completing-read "Newsgroup" nil
700 (gnus-read-active-file-p))
701 (or (gnus-group-group-name) ""))
703 ;; make sure last viewed article doesn't affect posting styles:
705 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
706 (string= gnus-newsgroup-name
""))))
708 (defun gnus-summary-mail-other-window (&optional arg
)
709 "Start composing a mail in another window.
710 Use the posting of the current group by default.
711 If ARG, don't do that. If ARG is 1, prompt for group name to find the
714 ;; We can't `let' gnus-newsgroup-name here, since that leads
715 ;; to local variables leaking.
716 (let ((group gnus-newsgroup-name
)
717 ;; make sure last viewed article doesn't affect posting styles:
719 (buffer (current-buffer)))
722 (setq gnus-newsgroup-name
724 (if (= 1 (prefix-numeric-value arg
))
725 (gnus-group-completing-read "Use group"
727 (gnus-read-active-file-p))
729 gnus-newsgroup-name
))
730 ;; #### see comment in gnus-setup-message -- drv
731 (gnus-setup-message 'message
(message-mail)))
732 (with-current-buffer buffer
733 (setq gnus-newsgroup-name group
)))))
735 (defun gnus-summary-news-other-window (&optional arg
)
736 "Start composing a news in another window.
737 Post to the current group by default.
738 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
740 This function prepares a news even when using mail groups. This is useful
741 for posting messages to mail groups without actually sending them over the
742 network. The corresponding back end must have a 'request-post method."
744 ;; We can't `let' gnus-newsgroup-name here, since that leads
745 ;; to local variables leaking.
746 (let ((group gnus-newsgroup-name
)
747 ;; make sure last viewed article doesn't affect posting styles:
749 (buffer (current-buffer)))
752 (setq gnus-newsgroup-name
754 (if (= 1 (prefix-numeric-value arg
))
755 (gnus-group-completing-read "Use group"
757 (gnus-read-active-file-p))
759 gnus-newsgroup-name
))
760 ;; #### see comment in gnus-setup-message -- drv
761 (gnus-setup-message 'message
763 (message-news (gnus-group-real-name gnus-newsgroup-name
))
764 (set (make-local-variable 'gnus-discouraged-post-methods
)
766 (car (gnus-find-method-for-group gnus-newsgroup-name
))
767 gnus-discouraged-post-methods
)))))
768 (with-current-buffer buffer
769 (setq gnus-newsgroup-name group
)))))
771 (defun gnus-summary-post-news (&optional arg
)
772 "Start composing a message. Post to the current group by default.
773 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
774 Depending on the selected group, the message might be either a mail or
777 ;; Bind this variable here to make message mode hooks work ok.
778 (let ((gnus-newsgroup-name
780 (if (= 1 (prefix-numeric-value arg
))
781 (gnus-group-completing-read "Newsgroup" nil
782 (gnus-read-active-file-p))
784 gnus-newsgroup-name
))
785 ;; make sure last viewed article doesn't affect posting styles:
787 (gnus-post-news 'post gnus-newsgroup-name
)))
790 (defun gnus-summary-followup (yank &optional force-news
)
791 "Compose a followup to an article.
792 If prefix argument YANK is non-nil, the original article is yanked
794 YANK is a list of elements, where the car of each element is the
795 article number, and the cdr is the string to be yanked."
797 (list (and current-prefix-arg
798 (gnus-summary-work-articles 1))))
800 (gnus-summary-goto-subject
801 (if (listp (car yank
))
804 (save-window-excursion
805 (gnus-summary-select-article))
806 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
807 (gnus-newsgroup-name gnus-newsgroup-name
))
809 (gnus-post-news nil gnus-newsgroup-name
810 headers gnus-article-buffer
812 (gnus-summary-handle-replysign)))
814 (defun gnus-summary-followup-with-original (n &optional force-news
)
815 "Compose a followup to an article and include the original article.
816 The text in the region will be yanked. If the region isn't
817 active, the entire article will be yanked."
819 (gnus-summary-followup (gnus-summary-work-articles n
) force-news
))
821 (defun gnus-summary-followup-to-mail (&optional arg
)
822 "Followup to the current mail message via news."
824 (list (and current-prefix-arg
825 (gnus-summary-work-articles 1))))
826 (gnus-summary-followup arg t
))
828 (defun gnus-summary-followup-to-mail-with-original (&optional arg
)
829 "Followup to the current mail message via news."
831 (gnus-summary-followup (gnus-summary-work-articles arg
) t
))
833 (defun gnus-inews-yank-articles (articles)
834 (let (beg article yank-string
)
836 (while (setq article
(pop articles
))
837 (when (listp article
)
838 (setq yank-string
(nth 1 article
)
839 article
(nth 0 article
)))
840 (save-window-excursion
841 (set-buffer gnus-summary-buffer
)
842 (gnus-summary-select-article nil nil nil article
)
843 (gnus-summary-remove-process-mark article
))
844 (gnus-copy-article-buffer nil yank-string
)
845 (let ((message-reply-buffer gnus-article-copy
)
846 (message-reply-headers
847 ;; The headers are decoded.
848 (with-current-buffer gnus-article-copy
850 (nnheader-narrow-to-headers)
851 (nnheader-parse-naked-head)))))
852 (message-yank-original)
853 (message-exchange-point-and-mark)
854 (setq beg
(or beg
(mark t
))))
860 (defun gnus-summary-cancel-article (&optional n symp
)
861 "Cancel an article you posted.
862 Uses the process-prefix convention. If given the symbolic
863 prefix `a', cancel using the standard posting method; if not
864 post using the current select method."
865 (interactive (gnus-interactive "P\ny"))
866 (let ((message-post-method
868 (gnus-post-method (eq ',symp
'a
) ,gnus-newsgroup-name
)))
869 (custom-address user-mail-address
))
870 (dolist (article (gnus-summary-work-articles n
))
871 (when (gnus-summary-select-article t nil nil article
)
872 ;; Pretend that we're doing a followup so that we can see what
873 ;; the From header would have ended up being.
874 (save-window-excursion
876 (gnus-summary-followup nil
)
877 (let ((from (message-fetch-field "from")))
880 (car (mail-header-parse-address from
)))))
881 (kill-buffer (current-buffer))))
882 ;; Now cancel the article using the From header we got.
883 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
884 (let ((user-mail-address (or custom-address user-mail-address
)))
885 (message-cancel-news)))
886 (gnus-summary-mark-as-read article gnus-canceled-mark
)
887 (gnus-cache-remove-article 1))
888 (gnus-article-hide-headers-if-wanted))
889 (gnus-summary-remove-process-mark article
))))
891 (defun gnus-summary-supersede-article ()
892 "Compose an article that will supersede a previous article.
893 This is done simply by taking the old article and adding a Supersedes
894 header line with the old Message-ID."
896 (let ((article (gnus-summary-article-number))
897 (mail-parse-charset gnus-newsgroup-charset
))
898 (gnus-setup-message 'reply-yank
899 (gnus-summary-select-article t
)
900 (set-buffer gnus-original-article-buffer
)
904 (when (gnus-buffer-exists-p ,gnus-summary-buffer
)
905 (with-current-buffer ,gnus-summary-buffer
906 (gnus-cache-possibly-remove-article ,article nil nil nil t
)
907 (gnus-summary-mark-as-read ,article gnus-canceled-mark
)))))
908 message-send-actions
)
910 (gnus-inews-insert-gcc))))
914 (defun gnus-copy-article-buffer (&optional article-buffer yank-string
)
915 ;; make a copy of the article buffer with all text properties removed
916 ;; this copy is in the buffer gnus-article-copy.
917 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
918 ;; this buffer should be passed to all mail/news reply/post routines.
919 (setq gnus-article-copy
(gnus-get-buffer-create " *gnus article copy*"))
920 (with-current-buffer gnus-article-copy
921 (mm-enable-multibyte))
922 (let ((article-buffer (or article-buffer gnus-article-buffer
))
924 (if (not (and (get-buffer article-buffer
)
925 (gnus-buffer-exists-p article-buffer
)))
926 (error "Can't find any article buffer")
927 (with-current-buffer article-buffer
928 (let ((gnus-newsgroup-charset (or gnus-article-charset
929 gnus-newsgroup-charset
))
930 (inhibit-read-only t
)
931 (gnus-newsgroup-ignored-charsets
932 (or gnus-article-ignored-charsets
933 gnus-newsgroup-ignored-charsets
)))
935 ;; Copy over the (displayed) article buffer, delete
936 ;; hidden text and remove text properties.
938 (copy-to-buffer gnus-article-copy
(point-min) (point-max))
939 (set-buffer gnus-article-copy
)
942 (delete-region (point) (point-max))
943 (insert yank-string
))
944 (gnus-article-delete-text-of-type 'annotation
)
945 (gnus-article-delete-text-of-type 'multipart
)
946 (gnus-remove-text-with-property 'gnus-prev
)
947 (gnus-remove-text-with-property 'gnus-next
)
948 (gnus-remove-text-with-property 'gnus-decoration
)
951 (buffer-substring-no-properties (point-min) (point-max))
953 ;; Find the original headers.
954 (set-buffer gnus-original-article-buffer
)
955 (goto-char (point-min))
956 (while (looking-at message-unix-mail-delimiter
)
958 (let ((mail-header-separator ""))
960 end
(or (message-goto-body)
961 ;; There may be just a header.
963 ;; Delete the headers from the displayed articles.
964 (set-buffer gnus-article-copy
)
965 (let ((mail-header-separator ""))
966 (delete-region (goto-char (point-min))
967 (or (message-goto-body) (point-max))))
968 ;; Insert the original article headers.
969 (insert-buffer-substring gnus-original-article-buffer beg end
)
971 (let ((gnus-article-decode-hook
972 (delq 'article-decode-charset
973 (copy-sequence gnus-article-decode-hook
)))
974 (rfc2047-quote-decoded-words-containing-tspecials t
))
975 (run-hooks 'gnus-article-decode-hook
)))))
978 (defun gnus-post-news (post &optional group header article-buffer yank subject
981 (gnus-copy-article-buffer))
982 (let ((gnus-article-reply (and article-buffer
(gnus-summary-article-number)))
983 (gnus-article-yanked-articles yank
)
984 (add-to-list gnus-add-to-list
))
985 (gnus-setup-message (cond (yank 'reply-yank
)
986 (article-buffer 'reply
)
988 (let* ((group (or group gnus-newsgroup-name
))
989 (charset (gnus-group-name-charset nil group
))
991 to-address to-group mailing-list to-list
994 (setq to-address
(gnus-parameter-to-address group
)
995 to-group
(gnus-group-find-parameter group
'to-group
)
996 to-list
(gnus-parameter-to-list group
)
997 newsgroup-p
(gnus-group-find-parameter group
'newsgroup
)
998 mailing-list
(when gnus-mailing-list-groups
999 (string-match gnus-mailing-list-groups group
))
1000 group
(gnus-group-name-decode (gnus-group-real-name group
)
1002 (if (or (and to-group
1003 (gnus-news-group-p to-group
))
1006 (and (gnus-news-group-p
1007 (or pgroup gnus-newsgroup-name
)
1008 (or header gnus-current-article
))
1016 (and (not (gnus-virtual-group-p pgroup
)) group
)))
1017 (set-buffer gnus-article-copy
)
1018 (gnus-msg-treat-broken-reply-to)
1019 (message-followup (if (or newsgroup-p force-news
)
1020 (if (save-restriction
1021 (article-narrow-to-head)
1022 (message-fetch-field "newsgroups"))
1029 (message-mail (or to-address to-list
))
1030 ;; Arrange for mail groups that have no `to-address' to
1031 ;; get that when the user sends off the mail.
1032 (when (and (not to-list
)
1035 (push (list 'gnus-inews-add-to-address pgroup
)
1036 message-send-actions
)))
1037 (set-buffer gnus-article-copy
)
1038 (gnus-msg-treat-broken-reply-to)
1039 (message-wide-reply to-address
)))
1041 (gnus-inews-yank-articles yank
))))))
1043 (defun gnus-msg-treat-broken-reply-to (&optional force
)
1044 "Remove the Reply-to header if broken-reply-to."
1046 (gnus-group-find-parameter
1047 gnus-newsgroup-name
'broken-reply-to
))
1049 (message-narrow-to-head)
1050 (message-remove-header "reply-to"))))
1052 (defun gnus-post-method (arg group
&optional silent
)
1053 "Return the posting method based on GROUP and ARG.
1054 If SILENT, don't prompt the user."
1055 (let ((gnus-post-method (or (gnus-parameter-post-method group
)
1057 (group-method (gnus-find-method-for-group group
)))
1059 ;; If the group-method is nil (which shouldn't happen) we use
1060 ;; the default method.
1061 ((null group-method
)
1062 (or (and (listp gnus-post-method
) ;If not current/native/nil
1063 (not (listp (car gnus-post-method
))) ; and not a list of methods
1064 gnus-post-method
) ;then use it.
1066 message-post-method
))
1067 ;; We want the inverse of the default
1068 ((and arg
(not (eq arg
0)))
1069 (if (eq gnus-post-method
'current
)
1072 ;; We query the user for a post method.
1074 (and (listp gnus-post-method
)
1075 (listp (car gnus-post-method
))))
1077 ;; Collect all methods we know about.
1079 (when (listp gnus-post-method
)
1080 (if (listp (car gnus-post-method
))
1082 (list gnus-post-method
)))
1083 gnus-secondary-select-methods
1084 (mapcar 'cdr gnus-server-alist
)
1085 (mapcar 'car gnus-opened-servers
)
1086 (list gnus-select-method
)
1087 (list group-method
)))
1088 method-alist post-methods method
)
1089 ;; Weed out all mail methods.
1091 (setq method
(gnus-server-get-method "" (pop methods
)))
1092 (when (and (or (gnus-method-option-p method
'post
)
1093 (gnus-method-option-p method
'post-mail
))
1094 (not (member method post-methods
)))
1095 (push method post-methods
)))
1096 ;; Create a name-method alist.
1100 (if (equal (cadr m
) "")
1101 (list (symbol-name (car m
)) m
)
1102 (list (concat (cadr m
) " (" (symbol-name (car m
)) ")") m
)))
1107 (setq gnus-last-posting-server
1109 gnus-last-posting-server
)
1110 ;; Just use the last value.
1111 gnus-last-posting-server
1112 (gnus-completing-read
1113 "Posting method" (mapcar 'car method-alist
) t
1114 (cons (or gnus-last-posting-server
"") 0))))
1116 ;; Override normal method.
1117 ((and (eq gnus-post-method
'current
)
1118 (not (memq (car group-method
) gnus-discouraged-post-methods
))
1119 (gnus-get-function group-method
'request-post t
))
1122 ;; Use gnus-post-method.
1123 ((listp gnus-post-method
) ;A method...
1124 (assert (not (listp (car gnus-post-method
)))) ;... not a list of methods.
1126 ;; Use the normal select method (nil or native).
1127 (t gnus-select-method
))))
1131 (defun gnus-extended-version ()
1132 "Stringified Gnus version and Emacs version.
1133 See the variable `gnus-user-agent'."
1135 (if (stringp gnus-user-agent
)
1137 ;; `gnus-user-agent' is a list:
1138 (let* ((float-output-format nil
)
1140 (when (memq 'gnus gnus-user-agent
)
1142 (gnus-replace-in-string
1143 (format "%1.8f" (gnus-continuum-version gnus-version
))
1145 " (" gnus-version
")")))
1146 (emacs-v (gnus-emacs-version)))
1147 (concat gnus-v
(when (and gnus-v emacs-v
) " ")
1152 ;;; Gnus Mail Functions
1155 ;;; Mail reply commands of Gnus summary mode
1157 (defun gnus-summary-reply (&optional yank wide very-wide
)
1158 "Start composing a mail reply to the current message.
1159 If prefix argument YANK is non-nil, the original article is yanked
1161 If WIDE, make a wide reply.
1162 If VERY-WIDE, make a very wide reply."
1164 (list (and current-prefix-arg
1165 (gnus-summary-work-articles 1))))
1166 ;; Allow user to require confirmation before replying by mail to the
1167 ;; author of a news article (or mail message).
1168 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name
)
1169 gnus-confirm-treat-mail-like-news
))
1170 (not (cond ((stringp gnus-confirm-mail-reply-to-news
)
1171 (string-match gnus-confirm-mail-reply-to-news
1172 gnus-newsgroup-name
))
1173 ((functionp gnus-confirm-mail-reply-to-news
)
1174 (funcall gnus-confirm-mail-reply-to-news
1175 gnus-newsgroup-name
))
1176 (t gnus-confirm-mail-reply-to-news
)))
1177 (if (or wide very-wide
)
1178 t
;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1180 (y-or-n-p "Really reply by mail to article author? ")))
1182 (if (listp (car yank
))
1185 (gnus-article-reply (or article
(gnus-summary-article-number)))
1186 (gnus-article-yanked-articles yank
)
1188 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1190 (gnus-summary-goto-subject article
))
1191 (gnus-setup-message (if yank
'reply-yank
'reply
)
1193 (gnus-summary-select-article)
1194 (dolist (article very-wide
)
1195 (gnus-summary-select-article nil nil nil article
)
1196 (with-current-buffer (gnus-copy-article-buffer)
1197 (gnus-msg-treat-broken-reply-to)
1199 (message-narrow-to-head)
1200 (setq headers
(concat headers
(buffer-string)))))))
1201 (set-buffer (gnus-copy-article-buffer))
1202 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to
)
1204 (message-narrow-to-head)
1208 (goto-char (point-max)))
1209 (mml-quote-region (point) (point-max))
1210 (message-reply nil wide
)
1212 (gnus-inews-yank-articles yank
))
1213 (gnus-summary-handle-replysign)))))
1215 (defun gnus-summary-handle-replysign ()
1216 "Check the various replysign variables and take action accordingly."
1217 (when (or gnus-message-replysign gnus-message-replyencrypt
)
1218 (let (signed encrypted
)
1219 (with-current-buffer gnus-article-buffer
1220 (setq signed
(memq 'signed gnus-article-wash-types
))
1221 (setq encrypted
(memq 'encrypted gnus-article-wash-types
)))
1222 (cond ((and gnus-message-replyencrypt encrypted
)
1223 (mml-secure-message mml-default-encrypt-method
1224 (if gnus-message-replysignencrypted
1227 ((and gnus-message-replysign signed
)
1228 (mml-secure-message mml-default-sign-method
'sign
))))))
1230 (defun gnus-summary-reply-with-original (n &optional wide
)
1231 "Start composing a reply mail to the current message.
1232 The original article will be yanked."
1234 (gnus-summary-reply (gnus-summary-work-articles n
) wide
))
1236 (defun gnus-summary-reply-to-list-with-original (n &optional wide
)
1237 "Start composing a reply mail to the current message.
1238 The reply goes only to the mailing list.
1239 The original article will be yanked."
1241 (let ((message-reply-to-function
1243 `((To .
,(gnus-mailing-list-followup-to))))))
1244 (gnus-summary-reply (gnus-summary-work-articles n
) wide
)))
1246 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide
)
1247 "Like `gnus-summary-reply' except removing reply-to field.
1248 If prefix argument YANK is non-nil, the original article is yanked
1250 If WIDE, make a wide reply.
1251 If VERY-WIDE, make a very wide reply."
1253 (list (and current-prefix-arg
1254 (gnus-summary-work-articles 1))))
1255 (let ((gnus-msg-force-broken-reply-to t
))
1256 (gnus-summary-reply yank wide very-wide
)))
1258 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide
)
1259 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1260 The original article will be yanked."
1262 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n
) wide
))
1264 (defun gnus-summary-wide-reply (&optional yank
)
1265 "Start composing a wide reply mail to the current message.
1266 If prefix argument YANK is non-nil, the original article is yanked
1269 (list (and current-prefix-arg
1270 (gnus-summary-work-articles 1))))
1271 (gnus-summary-reply yank t
))
1273 (defun gnus-summary-wide-reply-with-original (n)
1274 "Start composing a wide reply mail to the current message.
1275 The original article will be yanked.
1276 Uses the process/prefix convention."
1278 (gnus-summary-reply-with-original n t
))
1280 (defun gnus-summary-very-wide-reply (&optional yank
)
1281 "Start composing a very wide reply mail to the current message.
1282 If prefix argument YANK is non-nil, the original article is yanked
1285 (list (and current-prefix-arg
1286 (gnus-summary-work-articles 1))))
1287 (gnus-summary-reply yank t
(gnus-summary-work-articles yank
)))
1289 (defun gnus-summary-very-wide-reply-with-original (n)
1290 "Start composing a very wide reply mail to the current message.
1291 The original article will be yanked."
1294 (gnus-summary-work-articles n
) t
(gnus-summary-work-articles n
)))
1296 (defun gnus-summary-mail-forward (&optional arg post
)
1297 "Forward the current message(s) to another user.
1298 If process marks exist, forward all marked messages;
1299 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1300 if ARG is 1, decode the message and forward directly inline;
1301 if ARG is 2, forward message as an rfc822 MIME section;
1302 if ARG is 3, decode message and forward as an rfc822 MIME section;
1303 if ARG is 4, forward message directly inline;
1304 otherwise, use flipped `message-forward-as-mime'.
1305 If POST, post instead of mail.
1306 For the \"inline\" alternatives, also see the variable
1307 `message-forward-ignored-headers'."
1309 (if (cdr (gnus-summary-work-articles nil
))
1310 ;; Process marks are given.
1311 (gnus-uu-digest-mail-forward nil post
)
1312 ;; No process marks.
1313 (let ((message-forward-as-mime message-forward-as-mime
)
1314 (message-forward-show-mml message-forward-show-mml
))
1318 (setq message-forward-as-mime nil
1319 message-forward-show-mml t
))
1321 (setq message-forward-as-mime t
1322 message-forward-show-mml nil
))
1324 (setq message-forward-as-mime t
1325 message-forward-show-mml t
))
1327 (setq message-forward-as-mime nil
1328 message-forward-show-mml nil
))
1330 (setq message-forward-as-mime
(not message-forward-as-mime
))))
1331 (let* ((gnus-article-reply (gnus-summary-article-number))
1332 (gnus-article-yanked-articles (list gnus-article-reply
)))
1333 (gnus-setup-message 'forward
1334 (gnus-summary-select-article)
1335 (let ((mail-parse-charset
1336 (or (and (gnus-buffer-live-p gnus-article-buffer
)
1337 (with-current-buffer gnus-article-buffer
1338 gnus-article-charset
))
1339 gnus-newsgroup-charset
))
1340 (mail-parse-ignored-charsets
1341 gnus-newsgroup-ignored-charsets
))
1342 (set-buffer gnus-original-article-buffer
)
1343 (message-forward post
)))))))
1345 (defun gnus-summary-resend-message-insert-gcc ()
1346 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1347 (gnus-inews-insert-gcc)
1350 (mm-encode-coding-string
1352 (gnus-group-name-charset (gnus-inews-group-method group
)
1354 (message-unquote-tokens
1355 (message-tokenize-header (mail-fetch-field "gcc" nil t
)
1357 (self (with-current-buffer gnus-summary-buffer
1358 gnus-gcc-self-resent-messages
)))
1359 (message-remove-header "gcc")
1361 (goto-char (point-max))
1362 (cond ((eq self
'none
))
1364 (insert "Gcc: \"" gnus-newsgroup-name
"\"\n"))
1367 (mm-encode-coding-string
1368 (if (string-match " " self
)
1369 (concat "\"" self
"\"")
1371 (gnus-group-name-charset (gnus-inews-group-method self
)
1375 (insert "Gcc: " (mapconcat 'identity gcc
", ") "\n"))
1376 ((eq self
'no-gcc-self
)
1377 (when (setq gcc
(delete
1379 (delete (concat "\"" gnus-newsgroup-name
"\"")
1381 (insert "Gcc: " (mapconcat 'identity gcc
", ") "\n")))))))
1383 (defun gnus-summary-resend-message (address n
)
1384 "Resend the current article to ADDRESS."
1386 (list (message-read-from-minibuffer
1387 "Resend message(s) to: "
1388 (when (and gnus-summary-resend-default-address
1389 (gnus-buffer-live-p gnus-original-article-buffer
))
1390 ;; If some other article is currently selected, the
1391 ;; initial-contents is wrong. Whatever, it is just the
1392 ;; initial-contents.
1393 (with-current-buffer gnus-original-article-buffer
1394 (nnmail-fetch-field "to"))))
1395 current-prefix-arg
))
1396 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook
))
1397 (message-sent-hook (copy-sequence message-sent-hook
))
1398 ;; Honor posting-style for `name' and `address' in Resent-From header.
1399 (styles (gnus-group-find-parameter gnus-newsgroup-name
1401 (user-full-name user-full-name
)
1402 (user-mail-address user-mail-address
)
1404 (dolist (style styles
)
1405 (when (stringp (cadr style
))
1406 (setcdr style
(list (mm-decode-coding-string (cadr style
) 'utf-8
)))))
1407 (dolist (style (if styles
1408 (append gnus-posting-styles
(list (cons ".*" styles
)))
1409 gnus-posting-styles
))
1410 (when (and (stringp (car style
))
1411 (string-match (pop style
) gnus-newsgroup-name
))
1412 (when (setq tem
(cadr (assq 'name style
)))
1413 (setq user-full-name tem
))
1414 (when (setq tem
(cadr (assq 'address style
)))
1415 (setq user-mail-address tem
))))
1416 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1417 (add-hook 'message-header-setup-hook
1418 'gnus-summary-resend-message-insert-gcc t
)
1419 (add-hook 'message-sent-hook
1421 (let ((rfc2047-encode-encoded-words nil
))
1423 '(gnus-agent-possibly-do-gcc)
1424 '(gnus-inews-do-gcc)))))
1425 (dolist (article (gnus-summary-work-articles n
))
1426 (gnus-summary-select-article nil nil nil article
)
1427 (with-current-buffer gnus-original-article-buffer
1428 (let ((gnus-gcc-externalize-attachments nil
)
1429 (message-inhibit-body-encoding t
))
1430 (message-resend address
)))
1431 (gnus-summary-mark-article-as-forwarded article
))))
1433 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1434 (defun gnus-summary-resend-message-edit ()
1435 "Resend an article that has already been sent.
1436 A new buffer will be created to allow the user to modify body and
1437 contents of the message, and then, everything will happen as when
1438 composing a new message."
1440 (let ((mail-parse-charset gnus-newsgroup-charset
))
1441 (gnus-setup-message 'reply-yank
1442 (gnus-summary-select-article t
)
1443 (set-buffer gnus-original-article-buffer
)
1444 (let ((cur (current-buffer))
1445 (to (message-fetch-field "to")))
1446 ;; Get a normal message buffer.
1447 (message-pop-to-buffer (message-buffer-name "Resend" to
))
1448 (insert-buffer-substring cur
)
1450 (message-narrow-to-head-1)
1451 ;; Gnus will generate a new one when sending.
1452 (message-remove-header "Message-ID")
1453 ;; Remove unwanted headers.
1454 (message-remove-header message-ignored-resent-headers t
)
1455 (goto-char (point-max))
1456 (insert mail-header-separator
)
1458 (gnus-inews-insert-gcc)
1459 (goto-char (point-min))
1460 (when (re-search-forward "^To:\\|^Newsgroups:" nil
'move
)
1464 (defun gnus-summary-post-forward (&optional arg
)
1465 "Forward the current article to a newsgroup.
1466 See `gnus-summary-mail-forward' for ARG."
1468 (gnus-summary-mail-forward arg t
))
1470 (defun gnus-summary-mail-crosspost-complaint (n)
1471 "Send a complaint about crossposting to the current article(s)."
1473 (dolist (article (gnus-summary-work-articles n
))
1474 (set-buffer gnus-summary-buffer
)
1475 (gnus-summary-goto-subject article
)
1476 (let ((group (gnus-group-real-name gnus-newsgroup-name
))
1477 newsgroups followup-to
)
1478 (gnus-summary-select-article)
1479 (set-buffer gnus-original-article-buffer
)
1480 (if (and (<= (length (message-tokenize-header
1482 (mail-fetch-field "newsgroups"))
1485 (or (not (setq followup-to
(mail-fetch-field "followup-to")))
1486 (not (member group
(message-tokenize-header
1487 followup-to
", ")))))
1489 (gnus-message 1 "Followup-to restricted")
1490 (gnus-message 1 "Not a crossposted article"))
1491 (set-buffer gnus-summary-buffer
)
1492 (gnus-summary-reply-with-original 1)
1493 (set-buffer gnus-message-buffer
)
1495 (insert (format gnus-crosspost-complaint newsgroups group
))
1496 (message-goto-subject)
1497 (re-search-forward " *$")
1498 (replace-match " (crosspost notification)" t t
)
1499 (gnus-deactivate-mark)
1500 (when (gnus-y-or-n-p "Send this complaint? ")
1501 (message-send-and-exit))))))
1503 (defun gnus-inews-add-to-address (group)
1504 (let ((to-address (mail-fetch-field "to")))
1505 (when (and to-address
1507 ;; This mail group doesn't have a `to-list', so we add one
1509 (when (gnus-y-or-n-p
1510 (format "Do you want to add this as `to-list': %s? " to-address
))
1511 (gnus-group-add-parameter group
(cons 'to-list to-address
))))))
1513 (defun gnus-article-mail (yank)
1514 "Send a reply to the address near point.
1515 If YANK is non-nil, include the original article."
1519 (save-excursion (re-search-backward "[ \t\n]" nil t
) (1+ (point)))
1520 (save-excursion (re-search-forward "[ \t\n]" nil t
) (1- (point))))))
1522 (gnus-msg-mail address
)
1524 (gnus-inews-yank-articles (list (cdr gnus-article-current
)))))))
1526 (defvar nntp-server-type
)
1528 "Send a bug report to the Gnus maintainers."
1530 (unless (gnus-alive-p)
1531 (error "Gnus has been shut down"))
1532 (gnus-setup-message (if (message-mail-user-agent) 'message
'bug
)
1533 (unless (message-mail-user-agent)
1534 (when gnus-bug-create-help-buffer
1535 (switch-to-buffer "*Gnus Help Bug*")
1537 (insert gnus-bug-message
)
1538 (goto-char (point-min)))
1539 (message-pop-to-buffer "*Gnus Bug*"))
1540 (let ((message-this-is-mail t
))
1541 (message-setup `((To .
,gnus-maintainer
)
1544 .
,(format "%s" gnus-bug-package
))
1546 .
,(format "%s" (gnus-continuum-version))))))
1547 (when gnus-bug-create-help-buffer
1548 (push `(gnus-bug-kill-buffer) message-send-actions
))
1549 (goto-char (point-min))
1551 (insert "\n\n\n\n\n")
1552 (insert (gnus-version) "\n"
1553 (emacs-version) "\n")
1554 (when (and (boundp 'nntp-server-type
)
1555 (stringp nntp-server-type
))
1556 (insert nntp-server-type
))
1557 (goto-char (point-min))
1558 (search-forward "Subject: " nil t
)
1561 (defun gnus-bug-kill-buffer ()
1562 (when (get-buffer "*Gnus Help Bug*")
1563 (kill-buffer "*Gnus Help Bug*")))
1565 (defun gnus-summary-yank-message (buffer n
)
1566 "Yank the current article into a composed message."
1568 (list (gnus-completing-read "Buffer" (message-buffers) t
)
1569 current-prefix-arg
))
1570 (gnus-summary-iterate n
1571 (let ((gnus-inhibit-treatment t
))
1572 (gnus-summary-select-article))
1573 (with-current-buffer buffer
1574 (message-yank-buffer gnus-article-buffer
))))
1576 ;;; Treatment of rejected articles.
1579 (defun gnus-summary-resend-bounced-mail (&optional fetch
)
1580 "Re-mail the current message.
1581 This only makes sense if the current message is a bounce message that
1582 contains some mail you have written which has been bounced back to
1584 If FETCH, try to fetch the article that this is a reply to, if indeed
1587 (gnus-summary-select-article t
)
1588 (let (summary-buffer parent
)
1591 (setq summary-buffer
(current-buffer))
1592 (set-buffer gnus-original-article-buffer
)
1594 (when (re-search-forward "^References:\n?" nil t
)
1595 (while (memq (char-after) '(?
\t ?
))
1597 (skip-chars-backward "\t\n ")
1599 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1600 (set-buffer gnus-original-article-buffer
))
1601 (gnus-setup-message 'compose-bounce
1604 (gnus-inews-insert-gcc)
1605 ;; If there are references, we fetch the article we answered to.
1607 (with-current-buffer summary-buffer
1608 (gnus-summary-refer-article parent
)
1609 (gnus-summary-show-all-headers))))))
1613 (defun gnus-inews-group-method (group)
1615 ;; If the group doesn't exist, we assume
1616 ;; it's an archive group...
1617 ((and (null (gnus-get-info group
))
1618 (eq (car (gnus-server-to-method gnus-message-archive-method
))
1619 (car (gnus-server-to-method (gnus-group-method group
)))))
1620 gnus-message-archive-method
)
1622 ((gnus-info-method (gnus-get-info group
))
1623 (gnus-info-method (gnus-get-info group
)))
1625 (t (gnus-server-to-method (gnus-group-method group
)))))
1627 ;; Do Gcc handling, which copied the message over to some group.
1628 (defun gnus-inews-do-gcc (&optional gcc
)
1632 (message-narrow-to-headers)
1633 (let ((gcc (or gcc
(mail-fetch-field "gcc" nil t
)))
1634 (cur (current-buffer))
1635 groups group method group-art options
1636 mml-externalize-attachments
)
1638 (message-remove-header "gcc")
1640 (setq groups
(message-unquote-tokens
1641 (message-tokenize-header gcc
" ,")))
1642 ;; Copy the article over to some group(s).
1643 (while (setq group
(pop groups
))
1644 (setq method
(gnus-inews-group-method group
)
1645 group
(mm-encode-coding-string
1647 (gnus-group-name-charset method group
)))
1648 (unless (gnus-check-server method
)
1649 (error "Can't open server %s" (if (stringp method
) method
1651 (unless (gnus-request-group group t method
)
1652 (gnus-request-create-group group method
))
1653 (setq mml-externalize-attachments
1654 (if (stringp gnus-gcc-externalize-attachments
)
1655 (string-match gnus-gcc-externalize-attachments group
)
1656 gnus-gcc-externalize-attachments
))
1658 (nnheader-set-temp-buffer " *acc*")
1659 (setq message-options
(with-current-buffer cur message-options
))
1660 (insert-buffer-substring cur
)
1661 (run-hooks 'gnus-gcc-pre-body-encode-hook
)
1662 (message-encode-message-body)
1663 (run-hooks 'gnus-gcc-post-body-encode-hook
)
1665 (message-narrow-to-headers)
1666 (let* ((mail-parse-charset message-default-charset
)
1667 (newsgroups-field (save-restriction
1668 (message-narrow-to-headers-or-head)
1669 (message-fetch-field "Newsgroups")))
1670 (followup-field (save-restriction
1671 (message-narrow-to-headers-or-head)
1672 (message-fetch-field "Followup-To")))
1673 ;; BUG: We really need to get the charset for
1674 ;; each name in the Newsgroups and Followup-To
1675 ;; lines to allow crossposting between group
1676 ;; names with incompatible character sets.
1677 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1678 (group-field-charset
1679 (gnus-group-name-charset
1680 method
(or newsgroups-field
"")))
1681 (followup-field-charset
1682 (gnus-group-name-charset
1683 method
(or followup-field
"")))
1684 (rfc2047-header-encoding-alist
1686 (when group-field-charset
1687 (list (cons "Newsgroups" group-field-charset
)))
1688 (when followup-field-charset
1689 (list (cons "Followup-To" followup-field-charset
)))
1690 rfc2047-header-encoding-alist
)))
1691 (mail-encode-encoded-word-buffer)))
1692 (goto-char (point-min))
1693 (when (re-search-forward
1694 (concat "^" (regexp-quote mail-header-separator
) "$")
1696 (replace-match "" t t
))
1697 (when (or (not (gnus-check-backend-function
1698 'request-accept-article group
))
1699 (not (setq group-art
1700 (gnus-request-accept-article
1701 group method t t
))))
1702 (gnus-message 1 "Couldn't store article in group %s: %s"
1703 group
(gnus-status-message method
)))
1704 (when (stringp method
)
1705 (setq method
(gnus-server-to-method method
)))
1706 (when (and (listp method
)
1707 (gnus-native-method-p method
))
1708 (setq group
(gnus-group-short-name group
)))
1709 (when (and group-art
1710 ;; FIXME: Should gcc-mark-as-read work when
1711 ;; Gnus is not running?
1713 (if (or gnus-gcc-mark-as-read
1714 (and (boundp 'gnus-inews-mark-gcc-as-read
)
1715 (symbol-value 'gnus-inews-mark-gcc-as-read
)))
1716 (gnus-group-mark-article-read group
(cdr group-art
))
1717 (with-current-buffer gnus-group-buffer
1718 (let ((gnus-group-marked (list group
))
1719 (gnus-get-new-news-hook nil
)
1720 (inhibit-read-only t
))
1721 (gnus-group-get-new-news-this-group nil t
)))))
1722 (setq options message-options
)
1723 (with-current-buffer cur
(setq message-options options
))
1724 (kill-buffer (current-buffer)))))))))
1726 (defun gnus-inews-insert-gcc (&optional group
)
1727 "Insert the Gcc to say where the article is to be archived."
1728 (let* ((group (or group gnus-newsgroup-name
))
1729 (group (when group
(gnus-group-decoded-name group
)))
1730 (var (or gnus-outgoing-message-group gnus-message-archive-group
))
1732 (and group
(not (gnus-virtual-group-p group
))
1733 (gnus-group-find-parameter group
'gcc-self t
)))
1734 (gcc-self-get (lambda (gcc-self-val group
)
1735 (if (stringp gcc-self-val
)
1736 (if (string-match " " gcc-self-val
)
1737 (concat "\"" gcc-self-val
"\"")
1739 ;; In nndoc groups, we use the parent group name
1740 ;; instead of the current group.
1741 (let ((group (or (gnus-group-find-parameter
1742 gnus-newsgroup-name
'parent-group
)
1744 (if (string-match " " group
)
1745 (concat "\"" group
"\"")
1750 ((null gnus-message-archive-method
)
1754 ;; Just a single group.
1757 ;; We don't want this.
1759 ((and (listp var
) (stringp (car var
)))
1760 ;; A list of groups.
1764 (funcall var group
))
1766 ;; An alist of regexps/functions/forms.
1772 (stringp (caar var
)))
1774 (when (string-match (caar var
) group
)
1777 (functionp (car var
)))
1779 (funcall (car var
) group
))
1781 (eval (car var
)))))))
1782 (setq var
(cdr var
)))
1785 (when (and (or groups gcc-self-val
)
1787 (when (stringp groups
)
1788 (setq groups
(list groups
)))
1791 (message-narrow-to-headers)
1792 (goto-char (point-max))
1795 ;; Use the `gcc-self' param value instead.
1797 (insert (if (listp gcc-self-val
)
1798 (mapconcat (lambda (val)
1799 (funcall gcc-self-get val group
))
1801 (funcall gcc-self-get gcc-self-val group
)))
1802 (if (not (eq gcc-self-val
'none
))
1804 (gnus-delete-line)))
1805 ;; Use the list of groups.
1806 (while (setq name
(pop groups
))
1807 (let ((str (if (string-match ":" name
)
1809 (gnus-group-prefixed-name
1810 name gnus-message-archive-method
))))
1811 (insert (if (string-match " " str
)
1812 (concat "\"" str
"\"")
1818 (defun gnus-mailing-list-followup-to ()
1819 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1820 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1821 (list-post (gnus-fetch-original-field "list-post")))
1822 (when (and list-post
1823 (string-match "mailto:\\([^>]+\\)" list-post
))
1824 (setq list-post
(match-string 1 list-post
)))
1830 (defun gnus-configure-posting-styles (&optional group-name
)
1831 "Configure posting styles according to `gnus-posting-styles'."
1832 (unless gnus-inhibit-posting-styles
1833 (let ((group (or group-name gnus-newsgroup-name
""))
1834 (styles (if (gnus-buffer-live-p gnus-summary-buffer
)
1835 (with-current-buffer gnus-summary-buffer
1836 gnus-posting-styles
)
1837 gnus-posting-styles
))
1838 style match attribute value v results matched-string
1839 filep name address element
)
1840 ;; If the group has a posting-style parameter, add it at the end with a
1841 ;; regexp matching everything, to be sure it takes precedence over all
1843 (when gnus-newsgroup-name
1844 (let ((tmp-style (gnus-group-find-parameter group
'posting-style t
)))
1846 (dolist (style tmp-style
)
1847 (when (stringp (cadr style
))
1848 (setcdr style
(list (mm-decode-coding-string (cadr style
)
1850 (setq styles
(append styles
(list (cons ".*" tmp-style
)))))))
1851 ;; Go through all styles and look for matches.
1852 (dolist (style styles
)
1853 (setq match
(pop style
))
1854 (goto-char (point-min))
1857 ;; Regexp string match on the group name.
1858 (when (string-match match group
)
1859 (setq matched-string group
)
1862 ;; Obsolete format of header match.
1863 (and (gnus-buffer-live-p gnus-article-copy
)
1864 (with-current-buffer gnus-article-copy
1866 (nnheader-narrow-to-headers)
1867 (let ((header (message-fetch-field (pop style
))))
1869 (string-match (pop style
) header
)))))))
1870 ((or (symbolp match
)
1874 ;; Function to be called.
1877 ;; Variable to be checked.
1878 (symbol-value match
))))
1881 ((eq (car match
) 'header
)
1882 ;; New format of header match.
1883 (and (gnus-buffer-live-p gnus-article-copy
)
1884 (with-current-buffer gnus-article-copy
1886 (nnheader-narrow-to-headers)
1887 (let ((header (message-fetch-field (nth 1 match
))))
1889 (string-match (nth 2 match
) header
)
1890 (setq matched-string header
)))))))
1892 ;; This is a form to be evalled.
1894 ;; We have a match, so we set the variables.
1895 (dolist (attribute style
)
1896 (setq element
(pop attribute
)
1900 ((eq (car attribute
) :file
)
1903 ((eq (car attribute
) :value
)
1907 ;; We get the value.
1911 (if (and matched-string
1912 (gnus-string-match-p "\\\\[&[:digit:]]" value
)
1913 (match-beginning 1))
1914 (gnus-match-substitute-replacement value nil nil
1917 ((or (symbolp value
)
1919 (cond ((functionp value
)
1922 (symbol-value value
))))
1925 ;; Translate obsolescent value.
1927 ((eq element
'signature-file
)
1928 (setq element
'signature
1930 ((eq element
'x-face-file
)
1931 (setq element
'x-face
1933 ;; Post-processing for the signature posting-style:
1934 (and (eq element
'signature
) filep
1935 message-signature-directory
1936 ;; don't actually use the signature directory
1937 ;; if message-signature-file contains a path.
1938 (not (file-name-directory v
))
1939 (setq v
(nnheader-concat message-signature-directory v
)))
1940 ;; Get the contents of file elems.
1942 (setq v
(with-temp-buffer
1943 (insert-file-contents v
)
1947 (goto-char (point-max))
1948 (if (zerop (skip-chars-backward "\n"))
1951 (setq results
(delq (assoc element results
) results
))
1952 (push (cons element v
) results
))))
1953 ;; Now we have all the styles, so we insert them.
1954 (setq name
(assq 'name results
)
1955 address
(assq 'address results
))
1956 (setq results
(delq name
(delq address results
)))
1957 (gnus-make-local-hook 'message-setup-hook
)
1958 (setq results
(sort results
(lambda (x y
)
1959 (string-lessp (car x
) (car y
)))))
1960 (dolist (result results
)
1961 (add-hook 'message-setup-hook
1963 ((eq 'eval
(car result
))
1965 ((eq 'body
(car result
))
1969 (insert ,(cdr result
)))))
1970 ((eq 'signature
(car result
))
1971 (set (make-local-variable 'message-signature
) nil
)
1972 (set (make-local-variable 'message-signature-file
) nil
)
1973 (if (not (cdr result
))
1977 (let ((message-signature ,(cdr result
)))
1978 (when message-signature
1979 (message-insert-signature)))))))
1982 (if (symbolp (car result
))
1983 (capitalize (symbol-name (car result
)))
1987 (message-remove-header ,header
)
1988 (let ((value ,(cdr result
)))
1991 (insert ,header
": " value
)
1993 (insert "\n")))))))))
1995 (when (or name address
)
1996 (add-hook 'message-setup-hook
1998 (set (make-local-variable 'user-mail-address
)
1999 ,(or (cdr address
) user-mail-address
))
2000 (let ((user-full-name ,(or (cdr name
) (user-full-name)))
2002 ,(or (cdr address
) user-mail-address
)))
2004 (message-remove-header "From")
2006 (insert "From: " (message-make-from) "\n"))))
2009 ;;; Allow redefinition of functions.
2015 ;;; gnus-msg.el ends here