private function _sendInit() { if (!Mail::canSend()) { $this->error(ECode::$MAIL_SENDERROR); } $type = $num = false; if (isset($this->params['type'])) { $type = $this->params['type']; } if (isset($this->params['num'])) { $num = $this->params['num']; } else { if (isset($this->params['form']['num'])) { $num = $this->params['form']['num']; } } if (empty($type) || false === $num) { return false; } try { $mail = MAIL::getInstance($num, new MailBox(User::getInstance(), $type)); $this->set('num', $num); $this->set('type', $type); } catch (UserNullException $e) { $this->error(ECode::$USER_NOID); } catch (Exception $e) { return false; } return $mail; }
public function send() { if (!Mail::canSend()) { $this->error(ECode::$MAIL_SENDERROR); } $u = User::getInstance(); $mail = false; if (isset($this->params['type']) && isset($this->params['num'])) { $type = $this->params['type']; $num = $this->params['num']; try { $mail = MAIL::getInstance($num, new MailBox($u, $type)); } catch (Exception $e) { } } if ($this->RequestHandler->isPost()) { $title = $content = ''; $sig = User::getInstance()->signature; if (isset($this->params['form']['title'])) { $title = trim($this->params['form']['title']); } if (isset($this->params['form']['content'])) { $content = $this->params['form']['content']; } $sig = 0; $bak = isset($this->params['form']['backup']) ? 1 : 0; $title = nforum_iconv($this->encoding, $this->appEncoding, $title); $content = nforum_iconv($this->encoding, $this->appEncoding, $content); try { if (false === $mail) { //send new if (!isset($this->params['form']['id'])) { $this->error(ECode::$POST_NOID); } $id = trim($this->params['form']['id']); Mail::send($id, $title, $content, $sig, $bak); $this->redirect($this->_mbase . "/mail?m=" . ECode::$MAIL_SENDOK); } else { //reply $mail->reply($title, $content, $sig, $bak); $this->redirect($this->_mbase . "/mail/{$type}?m=" . ECode::$MAIL_SENDOK); } } catch (MailSendException $e) { $this->error($e->getMessage()); } } $uid = $title = $content = ""; if (isset($this->params['type']) && isset($this->params['num'])) { $this->notice = "邮件-回复邮件"; if (false === $mail) { //reply article try { $b = Board::getInstance($type); if (!$b->hasReadPerm($u)) { $this->error(ECode::$BOARD_NOPERM); } $mail = Article::getInstance($num, $b); } catch (Exception $e) { $this->error(ECode::$MAIL_NOMAIL); } } if (!strncmp($mail->TITLE, "Re: ", 4)) { $title = $mail->TITLE; } else { $title = "Re: " . $mail->TITLE; } $content = "\n" . $mail->getRef(); //remove ref ubb tag $content = XUBB::remove($content); $uid = $mail->OWNER; } else { $this->notice = "邮件-新邮件"; } $this->set("uid", $uid); $this->set("title", $title); $this->set("content", $content); $this->set("bak", $u->getCustom("mailbox_prop", 0)); }