| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace Heanup\App\Api\Controller\Vestacp;
- use Heanup\App\Api\Package\Database\Mail;
- use Heanup\App\Api\RestfulController;
- use Heanup\Library\Vestacp;
- use PhpImap\Exceptions\InvalidParameterException;
- use PhpImap\Mailbox;
- use ProfiCloS\VestaCP\ClientException;
- use ProfiCloS\VestaCP\ProcessException;
- class Domain extends RestfulController
- {
- /**
- * @var $this
- */
- public $_data;
- /**
- * @var $this
- */
- public $email;
- /**
- * @var array
- */
- public $mail_ids;
- /**
- * @var array
- */
- public $info;
- /**
- * Get Method|获取数据
- * @return void
- * @throws InvalidParameterException
- */
- protected function getData()
- {
- $type = $this->getRequest()->string("type", 'default');
- $this->_data = $_SESSION['data'];
- $login = $this->_data['email'] . "@" . $this->_data['domain'];
- $password = $this->_data['password'];
- $this->email = $this->getQuery()->string("email");
- // $this->showSuccess([$login,$password]);
- if ($this->email) {
- $login = $this->email;
- $account = substr($this->email, 0, strpos($this->email, "@"));
- $domain = substr($this->email, strpos($this->email, "@") + 1);
- $_mail = Mail::getOne(['email' => $account, 'domain' => $domain, 'status' => 1]);
- $password = $_mail['password'];
- $this->_data=$_mail;
- }
- if ($type == "get_mail") {
- $mailbox = new Mailbox(
- '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
- $login, // Username for the before configured mailbox
- $password, // Password for the before configured username
- __DIR__, // Directory, where attachments will be saved (optional)
- 'UTF-8' // Server encoding (optional)
- );
- $mail_ids = $mailbox->searchMailbox('ALL');
- $mail_info = $mailbox->getMailsInfo($mail_ids);
- $mail_info = array_reverse($mail_info);
- $this->showSuccess($mail_info);
- } elseif ($type == 'get_detail') {
- $mailbox = new Mailbox(
- '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
- $login, // Username for the before configured mailbox
- $password, // Password for the before configured username
- __DIR__, // Directory, where attachments will be saved (optional)
- 'UTF-8' // Server encoding (optional)
- );
- $mail_id = $this->getQuery()->intval("id");
- $detail = $mailbox->getMail($mail_id);
- $this->info = [
- 'subject' => $detail->subject,
- 'body' => $detail->textHtml,
- 'from' => $detail->fromAddress,
- 'fromName' => $detail->fromName,
- 'replyTo' => $detail->replyTo,
- 'date' => $detail->date,
- 'cc' => $detail->cc,
- 'bcc' => $detail->bcc,
- ];
- $this->getTemplate()->setTpl("Detail");
- $this->render();
- die();
- }
- // $this->showSuccess($this->_data);
- $this->getTemplate()->setTpl("Domain");
- $this->render();
- }
- /**
- * 新增一个临时邮箱
- * @return void
- */
- protected function postData()
- {
- $domain = $this->getRequest()->string("domain", 'a4sky.com');
- $email = $this->getRequest()->string("email");
- $password = md5(uniqid());
- $data = compact("domain", "email", "password");
- $data['expired_time'] = date("Y-m-d H:i:s", time() + 7200);
- $data['add_time'] = date("Y-m-d H:i:s");
- $exist = Mail::getOne(['email' => $email, 'domain' => $domain, 'status' => 1]);
- $this->getTemplate()->setTpl("Domain");
- $this->_data = $_SESSION['data'] = $data;
- if (!$exist) {
- try {
- $result = Vestacp::getInstance()->getModuleMail("admin")->addAccount($domain, $email, $password);
- if ($result) {
- Mail::insert($data);
- $this->render();
- }
- } catch (ClientException $e) {
- $this->showError(400, $e->getMessage());
- } catch (ProcessException $e) {
- $this->showError(400, $e->getMessage());
- }
- }
- $this->render();
- }
- /**
- * Put Method|更新数据
- * @return void
- */
- protected function putData()
- {
- }
- /**
- * Delete Method|删除数据
- * @return void
- */
- protected function deleteData()
- {
- }
- }
|