ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilMail Class Reference
+ Inheritance diagram for ilMail:
+ Collaboration diagram for ilMail:

Public Member Functions

 __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,)
 
 autoresponder ()
 
 withContextId (string $context_id)
 
 withContextParameters (array $parameters)
 
 existsRecipient (string $new_recipient, string $existing_recipients)
 
 setSaveInSentbox (bool $save_in_sentbox)
 
 getSaveInSentbox ()
 
 getMailObjectReferenceId ()
 
 formatNamesForOutput (string $recipients)
 
 getPreviousMail (int $mail_id)
 
 getNextMail (int $mail_id)
 
 getMailsOfFolder (int $a_folder_id, array $filter=[])
 
 countMailsOfFolder (int $folder_id)
 
 deleteMailsOfFolder (int $folder_id)
 
 getMail (int $mail_id)
 
 markRead (array $mail_ids)
 
 markUnread (array $mail_ids)
 
 moveMailsToFolder (array $mail_ids, int $folder_id)
 
 deleteMails (array $mail_ids)
 
 fetchMailData (?array $row)
 
 getNewDraftId (int $folder_id)
 
 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, ?DateTimeImmutable $schedule_time=null, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, array $a_tpl_context_params=[])
 
 scheduledMail (int $folder_id, int $sender_usr_id, MailScheduleData $mail_data, ?string $template_context_id=null, array $template_context_parameters=[])
 
 persistToStage (int $a_user_id, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, ?\ILIAS\ResourceStorage\Identification\ResourceCollectionIdentification $a_attachments=null, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, ?array $a_tpl_ctx_params=[])
 
 retrieveFromStage ()
 
 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'. More...
 
 sendMail (MailDeliveryData $mail_data)
 This method is used to finally send internal messages and external emails To use the mail system as a consumer, please use ilMail::enqueue. More...
 
 validateRecipients (string $to, string $cc, string $bcc)
 
 saveAttachments (?ResourceCollectionIdentification $attachments)
 
 appendInstallationSignature (?bool $a_flag=null)
 
 setUserInstanceById (array $user_instances_by_id_map)
 
 setMailOptionsByUserIdMap (array $mail_options_by_usr_id_map)
 

Static Public Member Functions

static _getAutoGeneratedMessageString (?ilLanguage $lang=null)
 
static _getIliasMailerName ()
 
static _getInstallationSignature ()
 
static getSalutation (int $a_usr_id, ?ilLanguage $a_language=null)
 

Data Fields

const string ILIAS_HOST = 'ilias'
 
const string PROP_CONTEXT_SUBJECT_PREFIX = 'subject_prefix'
 
int $user_id
 

Protected Attributes

array $mail_data = []
 

Private Member Functions

 isSystemMail ()
 
 readMailObjectReferenceId ()
 
 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=[])
 
 replacePlaceholders (string $message, int $usr_id=0)
 
 replacePlaceholdersEmpty (string $message)
 
 distributeMail (MailDeliveryData $mail_data)
 
 sendMailWithReplacedPlaceholder (MailDeliveryData $mail_data, array $to_usr_ids)
 
 sendMailWithReplacedEmptyPlaceholder (MailDeliveryData $mail_data, array $recipients,)
 
 sendMailWithoutReplacedPlaceholder (MailDeliveryData $mail_data, array $to_usr_ids, array $cc_bcc_recipients)
 
 sendChanneledMails (MailDeliveryData $mail_data, array $recipients, string $message)
 
 delegateExternalEmails (string $subject, array $attachments, string $message, array $usr_id_to_external_email_addresses_map)
 
 getUserIds (array $recipients)
 
 checkMail (string $to, string $cc, string $bcc, string $subject)
 
 checkRecipients (string $recipients)
 
 getSubjectSentFolderId ()
 
 saveInSentbox (array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
 
 sendMimeMail (string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)
 
 parseAddresses (string $addresses)
 Explode recipient string, allowed separators are ',' ';' ' '. More...
 
 getCountRecipient (string $recipients, bool $only_external_addresses=true)
 
 getCountRecipients (string $to_recipients, string $cc_recipients, string $bcc_recipients, bool $only_external_addresses=true)
 
 getEmailRecipients (string $recipients)
 
 getUserInstanceById (int $usr_id)
 
 getMailOptionsByUserId (int $usr_id)
 
 createRecipient (int $user_id)
 

Private Attributes

MailSignatureService $signature_service
 
string $table_mail
 
string $table_mail_saved
 
bool $save_in_sentbox
 
bool $append_installation_signature = false
 
bool $append_user_signature = false
 
string $context_id = null
 
array $context_parameters = []
 
array $mail_options_by_usr_id_map = []
 
array $user_instances_by_id_map = []
 
int $max_recipient_character_length = 998
 
readonly Conductor $legal_documents
 
readonly ILIAS Refinery Factory $refinery
 

Detailed Description

Definition at line 30 of file class.ilMail.php.

Constructor & Destructor Documentation

◆ __construct()

ilMail::__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 
)

Definition at line 59 of file class.ilMail.php.

80 {
81 global $DIC;
82 $this->logger = $logger ?? ilLoggerFactory::getLogger('mail');
83 $this->mail_address_type_factory = $mail_address_type_factory ?? new ilMailAddressTypeFactory(null, $logger);
84 $this->mail_address_parser_factory = $this->mail_address_parser_factory ?? new ilMailRfc822AddressParserFactory();
85 $this->event_handler = $event_handler ?? $DIC->event();
86 $this->db = $db ?? $DIC->database();
87 $this->lng = $lng ?? $DIC->language();
88 $this->actor = $actor ?? $DIC->user();
89 $this->mail_file_data = $mail_file_data ?? new ilFileDataMail($a_user_id);
90 $this->mail_options = $mail_options ?? new ilMailOptions($a_user_id);
91 $this->mailbox = $mailbox ?? new ilMailbox($a_user_id);
92
93 $this->sender_factory = $sender_factory ?? $DIC->mail()->mime()->senderFactory();
94 $this->usr_id_by_login_callable = $usr_id_by_login_callable ?? (static fn(string $login): int => (int) ilObjUser::_lookupId($login));
95 $this->auto_responder_service = $auto_responder_service ?? $DIC->mail()->autoresponder();
96 $this->user_id = $a_user_id;
97 if ($this->mail_obj_ref_id === null) {
99 }
100 $this->lng->loadLanguageModule('mail');
101 $this->table_mail = 'mail';
102 $this->table_mail_saved = 'mail_saved';
103 $this->setSaveInSentbox(false);
104 $this->placeholder_resolver = $placeholder_resolver ?? $DIC->mail()->placeholderResolver();
105 $this->placeholder_to_empty_resolver = $placeholder_to_empty_resolver ?? $DIC->mail()->placeholderToEmptyResolver();
106 $this->legal_documents = $legal_documents ?? $DIC['legalDocuments'];
107 $this->signature_service = $signature_service ?? $DIC->mail()->signature();
108 $this->refinery = $DIC->refinery();
109 }
static getLogger(string $a_component_id)
Get component logger.
readonly Conductor $legal_documents
readMailObjectReferenceId()
setSaveInSentbox(bool $save_in_sentbox)
MailSignatureService $signature_service
User class.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26

References $DIC, $legal_documents, $lng, $signature_service, ilObjUser\_lookupId(), ilLoggerFactory\getLogger(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), readMailObjectReferenceId(), ILIAS\Repository\refinery(), and setSaveInSentbox().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getAutoGeneratedMessageString()

static ilMail::_getAutoGeneratedMessageString ( ?ilLanguage  $lang = null)
static

Definition at line 1415 of file class.ilMail.php.

1415 : string
1416 {
1417 global $DIC;
1418
1419 if (!($lang instanceof ilLanguage)) {
1421 }
1422
1423 $lang->loadLanguageModule('mail');
1424
1425 return sprintf(
1426 $lang->txt('mail_auto_generated_info'),
1427 $DIC->settings()->get('inst_name', 'ILIAS ' . ((int) ILIAS_VERSION_NUMERIC)),
1429 ) . "\n\n";
1430 }
static _getLanguage(string $a_lang_key='')
Get language object.
language handling
static _getHttpPath()
const ILIAS_VERSION_NUMERIC

References $DIC, ilUtil\_getHttpPath(), ilLanguageFactory\_getLanguage(), and ILIAS_VERSION_NUMERIC.

