Beispiel #1
0
 public function init()
 {
     $this->uid = $uid = intval(Yii::app()->user->uid);
     $this->folders = EmailFolder::model()->fetchAllUserFolderByUid($uid);
     $this->allowWebMail = (bool) Yii::app()->setting->get("setting/emailexternalmail");
     $this->webMails = $this->allowWebMail ? EmailWeb::model()->fetchAllByUid($uid) : array();
     parent::init();
 }
Beispiel #2
0
 public static function receiveMail($web)
 {
     self::$_web = $web;
     @set_time_limit(0);
     ignore_user_abort(true);
     list($prefix) = explode(".", $web["server"]);
     $user = User::model()->fetchByUid($web["uid"]);
     $pwd = StringUtil::authCode($web["password"], "DECODE", $user["salt"]);
     if ($prefix == "imap") {
         $obj = new WebMailImap();
     } else {
         $obj = new WebMailPop();
     }
     $conn = $obj->connect($web["server"], $web["username"], $pwd, $web["ssl"], $web["port"], "plain");
     if (!$conn) {
         return implode(",", $obj->getError());
     } else {
         $totalNum = $obj->countMessages($conn, "INBOX");
         if (0 < $totalNum) {
             $messagesStr = "1:" . $totalNum;
         } else {
             $messagesStr = "";
         }
         if ($messagesStr != "") {
             $headers = $obj->fetchHeaders($conn, "INBOX", $messagesStr);
             $headers = $obj->sortHeaders($headers, "DATE", "DESC");
         } else {
             $headers = false;
         }
         if ($headers == false) {
             $headers = array();
         }
         $count = 0;
         if (0 < count($headers)) {
             while (list($key, $val) = each($headers)) {
                 $header = $headers[$key];
                 $time = $header->timestamp + 28800;
                 if ($web["lastrectime"] == 0 || $web["lastrectime"] < $time) {
                     $count++;
                     $data = array();
                     $data["subject"] = str_replace(array("<", ">"), array("&lt;", "&gt;"), EmailLangUtil::langDecodeSubject($header->subject, CHARSET));
                     $data["sendtime"] = $time;
                     $data["towebmail"] = $web["address"];
                     $data["issend"] = 1;
                     $data["fromid"] = $data["secrettoids"] = "";
                     $data["fromwebmail"] = EmailLangUtil::langGetParseAddressList($header->from);
                     if (isset($header->to) && !empty($header->to)) {
                         $data["toids"] = EmailLangUtil::langGetParseAddressList($header->to, ",");
                     } else {
                         $data["toids"] = "";
                     }
                     if (isset($header->cc) && !empty($header->cc)) {
                         $data["copytoids"] = EmailLangUtil::langGetParseAddressList($header->cc, ",");
                     } else {
                         $data["copytoids"] = "";
                     }
                     $body = self::getBody($header->id, $conn, $obj, $header);
                     $data["content"] = implode("", $body);
                     $data["size"] = EmailUtil::getEmailSize($data["content"]);
                     $bodyId = EmailBody::model()->add($data, true);
                     if ($bodyId) {
                         $email = array("toid" => $web["uid"], "isread" => 0, "fid" => $web["fid"], "isweb" => 1, "bodyid" => $bodyId);
                         Email::model()->add($email);
                     }
                 }
             }
             EmailWeb::model()->updateByPk($web["webid"], array("lastrectime" => TIMESTAMP));
         }
         return $count;
     }
 }
Beispiel #3
0
 protected function setDefault($webId)
 {
     if ($webId) {
         EmailWeb::model()->updateAll(array("isdefault" => 0), "uid = " . $this->uid);
         EmailWeb::model()->modify($webId, array("uid" => $this->uid, "isdefault" => 1));
         $isSuccess = true;
     } else {
         $isSuccess = false;
     }
     $this->ajaxReturn(array("isSuccess" => $isSuccess));
 }
Beispiel #4
0
 private function save($bodyId, $bodyData)
 {
     if (!empty($bodyData["attachmentid"]) && $bodyId) {
         AttachUtil::updateAttach($bodyData["attachmentid"], $bodyId);
     }
     if ($bodyData["issend"]) {
         Email::model()->send($bodyId, $bodyData);
         if (!empty($bodyData["towebmail"])) {
             $toUsers = StringUtil::filterStr($bodyData["towebmail"], ";");
             if (!empty($toUsers)) {
                 $webBox = EmailWeb::model()->fetchByPk($bodyData["fromwebid"]);
                 WebMailUtil::sendWebMail($toUsers, $bodyData, $webBox);
             }
         }
         UserUtil::updateCreditByAction("postmail", $this->uid);
         $message = Ibos::lang("Send succeed");
     } else {
         $message = Ibos::lang("Save succeed", "message");
     }
     if (Yii::app()->request->getIsAjaxRequest()) {
         $this->ajaxReturn(array("isSuccess" => true, "messsage" => $message));
     } else {
         $this->success($message, $this->createUrl("list/index"));
     }
 }