ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMail Class Reference
+ Inheritance diagram for ilMail:
+ Collaboration diagram for ilMail:

Public Member Functions

 __construct ( $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)
 
 withContextId (string $contextId)
 
 withContextParameters (array $parameters)
 
 existsRecipient (string $newRecipient, string $existingRecipients)
 
 setSaveInSentbox (bool $saveInSentbox)
 
 getSaveInSentbox ()
 
 getMailObjectReferenceId ()
 
 formatNamesForOutput (string $recipients)
 Prepends the full name of each ILIAS login name (if user has a public profile) found in the passed string and brackets the ILIAS login name afterwards. More...
 
 getPreviousMail (int $mailId)
 
 getNextMail (int $mailId)
 
 getMailsOfFolder ($a_folder_id, $filter=[])
 
 countMailsOfFolder (int $folderId)
 
 deleteMailsOfFolder (int $folderId)
 
 getMail (int $mailId)
 
 markRead (array $mailIds)
 
 markUnread (array $mailIds)
 
 moveMailsToFolder (array $mailIds, int $folderId)
 
 deleteMails (array $mailIds)
 
 getNewDraftId (int $usrId, int $folderId)
 
 updateDraft ( $a_folder_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_email, $a_m_subject, $a_m_message, $a_draft_id=0, $a_use_placeholders=0, $a_tpl_context_id=null, $a_tpl_context_params=[])
 
 savePostData ( $a_user_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_email, $a_m_subject, $a_m_message, $a_use_placeholders, $a_tpl_context_id=null, $a_tpl_ctx_params=array())
 save post data in table @access public More...
 
 getSavedData ()
 
 enqueue ( $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_attachment, $a_use_placeholders=0)
 Should be used to enqueue a 'mail'. More...
 
 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 consumer, please use \ilMail::enqueue. More...
 
 validateRecipients (string $to, string $cc, string $bcc)
 
 saveAttachments (array $attachments)
 
 appendInstallationSignature (bool $a_flag=null)
 
 setUserInstanceById (array $userInstanceByIdMap)
 
 setMailOptionsByUserIdMap (array $mailOptionsByUsrIdMap)
 
 formatLinebreakMessage (string $message)
 

Static Public Member Functions

static _getAutoGeneratedMessageString (ilLanguage $lang=null)
 Get auto generated info string. More...
 
static _getInstallationSignature ()
 
static getSalutation ($a_usr_id, ilLanguage $a_language=null)
 

Data Fields

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

