hellkvist.org Forum Index hellkvist.org
Discussions about the free software on hellkvist.org
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MMS to Email Delivery on Hosted Server

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    hellkvist.org Forum Index -> Peffisaur
View previous topic :: View next topic  
Author Message
andym



Joined: 16 Aug 2004
Posts: 6

PostPosted: Wed Aug 18, 2004 5:35 pm    Post subject: MMS to Email Delivery on Hosted Server Reply with quote

I have Peffisaur up and running for Direct posting of MMS messages from a Nokia Observation camera (Incidentally, Stefan - you can add that to your list of phones! It's actually based on a 7650). But I'm struggling to set up the email functionality, so here are my details:

Since I use a hosted server - the root web directory is:

/home/my_username/public_html

Peffisuar is served up from:
Code:
/home/my_username/public_html/peffisaur/index.php


Since I don't have root access to the server, I have compiled and installed munpack to:
Code:
/home/my_username/munpack/bin/munpack


msgstore is in:
Code:
/home/my_username/public_html/peffisaur/msgstore/


and the tmp directory is:

Code:
/home/my_username/tmp


.procmailrc and recmail.pl (the updated version) are both in:
Code:
/home/my_username/


I have set up a filter to capture all mail addressed to mail addresses beginning with "p-" using a .filter file with the setting:

Code:
$header_to: begins "p-"+++++++|/home/my_username/.procmailrc


So far so good - the mails are captured and routed through the .procmailrc file.

BUT - I don't get a recmail.log file in my tmp directory.

The settings in my recmail.pl file are
Code:
$driver ="mysql";
$user = "my_user";
$password = "my_password";
$munpack = "/home/my_username/munpack/bin/munpack";
$msgstore = "/home/my_username/public_html/peffisaur/msgstore";
$reldir = "msgstore";


and .procmailrc contains:
Code:
LOGFILE=/home/my_username/tmp/recmail.log

:0
| /home/my_username/recmail.pl


The emails aren't captured by the peffisaur app, nor do they appear in the catch all account - they disappear into thin air. Can anyone help?

I can't access the logs or use tail to see what's happening, since it's a hosted server - so any help appreciated?

Maybe something to do with the configs or my code somewhere.

Oh - and I changed the database in the recmail.pl file to reflect mine.

Any ideas?
Back to top
View user's profile Send private message MSN Messenger
Peffis
Site Admin


Joined: 09 Sep 2003
Posts: 324
Location: Sweden

PostPosted: Wed Aug 18, 2004 9:26 pm    Post subject: Reply with quote

When I installed it at one place I actually also needed a .forward with the content
Code:
|/usr/bin/procmail
or else it would not get processed by procmail and never reach recmail.pl.

But in your case I don't see that that is the case as you say it gets through .procmailrc.

Wait a second btw...the .procmailrc that your filter routs the message to. I don't think that really is a script that should be executed. Instead it's a resource file read by procmail when the mail is routed to procmail. The file itself, the .procmailrc should not be executed I think. I bet there's an error in your email spool logs somewhere saying that it cannot execute or something.

Either try piping it to /usr/bin/procmail or alter the filter line so that it pipes it directly to recmail.pl instead. Because that's all there is to procmailrc. It pipes it to the script.
Back to top
View user's profile Send private message Visit poster's website
andym



Joined: 16 Aug 2004
Posts: 6

PostPosted: Thu Aug 19, 2004 8:23 am    Post subject: Reply with quote

I altered the filter to pipe through recmail.pl directly and nothing happens. The email disappears completely. Nothing appears in the msgstore or the database.

my filter file, which is in /home/my_username/.filter now contains

Code:
$header_to: begins "p-"+++++++|/home/my_username/recmail.pl
and seems to be working, otherwise the email will appear in the catch all account.

The recmail.pl contains the following
Code:
#!/usr/bin/perl

use DBI;

$driver ="mysql";
$user = "my-user";
$password = "my-password";
$munpack = "/home/my_username/munpack/bin/munpack";
$msgstore = "/home/my_username/public_html/peffisaur/msgstore";
$reldir = "msgstore";

umask( 0 );

while ( $line = <STDIN> )
{
    @tmp = split( ": ", $line );

    if ( lc($tmp[0]) eq "to" )
    {
   chop( $tmp[1] );
   $to = $tmp[1];
    }
    elsif ( lc($tmp[0]) eq 'from' )
    {
   chop( $tmp[1] );
   $from = $tmp[1];
    }
    elsif ( lc($tmp[0]) eq 'subject' )
    {
   chop( $tmp[1] );
   $subject = $tmp[1];
    }
    elsif ( lc($tmp[0]) eq 'content-type' )
    {
   last;
    }
}

$dsn = "DBI:$driver:database=my-database;host=localhost";
$dbh = DBI->connect( $dsn, $user, $password );
   
$id = isValid( $to, $from ) || die( "Not a valid user $to $from" );

$time = time();

$dirname = $msgstore . "/" . $$ . "_" . $time . "_email";
mkdir( $dirname, 0775 );

open(UNPACK,"| $munpack -q -C $dirname > $dirname/info.txt 2> /dev/null" )
    || die( "Could not start unpacker program");

print( UNPACK $line );

while ( $line = <STDIN> )
{
    print( UNPACK $line );
}

close( UNPACK );

$info = $dirname . '/info.txt';

open( INFO, $info ) || die( "Could not open info file [$!]" );

$size = 0;
while ( $line = <INFO> )
{
    @tmp = split( " ", $line );
    $tmp[1] = substr( $tmp[1], 1, length($tmp[1])-2 );
    $content{$tmp[0]} = $tmp[1];

    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
     $atime,$mtime,$ctime,$blksize,$blocks)
   = stat( $dirname . "/" . $tmp[0] );
    $size += $blksize * $blocks;
    $content_size{$tmp[0]} = $size;
}

