1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2017 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 <https://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'cl
))
35 (defcustom gnus-post-method
'current
36 "Preferred method for posting USENET news.
38 If this variable is `current' (which is the default), Gnus will use
39 the \"current\" select method when posting. If it is `native', Gnus
40 will use the native select method when posting.
42 This method will not be used in mail groups and the like, only in
45 If not `native' nor `current', the value must be a valid method as discussed
46 in the documentation of `gnus-select-method'. It can also be a list of
47 methods. If that is the case, the user will be queried for what select
48 method to use when posting."
49 :group
'gnus-group-foreign
50 :link
'(custom-manual "(gnus)Posting Server")
51 :type
`(choice (const native
)
53 (sexp :tag
"Methods" ,gnus-select-method
)))
55 (defcustom gnus-outgoing-message-group nil
56 "All outgoing messages will be put in this group.
57 If you want to store all your outgoing mail and articles in the group
58 \"nnml:archive\", you set this variable to that value. This variable
59 can also be a list of group names.
61 If you want to have greater control over what group to put each
62 message in, you can set this variable to a function that checks the
63 current newsgroup name and then returns a suitable group name (or list
66 :type
'(choice (const nil
)
69 (repeat :tag
"List of groups" (string :tag
"Group"))))
71 (make-obsolete-variable 'gnus-outgoing-message-group
'gnus-message-archive-group
"24.1")
73 (defcustom gnus-mailing-list-groups nil
74 "If non-nil a regexp matching groups that are really mailing lists.
75 This is useful when you're reading a mailing list that has been
76 gatewayed to a newsgroup, and you want to followup to an article in
79 :type
'(choice (regexp)
82 (defcustom gnus-add-to-list nil
83 "If non-nil, add a `to-list' parameter automatically."
87 (defcustom gnus-crosspost-complaint
90 You posted the article below with the following Newsgroups header:
94 The %s group, at least, was an inappropriate recipient
95 of this message. Please trim your Newsgroups header to exclude this
96 group before posting in the future.
101 "Format string to be inserted when complaining about crossposts.
102 The first %s will be replaced by the Newsgroups header;
103 the second with the current group name."
107 (defcustom gnus-message-setup-hook nil
108 "Hook run after setting up a message buffer."
110 :options
'(message-remove-blank-cited-lines)
113 (defcustom gnus-bug-create-help-buffer t
114 "Should we create the *Gnus Help Bug* buffer?"
118 (defcustom gnus-posting-styles nil
119 "Alist of styles to use when posting.
120 See Info node `(gnus)Posting Styles'."
122 :link
'(custom-manual "(gnus)Posting Styles")
123 :type
'(repeat (cons (choice (regexp)
126 (string :tag
"Header")
127 (regexp :tag
"Regexp"))
131 (choice (const signature
)
132 (const signature-file
)
139 (string :tag
"Header"))
145 (defcustom gnus-gcc-mark-as-read nil
146 "If non-nil, automatically mark Gcc articles as read."
151 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
152 'gnus-gcc-mark-as-read
"Emacs 22.1")
154 (defcustom gnus-gcc-externalize-attachments nil
155 "Should local-file attachments be included as external parts in Gcc copies?
156 If it is `all', attach files as external parts;
157 if a regexp and matches the Gcc group name, attach files as external parts;
158 if nil, attach files as normal parts."
161 :type
'(choice (const nil
:tag
"None")
162 (const all
:tag
"Any")
163 (string :tag
"Regexp")))
165 (defcustom gnus-gcc-self-resent-messages
'no-gcc-self
166 "Like `gcc-self' group parameter, only for unmodified resent messages.
167 Applied to messages sent by `gnus-summary-resend-message'. Non-nil
168 value of this variable takes precedence over any existing Gcc header.
170 If this is `none', no Gcc copy will be made. If this is t, messages
171 resent will be Gcc'd to the current group. If this is a string, it
172 specifies a group to which resent messages will be Gcc'd. If this is
173 nil, Gcc will be done according to existing Gcc header(s), if any.
174 If this is `no-gcc-self', resent messages will be Gcc'd to groups that
175 existing Gcc header specifies, except for the current group."
178 :type
'(choice (const none
) (const t
) string
(const nil
)
179 (const no-gcc-self
)))
181 (gnus-define-group-parameter
182 posting-charset-alist
185 "Return the permitted unencoded charsets for posting of GROUP."
186 :variable gnus-group-posting-charset-alist
188 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1
(iso-8859-1))
189 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r
(koi8-r))
190 (message-this-is-mail nil nil
)
191 (message-this-is-news nil t
))
193 "Alist of regexps and permitted unencoded charsets for posting.
194 Each element of the alist has the form (TEST HEADER BODY-LIST), where
195 TEST is either a regular expression matching the newsgroup header or a
197 HEADER is the charset which may be left unencoded in the header (nil
198 means encode all charsets),
199 BODY-LIST is a list of charsets which may be encoded using 8bit
200 content-transfer encoding in the body, or one of the special values
201 nil (always encode using quoted-printable) or t (always use 8bit).
203 Note that any value other than nil for HEADER infringes some RFCs, so
204 use this option with care."
205 :variable-group gnus-charset
207 '(repeat (list :tag
"Permitted unencoded charsets"
209 (regexp :tag
"Group")
210 (const :tag
"Mail message" :value message-this-is-mail
)
211 (const :tag
"News article" :value message-this-is-news
))
212 (choice :tag
"Header"
213 (const :tag
"None" nil
)
214 (symbol :tag
"Charset"))
216 (const :tag
"Any" :value t
)
217 (const :tag
"None" :value nil
)
218 (repeat :tag
"Charsets"
219 (symbol :tag
"Charset")))))
220 :parameter-type
'(choice :tag
"Permitted unencoded charsets"
223 :parameter-document
"\
224 List of charsets that are permitted to be unencoded.")
226 (defcustom gnus-debug-files
227 '("gnus.el" "gnus-sum.el" "gnus-group.el"
228 "gnus-art.el" "gnus-start.el" "gnus-async.el"
229 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
230 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
231 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
232 "Files whose variables will be reported in `gnus-bug'."
235 :type
'(repeat (string :tag
"File")))
237 (defcustom gnus-debug-exclude-variables
238 '(mm-mime-mule-charset-alist
239 nnmail-split-fancy message-minibuffer-local-map
)
240 "Variables that should not be reported in `gnus-bug'."
243 :type
'(repeat (symbol :tag
"Variable")))
245 (defcustom gnus-discouraged-post-methods
246 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir
)
247 "A list of back ends that are not used in \"real\" newsgroups.
248 This variable is used only when `gnus-post-method' is `current'."
250 :group
'gnus-group-foreign
251 :type
'(repeat (symbol :tag
"Back end")))
253 (defcustom gnus-message-replysign
255 "Automatically sign replies to signed messages.
256 See also the `mml-default-sign-method' variable."
260 (defcustom gnus-message-replyencrypt t
261 "Automatically encrypt replies to encrypted messages.
262 See also the `mml-default-encrypt-method' variable."
267 (defcustom gnus-message-replysignencrypted
269 "Setting this causes automatically encrypted messages to also be signed."
273 (defcustom gnus-confirm-mail-reply-to-news
(and gnus-novice-user
274 (not gnus-expert-user
))
275 "If non-nil, Gnus requests confirmation when replying to news.
276 This is done because new users often reply by mistake when reading
278 This can also be a function receiving the group name as the only
279 parameter, which should return non-nil if a confirmation is needed; or
280 a regexp, in which case a confirmation is asked for if the group name
282 :version
"23.1" ;; No Gnus (default changed)
284 :type
'(choice (const :tag
"No" nil
)
286 (regexp :tag
"If group matches regexp")
287 (function :tag
"If function evaluates to non-nil")))
289 (defcustom gnus-confirm-treat-mail-like-news
291 "If non-nil, Gnus will treat mail like news with regard to confirmation
292 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
293 for fine-tuning this.
294 If nil, Gnus will never ask for confirmation if replying to mail."
299 (defcustom gnus-summary-resend-default-address t
300 "If non-nil, Gnus tries to suggest a default address to resend to.
301 If nil, the address field will always be empty after invoking
302 `gnus-summary-resend-message'."
307 (defcustom gnus-message-highlight-citation
308 t
;; gnus-treat-highlight-citation ;; gnus-cite dependency
309 "Enable highlighting of different citation levels in message-mode."
310 :version
"23.1" ;; No Gnus
315 (defcustom gnus-gcc-pre-body-encode-hook nil
316 "A hook called before encoding the body of the Gcc copy of a message.
317 The current buffer (when the hook is run) contains the message
318 including the message header. Changes made to the message will
319 only affect the Gcc copy, but not the original message."
324 (defcustom gnus-gcc-post-body-encode-hook nil
325 "A hook called after encoding the body of the Gcc copy of a message.
326 The current buffer (when the hook is run) contains the message
327 including the message header. Changes made to the message will
328 only affect the Gcc copy, but not the original message."
333 (autoload 'gnus-message-citation-mode
"gnus-cite" nil t
)
335 ;;; Internal variables.
337 (defvar gnus-inhibit-posting-styles nil
338 "Inhibit the use of posting styles.")
340 (defvar gnus-article-yanked-articles nil
)
341 (defvar gnus-message-buffer
"*Mail Gnus*")
342 (defvar gnus-article-copy nil
)
343 (defvar gnus-check-before-posting nil
)
344 (defvar gnus-last-posting-server nil
)
345 (defvar gnus-message-group-art nil
)
347 (defvar gnus-msg-force-broken-reply-to nil
)
349 (defconst gnus-bug-message
350 "Sending a bug report to the Gnus Towers.
351 ========================================
353 The buffer below is a mail buffer. When you press `C-c C-c', it will
354 be sent to the Gnus Bug Exterminators.
356 The thing near the bottom of the buffer is how the environment
357 settings will be included in the mail. Please do not delete that.
358 They will tell the Bug People what your environment is, so that it
359 will be easier to locate the bugs.
361 If you have found a bug that makes Emacs go \"beep\", set
362 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
363 and include the backtrace in your bug report.
365 Please describe the bug in annoying, painstaking detail.
367 Thank you for your help in stamping out bugs.
370 (autoload 'gnus-uu-post-news
"gnus-uu" nil t
)
374 ;;; Gnus Posting Functions
377 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map
)
378 "p" gnus-summary-post-news
379 "i" gnus-summary-news-other-window
380 "f" gnus-summary-followup
381 "F" gnus-summary-followup-with-original
382 "c" gnus-summary-cancel-article
383 "s" gnus-summary-supersede-article
384 "r" gnus-summary-reply
385 "y" gnus-summary-yank-message
386 "R" gnus-summary-reply-with-original
387 "L" gnus-summary-reply-to-list-with-original
388 "w" gnus-summary-wide-reply
389 "W" gnus-summary-wide-reply-with-original
390 "v" gnus-summary-very-wide-reply
391 "V" gnus-summary-very-wide-reply-with-original
392 "n" gnus-summary-followup-to-mail
393 "N" gnus-summary-followup-to-mail-with-original
394 "m" gnus-summary-mail-other-window
395 "u" gnus-uu-post-news
396 "\M-c" gnus-summary-mail-crosspost-complaint
397 "Br" gnus-summary-reply-broken-reply-to
398 "BR" gnus-summary-reply-broken-reply-to-with-original
399 "om" gnus-summary-mail-forward
400 "op" gnus-summary-post-forward
401 "Om" gnus-uu-digest-mail-forward
402 "Op" gnus-uu-digest-post-forward
)
404 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map
)
405 "b" gnus-summary-resend-bounced-mail
406 ;; "c" gnus-summary-send-draft
407 "r" gnus-summary-resend-message
408 "e" gnus-summary-resend-message-edit
)
410 ;;; Internal functions.
412 (defun gnus-inews-make-draft (articles)
414 (gnus-inews-make-draft-meta-information
415 ,(gnus-group-decoded-name gnus-newsgroup-name
) ',articles
)))
417 (autoload 'nnir-article-number
"nnir" nil nil
'macro
)
418 (autoload 'nnir-article-group
"nnir" nil nil
'macro
)
419 (autoload 'gnus-nnir-group-p
"nnir")
422 (defvar gnus-article-reply nil
)
423 (defmacro gnus-setup-message
(config &rest forms
)
424 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
425 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
426 (buffer (make-symbol "gnus-setup-message-buffer"))
427 (article (make-symbol "gnus-setup-message-article"))
428 (yanked (make-symbol "gnus-setup-yanked-articles"))
429 (group (make-symbol "gnus-setup-message-group")))
430 `(let ((,winconf
(current-window-configuration))
431 (,winconf-name gnus-current-window-configuration
)
432 (,buffer
(buffer-name (current-buffer)))
433 (,article
(if (and (gnus-nnir-group-p gnus-newsgroup-name
)
435 (nnir-article-number (or (car-safe gnus-article-reply
)
438 (,yanked gnus-article-yanked-articles
)
439 (,group
(if (and (gnus-nnir-group-p gnus-newsgroup-name
)
441 (nnir-article-group (or (car-safe gnus-article-reply
)
443 gnus-newsgroup-name
))
444 (message-header-setup-hook
445 (copy-sequence message-header-setup-hook
))
446 (mbl mml-buffer-list
)
447 (message-mode-hook (copy-sequence message-mode-hook
)))
448 (setq mml-buffer-list nil
)
449 (add-hook 'message-header-setup-hook
(lambda ()
450 (gnus-inews-insert-gcc ,group
)))
451 ;; message-newsreader and message-mailer were formerly set in
452 ;; gnus-inews-add-send-actions, but this is too late when
453 ;; message-generate-headers-first is used. --ansel
454 (add-hook 'message-mode-hook
456 (setq message-newsreader
457 (setq message-mailer
(gnus-extended-version)))))
458 ;; #### FIXME: for a reason that I did not manage to identify yet,
459 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
460 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
461 ;; After evaluation of @forms below, it gets the value we actually want
462 ;; to override, and the posting styles are used. For that reason, I've
463 ;; added an optional argument to `gnus-configure-posting-styles' to
464 ;; make sure that the correct value for the group name is used. -- drv
465 (add-hook 'message-mode-hook
466 (if (memq ,config
'(reply-yank reply
))
468 (gnus-configure-posting-styles ,group
))
470 ;; There may be an old " *gnus article copy*" buffer.
471 (let (gnus-article-copy)
472 (gnus-configure-posting-styles ,group
)))))
473 (gnus-alist-pull ',(intern gnus-draft-meta-information-header
)
474 message-required-headers
)
476 (not (string= ,group
"")))
478 (intern gnus-draft-meta-information-header
)
479 (gnus-inews-make-draft (or ,yanked
,article
)))
480 message-required-headers
))
484 (gnus-inews-add-send-actions ,winconf
,buffer
,article
,config
485 ,yanked
,winconf-name
)
486 (setq gnus-message-buffer
(current-buffer))
487 (set (make-local-variable 'gnus-message-group-art
)
488 (cons ,group
,article
))
489 (set (make-local-variable 'gnus-newsgroup-name
) ,group
)
490 ;; Enable highlighting of different citation levels
491 (when gnus-message-highlight-citation
492 (gnus-message-citation-mode 1))
493 (gnus-run-hooks 'gnus-message-setup-hook
)
494 (if (eq major-mode
'message-mode
)
495 (let ((mbl1 mml-buffer-list
))
496 (setq mml-buffer-list mbl
) ;; Global value
497 (set (make-local-variable 'mml-buffer-list
) mbl1
);; Local value
498 (add-hook 'change-major-mode-hook
'mml-destroy-buffers nil t
)
499 (add-hook 'kill-buffer-hook
'mml-destroy-buffers t t
))
500 (mml-destroy-buffers)
501 (setq mml-buffer-list mbl
)))
502 (message-hide-headers)
504 (gnus-configure-windows ,config t
)
505 (run-hooks 'post-command-hook
)
506 (set-buffer-modified-p nil
))))
508 (defun gnus-inews-make-draft-meta-information (group articles
)
509 (when (numberp articles
)
510 (setq articles
(list articles
)))
511 (concat "(\"" group
"\""
525 (defun gnus-msg-mail (&optional to subject other-headers continue
526 switch-action yank-action send-actions
528 "Start editing a mail message to be sent.
529 Like `message-mail', but with Gnus paraphernalia, particularly the
530 Gcc: header for archiving purposes.
531 If Gnus isn't running, a plain `message-mail' setup is used
534 (if (not (gnus-alive-p))
536 (message "Gnus not running; using plain Message mode")
537 (message-mail to subject other-headers continue
538 nil yank-action send-actions return-action
))
539 (let ((buf (current-buffer))
540 ;; Don't use posting styles corresponding to any existing group.
541 (group-name gnus-newsgroup-name
)
545 (setq gnus-newsgroup-name
"")
546 (gnus-setup-message 'message
547 (message-mail to subject other-headers continue
548 nil yank-action send-actions return-action
)))
549 (with-current-buffer buf
550 (setq gnus-newsgroup-name group-name
)))
552 (setq mail-buf
(current-buffer))
553 (switch-to-buffer buf
)
554 (apply switch-action mail-buf nil
))
555 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
559 (defun gnus-button-mailto (address)
561 (set-buffer (gnus-copy-article-buffer))
562 (gnus-setup-message 'message
563 (message-reply address
)))
566 (defun gnus-button-reply (&optional to-address wide
)
567 "Like `message-reply'."
569 (gnus-setup-message 'message
570 (message-reply to-address wide
)))
573 (define-mail-user-agent 'gnus-user-agent
574 'gnus-msg-mail
'message-send-and-exit
575 'message-kill-buffer
'message-send-hook
)
577 (defun gnus-setup-posting-charset (group)
578 (let ((alist gnus-group-posting-charset-alist
)
579 (group (or group
""))
583 (while (setq elem
(pop alist
))
584 (when (or (and (stringp (car elem
))
585 (string-match (car elem
) group
))
586 (and (functionp (car elem
))
587 (funcall (car elem
) group
))
588 (and (symbolp (car elem
))
589 (symbol-value (car elem
))))
590 (throw 'found
(cons (cadr elem
) (caddr elem
)))))))))
592 (defun gnus-inews-add-send-actions (winconf buffer article
593 &optional config yanked
595 (add-hook 'message-sent-hook
(if gnus-agent
'gnus-agent-possibly-do-gcc
596 'gnus-inews-do-gcc
) nil t
)
598 (add-hook 'message-header-hook
'gnus-agent-possibly-save-gcc nil t
))
599 (setq message-post-method
600 `(lambda (&optional arg
)
601 (gnus-post-method arg
,gnus-newsgroup-name
)))
604 (setq gnus-current-window-configuration
',winconf-name
)
605 (when (gnus-buffer-exists-p ,buffer
)
606 (set-window-configuration ,winconf
)))
607 'exit
'postpone
'kill
)
608 (let ((to-be-marked (cond
611 (lambda (x) (if (listp x
) (car x
) x
)) yanked
))
612 (article (if (listp article
) article
(list article
)))
615 `(when (gnus-buffer-exists-p ,buffer
)
616 (with-current-buffer ,buffer
618 (if (eq config
'forward
)
619 `(gnus-summary-mark-article-as-forwarded ',to-be-marked
)
620 `(gnus-summary-mark-article-as-replied ',to-be-marked
)))))
623 (put 'gnus-setup-message
'lisp-indent-function
1)
624 (put 'gnus-setup-message
'edebug-form-spec
'(form body
))
626 ;;; Post news commands of Gnus group mode and summary mode
628 (defun gnus-group-mail (&optional arg
)
629 "Start composing a mail.
630 If ARG, use the group under the point to find a posting style.
631 If ARG is 1, prompt for a group name to find the posting style."
633 ;; We can't `let' gnus-newsgroup-name here, since that leads
634 ;; to local variables leaking.
635 (let ((group gnus-newsgroup-name
)
636 ;; make sure last viewed article doesn't affect posting styles:
638 (buffer (current-buffer)))
641 (setq gnus-newsgroup-name
643 (if (= 1 (prefix-numeric-value arg
))
644 (gnus-group-completing-read
645 "Use posting style of group"
646 nil
(gnus-read-active-file-p))
647 (gnus-group-group-name))
649 ;; #### see comment in gnus-setup-message -- drv
650 (gnus-setup-message 'message
(message-mail)))
651 (with-current-buffer buffer
652 (setq gnus-newsgroup-name group
)))))
654 (defun gnus-group-news (&optional arg
)
655 "Start composing a news.
656 If ARG, post to group under point.
657 If ARG is 1, prompt for group name to post to.
659 This function prepares a news even when using mail groups. This is useful
660 for posting messages to mail groups without actually sending them over the
661 network. The corresponding back end must have a 'request-post method."
663 ;; We can't `let' gnus-newsgroup-name here, since that leads
664 ;; to local variables leaking.
665 (let ((group gnus-newsgroup-name
)
666 ;; make sure last viewed article doesn't affect posting styles:
668 (buffer (current-buffer)))
671 (setq gnus-newsgroup-name
673 (if (= 1 (prefix-numeric-value arg
))
674 (gnus-group-completing-read "Use group"
676 (gnus-read-active-file-p))
677 (gnus-group-group-name))
679 ;; #### see comment in gnus-setup-message -- drv
680 (gnus-setup-message 'message
681 (message-news (gnus-group-real-name gnus-newsgroup-name
))))
682 (with-current-buffer buffer
683 (setq gnus-newsgroup-name group
)))))
685 (defun gnus-group-post-news (&optional arg
)
686 "Start composing a message (a news by default).
687 If ARG, post to group under point. If ARG is 1, prompt for group name.
688 Depending on the selected group, the message might be either a mail or
691 ;; Bind this variable here to make message mode hooks work ok.
692 (let ((gnus-newsgroup-name
694 (if (= 1 (prefix-numeric-value arg
))
695 (gnus-group-completing-read "Newsgroup" nil
696 (gnus-read-active-file-p))
697 (or (gnus-group-group-name) ""))
699 ;; make sure last viewed article doesn't affect posting styles:
701 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
702 (string= gnus-newsgroup-name
""))))
704 (defun gnus-summary-mail-other-window (&optional arg
)
705 "Start composing a mail in another window.
706 Use the posting of the current group by default.
707 If ARG, don't do that. If ARG is 1, prompt for group name to find the
710 ;; We can't `let' gnus-newsgroup-name here, since that leads
711 ;; to local variables leaking.
712 (let ((group gnus-newsgroup-name
)
713 ;; make sure last viewed article doesn't affect posting styles:
715 (buffer (current-buffer)))
718 (setq gnus-newsgroup-name
720 (if (= 1 (prefix-numeric-value arg
))
721 (gnus-group-completing-read "Use group"
723 (gnus-read-active-file-p))
725 gnus-newsgroup-name
))
726 ;; #### see comment in gnus-setup-message -- drv
727 (gnus-setup-message 'message
(message-mail)))
728 (with-current-buffer buffer
729 (setq gnus-newsgroup-name group
)))))
731 (defun gnus-summary-news-other-window (&optional arg
)
732 "Start composing a news in another window.
733 Post to the current group by default.
734 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
736 This function prepares a news even when using mail groups. This is useful
737 for posting messages to mail groups without actually sending them over the
738 network. The corresponding back end must have a 'request-post method."
740 ;; We can't `let' gnus-newsgroup-name here, since that leads
741 ;; to local variables leaking.
742 (let ((group gnus-newsgroup-name
)
743 ;; make sure last viewed article doesn't affect posting styles:
745 (buffer (current-buffer)))
748 (setq gnus-newsgroup-name
750 (if (= 1 (prefix-numeric-value arg
))
751 (gnus-group-completing-read "Use group"
753 (gnus-read-active-file-p))
755 gnus-newsgroup-name
))
756 ;; #### see comment in gnus-setup-message -- drv
757 (gnus-setup-message 'message
759 (message-news (gnus-group-real-name gnus-newsgroup-name
))
760 (set (make-local-variable 'gnus-discouraged-post-methods
)
762 (car (gnus-find-method-for-group gnus-newsgroup-name
))
763 gnus-discouraged-post-methods
)))))
764 (with-current-buffer buffer
765 (setq gnus-newsgroup-name group
)))))
767 (defun gnus-summary-post-news (&optional arg
)
768 "Start composing a message. Post to the current group by default.
769 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
770 Depending on the selected group, the message might be either a mail or
773 ;; Bind this variable here to make message mode hooks work ok.
774 (let ((gnus-newsgroup-name
776 (if (= 1 (prefix-numeric-value arg
))
777 (gnus-group-completing-read "Newsgroup" nil
778 (gnus-read-active-file-p))
780 gnus-newsgroup-name
))
781 ;; make sure last viewed article doesn't affect posting styles:
783 (gnus-post-news 'post gnus-newsgroup-name
)))
786 (defun gnus-summary-followup (yank &optional force-news
)
787 "Compose a followup to an article.
788 If prefix argument YANK is non-nil, the original article is yanked
790 YANK is a list of elements, where the car of each element is the
791 article number, and the cdr is the string to be yanked."
793 (list (and current-prefix-arg
794 (gnus-summary-work-articles 1))))
796 (gnus-summary-goto-subject
797 (if (listp (car yank
))
800 (save-window-excursion
801 (gnus-summary-select-article))
802 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
803 (gnus-newsgroup-name gnus-newsgroup-name
))
805 (gnus-post-news nil gnus-newsgroup-name
806 headers gnus-article-buffer
808 (gnus-summary-handle-replysign)))
810 (defun gnus-summary-followup-with-original (n &optional force-news
)
811 "Compose a followup to an article and include the original article.
812 The text in the region will be yanked. If the region isn't
813 active, the entire article will be yanked."
815 (gnus-summary-followup (gnus-summary-work-articles n
) force-news
))
817 (defun gnus-summary-followup-to-mail (&optional arg
)
818 "Followup to the current mail message via news."
820 (list (and current-prefix-arg
821 (gnus-summary-work-articles 1))))
822 (gnus-summary-followup arg t
))
824 (defun gnus-summary-followup-to-mail-with-original (&optional arg
)
825 "Followup to the current mail message via news."
827 (gnus-summary-followup (gnus-summary-work-articles arg
) t
))
829 (defun gnus-inews-yank-articles (articles)
830 (let (beg article yank-string
)
832 (while (setq article
(pop articles
))
833 (when (listp article
)
834 (setq yank-string
(nth 1 article
)
835 article
(nth 0 article
)))
836 (save-window-excursion
837 (set-buffer gnus-summary-buffer
)
838 (gnus-summary-select-article nil nil nil article
)
839 (gnus-summary-remove-process-mark article
))
840 (gnus-copy-article-buffer nil yank-string
)
841 (let ((message-reply-buffer gnus-article-copy
)
842 (message-reply-headers
843 ;; The headers are decoded.
844 (with-current-buffer gnus-article-copy
846 (nnheader-narrow-to-headers)
847 (nnheader-parse-naked-head)))))
848 (message-yank-original)
849 (message-exchange-point-and-mark)
850 (setq beg
(or beg
(mark t
))))
856 (defun gnus-summary-cancel-article (&optional n symp
)
857 "Cancel an article you posted.
858 Uses the process-prefix convention. If given the symbolic
859 prefix `a', cancel using the standard posting method; if not
860 post using the current select method."
861 (interactive (gnus-interactive "P\ny"))
862 (let ((message-post-method
864 (gnus-post-method (eq ',symp
'a
) ,gnus-newsgroup-name
)))
865 (custom-address user-mail-address
))
866 (dolist (article (gnus-summary-work-articles n
))
867 (when (gnus-summary-select-article t nil nil article
)
868 ;; Pretend that we're doing a followup so that we can see what
869 ;; the From header would have ended up being.
870 (save-window-excursion
872 (gnus-summary-followup nil
)
873 (let ((from (message-fetch-field "from")))
876 (car (mail-header-parse-address from
)))))
877 (kill-buffer (current-buffer))))
878 ;; Now cancel the article using the From header we got.
879 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
880 (let ((user-mail-address (or custom-address user-mail-address
)))
881 (message-cancel-news)))
882 (gnus-summary-mark-as-read article gnus-canceled-mark
)
883 (gnus-cache-remove-article 1))
884 (gnus-article-hide-headers-if-wanted))
885 (gnus-summary-remove-process-mark article
))))
887 (defun gnus-summary-supersede-article ()
888 "Compose an article that will supersede a previous article.
889 This is done simply by taking the old article and adding a Supersedes
890 header line with the old Message-ID."
892 (let ((article (gnus-summary-article-number))
893 (mail-parse-charset gnus-newsgroup-charset
))
894 (gnus-setup-message 'reply-yank
895 (gnus-summary-select-article t
)
896 (set-buffer gnus-original-article-buffer
)
900 (when (gnus-buffer-exists-p ,gnus-summary-buffer
)
901 (with-current-buffer ,gnus-summary-buffer
902 (gnus-cache-possibly-remove-article ,article nil nil nil t
)
903 (gnus-summary-mark-as-read ,article gnus-canceled-mark
)))))
904 message-send-actions
)
906 (gnus-inews-insert-gcc))))
910 (defun gnus-copy-article-buffer (&optional article-buffer yank-string
)
911 ;; make a copy of the article buffer with all text properties removed
912 ;; this copy is in the buffer gnus-article-copy.
913 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
914 ;; this buffer should be passed to all mail/news reply/post routines.
915 (setq gnus-article-copy
(gnus-get-buffer-create " *gnus article copy*"))
916 (with-current-buffer gnus-article-copy
917 (mm-enable-multibyte))
918 (let ((article-buffer (or article-buffer gnus-article-buffer
))
920 (if (not (and (get-buffer article-buffer
)
921 (gnus-buffer-exists-p article-buffer
)))
922 (error "Can't find any article buffer")
923 (with-current-buffer article-buffer
924 (let ((gnus-newsgroup-charset (or gnus-article-charset
925 gnus-newsgroup-charset
))
926 (inhibit-read-only t
)
927 (gnus-newsgroup-ignored-charsets
928 (or gnus-article-ignored-charsets
929 gnus-newsgroup-ignored-charsets
)))
931 ;; Copy over the (displayed) article buffer, delete
932 ;; hidden text and remove text properties.
934 (copy-to-buffer gnus-article-copy
(point-min) (point-max))
935 (set-buffer gnus-article-copy
)
938 (delete-region (point) (point-max))
939 (insert yank-string
))
940 (gnus-article-delete-text-of-type 'annotation
)
941 (gnus-article-delete-text-of-type 'multipart
)
942 (gnus-remove-text-with-property 'gnus-prev
)
943 (gnus-remove-text-with-property 'gnus-next
)
944 (gnus-remove-text-with-property 'gnus-decoration
)
947 (buffer-substring-no-properties (point-min) (point-max))
949 ;; Find the original headers.
950 (set-buffer gnus-original-article-buffer
)
951 (goto-char (point-min))
952 (while (looking-at message-unix-mail-delimiter
)
954 (let ((mail-header-separator ""))
956 end
(or (message-goto-body)
957 ;; There may be just a header.
959 ;; Delete the headers from the displayed articles.
960 (set-buffer gnus-article-copy
)
961 (let ((mail-header-separator ""))
962 (delete-region (goto-char (point-min))
963 (or (message-goto-body) (point-max))))
964 ;; Insert the original article headers.
965 (insert-buffer-substring gnus-original-article-buffer beg end
)
967 (let ((gnus-article-decode-hook
968 (delq 'article-decode-charset
969 (copy-sequence gnus-article-decode-hook
)))
970 (rfc2047-quote-decoded-words-containing-tspecials t
))
971 (run-hooks 'gnus-article-decode-hook
)))))
974 (defun gnus-post-news (post &optional group header article-buffer yank subject
977 (gnus-copy-article-buffer))
978 (let ((gnus-article-reply (and article-buffer
(gnus-summary-article-number)))
979 (gnus-article-yanked-articles yank
)
980 (add-to-list gnus-add-to-list
))
981 (gnus-setup-message (cond (yank 'reply-yank
)
982 (article-buffer 'reply
)
984 (let* ((group (or group gnus-newsgroup-name
))
985 (charset (gnus-group-name-charset nil group
))
987 to-address to-group mailing-list to-list
990 (setq to-address
(gnus-parameter-to-address group
)
991 to-group
(gnus-group-find-parameter group
'to-group
)
992 to-list
(gnus-parameter-to-list group
)
993 newsgroup-p
(gnus-group-find-parameter group
'newsgroup
)
994 mailing-list
(when gnus-mailing-list-groups
995 (string-match gnus-mailing-list-groups group
))
996 group
(gnus-group-name-decode (gnus-group-real-name group
)
998 (if (or (and to-group
999 (gnus-news-group-p to-group
))
1002 (and (gnus-news-group-p
1003 (or pgroup gnus-newsgroup-name
)
1004 (or header gnus-current-article
))
1012 (and (not (gnus-virtual-group-p pgroup
)) group
)))
1013 (set-buffer gnus-article-copy
)
1014 (gnus-msg-treat-broken-reply-to)
1015 (message-followup (if (or newsgroup-p force-news
)
1016 (if (save-restriction
1017 (article-narrow-to-head)
1018 (message-fetch-field "newsgroups"))
1025 (message-mail (or to-address to-list
))
1026 ;; Arrange for mail groups that have no `to-address' to
1027 ;; get that when the user sends off the mail.
1028 (when (and (not to-list
)
1031 (push (list 'gnus-inews-add-to-address pgroup
)
1032 message-send-actions
)))
1033 (set-buffer gnus-article-copy
)
1034 (gnus-msg-treat-broken-reply-to)
1035 (message-wide-reply to-address
)))
1037 (gnus-inews-yank-articles yank
))))))
1039 (defun gnus-msg-treat-broken-reply-to (&optional force
)
1040 "Remove the Reply-to header if broken-reply-to."
1042 (gnus-group-find-parameter
1043 gnus-newsgroup-name
'broken-reply-to
))
1045 (message-narrow-to-head)
1046 (message-remove-header "reply-to"))))
1048 (defun gnus-post-method (arg group
&optional silent
)
1049 "Return the posting method based on GROUP and ARG.
1050 If SILENT, don't prompt the user."
1051 (let ((gnus-post-method (or (gnus-parameter-post-method group
)
1053 (group-method (gnus-find-method-for-group group
)))
1055 ;; If the group-method is nil (which shouldn't happen) we use
1056 ;; the default method.
1057 ((null group-method
)
1058 (or (and (listp gnus-post-method
) ;If not current/native/nil
1059 (not (listp (car gnus-post-method
))) ; and not a list of methods
1060 gnus-post-method
) ;then use it.
1062 message-post-method
))
1063 ;; We want the inverse of the default
1064 ((and arg
(not (eq arg
0)))
1065 (if (eq gnus-post-method
'current
)
1068 ;; We query the user for a post method.
1070 (and (listp gnus-post-method
)
1071 (listp (car gnus-post-method
))))
1073 ;; Collect all methods we know about.
1075 (when (listp gnus-post-method
)
1076 (if (listp (car gnus-post-method
))
1078 (list gnus-post-method
)))
1079 gnus-secondary-select-methods
1080 (mapcar 'cdr gnus-server-alist
)
1081 (mapcar 'car gnus-opened-servers
)
1082 (list gnus-select-method
)
1083 (list group-method
)))
1084 method-alist post-methods method
)
1085 ;; Weed out all mail methods.
1087 (setq method
(gnus-server-get-method "" (pop methods
)))
1088 (when (and (or (gnus-method-option-p method
'post
)
1089 (gnus-method-option-p method
'post-mail
))
1090 (not (member method post-methods
)))
1091 (push method post-methods
)))
1092 ;; Create a name-method alist.
1096 (if (equal (cadr m
) "")
1097 (list (symbol-name (car m
)) m
)
1098 (list (concat (cadr m
) " (" (symbol-name (car m
)) ")") m
)))
1103 (setq gnus-last-posting-server
1105 gnus-last-posting-server
)
1106 ;; Just use the last value.
1107 gnus-last-posting-server
1108 (gnus-completing-read
1109 "Posting method" (mapcar 'car method-alist
) t
1110 (cons (or gnus-last-posting-server
"") 0))))
1112 ;; Override normal method.
1113 ((and (eq gnus-post-method
'current
)
1114 (not (memq (car group-method
) gnus-discouraged-post-methods
))
1115 (gnus-get-function group-method
'request-post t
))
1118 ;; Use gnus-post-method.
1119 ((listp gnus-post-method
) ;A method...
1120 (assert (not (listp (car gnus-post-method
)))) ;... not a list of methods.
1122 ;; Use the normal select method (nil or native).
1123 (t gnus-select-method
))))
1127 (defun gnus-extended-version ()
1128 "Stringified Gnus version and Emacs version.
1129 See the variable `gnus-user-agent'."
1131 (if (stringp gnus-user-agent
)
1133 ;; `gnus-user-agent' is a list:
1134 (let* ((float-output-format nil
)
1136 (when (memq 'gnus gnus-user-agent
)
1138 (replace-regexp-in-string
1140 (format "%1.8f" (gnus-continuum-version gnus-version
)))
1141 " (" gnus-version
")")))
1142 (emacs-v (gnus-emacs-version)))
1143 (concat gnus-v
(when (and gnus-v emacs-v
) " ")
1148 ;;; Gnus Mail Functions
1151 ;;; Mail reply commands of Gnus summary mode
1153 (defun gnus-summary-reply (&optional yank wide very-wide
)
1154 "Start composing a mail reply to the current message.
1155 If prefix argument YANK is non-nil, the original article is yanked
1157 If WIDE, make a wide reply.
1158 If VERY-WIDE, make a very wide reply."
1160 (list (and current-prefix-arg
1161 (gnus-summary-work-articles 1))))
1162 ;; Allow user to require confirmation before replying by mail to the
1163 ;; author of a news article (or mail message).
1164 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name
)
1165 gnus-confirm-treat-mail-like-news
))
1166 (not (cond ((stringp gnus-confirm-mail-reply-to-news
)
1167 (string-match gnus-confirm-mail-reply-to-news
1168 gnus-newsgroup-name
))
1169 ((functionp gnus-confirm-mail-reply-to-news
)
1170 (funcall gnus-confirm-mail-reply-to-news
1171 gnus-newsgroup-name
))
1172 (t gnus-confirm-mail-reply-to-news
)))
1173 (if (or wide very-wide
)
1174 t
;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1176 (y-or-n-p "Really reply by mail to article author? ")))
1178 (if (listp (car yank
))
1181 (gnus-article-reply (or article
(gnus-summary-article-number)))
1182 (gnus-article-yanked-articles yank
)
1184 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1186 (gnus-summary-goto-subject article
))
1187 (gnus-setup-message (if yank
'reply-yank
'reply
)
1189 (gnus-summary-select-article)
1190 (dolist (article very-wide
)
1191 (gnus-summary-select-article nil nil nil article
)
1192 (with-current-buffer (gnus-copy-article-buffer)
1193 (gnus-msg-treat-broken-reply-to)
1195 (message-narrow-to-head)
1196 (setq headers
(concat headers
(buffer-string)))))))
1197 (set-buffer (gnus-copy-article-buffer))
1198 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to
)
1200 (message-narrow-to-head)
1204 (goto-char (point-max)))
1205 (mml-quote-region (point) (point-max))
1206 (message-reply nil wide
)
1208 (gnus-inews-yank-articles yank
))
1209 (gnus-summary-handle-replysign)))))
1211 (defun gnus-summary-handle-replysign ()
1212 "Check the various replysign variables and take action accordingly."
1213 (when (or gnus-message-replysign gnus-message-replyencrypt
)
1214 (let (signed encrypted
)
1215 (with-current-buffer gnus-article-buffer
1216 (setq signed
(memq 'signed gnus-article-wash-types
))
1217 (setq encrypted
(memq 'encrypted gnus-article-wash-types
)))
1218 (cond ((and gnus-message-replyencrypt encrypted
)
1219 (mml-secure-message mml-default-encrypt-method
1220 (if gnus-message-replysignencrypted
1223 ((and gnus-message-replysign signed
)
1224 (mml-secure-message mml-default-sign-method
'sign
))))))
1226 (defun gnus-summary-reply-with-original (n &optional wide
)
1227 "Start composing a reply mail to the current message.
1228 The original article will be yanked."
1230 (gnus-summary-reply (gnus-summary-work-articles n
) wide
))
1232 (defun gnus-summary-reply-to-list-with-original (n &optional wide
)
1233 "Start composing a reply mail to the current message.
1234 The reply goes only to the mailing list.
1235 The original article will be yanked."
1237 (let ((message-reply-to-function
1239 `((To .
,(gnus-mailing-list-followup-to))))))
1240 (gnus-summary-reply (gnus-summary-work-articles n
) wide
)))
1242 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide
)
1243 "Like `gnus-summary-reply' except removing reply-to field.
1244 If prefix argument YANK is non-nil, the original article is yanked
1246 If WIDE, make a wide reply.
1247 If VERY-WIDE, make a very wide reply."
1249 (list (and current-prefix-arg
1250 (gnus-summary-work-articles 1))))
1251 (let ((gnus-msg-force-broken-reply-to t
))
1252 (gnus-summary-reply yank wide very-wide
)))
1254 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide
)
1255 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1256 The original article will be yanked."
1258 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n
) wide
))
1260 (defun gnus-summary-wide-reply (&optional yank
)
1261 "Start composing a wide reply mail to the current message.
1262 If prefix argument YANK is non-nil, the original article is yanked
1265 (list (and current-prefix-arg
1266 (gnus-summary-work-articles 1))))
1267 (gnus-summary-reply yank t
))
1269 (defun gnus-summary-wide-reply-with-original (n)
1270 "Start composing a wide reply mail to the current message.
1271 The original article will be yanked.
1272 Uses the process/prefix convention."
1274 (gnus-summary-reply-with-original n t
))
1276 (defun gnus-summary-very-wide-reply (&optional yank
)
1277 "Start composing a very wide reply mail to the current message.
1278 If prefix argument YANK is non-nil, the original article is yanked
1281 (list (and current-prefix-arg
1282 (gnus-summary-work-articles 1))))
1283 (gnus-summary-reply yank t
(gnus-summary-work-articles yank
)))
1285 (defun gnus-summary-very-wide-reply-with-original (n)
1286 "Start composing a very wide reply mail to the current message.
1287 The original article will be yanked."
1290 (gnus-summary-work-articles n
) t
(gnus-summary-work-articles n
)))
1292 (defun gnus-summary-mail-forward (&optional arg post
)
1293 "Forward the current message(s) to another user.
1294 If process marks exist, forward all marked messages;
1295 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1296 if ARG is 1, decode the message and forward directly inline;
1297 if ARG is 2, forward message as an rfc822 MIME section;
1298 if ARG is 3, decode message and forward as an rfc822 MIME section;
1299 if ARG is 4, forward message directly inline;
1300 otherwise, use flipped `message-forward-as-mime'.
1301 If POST, post instead of mail.
1302 For the \"inline\" alternatives, also see the variable
1303 `message-forward-ignored-headers'."
1305 (if (cdr (gnus-summary-work-articles nil
))
1306 ;; Process marks are given.
1307 (gnus-uu-digest-mail-forward nil post
)
1308 ;; No process marks.
1309 (let ((message-forward-as-mime message-forward-as-mime
)
1310 (message-forward-show-mml message-forward-show-mml
))
1314 (setq message-forward-as-mime nil
1315 message-forward-show-mml t
))
1317 (setq message-forward-as-mime t
1318 message-forward-show-mml nil
))
1320 (setq message-forward-as-mime t
1321 message-forward-show-mml t
))
1323 (setq message-forward-as-mime nil
1324 message-forward-show-mml nil
))
1326 (setq message-forward-as-mime
(not message-forward-as-mime
))))
1327 (let* ((gnus-article-reply (gnus-summary-article-number))
1328 (gnus-article-yanked-articles (list gnus-article-reply
)))
1329 (gnus-setup-message 'forward
1330 (gnus-summary-select-article)
1331 (let ((mail-parse-charset
1332 (or (and (gnus-buffer-live-p gnus-article-buffer
)
1333 (with-current-buffer gnus-article-buffer
1334 gnus-article-charset
))
1335 gnus-newsgroup-charset
))
1336 (mail-parse-ignored-charsets
1337 gnus-newsgroup-ignored-charsets
))
1338 (set-buffer gnus-original-article-buffer
)
1339 (message-forward post
)))))))
1341 (defun gnus-summary-resend-message-insert-gcc ()
1342 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1343 (gnus-inews-insert-gcc)
1346 (encode-coding-string
1348 (gnus-group-name-charset (gnus-inews-group-method group
)
1350 (message-unquote-tokens
1351 (message-tokenize-header (mail-fetch-field "gcc" nil t
)
1353 (self (with-current-buffer gnus-summary-buffer
1354 gnus-gcc-self-resent-messages
)))
1355 (message-remove-header "gcc")
1357 (goto-char (point-max))
1358 (cond ((eq self
'none
))
1360 (insert "Gcc: \"" gnus-newsgroup-name
"\"\n"))
1363 (encode-coding-string
1364 (if (string-match " " self
)
1365 (concat "\"" self
"\"")
1367 (gnus-group-name-charset (gnus-inews-group-method self
)
1371 (insert "Gcc: " (mapconcat 'identity gcc
", ") "\n"))
1372 ((eq self
'no-gcc-self
)
1373 (when (setq gcc
(delete
1375 (delete (concat "\"" gnus-newsgroup-name
"\"")
1377 (insert "Gcc: " (mapconcat 'identity gcc
", ") "\n")))))))
1379 (defun gnus-summary-resend-message (address n
)
1380 "Resend the current article to ADDRESS."
1382 (list (message-read-from-minibuffer
1383 "Resend message(s) to: "
1384 (when (and gnus-summary-resend-default-address
1385 (gnus-buffer-live-p gnus-original-article-buffer
))
1386 ;; If some other article is currently selected, the
1387 ;; initial-contents is wrong. Whatever, it is just the
1388 ;; initial-contents.
1389 (with-current-buffer gnus-original-article-buffer
1390 (nnmail-fetch-field "to"))))
1391 current-prefix-arg
))
1392 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook
))
1393 (message-sent-hook (copy-sequence message-sent-hook
))
1394 ;; Honor posting-style for `name' and `address' in Resent-From header.
1395 (styles (gnus-group-find-parameter gnus-newsgroup-name
1397 (user-full-name user-full-name
)
1398 (user-mail-address user-mail-address
)
1400 (dolist (style styles
)
1401 (when (stringp (cadr style
))
1402 (setcdr style
(list (decode-coding-string (cadr style
) 'utf-8
)))))
1403 (dolist (style (if styles
1404 (append gnus-posting-styles
(list (cons ".*" styles
)))
1405 gnus-posting-styles
))
1406 (when (and (stringp (car style
))
1407 (string-match (pop style
) gnus-newsgroup-name
))
1408 (when (setq tem
(cadr (assq 'name style
)))
1409 (setq user-full-name tem
))
1410 (when (setq tem
(cadr (assq 'address style
)))
1411 (setq user-mail-address tem
))))
1412 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1413 (add-hook 'message-header-setup-hook
1414 'gnus-summary-resend-message-insert-gcc t
)
1415 (add-hook 'message-sent-hook
1417 (let ((rfc2047-encode-encoded-words nil
))
1419 '(gnus-agent-possibly-do-gcc)
1420 '(gnus-inews-do-gcc)))))
1421 (dolist (article (gnus-summary-work-articles n
))
1422 (gnus-summary-select-article nil nil nil article
)
1423 (with-current-buffer gnus-original-article-buffer
1424 (let ((gnus-gcc-externalize-attachments nil
)
1425 (message-inhibit-body-encoding t
))
1426 (message-resend address
)))
1427 (gnus-summary-mark-article-as-forwarded article
))))
1429 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1430 (defun gnus-summary-resend-message-edit ()
1431 "Resend an article that has already been sent.
1432 A new buffer will be created to allow the user to modify body and
1433 contents of the message, and then, everything will happen as when
1434 composing a new message."
1436 (let ((mail-parse-charset gnus-newsgroup-charset
))
1437 (gnus-setup-message 'reply-yank
1438 (gnus-summary-select-article t
)
1439 (set-buffer gnus-original-article-buffer
)
1440 (let ((cur (current-buffer))
1441 (to (message-fetch-field "to")))
1442 ;; Get a normal message buffer.
1443 (message-pop-to-buffer (message-buffer-name "Resend" to
))
1444 (insert-buffer-substring cur
)
1446 (message-narrow-to-head-1)
1447 ;; Gnus will generate a new one when sending.
1448 (message-remove-header "Message-ID")
1449 ;; Remove unwanted headers.
1450 (message-remove-header message-ignored-resent-headers t
)
1451 (goto-char (point-max))
1452 (insert mail-header-separator
)
1454 (gnus-inews-insert-gcc)
1455 (goto-char (point-min))
1456 (when (re-search-forward "^To:\\|^Newsgroups:" nil
'move
)
1460 (defun gnus-summary-post-forward (&optional arg
)
1461 "Forward the current article to a newsgroup.
1462 See `gnus-summary-mail-forward' for ARG."
1464 (gnus-summary-mail-forward arg t
))
1466 (defun gnus-summary-mail-crosspost-complaint (n)
1467 "Send a complaint about crossposting to the current article(s)."
1469 (dolist (article (gnus-summary-work-articles n
))
1470 (set-buffer gnus-summary-buffer
)
1471 (gnus-summary-goto-subject article
)
1472 (let ((group (gnus-group-real-name gnus-newsgroup-name
))
1473 newsgroups followup-to
)
1474 (gnus-summary-select-article)
1475 (set-buffer gnus-original-article-buffer
)
1476 (if (and (<= (length (message-tokenize-header
1478 (mail-fetch-field "newsgroups"))
1481 (or (not (setq followup-to
(mail-fetch-field "followup-to")))
1482 (not (member group
(message-tokenize-header
1483 followup-to
", ")))))
1485 (gnus-message 1 "Followup-to restricted")
1486 (gnus-message 1 "Not a crossposted article"))
1487 (set-buffer gnus-summary-buffer
)
1488 (gnus-summary-reply-with-original 1)
1489 (set-buffer gnus-message-buffer
)
1491 (insert (format gnus-crosspost-complaint newsgroups group
))
1492 (message-goto-subject)
1493 (re-search-forward " *$")
1494 (replace-match " (crosspost notification)" t t
)
1496 (when (gnus-y-or-n-p "Send this complaint? ")
1497 (message-send-and-exit))))))
1499 (defun gnus-inews-add-to-address (group)
1500 (let ((to-address (mail-fetch-field "to")))
1501 (when (and to-address
1503 ;; This mail group doesn't have a `to-list', so we add one
1505 (when (gnus-y-or-n-p
1506 (format "Do you want to add this as `to-list': %s? " to-address
))
1507 (gnus-group-add-parameter group
(cons 'to-list to-address
))))))
1509 (defun gnus-article-mail (yank)
1510 "Send a reply to the address near point.
1511 If YANK is non-nil, include the original article."
1515 (save-excursion (re-search-backward "[ \t\n]" nil t
) (1+ (point)))
1516 (save-excursion (re-search-forward "[ \t\n]" nil t
) (1- (point))))))
1518 (gnus-msg-mail address
)
1520 (gnus-inews-yank-articles (list (cdr gnus-article-current
)))))))
1522 (defvar nntp-server-type
)
1524 "Send a bug report to the Gnus maintainers."
1526 (unless (gnus-alive-p)
1527 (error "Gnus has been shut down"))
1528 (gnus-setup-message (if (message-mail-user-agent) 'message
'bug
)
1529 (unless (message-mail-user-agent)
1530 (when gnus-bug-create-help-buffer
1531 (switch-to-buffer "*Gnus Help Bug*")
1533 (insert gnus-bug-message
)
1534 (goto-char (point-min)))
1535 (message-pop-to-buffer "*Gnus Bug*"))
1536 (let ((message-this-is-mail t
))
1537 (message-setup `((To .
,gnus-maintainer
)
1540 .
,(format "%s" gnus-bug-package
))
1542 .
,(format "%s" (gnus-continuum-version))))))
1543 (when gnus-bug-create-help-buffer
1544 (push `(gnus-bug-kill-buffer) message-send-actions
))
1545 (goto-char (point-min))
1547 (insert "\n\n\n\n\n")
1548 (insert (gnus-version) "\n"
1549 (emacs-version) "\n")
1550 (when (and (boundp 'nntp-server-type
)
1551 (stringp nntp-server-type
))
1552 (insert nntp-server-type
))
1553 (goto-char (point-min))
1554 (search-forward "Subject: " nil t
)
1557 (defun gnus-bug-kill-buffer ()
1558 (when (get-buffer "*Gnus Help Bug*")
1559 (kill-buffer "*Gnus Help Bug*")))
1561 (defun gnus-summary-yank-message (buffer n
)
1562 "Yank the current article into a composed message."
1564 (list (gnus-completing-read "Buffer" (message-buffers) t
)
1565 current-prefix-arg
))
1566 (gnus-summary-iterate n
1567 (let ((gnus-inhibit-treatment t
))
1568 (gnus-summary-select-article))
1569 (with-current-buffer buffer
1570 (message-yank-buffer gnus-article-buffer
))))
1572 ;;; Treatment of rejected articles.
1575 (defun gnus-summary-resend-bounced-mail (&optional fetch
)
1576 "Re-mail the current message.
1577 This only makes sense if the current message is a bounce message that
1578 contains some mail you have written which has been bounced back to
1580 If FETCH, try to fetch the article that this is a reply to, if indeed
1583 (gnus-summary-select-article t
)
1584 (let (summary-buffer parent
)
1587 (setq summary-buffer
(current-buffer))
1588 (set-buffer gnus-original-article-buffer
)
1590 (when (re-search-forward "^References:\n?" nil t
)
1591 (while (memq (char-after) '(?
\t ?
))
1593 (skip-chars-backward "\t\n ")
1595 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1596 (set-buffer gnus-original-article-buffer
))
1597 (gnus-setup-message 'compose-bounce
1600 (gnus-inews-insert-gcc)
1601 ;; If there are references, we fetch the article we answered to.
1603 (with-current-buffer summary-buffer
1604 (gnus-summary-refer-article parent
)
1605 (gnus-summary-show-all-headers))))))
1609 (defun gnus-inews-group-method (group)
1611 ;; If the group doesn't exist, we assume
1612 ;; it's an archive group...
1613 ((and (null (gnus-get-info group
))
1614 (eq (car (gnus-server-to-method gnus-message-archive-method
))
1615 (car (gnus-server-to-method (gnus-group-method group
)))))
1616 gnus-message-archive-method
)
1618 ((gnus-info-method (gnus-get-info group
))
1619 (gnus-info-method (gnus-get-info group
)))
1621 (t (gnus-server-to-method (gnus-group-method group
)))))
1623 ;; Do Gcc handling, which copied the message over to some group.
1624 (defun gnus-inews-do-gcc (&optional gcc
)
1628 (message-narrow-to-headers)
1629 (let ((gcc (or gcc
(mail-fetch-field "gcc" nil t
)))
1630 (cur (current-buffer))
1631 groups group method group-art options
1632 mml-externalize-attachments
)
1634 (message-remove-header "gcc")
1636 (setq groups
(message-unquote-tokens
1637 (message-tokenize-header gcc
" ,")))
1638 ;; Copy the article over to some group(s).
1639 (while (setq group
(pop groups
))
1640 (setq method
(gnus-inews-group-method group
)
1641 group
(encode-coding-string
1643 (gnus-group-name-charset method group
)))
1644 (unless (gnus-check-server method
)
1645 (error "Can't open server %s" (if (stringp method
) method
1647 (unless (gnus-request-group group t method
)
1648 (gnus-request-create-group group method
))
1649 (setq mml-externalize-attachments
1650 (if (stringp gnus-gcc-externalize-attachments
)
1651 (string-match gnus-gcc-externalize-attachments group
)
1652 gnus-gcc-externalize-attachments
))
1654 (nnheader-set-temp-buffer " *acc*")
1655 (setq message-options
(with-current-buffer cur message-options
))
1656 (insert-buffer-substring cur
)
1657 (run-hooks 'gnus-gcc-pre-body-encode-hook
)
1658 (message-encode-message-body)
1659 (run-hooks 'gnus-gcc-post-body-encode-hook
)
1661 (message-narrow-to-headers)
1662 (let* ((newsgroups-field (save-restriction
1663 (message-narrow-to-headers-or-head)
1664 (message-fetch-field "Newsgroups")))
1665 (followup-field (save-restriction
1666 (message-narrow-to-headers-or-head)
1667 (message-fetch-field "Followup-To")))
1668 ;; BUG: We really need to get the charset for
1669 ;; each name in the Newsgroups and Followup-To
1670 ;; lines to allow crossposting between group
1671 ;; names with incompatible character sets.
1672 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1673 (group-field-charset
1674 (gnus-group-name-charset
1675 method
(or newsgroups-field
"")))
1676 (followup-field-charset
1677 (gnus-group-name-charset
1678 method
(or followup-field
"")))
1679 (rfc2047-header-encoding-alist
1681 (when group-field-charset
1682 (list (cons "Newsgroups" group-field-charset
)))
1683 (when followup-field-charset
1684 (list (cons "Followup-To" followup-field-charset
)))
1685 rfc2047-header-encoding-alist
)))
1686 (mail-encode-encoded-word-buffer)))
1687 (goto-char (point-min))
1688 (when (re-search-forward
1689 (concat "^" (regexp-quote mail-header-separator
) "$")
1691 (replace-match "" t t
))
1692 (when (or (not (gnus-check-backend-function
1693 'request-accept-article group
))
1694 (not (setq group-art
1695 (gnus-request-accept-article
1696 group method t t
))))
1697 (gnus-message 1 "Couldn't store article in group %s: %s"
1698 group
(gnus-status-message method
)))
1699 (when (stringp method
)
1700 (setq method
(gnus-server-to-method method
)))
1701 (when (and (listp method
)
1702 (gnus-native-method-p method
))
1703 (setq group
(gnus-group-short-name group
)))
1704 (when (and group-art
1705 ;; FIXME: Should gcc-mark-as-read work when
1706 ;; Gnus is not running?
1708 (if (or gnus-gcc-mark-as-read
1709 (and (boundp 'gnus-inews-mark-gcc-as-read
)
1710 (symbol-value 'gnus-inews-mark-gcc-as-read
)))
1711 (gnus-group-mark-article-read group
(cdr group-art
))
1712 (with-current-buffer gnus-group-buffer
1713 (let ((gnus-group-marked (list group
))
1714 (gnus-get-new-news-hook nil
)
1715 (inhibit-read-only t
))
1716 (gnus-group-get-new-news-this-group nil t
)))))
1717 (setq options message-options
)
1718 (with-current-buffer cur
(setq message-options options
))
1719 (kill-buffer (current-buffer)))))))))
1721 (defun gnus-inews-insert-gcc (&optional group
)
1722 "Insert the Gcc to say where the article is to be archived."
1723 (let* ((group (or group gnus-newsgroup-name
))
1724 (group (when group
(gnus-group-decoded-name group
)))
1725 (var (or gnus-outgoing-message-group gnus-message-archive-group
))
1727 (and group
(not (gnus-virtual-group-p group
))
1728 (gnus-group-find-parameter group
'gcc-self t
)))
1729 (gcc-self-get (lambda (gcc-self-val group
)
1730 (if (stringp gcc-self-val
)
1731 (if (string-match " " gcc-self-val
)
1732 (concat "\"" gcc-self-val
"\"")
1734 ;; In nndoc groups, we use the parent group name
1735 ;; instead of the current group.
1736 (let ((group (or (gnus-group-find-parameter
1737 gnus-newsgroup-name
'parent-group
)
1739 (if (string-match " " group
)
1740 (concat "\"" group
"\"")
1745 ((null gnus-message-archive-method
)
1749 ;; Just a single group.
1752 ;; We don't want this.
1754 ((and (listp var
) (stringp (car var
)))
1755 ;; A list of groups.
1759 (funcall var group
))
1761 ;; An alist of regexps/functions/forms.
1767 (stringp (caar var
)))
1769 (when (string-match (caar var
) group
)
1772 (functionp (car var
)))
1774 (funcall (car var
) group
))
1776 (eval (car var
)))))))
1777 (setq var
(cdr var
)))
1780 (when (and (or groups gcc-self-val
)
1782 (when (stringp groups
)
1783 (setq groups
(list groups
)))
1786 (message-narrow-to-headers)
1787 (goto-char (point-max))
1790 ;; Use the `gcc-self' param value instead.
1792 (insert (if (listp gcc-self-val
)
1793 (mapconcat (lambda (val)
1794 (funcall gcc-self-get val group
))
1796 (funcall gcc-self-get gcc-self-val group
)))
1797 (if (not (eq gcc-self-val
'none
))
1799 (gnus-delete-line)))
1800 ;; Use the list of groups.
1801 (while (setq name
(pop groups
))
1802 (let ((str (if (string-match ":" name
)
1804 (gnus-group-prefixed-name
1805 name gnus-message-archive-method
))))
1806 (insert (if (string-match " " str
)
1807 (concat "\"" str
"\"")
1813 (defun gnus-mailing-list-followup-to ()
1814 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1815 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1816 (list-post (gnus-fetch-original-field "list-post")))
1817 (when (and list-post
1818 (string-match "mailto:\\([^>]+\\)" list-post
))
1819 (setq list-post
(match-string 1 list-post
)))
1825 (defun gnus-configure-posting-styles (&optional group-name
)
1826 "Configure posting styles according to `gnus-posting-styles'."
1827 (unless gnus-inhibit-posting-styles
1828 (let ((group (or group-name gnus-newsgroup-name
""))
1829 (styles (if (gnus-buffer-live-p gnus-summary-buffer
)
1830 (with-current-buffer gnus-summary-buffer
1831 gnus-posting-styles
)
1832 gnus-posting-styles
))
1833 style match attribute value v results matched-string
1834 filep name address element
)
1835 ;; If the group has a posting-style parameter, add it at the end with a
1836 ;; regexp matching everything, to be sure it takes precedence over all
1838 (when gnus-newsgroup-name
1839 (let ((tmp-style (gnus-group-find-parameter group
'posting-style t
)))
1841 (dolist (style tmp-style
)
1842 (when (stringp (cadr style
))
1843 (setcdr style
(list (decode-coding-string (cadr style
)
1845 (setq styles
(append styles
(list (cons ".*" tmp-style
)))))))
1846 ;; Go through all styles and look for matches.
1847 (dolist (style styles
)
1848 (setq match
(pop style
))
1849 (goto-char (point-min))
1852 ;; Regexp string match on the group name.
1853 (when (string-match match group
)
1854 (setq matched-string group
)
1857 ;; Obsolete format of header match.
1858 (and (gnus-buffer-live-p gnus-article-copy
)
1859 (with-current-buffer gnus-article-copy
1861 (nnheader-narrow-to-headers)
1862 (let ((header (message-fetch-field (pop style
))))
1864 (string-match (pop style
) header
)))))))
1865 ((or (symbolp match
)
1869 ;; Function to be called.
1872 ;; Variable to be checked.
1873 (symbol-value match
))))
1876 ((eq (car match
) 'header
)
1877 ;; New format of header match.
1878 (and (gnus-buffer-live-p gnus-article-copy
)
1879 (with-current-buffer gnus-article-copy
1881 (nnheader-narrow-to-headers)
1882 (let ((header (message-fetch-field (nth 1 match
))))
1884 (string-match (nth 2 match
) header
)
1885 (setq matched-string header
)))))))
1887 ;; This is a form to be evalled.
1889 ;; We have a match, so we set the variables.
1890 (dolist (attribute style
)
1891 (setq element
(pop attribute
)
1895 ((eq (car attribute
) :file
)
1898 ((eq (car attribute
) :value
)
1902 ;; We get the value.
1906 (if (and matched-string
1907 (string-match-p "\\\\[&[:digit:]]" value
)
1908 (match-beginning 1))
1909 (match-substitute-replacement value nil nil
1912 ((or (symbolp value
)
1914 (cond ((functionp value
)
1917 (symbol-value value
))))
1920 ;; Translate obsolescent value.
1922 ((eq element
'signature-file
)
1923 (setq element
'signature
1925 ((eq element
'x-face-file
)
1926 (setq element
'x-face
1928 ;; Post-processing for the signature posting-style:
1929 (and (eq element
'signature
) filep
1930 message-signature-directory
1931 ;; don't actually use the signature directory
1932 ;; if message-signature-file contains a path.
1933 (not (file-name-directory v
))
1934 (setq v
(nnheader-concat message-signature-directory v
)))
1935 ;; Get the contents of file elems.
1937 (setq v
(with-temp-buffer
1938 (insert-file-contents v
)
1942 (goto-char (point-max))
1943 (if (zerop (skip-chars-backward "\n"))
1946 (setq results
(delq (assoc element results
) results
))
1947 (push (cons element v
) results
))))
1948 ;; Now we have all the styles, so we insert them.
1949 (setq name
(assq 'name results
)
1950 address
(assq 'address results
))
1951 (setq results
(delq name
(delq address results
)))
1952 (setq results
(sort results
(lambda (x y
)
1953 (string-lessp (car x
) (car y
)))))
1954 (dolist (result results
)
1955 (add-hook 'message-setup-hook
1957 ((eq 'eval
(car result
))
1959 ((eq 'body
(car result
))
1963 (insert ,(cdr result
)))))
1964 ((eq 'signature
(car result
))
1965 (set (make-local-variable 'message-signature
) nil
)
1966 (set (make-local-variable 'message-signature-file
) nil
)
1967 (if (not (cdr result
))
1971 (let ((message-signature ,(cdr result
)))
1972 (when message-signature
1973 (message-insert-signature)))))))
1976 (if (symbolp (car result
))
1977 (capitalize (symbol-name (car result
)))
1981 (message-remove-header ,header
)
1982 (let ((value ,(cdr result
)))
1985 (insert ,header
": " value
)
1987 (insert "\n")))))))))
1989 (when (or name address
)
1990 (add-hook 'message-setup-hook
1992 (set (make-local-variable 'user-mail-address
)
1993 ,(or (cdr address
) user-mail-address
))
1994 (let ((user-full-name ,(or (cdr name
) (user-full-name)))
1996 ,(or (cdr address
) user-mail-address
)))
1998 (message-remove-header "From")
2000 (insert "From: " (message-make-from) "\n"))))
2005 ;;; gnus-msg.el ends here