Protected Member Functions

 isSystemMail ()
 
 readMailObjectReferenceId ()
 Read and set the mail object ref id (administration node) More...
 
 fetchMailData (?array $row)
 
 replacePlaceholders (string $message, int $usrId=0, bool $replaceEmptyPlaceholders=true)
 
 distributeMail (string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
 
 sendChanneledMails (string $to, string $cc, string $bcc, array $usrIds, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
 
 delegateExternalEmails (string $subject, string $message, array $attachments, bool $usePlaceholders, array $usrIdToExternalEmailAddressesMap, array $usrIdToMessageMap)
 
 getUserIds (array $recipients)
 
 checkMail (string $to, string $cc, string $bcc, string $subject)
 
 checkRecipients (string $recipients)
 Check if recipients are valid. More...
 
 saveInSentbox (array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
 Stores a message in the sent bod of the current user. More...
 
 parseAddresses ($addresses)
 Explode recipient string, allowed separators are ',' ';' ' ' Returns an array with recipient ilMailAddress instances. More...
 
 getCountRecipient (string $recipients, $onlyExternalAddresses=true)
 
 getCountRecipients (string $toRecipients, string $ccRecipients, string $bccRecipients, $onlyExternalAddresses=true)
 
 getEmailRecipients (string $recipients)
 
 getUserInstanceById (int $usrId)
 
 getMailOptionsByUserId (int $usrId)
 

Protected Attributes

 $lng
 
 $db
 
 $mfile
 
 $mail_options
 
 $mailbox
 
 $table_mail
 
 $table_mail_saved
 
 $mail_data = array()
 
 $mail_obj_ref_id
 
 $save_in_sentbox
 
 $appendInstallationSignature = false
 
 $contextId = null
 
 $contextParameters = []
 
 $logger
 
 $mailOptionsByUsrIdMap = []
 
 $userInstancesByIdMap = []
 
 $usrIdByLoginCallable = null
 
 $maxRecipientCharacterLength = 998
 
 $senderFactory
 

Private Member Functions

 sendInternalMail ( $folderId, $senderUsrId, $attachments, $to, $cc, $bcc, $status, $email, $subject, $message, $usrId=0, $usePlaceholders=0, $templateContextId=null, $templateContextParameters=[])
 
 sendMimeMail (string $to, string $cc, string $bcc, $subject, $message, array $attachments)
 

Private Attributes

 $eventHandler
 
 $mailAddressTypeFactory
 
 $mailAddressParserFactory
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMail::__construct (   $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 
)
Parameters
integer$a_user_id
ilMailAddressTypeFactory | null$mailAddressTypeFactory
ilMailRfc822AddressParserFactory | null$mailAddressParserFactory
ilAppEventHandler | null$eventHandler
ilLogger | null$logger
ilDBInterface | null$db
ilLanguage | null$lng
ilFileDataMail | null$mailFileData
ilMailOptions | null$mailOptions
ilMailbox | null$mailBox
ilMailMimeSenderFactory | null$senderFactory
callable | null$usrIdByLoginCallable
int | null$mailAdminNodeRefId

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

113 {
114 global $DIC;
115
116 if ($logger === null) {
118 }
119 if ($mailAddressTypeFactory === null) {
121 }
122 if ($mailAddressParserFactory === null) {
124 }
125 if ($eventHandler === null) {
126 $eventHandler = $DIC->event();
127 }
128 if ($db === null) {
129 $db = $DIC->database();
130 }
131 if ($lng === null) {
132 $lng = $DIC->language();
133 }
134 if ($mailFileData === null) {
135 $mailFileData = new ilFileDataMail($a_user_id);
136 }
137 if ($mailOptions === null) {
138 $mailOptions = new ilMailOptions($a_user_id);
139 }
140 if ($mailBox === null) {
141 $mailBox = new ilMailbox($a_user_id);
142 }
143 if ($senderFactory === null) {
144 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
145 }
146 if ($usrIdByLoginCallable === null) {
147 $usrIdByLoginCallable = function (string $login) {
149 };
150 }
151
152 $this->user_id = (int) $a_user_id;
153 $this->mailAddressParserFactory = $mailAddressParserFactory;
154 $this->mailAddressTypeFactory = $mailAddressTypeFactory;
155 $this->eventHandler = $eventHandler;
156 $this->logger = $logger;
157 $this->db = $db;
158 $this->lng = $lng;
159 $this->mfile = $mailFileData;
160 $this->mail_options = $mailOptions;
161 $this->mailbox = $mailBox;
162 $this->senderFactory = $senderFactory;
163 $this->usrIdByLoginCallable = $usrIdByLoginCallable;
164
165 $this->mail_obj_ref_id = $mailAdminNodeRefId;
166 if (null === $this->mail_obj_ref_id) {
168 }
169
170 $this->lng->loadLanguageModule('mail');
171 $this->table_mail = 'mail';
172 $this->table_mail_saved = 'mail_saved';
173 $this->setSaveInSentbox(false);
174 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Class ilFileDataMail.
static getLogger($a_component_id)
Get component logger.
Class ilMailAddressTypeFactory.
Class ilMailOptions this class handles user mails.
Class ilMailRfc822AddressParserFactory.
$mailAddressParserFactory
$usrIdByLoginCallable
setSaveInSentbox(bool $saveInSentbox)
$mailAddressTypeFactory
readMailObjectReferenceId()
Read and set the mail object ref id (administration node)
Mail Box class Base class for creating and handling mail boxes.
static _lookupId($a_user_str)
Lookup id by login.
$login
Definition: cron.php:13
global $DIC
Definition: goto.php:24

References $db, $DIC, $eventHandler, $GLOBALS, $lng, $logger, $login, $mailAddressParserFactory, $mailAddressTypeFactory, $senderFactory, $usrIdByLoginCallable, ilObjUser\_lookupId(), ilLoggerFactory\getLogger(), readMailObjectReferenceId(), and setSaveInSentbox().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getAutoGeneratedMessageString()

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

Get auto generated info string.

Parameters
ilLanguage$lang
Returns
string;

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

1600 : string
1601 {
1602 global $DIC;
1603
1604 if (!($lang instanceof ilLanguage)) {
1606 }
1607
1608 $lang->loadLanguageModule('mail');
1609
1610 return sprintf(
1611 $lang->txt('mail_auto_generated_info'),
1612 $DIC->settings()->get('inst_name', 'ILIAS ' . ((int) ILIAS_VERSION_NUMERIC)),
1614 ) . "\n\n";
1615 }
static _getLanguage($a_lang_key='')
Get langauge object.
language handling
static _getHttpPath()
const ILIAS_VERSION_NUMERIC
$lang
Definition: xapiexit.php:8

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

Referenced by ilECSAppEventListener\_sendNotification(), ilSystemNotification\compose(), ilRemoteObjectBase\sendNewContentNotification(), and ilECSObjectSettings\sendNewContentNotification().

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

◆ _getInstallationSignature()

static ilMail::_getInstallationSignature ( )
static
Returns
string The installation mail signature

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

1645 : string
1646 {
1647 global $DIC;
1648
1649 $signature = $DIC->settings()->get('mail_system_sys_signature');
1650
1651 $clientUrl = ilUtil::_getHttpPath();
1652 $clientdirs = glob(ILIAS_WEB_DIR . '/*', GLOB_ONLYDIR);
1653 if (is_array($clientdirs) && count($clientdirs) > 1) {
1654 $clientUrl .= '/login.php?client_id=' . CLIENT_ID; // #18051
1655 }
1656
1657 $signature = str_ireplace('[CLIENT_NAME]', $DIC['ilClientIniFile']->readVariable('client', 'name'), $signature);
1658 $signature = str_ireplace(
1659 '[CLIENT_DESC]',
1660 $DIC['ilClientIniFile']->readVariable('client', 'description'),
1661 $signature
1662 );
1663 $signature = str_ireplace('[CLIENT_URL]', $clientUrl, $signature);
1664
1665 if (!preg_match('/^[\n\r]+/', $signature)) {
1666 $signature = "\n" . $signature;
1667 }
1668
1669 return $signature;
1670 }
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public
const CLIENT_ID
Definition: constants.php:39
const ILIAS_WEB_DIR
Definition: constants.php:43

References $DIC, ilUtil\_getHttpPath(), CLIENT_ID, ILIAS_WEB_DIR, and readVariable().

Referenced by ilForumMailNotification\addLinkToMail(), ilSystemNotification\compose(), ilForumMailEventNotificationSender\createAttachmentLinkText(), ilTimingsCronReminder\fillObjectListForMailBody(), ilMailCronOrphanedMailsNotification\send(), ilCronDeleteInactiveUserReminderMailNotification\send(), ilAccountRegistrationMail\sendLanguageVariableBasedAccountMail(), and ilWikiUtil\sendNotification().

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

◆ appendInstallationSignature()

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

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

1633 {
1634 if (null === $a_flag) {
1636 }
1637
1638 $this->appendInstallationSignature = $a_flag;
1639 return $this;
1640 }
appendInstallationSignature(bool $a_flag=null)
$appendInstallationSignature

◆ checkMail()

ilMail::checkMail ( string  $to,
string  $cc,
string  $bcc,
string  $subject 
)
protected
Parameters
string$to
string$cc
string$bcc
string$subject
Returns
ilMailError[] An array of errors determined on validation

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

1056 : array
1057 {
1058 $errors = [];
1059
1060 foreach ([
1061 $subject => 'mail_add_subject',
1062 $to => 'mail_add_recipient'
1063 ] as $string => $error
1064 ) {
1065 if (0 === strlen($string)) {
1066 $errors[] = new ilMailError($error);
1067 }
1068 }
1069
1070 return $errors;
1071 }
Class ilMailError.
$errors
Definition: imgupload.php:49

References $errors.

◆ checkRecipients()

ilMail::checkRecipients ( string  $recipients)
protected

Check if recipients are valid.

Parameters
string$recipients
Returns
ilMailError[] An array of errors determined on validation
Exceptions
ilMailException

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

1079 : array
1080 {
1081 $errors = [];
1082
1083 try {
1084 $addresses = $this->parseAddresses($recipients);
1085 foreach ($addresses as $address) {
1086 $addressType = $this->mailAddressTypeFactory->getByPrefix($address);
1087 if (!$addressType->validate($this->user_id)) {
1088 $newErrors = $addressType->getErrors();
1089 $errors = array_merge($errors, $newErrors);
1090 }
1091 }
1092 } catch (ilException $e) {
1093 $colonPosition = strpos($e->getMessage(), ':');
1094 throw new ilMailException(
1095 ($colonPosition === false) ? $e->getMessage() : substr($e->getMessage(), $colonPosition + 2)
1096 );
1097 }
1098
1099 return $errors;
1100 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMailException.
parseAddresses($addresses)
Explode recipient string, allowed separators are ',' ';' ' ' Returns an array with recipient ilMailAd...

References Vendor\Package\$e, and $errors.

◆ countMailsOfFolder()

ilMail::countMailsOfFolder ( int  $folderId)
Parameters
int$folderId
Returns
int

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

385 : int
386 {
387 $res = $this->db->queryF(
388 "SELECT COUNT(*) FROM {$this->table_mail} WHERE user_id = %s AND folder_id = %s",
389 ['integer', 'integer'],
390 [$this->user_id, $folderId]
391 );
392
393 return $this->db->numRows($res);
394 }
foreach($_POST as $key=> $value) $res

References $res.

◆ delegateExternalEmails()

ilMail::delegateExternalEmails ( string  $subject,
string  $message,
array  $attachments,
bool  $usePlaceholders,
array  $usrIdToExternalEmailAddressesMap,
array  $usrIdToMessageMap 
)
protected
Parameters
string$subject
string$message
array$attachments
bool$usePlaceholders
array$usrIdToExternalEmailAddressesMap
array$usrIdToMessageMap

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

950 : void {
951 if (1 === count($usrIdToExternalEmailAddressesMap)) {
952 if ($usePlaceholders) {
953 $message = array_values($usrIdToMessageMap)[0];
954 }
955
956 $usrIdToExternalEmailAddressesMap = array_values($usrIdToExternalEmailAddressesMap);
957 $firstAddresses = current($usrIdToExternalEmailAddressesMap);
958
959 $this->sendMimeMail(
960 implode(',', $firstAddresses),
961 '',
962 '',
963 $subject,
965 (array) $attachments
966 );
967 } elseif (count($usrIdToExternalEmailAddressesMap) > 1) {
968 if ($usePlaceholders) {
969 foreach ($usrIdToExternalEmailAddressesMap as $usrId => $addresses) {
970 if (0 === count($addresses)) {
971 continue;
972 }
973
974 $this->sendMimeMail(
975 implode(',', $addresses),
976 '',
977 '',
978 $subject,
979 $this->formatLinebreakMessage($usrIdToMessageMap[$usrId]),
980 (array) $attachments
981 );
982 }
983 } else {
984 $flattenEmailAddresses = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator(
985 $usrIdToExternalEmailAddressesMap
986 )), false);
987
988 $flattenEmailAddresses = array_unique($flattenEmailAddresses);
989
990 // https://mantis.ilias.de/view.php?id=23981 and https://www.ietf.org/rfc/rfc2822.txt
991 $remainingAddresses = '';
992 foreach ($flattenEmailAddresses as $emailAddress) {
993 $sep = '';
994 if (strlen($remainingAddresses) > 0) {
995 $sep = ',';
996 }
997
998 $recipientsLineLength = ilStr::strLen($remainingAddresses) + ilStr::strLen($sep . $emailAddress);
999 if ($recipientsLineLength >= $this->maxRecipientCharacterLength) {
1000 $this->sendMimeMail(
1001 '',
1002 '',
1003 $remainingAddresses,
1004 $subject,
1006 (array) $attachments
1007 );
1008
1009 $remainingAddresses = '';
1010 $sep = '';
1011 }
1012
1013 $remainingAddresses .= ($sep . $emailAddress);
1014 }
1015
1016 if ('' !== $remainingAddresses) {
1017 $this->sendMimeMail(
1018 '',
1019 '',
1020 $remainingAddresses,
1021 $subject,
1023 (array) $attachments
1024 );
1025 }
1026 }
1027 }
1028 }
sendMimeMail(string $to, string $cc, string $bcc, $subject, $message, array $attachments)
formatLinebreakMessage(string $message)
static strLen($a_string)
Definition: class.ilStr.php:78
$message
Definition: xapiexit.php:14

References $message.

◆ deleteMails()

ilMail::deleteMails ( array  $mailIds)
Parameters
int[]$mailIds

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

497 : void
498 {
499 $mailIds = array_filter(array_map('intval', $mailIds));
500 foreach ($mailIds as $id) {
501 $this->db->manipulateF(
502 "DELETE FROM {$this->table_mail} WHERE user_id = %s AND mail_id = %s",
503 ['integer', 'integer'],
504 [$this->user_id, $id]
505 );
506 $this->mfile->deassignAttachmentFromDirectory($id);
507 }
508 }

Referenced by deleteMailsOfFolder().

+ Here is the caller graph for this function:

◆ deleteMailsOfFolder()

ilMail::deleteMailsOfFolder ( int  $folderId)
Parameters
int$folderId

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

399 : void
400 {
401 $mails = $this->getMailsOfFolder($folderId);
402 foreach ($mails as $mail_data) {
403 $this->deleteMails([$mail_data['mail_id']]);
404 }
405 }
deleteMails(array $mailIds)
getMailsOfFolder($a_folder_id, $filter=[])

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

+ Here is the call graph for this function:

◆ distributeMail()

ilMail::distributeMail ( string  $to,
string  $cc,
string  $bcc,
string  $subject,
string  $message,
array  $attachments,
int  $sentMailId,
bool  $usePlaceholders = false 
)
protected
Parameters
string$to
string$cc
string$bcc
string$subject
string$message
array$attachments
int$sentMailId
bool$usePlaceholders
Returns
bool

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

747 : bool {
748 if ($usePlaceholders) {
749 $toUsrIds = $this->getUserIds([$to]);
750 $this->logger->debug(sprintf(
751 "Parsed TO user ids from given recipients for serial letter notification: %s",
752 implode(', ', $toUsrIds)
753 ));
754
755 $this->sendChanneledMails(
756 $to,
757 $cc,
758 $bcc,
759 $toUsrIds,
760 $subject,
761 $message,
762 $attachments,
763 $sentMailId,
764 true
765 );
766
767 $otherUsrIds = $this->getUserIds([$cc, $bcc]);
768 $this->logger->debug(sprintf(
769 "Parsed CC/BCC user ids from given recipients for serial letter notification: %s",
770 implode(', ', $otherUsrIds)
771 ));
772
773 $this->sendChanneledMails(
774 $to,
775 $cc,
776 $bcc,
777 $otherUsrIds,
778 $subject,
779 $this->replacePlaceholders($message, 0, false),
780 $attachments,
781 $sentMailId,
782 false
783 );
784 } else {
785 $usrIds = $this->getUserIds([$to, $cc, $bcc]);
786 $this->logger->debug(sprintf(
787 "Parsed TO/CC/BCC user ids from given recipients: %s",
788 implode(', ', $usrIds)
789 ));
790
791 $this->sendChanneledMails(
792 $to,
793 $cc,
794 $bcc,
795 $usrIds,
796 $subject,
797 $message,
798 $attachments,
799 $sentMailId,
800 false
801 );
802 }
803
804 return true;
805 }
replacePlaceholders(string $message, int $usrId=0, bool $replaceEmptyPlaceholders=true)
getUserIds(array $recipients)
sendChanneledMails(string $to, string $cc, string $bcc, array $usrIds, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)

References $message.

◆ enqueue()

ilMail::enqueue (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_subject,
  $a_m_message,
  $a_attachment,
  $a_use_placeholders = 0 
)

Should be used to enqueue a 'mail'.

A validation is executed before, errors are returned

Parameters
string$a_rcp_to
string$a_rcp_cc
string$a_rcp_bcc
string$a_m_subject
string$a_m_message
array$a_attachment
bool | int$a_use_placeholders
Returns
ilMailError[]

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

1212 : array {
1213 global $DIC;
1214
1215 $this->logger->info(
1216 "New mail system task:" .
1217 " To: " . $a_rcp_to .
1218 " | CC: " . $a_rcp_cc .
1219 " | BCC: " . $a_rcp_bcc .
1220 " | Subject: " . $a_m_subject .
1221 " | Attachments: " . print_r($a_attachment, true)
1222 );
1223
1224 if ($a_attachment && !$this->mfile->checkFilesExist($a_attachment)) {
1225 return [new ilMailError('mail_attachment_file_not_exist', [$a_attachment])];
1226 }
1227
1228 $errors = $this->checkMail((string) $a_rcp_to, (string) $a_rcp_cc, (string) $a_rcp_bcc, (string) $a_m_subject);
1229 if (count($errors) > 0) {
1230 return $errors;
1231 }
1232
1233 $errors = $this->validateRecipients((string) $a_rcp_to, (string) $a_rcp_cc, (string) $a_rcp_bcc);
1234 if (count($errors) > 0) {
1235 return $errors;
1236 }
1237
1238 $rcp_to = $a_rcp_to;
1239 $rcp_cc = $a_rcp_cc;
1240 $rcp_bcc = $a_rcp_bcc;
1241
1242 if (null === $rcp_cc) {
1243 $rcp_cc = '';
1244 }
1245
1246 if (null === $rcp_bcc) {
1247 $rcp_bcc = '';
1248 }
1249
1250 $numberOfExternalAddresses = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bcc, true);
1251 if (
1252 $numberOfExternalAddresses > 0 &&
1253 !$this->isSystemMail() &&
1254 !$DIC->rbac()->system()->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id)
1255 ) {
1256 return [new ilMailError('mail_no_permissions_write_smtp')];
1257 }
1258
1259 if ($this->appendInstallationSignature()) {
1260 $a_m_message .= self::_getInstallationSignature();
1261 }
1262
1264 return $this->sendMail(
1265 (string) $rcp_to,
1266 (string) $rcp_cc,
1267 (string) $rcp_bcc,
1268 (string) $a_m_subject,
1269 (string) $a_m_message,
1270 (array) $a_attachment,
1271 (bool) $a_use_placeholders
1272 );
1273 }
1274
1275 $taskFactory = $DIC->backgroundTasks()->taskFactory();
1276 $taskManager = $DIC->backgroundTasks()->taskManager();
1277
1278 $bucket = new BasicBucket();
1279 $bucket->setUserId($this->user_id);
1280
1281 $task = $taskFactory->createTask(ilMailDeliveryJob::class, [
1282 (int) $this->user_id,
1283 (string) $rcp_to,
1284 (string) $rcp_cc,
1285 (string) $rcp_bcc,
1286 (string) $a_m_subject,
1287 (string) $a_m_message,
1288 (string) serialize($a_attachment),
1289 (bool) $a_use_placeholders,
1290 (bool) $this->getSaveInSentbox(),
1291 (string) $this->contextId,
1292 (string) serialize($this->contextParameters)
1293 ]);
1294 $interaction = $taskFactory->createTask(ilMailDeliveryJobUserInteraction::class, [
1295 $task,
1296 (int) $this->user_id
1297 ]);
1298
1299 $bucket->setTask($interaction);
1300 $bucket->setTitle($this->lng->txt('mail_bg_task_title'));
1301 $bucket->setDescription(sprintf($this->lng->txt('mail_bg_task_desc'), $a_m_subject));
1302
1303 $this->logger->info('Delegated delivery to background task');
1304 $taskManager->run($bucket);
1305
1306 return [];
1307 }
const CONTEXT_CRON
static getType()
Get context type.
isSystemMail()
validateRecipients(string $to, string $cc, string $bcc)
static _getInstallationSignature()
checkMail(string $to, string $cc, string $bcc, string $subject)
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...
getCountRecipients(string $toRecipients, string $ccRecipients, string $bccRecipients, $onlyExternalAddresses=true)
getSaveInSentbox()

