ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
10 class ilMail
11 {
12  const ILIAS_HOST = 'ilias';
13 
15  protected $lng;
16 
18  protected $db;
19 
21  protected $mfile;
22 
24  protected $mail_options;
25 
27  protected $mailbox;
28 
30  public $user_id;
31 
33  protected $table_mail;
34 
36  protected $table_mail_saved;
37 
39  protected $mail_data = array();
40 
42  protected $mail_obj_ref_id;
43 
45  protected $save_in_sentbox;
46 
48  protected $appendInstallationSignature = false;
49 
51  private $eventHandler;
52 
55 
58 
60  protected $contextId = null;
61 
63  protected $contextParameters = [];
64 
66  protected $logger;
67 
69  protected $mailOptionsByUsrIdMap = [];
70 
72  protected $userInstancesByIdMap = [];
73 
75  protected $usrIdByLoginCallable = null;
76 
79 
81  protected $senderFactory;
82 
98  public function __construct(
99  $a_user_id,
103  ilLogger $logger = null,
104  ilDBInterface $db = null,
105  ilLanguage $lng = null,
106  ilFileDataMail $mailFileData = null,
107  ilMailOptions $mailOptions = null,
108  ilMailbox $mailBox = null,
110  callable $usrIdByLoginCallable = null,
111  int $mailAdminNodeRefId = null
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) {
166  $this->readMailObjectReferenceId();
167  }
168 
169  $this->lng->loadLanguageModule('mail');
170  $this->table_mail = 'mail';
171  $this->table_mail_saved = 'mail_saved';
172  $this->setSaveInSentbox(false);
173  }
174 
179  public function withContextId(string $contextId) : self
180  {
181  $clone = clone $this;
182 
183  $clone->contextId = $contextId;
184 
185  return $clone;
186  }
187 
192  public function withContextParameters(array $parameters) : self
193  {
194  $clone = clone $this;
195 
196  $clone->contextParameters = $parameters;
197 
198  return $clone;
199  }
200 
204  protected function isSystemMail() : bool
205  {
206  return $this->user_id == ANONYMOUS_USER_ID;
207  }
208 
214  public function existsRecipient(string $newRecipient, string $existingRecipients) : 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  }
225 
229  public function setSaveInSentbox(bool $saveInSentbox) : void
230  {
231  $this->save_in_sentbox = (bool) $saveInSentbox;
232  }
233 
237  public function getSaveInSentbox() : bool
238  {
239  return (bool) $this->save_in_sentbox;
240  }
241 
245  protected function readMailObjectReferenceId() : void
246  {
247  $this->mail_obj_ref_id = (int) ilMailGlobalServices::getMailObjectRefId();
248  }
249 
253  public function getMailObjectReferenceId() : int
254  {
255  return $this->mail_obj_ref_id;
256  }
257 
264  public function formatNamesForOutput(string $recipients) : 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  }
292 
297  public function getPreviousMail(int $mailId) : ?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  }
317 
322  public function getNextMail(int $mailId) : ?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  }
342 
348  public function getMailsOfFolder($a_folder_id, $filter = []) : 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  }
377 
382  public function countMailsOfFolder(int $folderId) : 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  }
392 
396  public function deleteMailsOfFolder(int $folderId) : void
397  {
398  $mails = $this->getMailsOfFolder($folderId);
399  foreach ($mails as $mail_data) {
400  $this->deleteMails([$mail_data['mail_id']]);
401  }
402  }
403 
408  public function getMail(int $mailId) : ?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  }
420 
424  public function markRead(array $mailIds) : 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  }
439 
443  public function markUnread(array $mailIds) : 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  }
458 
464  public function moveMailsToFolder(array $mailIds, int $folderId) : 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  }
490 
494  public function deleteMails(array $mailIds) : 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  }
506 
511  protected function fetchMailData(?array $row) : ?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  }
522 
528  public function getNewDraftId(int $usrId, int $folderId) : 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  }
540 
541  public function updateDraft(
542  $a_folder_id,
543  $a_attachments,
544  $a_rcp_to,
545  $a_rcp_cc,
546  $a_rcp_bcc,
547  $a_m_email,
548  $a_m_subject,
549  $a_m_message,
550  $a_draft_id = 0,
551  $a_use_placeholders = 0,
552  $a_tpl_context_id = null,
553  $a_tpl_context_params = []
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  }
579 
597  private function sendInternalMail(
598  $folderId,
599  $senderUsrId,
600  $attachments,
601  $to,
602  $cc,
603  $bcc,
604  $status,
605  $email,
606  $subject,
607  $message,
608  $usrId = 0,
609  $usePlaceholders = 0,
610  $templateContextId = null,
611  $templateContextParameters = []
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  }
694 
701  protected function replacePlaceholders(
702  string $message,
703  int $usrId = 0,
704  bool $replaceEmptyPlaceholders = true
705  ) : string {
706  try {
707  if ($this->contextId) {
709  } else {
711  }
712 
713  $user = $usrId > 0 ? $this->getUserInstanceById($usrId) : null;
714 
715  $processor = new ilMailTemplatePlaceholderResolver($context, $message);
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  }
723 
735  protected function distributeMail(
736  string $to,
737  string $cc,
738  string $bcc,
739  string $subject,
740  string $message,
741  array $attachments,
742  int $sentMailId,
743  bool $usePlaceholders = false
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  }
803 
815  protected function sendChanneledMails(
816  string $to,
817  string $cc,
818  string $bcc,
819  array $usrIds,
820  string $subject,
821  string $message,
822  array $attachments,
823  int $sentMailId,
824  bool $usePlaceholders = false
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 
914  $this->delegateExternalEmails(
915  $subject,
916  $message,
917  $attachments,
918  $usePlaceholders,
919  $usrIdToExternalEmailAddressesMap,
920  $usrIdToMessageMap
921  );
922  }
923 
932  protected function delegateExternalEmails(
933  string $subject,
934  string $message,
935  array $attachments,
936  bool $usePlaceholders,
937  array $usrIdToExternalEmailAddressesMap,
938  array $usrIdToMessageMap
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,
953  $this->formatLinebreakMessage($message),
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,
994  $this->formatLinebreakMessage($message),
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,
1011  $this->formatLinebreakMessage($message),
1012  (array) $attachments
1013  );
1014  }
1015  }
1016  }
1017  }
1018 
1023  protected function getUserIds(array $recipients) : 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  }
1037 
1045  protected function checkMail(string $to, string $cc, string $bcc, string $subject) : 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  }
1061 
1068  protected function checkRecipients(string $recipients) : 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  }
1090 
1107  public function savePostData(
1108  $a_user_id,
1109  $a_attachments,
1110  $a_rcp_to,
1111  $a_rcp_cc,
1112  $a_rcp_bcc,
1113  $a_m_email,
1114  $a_m_subject,
1115  $a_m_message,
1116  $a_use_placeholders,
1117  $a_tpl_context_id = null,
1118  $a_tpl_ctx_params = array()
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  }
1165 
1169  public function getSavedData() : ?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  }
1181 
1193  public function enqueue(
1194  $a_rcp_to,
1195  $a_rcp_cc,
1196  $a_rcp_bcc,
1197  $a_m_subject,
1198  $a_m_message,
1199  $a_attachment,
1200  $a_use_placeholders = 0
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  }
1296 
1311  public function sendMail(
1312  string $to,
1313  string $cc,
1314  string $bcc,
1315  string $subject,
1316  string $message,
1317  array $attachments,
1318  bool $usePlaceholders
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,
1354  $this->formatLinebreakMessage(
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  }
1384 
1391  public function validateRecipients(string $to, string $cc, string $bcc) : 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  }
1408 
1419  protected function saveInSentbox(
1420  array $attachment,
1421  string $to,
1422  string $cc,
1423  string $bcc,
1424  string $subject,
1425  string $message
1426  ) : int {
1427  return $this->sendInternalMail(
1428  $this->mailbox->getSentFolder(),
1430  $attachment,
1431  $to,
1432  $cc,
1433  $bcc,
1434  'read',
1435  0,
1436  $subject,
1437  $message,
1439  0
1440  );
1441  }
1442 
1451  private function sendMimeMail(string $to, string $cc, string $bcc, $subject, $message, array $attachments) : 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  }
1478 
1482  public function saveAttachments(array $attachments) : 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  }
1494 
1501  protected function parseAddresses($addresses) : 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  }
1524 
1530  protected function getCountRecipient(string $recipients, $onlyExternalAddresses = true) : 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  }
1543 
1551  protected function getCountRecipients(
1552  string $toRecipients,
1553  string $ccRecipients,
1554  string $bccRecipients,
1555  $onlyExternalAddresses = true
1556  ) : int {
1557  return (
1558  $this->getCountRecipient($toRecipients, $onlyExternalAddresses) +
1559  $this->getCountRecipient($ccRecipients, $onlyExternalAddresses) +
1560  $this->getCountRecipient($bccRecipients, $onlyExternalAddresses)
1561  );
1562  }
1563 
1568  protected function getEmailRecipients(string $recipients) : 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  }
1582 
1588  public static function _getAutoGeneratedMessageString(ilLanguage $lang = null) : 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  }
1604 
1608  public static function _getIliasMailerName() : string
1609  {
1611  $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
1612 
1613  return $senderFactory->system()->getFromName();
1614  }
1615 
1620  public function appendInstallationSignature(bool $a_flag = null)
1621  {
1622  if (null === $a_flag) {
1624  }
1625 
1626  $this->appendInstallationSignature = $a_flag;
1627  return $this;
1628  }
1629 
1633  public static function _getInstallationSignature() : 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  }
1659 
1665  public static function getSalutation($a_usr_id, ilLanguage $a_language = null) : 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  }
1686 
1691  protected function getUserInstanceById(int $usrId) : ilObjUser
1692  {
1693  if (!isset($this->userInstancesByIdMap[$usrId])) {
1694  $this->userInstancesByIdMap[$usrId] = new ilObjUser($usrId);
1695  }
1696 
1697  return $this->userInstancesByIdMap[$usrId];
1698  }
1699 
1704  public function setUserInstanceById(array $userInstanceByIdMap) : void
1705  {
1706  $this->userInstancesByIdMap = $userInstanceByIdMap;
1707  }
1708 
1713  protected function getMailOptionsByUserId(int $usrId) : ilMailOptions
1714  {
1715  if (!isset($this->mailOptionsByUsrIdMap[$usrId])) {
1716  $this->mailOptionsByUsrIdMap[$usrId] = new ilMailOptions($usrId);
1717  }
1718 
1719  return $this->mailOptionsByUsrIdMap[$usrId];
1720  }
1721 
1727  {
1728  $this->mailOptionsByUsrIdMap = $mailOptionsByUsrIdMap;
1729  }
1730 
1734  public function formatLinebreakMessage(string $message) : string
1735  {
1736  return $message;
1737  }
1738 }
setSaveInSentbox(bool $saveInSentbox)
static _lookupName($a_user_id)
lookup user name
Class ilMailError.
formatLinebreakMessage(string $message)
$errors
Class ilMailOptions this class handles user mails.
Global event handler.
getEmailRecipients(string $recipients)
$login
Definition: cron.php:13
getCountRecipients(string $toRecipients, string $ccRecipients, string $bccRecipients, $onlyExternalAddresses=true)
Class ilMailMimeSenderFactory.
static strLen($a_string)
Definition: class.ilStr.php:78
countMailsOfFolder(int $folderId)
$context
Definition: webdav.php:26
$contextParameters
const ILIAS_VERSION_NUMERIC
const ILIAS_HOST
markUnread(array $mailIds)
delegateExternalEmails(string $subject, string $message, array $attachments, bool $usePlaceholders, array $usrIdToExternalEmailAddressesMap, array $usrIdToMessageMap)
Class ilFileDataMail.
appendInstallationSignature(bool $a_flag=null)
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=[])
existsRecipient(string $newRecipient, string $existingRecipients)
const CONTEXT_CRON
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 &#39;mail&#39;.
__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)
getMailsOfFolder($a_folder_id, $filter=[])
getNewDraftId(int $usrId, int $folderId)
Class ilMailException.
getUserInstanceById(int $usrId)
static _lookupId($a_user_str)
Lookup id by login.
Class ilMailOnlyExternalAddressList.
deleteMailsOfFolder(int $folderId)
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
Stores a message in the sent bod of the current user.
getPreviousMail(int $mailId)
static _lookupGender($a_user_id)
Lookup gender.
Class ilMailDiffAddressList.
$save_in_sentbox
withContextParameters(array $parameters)
$mailAddressParserFactory
Interface ilDBInterface.
saveAttachments(array $attachments)
if($format !==null) $name
Definition: metadata.php:230
static _getLanguage($a_lang_key='')
Get langauge object.
Class ilMailRfc822AddressParserFactory.
foreach($_POST as $key=> $value) $res
$userInstancesByIdMap
Class ilMimeMail.
fetchMailData(?array $row)
withContextId(string $contextId)
isSystemMail()
$mail_obj_ref_id
$appendInstallationSignature
getCountRecipient(string $recipients, $onlyExternalAddresses=true)
Mail Box class Base class for creating and handling mail boxes.
checkRecipients(string $recipients)
Check if recipients are valid.
$table_mail_saved
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
sendMimeMail(string $to, string $cc, string $bcc, $subject, $message, array $attachments)
$mailOptionsByUsrIdMap
getMailOptionsByUserId(int $usrId)
$query
$usrIdByLoginCallable
getSaveInSentbox()
setUserInstanceById(array $userInstanceByIdMap)
Class ilMailTemplatePlaceholderResolver.
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=[])
getMailObjectReferenceId()
if($orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:285
$mailAddressTypeFactory
distributeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
validateRecipients(string $to, string $cc, string $bcc)
$lang
Definition: xapiexit.php:8
$maxRecipientCharacterLength
$parser
Definition: BPMN2Parser.php:23
getMail(int $mailId)
static _getHttpPath()
formatNamesForOutput(string $recipients)
Prepends the full name of each ILIAS login name (if user has a public profile) found in the passed st...
static _lookupPref($a_usr_id, $a_keyword)
deleteMails(array $mailIds)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable...
$DIC
Definition: xapitoken.php:46
getNextMail(int $mailId)
setMailOptionsByUserIdMap(array $mailOptionsByUsrIdMap)
sendChanneledMails(string $to, string $cc, string $bcc, array $usrIds, string $subject, string $message, array $attachments, int $sentMailId, bool $usePlaceholders=false)
$message
Definition: xapiexit.php:14
language handling
getUserIds(array $recipients)
static getLogger($a_component_id)
Get component logger.
static getType()
Get context type.
Component logger with individual log levels by component id.
replacePlaceholders(string $message, int $usrId=0, bool $replaceEmptyPlaceholders=true)
markRead(array $mailIds)
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...
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 public
Class ilMailAddressTypeFactory.
moveMailsToFolder(array $mailIds, int $folderId)
readMailObjectReferenceId()
Read and set the mail object ref id (administration node)
Class ilMailAddress.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)
Class ilMailAddressListImpl.
parseAddresses($addresses)
Explode recipient string, allowed separators are &#39;,&#39; &#39;;&#39; &#39; &#39; Returns an array with recipient ilMailAd...