不从服务器删除电子邮件时,PHP向mysql数据库发送电子邮件问题

时间:2022-10-23 18:17:56

I am using a php class etodb found here

我正在使用这里找到的php类etodb

http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.html

It checks an email account and downloads the messages into a mysql database. It works perfectly, however at the end of each loop (looping for each message in the inbox) it deletes the email. I know how to stop it from deleting the email, but the issue is for some reason the script wont insert any new emails into the database unless I allow it to delete the messages OR the inbox is completely empty.

它检查电子邮件帐户并将消息下载到mysql数据库中。它工作正常,但是在每个循环结束时(为收件箱中的每个邮件循环),它会删除电子邮件。我知道如何阻止它删除电子邮件,但问题是由于某种原因,脚本不会将任何新电子邮件插入数据库,除非我允许它删除邮件或收件箱完全为空。

Here is the end portion of the php class referenced above. This section just loops through each message and inserts it into the database AND if set it will delete the messages. My question in summary is to just let the script work correctly without the need to delete messages or have an empty inbox.

这是上面引用的php类的结尾部分。本节只循环遍历每条消息并将其插入数据库中,如果设置它将删除消息。总结我的问题是让脚本正常工作而不需要删除邮件或有一个空的收件箱。

$total_messages = $this->num_message(); 

// IM ASSUMING THIS FOR LOOP IS NOT LOOPING MESSAGES CORRECTLY 
for ($i = 0; $i < $total_messages; $i++) {


#Get first message
$email = $this->email_get();

$ismsgdb = $this->db_add_message($email); // THIS INSERTS EACH MSG INTO DATABASE

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

$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(); // WHEN I REMOVE THIS THE SCRIPT WONT GRAB NEW EMAILS
$this->email_expunge(); // WHEN I REMOVE THIS THE SCRIPT WONT GRAB NEW EMAILS




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


}

1 个解决方案

#1


1  

But your problem is that in the loop, you keep grabbing hte first email.

但你的问题是,在循环中,你继续抓住第一封电子邮件。

#Get first message
$email = $this->email_get();

The class has an internal pointer "$this->msgid" that you need to increment to get the next message. If you set this to $i + 1 before calling the function you should get the next message.

该类有一个内部指针“$ this-> msgid”,您需要递增以获取下一条消息。如果在调用函数之前将其设置为$ i + 1,则应该获得下一条消息。

#Get message determined b $i
$this->msgeid = $i + 1;
$email = $this->email_get();

(Note: edited, now seen the source)

(注:编辑,现在见过来了)

#1


1  

But your problem is that in the loop, you keep grabbing hte first email.

但你的问题是,在循环中,你继续抓住第一封电子邮件。

#Get first message
$email = $this->email_get();

The class has an internal pointer "$this->msgid" that you need to increment to get the next message. If you set this to $i + 1 before calling the function you should get the next message.

该类有一个内部指针“$ this-> msgid”,您需要递增以获取下一条消息。如果在调用函数之前将其设置为$ i + 1,则应该获得下一条消息。

#Get message determined b $i
$this->msgeid = $i + 1;
$email = $this->email_get();

(Note: edited, now seen the source)

(注:编辑,现在见过来了)