◆ existsRecipient()

ilMail::existsRecipient ( string  $newRecipient,
string  $existingRecipients 
)
Parameters
string$newRecipient
string$existingRecipients
Returns
bool

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

215 : bool
216 {
217 $newAddresses = new ilMailAddressListImpl($this->parseAddresses($newRecipient));
218 $addresses = new ilMailAddressListImpl($this->parseAddresses($existingRecipients));
219
220 $list = new ilMailDiffAddressList($newAddresses, $addresses);
221
222 $diffedAddresses = $list->value();
223
224 return count($diffedAddresses) === 0;
225 }
Class ilMailAddressListImpl.
Class ilMailDiffAddressList.

References parseAddresses().

+ Here is the call graph for this function:

◆ fetchMailData()

ilMail::fetchMailData ( ?array  $row)
protected
Parameters
array | null$row
Returns
array|null

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

514 : ?array
515 {
516 if (!is_array($row) || empty($row)) {
517 return null;
518 }
519
520 $row['attachments'] = unserialize(stripslashes($row['attachments']));
521 $row['tpl_ctx_params'] = (array) (@json_decode($row['tpl_ctx_params'], true));
522
523 return $row;
524 }

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

+ Here is the caller graph for this function:

◆ formatLinebreakMessage()

ilMail::formatLinebreakMessage ( string  $message)

