4 require_once
'Services/User/classes/class.ilObjUser.php';
233 require_once
"./Services/Mail/classes/class.ilFileDataMail.php";
234 require_once
"Services/Mail/classes/class.ilMailOptions.php";
238 $lng->loadLanguageModule(
"mail");
243 $this->table_mail =
'mail';
244 $this->table_mail_saved =
'mail_saved';
245 $this->user_id = $a_user_id;
267 if(isset($this->properties[$name]))
269 return $this->properties[$name];
273 if($name ==
'mlists')
275 if(is_object($ilUser))
277 require_once
'Services/Contact/classes/class.ilMailingLists.php';
279 return $this->properties[$name];
286 if(self::_usePearMail())
289 if(is_a($recipients,
'PEAR_Error'))
295 foreach($recipients as $rcp)
297 if (substr($rcp->mailbox, 0, 1) !=
'#')
299 if(trim($rcp->mailbox) == trim($a_recipient) ||
300 trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
305 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
307 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
314 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
325 if(count($recipients))
327 foreach($recipients as $recipient)
329 if(trim($recipient) == trim($a_recipient))
349 $this->soap_enabled = $a_status;
355 if(!extension_loaded(
'curl') || !$ilSetting->get(
'soap_user_administration'))
372 $this->save_in_sentbox = $a_save_in_sentbox;
387 $this->mail_send_type = $a_types;
397 $this->mail_rcp_to = $a_rcp_to;
407 $this->mail_rcp_cc = $a_rcp_cc;
417 $this->mail_rcp_bc = $a_rcp_bc;
427 $this->mail_subject = $a_subject;
437 $this->mail_message = $a_message;
446 include_once
'Services/Mail/classes/class.ilMailGlobalServices.php';
467 $users = trim($users);
470 if(strstr($users,
','))
472 $rcp_to_array = array();
474 $recipients = explode(
',', $users);
475 foreach($recipients as $recipient)
477 $recipient = trim($recipient);
483 $rcp_to_array[] = $tmp_obj->getFullname().
' ['.$recipient.
']';
487 $rcp_to_array[] = $recipient;
492 $rcp_to_array[] = $recipient;
496 return trim(implode(
', ', $rcp_to_array));
505 return $tmp_obj->getFullname().
' ['.$users.
']';
520 return $this->lng->txt(
'not_available');
529 $res = $ilDB->queryf(
"
530 SELECT b.* FROM " . $this->table_mail .
" a
531 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
532 AND b.user_id = a.user_id AND b.send_time > a.send_time
534 AND a.mail_id = %s ORDER BY b.send_time ASC",
535 array(
'integer',
'integer'),
536 array($this->user_id, $a_mail_id));
548 $res = $ilDB->queryf(
"
549 SELECT b.* FROM " . $this->table_mail .
" a
550 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
551 AND b.user_id = a.user_id AND b.send_time < a.send_time
553 AND a.mail_id = %s ORDER BY b.send_time DESC",
554 array(
'integer',
'integer'),
555 array($this->user_id, $a_mail_id));
573 $this->mail_counter = array();
574 $this->mail_counter[
'read'] = 0;
575 $this->mail_counter[
'unread'] = 0;
577 $query =
"SELECT sender_id, m_subject, mail_id, m_status, send_time FROM ". $this->table_mail .
"
578 LEFT JOIN object_data ON obj_id = sender_id
581 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)) ";
583 if($filter[
'status'])
585 $query .=
' AND m_status = '.$ilDB->quote($filter[
'status'],
'text');
589 $query .=
' AND '.$ilDB->like(
'm_type',
'text',
'%%:"'.$filter[
'type'].
'"%%',
false);
592 $query .=
" ORDER BY send_time DESC";
595 array(
'integer',
'integer'),
596 array($this->user_id, $a_folder_id));
598 while (
$row = $ilDB->fetchObject(
$res))
602 if($tmp[
'm_status'] ==
'read')
604 ++$this->mail_counter[
'read'];
607 if($tmp[
'm_status'] ==
'unread')
609 ++$this->mail_counter[
'unread'];
615 $this->mail_counter[
'total'] = count($output);
617 return $output ? $output : array();
630 $res = $ilDB->queryf(
"
631 SELECT COUNT(*) FROM ". $this->table_mail .
"
634 array(
'integer',
'integer'),
635 array($this->user_id, $a_folder_id));
637 return $res->numRows();
678 return is_array($this->mail_counter) ? $this->mail_counter : array(
694 $res = $ilDB->queryf(
"
695 SELECT * FROM ". $this->table_mail .
"
698 array(
'integer',
'integer'),
699 array($this->user_id, $a_mail_id));
718 $data_types = array();
720 $query =
"UPDATE ". $this->table_mail .
"
722 WHERE user_id = %s ";
723 array_push($data_types,
'text',
'integer');
724 array_push($data,
'read', $this->user_id);
726 $cnt_mail_ids = count($a_mail_ids);
728 if (is_array($a_mail_ids) &&
729 count($a_mail_ids) > 0)
732 $in =
'mail_id IN (';
734 foreach($a_mail_ids as $a_mail_id)
736 array_push($data, $a_mail_id);
737 array_push($data_types,
'integer');
739 if($counter > 0)
$in .=
',';
748 $res = $ilDB->manipulateF(
$query, $data_types, $data);
764 $data_types = array();
766 $query =
"UPDATE ". $this->table_mail .
"
768 WHERE user_id = %s ";
769 array_push($data_types,
'text',
'integer');
770 array_push($data,
'unread', $this->user_id);
772 $cnt_mail_ids = count($a_mail_ids);
774 if (is_array($a_mail_ids) &&
775 count($a_mail_ids) > 0)
778 $in =
'mail_id IN (';
780 foreach($a_mail_ids as $a_mail_id)
782 array_push($data, $a_mail_id);
783 array_push($data_types,
'integer');
785 if($counter > 0)
$in .=
',';
794 $statement = $ilDB->manipulateF(
$query, $data_types, $data);
811 $data_types = array();
813 $query =
"UPDATE ". $this->table_mail .
"
815 WHERE user_id = %s ";
816 array_push($data_types,
'text',
'integer');
817 array_push($data, $a_folder_id, $this->user_id);
819 $cnt_mail_ids = count($a_mail_ids);
821 if (is_array($a_mail_ids) &&
822 count($a_mail_ids) > 0)
825 $in =
'mail_id IN (';
827 foreach($a_mail_ids as $a_mail_id)
829 array_push($data, $a_mail_id);
830 array_push($data_types,
'integer');
832 if($counter > 0)
$in .=
',';
841 $statement = $ilDB->manipulateF(
$query, $data_types, $data);
856 foreach ($a_mail_ids as $id)
858 $statement = $ilDB->manipulateF(
"
859 DELETE FROM ". $this->table_mail .
"
862 array(
'integer',
'integer'),
863 array($this->user_id, $id));
865 $this->mfile->deassignAttachmentFromDirectory($id);
882 "mail_id" => $a_row->mail_id,
883 "user_id" => $a_row->user_id,
884 "folder_id" => $a_row->folder_id,
885 "sender_id" => $a_row->sender_id,
886 "attachments" => unserialize(stripslashes($a_row->attachments)),
887 "send_time" => $a_row->send_time,
888 "rcp_to" => $a_row->rcp_to,
889 "rcp_cc" => $a_row->rcp_cc,
890 "rcp_bcc" => $a_row->rcp_bcc,
891 "m_status" => $a_row->m_status,
892 "m_type" => unserialize(stripslashes($a_row->m_type)),
893 "m_email" => $a_row->m_email,
894 "m_subject" => $a_row->m_subject,
895 "m_message" => $a_row->m_message,
896 "import_name" => $a_row->import_name,
897 "use_placeholders"=> $a_row->use_placeholders);
909 $a_draft_id = 0, $a_use_placeholders = 0)
913 $ilDB->update($this->table_mail,
915 'folder_id' => array(
'integer', $a_folder_id),
916 'attachments' => array(
'clob', serialize($a_attachments)),
917 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
918 'rcp_to' => array(
'clob', $a_rcp_to),
919 'rcp_cc' => array(
'clob', $a_rcp_cc),
920 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
921 'm_status' => array(
'text',
'read'),
922 'm_type' => array(
'text', serialize($a_m_type)),
923 'm_email' => array(
'integer', $a_m_email),
924 'm_subject' => array(
'text', $a_m_subject),
925 'm_message' => array(
'clob', $a_m_message),
926 'use_placeholders' => array(
'integer', $a_use_placeholders)
929 'mail_id' => array(
'integer', $a_draft_id)
964 $a_user_id = 0, $a_use_placeholders = 0)
971 if ($a_use_placeholders)
977 $a_use_placeholders =
'0';
981 if(!$a_user_id) $a_user_id =
'0';
982 if(!$a_folder_id) $a_folder_id =
'0';
983 if(!$a_sender_id) $a_sender_id = NULL;
984 if(!$a_attachments) $a_attachments = NULL;
985 if(!$a_rcp_to) $a_rcp_to = NULL;
986 if(!$a_rcp_cc) $a_rcp_cc = NULL;
987 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
988 if(!$a_status) $a_status = NULL;
989 if(!$a_m_type) $a_m_type = NULL;
990 if(!$a_m_email) $a_m_email = NULL;
991 if(!$a_m_subject) $a_m_subject = NULL;
992 if(!$a_m_message) $a_m_message = NULL;
995 $next_id = $ilDB->nextId($this->table_mail);
997 $ilDB->insert($this->table_mail, array(
998 'mail_id' => array(
'integer', $next_id),
999 'user_id' => array(
'integer', $a_user_id),
1000 'folder_id' => array(
'integer', $a_folder_id),
1001 'sender_id' => array(
'integer', $a_sender_id),
1002 'attachments' => array(
'clob', serialize($a_attachments)),
1003 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
1004 'rcp_to' => array(
'clob', $a_rcp_to),
1005 'rcp_cc' => array(
'clob', $a_rcp_cc),
1006 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1007 'm_status' => array(
'text', $a_status),
1008 'm_type' => array(
'text', serialize($a_m_type)),
1009 'm_email' => array(
'integer', $a_m_email),
1010 'm_subject' => array(
'text', $a_m_subject),
1011 'm_message' => array(
'clob', $a_m_message)
1025 switch ($user->getGender())
1027 case 'f': $gender_salut = $lng->txt(
'salutation_f');
1029 case 'm': $gender_salut = $lng->txt(
'salutation_m');
1033 $a_message = str_replace(
'[MAIL_SALUTATION]', $gender_salut, $a_message);
1034 $a_message = str_replace(
'[LOGIN]', $user->getLogin(), $a_message);
1035 $a_message = str_replace(
'[FIRST_NAME]', $user->getFirstname(), $a_message);
1036 $a_message = str_replace(
'[LAST_NAME]', $user->getLastname(), $a_message);
1037 $a_message = str_replace(
'[ILIAS_URL]', ILIAS_HTTP_PATH.
'/login.php?client_id='.CLIENT_ID, $a_message);
1038 $a_message = str_replace(
'[CLIENT_NAME]', CLIENT_NAME, $a_message);
1056 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)
1060 include_once
'Services/Mail/classes/class.ilMailbox.php';
1061 include_once
'./Services/User/classes/class.ilObjUser.php';
1063 if (!ilMail::_usePearMail())
1073 if (!$a_use_placeholders) # No Placeholders
1075 $rcp_ids = $this->
getUserIds(trim($a_rcp_to).
','.trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1077 $as_email = array();
1079 foreach($rcp_ids as $id)
1085 $user_is_active = $tmp_user->getActive();
1086 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1089 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1100 if (!$user_can_read_internal_mails ||
1101 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1103 $as_email[] = $tmp_user->getEmail();
1107 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1109 $as_email[] = $tmp_user->getEmail();
1112 $mbox->setUserId($id);
1113 $inbox_id = $mbox->getInboxFolder();
1116 $a_attachments, $a_rcp_to,
1117 $a_rcp_cc,
'',
'unread', $a_type,
1118 0, $a_subject, $a_message, $id, 0);
1121 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1129 if(count($as_email) == 1)
1131 $to[] = $as_email[0];
1135 foreach ($as_email as $email)
1141 if(count($to) > 0 || count($bcc) > 0)
1143 $this->
sendMimeMail(implode(
',', $to),
'', implode(
',', $bcc), $a_subject, $a_message, $a_attachments);
1146 else # Use Placeholders
1149 $rcp_ids_replace = $this->
getUserIds(trim($a_rcp_to));
1152 $rcp_ids_no_replace = $this->
getUserIds(trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1154 $as_email = array();
1157 foreach($rcp_ids_replace as $id)
1163 $user_is_active = $tmp_user->getActive();
1164 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1167 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1178 if (!$user_can_read_internal_mails ||
1179 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1181 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1185 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1187 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1190 $mbox->setUserId($id);
1191 $inbox_id = $mbox->getInboxFolder();
1194 $a_attachments, $a_rcp_to,
1195 $a_rcp_cc,
'',
'unread', $a_type,
1196 0, $a_subject, $a_message, $id, 1);
1199 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1203 if (count($as_email))
1205 foreach ($as_email as $id => $email)
1211 $as_email = array();
1214 foreach($rcp_ids_no_replace as $id)
1220 $user_is_active = $tmp_user->getActive();
1221 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1227 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1234 if (!$user_can_read_internal_mails ||
1235 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1237 $as_email[] = $tmp_user->getEmail();
1241 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1243 $as_email[] = $tmp_user->getEmail();
1246 $mbox->setUserId($id);
1247 $inbox_id = $mbox->getInboxFolder();
1250 $a_attachments, $a_rcp_to,
1251 $a_rcp_cc,
'',
'unread', $a_type,
1252 0, $a_subject, $a_message, $id, 0);
1255 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1259 if (count($as_email))
1261 $this->
sendMimeMail(
'',
'', implode(
',', $as_email), $a_subject, $a_message, $a_attachments);
1275 global
$log, $rbacreview;
1279 if (ilMail::_usePearMail() && $this->
getUsePear() ==
true)
1282 if (! is_a($tmp_names,
'PEAR_Error'))
1284 for ($i = 0;$i < count($tmp_names); $i++)
1286 if ( substr($tmp_names[$i]->mailbox,0,1) ===
'#' ||
1287 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1288 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
1290 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1291 foreach($role_ids as $role_id)
1293 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1299 else if (strtolower($tmp_names[$i]->host) ==
'ilias')
1333 for ($i = 0;$i < count($tmp_names); $i++)
1335 if (substr($tmp_names[$i],0,1) ==
'#')
1339 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1340 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1348 foreach ($grp_object->getGroupMemberIds() as $id)
1354 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1356 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1363 else if (!empty($tmp_names[$i]))
1372 return array_unique($ids);
1385 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1387 $error_message =
'';
1389 $a_m_subject = trim($a_m_subject);
1390 $a_rcp_to = trim($a_rcp_to);
1392 if (empty($a_m_subject))
1394 $error_message .= $error_message ?
"<br>" :
'';
1395 $error_message .= $this->lng->txt(
"mail_add_subject");
1398 if (empty($a_rcp_to))
1400 $error_message .= $error_message ?
"<br>" :
'';
1401 $error_message .= $this->lng->txt(
"mail_add_recipient");
1404 return $error_message;
1417 $addresses = array();
1420 if (ilMail::_usePearMail() && $this->
getUsePear())
1423 if (! is_a($tmp_rcp,
'PEAR_Error'))
1425 foreach ($tmp_rcp as $rcp)
1428 if (substr($rcp->mailbox,0,1) !=
'#')
1430 if (strtolower($rcp->host) !=
'ilias')
1432 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
1439 $addresses[] = $tmp_user->getEmail();
1446 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1447 foreach($role_ids as $role_id)
1449 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1452 $addresses[] = $tmp_user->getEmail();
1463 foreach ($tmp_rcp as $rcp)
1466 if (substr($rcp,0,1) !=
'#')
1468 if (strpos($rcp,
'@'))
1470 $addresses[] = $rcp;
1477 $addresses[] = $tmp_user->getEmail();
1484 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1485 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1494 foreach ($grp_object->getGroupMemberIds() as $id)
1497 $addresses[] = $tmp_user->getEmail();
1515 global $rbacsystem,$rbacreview;
1519 if (ilMail::_usePearMail() && $this->
getUsePear())
1523 if (is_a($tmp_rcp,
'PEAR_Error'))
1525 $colon_pos = strpos($tmp_rcp->message,
':');
1526 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1530 foreach ($tmp_rcp as $rcp)
1533 if (substr($rcp->mailbox,0,1) !=
'#')
1537 if (
$user_id ==
false && $rcp->host ==
'ilias')
1539 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1546 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1548 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1549 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1554 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1556 if (!$this->mlists->mailingListExists($rcp->mailbox))
1558 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1559 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1567 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1569 if(!$this->mail_to_global_roles && is_array($role_ids))
1571 foreach($role_ids as $role_id)
1573 if($rbacreview->isGlobalRole($role_id))
1575 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1581 if (count($role_ids) == 0)
1583 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1584 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1587 else if (count($role_ids) > 1)
1589 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1590 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1600 foreach ($tmp_rcp as $rcp)
1607 if (substr($rcp,0,1) !=
'#')
1613 $wrong_rcps .=
"<br />".htmlentities($rcp);
1620 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1622 $wrong_rcps .=
"<br />".htmlentities($rcp).
1623 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1628 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1630 if (!$this->mlists->mailingListExists($rcp))
1632 $wrong_rcps .=
"<br />".htmlentities($rcp).
1633 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1642 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1644 $wrong_rcps .=
"<br />".htmlentities($rcp).
1645 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1648 else if (!$this->mail_to_global_roles)
1650 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1651 if((
int)$role_id && $rbacreview->isGlobalRole($role_id))
1653 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1686 $a_use_placeholders)
1691 if(!$a_attachments) $a_attachments = NULL;
1692 if(!$a_rcp_to) $a_rcp_to = NULL;
1693 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1694 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1695 if(!$a_m_type) $a_m_type = NULL;
1696 if(!$a_m_email) $a_m_email = NULL;
1697 if(!$a_m_message) $a_m_message = NULL;
1698 if(!$a_use_placeholders) $a_use_placeholders =
'0';
1701 $statement = $ilDB->manipulateF(
'
1702 DELETE FROM '. $this->table_mail_saved .
'
1703 WHERE user_id = %s',
1704 array(
'integer'), array($this->user_id));
1706 $ilDB->insert($this->table_mail_saved, array(
1707 'user_id' => array(
'integer', $a_user_id),
1708 'attachments' => array(
'clob', serialize($a_attachments)),
1709 'rcp_to' => array(
'clob', $a_rcp_to),
1710 'rcp_cc' => array(
'clob', $a_rcp_cc),
1711 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1712 'm_type' => array(
'text', serialize($a_m_type)),
1713 'm_email' => array(
'integer', $a_m_email),
1714 'm_subject' => array(
'text', $a_m_subject),
1715 'm_message' => array(
'clob', $a_m_message),
1716 'use_placeholders' => array(
'integer', $a_use_placeholders),
1733 $res = $ilDB->queryf(
'
1734 SELECT * FROM '. $this->table_mail_saved .
'
1735 WHERE user_id = %s',
1737 array($this->user_id));
1757 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)
1762 $this->mail_to_global_roles =
true;
1763 if($this->user_id != ANONYMOUS_USER_ID)
1765 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id,
'mail_to_global_roles', $this->mail_obj_ref_id);
1768 $error_message =
'';
1771 if (in_array(
"system",$a_type))
1774 $a_type = array(
'system');
1779 if (!$this->mfile->checkFilesExist($a_attachment))
1781 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1785 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1787 return $error_message;
1795 $message .= $error_message;
1800 $message .= $error_message;
1805 $message .= $error_message;
1811 return $this->lng->txt($e->getMessage());
1815 if (!empty($message))
1817 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1829 $rcp_to = $rcp_cc = $rcp_bc = array();
1830 foreach($rcp_to_list as $mlist_id => $mlist_rec)
1835 $mlist_id = substr($mlist_id, 7);
1838 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1843 $rcp_to = array_merge($rcp_to, $mlist_rec);
1845 foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1850 $mlist_id = substr($mlist_id, 7);
1853 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1858 $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1860 foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1862 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1865 $rcp_to = implode(
',', $rcp_to);
1866 $rcp_cc = implode(
',', $rcp_cc);
1867 $rcp_bc = implode(
',', $rcp_bc);
1870 if (! ilMail::_usePearMail() )
1894 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1895 !$rbacsystem->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id))
1897 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1906 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1907 $a_m_subject,$a_m_message);
1911 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1913 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1932 if (in_array(
'system',$a_type))
1934 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))
1936 return $lng->txt(
"mail_send_error");
1940 if (in_array(
'normal',$a_type))
1943 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))
1945 return $lng->txt(
"mail_send_error");
1962 if(!$maintain_lists)
1973 if (!is_array($arrRcpt) || empty($arrRcpt))
1975 if(!$maintain_lists)
1985 $new_rcpt = array();
1987 foreach ($arrRcpt as $item)
1989 if (ilMail::_usePearMail())
1991 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1993 if ($this->mlists->mailingListExists($item->mailbox))
1995 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1997 if(!$maintain_lists)
1999 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2003 $new_rcpt[$item->mailbox][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2010 if(!$maintain_lists)
2012 $new_rcpt[] = $item->mailbox.
'@'.$item->host;
2016 $new_rcpt[0][] = $item->mailbox.
'@'.$item->host;
2022 if (substr($item, 0, 7) ==
'#il_ml_')
2024 if ($this->mlists->mailingListExists($item))
2026 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2028 if(!$maintain_lists)
2030 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2034 $new_rcpt[$item][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2041 if(!$maintain_lists)
2043 $new_rcpt[] = $item;
2047 $new_rcpt[0][] = $item;
2053 if(!$maintain_lists)
2055 return implode(
',', $new_rcpt);
2076 $a_m_subject,$a_m_message)
2078 include_once
"Services/Mail/classes/class.ilMailbox.php";
2081 $sent_id = $mbox->getSentFolder();
2084 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2085 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2096 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2106 public function getMimeMailSender()
2113 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2115 if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2117 $email = $ilUser->getEmail();
2118 $fullname = $ilUser->getFullname();
2122 $email = $user->getEmail();
2123 $fullname = $user->getFullname();
2149 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2151 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2152 if(strlen($no_reply_adress))
2154 if(strpos($no_reply_adress,
'@') ===
false)
2155 $no_reply_adress =
'noreply@'.$no_reply_adress;
2159 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2163 ' <'.$no_reply_adress.
'>';
2168 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2187 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap =
false)
2189 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2191 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2193 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2194 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2198 $sender = $this->getMimeMailSender();
2204 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2207 $soap_client->setResponseTimeout(1);
2208 $soap_client->enableWSDL(
true);
2209 $soap_client->init();
2211 $attachments = array();
2212 $a_attachments = $a_attachments ? $a_attachments : array();
2213 foreach($a_attachments as $attachment)
2215 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2218 $attachments = implode(
'#:#',$attachments);
2220 if(strlen($attachments))
2221 $attachments =
"#:#".$attachments;
2223 $soap_client->call(
'sendMail',array(session_id().
'::'.
$_COOKIE[
'ilClientId'],
2237 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2240 $mmail->autoCheck(
false);
2241 $mmail->From($sender);
2242 $mmail->To($a_rcp_to);
2244 $mmail->Subject($a_m_subject);
2245 $mmail->Body($a_m_message);
2249 $mmail->Cc($a_rcp_cc);
2254 $mmail->Bcc($a_rcp_bcc);
2257 if (is_array($a_attachments))
2259 foreach ($a_attachments as $attachment)
2261 $mmail->Attach($this->mfile->getAbsolutePath($attachment),
'',
'inline', $attachment);
2276 $sender = $umail->getEmail();
2298 $ilDB->update($this->table_mail_saved,
2301 'attachments' => array(
'clob', serialize($a_attachments))
2305 'user_id' => array(
'integer', $this->user_id)
2319 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2337 $a_recipients = trim($a_recipients);
2340 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2341 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2343 if (ilMail::_usePearMail() &&
$use_pear ==
true)
2345 if (strlen(trim($a_recipients)) > 0)
2347 require_once
'./Services/PEAR/lib/Mail/RFC822.php';
2349 return $parser->parseAddressList($a_recipients,
"ilias",
false,
true);
2356 foreach(explode(
',',$a_recipients) as $tmp_rec)
2360 $rcps[] = trim($tmp_rec);
2363 return is_array($rcps) ? $rcps : array();
2372 if (ilMail::_usePearMail() && $this->
getUsePear())
2375 if (! is_a($tmp_rcp,
'PEAR_Error'))
2377 foreach ($tmp_rcp as $to)
2390 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#')
2409 if (strpos($to,
'@'))
2439 if (ilMail::_usePearMail())
2443 if (! is_a($tmp_rcp,
'PEAR_Error'))
2445 foreach ($tmp_rcp as $to)
2447 if(substr($to->mailbox,0,1) !=
'#' && $to->host !=
'ilias')
2455 $rcp[] = $to->mailbox.
'@'.$to->host;
2459 return implode(
',',$rcp);
2477 return implode(
',',$rcp ? $rcp : array());
2483 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2485 $message = $inst_name.
" To:".$rcp_to.
"\n";
2489 $message .=
"Cc: ".$rcp_cc;
2493 $message .= $a_m_message;
2500 if (preg_match(
"/@all/",$a_rcp_to))
2504 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2519 $new_name = array();
2524 foreach($tmp_names as $name)
2526 if(strpos($name,
"#") === 0)
2528 $new_name[] = $name;
2536 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2540 $new_name[] = $name;
2544 case "resubstitute":
2545 if(stristr($name,
"�#�"))
2547 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2551 $new_name[] = $name;
2556 return implode(
",",$new_name);
2576 if (ilMail::_usePearMail())
2580 require_once
'./Services/User/classes/class.ilObjUser.php';
2582 $login = $usr_obj->getLogin();
2583 $firstname = $usr_obj->getFirstname();
2584 $lastname = $usr_obj->getLastname();
2594 return $login.
'hhho';
2607 public static function _usePearMail()
2614 return $ilSetting->get(
'pear_mail_enable', 0);
2631 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2636 $lang->loadLanguageModule(
'mail');
2637 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2638 $ilSetting->get(
'inst_name',
'ILIAS 4'),
2648 public static function _getIliasMailerName()
2655 if(strlen($ilSetting->get(
'mail_system_sender_name')))
2657 return $ilSetting->get(
'mail_system_sender_name');
2659 else if(strlen($ilSetting->get(
'short_inst_name')))
2661 return $ilSetting->get(
'short_inst_name');
2677 if(null === $a_flag) {
2696 global $ilClientIniFile;
2698 $signature =
"\n\n* * * * *\n";
2700 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2701 if(strlen($desc = $ilClientIniFile->readVariable(
'client',
'description')))
2703 $signature .= $desc.
"\n";
2709 if(is_array($clientdirs) && count($clientdirs) > 1)
2711 $signature .=
'/?client_id='.CLIENT_ID;
2714 $signature .=
"\n\n";
2726 static $prefix = null;
2728 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2740 $lang = $a_language ? $a_language :
$lng;
2742 $lang->loadLanguageModule(
'mail');
2744 $gender = $gender ? $gender :
'n';
2747 if(!strlen($name[
'firstname']))
2749 return $lang->txt(
'mail_salutation_anonymous').
',';
2752 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2753 ($name[
'title'] ? $name[
'title'].
' ' :
'').
2754 ($name[
'firstname'] ? $name[
'firstname'].
' ' :
'').
2755 $name[
'lastname'].
',';
2760 $this->use_pear = $bool;
2775 if(ilMail::_usePearMail())
2779 if(is_a($tmp_names,
'PEAR_Error'))
2800 if(isset(self::$userInstances[$a_usr_id]))
2802 return self::$userInstances[$a_usr_id];
2805 self::$userInstances[$a_usr_id] =
new ilObjUser($a_usr_id);
2806 return self::$userInstances[$a_usr_id];