ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMail.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
10class ilMail
11{
12 public const ILIAS_HOST = 'ilias';
13 public const PROP_CONTEXT_SUBJECT_PREFIX = 'subject_prefix';
14
16 protected $lng;
17
19 protected $db;
20
22 protected $mfile;
23
25 protected $mail_options;
26
28 protected $mailbox;
29
31 public $user_id;
32
34 protected $table_mail;
35
38
40 protected $mail_data = array();
41
44
47
50
53
56
59
61 protected $contextId = null;
62
64 protected $contextParameters = [];
65
67 protected $logger;
68
70 protected $mailOptionsByUsrIdMap = [];
71
73 protected $userInstancesByIdMap = [];
74
76 protected $usrIdByLoginCallable = null;
77
80
82 protected $senderFactory;
83
99 public function __construct(
100 $a_user_id,
104 ilLogger $logger = null,
105 ilDBInterface $db = null,
106 ilLanguage $lng = null,
107 ilFileDataMail $mailFileData = null,
108 ilMailOptions $mailOptions = null,
109 ilMailbox $mailBox = null,
111 callable $usrIdByLoginCallable = null,
112 int $mailAdminNodeRefId = null
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 }
175
180 public function withContextId(string $contextId) : self
181 {
182 $clone = clone $this;
183
184 $clone->contextId = $contextId;
185
186 return $clone;
187 }
188
193 public function withContextParameters(array $parameters) : self
194 {
195 $clone = clone $this;
196
197 $clone->contextParameters = $parameters;
198
199 return $clone;
200 }
201
205 protected function isSystemMail() : bool
206 {
207 return $this->user_id == ANONYMOUS_USER_ID;
208 }
209
215 public function existsRecipient(string $newRecipient, string $existingRecipients) : 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 }
226
230 public function setSaveInSentbox(bool $saveInSentbox) : void
231 {
232 $this->save_in_sentbox = (bool) $saveInSentbox;
233 }
234
238 public function getSaveInSentbox() : bool
239 {
240 return (bool) $this->save_in_sentbox;
241 }
242
246 protected function readMailObjectReferenceId() : void
247 {
248 $this->mail_obj_ref_id = (int) ilMailGlobalServices::getMailObjectRefId();
249 }
250
254 public function getMailObjectReferenceId() : int
255 {
257 }
258
265 public function formatNamesForOutput(string $recipients) : 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 }
295
300 public function getPreviousMail(int $mailId) : ?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 }
320
325 public function getNextMail(int $mailId) : ?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 }
345
351 public function getMailsOfFolder($a_folder_id, $filter = []) : 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 }
380
385 public function countMailsOfFolder(int $folderId) : 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 }
395
399 public function deleteMailsOfFolder(int $folderId) : void
400 {
401 $mails = $this->getMailsOfFolder($folderId);
402 foreach ($mails as $mail_data) {
403 $this->deleteMails([$mail_data['mail_id']]);
404 }
405 }
406
411 public function getMail(int $mailId) : ?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 }
423
427 public function markRead(array $mailIds) : 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 }
442
446 public function markUnread(array $mailIds) : 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 }
461
467 public function moveMailsToFolder(array $mailIds, int $folderId) : 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 }
493
497 public function deleteMails(array $mailIds) : 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 }
509
514 protected function fetchMailData(?array $row) : ?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 }
525
531 public function getNewDraftId(int $usrId, int $folderId) : 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 }
543
544 public function updateDraft(
545 $a_folder_id,
546 $a_attachments,
547 $a_rcp_to,
548 $a_rcp_cc,
549 $a_rcp_bcc,
550 $a_m_email,
551 $a_m_subject,
552 $a_m_message,
553 $a_draft_id = 0,
554 $a_use_placeholders = 0,
555 $a_tpl_context_id = null,
556 $a_tpl_context_params = []
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 }
582
600 private function sendInternalMail(
601 $folderId,
602 $senderUsrId,
603 $attachments,
604 $to,
605 $cc,
606 $bcc,
607 $status,
608 $email,
609 $subject,
610 $message,
611 $usrId = 0,
612 $usePlaceholders = 0,
613 $templateContextId = null,
614 $templateContextParameters = []
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 }
697
704 protected function replacePlaceholders(
705 string $message,
706 int $usrId = 0,
707 bool $replaceEmptyPlaceholders = true
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 }
726
738 protected function distributeMail(
739 string $to,
740 string $cc,
741 string $bcc,
742 string $subject,
743 string $message,
744 array $attachments,
745 int $sentMailId,
746 bool $usePlaceholders = false
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 }
806
818 protected function sendChanneledMails(
819 string $to,
820 string $cc,
821 string $bcc,
822 array $usrIds,
823 string $subject,
824 string $message,
825 array $attachments,
826 int $sentMailId,
827 bool $usePlaceholders = false
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
925 $this->delegateExternalEmails(
926 $subject,
927 $message,
928 $attachments,
929 $usePlaceholders,
930 $usrIdToExternalEmailAddressesMap,
931 $usrIdToMessageMap
932 );
933 }
934
943 protected function delegateExternalEmails(
944 string $subject,
945 string $message,
946 array $attachments,
947 bool $usePlaceholders,
948 array $usrIdToExternalEmailAddressesMap,
949 array $usrIdToMessageMap
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,
964 $this->formatLinebreakMessage($message),
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,
1005 $this->formatLinebreakMessage($message),
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,
1022 $this->formatLinebreakMessage($message),
1023 (array) $attachments
1024 );
1025 }
1026 }
1027 }
1028 }
1029
1034 protected function getUserIds(array $recipients) : 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 }
1048
1056 protected function checkMail(string $to, string $cc, string $bcc, string $subject) : 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 }
1072
1079 protected function checkRecipients(string $recipients) : 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 }
1101
1118 public function savePostData(
1119 $a_user_id,
1120 $a_attachments,
1121 $a_rcp_to,
1122 $a_rcp_cc,
1123 $a_rcp_bcc,
1124 $a_m_email,
1125 $a_m_subject,
1126 $a_m_message,
1127 $a_use_placeholders,
1128 $a_tpl_context_id = null,
1129 $a_tpl_ctx_params = array()
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 }
1176
1180 public function getSavedData() : ?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 }
1192
1204 public function enqueue(
1205 $a_rcp_to,
1206 $a_rcp_cc,
1207 $a_rcp_bcc,
1208 $a_m_subject,
1209 $a_m_message,
1210 $a_attachment,
1211 $a_use_placeholders = 0
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 }
1308
1323 public function sendMail(
1324 string $to,
1325 string $cc,
1326 string $bcc,
1327 string $subject,
1328 string $message,
1329 array $attachments,
1330 bool $usePlaceholders
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,
1366 $this->formatLinebreakMessage(
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 }
1396
1403 public function validateRecipients(string $to, string $cc, string $bcc) : 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 }
1420
1431 protected function saveInSentbox(
1432 array $attachment,
1433 string $to,
1434 string $cc,
1435 string $bcc,
1436 string $subject,
1437 string $message
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 }
1454
1463 private function sendMimeMail(string $to, string $cc, string $bcc, $subject, $message, array $attachments) : 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 }
1490
1494 public function saveAttachments(array $attachments) : 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 }
1506
1513 protected function parseAddresses($addresses) : 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 }
1536
1542 protected function getCountRecipient(string $recipients, $onlyExternalAddresses = true) : 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 }
1555
1563 protected function getCountRecipients(
1564 string $toRecipients,
1565 string $ccRecipients,
1566 string $bccRecipients,
1567 $onlyExternalAddresses = true
1568 ) : int {
1569 return (
1570 $this->getCountRecipient($toRecipients, $onlyExternalAddresses) +
1571 $this->getCountRecipient($ccRecipients, $onlyExternalAddresses) +
1572 $this->getCountRecipient($bccRecipients, $onlyExternalAddresses)
1573 );
1574 }
1575
1580 protected function getEmailRecipients(string $recipients) : 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 }
1594
1600 public static function _getAutoGeneratedMessageString(ilLanguage $lang = null) : 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 }
1616
1620 public static function _getIliasMailerName() : string
1621 {
1623 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
1624
1625 return $senderFactory->system()->getFromName();
1626 }
1627
1632 public function appendInstallationSignature(bool $a_flag = null)
1633 {
1634 if (null === $a_flag) {
1635 return $this->appendInstallationSignature;
1636 }
1637
1638 $this->appendInstallationSignature = $a_flag;
1639 return $this;
1640 }
1641
1645 public static function _getInstallationSignature() : 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 }
1671
1677 public static function getSalutation($a_usr_id, ilLanguage $a_language = null) : 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 }
1698
1699 protected function getUserInstanceById(int $usrId) : ?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 }
1713
1718 public function setUserInstanceById(array $userInstanceByIdMap) : void
1719 {
1720 $this->userInstancesByIdMap = $userInstanceByIdMap;
1721 }
1722
1727 protected function getMailOptionsByUserId(int $usrId) : ilMailOptions
1728 {
1729 if (!isset($this->mailOptionsByUsrIdMap[$usrId])) {
1730 $this->mailOptionsByUsrIdMap[$usrId] = new ilMailOptions($usrId);
1731 }
1732
1733 return $this->mailOptionsByUsrIdMap[$usrId];
1734 }
1735
1740 public function setMailOptionsByUserIdMap(array $mailOptionsByUsrIdMap) : void
1741 {
1742 $this->mailOptionsByUsrIdMap = $mailOptionsByUsrIdMap;
1743 }
1744
1748 public function formatLinebreakMessage(string $message) : string
1749 {
1750 return $message;
1751 }
1752}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public
Global event handler.
const CONTEXT_CRON
static getType()
Get context type.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilFileDataMail.
static _getLanguage($a_lang_key='')
Get langauge object.
language handling
static getLogger($a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilMailAddressListImpl.
Class ilMailAddressTypeFactory.
Class ilMailAddress.
Class ilMailDiffAddressList.
Class ilMailError.
Class ilMailException.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
Class ilMailMimeSenderFactory.
Class ilMailOnlyExternalAddressList.
Class ilMailOptions this class handles user mails.
Class ilMailRfc822AddressParserFactory.
Class ilMailTemplatePlaceholderResolver.
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
$maxRecipientCharacterLength
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
withContextId(string $contextId)
$mailAddressParserFactory
withContextParameters(array $parameters)
getCountRecipient(string $recipients, $onlyExternalAddresses=true)
$table_mail_saved
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'.
deleteMailsOfFolder(int $folderId)
replacePlaceholders(string $message, int $usrId=0, bool $replaceEmptyPlaceholders=true)
markRead(array $mailIds)
getUserIds(array $recipients)
distributeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
checkRecipients(string $recipients)
Check if recipients are valid.
$usrIdByLoginCallable
setUserInstanceById(array $userInstanceByIdMap)
moveMailsToFolder(array $mailIds, int $folderId)
deleteMails(array $mailIds)
saveAttachments(array $attachments)
__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)
formatNamesForOutput(string $recipients)
Prepends the full name of each ILIAS login name (if user has a public profile) found in the passed st...
sendChanneledMails(string $to, string $cc, string $bcc, array $usrIds, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
setSaveInSentbox(bool $saveInSentbox)
isSystemMail()
sendMimeMail(string $to, string $cc, string $bcc, $subject, $message, array $attachments)
$save_in_sentbox
delegateExternalEmails(string $subject, string $message, array $attachments, bool $usePlaceholders, array $usrIdToExternalEmailAddressesMap, array $usrIdToMessageMap)
getMailsOfFolder($a_folder_id, $filter=[])
$mail_obj_ref_id
$mailAddressTypeFactory
getPreviousMail(int $mailId)
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=[])
validateRecipients(string $to, string $cc, string $bcc)
setMailOptionsByUserIdMap(array $mailOptionsByUsrIdMap)
getMail(int $mailId)
static _getInstallationSignature()
$userInstancesByIdMap
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
Stores a message in the sent bod of the current user.
appendInstallationSignature(bool $a_flag=null)
formatLinebreakMessage(string $message)
getUserInstanceById(int $usrId)
getEmailRecipients(string $recipients)
$appendInstallationSignature
checkMail(string $to, string $cc, string $bcc, string $subject)
sendInternalMail( $folderId, $senderUsrId, $attachments, $to, $cc, $bcc, $status, $email, $subject, $message, $usrId=0, $usePlaceholders=0, $templateContextId=null, $templateContextParameters=[])
static getSalutation($a_usr_id, ilLanguage $a_language=null)
existsRecipient(string $newRecipient, string $existingRecipients)
parseAddresses($addresses)
Explode recipient string, allowed separators are ',' ';' ' ' Returns an array with recipient ilMailAd...
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...
$contextParameters
getMailOptionsByUserId(int $usrId)
getMailObjectReferenceId()
$mailOptionsByUsrIdMap
getCountRecipients(string $toRecipients, string $ccRecipients, string $bccRecipients, $onlyExternalAddresses=true)
readMailObjectReferenceId()
Read and set the mail object ref id (administration node)
getNewDraftId(int $usrId, int $folderId)
getSaveInSentbox()
getNextMail(int $mailId)
fetchMailData(?array $row)
countMailsOfFolder(int $folderId)
const ILIAS_HOST
const PROP_CONTEXT_SUBJECT_PREFIX
markUnread(array $mailIds)
Mail Box class Base class for creating and handling mail boxes.
Class ilMimeMail.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupId($a_user_str)
Lookup id by login.
static _lookupGender($a_user_id)
Lookup gender.
static _lookupName($a_user_id)
lookup user name
static strLen($a_string)
Definition: class.ilStr.php:78
static _getHttpPath()
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
const CLIENT_ID
Definition: constants.php:39
const ILIAS_WEB_DIR
Definition: constants.php:43
const ANONYMOUS_USER_ID
Definition: constants.php:25
try
Definition: cron.php:22
$login
Definition: cron.php:13
global $DIC
Definition: goto.php:24
$errors
Definition: imgupload.php:49
const ILIAS_VERSION_NUMERIC
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:230
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:285
$query
foreach($_POST as $key=> $value) $res
$context
Definition: webdav.php:26
$lang
Definition: xapiexit.php:8
$message
Definition: xapiexit.php:14