Comment fix.
[bpt/emacs.git] / lisp / gnus / nngateway.el
CommitLineData
eec82323 1;;; nngateway.el --- posting news via mail gateways
16409b0b
GM
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000
4;; Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news, mail
8
9;; This file is part of GNU Emacs.
10
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 2, or (at your option)
14;; any later version.
15
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.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27
28;;; Code:
29
436cc82c 30(eval-when-compile (require 'cl))
eec82323
LMI
31(require 'nnoo)
32(require 'message)
33
34(nnoo-declare nngateway)
35
36(defvoo nngateway-address nil
37 "Address of the mail-to-news gateway.")
38
39(defvoo nngateway-header-transformation 'nngateway-simple-header-transformation
40 "Function to be called to rewrite the news headers into mail headers.
41It is called narrowed to the headers to be transformed with one
42parameter -- the gateway address.")
43
44;;; Interface functions
45
46(nnoo-define-basics nngateway)
47
48(deffoo nngateway-open-server (server &optional defs)
49 (if (nngateway-server-opened server)
50 t
51 (unless (assq 'nngateway-address defs)
52 (setq defs (append defs (list (list 'nngateway-address server)))))
53 (nnoo-change-server 'nngateway server defs)))
54
55(deffoo nngateway-request-post (&optional server)
56 (when (or (nngateway-server-opened server)
57 (nngateway-open-server server))
58 ;; Rewrite the header.
59 (let ((buf (current-buffer)))
16409b0b 60 (with-temp-buffer
eec82323
LMI
61 (insert-buffer-substring buf)
62 (message-narrow-to-head)
63 (funcall nngateway-header-transformation nngateway-address)
a8151ef7
LMI
64 (goto-char (point-max))
65 (insert mail-header-separator "\n")
eec82323
LMI
66 (widen)
67 (let (message-required-mail-headers)
6748645f
LMI
68 (funcall message-send-mail-function))
69 t))))
eec82323
LMI
70
71;;; Internal functions
72
73(defun nngateway-simple-header-transformation (gateway)
74 "Transform the headers to use GATEWAY."
75 (let ((newsgroups (mail-fetch-field "newsgroups")))
76 (message-remove-header "to")
77 (message-remove-header "cc")
78 (goto-char (point-min))
79 (insert "To: " (nnheader-replace-chars-in-string newsgroups ?. ?-)
80 "@" gateway "\n")))
81
6748645f
LMI
82(defun nngateway-mail2news-header-transformation (gateway)
83 "Transform the headers for sending to a mail2news gateway."
84 (message-remove-header "to")
85 (message-remove-header "cc")
86 (goto-char (point-min))
87 (insert "To: " gateway "\n"))
88
eec82323
LMI
89(nnoo-define-skeleton nngateway)
90
91(provide 'nngateway)
92
93;;; nngateway.el ends here