Referenced by ilUserCronCheckAccounts\run(), ilMailSummaryNotification\send(), ilRemoteObjectBase\sendNewContentNotification(), ilECSObjectSettings\sendNewContentNotification(), and ilECSAppEventListener\sendNotification().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getIliasMailerName()

static ilMail::_getIliasMailerName ( )
static

Definition at line 1432 of file class.ilMail.php.

1432 : string
1433 {
1434 global $DIC;
1435 $sender_factory = $DIC->mail()->mime()->senderFactory();
1436
1437 return $sender_factory->system()->getFromName();
1438 }

References $DIC.

Referenced by ilPDMailBlockGUI\getListItemForData(), ILIAS\Mail\Folder\MailFolderTableUI\getSender(), ilMailFolderGUI\printMail(), ilMailSummaryNotification\send(), and ilMailTest\testGetIliasMailerName().

+ Here is the caller graph for this function:

◆ _getInstallationSignature()

◆ appendInstallationSignature()

ilMail::appendInstallationSignature ( ?bool  $a_flag = null)
Returns
self|bool

Definition at line 1443 of file class.ilMail.php.

1444 {
1445 if ($a_flag === null) {
1447 }
1448
1449 $this->append_installation_signature = $a_flag;
1450 return $this;
1451 }
bool $append_installation_signature

◆ autoresponder()

ilMail::autoresponder ( )

Definition at line 111 of file class.ilMail.php.

112 {
113 return $this->auto_responder_service;
114 }

◆ checkMail()

ilMail::checkMail ( string  $to,
string  $cc,
string  $bcc,
string  $subject 
)
private
Returns
list<ilMailError>

Definition at line 927 of file class.ilMail.php.

927 : array
928 {
929 $errors = [];
930
931 $checks = [
932 $subject => 'mail_add_subject',
933 $to => 'mail_add_recipient',
934 ];
935 foreach ($checks as $string => $error) {
936 if ($string === '') {
937 $errors[] = new ilMailError($error);
938 }
939 }
940
941 if (ilStr::strLen($subject) > 255) {
942 // https://mantis.ilias.de/view.php?id=37881
943 $errors[] = new ilMailError('mail_subject_too_long');
944 }
945
946 return $errors;
947 }
static strLen(string $a_string)
Definition: class.ilStr.php:60

References ilStr\strLen().

+ Here is the call graph for this function:

◆ checkRecipients()

ilMail::checkRecipients ( string  $recipients)
private
Returns
list<ilMailError>

Definition at line 952 of file class.ilMail.php.

952 : array
953 {
954 $errors = [];
955
956 try {
957 $addresses = $this->parseAddresses($recipients);
958 foreach ($addresses as $address) {
959 $address_type = $this->mail_address_type_factory->getByPrefix($address);
960 if (!$address_type->validate($this->user_id)) {
961 $errors[] = $address_type->getErrors();
962 }
963 }
964 } catch (Exception $e) {
965 $position = strpos($e->getMessage(), ':');
966 throw new ilMailException(
967 ($position === false) ? $e->getMessage() : substr($e->getMessage(), $position + 2),
968 $e->getCode(),
969 $e
970 );
971 }
972
973 return array_merge(...$errors);
974 }
parseAddresses(string $addresses)
Explode recipient string, allowed separators are ',' ';' ' '.

References Vendor\Package\$e.

◆ countMailsOfFolder()

ilMail::countMailsOfFolder ( int  $folder_id)

Definition at line 272 of file class.ilMail.php.

272 : int
273 {
274 $res = $this->db->queryF(
275 "SELECT COUNT(*) FROM $this->table_mail WHERE user_id = %s AND folder_id = %s",
276 ['integer', 'integer'],
277 [$this->user_id, $folder_id]
278 );
279
280 return $this->db->numRows($res);
281 }
$res
Definition: ltiservices.php:69

References $res.

◆ createRecipient()

ilMail::createRecipient ( int  $user_id)
private

Definition at line 1521 of file class.ilMail.php.

1521 : Recipient
1522 {
1523 return new Recipient(
1524 $user_id,
1527 $this->legal_documents
1528 );
1529 }
getUserInstanceById(int $usr_id)
int $user_id
getMailOptionsByUserId(int $usr_id)

References $user_id.

◆ delegateExternalEmails()

ilMail::delegateExternalEmails ( string  $subject,
array  $attachments,
string  $message,
array  $usr_id_to_external_email_addresses_map 
)
private
Parameters
list<string>$attachments
array<int,string[]>$usr_id_to_external_email_addresses_map

Definition at line 840 of file class.ilMail.php.

845 : void {
846 if (count($usr_id_to_external_email_addresses_map) === 1) {
847 $usr_id_to_external_email_addresses_map = array_values($usr_id_to_external_email_addresses_map);
848 $first_addresses = current($usr_id_to_external_email_addresses_map);
849
850 $this->sendMimeMail(
851 implode(',', $first_addresses),
852 '',
853 '',
854 $subject,
855 $message,
856 $attachments
857 );
858 } elseif (count($usr_id_to_external_email_addresses_map) > 1) {
859 $flattened_email_addresses = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator(
860 $usr_id_to_external_email_addresses_map
861 )), false);
862
863 $flattened_email_addresses = array_unique($flattened_email_addresses);
864
865 // https://mantis.ilias.de/view.php?id=23981 and https://www.ietf.org/rfc/rfc2822.txt
866 $remaining_addresses = '';
867 foreach ($flattened_email_addresses as $email_address) {
868 $sep = '';
869 if ($remaining_addresses !== '') {
870 $sep = ',';
871 }
872
873 $recipients_line_length = ilStr::strLen($remaining_addresses) +
874 ilStr::strLen($sep . $email_address);
875 if ($recipients_line_length >= $this->max_recipient_character_length) {
876 $this->sendMimeMail(
877 '',
878 '',
879 $remaining_addresses,
880 $subject,
881 $message,
882 $attachments
883 );
884
885 $remaining_addresses = '';
886 $sep = '';
887 }
888
889 $remaining_addresses .= ($sep . $email_address);
890 }
891
892 if ($remaining_addresses !== '') {
893 $this->sendMimeMail(
894 '',
895 '',
896 $remaining_addresses,
897 $subject,
898 $message,
899 $attachments
900 );
901 }
902 }
903 }
sendMimeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)

◆ deleteMails()

ilMail::deleteMails ( array  $mail_ids)
Parameters
list<int>$mailIds

Definition at line 383 of file class.ilMail.php.

383 : void
384 {
385 $mail_ids = array_filter(array_map('intval', $mail_ids));
386 foreach ($mail_ids as $id) {
387 $this->db->manipulateF(
388 "DELETE FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
389 ['integer', 'integer'],
390 [$this->user_id, $id]
391 );
392 $this->mail_file_data->deassignAttachmentFromDirectory($id);
393 }
394 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

Referenced by deleteMailsOfFolder().

+ Here is the caller graph for this function:

◆ deleteMailsOfFolder()

ilMail::deleteMailsOfFolder ( int  $folder_id)

Definition at line 283 of file class.ilMail.php.

283 : void
284 {
285 $mails = $this->getMailsOfFolder($folder_id);
286 foreach ($mails as $mail_data) {
287 $this->deleteMails([$mail_data['mail_id']]);
288 }
289 }
deleteMails(array $mail_ids)
array $mail_data
getMailsOfFolder(int $a_folder_id, array $filter=[])

References $mail_data, deleteMails(), and getMailsOfFolder().

+ Here is the call graph for this function:

◆ distributeMail()

ilMail::distributeMail ( MailDeliveryData  $mail_data)
private

Definition at line 652 of file class.ilMail.php.

652 : bool
653 {
654 $this->auto_responder_service->emptyAutoresponderData();
655 $to_usr_ids = $this->getUserIds([$mail_data->getTo()]);
656 $this->logger->debug(sprintf(
657 'Parsed TO user ids from given recipients for serial letter notification: %s',
658 implode(', ', $to_usr_ids)
659 ));
660
661 $other_usr_ids = $this->getUserIds([$mail_data->getCc(), $mail_data->getBcc()]);
662 $cc_bcc_recipients = array_map(
663 $this->createRecipient(...),
664 $other_usr_ids
665 );
666 $this->logger->debug(sprintf(
667 'Parsed CC/BCC user ids from given recipients for serial letter notification: %s',
668 implode(', ', $other_usr_ids)
669 ));
670
671 if ($mail_data->isUsePlaceholder()) {
672 $this->sendMailWithReplacedPlaceholder($mail_data, $to_usr_ids);
673 $this->sendMailWithReplacedEmptyPlaceholder($mail_data, $cc_bcc_recipients);
674 } else {
675 $this->sendMailWithoutReplacedPlaceholder($mail_data, $to_usr_ids, $cc_bcc_recipients);
676 }
677
678 $this->auto_responder_service->disableAutoresponder();
679 $this->auto_responder_service->handleAutoresponderMails($this->user_id);
680
681 return true;
682 }
sendMailWithoutReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids, array $cc_bcc_recipients)
getUserIds(array $recipients)
sendMailWithReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids)
sendMailWithReplacedEmptyPlaceholder(MailDeliveryData $mail_data, array $recipients,)
createRecipient(int $user_id)

