public function actionIndex()
 {
     $model = new Receive();
     error_reporting(E_ALL ^ E_WARNING);
     $obj = new receiveMail('tclrg', 'Luanruitest', '*****@*****.**', 'imap.126.com', 'imap', '993', 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     //查看邮箱是否有新邮件
     $old_email_count = Email::find()->count();
     for ($i = $tot; $i > $old_email_count; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         //            echo $i.$head['date']."</br>";
         //            echo $i.strtotime($head['date'])."</br>";
         //            echo $i.date("Y-m-d H:i:s",strtotime($head['date']))."</br>";
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->text = $obj->getBody($i);
         //            $model->sendtime=$head['date'];
         $model->save();
         //            echo $i.$head['date'];
     }
     $obj->close_mailbox();
 }
예제 #2
0
 public function get($id, $elequent)
 {
     $cacheKey = self::CACHE . $id;
     if ($elequent) {
         return Email::find($id);
     }
     $cachedData = \Cache::has($cacheKey);
     if (empty($cachedData)) {
         $email = Email::find($id);
         if (!empty($email)) {
             $email = $email->toArray();
             $email['updated_at'] = date('Y-m-d', strtotime($email['updated_at']));
             $email['created_at_formatted'] = date('Y-m-d', strtotime($email['created_at']));
             $email['updated_at_formatted'] = date('Y-m-d', strtotime($email['updated_at']));
             // unset($country['password']);
             //unset($country['code']);
             // Set data in cache
             \Cache::forever($cacheKey, $email);
             return $email;
         } else {
             return false;
         }
     } else {
         return \Cache::get($cacheKey);
     }
 }
예제 #3
0
 /**
  * Show the application dashboard to the user.
  *
  * @param  Request $request
  * @param  integer $id
  * @return Response
  */
 public function success(Request $request, $id = 0)
 {
     $email = Email::find($id);
     if ($email) {
         return view('users.dashboard.success')->withEmail($email);
     }
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Email::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'sent_date' => $this->sent_date, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
예제 #5
0
                        <span class="title">&nbsp;&nbsp;收件箱</span>
                        
                        
                    </a>
                </li>
                <li>
                    <a href="<?php 
echo \yii\helpers\Url::toRoute(['site/undistribute', 'handle_status' => 0]);
?>
">
                        <i class="glyphicon glyphicon-remove-circle"></i>
                        <span class="title">&nbsp;&nbsp;待分发</span>
                        <span class="sr-only">(current)</span>
                        <?php 
use app\models\Email;
$count = Email::find()->where(['handle_status' => 0])->count();
if ($count > 0) {
    echo '<span class="badge pull-right">' . $count . '</span>';
}
?>
                    </a>
                </li>

                <li>
                    <a href="<?php 
echo \yii\helpers\Url::toRoute(['site/distributed', 'handle_status' => 1]);
?>
">
                        <i class="glyphicon glyphicon-ok-circle"></i>
                        <span class="title">&nbsp;&nbsp;已分发</span>
                    </a>
예제 #6
0
 public function actionReceiver()
 {
     $model = new Receive();
     error_reporting(E_ALL || ~E_WARNING || ~E_NOTICE);
     $mailaccount = setting::find()->one();
     $user = $mailaccount->user;
     $password = $mailaccount->password;
     $username = $mailaccount->username;
     $receivehost = $mailaccount->receivehost;
     $receiveapply = "imap";
     $receiveport = $mailaccount->receiveport;
     $obj = new receiveMail($user, $password, $username, $receivehost, $receiveapply, $receiveport, 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     //查看邮箱是否有新邮件
     $old_email_count = Email::find()->count();
     for ($i = $tot; $i > $old_email_count; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $text = $obj->getBody($i);
         $encode = mb_detect_encoding($text, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
         if ($encode == "EUC-CN") {
             $encode = "GB2312";
         }
         if ($encode != "UTF-8") {
             $text = iconv("{$encode}", "UTF-8", $text);
         }
         $model->text = $text;
         $attachments = $obj->GetAttach($i, "../attachment/receiveattachment");
         $attach = "";
         if ($attachments != "") {
             $attach = $attachments;
             $encode = mb_detect_encoding($attachments, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
             if ($encode == "EUC-CN") {
                 $encode = "GB2312";
             }
             if ($encode != "UTF-8") {
                 $attach = iconv("{$encode}", "UTF-8", $attachments);
             }
         }
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->attachment = $attach;
         $model->save();
     }
     $obj->close_mailbox();
 }