|
hellkvist.org Discussions about the free software on hellkvist.org
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Posted: Thu Aug 12, 2004 7:54 am Post subject: Perl error. |
|
|
After some headache with getting the webpage to work, you should but somewhere that you need to have Register_globals = On in php. ... or I might just have missed it...
But anyway, my problem is that when running the email thingy I get this error:
Undefined subroutine &main::strlen called at /home/pref/recmail.pl line 88.
Is it my perl installation that is missing something? |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Thu Aug 12, 2004 9:02 am Post subject: |
|
|
Nah, it's just an error in that version of recmail.pl. The fix was posted here in the forum once...somewhere...
Replace strlen with length and it should work.
There has also been a few other fixes to recmail.pl without there being a real release for it unfortunately. Therefore I just post the version I am currently using (and has been known to be working) here so that you can copy and paste it (with the risk that indentation goes berzerk). You'll need to insert your password and paths and stuff.
Enjoy!
/S
Code: |
#!/usr/local/bin/perl
use DBI;
$driver ="mysql";
$user = "<insert db user here>";
$password = "<insert db password here>";
$munpack = "/home/hellkvis/bin/munpack";
$msgstore = "/home/hellkvis/public_html/peffis/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=hellkvis_peffisaur;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;
}
|
|
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Thu Aug 12, 2004 9:07 am Post subject: |
|
|
...and yes. I will try and document the "Register globals" thingie...
There's also the "Safe Mode = Off" thingie which is probably undocumented
At least I need that at my webhost or I won't be able to store incoming files (the images) from send.php. |
|
Back to top |
|
|
joel Guest
|
Posted: Thu Aug 12, 2004 9:11 am Post subject: |
|
|
Thanks, works much better!
I needed to change the databasename also. Many thanks for the help.
One other thing, I cant get the modrewrite to work, do you know if there is anything I need to do to make it work in vhost in apache 2.0.49? |
|
Back to top |
|
|
joel Guest
|
Posted: Thu Aug 12, 2004 9:25 am Post subject: |
|
|
I use the email not the direct MMS, so I havent noticed the safemode error.
Actually, I set up my own SMTP server and uses that one from the phone and send as email directly. Then I only get to pay the data traffic and I dont need to fiddle around with the MMS settings.
This is on a Nec e616 on Swedish Tre (three). You also need to add another port and forward to port 25. Tre have blocket port 25, so I just use 2500 and forward.
Seems to work great! .. Now if I only can figure out whats wrong with Rewrite . |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Thu Aug 12, 2004 9:33 pm Post subject: |
|
|
In order for the .htaccess to have effect you will need to turn on the AllowOverride option in apache (so that users can have their own .htaccess). I think it was mentioned here in the forum some time ago....oh...yes...here it is: http://hellkvist.org/forum/viewtopic.php?t=92&highlight=htaccess
If that does not solve your problem you might need to edit the .htaccess - so that it matches where you have installed it.
But my guess is AllowOverride (httpd.conf) |
|
Back to top |
|
|
joel Guest
|
Posted: Fri Aug 13, 2004 9:11 pm Post subject: |
|
|
Will try that when I get home again. Thanks for your help.
If you want to you can add to your README that Nec e616 works fine atleast in email mode. |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Fri Aug 13, 2004 10:21 pm Post subject: |
|
|
Ok, good luck.
The thing is with the email interface, that there it is not so much the phone that needs to be put in a "working" list. It's more the operators. Because the MMSC sits in between your phone and Peffisaur in that case and translates the message to email and it's up to that one to make it work. The compatibility list is more useful when you use Peffisaur as MMSC. |
|
Back to top |
|
|
joel Guest
|
Posted: Sun Aug 15, 2004 9:46 pm Post subject: |
|
|
Works great now!, thanks alot for your help.
Getting some problems with UTF8/swedish åäö, but I remember seeing something about that on the forum, will check that out. |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Mon Aug 16, 2004 7:45 am Post subject: |
|
|
Good that it works now.
The Swedish characters and the email interface is still unsolved I think. Let me know if you find a solution. I think a conversion is needed.
What is solved is when you post directly to the site. Then it helps by simply setting the type of the page to UTF-8. The email case is another issue I'm afraid. |
|
Back to top |
|
|
joel Guest
|
Posted: Mon Aug 16, 2004 12:32 pm Post subject: |
|
|
Sorry to bother you again ...
First of all, should the message appear or only the subject? Because only the subject seems to work for me.
The swedish characters, wouldnt it be possible to somehave just have a conversionstable?
If =C3=A4 shows up it will convert it to ä, maybe in the recmail.pl script? I have never coded any perl so I dont know whats possible
Cheers,
Joel |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Mon Aug 16, 2004 1:32 pm Post subject: |
|
|
Hmm, what do you mean? Don't you get the image and the texts as well? If you don't I suppose there is something wrong with your setup of the munpack program that is used to unpack the incoming email and store the attachments in a file...or possibly there is write restrictions on the msgstore directory for the user that recmail.pl is running as. Have a look at http://peffis.com if you want to see how it should look like. You can also try it out there.
Yes, it would be possible to do such a conversion of characters. But it's not only that I'm afraid. It also adds some UTF-8 stuff at the beginning (the text UTF-8 and some other junk). I'm not familiar with the mail format really...but it should definitely be possible to change if one would like to. I just haven't had the time to do it. |
|
Back to top |
|
|
joel Guest
|
Posted: Mon Aug 16, 2004 1:44 pm Post subject: |
|
|
Looking at
http://peffis.com/~f.bonomi
There is a text below the image, which I guess is the "message" and the bold text at the top is the "subject".
Looking at my installation
http://mobil.rosafluffmoln.nu its only getting the subject, not the "message".
I have tried to see how the recmail.pl works but my perl knowledge is really poor. In the logfile in /tmp/ nothing shows up for the message either, but only the subject and the image.
Its not really a big thing, the subject is the important. |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Mon Aug 16, 2004 2:06 pm Post subject: |
|
|
Oh! That one! Yes, the text is the message (it's sent as an attachment of type text/plain).
Are you sure you are using the file I posted in this thread? Because there was a bug until just recently that made the text disappear. Did you take the entire file or did you just take the parts where you thought it differed? Because there is a small change in the function setTextForMid that made the message text work.
The function definition should look like this: Code: |
sub setTextForMid
{
( $mid, $txt ) = @_;
$txt = $dbh->quote( $txt );
$query = "UPDATE messages SET textmsg=$txt WHERE id=$mid";
$sth = $dbh->prepare($query) || die;
$sth->execute();
}
| and nothing else. What has changed is that there is now no ' around $txt. Have a look in your recmail.pl so that it looks like the one above.
Also make sure that the getTextForMid looks like this:
Code: | 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 "";
}
| (I think there was a bug in the "/../" that also prevented it from working before - this (see above) is what it should look like).
Once you have changed that it won't make the existing messages appear...just the new ones you send I'm afraid. |
|
Back to top |
|
|
Peffis Site Admin
Joined: 09 Sep 2003 Posts: 324 Location: Sweden
|
Posted: Mon Aug 16, 2004 2:17 pm Post subject: |
|
|
...otherwise, try and locate your recmail.log (it says in your .procmailrc where it should be) and see what it complains about |
|
Back to top |
|
|
|
|
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
|