ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once 'Services/User/classes/class.ilObjUser.php';
5require_once 'Services/Mail/exceptions/class.ilMailException.php';
6
66class ilMail
67{
69 const ILIAS_HOST = 'ilias';
70
71 const MAIL_SUBJECT_PREFIX = '[ILIAS]';
72
74 protected $lng;
75
77 protected $db;
78
80 protected $mfile;
81
83 protected $mail_options;
84
86 public $user_id;
87
89 protected $table_mail;
90
93
95 protected $mail_data = array();
96
99
102
103 protected $soap_enabled = true;
106
111 protected $properties = array();
112
114 protected static $userInstances = array();
115
118
121
127 public function __construct(
128 $a_user_id,
131 ) {
132 global $DIC;
133
134 require_once 'Services/Mail/classes/class.ilFileDataMail.php';
135 require_once 'Services/Mail/classes/class.ilMailOptions.php';
136
137 if ($mailAddressTypeFactory === null) {
139 }
140
141 if ($mailAddressParserFactory === null) {
143 }
144
145 $this->mailAddressParserFactory = $mailAddressParserFactory;
146 $this->mailAddressTypeFactory = $mailAddressTypeFactory;
147
148 $this->lng = $DIC->language();
149 $this->db = $DIC->database();
150
151 $this->lng->loadLanguageModule('mail');
152
153 $this->table_mail = 'mail';
154 $this->table_mail_saved = 'mail_saved';
155
156 $this->user_id = $a_user_id;
157
158 $this->mfile = new ilFileDataMail($this->user_id);
159 $this->mail_options = new ilMailOptions($a_user_id);
160
161 $this->setSaveInSentbox(false);
163 }
164
168 protected function isSystemMail()
169 {
170 return $this->user_id == ANONYMOUS_USER_ID;
171 }
172
179 public function __get($name)
180 {
181 global $DIC;
182
183 if (isset($this->properties[$name])) {
184 return $this->properties[$name];
185 }
186
187 if ($name == 'mlists') {
188 if (is_object($DIC->user())) {
189 require_once 'Services/Contact/classes/class.ilMailingLists.php';
190 $this->properties[$name] = new ilMailingLists($DIC->user());
191 return $this->properties[$name];
192 }
193 }
194 }
195
201 public function existsRecipient($a_recipient, $a_existing_recipients)
202 {
203 $recipients = $this->parseAddresses($a_existing_recipients);
204 foreach ($recipients as $rcp) {
205 if (substr($rcp->getMailbox(), 0, 1) != '#') {
206 if (trim($rcp->getMailbox()) == trim($a_recipient) || trim($rcp->getMailbox() . '@' . $rcp->getHost()) == trim($a_recipient)) {
207 return true;
208 }
209 } elseif (substr($rcp->getMailbox(), 0, 7) == '#il_ml_') {
210 if (trim($rcp->getMailbox() . '@' . $rcp->getHost()) == trim($a_recipient)) {
211 return true;
212 }
213 } else {
214 if (trim($rcp->getMailbox() . '@' . $rcp->getHost()) == trim($a_recipient)) {
215 return true;
216 }
217 }
218 }
219
220 return false;
221 }
222
228 public function enableSOAP($a_status)
229 {
230 $this->soap_enabled = (bool) $a_status;
231 }
232
236 public function isSOAPEnabled()
237 {
238 global $DIC;
239
240 if (!extension_loaded('curl') || !$DIC->settings()->get('soap_user_administration')) {
241 return false;
242 }
243
245 return false;
246 }
247
248 return (bool) $this->soap_enabled;
249 }
250
254 public function setSaveInSentbox($a_save_in_sentbox)
255 {
256 $this->save_in_sentbox = (bool) $a_save_in_sentbox;
257 }
258
262 public function getSaveInSentbox()
263 {
264 return (bool) $this->save_in_sentbox;
265 }
266
270 protected function readMailObjectReferenceId()
271 {
272 require_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
273 $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
274 }
275
279 public function getMailObjectReferenceId()
280 {
282 }
283
290 public function formatNamesForOutput($a_recipients)
291 {
292 global $DIC;
293
294 $a_recipients = trim($a_recipients);
295 if (!strlen($a_recipients)) {
296 return $this->lng->txt('not_available');
297 }
298
299 $names = array();
300
301 $recipients = array_filter(array_map('trim', explode(',', $a_recipients)));
302 foreach ($recipients as $recipient) {
303 $usr_id = ilObjUser::_lookupId($recipient);
304 if ($usr_id > 0) {
305 $pp = ilObjUser::_lookupPref($usr_id, 'public_profile');
306 if ($pp == 'y' || ($pp == 'g' && !$DIC->user()->isAnonymous())) {
307 $user = self::getCachedUserInstance($usr_id);
308 $names[] = $user->getFullname() . ' [' . $recipient . ']';
309 continue;
310 }
311 }
312
313 $names[] = $recipient;
314 }
315
316 return implode(', ', $names);
317 }
318
323 public function getPreviousMail($a_mail_id)
324 {
325 $this->db->setLimit(1);
326
327 $res = $this->db->queryF(
328 "
329 SELECT b.* FROM {$this->table_mail} a
330 INNER JOIN {$this->table_mail} b ON b.folder_id = a.folder_id
331 AND b.user_id = a.user_id AND b.send_time > a.send_time
332 WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time ASC",
333 array('integer', 'integer'),
334 array($this->user_id, $a_mail_id)
335 );
336
337 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
338
339 return $this->mail_data;
340 }
341
346 public function getNextMail($a_mail_id)
347 {
348 $this->db->setLimit(1);
349
350 $res = $this->db->queryF(
351 "
352 SELECT b.* FROM {$this->table_mail} a
353 INNER JOIN {$this->table_mail} b ON b.folder_id = a.folder_id
354 AND b.user_id = a.user_id AND b.send_time < a.send_time
355 WHERE a.user_id = %s AND a.mail_id = %s ORDER BY b.send_time DESC",
356 array('integer', 'integer'),
357 array($this->user_id, $a_mail_id)
358 );
359
360 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
361
362 return $this->mail_data;
363 }
364
370 public function getMailsOfFolder($a_folder_id, $filter = array())
371 {
372 $output = array();
373
374 $query = "
375 SELECT sender_id, m_subject, mail_id, m_status, send_time FROM {$this->table_mail}
376 LEFT JOIN object_data ON obj_id = sender_id
377 WHERE user_id = %s AND folder_id = %s
378 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)) ";
379
380 if (isset($filter['status']) && strlen($filter['status']) > 0) {
381 $query .= ' AND m_status = ' . $this->db->quote($filter['status'], 'text');
382 }
383
384 if (isset($filter['type']) && strlen($filter['type']) > 0) {
385 $query .= ' AND ' . $this->db->like('m_type', 'text', '%%:"' . $filter['type'] . '"%%', false);
386 }
387
388 $query .= " ORDER BY send_time DESC";
389
390 $res = $this->db->queryF(
391 $query,
392 array('integer', 'integer'),
393 array($this->user_id, $a_folder_id)
394 );
395
396 while ($row = $this->db->fetchAssoc($res)) {
397 $output[] = $this->fetchMailData($row);
398 }
399
400 return $output;
401 }
402
407 public function countMailsOfFolder($a_folder_id)
408 {
409 $res = $this->db->queryF(
410 "
411 SELECT COUNT(*) FROM {$this->table_mail}
412 WHERE user_id = %s AND folder_id = %s",
413 array('integer', 'integer'),
414 array($this->user_id, $a_folder_id)
415 );
416
417 return $this->db->numRows($res);
418 }
419
424 public function deleteMailsOfFolder($a_folder_id)
425 {
426 if ($a_folder_id) {
427 $mails = $this->getMailsOfFolder($a_folder_id);
428 foreach ((array) $mails as $mail_data) {
429 $this->deleteMails(array($mail_data['mail_id']));
430 }
431
432 return true;
433 }
434
435 return false;
436 }
437
442 public function getMail($a_mail_id)
443 {
444 $res = $this->db->queryF(
445 "
446 SELECT * FROM {$this->table_mail}
447 WHERE user_id = %s AND mail_id = %s",
448 array('integer', 'integer'),
449 array($this->user_id, $a_mail_id)
450 );
451
452 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
453
454 return $this->mail_data;
455 }
456
461 public function markRead(array $a_mail_ids)
462 {
463 $data = array();
464 $data_types = array();
465
466 $query = "UPDATE {$this->table_mail} SET m_status = %s WHERE user_id = %s ";
467 array_push($data_types, 'text', 'integer');
468 array_push($data, 'read', $this->user_id);
469
470 if (count($a_mail_ids) > 0) {
471 $in = 'mail_id IN (';
472 $counter = 0;
473 foreach ($a_mail_ids as $a_mail_id) {
474 array_push($data, $a_mail_id);
475 array_push($data_types, 'integer');
476
477 if ($counter > 0) {
478 $in .= ',';
479 }
480 $in .= '%s';
481 ++$counter;
482 }
483 $in .= ')';
484
485 $query .= ' AND ' . $in;
486 }
487
488 $this->db->manipulateF($query, $data_types, $data);
489
490 return true;
491 }
492
497 public function markUnread(array $a_mail_ids)
498 {
499 $data = array();
500 $data_types = array();
501
502 $query = "UPDATE {$this->table_mail} SET m_status = %s WHERE user_id = %s ";
503 array_push($data_types, 'text', 'integer');
504 array_push($data, 'unread', $this->user_id);
505
506 if (count($a_mail_ids) > 0) {
507 $in = 'mail_id IN (';
508 $counter = 0;
509 foreach ($a_mail_ids as $a_mail_id) {
510 array_push($data, $a_mail_id);
511 array_push($data_types, 'integer');
512
513 if ($counter > 0) {
514 $in .= ',';
515 }
516 $in .= '%s';
517 ++$counter;
518 }
519 $in .= ')';
520
521 $query .= ' AND ' . $in;
522 }
523
524 $this->db->manipulateF($query, $data_types, $data);
525
526 return true;
527 }
528
534 public function moveMailsToFolder(array $a_mail_ids, $a_folder_id)
535 {
536 $data = array();
537 $data_types = array();
538
539 $query = "UPDATE {$this->table_mail} SET folder_id = %s WHERE user_id = %s ";
540 array_push($data_types, 'text', 'integer');
541 array_push($data, $a_folder_id, $this->user_id);
542
543 if (count($a_mail_ids) > 0) {
544 $in = 'mail_id IN (';
545 $counter = 0;
546 foreach ($a_mail_ids as $a_mail_id) {
547 array_push($data, $a_mail_id);
548 array_push($data_types, 'integer');
549
550 if ($counter > 0) {
551 $in .= ',';
552 }
553 $in .= '%s';
554 ++$counter;
555 }
556 $in .= ')';
557
558 $query .= ' AND ' . $in;
559 }
560
561 $this->db->manipulateF($query, $data_types, $data);
562
563 return true;
564 }
565
570 public function deleteMails(array $a_mail_ids)
571 {
572 foreach ($a_mail_ids as $id) {
573 $this->db->manipulateF(
574 "
575 DELETE FROM {$this->table_mail}
576 WHERE user_id = %s AND mail_id = %s ",
577 array('integer', 'integer'),
578 array($this->user_id, $id)
579 );
580 $this->mfile->deassignAttachmentFromDirectory($id);
581 }
582
583 return true;
584 }
585
590 protected function fetchMailData($a_row)
591 {
592 if (!is_array($a_row) || empty($a_row)) {
593 return null;
594 }
595
596 $a_row['attachments'] = unserialize(stripslashes($a_row['attachments']));
597 $a_row['m_type'] = unserialize(stripslashes($a_row['m_type']));
598 $a_row['tpl_ctx_params'] = (array) (@json_decode($a_row['tpl_ctx_params'], true));
599
600 return $a_row;
601 }
602
608 public function getNewDraftId($usrId, $folderId)
609 {
610 $next_id = $this->db->nextId($this->table_mail);
611 $this->db->insert($this->table_mail, array(
612 'mail_id' => array('integer', $next_id),
613 'user_id' => array('integer', $usrId),
614 'folder_id' => array('integer', $folderId),
615 'sender_id' => array('integer', $usrId)
616 ));
617
618 return $next_id;
619 }
620
621 public function updateDraft(
622 $a_folder_id,
623 $a_attachments,
624 $a_rcp_to,
625 $a_rcp_cc,
626 $a_rcp_bcc,
627 $a_m_type,
628 $a_m_email,
629 $a_m_subject,
630 $a_m_message,
631 $a_draft_id = 0,
632 $a_use_placeholders = 0,
633 $a_tpl_context_id = null,
634 $a_tpl_context_params = array()
635 ) {
636 $this->db->update(
637 $this->table_mail,
638 array(
639 'folder_id' => array('integer', $a_folder_id),
640 'attachments' => array('clob', serialize($a_attachments)),
641 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
642 'rcp_to' => array('clob', $a_rcp_to),
643 'rcp_cc' => array('clob', $a_rcp_cc),
644 'rcp_bcc' => array('clob', $a_rcp_bcc),
645 'm_status' => array('text', 'read'),
646 'm_type' => array('text', serialize($a_m_type)),
647 'm_email' => array('integer', $a_m_email),
648 'm_subject' => array('text', $a_m_subject),
649 'm_message' => array('clob', $a_m_message),
650 'use_placeholders' => array('integer', $a_use_placeholders),
651 'tpl_ctx_id' => array('text', $a_tpl_context_id),
652 'tpl_ctx_params' => array('blob', @json_encode((array) $a_tpl_context_params))
653 ),
654 array(
655 'mail_id' => array('integer', $a_draft_id)
656 )
657 );
658
659 return $a_draft_id;
660 }
661
682 public function sendInternalMail(
683 $a_folder_id,
684 $a_sender_id,
685 $a_attachments,
686 $a_rcp_to,
687 $a_rcp_cc,
688 $a_rcp_bcc,
689 $a_status,
690 $a_m_type,
691 $a_m_email,
692 $a_m_subject,
693 $a_m_message,
694 $a_user_id = 0,
695 $a_use_placeholders = 0,
696 $a_tpl_context_id = null,
697 $a_tpl_context_params = array()
698 ) {
699 $a_user_id = $a_user_id ? $a_user_id : $this->user_id;
700
701 if ($a_use_placeholders) {
702 $a_m_message = $this->replacePlaceholders($a_m_message, $a_user_id);
703 }
704 $a_m_message = $this->formatLinebreakMessage($a_m_message);
705
706 if (!$a_user_id) {
707 $a_user_id = '0';
708 }
709 if (!$a_folder_id) {
710 $a_folder_id = '0';
711 }
712 if (!$a_sender_id) {
713 $a_sender_id = null;
714 }
715 if (!$a_attachments) {
716 $a_attachments = null;
717 }
718 if (!$a_rcp_to) {
719 $a_rcp_to = null;
720 }
721 if (!$a_rcp_cc) {
722 $a_rcp_cc = null;
723 }
724 if (!$a_rcp_bcc) {
725 $a_rcp_bcc = null;
726 }
727 if (!$a_status) {
728 $a_status = null;
729 }
730 if (!$a_m_type) {
731 $a_m_type = null;
732 }
733 if (!$a_m_email) {
734 $a_m_email = null;
735 }
736 if (!$a_m_subject) {
737 $a_m_subject = null;
738 }
739 if (!$a_m_message) {
740 $a_m_message = null;
741 }
742
743 $next_id = $this->db->nextId($this->table_mail);
744 $this->db->insert($this->table_mail, array(
745 'mail_id' => array('integer', $next_id),
746 'user_id' => array('integer', $a_user_id),
747 'folder_id' => array('integer', $a_folder_id),
748 'sender_id' => array('integer', $a_sender_id),
749 'attachments' => array('clob', serialize($a_attachments)),
750 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
751 'rcp_to' => array('clob', $a_rcp_to),
752 'rcp_cc' => array('clob', $a_rcp_cc),
753 'rcp_bcc' => array('clob', $a_rcp_bcc),
754 'm_status' => array('text', $a_status),
755 'm_type' => array('text', serialize($a_m_type)),
756 'm_email' => array('integer', $a_m_email),
757 'm_subject' => array('text', $a_m_subject),
758 'm_message' => array('clob', $a_m_message),
759 'tpl_ctx_id' => array('text', $a_tpl_context_id),
760 'tpl_ctx_params' => array('blob', @json_encode((array) $a_tpl_context_params))
761 ));
762
763 return $next_id;
764 }
765
772 protected function replacePlaceholders($a_message, $a_user_id = 0, $replace_empty = true)
773 {
774 try {
775 include_once 'Services/Mail/classes/class.ilMailFormCall.php';
776
778 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
780 } else {
781 require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
782 $context = new ilMailTemplateGenericContext();
783 }
784
785 $user = $a_user_id > 0 ? self::getCachedUserInstance($a_user_id) : null;
786
787 require_once 'Services/Mail/classes/class.ilMailTemplatePlaceholderResolver.php';
788 $processor = new ilMailTemplatePlaceholderResolver($context, $a_message);
789 $a_message = $processor->resolve($user, ilMailFormCall::getContextParameters(), $replace_empty);
790 } catch (Exception $e) {
791 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
792 ilLoggerFactory::getLogger('mail')->error(__METHOD__ . ' has been called with invalid context.');
793 }
794
795 return $a_message;
796 }
797
811 protected function distributeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_subject, $a_message, $a_attachments, $sent_mail_id, $a_type, $a_action, $a_use_placeholders = 0)
812 {
813 require_once 'Services/Mail/classes/class.ilMailbox.php';
814 require_once 'Services/User/classes/class.ilObjUser.php';
815
816 $mbox = new ilMailbox();
817 if (!$a_use_placeholders) {
818 $rcp_ids = $this->getUserIds(array($a_rcp_to, $a_rcp_cc, $a_rcp_bcc));
819
820 ilLoggerFactory::getLogger('mail')->debug(sprintf(
821 "Parsed TO/CC/BCC user ids from given recipients: %s",
822 implode(', ', $rcp_ids)
823 ));
824
825 $as_email = array();
826
827 foreach ($rcp_ids as $id) {
828 $tmp_mail_options = new ilMailOptions($id);
829
830 $tmp_user = self::getCachedUserInstance($id);
831 $user_is_active = $tmp_user->getActive();
832 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
833
834 if (in_array('system', $a_type) && !$user_can_read_internal_mails) {
835 ilLoggerFactory::getLogger('mail')->debug(sprintf(
836 "Message is marked as 'system', skipped recipient with id %s (Accepted User Agreement:%s|Expired Account:%s)",
837 $id,
838 var_export(!$tmp_user->hasToAcceptTermsOfService(), 1),
839 var_export(!$tmp_user->checkTimeLimit(), 1)
840 ));
841 continue;
842 }
843
844 if ($user_is_active) {
845 if (!$user_can_read_internal_mails
846 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL
847 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_BOTH) {
848 $newEmailAddresses = ilMailOptions::getExternalEmailsByUser($tmp_user, $tmp_mail_options);
849 $as_email = array_unique(array_merge($newEmailAddresses, $as_email));
850
851 if ($tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL) {
852 ilLoggerFactory::getLogger('mail')->debug(sprintf(
853 "Recipient with id %s will only receive external emails sent to: %s",
854 $id,
855 implode(', ', $newEmailAddresses)
856 ));
857 continue;
858 } else {
859 ilLoggerFactory::getLogger('mail')->debug(sprintf(
860 "Recipient with id %s will additionally receive external emails sent to: %s",
861 $id,
862 implode(', ', $newEmailAddresses)
863 ));
864 }
865 }
866 }
867
868 $mbox->setUserId($id);
869 $inbox_id = $mbox->getInboxFolder();
870
871 $mail_id = $this->sendInternalMail(
872 $inbox_id,
873 $this->user_id,
874 $a_attachments,
875 $a_rcp_to,
876 $a_rcp_cc,
877 '',
878 'unread',
879 $a_type,
880 0,
881 $a_subject,
882 $a_message,
883 $id,
884 0
885 );
886
887 if ($a_attachments) {
888 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id);
889 }
890 }
891
892 $to = array();
893 $bcc = array();
894
895 $as_email = array_values(array_unique($as_email));
896 if (count($as_email) == 1) {
897 $to[] = $as_email[0];
898 } else {
899 foreach ($as_email as $email) {
900 $bcc[] = $email;
901 }
902 }
903
904 if (count($to) > 0 || count($bcc) > 0) {
905 $this->sendMimeMail(implode(',', $to), '', implode(',', $bcc), $a_subject, $this->formatLinebreakMessage($a_message), $a_attachments);
906 }
907 } else {
908 $rcp_ids_replace = $this->getUserIds(array($a_rcp_to));
909 $rcp_ids_no_replace = $this->getUserIds(array($a_rcp_cc, $a_rcp_bcc));
910
911 ilLoggerFactory::getLogger('mail')->debug(sprintf(
912 "Parsed TO user ids from given recipients for serial letter notification: %s",
913 implode(', ', $rcp_ids_replace)
914 ));
915 ilLoggerFactory::getLogger('mail')->debug(sprintf(
916 "Parsed CC/BCC user ids from given recipients for serial letter notification: %s",
917 implode(', ', $rcp_ids_no_replace)
918 ));
919
920 $as_email = array();
921 $id_to_message_map = array();
922
923 foreach ($rcp_ids_replace as $id) {
924 $tmp_mail_options = new ilMailOptions($id);
925
926 $tmp_user = self::getCachedUserInstance($id);
927 $user_is_active = $tmp_user->getActive();
928 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
929
930 if (in_array('system', $a_type) && !$user_can_read_internal_mails) {
931 ilLoggerFactory::getLogger('mail')->debug(sprintf(
932 "Message is marked as 'system', skipped recipient with id %s (Accepted User Agreement:%s|Expired Account:%s)",
933 $id,
934 var_export(!$tmp_user->hasToAcceptTermsOfService(), 1),
935 var_export(!$tmp_user->checkTimeLimit(), 1)
936 ));
937 continue;
938 }
939
940 $id_to_message_map[$id] = $this->replacePlaceholders($a_message, $id);
941
942 if ($user_is_active) {
943 if (!$user_can_read_internal_mails
944 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL
945 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_BOTH) {
946 $as_email[$tmp_user->getId()] = ilMailOptions::getExternalEmailsByUser($tmp_user, $tmp_mail_options);
947
948 if ($tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL) {
949 ilLoggerFactory::getLogger('mail')->debug(sprintf(
950 "Recipient with id %s will only receive external emails sent to: %s",
951 $id,
952 implode(', ', $as_email[$tmp_user->getId()])
953 ));
954 continue;
955 } else {
956 ilLoggerFactory::getLogger('mail')->debug(sprintf(
957 "Recipient with id %s will additionally receive external emails sent to: %s",
958 $id,
959 implode(', ', $as_email[$tmp_user->getId()])
960 ));
961 }
962 }
963 }
964
965 $mbox->setUserId($id);
966 $inbox_id = $mbox->getInboxFolder();
967
968 $mail_id = $this->sendInternalMail(
969 $inbox_id,
970 $this->user_id,
971 $a_attachments,
972 $a_rcp_to,
973 $a_rcp_cc,
974 '',
975 'unread',
976 $a_type,
977 0,
978 $a_subject,
979 $id_to_message_map[$id],
980 $id,
981 0
982 );
983
984 if ($a_attachments) {
985 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id);
986 }
987 }
988
989 if (count($as_email)) {
990 foreach ($as_email as $id => $emails) {
991 if (0 == count($emails)) {
992 continue;
993 }
994
995 $toEmailAddresses = implode(',', $emails);
996 $this->sendMimeMail($toEmailAddresses, '', '', $a_subject, $this->formatLinebreakMessage($id_to_message_map[$id]), $a_attachments);
997 }
998 }
999
1000 $as_email = array();
1001
1002 $cc_and_bcc_message = $this->replacePlaceholders($a_message, 0, false);
1003
1004 foreach ($rcp_ids_no_replace as $id) {
1005 $tmp_mail_options = new ilMailOptions($id);
1006
1007 $tmp_user = self::getCachedUserInstance($id);
1008 $user_is_active = $tmp_user->getActive();
1009 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1010
1011 if ($user_is_active) {
1012 if (in_array('system', $a_type) && !$user_can_read_internal_mails) {
1013 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1014 "Message is marked as 'system', skipped recipient with id %s (Accepted User Agreement:%s|Expired Account:%s)",
1015 $id,
1016 var_export(!$tmp_user->hasToAcceptTermsOfService(), 1),
1017 var_export(!$tmp_user->checkTimeLimit(), 1)
1018 ));
1019 continue;
1020 }
1021
1022
1023 if (!$user_can_read_internal_mails
1024 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL
1025 || $tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_BOTH) {
1026 $newEmailAddresses = ilMailOptions::getExternalEmailsByUser($tmp_user, $tmp_mail_options);
1027 $as_email = array_unique(array_merge($newEmailAddresses, $as_email));
1028
1029 if ($tmp_mail_options->getIncomingType() == ilMailOptions::INCOMING_EMAIL) {
1030 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1031 "Recipient with id %s will only receive external emails sent to: %s",
1032 $id,
1033 implode(', ', $newEmailAddresses)
1034 ));
1035 continue;
1036 } else {
1037 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1038 "Recipient with id %s will additionally receive external emails sent to: %s",
1039 $id,
1040 implode(', ', $newEmailAddresses)
1041 ));
1042 }
1043 }
1044 }
1045
1046 $mbox->setUserId($id);
1047 $inbox_id = $mbox->getInboxFolder();
1048
1049 $mail_id = $this->sendInternalMail(
1050 $inbox_id,
1051 $this->user_id,
1052 $a_attachments,
1053 $a_rcp_to,
1054 $a_rcp_cc,
1055 '',
1056 'unread',
1057 $a_type,
1058 0,
1059 $a_subject,
1060 $cc_and_bcc_message,
1061 $id,
1062 0
1063 );
1064
1065 if ($a_attachments) {
1066 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id);
1067 }
1068 }
1069
1070 if (count($as_email)) {
1071 $this->sendMimeMail('', '', implode(',', $as_email), $a_subject, $this->formatLinebreakMessage($cc_and_bcc_message), $a_attachments);
1072 }
1073 }
1074
1075 return true;
1076 }
1077
1082 protected function getUserIds(array $a_recipients)
1083 {
1084 $usr_ids = array();
1085
1086 $a_recipients = implode(',', array_filter(array_map('trim', $a_recipients)));
1087
1088 $recipients = $this->parseAddresses($a_recipients);
1089 foreach ($recipients as $recipient) {
1090 $address_type = $this->mailAddressTypeFactory->getByPrefix($recipient);
1091 $usr_ids = array_merge($usr_ids, $address_type->resolve());
1092 }
1093
1094 return array_unique($usr_ids);
1095 }
1096
1104 protected function checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject)
1105 {
1106 $errors = array();
1107 foreach (array(
1108 $a_m_subject => array('mail_add_subject'),
1109 $a_rcp_to => array('mail_add_recipient')
1110 ) as $string => $e) {
1111 if (strlen($string) === 0) {
1112 $errors[] = $e;
1113 }
1114 }
1115
1116 return $errors;
1117 }
1118
1126 protected function checkRecipients($a_recipients)
1127 {
1128 $errors = array();
1129
1130 try {
1131 $recipients = $this->parseAddresses($a_recipients);
1132 foreach ($recipients as $recipient) {
1133 $address_type = $this->mailAddressTypeFactory->getByPrefix($recipient);
1134 if (!$address_type->validate($this->user_id)) {
1135 $errors = array_merge($errors, $address_type->getErrors());
1136 }
1137 }
1138 } catch (ilException $e) {
1139 $colon_pos = strpos($e->getMessage(), ':');
1140 throw new ilMailException(($colon_pos === false) ? $e->getMessage() : substr($e->getMessage(), $colon_pos + 2));
1141 }
1142
1143 return $errors;
1144 }
1145
1163 public function savePostData(
1164 $a_user_id,
1165 $a_attachments,
1166 $a_rcp_to,
1167 $a_rcp_cc,
1168 $a_rcp_bcc,
1169 $a_m_type,
1170 $a_m_email,
1171 $a_m_subject,
1172 $a_m_message,
1173 $a_use_placeholders,
1174 $a_tpl_context_id = null,
1175 $a_tpl_ctx_params = array()
1176 ) {
1177 if (!$a_attachments) {
1178 $a_attachments = null;
1179 }
1180 if (!$a_rcp_to) {
1181 $a_rcp_to = null;
1182 }
1183 if (!$a_rcp_cc) {
1184 $a_rcp_cc = null;
1185 }
1186 if (!$a_rcp_bcc) {
1187 $a_rcp_bcc = null;
1188 }
1189 if (!$a_m_type) {
1190 $a_m_type = null;
1191 }
1192 if (!$a_m_email) {
1193 $a_m_email = null;
1194 }
1195 if (!$a_m_message) {
1196 $a_m_message = null;
1197 }
1198 if (!$a_use_placeholders) {
1199 $a_use_placeholders = '0';
1200 }
1201
1202 $this->db->replace(
1203 $this->table_mail_saved,
1204 array(
1205 'user_id' => array('integer', $this->user_id)
1206 ),
1207 array(
1208 'attachments' => array('clob', serialize($a_attachments)),
1209 'rcp_to' => array('clob', $a_rcp_to),
1210 'rcp_cc' => array('clob', $a_rcp_cc),
1211 'rcp_bcc' => array('clob', $a_rcp_bcc),
1212 'm_type' => array('text', serialize($a_m_type)),
1213 'm_email' => array('integer', $a_m_email),
1214 'm_subject' => array('text', $a_m_subject),
1215 'm_message' => array('clob', $a_m_message),
1216 'use_placeholders' => array('integer', $a_use_placeholders),
1217 'tpl_ctx_id' => array('text', $a_tpl_context_id),
1218 'tpl_ctx_params' => array('blob', json_encode((array) $a_tpl_ctx_params))
1219 )
1220 );
1221
1222 $this->getSavedData();
1223
1224 return true;
1225 }
1226
1230 public function getSavedData()
1231 {
1232 $res = $this->db->queryF(
1233 "SELECT * FROM {$this->table_mail_saved} WHERE user_id = %s",
1234 array('integer'),
1235 array($this->user_id)
1236 );
1237
1238 $this->mail_data = $this->fetchMailData($this->db->fetchAssoc($res));
1239
1240 return $this->mail_data;
1241 }
1242
1255 public function sendMail($a_rcp_to, $a_rcp_cc, $a_rcp_bc, $a_m_subject, $a_m_message, $a_attachment, $a_type, $a_use_placeholders = 0)
1256 {
1257 global $DIC;
1258
1259 ilLoggerFactory::getLogger('mail')->debug(
1260 "New mail system task:" .
1261 " To: " . $a_rcp_to .
1262 " | CC: " . $a_rcp_cc .
1263 " | BCC: " . $a_rcp_bc .
1264 " | Subject: " . $a_m_subject
1265 );
1266
1267 $this->mail_to_global_roles = true;
1268 if (!$this->isSystemMail()) {
1269 $this->mail_to_global_roles = $DIC->rbac()->system()->checkAccessOfUser($this->user_id, 'mail_to_global_roles', $this->mail_obj_ref_id);
1270 }
1271
1272 if (in_array('system', $a_type)) {
1273 $a_type = array('system');
1274 }
1275
1276 if ($a_attachment && !$this->mfile->checkFilesExist($a_attachment)) {
1277 return array(array('mail_attachment_file_not_exist', $a_attachment));
1278 }
1279
1280 $errors = $this->checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bc, $a_m_subject);
1281 if (count($errors) > 0) {
1282 return $errors;
1283 }
1284
1285 $errors = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc);
1286 if (count($errors) > 0) {
1287 return $errors;
1288 }
1289
1290 $rcp_to = $a_rcp_to;
1291 $rcp_cc = $a_rcp_cc;
1292 $rcp_bc = $a_rcp_bc;
1293
1294 $c_emails = $this->getCountRecipients($rcp_to, $rcp_cc, $rcp_bc, true);
1295
1296 if (
1297 $c_emails && !$this->isSystemMail() &&
1298 !$DIC->rbac()->system()->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id)
1299 ) {
1300 return array(array('mail_no_permissions_write_smtp'));
1301 }
1302
1303 if ($this->appendInstallationSignature()) {
1304 $a_m_message .= self::_getInstallationSignature();
1305 }
1306
1307 $sent_id = $this->saveInSentbox($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bc, $a_type, $a_m_subject, $a_m_message);
1308
1309 if ($a_attachment) {
1310 $this->mfile->assignAttachmentsToDirectory($sent_id, $sent_id);
1311 $this->mfile->saveFiles($sent_id, $a_attachment);
1312 }
1313
1314 if ($c_emails) {
1315 $externalMailRecipientsTo = $this->getEmailRecipients($rcp_to);
1316 $externalMailRecipientsCc = $this->getEmailRecipients($rcp_cc);
1317 $externalMailRecipientsBcc = $this->getEmailRecipients($rcp_bc);
1318
1319 ilLoggerFactory::getLogger('mail')->debug(
1320 "Parsed external email addresses from given recipients:" .
1321 " To: " . $externalMailRecipientsTo .
1322 " | CC: " . $externalMailRecipientsCc .
1323 " | BCC: " . $externalMailRecipientsBcc .
1324 " | Subject: " . $a_m_subject
1325 );
1326
1327 $this->sendMimeMail(
1328 $externalMailRecipientsTo,
1329 $externalMailRecipientsCc,
1330 $externalMailRecipientsBcc,
1331 $a_m_subject,
1332 $this->formatLinebreakMessage($a_use_placeholders ? $this->replacePlaceholders($a_m_message, 0, false) : $a_m_message),
1333 $a_attachment,
1334 0
1335 );
1336 } else {
1337 ilLoggerFactory::getLogger('mail')->debug("No external email addresses given in recipient string");
1338 }
1339
1340 if (in_array('system', $a_type) && !$this->distributeMail($rcp_to, $rcp_cc, $rcp_bc, $a_m_subject, $a_m_message, $a_attachment, $sent_id, $a_type, 'system', $a_use_placeholders)) {
1341 return array(array('mail_send_error'));
1342 }
1343
1344 if (in_array('normal', $a_type) && !$this->distributeMail($rcp_to, $rcp_cc, $rcp_bc, $a_m_subject, $a_m_message, $a_attachment, $sent_id, $a_type, 'normal', $a_use_placeholders)) {
1345 return array(array('mail_send_error'));
1346 }
1347
1348 if (!$this->getSaveInSentbox()) {
1349 $this->deleteMails(array($sent_id));
1350 }
1351
1352 return array();
1353 }
1354
1361 public function validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
1362 {
1363 try {
1364 $errors = array();
1365 $errors = array_merge($errors, $this->checkRecipients($a_rcp_to));
1366 $errors = array_merge($errors, $this->checkRecipients($a_rcp_cc));
1367 $errors = array_merge($errors, $this->checkRecipients($a_rcp_bc));
1368
1369 if (count($errors) > 0) {
1370 return array_merge(array(array('mail_following_rcp_not_valid')), $errors);
1371 }
1372 } catch (ilMailException $e) {
1373 return array(array('mail_generic_rcp_error', $e->getMessage()));
1374 }
1375
1376 return array();
1377 }
1378
1390 protected function saveInSentbox($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_type, $a_m_subject, $a_m_message)
1391 {
1392 require_once 'Services/Mail/classes/class.ilMailbox.php';
1393
1394 $mbox = new ilMailbox($this->user_id);
1395 $sent_folder_id = $mbox->getSentFolder();
1396
1397 return $this->sendInternalMail(
1398 $sent_folder_id,
1399 $this->user_id,
1400 $a_attachment,
1401 $a_rcp_to,
1402 $a_rcp_cc,
1403 $a_rcp_bcc,
1404 'read',
1405 $a_type,
1406 0,
1407 $a_m_subject,
1408 $a_m_message,
1409 $this->user_id,
1410 0
1411 );
1412 }
1413
1425 public function sendMimeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_attachments, $a_no_soap = false)
1426 {
1427 require_once 'Services/Mail/classes/class.ilMimeMail.php';
1428
1429 $a_m_subject = self::getSubjectPrefix() . ' ' . $a_m_subject;
1430
1431 // #10854
1432 if ($this->isSOAPEnabled() && !$a_no_soap) {
1433 require_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
1434 $soap_client = new ilSoapClient();
1435 $soap_client->setResponseTimeout(5);
1436 $soap_client->enableWSDL(true);
1437 $soap_client->init();
1438
1439 $attachments = array();
1440 $a_attachments = $a_attachments ? $a_attachments : array();
1441 foreach ($a_attachments as $attachment) {
1442 $attachments[] = $this->mfile->getAbsolutePath($attachment);
1443 }
1444
1445 // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
1446 $attachments = implode('#:#', $attachments);
1447 // mjansen: use "#:#" as leading delimiter
1448 if (strlen($attachments)) {
1449 $attachments = "#:#" . $attachments;
1450 }
1451
1452 $soap_client->call('sendMail', array(
1453 session_id() . '::' . $_COOKIE['ilClientId'],
1454 $a_rcp_to,
1455 $a_rcp_cc,
1456 $a_rcp_bcc,
1457 $this->user_id,
1458 $a_m_subject,
1459 $a_m_message,
1460 $attachments
1461 ));
1462 } else {
1464 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
1465
1466 $mmail = new ilMimeMail();
1467 $mmail->From($senderFactory->getSenderByUsrId($this->user_id));
1468 $mmail->To($a_rcp_to);
1469 $mmail->Subject($a_m_subject);
1470 $mmail->Body($a_m_message);
1471
1472 if ($a_rcp_cc) {
1473 $mmail->Cc($a_rcp_cc);
1474 }
1475
1476 if ($a_rcp_bcc) {
1477 $mmail->Bcc($a_rcp_bcc);
1478 }
1479
1480 if (is_array($a_attachments)) {
1481 foreach ($a_attachments as $attachment) {
1482 $mmail->Attach($this->mfile->getAbsolutePath($attachment), '', 'inline', $attachment);
1483 }
1484 }
1485
1486 $mmail->Send();
1487 }
1488 }
1489
1494 public function saveAttachments($a_attachments)
1495 {
1496 $this->db->update(
1497 $this->table_mail_saved,
1498 array(
1499 'attachments' => array('clob', serialize($a_attachments))
1500 ),
1501 array(
1502 'user_id' => array('integer', $this->user_id)
1503 )
1504 );
1505
1506 return true;
1507 }
1508
1515 protected function parseAddresses($addresses)
1516 {
1517 if (strlen($addresses) > 0) {
1518 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1519 "Started parsing of recipient string: %s",
1520 $addresses
1521 ));
1522 }
1523
1524 $parser = $this->mailAddressParserFactory->getParser($addresses);
1525 $parsedAddresses = $parser->parse();
1526
1527 if (strlen($addresses) > 0) {
1528 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1529 "Parsed addresses: %s",
1530 implode(',', array_map(function (ilMailAddress $address) {
1531 return $address->getMailbox() . '@' . $address->getHost();
1532 }, $parsedAddresses))
1533 ));
1534 }
1535
1536 return $parsedAddresses;
1537 }
1538
1544 protected function getCountRecipient($a_recipients, $a_only_email = true)
1545 {
1546 $counter = 0;
1547
1548 $recipients = $this->parseAddresses($a_recipients);
1549 foreach ($recipients as $recipient) {
1550 if ($a_only_email) {
1551 // Fixed mantis bug #5875
1552 if (ilObjUser::_lookupId($recipient->getMailbox() . '@' . $recipient->getHost())) {
1553 continue;
1554 }
1555
1556 // Addresses which aren't on the self::ILIAS_HOST host, and
1557 // which have a mailbox which does not start with '#',
1558 // are external e-mail addresses
1559 if ($recipient->getHost() != self::ILIAS_HOST && substr($recipient->getMailbox(), 0, 1) != '#') {
1560 ++$counter;
1561 }
1562 } else {
1563 ++$counter;
1564 }
1565 }
1566
1567 return $counter;
1568 }
1569
1577 protected function getCountRecipients($a_to, $a_cc, $a_bcc, $a_only_email = true)
1578 {
1579 return
1580 $this->getCountRecipient($a_to, $a_only_email) +
1581 $this->getCountRecipient($a_cc, $a_only_email) +
1582 $this->getCountRecipient($a_bcc, $a_only_email);
1583 }
1584
1589 protected function getEmailRecipients($a_recipients)
1590 {
1591 $rcp = array();
1592
1593 $recipients = $this->parseAddresses($a_recipients);
1594 foreach ($recipients as $recipient) {
1595 if (substr($recipient->getMailbox(), 0, 1) != '#' && $recipient->getHost() != self::ILIAS_HOST) {
1596 // Fixed mantis bug #5875
1597 if (ilObjUser::_lookupId($recipient->getMailbox() . '@' . $recipient->getHost())) {
1598 continue;
1599 }
1600
1601 $rcp[] = $recipient->getMailbox() . '@' . $recipient->getHost();
1602 }
1603 }
1604
1605 return implode(',', $rcp);
1606 }
1607
1613 public static function _getAutoGeneratedMessageString(ilLanguage $lang = null)
1614 {
1615 global $DIC;
1616
1617 if (!($lang instanceof ilLanguage)) {
1618 require_once 'Services/Language/classes/class.ilLanguageFactory.php';
1620 }
1621
1622 $lang->loadLanguageModule('mail');
1623
1624 return sprintf(
1625 $lang->txt('mail_auto_generated_info'),
1626 $DIC->settings()->get('inst_name', 'ILIAS 5'),
1628 ) . "\n\n";
1629 }
1630
1635 public static function _getIliasMailerName()
1636 {
1638 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
1639
1640 return $senderFactory->system()->getFromName();
1641 }
1642
1648 public function appendInstallationSignature($a_flag = null)
1649 {
1650 if (null === $a_flag) {
1652 }
1653
1654 $this->appendInstallationSignature = $a_flag;
1655 return $this;
1656 }
1657
1661 public static function _getInstallationSignature()
1662 {
1663 global $DIC;
1664
1665 $signature = $DIC->settings()->get('mail_system_sys_signature');
1666
1667 $clientUrl = ilUtil::_getHttpPath();
1668 $clientdirs = glob(ILIAS_WEB_DIR . '/*', GLOB_ONLYDIR);
1669 if (is_array($clientdirs) && count($clientdirs) > 1) {
1670 $clientUrl .= '/login.php?client_id=' . CLIENT_ID; // #18051
1671 }
1672
1673 $signature = str_ireplace('[CLIENT_NAME]', $DIC['ilClientIniFile']->readVariable('client', 'name'), $signature);
1674 $signature = str_ireplace('[CLIENT_DESC]', $DIC['ilClientIniFile']->readVariable('client', 'description'), $signature);
1675 $signature = str_ireplace('[CLIENT_URL]', $clientUrl, $signature);
1676
1677 if (!preg_match('/^[\n\r]+/', $signature)) {
1678 $signature = "\n" . $signature;
1679 }
1680
1681 return $signature;
1682 }
1683
1688 public static function getSubjectPrefix()
1689 {
1690 global $DIC;
1691
1692 $subjectPrefix = $DIC->settings()->get('mail_subject_prefix');
1693 if (false === $subjectPrefix) {
1694 $subjectPrefix = self::MAIL_SUBJECT_PREFIX;
1695 }
1696
1697 return $subjectPrefix;
1698 }
1699
1705 public static function getSalutation($a_usr_id, ilLanguage $a_language = null)
1706 {
1707 global $DIC;
1708
1709 $lang = ($a_language instanceof ilLanguage) ? $a_language : $DIC->language();
1710 $lang->loadLanguageModule('mail');
1711
1712 $gender = ilObjUser::_lookupGender($a_usr_id);
1713 $gender = $gender ? $gender : 'n';
1714 $name = ilObjUser::_lookupName($a_usr_id);
1715
1716 if (!strlen($name['firstname'])) {
1717 return $lang->txt('mail_salutation_anonymous') . ',';
1718 }
1719
1720 return
1721 $lang->txt('mail_salutation_' . $gender) . ' ' .
1722 ($name['title'] ? $name['title'] . ' ' : '') .
1723 ($name['firstname'] ? $name['firstname'] . ' ' : '') .
1724 $name['lastname'] . ',';
1725 }
1726
1731 protected static function getCachedUserInstance($a_usr_id)
1732 {
1733 if (isset(self::$userInstances[$a_usr_id])) {
1734 return self::$userInstances[$a_usr_id];
1735 }
1736
1737 self::$userInstances[$a_usr_id] = new ilObjUser($a_usr_id);
1738 return self::$userInstances[$a_usr_id];
1739 }
1740
1744 public function formatLinebreakMessage($a_message)
1745 {
1746 return $a_message;
1747 }
1748}
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$parser
Definition: BPMN2Parser.php:23
$_COOKIE['client_id']
Definition: server.php:9
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
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
const CONTEXT_CRON
static getType()
Get context type.
Base class for ILIAS Exception handling.
This class handles all operations on files (attachments) in directory ilias_data/mail.
static _getLanguage($a_lang_key='')
Get langauge object.
language handling
static getLogger($a_component_id)
Get component logger.
Class ilMailAddressTypeFactory.
Class ilMailAddress.
Class ilMailException.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
Class ilMailOptions this class handles user mails.
static getExternalEmailsByUser(ilObjUser $user, ilMailOptions $mail_options=null)
Class ilMailRfc822AddressParserFactory.
This class handles base functions for mail handling.
static getCachedUserInstance($a_usr_id)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
formatNamesForOutput($a_recipients)
Prepends the fullname of each ILIAS login name (if user has a public profile) found in the passed str...
$mailAddressParserFactory
markUnread(array $a_mail_ids)
$table_mail_saved
getCountRecipient($a_recipients, $a_only_email=true)
deleteMails(array $a_mail_ids)
distributeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_subject, $a_message, $a_attachments, $sent_mail_id, $a_type, $a_action, $a_use_placeholders=0)
getEmailRecipients($a_recipients)
appendInstallationSignature($a_flag=null)
Setter/Getter for appending the installation signarue.
checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject)
setSaveInSentbox($a_save_in_sentbox)
getCountRecipients($a_to, $a_cc, $a_bcc, $a_only_email=true)
getMail($a_mail_id)
checkRecipients($a_recipients)
Check if recipients are valid.
markRead(array $a_mail_ids)
enableSOAP($a_status)
Define if external mails should be sent using SOAP client or not.
static $userInstances
isSOAPEnabled()
getNextMail($a_mail_id)
replacePlaceholders($a_message, $a_user_id=0, $replace_empty=true)
isSystemMail()
moveMailsToFolder(array $a_mail_ids, $a_folder_id)
updateDraft( $a_folder_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_type, $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=array())
const MAIL_SUBJECT_PREFIX
$mail_obj_ref_id
countMailsOfFolder($a_folder_id)
$mailAddressTypeFactory
existsRecipient($a_recipient, $a_existing_recipients)
sendInternalMail( $a_folder_id, $a_sender_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_status, $a_m_type, $a_m_email, $a_m_subject, $a_m_message, $a_user_id=0, $a_use_placeholders=0, $a_tpl_context_id=null, $a_tpl_context_params=array())
save mail in folder @access private
getMailsOfFolder($a_folder_id, $filter=array())
saveAttachments($a_attachments)
static getSubjectPrefix()
Get text that will be prepended to auto generated mails.
getNewDraftId($usrId, $folderId)
static _getInstallationSignature()
fetchMailData($a_row)
saveInSentbox($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_type, $a_m_subject, $a_m_message)
Stores a message in the sent bod of the current user.
getPreviousMail($a_mail_id)
$mail_to_global_roles
deleteMailsOfFolder($a_folder_id)
$appendInstallationSignature
static getSalutation($a_usr_id, ilLanguage $a_language=null)
parseAddresses($addresses)
Explode recipient string, allowed separators are ',' ';' ' ' Returns an array with recipient ilMailAd...
getMailObjectReferenceId()
__construct( $a_user_id, ilMailAddressTypeFactory $mailAddressTypeFactory=null, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
sendMail($a_rcp_to, $a_rcp_cc, $a_rcp_bc, $a_m_subject, $a_m_message, $a_attachment, $a_type, $a_use_placeholders=0)
Should be used to send notifcations over the internal or external mail channel.
readMailObjectReferenceId()
Read and set the mail object ref id (administration node)
__get($name)
Magic interceptor method __get Used to include files / instantiate objects at runtime.
formatLinebreakMessage($a_message)
getSaveInSentbox()
getUserIds(array $a_recipients)
const ILIAS_HOST
savePostData( $a_user_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_type, $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
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 _getHttpPath()
$counter
$lang
Definition: consent.php:3
if(!array_key_exists('StateId', $_REQUEST)) $id
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if($format !==null) $name
Definition: metadata.php:146
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:193
$errors
Definition: index.php:6
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$a_type
Definition: workflow.php:92