protected function processAddWebMail($inAjax = false) { $web = $_POST["web"]; $errMsg = ""; $this->submitCheck($web, $inAjax); if (isset($_POST["moreinfo"])) { if (empty($web["server"])) { $this->error(Ibos::lang("Empty server address"), "", array(), $inAjax); } $passCheck = WebMailUtil::checkAccount($web["address"], $web["password"], $web); if ($passCheck) { $web = WebMailUtil::mergePostConfig($web["address"], $web["password"], $web); } else { $errMsg = Ibos::lang("Error server info"); } } else { $passCheck = WebMailUtil::checkAccount($web["address"], $web["password"]); if ($passCheck) { $web = WebMailUtil::getEmailConfig($web["address"], $web["password"]); } else { $errMsg = Ibos::lang("More server info"); } } if (!$passCheck) { if (!$inAjax) { $this->setPageTitle(Ibos::lang("Add web email")); $this->setPageState("breadCrumbs", array(array("name" => Ibos::lang("Personal Office")), array("name" => Ibos::lang("Email center"), "url" => $this->createUrl("list/index")), array("name" => Ibos::lang("Add web email")))); $this->render("add", array("more" => true, "errMsg" => $errMsg, "web" => $web)); } else { $data = array("lang" => Ibos::getLangSources(), "more" => true, "errMsg" => $errMsg, "web" => $web); $content = $this->renderPartial("ajaxAdd", $data, true); $this->ajaxReturn(array("moreinfo" => true, "content" => $content)); } exit; } $web = $this->beforeSave($web); $newId = EmailWeb::model()->add($web, true); $folder = array("sort" => 0, "name" => isset($_POST["web"]["name"]) ? StringUtil::filterCleanHtml($_POST["web"]["name"]) : $web["address"], "uid" => $this->uid, "webid" => $newId); $fid = EmailFolder::model()->add($folder, true); EmailWeb::model()->modify($newId, array("fid" => $fid)); return $newId; }
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("<", ">"), 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; } }
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")); } }