/** * @see parent::doStore() */ function doStore() { if (isset($_FILES['attachment'])) { $mail_id = CValue::post('mail_id'); $mail = new CUserMail(); $mail->load($mail_id); $files = array(); foreach ($_FILES['attachment']['error'] as $key => $file_error) { if (isset($_FILES['attachment']['name'][$key])) { $files[] = array('name' => $_FILES['attachment']['name'][$key], 'tmp_name' => $_FILES['attachment']['tmp_name'][$key], 'error' => $_FILES['attachment']['error'][$key], 'size' => $_FILES['attachment']['size'][$key]); } } foreach ($files as $_key => $_file) { if ($_file['error'] == UPLOAD_ERR_NO_FILE) { continue; } if ($_file['error'] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $_file["error"]), UI_MSG_ERROR); continue; } $attachment = new CMailAttachments(); $attachment->name = $_file['name']; $content_type = mime_content_type($_file['tmp_name']); $attachment->type = $attachment->getTypeInt($content_type); $attachment->bytes = $_file['size']; $attachment->mail_id = $mail_id; $content_type = explode('/', $content_type); $attachment->subtype = strtoupper($content_type[1]); $attachment->disposition = 'ATTACHMENT'; $attachment->extension = substr(strrchr($attachment->name, '.'), 1); $attachment->part = $mail->countBackRefs('mail_attachments') + 1; $attachment->store(); $file = new CFile(); $file->setObject($attachment); $file->author_id = CAppUI::$user->_id; $file->file_name = $attachment->name; $file->file_date = CMbDT::dateTime(); $file->fillFields(); $file->updateFormFields(); $file->doc_size = $attachment->bytes; $file->file_type = mime_content_type($_file['tmp_name']); $file->moveFile($_file, true); if ($msg = $file->store()) { CAppUI::setMsg(CAppUI::tr('CMailAttachments-error-upload-file') . ':' . CAppUI::tr($msg), UI_MSG_ERROR); CApp::rip(); } $attachment->file_id = $file->_id; if ($msg = $attachment->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); CApp::rip(); } } CAppUI::setMsg('CMailAttachments-msg-added', UI_MSG_OK); } else { parent::doStore(); } }
<?php /** * Unlink an attachment * * @category Messagerie * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version SVN: $Id:\$ * @link http://www.mediboard.org */ CCanDo::checkEdit(); $attachment_id = CValue::get("attachment_id"); //open the attachment $attachment = new CMailAttachments(); $attachment->load($attachment_id); $attachment->loadFiles(); //work $file = $attachment->_file; $file->setObject($attachment); if (!($msg = $file->store())) { $attachment->file_id = ""; if (!($msg2 = $attachment->store())) { CAppUI::stepAjax("CMailAttachments-unlinked", UI_MSG_OK); } else { CAppUI::stepAjax("CMailAttachments-unlinked-failed", UI_MSG_ERROR, $msg2); } }
$mail_id = CValue::get("mail_id"); $part = CValue::get("part"); $log_pop = new CSourcePOP(); $log_pop->name = "user-pop-" . $user->_id; $log_pop->loadMatchingObject(); if (!$log_pop) { CAppUI::stepAjax("Source POP indisponible", UI_MSG_ERROR); } if (!$mail_id) { CAppUI::stepAjax("CSourcePOP-error-mail_id", UI_MSG_ERROR); } $mail = new CUserMail(); $mail->load($mail_id); if ($mail->_id) { $pop = new CPop($log_pop); $pop->open(); $attach = new CMailAttachments(); $struct = $pop->structure($mail->uid); $parts = explode(".", $part); //recursive parts foreach ($parts as $key => $value) { $struct = $struct->parts[$value]; } $attach->loadFromHeader($struct); $attach->part = $part; $attach->loadContentFromPop($pop->openPart($mail->uid, $attach->getpartDL())); $smarty = new CSmartyDP(); $smarty->assign("_attachment", $attach); $smarty->display("inc_show_attachments.tpl"); $pop->close(); }
$object->load($object_id); $mail = new CUserMail(); $mail->load($mail_id); if (!$object->_id) { CAppUI::stepAjax("CUserMail-link-objectNull", UI_MSG_ERROR); } if (str_replace("-", "", $attach_list) == "" && !$text_plain && !$text_html) { CAppUI::stepAjax("CMailAttachments-msg-no_object_to_attach", UI_MSG_ERROR); } $attachments = trim($attach_list) ? explode("-", $attach_list) : array(); foreach ($attachments as $_attachment) { //no attachment value if (!$_attachment) { continue; } $attachment = new CMailAttachments(); if ($_attachment != "") { $attachment->load($_attachment); $attachment->loadRefsFwd(); //already linked = skip, no id, skip if ($attachment->file_id || !$attachment->_id) { continue; } } //linking if ($attachment->_file->_id) { $attachment->_file->setObject($object); if ($msg = $attachment->_file->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { $attachment->file_id = $attachment->_file->_id;
function createUserMail($user_id, $object = null, $apicrypt = false) { if (CModule::getActive('messagerie')) { $mail = new CUserMail(); $mail->account_id = $this->_id; $mail->account_class = $this->_class; $mail->sent = 1; $mail->subject = $this->_mail->Subject; $mail->from = $this->_mail->From; $mail->to = $this->_to['address']; $mail->date_inbox = CMbDT::dateTime(); if ($this->_mail->ContentType == 'text/html') { $mail->_text_html = $this->_mail->Body; if ($apicrypt) { $mail->_is_apicrypt = 'html'; } $mail->getHtmlText($user_id); } else { $mail->_text_plain = $this->_mail->Body; if ($apicrypt) { $mail->_is_apicrypt = 'plain'; } $mail->getPlainText($user_id); } $mail->store(); if ($object) { $file = null; switch ($object->_class) { case "CCompteRendu": $file = $object->_ref_file; break; case "CFile": $file = $object; break; } if ($file && $file->_id) { $attachment = new CMailAttachments(); $attachment->mail_id = $mail->_id; list($type, $subtype) = explode('/', $file->file_type); $attachment->type = $attachment->getTypeInt($type); $attachment->part = 1; $attachment->subtype = $subtype; $attachment->bytes = $file->doc_size; list($file_name, $extension) = explode('.', $file->file_name); $attachment->name = $file_name; $attachment->extension = $extension; $attachment->file_id = $file->_id; $attachment->store(); } } } }
/** * Get the attachments of a mail_id * * @param int $mail_id id of the mail (warning, UID and not ID) * @param bool $structure structure * @param bool $part_number part number * @param bool $part_temp part for get the part later * * @return CMailAttachments[] */ function getListAttachments($mail_id, $structure = false, $part_number = false, $part_temp = false) { if (!$structure) { $structure = $this->structure($mail_id); } if ($structure) { if (!isset($structure->parts) && !$part_number) { //plain text only, no recursive $part_number = "1"; } if (!$part_number) { $part_number = "0"; } switch ($structure->type) { //multipart, alternatived case 1: while (list($index, $sub_structure) = each($structure->parts)) { if ($part_number !== false) { $prefix = $part_number . '.'; } else { $prefix = null; } if ($part_temp !== false) { $prefix_temp = $part_temp . '.'; } else { $prefix_temp = null; } self::getListAttachments($mail_id, $sub_structure, $prefix . ($index + 1), $prefix_temp . $index); } break; // text // text case 0: case 2: //message //message case 3: //application //application case 4: //audio //audio case 5: //images //images case 6: //video $attach = new CMailAttachments(); $attach->loadFromHeader($structure); if ($attach->name) { $attach->part = $part_temp; //inline attachments $this->content["attachments"][] = $attach; } break; default: //other } } return $this->content["attachments"]; }