Reimplemented in ilFormatMail.

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

1748 : string
1749 {
1750 return $message;
1751 }

References $message.

◆ formatNamesForOutput()

ilMail::formatNamesForOutput ( string  $recipients)

Prepends the full name of each ILIAS login name (if user has a public profile) found in the passed string and brackets the ILIAS login name afterwards.

Parameters
string$recipientsA string containing to, cc or bcc recipients
Returns
string

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

265 : string
266 {
267 global $DIC;
268
269 $recipients = trim($recipients);
270 if (0 === strlen($recipients)) {
271 return $this->lng->txt('not_available');
272 }
273
274 $names = [];
275
276 $recipients = array_filter(array_map('trim', explode(',', $recipients)));
277 foreach ($recipients as $recipient) {
278 $usrId = ilObjUser::_lookupId($recipient);
279 if ($usrId > 0) {
280 $pp = ilObjUser::_lookupPref($usrId, 'public_profile');
281 if ($pp === 'g' || ($pp === 'y' && !$DIC->user()->isAnonymous())) {
282 $user = $this->getUserInstanceById($usrId);
283 if ($user) {
284 $names[] = $user->getFullname() . ' [' . $recipient . ']';
285 continue;
286 }
287 }
288 }
289
290 $names[] = $recipient;
291 }
292
293 return implode(', ', $names);
294 }
getUserInstanceById(int $usrId)
static _lookupPref($a_usr_id, $a_keyword)

References $DIC, ilObjUser\_lookupId(), ilObjUser\_lookupPref(), and getUserInstanceById().

+ Here is the call graph for this function:

◆ getCountRecipient()

ilMail::getCountRecipient ( string  $recipients,
  $onlyExternalAddresses = true 
)
protected
Parameters
string$recipients
bool$onlyExternalAddresses
Returns
int

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

1542 : int
1543 {
1544 $addresses = new ilMailAddressListImpl($this->parseAddresses($recipients));
1545 if ($onlyExternalAddresses) {
1546 $addresses = new ilMailOnlyExternalAddressList(
1547 $addresses,
1548 self::ILIAS_HOST,
1549 $this->usrIdByLoginCallable
1550 );
1551 }
1552
1553 return count($addresses->value());
1554 }
Class ilMailOnlyExternalAddressList.

◆ getCountRecipients()

ilMail::getCountRecipients ( string  $toRecipients,
string  $ccRecipients,
string  $bccRecipients,
  $onlyExternalAddresses = true 
)
protected
Parameters
string$toRecipients
string$ccRecipients
$bccRecipients
bool$onlyExternalAddresses
Returns
int

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

1568 : int {
1569 return (
1570 $this->getCountRecipient($toRecipients, $onlyExternalAddresses) +
1571 $this->getCountRecipient($ccRecipients, $onlyExternalAddresses) +
1572 $this->getCountRecipient($bccRecipients, $onlyExternalAddresses)
1573 );
1574 }
getCountRecipient(string $recipients, $onlyExternalAddresses=true)

◆ getEmailRecipients()

ilMail::getEmailRecipients ( string  $recipients)
protected
Parameters
string$recipients
Returns
string

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

1580 : string
1581 {
1582 $addresses = new ilMailOnlyExternalAddressList(
1583 new ilMailAddressListImpl($this->parseAddresses($recipients)),
1584 self::ILIAS_HOST,
1585 $this->usrIdByLoginCallable
1586 );
1587
1588 $emailRecipients = array_map(function (ilMailAddress $address) {
1589 return (string) $address;
1590 }, $addresses->value());
1591
1592 return implode(',', $emailRecipients);
1593 }
Class ilMailAddress.

◆ getMail()

ilMail::getMail ( int  $mailId)
Parameters
int$mailId
Returns
array|null

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

411 : ?array
412 {
413 $res = $this->db->queryF(
414 "SELECT * FROM {$this->table_mail} WHERE user_id = %s AND mail_id = %s",
415 ['integer', 'integer'],
416 [$this->user_id, $mailId]
417 );
418
419 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
420
421 return $this->mail_data;
422 }
fetchMailData(?array $row)

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

+ Here is the call graph for this function:

◆ getMailObjectReferenceId()

ilMail::getMailObjectReferenceId ( )
Returns
int

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

254 : int
255 {
257 }
$mail_obj_ref_id

References $mail_obj_ref_id.

◆ getMailOptionsByUserId()

ilMail::getMailOptionsByUserId ( int  $usrId)
protected
Parameters
int$usrId
Returns
ilMailOptions

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

1728 {
1729 if (!isset($this->mailOptionsByUsrIdMap[$usrId])) {
1730 $this->mailOptionsByUsrIdMap[$usrId] = new ilMailOptions($usrId);
1731 }
1732
1733 return $this->mailOptionsByUsrIdMap[$usrId];
1734 }

◆ getMailsOfFolder()

ilMail::getMailsOfFolder (   $a_folder_id,
  $filter = [] 
)
Parameters
int$a_folder_idThe id of the folder
array$filterAn optional filter array
Returns
array

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

351 : array
352 {
353 $mails = [];
354
355 $query =
356 "SELECT sender_id, m_subject, mail_id, m_status, send_time " .
357 "FROM {$this->table_mail} " .
358 "LEFT JOIN object_data ON obj_id = sender_id " .
359 "WHERE user_id = %s AND folder_id = %s " .
360 "AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL))";
361
362 if (isset($filter['status']) && strlen($filter['status']) > 0) {
363 $query .= ' AND m_status = ' . $this->db->quote($filter['status'], 'text');
364 }
365
366 $query .= " ORDER BY send_time DESC";
367
368 $res = $this->db->queryF(
369 $query,
370 ['integer', 'integer'],
371 [$this->user_id, $a_folder_id]
372 );
373
374 while ($row = $this->db->fetchAssoc($res)) {
375 $mails[] = $this->fetchMailData($row);
376 }
377
378 return array_filter($mails);
379 }
$query