References MailDeliveryData\getBcc(), MailDeliveryData\getCc(), MailDeliveryData\getTo(), MailDeliveryData\isUsePlaceholder(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ enqueue()

ilMail::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'.

A validation is executed before, errors are returned

Parameters
list<string>$a_attachment
Returns
list<ilMailError>

Definition at line 1038 of file class.ilMail.php.

1046 : array {
1047 global $DIC;
1048
1049 $sanitizer = new Utf8Mb4Sanitizer();
1050 $a_m_subject = $sanitizer->transform($a_m_subject);
1051 $a_m_message = $sanitizer->transform($a_m_message);
1052
1053 $this->logger->info(
1054 'New mail system task:' .
1055 ' To: ' . $a_rcp_to .
1056 ' | CC: ' . $a_rcp_cc .
1057 ' | BCC: ' . $a_rcp_bcc .
1058 ' | Subject: ' . $a_m_subject .
1059 ' | Attachments: ' . print_r($a_attachment, true)
1060 );
1061
1062 if ($a_attachment && !$this->mail_file_data->checkFilesExist($a_attachment)) {
1063 return [new ilMailError('mail_attachment_file_not_exist', [implode(', ', $a_attachment)])];
1064 }
1065
1066 $errors = $this->checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject);
1067 if ($errors !== []) {
1068 return $errors;
1069 }
1070
1071 $errors = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bcc);
1072 if ($errors !== []) {
1073 return $errors;
1074 }
1075
1076 $rcp_to = $a_rcp_to;
1077 $rcp_cc = $a_rcp_cc;
1078 $rcp_bcc = $a_rcp_bcc;
1079
1080 $number_of_external_addresses = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bcc);
1081 if (
1082 $number_of_external_addresses > 0 &&
1083 !$this->isSystemMail() &&
1084 !$DIC->rbac()->system()->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id)
1085 ) {
1086 return [new ilMailError('mail_no_permissions_write_smtp')];
1087 }
1088
1089 if ($this->appendInstallationSignature()) {
1090 $a_m_message .= self::_getInstallationSignature();
1091 }
1092
1095 $rcp_to,
1096 $rcp_cc,
1097 $rcp_bcc,
1098 $a_m_subject,
1099 $a_m_message,
1100 $a_attachment,
1101 $a_use_placeholders
1102 );
1103 return $this->sendMail($mail_data);
1104 }
1105
1106 $task_factory = $DIC->backgroundTasks()->taskFactory();
1107 $task_manager = $DIC->backgroundTasks()->taskManager();
1108
1109 $bucket = new BasicBucket();
1110 $bucket->setUserId($this->user_id);
1111
1112 $task = $task_factory->createTask(ilMailDeliveryJob::class, [
1113 $this->user_id,
1114 $rcp_to,
1115 $rcp_cc,
1116 $rcp_bcc,
1117 $a_m_subject,
1118 $a_m_message,
1119 serialize($a_attachment),
1120 $a_use_placeholders,
1121 $this->getSaveInSentbox(),
1122 (string) $this->context_id,
1123 serialize(array_merge(
1124 $this->context_parameters,
1125 [
1126 'auto_responder' => $this->auto_responder_service->isAutoresponderEnabled()
1127 ]
1128 ))
1129 ]);
1130 $interaction = $task_factory->createTask(ilMailDeliveryJobUserInteraction::class, [
1131 $task,
1132 $this->user_id,
1133 ]);
1134
1135 $bucket->setTask($interaction);
1136 $bucket->setTitle($this->lng->txt('mail_bg_task_title'));
1137 $bucket->setDescription(sprintf($this->lng->txt('mail_bg_task_desc'), $a_m_subject));
1138
1139 $this->logger->info('Delegated delivery to background task');
1140 $task_manager->run($bucket);
1141
1142 return [];
1143 }
const CONTEXT_CRON
Definition: ilContext.php:31
static getType()
Get context type.
Definition: ilContext.php:165
isSystemMail()
getCountRecipients(string $to_recipients, string $cc_recipients, string $bcc_recipients, bool $only_external_addresses=true)
appendInstallationSignature(?bool $a_flag=null)
validateRecipients(string $to, string $cc, string $bcc)
static _getInstallationSignature()
checkMail(string $to, string $cc, string $bcc, string $subject)
getSaveInSentbox()
sendMail(MailDeliveryData $mail_data)
This method is used to finally send internal messages and external emails To use the mail system as a...

◆ existsRecipient()

ilMail::existsRecipient ( string  $new_recipient,
string  $existing_recipients 
)

Definition at line 139 of file class.ilMail.php.

139 : bool
140 {
141 $new_addresses = new ilMailAddressListImpl($this->parseAddresses($new_recipient));
142 $addresses = new ilMailAddressListImpl($this->parseAddresses($existing_recipients));
143 $list = new ilMailDiffAddressList($new_addresses, $addresses);
144
145 $diffed_addresses = $list->value();
146
147 return $diffed_addresses === [];
148 }

References parseAddresses().

+ Here is the call graph for this function:

◆ fetchMailData()

ilMail::fetchMailData ( ?array  $row)

Definition at line 396 of file class.ilMail.php.

396 : ?array
397 {
398 if (!is_array($row) || empty($row)) {
399 return null;
400 }
401
402 if (isset($row['attachments']) && is_string($row['attachments']) && str_contains($row['attachments'], '{')) {
403 $unserialized_attachments = unserialize($row['attachments'], ['allowed_classes' => false]);
404 $row['attachments'] = is_array($unserialized_attachments) ? $unserialized_attachments : null;
405 } elseif (isset($row['attachments']) && is_string($row['attachments']) && $row['attachments'] !== '') {
406 $row['attachments'] = new ResourceCollectionIdentification($row['attachments']);
407 } else {
408 $row['attachments'] = null;
409 }
410
411 if (isset($row['tpl_ctx_params']) && is_string($row['tpl_ctx_params'])) {
412 $decoded = json_decode($row['tpl_ctx_params'], true, 512, JSON_THROW_ON_ERROR);
413 $row['tpl_ctx_params'] = (array) ($decoded ?? []);
414 } else {
415 $row['tpl_ctx_params'] = [];
416 }
417
418 if (isset($row['mail_id'])) {
419 $row['mail_id'] = (int) $row['mail_id'];
420 }
421
422 if (isset($row['user_id'])) {
423 $row['user_id'] = (int) $row['user_id'];
424 }
425
426 if (isset($row['folder_id'])) {
427 $row['folder_id'] = (int) $row['folder_id'];
428 }
429
430 if (isset($row['sender_id'])) {
431 $row['sender_id'] = (int) $row['sender_id'];
432 }
433
434 if (isset($row['use_placeholders'])) {
435 $row['use_placeholders'] = (bool) $row['use_placeholders'];
436 }
437
438 $null_to_string_properties = ['m_subject', 'm_message', 'rcp_to', 'rcp_cc', 'rcp_bcc'];
439 foreach ($null_to_string_properties as $null_to_string_property) {
440 if (!isset($row[$null_to_string_property])) {
441 $row[$null_to_string_property] = '';
442 }
443 }
444
445 return $row;
446 }

References ILIAS\Repository\int().

Referenced by getMail(), getMailsOfFolder(), getNextMail(), and getPreviousMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatNamesForOutput()

ilMail::formatNamesForOutput ( string  $recipients)

Definition at line 170 of file class.ilMail.php.

