Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 05-15-2007, 11:10 AM
Moderator
 
Posts: 927
Default First version done!!

Ok, well I've pulled together some sample code from the net, played around with it a little and I have a version that works!

I'm using pop3 and the always bcc function, deleting the mail from the copy account once it's been announced. The script is running now and is shown for your amusement below. This only really took about an hour, I'm new to perl and there are some parts of this code that I dont actually understand. Perhaps once you have all finished laughing, you can offer a reworked version?

I'll come back to the code tomorrow and try to make something more concise, but for now, rest

PHP Code:
#!/usr/bin/perl -w

use Net::POP3;

while () {
print 
"Checking POP3 Server.... \n";

# Connect to pop3 server
my $pop3 Net::POP3->new("10.100.100.2") || die "Error : Couldn't log on to server";

# Login to pop3 server
my $Num_Message $pop3->login("spokenemail""spokenemail");
my $Messages $pop3->list();
my ($MsgId$MsgDate$MsgFrom$MsgTo$MsgCc$MsgSub);
my ($MsgAttach$MsgSize$MsgHeader$MsgHeadFlg$MsgBody);

foreach 
$MsgNo (keys %$Messages)
    {
    
my $MsgContent $pop3->get($MsgNo);
    
my $count 0;
    
$MsgHeadFlg 0;
    
$MsgBody "";
 
    
# Process message data
    
while()
    {

    
# Exit if last line of mail
    
if ($count >= scalar(@$MsgContent))
        {
        
last;
        }

        
# Check if end of mail header
        
if (@$MsgContent[$count] =~ /^n/)
        {
        
$MsgHeadFlg 1;
        }

    
# Proceed if message header not processed
    
if (not $MsgHeadFlg)
        {

        
# Split the line 
        
my @LineContent split /: /, @$MsgContent[$count];

        
# Check Header Info
        
SWITCH:
        {
        
# Get message from
        
$LineContent[0] =~ /From/&& do
            {
            
$MsgFrom $LineContent[1];
            
last SWITCH;
        };
    
        
# Get message to
        
$LineContent[0] =~ /To/&& do
        {
        
$MsgTo $LineContent[1];
print 
$MsgTo;
        
last SWITCH;
        };
        
        
# Get message subject
        
$LineContent[0] =~ /Subject/&& do
        {
        
$MsgSub $LineContent[1];
        
last SWITCH;
        };
    }
    }
    else
    {
    
# Process message body
    
$MsgBody .= @$MsgContent[$count];
    }
    
$count++;
  }
  
system "swift 'New message from: $MsgFrom'";
  
system "swift 'For: $MsgTo'";
  
system "swift 'Subject is: $MsgSub'";
  
$pop3->delete($MsgNo);
}

# Disconnect from pop3 server
$pop3->quit();

sleep (30);


Reply With Quote
  #12 (permalink)  
Old 05-16-2007, 03:39 AM
Moderator
 
Posts: 927
Default And version 2

Right, I've managed a newter version of the code, it has some screen feedback and its shorter.

I'm done with this now, task achieved, I know the only zimbra centric part of this was a single line adding to the postfix conf, but still, I'd have struggled without that but of advice, thanks all.

PHP Code:
#!/usr/bin/perl -w

use Net::POP3;
# ----- Define email server and account -----
my $pop3server "192.169.0.1";
my $username "user";
my $password "pass";
# -------------------------------------------

my $speechstring;

while () {
    
my $pop3 Net::POP3->new($pop3serverTimeout=>10Debug=>0) || die "Error : Couldn't log on to server";
    print 
"Checking POP3 server.... ";

    
my $pop3_msgcount $pop3->login($username$password);
    print 
"Messages found: $pop3_msgcount \n";

    
unless ($pop3_msgcount eq "0e0") {
        foreach 
my $pop3_id (.. $pop3_msgcount) {
            
$pop3_header $pop3 -> top($pop3_id0);
            
my ($pop3_to$pop3_from$pop3_subject) = read_header($pop3_header);
            
$speechstring "Message from: $pop3_from, for: $pop3_to, Subject is: $pop3_subject.\n";
            
system "swift \"$speechstring\"";
            print 
$speechstring;
            
$pop3 -> delete ($pop3_id);
        }
    }
    
$pop3 -> quit();
    print 
"Will poll server in 30 seconds... \n";
    
sleep (10);
    print 
"20... \n";
    
sleep (10);
    print 
"10... \n";
    
sleep (10);
}

sub read_header {
    
my $header_array_ref shift;
    
my $header join "", @$header_array_ref;

    
my ($pop3_subject) = $header =~ /Subject: (.*)/m;

    
my ($pop3_from) = $header =~ /From"(.*)\" </m;
    if (!$pop3_from) {
        ($pop3_from) = $header =~ /From: (.*) </m;
    }
    if (!$pop3_from) {
        ($pop3_from) = $header =~ /From: (.*)@/m;
    }
    if (!$pop3_from) {
        ($pop3_from) = "
Unknown";
    }

    my ($pop3_to) = $header =~ /To: \"(.*)\" </m;
    if (!$pop3_to) {
        ($pop3_to) = $header =~ /To: (.*) </m;
    }
    if (!$pop3_to) {
        ($pop3_to) = $header =~ /To: <(.*)@/m;
    }
    if (!$pop3_to) {
        ($pop3_to) = $header =~ /To: (.*)@/m;
    }
    if (!$pop3_to) {
        ($pop3_to) = "
Unknown";
    }

    return ($pop3_to, $pop3_from, $pop3_subject);


Last edited by Dirk; 05-16-2007 at 03:42 AM..
Reply With Quote
  #13 (permalink)  
Old 05-16-2007, 10:54 AM
raj raj is offline
Moderator
 
Posts: 768
Default

Cool..it was nice to talk about things which are FUN than usual admin stuff.

Remember when you upgrade your postfix config will be overwitten..so u should add the always_bcc line again..

Cheers..
Raj
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.