ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMail.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
27 class ilMail
28 {
29  public const string ILIAS_HOST = 'ilias';
30  public const string PROP_CONTEXT_SUBJECT_PREFIX = 'subject_prefix';
31 
33  public int $user_id;
34  private string $table_mail;
35  private string $table_mail_saved;
37  protected ?array $mail_data = [];
38  private bool $save_in_sentbox;
39  private bool $append_installation_signature = false;
40  private bool $append_user_signature = false;
41 
42  private ?string $context_id = null;
43  private array $context_parameters = [];
44 
46  private array $mail_options_by_usr_id_map = [];
47 
49  private array $user_instances_by_id_map = [];
51  private readonly Conductor $legal_documents;
52 
53  public function __construct(
54  private int $a_user_id,
55  private ?ilMailAddressTypeFactory $mail_address_type_factory = null,
56  private ilMailRfc822AddressParserFactory $mail_address_parser_factory = new ilMailRfc822AddressParserFactory(),
57  private ?ilAppEventHandler $event_handler = null,
58  private ?ilLogger $logger = null,
59  private ?ilDBInterface $db = null,
60  private ?ilLanguage $lng = null,
61  private ?ilFileDataMail $mail_file_data = null,
62  protected ?ilMailOptions $mail_options = null,
63  private ?ilMailbox $mailbox = null,
64  private ?ilMailMimeSenderFactory $sender_factory = null,
65  private ?Closure $usr_id_by_login_callable = null,
66  private ?AutoresponderService $auto_responder_service = null,
67  private ?int $mail_admin_node_ref_id = null,
68  private ?int $mail_obj_ref_id = null,
69  private ?ilObjUser $actor = null,
70  private ?ilMailTemplatePlaceholderResolver $placeholder_resolver = null,
71  private ?ilMailTemplatePlaceholderToEmptyResolver $placeholder_to_empty_resolver = null,
72  ?Conductor $legal_documents = null,
73  ?MailSignatureService $signature_service = null,
74  ) {
75  global $DIC;
76  $this->logger = $logger ?? ilLoggerFactory::getLogger('mail');
77  $this->mail_address_type_factory = $mail_address_type_factory ?? new ilMailAddressTypeFactory(null, $logger);
78  $this->event_handler = $event_handler ?? $DIC->event();
79  $this->db = $db ?? $DIC->database();
80  $this->lng = $lng ?? $DIC->language();
81  $this->actor = $actor ?? $DIC->user();
82  $this->mail_file_data = $mail_file_data ?? new ilFileDataMail($a_user_id);
83  $this->mail_options = $mail_options ?? new ilMailOptions($a_user_id);
84  $this->mailbox = $mailbox ?? new ilMailbox($a_user_id);
85 
86  $this->sender_factory = $sender_factory ?? $DIC->mail()->mime()->senderFactory();
87  $this->usr_id_by_login_callable = $usr_id_by_login_callable ?? (static fn(string $login): int => (int) ilObjUser::_lookupId($login));
88  $this->auto_responder_service = $auto_responder_service ?? $DIC->mail()->autoresponder();
89  $this->user_id = $a_user_id;
90  if ($this->mail_obj_ref_id === null) {
92  }
93  $this->lng->loadLanguageModule('mail');
94  $this->table_mail = 'mail';
95  $this->table_mail_saved = 'mail_saved';
96  $this->setSaveInSentbox(false);
97  $this->placeholder_resolver = $placeholder_resolver ?? $DIC->mail()->placeholderResolver();
98  $this->placeholder_to_empty_resolver = $placeholder_to_empty_resolver ?? $DIC->mail()->placeholderToEmptyResolver();
99  $this->legal_documents = $legal_documents ?? $DIC['legalDocuments'];
100  $this->signature_service = $signature_service ?? $DIC->mail()->signature();
101  }
102 
104  {
105  return $this->auto_responder_service;
106  }
107 
108  public function withContextId(string $context_id): self
109  {
110  $clone = clone $this;
111 
112  $clone->context_id = $context_id;
113 
114  return $clone;
115  }
116 
117  public function withContextParameters(array $parameters): self
118  {
119  $clone = clone $this;
120 
121  $clone->context_parameters = $parameters;
122 
123  return $clone;
124  }
125 
126  private function isSystemMail(): bool
127  {
128  return $this->user_id === ANONYMOUS_USER_ID;
129  }
130 
131  public function existsRecipient(string $new_recipient, string $existing_recipients): bool
132  {
133  $new_addresses = new ilMailAddressListImpl($this->parseAddresses($new_recipient));
134  $addresses = new ilMailAddressListImpl($this->parseAddresses($existing_recipients));
135  $list = new ilMailDiffAddressList($new_addresses, $addresses);
136 
137  $diffed_addresses = $list->value();
138 
139  return $diffed_addresses === [];
140  }
141 
142  public function setSaveInSentbox(bool $save_in_sentbox): void
143  {
144  $this->save_in_sentbox = $save_in_sentbox;
145  }
146 
147  public function getSaveInSentbox(): bool
148  {
149  return $this->save_in_sentbox;
150  }
151 
152  private function readMailObjectReferenceId(): void
153  {
154  $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
155  }
156 
157  public function getMailObjectReferenceId(): int
158  {
159  return $this->mail_obj_ref_id;
160  }
161 
162  public function formatNamesForOutput(string $recipients): string
163  {
164  $recipients = trim($recipients);
165  if ($recipients === '') {
166  return $this->lng->txt('not_available');
167  }
168 
169  $names = [];
170 
171  $recipients = array_filter(array_map('trim', explode(',', $recipients)));
172  foreach ($recipients as $recipient) {
173  $usr_id = ilObjUser::_lookupId($recipient);
174  if (is_int($usr_id) && $usr_id > 0) {
175  $pp = ilObjUser::_lookupPref($usr_id, 'public_profile');
176  if ($pp === 'g' || ($pp === 'y' && !$this->actor->isAnonymous())) {
177  $user = $this->getUserInstanceById($usr_id);
178  if ($user) {
179  $names[] = $user->getFullname() . ' [' . $recipient . ']';
180  continue;
181  }
182  }
183  }
184 
185  $names[] = $recipient;
186  }
187 
188  return implode(', ', $names);
189  }
190 
191  public function getPreviousMail(int $mail_id): ?array
192  {
193  $this->db->setLimit(1, 0);
194 
195  $query = implode(' ', [
196  "SELECT b.* FROM $this->table_mail a",
197  "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
198  'AND b.user_id = a.user_id AND b.send_time > a.send_time',
199  'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC',
200  ]);
201  $res = $this->db->queryF(
202  $query,
203  ['integer', 'integer'],
204  [$this->user_id, $mail_id]
205  );
206 
207  $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
208 
209  return $this->mail_data;
210  }
211 
212  public function getNextMail(int $mail_id): ?array
213  {
214  $this->db->setLimit(1, 0);
215 
216  $query = implode(' ', [
217  "SELECT b.* FROM $this->table_mail a",
218  "INNER JOIN $this->table_mail b ON b.folder_id = a.folder_id",
219  'AND b.user_id = a.user_id AND b.send_time < a.send_time',
220  'WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC',
221  ]);
222  $res = $this->db->queryF(
223  $query,
224  ['integer', 'integer'],
225  [$this->user_id, $mail_id]
226  );
227 
228  $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
229 
230  return $this->mail_data;
231  }
232 
233  public function getMailsOfFolder(int $a_folder_id, array $filter = []): array
234  {
235  $mails = [];
236 
237  $query =
238  'SELECT sender_id, m_subject, mail_id, m_status, send_time, import_name ' .
239  "FROM $this->table_mail " .
240  'LEFT JOIN object_data ON obj_id = sender_id ' .
241  'WHERE user_id = %s AND folder_id = %s ' .
242  'AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) ' .
243  'OR (sender_id = 0 OR sender_id IS NULL))';
244 
245  if (isset($filter['status']) && $filter['status'] !== '') {
246  $query .= ' AND m_status = ' . $this->db->quote($filter['status'], 'text');
247  }
248 
249  $query .= ' ORDER BY send_time DESC';
250 
251  $res = $this->db->queryF(
252  $query,
253  ['integer', 'integer'],
254  [$this->user_id, $a_folder_id]
255  );
256 
257  while ($row = $this->db->fetchAssoc($res)) {
258  $mails[] = $this->fetchMailData($row);
259  }
260 
261  return array_filter($mails);
262  }
263 
264  public function countMailsOfFolder(int $folder_id): int
265  {
266  $res = $this->db->queryF(
267  "SELECT COUNT(*) FROM $this->table_mail WHERE user_id = %s AND folder_id = %s",
268  ['integer', 'integer'],
269  [$this->user_id, $folder_id]
270  );
271 
272  return $this->db->numRows($res);
273  }
274 
275  public function deleteMailsOfFolder(int $folder_id): void
276  {
277  $mails = $this->getMailsOfFolder($folder_id);
278  foreach ($mails as $mail_data) {
279  $this->deleteMails([$mail_data['mail_id']]);
280  }
281  }
282 
283  public function getMail(int $mail_id): ?array
284  {
285  $res = $this->db->queryF(
286  "SELECT * FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
287  ['integer', 'integer'],
288  [$this->user_id, $mail_id]
289  );
290 
291  $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
292 
293  return $this->mail_data;
294  }
295 
299  public function markRead(array $mail_ids): void
300  {
301  $values = [];
302  $types = [];
303 
304  $query = "UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
305  $types[] = 'text';
306  $types[] = 'integer';
307  $values[] = 'read';
308  $values[] = $this->user_id;
309 
310  if ($mail_ids !== []) {
311  $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
312  }
313 
314  $this->db->manipulateF($query, $types, $values);
315  }
316 
320  public function markUnread(array $mail_ids): void
321  {
322  $values = [];
323  $types = [];
324 
325  $query = "UPDATE $this->table_mail SET m_status = %s WHERE user_id = %s ";
326  $types[] = 'text';
327  $types[] = 'integer';
328  $values[] = 'unread';
329  $values[] = $this->user_id;
330 
331  if ($mail_ids !== []) {
332  $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
333  }
334 
335  $this->db->manipulateF($query, $types, $values);
336  }
337 
341  public function moveMailsToFolder(array $mail_ids, int $folder_id): bool
342  {
343  $values = [];
344  $types = [];
345 
346  $mail_ids = array_filter(array_map(intval(...), $mail_ids));
347 
348  if ([] === $mail_ids) {
349  return false;
350  }
351 
352  $query =
353  "UPDATE $this->table_mail " .
354  'INNER JOIN mail_obj_data ' .
355  'ON mail_obj_data.obj_id = %s AND mail_obj_data.user_id = %s ' .
356  "SET $this->table_mail.folder_id = mail_obj_data.obj_id " .
357  "WHERE $this->table_mail.user_id = %s";
358  $types[] = 'integer';
359  $types[] = 'integer';
360  $types[] = 'integer';
361  $values[] = $folder_id;
362  $values[] = $this->user_id;
363  $values[] = $this->user_id;
364 
365  $query .= ' AND ' . $this->db->in('mail_id', $mail_ids, false, 'integer');
366 
367  $affected_rows = $this->db->manipulateF($query, $types, $values);
368 
369  return $affected_rows > 0;
370  }
371 
375  public function deleteMails(array $mail_ids): void
376  {
377  $mail_ids = array_filter(array_map('intval', $mail_ids));
378  foreach ($mail_ids as $id) {
379  $this->db->manipulateF(
380  "DELETE FROM $this->table_mail WHERE user_id = %s AND mail_id = %s",
381  ['integer', 'integer'],
382  [$this->user_id, $id]
383  );
384  $this->mail_file_data->deassignAttachmentFromDirectory($id);
385  }
386  }
387 
388  private function fetchMailData(?array $row): ?array
389  {
390  if (!is_array($row) || empty($row)) {
391  return null;
392  }
393 
394  if (isset($row['attachments'])) {
395  $unserialized = unserialize(stripslashes((string) $row['attachments']), ['allowed_classes' => false]);
396  $row['attachments'] = is_array($unserialized) ? $unserialized : [];
397  } else {
398  $row['attachments'] = [];
399  }
400 
401  if (isset($row['tpl_ctx_params']) && is_string($row['tpl_ctx_params'])) {
402  $decoded = json_decode($row['tpl_ctx_params'], true, 512, JSON_THROW_ON_ERROR);
403  $row['tpl_ctx_params'] = (array) ($decoded ?? []);
404  } else {
405  $row['tpl_ctx_params'] = [];
406  }
407 
408  if (isset($row['mail_id'])) {
409  $row['mail_id'] = (int) $row['mail_id'];
410  }
411 
412  if (isset($row['user_id'])) {
413  $row['user_id'] = (int) $row['user_id'];
414  }
415 
416  if (isset($row['folder_id'])) {
417  $row['folder_id'] = (int) $row['folder_id'];
418  }
419 
420  if (isset($row['sender_id'])) {
421  $row['sender_id'] = (int) $row['sender_id'];
422  }
423 
424  if (isset($row['use_placeholders'])) {
425  $row['use_placeholders'] = (bool) $row['use_placeholders'];
426  }
427 
428  $null_to_string_properties = ['m_subject', 'm_message', 'rcp_to', 'rcp_cc', 'rcp_bcc'];
429  foreach ($null_to_string_properties as $null_to_string_property) {
430  if (!isset($row[$null_to_string_property])) {
431  $row[$null_to_string_property] = '';
432  }
433  }
434 
435  return $row;
436  }
437 
438  public function getNewDraftId(int $folder_id): int
439  {
440  $next_id = $this->db->nextId($this->table_mail);
441  $this->db->insert($this->table_mail, [
442  'mail_id' => ['integer', $next_id],
443  'user_id' => ['integer', $this->user_id],
444  'folder_id' => ['integer', $folder_id],
445  'sender_id' => ['integer', $this->user_id],
446  ]);
447 
448  return $next_id;
449  }
450 
454  public function updateDraft(
455  int $a_folder_id,
456  array $a_attachments,
457  string $a_rcp_to,
458  string $a_rcp_cc,
459  string $a_rcp_bcc,
460  string $a_m_subject,
461  string $a_m_message,
462  int $a_draft_id = 0,
463  bool $a_use_placeholders = false,
464  ?string $a_tpl_context_id = null,
465  array $a_tpl_context_params = []
466  ): int {
467  $this->db->update(
468  $this->table_mail,
469  [
470  'folder_id' => ['integer', $a_folder_id],
471  'attachments' => ['clob', serialize($a_attachments)],
472  'send_time' => ['timestamp', date('Y-m-d H:i:s')],
473  'rcp_to' => ['clob', $a_rcp_to],
474  'rcp_cc' => ['clob', $a_rcp_cc],
475  'rcp_bcc' => ['clob', $a_rcp_bcc],
476  'm_status' => ['text', 'read'],
477  'm_subject' => ['text', $a_m_subject],
478  'm_message' => ['clob', $a_m_message],
479  'use_placeholders' => ['integer', (int) $a_use_placeholders],
480  'tpl_ctx_id' => ['text', $a_tpl_context_id],
481  'tpl_ctx_params' => ['blob', json_encode($a_tpl_context_params, JSON_THROW_ON_ERROR)],
482  ],
483  [
484  'mail_id' => ['integer', $a_draft_id],
485  ]
486  );
487 
488  return $a_draft_id;
489  }
490 
491  private function sendInternalMail(
492  int $folder_id,
493  int $sender_usr_id,
494  array $attachments,
495  string $to,
496  string $cc,
497  string $bcc,
498  string $status,
499  string $subject,
500  string $message,
501  int $usr_id = 0,
502  bool $use_placeholders = false,
503  ?string $template_contenxt_id = null,
504  array $template_context_parameters = []
505  ): int {
506  $usr_id = $usr_id ?: $this->user_id;
507 
508  if ($use_placeholders) {
509  $message = $this->replacePlaceholders($message, $usr_id);
510  }
511  $message = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $message);
512 
513  $next_id = $this->db->nextId($this->table_mail);
514  $this->db->insert($this->table_mail, [
515  'mail_id' => ['integer', $next_id],
516  'user_id' => ['integer', $usr_id],
517  'folder_id' => ['integer', $folder_id],
518  'sender_id' => ['integer', $sender_usr_id],
519  'attachments' => ['clob', serialize($attachments)],
520  'send_time' => ['timestamp', date('Y-m-d H:i:s')],
521  'rcp_to' => ['clob', $to],
522  'rcp_cc' => ['clob', $cc],
523  'rcp_bcc' => ['clob', $bcc],
524  'm_status' => ['text', $status],
525  'm_subject' => ['text', $subject],
526  'm_message' => ['clob', $message],
527  'tpl_ctx_id' => ['text', $template_contenxt_id],
528  'tpl_ctx_params' => ['blob', json_encode($template_context_parameters, JSON_THROW_ON_ERROR)],
529  ]);
530 
531  $sender_equals_reveiver = $usr_id === $this->mailbox->getUsrId();
532  $is_sent_folder_of_sender = false;
533  if ($sender_equals_reveiver) {
534  $current_folder_id = $this->getSubjectSentFolderId();
535  $is_sent_folder_of_sender = $folder_id === $current_folder_id;
536  }
537 
538  $raise_event = !$sender_equals_reveiver || !$is_sent_folder_of_sender;
539 
540  if ($raise_event) {
541  $this->event_handler->raise('components/ILIAS/Mail', 'sentInternalMail', [
542  'id' => $next_id,
543  'subject' => $subject,
544  'body' => $message,
545  'from_usr_id' => $sender_usr_id,
546  'to_usr_id' => $usr_id,
547  'rcp_to' => $to,
548  'rcp_cc' => $cc,
549  'rcp_bcc' => $bcc,
550  ]);
551  }
552 
553  return $next_id;
554  }
555 
556  private function replacePlaceholders(
557  string $message,
558  int $usr_id = 0
559  ): string {
560  try {
561  if ($this->context_id) {
563  } else {
565  }
566 
567  $user = $usr_id > 0 ? $this->getUserInstanceById($usr_id) : null;
568  $message = $this->placeholder_resolver->resolve(
569  $context,
570  $message,
571  $user,
572  $this->context_parameters
573  );
574  } catch (Exception $e) {
575  $this->logger->error(sprintf(
576  '%s has been called with invalid context: %s / %s',
577  __METHOD__,
578  $e->getMessage(),
579  $e->getTraceAsString()
580  ));
581  }
582 
583  return $message;
584  }
585 
586  private function replacePlaceholdersEmpty(string $message): string
587  {
588  return $this->placeholder_to_empty_resolver->resolve($message);
589  }
590 
591  private function distributeMail(MailDeliveryData $mail_data): bool
592  {
593  $this->auto_responder_service->emptyAutoresponderData();
594  $to_usr_ids = $this->getUserIds([$mail_data->getTo()]);
595  $this->logger->debug(sprintf(
596  'Parsed TO user ids from given recipients for serial letter notification: %s',
597  implode(', ', $to_usr_ids)
598  ));
599 
600  $other_usr_ids = $this->getUserIds([$mail_data->getCc(), $mail_data->getBcc()]);
601  $cc_bcc_recipients = array_map(
602  $this->createRecipient(...),
603  $other_usr_ids
604  );
605  $this->logger->debug(sprintf(
606  'Parsed CC/BCC user ids from given recipients for serial letter notification: %s',
607  implode(', ', $other_usr_ids)
608  ));
609 
610  if ($mail_data->isUsePlaceholder()) {
611  $this->sendMailWithReplacedPlaceholder($mail_data, $to_usr_ids);
612  $this->sendMailWithReplacedEmptyPlaceholder($mail_data, $cc_bcc_recipients);
613  } else {
614  $this->sendMailWithoutReplacedPlaceholder($mail_data, $to_usr_ids, $cc_bcc_recipients);
615  }
616 
617  $this->auto_responder_service->disableAutoresponder();
618  $this->auto_responder_service->handleAutoresponderMails($this->user_id);
619 
620  return true;
621  }
622 
627  MailDeliveryData $mail_data,
628  array $to_usr_ids
629  ): void {
630  foreach ($to_usr_ids as $user_id) {
631  $recipient = $this->createRecipient($user_id);
632 
633  $this->sendChanneledMails(
634  $mail_data,
635  [$recipient],
636  $this->replacePlaceholders($mail_data->getMessage(), $user_id),
637  );
638  }
639  }
640 
645  MailDeliveryData $mail_data,
646  array $recipients,
647  ): void {
648  $this->sendChanneledMails(
649  $mail_data,
650  $recipients,
651  $this->replacePlaceholdersEmpty($mail_data->getMessage()),
652  );
653  }
654 
660  MailDeliveryData $mail_data,
661  array $to_usr_ids,
662  array $cc_bcc_recipients
663  ): void {
664  $to_recipients = array_map(
665  $this->createRecipient(...),
666  $to_usr_ids
667  );
668 
669  $this->sendChanneledMails(
670  $mail_data,
671  array_merge($to_recipients, $cc_bcc_recipients),
672  $mail_data->getMessage()
673  );
674  }
675 
679  private function sendChanneledMails(
680  MailDeliveryData $mail_data,
681  array $recipients,
682  string $message
683  ): void {
684  $usr_id_to_external_email_addresses_map = [];
685 
686  foreach ($recipients as $recipient) {
687  if (!$recipient->isUser()) {
688  $this->logger->critical(sprintf(
689  'Skipped recipient with id %s (User not found)',
690  $recipient->getUserId()
691  ));
692  continue;
693  }
694 
695  $can_read_internal = $recipient->evaluateInternalMailReadability();
696  if ($this->isSystemMail() && !$can_read_internal->isOk()) {
697  $this->logger->debug(sprintf(
698  'Skipped recipient with id %s and reason: %s',
699  $recipient->getUserId(),
700  is_string($can_read_internal->error()) ? $can_read_internal->error() : $can_read_internal->error()->getMessage()
701  ));
702  continue;
703  }
704 
705  if ($recipient->isUserActive() && !$recipient->isUserExpired()) {
706  if (!$can_read_internal->isOk() || $recipient->userWantsToReceiveExternalMails()) {
707  $email_addresses = $recipient->getExternalMailAddress();
708  $usr_id_to_external_email_addresses_map[$recipient->getUserId()] = $email_addresses;
709 
710  if ($recipient->onlyToExternalMailAddress()) {
711  $this->logger->debug(sprintf(
712  'Recipient with id %s will only receive external emails sent to: %s',
713  $recipient->getUserId(),
714  implode(', ', $email_addresses)
715  ));
716  continue;
717  }
718 
719  $this->logger->debug(sprintf(
720  'Recipient with id %s will additionally receive external emails ' .
721  '(because the user wants to receive it externally, or the user cannot did not accept ' .
722  'the legal documents) sent to: %s',
723  $recipient->getUserId(),
724  implode(', ', $email_addresses)
725  ));
726  } else {
727  $this->logger->debug(sprintf(
728  'Recipient with id %s does not want to receive external emails',
729  $recipient->getUserId()
730  ));
731  }
732  } else {
733  $this->logger->debug(sprintf(
734  'Recipient with id %s is inactive or expired and will not receive external emails',
735  $recipient->getUserId()
736  ));
737  }
738 
739  $mbox = clone $this->mailbox;
740  $mbox->setUsrId($recipient->getUserId());
741  $recipient_inbox_id = $mbox->getInboxFolder();
742 
743  $internal_mail_id = $this->sendInternalMail(
744  $recipient_inbox_id,
745  $this->user_id,
746  $mail_data->getAttachments(),
747  $mail_data->getTo(),
748  $mail_data->getCc(),
749  '',
750  'unread',
751  $mail_data->getSubject(),
752  $message,
753  $recipient->getUserId()
754  );
755 
756  $this->auto_responder_service->enqueueAutoresponderIfEnabled(
757  $recipient->getUserId(),
758  $recipient->getMailOptions(),
759  $this->getMailOptionsByUserId($this->user_id),
760  );
761 
762  if ($mail_data->getAttachments() !== []) {
763  $this->mail_file_data->assignAttachmentsToDirectory($internal_mail_id, $mail_data->getInternalMailId());
764  }
765  }
766 
767  $this->delegateExternalEmails(
768  $mail_data->getSubject(),
769  $mail_data->getAttachments(),
770  $message,
771  $usr_id_to_external_email_addresses_map
772  );
773  }
774 
779  private function delegateExternalEmails(
780  string $subject,
781  array $attachments,
782  string $message,
783  array $usr_id_to_external_email_addresses_map
784  ): void {
785  if (count($usr_id_to_external_email_addresses_map) === 1) {
786  $usr_id_to_external_email_addresses_map = array_values($usr_id_to_external_email_addresses_map);
787  $first_addresses = current($usr_id_to_external_email_addresses_map);
788 
789  $this->sendMimeMail(
790  implode(',', $first_addresses),
791  '',
792  '',
793  $subject,
794  $message,
795  $attachments
796  );
797  } elseif (count($usr_id_to_external_email_addresses_map) > 1) {
798  $flattened_email_addresses = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator(
799  $usr_id_to_external_email_addresses_map
800  )), false);
801 
802  $flattened_email_addresses = array_unique($flattened_email_addresses);
803 
804  // https://mantis.ilias.de/view.php?id=23981 and https://www.ietf.org/rfc/rfc2822.txt
805  $remaining_addresses = '';
806  foreach ($flattened_email_addresses as $email_address) {
807  $sep = '';
808  if ($remaining_addresses !== '') {
809  $sep = ',';
810  }
811 
812  $recipients_line_length = ilStr::strLen($remaining_addresses) +
813  ilStr::strLen($sep . $email_address);
814  if ($recipients_line_length >= $this->max_recipient_character_length) {
815  $this->sendMimeMail(
816  '',
817  '',
818  $remaining_addresses,
819  $subject,
820  $message,
821  $attachments
822  );
823 
824  $remaining_addresses = '';
825  $sep = '';
826  }
827 
828  $remaining_addresses .= ($sep . $email_address);
829  }
830 
831  if ($remaining_addresses !== '') {
832  $this->sendMimeMail(
833  '',
834  '',
835  $remaining_addresses,
836  $subject,
837  $message,
838  $attachments
839  );
840  }
841  }
842  }
843 
848  private function getUserIds(array $recipients): array
849  {
850  $parsed_usr_ids = [];
851 
852  $joined_recipients = implode(',', array_filter(array_map('trim', $recipients)));
853 
854  $addresses = $this->parseAddresses($joined_recipients);
855  foreach ($addresses as $address) {
856  $address_type = $this->mail_address_type_factory->getByPrefix($address);
857  $parsed_usr_ids[] = $address_type->resolve();
858  }
859 
860  return array_unique(array_merge(...$parsed_usr_ids));
861  }
862 
866  private function checkMail(string $to, string $cc, string $bcc, string $subject): array
867  {
868  $errors = [];
869 
870  $checks = [
871  $subject => 'mail_add_subject',
872  $to => 'mail_add_recipient',
873  ];
874  foreach ($checks as $string => $error) {
875  if ($string === '') {
876  $errors[] = new ilMailError($error);
877  }
878  }
879 
880  if (ilStr::strLen($subject) > 255) {
881  // https://mantis.ilias.de/view.php?id=37881
882  $errors[] = new ilMailError('mail_subject_too_long');
883  }
884 
885  return $errors;
886  }
887 
891  private function checkRecipients(string $recipients): array
892  {
893  $errors = [];
894 
895  try {
896  $addresses = $this->parseAddresses($recipients);
897  foreach ($addresses as $address) {
898  $address_type = $this->mail_address_type_factory->getByPrefix($address);
899  if (!$address_type->validate($this->user_id)) {
900  $errors[] = $address_type->getErrors();
901  }
902  }
903  } catch (Exception $e) {
904  $position = strpos($e->getMessage(), ':');
905  throw new ilMailException(
906  ($position === false) ? $e->getMessage() : substr($e->getMessage(), $position + 2),
907  $e->getCode(),
908  $e
909  );
910  }
911 
912  return array_merge(...$errors);
913  }
914 
918  public function persistToStage(
919  int $a_user_id,
920  array $a_attachments,
921  string $a_rcp_to,
922  string $a_rcp_cc,
923  string $a_rcp_bcc,
924  string $a_m_subject,
925  string $a_m_message,
926  bool $a_use_placeholders = false,
927  ?string $a_tpl_context_id = null,
928  ?array $a_tpl_ctx_params = []
929  ): bool {
930  $this->db->replace(
931  $this->table_mail_saved,
932  [
933  'user_id' => ['integer', $this->user_id],
934  ],
935  [
936  'attachments' => ['clob', serialize($a_attachments)],
937  'rcp_to' => ['clob', $a_rcp_to],
938  'rcp_cc' => ['clob', $a_rcp_cc],
939  'rcp_bcc' => ['clob', $a_rcp_bcc],
940  'm_subject' => ['text', $a_m_subject],
941  'm_message' => ['clob', $a_m_message],
942  'use_placeholders' => ['integer', (int) $a_use_placeholders],
943  'tpl_ctx_id' => ['text', $a_tpl_context_id],
944  'tpl_ctx_params' => ['blob', json_encode((array) $a_tpl_ctx_params, JSON_THROW_ON_ERROR)],
945  ]
946  );
947 
948  $this->retrieveFromStage();
949 
950  return true;
951  }
952 
953  public function retrieveFromStage(): array
954  {
955  $res = $this->db->queryF(
956  "SELECT * FROM $this->table_mail_saved WHERE user_id = %s",
957  ['integer'],
958  [$this->user_id]
959  );
960 
961  $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
962  if (!is_array($this->mail_data)) {
963  $this->persistToStage($this->user_id, [], '', '', '', '', '', false);
964  }
965 
966  return $this->mail_data;
967  }
968 
974  public function enqueue(
975  string $a_rcp_to,
976  string $a_rcp_cc,
977  string $a_rcp_bcc,
978  string $a_m_subject,
979  string $a_m_message,
980  array $a_attachment,
981  bool $a_use_placeholders = false
982  ): array {
983  global $DIC;
984 
985  $this->logger->info(
986  'New mail system task:' .
987  ' To: ' . $a_rcp_to .
988  ' | CC: ' . $a_rcp_cc .
989  ' | BCC: ' . $a_rcp_bcc .
990  ' | Subject: ' . $a_m_subject .
991  ' | Attachments: ' . print_r($a_attachment, true)
992  );
993 
994  if ($a_attachment && !$this->mail_file_data->checkFilesExist($a_attachment)) {
995  return [new ilMailError('mail_attachment_file_not_exist', [implode(', ', $a_attachment)])];
996  }
997 
998  $errors = $this->checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject);
999  if ($errors !== []) {
1000  return $errors;
1001  }
1002 
1003  $errors = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bcc);
1004  if ($errors !== []) {
1005  return $errors;
1006  }
1007 
1008  $rcp_to = $a_rcp_to;
1009  $rcp_cc = $a_rcp_cc;
1010  $rcp_bcc = $a_rcp_bcc;
1011 
1012  $number_of_external_addresses = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bcc);
1013  if (
1014  $number_of_external_addresses > 0 &&
1015  !$this->isSystemMail() &&
1016  !$DIC->rbac()->system()->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id)
1017  ) {
1018  return [new ilMailError('mail_no_permissions_write_smtp')];
1019  }
1020 
1021  if ($this->appendInstallationSignature()) {
1022  $a_m_message .= self::_getInstallationSignature();
1023  }
1024 
1026  $mail_data = new MailDeliveryData(
1027  $rcp_to,
1028  $rcp_cc,
1029  $rcp_bcc,
1030  $a_m_subject,
1031  $a_m_message,
1032  $a_attachment,
1033  $a_use_placeholders
1034  );
1035  return $this->sendMail($mail_data);
1036  }
1037 
1038  $task_factory = $DIC->backgroundTasks()->taskFactory();
1039  $task_manager = $DIC->backgroundTasks()->taskManager();
1040 
1041  $bucket = new BasicBucket();
1042  $bucket->setUserId($this->user_id);
1043 
1044  $task = $task_factory->createTask(ilMailDeliveryJob::class, [
1045  $this->user_id,
1046  $rcp_to,
1047  $rcp_cc,
1048  $rcp_bcc,
1049  $a_m_subject,
1050  $a_m_message,
1051  serialize($a_attachment),
1052  $a_use_placeholders,
1053  $this->getSaveInSentbox(),
1054  (string) $this->context_id,
1055  serialize(array_merge(
1056  $this->context_parameters,
1057  [
1058  'auto_responder' => $this->auto_responder_service->isAutoresponderEnabled()
1059  ]
1060  ))
1061  ]);
1062  $interaction = $task_factory->createTask(ilMailDeliveryJobUserInteraction::class, [
1063  $task,
1064  $this->user_id,
1065  ]);
1066 
1067  $bucket->setTask($interaction);
1068  $bucket->setTitle($this->lng->txt('mail_bg_task_title'));
1069  $bucket->setDescription(sprintf($this->lng->txt('mail_bg_task_desc'), $a_m_subject));
1070 
1071  $this->logger->info('Delegated delivery to background task');
1072  $task_manager->run($bucket);
1073 
1074  return [];
1075  }
1076 
1085  public function sendMail(
1086  MailDeliveryData $mail_data
1087  ): array {
1088  $internal_message_id = $this->saveInSentbox(
1089  $mail_data->getAttachments(),
1090  $mail_data->getTo(),
1091  $mail_data->getCc(),
1092  $mail_data->getBcc(),
1093  $mail_data->getSubject(),
1094  $mail_data->getMessage()
1095  );
1096  $mail_data = $mail_data->withInternalMailId($internal_message_id);
1097 
1098  if ($mail_data->getAttachments() !== []) {
1099  $this->mail_file_data->assignAttachmentsToDirectory($internal_message_id, $internal_message_id);
1100  $this->mail_file_data->saveFiles($internal_message_id, $mail_data->getAttachments());
1101  }
1102 
1103  $num_external_email_addresses = $this->getCountRecipients(
1104  $mail_data->getTo(),
1105  $mail_data->getCc(),
1106  $mail_data->getBcc()
1107  );
1108 
1109  if ($num_external_email_addresses > 0) {
1110  $external_mail_recipients_to = $this->getEmailRecipients($mail_data->getTo());
1111  $external_mail_recipients_cc = $this->getEmailRecipients($mail_data->getCc());
1112  $external_eail_recipients_bcc = $this->getEmailRecipients($mail_data->getBcc());
1113 
1114  $this->logger->debug(
1115  'Parsed external email addresses from given recipients /' .
1116  ' To: ' . $external_mail_recipients_to .
1117  ' | CC: ' . $external_mail_recipients_cc .
1118  ' | BCC: ' . $external_eail_recipients_bcc .
1119  ' | Subject: ' . $mail_data->getSubject()
1120  );
1121 
1122  $this->sendMimeMail(
1123  $external_mail_recipients_to,
1124  $external_mail_recipients_cc,
1125  $external_eail_recipients_bcc,
1126  $mail_data->getSubject(),
1127  $mail_data->isUsePlaceholder() ?
1128  $this->replacePlaceholders($mail_data->getMessage(), 0) :
1129  $mail_data->getMessage(),
1130  $mail_data->getAttachments()
1131  );
1132  } else {
1133  $this->logger->debug('No external email addresses given in recipient string');
1134  }
1135 
1136  $errors = [];
1137  if (!$this->distributeMail($mail_data)) {
1138  $errors['mail_send_error'] = new ilMailError('mail_send_error');
1139  }
1140 
1141  if (!$this->getSaveInSentbox()) {
1142  $this->deleteMails([$internal_message_id]);
1143  }
1144 
1145  if ($this->isSystemMail()) {
1146  $random = new Random\Randomizer();
1147  if ($random->getInt(0, 50) === 2) {
1149  $this->logger,
1150  $this->mail_file_data
1151  ))->run();
1152  }
1153  }
1154 
1155  return array_values($errors);
1156  }
1157 
1161  public function validateRecipients(string $to, string $cc, string $bcc): array
1162  {
1163  try {
1164  $errors = [];
1165  $errors = array_merge($errors, $this->checkRecipients($to));
1166  $errors = array_merge($errors, $this->checkRecipients($cc));
1167  $errors = array_merge($errors, $this->checkRecipients($bcc));
1168 
1169  if ($errors !== []) {
1170  return array_merge([new ilMailError('mail_following_rcp_not_valid')], $errors);
1171  }
1172  } catch (ilMailException $e) {
1173  return [new ilMailError('mail_generic_rcp_error', [$e->getMessage()])];
1174  }
1175 
1176  return [];
1177  }
1178 
1179  private function getSubjectSentFolderId(): int
1180  {
1181  $send_folder_id = 0;
1182  if (!$this->isSystemMail()) {
1183  $send_folder_id = $this->mailbox->getSentFolder();
1184  }
1185 
1186  return $send_folder_id;
1187  }
1188 
1192  private function saveInSentbox(
1193  array $attachment,
1194  string $to,
1195  string $cc,
1196  string $bcc,
1197  string $subject,
1198  string $message
1199  ): int {
1200  return $this->sendInternalMail(
1201  $this->getSubjectSentFolderId(),
1202  $this->user_id,
1203  $attachment,
1204  $to,
1205  $cc,
1206  $bcc,
1207  'read',
1208  $subject,
1209  $message,
1210  $this->user_id
1211  );
1212  }
1213 
1217  private function sendMimeMail(
1218  string $to,
1219  string $cc,
1220  string $bcc,
1221  string $subject,
1222  string $message,
1223  array $attachments
1224  ): void {
1225  $mailer = new ilMimeMail();
1226  $mailer->From($this->sender_factory->getSenderByUsrId($this->user_id));
1227  $mailer->To($to);
1228  $mailer->Subject(
1229  $subject,
1230  true,
1231  (string) ($this->context_parameters[self::PROP_CONTEXT_SUBJECT_PREFIX] ?? '')
1232  );
1233 
1234  if (!$this->isSystemMail()) {
1235  $message .= $this->signature_service->user($this->user_id);
1236  }
1237  $mailer->Body($message);
1238 
1239  if ($cc !== '') {
1240  $mailer->Cc($cc);
1241  }
1242 
1243  if ($bcc !== '') {
1244  $mailer->Bcc($bcc);
1245  }
1246 
1247 
1248  foreach ($attachments as $attachment) {
1249  $mailer->Attach(
1250  $this->mail_file_data->getAbsoluteAttachmentPoolPathByFilename($attachment),
1251  '',
1252  'inline',
1253  $attachment
1254  );
1255  }
1256 
1257  $mailer->Send();
1258  }
1259 
1263  public function saveAttachments(array $attachments): void
1264  {
1265  $this->db->update(
1266  $this->table_mail_saved,
1267  [
1268  'attachments' => ['clob', serialize($attachments)],
1269  ],
1270  [
1271  'user_id' => ['integer', $this->user_id],
1272  ]
1273  );
1274  }
1275 
1280  private function parseAddresses(string $addresses): array
1281  {
1282  if ($addresses !== '') {
1283  $this->logger->debug(sprintf(
1284  'Started parsing of recipient string: %s',
1285  $addresses
1286  ));
1287  }
1288 
1289  $parser = $this->mail_address_parser_factory->getParser($addresses);
1290  $parsed_addresses = $parser->parse();
1291 
1292  if ($addresses !== '') {
1293  $this->logger->debug(sprintf(
1294  'Parsed addresses: %s',
1295  implode(',', array_map(static fn(ilMailAddress $address): string => (string) $address, $parsed_addresses))
1296  ));
1297  }
1298 
1299  return $parsed_addresses;
1300  }
1301 
1302  private function getCountRecipient(string $recipients, bool $only_external_addresses = true): int
1303  {
1304  $addresses = new ilMailAddressListImpl($this->parseAddresses($recipients));
1305  if ($only_external_addresses) {
1306  $addresses = new ilMailOnlyExternalAddressList(
1307  $addresses,
1308  self::ILIAS_HOST,
1309  $this->usr_id_by_login_callable
1310  );
1311  }
1312 
1313  return count($addresses->value());
1314  }
1315 
1316  private function getCountRecipients(
1317  string $to_recipients,
1318  string $cc_recipients,
1319  string $bcc_recipients,
1320  bool $only_external_addresses = true
1321  ): int {
1322  return (
1323  $this->getCountRecipient($to_recipients, $only_external_addresses) +
1324  $this->getCountRecipient($cc_recipients, $only_external_addresses) +
1325  $this->getCountRecipient($bcc_recipients, $only_external_addresses)
1326  );
1327  }
1328 
1329  private function getEmailRecipients(string $recipients): string
1330  {
1331  $addresses = new ilMailOnlyExternalAddressList(
1332  new ilMailAddressListImpl($this->parseAddresses($recipients)),
1333  self::ILIAS_HOST,
1334  $this->usr_id_by_login_callable
1335  );
1336 
1337  $email_recipients = array_map(static fn(ilMailAddress $address): string => (string) $address, $addresses->value());
1338 
1339  return implode(',', $email_recipients);
1340  }
1341 
1342  public static function _getAutoGeneratedMessageString(?ilLanguage $lang = null): string
1343  {
1344  global $DIC;
1345 
1346  if (!($lang instanceof ilLanguage)) {
1348  }
1349 
1350  $lang->loadLanguageModule('mail');
1351 
1352  return sprintf(
1353  $lang->txt('mail_auto_generated_info'),
1354  $DIC->settings()->get('inst_name', 'ILIAS ' . ((int) ILIAS_VERSION_NUMERIC)),
1356  ) . "\n\n";
1357  }
1358 
1359  public static function _getIliasMailerName(): string
1360  {
1361  global $DIC;
1362  $sender_factory = $DIC->mail()->mime()->senderFactory();
1363 
1364  return $sender_factory->system()->getFromName();
1365  }
1366 
1370  public function appendInstallationSignature(?bool $a_flag = null)
1371  {
1372  if ($a_flag === null) {
1374  }
1375 
1376  $this->append_installation_signature = $a_flag;
1377  return $this;
1378  }
1379 
1380  public static function _getInstallationSignature(): string
1381  {
1382  global $DIC;
1383  return $DIC->mail()->signature()->installation();
1384  }
1385 
1386  public static function getSalutation(int $a_usr_id, ?ilLanguage $a_language = null): string
1387  {
1388  global $DIC;
1389 
1390  $lang = ($a_language instanceof ilLanguage) ? $a_language : $DIC->language();
1391  $lang->loadLanguageModule('mail');
1392 
1393  $gender = ilObjUser::_lookupGender($a_usr_id);
1394  $gender = $gender ?: 'n';
1395  $name = ilObjUser::_lookupName($a_usr_id);
1396 
1397  if ($name['firstname'] === '') {
1398  return $lang->txt('mail_salutation_anonymous') . ',';
1399  }
1400 
1401  return
1402  $lang->txt('mail_salutation_' . $gender) . ' ' .
1403  ($name['title'] ? $name['title'] . ' ' : '') .
1404  ($name['firstname'] ? $name['firstname'] . ' ' : '') .
1405  $name['lastname'] . ',';
1406  }
1407 
1408  private function getUserInstanceById(int $usr_id): ?ilObjUser
1409  {
1410  if (!array_key_exists($usr_id, $this->user_instances_by_id_map)) {
1411  try {
1412  $user = new ilObjUser($usr_id);
1413  } catch (Exception) {
1414  $user = null;
1415  }
1416 
1417  $this->user_instances_by_id_map[$usr_id] = $user;
1418  }
1419 
1420  return $this->user_instances_by_id_map[$usr_id];
1421  }
1422 
1426  public function setUserInstanceById(array $user_instances_by_id_map): void
1427  {
1428  $this->user_instances_by_id_map = $user_instances_by_id_map;
1429  }
1430 
1431  private function getMailOptionsByUserId(int $usr_id): ilMailOptions
1432  {
1433  if (!isset($this->mail_options_by_usr_id_map[$usr_id])) {
1434  $this->mail_options_by_usr_id_map[$usr_id] = new ilMailOptions($usr_id);
1435  }
1436 
1437  return $this->mail_options_by_usr_id_map[$usr_id];
1438  }
1439 
1443  public function setMailOptionsByUserIdMap(array $mail_options_by_usr_id_map): void
1444  {
1445  $this->mail_options_by_usr_id_map = $mail_options_by_usr_id_map;
1446  }
1447 
1448  public function formatLinebreakMessage(string $message): string
1449  {
1450  return $message;
1451  }
1452 
1453  private function createRecipient(int $user_id): Recipient
1454  {
1455  return new Recipient(
1456  $user_id,
1457  $this->getUserInstanceById($user_id),
1458  $this->getMailOptionsByUserId($user_id),
1459  $this->legal_documents
1460  );
1461  }
1462 }
replacePlaceholders(string $message, int $usr_id=0)
formatLinebreakMessage(string $message)
moveMailsToFolder(array $mail_ids, int $folder_id)
$res
Definition: ltiservices.php:66
Global event handler.
sendMailWithReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids)
getEmailRecipients(string $recipients)
int $max_recipient_character_length
persistToStage(int $a_user_id, array $a_attachments, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, ?array $a_tpl_ctx_params=[])
$context
Definition: webdav.php:31
markUnread(array $mail_ids)
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getLogger(string $a_component_id)
Get component logger.
getCountRecipients(string $to_recipients, string $cc_recipients, string $bcc_recipients, bool $only_external_addresses=true)
array $mail_data
checkMail(string $to, string $cc, string $bcc, string $subject)
const CONTEXT_CRON
MailSignatureService $signature_service
getMailsOfFolder(int $a_folder_id, array $filter=[])
appendInstallationSignature(?bool $a_flag=null)
sendMimeMail(string $to, string $cc, string $bcc, string $subject, string $message, array $attachments)
enqueue(string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, array $a_attachment, bool $a_use_placeholders=false)
Should be used to enqueue a &#39;mail&#39;.
static _lookupName(int $a_user_id)
lookup user name
string $context_id
static _lookupId($a_user_str)
static _getIliasMailerName()
static _lookupPref(int $a_usr_id, string $a_keyword)
array $mail_options_by_usr_id_map
saveInSentbox(array $attachment, string $to, string $cc, string $bcc, string $subject, string $message)
markRead(array $mail_ids)
getNextMail(int $mail_id)
sendChanneledMails(MailDeliveryData $mail_data, array $recipients, string $message)
static _lookupGender(int $a_user_id)
int $user_id
setUserInstanceById(array $user_instances_by_id_map)
setSaveInSentbox(bool $save_in_sentbox)
bool $append_installation_signature
readonly Conductor $legal_documents
static _getAutoGeneratedMessageString(?ilLanguage $lang=null)
retrieveFromStage()
withContextParameters(array $parameters)
sendInternalMail(int $folder_id, int $sender_usr_id, array $attachments, string $to, string $cc, string $bcc, string $status, string $subject, string $message, int $usr_id=0, bool $use_placeholders=false, ?string $template_contenxt_id=null, array $template_context_parameters=[])
getMailOptionsByUserId(int $usr_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
array $user_instances_by_id_map
deleteMailsOfFolder(int $folder_id)
saveAttachments(array $attachments)
static strLen(string $a_string)
Definition: class.ilStr.php:60
array $context_parameters
const ILIAS_VERSION_NUMERIC
getPreviousMail(int $mail_id)
replacePlaceholdersEmpty(string $message)
fetchMailData(?array $row)
isSystemMail()
setMailOptionsByUserIdMap(array $mail_options_by_usr_id_map)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
checkRecipients(string $recipients)
bool $save_in_sentbox
distributeMail(MailDeliveryData $mail_data)
global $DIC
Definition: shib_login.php:26
string $table_mail_saved
autoresponder()
bool $append_user_signature
getSaveInSentbox()
sendMailWithReplacedEmptyPlaceholder(MailDeliveryData $mail_data, array $recipients,)
static _getLanguage(string $a_lang_key='')
Get language object.
getMailObjectReferenceId()
const string PROP_CONTEXT_SUBJECT_PREFIX
existsRecipient(string $new_recipient, string $existing_recipients)
__construct(private int $a_user_id, private ?ilMailAddressTypeFactory $mail_address_type_factory=null, private ilMailRfc822AddressParserFactory $mail_address_parser_factory=new ilMailRfc822AddressParserFactory(), private ?ilAppEventHandler $event_handler=null, private ?ilLogger $logger=null, private ?ilDBInterface $db=null, private ?ilLanguage $lng=null, private ?ilFileDataMail $mail_file_data=null, protected ?ilMailOptions $mail_options=null, private ?ilMailbox $mailbox=null, private ?ilMailMimeSenderFactory $sender_factory=null, private ?Closure $usr_id_by_login_callable=null, private ?AutoresponderService $auto_responder_service=null, private ?int $mail_admin_node_ref_id=null, private ?int $mail_obj_ref_id=null, private ?ilObjUser $actor=null, private ?ilMailTemplatePlaceholderResolver $placeholder_resolver=null, private ?ilMailTemplatePlaceholderToEmptyResolver $placeholder_to_empty_resolver=null, ?Conductor $legal_documents=null, ?MailSignatureService $signature_service=null,)
validateRecipients(string $to, string $cc, string $bcc)
$lang
Definition: xapiexit.php:25
withContextId(string $context_id)
sendMail(MailDeliveryData $mail_data)
This method is used to finally send internal messages and external emails To use the mail system as a...
deleteMails(array $mail_ids)
createRecipient(int $user_id)
static _getHttpPath()
const string ILIAS_HOST
sendMailWithoutReplacedPlaceholder(MailDeliveryData $mail_data, array $to_usr_ids, array $cc_bcc_recipients)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
formatNamesForOutput(string $recipients)
global $lng
Definition: privfeed.php:31
string $table_mail
withInternalMailId(int $internal_mail_id)
$message
Definition: xapiexit.php:31
getUserIds(array $recipients)
static getType()
Get context type.
delegateExternalEmails(string $subject, array $attachments, string $message, array $usr_id_to_external_email_addresses_map)
getSubjectSentFolderId()
parseAddresses(string $addresses)
Explode recipient string, allowed separators are &#39;,&#39; &#39;;&#39; &#39; &#39;.
countMailsOfFolder(int $folder_id)
getUserInstanceById(int $usr_id)
updateDraft(int $a_folder_id, array $a_attachments, string $a_rcp_to, string $a_rcp_cc, string $a_rcp_bcc, string $a_m_subject, string $a_m_message, int $a_draft_id=0, bool $a_use_placeholders=false, ?string $a_tpl_context_id=null, array $a_tpl_context_params=[])
getMail(int $mail_id)
readMailObjectReferenceId()
static _getInstallationSignature()
getNewDraftId(int $folder_id)
getCountRecipient(string $recipients, bool $only_external_addresses=true)