19 declare(strict_types=1);
56 private int $a_user_id,
67 private ?
Closure $usr_id_by_login_callable = null,
69 private ?
int $mail_admin_node_ref_id = null,
70 private ?
int $mail_obj_ref_id = null,
80 $this->event_handler = $event_handler ?? $DIC->event();
81 $this->db = $db ?? $DIC->database();
82 $this->
lng =
$lng ?? $DIC->language();
83 $this->actor = $actor ?? $DIC->user();
84 $this->mail_file_data = $mail_file_data ??
new ilFileDataMail($a_user_id);
85 $this->mail_options = $mail_options ??
new ilMailOptions($a_user_id);
86 $this->mailbox = $mailbox ??
new ilMailbox($a_user_id);
88 $this->sender_factory = $sender_factory ?? $DIC->mail()->mime()->senderFactory();
89 $this->usr_id_by_login_callable = $usr_id_by_login_callable ??
static function (
string $login):
int {
92 $this->auto_responder_service = $auto_responder_service ?? $DIC->mail()->autoresponder();
93 $this->user_id = $a_user_id;
94 if (null === $this->mail_obj_ref_id) {
97 $this->
lng->loadLanguageModule(
'mail');
98 $this->table_mail =
'mail';
99 $this->table_mail_saved =
'mail_saved';
101 $this->placeholder_resolver = $placeholder_resolver ?? $DIC->mail()->placeholderResolver();
102 $this->placeholder_to_empty_resolver = $placeholder_to_empty_resolver ?? $DIC->mail()->placeholderToEmptyResolver();
103 $this->legal_documents = $legal_documents ?? $DIC[
'legalDocuments'];
108 return $this->auto_responder_service;
113 $clone = clone $this;
115 $clone->context_id = $contextId;
122 $clone = clone $this;
124 $clone->context_parameters = $parameters;
134 public function existsRecipient(
string $newRecipient,
string $existingRecipients): bool
141 $diffedAddresses = $list->value();
143 return $diffedAddresses === [];
148 $this->save_in_sentbox = $saveInSentbox;
163 return $this->mail_obj_ref_id;
168 $recipients = trim($recipients);
169 if ($recipients ===
'') {
170 return $this->
lng->txt(
'not_available');
175 $recipients = array_filter(array_map(
'trim', explode(
',', $recipients)));
176 foreach ($recipients as $recipient) {
178 if (is_int($usrId) && $usrId > 0) {
180 if ($pp ===
'g' || ($pp ===
'y' && !$this->actor->isAnonymous())) {
183 $names[] = $user->getFullname() .
' [' . $recipient .
']';
189 $names[] = $recipient;
192 return implode(
', ', $names);
197 $this->db->setLimit(1, 0);
199 $query = implode(
' ', [
200 "SELECT b.* FROM $this->table_mail a",
201 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
202 'AND b.user_id = a.user_id AND b.send_time > a.send_time',
203 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
205 $res = $this->db->queryF(
207 [
'integer',
'integer'],
208 [$this->user_id, $mailId]
218 $this->db->setLimit(1, 0);
220 $query = implode(
' ', [
221 "SELECT b.* FROM $this->table_mail a",
222 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
223 'AND b.user_id = a.user_id AND b.send_time < a.send_time',
224 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
226 $res = $this->db->queryF(
228 [
'integer',
'integer'],
229 [$this->user_id, $mailId]
242 "SELECT sender_id, m_subject, mail_id, m_status, send_time, import_name " .
243 "FROM $this->table_mail " .
244 "LEFT JOIN object_data ON obj_id = sender_id " .
245 "WHERE user_id = %s AND folder_id = %s " .
246 "AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) " .
247 "OR (sender_id = 0 OR sender_id IS NULL))";
249 if (isset($filter[
'status']) && $filter[
'status'] !==
'') {
250 $query .=
' AND m_status = ' . $this->db->quote($filter[
'status'],
'text');
253 $query .=
" ORDER BY send_time DESC";
255 $res = $this->db->queryF(
257 [
'integer',
'integer'],
258 [$this->user_id, $a_folder_id]
261 while ($row = $this->db->fetchAssoc(
$res)) {
265 return array_filter($mails);
270 $res = $this->db->queryF(
271 "SELECT COUNT(*) FROM $this->table_mail WHERE user_id = %s AND folder_id = %s",
272 [
'integer',
'integer'],
273 [$this->user_id, $folderId]
276 return $this->db->numRows(
$res);
282 foreach ($mails as $mail_data) {
289 $res = $this->db->queryF(
290 "SELECT * FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
291 [
'integer',
'integer'],
292 [$this->user_id, $mailId]
308 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
310 $types[] =
'integer';
314 if ($mailIds !== []) {
315 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
318 $this->db->manipulateF($query, $types, $values);
329 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
331 $types[] =
'integer';
332 $values[] =
'unread';
335 if ($mailIds !== []) {
336 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
339 $this->db->manipulateF($query, $types, $values);
350 $mailIds = array_filter(array_map(
'intval', $mailIds));
352 if ([] === $mailIds) {
357 "UPDATE $this->table_mail " .
358 "INNER JOIN mail_obj_data " .
359 "ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s " .
360 "SET $this->table_mail.folder_id = mail_obj_data.obj_id " .
361 "WHERE $this->table_mail.user_id = %s";
362 $types[] =
'integer';
363 $types[] =
'integer';
364 $types[] =
'integer';
365 $values[] = $folderId;
369 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
371 $affectedRows = $this->db->manipulateF($query, $types, $values);
373 return $affectedRows > 0;
381 $mailIds = array_filter(array_map(
'intval', $mailIds));
382 foreach ($mailIds as
$id) {
383 $this->db->manipulateF(
384 "DELETE FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
385 [
'integer',
'integer'],
386 [$this->user_id, $id]
388 $this->mail_file_data->deassignAttachmentFromDirectory($id);
394 if (!is_array($row) || empty($row)) {
398 if (isset($row[
'attachments'])) {
399 $unserialized = unserialize(stripslashes($row[
'attachments']), [
'allowed_classes' =>
false]);
400 $row[
'attachments'] = is_array($unserialized) ? $unserialized : [];
402 $row[
'attachments'] = [];
405 if (isset($row[
'tpl_ctx_params']) && is_string($row[
'tpl_ctx_params'])) {
406 $decoded = json_decode($row[
'tpl_ctx_params'],
true, 512, JSON_THROW_ON_ERROR);
407 $row[
'tpl_ctx_params'] = (array) ($decoded ?? []);
409 $row[
'tpl_ctx_params'] = [];
412 if (isset($row[
'mail_id'])) {
413 $row[
'mail_id'] = (
int) $row[
'mail_id'];
416 if (isset($row[
'user_id'])) {
417 $row[
'user_id'] = (
int) $row[
'user_id'];
420 if (isset($row[
'folder_id'])) {
421 $row[
'folder_id'] = (
int) $row[
'folder_id'];
424 if (isset($row[
'sender_id'])) {
425 $row[
'sender_id'] = (
int) $row[
'sender_id'];
428 if (isset($row[
'use_placeholders'])) {
429 $row[
'use_placeholders'] = (bool) $row[
'use_placeholders'];
432 $null_to_string_properties = [
'm_subject',
'm_message',
'rcp_to',
'rcp_cc',
'rcp_bcc'];
433 foreach ($null_to_string_properties as $null_to_string_property) {
434 if (!isset($row[$null_to_string_property])) {
435 $row[$null_to_string_property] =
'';
444 $nextId = $this->db->nextId($this->table_mail);
445 $this->db->insert($this->table_mail, [
446 'mail_id' => [
'integer', $nextId],
447 'user_id' => [
'integer', $this->user_id],
448 'folder_id' => [
'integer', $folderId],
449 'sender_id' => [
'integer', $this->user_id],
460 array $a_attachments,
467 bool $a_use_placeholders =
false,
468 ?
string $a_tpl_context_id = null,
469 array $a_tpl_context_params = []
474 'folder_id' => [
'integer', $a_folder_id],
475 'attachments' => [
'clob', serialize($a_attachments)],
476 'send_time' => [
'timestamp', date(
'Y-m-d H:i:s')],
477 'rcp_to' => [
'clob', $a_rcp_to],
478 'rcp_cc' => [
'clob', $a_rcp_cc],
479 'rcp_bcc' => [
'clob', $a_rcp_bcc],
480 'm_status' => [
'text',
'read'],
481 'm_subject' => [
'text', $a_m_subject],
482 'm_message' => [
'clob', $a_m_message],
483 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
484 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
485 'tpl_ctx_params' => [
'blob', json_encode($a_tpl_context_params, JSON_THROW_ON_ERROR)],
488 'mail_id' => [
'integer', $a_draft_id],
506 bool $usePlaceholders =
false,
507 ?
string $templateContextId = null,
508 array $templateContextParameters = []
512 if ($usePlaceholders) {
515 $message = str_ireplace([
"<br />",
"<br>",
"<br/>"],
"\n", $message);
517 $nextId = $this->db->nextId($this->table_mail);
518 $this->db->insert($this->table_mail, [
519 'mail_id' => [
'integer', $nextId],
520 'user_id' => [
'integer', $usrId],
521 'folder_id' => [
'integer', $folderId],
522 'sender_id' => [
'integer', $senderUsrId],
523 'attachments' => [
'clob', serialize($attachments)],
524 'send_time' => [
'timestamp', date(
'Y-m-d H:i:s')],
525 'rcp_to' => [
'clob', $to],
526 'rcp_cc' => [
'clob', $cc],
527 'rcp_bcc' => [
'clob', $bcc],
528 'm_status' => [
'text', $status],
529 'm_subject' => [
'text', $subject],
530 'm_message' => [
'clob', $message],
531 'tpl_ctx_id' => [
'text', $templateContextId],
532 'tpl_ctx_params' => [
'blob', json_encode($templateContextParameters, JSON_THROW_ON_ERROR)],
535 $sender_equals_reveiver = $usrId === $this->mailbox->getUsrId();
536 $is_sent_folder_of_sender =
false;
537 if ($sender_equals_reveiver) {
539 $is_sent_folder_of_sender = $folderId === $current_folder_id;
542 $raise_event = !$sender_equals_reveiver || !$is_sent_folder_of_sender;
545 $this->event_handler->raise(
'Services/Mail',
'sentInternalMail', [
547 'subject' => $subject,
549 'from_usr_id' => $senderUsrId,
550 'to_usr_id' => $usrId,
565 if ($this->context_id) {
572 $message = $this->placeholder_resolver->resolve(
576 $this->context_parameters
579 $this->
logger->error(sprintf(
580 '%s has been called with invalid context: %s / %s',
583 $e->getTraceAsString()
592 return $this->placeholder_to_empty_resolver->resolve($message);
597 $this->auto_responder_service->emptyAutoresponderData();
599 $this->
logger->debug(sprintf(
600 "Parsed TO user ids from given recipients for serial letter notification: %s",
601 implode(
', ', $to_usr_ids)
605 $cc_bcc_recipients = array_map(
609 $this->
logger->debug(sprintf(
610 "Parsed CC/BCC user ids from given recipients for serial letter notification: %s",
611 implode(
', ', $other_usr_ids)
621 $this->auto_responder_service->disableAutoresponder();
622 $this->auto_responder_service->handleAutoresponderMails($this->user_id);
631 foreach ($to_usr_ids as $user_id) {
656 array $cc_bcc_recipients
658 $to_recipients = array_map(
665 array_merge($to_recipients, $cc_bcc_recipients),
679 $usrIdToExternalEmailAddressesMap = [];
681 foreach ($recipients as $recipient) {
682 if (!$recipient->isUser()) {
683 $this->
logger->critical(sprintf(
684 "Skipped recipient with id %s (User not found)",
685 $recipient->getUserId()
690 $can_read_internal = $recipient->evaluateInternalMailReadability();
691 if ($this->
isSystemMail() && !$can_read_internal->isOk()) {
692 $this->
logger->debug(sprintf(
693 'Skipped recipient with id %s and reason: %s',
694 $recipient->getUserId(),
695 is_string($can_read_internal->error()) ? $can_read_internal->error() : $can_read_internal->error()->getMessage()
700 if ($recipient->isUserActive()) {
701 if (!$can_read_internal->isOk() || $recipient->userWantsToReceiveExternalMails()) {
702 $emailAddresses = $recipient->getExternalMailAddress();
703 $usrIdToExternalEmailAddressesMap[$recipient->getUserId()] = $emailAddresses;
705 if ($recipient->onlyToExternalMailAddress()) {
706 $this->
logger->debug(sprintf(
707 "Recipient with id %s will only receive external emails sent to: %s",
708 $recipient->getUserId(),
709 implode(
', ', $emailAddresses)
714 $this->
logger->debug(sprintf(
715 "Recipient with id %s will additionally receive external emails " .
716 "(because the user wants to receive it externally, or the user cannot access " .
717 "the internal mail system) sent to: %s",
718 $recipient->getUserId(),
719 implode(
', ', $emailAddresses)
722 $this->
logger->debug(sprintf(
723 "Recipient with id %s is does not want to receive external emails",
724 $recipient->getUserId()
728 $this->
logger->debug(sprintf(
729 "Recipient with id %s is inactive and will not receive external emails",
730 $recipient->getUserId()
734 $mbox = clone $this->mailbox;
735 $mbox->setUsrId($recipient->getUserId());
736 $recipientInboxId = $mbox->getInboxFolder();
748 $recipient->getUserId()
753 $this->auto_responder_service->enqueueAutoresponderIfEnabled(
754 $recipient->getUserId(),
755 $recipient->getMailOptions(),
756 $mail_receiver_options,
760 $this->mail_file_data->assignAttachmentsToDirectory($internalMailId, $mail_data->
getInternalMailId());
768 $usrIdToExternalEmailAddressesMap
780 array $usrIdToExternalEmailAddressesMap
782 if (1 === count($usrIdToExternalEmailAddressesMap)) {
783 $usrIdToExternalEmailAddressesMap = array_values($usrIdToExternalEmailAddressesMap);
784 $firstAddresses = current($usrIdToExternalEmailAddressesMap);
787 implode(
',', $firstAddresses),
794 } elseif (count($usrIdToExternalEmailAddressesMap) > 1) {
796 $usrIdToExternalEmailAddressesMap
799 $flattenEmailAddresses = array_unique($flattenEmailAddresses);
802 $remainingAddresses =
'';
803 foreach ($flattenEmailAddresses as $emailAddress) {
805 if ($remainingAddresses !==
'') {
811 if ($recipientsLineLength >= $this->max_recipient_character_length) {
821 $remainingAddresses =
'';
825 $remainingAddresses .= ($sep . $emailAddress);
828 if (
'' !== $remainingAddresses) {
847 $parsed_usr_ids = [];
849 $joined_recipients = implode(
',', array_filter(array_map(
'trim', $recipients)));
852 foreach ($addresses as $address) {
853 $address_type = $this->mail_address_type_factory->getByPrefix($address);
854 $parsed_usr_ids[] = $address_type->resolve();
857 return array_unique(array_merge(...$parsed_usr_ids));
863 private function checkMail(
string $to,
string $cc,
string $bcc,
string $subject): array
868 $subject =>
'mail_add_subject',
869 $to =>
'mail_add_recipient',
871 foreach ($checks as $string => $error) {
872 if ($string ===
'') {
879 $errors[] =
new ilMailError(
'mail_subject_too_long');
895 foreach ($addresses as $address) {
896 $address_type = $this->mail_address_type_factory->getByPrefix($address);
897 if (!$address_type->validate($this->user_id)) {
898 $errors[] = $address_type->getErrors();
902 $colonPosition = strpos($e->getMessage(),
':');
904 ($colonPosition ===
false) ? $e->getMessage() : substr($e->getMessage(), $colonPosition + 2),
910 return array_merge(...$errors);
918 array $a_attachments,
924 bool $a_use_placeholders =
false,
925 ?
string $a_tpl_context_id = null,
926 ?array $a_tpl_ctx_params = []
929 $this->table_mail_saved,
931 'user_id' => [
'integer', $this->user_id],
934 'attachments' => [
'clob', serialize($a_attachments)],
935 'rcp_to' => [
'clob', $a_rcp_to],
936 'rcp_cc' => [
'clob', $a_rcp_cc],
937 'rcp_bcc' => [
'clob', $a_rcp_bcc],
938 'm_subject' => [
'text', $a_m_subject],
939 'm_message' => [
'clob', $a_m_message],
940 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
941 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
942 'tpl_ctx_params' => [
'blob', json_encode((array) $a_tpl_ctx_params, JSON_THROW_ON_ERROR)],
953 $res = $this->db->queryF(
954 "SELECT * FROM $this->table_mail_saved WHERE user_id = %s",
960 if (!is_array($this->mail_data)) {
961 $this->
persistToStage($this->user_id, [],
'',
'',
'',
'',
'',
false);
979 bool $a_use_placeholders =
false 984 $a_m_subject = $sanitizeMb4Encoding->transform($a_m_subject);
985 $a_m_message = $sanitizeMb4Encoding->transform($a_m_message);
988 "New mail system task:" .
989 " To: " . $a_rcp_to .
990 " | CC: " . $a_rcp_cc .
991 " | BCC: " . $a_rcp_bcc .
992 " | Subject: " . $a_m_subject .
993 " | Attachments: " . print_r($a_attachment,
true)
996 if ($a_attachment && !$this->mail_file_data->checkFilesExist($a_attachment)) {
997 return [
new ilMailError(
'mail_attachment_file_not_exist', [$a_attachment])];
1000 $errors = $this->
checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject);
1001 if ($errors !== []) {
1006 if ($errors !== []) {
1010 $rcp_to = $a_rcp_to;
1011 $rcp_cc = $a_rcp_cc;
1012 $rcp_bcc = $a_rcp_bcc;
1016 $numberOfExternalAddresses > 0 &&
1018 !$DIC->rbac()->system()->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id)
1020 return [
new ilMailError(
'mail_no_permissions_write_smtp')];
1024 $a_m_message .= self::_getInstallationSignature();
1037 return $this->
sendMail($mail_data);
1040 $taskFactory = $DIC->backgroundTasks()->taskFactory();
1041 $taskManager = $DIC->backgroundTasks()->taskManager();
1044 $bucket->setUserId($this->user_id);
1046 $task = $taskFactory->createTask(ilMailDeliveryJob::class, [
1053 serialize($a_attachment),
1054 $a_use_placeholders,
1056 (
string) $this->context_id,
1057 serialize(array_merge(
1058 $this->context_parameters,
1060 'auto_responder' => $this->auto_responder_service->isAutoresponderEnabled()
1064 $interaction = $taskFactory->createTask(ilMailDeliveryJobUserInteraction::class, [
1069 $bucket->setTask($interaction);
1070 $bucket->setTitle($this->
lng->txt(
'mail_bg_task_title'));
1071 $bucket->setDescription(sprintf($this->
lng->txt(
'mail_bg_task_desc'), $a_m_subject));
1073 $this->
logger->info(
'Delegated delivery to background task');
1074 $taskManager->run($bucket);
1092 $mail_data->
getTo(),
1093 $mail_data->
getCc(),
1100 if ($mail_data->getAttachments() !== []) {
1101 $this->mail_file_data->assignAttachmentsToDirectory($internalMessageId, $internalMessageId);
1102 $this->mail_file_data->saveFiles($internalMessageId, $mail_data->getAttachments());
1105 $numberOfExternalAddresses = $this->
getCountRecipients($mail_data->getTo(), $mail_data->getCc(), $mail_data->getBcc());
1107 if ($numberOfExternalAddresses > 0) {
1113 "Parsed external email addresses from given recipients /" .
1114 " To: " . $externalMailRecipientsTo .
1115 " | CC: " . $externalMailRecipientsCc .
1116 " | BCC: " . $externalMailRecipientsBcc .
1117 " | Subject: " . $mail_data->getSubject()
1121 $externalMailRecipientsTo,
1122 $externalMailRecipientsCc,
1123 $externalMailRecipientsBcc,
1124 $mail_data->getSubject(),
1125 $mail_data->isUsePlaceholder() ?
1127 $mail_data->getMessage(),
1128 $mail_data->getAttachments()
1131 $this->
logger->debug(
'No external email addresses given in recipient string');
1137 $errors[
'mail_send_error'] =
new ilMailError(
'mail_send_error');
1146 if ($random->int(0, 50) === 2) {
1149 $this->mail_file_data
1154 return array_values($errors);
1168 if ($errors !== []) {
1169 return array_merge([
new ilMailError(
'mail_following_rcp_not_valid')], $errors);
1172 return [
new ilMailError(
'mail_generic_rcp_error', [$e->getMessage()])];
1180 $send_folder_id = 0;
1182 $send_folder_id = $this->mailbox->getSentFolder();
1185 return $send_folder_id;
1225 $mailer->From($this->sender_factory->getSenderByUsrId($this->user_id));
1230 (
string) ($this->context_parameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ??
'')
1232 $mailer->Body($message);
1242 foreach ($attachments as $attachment) {
1244 $this->mail_file_data->getAbsoluteAttachmentPoolPathByFilename($attachment),
1260 $this->table_mail_saved,
1262 'attachments' => [
'clob', serialize($attachments)],
1265 'user_id' => [
'integer', $this->user_id],
1276 if ($addresses !==
'') {
1277 $this->
logger->debug(sprintf(
1278 "Started parsing of recipient string: %s",
1283 $parser = $this->mail_address_parser_factory->getParser($addresses);
1284 $parsedAddresses = $parser->parse();
1286 if ($addresses !==
'') {
1287 $this->
logger->debug(sprintf(
1288 "Parsed addresses: %s",
1289 implode(
',', array_map(
static function (
ilMailAddress $address):
string {
1290 return (
string) $address;
1291 }, $parsedAddresses))
1295 return $parsedAddresses;
1301 if ($onlyExternalAddresses) {
1305 $this->usr_id_by_login_callable
1309 return count($addresses->value());
1313 string $toRecipients,
1314 string $ccRecipients,
1315 string $bccRecipients,
1316 bool $onlyExternalAddresses =
true 1330 $this->usr_id_by_login_callable
1333 $emailRecipients = array_map(
static function (
ilMailAddress $address):
string {
1334 return (
string) $address;
1335 }, $addresses->value());
1337 return implode(
',', $emailRecipients);
1348 $lang->loadLanguageModule(
'mail');
1351 $lang->txt(
'mail_auto_generated_info'),
1360 $senderFactory = $DIC->mail()->mime()->senderFactory();
1362 return $senderFactory->system()->getFromName();
1371 if (null === $a_flag) {
1375 $this->append_installation_signature = $a_flag;
1383 $signature = $DIC->settings()->get(
'mail_system_sys_signature',
'');
1387 if (is_array($clientdirs) && count($clientdirs) > 1) {
1388 $clientUrl .=
'/login.php?client_id=' .
CLIENT_ID;
1392 'INSTALLATION_NAME' => $DIC[
'ilClientIniFile']->readVariable(
'client',
'name'),
1393 'INSTALLATION_DESC' => $DIC[
'ilClientIniFile']->readVariable(
'client',
'description'),
1394 'ILIAS_URL' => $clientUrl,
1397 $signature = $DIC->mail()->mustacheFactory()->getBasicEngine()->render($signature, $placeholders);
1399 if (!preg_match(
'/^[\n\r]+/', (
string) $signature)) {
1400 $signature =
"\n" . $signature;
1410 $lang = ($a_language instanceof
ilLanguage) ? $a_language : $DIC->language();
1411 $lang->loadLanguageModule(
'mail');
1414 $gender = $gender ?:
'n';
1417 if ($name[
'firstname'] ===
'') {
1418 return $lang->txt(
'mail_salutation_anonymous') .
',';
1422 $lang->txt(
'mail_salutation_' . $gender) .
' ' .
1423 ($name[
'title'] ? $name[
'title'] .
' ' :
'') .
1424 ($name[
'firstname'] ? $name[
'firstname'] .
' ' :
'') .
1425 $name[
'lastname'] .
',';
1430 if (!array_key_exists($usrId, $this->user_instances_by_id_map)) {
1437 $this->user_instances_by_id_map[$usrId] = $user;
1440 return $this->user_instances_by_id_map[$usrId];
1448 $this->user_instances_by_id_map = $userInstanceByIdMap;
1453 if (!isset($this->mail_options_by_usr_id_map[$usrId])) {
1454 $this->mail_options_by_usr_id_map[$usrId] =
new ilMailOptions($usrId);
1457 return $this->mail_options_by_usr_id_map[$usrId];
1465 $this->mail_options_by_usr_id_map = $mailOptionsByUsrIdMap;
1479 $this->legal_documents
setSaveInSentbox(bool $saveInSentbox)
formatLinebreakMessage(string $message)
sendMailWithReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids)
getEmailRecipients(string $recipients)
int $max_recipient_character_length
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=[])
__construct(private int $a_user_id, private ?ilMailAddressTypeFactory $mail_address_type_factory=null, private ?ilMailRfc822AddressParserFactory $mail_address_parser_factory=null, 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)
countMailsOfFolder(int $folderId)
static getLogger(string $a_component_id)
Get component logger.
const ILIAS_VERSION_NUMERIC
markUnread(array $mailIds)
This class handles all operations on files (attachments) in directory ilias_data/mail.
appendInstallationSignature(bool $a_flag=null)
checkMail(string $to, string $cc, string $bcc, string $subject)
existsRecipient(string $newRecipient, string $existingRecipients)
getCountRecipients(string $toRecipients, string $ccRecipients, string $bccRecipients, bool $onlyExternalAddresses=true)
getMailsOfFolder(int $a_folder_id, array $filter=[])
const PROP_CONTEXT_SUBJECT_PREFIX
sendMimeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)
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'.
getUserInstanceById(int $usrId)
static _lookupName(int $a_user_id)
lookup user name
static _lookupId($a_user_str)
static _getIliasMailerName()
Class ilMailOnlyExternalAddressList.
deleteMailsOfFolder(int $folderId)
static _lookupPref(int $a_usr_id, string $a_keyword)
array $mail_options_by_usr_id_map
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
getPreviousMail(int $mailId)
sendChanneledMails(MailDeliveryData $mail_data, array $recipients, string $message)
static _lookupGender(int $a_user_id)
Class ilMailDiffAddressList.
getCountRecipient(string $recipients, bool $onlyExternalAddresses=true)
bool $append_installation_signature
readonly Conductor $legal_documents
static getTemplateContextById(string $a_id)
withContextParameters(array $parameters)
array $user_instances_by_id_map
saveAttachments(array $attachments)
static strLen(string $a_string)
Class ilMailRfc822AddressParserFactory.
array $context_parameters
delegateExternalEmails(string $subject, array $attachments, string $message, array $usrIdToExternalEmailAddressesMap)
replacePlaceholdersEmpty(string $message)
fetchMailData(?array $row)
withContextId(string $contextId)
Mail Box class Base class for creating and handling mail boxes.
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
checkRecipients(string $recipients)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
distributeMail(MailDeliveryData $mail_data)
replacePlaceholders(string $message, int $usrId=0)
getMailOptionsByUserId(int $usrId)
setUserInstanceById(array $userInstanceByIdMap)
sendMailWithReplacedEmptyPlaceholder(MailDeliveryData $mail_data, array $recipients,)
static _getLanguage(string $a_lang_key='')
Get language object.
Class ilMailTemplatePlaceholderResolver.
getMailObjectReferenceId()
validateRecipients(string $to, string $cc, string $bcc)
getNewDraftId(int $folderId)
sendMail(MailDeliveryData $mail_data)
This method is used to finally send internal messages and external emails To use the mail system as a...
createRecipient(int $user_id)
sendMailWithoutReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids, array $cc_bcc_recipients)
formatNamesForOutput(string $recipients)
deleteMails(array $mailIds)
Wrapper for generation of random numbers, strings, bytes.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static getMailObjectRefId()
setMailOptionsByUserIdMap(array $mailOptionsByUsrIdMap)
withInternalMailId(int $internal_mail_id)
sendInternalMail(int $folderId, int $senderUsrId, array $attachments, string $to, string $cc, string $bcc, string $status, string $subject, string $message, int $usrId=0, bool $usePlaceholders=false, ?string $templateContextId=null, array $templateContextParameters=[])
getUserIds(array $recipients)
static getType()
Get context type.
parseAddresses(string $addresses)
Explode recipient string, allowed separators are ',' ';' ' '.
Class ilMailAddressTypeFactory.
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=[])
moveMailsToFolder(array $mailIds, int $folderId)
readMailObjectReferenceId()
static _getInstallationSignature()
Class ilMailAddressListImpl.