170 : string
171 {
172 $recipients = trim($recipients);
173 if ($recipients === '') {
174 return $this->lng->txt('not_available');
175 }
176
177 $names = [];
178
179 $recipients = array_filter(array_map('trim', explode(',', $recipients)));
180 foreach ($recipients as $recipient) {
181 $usr_id = ilObjUser::_lookupId($recipient);
182 if (is_int($usr_id) && $usr_id > 0) {
183 $pp = ilObjUser::_lookupPref($usr_id, 'public_profile');
184 if ($pp === 'g' || ($pp === 'y' && !$this->actor->isAnonymous())) {
185 $user = $this->getUserInstanceById($usr_id);
186 if ($user) {
187 $names[] = $user->getFullname() . ' [' . $recipient . ']';
188 continue;
189 }
190 }
191 }
192
193 $names[] = $recipient;
194 }
195
196 return implode(', ', $names);
197 }
static _lookupId(string|array $a_user_str)
static _lookupPref(int $a_usr_id, string $a_keyword)

References ilObjUser\_lookupId(), ilObjUser\_lookupPref(), getUserInstanceById(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getCountRecipient()

ilMail::getCountRecipient ( string  $recipients,
bool  $only_external_addresses = true 
)
private

Definition at line 1375 of file class.ilMail.php.

1375 : int
1376 {
1377 $addresses = new ilMailAddressListImpl($this->parseAddresses($recipients));
1378 if ($only_external_addresses) {
1379 $addresses = new ilMailOnlyExternalAddressList(
1380 $addresses,
1381 self::ILIAS_HOST,
1382 $this->usr_id_by_login_callable
1383 );
1384 }
1385
1386 return count($addresses->value());
1387 }

◆ getCountRecipients()

ilMail::getCountRecipients ( string  $to_recipients,
string  $cc_recipients,
string  $bcc_recipients,
bool  $only_external_addresses = true 
)
private

Definition at line 1389 of file class.ilMail.php.

1394 : int {
1395 return (
1396 $this->getCountRecipient($to_recipients, $only_external_addresses) +
1397 $this->getCountRecipient($cc_recipients, $only_external_addresses) +
1398 $this->getCountRecipient($bcc_recipients, $only_external_addresses)
1399 );
1400 }
getCountRecipient(string $recipients, bool $only_external_addresses=true)

◆ getEmailRecipients()

ilMail::getEmailRecipients ( string  $recipients)
private

Definition at line 1402 of file class.ilMail.php.

1402 : string
1403 {
1404 $addresses = new ilMailOnlyExternalAddressList(
1405 new ilMailAddressListImpl($this->parseAddresses($recipients)),
1406 self::ILIAS_HOST,
1407 $this->usr_id_by_login_callable
1408 );
1409
1410 $email_recipients = array_map(static fn(ilMailAddress $address): string => (string) $address, $addresses->value());
1411
1412 return implode(',', $email_recipients);
1413 }

◆ getMail()

ilMail::getMail ( int  $mail_id)

Definition at line 291 of file class.ilMail.php.

291 : ?array
292 {
293 $res = $this->db->queryF(
294 "SELECT * FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
295 ['integer', 'integer'],
296 [$this->user_id, $mail_id]
297 );
298
299 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
300
301 return $this->mail_data;
302 }
fetchMailData(?array $row)

References $mail_data, $res, and fetchMailData().

+ Here is the call graph for this function:

◆ getMailObjectReferenceId()

ilMail::getMailObjectReferenceId ( )

Definition at line 165 of file class.ilMail.php.

165 : int
166 {
167 return $this->mail_obj_ref_id;
168 }

◆ getMailOptionsByUserId()

ilMail::getMailOptionsByUserId ( int  $usr_id)
private

Definition at line 1504 of file class.ilMail.php.

1505 {
1506 if (!isset($this->mail_options_by_usr_id_map[$usr_id])) {
1507 $this->mail_options_by_usr_id_map[$usr_id] = new ilMailOptions($usr_id);
1508 }
1509
1510 return $this->mail_options_by_usr_id_map[$usr_id];
1511 }

◆ getMailsOfFolder()

ilMail::getMailsOfFolder ( int  $a_folder_id,
array  $filter = [] 
)

Definition at line 241 of file class.ilMail.php.

241 : array
242 {
243 $mails = [];
244
245 $query =
246 'SELECT sender_id, m_subject, mail_id, m_status, send_time, import_name ' .
247 "FROM $this->table_mail " .
248 'LEFT JOIN object_data ON obj_id = sender_id ' .
249 'WHERE user_id = %s AND folder_id = %s ' .
250 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) ' .
251 'OR (sender_id = 0 OR sender_id IS NULL))';
252
253 if (isset($filter['status']) && $filter['status'] !== '') {
254 $query .= ' AND m_status = ' . $this->db->quote($filter['status'], 'text');
255 }
256
257 $query .= ' ORDER BY send_time DESC';
258
259 $res = $this->db->queryF(
260 $query,
261 ['integer', 'integer'],
262 [$this->user_id, $a_folder_id]
263 );
264
265 while ($row = $this->db->fetchAssoc($res)) {
266 $mails[] = $this->fetchMailData($row);
267 }
268
269 return array_filter($mails);
270 }

References $res, and fetchMailData().

Referenced by deleteMailsOfFolder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewDraftId()

ilMail::getNewDraftId ( int  $folder_id)

Definition at line 448 of file class.ilMail.php.

448 : int
449 {
450 $next_id = $this->db->nextId($this->table_mail);
451 $this->db->insert($this->table_mail, [
452 'mail_id' => ['integer', $next_id],
453 'user_id' => ['integer', $this->user_id],
454 'folder_id' => ['integer', $folder_id],
455 'sender_id' => ['integer', $this->user_id],
456 ]);
457
458 return $next_id;
459 }

◆ getNextMail()

ilMail::getNextMail ( int  $mail_id)

Definition at line 220 of file class.ilMail.php.

220 : ?array
221 {
222 $this->db->setLimit(1, 0);
223
224 $query = implode(' ', [
225 "SELECT b.* FROM $this->table_mail a",
226 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
227 'AND b.user_id = a.user_id AND b.send_time < a.send_time',
228 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
229 ]);
230 $res = $this->db->queryF(
231 $query,
232 ['integer', 'integer'],
233 [$this->user_id, $mail_id]
234 );
235
236 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
237
238 return $this->mail_data;
239 }

References $mail_data, $res, and fetchMailData().

+ Here is the call graph for this function:

◆ getPreviousMail()

ilMail::getPreviousMail ( int  $mail_id)

Definition at line 199 of file class.ilMail.php.

199 : ?array
200 {
201 $this->db->setLimit(1, 0);
202
203 $query = implode(' ', [
204 "SELECT b.* FROM $this->table_mail a",
205 "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
206 'AND b.user_id = a.user_id AND b.send_time > a.send_time',
207 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
208 ]);
209 $res = $this->db->queryF(
210 $query,
211 ['integer', 'integer'],
212 [$this->user_id, $mail_id]
213 );
214
215 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
216
217 return $this->mail_data;
218 }

References $mail_data, $res, and fetchMailData().

+ Here is the call graph for this function:

◆ getSalutation()

static ilMail::getSalutation ( int  $a_usr_id,
?ilLanguage  $a_language = null 
)
static

Definition at line 1459 of file class.ilMail.php.

1459 : string
1460 {
1461 global $DIC;
1462
1463 $lang = ($a_language instanceof ilLanguage) ? $a_language : $DIC->language();
1464 $lang->loadLanguageModule('mail');
1465
1466 $gender = ilObjUser::_lookupGender($a_usr_id);
1467 $gender = $gender ?: 'n';
1468 $name = ilObjUser::_lookupName($a_usr_id);
1469
1470 if ($name['firstname'] === '') {
1471 return $lang->txt('mail_salutation_anonymous') . ',';
1472 }
1473
1474 return
1475 $lang->txt('mail_salutation_' . $gender) . ' ' .
1476 ($name['title'] ? $name['title'] . ' ' : '') .
1477 ($name['firstname'] ? $name['firstname'] . ' ' : '') .
1478 $name['lastname'] . ',';
1479 }
static _lookupName(int $a_user_id)
static _lookupGender(int $a_user_id)

References $DIC, ilObjUser\_lookupGender(), and ilObjUser\_lookupName().

