ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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'
 
 $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 98 of file class.ilMail.php.

112 {
113 global $DIC;
114
115 if ($logger === null) {
117 }
118 if ($mailAddressTypeFactory === null) {
120 }
121 if ($mailAddressParserFactory === null) {
123 }
124 if ($eventHandler === null) {
125 $eventHandler = $DIC->event();
126 }
127 if ($db === null) {
128 $db = $DIC->database();
129 }
130 if ($lng === null) {
131 $lng = $DIC->language();
132 }
133 if ($mailFileData === null) {
134 $mailFileData = new ilFileDataMail($a_user_id);
135 }
136 if ($mailOptions === null) {
137 $mailOptions = new ilMailOptions($a_user_id);
138 }
139 if ($mailBox === null) {
140 $mailBox = new ilMailbox($a_user_id);
141 }
142 if ($senderFactory === null) {
143 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
144 }
145 if ($usrIdByLoginCallable === null) {
146 $usrIdByLoginCallable = function (string $login) {
148 };
149 }
150
151 $this->user_id = (int) $a_user_id;
152 $this->mailAddressParserFactory = $mailAddressParserFactory;
153 $this->mailAddressTypeFactory = $mailAddressTypeFactory;
154 $this->eventHandler = $eventHandler;
155 $this->logger = $logger;
156 $this->db = $db;
157 $this->lng = $lng;
158 $this->mfile = $mailFileData;
159 $this->mail_options = $mailOptions;
160 $this->mailbox = $mailBox;
161 $this->senderFactory = $senderFactory;
162 $this->usrIdByLoginCallable = $usrIdByLoginCallable;
163
164 $this->mail_obj_ref_id = $mailAdminNodeRefId;
165 if (null === $this->mail_obj_ref_id) {
167 }
168
169 $this->lng->loadLanguageModule('mail');
170 $this->table_mail = 'mail';
171 $this->table_mail_saved = 'mail_saved';
172 $this->setSaveInSentbox(false);
173 }
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
$DIC
Definition: xapitoken.php:46

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 1588 of file class.ilMail.php.

1588 : string
1589 {
1590 global $DIC;
1591
1592 if (!($lang instanceof ilLanguage)) {
1594 }
1595
1596 $lang->loadLanguageModule('mail');
1597
1598 return sprintf(
1599 $lang->txt('mail_auto_generated_info'),
1600 $DIC->settings()->get('inst_name', 'ILIAS ' . ((int) ILIAS_VERSION_NUMERIC)),
1602 ) . "\n\n";
1603 }
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 1633 of file class.ilMail.php.

1633 : string
1634 {
1635 global $DIC;
1636
1637 $signature = $DIC->settings()->get('mail_system_sys_signature');
1638
1639 $clientUrl = ilUtil::_getHttpPath();
1640 $clientdirs = glob(ILIAS_WEB_DIR . '/*', GLOB_ONLYDIR);
1641 if (is_array($clientdirs) && count($clientdirs) > 1) {
1642 $clientUrl .= '/login.php?client_id=' . CLIENT_ID; // #18051
1643 }
1644
1645 $signature = str_ireplace('[CLIENT_NAME]', $DIC['ilClientIniFile']->readVariable('client', 'name'), $signature);
1646 $signature = str_ireplace(
1647 '[CLIENT_DESC]',
1648 $DIC['ilClientIniFile']->readVariable('client', 'description'),
1649 $signature
1650 );
1651 $signature = str_ireplace('[CLIENT_URL]', $clientUrl, $signature);
1652
1653 if (!preg_match('/^[\n\r]+/', $signature)) {
1654 $signature = "\n" . $signature;
1655 }
1656
1657 return $signature;
1658 }
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public

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

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

+ 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 1620 of file class.ilMail.php.

1621 {
1622 if (null === $a_flag) {
1624 }
1625
1626 $this->appendInstallationSignature = $a_flag;
1627 return $this;
1628 }
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 1045 of file class.ilMail.php.

