128 require_once
"Services/User/classes/class.ilObjUser.php";
242 require_once
"classes/class.ilFileDataMail.php";
243 require_once
"Services/Mail/classes/class.ilMailOptions.php";
244 require_once
"Services/Contact/classes/class.ilMailingLists.php";
248 $lng->loadLanguageModule(
"mail");
253 $this->table_mail =
'mail';
254 $this->table_mail_saved =
'mail_saved';
255 $this->user_id = $a_user_id;
258 if(is_object($ilUser))
273 if(self::_usePearMail())
276 if(is_a($recipients,
'PEAR_Error'))
282 foreach($recipients as $rcp)
284 if (substr($rcp->mailbox, 0, 1) !=
'#')
286 if(trim($rcp->mailbox) == trim($a_recipient) ||
287 trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
292 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
294 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
301 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
312 if(count($recipients))
314 foreach($recipients as $recipient)
316 if(trim($recipient) == trim($a_recipient))
336 $this->soap_enabled = $a_status;
342 if(!extension_loaded(
'curl') || !$ilSetting->get(
'soap_user_administration'))
353 $this->save_in_sentbox = $a_save_in_sentbox;
368 $this->mail_send_type = $a_types;
378 $this->mail_rcp_to = $a_rcp_to;
388 $this->mail_rcp_cc = $a_rcp_cc;
398 $this->mail_rcp_bc = $a_rcp_bc;
408 $this->mail_subject = $a_subject;
418 $this->mail_message = $a_message;
430 if (!MAIL_SETTINGS_ID)
432 $res = $ilDB->queryf(
'
433 SELECT object_reference.ref_id FROM object_reference, tree, object_data
434 WHERE tree.parent = %s
435 AND object_data.type = %s
436 AND object_reference.ref_id = tree.child
437 AND object_reference.obj_id = object_data.obj_id',
438 array(
'integer',
'text'),
439 array(SYSTEM_FOLDER_ID,
'mail'));
443 $this->mail_obj_ref_id =
$row[
"ref_id"];
448 $this->mail_obj_ref_id = MAIL_SETTINGS_ID;
469 $users = trim($users);
472 if(strstr($users,
','))
474 $rcp_to_array = array();
476 $recipients = explode(
',', $users);
477 foreach($recipients as $recipient)
479 $recipient = trim($recipient);
486 $rcp_to_array[] = $tmp_obj->getFullname().
' ['.$recipient.
']';
490 $rcp_to_array[] = $recipient;
496 $rcp_to_array[] = $recipient;
500 return trim(implode(
', ', $rcp_to_array));
509 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 .=
',';
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);
1063 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)
1067 include_once
'Services/Mail/classes/class.ilMailbox.php';
1068 include_once
'./Services/User/classes/class.ilObjUser.php';
1080 if (!$a_use_placeholders) # No Placeholders
1082 $rcp_ids = $this->
getUserIds(trim($a_rcp_to).
','.trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1084 $as_email = array();
1086 foreach($rcp_ids as $id)
1093 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1094 $tmp_user->getActive() &&
1095 $tmp_user->checkTimeLimit();
1098 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)
1112 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
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)
1140 foreach ($as_email as $id)
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)
1169 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1170 $tmp_user->getActive() &&
1171 $tmp_user->checkTimeLimit();
1174 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1181 if (!$user_can_read_internal_mails ||
1182 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1188 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1193 $mbox->setUserId($id);
1194 $inbox_id = $mbox->getInboxFolder();
1197 $a_attachments, $a_rcp_to,
1198 $a_rcp_cc,
'',
'unread', $a_type,
1199 0, $a_subject, $a_message, $id, 1);
1202 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1206 if (count($as_email))
1208 foreach ($as_email as $id)
1214 $as_email = array();
1217 foreach($rcp_ids_no_replace as $id)
1224 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement()
1225 && $tmp_user->getActive() && $tmp_user->checkTimeLimit();
1228 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1235 if (!$user_can_read_internal_mails ||
1236 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1242 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1247 $mbox->setUserId($id);
1248 $inbox_id = $mbox->getInboxFolder();
1251 $a_attachments, $a_rcp_to,
1252 $a_rcp_cc,
'',
'unread', $a_type,
1253 0, $a_subject, $a_message, $id, 0);
1256 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1260 if (count($as_email))
1262 foreach ($as_email as $id)
1279 global
$log, $rbacreview;
1286 if (! is_a($tmp_names,
'PEAR_Error'))
1288 for ($i = 0;$i < count($tmp_names); $i++)
1290 if ( substr($tmp_names[$i]->mailbox,0,1) ===
'#' ||
1291 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1292 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
1294 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1295 foreach($role_ids as $role_id)
1297 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1303 else if (strtolower($tmp_names[$i]->host) ==
'ilias')
1337 for ($i = 0;$i < count($tmp_names); $i++)
1339 if (substr($tmp_names[$i],0,1) ==
'#')
1343 include_once(
"./classes/class.ilObjectFactory.php");
1344 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1352 foreach ($grp_object->getGroupMemberIds() as $id)
1358 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1360 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1367 else if (!empty($tmp_names[$i]))
1376 return array_unique($ids);
1389 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1391 $error_message =
'';
1393 $a_m_subject = trim($a_m_subject);
1394 $a_rcp_to = trim($a_rcp_to);
1396 if (empty($a_m_subject))
1398 $error_message .= $error_message ?
"<br>" :
'';
1399 $error_message .= $this->lng->txt(
"mail_add_subject");
1402 if (empty($a_rcp_to))
1404 $error_message .= $error_message ?
"<br>" :
'';
1405 $error_message .= $this->lng->txt(
"mail_add_recipient");
1408 return $error_message;
1419 $addresses = array();
1425 if (! is_a($tmp_rcp,
'PEAR_Error'))
1427 foreach ($tmp_rcp as $rcp)
1430 if (substr($rcp->mailbox,0,1) !=
'#')
1432 if (strtolower($rcp->host) !=
'ilias')
1434 $addresses[] = $rcp->mailbox.
'@'.$rcp->host;
1441 $addresses[] = $tmp_user->getEmail();
1448 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1449 foreach($role_ids as $role_id)
1451 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1454 $addresses[] = $tmp_user->getEmail();
1465 foreach ($tmp_rcp as $rcp)
1468 if (substr($rcp,0,1) !=
'#')
1470 if (strpos($rcp,
'@'))
1472 $addresses[] = $rcp;
1479 $addresses[] = $tmp_user->getEmail();
1486 include_once(
"./classes/class.ilObjectFactory.php");
1487 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1496 foreach ($grp_object->getGroupMemberIds() as $id)
1499 $addresses[] = $tmp_user->getEmail();
1517 global $rbacsystem,$rbacreview;
1525 if (is_a($tmp_rcp,
'PEAR_Error'))
1527 $colon_pos = strpos($tmp_rcp->message,
':');
1528 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1532 foreach ($tmp_rcp as $rcp)
1535 if (substr($rcp->mailbox,0,1) !=
'#')
1539 if (
$user_id ==
false && $rcp->host ==
'ilias')
1541 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1548 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1550 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1551 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1556 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1558 if (!$this->mlists->mailingListExists($rcp->mailbox))
1560 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1561 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1569 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1571 if(!$this->mail_to_global_roles && is_array($role_ids))
1573 foreach($role_ids as $role_id)
1575 if($rbacreview->isGlobalRole($role_id))
1577 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1583 if (count($role_ids) == 0)
1585 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1586 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1589 else if (count($role_ids) > 1)
1591 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1592 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1602 foreach ($tmp_rcp as $rcp)
1609 if (substr($rcp,0,1) !=
'#')
1615 $wrong_rcps .=
"<br />".htmlentities($rcp);
1622 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1624 $wrong_rcps .=
"<br />".htmlentities($rcp).
1625 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1630 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1632 if (!$this->mlists->mailingListExists($rcp))
1634 $wrong_rcps .=
"<br />".htmlentities($rcp).
1635 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1644 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1646 $wrong_rcps .=
"<br />".htmlentities($rcp).
1647 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1650 else if (!$this->mail_to_global_roles)
1652 $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1653 if((
int)$role_id && $rbacreview->isGlobalRole($role_id))
1655 include_once(
'Services/Mail/exceptions/class.ilMailException.php');
1688 $a_use_placeholders)
1693 if(!$a_attachments) $a_attachments = NULL;
1694 if(!$a_rcp_to) $a_rcp_to = NULL;
1695 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1696 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1697 if(!$a_m_type) $a_m_type = NULL;
1698 if(!$a_m_email) $a_m_email = NULL;
1699 if(!$a_m_message) $a_m_message = NULL;
1700 if(!$a_use_placeholders) $a_use_placeholders =
'0';
1703 $statement = $ilDB->manipulateF(
'
1704 DELETE FROM '. $this->table_mail_saved .
'
1705 WHERE user_id = %s',
1706 array(
'integer'), array($this->user_id));
1708 $ilDB->insert($this->table_mail_saved, array(
1709 'user_id' => array(
'integer', $a_user_id),
1710 'attachments' => array(
'clob', serialize($a_attachments)),
1711 'rcp_to' => array(
'clob', $a_rcp_to),
1712 'rcp_cc' => array(
'clob', $a_rcp_cc),
1713 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1714 'm_type' => array(
'text', serialize($a_m_type)),
1715 'm_email' => array(
'integer', $a_m_email),
1716 'm_subject' => array(
'text', $a_m_subject),
1717 'm_message' => array(
'clob', $a_m_message),
1718 'use_placeholders' => array(
'integer', $a_use_placeholders),
1735 $res = $ilDB->queryf(
'
1736 SELECT * FROM '. $this->table_mail_saved .
'
1737 WHERE user_id = %s',
1739 array($this->user_id));
1759 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)
1764 $this->mail_to_global_roles = $rbacsystem->checkAccess(
'mail_to_global_roles', $this->mail_obj_ref_id);
1766 $error_message =
'';
1769 if (in_array(
"system",$a_type))
1772 $a_type = array(
'system');
1777 if (!$this->mfile->checkFilesExist($a_attachment))
1779 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1783 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1785 return $error_message;
1793 $message .= $error_message;
1798 $message .= $error_message;
1803 $message .= $error_message;
1809 return $this->lng->txt($e->getMessage());
1813 if (!empty($message))
1815 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1819 if (in_array(
'system',$a_type))
1821 if (!empty($a_attachment))
1823 return $lng->txt(
"mail_no_attach_allowed");
1857 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1858 !$rbacsystem->checkAccess(
'smtp_mail', $this->mail_obj_ref_id))
1860 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1869 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1870 $a_m_subject,$a_m_message);
1874 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1876 if (
$error = $this->mfile->saveFiles($sent_id,$a_attachment))
1895 if (in_array(
'system',$a_type))
1897 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))
1899 return $lng->txt(
"mail_send_error");
1903 if (in_array(
'normal',$a_type))
1906 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))
1908 return $lng->txt(
"mail_send_error");
1923 if ($rcpt ==
'')
return $rcpt;
1926 if (!is_array($arrRcpt) || empty($arrRcpt))
return $rcpt;
1928 $new_rcpt = array();
1930 foreach ($arrRcpt as $item)
1934 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1936 if ($this->mlists->mailingListExists($item->mailbox))
1938 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1940 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1946 $new_rcpt[] = $item->mailbox.
'@'.$item->host;
1951 if (substr($item, 0, 7) ==
'#il_ml_')
1953 if ($this->mlists->mailingListExists($item))
1955 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1957 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1963 $new_rcpt[] = $item;
1968 return implode(
',', $new_rcpt);
1984 $a_m_subject,$a_m_message)
1986 include_once
"Services/Mail/classes/class.ilMailbox.php";
1989 $sent_id = $mbox->getSentFolder();
1991 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
1992 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2004 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2019 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2021 if($this->user_id != ANONYMOUS_USER_ID)
2046 include_once
'Services/Mail/classes/class.ilMimeMail.php';
2048 $no_reply_adress = trim($ilSetting->get(
'mail_external_sender_noreply'));
2049 if(strlen($no_reply_adress))
2051 if(strpos($no_reply_adress,
'@') ===
false)
2052 $no_reply_adress =
'noreply@'.$no_reply_adress;
2056 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2060 ' <'.$no_reply_adress.
'>';
2065 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2083 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments)
2085 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2087 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2089 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2090 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2099 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2102 $soap_client->setTimeout(1);
2103 $soap_client->setResponseTimeout(1);
2104 $soap_client->enableWSDL(
true);
2105 $soap_client->init();
2107 $attachments = array();
2108 $a_attachments = $a_attachments ? $a_attachments : array();
2109 foreach($a_attachments as $attachment)
2111 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2114 $attachments = implode(
'#:#',$attachments);
2116 if(strlen($attachments))
2117 $attachments =
"#:#".$attachments;
2119 $soap_client->call(
'sendMail',array(
$_COOKIE[
'PHPSESSID'].
'::'.
$_COOKIE[
'ilClientId'],
2133 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2136 $mmail->autoCheck(
false);
2137 $mmail->From($sender);
2138 $mmail->To($a_rcp_to);
2140 $mmail->Subject($a_m_subject);
2141 $mmail->Body($a_m_message);
2145 $mmail->Cc($a_rcp_cc);
2150 $mmail->Bcc($a_rcp_bcc);
2153 if (is_array($a_attachments))
2155 foreach ($a_attachments as $attachment)
2157 $mmail->Attach($this->mfile->getAbsolutePath($attachment));
2172 $sender = $umail->getEmail();
2194 $ilDB->update($this->table_mail_saved,
2197 'attachments' => array(
'clob', serialize($a_attachments))
2201 'user_id' => array(
'integer', $this->user_id)
2215 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2235 if (strlen(trim($a_recipients)) > 0)
2237 require_once
'Mail/RFC822.php';
2239 return $parser->parseAddressList($a_recipients,
"ilias",
false,
true);
2246 $a_recipients = trim($a_recipients);
2249 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2250 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2253 foreach(explode(
',',$a_recipients) as $tmp_rec)
2257 $rcps[] = trim($tmp_rec);
2260 return is_array($rcps) ? $rcps : array();
2272 if (! is_a($tmp_rcp,
'PEAR_Error'))
2274 foreach ($tmp_rcp as $to)
2287 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#')
2306 if (strpos($to,
'@'))
2340 if (! is_a($tmp_rcp,
'PEAR_Error'))
2342 foreach ($tmp_rcp as $to)
2344 if(substr($to->mailbox,0,1) !=
'#' && $to->host !=
'ilias')
2352 $rcp[] = $to->mailbox.
'@'.$to->host;
2356 return implode(
',',$rcp);
2374 return implode(
',',$rcp ? $rcp : array());
2380 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2382 $message = $inst_name.
" To:".$rcp_to.
"\n";
2386 $message .=
"Cc: ".$rcp_cc;
2390 $message .= $a_m_message;
2397 if (preg_match(
"/@all/",$a_rcp_to))
2401 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2416 $new_name = array();
2421 foreach($tmp_names as
$name)
2423 if(strpos($name,
"#") === 0)
2425 $new_name[] =
$name;
2433 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2437 $new_name[] =
$name;
2441 case "resubstitute":
2442 if(stristr($name,
"�#�"))
2444 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2448 $new_name[] =
$name;
2453 return implode(
",",$new_name);
2477 require_once
'./Services/User/classes/class.ilObjUser.php';
2480 $login = $usr_obj->getLogin();
2481 $firstname = $usr_obj->getFirstname();
2482 $lastname = $usr_obj->getLastname();
2492 return $login.
'hhho';
2510 if ($ilias->getSetting(
'pear_mail_enable') ==
true)
2515 $is_pear_mail_installed = @include_once
'Mail/RFC822.php';
2516 if ($is_pear_mail_installed) {
2522 $log->write(
"WARNING: ilMail::_userPearMail disabled Pear Mail support, because include 'Mail/RFC822.php' failed.");
2523 $ilias->setSetting(
'pear_mail_enable',
false);
2543 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2548 $lang->loadLanguageModule(
'mail');
2549 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2550 $ilSetting->get(
'inst_name',
'ILIAS 4'),
2577 if(null === $a_flag) {
2596 global $ilClientIniFile;
2598 $signature =
"\n\n* * * * *\n";
2599 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2600 if(strlen(
$desc = $ilClientIniFile->readVariable(
'client',
'description')))
2602 $signature .=
$desc.
"\n";
2608 if(is_array($clientdirs) && count($clientdirs) > 1)
2610 $signature .=
'/?client_id='.CLIENT_ID;
2623 static $prefix = null;
2625 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2637 $lang = $a_language ? $a_language :
$lng;
2640 $gender = $gender ? $gender :
'n';
2643 if(!strlen(
$name[
'firstname']))
2645 return $lang->txt(
'mail_salutation_anonymous').
',';
2648 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2650 (
$name[
'firstname'] ?
$name[
'firstname'].
' ' :
'').
2651 $name[
'lastname'].
',';
2656 $this->use_pear = $bool;
2674 if(is_a($tmp_names,
'PEAR_Error'))