Referenced by ilTestManScoringParticipantNotification\buildBody(), ilUserCronCheckAccounts\run(), ilCalendarMailNotification\send(), ilBuddySystemNotification\send(), ilCourseMembershipMailNotification\send(), ilDataCollectionMailNotification\send(), ilExerciseMailNotification\send(), ilGroupMembershipMailNotification\send(), ilIndividualAssessmentPrimitiveInternalNotificator\send(), ilLMMailNotification\send(), ilLearningSequenceMembershipMailNotification\send(), ilMailSummaryNotification\send(), ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailNotification\send(), ILIAS\Portfolio\Notification\SharedNotification\send(), ilRegistrationMailNotification\send(), ilSessionMembershipMailNotification\send(), ilTestMailNotification\sendAdvancedNotification(), and ilTestMailNotification\sendSimpleNotification().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSaveInSentbox()

ilMail::getSaveInSentbox ( )

Definition at line 155 of file class.ilMail.php.

155 : bool
156 {
158 }
bool $save_in_sentbox

References $save_in_sentbox.

◆ getSubjectSentFolderId()

ilMail::getSubjectSentFolderId ( )
private

Definition at line 1247 of file class.ilMail.php.

1247 : int
1248 {
1249 $send_folder_id = 0;
1250 if (!$this->isSystemMail()) {
1251 $send_folder_id = $this->mailbox->getSentFolder();
1252 }
1253
1254 return $send_folder_id;
1255 }

◆ getUserIds()

ilMail::getUserIds ( array  $recipients)
private
Parameters
list<string>$recipients
Returns
list<int>

Definition at line 909 of file class.ilMail.php.

909 : array
910 {
911 $parsed_usr_ids = [];
912
913 $joined_recipients = implode(',', array_filter(array_map('trim', $recipients)));
914
915 $addresses = $this->parseAddresses($joined_recipients);
916 foreach ($addresses as $address) {
917 $address_type = $this->mail_address_type_factory->getByPrefix($address);
918 $parsed_usr_ids[] = $address_type->resolve();
919 }
920
921 return array_unique(array_merge(...$parsed_usr_ids));
922 }

◆ getUserInstanceById()

ilMail::getUserInstanceById ( int  $usr_id)
private

Definition at line 1481 of file class.ilMail.php.

1481 : ?ilObjUser
1482 {
1483 if (!array_key_exists($usr_id, $this->user_instances_by_id_map)) {
1484 try {
1485 $user = new ilObjUser($usr_id);
1486 } catch (Exception) {
1487 $user = null;
1488 }
1489
1490 $this->user_instances_by_id_map[$usr_id] = $user;
1491 }
1492
1493 return $this->user_instances_by_id_map[$usr_id];
1494 }

Referenced by formatNamesForOutput().

+ Here is the caller graph for this function:

◆ isSystemMail()

ilMail::isSystemMail ( )
private

Definition at line 134 of file class.ilMail.php.

134 : bool
135 {
136 return $this->user_id === ANONYMOUS_USER_ID;
137 }
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID.

◆ markRead()

ilMail::markRead ( array  $mail_ids)
Parameters
list<int>$mail_ids

Definition at line 307 of file class.ilMail.php.

307 : void
308 {
309 $values = [];
310 $types = [];
311
312 $query = "UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
313 $types[] = 'text';
314 $types[] = 'integer';
315 $values[] = 'read';
316 $values[] = $this->user_id;
317
318 if ($mail_ids !== []) {
319 $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
320 }
321
322 $this->db->manipulateF($query, $types, $values);
323 }

References $user_id.

◆ markUnread()

ilMail::markUnread ( array  $mail_ids)
Parameters
list<int>$mail_ids

Definition at line 328 of file class.ilMail.php.

328 : void
329 {
330 $values = [];
331 $types = [];
332
333 $query = "UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
334 $types[] = 'text';
335 $types[] = 'integer';
336 $values[] = 'unread';
337 $values[] = $this->user_id;
338
339 if ($mail_ids !== []) {
340 $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
341 }
342
343 $this->db->manipulateF($query, $types, $values);
344 }

References $user_id.

◆ moveMailsToFolder()

ilMail::moveMailsToFolder ( array  $mail_ids,
int  $folder_id 
)
Parameters
list<int>$mail_ids

Definition at line 349 of file class.ilMail.php.

349 : bool
350 {
351 $values = [];
352 $types = [];
353
354 $mail_ids = array_filter(array_map(intval(...), $mail_ids));
355
356 if ([] === $mail_ids) {
357 return false;
358 }
359
360 $query =
361 "UPDATE $this->table_mail " .
362 'INNER JOIN mail_obj_data ' .
363 'ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s ' .
364 "SET $this->table_mail.folder_id = mail_obj_data.obj_id " .
365 "WHERE $this->table_mail.user_id = %s";
366 $types[] = 'integer';
367 $types[] = 'integer';
368 $types[] = 'integer';
369 $values[] = $folder_id;
370 $values[] = $this->user_id;
371 $values[] = $this->user_id;
372
373 $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
374
375 $affected_rows = $this->db->manipulateF($query, $types, $values);
376
377 return $affected_rows > 0;
378 }

References $user_id.

◆ parseAddresses()

ilMail::parseAddresses ( string  $addresses)
private

Explode recipient string, allowed separators are ',' ';' ' '.

Returns
list<ilMailAddress>

Definition at line 1353 of file class.ilMail.php.

1353 : array
1354 {
1355 if ($addresses !== '') {
1356 $this->logger->debug(sprintf(
1357 'Started parsing of recipient string: %s',
1358 $addresses
1359 ));
1360 }
1361
1362 $parser = $this->mail_address_parser_factory->getParser($addresses);
1363 $parsed_addresses = $parser->parse();
1364
1365 if ($addresses !== '') {
1366 $this->logger->debug(sprintf(
1367 'Parsed addresses: %s',
1368 implode(',', array_map(static fn(ilMailAddress $address): string => (string) $address, $parsed_addresses))
1369 ));
1370 }
1371
1372 return $parsed_addresses;
1373 }

References ILIAS\Repository\logger().

Referenced by existsRecipient().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ persistToStage()

ilMail::persistToStage ( int  $a_user_id,
string  $a_rcp_to,
string  $a_rcp_cc,
string  $a_rcp_bcc,
string  $a_m_subject,
string  $a_m_message,
?\ILIAS\ResourceStorage\Identification\ResourceCollectionIdentification  $a_attachments = null,
bool  $a_use_placeholders = false,
?string  $a_tpl_context_id = null,
?array  $a_tpl_ctx_params = [] 
)
Parameters
list<string>$a_attachments

Definition at line 979 of file class.ilMail.php.

990 : bool {
991 if (!is_null($a_attachments)) {
992 $a_attachments = $a_attachments->serialize();
993 }
994 $this->db->replace(
995 $this->table_mail_saved,
996 [
997 'user_id' => ['integer', $this->user_id],
998 ],
999 [
1000 'attachments' => ['text', $a_attachments],
1001 'rcp_to' => ['clob', $a_rcp_to],
1002 'rcp_cc' => ['clob', $a_rcp_cc],
1003 'rcp_bcc' => ['clob', $a_rcp_bcc],
1004 'm_subject' => ['text', $a_m_subject],
1005 'm_message' => ['clob', $a_m_message],
1006 'use_placeholders' => ['integer', (int) $a_use_placeholders],
1007 'tpl_ctx_id' => ['text', $a_tpl_context_id],
1008 'tpl_ctx_params' => ['blob', json_encode((array) $a_tpl_ctx_params, JSON_THROW_ON_ERROR)],
1009 ]
1010 );
1011
1012 $this->retrieveFromStage();
1013
1014 return true;
1015 }
retrieveFromStage()

◆ readMailObjectReferenceId()

ilMail::readMailObjectReferenceId ( )
private

Definition at line 160 of file class.ilMail.php.

160 : void
161 {
162 $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
163 }

References ilMailGlobalServices\getMailObjectRefId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replacePlaceholders()

ilMail::replacePlaceholders ( string  $message,
int  $usr_id = 0 
)
private

Definition at line 617 of file class.ilMail.php.

