ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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';
5
110{
118
124 var $lng;
125
132
134
141
148
155
162
169
170
177
184
191
203
204 var $soap_enabled = true;
206
207 private $use_pear = true;
209
213 const ILIAS_HOST = 'ilias';
214
223 protected $properties = array();
224
228 protected static $userInstances = array();
229
236 public function __construct($a_user_id)
237 {
238 require_once "./Services/Mail/classes/class.ilFileDataMail.php";
239 require_once "Services/Mail/classes/class.ilMailOptions.php";
240
241 global $ilias, $lng, $ilUser;
242
243 $lng->loadLanguageModule("mail");
244
245 // Initiate variables
246 $this->ilias =& $ilias;
247 $this->lng =& $lng;
248 $this->table_mail = 'mail';
249 $this->table_mail_saved = 'mail_saved';
250 $this->user_id = $a_user_id;
251 $this->mfile = new ilFileDataMail($this->user_id);
252 $this->mail_options = new ilMailOptions($a_user_id);
253
254 // DEFAULT: sent mail aren't stored insentbox of user.
255 $this->setSaveInSentbox(false);
256
257 // GET REFERENCE ID OF MAIL OBJECT
259 }
260
268 public function __get($name)
269 {
270 global $ilUser;
271
272 if(isset($this->properties[$name]))
273 {
274 return $this->properties[$name];
275 }
276
277 // Used to include files / instantiate objects at runtime
278 if($name == 'mlists')
279 {
280 if(is_object($ilUser))
281 {
282 require_once 'Services/Contact/classes/class.ilMailingLists.php';
283 $this->properties[$name] = new ilMailingLists($ilUser);
284 return $this->properties[$name];
285 }
286 }
287 }
288
289 public function doesRecipientStillExists($a_recipient, $a_existing_recipients)
290 {
291 if(self::_usePearMail())
292 {
293 $recipients = $this->explodeRecipients($a_existing_recipients);
294 if(is_a($recipients, 'PEAR_Error'))
295 {
296 return false;
297 }
298 else
299 {
300 foreach($recipients as $rcp)
301 {
302 if (substr($rcp->mailbox, 0, 1) != '#')
303 {
304 if(trim($rcp->mailbox) == trim($a_recipient) ||
305 trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
306 {
307 return true;
308 }
309 }
310 else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
311 {
312 if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
313 {
314 return true;
315 }
316 }
317 else
318 {
319 if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
320 {
321 return true;
322 }
323 }
324 }
325 }
326 }
327 else
328 {
329 $recipients = $this->explodeRecipients($a_existing_recipients);
330 if(count($recipients))
331 {
332 foreach($recipients as $recipient)
333 {
334 if(trim($recipient) == trim($a_recipient))
335 {
336 return true;
337 }
338 }
339 }
340 }
341
342 return false;
343 }
344
352 function enableSOAP($a_status)
353 {
354 $this->soap_enabled = $a_status;
355 }
356 function isSOAPEnabled()
357 {
358 global $ilSetting;
359
360 if(!extension_loaded('curl') || !$ilSetting->get('soap_user_administration'))
361 {
362 return false;
363 }
364
365 // Prevent using SOAP in cron context
367 {
368 return false;
369 }
370
371 return (bool) $this->soap_enabled;
372 }
373
374
375 function setSaveInSentbox($a_save_in_sentbox)
376 {
377 $this->save_in_sentbox = $a_save_in_sentbox;
378 }
379
381 {
383 }
384
390 function setMailSendType($a_types)
391 {
392 $this->mail_send_type = $a_types;
393 }
394
400 function setMailRcpTo($a_rcp_to)
401 {
402 $this->mail_rcp_to = $a_rcp_to;
403 }
404
410 function setMailRcpCc($a_rcp_cc)
411 {
412 $this->mail_rcp_cc = $a_rcp_cc;
413 }
414
420 function setMailRcpBc($a_rcp_bc)
421 {
422 $this->mail_rcp_bc = $a_rcp_bc;
423 }
424
430 function setMailSubject($a_subject)
431 {
432 $this->mail_subject = $a_subject;
433 }
434
440 function setMailMessage($a_message)
441 {
442 $this->mail_message = $a_message;
443 }
444
450 {
451 include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
452 $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
453 }
454
456 {
458 }
459
470 public function formatNamesForOutput($users = '')
471 {
472 $users = trim($users);
473 if($users)
474 {
475 if(strstr($users, ','))
476 {
477 $rcp_to_array = array();
478
479 $recipients = explode(',', $users);
480 foreach($recipients as $recipient)
481 {
482 $recipient = trim($recipient);
483 if($uid = ilObjUser::_lookupId($recipient))
484 {
485 if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
486 {
487 $tmp_obj = self::getCachedUserInstance($uid);
488 $rcp_to_array[] = $tmp_obj->getFullname().' ['.$recipient.']';
489 }
490 else
491 {
492 $rcp_to_array[] = $recipient;
493 }
494 }
495 else
496 {
497 $rcp_to_array[] = $recipient;
498 }
499 }
500
501 return trim(implode(', ', $rcp_to_array));
502 }
503 else
504 {
505 if($uid = ilObjUser::_lookupId($users))
506 {
507 if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
508 {
509 $tmp_obj = self::getCachedUserInstance($uid);
510 return $tmp_obj->getFullname().' ['.$users.']';
511 }
512 else
513 {
514 return $users;
515 }
516 }
517 else
518 {
519 return $users;
520 }
521 }
522 }
523 else
524 {
525 return $this->lng->txt('not_available');
526 }
527 }
528
529 function getPreviousMail($a_mail_id)
530 {
531 global $ilDB;
532
533 $ilDB->setLimit(1);
534 $res = $ilDB->queryf("
535 SELECT b.* FROM " . $this->table_mail ." a
536 INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
537 AND b.user_id = a.user_id AND b.send_time > a.send_time
538 WHERE a.user_id = %s
539 AND a.mail_id = %s ORDER BY b.send_time ASC",
540 array('integer', 'integer'),
541 array($this->user_id, $a_mail_id));
542
543 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
544
545 return $this->mail_data;
546 }
547
548 function getNextMail($a_mail_id)
549 {
550 global $ilDB;
551
552 $ilDB->setLimit(1);
553 $res = $ilDB->queryf("
554 SELECT b.* FROM " . $this->table_mail ." a
555 INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
556 AND b.user_id = a.user_id AND b.send_time < a.send_time
557 WHERE a.user_id = %s
558 AND a.mail_id = %s ORDER BY b.send_time DESC",
559 array('integer', 'integer'),
560 array($this->user_id, $a_mail_id));
561
562 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
563
564 return $this->mail_data;
565 }
566
574 function getMailsOfFolder($a_folder_id, $filter = array())
575 {
576 global $ilDB;
577
578 $this->mail_counter = array();
579 $this->mail_counter['read'] = 0;
580 $this->mail_counter['unread'] = 0;
581
582 $query = "SELECT sender_id, m_subject, mail_id, m_status, send_time FROM ". $this->table_mail ."
583 LEFT JOIN object_data ON obj_id = sender_id
584 WHERE user_id = %s
585 AND folder_id = %s
586 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)) ";
587
588 if($filter['status'])
589 {
590 $query .= ' AND m_status = '.$ilDB->quote($filter['status'], 'text');
591 }
592 if($filter['type'])
593 {
594 $query .= ' AND '.$ilDB->like('m_type', 'text', '%%:"'.$filter['type'].'"%%', false);
595 }
596
597 $query .= " ORDER BY send_time DESC";
598
599 $res = $ilDB->queryf($query,
600 array('integer', 'integer'),
601 array($this->user_id, $a_folder_id));
602
603 while ($row = $ilDB->fetchObject($res))
604 {
605 $tmp = $this->fetchMailData($row);
606
607 if($tmp['m_status'] == 'read')
608 {
609 ++$this->mail_counter['read'];
610 }
611
612 if($tmp['m_status'] == 'unread')
613 {
614 ++$this->mail_counter['unread'];
615 }
616
617 $output[] = $tmp;
618 }
619
620 $this->mail_counter['total'] = count($output);
621
622 return $output ? $output : array();
623 }
624
631 function countMailsOfFolder($a_folder_id)
632 {
633 global $ilDB;
634
635 $res = $ilDB->queryf("
636 SELECT COUNT(*) FROM ". $this->table_mail ."
637 WHERE user_id = %s
638 AND folder_id = %s",
639 array('integer', 'integer'),
640 array($this->user_id, $a_folder_id));
641
642 return $res->numRows();
643 }
644
651 function deleteMailsOfFolder($a_folder_id)
652 {
653 if ($a_folder_id)
654 {
655 global $ilDB;
656
657 /*$statement = $ilDB->manipulateF("
658 DELETE FROM ". $this->table_mail ."
659 WHERE user_id = %s
660 AND folder_id = %s",
661 array('integer', 'integer'),
662 array($this->user_id, $a_folder_id));*/
663 $mails = $this->getMailsOfFolder($a_folder_id);
664 foreach((array)$mails as $mail_data)
665 {
666 $this->deleteMails(array($mail_data['mail_id']));
667 }
668
669 return true;
670 }
671
672 return false;
673 }
674
682 {
683 return is_array($this->mail_counter) ? $this->mail_counter : array(
684 "total" => 0,
685 "read" => 0,
686 "unread" => 0);
687 }
688
695 function getMail($a_mail_id)
696 {
697 global $ilDB;
698
699 $res = $ilDB->queryf("
700 SELECT * FROM ". $this->table_mail ."
701 WHERE user_id = %s
702 AND mail_id = %s",
703 array('integer', 'integer'),
704 array($this->user_id, $a_mail_id));
705
706 $this->mail_data =$this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
707
708 return $this->mail_data;
709 }
710
717 function markRead($a_mail_ids)
718 {
719
720 global $ilDB;
721
722 $data = array();
723 $data_types = array();
724
725 $query = "UPDATE ". $this->table_mail ."
726 SET m_status = %s
727 WHERE user_id = %s ";
728 array_push($data_types, 'text', 'integer');
729 array_push($data, 'read', $this->user_id);
730
731 $cnt_mail_ids = count($a_mail_ids);
732
733 if (is_array($a_mail_ids) &&
734 count($a_mail_ids) > 0)
735 {
736
737 $in = 'mail_id IN (';
738 $counter = 0;
739 foreach($a_mail_ids as $a_mail_id)
740 {
741 array_push($data, $a_mail_id);
742 array_push($data_types, 'integer');
743
744 if($counter > 0) $in .= ',';
745 $in .= '%s';
746 ++$counter;
747 }
748 $in .= ')';
749
750 $query .= ' AND '.$in;
751 }
752
753 $res = $ilDB->manipulateF($query, $data_types, $data);
754
755 return true;
756 }
757
764 function markUnread($a_mail_ids)
765 {
766 global $ilDB;
767
768 $data = array();
769 $data_types = array();
770
771 $query = "UPDATE ". $this->table_mail ."
772 SET m_status = %s
773 WHERE user_id = %s ";
774 array_push($data_types, 'text', 'integer');
775 array_push($data, 'unread', $this->user_id);
776
777 $cnt_mail_ids = count($a_mail_ids);
778
779 if (is_array($a_mail_ids) &&
780 count($a_mail_ids) > 0)
781 {
782
783 $in = 'mail_id IN (';
784 $counter = 0;
785 foreach($a_mail_ids as $a_mail_id)
786 {
787 array_push($data, $a_mail_id);
788 array_push($data_types, 'integer');
789
790 if($counter > 0) $in .= ',';
791 $in .= '%s';
792 ++$counter;
793 }
794 $in .= ')';
795
796 $query .= ' AND '.$in;
797 }
798
799 $statement = $ilDB->manipulateF($query, $data_types, $data);
800
801 return true;
802 }
803
811 function moveMailsToFolder($a_mail_ids,$a_folder_id)
812 {
813 global $ilDB;
814
815 $data = array();
816 $data_types = array();
817
818 $query = "UPDATE ". $this->table_mail ."
819 SET folder_id = %s
820 WHERE user_id = %s ";
821 array_push($data_types, 'text', 'integer');
822 array_push($data, $a_folder_id, $this->user_id);
823
824 $cnt_mail_ids = count($a_mail_ids);
825
826 if (is_array($a_mail_ids) &&
827 count($a_mail_ids) > 0)
828 {
829
830 $in = 'mail_id IN (';
831 $counter = 0;
832 foreach($a_mail_ids as $a_mail_id)
833 {
834 array_push($data, $a_mail_id);
835 array_push($data_types, 'integer');
836
837 if($counter > 0) $in .= ',';
838 $in .= '%s';
839 ++$counter;
840 }
841 $in .= ')';
842
843 $query .= ' AND '.$in;
844 }
845
846 $statement = $ilDB->manipulateF($query, $data_types, $data);
847
848 return true;
849 }
850
857 function deleteMails($a_mail_ids)
858 {
859 global $ilDB;
860
861 foreach ($a_mail_ids as $id)
862 {
863 $statement = $ilDB->manipulateF("
864 DELETE FROM ". $this->table_mail ."
865 WHERE user_id = %s
866 AND mail_id = %s ",
867 array('integer', 'integer'),
868 array($this->user_id, $id));
869
870 $this->mfile->deassignAttachmentFromDirectory($id);
871 }
872
873 return true;
874 }
875
882 function fetchMailData($a_row)
883 {
884 if (!$a_row) return;
885
886 return array(
887 "mail_id" => $a_row->mail_id,
888 "user_id" => $a_row->user_id,
889 "folder_id" => $a_row->folder_id,
890 "sender_id" => $a_row->sender_id,
891 "attachments" => unserialize(stripslashes($a_row->attachments)),
892 "send_time" => $a_row->send_time,
893 "rcp_to" => $a_row->rcp_to,
894 "rcp_cc" => $a_row->rcp_cc,
895 "rcp_bcc" => $a_row->rcp_bcc,
896 "m_status" => $a_row->m_status,
897 "m_type" => unserialize(stripslashes($a_row->m_type)),
898 "m_email" => $a_row->m_email,
899 "m_subject" => $a_row->m_subject,
900 "m_message" => $a_row->m_message,
901 "import_name" => $a_row->import_name,
902 "use_placeholders"=> $a_row->use_placeholders);
903 }
904
905 function updateDraft($a_folder_id,
906 $a_attachments,
907 $a_rcp_to,
908 $a_rcp_cc,
909 $a_rcp_bcc,
910 $a_m_type,
911 $a_m_email,
912 $a_m_subject,
913 $a_m_message,
914 $a_draft_id = 0, $a_use_placeholders = 0)
915 {
916 global $ilDB;
917
918 $ilDB->update($this->table_mail,
919 array(
920 'folder_id' => array('integer', $a_folder_id),
921 'attachments' => array('clob', serialize($a_attachments)),
922 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
923 'rcp_to' => array('clob', $a_rcp_to),
924 'rcp_cc' => array('clob', $a_rcp_cc),
925 'rcp_bcc' => array('clob', $a_rcp_bcc),
926 'm_status' => array('text', 'read'),
927 'm_type' => array('text', serialize($a_m_type)),
928 'm_email' => array('integer', $a_m_email),
929 'm_subject' => array('text', $a_m_subject),
930 'm_message' => array('clob', $a_m_message),
931 'use_placeholders' => array('integer', $a_use_placeholders)
932 ),
933 array(
934 'mail_id' => array('integer', $a_draft_id)
935 )
936 );
937
938 return $a_draft_id;
939 }
940
958 function sendInternalMail($a_folder_id,
959 $a_sender_id,
960 $a_attachments,
961 $a_rcp_to,
962 $a_rcp_cc,
963 $a_rcp_bcc,
964 $a_status,
965 $a_m_type,
966 $a_m_email,
967 $a_m_subject,
968 $a_m_message,
969 $a_user_id = 0, $a_use_placeholders = 0)
970 {
971 $a_user_id = $a_user_id ? $a_user_id : $this->user_id;
972
973 global $ilDB, $log;
974 //$log->write('class.ilMail->sendInternalMail to user_id:'.$a_rcp_to.' '.$a_m_message);
975
976 if ($a_use_placeholders)
977 {
978 $a_m_message = $this->replacePlaceholders($a_m_message, $a_user_id);
979 }
980 else
981 {
982 $a_use_placeholders = '0';
983 }
984
985
986 if(!$a_user_id) $a_user_id = '0';
987 if(!$a_folder_id) $a_folder_id = '0';
988 if(!$a_sender_id) $a_sender_id = NULL;
989 if(!$a_attachments) $a_attachments = NULL;
990 if(!$a_rcp_to) $a_rcp_to = NULL;
991 if(!$a_rcp_cc) $a_rcp_cc = NULL;
992 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
993 if(!$a_status) $a_status = NULL;
994 if(!$a_m_type) $a_m_type = NULL;
995 if(!$a_m_email) $a_m_email = NULL;
996 if(!$a_m_subject) $a_m_subject = NULL;
997 if(!$a_m_message) $a_m_message = NULL;
998
999
1000 $next_id = $ilDB->nextId($this->table_mail);
1001
1002 $ilDB->insert($this->table_mail, array(
1003 'mail_id' => array('integer', $next_id),
1004 'user_id' => array('integer', $a_user_id),
1005 'folder_id' => array('integer', $a_folder_id),
1006 'sender_id' => array('integer', $a_sender_id),
1007 'attachments' => array('clob', serialize($a_attachments)),
1008 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
1009 'rcp_to' => array('clob', $a_rcp_to),
1010 'rcp_cc' => array('clob', $a_rcp_cc),
1011 'rcp_bcc' => array('clob', $a_rcp_bcc),
1012 'm_status' => array('text', $a_status),
1013 'm_type' => array('text', serialize($a_m_type)),
1014 'm_email' => array('integer', $a_m_email),
1015 'm_subject' => array('text', $a_m_subject),
1016 'm_message' => array('clob', $a_m_message)
1017 ));
1018
1019 return $next_id; //$ilDB->getLastInsertId();
1020
1021 }
1022
1023 function replacePlaceholders($a_message, $a_user_id)
1024 {
1025 global $lng;
1026
1027 $user = self::getCachedUserInstance($a_user_id);
1028
1029 // determine salutation
1030 switch ($user->getGender())
1031 {
1032 case 'f': $gender_salut = $lng->txt('salutation_f');
1033 break;
1034 case 'm': $gender_salut = $lng->txt('salutation_m');
1035 break;
1036 }
1037
1038 $a_message = str_replace('[MAIL_SALUTATION]', $gender_salut, $a_message);
1039 $a_message = str_replace('[LOGIN]', $user->getLogin(), $a_message);
1040 $a_message = str_replace('[FIRST_NAME]', $user->getFirstname(), $a_message);
1041 $a_message = str_replace('[LAST_NAME]', $user->getLastname(), $a_message);
1042 $a_message = str_replace('[ILIAS_URL]', ILIAS_HTTP_PATH.'/login.php?client_id='.CLIENT_ID, $a_message);
1043 $a_message = str_replace('[CLIENT_NAME]', CLIENT_NAME, $a_message);
1044
1045 return $a_message;
1046 }
1047
1061 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)
1062 {
1063 global $log;
1064
1065 include_once 'Services/Mail/classes/class.ilMailbox.php';
1066 include_once './Services/User/classes/class.ilObjUser.php';
1067
1068 if (!ilMail::_usePearMail())
1069 {
1070 // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1071 $a_rcp_to = $this->__substituteRecipients($a_rcp_to, 'resubstitute');
1072 $a_rcp_cc = $this->__substituteRecipients($a_rcp_cc, 'resubstitute');
1073 $a_rcp_bcc = $this->__substituteRecipients($a_rcp_bcc, 'resubstitute');
1074 }
1075
1076 $mbox = new ilMailbox();
1077
1078 if (!$a_use_placeholders) # No Placeholders
1079 {
1080 $rcp_ids = $this->getUserIds(trim($a_rcp_to).','.trim($a_rcp_cc).','.trim($a_rcp_bcc));
1081
1082 $as_email = array();
1083
1084 foreach($rcp_ids as $id)
1085 {
1086 $tmp_mail_options = new ilMailOptions($id);
1087
1088 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1089 $tmp_user = self::getCachedUserInstance($id);
1090 $user_is_active = $tmp_user->getActive();
1091 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1092
1093 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1094 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1095 {
1096 continue;
1097 }
1098
1099 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS/HER MAIL
1100 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1101
1102 // Do not send external mails to inactive users!!!
1103 if($user_is_active)
1104 {
1105 if (!$user_can_read_internal_mails ||
1106 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1107 {
1108 $as_email[] = $tmp_user->getEmail();
1109 continue;
1110 }
1111
1112 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1113 {
1114 $as_email[] = $tmp_user->getEmail();
1115 }
1116 }
1117 $mbox->setUserId($id);
1118 $inbox_id = $mbox->getInboxFolder();
1119
1120 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1121 $a_attachments, $a_rcp_to,
1122 $a_rcp_cc, '', 'unread', $a_type,
1123 0, $a_subject, $a_message, $id, 0);
1124 if ($a_attachments)
1125 {
1126 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1127 }
1128 }
1129
1130 // SEND EMAIL TO ALL USERS WHO DECIDED 'email' or 'both'
1131 $to = array();
1132 $bcc = array();
1133
1134 if(count($as_email) == 1)
1135 {
1136 $to[] = $as_email[0];
1137 }
1138 else
1139 {
1140 foreach ($as_email as $email)
1141 {
1142 $bcc[] = $email;
1143 }
1144 }
1145
1146 if(count($to) > 0 || count($bcc) > 0)
1147 {
1148 $this->sendMimeMail(implode(',', $to), '', implode(',', $bcc), $a_subject, $a_message, $a_attachments);
1149 }
1150 }
1151 else # Use Placeholders
1152 {
1153 // to
1154 $rcp_ids_replace = $this->getUserIds(trim($a_rcp_to));
1155
1156 // cc / bcc
1157 $rcp_ids_no_replace = $this->getUserIds(trim($a_rcp_cc).','.trim($a_rcp_bcc));
1158
1159 $as_email = array();
1160
1161 // to
1162 foreach($rcp_ids_replace as $id)
1163 {
1164 $tmp_mail_options = new ilMailOptions($id);
1165
1166 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1167 $tmp_user = self::getCachedUserInstance($id);
1168 $user_is_active = $tmp_user->getActive();
1169 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1170
1171 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1172 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1173 {
1174 continue;
1175 }
1176
1177 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1178 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1179
1180 // Do not send external mails to inactive users!!!
1181 if($user_is_active)
1182 {
1183 if (!$user_can_read_internal_mails ||
1184 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1185 {
1186 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1187 continue;
1188 }
1189
1190 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1191 {
1192 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1193 }
1194 }
1195 $mbox->setUserId($id);
1196 $inbox_id = $mbox->getInboxFolder();
1197
1198 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1199 $a_attachments, $a_rcp_to,
1200 $a_rcp_cc, '', 'unread', $a_type,
1201 0, $a_subject, $a_message, $id, 1);
1202 if ($a_attachments)
1203 {
1204 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1205 }
1206 }
1207
1208 if (count($as_email))
1209 {
1210 foreach ($as_email as $id => $email)
1211 {
1212 $this->sendMimeMail($email, '', '', $a_subject, $this->replacePlaceholders($a_message, $id), $a_attachments);
1213 }
1214 }
1215
1216 $as_email = array();
1217
1218 // cc / bcc
1219 foreach($rcp_ids_no_replace as $id)
1220 {
1221 $tmp_mail_options = new ilMailOptions($id);
1222
1223 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1224 $tmp_user = self::getCachedUserInstance($id);
1225 $user_is_active = $tmp_user->getActive();
1226 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1227
1228 // Do not send external mails to inactive users!!!
1229 if($user_is_active)
1230 {
1231 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1232 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1233 {
1234 continue;
1235 }
1236
1237 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1238 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1239 if (!$user_can_read_internal_mails ||
1240 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1241 {
1242 $as_email[] = $tmp_user->getEmail();
1243 continue;
1244 }
1245
1246 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1247 {
1248 $as_email[] = $tmp_user->getEmail();
1249 }
1250 }
1251 $mbox->setUserId($id);
1252 $inbox_id = $mbox->getInboxFolder();
1253
1254 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1255 $a_attachments, $a_rcp_to,
1256 $a_rcp_cc, '', 'unread', $a_type,
1257 0, $a_subject, $a_message, $id, 0);
1258 if ($a_attachments)
1259 {
1260 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1261 }
1262 }
1263
1264 if (count($as_email))
1265 {
1266 $this->sendMimeMail('', '', implode(',', $as_email), $a_subject, $a_message, $a_attachments);
1267 }
1268 }
1269
1270 return true;
1271 }
1272
1278 function getUserIds($a_recipients)
1279 {
1280 global $log, $rbacreview;
1281 $ids = array();
1282
1283 $this->validatePear($a_recipients);
1284 if (ilMail::_usePearMail() && $this->getUsePear() == true)
1285 {
1286 $tmp_names = $this->explodeRecipients($a_recipients );
1287 if (! is_a($tmp_names, 'PEAR_Error'))
1288 {
1289 for ($i = 0;$i < count($tmp_names); $i++)
1290 {
1291 if (substr($tmp_names[$i]->mailbox,0,1) == '#' || substr($tmp_names[$i]->mailbox,0,2) == '"#')
1292 {
1293 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1294 foreach($role_ids as $role_id)
1295 {
1296 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1297 {
1298 $ids[] = $usr_id;
1299 }
1300 }
1301 }
1302 else if (strtolower($tmp_names[$i]->host) == self::ILIAS_HOST)
1303 {
1304 if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i]->mailbox)))
1305 {
1306 //$log->write('class.ilMail->getUserIds() recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host.' user_id:'.$id);
1307 $ids[] = $id;
1308 }
1309 else
1310 {
1311 //$log->write('class.ilMail->getUserIds() no user account found for recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1312 }
1313 }
1314 else
1315 {
1316 // Fixed mantis bug #5875
1317 if($id = ilObjUser::_lookupId($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host))
1318 {
1319 $ids[] = $id;
1320 }
1321 else
1322 {
1323 //$log->write('class.ilMail->getUserIds() external recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1324 }
1325 }
1326 }
1327 }
1328 else
1329 {
1330 //$log->write('class.ilMail->getUserIds() illegal recipients:'.$a_recipients);
1331 }
1332 }
1333 else
1334 {
1335 $tmp_names = $this->explodeRecipients($a_recipients, $this->getUsePear());
1336 for ($i = 0;$i < count($tmp_names); $i++)
1337 {
1338 if (substr($tmp_names[$i],0,1) == '#' || substr($tmp_names[$i], 0, 2) == '"#')
1339 {
1340 if(ilUtil::groupNameExists(addslashes(substr($tmp_names[$i],1))))
1341 {
1342 include_once("./Services/Object/classes/class.ilObjectFactory.php");
1343 include_once('./Modules/Group/classes/class.ilObjGroup.php');
1344
1345 foreach(ilObject::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($tmp_names[$i],1)))) as $ref_id)
1346 {
1348 break;
1349 }
1350 // STORE MEMBER IDS IN $ids
1351 foreach ($grp_object->getGroupMemberIds() as $id)
1352 {
1353 $ids[] = $id;
1354 }
1355 }
1356 // is role: get role ids
1357 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1358 {
1359 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1360 {
1361 $ids[] = $usr_id;
1362 }
1363 }
1364
1365 }
1366 else if (!empty($tmp_names[$i]))
1367 {
1368 if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i])))
1369 {
1370 $ids[] = $id;
1371 }
1372 }
1373 }
1374 }
1375 return array_unique($ids);
1376 }
1377
1388 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1389 {
1390 $error_message = '';
1391
1392 $a_m_subject = trim($a_m_subject);
1393 $a_rcp_to = trim($a_rcp_to);
1394
1395 if (empty($a_m_subject))
1396 {
1397 $error_message .= $error_message ? "<br>" : '';
1398 $error_message .= $this->lng->txt("mail_add_subject");
1399 }
1400
1401 if (empty($a_rcp_to))
1402 {
1403 $error_message .= $error_message ? "<br>" : '';
1404 $error_message .= $this->lng->txt("mail_add_recipient");
1405 }
1406
1407 return $error_message;
1408 }
1409
1416 function getEmailsOfRecipients($a_rcp)
1417 {
1418 global $rbacreview;
1419
1420 $addresses = array();
1421
1422 $this->validatePear($a_rcp);
1423 if (ilMail::_usePearMail() && $this->getUsePear())
1424 {
1425 $tmp_rcp = $this->explodeRecipients($a_rcp);
1426 if (! is_a($tmp_rcp, 'PEAR_Error'))
1427 {
1428 foreach ($tmp_rcp as $rcp)
1429 {
1430 // NO GROUP
1431 if (substr($rcp->mailbox,0,1) != '#' && substr($rcp->mailbox,0, 2) != '"#')
1432 {
1433 if (strtolower($rcp->host) != self::ILIAS_HOST)
1434 {
1435 $addresses[] = $rcp->mailbox.'@'.$rcp->host;
1436 continue;
1437 }
1438
1439 if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)))
1440 {
1441 $tmp_user = self::getCachedUserInstance($id);
1442 $addresses[] = $tmp_user->getEmail();
1443 continue;
1444 }
1445 }
1446 else
1447 {
1448 // Roles
1449 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1450 foreach($role_ids as $role_id)
1451 {
1452 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1453 {
1454 $tmp_user = self::getCachedUserInstance($usr_id);
1455 $addresses[] = $tmp_user->getEmail();
1456 }
1457 }
1458 }
1459 }
1460 }
1461 }
1462 else
1463 {
1464 $tmp_rcp = $this->explodeRecipients($a_rcp, $this->getUsePear());
1465
1466 foreach ($tmp_rcp as $rcp)
1467 {
1468 // NO GROUP
1469 if (substr($rcp,0,1) != '#' && substr($rcp,0,2) != '"#')
1470 {
1471 if (strpos($rcp,'@'))
1472 {
1473 $addresses[] = $rcp;
1474 continue;
1475 }
1476
1477 if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1478 {
1479 $tmp_user = self::getCachedUserInstance($id);
1480 $addresses[] = $tmp_user->getEmail();
1481 continue;
1482 }
1483 }
1484 else
1485 {
1486 // GROUP THINGS
1487 include_once("./Services/Object/classes/class.ilObjectFactory.php");
1488 include_once('./Modules/Group/classes/class.ilObjGroup.php');
1489
1490 // Fix
1491 foreach(ilObjGroup::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($rcp,1)))) as $ref_id)
1492 {
1494 break;
1495 }
1496 // GET EMAIL OF MEMBERS AND STORE THEM IN $addresses
1497 foreach ($grp_object->getGroupMemberIds() as $id)
1498 {
1499 $tmp_user = self::getCachedUserInstance($id);
1500 $addresses[] = $tmp_user->getEmail();
1501 }
1502 }
1503 }
1504 }
1505
1506 return $addresses;
1507 }
1508
1516 function checkRecipients($a_recipients)
1517 {
1518 global $rbacsystem,$rbacreview;
1519 $wrong_rcps = '';
1520
1521 $this->validatePear($a_recipients);
1522 if (ilMail::_usePearMail() && $this->getUsePear())
1523 {
1524 $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1525
1526 if (is_a($tmp_rcp, 'PEAR_Error'))
1527 {
1528 $colon_pos = strpos($tmp_rcp->message, ':');
1529 $wrong_rcps = '<br />'.(($colon_pos === false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1530 }
1531 else
1532 {
1533 foreach ($tmp_rcp as $rcp)
1534 {
1535 // NO ROLE MAIL ADDRESS
1536 if (substr($rcp->mailbox,0,1) != '#' && substr($rcp->mailbox,0,2) != '"#')
1537 {
1538 // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1539 $user_id = ($rcp->host == self::ILIAS_HOST) ? ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)) : false;
1540 if ($user_id == false && $rcp->host == self::ILIAS_HOST)
1541 {
1542 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox);
1543 continue;
1544 }
1545
1546 // CHECK IF USER CAN RECEIVE MAIL
1547 if ($user_id)
1548 {
1549 if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1550 {
1551 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1552 " (".$this->lng->txt("user_cant_receive_mail").")";
1553 continue;
1554 }
1555 }
1556 }
1557 else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
1558 {
1559 if (!$this->mlists->mailingListExists($rcp->mailbox))
1560 {
1561 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1562 " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1563 }
1564
1565 continue;
1566 }
1567 else
1568 {
1569
1570 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1571
1572 if(!$this->mail_to_global_roles && is_array($role_ids))
1573 {
1574 foreach($role_ids as $role_id)
1575 {
1576 if($rbacreview->isGlobalRole($role_id))
1577 {
1578 include_once('Services/Mail/exceptions/class.ilMailException.php');
1579 throw new ilMailException('mail_to_global_roles_not_allowed');
1580
1581 }
1582 }
1583 }
1584 if (count($role_ids) == 0)
1585 {
1586 $wrong_rcps .= '<br />'.htmlentities($rcp->mailbox).
1587 ' ('.$this->lng->txt('mail_no_recipient_found').')';
1588 continue;
1589 }
1590 else if (count($role_ids) > 1)
1591 {
1592 $wrong_rcps .= '<br/>'.htmlentities($rcp->mailbox).
1593 ' ('.sprintf($this->lng->txt('mail_multiple_recipients_found'), implode(',', $role_ids)).')';
1594 }
1595 }
1596 }
1597 }
1598 }
1599 else // NO PEAR
1600 {
1601 $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1602
1603 foreach ($tmp_rcp as $rcp)
1604 {
1605 if (empty($rcp))
1606 {
1607 continue;
1608 }
1609 // NO GROUP
1610 if (substr($rcp,0,1) != '#' && substr($rcp,0,2) != '"#')
1611 {
1612 // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1613 if (!ilObjUser::getUserIdByLogin(addslashes($rcp)) and
1614 !ilUtil::is_email($rcp))
1615 {
1616 $wrong_rcps .= "<br />".htmlentities($rcp);
1617 continue;
1618 }
1619
1620 // CHECK IF USER CAN RECEIVE MAIL
1621 if ($user_id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1622 {
1623 if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1624 {
1625 $wrong_rcps .= "<br />".htmlentities($rcp).
1626 " (".$this->lng->txt("user_cant_receive_mail").")";
1627 continue;
1628 }
1629 }
1630 }
1631 else if (substr($rcp, 0, 7) == '#il_ml_')
1632 {
1633 if (!$this->mlists->mailingListExists($rcp))
1634 {
1635 $wrong_rcps .= "<br />".htmlentities($rcp).
1636 " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1637 }
1638
1639 continue;
1640 }
1641 else if (ilUtil::groupNameExists(addslashes(substr($rcp,1))))
1642 {
1643 continue;
1644 }
1645 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1646 {
1647 $wrong_rcps .= "<br />".htmlentities($rcp).
1648 " (".$this->lng->txt("mail_no_valid_group_role").")";
1649 continue;
1650 }
1651 else if (!$this->mail_to_global_roles)
1652 {
1653 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1654 if((int)$role_id && $rbacreview->isGlobalRole($role_id))
1655 {
1656 include_once('Services/Mail/exceptions/class.ilMailException.php');
1657 throw new ilMailException('mail_to_global_roles_not_allowed');
1658 }
1659 }
1660 }
1661 }
1662 return $wrong_rcps;
1663 }
1664
1680 function savePostData($a_user_id,
1681 $a_attachments,
1682 $a_rcp_to,
1683 $a_rcp_cc,
1684 $a_rcp_bcc,
1685 $a_m_type,
1686 $a_m_email,
1687 $a_m_subject,
1688 $a_m_message,
1689 $a_use_placeholders)
1690 {
1691 global $ilDB;
1692
1693
1694 if(!$a_attachments) $a_attachments = NULL;
1695 if(!$a_rcp_to) $a_rcp_to = NULL;
1696 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1697 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1698 if(!$a_m_type) $a_m_type = NULL;
1699 if(!$a_m_email) $a_m_email = NULL;
1700 if(!$a_m_message) $a_m_message = NULL;
1701 if(!$a_use_placeholders) $a_use_placeholders = '0';
1702
1703
1704 $statement = $ilDB->manipulateF('
1705 DELETE FROM '. $this->table_mail_saved .'
1706 WHERE user_id = %s',
1707 array('integer'), array($this->user_id));
1708
1709 $ilDB->insert($this->table_mail_saved, array(
1710 'user_id' => array('integer', $a_user_id),
1711 'attachments' => array('clob', serialize($a_attachments)),
1712 'rcp_to' => array('clob', $a_rcp_to),
1713 'rcp_cc' => array('clob', $a_rcp_cc),
1714 'rcp_bcc' => array('clob', $a_rcp_bcc),
1715 'm_type' => array('text', serialize($a_m_type)),
1716 'm_email' => array('integer', $a_m_email),
1717 'm_subject' => array('text', $a_m_subject),
1718 'm_message' => array('clob', $a_m_message),
1719 'use_placeholders' => array('integer', $a_use_placeholders),
1720 ));
1721
1722 $this->getSavedData();
1723
1724 return true;
1725 }
1726
1732 function getSavedData()
1733 {
1734 global $ilDB;
1735
1736 $res = $ilDB->queryf('
1737 SELECT * FROM '. $this->table_mail_saved .'
1738 WHERE user_id = %s',
1739 array('integer'),
1740 array($this->user_id));
1741
1742 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
1743
1744 return $this->mail_data;
1745 }
1746
1753 public function validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
1754 {
1755 try
1756 {
1757 $message = '';
1758
1759 if($error_message = $this->checkRecipients($a_rcp_to))
1760 {
1761 $message .= $error_message;
1762 }
1763 if($error_message = $this->checkRecipients($a_rcp_cc))
1764 {
1765 $message .= $error_message;
1766 }
1767 if($error_message = $this->checkRecipients($a_rcp_bc))
1768 {
1769 $message .= $error_message;
1770 }
1771
1772 if(strlen($message) > 0)
1773 {
1774 return $this->lng->txt('mail_following_rcp_not_valid') . $message;
1775 }
1776
1777 return '';
1778 }
1779 catch(ilMailException $e)
1780 {
1781 return $this->lng->txt('mail_following_rcp_not_valid') . $this->lng->txt($e->getMessage());
1782 }
1783 }
1784
1798 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)
1799 {
1800 global $lng,$rbacsystem,$log;
1801 //$log->write('class.ilMail.sendMail '.$a_rcp_to.' '.$a_m_subject);
1802
1803 $this->mail_to_global_roles = true;
1804 if($this->user_id != ANONYMOUS_USER_ID)
1805 {
1806 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id, 'mail_to_global_roles', $this->mail_obj_ref_id);
1807 }
1808
1809 if (in_array("system",$a_type))
1810 {
1811 $a_type = array('system');
1812 }
1813
1814 if ($a_attachment)
1815 {
1816 if (!$this->mfile->checkFilesExist($a_attachment))
1817 {
1818 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1819 }
1820 }
1821 // CHECK NECESSARY MAIL DATA FOR ALL TYPES
1822 if ($error_message = $this->checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1823 {
1824 return $error_message;
1825 }
1826
1827 $error_message = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc);
1828 if(strlen($error_message) > 0)
1829 {
1830 return $error_message;
1831 }
1832
1833 // ACTIONS FOR ALL TYPES
1834
1835
1836 // GET RCPT OF MAILING LISTS
1837
1838 $rcp_to_list = $this->parseRcptOfMailingLists($a_rcp_to, true);
1839 $rcp_cc_list = $this->parseRcptOfMailingLists($a_rcp_cc, true);
1840 $rcp_bc_list = $this->parseRcptOfMailingLists($a_rcp_bc, true);
1841
1842 $rcp_to = $rcp_cc = $rcp_bc = array();
1843 foreach($rcp_to_list as $mlist_id => $mlist_rec)
1844 {
1845 if($mlist_id)
1846 {
1847 // internal mailing lists are sent as bcc
1848 $mlist_id = substr($mlist_id, 7);
1849 if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1850 {
1851 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1852 continue;
1853 }
1854 }
1855
1856 $rcp_to = array_merge($rcp_to, $mlist_rec);
1857 }
1858 foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1859 {
1860 if($mlist_id)
1861 {
1862 // internal mailing lists are sent as bcc
1863 $mlist_id = substr($mlist_id, 7);
1864 if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1865 {
1866 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1867 continue;
1868 }
1869 }
1870
1871 $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1872 }
1873 foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1874 {
1875 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1876 }
1877
1878 $rcp_to = implode(',', $rcp_to);
1879 $rcp_cc = implode(',', $rcp_cc);
1880 $rcp_bc = implode(',', $rcp_bc);
1881
1882
1883 if (! ilMail::_usePearMail() )
1884 {
1885 // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1886 $rcp_to = $this->__substituteRecipients($rcp_to,"substitute");
1887 $rcp_cc = $this->__substituteRecipients($rcp_cc,"substitute");
1888 $rcp_bc = $this->__substituteRecipients($rcp_bc,"substitute");
1889 }
1890
1891 // COUNT EMAILS
1892 $c_emails = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,true);
1893 $c_rcp = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,false);
1894
1895 // currently disabled..
1896 /*
1897 if (count($c_emails))
1898 {
1899 if (!$this->getEmailOfSender())
1900 {
1901 return $lng->txt("mail_check_your_email_addr");
1902 }
1903 }
1904 */
1905
1906 // check smtp permission
1907 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1908 !$rbacsystem->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id))
1909 {
1910 return $this->lng->txt('mail_no_permissions_write_smtp');
1911 }
1912
1913 if($this->appendInstallationSignature())
1914 {
1915 $a_m_message .= self::_getInstallationSignature();
1916 }
1917
1918 // save mail in sent box
1919 $sent_id = $this->saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1920 $a_m_subject,$a_m_message);
1921
1922 if($a_attachment)
1923 {
1924 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1925
1926 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1927 {
1928 return $error;
1929 }
1930 }
1931
1932 // FILTER EMAILS
1933 // IF EMAIL RECIPIENT
1934 if($c_emails)
1935 {
1936 $this->sendMimeMail($this->__getEmailRecipients($rcp_to),
1937 $this->__getEmailRecipients($rcp_cc),
1938 $this->__getEmailRecipients($rcp_bc),
1939 $a_m_subject,
1940 $a_m_message,
1941 $a_attachment,
1942 0);
1943 }
1944
1945 if (in_array('system',$a_type))
1946 {
1947 if (!$this->distributeMail($rcp_to,$rcp_cc,$rcp_bc,$a_m_subject,$a_m_message,$a_attachment,$sent_id,$a_type,'system', $a_use_placeholders))
1948 {
1949 return $lng->txt("mail_send_error");
1950 }
1951 }
1952 // ACTIONS FOR TYPE SYSTEM AND NORMAL
1953 if (in_array('normal',$a_type))
1954 {
1955 // TRY BOTH internal and email (depends on user settings)
1956 if (!$this->distributeMail($rcp_to,$rcp_cc,$rcp_bc,$a_m_subject,$a_m_message,$a_attachment,$sent_id,$a_type,'normal', $a_use_placeholders))
1957 {
1958 return $lng->txt("mail_send_error");
1959 }
1960 }
1961
1962 // Temporary bugfix
1963 if (!$this->getSaveInSentbox())
1964 {
1965 $this->deleteMails(array($sent_id));
1966 }
1967
1968 return '';
1969 }
1970
1971 function parseRcptOfMailingLists($rcpt = '', $maintain_lists = false)
1972 {
1973 if ($rcpt == '')
1974 {
1975 if(!$maintain_lists)
1976 {
1977 return $rcpt;
1978 }
1979 else
1980 {
1981 return array();
1982 }
1983 }
1984//@todo check rcp pear validation
1985 $arrRcpt = $this->explodeRecipients(trim($rcpt));
1986 if (!is_array($arrRcpt) || empty($arrRcpt))
1987 {
1988 if(!$maintain_lists)
1989 {
1990 return $rcpt;
1991 }
1992 else
1993 {
1994 return array();
1995 }
1996 }
1997
1998 $new_rcpt = array();
1999
2000 foreach ($arrRcpt as $item)
2001 {
2002 if (ilMail::_usePearMail())
2003 {
2004 if (substr($item->mailbox, 0, 7) == '#il_ml_')
2005 {
2006 if ($this->mlists->mailingListExists($item->mailbox))
2007 {
2008 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2009 {
2010 if(!$maintain_lists)
2011 {
2012 $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2013 }
2014 else
2015 {
2016 $new_rcpt[$item->mailbox][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2017 }
2018 }
2019 }
2020 }
2021 else
2022 {
2023 $tmp_rcpt = '';
2024 if($item->host == self::ILIAS_HOST)
2025 {
2026 $tmp_rcpt = $item->mailbox;
2027 }
2028 else
2029 {
2030 $tmp_rcpt = $item->mailbox.'@'.$item->host;
2031 }
2032
2033 if(!$maintain_lists)
2034 {
2035 $new_rcpt[] = $tmp_rcpt;
2036 }
2037 else
2038 {
2039 $new_rcpt[0][] = $tmp_rcpt;
2040 }
2041 }
2042 }
2043 else
2044 {
2045 if (substr($item, 0, 7) == '#il_ml_')
2046 {
2047 if ($this->mlists->mailingListExists($item))
2048 {
2049 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2050 {
2051 if(!$maintain_lists)
2052 {
2053 $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2054 }
2055 else
2056 {
2057 $new_rcpt[$item][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2058 }
2059 }
2060 }
2061 }
2062 else
2063 {
2064 if(!$maintain_lists)
2065 {
2066 $new_rcpt[] = $item;
2067 }
2068 else
2069 {
2070 $new_rcpt[0][] = $item;
2071 }
2072 }
2073 }
2074 }
2075
2076 if(!$maintain_lists)
2077 {
2078 return implode(',', $new_rcpt);
2079 }
2080 else
2081 {
2082 return $new_rcpt;
2083 }
2084 }
2085
2098 function saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_type,
2099 $a_m_subject,$a_m_message)
2100 {
2101 include_once "Services/Mail/classes/class.ilMailbox.php";
2102
2103 $mbox = new ilMailbox($this->user_id);
2104 $sent_id = $mbox->getSentFolder();
2105
2107 return $this->sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2108 $a_rcp_bcc,'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2109 }
2110
2117 public static function addFullname($a_email, $a_fullname)
2118 {
2119 include_once 'Services/Mail/classes/class.ilMimeMail.php';
2120 return ilMimeMail::_mimeEncode($a_fullname).' <'.$a_email.'>';
2121 }
2122
2129 public function getMimeMailSender()
2130 {
2134 global $ilUser;
2135
2136 include_once "Services/Mail/classes/class.ilMimeMail.php";
2137
2138 if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2139 {
2140 $email = $ilUser->getEmail();
2141 $fullname = $ilUser->getFullname();
2142 if($ilUser->getId() != $this->user_id)
2143 {
2144 $user = self::getCachedUserInstance($this->user_id);
2145 $email = $user->getEmail();
2146 $fullname = $user->getFullname();
2147 }
2148
2149 $sender = self::addFullname($email, $fullname);
2150 }
2151 else
2152 {
2153 $sender = self::getIliasMailerAddress();
2154 }
2155
2156 return $sender;
2157 }
2158
2168 public static function getIliasMailerAddress()
2169 {
2170 global $ilSetting;
2171
2172 include_once 'Services/Mail/classes/class.ilMimeMail.php';
2173
2174 $no_reply_adress = trim($ilSetting->get('mail_external_sender_noreply'));
2175 if(strlen($no_reply_adress))
2176 {
2177 if(strpos($no_reply_adress, '@') === false)
2178 $no_reply_adress = 'noreply@'.$no_reply_adress;
2179
2180 if(!ilUtil::is_email($no_reply_adress))
2181 {
2182 $no_reply_adress = 'noreply@'.$_SERVER['SERVER_NAME'];
2183 }
2184
2185 $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2186 ' <'.$no_reply_adress.'>';
2187 }
2188 else
2189 {
2190 $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2191 ' <noreply@'.$_SERVER['SERVER_NAME'].'>';
2192 }
2193
2194 return $sender;
2195 }
2196
2210 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap = false)
2211 {
2212 include_once "Services/Mail/classes/class.ilMimeMail.php";
2213
2214 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2215
2216 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2217 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2218
2219 $a_m_subject = self::getSubjectPrefix().' '.$a_m_subject;
2220
2221 $sender = $this->getMimeMailSender();
2222
2223 // #10854
2224 if($this->isSOAPEnabled() && !$a_no_soap)
2225 {
2226 // Send per soap
2227 include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2228
2229 $soap_client = new ilSoapClient();
2230 $soap_client->setResponseTimeout(1);
2231 $soap_client->enableWSDL(true);
2232 $soap_client->init();
2233
2234 $attachments = array();
2235 $a_attachments = $a_attachments ? $a_attachments : array();
2236 foreach($a_attachments as $attachment)
2237 {
2238 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2239 }
2240 // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
2241 $attachments = implode('#:#',$attachments);
2242 // mjansen: use "#:#" as leading delimiter
2243 if(strlen($attachments))
2244 $attachments = "#:#".$attachments;
2245
2246 $soap_client->call('sendMail',array(session_id().'::'.$_COOKIE['ilClientId'], // session id
2247 $a_rcp_to,
2248 $a_rcp_cc,
2249 $a_rcp_bcc,
2250 $sender,
2251 $a_m_subject,
2252 $a_m_message,
2253 $attachments));
2254
2255 return true;
2256 }
2257 else
2258 {
2259 // send direct
2260 include_once "Services/Mail/classes/class.ilMimeMail.php";
2261
2262 $mmail = new ilMimeMail();
2263 $mmail->autoCheck(false);
2264 $mmail->From($sender);
2265 $mmail->To($a_rcp_to);
2266 // Add installation name to subject
2267 $mmail->Subject($a_m_subject);
2268 $mmail->Body($a_m_message);
2269
2270 if ($a_rcp_cc)
2271 {
2272 $mmail->Cc($a_rcp_cc);
2273 }
2274
2275 if ($a_rcp_bcc)
2276 {
2277 $mmail->Bcc($a_rcp_bcc);
2278 }
2279
2280 if (is_array($a_attachments))
2281 {
2282 foreach ($a_attachments as $attachment)
2283 {
2284 $mmail->Attach($this->mfile->getAbsolutePath($attachment), '', 'inline', $attachment);
2285 }
2286 }
2287
2288 $mmail->Send();
2289 }
2290 }
2297 {
2298 $umail = self::getCachedUserInstance($this->user_id);
2299 $sender = $umail->getEmail();
2300
2301 if (ilUtil::is_email($sender))
2302 {
2303 return $sender;
2304 }
2305 else
2306 {
2307 return '';
2308 }
2309 }
2310
2317 function saveAttachments($a_attachments)
2318 {
2319 global $ilDB;
2320
2321 $ilDB->update($this->table_mail_saved,
2322 array
2323 (
2324 'attachments' => array('clob', serialize($a_attachments))
2325 ),
2326 array
2327 (
2328 'user_id' => array('integer', $this->user_id)
2329 )
2330 );
2331
2332 return true;
2333 }
2334
2341 {
2342 return $this->mail_data["attachments"] ? $this->mail_data["attachments"] : array();
2343 }
2344
2358 function explodeRecipients($a_recipients, $use_pear = true)
2359 {
2360 $a_recipients = trim($a_recipients);
2361
2362 // WHITESPACE IS NOT ALLOWED AS SEPERATOR
2363 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2364 $a_recipients = preg_replace("/;/",",",$a_recipients);
2365
2366 if (ilMail::_usePearMail() && $use_pear == true)
2367 {
2368 if (strlen(trim($a_recipients)) > 0)
2369 {
2370 require_once './Services/PEAR/lib/Mail/RFC822.php';
2371 $parser = new Mail_RFC822();
2372 return $parser->parseAddressList($a_recipients, self::ILIAS_HOST, false, true);
2373 } else {
2374 return array();
2375 }
2376 }
2377 else
2378 {
2379 foreach(explode(',',$a_recipients) as $tmp_rec)
2380 {
2381 if($tmp_rec)
2382 {
2383 $rcps[] = trim($tmp_rec);
2384 }
2385 }
2386 return is_array($rcps) ? $rcps : array();
2387 }
2388 }
2389
2390 function __getCountRecipient($rcp,$a_only_email = true)
2391 {
2392 $counter = 0;
2393
2394 $this->validatePear($rcp);
2395 if (ilMail::_usePearMail() && $this->getUsePear())
2396 {
2397 $tmp_rcp = $this->explodeRecipients($rcp);
2398 if (! is_a($tmp_rcp, 'PEAR_Error'))
2399 {
2400 foreach ($tmp_rcp as $to)
2401 {
2402 if ($a_only_email)
2403 {
2404 // Fixed mantis bug #5875
2405 if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2406 {
2407 continue;
2408 }
2409
2410 // Addresses which aren't on the self::ILIAS_HOST host, and
2411 // which have a mailbox which does not start with '#',
2412 // are external e-mail addresses
2413 if ($to->host != 'ilias' && substr($to->mailbox,0,1) != '#' && substr($to->mailbox,0,2) != '"#')
2414 {
2415 ++$counter;
2416 }
2417 }
2418 else
2419 {
2420 ++$counter;
2421 }
2422 }
2423 }
2424 }
2425 else
2426 {
2427 foreach ($this->explodeRecipients($rcp,$this->getUsePear()) as $to)
2428 {
2429 if ($a_only_email)
2430 {
2431 $to = $this->__substituteRecipients($to,"resubstitute");
2432 if (strpos($to,'@'))
2433 {
2434 // Fixed mantis bug #5875
2435 if(ilObjUser::_lookupId($to))
2436 {
2437 continue;
2438 }
2439
2440 ++$counter;
2441 }
2442 }
2443 else
2444 {
2445 ++$counter;
2446 }
2447 }
2448 }
2449 return $counter;
2450 }
2451
2452
2453 function __getCountRecipients($a_to,$a_cc,$a_bcc,$a_only_email = true)
2454 {
2455 return $this->__getCountRecipient($a_to,$a_only_email)
2456 + $this->__getCountRecipient($a_cc,$a_only_email)
2457 + $this->__getCountRecipient($a_bcc,$a_only_email);
2458 }
2459
2460 function __getEmailRecipients($a_rcp)
2461 {
2462 if (ilMail::_usePearMail())
2463 {
2464 $rcp = array();
2465 $tmp_rcp = $this->explodeRecipients($a_rcp);
2466 if (! is_a($tmp_rcp, 'PEAR_Error'))
2467 {
2468 foreach ($tmp_rcp as $to)
2469 {
2470 if(substr($to->mailbox,0,1) != '#' && substr($to->mailbox,0,2) != '"#' && $to->host != 'ilias')
2471 {
2472 // Fixed mantis bug #5875
2473 if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2474 {
2475 continue;
2476 }
2477
2478 $rcp[] = $to->mailbox.'@'.$to->host;
2479 }
2480 }
2481 }
2482 return implode(',',$rcp);
2483 }
2484 else
2485 {
2486 foreach ($this->explodeRecipients($a_rcp) as $to)
2487 {
2488 $to = $this->__substituteRecipients($to,"resubstitute");
2489 if(strpos($to,'@'))
2490 {
2491 // Fixed mantis bug #5875
2492 if(ilObjUser::_lookupId($to))
2493 {
2494 continue;
2495 }
2496
2497 $rcp[] = $to;
2498 }
2499 }
2500 return implode(',',$rcp ? $rcp : array());
2501 }
2502 }
2503
2504 function __prependMessage($a_m_message,$rcp_to,$rcp_cc)
2505 {
2506 $inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 3";
2507
2508 $message = $inst_name." To:".$rcp_to."\n";
2509
2510 if ($rcp_cc)
2511 {
2512 $message .= "Cc: ".$rcp_cc;
2513 }
2514
2515 $message .= "\n\n";
2516 $message .= $a_m_message;
2517
2518 return $message;
2519 }
2520
2528 function __substituteRecipients($a_rcp,$direction)
2529 {
2530 $new_name = array();
2531
2532 $tmp_names = $this->explodeRecipients($a_rcp);
2533
2534
2535 foreach($tmp_names as $name)
2536 {
2537 if(strpos($name,"#") === 0)
2538 {
2539 $new_name[] = $name;
2540 continue;
2541 }
2542 switch($direction)
2543 {
2544 case "substitute":
2545 if(strpos($name,"@") and ilObjUser::_loginExists($name))
2546 {
2547 $new_name[] = preg_replace("/@/","�#�",$name);
2548 }
2549 else
2550 {
2551 $new_name[] = $name;
2552 }
2553 break;
2554
2555 case "resubstitute":
2556 if(stristr($name,"�#�"))
2557 {
2558 $new_name[] = preg_replace("/�#�/","@",$name);
2559 }
2560 else
2561 {
2562 $new_name[] = $name;
2563 }
2564 break;
2565 }
2566 }
2567 return implode(",",$new_name);
2568 }
2569
2585 public static function _getUserInternalMailboxAddress($usr_id, $login=null, $firstname=null, $lastname=null)
2586 {
2587 if (ilMail::_usePearMail())
2588 {
2589 if ($login == null)
2590 {
2591 require_once './Services/User/classes/class.ilObjUser.php';
2592 $usr_obj = self::getCachedUserInstance($usr_id);
2593 $login = $usr_obj->getLogin();
2594 $firstname = $usr_obj->getFirstname();
2595 $lastname = $usr_obj->getLastname();
2596 }
2597 // The following line of code creates a properly formatted mailbox
2598 // address. Unfortunately, it does not work, because ILIAS removes
2599 // everything between '<' '>' characters
2600 // Therefore, we just return the login - sic.
2601 // FIXME - Make this work in a future release
2602 /*
2603 return preg_replace('/[()<>@,;:\\".\[\]]/','',$firstname.' '.$lastname).' <'.$login.'>';
2604 */
2605 return $login.'hhho';
2606 }
2607 else
2608 {
2609 return $login;
2610 }
2611 }
2618 public static function _usePearMail()
2619 {
2623 global $ilSetting;
2624
2625 return $ilSetting->get('pear_mail_enable', 0);
2626 }
2627
2636 public static function _getAutoGeneratedMessageString($lang = null)
2637 {
2638 global $ilSetting;
2639
2640 if(!$lang)
2641 {
2642 include_once('./Services/Language/classes/class.ilLanguageFactory.php');
2644 }
2645 $http_path = ilUtil::_getHttpPath();
2646
2647 $lang->loadLanguageModule('mail');
2648 return sprintf($lang->txt('mail_auto_generated_info'),
2649 $ilSetting->get('inst_name','ILIAS 5'),
2650 $http_path)."\n\n";
2651 }
2652
2659 public static function _getIliasMailerName()
2660 {
2664 global $ilSetting;
2665
2666 if(strlen($ilSetting->get('mail_system_sender_name')))
2667 {
2668 return $ilSetting->get('mail_system_sender_name');
2669 }
2670 else if(strlen($ilSetting->get('short_inst_name')))
2671 {
2672 return $ilSetting->get('short_inst_name');
2673 }
2674
2675 return 'ILIAS';
2676 }
2677
2686 public function appendInstallationSignature($a_flag = null)
2687 {
2688 if(null === $a_flag) {
2690 }
2691
2692 $this->appendInstallationSignature = $a_flag;
2693
2694 return $this;
2695 }
2696
2705 public static function _getInstallationSignature()
2706 {
2707 global $ilClientIniFile;
2708
2709 $signature = "\n\n* * * * *\n";
2710
2711 $signature .= $ilClientIniFile->readVariable('client', 'name')."\n";
2712 if(strlen($desc = $ilClientIniFile->readVariable('client', 'description')))
2713 {
2714 $signature .= $desc."\n";
2715 }
2716
2717 $signature .= ilUtil::_getHttpPath();
2718
2719 $clientdirs = glob(ILIAS_WEB_DIR."/*", GLOB_ONLYDIR);
2720 if(is_array($clientdirs) && count($clientdirs) > 1)
2721 {
2722 // #18051
2723 $signature .= '/login.php?client_id='.CLIENT_ID;
2724 }
2725
2726 $signature .= "\n\n";
2727
2728 return $signature;
2729 }
2730
2735 public static function getSubjectPrefix()
2736 {
2737 global $ilSetting;
2738 static $prefix = null;
2739
2740 return $prefix == null ? $ilSetting->get('mail_subject_prefix','') : $prefix;
2741 }
2742
2748 public static function getSalutation($a_usr_id,$a_language = null)
2749 {
2750 global $lng;
2751
2752 $lang = $a_language ? $a_language : $lng;
2753
2754 $lang->loadLanguageModule('mail');
2755 $gender = ilObjUser::_lookupGender($a_usr_id);
2756 $gender = $gender ? $gender : 'n';
2757 $name = ilObjUser::_lookupName($a_usr_id);
2758
2759 if(!strlen($name['firstname']))
2760 {
2761 return $lang->txt('mail_salutation_anonymous').',';
2762 }
2763
2764 return $lang->txt('mail_salutation_'.$gender).' '.
2765 ($name['title'] ? $name['title'].' ' : '').
2766 ($name['firstname'] ? $name['firstname'].' ' : '').
2767 $name['lastname'].',';
2768 }
2769
2770 private function setUsePear($bool)
2771 {
2772 $this->use_pear = $bool;
2773 }
2774
2775 private function getUsePear()
2776 {
2777 return $this->use_pear;
2778 }
2779
2780 // Force fallback for sending mails via ILIAS, if internal Pear-Validation returns PEAR_Error
2785 private function validatePear($a_recipients)
2786 {
2787 if(ilMail::_usePearMail())
2788 {
2789 $this->setUsePear(true);
2790 $tmp_names = $this->explodeRecipients($a_recipients, true);
2791 if(is_a($tmp_names, 'PEAR_Error'))
2792 {
2793 $this->setUsePear(false);
2794 }
2795 }
2796 else
2797 {
2798 $this->setUsePear(false);
2799 }
2800 }
2801
2810 protected static function getCachedUserInstance($a_usr_id)
2811 {
2812 if(isset(self::$userInstances[$a_usr_id]))
2813 {
2814 return self::$userInstances[$a_usr_id];
2815 }
2816
2817 self::$userInstances[$a_usr_id] = new ilObjUser($a_usr_id);
2818 return self::$userInstances[$a_usr_id];
2819 }
2820} // END class.ilMail
2821?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const CONTEXT_CRON
static getType()
Get context type.
This class handles all operations on files (attachments) in directory ilias_data/mail.
static _getLanguage($a_lang_key='')
Get langauge object.
ILIAS Exception for Service Mail.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
Class UserMail this class handles user mails.
Class Mail this class handles base functions for mail handling.
replacePlaceholders($a_message, $a_user_id)
static getCachedUserInstance($a_usr_id)
Returns a cached instance of ilObjUser.
static getSalutation($a_usr_id, $a_language=null)
Get salutation.
doesRecipientStillExists($a_recipient, $a_existing_recipients)
parseRcptOfMailingLists($rcpt='', $maintain_lists=false)
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)
send internal message to recipients @access private
appendInstallationSignature($a_flag=null)
Setter/Getter for appending the installation signarue.
sendMimeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_attachments, $a_no_soap=false)
send mime mail using class.ilMimeMail.php All external mails are send to SOAP::sendMail starting a ki...
setSaveInSentbox($a_save_in_sentbox)
__getEmailRecipients($a_rcp)
getMail($a_mail_id)
get data of one mail @access public
markUnread($a_mail_ids)
mark mails as unread @access public
checkRecipients($a_recipients)
check if recipients are valid @access public
formatNamesForOutput($users='')
Prepends the fullname of each ILIAS login name (is user has a public profile) found in the passed str...
moveMailsToFolder($a_mail_ids, $a_folder_id)
move mail to folder @access public
enableSOAP($a_status)
static $userInstances
__getCountRecipients($a_to, $a_cc, $a_bcc, $a_only_email=true)
isSOAPEnabled()
getNextMail($a_mail_id)
explodeRecipients($a_recipients, $use_pear=true)
explode recipient string allowed seperators are ',' ';' ' '
static getIliasMailerAddress()
Builds an email address used for system notifications.
static addFullname($a_email, $a_fullname)
getEmailsOfRecipients($a_rcp)
get email addresses of recipients @access public
countMailsOfFolder($a_folder_id)
count all mails of a specific folder @access public
getUserIds($a_recipients)
get user_ids
getMailsOfFolder($a_folder_id, $filter=array())
__substituteRecipients($a_rcp, $direction)
Note: This function can only be used, when ILIAS is configured to not use standards compliant mail ad...
saveAttachments($a_attachments)
set attachments
static getSubjectPrefix()
Get text that will be prepended to auto generated mails.
setMailSubject($a_subject)
setMailMessage($a_message)
getEmailOfSender()
get email of sender @access public
__getCountRecipient($rcp, $a_only_email=true)
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)
save mail in folder @access private
getAttachments()
get attachments @access public
static _getInstallationSignature()
Static getter for the installation signature.
static _getUserInternalMailboxAddress($usr_id, $login=null, $firstname=null, $lastname=null)
static _getAutoGeneratedMessageString($lang=null)
get auto generated info string
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)
fetchMailData($a_row)
fetch all query data from table mail @access public
saveInSentbox($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_type, $a_m_subject, $a_m_message)
send mime mail using class.ilMimeMail.php
getPreviousMail($a_mail_id)
getMailCounterData()
get mail counter data returns data array with indexes "total","read","unread" @access public
__construct($a_user_id)
Constructor setup an mail object @access public.
$mail_to_global_roles
deleteMailsOfFolder($a_folder_id)
delete all mails of a specific folder @access public
setMailRcpBc($a_rcp_bc)
setMailSendType($a_types)
$appendInstallationSignature
checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_type)
check if mail is complete, recipients are valid @access public
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)
save post data in table @access public
setMailRcpTo($a_rcp_to)
deleteMails($a_mail_ids)
delete mail @access public
getMailObjectReferenceId()
markRead($a_mail_ids)
mark mails as read @access public
setUsePear($bool)
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)
send external mail using class.ilMimeMail.php
readMailObjectReferenceId()
read and set mail object id @access private
__get($name)
Magic interceptor method __get Used to include files / instantiate objects at runtime.
getSaveInSentbox()
const ILIAS_HOST
$mail_use_placeholders
__prependMessage($a_m_message, $rcp_to, $rcp_cc)
validatePear($a_recipients)
getSavedData()
get saved data @access public
setMailRcpCc($a_rcp_cc)
Mail Box class Base class for creating and handling mail boxes.
this class encapsulates the PHP mail() function.
_mimeEncode($a_string)
_lookupIdByTitle($a_title)
getUserIdByLogin($a_login)
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 _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
_lookupPref($a_usr_id, $a_keyword)
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences($a_id)
get all reference ids of object
static is_email($a_email)
This preg-based function checks whether an e-mail address is formally valid.
static _getHttpPath()
static groupNameExists($a_group_name, $a_id=0)
checks if group name already exists.
$_COOKIE["ilClientId"]
Definition: cron.php:11
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB
global $ilUser
Definition: imgupload.php:15
const ILIAS_WEB_DIR