19declare(strict_types=1);
55 private int $a_user_id,
66 private ?Closure $usr_id_by_login_callable =
null,
68 private ?
int $mail_admin_node_ref_id =
null,
69 private ?
int $mail_obj_ref_id =
null,
79 $this->event_handler = $event_handler ??
$DIC->event();
80 $this->db = $db ??
$DIC->database();
81 $this->
lng =
$lng ?? $DIC->language();
82 $this->actor = $actor ??
$DIC->user();
83 $this->mail_file_data = $mail_file_data ??
new ilFileDataMail($a_user_id);
84 $this->mail_options = $mail_options ??
new ilMailOptions($a_user_id);
85 $this->mailbox = $mailbox ??
new ilMailbox($a_user_id);
87 $this->sender_factory = $sender_factory ??
$DIC->mail()->mime()->senderFactory();
88 $this->usr_id_by_login_callable = $usr_id_by_login_callable ?? (
static fn(
string $login):
int => (
int)
ilObjUser::_lookupId($login));
89 $this->auto_responder_service = $auto_responder_service ??
$DIC->mail()->autoresponder();
90 $this->user_id = $a_user_id;
91 if ($this->mail_obj_ref_id ===
null) {
94 $this->
lng->loadLanguageModule(
'mail');
95 $this->table_mail =
'mail';
96 $this->table_mail_saved =
'mail_saved';
98 $this->placeholder_resolver = $placeholder_resolver ??
$DIC->mail()->placeholderResolver();
99 $this->placeholder_to_empty_resolver = $placeholder_to_empty_resolver ??
$DIC->mail()->placeholderToEmptyResolver();
106 return $this->auto_responder_service;
111 $clone = clone $this;
120 $clone = clone $this;
122 $clone->context_parameters = $parameters;
132 public function existsRecipient(
string $new_recipient,
string $existing_recipients): bool
138 $diffed_addresses = $list->value();
140 return $diffed_addresses === [];
160 return $this->mail_obj_ref_id;
165 $recipients = trim($recipients);
166 if ($recipients ===
'') {
167 return $this->
lng->txt(
'not_available');
172 $recipients = array_filter(array_map(
'trim', explode(
',', $recipients)));
173 foreach ($recipients as $recipient) {
175 if (is_int($usr_id) && $usr_id > 0) {
177 if ($pp ===
'g' || ($pp ===
'y' && !$this->actor->isAnonymous())) {
180 $names[] = $user->getFullname() .
' [' . $recipient .
']';
186 $names[] = $recipient;
189 return implode(
', ', $names);
194 $this->db->setLimit(1, 0);
196 $query = implode(
' ', [
197 "SELECT b.* FROM $this->table_mail a",
198 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
199 'AND b.user_id = a.user_id AND b.send_time > a.send_time',
200 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
202 $res = $this->db->queryF(
204 [
'integer',
'integer'],
205 [$this->user_id, $mail_id]
215 $this->db->setLimit(1, 0);
217 $query = implode(
' ', [
218 "SELECT b.* FROM $this->table_mail a",
219 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
220 'AND b.user_id = a.user_id AND b.send_time < a.send_time',
221 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
223 $res = $this->db->queryF(
225 [
'integer',
'integer'],
226 [$this->user_id, $mail_id]
239 'SELECT sender_id, m_subject, mail_id, m_status, send_time, import_name ' .
240 "FROM $this->table_mail " .
241 'LEFT JOIN object_data ON obj_id = sender_id ' .
242 'WHERE user_id = %s AND folder_id = %s ' .
243 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) ' .
244 'OR (sender_id = 0 OR sender_id IS NULL))';
246 if (isset($filter[
'status']) && $filter[
'status'] !==
'') {
247 $query .=
' AND m_status = ' . $this->db->quote($filter[
'status'],
'text');
250 $query .=
' ORDER BY send_time DESC';
252 $res = $this->db->queryF(
254 [
'integer',
'integer'],
255 [$this->user_id, $a_folder_id]
258 while ($row = $this->db->fetchAssoc(
$res)) {
262 return array_filter($mails);
267 $res = $this->db->queryF(
268 "SELECT COUNT(*) FROM $this->table_mail WHERE user_id = %s AND folder_id = %s",
269 [
'integer',
'integer'],
270 [$this->user_id, $folder_id]
273 return $this->db->numRows(
$res);
286 $res = $this->db->queryF(
287 "SELECT * FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
288 [
'integer',
'integer'],
289 [$this->user_id, $mail_id]
305 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
307 $types[] =
'integer';
311 if ($mail_ids !== []) {
312 $query .=
' AND ' . $this->db->in(
'mail_id', $mail_ids,
false,
'integer');
315 $this->db->manipulateF($query, $types, $values);
326 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
328 $types[] =
'integer';
329 $values[] =
'unread';
332 if ($mail_ids !== []) {
333 $query .=
' AND ' . $this->db->in(
'mail_id', $mail_ids,
false,
'integer');
336 $this->db->manipulateF($query, $types, $values);
347 $mail_ids = array_filter(array_map(intval(...), $mail_ids));
349 if ([] === $mail_ids) {
354 "UPDATE $this->table_mail " .
355 'INNER JOIN mail_obj_data ' .
356 'ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s ' .
357 "SET $this->table_mail.folder_id = mail_obj_data.obj_id " .
358 "WHERE $this->table_mail.user_id = %s";
359 $types[] =
'integer';
360 $types[] =
'integer';
361 $types[] =
'integer';
362 $values[] = $folder_id;
366 $query .=
' AND ' . $this->db->in(
'mail_id', $mail_ids,
false,
'integer');
368 $affected_rows = $this->db->manipulateF($query, $types, $values);
370 return $affected_rows > 0;
378 $mail_ids = array_filter(array_map(
'intval', $mail_ids));
379 foreach ($mail_ids as
$id) {
380 $this->db->manipulateF(
381 "DELETE FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
382 [
'integer',
'integer'],
383 [$this->user_id,
$id]
385 $this->mail_file_data->deassignAttachmentFromDirectory(
$id);
391 if (!is_array($row) || empty($row)) {
395 if (isset($row[
'attachments'])) {
396 $unserialized = unserialize(stripslashes((
string) $row[
'attachments']), [
'allowed_classes' =>
false]);
397 $row[
'attachments'] = is_array($unserialized) ? $unserialized : [];
399 $row[
'attachments'] = [];
402 if (isset($row[
'tpl_ctx_params']) && is_string($row[
'tpl_ctx_params'])) {
403 $decoded = json_decode($row[
'tpl_ctx_params'],
true, 512, JSON_THROW_ON_ERROR);
404 $row[
'tpl_ctx_params'] = (array) ($decoded ?? []);
406 $row[
'tpl_ctx_params'] = [];
409 if (isset($row[
'mail_id'])) {
410 $row[
'mail_id'] = (
int) $row[
'mail_id'];
413 if (isset($row[
'user_id'])) {
414 $row[
'user_id'] = (
int) $row[
'user_id'];
417 if (isset($row[
'folder_id'])) {
418 $row[
'folder_id'] = (
int) $row[
'folder_id'];
421 if (isset($row[
'sender_id'])) {
422 $row[
'sender_id'] = (
int) $row[
'sender_id'];
425 if (isset($row[
'use_placeholders'])) {
426 $row[
'use_placeholders'] = (bool) $row[
'use_placeholders'];
429 $null_to_string_properties = [
'm_subject',
'm_message',
'rcp_to',
'rcp_cc',
'rcp_bcc'];
430 foreach ($null_to_string_properties as $null_to_string_property) {
431 if (!isset($row[$null_to_string_property])) {
432 $row[$null_to_string_property] =
'';
441 $next_id = $this->db->nextId($this->table_mail);
442 $this->db->insert($this->table_mail, [
443 'mail_id' => [
'integer', $next_id],
444 'user_id' => [
'integer', $this->user_id],
445 'folder_id' => [
'integer', $folder_id],
446 'sender_id' => [
'integer', $this->user_id],
457 array $a_attachments,
464 bool $a_use_placeholders =
false,
465 ?
string $a_tpl_context_id =
null,
466 array $a_tpl_context_params = []
471 'folder_id' => [
'integer', $a_folder_id],
472 'attachments' => [
'clob', serialize($a_attachments)],
473 'send_time' => [
'timestamp', date(
'Y-m-d H:i:s')],
474 'rcp_to' => [
'clob', $a_rcp_to],
475 'rcp_cc' => [
'clob', $a_rcp_cc],
476 'rcp_bcc' => [
'clob', $a_rcp_bcc],
477 'm_status' => [
'text',
'read'],
478 'm_subject' => [
'text', $a_m_subject],
479 'm_message' => [
'clob', $a_m_message],
480 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
481 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
482 'tpl_ctx_params' => [
'blob', json_encode($a_tpl_context_params, JSON_THROW_ON_ERROR)],
485 'mail_id' => [
'integer', $a_draft_id],
503 bool $use_placeholders =
false,
504 ?
string $template_contenxt_id =
null,
505 array $template_context_parameters = []
507 $usr_id = $usr_id ?: $this->user_id;
509 if ($use_placeholders) {
514 $next_id = $this->db->nextId($this->table_mail);
515 $this->db->insert($this->table_mail, [
516 'mail_id' => [
'integer', $next_id],
517 'user_id' => [
'integer', $usr_id],
518 'folder_id' => [
'integer', $folder_id],
519 'sender_id' => [
'integer', $sender_usr_id],
520 'attachments' => [
'clob', serialize($attachments)],
521 'send_time' => [
'timestamp', date(
'Y-m-d H:i:s')],
522 'rcp_to' => [
'clob', $to],
523 'rcp_cc' => [
'clob', $cc],
524 'rcp_bcc' => [
'clob', $bcc],
525 'm_status' => [
'text', $status],
526 'm_subject' => [
'text', $subject],
528 'tpl_ctx_id' => [
'text', $template_contenxt_id],
529 'tpl_ctx_params' => [
'blob', json_encode($template_context_parameters, JSON_THROW_ON_ERROR)],
532 $sender_equals_reveiver = $usr_id === $this->mailbox->getUsrId();
533 $is_sent_folder_of_sender =
false;
534 if ($sender_equals_reveiver) {
535 $current_folder_id = $this->getSubjectSentFolderId();
536 $is_sent_folder_of_sender = $folder_id === $current_folder_id;
539 $raise_event = !$sender_equals_reveiver || !$is_sent_folder_of_sender;
542 $this->event_handler->raise(
'components/ILIAS/Mail',
'sentInternalMail', [
544 'subject' => $subject,
546 'from_usr_id' => $sender_usr_id,
547 'to_usr_id' => $usr_id,
562 if ($this->context_id) {
568 $user = $usr_id > 0 ? $this->getUserInstanceById($usr_id) : null;
569 $message = $this->placeholder_resolver->resolve(
573 $this->context_parameters
575 }
catch (Exception
$e) {
576 $this->
logger->error(sprintf(
577 '%s has been called with invalid context: %s / %s',
580 $e->getTraceAsString()
589 return $this->placeholder_to_empty_resolver->resolve(
$message);
594 $this->auto_responder_service->emptyAutoresponderData();
595 $to_usr_ids = $this->getUserIds([$mail_data->
getTo()]);
596 $this->
logger->debug(sprintf(
597 'Parsed TO user ids from given recipients for serial letter notification: %s',
598 implode(
', ', $to_usr_ids)
601 $other_usr_ids = $this->getUserIds([$mail_data->
getCc(), $mail_data->
getBcc()]);
602 $cc_bcc_recipients = array_map(
603 $this->createRecipient(...),
606 $this->
logger->debug(sprintf(
607 'Parsed CC/BCC user ids from given recipients for serial letter notification: %s',
608 implode(
', ', $other_usr_ids)
612 $this->sendMailWithReplacedPlaceholder($mail_data, $to_usr_ids);
613 $this->sendMailWithReplacedEmptyPlaceholder($mail_data, $cc_bcc_recipients);
615 $this->sendMailWithoutReplacedPlaceholder($mail_data, $to_usr_ids, $cc_bcc_recipients);
618 $this->auto_responder_service->disableAutoresponder();
619 $this->auto_responder_service->handleAutoresponderMails($this->user_id);
632 $recipient = $this->createRecipient(
$user_id);
634 $this->sendChanneledMails(
649 $this->sendChanneledMails(
652 $this->replacePlaceholdersEmpty($mail_data->getMessage()),
663 array $cc_bcc_recipients
665 $to_recipients = array_map(
666 $this->createRecipient(...),
670 $this->sendChanneledMails(
672 array_merge($to_recipients, $cc_bcc_recipients),
685 $usr_id_to_external_email_addresses_map = [];
687 foreach ($recipients as $recipient) {
688 if (!$recipient->isUser()) {
689 $this->
logger->critical(sprintf(
690 'Skipped recipient with id %s (User not found)',
691 $recipient->getUserId()
696 $can_read_internal = $recipient->evaluateInternalMailReadability();
697 if ($this->isSystemMail() && !$can_read_internal->isOk()) {
698 $this->
logger->debug(sprintf(
699 'Skipped recipient with id %s and reason: %s',
700 $recipient->getUserId(),
701 is_string($can_read_internal->error()) ? $can_read_internal->error() : $can_read_internal->error()->getMessage()
706 if ($recipient->isUserActive() && !$recipient->isUserExpired()) {
707 if (!$can_read_internal->isOk() || $recipient->userWantsToReceiveExternalMails()) {
708 $email_addresses = $recipient->getExternalMailAddress();
709 $usr_id_to_external_email_addresses_map[$recipient->getUserId()] = $email_addresses;
711 if ($recipient->onlyToExternalMailAddress()) {
712 $this->
logger->debug(sprintf(
713 'Recipient with id %s will only receive external emails sent to: %s',
714 $recipient->getUserId(),
715 implode(
', ', $email_addresses)
720 $this->
logger->debug(sprintf(
721 'Recipient with id %s will additionally receive external emails ' .
722 '(because the user wants to receive it externally, or the user cannot did not accept ' .
723 'the legal documents) sent to: %s',
724 $recipient->getUserId(),
725 implode(
', ', $email_addresses)
728 $this->
logger->debug(sprintf(
729 'Recipient with id %s does not want to receive external emails',
730 $recipient->getUserId()
734 $this->
logger->debug(sprintf(
735 'Recipient with id %s is inactive or expired and will not receive external emails',
736 $recipient->getUserId()
740 $mbox = clone $this->mailbox;
741 $mbox->setUsrId($recipient->getUserId());
742 $recipient_inbox_id = $mbox->getInboxFolder();
744 $internal_mail_id = $this->sendInternalMail(
754 $recipient->getUserId()
757 $this->auto_responder_service->enqueueAutoresponderIfEnabled(
758 $recipient->getUserId(),
759 $recipient->getMailOptions(),
760 $this->getMailOptionsByUserId($this->user_id),
764 $this->mail_file_data->assignAttachmentsToDirectory($internal_mail_id, $mail_data->
getInternalMailId());
768 $this->delegateExternalEmails(
772 $usr_id_to_external_email_addresses_map
784 array $usr_id_to_external_email_addresses_map
786 if (count($usr_id_to_external_email_addresses_map) === 1) {
787 $usr_id_to_external_email_addresses_map = array_values($usr_id_to_external_email_addresses_map);
788 $first_addresses = current($usr_id_to_external_email_addresses_map);
791 implode(
',', $first_addresses),
798 } elseif (count($usr_id_to_external_email_addresses_map) > 1) {
799 $flattened_email_addresses = iterator_to_array(
new RecursiveIteratorIterator(
new RecursiveArrayIterator(
800 $usr_id_to_external_email_addresses_map
803 $flattened_email_addresses = array_unique($flattened_email_addresses);
806 $remaining_addresses =
'';
807 foreach ($flattened_email_addresses as $email_address) {
809 if ($remaining_addresses !==
'') {
813 $recipients_line_length =
ilStr::strLen($remaining_addresses) +
815 if ($recipients_line_length >= $this->max_recipient_character_length) {
819 $remaining_addresses,
825 $remaining_addresses =
'';
829 $remaining_addresses .= ($sep . $email_address);
832 if ($remaining_addresses !==
'') {
836 $remaining_addresses,
851 $parsed_usr_ids = [];
853 $joined_recipients = implode(
',', array_filter(array_map(
'trim', $recipients)));
855 $addresses = $this->parseAddresses($joined_recipients);
856 foreach ($addresses as $address) {
857 $address_type = $this->mail_address_type_factory->getByPrefix($address);
858 $parsed_usr_ids[] = $address_type->resolve();
861 return array_unique(array_merge(...$parsed_usr_ids));
867 private function checkMail(
string $to,
string $cc,
string $bcc,
string $subject): array
872 $subject =>
'mail_add_subject',
873 $to =>
'mail_add_recipient',
875 foreach ($checks as $string => $error) {
876 if ($string ===
'') {
883 $errors[] =
new ilMailError(
'mail_subject_too_long');
897 $addresses = $this->parseAddresses($recipients);
898 foreach ($addresses as $address) {
899 $address_type = $this->mail_address_type_factory->getByPrefix($address);
900 if (!$address_type->validate($this->user_id)) {
901 $errors[] = $address_type->getErrors();
904 }
catch (Exception
$e) {
905 $position = strpos(
$e->getMessage(),
':');
907 ($position ===
false) ?
$e->getMessage() : substr(
$e->getMessage(), $position + 2),
913 return array_merge(...$errors);
921 array $a_attachments,
927 bool $a_use_placeholders =
false,
928 ?
string $a_tpl_context_id =
null,
929 ?array $a_tpl_ctx_params = []
932 $this->table_mail_saved,
934 'user_id' => [
'integer', $this->user_id],
937 'attachments' => [
'clob', serialize($a_attachments)],
938 'rcp_to' => [
'clob', $a_rcp_to],
939 'rcp_cc' => [
'clob', $a_rcp_cc],
940 'rcp_bcc' => [
'clob', $a_rcp_bcc],
941 'm_subject' => [
'text', $a_m_subject],
942 'm_message' => [
'clob', $a_m_message],
943 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
944 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
945 'tpl_ctx_params' => [
'blob', json_encode((array) $a_tpl_ctx_params, JSON_THROW_ON_ERROR)],
949 $this->retrieveFromStage();
956 $res = $this->db->queryF(
957 "SELECT * FROM $this->table_mail_saved WHERE user_id = %s",
962 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc(
$res));
963 if (!is_array($this->mail_data)) {
964 $this->persistToStage($this->user_id, [],
'',
'',
'',
'',
'',
false);
967 return $this->mail_data;
982 bool $a_use_placeholders =
false
987 $a_m_subject = $sanitizeMb4Encoding->transform($a_m_subject);
988 $a_m_message = $sanitizeMb4Encoding->transform($a_m_message);
991 'New mail system task:' .
992 ' To: ' . $a_rcp_to .
993 ' | CC: ' . $a_rcp_cc .
994 ' | BCC: ' . $a_rcp_bcc .
995 ' | Subject: ' . $a_m_subject .
996 ' | Attachments: ' . print_r($a_attachment,
true)
999 if ($a_attachment && !$this->mail_file_data->checkFilesExist($a_attachment)) {
1000 return [
new ilMailError(
'mail_attachment_file_not_exist', [implode(
', ', $a_attachment)])];
1003 $errors = $this->checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject);
1004 if ($errors !== []) {
1008 $errors = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bcc);
1009 if ($errors !== []) {
1013 $rcp_to = $a_rcp_to;
1014 $rcp_cc = $a_rcp_cc;
1015 $rcp_bcc = $a_rcp_bcc;
1017 $number_of_external_addresses = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bcc);
1019 $number_of_external_addresses > 0 &&
1020 !$this->isSystemMail() &&
1021 !
$DIC->rbac()->system()->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id)
1023 return [
new ilMailError(
'mail_no_permissions_write_smtp')];
1026 if ($this->appendInstallationSignature()) {
1027 $a_m_message .= self::_getInstallationSignature();
1040 return $this->sendMail($mail_data);
1043 $task_factory =
$DIC->backgroundTasks()->taskFactory();
1044 $task_manager =
$DIC->backgroundTasks()->taskManager();
1047 $bucket->setUserId($this->user_id);
1049 $task = $task_factory->createTask(ilMailDeliveryJob::class, [
1056 serialize($a_attachment),
1057 $a_use_placeholders,
1058 $this->getSaveInSentbox(),
1059 (
string) $this->context_id,
1060 serialize(array_merge(
1061 $this->context_parameters,
1063 'auto_responder' => $this->auto_responder_service->isAutoresponderEnabled()
1067 $interaction = $task_factory->createTask(ilMailDeliveryJobUserInteraction::class, [
1072 $bucket->setTask($interaction);
1073 $bucket->setTitle($this->
lng->txt(
'mail_bg_task_title'));
1074 $bucket->setDescription(sprintf($this->
lng->txt(
'mail_bg_task_desc'), $a_m_subject));
1076 $this->
logger->info(
'Delegated delivery to background task');
1077 $task_manager->run($bucket);
1093 $internal_message_id = $this->saveInSentbox(
1094 $mail_data->getAttachments(),
1095 $mail_data->getTo(),
1096 $mail_data->getCc(),
1097 $mail_data->getBcc(),
1098 $mail_data->getSubject(),
1099 $mail_data->getMessage()
1104 $this->mail_file_data->assignAttachmentsToDirectory($internal_message_id, $internal_message_id);
1105 $this->mail_file_data->saveFiles($internal_message_id, $mail_data->
getAttachments());
1108 $num_external_email_addresses = $this->getCountRecipients(
1109 $mail_data->
getTo(),
1110 $mail_data->
getCc(),
1114 if ($num_external_email_addresses > 0) {
1115 $external_mail_recipients_to = $this->getEmailRecipients($mail_data->
getTo());
1116 $external_mail_recipients_cc = $this->getEmailRecipients($mail_data->
getCc());
1117 $external_eail_recipients_bcc = $this->getEmailRecipients($mail_data->
getBcc());
1120 'Parsed external email addresses from given recipients /' .
1121 ' To: ' . $external_mail_recipients_to .
1122 ' | CC: ' . $external_mail_recipients_cc .
1123 ' | BCC: ' . $external_eail_recipients_bcc .
1127 $this->sendMimeMail(
1128 $external_mail_recipients_to,
1129 $external_mail_recipients_cc,
1130 $external_eail_recipients_bcc,
1133 $this->replacePlaceholders($mail_data->
getMessage(), 0) :
1138 $this->
logger->debug(
'No external email addresses given in recipient string');
1142 if (!$this->distributeMail($mail_data)) {
1143 $errors[
'mail_send_error'] =
new ilMailError(
'mail_send_error');
1146 if (!$this->getSaveInSentbox()) {
1147 $this->deleteMails([$internal_message_id]);
1150 if ($this->isSystemMail()) {
1151 $random =
new Random\Randomizer();
1152 if ($random->getInt(0, 50) === 2) {
1155 $this->mail_file_data
1160 return array_values($errors);
1170 $errors = array_merge($errors, $this->checkRecipients($to));
1171 $errors = array_merge($errors, $this->checkRecipients($cc));
1172 $errors = array_merge($errors, $this->checkRecipients($bcc));
1174 if ($errors !== []) {
1175 return array_merge([
new ilMailError(
'mail_following_rcp_not_valid')], $errors);
1178 return [
new ilMailError(
'mail_generic_rcp_error', [
$e->getMessage()])];
1186 $send_folder_id = 0;
1187 if (!$this->isSystemMail()) {
1188 $send_folder_id = $this->mailbox->getSentFolder();
1191 return $send_folder_id;
1205 return $this->sendInternalMail(
1206 $this->getSubjectSentFolderId(),
1231 $mailer->
From($this->sender_factory->getSenderByUsrId($this->user_id));
1236 (
string) ($this->context_parameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ??
'')
1239 if (!$this->isSystemMail()) {
1240 $message .= $this->signature_service->user($this->user_id);
1253 foreach ($attachments as $attachment) {
1255 $this->mail_file_data->getAbsoluteAttachmentPoolPathByFilename($attachment),
1271 $this->table_mail_saved,
1273 'attachments' => [
'clob', serialize($attachments)],
1276 'user_id' => [
'integer', $this->user_id],
1287 if ($addresses !==
'') {
1288 $this->
logger->debug(sprintf(
1289 'Started parsing of recipient string: %s',
1294 $parser = $this->mail_address_parser_factory->getParser($addresses);
1295 $parsed_addresses = $parser->parse();
1297 if ($addresses !==
'') {
1298 $this->
logger->debug(sprintf(
1299 'Parsed addresses: %s',
1300 implode(
',', array_map(
static fn(
ilMailAddress $address):
string => (
string) $address, $parsed_addresses))
1304 return $parsed_addresses;
1310 if ($only_external_addresses) {
1314 $this->usr_id_by_login_callable
1318 return count($addresses->value());
1322 string $to_recipients,
1323 string $cc_recipients,
1324 string $bcc_recipients,
1325 bool $only_external_addresses =
true
1328 $this->getCountRecipient($to_recipients, $only_external_addresses) +
1329 $this->getCountRecipient($cc_recipients, $only_external_addresses) +
1330 $this->getCountRecipient($bcc_recipients, $only_external_addresses)
1339 $this->usr_id_by_login_callable
1342 $email_recipients = array_map(
static fn(
ilMailAddress $address):
string => (
string) $address, $addresses->value());
1344 return implode(
',', $email_recipients);
1355 $lang->loadLanguageModule(
'mail');
1358 $lang->txt(
'mail_auto_generated_info'),
1367 $sender_factory =
$DIC->mail()->mime()->senderFactory();
1369 return $sender_factory->system()->getFromName();
1377 if ($a_flag ===
null) {
1378 return $this->append_installation_signature;
1381 $this->append_installation_signature = $a_flag;
1388 return $DIC->mail()->signature()->installation();
1396 $lang->loadLanguageModule(
'mail');
1399 $gender = $gender ?:
'n';
1402 if ($name[
'firstname'] ===
'') {
1403 return $lang->txt(
'mail_salutation_anonymous') .
',';
1407 $lang->txt(
'mail_salutation_' . $gender) .
' ' .
1408 ($name[
'title'] ? $name[
'title'] .
' ' :
'') .
1409 ($name[
'firstname'] ? $name[
'firstname'] .
' ' :
'') .
1410 $name[
'lastname'] .
',';
1415 if (!array_key_exists($usr_id, $this->user_instances_by_id_map)) {
1418 }
catch (Exception) {
1422 $this->user_instances_by_id_map[$usr_id] = $user;
1425 return $this->user_instances_by_id_map[$usr_id];
1433 $this->user_instances_by_id_map = $user_instances_by_id_map;
1438 if (!isset($this->mail_options_by_usr_id_map[$usr_id])) {
1439 $this->mail_options_by_usr_id_map[$usr_id] =
new ilMailOptions($usr_id);
1442 return $this->mail_options_by_usr_id_map[$usr_id];
1450 $this->mail_options_by_usr_id_map = $mail_options_by_usr_id_map;
1462 $this->getUserInstanceById(
$user_id),
1463 $this->getMailOptionsByUserId(
$user_id),
1464 $this->legal_documents
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
withInternalMailId(int $internal_mail_id)
static getType()
Get context type.
static _getLanguage(string $a_lang_key='')
Get language object.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static getMailObjectRefId()
static getTemplateContextById(string $a_id)
static _getIliasMailerName()
sendMimeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)
int $max_recipient_character_length
getCountRecipient(string $recipients, bool $only_external_addresses=true)
withContextParameters(array $parameters)
sendMailWithoutReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids, array $cc_bcc_recipients)
deleteMails(array $mail_ids)
parseAddresses(string $addresses)
Explode recipient string, allowed separators are ',' ';' ' '.
getUserIds(array $recipients)
getUserInstanceById(int $usr_id)
moveMailsToFolder(array $mail_ids, int $folder_id)
checkRecipients(string $recipients)
array $context_parameters
markUnread(array $mail_ids)
saveAttachments(array $attachments)
array $mail_options_by_usr_id_map
const string PROP_CONTEXT_SUBJECT_PREFIX
array $user_instances_by_id_map
formatNamesForOutput(string $recipients)
getCountRecipients(string $to_recipients, string $cc_recipients, string $bcc_recipients, bool $only_external_addresses=true)
bool $append_installation_signature
sendMailWithReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids)
sendMailWithReplacedEmptyPlaceholder(MailDeliveryData $mail_data, array $recipients,)
deleteMailsOfFolder(int $folder_id)
appendInstallationSignature(?bool $a_flag=null)
persistToStage(int $a_user_id, array $a_attachments, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, ?array $a_tpl_ctx_params=[])
validateRecipients(string $to, string $cc, string $bcc)
readonly Conductor $legal_documents
setMailOptionsByUserIdMap(array $mail_options_by_usr_id_map)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
distributeMail(MailDeliveryData $mail_data)
static _getInstallationSignature()
sendInternalMail(int $folder_id, int $sender_usr_id, array $attachments, string $to, string $cc, string $bcc, string $status, string $subject, string $message, int $usr_id=0, bool $use_placeholders=false, ?string $template_contenxt_id=null, array $template_context_parameters=[])
__construct(private int $a_user_id, private ?ilMailAddressTypeFactory $mail_address_type_factory=null, private ilMailRfc822AddressParserFactory $mail_address_parser_factory=new ilMailRfc822AddressParserFactory(), private ?ilAppEventHandler $event_handler=null, private ?ilLogger $logger=null, private ?ilDBInterface $db=null, private ?ilLanguage $lng=null, private ?ilFileDataMail $mail_file_data=null, protected ?ilMailOptions $mail_options=null, private ?ilMailbox $mailbox=null, private ?ilMailMimeSenderFactory $sender_factory=null, private ?Closure $usr_id_by_login_callable=null, private ?AutoresponderService $auto_responder_service=null, private ?int $mail_admin_node_ref_id=null, private ?int $mail_obj_ref_id=null, private ?ilObjUser $actor=null, private ?ilMailTemplatePlaceholderResolver $placeholder_resolver=null, private ?ilMailTemplatePlaceholderToEmptyResolver $placeholder_to_empty_resolver=null, ?Conductor $legal_documents=null, ?MailSignatureService $signature_service=null,)
sendChanneledMails(MailDeliveryData $mail_data, array $recipients, string $message)
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
withContextId(string $context_id)
existsRecipient(string $new_recipient, string $existing_recipients)
replacePlaceholders(string $message, int $usr_id=0)
formatLinebreakMessage(string $message)
updateDraft(int $a_folder_id, array $a_attachments, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, int $a_draft_id=0, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, array $a_tpl_context_params=[])
markRead(array $mail_ids)
countMailsOfFolder(int $folder_id)
setUserInstanceById(array $user_instances_by_id_map)
getMailsOfFolder(int $a_folder_id, array $filter=[])
getEmailRecipients(string $recipients)
delegateExternalEmails(string $subject, array $attachments, string $message, array $usr_id_to_external_email_addresses_map)
checkMail(string $to, string $cc, string $bcc, string $subject)
replacePlaceholdersEmpty(string $message)
static _getAutoGeneratedMessageString(?ilLanguage $lang=null)
createRecipient(int $user_id)
getMailObjectReferenceId()
getPreviousMail(int $mail_id)
bool $append_user_signature
readMailObjectReferenceId()
getNextMail(int $mail_id)
enqueue(string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, array $a_attachment, bool $a_use_placeholders=false)
Should be used to enqueue a 'mail'.
setSaveInSentbox(bool $save_in_sentbox)
fetchMailData(?array $row)
getNewDraftId(int $folder_id)
getMailOptionsByUserId(int $usr_id)
MailSignatureService $signature_service
sendMail(MailDeliveryData $mail_data)
This method is used to finally send internal messages and external emails To use the mail system as a...
From(ilMailMimeSender $sender)
static _lookupName(int $a_user_id)
static _lookupId(string|array $a_user_str)
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupGender(int $a_user_id)
static strLen(string $a_string)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ILIAS_VERSION_NUMERIC
if(!file_exists('../ilias.ini.php'))