620 : string {
621 try {
622 if ($this->context_id) {
623 $context = ilMailTemplateContextService::getTemplateContextById($this->context_id);
624 } else {
625 $context = new ilMailTemplateGenericContext();
626 }
627
628 $user = $usr_id > 0 ? $this->getUserInstanceById($usr_id) : null;
629 $message = $this->placeholder_resolver->resolve(
630 $context,
631 $message,
632 $user,
633 $this->context_parameters
634 );
635 } catch (Exception $e) {
636 $this->logger->error(sprintf(
637 '%s has been called with invalid context: %s / %s',
638 __METHOD__,
639 $e->getMessage(),
640 $e->getTraceAsString()
641 ));
642 }
643
644 return $message;
645 }

References ilMailTemplateContextService\getTemplateContextById().

+ Here is the call graph for this function:

◆ replacePlaceholdersEmpty()

ilMail::replacePlaceholdersEmpty ( string  $message)
private

Definition at line 647 of file class.ilMail.php.

647 : string
648 {
649 return $this->placeholder_to_empty_resolver->resolve($message);
650 }

◆ retrieveFromStage()

ilMail::retrieveFromStage ( )

Definition at line 1017 of file class.ilMail.php.

1017 : array
1018 {
1019 $res = $this->db->queryF(
1020 "SELECT * FROM $this->table_mail_saved WHERE user_id = %s",
1021 ['integer'],
1022 [$this->user_id]
1023 );
1024
1025 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
1026 if (!is_array($this->mail_data)) {
1027 $this->persistToStage($this->user_id, '', '', '', '', '', null, false);
1028 }
1029
1030 return $this->mail_data;
1031 }
persistToStage(int $a_user_id, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, ?\ILIAS\ResourceStorage\Identification\ResourceCollectionIdentification $a_attachments=null, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, ?array $a_tpl_ctx_params=[])

References $res.

◆ saveAttachments()

ilMail::saveAttachments ( ?ResourceCollectionIdentification  $attachments)

Definition at line 1332 of file class.ilMail.php.

1332 : void
1333 {
1334 if (!is_null($attachments)) {
1335 $attachments = $attachments->serialize();
1336 }
1337
1338 $this->db->update(
1339 $this->table_mail_saved,
1340 [
1341 'attachments' => ['text', $attachments],
1342 ],
1343 [
1344 'user_id' => ['integer', $this->user_id],
1345 ]
1346 );
1347 }

References ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize().

+ Here is the call graph for this function:

◆ saveInSentbox()

ilMail::saveInSentbox ( array  $attachment,
string  $to,
string  $cc,
string  $bcc,
string  $subject,
string  $message 
)
private
Parameters
list<string>$attachment

Definition at line 1260 of file class.ilMail.php.

1267 : int {
1268 return $this->sendInternalMail(
1269 $this->getSubjectSentFolderId(),
1270 $this->user_id,
1271 $attachment,
1272 $to,
1273 $cc,
1274 $bcc,
1275 'read',
1276 $subject,
1277 $message,
1278 $this->user_id
1279 );
1280 }
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=[])
getSubjectSentFolderId()

◆ scheduledMail()

ilMail::scheduledMail ( int  $folder_id,
int  $sender_usr_id,
MailScheduleData  $mail_data,
?string  $template_context_id = null,
array  $template_context_parameters = [] 
)
Parameters
array<string,mixed>$template_context_parameters

Definition at line 507 of file class.ilMail.php.

513 : int {
514 $message = $mail_data->getMailDeliveryData()->getMessage();
515 if ($mail_data->getMailDeliveryData()->isUsePlaceholder()) {
516 $message = $this->replacePlaceholders($mail_data->getMailDeliveryData()->getMessage(), $sender_usr_id);
517 }
518 $message = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $message);
519 $mail_values = [
520 'user_id' => [ilDBConstants::T_INTEGER, $sender_usr_id],
521 'folder_id' => [ilDBConstants::T_INTEGER, $folder_id],
522 'sender_id' => [ilDBConstants::T_INTEGER, $sender_usr_id],
523 'attachments' => [ilDBConstants::T_CLOB, serialize($mail_data->getMailDeliveryData()->getAttachments())],
524 'send_time' => [ilDBConstants::T_TIMESTAMP, date('Y-m-d H:i:s')],
525 'rcp_to' => [ilDBConstants::T_CLOB, $mail_data->getMailDeliveryData()->getTo()],
526 'rcp_cc' => [ilDBConstants::T_CLOB, $mail_data->getMailDeliveryData()->getCC()],
527 'rcp_bcc' => [ilDBConstants::T_CLOB, $mail_data->getMailDeliveryData()->getBcc()],
528 'm_status' => [ilDBConstants::T_TEXT, 'read'],
529 'm_subject' => [ilDBConstants::T_TEXT, $mail_data->getMailDeliveryData()->getSubject()],
530 'm_message' => [ilDBConstants::T_CLOB, $message],
531 'tpl_ctx_id' => [ilDBConstants::T_TEXT, $template_context_id],
532 'tpl_ctx_params' => [ilDBConstants::T_BLOB, json_encode($template_context_parameters, JSON_THROW_ON_ERROR)],
533 'schedule_datetime' => [ilDBConstants::T_TIMESTAMP, $mail_data->getScheduleDatetime()->format('Y-m-d H:i:s')],
534 'schedule_timezone' => [ilDBConstants::T_TEXT, $mail_data->getScheduleDatetime()->getTimezone()->getName()],
535 ];
536
537 if (!$mail_data->getMailDeliveryData()->getInternalMailId()) {
538 $outbox_id = $this->db->nextId($this->table_mail);
539 $mail_values['mail_id'] = [ilDBConstants::T_INTEGER, $outbox_id];
540 $this->db->insert($this->table_mail, $mail_values);
541 } else {
542 $outbox_id = $mail_data->getMailDeliveryData()->getInternalMailId();
543 $this->db->update($this->table_mail, $mail_values, [
544 'mail_id' => [ilDBConstants::T_INTEGER, $outbox_id],
545 ]);
546 }
547
548 return $outbox_id;
549 }
replacePlaceholders(string $message, int $usr_id=0)

References ILIAS\Mail\Folder\MailScheduleData\getMailDeliveryData().

+ Here is the call graph for this function:

◆ sendChanneledMails()

ilMail::sendChanneledMails ( MailDeliveryData  $mail_data,
array  $recipients,
string  $message 
)
private
Parameters
list<Recipient>$recipients

Definition at line 740 of file class.ilMail.php.

744 : void {
745 $usr_id_to_external_email_addresses_map = [];
746
747 foreach ($recipients as $recipient) {
748 if (!$recipient->isUser()) {
749 $this->logger->critical(sprintf(
750 'Skipped recipient with id %s (User not found)',
751 $recipient->getUserId()
752 ));
753 continue;
754 }
755
756 $can_read_internal = $recipient->evaluateInternalMailReadability();
757 if ($this->isSystemMail() && !$can_read_internal->isOk()) {
758 $this->logger->debug(sprintf(
759 'Skipped recipient with id %s and reason: %s',
760 $recipient->getUserId(),
761 is_string($can_read_internal->error()) ? $can_read_internal->error() : $can_read_internal->error()->getMessage()
762 ));
763 continue;
764 }
765
766 if ($recipient->isUserActive() && !$recipient->isUserExpired()) {
767 if (!$can_read_internal->isOk() || $recipient->userWantsToReceiveExternalMails()) {
768 $email_addresses = $recipient->getExternalMailAddress();
769 $usr_id_to_external_email_addresses_map[$recipient->getUserId()] = $email_addresses;
770
771 if ($recipient->onlyToExternalMailAddress()) {
772 $this->logger->debug(sprintf(
773 'Recipient with id %s will only receive external emails sent to: %s',
774 $recipient->getUserId(),
775 implode(', ', $email_addresses)
776 ));
777 continue;
778 }
779
780 $this->logger->debug(sprintf(
781 'Recipient with id %s will additionally receive external emails ' .
782 '(because the user wants to receive it externally, or the user cannot did not accept ' .
783 'the legal documents) sent to: %s',
784 $recipient->getUserId(),
785 implode(', ', $email_addresses)
786 ));
787 } else {
788 $this->logger->debug(sprintf(
789 'Recipient with id %s does not want to receive external emails',
790 $recipient->getUserId()
791 ));
792 }
793 } else {
794 $this->logger->debug(sprintf(
795 'Recipient with id %s is inactive or expired and will not receive external emails',
796 $recipient->getUserId()
797 ));
798 }
799
800 $mbox = clone $this->mailbox;
801 $mbox->setUsrId($recipient->getUserId());
802 $recipient_inbox_id = $mbox->getInboxFolder();
803
804 $internal_mail_id = $this->sendInternalMail(
805 $recipient_inbox_id,
806 $this->user_id,
807 $mail_data->getAttachments(),
808 $mail_data->getTo(),
809 $mail_data->getCc(),
810 '',
811 'unread',
812 $mail_data->getSubject(),
813 $message,
814 $recipient->getUserId()
815 );
816
817 $this->auto_responder_service->enqueueAutoresponderIfEnabled(
818 $recipient->getUserId(),
819 $recipient->getMailOptions(),
820 $this->getMailOptionsByUserId($this->user_id),
821 );
822
823 if ($mail_data->getAttachments() !== []) {
824 $this->mail_file_data->assignAttachmentsToDirectory($internal_mail_id, $mail_data->getInternalMailId());
825 }
826 }
827
829 $mail_data->getSubject(),
830 $mail_data->getAttachments(),
831 $message,
832 $usr_id_to_external_email_addresses_map
833 );
834 }
delegateExternalEmails(string $subject, array $attachments, string $message, array $usr_id_to_external_email_addresses_map)

