PHP Classes

Missing a post on busy times

Recommend this page to a friend!

      pop3.class.inc  >  All threads  >  Missing a post on busy times  >  (Un) Subscribe thread alerts  
Subject:Missing a post on busy times
Summary:Seems to miss reading a post if one bomes in while it's busy
Messages:2
Author:John Brohan
Date:2007-10-21 16:21:57
Update:2007-10-22 11:41:07
 

  1. Missing a post on busy times   Reply   Report abuse  
Picture of John Brohan John Brohan - 2007-10-21 16:21:57
Hello
I'm using this excellent class to receive mail to several addresses @woundfollowup.com The messages typically include a jpeg attachment, so they are quite long. The php reads and stores the emails as .txt files, which are downloaded and interpreted by a program running on a slow laptop computer.
I do it this way because some of the images come directly from cell phones and these need to be 'unpicked' carefully. For the time being I'm doing this in another computer language.

If there are a lot of emails, or some ones with large images, I often lose an email.

I would be very happy if one of you could tell me where is my mistake or how to avoid this problem.

I include the php program.

Yours Sincerely
John


<?php session_start();
include_once('WFUConnect.php');
$nextfile=$_POST['nextfile'];
require ('pop3.class.inc');
$pop3 = new POP3;

// Connect to mail server
$do = $pop3->connect ('pop.videotron.ca');
if ($do == false) {
die($pop3->error);
}
echo 'Connected to mail server<br/>';


// Login to your inbox
$do = $pop3->login ('login', 'password');

if ($do == false) {
die($pop3->error);
}
echo "logged in<br/>";
// Get office status
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);
}
$count = $status['count_mails'];
echo "there are ".$count."emails waiting<br/>";
if ($count == '0') {
echo 'There are no new e-mails<br/>';
exit();
}


for ($i = 1; $i <= $count; $i++) {
$email = $pop3->get_mail($i);

if ($email == false) {
echo $pop3->error;
continue;
}
// print_r ($email);

$Text=implode($email);


$pos1 = strpos($Text,'To: ');
$pos1+=4;
$pos2 = strpos($Text,chr(10),$pos1);
$To = substr($Text,$pos1,$pos2-$pos1);
// if ($To != 'image@woundfollowup.com') break;
// echo "To =".$To."<br/>";
$pos1 = strpos($To,'@');
$username = trim(substr($To,0,$pos1));
$To = trim(substr($To,$pos1+1));
if(strtolower($To) != 'woundfollowup.com'){
$username=''; // dump spam and junk
}
// echo "username=".$username."To = ".$To;
$pos1 = strpos($Text,'From: ');
$pos1+=6;
$pos2 = strpos($Text,chr(10),$pos1);
$From = substr($Text,$pos1,$pos2-$pos1);
$pos1 = strpos($From,'<');
if ($pos1){
$pos2 = strpos($From,'>',$pos1);
$From = substr($From,$pos1+1,$pos2-$pos1-1);
}
$pos1 = strpos ($From,'@');
if ($pos1 > 0 ){
$phone = substr ($From,0,$pos1);
}
$pos1 = strpos($Text, 'Content-disposition: inline');
if ($pos1){
$pos1 = strpos($Text,chr(10),$pos1)+1;
$pos2 = strpos($Text,chr(10),$pos1);
$message= trim(substr($Text,$pos1,$pos2 - $pos1-1));
// echo "message= ".$message."<br/>";
}

$message = addslashes($message);
if ($username != ''){

$result=mysql_query("insert into WoundEmails (processed) values (0);");
if(!$result){die ('Database error insert into wound emails: ' . mysql_error());}
$RecordNumber=mysql_insert_id();
$filename='text/'.$RecordNumber.'.txt';
$descriptor = fopen ($filename, "w");
$res = fwrite($descriptor,$Text);
fclose($descriptor);
echo "username=".$username."*<br/>";
echo "File ".$filename." written with ".$res." characters <br/>";
echo "message=".$message."*<br/>";
$result=mysql_query("update WoundEmails set
username = '$username',
filename = '$filename',
FromSP = '$From',
ToEmail = '$To',
Subject = '$message'
where woundx = $RecordNumber;");
if(!$result){die ('Database error update woundemails: ' . mysql_error());}
}else{
$headers='From: testcenter@test.com';
mail('jbrohan@ttest.com','WoundFollowUp Spam',$Text,$headers);
}
$res=$pop3->delete_mail($i); // delete the valid emails
echo "res=".$res."i=".$i;

}
$pop3->close();

?>

  2. Re: Missing a post on busy times   Reply   Report abuse  
Picture of Steffen Stollfuß Steffen Stollfuß - 2007-10-22 11:41:10 - In reply to message 1 from John Brohan
Hi,

I think you should try at first this correction of your fwrite line

$res = fwrite($descriptor,$Text,strlen($Text));

and you should have a look at the php.ini memory_limit of a script. Maybe that the scipt reachs the limit and don't work correctly anymore.

regards
j0inty.sL



 
For more information send a message to info at phpclasses dot org.