1045 : array
1046 {
1047 $errors = [];
1048
1049 foreach ([
1050 $subject => 'mail_add_subject',
1051 $to => 'mail_add_recipient'
1052 ] as $string => $error
1053 ) {
1054 if (0 === strlen($string)) {
1055 $errors[] = new ilMailError($error);
1056 }
1057 }
1058
1059 return $errors;
1060 }
Class ilMailError.
$errors

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 1068 of file class.ilMail.php.

1068 : array
1069 {
1070 $errors = [];
1071
1072 try {
1073 $addresses = $this->parseAddresses($recipients);
1074 foreach ($addresses as $address) {
1075 $addressType = $this->mailAddressTypeFactory->getByPrefix($address);
1076 if (!$addressType->validate($this->user_id)) {
1077 $newErrors = $addressType->getErrors();
1078 $errors = array_merge($errors, $newErrors);
1079 }
1080 }
1081 } catch (ilException $e) {
1082 $colonPosition = strpos($e->getMessage(), ':');
1083 throw new ilMailException(
1084 ($colonPosition === false) ? $e->getMessage() : substr($e->getMessage(), $colonPosition + 2)
1085 );
1086 }
1087
1088 return $errors;
1089 }
Base class for ILIAS Exception handling.
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 382 of file class.ilMail.php.

382 : int
383 {
384 $res = $this->db->queryF(
385 "SELECT COUNT(*) FROM {$this->table_mail} WHERE user_id = %s AND folder_id = %s",
386 ['integer', 'integer'],
387 [$this->user_id, $folderId]
388 );
389
390 return $this->db->numRows($res);
391 }
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 932 of file class.ilMail.php.

939 : void {
940 if (1 === count($usrIdToExternalEmailAddressesMap)) {
941 if ($usePlaceholders) {
942 $message = array_values($usrIdToMessageMap)[0];
943 }
944
945 $usrIdToExternalEmailAddressesMap = array_values($usrIdToExternalEmailAddressesMap);
946 $firstAddresses = current($usrIdToExternalEmailAddressesMap);
947
948 $this->sendMimeMail(
949 implode(',', $firstAddresses),
950 '',
951 '',
952 $subject,
954 (array) $attachments
955 );
956 } elseif (count($usrIdToExternalEmailAddressesMap) > 1) {
957 if ($usePlaceholders) {
958 foreach ($usrIdToExternalEmailAddressesMap as $usrId => $addresses) {
959 if (0 === count($addresses)) {
960 continue;
961 }
962
963 $this->sendMimeMail(
964 implode(',', $addresses),
965 '',
966 '',
967 $subject,
968 $this->formatLinebreakMessage($usrIdToMessageMap[$usrId]),
969 (array) $attachments
970 );
971 }
972 } else {
973 $flattenEmailAddresses = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator(
974 $usrIdToExternalEmailAddressesMap
975 )), false);
976
977 $flattenEmailAddresses = array_unique($flattenEmailAddresses);
978
979 // https://mantis.ilias.de/view.php?id=23981 and https://www.ietf.org/rfc/rfc2822.txt
980 $remainingAddresses = '';
981 foreach ($flattenEmailAddresses as $emailAddress) {
982 $sep = '';
983 if (strlen($remainingAddresses) > 0) {
984 $sep = ',';
985 }
986
987 $recipientsLineLength = ilStr::strLen($remainingAddresses) + ilStr::strLen($sep . $emailAddress);
988 if ($recipientsLineLength >= $this->maxRecipientCharacterLength) {
989 $this->sendMimeMail(
990 '',
991 '',
992 $remainingAddresses,
993 $subject,
995 (array) $attachments
996 );
997
998 $remainingAddresses = '';
999 $sep = '';
1000 }
1001
1002 $remainingAddresses .= ($sep . $emailAddress);
1003 }
1004
1005 if ('' !== $remainingAddresses) {
1006 $this->sendMimeMail(
1007 '',
1008 '',
1009 $remainingAddresses,
1010 $subject,
1012 (array) $attachments
1013 );
1014 }
1015 }
1016 }
1017 }
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 494 of file class.ilMail.php.

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

Referenced by deleteMailsOfFolder().

+ Here is the caller graph for this function:

◆ deleteMailsOfFolder()

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

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

396 : void
397 {
398 $mails = $this->getMailsOfFolder($folderId);
399 foreach ($mails as $mail_data) {
400 $this->deleteMails([$mail_data['mail_id']]);
401 }
402 }
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 735 of file class.ilMail.php.

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

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

