kartero v0.02
[kartero.git] / kartero
blob122b3f9255e04505bfb2d0272d55ed3150d24ef7
1 #!/usr/bin/perl -wT
2 # -*- Mode: Perl -*-
3 # kartero -- a user-session Mail Relay Agent
5 # Copyright (C) 2007 Zak B. Elep <zakame@spunge.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use warnings;
24 use Carp;
25 use Config::IniFiles;
26 use Date::Format;
27 use Net::SMTP::Server;
28 use Net::SMTP::Server::Client;
29 use Net::SMTP::Server::SmartHost;
31 our $VERSION = $Net::SMTP::Server::SmartHost::VERSION;
33 my %ini;
34 tie %ini, 'Config::IniFiles', -file => "$ENV{HOME}/.karterorc";
36 my $server = Net::SMTP::Server->new($ini{server}{host}, $ini{server}{port})
37 or croak "Unable to start SMTP server at "
38 . "$ini{server}{host}:$ini{server}{port}: $!\n";
40 my $smarthost = (split ':' => $ini{relay}{smarthost})[0] || 'localhost';
41 my $port = (split ':' => $ini{relay}{smarthost})[1] || 25;
43 my $relay = Net::SMTP::Server::SmartHost->new($smarthost, $port);
45 while (my $conn = $server->accept) {
46 my $client = Net::SMTP::Server::Client->new($conn)
47 or croak "Unable to handle client connection: $!\n";
49 $client->process || next;
51 $relay->auth($ini{relay}{username}, $ini{relay}{passwd})
52 if defined($ini{relay}{username}) && defined($ini{relay}{passwd});
54 my $received;
55 my $time = time2str("%a, %e %h %Y %X %z", time);
57 ($received = <<" EOF") =~ s/^\s\s//gm;
58 Received: from $ENV{USER} by $ini{server}{host}
59 with local (kartero $VERSION); $time
60 EOF
62 $relay->relay($client->{FROM}, $client->{TO}, $received . $client->{MSG});
65 __END__
66 # POD follows
68 =head1 NAME
70 kartero - relay mails to a smarhost
73 =head1 SYNOPSIS
75 kartero [options]
78 =head1 DESCRIPTION
80 C<kartero> is a program that relays outgoing mail from a Mail User Agent
81 (MUAs such as KMail, Gnus, or Icedove) to a ``smart host'' that does the
82 actual transport to the mail's destination. It uses the bundled
83 Net::SMTP::Server::SmartHost module to spawn a local SMTP server that
84 the user's MUA can talk to, and relay, outgoing mail.
87 =head1 CONFIGURATION
89 C<kartero> is configured by reading the C<.karterorc> file in the user's
90 home directory. This configuration file follow the INI convention
91 commonly found in many Windows applications.
94 =head2 Server Block
96 =over 4
98 =item host
100 Name of the host where C<kartero> will listen on.
102 =item port
104 Name of the port where C<kartero> will listen on.
106 =back
109 =head2 Relay Block
111 =over 4
113 =item name
115 Name of the account for this smarthost.
117 =item smarthost
119 The actual address of the smarthost.
121 =item auth
123 Whether C<kartero> should authenticate to the smarthost.
125 =item username
127 When C<auth = yes>, use this username for authentication.
129 =item passwd
131 When C<auth = yes>, use this password for authentication.
133 =back
136 =head1 SEE ALSO
138 L<Net::SMTP>, L<Net::SMTP::Server>, L<Net::SMTP::Server::Client>,
139 L<Net::SMTP::Server::SmartHost>.
141 L<kartero> is part of the L<kartero> suite.
144 =head1 AUTHOR
146 Zak B. Elep, E<lt>zakame@spunge.orgE<gt>
149 =head1 COPYRIGHT AND LICENSE
151 Copyright (C) 2007 by Zak B. Elep
153 This program is free software; you can redistribute it and/or modify
154 it under the terms of the GNU General Public License as published by
155 the Free Software Foundation; either version 2 of the License, or
156 (at your option) any later version.
158 This program is distributed in the hope that it will be useful,
159 but WITHOUT ANY WARRANTY; without even the implied warranty of
160 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161 GNU General Public License for more details.
163 You should have received a copy of the GNU General Public License along
164 with this program; if not, write to the Free Software Foundation, Inc.,
165 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
168 =cut