References $query, $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  $usrId,
int  $folderId 
)
Parameters
int$usrId
int$folderId
Returns
int

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

531 : int
532 {
533 $nextId = (int) $this->db->nextId($this->table_mail);
534 $this->db->insert($this->table_mail, [
535 'mail_id' => ['integer', $nextId],
536 'user_id' => ['integer', $usrId],
537 'folder_id' => ['integer', $folderId],
538 'sender_id' => ['integer', $usrId]
539 ]);
540
541 return $nextId;
542 }

◆ getNextMail()

ilMail::getNextMail ( int  $mailId)
Parameters
int$mailId
Returns
array|null

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

325 : ?array
326 {
327 $this->db->setLimit(1, 0);
328
329 $query = implode(' ', [
330 "SELECT b.* FROM {$this->table_mail} a",
331 "INNER JOIN {$this->table_mail} b ON b.folder_id = a.folder_id",
332 'AND b.user_id = a.user_id AND b.send_time < a.send_time',
333 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
334 ]);
335 $res = $this->db->queryF(
336 $query,
337 ['integer', 'integer'],
338 [$this->user_id, $mailId]
339 );
340
341 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
342
343 return $this->mail_data;
344 }

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

+ Here is the call graph for this function:

◆ getPreviousMail()

ilMail::getPreviousMail ( int  $mailId)
Parameters
int$mailId
Returns
array|null

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

300 : ?array
301 {
302 $this->db->setLimit(1, 0);
303
304 $query = implode(' ', [
305 "SELECT b.* FROM {$this->table_mail} a",
306 "INNER JOIN {$this->table_mail} b ON b.folder_id = a.folder_id",
307 'AND b.user_id = a.user_id AND b.send_time > a.send_time',
308 'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
309 ]);
310 $res = $this->db->queryF(
311 $query,
312 ['integer', 'integer'],
313 [$this->user_id, $mailId]
314 );
315
316 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
317
318 return $this->mail_data;
319 }

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

+ Here is the call graph for this function:

◆ getSalutation()

static ilMail::getSalutation (   $a_usr_id,
ilLanguage  $a_language = null 
)
static
Parameters
int$a_usr_id
$a_languageilLanguage|null
Returns
string

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

1677 : string
1678 {
1679 global $DIC;
1680
1681 $lang = ($a_language instanceof ilLanguage) ? $a_language : $DIC->language();
1682 $lang->loadLanguageModule('mail');
1683
1684 $gender = ilObjUser::_lookupGender($a_usr_id);
1685 $gender = $gender ? $gender : 'n';
1686 $name = ilObjUser::_lookupName($a_usr_id);
1687
1688 if (!strlen($name['firstname'])) {
1689 return $lang->txt('mail_salutation_anonymous') . ',';
1690 }
1691
1692 return
1693 $lang->txt('mail_salutation_' . $gender) . ' ' .
1694 ($name['title'] ? $name['title'] . ' ' : '') .
1695 ($name['firstname'] ? $name['firstname'] . ' ' : '') .
1696 $name['lastname'] . ',';
1697 }
static _lookupGender($a_user_id)
Lookup gender.
static _lookupName($a_user_id)
lookup user name
if($format !==null) $name
Definition: metadata.php:230

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

Referenced by ilTestManScoringParticipantNotification\buildBody(), ilSystemNotification\compose(), ilForumMailNotification\createMail(), ilForumMailEventNotificationSender\createMailBodyText(), ilSessionMembershipMailNotification\send(), ilCourseMembershipMailNotification\send(), ilExerciseMailNotification\send(), ilGroupMembershipMailNotification\send(), ilIndividualAssessmentPrimitiveInternalNotificator\send(), ilLMMailNotification\send(), ilLearningSequenceMembershipMailNotification\send(), ilCalendarMailNotification\send(), ilBuddySystemNotification\send(), ilMailCronOrphanedMailsNotification\send(), ilRegistrationMailNotification\send(), ilTestMailNotification\sendAdvancedNotification(), and ilTestMailNotification\sendSimpleNotification().

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

◆ getSavedData()

ilMail::getSavedData ( )
Returns
array|null

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

1180 : ?array
1181 {
1182 $res = $this->db->queryF(
1183 "SELECT * FROM {$this->table_mail_saved} WHERE user_id = %s",
1184 ['integer'],
1185 [$this->user_id]
1186 );
1187
1188 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
1189
1190 return $this->mail_data;
1191 }

References $res.

◆ getSaveInSentbox()

ilMail::getSaveInSentbox ( )
Returns
bool

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

238 : bool
239 {
240 return (bool) $this->save_in_sentbox;
241 }
$save_in_sentbox

References $save_in_sentbox.

◆ getUserIds()

ilMail::getUserIds ( array  $recipients)
protected
Parameters
string[]$recipients
Returns
int[]

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

1034 : array
1035 {
1036 $usrIds = array();
1037
1038 $joinedRecipients = implode(',', array_filter(array_map('trim', $recipients)));
1039
1040 $addresses = $this->parseAddresses($joinedRecipients);
1041 foreach ($addresses as $address) {
1042 $addressType = $this->mailAddressTypeFactory->getByPrefix($address);
1043 $usrIds = array_merge($usrIds, $addressType->resolve());
1044 }
1045
1046 return array_unique($usrIds);
1047 }

◆ getUserInstanceById()

ilMail::getUserInstanceById ( int  $usrId)
protected

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

1699 : ?ilObjUser
1700 {
1701 if (!array_key_exists($usrId, $this->userInstancesByIdMap)) {
1702 try {
1703 $user = new ilObjUser($usrId);
1704 } catch (Exception $e) {
1705 $user = null;
1706 }
1707
1708 $this->userInstancesByIdMap[$usrId] = $user;
1709 }
1710
1711 return $this->userInstancesByIdMap[$usrId];
1712 }

References Vendor\Package\$e.

Referenced by formatNamesForOutput().

+ Here is the caller graph for this function:

◆ isSystemMail()

ilMail::isSystemMail ( )
protected
Returns
bool

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

205 : bool
206 {
207 return $this->user_id == ANONYMOUS_USER_ID;
208 }
const ANONYMOUS_USER_ID
Definition: constants.php:25

References ANONYMOUS_USER_ID.

◆ markRead()

ilMail::markRead ( array  $mailIds)
Parameters
int[]$mailIds

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

427 : void
428 {
429 $values = [];
430 $types = [];
431
432 $query = "UPDATE {$this->table_mail} SET m_status = %s WHERE user_id = %s ";
433 array_push($types, 'text', 'integer');
434 array_push($values, 'read', $this->user_id);
435
436 if (count($mailIds) > 0) {
437 $query .= ' AND ' . $this->db->in('mail_id', $mailIds, false, 'integer');
438 }
439
440 $this->db->manipulateF($query, $types, $values);
441 }

References $query.

◆ markUnread()

ilMail::markUnread ( array  $mailIds)
Parameters
int[]$mailIds

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

446 : void
447 {
448 $values = array();
449 $types = array();
450
451 $query = "UPDATE {$this->table_mail} SET m_status = %s WHERE user_id = %s ";
452 array_push($types, 'text', 'integer');
453 array_push($values, 'unread', $this->user_id);
454
455 if (count($mailIds) > 0) {
456 $query .= ' AND ' . $this->db->in('mail_id', $mailIds, false, 'integer');
457 }
458
459 $this->db->manipulateF($query, $types, $values);
460 }

References $query.

◆ moveMailsToFolder()

