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 .=
',';
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->hasAcceptedUserAgreement() &&
1087 $tmp_user->checkTimeLimit();
1090 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1101 if (!$user_can_read_internal_mails ||
1102 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1104 $as_email[] = $tmp_user->getEmail();
1108 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1110 $as_email[] = $tmp_user->getEmail();
1113 $mbox->setUserId($id);
1114 $inbox_id = $mbox->getInboxFolder();
1117 $a_attachments, $a_rcp_to,
1118 $a_rcp_cc,
'',
'unread', $a_type,
1119 0, $a_subject, $a_message, $id, 0);
1122 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1130 if(count($as_email) == 1)
1132 $to[] = $as_email[0];
1136 foreach ($as_email as $email)
1142 if(count($to) > 0 || count($bcc) > 0)
1144 $this->
sendMimeMail(implode(
',', $to),
'', implode(
',', $bcc), $a_subject, $a_message, $a_attachments);
1147 else # Use Placeholders
1150 $rcp_ids_replace = $this->
getUserIds(trim($a_rcp_to));
1153 $rcp_ids_no_replace = $this->
getUserIds(trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1155 $as_email = array();
1158 foreach($rcp_ids_replace as $id)
1164 $user_is_active = $tmp_user->getActive();
1165 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1166 $tmp_user->checkTimeLimit();
1169 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1180 if (!$user_can_read_internal_mails ||
1181 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1183 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1187 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1189 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1192 $mbox->setUserId($id);
1193 $inbox_id = $mbox->getInboxFolder();
1196 $a_attachments, $a_rcp_to,
1197 $a_rcp_cc,
'',
'unread', $a_type,
1198 0, $a_subject, $a_message, $id, 1);
1201 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1205 if (count($as_email))
1207 foreach ($as_email as $id => $email)
1213 $as_email = array();
1216 foreach($rcp_ids_no_replace as $id)
1222 $user_is_active = $tmp_user->getActive();
1223 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement()
1224 && $tmp_user->checkTimeLimit();
1230 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1237 if (!$user_can_read_internal_mails ||
1238 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1240 $as_email[] = $tmp_user->getEmail();
1244 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1246 $as_email[] = $tmp_user->getEmail();
1249 $mbox->setUserId($id);
1250 $inbox_id = $mbox->getInboxFolder();
1253 $a_attachments, $a_rcp_to,
1254 $a_rcp_cc,
'',
'unread', $a_type,
1255 0, $a_subject, $a_message, $id, 0);
1258 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1262 if (count($as_email))
1264 $this->
sendMimeMail(
'',
'', implode(
',', $as_email), $a_subject, $a_message, $a_attachments);
1278 global
$log, $rbacreview;
1282 if (ilMail::_usePearMail() && $this->
getUsePear() ==
true)
1285 if (! is_a($tmp_names,
'PEAR_Error'))
1287 for ($i = 0;$i < count($tmp_names); $i++)
1289 if ( substr($tmp_names[$i]->mailbox,0,1) ===
'#' ||
1290 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1291 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
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) ==
'ilias')
1336 for ($i = 0;$i < count($tmp_names); $i++)
1338 if (substr($tmp_names[$i],0,1) ==
'#')
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) !=
'#')
1433 if (strtolower($rcp->host) !=
'ilias')
1435 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
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)
1455 $addresses[] = $tmp_user->getEmail();
1466 foreach ($tmp_rcp as $rcp)
1469 if (substr($rcp,0,1) !=
'#')
1471 if (strpos($rcp,
'@'))
1473 $addresses[] = $rcp;
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)
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) !=
'#')
1540 if (
$user_id ==
false && $rcp->host ==
'ilias')
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) !=
'#')
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));
1760 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)
1765 $this->mail_to_global_roles =
true;
1766 if($this->user_id != ANONYMOUS_USER_ID)
1768 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id,
'mail_to_global_roles', $this->mail_obj_ref_id);
1771 $error_message =
'';
1774 if (in_array(
"system",$a_type))
1777 $a_type = array(
'system');
1782 if (!$this->mfile->checkFilesExist($a_attachment))
1784 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1788 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1790 return $error_message;
1798 $message .= $error_message;
1803 $message .= $error_message;
1808 $message .= $error_message;
1814 return $this->lng->txt($e->getMessage());
1818 if (!empty($message))
1820 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1829 if (! ilMail::_usePearMail() )
1853 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1854 !$rbacsystem->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id))
1856 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1865 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1866 $a_m_subject,$a_m_message);
1870 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1872 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1891 if (in_array(
'system',$a_type))
1893 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))
1895 return $lng->txt(
"mail_send_error");
1899 if (in_array(
'normal',$a_type))
1902 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))
1904 return $lng->txt(
"mail_send_error");
1919 if ($rcpt ==
'')
return $rcpt;
1922 if (!is_array($arrRcpt) || empty($arrRcpt))
return $rcpt;
1924 $new_rcpt = array();
1926 foreach ($arrRcpt as $item)
1928 if (ilMail::_usePearMail())
1930 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1932 if ($this->mlists->mailingListExists($item->mailbox))
1934 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1936 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1942 $new_rcpt[] = $item->mailbox.
'@'.$item->host;
1947 if (substr($item, 0, 7) ==
'#il_ml_')
1949 if ($this->mlists->mailingListExists($item))
1951 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1953 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1959 $new_rcpt[] = $item;
1964 return implode(
',', $new_rcpt);
1980 $a_m_subject,$a_m_message)
1982 include_once
"Services/Mail/classes/class.ilMailbox.php";
1985 $sent_id = $mbox->getSentFolder();
1988 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
1989 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2000 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2010 public function getMimeMailSender()
2017 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2019 if($this->user_id != ANONYMOUS_USER_ID)
2021 $email = $ilUser->getEmail();
2022 $fullname = $ilUser->getFullname();
2026 $email = $user->getEmail();
2027 $fullname = $user->getFullname();
2053 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2055 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2056 if(strlen($no_reply_adress))
2058 if(strpos($no_reply_adress,
'@') ===
false)
2059 $no_reply_adress =
'noreply@'.$no_reply_adress;
2063 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2067 ' <'.$no_reply_adress.
'>';
2072 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2091 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap =
false)
2093 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2095 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2097 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2098 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2102 $sender = $this->getMimeMailSender();
2108 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2111 $soap_client->setResponseTimeout(1);
2112 $soap_client->enableWSDL(
true);
2113 $soap_client->init();
2115 $attachments = array();
2116 $a_attachments = $a_attachments ? $a_attachments : array();
2117 foreach($a_attachments as $attachment)
2119 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2122 $attachments = implode(
'#:#',$attachments);
2124 if(strlen($attachments))
2125 $attachments =
"#:#".$attachments;
2127 $soap_client->call(
'sendMail',array(session_id().
'::'.
$_COOKIE[
'ilClientId'],
2141 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2144 $mmail->autoCheck(
false);
2145 $mmail->From($sender);
2146 $mmail->To($a_rcp_to);
2148 $mmail->Subject($a_m_subject);
2149 $mmail->Body($a_m_message);
2153 $mmail->Cc($a_rcp_cc);
2158 $mmail->Bcc($a_rcp_bcc);
2161 if (is_array($a_attachments))
2163 foreach ($a_attachments as $attachment)
2165 $mmail->Attach($this->mfile->getAbsolutePath($attachment));
2180 $sender = $umail->getEmail();
2202 $ilDB->update($this->table_mail_saved,
2205 'attachments' => array(
'clob', serialize($a_attachments))
2209 'user_id' => array(
'integer', $this->user_id)
2223 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2241 $a_recipients = trim($a_recipients);
2244 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2245 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2247 if (ilMail::_usePearMail() &&
$use_pear ==
true)
2249 if (strlen(trim($a_recipients)) > 0)
2251 require_once
'./Services/PEAR/lib/Mail/RFC822.php';
2253 return $parser->parseAddressList($a_recipients,
"ilias",
false,
true);
2260 foreach(explode(
',',$a_recipients) as $tmp_rec)
2264 $rcps[] = trim($tmp_rec);
2267 return is_array($rcps) ? $rcps : array();
2276 if (ilMail::_usePearMail() && $this->
getUsePear())
2279 if (! is_a($tmp_rcp,
'PEAR_Error'))
2281 foreach ($tmp_rcp as $to)
2294 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#')
2313 if (strpos($to,
'@'))
2343 if (ilMail::_usePearMail())
2347 if (! is_a($tmp_rcp,
'PEAR_Error'))
2349 foreach ($tmp_rcp as $to)
2351 if(substr($to->mailbox,0,1) !=
'#' && $to->host !=
'ilias')
2359 $rcp[] = $to->mailbox.
'@'.$to->host;
2363 return implode(
',',$rcp);
2381 return implode(
',',$rcp ? $rcp : array());
2387 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2389 $message = $inst_name.
" To:".$rcp_to.
"\n";
2393 $message .=
"Cc: ".$rcp_cc;
2397 $message .= $a_m_message;
2404 if (preg_match(
"/@all/",$a_rcp_to))
2408 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2423 $new_name = array();
2428 foreach($tmp_names as $name)
2430 if(strpos($name,
"#") === 0)
2432 $new_name[] = $name;
2440 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2444 $new_name[] = $name;
2448 case "resubstitute":
2449 if(stristr($name,
"�#�"))
2451 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2455 $new_name[] = $name;
2460 return implode(
",",$new_name);
2480 if (ilMail::_usePearMail())
2484 require_once
'./Services/User/classes/class.ilObjUser.php';
2486 $login = $usr_obj->getLogin();
2487 $firstname = $usr_obj->getFirstname();
2488 $lastname = $usr_obj->getLastname();
2498 return $login.
'hhho';
2511 public static function _usePearMail()
2518 return $ilSetting->get(
'pear_mail_enable', 0);
2535 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2540 $lang->loadLanguageModule(
'mail');
2541 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2542 $ilSetting->get(
'inst_name',
'ILIAS 4'),
2552 public static function _getIliasMailerName()
2559 if(strlen($ilSetting->get(
'mail_system_sender_name')))
2561 return $ilSetting->get(
'mail_system_sender_name');
2563 else if(strlen($ilSetting->get(
'short_inst_name')))
2565 return $ilSetting->get(
'short_inst_name');
2581 if(null === $a_flag) {
2600 global $ilClientIniFile;
2602 $signature =
"\n\n* * * * *\n";
2603 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2604 if(strlen($desc = $ilClientIniFile->readVariable(
'client',
'description')))
2606 $signature .= $desc.
"\n";
2612 if(is_array($clientdirs) && count($clientdirs) > 1)
2614 $signature .=
'/?client_id='.CLIENT_ID;
2617 $signature .=
"\n\n";
2629 static $prefix = null;
2631 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2643 $lang = $a_language ? $a_language :
$lng;
2645 $lang->loadLanguageModule(
'mail');
2647 $gender = $gender ? $gender :
'n';
2650 if(!strlen($name[
'firstname']))
2652 return $lang->txt(
'mail_salutation_anonymous').
',';
2655 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2656 ($name[
'title'] ? $name[
'title'].
' ' :
'').
2657 ($name[
'firstname'] ? $name[
'firstname'].
' ' :
'').
2658 $name[
'lastname'].
',';
2663 $this->use_pear = $bool;
2678 if(ilMail::_usePearMail())
2682 if(is_a($tmp_names,
'PEAR_Error'))
2703 if(isset(self::$userInstances[$a_usr_id]))
2705 return self::$userInstances[$a_usr_id];
2708 self::$userInstances[$a_usr_id] =
new ilObjUser($a_usr_id);
2709 return self::$userInstances[$a_usr_id];