214 : bool
215 {
216 $newAddresses = new ilMailAddressListImpl($this->parseAddresses($newRecipient));
217 $addresses = new ilMailAddressListImpl($this->parseAddresses($existingRecipients));
218
219 $list = new ilMailDiffAddressList($newAddresses, $addresses);
220
221 $diffedAddresses = $list->value();
222
223 return count($diffedAddresses) === 0;
224 }
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 511 of file class.ilMail.php.

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

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 1734 of file class.ilMail.php.

1734 : string
1735 {
1736 return $message;
1737 }

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 264 of file class.ilMail.php.

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

1530 : int
1531 {
1532 $addresses = new ilMailAddressListImpl($this->parseAddresses($recipients));
1533 if ($onlyExternalAddresses) {
1534 $addresses = new ilMailOnlyExternalAddressList(
1535 $addresses,
1536 self::ILIAS_HOST,
1537 $this->usrIdByLoginCallable
1538 );
1539 }
1540
1541 return count($addresses->value());
1542 }
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 1551 of file class.ilMail.php.

1556 : int {
1557 return (
1558 $this->getCountRecipient($toRecipients, $onlyExternalAddresses) +
1559 $this->getCountRecipient($ccRecipients, $onlyExternalAddresses) +
1560 $this->getCountRecipient($bccRecipients, $onlyExternalAddresses)
1561 );
1562 }
getCountRecipient(string $recipients, $onlyExternalAddresses=true)

◆ getEmailRecipients()

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

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

1568 : string
1569 {
1570 $addresses = new ilMailOnlyExternalAddressList(
1571 new ilMailAddressListImpl($this->parseAddresses($recipients)),
1572 self::ILIAS_HOST,
1573 $this->usrIdByLoginCallable
1574 );
1575
1576 $emailRecipients = array_map(function (ilMailAddress $address) {
1577 return (string) $address;
1578 }, $addresses->value());
1579
1580 return implode(',', $emailRecipients);
1581 }
Class ilMailAddress.

◆ getMail()

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

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

408 : ?array
409 {
410 $res = $this->db->queryF(
411 "SELECT * FROM {$this->table_mail} WHERE user_id = %s AND mail_id = %s",
412 ['integer', 'integer'],
413 [$this->user_id, $mailId]
414 );
415
416 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
417
418 return $this->mail_data;
419 }
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 253 of file class.ilMail.php.

253 : int
254 {
256 }
$mail_obj_ref_id

References $mail_obj_ref_id.

◆ getMailOptionsByUserId()

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

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

1714 {
1715 if (!isset($this->mailOptionsByUsrIdMap[$usrId])) {
1716 $this->mailOptionsByUsrIdMap[$usrId] = new ilMailOptions($usrId);
1717 }
1718
1719 return $this->mailOptionsByUsrIdMap[$usrId];
1720 }

◆ 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 348 of file class.ilMail.php.

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

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

◆ getNextMail()

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

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

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

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 297 of file class.ilMail.php.

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

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 1665 of file class.ilMail.php.

1665 : string
1666 {
1667 global $DIC;
1668
1669 $lang = ($a_language instanceof ilLanguage) ? $a_language : $DIC->language();
1670 $lang->loadLanguageModule('mail');
1671
1672 $gender = ilObjUser::_lookupGender($a_usr_id);
1673 $gender = $gender ? $gender : 'n';
1674 $name = ilObjUser::_lookupName($a_usr_id);
1675
1676 if (!strlen($name['firstname'])) {
1677 return $lang->txt('mail_salutation_anonymous') . ',';
1678 }
1679
1680 return
1681 $lang->txt('mail_salutation_' . $gender) . ' ' .
1682 ($name['title'] ? $name['title'] . ' ' : '') .
1683 ($name['firstname'] ? $name['firstname'] . ' ' : '') .
1684 $name['lastname'] . ',';
1685 }
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(), ilMailEventNotificationSender\createMailBodyText(), ilSessionMembershipMailNotification\send(), ilCourseMembershipMailNotification\send(), ilExerciseMailNotification\send(), ilGroupMembershipMailNotification\send(), ilIndividualAssessmentPrimitiveInternalNotificator\send(), ilLMMailNotification\send(), ilLearningSequenceMembershipMailNotification\send(), ilCalendarMailNotification\send(), ilBuddySystemNotification\send(), ilDiskQuotaSummaryNotification\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 1169 of file class.ilMail.php.