ilMail::moveMailsToFolder ( array  $mailIds,
int  $folderId 
)
Parameters
int[]$mailIds
int$folderId
Returns
bool

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

467 : bool
468 {
469 $values = [];
470 $types = [];
471
472 $mailIds = array_filter(array_map('intval', $mailIds));
473
474 if (0 === count($mailIds)) {
475 return false;
476 }
477
478 $query =
479 "UPDATE {$this->table_mail} " .
480 "INNER JOIN mail_obj_data " .
481 "ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s " .
482 "SET {$this->table_mail}.folder_id = mail_obj_data.obj_id " .
483 "WHERE {$this->table_mail}.user_id = %s";
484 array_push($types, 'integer', 'integer', 'integer');
485 array_push($values, $folderId, $this->user_id, $this->user_id);
486
487 $query .= ' AND ' . $this->db->in('mail_id', $mailIds, false, 'integer');
488
489 $affectedRows = $this->db->manipulateF($query, $types, $values);
490
491 return $affectedRows > 0;
492 }

References $query.

◆ parseAddresses()

ilMail::parseAddresses (   $addresses)
protected

Explode recipient string, allowed separators are ',' ';' ' ' Returns an array with recipient ilMailAddress instances.

Parameters
string$addresses
Returns
ilMailAddress[] An array with objects of type ilMailAddress

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

1513 : array
1514 {
1515 if (strlen($addresses) > 0) {
1516 $this->logger->debug(sprintf(
1517 "Started parsing of recipient string: %s",
1518 $addresses
1519 ));
1520 }
1521
1522 $parser = $this->mailAddressParserFactory->getParser((string) $addresses);
1523 $parsedAddresses = $parser->parse();
1524
1525 if (strlen($addresses) > 0) {
1526 $this->logger->debug(sprintf(
1527 "Parsed addresses: %s",
1528 implode(',', array_map(function (ilMailAddress $address) {
1529 return (string) $address;
1530 }, $parsedAddresses))
1531 ));
1532 }
1533
1534 return $parsedAddresses;
1535 }

Referenced by existsRecipient().

+ Here is the caller graph for this function:

◆ readMailObjectReferenceId()

ilMail::readMailObjectReferenceId ( )
protected

Read and set the mail object ref id (administration node)

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

246 : void
247 {
248 $this->mail_obj_ref_id = (int) ilMailGlobalServices::getMailObjectRefId();
249 }
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.

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  $usrId = 0,
bool  $replaceEmptyPlaceholders = true 
)
protected
Parameters
string$message
int$usrId
boolean$replaceEmptyPlaceholders
Returns
string

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

708 : string {
709 try {
710 if ($this->contextId) {
712 } else {
714 }
715
716 $user = $usrId > 0 ? $this->getUserInstanceById($usrId) : null;
717
719 $message = $processor->resolve($user, $this->contextParameters, $replaceEmptyPlaceholders);
720 } catch (Exception $e) {
721 $this->logger->error(__METHOD__ . ' has been called with invalid context.');
722 }
723
724 return $message;
725 }
Class ilMailTemplatePlaceholderResolver.
$context
Definition: webdav.php:26

References $context, and ilMailTemplateContextService\getTemplateContextById().

Referenced by sendInternalMail().

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

◆ saveAttachments()

ilMail::saveAttachments ( array  $attachments)
Parameters
string[]$attachmentsAn array of attachments

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

1494 : void
1495 {
1496 $this->db->update(
1497 $this->table_mail_saved,
1498 [
1499 'attachments' => ['clob', serialize($attachments)]
1500 ],
1501 [
1502 'user_id' => ['integer', $this->user_id]
1503 ]
1504 );
1505 }

◆ saveInSentbox()

ilMail::saveInSentbox ( array  $attachment,
string  $to,
string  $cc,
string  $bcc,
string  $subject,
string  $message 
)
protected

Stores a message in the sent bod of the current user.

Parameters
array$attachment
string$to
string$cc
string$bcc
string$subject
string$message
Returns
int mail id

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

1438 : int {
1439 return $this->sendInternalMail(
1440 $this->mailbox->getSentFolder(),
1441 $this->user_id,
1442 $attachment,
1443 $to,
1444 $cc,
1445 $bcc,
1446 'read',
1447 0,
1448 $subject,
1449 $message,
1450 $this->user_id,
1451 0
1452 );
1453 }
sendInternalMail( $folderId, $senderUsrId, $attachments, $to, $cc, $bcc, $status, $email, $subject, $message, $usrId=0, $usePlaceholders=0, $templateContextId=null, $templateContextParameters=[])

◆ savePostData()

ilMail::savePostData (   $a_user_id,
  $a_attachments,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_email,
  $a_m_subject,
  $a_m_message,
  $a_use_placeholders,
  $a_tpl_context_id = null,
  $a_tpl_ctx_params = array() 
)

save post data in table @access public

Parameters
int$a_user_id
array$a_attachments
string$a_rcp_to
string$a_rcp_cc
string$a_rcp_bcc
int$a_m_email
string$a_m_subject
string$a_m_message
int$a_use_placeholders
string | null$a_tpl_context_id
array | null$a_tpl_ctx_params
Returns
bool

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

1130 {
1131 if (!$a_attachments) {
1132 $a_attachments = null;
1133 }
1134 if (!$a_rcp_to) {
1135 $a_rcp_to = null;
1136 }
1137 if (!$a_rcp_cc) {
1138 $a_rcp_cc = null;
1139 }
1140 if (!$a_rcp_bcc) {
1141 $a_rcp_bcc = null;
1142 }
1143 if (!$a_m_email) {
1144 $a_m_email = null;
1145 }
1146 if (!$a_m_message) {
1147 $a_m_message = null;
1148 }
1149 if (!$a_use_placeholders) {
1150 $a_use_placeholders = '0';
1151 }
1152
1153 $this->db->replace(
1154 $this->table_mail_saved,
1155 [
1156 'user_id' => ['integer', $this->user_id]
1157 ],
1158 [
1159 'attachments' => ['clob', serialize($a_attachments)],
1160 'rcp_to' => ['clob', $a_rcp_to],
1161 'rcp_cc' => ['clob', $a_rcp_cc],
1162 'rcp_bcc' => ['clob', $a_rcp_bcc],
1163 'm_email' => ['integer', $a_m_email],
1164 'm_subject' => ['text', $a_m_subject],
1165 'm_message' => ['clob', $a_m_message],
1166 'use_placeholders' => ['integer', $a_use_placeholders],
1167 'tpl_ctx_id' => ['text', $a_tpl_context_id],
1168 'tpl_ctx_params' => ['blob', json_encode((array) $a_tpl_ctx_params)]
1169 ]
1170 );
1171
1172 $this->getSavedData();
1173
1174 return true;
1175 }

◆ sendChanneledMails()

ilMail::sendChanneledMails ( string  $to,
string  $cc,
string  $bcc,
array  $usrIds,
string  $subject,
string  $message,
array  $attachments,
int  $sentMailId,
bool  $usePlaceholders = false 
)
protected
Parameters
string$to
string$cc
string$bcc
array$usrIds
string$subject
string$message
array$attachments
int$sentMailId
bool$usePlaceholders

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

