19declare(strict_types=1);
72 int $mailAdminNodeRefId =
null,
80 $this->db =
$db ??
$DIC->database();
81 $this->
lng = $lng ??
$DIC->language();
84 $this->mail_options = $mailOptions ??
new ilMailOptions($a_user_id);
85 $this->mailbox = $mailBox ??
new ilMailbox($a_user_id);
90 $this->user_id = $a_user_id;
91 $this->mail_obj_ref_id = $mailAdminNodeRefId;
92 if (
null === $this->mail_obj_ref_id) {
95 $this->
lng->loadLanguageModule(
'mail');
96 $this->table_mail =
'mail';
97 $this->table_mail_saved =
'mail_saved';
103 $clone = clone $this;
112 $clone = clone $this;
114 $clone->contextParameters = $parameters;
124 public function existsRecipient(
string $newRecipient,
string $existingRecipients): bool
131 $diffedAddresses = $list->value();
133 return count($diffedAddresses) === 0;
138 $this->save_in_sentbox = $saveInSentbox;
158 $recipients = trim($recipients);
159 if ($recipients ===
'') {
160 return $this->
lng->txt(
'not_available');
165 $recipients = array_filter(array_map(
'trim', explode(
',', $recipients)));
166 foreach ($recipients as $recipient) {
168 if (is_int($usrId) && $usrId > 0) {
170 if ($pp ===
'g' || ($pp ===
'y' && !$this->actor->isAnonymous())) {
173 $names[] = $user->getFullname() .
' [' . $recipient .
']';
179 $names[] = $recipient;
182 return implode(
', ', $names);
187 $this->db->setLimit(1, 0);
190 "SELECT b.* FROM $this->table_mail a",
191 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
192 'AND b.user_id = a.user_id AND b.send_time > a.send_time',
193 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
195 $res = $this->db->queryF(
197 [
'integer',
'integer'],
198 [$this->user_id, $mailId]
208 $this->db->setLimit(1, 0);
211 "SELECT b.* FROM $this->table_mail a",
212 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
213 'AND b.user_id = a.user_id AND b.send_time < a.send_time',
214 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
216 $res = $this->db->queryF(
218 [
'integer',
'integer'],
219 [$this->user_id, $mailId]
232 "SELECT sender_id, m_subject, mail_id, m_status, send_time, import_name " .
233 "FROM $this->table_mail " .
234 "LEFT JOIN object_data ON obj_id = sender_id " .
235 "WHERE user_id = %s AND folder_id = %s " .
236 "AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) " .
237 "OR (sender_id = 0 OR sender_id IS NULL))";
239 if (isset($filter[
'status']) && $filter[
'status'] !==
'') {
240 $query .=
' AND m_status = ' . $this->db->quote($filter[
'status'],
'text');
243 $query .=
" ORDER BY send_time DESC";
245 $res = $this->db->queryF(
247 [
'integer',
'integer'],
248 [$this->user_id, $a_folder_id]
251 while ($row = $this->db->fetchAssoc(
$res)) {
255 return array_filter($mails);
260 $res = $this->db->queryF(
261 "SELECT COUNT(*) FROM $this->table_mail WHERE user_id = %s AND folder_id = %s",
262 [
'integer',
'integer'],
263 [$this->user_id, $folderId]
266 return $this->db->numRows(
$res);
279 $res = $this->db->queryF(
280 "SELECT * FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
281 [
'integer',
'integer'],
282 [$this->user_id, $mailId]
298 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
299 array_push($types,
'text',
'integer');
300 array_push($values,
'read', $this->user_id);
302 if (count($mailIds) > 0) {
303 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
306 $this->db->manipulateF(
$query, $types, $values);
317 $query =
"UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
318 array_push($types,
'text',
'integer');
319 array_push($values,
'unread', $this->user_id);
321 if (count($mailIds) > 0) {
322 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
325 $this->db->manipulateF(
$query, $types, $values);
338 $mailIds = array_filter(array_map(
'intval', $mailIds));
340 if (0 === count($mailIds)) {
345 "UPDATE $this->table_mail " .
346 "INNER JOIN mail_obj_data " .
347 "ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s " .
348 "SET $this->table_mail.folder_id = mail_obj_data.obj_id " .
349 "WHERE $this->table_mail.user_id = %s";
350 array_push($types,
'integer',
'integer',
'integer');
351 array_push($values, $folderId, $this->user_id, $this->user_id);
353 $query .=
' AND ' . $this->db->in(
'mail_id', $mailIds,
false,
'integer');
355 $affectedRows = $this->db->manipulateF(
$query, $types, $values);
357 return $affectedRows > 0;
365 $mailIds = array_filter(array_map(
'intval', $mailIds));
366 foreach ($mailIds as
$id) {
367 $this->db->manipulateF(
368 "DELETE FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
369 [
'integer',
'integer'],
370 [$this->user_id,
$id]
372 $this->mfile->deassignAttachmentFromDirectory(
$id);
382 if (!is_array($row) || empty($row)) {
386 if (isset($row[
'attachments'])) {
387 $unserialized = unserialize(stripslashes($row[
'attachments']), [
'allowed_classes' =>
false]);
388 $row[
'attachments'] = is_array($unserialized) ? $unserialized : [];
390 $row[
'attachments'] = [];
393 if (isset($row[
'tpl_ctx_params']) && is_string($row[
'tpl_ctx_params'])) {
394 $decoded = json_decode($row[
'tpl_ctx_params'],
true, 512, JSON_THROW_ON_ERROR);
395 $row[
'tpl_ctx_params'] = (array) ($decoded ?? []);
397 $row[
'tpl_ctx_params'] = [];
400 if (isset($row[
'mail_id'])) {
401 $row[
'mail_id'] = (
int) $row[
'mail_id'];
404 if (isset($row[
'user_id'])) {
405 $row[
'user_id'] = (
int) $row[
'user_id'];
408 if (isset($row[
'folder_id'])) {
409 $row[
'folder_id'] = (
int) $row[
'folder_id'];
412 if (isset($row[
'sender_id'])) {
413 $row[
'sender_id'] = (
int) $row[
'sender_id'];
416 if (isset($row[
'use_placeholders'])) {
417 $row[
'use_placeholders'] = (bool) $row[
'use_placeholders'];
420 $null_to_string_properties = [
'm_subject',
'm_message',
'rcp_to',
'rcp_cc',
'rcp_bcc'];
421 foreach ($null_to_string_properties as $null_to_string_property) {
422 if (!isset($row[$null_to_string_property])) {
423 $row[$null_to_string_property] =
'';
432 $nextId = $this->db->nextId($this->table_mail);
433 $this->db->insert($this->table_mail, [
434 'mail_id' => [
'integer', $nextId],
435 'user_id' => [
'integer', $this->user_id],
436 'folder_id' => [
'integer', $folderId],
437 'sender_id' => [
'integer', $this->user_id],
459 array $a_attachments,
466 bool $a_use_placeholders =
false,
467 ?
string $a_tpl_context_id =
null,
468 array $a_tpl_context_params = []
473 'folder_id' => [
'integer', $a_folder_id],
474 'attachments' => [
'clob', serialize($a_attachments)],
475 'send_time' => [
'timestamp', date(
'Y-m-d H:i:s')],
476 'rcp_to' => [
'clob', $a_rcp_to],
477 'rcp_cc' => [
'clob', $a_rcp_cc],
478 'rcp_bcc' => [
'clob', $a_rcp_bcc],
479 'm_status' => [
'text',
'read'],
480 'm_subject' => [
'text', $a_m_subject],
481 'm_message' => [
'clob', $a_m_message],
482 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
483 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
484 'tpl_ctx_params' => [
'blob', json_encode($a_tpl_context_params, JSON_THROW_ON_ERROR)],
487 'mail_id' => [
'integer', $a_draft_id],
505 bool $usePlaceholders =
false,
506 ?
string $templateContextId =
null,
507 array $templateContextParameters = []
509 $usrId = $usrId ?: $this->user_id;
511 if ($usePlaceholders) {
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],
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) {
538 $current_folder_id = $this->getSubjectSentFolderId();
539 $is_sent_folder_of_sender = $folderId === $current_folder_id;
542 $raise_event = !$sender_equals_reveiver || !$is_sent_folder_of_sender;
545 $this->eventHandler->raise(
'Services/Mail',
'sentInternalMail', [
547 'subject' => $subject,
549 'from_usr_id' => $senderUsrId,
550 'to_usr_id' => $usrId,
563 bool $replaceEmptyPlaceholders =
true
566 if ($this->contextId) {
571 $user = $usrId > 0 ? $this->getUserInstanceById($usrId) : null;
574 $message = $processor->resolve($user, $this->contextParameters, $replaceEmptyPlaceholders);
575 }
catch (Exception
$e) {
576 $this->
logger->error(__METHOD__ .
' has been called with invalid context. ' .
$e->getMessage());
601 bool $usePlaceholders =
false
603 if ($usePlaceholders) {
604 $toUsrIds = $this->getUserIds([$to]);
605 $this->
logger->debug(sprintf(
606 "Parsed TO user ids from given recipients for serial letter notification: %s",
607 implode(
', ', $toUsrIds)
610 $this->sendChanneledMails(
622 $otherUsrIds = $this->getUserIds([$cc, $bcc]);
623 $this->
logger->debug(sprintf(
624 "Parsed CC/BCC user ids from given recipients for serial letter notification: %s",
625 implode(
', ', $otherUsrIds)
628 $this->sendChanneledMails(
634 $this->replacePlaceholders(
$message, 0,
false),
639 $usrIds = $this->getUserIds([$to, $cc, $bcc]);
640 $this->
logger->debug(sprintf(
641 "Parsed TO/CC/BCC user ids from given recipients: %s",
642 implode(
', ', $usrIds)
645 $this->sendChanneledMails(
680 bool $usePlaceholders =
false
682 $usrIdToExternalEmailAddressesMap = [];
683 $usrIdToMessageMap = [];
685 foreach ($usrIds as $usrId) {
686 $user = $this->getUserInstanceById($usrId);
688 $this->
logger->critical(sprintf(
689 "Skipped recipient with id %s (User not found)",
695 $mailOptions = $this->getMailOptionsByUserId($user->getId());
697 $canReadInternalMails = !$user->hasToAcceptTermsOfService() && $user->checkTimeLimit();
699 if ($this->isSystemMail() && !$canReadInternalMails) {
700 $this->
logger->debug(sprintf(
701 "Skipped recipient with id %s (Accepted User Agreement:%s|Expired Account:%s)",
703 var_export(!$user->hasToAcceptTermsOfService(),
true),
704 var_export(!$user->checkTimeLimit(),
true)
710 if ($usePlaceholders) {
711 $individualMessage = $this->replacePlaceholders(
$message, $user->getId());
712 $usrIdToMessageMap[$user->getId()] = $individualMessage;
715 if ($user->getActive()) {
716 $wantsToReceiveExternalEmail = (
721 if (!$canReadInternalMails || $wantsToReceiveExternalEmail) {
722 $emailAddresses = $mailOptions->getExternalEmailAddresses();
723 $usrIdToExternalEmailAddressesMap[$user->getId()] = $emailAddresses;
726 $this->
logger->debug(sprintf(
727 "Recipient with id %s will only receive external emails sent to: %s",
729 implode(
', ', $emailAddresses)
734 $this->
logger->debug(sprintf(
735 "Recipient with id %s will additionally receive external emails " .
736 "(because the user wants to receive it externally, or the user cannot access " .
737 "the internal mail system) sent to: %s",
739 implode(
', ', $emailAddresses)
742 $this->
logger->debug(sprintf(
743 "Recipient with id %s is does not want to receive external emails",
748 $this->
logger->debug(sprintf(
749 "Recipient with id %s is inactive and will not receive external emails",
754 $mbox = clone $this->mailbox;
755 $mbox->setUsrId($user->getId());
756 $recipientInboxId = $mbox->getInboxFolder();
758 $internalMailId = $this->sendInternalMail(
771 if (count($attachments) > 0) {
772 $this->mfile->assignAttachmentsToDirectory($internalMailId, $sentMailId);
776 $this->delegateExternalEmails(
781 $usrIdToExternalEmailAddressesMap,
798 bool $usePlaceholders,
799 array $usrIdToExternalEmailAddressesMap,
800 array $usrIdToMessageMap
802 if (1 === count($usrIdToExternalEmailAddressesMap)) {
803 if ($usePlaceholders) {
804 $message = array_values($usrIdToMessageMap)[0];
807 $usrIdToExternalEmailAddressesMap = array_values($usrIdToExternalEmailAddressesMap);
808 $firstAddresses = current($usrIdToExternalEmailAddressesMap);
811 implode(
',', $firstAddresses),
815 $this->formatLinebreakMessage(
$message),
818 } elseif (count($usrIdToExternalEmailAddressesMap) > 1) {
819 if ($usePlaceholders) {
820 foreach ($usrIdToExternalEmailAddressesMap as $usrId => $addresses) {
821 if (0 === count($addresses)) {
826 implode(
',', $addresses),
830 $this->formatLinebreakMessage($usrIdToMessageMap[$usrId]),
835 $flattenEmailAddresses = iterator_to_array(
new RecursiveIteratorIterator(
new RecursiveArrayIterator(
836 $usrIdToExternalEmailAddressesMap
839 $flattenEmailAddresses = array_unique($flattenEmailAddresses);
842 $remainingAddresses =
'';
843 foreach ($flattenEmailAddresses as $emailAddress) {
845 if ($remainingAddresses !==
'') {
851 if ($recipientsLineLength >= $this->maxRecipientCharacterLength) {
857 $this->formatLinebreakMessage(
$message),
861 $remainingAddresses =
'';
865 $remainingAddresses .= ($sep . $emailAddress);
868 if (
'' !== $remainingAddresses) {
874 $this->formatLinebreakMessage(
$message),
888 $parsed_usr_ids = [];
890 $joined_recipients = implode(
',', array_filter(array_map(
'trim', $recipients)));
892 $addresses = $this->parseAddresses($joined_recipients);
893 foreach ($addresses as $address) {
894 $address_type = $this->mailAddressTypeFactory->getByPrefix($address);
895 $parsed_usr_ids[] = $address_type->resolve();
898 return array_unique(array_merge(...$parsed_usr_ids));
908 protected function checkMail(
string $to,
string $cc,
string $bcc,
string $subject): array
913 $subject =>
'mail_add_subject',
914 $to =>
'mail_add_recipient',
916 foreach ($checks as $string => $error) {
917 if ($string ===
'') {
940 $addresses = $this->parseAddresses($recipients);
941 foreach ($addresses as $address) {
942 $address_type = $this->mailAddressTypeFactory->getByPrefix($address);
943 if (!$address_type->validate($this->user_id)) {
944 $errors[] = $address_type->getErrors();
948 $colonPosition = strpos(
$e->getMessage(),
':');
950 ($colonPosition ===
false) ?
952 substr(
$e->getMessage(), $colonPosition + 2)
956 return array_merge(...
$errors);
974 array $a_attachments,
980 bool $a_use_placeholders =
false,
981 ?
string $a_tpl_context_id =
null,
982 ?array $a_tpl_ctx_params = []
985 $this->table_mail_saved,
987 'user_id' => [
'integer', $this->user_id],
990 'attachments' => [
'clob', serialize($a_attachments)],
991 'rcp_to' => [
'clob', $a_rcp_to],
992 'rcp_cc' => [
'clob', $a_rcp_cc],
993 'rcp_bcc' => [
'clob', $a_rcp_bcc],
994 'm_subject' => [
'text', $a_m_subject],
995 'm_message' => [
'clob', $a_m_message],
996 'use_placeholders' => [
'integer', (
int) $a_use_placeholders],
997 'tpl_ctx_id' => [
'text', $a_tpl_context_id],
998 'tpl_ctx_params' => [
'blob', json_encode((array) $a_tpl_ctx_params, JSON_THROW_ON_ERROR)],
1002 $this->retrieveFromStage();
1009 $res = $this->db->queryF(
1010 "SELECT * FROM $this->table_mail_saved WHERE user_id = %s",
1015 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc(
$res));
1016 if (!is_array($this->mail_data)) {
1017 $this->persistToStage($this->user_id, [],
'',
'',
'',
'',
'',
false);
1020 return $this->mail_data;
1038 string $a_m_subject,
1039 string $a_m_message,
1040 array $a_attachment,
1041 bool $a_use_placeholders =
false
1046 "New mail system task:" .
1047 " To: " . $a_rcp_to .
1048 " | CC: " . $a_rcp_cc .
1049 " | BCC: " . $a_rcp_bcc .
1050 " | Subject: " . $a_m_subject .
1051 " | Attachments: " . print_r($a_attachment,
true)
1054 if ($a_attachment && !$this->mfile->checkFilesExist($a_attachment)) {
1055 return [
new ilMailError(
'mail_attachment_file_not_exist', [$a_attachment])];
1058 $errors = $this->checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject);
1063 $errors = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bcc);
1068 $rcp_to = $a_rcp_to;
1069 $rcp_cc = $a_rcp_cc;
1070 $rcp_bcc = $a_rcp_bcc;
1072 $numberOfExternalAddresses = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bcc);
1074 $numberOfExternalAddresses > 0 &&
1075 !$this->isSystemMail() &&
1076 !
$DIC->rbac()->system()->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id)
1078 return [
new ilMailError(
'mail_no_permissions_write_smtp')];
1081 if ($this->appendInstallationSignature()) {
1082 $a_m_message .= self::_getInstallationSignature();
1086 return $this->sendMail(
1097 $taskFactory =
$DIC->backgroundTasks()->taskFactory();
1098 $taskManager =
$DIC->backgroundTasks()->taskManager();
1101 $bucket->setUserId($this->user_id);
1103 $task = $taskFactory->createTask(ilMailDeliveryJob::class, [
1110 serialize($a_attachment),
1111 $a_use_placeholders,
1112 $this->getSaveInSentbox(),
1113 (
string) $this->contextId,
1114 serialize($this->contextParameters),
1116 $interaction = $taskFactory->createTask(ilMailDeliveryJobUserInteraction::class, [
1121 $bucket->setTask($interaction);
1122 $bucket->setTitle($this->
lng->txt(
'mail_bg_task_title'));
1123 $bucket->setDescription(sprintf($this->
lng->txt(
'mail_bg_task_desc'), $a_m_subject));
1125 $this->
logger->info(
'Delegated delivery to background task');
1126 $taskManager->run($bucket);
1152 bool $usePlaceholders
1154 $internalMessageId = $this->saveInSentbox(
1163 if (count($attachments) > 0) {
1164 $this->mfile->assignAttachmentsToDirectory($internalMessageId, $internalMessageId);
1165 $this->mfile->saveFiles($internalMessageId, $attachments);
1168 $numberOfExternalAddresses = $this->getCountRecipients($to, $cc, $bcc);
1170 if ($numberOfExternalAddresses > 0) {
1171 $externalMailRecipientsTo = $this->getEmailRecipients($to);
1172 $externalMailRecipientsCc = $this->getEmailRecipients($cc);
1173 $externalMailRecipientsBcc = $this->getEmailRecipients($bcc);
1176 "Parsed external email addresses from given recipients /" .
1177 " To: " . $externalMailRecipientsTo .
1178 " | CC: " . $externalMailRecipientsCc .
1179 " | BCC: " . $externalMailRecipientsBcc .
1180 " | Subject: " . $subject
1183 $this->sendMimeMail(
1184 $externalMailRecipientsTo,
1185 $externalMailRecipientsCc,
1186 $externalMailRecipientsBcc,
1188 $this->formatLinebreakMessage(
1190 $this->replacePlaceholders(
$message, 0,
false) :
1196 $this->
logger->debug(
'No external email addresses given in recipient string');
1201 if (!$this->distributeMail(
1214 if (!$this->getSaveInSentbox()) {
1215 $this->deleteMails([$internalMessageId]);
1218 if ($this->isSystemMail()) {
1220 if ($random->int(0, 50) === 2) {
1249 return [
new ilMailError(
'mail_generic_rcp_error', [
$e->getMessage()])];
1257 $send_folder_id = 0;
1258 if (!$this->isSystemMail()) {
1259 $send_folder_id = $this->mailbox->getSentFolder();
1262 return $send_folder_id;
1282 return $this->sendInternalMail(
1283 $this->getSubjectSentFolderId(),
1313 $mailer->
From($this->senderFactory->getSenderByUsrId($this->user_id));
1318 (
string) ($this->contextParameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ??
'')
1330 foreach ($attachments as $attachment) {
1332 $this->mfile->getAbsoluteAttachmentPoolPathByFilename($attachment),
1348 $this->table_mail_saved,
1350 'attachments' => [
'clob', serialize($attachments)],
1353 'user_id' => [
'integer', $this->user_id],
1365 if ($addresses !==
'') {
1366 $this->
logger->debug(sprintf(
1367 "Started parsing of recipient string: %s",
1372 $parser = $this->mailAddressParserFactory->getParser($addresses);
1373 $parsedAddresses = $parser->parse();
1375 if ($addresses !==
'') {
1376 $this->
logger->debug(sprintf(
1377 "Parsed addresses: %s",
1378 implode(
',', array_map(
static function (
ilMailAddress $address):
string {
1379 return (
string) $address;
1380 }, $parsedAddresses))
1384 return $parsedAddresses;
1390 if ($onlyExternalAddresses) {
1394 $this->usrIdByLoginCallable
1398 return count($addresses->value());
1402 string $toRecipients,
1403 string $ccRecipients,
1404 string $bccRecipients,
1405 bool $onlyExternalAddresses =
true
1408 $this->getCountRecipient($toRecipients, $onlyExternalAddresses) +
1409 $this->getCountRecipient($ccRecipients, $onlyExternalAddresses) +
1410 $this->getCountRecipient($bccRecipients, $onlyExternalAddresses)
1419 $this->usrIdByLoginCallable
1422 $emailRecipients = array_map(
static function (
ilMailAddress $address):
string {
1423 return (
string) $address;
1424 }, $addresses->value());
1426 return implode(
',', $emailRecipients);
1437 $lang->loadLanguageModule(
'mail');
1440 $lang->txt(
'mail_auto_generated_info'),
1446 public static function _getIliasMailerName(): string
1449 $senderFactory =
$GLOBALS[
"DIC"][
"mail.mime.sender.factory"];
1451 return $senderFactory->
system()->getFromName();
1460 if (
null === $a_flag) {
1461 return $this->appendInstallationSignature;
1464 $this->appendInstallationSignature = $a_flag;
1472 $signature =
$DIC->settings()->get(
'mail_system_sys_signature',
'');
1476 if (is_array($clientdirs) && count($clientdirs) > 1) {
1477 $clientUrl .=
'/login.php?client_id=' .
CLIENT_ID;
1480 $signature = str_ireplace(
1481 '[INSTALLATION_NAME]',
1485 $signature = str_ireplace(
1486 '[INSTALLATION_DESC]',
1490 $signature = str_ireplace(
'[ILIAS_URL]', $clientUrl, $signature);
1492 if (!preg_match(
'/^[\n\r]+/', $signature)) {
1493 $signature =
"\n" . $signature;
1504 $lang->loadLanguageModule(
'mail');
1507 $gender = $gender ?:
'n';
1510 if (
$name[
'firstname'] ===
'') {
1511 return $lang->txt(
'mail_salutation_anonymous') .
',';
1515 $lang->txt(
'mail_salutation_' . $gender) .
' ' .
1516 (
$name[
'title'] ?
$name[
'title'] .
' ' :
'') .
1517 (
$name[
'firstname'] ?
$name[
'firstname'] .
' ' :
'') .
1518 $name[
'lastname'] .
',';
1523 if (!array_key_exists($usrId, $this->userInstancesByIdMap)) {
1526 }
catch (Exception
$e) {
1530 $this->userInstancesByIdMap[$usrId] = $user;
1533 return $this->userInstancesByIdMap[$usrId];
1541 $this->userInstancesByIdMap = $userInstanceByIdMap;
1546 if (!isset($this->mailOptionsByUsrIdMap[$usrId])) {
1547 $this->mailOptionsByUsrIdMap[$usrId] =
new ilMailOptions($usrId);
1550 return $this->mailOptionsByUsrIdMap[$usrId];
1558 $this->mailOptionsByUsrIdMap = $mailOptionsByUsrIdMap;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
readVariable(string $a_group, string $a_var_name)
reads a single variable from a group
static getType()
Get context type.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class handles all operations on files (attachments) in directory ilias_data/mail.
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.
Class ilMailAddressListImpl.
Class ilMailAddressTypeFactory.
Class ilMailDiffAddressList.
static getMailObjectRefId()
Class ilMailMimeSenderFactory.
Class ilMailOnlyExternalAddressList.
Class ilMailOptions this class handles user mails.
Class ilMailRfc822AddressParserFactory.
static getTemplateContextById(string $a_id)
Class ilMailTemplatePlaceholderResolver.
bool $appendInstallationSignature
sendMimeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
withContextId(string $contextId)
withContextParameters(array $parameters)
ilMailRfc822AddressParserFactory $mailAddressParserFactory
deleteMailsOfFolder(int $folderId)
replacePlaceholders(string $message, int $usrId=0, bool $replaceEmptyPlaceholders=true)
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=[])
parseAddresses(string $addresses)
Explode recipient string, allowed separators are ',' ';' ' '.
array $userInstancesByIdMap
getUserIds(array $recipients)
distributeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
__construct(int $a_user_id, ilMailAddressTypeFactory $mailAddressTypeFactory=null, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null, ilAppEventHandler $eventHandler=null, ilLogger $logger=null, ilDBInterface $db=null, ilLanguage $lng=null, ilFileDataMail $mailFileData=null, ilMailOptions $mailOptions=null, ilMailbox $mailBox=null, ilMailMimeSenderFactory $senderFactory=null, callable $usrIdByLoginCallable=null, int $mailAdminNodeRefId=null, ilObjUser $actor=null)
ilMailOptions $mail_options
checkRecipients(string $recipients)
setUserInstanceById(array $userInstanceByIdMap)
moveMailsToFolder(array $mailIds, int $folderId)
deleteMails(array $mailIds)
saveAttachments(array $attachments)
formatNamesForOutput(string $recipients)
sendChanneledMails(string $to, string $cc, string $bcc, array $usrIds, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
setSaveInSentbox(bool $saveInSentbox)
ilAppEventHandler $eventHandler
delegateExternalEmails(string $subject, string $message, array $attachments, bool $usePlaceholders, array $usrIdToExternalEmailAddressesMap, array $usrIdToMessageMap)
getNewDraftId(int $folderId)
getPreviousMail(int $mailId)
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)
setMailOptionsByUserIdMap(array $mailOptionsByUsrIdMap)
getCountRecipient(string $recipients, bool $onlyExternalAddresses=true)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getInstallationSignature()
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
appendInstallationSignature(bool $a_flag=null)
getCountRecipients(string $toRecipients, string $ccRecipients, string $bccRecipients, bool $onlyExternalAddresses=true)
formatLinebreakMessage(string $message)
getUserInstanceById(int $usrId)
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=[])
getMailsOfFolder(int $a_folder_id, array $filter=[])
getEmailRecipients(string $recipients)
checkMail(string $to, string $cc, string $bcc, string $subject)
existsRecipient(string $newRecipient, string $existingRecipients)
array $mailOptionsByUsrIdMap
sendMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, bool $usePlaceholders)
This method is used to finally send internal messages and external emails To use the mail system as a...
getMailOptionsByUserId(int $usrId)
getMailObjectReferenceId()
readMailObjectReferenceId()
ilMailAddressTypeFactory $mailAddressTypeFactory
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'.
fetchMailData(?array $row)
countMailsOfFolder(int $folderId)
const PROP_CONTEXT_SUBJECT_PREFIX
ilMailMimeSenderFactory $senderFactory
markUnread(array $mailIds)
int $maxRecipientCharacterLength
Mail Box class Base class for creating and handling mail boxes.
From(ilMailMimeSender $sender)
static _lookupId($a_user_str)
static _lookupName(int $a_user_id)
lookup user name
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupGender(int $a_user_id)
Wrapper for generation of random numbers, strings, bytes.
static strLen(string $a_string)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
const ILIAS_VERSION_NUMERIC