Mail-Karmasphere-Client
view release on metacpan or search on metacpan
karmad-exim view on Meta::CPAN
"verbose-header" => \$verbose_header,
"verbose-headers" => \$verbose_header,
"cutoff-fail=i" => \$cutoff_fail,
"cutoff-pass=i" => \$cutoff_pass,
"syslog" => \$syslog,
);
$mta ||= "exim";
$cutoff_pass = +300 if not defined $cutoff_pass;
$cutoff_fail = -300 if not defined $cutoff_fail;
if ($syslog) { $syslog = LOG_MAIL }
openlog "karmad", LOG_PID, $syslog if $syslog;
syslog (LOG_INFO, "starting. mta=%s server=%s feedset=%s action=%s", $mta, $server, $composite, $action) if $syslog;
syslog (LOG_DEBUG, "starting. cutoff-fail=%s, cutoff-pass=%s, verbose-header=%s", $cutoff_fail, $cutoff_pass, $verbose_header) if $syslog;
syslog (LOG_DEBUG, "starting. username=%s password=%s", $login, map { "x" x length($_) } $pass) if $syslog;
if (!$result or $help) {
usage();
exit 0;
}
my @args;
my $socktype;
my $listen = undef;
if ($sockaddr =~ /\D/) {
unlink($sockaddr) if -S $sockaddr;
$listen = new IO::Socket::UNIX(
Listen => 1,
Local => $sockaddr,
)
or die "Failed to create socket: $!";
my ($uid, $gid);
unless ($>) {
unless ($socketuser) {
$socketuser = 'nobody';
}
if ($socketuser =~ /\D/) {
$uid = getpwnam($socketuser)
or die "Socket user $socketuser not found: $!";
}
else {
$uid = $socketuser;
}
unless ($socketgroup) {
$socketgroup = 'nogroup';
}
if ($socketgroup =~ /\D/) {
$gid = getgrnam($socketgroup)
or die "Socket group $socketgroup not found: $!";
}
else {
$gid = $socketgroup;
}
chown($uid, $gid, $sockaddr)
or die "chown($socketuser=$uid, $socketgroup=$gid, $sockaddr) failed";
}
elsif ($socketuser or $socketgroup) {
warn "Cannot change socket owner as non-root.";
}
if (defined $socketmode) {
chmod(oct($socketmode), $sockaddr)
or die "chmod($socketmode, $sockaddr) failed";
}
syslog LOG_INFO, "listening on %s", $sockaddr if $syslog;
}
else {
$listen = new IO::Socket::INET(
Listen => 1,
# LocalAddr => "127.0.0.1",
LocalPort => $sockaddr,
ReuseAddr => 1
)
or die "Failed to create socket: $!";
syslog LOG_INFO, "listening on %s", $sockaddr if $syslog;
}
unless ($>) {
my ($uid, $gid);
unless ($group) {
$group = 'nobody';
}
if ($group =~ /\D/) {
$gid = getpwnam($group)
or die "Runtime group $group not found: $!";
}
else {
$gid = $group;
}
$( = $gid;
$) = $gid;
unless ($( == $gid and $) == $gid) {
die "Failed to change to group $group: $!\n";
}
unless ($user) {
$user = 'nobody';
}
if ($user =~ /\D/) {
$uid = getpwnam($user)
or die "Runtime user $user not found: $!";
}
else {
$uid = $user;
}
$< = $uid;
$> = $uid;
unless ($< == $uid and $> == $uid) {
die "Failed to change to user $user: $!\n";
}
}
karmad-exim view on Meta::CPAN
the score, but you decide policy. If you do not, they will
default to +300 and -300.
=item --action
Optional.
If you're running postfix, you can set --action to one of
C<prepend> (default) or C<reject>. Prepend will prepend an
X-Karma header. Reject will cause any mail with a karma
score below C<cutoff-fail> to be rejected. Use this only if
you are happy with the results you've observed.
If not specified, defaults to C<prepend>.
=item --verbose-header
Optional.
If you've set C<action> to C<prepend>, this flag will add
two fields to the X-Karma header: C<identities> shows what
was queried, and C<query_id> includes the timestamp and (if
available) the MTA's queue ID.) This is useful for
debugging purposes: it allows one to replay the query.
=item --username
=item --password
Optional.
Query credentials for authenticated queries. You only need
to set this if you're querying a restricted feedset. For
more information, see
L<http://www.karmasphere.com/devzone/client/configuration#credentials>
=item --socket
Where to listen. Defaults to /tmp/karmad. You probably
don't need to set this.
=item --server
Hostname of the Karmasphere Query Server to connect to.
Defaults to query.karmasphere.com. You probably don't need
to set this, unless you have set up a local query server, in
which case you should be following the directions provided
with that server.
=item --feedset
The name of the feedset you want to query. Defaults to
karmasphere.email-sender. You probably don't need to set
this.
=item --socketuser
=item --socketgroup
Who to listen as; defaults to 'nobody'. The socket file
will be chowned to this user and group. You probably don't
need to set this.
=item --socketmode
Mode to chmod the socket. You probably don't need to set
this.
=item --user
=item --group
When running, setuid to this user and group. Defaults to
'nobody', 'nobody'. You probably don't need to set this.
=item --syslog
Syslog verbosely to mail.info and mail.debug.
=back
=head1 OPERATIONAL USAGE
Connect to the socket (default: /tmp/karmad) and send the
following newline-terminated stanza:
client_address=192.0.2.1
helo_name=host.example.com
sender=localpart@example.com
Each of the above lines is optional; you may omit whatever is unavailable.
If all goes well, Karmad will return the following stanza:
value=NN
opinion=(good|bad|neutral)
data=.....
"Value" is a number between -1000 and +1000.
"Opinion" is one of good, bad, or neutral. If the value is
greater than 300, opinion is good. If the value is less
than -300, the opinion is bad. If it's between, opinion is
neutral.
"Data" contains a brief explanation of how the verdict was reached.
If an error occurs, Karmad will return:
error=...
usually, something like
error=timeout
error=Incorrect user and/or password.
=head1 HOW TO TEST THAT IT'S WORKING
This section assumes you're running Postfix.
% ./karmad --mta=postfix --action=prepend --verbose-header
( run in 0.697 second using v1.01-cache-2.11-cpan-71847e10f99 )