1169 : ?array
1170 {
1171 $res = $this->db->queryF(
1172 "SELECT * FROM {$this->table_mail_saved} WHERE user_id = %s",
1173 ['integer'],
1174 [$this->user_id]
1175 );
1176
1177 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
1178
1179 return $this->mail_data;
1180 }

References $res.

◆ getSaveInSentbox()

ilMail::getSaveInSentbox ( )
Returns
bool

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

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

References $save_in_sentbox.

◆ getUserIds()

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

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

1023 : array
1024 {
1025 $usrIds = array();
1026
1027 $joinedRecipients = implode(',', array_filter(array_map('trim', $recipients)));
1028
1029 $addresses = $this->parseAddresses($joinedRecipients);
1030 foreach ($addresses as $address) {
1031 $addressType = $this->mailAddressTypeFactory->getByPrefix($address);
1032 $usrIds = array_merge($usrIds, $addressType->resolve());
1033 }
1034
1035 return array_unique($usrIds);
1036 }

◆ getUserInstanceById()

ilMail::getUserInstanceById ( int  $usrId)
protected
Parameters
int$usrId
Returns
ilObjUser

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

1691 : ilObjUser
1692 {
1693 if (!isset($this->userInstancesByIdMap[$usrId])) {
1694 $this->userInstancesByIdMap[$usrId] = new ilObjUser($usrId);
1695 }
1696
1697 return $this->userInstancesByIdMap[$usrId];
1698 }

Referenced by formatNamesForOutput().

+ Here is the caller graph for this function:

◆ isSystemMail()

ilMail::isSystemMail ( )
protected
Returns
bool

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

204 : bool
205 {
206 return $this->user_id == ANONYMOUS_USER_ID;
207 }

◆ markRead()

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

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

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

References $query.

◆ markUnread()

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

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

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

References $query.

◆ moveMailsToFolder()

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

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

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

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 1501 of file class.ilMail.php.

1501 : array
1502 {
1503 if (strlen($addresses) > 0) {
1504 $this->logger->debug(sprintf(
1505 "Started parsing of recipient string: %s",
1506 $addresses
1507 ));
1508 }
1509
1510 $parser = $this->mailAddressParserFactory->getParser((string) $addresses);
1511 $parsedAddresses = $parser->parse();
1512
1513 if (strlen($addresses) > 0) {
1514 $this->logger->debug(sprintf(
1515 "Parsed addresses: %s",
1516 implode(',', array_map(function (ilMailAddress $address) {
1517 return (string) $address;
1518 }, $parsedAddresses))
1519 ));
1520 }
1521
1522 return $parsedAddresses;
1523 }
$parser
Definition: BPMN2Parser.php:23

References $parser.

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 245 of file class.ilMail.php.

245 : void
246 {
247 $this->mail_obj_ref_id = (int) ilMailGlobalServices::getMailObjectRefId();
248 }
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 701 of file class.ilMail.php.

705 : string {
706 try {
707 if ($this->contextId) {
709 } else {
711 }
712
713 $user = $usrId > 0 ? $this->getUserInstanceById($usrId) : null;
714
716 $message = $processor->resolve($user, $this->contextParameters, $replaceEmptyPlaceholders);
717 } catch (Exception $e) {
718 $this->logger->error(__METHOD__ . ' has been called with invalid context.');
719 }
720
721 return $message;
722 }
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 1482 of file class.ilMail.php.

1482 : void
1483 {
1484 $this->db->update(
1485 $this->table_mail_saved,
1486 [
1487 'attachments' => ['clob', serialize($attachments)]
1488 ],
1489 [
1490 'user_id' => ['integer', $this->user_id]
1491 ]
1492 );
1493 }

◆ 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 1419 of file class.ilMail.php.

