if ($mail->_text_plain) { $textP = new CContentAny(); $textP->content = $mail->_text_plain; if ($msg = $textP->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } $mail->text_plain_id = $textP->_id; } //text html if ($mail->_text_html) { $textH = new CContentHTML(); $text = new CMbXMLDocument(); $text = $text->sanitizeHTML($mail->_text_html); //cleanup $textH->content = $text; if ($msg = $textH->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { $mail->text_html_id = $textH->_id; } } $msg = $mail->store(); if ($msg) { CAppUI::setMsg($msg, UI_MSG_ERROR); } } $mail->loadRefsFwd(); $pop->close(); //Smarty $smarty = new CSmartyDP(); $smarty->assign("mail", $mail);
/** * @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; } }
/** * get the html text from the mail structure * * @param int $source_object_id the user id * * @return mixed */ function getHtmlText($source_object_id) { if ($this->_text_html) { $textH = new CContentHTML(); //apicrypt if (CModule::getActive("apicrypt") && $this->_is_apicrypt == "html") { $this->_text_html = CApicrypt::uncryptBody($source_object_id, $this->_text_html); } $textH->content = CUserMail::purifyHTML($this->_text_html); //cleanup if (!($msg = $textH->store())) { $this->text_html_id = $textH->_id; } } return $this->text_html_id; }
/** * Enregistrement du document / modèle * * @return string */ function store() { $this->completeField("content_id", "_source", "language", "version"); if (!$this->creation_date) { $this->creation_date = CMbDT::dateTime(); if ($this->_id) { $this->creation_date = $this->loadFirstLog()->date; } } // Prevent source modification when not editing the doc $this->loadContent($this->_send || $this->_source === null); $source_modified = $this->_ref_content->content != $this->_source || $this->fieldModified("margin_top") || $this->fieldModified("margin_left") || $this->fieldModified("margin_right") || $this->fieldModified("margin_bottom") || $this->fieldModified("page_height") || $this->fieldModified("page_width") || $this->fieldModified("header_id") || $this->fieldModified("preface_id") || $this->fieldModified("ending_id") || $this->fieldModified("footer_id"); if ($source_modified || $this->fieldModified("valide")) { // Empty PDF File /** @var CFile $_file */ foreach ($this->loadBackRefs("files") as $_file) { $_file->fileEmpty(); } } if ($source_modified) { // Bug IE : delete id attribute $this->_source = CCompteRendu::restoreId($this->_source); $this->doc_size = strlen($this->_source); // Send status to obsolete $this->completeField("etat_envoi"); if ($source_modified && $this->etat_envoi == "oui") { $this->etat_envoi = "obsolete"; } } $this->_ref_content->content = $this->_source; if (!$this->_id) { $parent_modele = $this->loadModele(); $parent_modele->loadContent(false); // Si issu d'une duplication depuis un document existant, alors on reprend la version du document d'origine // L'incrément de version se fait en fin de store if ($parent_modele->object_id) { $this->version = $parent_modele->version; $parent_modele->isAutoLock(); // Si le document existant est verrouillé, alors on l'archive if ($parent_modele->valide || $parent_modele->_is_auto_locked) { $parent_modele->annule = 1; $parent_modele->store(); } } } if ($msg = $this->_ref_content->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } // Prevent modele_id = compte_rendu_id // But, allow to save the content if ($this->_id === $this->modele_id) { $this->modele_id = ""; } // Detect the fields not completed $matches = array(); preg_match_all("/(field|name)\">(\\[)+[^\\]]+(\\])+<\\/span>/ms", $this->_source, $matches); $this->fields_missing = count($matches[0]); if (!$this->content_id) { $this->content_id = $this->_ref_content->_id; } if (!$this->_id) { $this->author_id = CMediusers::get()->_id; } if ($this->factory == "none" || !$this->factory) { $this->factory = CAppUI::pref("dPcompteRendu choice_factory"); if (!$this->factory) { $this->factory = "CWkHtmlToPDFConverter"; } } $this->version++; return parent::store(); }