References MailDeliveryData\getAttachments(), MailDeliveryData\getCc(), MailDeliveryData\getInternalMailId(), MailDeliveryData\getSubject(), MailDeliveryData\getTo(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ sendInternalMail()

ilMail::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 = [] 
)
private

Definition at line 551 of file class.ilMail.php.

565 : int {
566 $usr_id = $usr_id ?: $this->user_id;
567
568 if ($use_placeholders) {
569 $message = $this->replacePlaceholders($message, $usr_id);
570 }
571
572 $message = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $message);
573
574 $next_id = $this->db->nextId($this->table_mail);
575 $this->db->insert($this->table_mail, [
576 'mail_id' => ['integer', $next_id],
577 'user_id' => ['integer', $usr_id],
578 'folder_id' => ['integer', $folder_id],
579 'sender_id' => ['integer', $sender_usr_id],
580 'attachments' => ['clob', serialize($attachments)],
581 'send_time' => ['timestamp', date('Y-m-d H:i:s')],
582 'rcp_to' => ['clob', $to],
583 'rcp_cc' => ['clob', $cc],
584 'rcp_bcc' => ['clob', $bcc],
585 'm_status' => ['text', $status],
586 'm_subject' => ['text', $subject],
587 'm_message' => ['clob', $message],
588 'tpl_ctx_id' => ['text', $template_contenxt_id],
589 'tpl_ctx_params' => ['blob', json_encode($template_context_parameters, JSON_THROW_ON_ERROR)],
590 ]);
591
592 $sender_equals_reveiver = $usr_id === $this->mailbox->getUsrId();
593 $is_sent_folder_of_sender = false;
594 if ($sender_equals_reveiver) {
595 $current_folder_id = $this->getSubjectSentFolderId();
596 $is_sent_folder_of_sender = $folder_id === $current_folder_id;
597 }
598
599 $raise_event = !$sender_equals_reveiver || !$is_sent_folder_of_sender;
600
601 if ($raise_event) {
602 $this->event_handler->raise('components/ILIAS/Mail', 'sentInternalMail', [
603 'id' => $next_id,
604 'subject' => $subject,
605 'body' => $message,
606 'from_usr_id' => $sender_usr_id,
607 'to_usr_id' => $usr_id,
608 'rcp_to' => $to,
609 'rcp_cc' => $cc,
610 'rcp_bcc' => $bcc,
611 ]);
612 }
613
614 return $next_id;
615 }

◆ sendMail()

ilMail::sendMail ( MailDeliveryData  $mail_data)

This method is used to finally send internal messages and external emails To use the mail system as a consumer, please use ilMail::enqueue.

Parameters
list<string>$attachments
Returns
list<ilMailError>
See also
ilMail::enqueue()

Definition at line 1153 of file class.ilMail.php.

1155 : array {
1156 $internal_message_id = $this->saveInSentbox(
1157 $mail_data->getAttachments(),
1158 $mail_data->getTo(),
1159 $mail_data->getCc(),
1160 $mail_data->getBcc(),
1161 $mail_data->getSubject(),
1162 $mail_data->getMessage()
1163 );
1164 $mail_data = $mail_data->withInternalMailId($internal_message_id);
1165
1166 if ($mail_data->getAttachments() !== []) {
1167 $this->mail_file_data->assignAttachmentsToDirectory($internal_message_id, $internal_message_id);
1168 $this->mail_file_data->saveFiles($internal_message_id, $mail_data->getAttachments());
1169 }
1170
1171 $num_external_email_addresses = $this->getCountRecipients(
1172 $mail_data->getTo(),
1173 $mail_data->getCc(),
1174 $mail_data->getBcc()
1175 );
1176
1177 if ($num_external_email_addresses > 0) {
1178 $external_mail_recipients_to = $this->getEmailRecipients($mail_data->getTo());
1179 $external_mail_recipients_cc = $this->getEmailRecipients($mail_data->getCc());
1180 $external_eail_recipients_bcc = $this->getEmailRecipients($mail_data->getBcc());
1181
1182 $this->logger->debug(
1183 'Parsed external email addresses from given recipients /' .
1184 ' To: ' . $external_mail_recipients_to .
1185 ' | CC: ' . $external_mail_recipients_cc .
1186 ' | BCC: ' . $external_eail_recipients_bcc .
1187 ' | Subject: ' . $mail_data->getSubject()
1188 );
1189
1190 $this->sendMimeMail(
1191 $external_mail_recipients_to,
1192 $external_mail_recipients_cc,
1193 $external_eail_recipients_bcc,
1194 $mail_data->getSubject(),
1195 $mail_data->isUsePlaceholder() ?
1196 $this->replacePlaceholders($mail_data->getMessage(), 0) :
1197 $mail_data->getMessage(),
1198 $mail_data->getAttachments()
1199 );
1200 } else {
1201 $this->logger->debug('No external email addresses given in recipient string');
1202 }
1203
1204 $errors = [];
1205 if (!$this->distributeMail($mail_data)) {
1206 $errors['mail_send_error'] = new ilMailError('mail_send_error');
1207 }
1208
1209 if (!$this->getSaveInSentbox()) {
1210 $this->deleteMails([$internal_message_id]);
1211 }
1212
1213 if ($this->isSystemMail()) {
1214 $random = new Random\Randomizer();
1215 if ($random->getInt(0, 50) === 2) {
1217 $this->logger,
1218 $this->mail_file_data
1219 ))->run();
1220 }
1221 }
1222
1223 return array_values($errors);
1224 }
distributeMail(MailDeliveryData $mail_data)
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
getEmailRecipients(string $recipients)

References MailDeliveryData\getAttachments().

+ Here is the call graph for this function:

◆ sendMailWithoutReplacedPlaceholder()

ilMail::sendMailWithoutReplacedPlaceholder ( MailDeliveryData  $mail_data,
array  $to_usr_ids,
array  $cc_bcc_recipients 
)
private
Parameters
list<int>$to_usr_ids
list<Recipient>$cc_bcc_recipients

Definition at line 720 of file class.ilMail.php.

724 : void {
725 $to_recipients = array_map(
726 $this->createRecipient(...),
727 $to_usr_ids
728 );
729
730 $this->sendChanneledMails(
731 $mail_data,
732 array_merge($to_recipients, $cc_bcc_recipients),
733 $mail_data->getMessage()
734 );
735 }
sendChanneledMails(MailDeliveryData $mail_data, array $recipients, string $message)

◆ sendMailWithReplacedEmptyPlaceholder()

ilMail::sendMailWithReplacedEmptyPlaceholder ( MailDeliveryData  $mail_data,
array  $recipients 
)
private
Parameters
list<Recipient>$recipients

Definition at line 705 of file class.ilMail.php.

708 : void {
709 $this->sendChanneledMails(
710 $mail_data,
711 $recipients,
712 $this->replacePlaceholdersEmpty($mail_data->getMessage()),
713 );
714 }
replacePlaceholdersEmpty(string $message)

◆ sendMailWithReplacedPlaceholder()

