foreach ($unseen as $_mail) { $pop->cleanTemp(); $mail_unseen = new CUserMail(); $mail_unseen->account_id = $_source->_id; $mail_unseen->account_class = $_source->_class; //mail non existant $header = $pop->header($_mail); $content = $pop->getFullBody($_mail, false, false, true); $hash = $mail_unseen->makeHash($header, $content); if (!$mail_unseen->loadMatchingFromHash($hash)) { $mail_unseen->setHeaderFromSource($header); $mail_unseen->setContentFromSource($pop->getFullBody($_mail, false, false, true)); //text plain $mail_unseen->getPlainText($_source->object_id); //text html $mail_unseen->getHtmlText($_source->object_id); //sent ? if (strpos($mail_unseen->from, $_source->user) !== false) { $mail_unseen->sent = 1; } //unread increment if (!$mail_unseen->date_read) { $unread++; } //read on server + pref + not sent => archived ! if ($mail_unseen->date_read && $archivedOnReception && !$mail_unseen->sent) { $mail_unseen->archived = 1; } //store the usermail if (!($msg = $mail_unseen->store())) { $created++;
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(); } } } }