1426 : int {
1427 return $this->sendInternalMail(
1428 $this->mailbox->getSentFolder(),
1429 $this->user_id,
1430 $attachment,
1431 $to,
1432 $cc,
1433 $bcc,
1434 'read',
1435 0,
1436 $subject,
1437 $message,
1438 $this->user_id,
1439 0
1440 );
1441 }
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 1107 of file class.ilMail.php.

1119 {
1120 if (!$a_attachments) {
1121 $a_attachments = null;
1122 }
1123 if (!$a_rcp_to) {
1124 $a_rcp_to = null;
1125 }
1126 if (!$a_rcp_cc) {
1127 $a_rcp_cc = null;
1128 }
1129 if (!$a_rcp_bcc) {
1130 $a_rcp_bcc = null;
1131 }
1132 if (!$a_m_email) {
1133 $a_m_email = null;
1134 }
1135 if (!$a_m_message) {
1136 $a_m_message = null;
1137 }
1138 if (!$a_use_placeholders) {
1139 $a_use_placeholders = '0';
1140 }
1141
1142 $this->db->replace(
1143 $this->table_mail_saved,
1144 [
1145 'user_id' => ['integer', $this->user_id]
1146 ],
1147 [
1148 'attachments' => ['clob', serialize($a_attachments)],
1149 'rcp_to' => ['clob', $a_rcp_to],
1150 'rcp_cc' => ['clob', $a_rcp_cc],
1151 'rcp_bcc' => ['clob', $a_rcp_bcc],
1152 'm_email' => ['integer', $a_m_email],
1153 'm_subject' => ['text', $a_m_subject],
1154 'm_message' => ['clob', $a_m_message],
1155 'use_placeholders' => ['integer', $a_use_placeholders],
1156 'tpl_ctx_id' => ['text', $a_tpl_context_id],
1157 'tpl_ctx_params' => ['blob', json_encode((array) $a_tpl_ctx_params)]
1158 ]
1159 );
1160
1161 $this->getSavedData();
1162
1163 return true;
1164 }

◆ 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 815 of file class.ilMail.php.

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

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

1319 : array {
1320 $internalMessageId = $this->saveInSentbox(
1321 $attachments,
1322 $to,
1323 $cc,
1324 $bcc,
1325 $subject,
1326 $message
1327 );
1328
1329 if (count($attachments) > 0) {
1330 $this->mfile->assignAttachmentsToDirectory($internalMessageId, $internalMessageId);
1331 $this->mfile->saveFiles($internalMessageId, $attachments);
1332 }
1333
1334 $numberOfExternalAddresses = $this->getCountRecipients($to, $cc, $bcc, true);
1335
1336 if ($numberOfExternalAddresses > 0) {
1337 $externalMailRecipientsTo = $this->getEmailRecipients($to);
1338 $externalMailRecipientsCc = $this->getEmailRecipients($cc);
1339 $externalMailRecipientsBcc = $this->getEmailRecipients($bcc);
1340
1341 $this->logger->debug(
1342 "Parsed external email addresses from given recipients /" .
1343 " To: " . $externalMailRecipientsTo .
1344 " | CC: " . $externalMailRecipientsCc .
1345 " | BCC: " . $externalMailRecipientsBcc .
1346 " | Subject: " . $subject
1347 );
1348
1349 $this->sendMimeMail(
1350 $externalMailRecipientsTo,
1351 $externalMailRecipientsCc,
1352 $externalMailRecipientsBcc,
1353 $subject,
1355 $usePlaceholders ? $this->replacePlaceholders($message, 0, false) : $message
1356 ),
1357 $attachments
1358 );
1359 } else {
1360 $this->logger->debug('No external email addresses given in recipient string');
1361 }
1362
1363 $errors = [];
1364
1365 if (!$this->distributeMail(
1366 $to,
1367 $cc,
1368 $bcc,
1369 $subject,
1370 $message,
1371 $attachments,
1372 $internalMessageId,
1373 $usePlaceholders
1374 )) {
1375 $errors['mail_send_error'] = new ilMailError('mail_send_error');
1376 }
1377
1378 if (!$this->getSaveInSentbox()) {
1379 $this->deleteMails([$internalMessageId]);
1380 }
1381
1382 return array_values($errors);
1383 }
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 1451 of file class.ilMail.php.

