接收新电子邮件时是否有可能收到回电

时间:2016-08-10 06:06:34

标签: php cron imap

我有一个函数可以捕获带有imap的电子邮件,但问题是每当我收到新邮件时我都要手动检查或运行cron来检查它。有没有什么方法,每当我收到新的电子邮件时,我都会收到任何回调,所以只有当我知道收到电子邮件并停止连续运行cron时,我才会调用该函数。

我正在使用webmail和imap。

function read_emails()
    {        
        //load email reader class
        $this->load->model('upload_file_model');
        //delete media
        //$this->delete_all_attach();

        $this->load->library('Email_reader', array('UserName' => 'abcd@example.org', 'Password' => '12345678'));        
        //this will fetch emails as well all attachements
        $commentsData = $this->email_reader->catchEmails();

        if(isset($commentsData) && !empty($commentsData))
        {
            //$url = 'http://localhost/myproject/api/activity/addComment';
            foreach ($commentsData as $Data)
            {                
                //check if the entity exists in the system
                $IsEntityExists = get_detail_by_guid($Data['EntityGUID']);
                if($IsEntityExists)
                {
                   //Process attachment                
                   $media = $this->upload_file_model->uploadExternalAttachmnts($Data['Media']['attachments'],array('Sender'=>$Data['sender'],'Type'=>$Data['Type']));

                   //$attachmentData = array('qqfile'=>$Data['Media']['attachments'],'Type'=>$Data['Type'],'DeviceType'=>'native');

                   //calling uploadImage
                   //$media = $this->callAPI($attachmentData, SITE_URL.ROOT_FOLDER.'/api/upload_image');

                   //for requesting any api we need to send Login Sesion Key
                   $Data['LoginSessionKey'] = $this->session->userdata('LoginSessionKey');
                   if(!empty($media))
                   {
                       $Data['Media'] = array();
                       foreach ($media as  $md)
                          $Data['Media'][] = array('MediaGUID'=> $md,'Caption'=>'');
                   }
                   $Data['IsExternaCommunication'] = 1;

                   //calling comment  api
                   //$this->callAPI($Data, SITE_URL.ROOT_FOLDER.'/api/activity/addComment');
                   ExecuteCurl($Data, base_url().'api/activity/addComment');
                }                
                else
                {
                    @unlink($Data['Media']['attachments']);
                    foreach ($Data['Media']['attachments'] as $attachment)
                    {
                        $i=0;
                        //checkif attachment is there in the response
                        if($attachment['is_attachment'])
                        {
                            //Delete irrelevant data
                            @unlink($attachment['filepath']);
                        }
                    }
                }
            }
           echo 'Done'; 
        }
        else            
            echo 'comments not found!';
        die;        
    }

0 个答案:

没有答案