Merge branch 'master' into comment-cache
[emacs.git] / lisp / gnus / nngateway.el
blob1e57f7c6f6014963b4796b1cfdce24a1942b0278
1 ;;; nngateway.el --- posting news via mail gateways
3 ;; Copyright (C) 1996-2017 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl))
28 (require 'nnoo)
29 (require 'message)
31 (nnoo-declare nngateway)
33 (defvoo nngateway-address nil
34 "Address of the mail-to-news gateway.")
36 (defvoo nngateway-header-transformation 'nngateway-simple-header-transformation
37 "Function to be called to rewrite the news headers into mail headers.
38 It is called narrowed to the headers to be transformed with one
39 parameter -- the gateway address.")
41 ;;; Interface functions
43 (nnoo-define-basics nngateway)
45 (deffoo nngateway-open-server (server &optional defs)
46 (if (nngateway-server-opened server)
48 (unless (assq 'nngateway-address defs)
49 (setq defs (append defs (list (list 'nngateway-address server)))))
50 (nnoo-change-server 'nngateway server defs)))
52 (deffoo nngateway-request-post (&optional server)
53 (when (or (nngateway-server-opened server)
54 (nngateway-open-server server))
55 ;; Rewrite the header.
56 (let ((buf (current-buffer)))
57 (with-temp-buffer
58 (insert-buffer-substring buf)
59 (message-narrow-to-head)
60 (funcall nngateway-header-transformation nngateway-address)
61 (goto-char (point-max))
62 (insert mail-header-separator "\n")
63 (widen)
64 (let (message-required-mail-headers)
65 (funcall (or message-send-mail-real-function
66 message-send-mail-function)))
67 t))))
69 ;;; Internal functions
71 (defun nngateway-simple-header-transformation (gateway)
72 "Transform the headers to use GATEWAY."
73 (let ((newsgroups (mail-fetch-field "newsgroups")))
74 (message-remove-header "to")
75 (message-remove-header "cc")
76 (goto-char (point-min))
77 (insert "To: " (nnheader-replace-chars-in-string newsgroups ?. ?-)
78 "@" gateway "\n")))
80 (defun nngateway-mail2news-header-transformation (gateway)
81 "Transform the headers for sending to a mail2news gateway."
82 (message-remove-header "to")
83 (message-remove-header "cc")
84 (goto-char (point-min))
85 (insert "To: " gateway "\n"))
87 (nnoo-define-skeleton nngateway)
89 (provide 'nngateway)
91 ;;; nngateway.el ends here