Пример #1
0
 public function receve($user_id = null, $background = false)
 {
     if (empty($user_id)) {
         $user_id = get_user_id();
     }
     $mail_account = $this->_get_mail_account($user_id);
     $new = 0;
     session_write_close();
     import("@.ORG.Util.receve");
     $mail_list = array();
     $mail = new receiveMail();
     $connect = $mail->connect($mail_account['pop3svr'], '110', $mail_account['mail_id'], $mail_account['mail_pwd'], 'INBOX', 'pop3/novalidate-cert');
     if (!$connect) {
         $connect = $mail->connect($mail_account['pop3svr'], '995', $mail_account['mail_id'], $mail_account['mail_pwd'], 'INBOX', 'pop3/ssl/novalidate-cert');
     }
     $mail_count = $mail->mail_total_count();
     if ($connect) {
         for ($i = 1; $i <= $mail_count; $i++) {
             $mail_id = $mail_count - $i + 1;
             $item = $mail->mail_list($mail_id);
             $where = array();
             $where['user_id'] = $user_id;
             if (empty($item[$mail_id])) {
                 $temp_mail_header = $mail->mail_header($mail_id);
                 $where['mid'] = $temp_mail_header['mid'];
             } else {
                 $where['mid'] = $item[$mail_id];
             }
             $count = M('Mail')->where($where)->count();
             if ($count == 0) {
                 $model = M("Mail");
                 $model->create($mail->mail_header($mail_id));
                 if ($model->create_time < strtotime(date('y-m-d h:i:s')) - 86400 * 30) {
                     $mail->close_mail();
                     if ($new > 0) {
                         $this->_pushReturn($new, "收到" . $new . "封邮件", 1);
                     }
                     return;
                 }
                 $new++;
                 $model->user_id = $user_id;
                 $model->read = 0;
                 $model->folder = 1;
                 $model->is_del = 0;
                 $str = $mail->get_attach($mail_id, $this->tmpPath);
                 $model->add_file = $this->_receive_file($str, $model);
                 $this->_organize($model);
                 $model->add();
             } else {
                 if (!$background) {
                     if ($new == 0) {
                         $this->_pushReturn($new, "没有新邮件", 1);
                         return;
                     }
                 }
                 $mail->close_mail();
             }
         }
     }
     $mail->close_mail();
     $this->_pushReturn($new, "收到" . $new . "封邮件", 1);
     return;
 }
Пример #2
0
 public function receve()
 {
     $new = 0;
     if ($this->_check_mail_account() == false) {
         $this->ajaxReturn(1, "请设置邮箱帐号", 0);
         die;
     }
     $user_id = get_user_id();
     session_write_close();
     vendor("Mail.class#receve2");
     $mail_list = array();
     $mail = new receiveMail();
     $connect = $mail->connect($this->_account['pop3svr'], '110', $this->_account['mail_id'], $this->_account['mail_pwd'], 'INBOX', 'pop3');
     $mail_count = $mail->mail_total_count();
     if ($connect) {
         for ($i = 1; $i < $mail_count; $i++) {
             $mail_id = $mail_count - $i + 1;
             $item = $mail->mail_list($mail_id);
             $where = array();
             $where['user_id'] = $user_id;
             $where['mid'] = $item[$mail_id];
             $count = M('Mail')->where($where)->count();
             if (empty($item[$mail_id])) {
                 //mid 空时当成新邮件处理
                 $count = 0;
             }
             if ($count == 0) {
                 $new++;
                 $model = M("Mail");
                 $model->create($mail->mail_header($mail_id));
                 if ($model->create_time < strtotime(date('y-m-d h:i:s')) - 86400 * 30) {
                     $mail->close_mail();
                     $this->pushReturn($new, "收到" . $new . "封邮件", 1);
                 }
                 $model->user_id = $user_id;
                 $model->read = 0;
                 $model->folder = 1;
                 $model->is_del = 0;
                 $str = $mail->get_attach($mail_id, $this->tmpPath);
                 $model->add_file = $this->_receive_file($str, $model);
                 $this->organize($model);
                 $model->add();
             } else {
                 $mail->close_mail();
                 if ($new == 0) {
                     $this->pushReturn($new, "没有新邮件", 1);
                 }
             }
         }
     }
     $mail->close_mail();
     $this->pushReturn($new, "收到" . $new . "封邮件", 1);
     //$this -> ajaxReturn($new, "收到" . $new . "封邮件", 1);
 }