public function handleEmailBody($data) { $data["toids"] = implode(",", StringUtil::getId($data["toids"])); $data["sendtime"] = TIMESTAMP; $data["isneedreceipt"] = isset($data["isneedreceipt"]) ? 1 : 0; if (empty($data["isOtherRec"])) { $data["copytoids"] = $data["secrettoids"] = ""; } else { $data["copytoids"] = implode(",", StringUtil::getId($data["copytoids"])); $data["secrettoids"] = implode(",", StringUtil::getId($data["secrettoids"])); } if (empty($data["isWebRec"])) { $data["towebmail"] = ""; } if (!isset($data["fromwebmail"])) { $data["fromwebmail"] = ""; } !empty($data["attachmentid"]) && ($data["attachmentid"] = StringUtil::filterStr($data["attachmentid"])); $data["size"] = EmailUtil::getEmailSize($data["content"], $data["attachmentid"]); return $data; }
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; } }