1451 : void
1452 {
1453 $mailer = new ilMimeMail();
1454 $mailer->From($this->senderFactory->getSenderByUsrId((int) $this->user_id));
1455 $mailer->To($to);
1456 $mailer->Subject($subject, true);
1457 $mailer->Body($message);
1458
1459 if ($cc) {
1460 $mailer->Cc($cc);
1461 }
1462
1463 if ($bcc) {
1464 $mailer->Bcc($bcc);
1465 }
1466
1467 foreach ($attachments as $attachment) {
1468 $mailer->Attach(
1469 $this->mfile->getAbsoluteAttachmentPoolPathByFilename($attachment),
1470 '',
1471 'inline',
1472 $attachment
1473 );
1474 }
1475
1476 $mailer->Send();
1477 }
Class ilMimeMail.

References $message.

◆ setMailOptionsByUserIdMap()

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

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

1726 : void
1727 {
1728 $this->mailOptionsByUsrIdMap = $mailOptionsByUsrIdMap;
1729 }
$mailOptionsByUsrIdMap

◆ setSaveInSentbox()

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

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

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

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUserInstanceById()

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

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

1704 : void
1705 {
1706 $this->userInstancesByIdMap = $userInstanceByIdMap;
1707 }

◆ 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 541 of file class.ilMail.php.

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

◆ 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 1391 of file class.ilMail.php.

1391 : array
1392 {
1393 try {
1394 $errors = [];
1395 $errors = array_merge($errors, $this->checkRecipients($to));
1396 $errors = array_merge($errors, $this->checkRecipients($cc));
1397 $errors = array_merge($errors, $this->checkRecipients($bcc));
1398
1399 if (count($errors) > 0) {
1400 return array_merge([new ilMailError('mail_following_rcp_not_valid')], $errors);
1401 }
1402 } catch (ilMailException $e) {
1403 return [new ilMailError('mail_generic_rcp_error', [$e->getMessage()])];
1404 }
1405
1406 return [];
1407 }
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 179 of file class.ilMail.php.

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

References $contextId.

◆ withContextParameters()

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

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

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

Field Documentation

◆ $appendInstallationSignature

ilMail::$appendInstallationSignature = false
protected

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

◆ $contextId

ilMail::$contextId = null
protected

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

Referenced by withContextId().

◆ $contextParameters

ilMail::$contextParameters = []
protected

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

◆ $db

ilMail::$db
protected

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

Referenced by __construct().

◆ $eventHandler

ilMail::$eventHandler
private

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

Referenced by __construct().

◆ $lng

ilMail::$lng
protected

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

Referenced by __construct().

◆ $logger

ilMail::$logger
protected

Definition at line 66 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 42 of file class.ilMail.php.

Referenced by getMailObjectReferenceId().

◆ $mail_options

ilMail::$mail_options
protected

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

◆ $mailAddressParserFactory

ilMail::$mailAddressParserFactory
private

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

Referenced by __construct().

◆ $mailAddressTypeFactory

ilMail::$mailAddressTypeFactory
private

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

Referenced by __construct().

◆ $mailbox

ilMail::$mailbox
protected

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

◆ $mailOptionsByUsrIdMap

ilMail::$mailOptionsByUsrIdMap = []
protected

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

◆ $maxRecipientCharacterLength

ilMail::$maxRecipientCharacterLength = 998
protected

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

◆ $mfile

ilMail::$mfile
protected

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

◆ $save_in_sentbox

ilMail::$save_in_sentbox
protected

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

Referenced by getSaveInSentbox().

◆ $senderFactory

ilMail::$senderFactory
protected

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

Referenced by __construct().

◆ $table_mail

ilMail::$table_mail
protected

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

◆ $table_mail_saved

ilMail::$table_mail_saved
protected

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

◆ $user_id

ilMail::$user_id

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

◆ $userInstancesByIdMap

ilMail::$userInstancesByIdMap = []
protected

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

◆ $usrIdByLoginCallable

ilMail::$usrIdByLoginCallable = null
protected

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

Referenced by __construct().

◆ ILIAS_HOST

const ilMail::ILIAS_HOST = 'ilias'

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