ilMail::sendMailWithReplacedPlaceholder ( MailDeliveryData  $mail_data,
array  $to_usr_ids 
)
private
Parameters
list<int>$to_usr_ids

Definition at line 687 of file class.ilMail.php.

690 : void {
691 foreach ($to_usr_ids as $user_id) {
692 $recipient = $this->createRecipient($user_id);
693
694 $this->sendChanneledMails(
695 $mail_data,
696 [$recipient],
697 $this->replacePlaceholders($mail_data->getMessage(), $user_id),
698 );
699 }
700 }

References $user_id, and MailDeliveryData\getMessage().

+ Here is the call graph for this function:

◆ sendMimeMail()

ilMail::sendMimeMail ( string  $to,
string  $cc,
string  $bcc,
string  $subject,
string  $message,
array  $attachments 
)
private
Parameters
list<string>$attachments

Definition at line 1285 of file class.ilMail.php.

1292 : void {
1293 $mailer = new ilMimeMail();
1294 $mailer->From($this->sender_factory->getSenderByUsrId($this->user_id));
1295 $mailer->To($to);
1296 $mailer->Subject(
1297 $subject,
1298 true,
1299 (string) ($this->context_parameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ?? '')
1300 );
1301
1302 if (!$this->isSystemMail()) {
1303 $message .= $this->signature_service->user($this->user_id);
1304 }
1305 $mailer->Body(
1306 $message,
1307 function (string $message): string {
1308 return $this->refinery->string()->markdown()->toHTML()->transform($message) ?? '';
1309 }
1310 );
1311
1312 if ($cc !== '') {
1313 $mailer->Cc($cc);
1314 }
1315
1316 if ($bcc !== '') {
1317 $mailer->Bcc($bcc);
1318 }
1319
1320 foreach ($attachments as $attachment) {
1321 $mailer->Attach(
1322 $this->mail_file_data->getAbsoluteAttachmentPoolPathByFilename($attachment),
1323 '',
1324 'inline',
1325 $attachment
1326 );
1327 }
1328
1329 $mailer->Send();
1330 }

◆ setMailOptionsByUserIdMap()

ilMail::setMailOptionsByUserIdMap ( array  $mail_options_by_usr_id_map)
Parameters
ilMailOptions[]$mail_options_by_usr_id_map

Definition at line 1516 of file class.ilMail.php.

1516 : void
1517 {
1518 $this->mail_options_by_usr_id_map = $mail_options_by_usr_id_map;
1519 }
array $mail_options_by_usr_id_map

◆ setSaveInSentbox()

ilMail::setSaveInSentbox ( bool  $save_in_sentbox)

Definition at line 150 of file class.ilMail.php.

150 : void
151 {
152 $this->save_in_sentbox = $save_in_sentbox;
153 }

References $save_in_sentbox.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUserInstanceById()

ilMail::setUserInstanceById ( array  $user_instances_by_id_map)
Parameters
array<int,ilObjUser>$user_instances_by_id_map

Definition at line 1499 of file class.ilMail.php.

1499 : void
1500 {
1501 $this->user_instances_by_id_map = $user_instances_by_id_map;
1502 }
array $user_instances_by_id_map

◆ updateDraft()

ilMail::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,
?DateTimeImmutable  $schedule_time = null,
bool  $a_use_placeholders = false,
?string  $a_tpl_context_id = null,
array  $a_tpl_context_params = [] 
)
Parameters
list<string>$a_attachments

Definition at line 464 of file class.ilMail.php.

477 : int {
478 $this->db->update(
479 $this->table_mail,
480 [
481 'folder_id' => ['integer', $a_folder_id],
482 'attachments' => ['clob', serialize($a_attachments)],
483 'send_time' => ['timestamp', date('Y-m-d H:i:s')],
484 'rcp_to' => ['clob', $a_rcp_to],
485 'rcp_cc' => ['clob', $a_rcp_cc],
486 'rcp_bcc' => ['clob', $a_rcp_bcc],
487 'm_status' => ['text', 'read'],
488 'm_subject' => ['text', $a_m_subject],
489 'm_message' => ['clob', $a_m_message],
490 'use_placeholders' => ['integer', (int) $a_use_placeholders],
491 'tpl_ctx_id' => ['text', $a_tpl_context_id],
492 'tpl_ctx_params' => ['blob', json_encode($a_tpl_context_params, JSON_THROW_ON_ERROR)],
493 'schedule_datetime' => [ilDBConstants::T_TIMESTAMP, $schedule_time?->format('Y-m-d H:i:s')],
494 'schedule_timezone' => [ilDBConstants::T_TEXT, $schedule_time?->getTimezone()->getName()],
495 ],
496 [
497 'mail_id' => ['integer', $a_draft_id],
498 ]
499 );
500
501 return $a_draft_id;
502 }

◆ validateRecipients()

ilMail::validateRecipients ( string  $to,
string  $cc,
string  $bcc 
)
Returns
list<ilMailError>

Definition at line 1229 of file class.ilMail.php.

1229 : array
1230 {
1231 try {
1232 $errors = [];
1233 $errors = array_merge($errors, $this->checkRecipients($to));
1234 $errors = array_merge($errors, $this->checkRecipients($cc));
1235 $errors = array_merge($errors, $this->checkRecipients($bcc));
1236
1237 if ($errors !== []) {
1238 return array_merge([new ilMailError('mail_following_rcp_not_valid')], $errors);
1239 }
1240 } catch (ilMailException $e) {
1241 return [new ilMailError('mail_generic_rcp_error', [$e->getMessage()])];
1242 }
1243
1244 return [];
1245 }
checkRecipients(string $recipients)

References Vendor\Package\$e.

◆ withContextId()

ilMail::withContextId ( string  $context_id)

Definition at line 116 of file class.ilMail.php.

116 : self
117 {
118 $clone = clone $this;
119
120 $clone->context_id = $context_id;
121
122 return $clone;
123 }
string $context_id

References $context_id.

◆ withContextParameters()

ilMail::withContextParameters ( array  $parameters)

Definition at line 125 of file class.ilMail.php.

125 : self
126 {
127 $clone = clone $this;
128
129 $clone->context_parameters = $parameters;
130
131 return $clone;
132 }

Field Documentation

◆ $append_installation_signature

bool ilMail::$append_installation_signature = false
private

Definition at line 44 of file class.ilMail.php.

◆ $append_user_signature

bool ilMail::$append_user_signature = false
private

Definition at line 45 of file class.ilMail.php.

◆ $context_id

string ilMail::$context_id = null
private

Definition at line 47 of file class.ilMail.php.

Referenced by withContextId().

◆ $context_parameters

array ilMail::$context_parameters = []
private

Definition at line 48 of file class.ilMail.php.

◆ $legal_documents

readonly Conductor ilMail::$legal_documents
private

Definition at line 56 of file class.ilMail.php.

Referenced by __construct().

◆ $mail_data

array ilMail::$mail_data = []
protected

◆ $mail_options_by_usr_id_map

array ilMail::$mail_options_by_usr_id_map = []
private

Definition at line 51 of file class.ilMail.php.

◆ $max_recipient_character_length

int ilMail::$max_recipient_character_length = 998
private

Definition at line 55 of file class.ilMail.php.

◆ $refinery

readonly ILIAS Refinery Factory ilMail::$refinery
private

Definition at line 57 of file class.ilMail.php.

◆ $save_in_sentbox

bool ilMail::$save_in_sentbox
private

Definition at line 43 of file class.ilMail.php.

Referenced by getSaveInSentbox(), and setSaveInSentbox().

◆ $signature_service

MailSignatureService ilMail::$signature_service
private

Definition at line 37 of file class.ilMail.php.

Referenced by __construct().

◆ $table_mail

string ilMail::$table_mail
private

Definition at line 39 of file class.ilMail.php.

◆ $table_mail_saved

string ilMail::$table_mail_saved
private

Definition at line 40 of file class.ilMail.php.

◆ $user_id

int ilMail::$user_id

Definition at line 38 of file class.ilMail.php.

Referenced by markRead(), markUnread(), and moveMailsToFolder().

◆ $user_instances_by_id_map

array ilMail::$user_instances_by_id_map = []
private

Definition at line 54 of file class.ilMail.php.

◆ ILIAS_HOST

const string ilMail::ILIAS_HOST = 'ilias'

◆ PROP_CONTEXT_SUBJECT_PREFIX


The documentation for this class was generated from the following file: