24 require_once
'Services/User/classes/class.ilObjUser.php';
253 require_once
"classes/class.ilFileDataMail.php";
254 require_once
"Services/Mail/classes/class.ilMailOptions.php";
258 $lng->loadLanguageModule(
"mail");
263 $this->table_mail =
'mail';
264 $this->table_mail_saved =
'mail_saved';
265 $this->user_id = $a_user_id;
287 if(isset($this->properties[$name]))
289 return $this->properties[$name];
293 if($name ==
'mlists')
295 if(is_object($ilUser))
297 require_once
'Services/Contact/classes/class.ilMailingLists.php';
299 return $this->properties[$name];
306 if(self::_usePearMail())
309 if(is_a($recipients,
'PEAR_Error'))
315 foreach($recipients as $rcp)
317 if (substr($rcp->mailbox, 0, 1) !=
'#')
319 if(trim($rcp->mailbox) == trim($a_recipient) ||
320 trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
325 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
327 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
334 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
345 if(count($recipients))
347 foreach($recipients as $recipient)
349 if(trim($recipient) == trim($a_recipient))
369 $this->soap_enabled = $a_status;
375 if(!extension_loaded(
'curl') || !$ilSetting->get(
'soap_user_administration'))
386 $this->save_in_sentbox = $a_save_in_sentbox;
401 $this->mail_send_type = $a_types;
411 $this->mail_rcp_to = $a_rcp_to;
421 $this->mail_rcp_cc = $a_rcp_cc;
431 $this->mail_rcp_bc = $a_rcp_bc;
441 $this->mail_subject = $a_subject;
451 $this->mail_message = $a_message;
460 include_once
'Services/Mail/classes/class.ilMailGlobalServices.php';
481 $users = trim($users);
484 if(strstr($users,
','))
486 $rcp_to_array = array();
488 $recipients = explode(
',', $users);
489 foreach($recipients as $recipient)
491 $recipient = trim($recipient);
497 $rcp_to_array[] = $tmp_obj->getFullname().
' ['.$recipient.
']';
501 $rcp_to_array[] = $recipient;
506 $rcp_to_array[] = $recipient;
510 return trim(implode(
', ', $rcp_to_array));
519 return $tmp_obj->getFullname().
' ['.$users.
']';
534 return $this->lng->txt(
'not_available');
543 $res = $ilDB->queryf(
"
544 SELECT b.* FROM " . $this->table_mail .
" a
545 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
546 AND b.user_id = a.user_id AND b.send_time > a.send_time
548 AND a.mail_id = %s ORDER BY b.send_time ASC",
549 array(
'integer',
'integer'),
550 array($this->user_id, $a_mail_id));
562 $res = $ilDB->queryf(
"
563 SELECT b.* FROM " . $this->table_mail .
" a
564 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
565 AND b.user_id = a.user_id AND b.send_time < a.send_time
567 AND a.mail_id = %s ORDER BY b.send_time DESC",
568 array(
'integer',
'integer'),
569 array($this->user_id, $a_mail_id));
587 $this->mail_counter = array();
588 $this->mail_counter[
'read'] = 0;
589 $this->mail_counter[
'unread'] = 0;
591 $query =
"SELECT sender_id, m_subject, mail_id, m_status, send_time FROM ". $this->table_mail .
"
592 LEFT JOIN object_data ON obj_id = sender_id
595 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)) ";
597 if($filter[
'status'])
599 $query .=
' AND m_status = '.$ilDB->quote($filter[
'status'],
'text');
603 $query .=
' AND '.$ilDB->like(
'm_type',
'text',
'%%:"'.$filter[
'type'].
'"%%',
false);
606 $query .=
" ORDER BY send_time DESC";
609 array(
'integer',
'integer'),
610 array($this->user_id, $a_folder_id));
612 while (
$row = $ilDB->fetchObject(
$res))
616 if($tmp[
'm_status'] ==
'read')
618 ++$this->mail_counter[
'read'];
621 if($tmp[
'm_status'] ==
'unread')
623 ++$this->mail_counter[
'unread'];
629 $this->mail_counter[
'total'] = count($output);
631 return $output ? $output : array();
644 $res = $ilDB->queryf(
"
645 SELECT COUNT(*) FROM ". $this->table_mail .
"
648 array(
'integer',
'integer'),
649 array($this->user_id, $a_folder_id));
651 return $res->numRows();
692 return is_array($this->mail_counter) ? $this->mail_counter : array(
708 $res = $ilDB->queryf(
"
709 SELECT * FROM ". $this->table_mail .
"
712 array(
'integer',
'integer'),
713 array($this->user_id, $a_mail_id));
732 $data_types = array();
734 $query =
"UPDATE ". $this->table_mail .
"
736 WHERE user_id = %s ";
737 array_push($data_types,
'text',
'integer');
738 array_push(
$data,
'read', $this->user_id);
740 $cnt_mail_ids = count($a_mail_ids);
742 if (is_array($a_mail_ids) &&
743 count($a_mail_ids) > 0)
746 $in =
'mail_id IN (';
748 foreach($a_mail_ids as $a_mail_id)
750 array_push(
$data, $a_mail_id);
751 array_push($data_types,
'integer');
753 if($counter > 0)
$in .=
',';
778 $data_types = array();
780 $query =
"UPDATE ". $this->table_mail .
"
782 WHERE user_id = %s ";
783 array_push($data_types,
'text',
'integer');
784 array_push(
$data,
'unread', $this->user_id);
786 $cnt_mail_ids = count($a_mail_ids);
788 if (is_array($a_mail_ids) &&
789 count($a_mail_ids) > 0)
792 $in =
'mail_id IN (';
794 foreach($a_mail_ids as $a_mail_id)
796 array_push(
$data, $a_mail_id);
797 array_push($data_types,
'integer');
799 if($counter > 0)
$in .=
',';
808 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
825 $data_types = array();
827 $query =
"UPDATE ". $this->table_mail .
"
829 WHERE user_id = %s ";
830 array_push($data_types,
'text',
'integer');
831 array_push(
$data, $a_folder_id, $this->user_id);
833 $cnt_mail_ids = count($a_mail_ids);
835 if (is_array($a_mail_ids) &&
836 count($a_mail_ids) > 0)
839 $in =
'mail_id IN (';
841 foreach($a_mail_ids as $a_mail_id)
843 array_push(
$data, $a_mail_id);
844 array_push($data_types,
'integer');
846 if($counter > 0)
$in .=
',';
855 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
870 foreach ($a_mail_ids as $id)
872 $statement = $ilDB->manipulateF(
"
873 DELETE FROM ". $this->table_mail .
"
876 array(
'integer',
'integer'),
877 array($this->user_id, $id));
879 $this->mfile->deassignAttachmentFromDirectory($id);
896 "mail_id" => $a_row->mail_id,
897 "user_id" => $a_row->user_id,
898 "folder_id" => $a_row->folder_id,
899 "sender_id" => $a_row->sender_id,
900 "attachments" => unserialize(stripslashes($a_row->attachments)),
901 "send_time" => $a_row->send_time,
902 "rcp_to" => $a_row->rcp_to,
903 "rcp_cc" => $a_row->rcp_cc,
904 "rcp_bcc" => $a_row->rcp_bcc,
905 "m_status" => $a_row->m_status,
906 "m_type" => unserialize(stripslashes($a_row->m_type)),
907 "m_email" => $a_row->m_email,
908 "m_subject" => $a_row->m_subject,
909 "m_message" => $a_row->m_message,
910 "import_name" => $a_row->import_name,
911 "use_placeholders"=> $a_row->use_placeholders);
923 $a_draft_id = 0, $a_use_placeholders = 0)
927 $ilDB->update($this->table_mail,
929 'folder_id' => array(
'integer', $a_folder_id),
930 'attachments' => array(
'clob', serialize($a_attachments)),
931 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
932 'rcp_to' => array(
'clob', $a_rcp_to),
933 'rcp_cc' => array(
'clob', $a_rcp_cc),
934 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
935 'm_status' => array(
'text',
'read'),
936 'm_type' => array(
'text', serialize($a_m_type)),
937 'm_email' => array(
'integer', $a_m_email),
938 'm_subject' => array(
'text', $a_m_subject),
939 'm_message' => array(
'clob', $a_m_message),
940 'use_placeholders' => array(
'integer', $a_use_placeholders)
943 'mail_id' => array(
'integer', $a_draft_id)
978 $a_user_id = 0, $a_use_placeholders = 0)
985 if ($a_use_placeholders)
991 $a_use_placeholders =
'0';
995 if(!$a_user_id) $a_user_id =
'0';
996 if(!$a_folder_id) $a_folder_id =
'0';
997 if(!$a_sender_id) $a_sender_id = NULL;
998 if(!$a_attachments) $a_attachments = NULL;
999 if(!$a_rcp_to) $a_rcp_to = NULL;
1000 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1001 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1002 if(!$a_status) $a_status = NULL;
1003 if(!$a_m_type) $a_m_type = NULL;
1004 if(!$a_m_email) $a_m_email = NULL;
1005 if(!$a_m_subject) $a_m_subject = NULL;
1006 if(!$a_m_message) $a_m_message = NULL;
1009 $next_id = $ilDB->nextId($this->table_mail);
1011 $ilDB->insert($this->table_mail, array(
1012 'mail_id' => array(
'integer', $next_id),
1013 'user_id' => array(
'integer', $a_user_id),
1014 'folder_id' => array(
'integer', $a_folder_id),
1015 'sender_id' => array(
'integer', $a_sender_id),
1016 'attachments' => array(
'clob', serialize($a_attachments)),
1017 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
1018 'rcp_to' => array(
'clob', $a_rcp_to),
1019 'rcp_cc' => array(
'clob', $a_rcp_cc),
1020 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1021 'm_status' => array(
'text', $a_status),
1022 'm_type' => array(
'text', serialize($a_m_type)),
1023 'm_email' => array(
'integer', $a_m_email),
1024 'm_subject' => array(
'text', $a_m_subject),
1025 'm_message' => array(
'clob', $a_m_message)
1039 switch ($user->getGender())
1041 case 'f': $gender_salut = $lng->txt(
'salutation_f');
1043 case 'm': $gender_salut = $lng->txt(
'salutation_m');
1047 $a_message = str_replace(
'[MAIL_SALUTATION]', $gender_salut, $a_message);
1048 $a_message = str_replace(
'[LOGIN]', $user->getLogin(), $a_message);
1049 $a_message = str_replace(
'[FIRST_NAME]', $user->getFirstname(), $a_message);
1050 $a_message = str_replace(
'[LAST_NAME]', $user->getLastname(), $a_message);
1051 $a_message = str_replace(
'[ILIAS_URL]', ILIAS_HTTP_PATH.
'/login.php?client_id='.CLIENT_ID, $a_message);
1052 $a_message = str_replace(
'[CLIENT_NAME]', CLIENT_NAME, $a_message);
1070 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)
1074 include_once
'Services/Mail/classes/class.ilMailbox.php';
1075 include_once
'./Services/User/classes/class.ilObjUser.php';
1087 if (!$a_use_placeholders) # No Placeholders
1089 $rcp_ids = $this->
getUserIds(trim($a_rcp_to).
','.trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1091 $as_email = array();
1093 foreach($rcp_ids as $id)
1099 $user_is_active = $tmp_user->getActive();
1100 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1101 $tmp_user->checkTimeLimit();
1104 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1115 if (!$user_can_read_internal_mails ||
1116 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1118 $as_email[] = $tmp_user->getEmail();
1122 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1124 $as_email[] = $tmp_user->getEmail();
1127 $mbox->setUserId($id);
1128 $inbox_id = $mbox->getInboxFolder();
1131 $a_attachments, $a_rcp_to,
1132 $a_rcp_cc,
'',
'unread', $a_type,
1133 0, $a_subject, $a_message, $id, 0);
1136 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1144 if(count($as_email) == 1)
1146 $to[] = $as_email[0];
1150 foreach ($as_email as $email)
1156 if(count($to) > 0 || count($bcc) > 0)
1158 $this->
sendMimeMail(implode(
',', $to),
'', implode(
',', $bcc), $a_subject, $a_message, $a_attachments);
1161 else # Use Placeholders
1164 $rcp_ids_replace = $this->
getUserIds(trim($a_rcp_to));
1167 $rcp_ids_no_replace = $this->
getUserIds(trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1169 $as_email = array();
1172 foreach($rcp_ids_replace as $id)
1178 $user_is_active = $tmp_user->getActive();
1179 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1180 $tmp_user->checkTimeLimit();
1183 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1194 if (!$user_can_read_internal_mails ||
1195 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1197 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1201 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1203 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1206 $mbox->setUserId($id);
1207 $inbox_id = $mbox->getInboxFolder();
1210 $a_attachments, $a_rcp_to,
1211 $a_rcp_cc,
'',
'unread', $a_type,
1212 0, $a_subject, $a_message, $id, 1);
1215 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1219 if (count($as_email))
1221 foreach ($as_email as $id => $email)
1227 $as_email = array();
1230 foreach($rcp_ids_no_replace as $id)
1236 $user_is_active = $tmp_user->getActive();
1237 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement()
1238 && $tmp_user->checkTimeLimit();
1244 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1251 if (!$user_can_read_internal_mails ||
1252 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1254 $as_email[] = $tmp_user->getEmail();
1258 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1260 $as_email[] = $tmp_user->getEmail();
1263 $mbox->setUserId($id);
1264 $inbox_id = $mbox->getInboxFolder();
1267 $a_attachments, $a_rcp_to,
1268 $a_rcp_cc,
'',
'unread', $a_type,
1269 0, $a_subject, $a_message, $id, 0);
1272 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1276 if (count($as_email))
1278 $this->
sendMimeMail(
'',
'', implode(
',', $as_email), $a_subject, $a_message, $a_attachments);
1292 global
$log, $rbacreview;
1299 if (! is_a($tmp_names,
'PEAR_Error'))
1301 for ($i = 0;$i < count($tmp_names); $i++)
1303 if ( substr($tmp_names[$i]->mailbox,0,1) ===
'#' ||
1304 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1305 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
1307 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1308 foreach($role_ids as $role_id)
1310 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1316 else if (strtolower($tmp_names[$i]->host) ==
'ilias')
1350 for ($i = 0;$i < count($tmp_names); $i++)
1352 if (substr($tmp_names[$i],0,1) ==
'#')
1356 include_once(
"./classes/class.ilObjectFactory.php");
1357 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1365 foreach ($grp_object->getGroupMemberIds() as $id)
1371 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1373 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1380 else if (!empty($tmp_names[$i]))
1389 return array_unique($ids);
1402 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1404 $error_message =
'';
1406 $a_m_subject = trim($a_m_subject);
1407 $a_rcp_to = trim($a_rcp_to);
1409 if (empty($a_m_subject))
1411 $error_message .= $error_message ?
"<br>" :
'';
1412 $error_message .= $this->lng->txt(
"mail_add_subject");
1415 if (empty($a_rcp_to))
1417 $error_message .= $error_message ?
"<br>" :
'';
1418 $error_message .= $this->lng->txt(
"mail_add_recipient");
1421 return $error_message;
1434 $addresses = array();
1440 if (! is_a($tmp_rcp,
'PEAR_Error'))
1442 foreach ($tmp_rcp as $rcp)
1445 if (substr($rcp->mailbox,0,1) !=
'#')
1447 if (strtolower($rcp->host) !=
'ilias')
1449 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
1456 $addresses[] = $tmp_user->getEmail();
1463 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1464 foreach($role_ids as $role_id)
1466 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1469 $addresses[] = $tmp_user->getEmail();
1480 foreach ($tmp_rcp as $rcp)
1483 if (substr($rcp,0,1) !=
'#')
1485 if (strpos($rcp,
'@'))
1487 $addresses[] = $rcp;
1494 $addresses[] = $tmp_user->getEmail();
1501 include_once(
"./classes/class.ilObjectFactory.php");
1502 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1511 foreach ($grp_object->getGroupMemberIds() as $id)
1514 $addresses[] = $tmp_user->getEmail();
1532 global $rbacsystem,$rbacreview;
1540 if (is_a($tmp_rcp,
'PEAR_Error'))
1542 $colon_pos = strpos($tmp_rcp->message,
':');
1543 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1547 foreach ($tmp_rcp as $rcp)
1550 if (substr($rcp->mailbox,0,1) !=
'#')
1554 if (
$user_id ==
false && $rcp->host ==
'ilias')
1556 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1563 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1565 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1566 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1571 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1573 if (!$this->mlists->mailingListExists($rcp->mailbox))
1575 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1576 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1584 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1586 if(!$this->mail_to_global_roles && is_array($role_ids))
1588 foreach($role_ids as $role_id)
1590 if($rbacreview->isGlobalRole($role_id))
1592 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1598 if (count($role_ids) == 0)
1600 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1601 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1604 else if (count($role_ids) > 1)
1606 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1607 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1617 foreach ($tmp_rcp as $rcp)
1624 if (substr($rcp,0,1) !=
'#')
1630 $wrong_rcps .=
"<br />".htmlentities($rcp);
1637 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1639 $wrong_rcps .=
"<br />".htmlentities($rcp).
1640 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1645 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1647 if (!$this->mlists->mailingListExists($rcp))
1649 $wrong_rcps .=
"<br />".htmlentities($rcp).
1650 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1659 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1661 $wrong_rcps .=
"<br />".htmlentities($rcp).
1662 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1665 else if (!$this->mail_to_global_roles)
1667 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1668 if((
int)$role_id && $rbacreview->isGlobalRole($role_id))
1670 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1703 $a_use_placeholders)
1708 if(!$a_attachments) $a_attachments = NULL;
1709 if(!$a_rcp_to) $a_rcp_to = NULL;
1710 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1711 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1712 if(!$a_m_type) $a_m_type = NULL;
1713 if(!$a_m_email) $a_m_email = NULL;
1714 if(!$a_m_message) $a_m_message = NULL;
1715 if(!$a_use_placeholders) $a_use_placeholders =
'0';
1718 $statement = $ilDB->manipulateF(
'
1719 DELETE FROM '. $this->table_mail_saved .
'
1720 WHERE user_id = %s',
1721 array(
'integer'), array($this->user_id));
1723 $ilDB->insert($this->table_mail_saved, array(
1724 'user_id' => array(
'integer', $a_user_id),
1725 'attachments' => array(
'clob', serialize($a_attachments)),
1726 'rcp_to' => array(
'clob', $a_rcp_to),
1727 'rcp_cc' => array(
'clob', $a_rcp_cc),
1728 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1729 'm_type' => array(
'text', serialize($a_m_type)),
1730 'm_email' => array(
'integer', $a_m_email),
1731 'm_subject' => array(
'text', $a_m_subject),
1732 'm_message' => array(
'clob', $a_m_message),
1733 'use_placeholders' => array(
'integer', $a_use_placeholders),
1750 $res = $ilDB->queryf(
'
1751 SELECT * FROM '. $this->table_mail_saved .
'
1752 WHERE user_id = %s',
1754 array($this->user_id));
1774 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)
1779 $this->mail_to_global_roles =
true;
1780 if($this->user_id != ANONYMOUS_USER_ID)
1782 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id,
'mail_to_global_roles', $this->mail_obj_ref_id);
1785 $error_message =
'';
1788 if (in_array(
"system",$a_type))
1791 $a_type = array(
'system');
1796 if (!$this->mfile->checkFilesExist($a_attachment))
1798 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1802 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1804 return $error_message;
1812 $message .= $error_message;
1817 $message .= $error_message;
1822 $message .= $error_message;
1828 return $this->lng->txt($e->getMessage());
1832 if (!empty($message))
1834 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1838 if (in_array(
'system',$a_type))
1840 if (!empty($a_attachment))
1842 return $lng->txt(
"mail_no_attach_allowed");
1876 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1877 !$rbacsystem->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id))
1879 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1888 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1889 $a_m_subject,$a_m_message);
1893 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1895 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1914 if (in_array(
'system',$a_type))
1916 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))
1918 return $lng->txt(
"mail_send_error");
1922 if (in_array(
'normal',$a_type))
1925 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))
1927 return $lng->txt(
"mail_send_error");
1942 if ($rcpt ==
'')
return $rcpt;
1945 if (!is_array($arrRcpt) || empty($arrRcpt))
return $rcpt;
1947 $new_rcpt = array();
1949 foreach ($arrRcpt as $item)
1953 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1955 if ($this->mlists->mailingListExists($item->mailbox))
1957 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1959 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1965 $new_rcpt[] = $item->mailbox.
'@'.$item->host;
1970 if (substr($item, 0, 7) ==
'#il_ml_')
1972 if ($this->mlists->mailingListExists($item))
1974 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1976 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1982 $new_rcpt[] = $item;
1987 return implode(
',', $new_rcpt);
2003 $a_m_subject,$a_m_message)
2005 include_once
"Services/Mail/classes/class.ilMailbox.php";
2008 $sent_id = $mbox->getSentFolder();
2011 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2012 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2023 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2033 public function getMimeMailSender()
2040 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2042 if($this->user_id != ANONYMOUS_USER_ID)
2044 $email = $ilUser->getEmail();
2045 $fullname = $ilUser->getFullname();
2049 $email = $user->getEmail();
2050 $fullname = $user->getFullname();
2076 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2078 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2079 if(strlen($no_reply_adress))
2081 if(strpos($no_reply_adress,
'@') ===
false)
2082 $no_reply_adress =
'noreply@'.$no_reply_adress;
2086 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2090 ' <'.$no_reply_adress.
'>';
2095 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2113 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments)
2115 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2117 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2119 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2120 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2124 $sender = $this->getMimeMailSender();
2129 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2132 $soap_client->setResponseTimeout(1);
2133 $soap_client->enableWSDL(
true);
2134 $soap_client->init();
2136 $attachments = array();
2137 $a_attachments = $a_attachments ? $a_attachments : array();
2138 foreach($a_attachments as $attachment)
2140 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2143 $attachments = implode(
'#:#',$attachments);
2145 if(strlen($attachments))
2146 $attachments =
"#:#".$attachments;
2148 $soap_client->call(
'sendMail',array(
$_COOKIE[
'PHPSESSID'].
'::'.
$_COOKIE[
'ilClientId'],
2162 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2165 $mmail->autoCheck(
false);
2166 $mmail->From($sender);
2167 $mmail->To($a_rcp_to);
2169 $mmail->Subject($a_m_subject);
2170 $mmail->Body($a_m_message);
2174 $mmail->Cc($a_rcp_cc);
2179 $mmail->Bcc($a_rcp_bcc);
2182 if (is_array($a_attachments))
2184 foreach ($a_attachments as $attachment)
2186 $mmail->Attach($this->mfile->getAbsolutePath($attachment));
2201 $sender = $umail->getEmail();
2223 $ilDB->update($this->table_mail_saved,
2226 'attachments' => array(
'clob', serialize($a_attachments))
2230 'user_id' => array(
'integer', $this->user_id)
2244 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2262 $a_recipients = trim($a_recipients);
2265 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2266 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2270 if (strlen(trim($a_recipients)) > 0)
2272 require_once
'Mail/RFC822.php';
2274 return $parser->parseAddressList($a_recipients,
"ilias",
false,
true);
2281 foreach(explode(
',',$a_recipients) as $tmp_rec)
2285 $rcps[] = trim($tmp_rec);
2288 return is_array($rcps) ? $rcps : array();
2300 if (! is_a($tmp_rcp,
'PEAR_Error'))
2302 foreach ($tmp_rcp as $to)
2315 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#')
2334 if (strpos($to,
'@'))
2368 if (! is_a($tmp_rcp,
'PEAR_Error'))
2370 foreach ($tmp_rcp as $to)
2372 if(substr($to->mailbox,0,1) !=
'#' && $to->host !=
'ilias')
2380 $rcp[] = $to->mailbox.
'@'.$to->host;
2384 return implode(
',',$rcp);
2402 return implode(
',',$rcp ? $rcp : array());
2408 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2410 $message = $inst_name.
" To:".$rcp_to.
"\n";
2414 $message .=
"Cc: ".$rcp_cc;
2418 $message .= $a_m_message;
2425 if (preg_match(
"/@all/",$a_rcp_to))
2429 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2444 $new_name = array();
2449 foreach($tmp_names as $name)
2451 if(strpos($name,
"#") === 0)
2453 $new_name[] = $name;
2461 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2465 $new_name[] = $name;
2469 case "resubstitute":
2470 if(stristr($name,
"�#�"))
2472 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2476 $new_name[] = $name;
2481 return implode(
",",$new_name);
2505 require_once
'./Services/User/classes/class.ilObjUser.php';
2507 $login = $usr_obj->getLogin();
2508 $firstname = $usr_obj->getFirstname();
2509 $lastname = $usr_obj->getLastname();
2519 return $login.
'hhho';
2537 if ($ilias->getSetting(
'pear_mail_enable', 0))
2542 $is_pear_mail_installed = @include_once
'Mail/RFC822.php';
2543 if($is_pear_mail_installed ==
false)
2546 $is_pear_mail_installed = @include_once
'./Services/PEAR/lib/Mail/RFC822.php';
2549 if ($is_pear_mail_installed)
2558 $log->write(
"WARNING: ilMail::_userPearMail disabled Pear Mail support, because include 'Mail/RFC822.php' failed.");
2559 $ilias->setSetting(
'pear_mail_enable', 0);
2579 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2584 $lang->loadLanguageModule(
'mail');
2585 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2586 $ilSetting->get(
'inst_name',
'ILIAS 4'),
2598 public static function _getIliasMailerName()
2605 if(strlen($ilSetting->get(
'short_inst_name')))
2607 return $ilSetting->get(
'short_inst_name');
2623 if(null === $a_flag) {
2642 global $ilClientIniFile;
2644 $signature =
"\n\n* * * * *\n";
2645 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2646 if(strlen($desc = $ilClientIniFile->readVariable(
'client',
'description')))
2648 $signature .= $desc.
"\n";
2654 if(is_array($clientdirs) && count($clientdirs) > 1)
2656 $signature .=
'/?client_id='.CLIENT_ID;
2659 $signature .=
"\n\n";
2671 static $prefix = null;
2673 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2685 $lang = $a_language ? $a_language :
$lng;
2688 $gender = $gender ? $gender :
'n';
2691 if(!strlen($name[
'firstname']))
2693 return $lang->txt(
'mail_salutation_anonymous').
',';
2696 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2697 ($name[
'title'] ? $name[
'title'].
' ' :
'').
2698 ($name[
'firstname'] ? $name[
'firstname'].
' ' :
'').
2699 $name[
'lastname'].
',';
2704 $this->use_pear = $bool;
2723 if(is_a($tmp_names,
'PEAR_Error'))
2744 if(isset(self::$userInstances[$a_usr_id]))
2746 return self::$userInstances[$a_usr_id];
2749 self::$userInstances[$a_usr_id] =
new ilObjUser($a_usr_id);
2750 return self::$userInstances[$a_usr_id];