示例#1
1
 /**
  * Set the hash for the user mails
  *
  * @return bool
  */
 protected function setUserMailHash()
 {
     $ds = CSQLDataSource::get("std");
     $mails = $ds->loadList("SELECT m.user_mail_id, m.account_class, m.account_id, m.from, m.to, m.subject, c.content FROM user_mail as m, content_html as c WHERE m.account_class IS NOT NULL AND m.account_id IS NOT NULL AND m.text_html_id = c.content_id ORDER BY m.user_mail_id DESC;");
     if (count($mails)) {
         $values = array();
         foreach ($mails as $_mail) {
             $data = "==FROM==\n" . $_mail['from'] . "\n==TO==\n" . $_mail['to'] . "\n==SUBJECT==\n" . $_mail['subject'] . "\n==CONTENT==\n" . $_mail['content'];
             $hash = CMbSecurity::hash(CMbSecurity::SHA256, $data);
             $values[] = '(' . $_mail['user_mail_id'] . ', ' . $_mail['account_id'] . ', \'' . $_mail['account_class'] . "', '{$hash}')";
         }
         $mails = $ds->loadList("SELECT m.user_mail_id, m.account_class, m.account_id, m.from, m.to, m.subject, c.content FROM user_mail AS m, content_any AS c WHERE m.account_class IS NOT NULL AND m.account_id IS NOT NULL AND m.text_html_id IS NULL AND m.text_plain_id = c.content_id ORDER BY m.user_mail_id DESC;");
         foreach ($mails as $_mail) {
             $data = "==FROM==\n" . $_mail['from'] . "\n==TO==\n" . $_mail['to'] . "\n==SUBJECT==\n" . $_mail['subject'] . "\n==CONTENT==\n" . $_mail['content'];
             $hash = CMbSecurity::hash(CMbSecurity::SHA256, $data);
             $values[] = '(' . $_mail['user_mail_id'] . ', ' . $_mail['account_id'] . ', \'' . $_mail['account_class'] . "', '{$hash}')";
         }
         $query = "INSERT INTO `user_mail` (`user_mail_id`, `account_id`, `account_class`, `hash`) VALUES " . implode(', ', $values) . " ON DUPLICATE KEY UPDATE `hash` = VALUES(`hash`);";
         $ds->query($query);
         if ($msg = $ds->error()) {
             CAppUI::stepAjax($msg, UI_MSG_WARNING);
             return false;
         }
     }
     return true;
 }
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("datetime_start");
     if (!$this->datetime_start) {
         $this->datetime_start = CMbDT::dateTime();
     }
     if (!$this->_id) {
         $rand = CMbSecurity::getRandomString(16);
         $this->hash = CMbSecurity::hash(CMbSecurity::SHA1, $rand);
     }
     return parent::store();
 }
示例#3
0
 /**
  * Make the hash for the given headers and mail content
  *
  * @param stdOject $header  The headers, returned by the POP source
  * @param array    $content The content, returned by the POP source
  *
  * @return bool|string
  */
 public function makeHash($header, $content)
 {
     if (!isset($header->fromaddress) && !isset($header->toaddress) && !isset($header->subject)) {
         return null;
     }
     $data = "==FROM==\n" . self::flatMimeDecode($header->fromaddress) . "\n==TO==\n" . self::flatMimeDecode($header->toaddress) . "\n==SUBJECT==\n" . self::flatMimeDecode($header->subject);
     if (!empty($content['text']['html'])) {
         $content = $content['text']['html'];
     } elseif (!empty($content['text']['plain'])) {
         $content = $content['text']['plain'];
     }
     $data .= "\n==CONTENT==\n{$content}";
     return CMbSecurity::hash(CMbSecurity::SHA256, $data);
 }
 /**
  * @see parent::doStore()
  */
 function doStore()
 {
     /** @var CUserMail $mail */
     $mail = $this->_obj;
     $mail->date_inbox = CMbDT::dateTime();
     $mail->date_read = $mail->date_inbox;
     $content_html = new CContentHTML();
     $mail->_content = CUserMail::purifyHTML($mail->_content);
     $content_html->content = $mail->_content;
     if (!($msg = $content_html->store())) {
         $mail->text_html_id = $content_html->_id;
         $mail->_text_html = $content_html;
     }
     $content_plain = new CContentAny();
     $content_plain->content = strip_tags($mail->_content);
     if (!($msg = $content_plain->store())) {
         $mail->text_plain_id = $content_plain->_id;
     }
     $hash = CMbSecurity::hash(CMbSecurity::SHA256, "==FROM==\n{$mail->from}\n==TO==\n{$mail->to}\n==SUBJECT==\n{$mail->subject}\n==CONTENT==\n{$mail->_content}");
     if ($msg = $mail->store()) {
         CAppUI::setMsg($msg, UI_MSG_ERROR);
         return parent::doStore();
     }
     $action = CValue::post('action');
     switch ($action) {
         case 'draft':
             $mail->draft = '1';
             CAppUI::setMsg('CUserMail-msg-drafted', UI_MSG_OK);
             break;
         case 'send':
             $mail->sent = '1';
             $mail->draft = '0';
             $account = $mail->loadAccount();
             if ($mail->_is_apicrypt) {
                 /** @var CSourceSMTP $smtp */
                 $smtp = CExchangeSource::get("mediuser-{$account->object_id}-apicrypt", 'smtp');
             } else {
                 /** @var CSourceSMTP $smtp */
                 $smtp = CExchangeSource::get("mediuser-{$account->object_id}", 'smtp');
             }
             $smtp->init();
             foreach (explode(',', $mail->to) as $_address) {
                 $smtp->addTo($_address);
             }
             if ($mail->cc != '') {
                 foreach (explode(',', $mail->cc) as $_address) {
                     $smtp->addCc($_address);
                 }
             }
             if ($mail->bcc != '') {
                 foreach (explode(',', $mail->bcc) as $_address) {
                     $smtp->addBcc($_address);
                 }
             }
             $smtp->setSubject($mail->subject);
             if ($mail->_is_apicrypt) {
                 $receiver = explode(',', $mail->to);
                 $body = CApicrypt::encryptBody($account->object_id, $receiver[0], $mail->_content);
                 $smtp->setBody($body);
             } else {
                 $smtp->setBody($mail->_content);
             }
             /** @var CMailAttachments[] $attachments */
             $attachments = $mail->loadAttachments();
             foreach ($attachments as $_attachment) {
                 $file = $_attachment->loadFiles();
                 $smtp->addAttachment($file->_file_path, $file->file_name);
             }
             try {
                 $smtp->send();
                 CAppUI::setMsg('CUserMail-msg-sent', UI_MSG_OK);
             } catch (phpmailerException $e) {
                 CAppUI::setMsg($e->errorMessage(), UI_MSG_ERROR);
             } catch (CMbException $e) {
                 $e->stepAjax();
             }
             break;
         default:
     }
     $mail->store();
     if (CAppUI::isMsgOK() && $this->redirectStore) {
         $this->redirect =& $this->redirectStore;
     }
     if (!CAppUI::isMsgOK() && $this->redirectError) {
         $this->redirect =& $this->redirectError;
     }
 }