828 : void {
829 $usrIdToExternalEmailAddressesMap = [];
830 $usrIdToMessageMap = [];
831
832 foreach ($usrIds as $usrId) {
833 $user = $this->getUserInstanceById($usrId);
834 if (!($user instanceof ilObjUser)) {
835 $this->logger->critical(sprintf(
836 "Skipped recipient with id %s (User not found)",
837 $usrId
838 ));
839 continue;
840 }
841
842 $mailOptions = $this->getMailOptionsByUserId($user->getId());
843
844 $canReadInternalMails = !$user->hasToAcceptTermsOfService() && $user->checkTimeLimit();
845
846 if ($this->isSystemMail() && !$canReadInternalMails) {
847 $this->logger->debug(sprintf(
848 "Skipped recipient with id %s (Accepted User Agreement:%s|Expired Account:%s)",
849 $usrId,
850 var_export(!$user->hasToAcceptTermsOfService(), true),
851 var_export(!$user->checkTimeLimit(), true)
852 ));
853 continue;
854 }
855
856 $individualMessage = $message;
857 if ($usePlaceholders) {
858 $individualMessage = $this->replacePlaceholders($message, $user->getId());
859 $usrIdToMessageMap[$user->getId()] = $individualMessage;
860 }
861
862 if ($user->getActive()) {
863 $wantsToReceiveExternalEmail = (
864 $mailOptions->getIncomingType() == ilMailOptions::INCOMING_EMAIL ||
865 $mailOptions->getIncomingType() == ilMailOptions::INCOMING_BOTH
866 );
867
868 if (!$canReadInternalMails || $wantsToReceiveExternalEmail) {
869 $emailAddresses = $mailOptions->getExternalEmailAddresses();
870 $usrIdToExternalEmailAddressesMap[$user->getId()] = $emailAddresses;
871
872 if ($mailOptions->getIncomingType() == ilMailOptions::INCOMING_EMAIL) {
873 $this->logger->debug(sprintf(
874 "Recipient with id %s will only receive external emails sent to: %s",
875 $user->getId(),
876 implode(', ', $emailAddresses)
877 ));
878 continue;
879 } else {
880 $this->logger->debug(sprintf(
881 "Recipient with id %s will additionally receive external emails " .
882 "(because the user wants to receive it externally, or the user cannot access " .
883 "the internal mail system) sent to: %s",
884 $user->getId(),
885 implode(', ', $emailAddresses)
886 ));
887 }
888 } else {
889 $this->logger->debug(sprintf(
890 "Recipient with id %s is does not want to receive external emails",
891 $user->getId()
892 ));
893 }
894 } else {
895 $this->logger->debug(sprintf(
896 "Recipient with id %s is inactive and will not receive external emails",
897 $user->getId()
898 ));
899 }
900
901 $mbox = clone $this->mailbox;
902 $mbox->setUsrId((int) $user->getId());
903 $recipientInboxId = $mbox->getInboxFolder();
904
905 $internalMailId = $this->sendInternalMail(
906 $recipientInboxId,
907 $this->user_id,
908 $attachments,
909 $to,
910 $cc,
911 '',
912 'unread',
913 0,
914 $subject,
915 $individualMessage,
916 $user->getId(),
917 0
918 );
919
920 if (count($attachments) > 0) {
921 $this->mfile->assignAttachmentsToDirectory($internalMailId, $sentMailId);
922 }
923 }
924
926 $subject,
927 $message,
928 $attachments,
929 $usePlaceholders,
930 $usrIdToExternalEmailAddressesMap,
931 $usrIdToMessageMap
932 );
933 }
delegateExternalEmails(string $subject, string $message, array $attachments, bool $usePlaceholders, array $usrIdToExternalEmailAddressesMap, array $usrIdToMessageMap)
getMailOptionsByUserId(int $usrId)

References $message, ilMailOptions\INCOMING_BOTH, and ilMailOptions\INCOMING_EMAIL.

◆ sendInternalMail()

ilMail::sendInternalMail (   $folderId,
  $senderUsrId,
  $attachments,
  $to,
  $cc,
  $bcc,
  $status,
  $email,
  $subject,
  $message,
  $usrId = 0,
  $usePlaceholders = 0,
  $templateContextId = null,
  $templateContextParameters = [] 
)
private
Parameters
integer$folderId
integer$senderUsrId
array$attachments
string$to
string$cc
string$bcc
string$status
integer$email
string$subject
string$message
integer$usrId
integer$usePlaceholders
string | null$templateContextId
array | null$templateContextParameters
Returns
int

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

615 : int {
616 $usrId = $usrId ? $usrId : $this->user_id;
617
618 if ($usePlaceholders) {
619 $message = $this->replacePlaceholders($message, $usrId);
620 }
621 $message = $this->formatLinebreakMessage((string) $message);
622 $message = str_ireplace(["<br />", "<br>", "<br/>"], "\n", $message);
623
624 if (!$usrId) {
625 $usrId = '0';
626 }
627 if (!$folderId) {
628 $folderId = '0';
629 }
630 if (!$senderUsrId) {
631 $senderUsrId = null;
632 }
633 if (!$attachments) {
634 $attachments = null;
635 }
636 if (!$to) {
637 $to = null;
638 }
639 if (!$cc) {
640 $cc = null;
641 }
642 if (!$bcc) {
643 $bcc = null;
644 }
645 if (!$status) {
646 $status = null;
647 }
648 if (!$email) {
649 $email = null;
650 }
651 if (!$subject) {
652 $subject = null;
653 }
654 if (!$message) {
655 $message = null;
656 }
657
658 $nextId = (int) $this->db->nextId($this->table_mail);
659 $this->db->insert($this->table_mail, array(
660 'mail_id' => array('integer', $nextId),
661 'user_id' => array('integer', $usrId),
662 'folder_id' => array('integer', $folderId),
663 'sender_id' => array('integer', $senderUsrId),
664 'attachments' => array('clob', serialize($attachments)),
665 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
666 'rcp_to' => array('clob', $to),
667 'rcp_cc' => array('clob', $cc),
668 'rcp_bcc' => array('clob', $bcc),
669 'm_status' => array('text', $status),
670 'm_email' => array('integer', $email),
671 'm_subject' => array('text', $subject),
672 'm_message' => array('clob', $message),
673 'tpl_ctx_id' => array('text', $templateContextId),
674 'tpl_ctx_params' => array('blob', @json_encode((array) $templateContextParameters))
675 ));
676
677 $raiseEvent = (int) $usrId !== $this->mailbox->getUsrId();
678 if (!$raiseEvent) {
679 $raiseEvent = (int) $folderId !== $this->mailbox->getSentFolder();
680 }
681
682 if ($raiseEvent) {
683 $this->eventHandler->raise('Services/Mail', 'sentInternalMail', [
684 'id' => $nextId,
685 'subject' => (string) $subject,
686 'body' => (string) $message,
687 'from_usr_id' => (int) $senderUsrId,
688 'to_usr_id' => (int) $usrId,
689 'rcp_to' => (string) $to,
690 'rcp_cc' => (string) $cc,
691 'rcp_bcc' => (string) $bcc,
692 ]);
693 }
694
695 return $nextId;
696 }
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:285

References $message, and replacePlaceholders().

+ Here is the call graph for this function:

◆ sendMail()

ilMail::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 consumer, please use \ilMail::enqueue.

Parameters
string$to
string$cc
string$bcc
string$subject
string$message
array$attachments
bool$usePlaceholders
Returns
ilMailError[]
See also
\ilMail::enqueue()

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

