PHP Classes

Doesn't work with multiple messages

Recommend this page to a friend!

      PHP Email To DB  >  All threads  >  Doesn't work with multiple messages  >  (Un) Subscribe thread alerts  
Subject:Doesn't work with multiple messages
Summary:Running the script when there is more than 1 message
Messages:6
Author:Jason Kerner
Date:2011-03-05 12:50:00
Update:2013-04-16 19:21:27
 

  1. Doesn't work with multiple messages   Reply   Report abuse  
Picture of Jason Kerner Jason Kerner - 2011-03-05 12:50:00
If there is more than one message in the inbox when the script runs, the script only saves the first one as within the do_action routine, it doesn't get called again once its processed the first message. Changing it to a while loop (while we still have a message in the inbox) it doesn't save any variables when the DB save statement runs


  2. Re: Doesn't work with multiple messages   Reply   Report abuse  
Picture of sofus comer sofus comer - 2011-06-19 15:35:10 - In reply to message 1 from Jason Kerner
Awesome script in so many ways!!!, but would like it to loop thru my inbox until its empty.

  3. Re: Doesn't work with multiple messages   Reply   Report abuse  
Picture of Lil Peck Lil Peck - 2011-06-19 16:04:41 - In reply to message 2 from sofus comer
If memory serves me right, I remember the script refreshing/reloading and capturing messages one by one. Otherwise, a person could manually reload it or put a javascript refresh on it. One could also set up a cron tab to call it automatically every minute.

I wrote a script in Classic ASP that uses the jmail component to archive emails to MySQL. If you are using a Windows server with jmail, you can google for my script.

  4. Re: Doesn't work with multiple messages   Reply   Report abuse  
Picture of sofus comer sofus comer - 2011-06-19 16:27:20 - In reply to message 3 from Lil Peck
Hi Lil, thanks for replying. I am on apache, linux. I have set up a cron so its not 100% dire if its not looping thru. Would just be nice!.

  5. Re: Doesn't work with multiple messages   Reply   Report abuse  
Picture of Nick Fat Nick Fat - 2013-04-16 19:21:27 - In reply to message 4 from sofus comer
Hi, I would like to help, because this great class is provided for free:

I adapted my do_action function as follows in order to import multiple messages into db:

$this->num_message is the number of messages in the inbox. I simply made a loop. I don't know if this is the right way to go, and maybe some debugging will be needed.


function do_action() {

if ($this->num_message() >= 1) {

if ($this->msgid <= 0) {
$this->msgid = 1;
} else {
$this->msgid = $_GET[msgid] + 1;
}
for ($i = 1; $i <= $this->num_message(); $i++) {
#Get first message
$email = $this->email_get();

#Get store dir
$dir = $this->dir_name();

#Insert message to db
$ismsgdb = $this->db_add_message($email);

$id_log = $this->add_db_log($email, 'Copy e-mail - start ');

foreach ($this->partsarray as $part) {
if ($part[text][type] == 'HTML') {
#$message_HTML = $part[text][string];
$this->db_update_message($part[text][string], $type = 'HTML');
} elseif ($part[text][type] == 'PLAIN') {
$message_PLAIN = $part[text][string];
$this->db_update_message($part[text][string], $type = 'PLAIN');
} elseif ($part[attachment]) {
#Save files(attachments) on local disc
// $message_ATTACH[] = $part[attachment];
foreach (array($part[attachment]) as $attach) {
$attach[filename] = $this->mimie_text_decode($attach[filename]);
$attach[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $attach[filename]);
$this->add_db_log($email, 'Start coping file:"' . strip_tags($attach[filename]) . '"');

$this->save_files($this->newid . $attach[filename], $attach[string]);
$filename = $dir . $this->newid . $attach[filename];
$this->db_add_attach($attach[filename], $filename);
$this->update_db_log('<b>' . $filename . '</b>Finish coping: "' . strip_tags($attach[filename]) . '"', $this->logid);
}
//
} elseif ($part[image]) {
#Save files(attachments) on local disc

$message_IMAGE[] = $part[image];

foreach ($message_IMAGE as $image) {
$image[filename] = $this->mimie_text_decode($image[filename]);
$image[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $image[filename]);
$this->add_db_log($email, 'Start coping file: "' . strip_tags($image[filename]) . '"');


$this->save_files($this->newid . $image[filename], $image[string]);
$filename = $dir . $this->newid . $image[filename];
$this->db_add_attach($image[filename], $filename);
$this->update_db_log('<b>' . $filename . '</b>Finish coping:"' . strip_tags($image[filename]) . '"', $this->logid);
}
}
}
$this->spam_detect();
$this->email_setflag();
$this->email_delete();
$this->email_expunge();

$this->update_db_log('Finish coping', $id_log);

if ($email <> '') {
unset($this->partsarray);
# echo "<meta http-equiv=\"refresh\" content=\"2; url=email.monitor.mail.php?msgid=".$this->msgid."\">";
// if ($this->mode == 'html') {
// echo "<meta http-equiv=\"refresh\" content=\"2; url=" . $this->this_file_name . "?msgid=0\">";
// echo "E-mail extract";
// }
}
$this->msgid = $this->msgid + 1;
}
} else {
# No messages
// if ($this->mode == 'html') {
// echo "<meta http-equiv=\"refresh\" content=\"10; url=" . $this->this_file_name . "?msgid=0\">";
// echo "E-mail extract";
// }
}
}

  6. Re: Doesn't work with multiple messages   Reply   Report abuse  
Picture of Joao Jose Joao Jose - 2015-02-18 22:07:55 - In reply to message 5 from Nick Fat
Hi,
I'm a complete idiot in terms of PHP. Could you post the complete PHP class so I don't mess it up?