LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-10-2011, 11:49 PM   #1
wasamzy
Member
 
Registered: Apr 2009
Location: Ghana Accra
Posts: 64

Rep: Reputation: 15
icewarp mail server


Hi,

I am having some problem with the content filter. The issue is that, I
have a script that the filter is suppose to run. The script is written
in perl.

The way it is suppose to work is, the content filter have to feed the
email address the mail is coming from to the script as an input. The
script then takes the email address and filter's the mail accordingly.

Please I want to know how icewarp content filter parses an email address to a program as an input?

I need a help with this.




NB: This script works with qmail as the mail server and procmail as the
content filter.


I tried to use procmail in icewarp as external filter, but it didn't
work either.

Also, the content filter is able to run the scrip, but just that it is not parsing the email address to the script.

Below is the script:

#!/usr/bin/perl

# Title: Mail fiter script
# version: 0.1v
# Description: The script accepts mail from stdin fed from procmail, and do a querry to mssql database to perfom the neccesary filtering.
# Author: Emmanuel Buamah
# Written for: TeledataICT


#Required modules:
# Mail::Internet
# DBI
# Mail::Message
# Mail::Head
#Shell
use strict;
use DBI;
use Mail::Internet;
use Mail::Sendmail;
use Mail::Header;
use Mail::Address;
use Net::POP3;
##################################################################
sendlog();
my ($ref, $mid, $mail, $sql, $sth, $data, $sender, $message_sent, $message);


# Read mail from STDIN
my $mail = Mail::Internet->new( \*STDIN );

# Creating an empty mail object
my $reply = Mail::Internet->new();

# Locate address of sender. The get() method returns a header line from the
# message, or undef if it doesn't exist.
my $headers = $mail->head->header_hashref;
# $sender = $mail->get('Reply-To') or
$sender = $mail->get('From');

my @sender = @{${$headers}{'From'}};
my $from = $headers->{From}->[0];

#split and use only the email address part
my @hfrom = split(/[<>]/, $from);
my $emailfrom = $hfrom[1];

$sender = (Mail::Address->parse($sender))[0];
#$reply->add(To => $sender->format);
my $mailto = "mbryqf\@dot.com.gh";
#my $newreply->add(To => $mailaddr->format);
my $subject = $headers->{Subject}->[0];

my $email = $emailfrom;

my $body = join '', @{ $mail->body };
my @newbody = split(//, $body);

#$body = @newbody[1];
print $body . "\n";


my $support = "support\@dot.com.gh";

my @newmessage = ( "You are not authorized to send email message to $support from $email.\n",
"For any clarification, please call Teledata ICT customer service deparment",
" on \+233-30-2234488 weekdays between 0900 and 1700\n\n",
"Best Regards,\n",
"Customer Support\n",
"Teledata ICT Ltd\n" );

my $subauto = "AUTO RESPONDER - Not autorized to send to $support";

#database connection
my $data_source = q/dbi:ODBC:MSSQLServer/;
my $user = q/test/;
my $password = q/test/;
my $dbh = DBI->connect($data_source, $user, $password);

my $logfile = "/tmp/mailfilter.log";
my $date = localtime();
my $logmesg = $date;
open LOGFILE, ">>$logfile" or die "can't open logfile $logfile for writting $!";


if (!$dbh)
{
$subject = "AM-100" . "" . $subject;
sendEmail("$mailto", "$email", "$subject", "$body");
print LOGFILE $logmesg, "\tError connceting to the $data_source:$DBI::errstr\n \t\tMail sent with subject: $subject, succesfuly to $mailto \n";
}

my $error = "Can't prepare statement: $DBI::errstr";
$sql = "select coalesce(acm,0)acm from accounts where id in (select accid from category ";
$sql .= "where email like '%" . $email . "%') and coalesce(acm,0)>0";
$sth = $dbh->prepare($sql) or die "$error";


$sth->execute();
my $exist = $sth->fetchrow_array();

if ($exist)
{
#$subject = "AM-$exist $subject";
$subject = "AM-$exist $subject";
sendEmail("$mailto", "$email", "$subject", "$body");
print LOGFILE $date, "\t$email Found in database. Mail sent succesfuly to $mailto with the subject $subject \n";


}
else
{
sendEmail("$email", "$support","$subauto", "@newmessage");
print LOGFILE $logmesg, "\t$emailfrom was not found in database, message rejected from $emailfrom\n";

}

close(MAIL);
close(LOGFILE);
deletemail();

###################################################################
sub sendlog
{
my $logfile = "/tmp/mailfilter.log";
my $date = localtime();
my $logmesg = $date;
my $logstr = shift();
open LOGFILE, ">>$logfile" or die "can't open logfile $logfile for appemd $!";
print LOGFILE $logmesg, "\tStarting\....................\n";
close LOGFILE;

}
######################################################################

sub sendEmail
{
my ($mailto, $emailfrom, $subject, $body) = @_;
my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $emailfrom\n";
print MAIL "To: $mailto\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$body \n";
close(MAIL);
}
###############################################################################################
sub deletemail
{
my ($connection, $host, $port, $deleted, $login, $user, $passwd, $messages, $mail, $message);

my $logfile = "/tmp/mailfilter.log";
my $date = localtime();
open LOGFILE, ">>$logfile" or die "can't open logfile $logfile for appemd $!";

$host = "41.211.31.55";
$port = 110;
$connection = Net::POP3->new($host, Timeout => 30);
if (!$connection)
{
print LOGFILE $date, "\tERROR:Unable to conncet to pop server $host\n";

}
$user = "support\@dot.com.gh";
$passwd = "crack";

$login = $connection->login($user,$passwd);
if (!$login)
{
print LOGFILE $date, "\t ERROR:Unable to login to host $host. check user and password\n";

}

$messages = $connection->list() or print LOFILE $date, "\t Can't get list of undeleted messages:$!\n";
foreach $mail(keys %$messages)
{
$message = $connection->get($mail);

unless (defined $message)
{
print LOGFILE $date, warn "\t Couldn't fetch $mail from server $host. $!\n";
next;
}
$connection->delete($mail);
}
close LOGFILE;
$connection->quit();



}


Regards
 
Old 02-11-2011, 07:07 PM   #2
tenmei08
LQ Newbie
 
Registered: Jan 2011
Location: Roatan Honduras
Distribution: Debian Lenny, Squeeze, Ubuntu Various
Posts: 13

Rep: Reputation: 5
Mail server issue

I've used Icewarp in the old Windows days. I can't help with this but I wonder why you're not addressing this to the Icewarp Support or Forum?

Not trying to be mean, but you might get more and faster responses from them.
Good luck!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mail server naughtyness; mail from:user@server rcpt to:user@server on exim bicpen Linux - Server 1 01-27-2011 11:53 AM
mail server migration: howto deliver locally AND forward mail to new server pedrobl Linux - Server 1 01-21-2011 11:12 PM
How to connect linux mail server with the exchange mail server nanuseenu Linux - Newbie 4 03-04-2008 03:37 AM
Mail Server Delimiter for alternate mail server venugopalmk Linux - Networking 2 04-29-2003 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration