Add 2010 to copyright years.
[bpt/emacs.git] / lisp / gnus / nngateway.el
CommitLineData
eec82323 1;;; nngateway.el --- posting news via mail gateways
16409b0b 2
e84b4b86 3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 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
5e809f55 11;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 12;; it under the terms of the GNU General Public License as published by
5e809f55
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
eec82323
LMI
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
5e809f55 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
23
24;;; Commentary:
25
26;;; Code:
27
436cc82c 28(eval-when-compile (require 'cl))
eec82323
LMI
29(require 'nnoo)
30(require 'message)
31
32(nnoo-declare nngateway)
33
34(defvoo nngateway-address nil
35 "Address of the mail-to-news gateway.")
36
37(defvoo nngateway-header-transformation 'nngateway-simple-header-transformation
38 "Function to be called to rewrite the news headers into mail headers.
39It is called narrowed to the headers to be transformed with one
40parameter -- the gateway address.")
41
42;;; Interface functions
43
44(nnoo-define-basics nngateway)
45
46(deffoo nngateway-open-server (server &optional defs)
47 (if (nngateway-server-opened server)
48 t
49 (unless (assq 'nngateway-address defs)
50 (setq defs (append defs (list (list 'nngateway-address server)))))
51 (nnoo-change-server 'nngateway server defs)))
52
53(deffoo nngateway-request-post (&optional server)
54 (when (or (nngateway-server-opened server)
55 (nngateway-open-server server))
56 ;; Rewrite the header.
57 (let ((buf (current-buffer)))
16409b0b 58 (with-temp-buffer
eec82323
LMI
59 (insert-buffer-substring buf)
60 (message-narrow-to-head)
61 (funcall nngateway-header-transformation nngateway-address)
a8151ef7
LMI
62 (goto-char (point-max))
63 (insert mail-header-separator "\n")
eec82323
LMI
64 (widen)
65 (let (message-required-mail-headers)
23f87bed
MB
66 (funcall (or message-send-mail-real-function
67 message-send-mail-function)))
6748645f 68 t))))
eec82323
LMI
69
70;;; Internal functions
71
72(defun nngateway-simple-header-transformation (gateway)
73 "Transform the headers to use GATEWAY."
74 (let ((newsgroups (mail-fetch-field "newsgroups")))
75 (message-remove-header "to")
76 (message-remove-header "cc")
77 (goto-char (point-min))
78 (insert "To: " (nnheader-replace-chars-in-string newsgroups ?. ?-)
79 "@" gateway "\n")))
80
6748645f
LMI
81(defun nngateway-mail2news-header-transformation (gateway)
82 "Transform the headers for sending to a mail2news gateway."
83 (message-remove-header "to")
84 (message-remove-header "cc")
85 (goto-char (point-min))
86 (insert "To: " gateway "\n"))
87
eec82323
LMI
88(nnoo-define-skeleton nngateway)
89
90(provide 'nngateway)
91
cbee283d 92;; arch-tag: f7ecb92e-b10c-43d5-9a9b-1314233341fc
eec82323 93;;; nngateway.el ends here