1331 : array {
1332 $internalMessageId = $this->saveInSentbox(
1333 $attachments,
1334 $to,
1335 $cc,
1336 $bcc,
1337 $subject,
1338 $message
1339 );
1340
1341 if (count($attachments) > 0) {
1342 $this->mfile->assignAttachmentsToDirectory($internalMessageId, $internalMessageId);
1343 $this->mfile->saveFiles($internalMessageId, $attachments);
1344 }
1345
1346 $numberOfExternalAddresses = $this->getCountRecipients($to, $cc, $bcc, true);
1347
1348 if ($numberOfExternalAddresses > 0) {
1349 $externalMailRecipientsTo = $this->getEmailRecipients($to);
1350 $externalMailRecipientsCc = $this->getEmailRecipients($cc);
1351 $externalMailRecipientsBcc = $this->getEmailRecipients($bcc);
1352
1353 $this->logger->debug(
1354 "Parsed external email addresses from given recipients /" .
1355 " To: " . $externalMailRecipientsTo .
1356 " | CC: " . $externalMailRecipientsCc .
1357 " | BCC: " . $externalMailRecipientsBcc .
1358 " | Subject: " . $subject
1359 );
1360
1361 $this->sendMimeMail(
1362 $externalMailRecipientsTo,
1363 $externalMailRecipientsCc,
1364 $externalMailRecipientsBcc,
1365 $subject,
1367 $usePlaceholders ? $this->replacePlaceholders($message, 0, false) : $message
1368 ),
1369 $attachments
1370 );
1371 } else {
1372 $this->logger->debug('No external email addresses given in recipient string');
1373 }
1374
1375 $errors = [];
1376
1377 if (!$this->distributeMail(
1378 $to,
1379 $cc,
1380 $bcc,
1381 $subject,
1382 $message,
1383 $attachments,
1384 $internalMessageId,
1385 $usePlaceholders
1386 )) {
1387 $errors['mail_send_error'] = new ilMailError('mail_send_error');
1388 }
1389
1390 if (!$this->getSaveInSentbox()) {
1391 $this->deleteMails([$internalMessageId]);
1392 }
1393
1394 return array_values($errors);
1395 }
distributeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
Stores a message in the sent bod of the current user.
getEmailRecipients(string $recipients)

◆ sendMimeMail()

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

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

1463 : void
1464 {
1465 $mailer = new ilMimeMail();
1466 $mailer->From($this->senderFactory->getSenderByUsrId((int) $this->user_id));
1467 $mailer->To($to);
1468 $mailer->Subject($subject, true, (string) ($this->contextParameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ?? ''));
1469 $mailer->Body($message);
1470
1471 if ($cc) {
1472 $mailer->Cc($cc);
1473 }
1474
1475 if ($bcc) {
1476 $mailer->Bcc($bcc);
1477 }
1478
1479 foreach ($attachments as $attachment) {
1480 $mailer->Attach(
1481 $this->mfile->getAbsoluteAttachmentPoolPathByFilename($attachment),
1482 '',
1483 'inline',
1484 $attachment
1485 );
1486 }
1487
1488 $mailer->Send();
1489 }
Class ilMimeMail.

References $message.

◆ setMailOptionsByUserIdMap()

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

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

1740 : void
1741 {
1742 $this->mailOptionsByUsrIdMap = $mailOptionsByUsrIdMap;
1743 }
$mailOptionsByUsrIdMap

◆ setSaveInSentbox()

ilMail::setSaveInSentbox ( bool  $saveInSentbox)
Parameters
bool$saveInSentbox

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

230 : void
231 {
232 $this->save_in_sentbox = (bool) $saveInSentbox;
233 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUserInstanceById()

ilMail::setUserInstanceById ( array  $userInstanceByIdMap)
Parameters
ilObjUser[]$userInstanceByIdMap

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

1718 : void
1719 {
1720 $this->userInstancesByIdMap = $userInstanceByIdMap;
1721 }

◆ updateDraft()

ilMail::updateDraft (   $a_folder_id,
  $a_attachments,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_email,
  $a_m_subject,
  $a_m_message,
  $a_draft_id = 0,
  $a_use_placeholders = 0,
  $a_tpl_context_id = null,
  $a_tpl_context_params = [] 
)

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

557 {
558 $this->db->update(
559 $this->table_mail,
560 [
561 'folder_id' => ['integer', $a_folder_id],
562 'attachments' => ['clob', serialize($a_attachments)],
563 'send_time' => ['timestamp', date('Y-m-d H:i:s', time())],
564 'rcp_to' => ['clob', $a_rcp_to],
565 'rcp_cc' => ['clob', $a_rcp_cc],
566 'rcp_bcc' => ['clob', $a_rcp_bcc],
567 'm_status' => ['text', 'read'],
568 'm_email' => ['integer', $a_m_email],
569 'm_subject' => ['text', $a_m_subject],
570 'm_message' => ['clob', $a_m_message],
571 'use_placeholders' => ['integer', $a_use_placeholders],
572 'tpl_ctx_id' => ['text', $a_tpl_context_id],
573 'tpl_ctx_params' => ['blob', @json_encode((array) $a_tpl_context_params)]
574 ],
575 [
576 'mail_id' => ['integer', $a_draft_id]
577 ]
578 );
579
580 return $a_draft_id;
581 }

◆ validateRecipients()

ilMail::validateRecipients ( string  $to,
string  $cc,
string  $bcc 
)
Parameters
string$to
string$cc
string$bcc
Returns
ilMailError[] An array of errors determined on validation

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

1403 : array
1404 {
1405 try {
1406 $errors = [];
1407 $errors = array_merge($errors, $this->checkRecipients($to));
1408 $errors = array_merge($errors, $this->checkRecipients($cc));
1409 $errors = array_merge($errors, $this->checkRecipients($bcc));
1410
1411 if (count($errors) > 0) {
1412 return array_merge([new ilMailError('mail_following_rcp_not_valid')], $errors);
1413 }
1414 } catch (ilMailException $e) {
1415 return [new ilMailError('mail_generic_rcp_error', [$e->getMessage()])];
1416 }
1417
1418 return [];
1419 }
checkRecipients(string $recipients)
Check if recipients are valid.

References Vendor\Package\$e, and $errors.

◆ withContextId()

ilMail::withContextId ( string  $contextId)
Parameters
string$contextId
Returns
ilMail

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

180 : self
181 {
182 $clone = clone $this;
183
184 $clone->contextId = $contextId;
185
186 return $clone;
187 }

References $contextId.

◆ withContextParameters()

ilMail::withContextParameters ( array  $parameters)
Parameters
array$parameters
Returns
ilMail

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

193 : self
194 {
195 $clone = clone $this;
196
197 $clone->contextParameters = $parameters;
198
199 return $clone;
200 }

Field Documentation

◆ $appendInstallationSignature

ilMail::$appendInstallationSignature = false
protected

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

◆ $contextId

ilMail::$contextId = null
protected

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

Referenced by withContextId().

◆ $contextParameters

ilMail::$contextParameters = []
protected

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

◆ $db

ilMail::$db
protected

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

Referenced by __construct().

◆ $eventHandler

ilMail::$eventHandler
private

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

Referenced by __construct().

◆ $lng

ilMail::$lng
protected

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

Referenced by __construct().

◆ $logger

ilMail::$logger
protected

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

Referenced by __construct().

◆ $mail_data

ilMail::$mail_data = array()
protected

◆ $mail_obj_ref_id

ilMail::$mail_obj_ref_id
protected

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

Referenced by getMailObjectReferenceId().

◆ $mail_options

ilMail::$mail_options
protected

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

◆ $mailAddressParserFactory

ilMail::$mailAddressParserFactory
private

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

Referenced by __construct().

◆ $mailAddressTypeFactory

ilMail::$mailAddressTypeFactory
private

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

Referenced by __construct().

◆ $mailbox

ilMail::$mailbox
protected

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

◆ $mailOptionsByUsrIdMap

ilMail::$mailOptionsByUsrIdMap = []
protected

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

◆ $maxRecipientCharacterLength

ilMail::$maxRecipientCharacterLength = 998
protected

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

◆ $mfile

ilMail::$mfile
protected

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

◆ $save_in_sentbox

ilMail::$save_in_sentbox
protected

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

Referenced by getSaveInSentbox().

◆ $senderFactory

ilMail::$senderFactory
protected

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

Referenced by __construct().

◆ $table_mail

ilMail::$table_mail
protected

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

◆ $table_mail_saved

ilMail::$table_mail_saved
protected

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

◆ $user_id

ilMail::$user_id

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

◆ $userInstancesByIdMap

ilMail::$userInstancesByIdMap = []
protected

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

◆ $usrIdByLoginCallable

ilMail::$usrIdByLoginCallable = null
protected

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

Referenced by __construct().

◆ ILIAS_HOST

const ilMail::ILIAS_HOST = 'ilias'

◆ PROP_CONTEXT_SUBJECT_PREFIX


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