close( INFO );

$mid = storeMessage( $to, $id, $subject, int( $size / 1024 ) );

foreach $file ( keys(%content) )
{
    storeContent( $mid, $file, $content{$file}, $content_size{$file} );
}

$txt = getTextForMid( $mid );
if ( length( $txt ) > 0 )
{
    setTextForMid( $mid, $txt );
}


sub storeContent
{
    ($mid, $file, $type, $size) = @_;
    $fname = $reldir  . "/" . $$ . "_" . $time . "_email/". $file;
    $query = "INSERT INTO content VALUES " .
   "(NULL, $mid, '$type', '$fname', $size )";
    chmod( 0775, $msgstore . "/" . $$ . "_" . $time . "_email/". $fname );
    $sth = $dbh->prepare($query) || die;
    $sth->execute();
}

sub setTextForMid
{
    ( $mid, $txt ) = @_;
    $txt = $dbh->quote( $txt );
    $query = "UPDATE messages SET textmsg=$txt WHERE id=$mid";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();
}

sub getTextForMid
{
    ($mid) = @_;

    $query = "SELECT fname FROM content WHERE mid=$mid && ".
   "contenttype='text/plain'";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();
   
    if ( @row = $sth->fetchrow() )
    {
   $fname = $row[0];
   open( TXTFILE, $msgstore . "/../" . $fname );
   @content = <TXTFILE>;
   $txt = join('', @content);
   return $txt;
    }
    return "";
}

sub storeMessage
{
    ($to, $sid, $subject, $size ) = @_;
    $subject = $dbh->quote($subject);
    $to = $dbh->quote($to);
    $query = "INSERT INTO messages VALUES " .
   "(NULL, $sid, 1, $to, $subject, NOW(), 'email', '0.0.0.0', 0, 0, '', 0  )";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();

    $query = "SELECT LAST_INSERT_ID() FROM messages";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();
    @row = $sth->fetchrow();
    $id = $row[0];

    $query = "UPDATE users SET nkbytes=nkbytes+$size, ".
   " lastupload=NOW(), ".
       " nuploads=nuploads+1 WHERE id=$sid";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();

    return $id;
}

#isValid
#to-address is on form p-<number>@domain.com
#from-address is on form <MSISDN>@domain.com
sub isValid
{
    ($to, $from) = @_;
    $end = index( $to, "@" );
    $start = index( $to, "p-" );
    $pwd = substr( $to, $start + 2, $end - $start - 2 );
   
    @froms = split( "@", $from );
    $msisdn = $froms[0];
    if ( ($index = index( $msisdn, "<" )) >= 0 )
    {
   $msisdn = substr( $msisdn, $index + 1 );
    }

    $query = "SELECT id FROM users WHERE phonepwd='$pwd'";
    $sth = $dbh->prepare($query) || die;
    $sth->execute();

    $id = 0;   
    if ( @row = $sth->fetchrow() )
    {
   $id = $row[0];
    }
    $sth->finish();

    $id || die( "msisdn is $msisdn and pwd is $pwd" );

    return $id;
}



my email address if I send directly to an email account comes up as 447799xxxxx@mmsbe2.vodafone.co.uk (I changed the numbers!) and I have added the 447799xxxxxx into the preferences in Peffisaur, so everything should work!

Can you see anything wrong? It seems it's half working - just not processing the email.[/b][/i]
Back to top
View user's profile Send private message MSN Messenger
Peffis
Site Admin


Joined: 09 Sep 2003
Posts: 324
Location: Sweden

PostPosted: Thu Aug 19, 2004 8:40 am    Post subject: Reply with quote

First: the sender check is removed in that version (and mine) so the sender address does not really matter any longer (it turned out to be too hard for average Joe to figure out what to do).

Second: There doesn't seem to be anything wrong with the script, assuming that it is executable by the user the mail server runs as, that msgstore is writable by the user the mail server runs as, that your home directory is readable by the user the mail server runs as and that your munpack is executable and that all the directories down to munpack/bin are readable.

Could you replace recmail.pl with some much simpler script that, say, write "Hello" to a file whenever it is called? Just to verify that the scipt is actually called.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    hellkvist.org Forum Index -> Peffisaur All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group