4 require_once
'Services/User/classes/class.ilObjUser.php';
238 require_once
"./Services/Mail/classes/class.ilFileDataMail.php";
239 require_once
"Services/Mail/classes/class.ilMailOptions.php";
243 $lng->loadLanguageModule(
"mail");
248 $this->table_mail =
'mail';
249 $this->table_mail_saved =
'mail_saved';
250 $this->user_id = $a_user_id;
272 if(isset($this->properties[$name]))
274 return $this->properties[$name];
278 if($name ==
'mlists')
280 if(is_object($ilUser))
282 require_once
'Services/Contact/classes/class.ilMailingLists.php';
284 return $this->properties[$name];
291 if(self::_usePearMail())
294 if(is_a($recipients,
'PEAR_Error'))
300 foreach($recipients as $rcp)
302 if (substr($rcp->mailbox, 0, 1) !=
'#')
304 if(trim($rcp->mailbox) == trim($a_recipient) ||
305 trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
310 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
312 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
319 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
330 if(count($recipients))
332 foreach($recipients as $recipient)
334 if(trim($recipient) == trim($a_recipient))
354 $this->soap_enabled = $a_status;
360 if(!extension_loaded(
'curl') || !$ilSetting->get(
'soap_user_administration'))
377 $this->save_in_sentbox = $a_save_in_sentbox;
392 $this->mail_send_type = $a_types;
402 $this->mail_rcp_to = $a_rcp_to;
412 $this->mail_rcp_cc = $a_rcp_cc;
422 $this->mail_rcp_bc = $a_rcp_bc;
432 $this->mail_subject = $a_subject;
442 $this->mail_message = $a_message;
451 include_once
'Services/Mail/classes/class.ilMailGlobalServices.php';
472 $users = trim($users);
475 if(strstr($users,
','))
477 $rcp_to_array = array();
479 $recipients = explode(
',', $users);
480 foreach($recipients as $recipient)
482 $recipient = trim($recipient);
487 $tmp_obj = self::getCachedUserInstance($uid);
488 $rcp_to_array[] = $tmp_obj->getFullname().
' ['.$recipient.
']';
492 $rcp_to_array[] = $recipient;
497 $rcp_to_array[] = $recipient;
501 return trim(implode(
', ', $rcp_to_array));
509 $tmp_obj = self::getCachedUserInstance($uid);
510 return $tmp_obj->getFullname().
' ['.$users.
']';
525 return $this->lng->txt(
'not_available');
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 539 AND a.mail_id = %s ORDER BY b.send_time ASC",
540 array(
'integer',
'integer'),
541 array($this->user_id, $a_mail_id));
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 558 AND a.mail_id = %s ORDER BY b.send_time DESC",
559 array(
'integer',
'integer'),
560 array($this->user_id, $a_mail_id));
578 $this->mail_counter = array();
579 $this->mail_counter[
'read'] = 0;
580 $this->mail_counter[
'unread'] = 0;
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 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)) ";
588 if($filter[
'status'])
590 $query .=
' AND m_status = '.$ilDB->quote($filter[
'status'],
'text');
594 $query .=
' AND '.$ilDB->like(
'm_type',
'text',
'%%:"'.$filter[
'type'].
'"%%',
false);
597 $query .=
" ORDER BY send_time DESC";
600 array(
'integer',
'integer'),
601 array($this->user_id, $a_folder_id));
603 while (
$row = $ilDB->fetchObject(
$res))
607 if($tmp[
'm_status'] ==
'read')
609 ++$this->mail_counter[
'read'];
612 if($tmp[
'm_status'] ==
'unread')
614 ++$this->mail_counter[
'unread'];
620 $this->mail_counter[
'total'] = count($output);
622 return $output ? $output : array();
635 $res = $ilDB->queryf(
" 636 SELECT COUNT(*) FROM ". $this->table_mail .
" 639 array(
'integer',
'integer'),
640 array($this->user_id, $a_folder_id));
642 return $res->numRows();
664 foreach((array)$mails as $mail_data)
683 return is_array($this->mail_counter) ? $this->mail_counter : array(
699 $res = $ilDB->queryf(
" 700 SELECT * FROM ". $this->table_mail .
" 703 array(
'integer',
'integer'),
704 array($this->user_id, $a_mail_id));
723 $data_types = array();
725 $query =
"UPDATE ". $this->table_mail .
" 727 WHERE user_id = %s ";
728 array_push($data_types,
'text',
'integer');
729 array_push(
$data,
'read', $this->user_id);
731 $cnt_mail_ids = count($a_mail_ids);
733 if (is_array($a_mail_ids) &&
734 count($a_mail_ids) > 0)
737 $in =
'mail_id IN (';
739 foreach($a_mail_ids as $a_mail_id)
741 array_push(
$data, $a_mail_id);
742 array_push($data_types,
'integer');
744 if($counter > 0)
$in .=
',';
769 $data_types = array();
771 $query =
"UPDATE ". $this->table_mail .
" 773 WHERE user_id = %s ";
774 array_push($data_types,
'text',
'integer');
775 array_push(
$data,
'unread', $this->user_id);
777 $cnt_mail_ids = count($a_mail_ids);
779 if (is_array($a_mail_ids) &&
780 count($a_mail_ids) > 0)
783 $in =
'mail_id IN (';
785 foreach($a_mail_ids as $a_mail_id)
787 array_push(
$data, $a_mail_id);
788 array_push($data_types,
'integer');
790 if($counter > 0)
$in .=
',';
799 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
816 $data_types = array();
818 $query =
"UPDATE ". $this->table_mail .
" 820 WHERE user_id = %s ";
821 array_push($data_types,
'text',
'integer');
822 array_push(
$data, $a_folder_id, $this->user_id);
824 $cnt_mail_ids = count($a_mail_ids);
826 if (is_array($a_mail_ids) &&
827 count($a_mail_ids) > 0)
830 $in =
'mail_id IN (';
832 foreach($a_mail_ids as $a_mail_id)
834 array_push(
$data, $a_mail_id);
835 array_push($data_types,
'integer');
837 if($counter > 0)
$in .=
',';
846 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
861 foreach ($a_mail_ids as $id)
863 $statement = $ilDB->manipulateF(
" 864 DELETE FROM ". $this->table_mail .
" 867 array(
'integer',
'integer'),
868 array($this->user_id, $id));
870 $this->mfile->deassignAttachmentFromDirectory($id);
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);
914 $a_draft_id = 0, $a_use_placeholders = 0)
918 $ilDB->update($this->table_mail,
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)
934 'mail_id' => array(
'integer', $a_draft_id)
969 $a_user_id = 0, $a_use_placeholders = 0)
976 if ($a_use_placeholders)
982 $a_use_placeholders =
'0';
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;
1000 $next_id = $ilDB->nextId($this->table_mail);
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)
1027 $user = self::getCachedUserInstance($a_user_id);
1030 switch ($user->getGender())
1032 case 'f': $gender_salut = $lng->txt(
'salutation_f');
1034 case 'm': $gender_salut = $lng->txt(
'salutation_m');
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);
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)
1065 include_once
'Services/Mail/classes/class.ilMailbox.php';
1066 include_once
'./Services/User/classes/class.ilObjUser.php';
1068 if (!ilMail::_usePearMail())
1078 if (!$a_use_placeholders) # No Placeholders
1080 $rcp_ids = $this->
getUserIds(trim($a_rcp_to).
','.trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1082 $as_email = array();
1084 foreach($rcp_ids as $id)
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();
1094 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1105 if (!$user_can_read_internal_mails ||
1106 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1108 $as_email[] = $tmp_user->getEmail();
1112 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1114 $as_email[] = $tmp_user->getEmail();
1117 $mbox->setUserId($id);
1118 $inbox_id = $mbox->getInboxFolder();
1121 $a_attachments, $a_rcp_to,
1122 $a_rcp_cc,
'',
'unread', $a_type,
1123 0, $a_subject, $a_message, $id, 0);
1126 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1134 if(count($as_email) == 1)
1136 $to[] = $as_email[0];
1140 foreach ($as_email as $email)
1146 if(count($to) > 0 || count($bcc) > 0)
1148 $this->
sendMimeMail(implode(
',', $to),
'', implode(
',', $bcc), $a_subject, $a_message, $a_attachments);
1151 else # Use Placeholders
1154 $rcp_ids_replace = $this->
getUserIds(trim($a_rcp_to));
1157 $rcp_ids_no_replace = $this->
getUserIds(trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1159 $as_email = array();
1162 foreach($rcp_ids_replace as $id)
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();
1172 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1183 if (!$user_can_read_internal_mails ||
1184 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1186 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1190 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1192 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1195 $mbox->setUserId($id);
1196 $inbox_id = $mbox->getInboxFolder();
1199 $a_attachments, $a_rcp_to,
1200 $a_rcp_cc,
'',
'unread', $a_type,
1201 0, $a_subject, $a_message, $id, 1);
1204 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1208 if (count($as_email))
1210 foreach ($as_email as $id => $email)
1216 $as_email = array();
1219 foreach($rcp_ids_no_replace as $id)
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();
1232 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1239 if (!$user_can_read_internal_mails ||
1240 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1242 $as_email[] = $tmp_user->getEmail();
1246 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1248 $as_email[] = $tmp_user->getEmail();
1251 $mbox->setUserId($id);
1252 $inbox_id = $mbox->getInboxFolder();
1255 $a_attachments, $a_rcp_to,
1256 $a_rcp_cc,
'',
'unread', $a_type,
1257 0, $a_subject, $a_message, $id, 0);
1260 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1264 if (count($as_email))
1266 $this->
sendMimeMail(
'',
'', implode(
',', $as_email), $a_subject, $a_message, $a_attachments);
1280 global
$log, $rbacreview;
1284 if (ilMail::_usePearMail() && $this->
getUsePear() ==
true)
1287 if (! is_a($tmp_names,
'PEAR_Error'))
1289 for ($i = 0;$i < count($tmp_names); $i++)
1291 if (substr($tmp_names[$i]->mailbox,0,1) ==
'#' || substr($tmp_names[$i]->mailbox,0,2) ==
'"#')
1293 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1294 foreach($role_ids as $role_id)
1296 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1302 else if (strtolower($tmp_names[$i]->host) == self::ILIAS_HOST)
1336 for ($i = 0;$i < count($tmp_names); $i++)
1338 if (substr($tmp_names[$i],0,1) ==
'#' || substr($tmp_names[$i], 0, 2) ==
'"#')
1342 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1343 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1351 foreach ($grp_object->getGroupMemberIds() as $id)
1357 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1359 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1366 else if (!empty($tmp_names[$i]))
1375 return array_unique($ids);
1388 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1390 $error_message =
'';
1392 $a_m_subject = trim($a_m_subject);
1393 $a_rcp_to = trim($a_rcp_to);
1395 if (empty($a_m_subject))
1397 $error_message .= $error_message ?
"<br>" :
'';
1398 $error_message .= $this->lng->txt(
"mail_add_subject");
1401 if (empty($a_rcp_to))
1403 $error_message .= $error_message ?
"<br>" :
'';
1404 $error_message .= $this->lng->txt(
"mail_add_recipient");
1407 return $error_message;
1420 $addresses = array();
1423 if (ilMail::_usePearMail() && $this->
getUsePear())
1426 if (! is_a($tmp_rcp,
'PEAR_Error'))
1428 foreach ($tmp_rcp as $rcp)
1431 if (substr($rcp->mailbox,0,1) !=
'#' && substr($rcp->mailbox,0, 2) !=
'"#')
1433 if (strtolower($rcp->host) != self::ILIAS_HOST)
1435 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
1441 $tmp_user = self::getCachedUserInstance($id);
1442 $addresses[] = $tmp_user->getEmail();
1449 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1450 foreach($role_ids as $role_id)
1452 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1454 $tmp_user = self::getCachedUserInstance($usr_id);
1455 $addresses[] = $tmp_user->getEmail();
1466 foreach ($tmp_rcp as $rcp)
1469 if (substr($rcp,0,1) !=
'#' && substr($rcp,0,2) !=
'"#')
1471 if (strpos($rcp,
'@'))
1473 $addresses[] = $rcp;
1479 $tmp_user = self::getCachedUserInstance($id);
1480 $addresses[] = $tmp_user->getEmail();
1487 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1488 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1497 foreach ($grp_object->getGroupMemberIds() as $id)
1499 $tmp_user = self::getCachedUserInstance($id);
1500 $addresses[] = $tmp_user->getEmail();
1518 global $rbacsystem,$rbacreview;
1522 if (ilMail::_usePearMail() && $this->
getUsePear())
1526 if (is_a($tmp_rcp,
'PEAR_Error'))
1528 $colon_pos = strpos($tmp_rcp->message,
':');
1529 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1533 foreach ($tmp_rcp as $rcp)
1536 if (substr($rcp->mailbox,0,1) !=
'#' && substr($rcp->mailbox,0,2) !=
'"#')
1540 if ($user_id ==
false && $rcp->host == self::ILIAS_HOST)
1542 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1549 if(!$rbacsystem->checkAccessOfUser($user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1551 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1552 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1557 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1559 if (!$this->mlists->mailingListExists($rcp->mailbox))
1561 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1562 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1570 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1572 if(!$this->mail_to_global_roles && is_array($role_ids))
1574 foreach($role_ids as $role_id)
1576 if($rbacreview->isGlobalRole($role_id))
1578 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1584 if (count($role_ids) == 0)
1586 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1587 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1590 else if (count($role_ids) > 1)
1592 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1593 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1603 foreach ($tmp_rcp as $rcp)
1610 if (substr($rcp,0,1) !=
'#' && substr($rcp,0,2) !=
'"#')
1616 $wrong_rcps .=
"<br />".htmlentities($rcp);
1623 if(!$rbacsystem->checkAccessOfUser($user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1625 $wrong_rcps .=
"<br />".htmlentities($rcp).
1626 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1631 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1633 if (!$this->mlists->mailingListExists($rcp))
1635 $wrong_rcps .=
"<br />".htmlentities($rcp).
1636 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1645 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1647 $wrong_rcps .=
"<br />".htmlentities($rcp).
1648 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1651 else if (!$this->mail_to_global_roles)
1653 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1654 if((
int)$role_id && $rbacreview->isGlobalRole($role_id))
1656 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1689 $a_use_placeholders)
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';
1704 $statement = $ilDB->manipulateF(
' 1705 DELETE FROM '. $this->table_mail_saved .
' 1706 WHERE user_id = %s',
1707 array(
'integer'), array($this->user_id));
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),
1736 $res = $ilDB->queryf(
' 1737 SELECT * FROM '. $this->table_mail_saved .
' 1738 WHERE user_id = %s',
1740 array($this->user_id));
1761 $message .= $error_message;
1765 $message .= $error_message;
1769 $message .= $error_message;
1772 if(strlen($message) > 0)
1774 return $this->lng->txt(
'mail_following_rcp_not_valid') . $message;
1781 return $this->lng->txt(
'mail_following_rcp_not_valid') . $this->lng->txt($e->getMessage());
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)
1803 $this->mail_to_global_roles =
true;
1804 if($this->user_id != ANONYMOUS_USER_ID)
1806 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id,
'mail_to_global_roles', $this->mail_obj_ref_id);
1809 if (in_array(
"system",$a_type))
1811 $a_type = array(
'system');
1816 if (!$this->mfile->checkFilesExist($a_attachment))
1818 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1822 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1824 return $error_message;
1828 if(strlen($error_message) > 0)
1830 return $error_message;
1842 $rcp_to = $rcp_cc = $rcp_bc = array();
1843 foreach($rcp_to_list as $mlist_id => $mlist_rec)
1848 $mlist_id = substr($mlist_id, 7);
1851 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1856 $rcp_to = array_merge($rcp_to, $mlist_rec);
1858 foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1863 $mlist_id = substr($mlist_id, 7);
1866 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1871 $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1873 foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1875 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1878 $rcp_to = implode(
',', $rcp_to);
1879 $rcp_cc = implode(
',', $rcp_cc);
1880 $rcp_bc = implode(
',', $rcp_bc);
1883 if (! ilMail::_usePearMail() )
1907 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1908 !$rbacsystem->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id))
1910 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1915 $a_m_message .= self::_getInstallationSignature();
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);
1924 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1926 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1945 if (in_array(
'system',$a_type))
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))
1949 return $lng->txt(
"mail_send_error");
1953 if (in_array(
'normal',$a_type))
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))
1958 return $lng->txt(
"mail_send_error");
1975 if(!$maintain_lists)
1986 if (!is_array($arrRcpt) || empty($arrRcpt))
1988 if(!$maintain_lists)
1998 $new_rcpt = array();
2000 foreach ($arrRcpt as $item)
2002 if (ilMail::_usePearMail())
2004 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
2006 if ($this->mlists->mailingListExists($item->mailbox))
2008 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2010 if(!$maintain_lists)
2012 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2016 $new_rcpt[$item->mailbox][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2024 if($item->host == self::ILIAS_HOST)
2026 $tmp_rcpt = $item->mailbox;
2030 $tmp_rcpt = $item->mailbox.
'@'.$item->host;
2033 if(!$maintain_lists)
2035 $new_rcpt[] = $tmp_rcpt;
2039 $new_rcpt[0][] = $tmp_rcpt;
2045 if (substr($item, 0, 7) ==
'#il_ml_')
2047 if ($this->mlists->mailingListExists($item))
2049 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2051 if(!$maintain_lists)
2053 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2057 $new_rcpt[$item][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2064 if(!$maintain_lists)
2066 $new_rcpt[] = $item;
2070 $new_rcpt[0][] = $item;
2076 if(!$maintain_lists)
2078 return implode(
',', $new_rcpt);
2099 $a_m_subject,$a_m_message)
2101 include_once
"Services/Mail/classes/class.ilMailbox.php";
2104 $sent_id = $mbox->getSentFolder();
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);
2119 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2129 public function getMimeMailSender()
2136 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2138 if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2140 $email = $ilUser->getEmail();
2141 $fullname = $ilUser->getFullname();
2144 $user = self::getCachedUserInstance($this->user_id);
2145 $email = $user->getEmail();
2146 $fullname = $user->getFullname();
2149 $sender = self::addFullname($email, $fullname);
2153 $sender = self::getIliasMailerAddress();
2172 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2174 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2175 if(strlen($no_reply_adress))
2177 if(strpos($no_reply_adress,
'@') ===
false)
2178 $no_reply_adress =
'noreply@'.$no_reply_adress;
2182 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2186 ' <'.$no_reply_adress.
'>';
2191 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2210 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap =
false)
2212 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2214 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>"); 2216 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4"; 2217 #$a_m_subject = "[".$inst_name."] ".$a_m_subject; 2219 $a_m_subject = self::getSubjectPrefix().
' '.$a_m_subject;
2221 $sender = $this->getMimeMailSender();
2227 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2230 $soap_client->setResponseTimeout(1);
2231 $soap_client->enableWSDL(
true);
2232 $soap_client->init();
2234 $attachments = array();
2235 $a_attachments = $a_attachments ? $a_attachments : array();
2236 foreach($a_attachments as $attachment)
2238 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2241 $attachments = implode(
'#:#',$attachments);
2243 if(strlen($attachments))
2244 $attachments =
"#:#".$attachments;
2246 $soap_client->call(
'sendMail',array(session_id().
'::'.
$_COOKIE[
'ilClientId'],
2260 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2263 $mmail->autoCheck(
false);
2264 $mmail->From($sender);
2265 $mmail->To($a_rcp_to);
2267 $mmail->Subject($a_m_subject);
2268 $mmail->Body($a_m_message);
2272 $mmail->Cc($a_rcp_cc);
2277 $mmail->Bcc($a_rcp_bcc);
2280 if (is_array($a_attachments))
2282 foreach ($a_attachments as $attachment)
2284 $mmail->Attach($this->mfile->getAbsolutePath($attachment),
'',
'inline', $attachment);
2298 $umail = self::getCachedUserInstance($this->user_id);
2299 $sender = $umail->getEmail();
2321 $ilDB->update($this->table_mail_saved,
2324 'attachments' => array(
'clob', serialize($a_attachments))
2328 'user_id' => array(
'integer', $this->user_id)
2342 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2360 $a_recipients = trim($a_recipients);
2363 #$a_recipients = preg_replace("/ /",",",$a_recipients); 2364 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2366 if (ilMail::_usePearMail() &&
$use_pear ==
true)
2368 if (strlen(trim($a_recipients)) > 0)
2370 require_once
'./Services/PEAR/lib/Mail/RFC822.php';
2372 return $parser->parseAddressList($a_recipients, self::ILIAS_HOST,
false,
true);
2379 foreach(explode(
',',$a_recipients) as $tmp_rec)
2383 $rcps[] = trim($tmp_rec);
2386 return is_array($rcps) ? $rcps : array();
2395 if (ilMail::_usePearMail() && $this->
getUsePear())
2398 if (! is_a($tmp_rcp,
'PEAR_Error'))
2400 foreach ($tmp_rcp as $to)
2413 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#' && substr($to->mailbox,0,2) !=
'"#')
2432 if (strpos($to,
'@'))
2462 if (ilMail::_usePearMail())
2466 if (! is_a($tmp_rcp,
'PEAR_Error'))
2468 foreach ($tmp_rcp as $to)
2470 if(substr($to->mailbox,0,1) !=
'#' && substr($to->mailbox,0,2) !=
'"#' && $to->host !=
'ilias')
2478 $rcp[] = $to->mailbox.
'@'.$to->host;
2482 return implode(
',',$rcp);
2500 return implode(
',',$rcp ? $rcp : array());
2506 $inst_name = $this->
ilias->getSetting(
"inst_name") ? $this->
ilias->getSetting(
"inst_name") :
"ILIAS 3";
2508 $message = $inst_name.
" To:".$rcp_to.
"\n";
2512 $message .=
"Cc: ".$rcp_cc;
2516 $message .= $a_m_message;
2530 $new_name = array();
2535 foreach($tmp_names as $name)
2537 if(strpos($name,
"#") === 0)
2539 $new_name[] = $name;
2547 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2551 $new_name[] = $name;
2555 case "resubstitute":
2556 if(stristr($name,
"�#�"))
2558 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2562 $new_name[] = $name;
2567 return implode(
",",$new_name);
2587 if (ilMail::_usePearMail())
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();
2605 return $login.
'hhho';
2618 public static function _usePearMail()
2625 return $ilSetting->get(
'pear_mail_enable', 0);
2642 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2647 $lang->loadLanguageModule(
'mail');
2648 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2649 $ilSetting->get(
'inst_name',
'ILIAS 5'),
2659 public static function _getIliasMailerName()
2666 if(strlen($ilSetting->get(
'mail_system_sender_name')))
2668 return $ilSetting->get(
'mail_system_sender_name');
2670 else if(strlen($ilSetting->get(
'short_inst_name')))
2672 return $ilSetting->get(
'short_inst_name');
2688 if(null === $a_flag) {
2707 global $ilClientIniFile;
2709 $signature =
"\n\n* * * * *\n";
2711 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2712 if(strlen($desc = $ilClientIniFile->readVariable(
'client',
'description')))
2714 $signature .= $desc.
"\n";
2720 if(is_array($clientdirs) && count($clientdirs) > 1)
2723 $signature .=
'/login.php?client_id='.CLIENT_ID;
2726 $signature .=
"\n\n";
2738 static $prefix = null;
2740 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2752 $lang = $a_language ? $a_language :
$lng;
2754 $lang->loadLanguageModule(
'mail');
2756 $gender = $gender ? $gender :
'n';
2759 if(!strlen($name[
'firstname']))
2761 return $lang->txt(
'mail_salutation_anonymous').
',';
2764 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2765 ($name[
'title'] ? $name[
'title'].
' ' :
'').
2766 ($name[
'firstname'] ? $name[
'firstname'].
' ' :
'').
2767 $name[
'lastname'].
',';
2772 $this->use_pear = $bool;
2787 if(ilMail::_usePearMail())
2791 if(is_a($tmp_names,
'PEAR_Error'))
2812 if(isset(self::$userInstances[$a_usr_id]))
2814 return self::$userInstances[$a_usr_id];
2817 self::$userInstances[$a_usr_id] =
new ilObjUser($a_usr_id);
2818 return self::$userInstances[$a_usr_id];
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 private
static _lookupName($a_user_id)
lookup user name
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 public
Class UserMail this class handles user mails.
getEmailsOfRecipients($a_rcp)
get email addresses of recipients public
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 private
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
__getCountRecipients($a_to, $a_cc, $a_bcc, $a_only_email=true)
getSavedData()
get saved data public
static getCachedUserInstance($a_usr_id)
Returns a cached instance of ilObjUser.
This class handles all operations on files (attachments) in directory ilias_data/mail.
replacePlaceholders($a_message, $a_user_id)
__get($name)
Magic interceptor method __get Used to include files / instantiate objects at runtime.
static _getUserInternalMailboxAddress($usr_id, $login=null, $firstname=null, $lastname=null)
STATIC METHOD.
moveMailsToFolder($a_mail_ids, $a_folder_id)
move mail to folder public
static is_email($a_email)
This preg-based function checks whether an e-mail address is formally valid.
ILIAS Exception for Service Mail.
static groupNameExists($a_group_name, $a_id=0)
checks if group name already exists.
static _lookupId($a_user_str)
lookup id by login
setSaveInSentbox($a_save_in_sentbox)
explodeRecipients($a_recipients, $use_pear=true)
explode recipient string allowed seperators are ',' ';' ' '
getMailCounterData()
get mail counter data returns data array with indexes "total","read","unread" public ...
validatePear($a_recipients)
markRead($a_mail_ids)
mark mails as read public
_lookupPref($a_usr_id, $a_keyword)
static _lookupGender($a_user_id)
Lookup gender.
deleteMailsOfFolder($a_folder_id)
delete all mails of a specific folder public
getEmailOfSender()
get email of sender public
getAttachments()
get attachments public
static _getAllReferences($a_id)
get all reference ids of object
const DB_FETCHMODE_OBJECT
getUserIdByLogin($a_login)
_lookupIdByTitle($a_title)
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...
static _getLanguage($a_lang_key='')
Get langauge object.
validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
__getCountRecipient($rcp, $a_only_email=true)
this class encapsulates the PHP mail() function.
$appendInstallationSignature
Mail Box class Base class for creating and handling mail boxes.
Class Mail this class handles base functions for mail handling.
__construct($a_user_id)
Constructor setup an mail object public.
__substituteRecipients($a_rcp, $direction)
Note: This function can only be used, when ILIAS is configured to not use standards compliant mail ad...
countMailsOfFolder($a_folder_id)
count all mails of a specific folder public
static getSalutation($a_usr_id, $a_language=null)
Get salutation.
redirection script todo: (a better solution should control the processing via a xml file) ...
getMail($a_mail_id)
get data of one mail public
parseRcptOfMailingLists($rcpt='', $maintain_lists=false)
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)
appendInstallationSignature($a_flag=null)
Setter/Getter for appending the installation signarue.
doesRecipientStillExists($a_recipient, $a_existing_recipients)
getMailObjectReferenceId()
static addFullname($a_email, $a_fullname)
getMailsOfFolder($a_folder_id, $filter=array())
get all mails of a specific folder public
setMailSubject($a_subject)
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
setMailSendType($a_types)
deleteMails($a_mail_ids)
delete mail public
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable...
fetchMailData($a_row)
fetch all query data from table mail public
__prependMessage($a_m_message, $rcp_to, $rcp_cc)
static getType()
Get context type.
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...
formatNamesForOutput($users='')
Prepends the fullname of each ILIAS login name (is user has a public profile) found in the passed str...
static getSubjectPrefix()
Get text that will be prepended to auto generated mails.
__getEmailRecipients($a_rcp)
setMailMessage($a_message)
markUnread($a_mail_ids)
mark mails as unread public
static _getAutoGeneratedMessageString($lang=null)
get auto generated info string
readMailObjectReferenceId()
read and set mail object id private
getPreviousMail($a_mail_id)
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
static _getInstallationSignature()
Static getter for the installation signature.
checkRecipients($a_recipients)
check if recipients are valid public
static getIliasMailerAddress()
Builds an email address used for system notifications.
getUserIds($a_recipients)
get user_ids
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 public
saveAttachments($a_attachments)
set attachments