Doc fixes
[bpt/emacs.git] / lisp / gnus / nngateway.el
CommitLineData
eec82323 1;;; nngateway.el --- posting news via mail gateways
16409b0b 2
ba318903 3;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news, mail
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
eec82323
LMI
14
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.
19
20;; You should have received a copy of the GNU General Public License
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
22
23;;; Commentary:
24
25;;; Code:
26
436cc82c 27(eval-when-compile (require 'cl))
eec82323
LMI
28(require 'nnoo)
29(require 'message)
30
31(nnoo-declare nngateway)
32
33(defvoo nngateway-address nil
34 "Address of the mail-to-news gateway.")
35
36(defvoo nngateway-header-transformation 'nngateway-simple-header-transformation
37 "Function to be called to rewrite the news headers into mail headers.
38It is called narrowed to the headers to be transformed with one
39parameter -- the gateway address.")
40
41;;; Interface functions
42
43(nnoo-define-basics nngateway)
44
45(deffoo nngateway-open-server (server &optional defs)
46 (if (nngateway-server-opened server)
47 t
48 (unless (assq 'nngateway-address defs)
49 (setq defs (append defs (list (list 'nngateway-address server)))))
50 (nnoo-change-server 'nngateway server defs)))
51
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)))
16409b0b 57 (with-temp-buffer
eec82323
LMI
58 (insert-buffer-substring buf)
59 (message-narrow-to-head)
60 (funcall nngateway-header-transformation nngateway-address)
a8151ef7
LMI
61 (goto-char (point-max))
62 (insert mail-header-separator "\n")
eec82323
LMI
63 (widen)
64 (let (message-required-mail-headers)
23f87bed
MB
65 (funcall (or message-send-mail-real-function
66 message-send-mail-function)))
6748645f 67 t))))
eec82323
LMI
68
69;;; Internal functions
70
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")))
79
6748645f
LMI
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"))
86
eec82323
LMI
87(nnoo-define-skeleton nngateway)
88
89(provide 'nngateway)
90
91;;; nngateway.el ends here