/** * create the CFiles attached to the mail * * @param CMailAttachments[] $attachList The list of CMailAttachment * @param CPop $popClient the CPop client * * @return void */ function attachFiles($attachList, $popClient) { //size limit $size_required = CAppUI::pref("getAttachmentOnUpdate"); if ($size_required == "") { $size_required = 0; } foreach ($attachList as $_attch) { $_attch->mail_id = $this->_id; $_attch->loadMatchingObject(); if (!$_attch->_id) { $_attch->store(); } //si preference taille ok OU que la piece jointe est incluse au texte => CFile if ($_attch->bytes <= $size_required || $_attch->disposition == "INLINE") { $file = new CFile(); $file->setObject($_attch); $file->author_id = CAppUI::$user->_id; if (!$file->loadMatchingObject()) { $file_pop = $popClient->decodeMail($_attch->encoding, $popClient->openPart($this->uid, $_attch->getpartDL())); $file->file_name = $_attch->name; //apicrypt attachment if (strpos($_attch->name, ".apz") !== false) { $file_pop = CApicrypt::uncryptAttachment($popClient->source->object_id, $file_pop); } //file type detection $first = is_array($file_pop) ? reset($file_pop) : $file_pop; $mime = $this->extensionDetection($first); //file name $infos = pathinfo($_attch->name); $extension = $infos['extension']; $mime_extension = strtolower(end(explode("/", $mime))); if (strtolower($extension) != $mime_extension) { $file->file_name = $infos['filename'] . "." . $mime_extension; } $file->file_type = $mime ? $mime : $_attch->getType($_attch->type, $_attch->subtype); $file->fillFields(); $file->updateFormFields(); $file->putContent($file_pop); $file->store(); } } } }
/** * @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; } }