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);
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));
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();
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 .=
',';
753 $res = $ilDB->manipulateF(
$query, $data_types, $data);
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)
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)
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)
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)
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) ===
'#' ||
1292 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1293 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
1295 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1296 foreach($role_ids as $role_id)
1298 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1338 for ($i = 0;$i < count($tmp_names); $i++)
1340 if (substr($tmp_names[$i],0,1) ==
'#')
1344 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1345 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1353 foreach ($grp_object->getGroupMemberIds() as $id)
1359 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1361 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1368 else if (!empty($tmp_names[$i]))
1377 return array_unique($ids);
1390 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1392 $error_message =
'';
1394 $a_m_subject = trim($a_m_subject);
1395 $a_rcp_to = trim($a_rcp_to);
1397 if (empty($a_m_subject))
1399 $error_message .= $error_message ?
"<br>" :
'';
1400 $error_message .= $this->lng->txt(
"mail_add_subject");
1403 if (empty($a_rcp_to))
1405 $error_message .= $error_message ?
"<br>" :
'';
1406 $error_message .= $this->lng->txt(
"mail_add_recipient");
1409 return $error_message;
1422 $addresses = array();
1425 if (ilMail::_usePearMail() && $this->
getUsePear())
1428 if (! is_a($tmp_rcp,
'PEAR_Error'))
1430 foreach ($tmp_rcp as $rcp)
1433 if (substr($rcp->mailbox,0,1) !=
'#')
1435 if (strtolower($rcp->host) != self::ILIAS_HOST)
1437 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
1444 $addresses[] = $tmp_user->getEmail();
1451 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1452 foreach($role_ids as $role_id)
1454 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1457 $addresses[] = $tmp_user->getEmail();
1468 foreach ($tmp_rcp as $rcp)
1471 if (substr($rcp,0,1) !=
'#')
1473 if (strpos($rcp,
'@'))
1475 $addresses[] = $rcp;
1482 $addresses[] = $tmp_user->getEmail();
1489 include_once(
"./Services/Object/classes/class.ilObjectFactory.php");
1490 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1499 foreach ($grp_object->getGroupMemberIds() as $id)
1502 $addresses[] = $tmp_user->getEmail();
1520 global $rbacsystem,$rbacreview;
1524 if (ilMail::_usePearMail() && $this->
getUsePear())
1528 if (is_a($tmp_rcp,
'PEAR_Error'))
1530 $colon_pos = strpos($tmp_rcp->message,
':');
1531 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1535 foreach ($tmp_rcp as $rcp)
1538 if (substr($rcp->mailbox,0,1) !=
'#')
1542 if (
$user_id ==
false && $rcp->host == self::ILIAS_HOST)
1544 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1551 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1553 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1554 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1559 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1561 if (!$this->mlists->mailingListExists($rcp->mailbox))
1563 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1564 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1572 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1574 if(!$this->mail_to_global_roles && is_array($role_ids))
1576 foreach($role_ids as $role_id)
1578 if($rbacreview->isGlobalRole($role_id))
1580 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1586 if (count($role_ids) == 0)
1588 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1589 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1592 else if (count($role_ids) > 1)
1594 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1595 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1605 foreach ($tmp_rcp as $rcp)
1612 if (substr($rcp,0,1) !=
'#')
1618 $wrong_rcps .=
"<br />".htmlentities($rcp);
1625 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"internal_mail", $this->getMailObjectReferenceId()))
1627 $wrong_rcps .=
"<br />".htmlentities($rcp).
1628 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1633 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1635 if (!$this->mlists->mailingListExists($rcp))
1637 $wrong_rcps .=
"<br />".htmlentities($rcp).
1638 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1647 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1649 $wrong_rcps .=
"<br />".htmlentities($rcp).
1650 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1653 else if (!$this->mail_to_global_roles)
1655 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1656 if((
int)$role_id && $rbacreview->isGlobalRole($role_id))
1658 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1691 $a_use_placeholders)
1696 if(!$a_attachments) $a_attachments = NULL;
1697 if(!$a_rcp_to) $a_rcp_to = NULL;
1698 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1699 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1700 if(!$a_m_type) $a_m_type = NULL;
1701 if(!$a_m_email) $a_m_email = NULL;
1702 if(!$a_m_message) $a_m_message = NULL;
1703 if(!$a_use_placeholders) $a_use_placeholders =
'0';
1706 $statement = $ilDB->manipulateF(
'
1707 DELETE FROM '. $this->table_mail_saved .
'
1708 WHERE user_id = %s',
1709 array(
'integer'), array($this->user_id));
1711 $ilDB->insert($this->table_mail_saved, array(
1712 'user_id' => array(
'integer', $a_user_id),
1713 'attachments' => array(
'clob', serialize($a_attachments)),
1714 'rcp_to' => array(
'clob', $a_rcp_to),
1715 'rcp_cc' => array(
'clob', $a_rcp_cc),
1716 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1717 'm_type' => array(
'text', serialize($a_m_type)),
1718 'm_email' => array(
'integer', $a_m_email),
1719 'm_subject' => array(
'text', $a_m_subject),
1720 'm_message' => array(
'clob', $a_m_message),
1721 'use_placeholders' => array(
'integer', $a_use_placeholders),
1738 $res = $ilDB->queryf(
'
1739 SELECT * FROM '. $this->table_mail_saved .
'
1740 WHERE user_id = %s',
1742 array($this->user_id));
1762 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)
1767 $this->mail_to_global_roles =
true;
1768 if($this->user_id != ANONYMOUS_USER_ID)
1770 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id,
'mail_to_global_roles', $this->mail_obj_ref_id);
1773 $error_message =
'';
1776 if (in_array(
"system",$a_type))
1779 $a_type = array(
'system');
1784 if (!$this->mfile->checkFilesExist($a_attachment))
1786 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1790 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1792 return $error_message;
1800 $message .= $error_message;
1805 $message .= $error_message;
1810 $message .= $error_message;
1816 return $this->lng->txt($e->getMessage());
1820 if (!empty($message))
1822 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1834 $rcp_to = $rcp_cc = $rcp_bc = array();
1835 foreach($rcp_to_list as $mlist_id => $mlist_rec)
1840 $mlist_id = substr($mlist_id, 7);
1843 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1848 $rcp_to = array_merge($rcp_to, $mlist_rec);
1850 foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1855 $mlist_id = substr($mlist_id, 7);
1858 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1863 $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1865 foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1867 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1870 $rcp_to = implode(
',', $rcp_to);
1871 $rcp_cc = implode(
',', $rcp_cc);
1872 $rcp_bc = implode(
',', $rcp_bc);
1875 if (! ilMail::_usePearMail() )
1899 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1900 !$rbacsystem->checkAccessOfUser($this->user_id,
'smtp_mail', $this->mail_obj_ref_id))
1902 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1911 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1912 $a_m_subject,$a_m_message);
1916 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1918 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1937 if (in_array(
'system',$a_type))
1939 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))
1941 return $lng->txt(
"mail_send_error");
1945 if (in_array(
'normal',$a_type))
1948 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))
1950 return $lng->txt(
"mail_send_error");
1967 if(!$maintain_lists)
1978 if (!is_array($arrRcpt) || empty($arrRcpt))
1980 if(!$maintain_lists)
1990 $new_rcpt = array();
1992 foreach ($arrRcpt as $item)
1994 if (ilMail::_usePearMail())
1996 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1998 if ($this->mlists->mailingListExists($item->mailbox))
2000 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2002 if(!$maintain_lists)
2004 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2008 $new_rcpt[$item->mailbox][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2016 if($item->host == self::ILIAS_HOST)
2018 $tmp_rcpt = $item->mailbox;
2022 $tmp_rcpt = $item->mailbox.
'@'.$item->host;
2025 if(!$maintain_lists)
2027 $new_rcpt[] = $tmp_rcpt;
2031 $new_rcpt[0][] = $tmp_rcpt;
2037 if (substr($item, 0, 7) ==
'#il_ml_')
2039 if ($this->mlists->mailingListExists($item))
2041 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2043 if(!$maintain_lists)
2045 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2049 $new_rcpt[$item][] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
2056 if(!$maintain_lists)
2058 $new_rcpt[] = $item;
2062 $new_rcpt[0][] = $item;
2068 if(!$maintain_lists)
2070 return implode(
',', $new_rcpt);
2091 $a_m_subject,$a_m_message)
2093 include_once
"Services/Mail/classes/class.ilMailbox.php";
2096 $sent_id = $mbox->getSentFolder();
2099 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2100 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2111 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2121 public function getMimeMailSender()
2128 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2130 if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2132 $email = $ilUser->getEmail();
2133 $fullname = $ilUser->getFullname();
2137 $email = $user->getEmail();
2138 $fullname = $user->getFullname();
2164 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2166 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2167 if(strlen($no_reply_adress))
2169 if(strpos($no_reply_adress,
'@') ===
false)
2170 $no_reply_adress =
'noreply@'.$no_reply_adress;
2174 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2178 ' <'.$no_reply_adress.
'>';
2183 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2202 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap =
false)
2204 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2206 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2208 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2209 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2213 $sender = $this->getMimeMailSender();
2219 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2222 $soap_client->setResponseTimeout(1);
2223 $soap_client->enableWSDL(
true);
2224 $soap_client->init();
2226 $attachments = array();
2227 $a_attachments = $a_attachments ? $a_attachments : array();
2228 foreach($a_attachments as $attachment)
2230 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2233 $attachments = implode(
'#:#',$attachments);
2235 if(strlen($attachments))
2236 $attachments =
"#:#".$attachments;
2238 $soap_client->call(
'sendMail',array(session_id().
'::'.
$_COOKIE[
'ilClientId'],
2252 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2255 $mmail->autoCheck(
false);
2256 $mmail->From($sender);
2257 $mmail->To($a_rcp_to);
2259 $mmail->Subject($a_m_subject);
2260 $mmail->Body($a_m_message);
2264 $mmail->Cc($a_rcp_cc);
2269 $mmail->Bcc($a_rcp_bcc);
2272 if (is_array($a_attachments))
2274 foreach ($a_attachments as $attachment)
2276 $mmail->Attach($this->mfile->getAbsolutePath($attachment),
'',
'inline', $attachment);
2291 $sender = $umail->getEmail();
2313 $ilDB->update($this->table_mail_saved,
2316 'attachments' => array(
'clob', serialize($a_attachments))
2320 'user_id' => array(
'integer', $this->user_id)
2334 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2352 $a_recipients = trim($a_recipients);
2355 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2356 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2358 if (ilMail::_usePearMail() &&
$use_pear ==
true)
2360 if (strlen(trim($a_recipients)) > 0)
2362 require_once
'./Services/PEAR/lib/Mail/RFC822.php';
2364 return $parser->parseAddressList($a_recipients, self::ILIAS_HOST,
false,
true);
2371 foreach(explode(
',',$a_recipients) as $tmp_rec)
2375 $rcps[] = trim($tmp_rec);
2378 return is_array($rcps) ? $rcps : array();
2387 if (ilMail::_usePearMail() && $this->
getUsePear())
2390 if (! is_a($tmp_rcp,
'PEAR_Error'))
2392 foreach ($tmp_rcp as $to)
2405 if ($to->host != self::ILIAS_HOST && substr($to->mailbox,0,1) !=
'#')
2424 if (strpos($to,
'@'))
2454 if (ilMail::_usePearMail())
2458 if (! is_a($tmp_rcp,
'PEAR_Error'))
2460 foreach ($tmp_rcp as $to)
2462 if(substr($to->mailbox,0,1) !=
'#' && $to->host != self::ILIAS_HOST)
2470 $rcp[] = $to->mailbox.
'@'.$to->host;
2474 return implode(
',',$rcp);
2492 return implode(
',',$rcp ? $rcp : array());
2498 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2500 $message = $inst_name.
" To:".$rcp_to.
"\n";
2504 $message .=
"Cc: ".$rcp_cc;
2508 $message .= $a_m_message;
2515 if (preg_match(
"/@all/",$a_rcp_to))
2519 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2534 $new_name = array();
2539 foreach($tmp_names as $name)
2541 if(strpos($name,
"#") === 0)
2543 $new_name[] = $name;
2551 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2555 $new_name[] = $name;
2559 case "resubstitute":
2560 if(stristr($name,
"�#�"))
2562 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2566 $new_name[] = $name;
2571 return implode(
",",$new_name);
2591 if (ilMail::_usePearMail())
2595 require_once
'./Services/User/classes/class.ilObjUser.php';
2597 $login = $usr_obj->getLogin();
2598 $firstname = $usr_obj->getFirstname();
2599 $lastname = $usr_obj->getLastname();
2609 return $login.
'hhho';
2622 public static function _usePearMail()
2629 return $ilSetting->get(
'pear_mail_enable', 0);
2646 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2651 $lang->loadLanguageModule(
'mail');
2652 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2653 $ilSetting->get(
'inst_name',
'ILIAS 5'),
2663 public static function _getIliasMailerName()
2670 if(strlen($ilSetting->get(
'mail_system_sender_name')))
2672 return $ilSetting->get(
'mail_system_sender_name');
2674 else if(strlen($ilSetting->get(
'short_inst_name')))
2676 return $ilSetting->get(
'short_inst_name');
2692 if(null === $a_flag) {
2711 global $ilClientIniFile;
2713 $signature =
"\n\n* * * * *\n";
2715 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2716 if(strlen($desc = $ilClientIniFile->readVariable(
'client',
'description')))
2718 $signature .= $desc.
"\n";
2724 if(is_array($clientdirs) && count($clientdirs) > 1)
2727 $signature .=
'/login.php?client_id='.CLIENT_ID;
2730 $signature .=
"\n\n";
2742 static $prefix = null;
2744 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2756 $lang = $a_language ? $a_language :
$lng;
2758 $lang->loadLanguageModule(
'mail');
2760 $gender = $gender ? $gender :
'n';
2763 if(!strlen($name[
'firstname']))
2765 return $lang->txt(
'mail_salutation_anonymous').
',';
2768 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2769 ($name[
'title'] ? $name[
'title'].
' ' :
'').
2770 ($name[
'firstname'] ? $name[
'firstname'].
' ' :
'').
2771 $name[
'lastname'].
',';
2776 $this->use_pear = $bool;
2791 if(ilMail::_usePearMail())
2795 if(is_a($tmp_names,
'PEAR_Error'))
2816 if(isset(self::$userInstances[$a_usr_id]))
2818 return self::$userInstances[$a_usr_id];
2821 self::$userInstances[$a_usr_id] =
new ilObjUser($a_usr_id);
2822 return self::$userInstances[$a_usr_id];