128 require_once
"Services/User/classes/class.ilObjUser.php";
239 require_once
"classes/class.ilFileDataMail.php";
240 require_once
"Services/Mail/classes/class.ilMailOptions.php";
241 require_once
"Services/Contact/classes/class.ilMailingLists.php";
245 $lng->loadLanguageModule(
"mail");
249 $this->table_mail =
'mail';
250 $this->table_mail_saved =
'mail_saved';
251 $this->user_id = $a_user_id;
254 if(is_object($ilUser))
269 if(self::_usePearMail())
272 if(is_a($recipients,
'PEAR_Error'))
278 foreach($recipients as $rcp)
280 if (substr($rcp->mailbox, 0, 1) !=
'#')
282 if(trim($rcp->mailbox) == trim($a_recipient) ||
283 trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
288 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
290 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
297 if(trim($rcp->mailbox.
'@'.$rcp->host) == trim($a_recipient))
308 if(count($recipients))
310 foreach($recipients as $recipient)
312 if(trim($recipient) == trim($a_recipient))
332 $this->soap_enabled = $a_status;
338 if(!extension_loaded(
'curl') || !$ilSetting->get(
'soap_user_administration'))
349 $this->save_in_sentbox = $a_save_in_sentbox;
364 $this->mail_send_type = $a_types;
374 $this->mail_rcp_to = $a_rcp_to;
384 $this->mail_rcp_cc = $a_rcp_cc;
394 $this->mail_rcp_bc = $a_rcp_bc;
404 $this->mail_subject = $a_subject;
414 $this->mail_message = $a_message;
426 if (!MAIL_SETTINGS_ID)
428 $res = $ilDB->queryf(
'
429 SELECT object_reference.ref_id FROM object_reference, tree, object_data
430 WHERE tree.parent = %s
431 AND object_data.type = %s
432 AND object_reference.ref_id = tree.child
433 AND object_reference.obj_id = object_data.obj_id',
434 array(
'integer',
'text'),
435 array(SYSTEM_FOLDER_ID,
'mail'));
439 $this->mail_obj_ref_id =
$row[
"ref_id"];
444 $this->mail_obj_ref_id = MAIL_SETTINGS_ID;
455 return $this->lng->txt(
'mail_notification_subject');
462 $tpl =&
new ilTemplate(
'tpl.mail_notifications.html',
true,
true,
'Services/Mail');
464 $tpl->setVariable(
'TXT_RECEIVED_MAILS', sprintf($this->lng->txt(
'mail_received_x_new_mails'), count(
$mail_data)));
469 $tpl->setCurrentBlock(
'mails');
470 $tpl->setVariable(
'NR', $counter + 1);
471 $tpl->setVariable(
'TXT_SENT', $this->lng->txt(
'sent'));
474 $tpl->setVariable(
'TXT_SUBJECT', $this->lng->txt(
'subject'));
475 $tpl->setVariable(
'SUBJECT', $mail[
'm_subject']);
476 $tpl->parseCurrentBlock();
498 $users = trim($users);
501 if(strstr($users,
','))
503 $rcp_to_array = array();
505 $recipients = explode(
',', $users);
506 foreach($recipients as $recipient)
508 $recipient = trim($recipient);
515 $rcp_to_array[] = $tmp_obj->getFullname().
' ['.$recipient.
']';
519 $rcp_to_array[] = $recipient;
525 $rcp_to_array[] = $recipient;
529 return trim(implode(
', ', $rcp_to_array));
538 return $tmp_obj->getFullname().
' ['.$users.
']';
554 return $this->lng->txt(
'not_available');
563 $res = $ilDB->queryf(
"
564 SELECT b.* FROM " . $this->table_mail .
" a
565 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
566 AND b.user_id = a.user_id AND b.send_time > a.send_time
568 AND a.mail_id = %s ORDER BY b.send_time ASC",
569 array(
'integer',
'integer'),
570 array($this->user_id, $a_mail_id));
582 $res = $ilDB->queryf(
"
583 SELECT b.* FROM " . $this->table_mail .
" a
584 INNER JOIN ".$this->table_mail .
" b ON b.folder_id = a.folder_id
585 AND b.user_id = a.user_id AND b.send_time < a.send_time
587 AND a.mail_id = %s ORDER BY b.send_time DESC",
588 array(
'integer',
'integer'),
589 array($this->user_id, $a_mail_id));
606 $this->mail_counter = array();
607 $this->mail_counter[
"read"] = 0;
608 $this->mail_counter[
"unread"] = 0;
610 $res = $ilDB->queryf(
"
611 SELECT ".$this->table_mail.
".* FROM ". $this->table_mail .
"
612 LEFT JOIN object_data ON obj_id = sender_id
615 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))
616 ORDER BY send_time DESC",
617 array(
'integer',
'integer'),
618 array($this->user_id, $a_folder_id));
624 if ($tmp[
"m_status"] ==
'read')
626 ++$this->mail_counter[
"read"];
629 if ($tmp[
"m_status"] ==
'unread')
631 ++$this->mail_counter[
"unread"];
637 $this->mail_counter[
"total"] = count($output);
639 return $output ? $output : array();
652 $res = $ilDB->queryf(
"
653 SELECT COUNT(*) FROM ". $this->table_mail .
"
656 array(
'integer',
'integer'),
657 array($this->user_id, $a_folder_id));
659 return $res->numRows();
700 return is_array($this->mail_counter) ? $this->mail_counter : array(
716 $res = $ilDB->queryf(
"
717 SELECT * FROM ". $this->table_mail .
"
720 array(
'integer',
'integer'),
721 array($this->user_id, $a_mail_id));
740 $data_types = array();
742 $query =
"UPDATE ". $this->table_mail .
"
744 WHERE user_id = %s ";
745 array_push($data_types,
'text',
'integer');
746 array_push(
$data,
'read', $this->user_id);
748 $cnt_mail_ids = count($a_mail_ids);
750 if (is_array($a_mail_ids) &&
751 count($a_mail_ids) > 0)
754 $in =
'mail_id IN (';
756 foreach($a_mail_ids as $a_mail_id)
758 array_push(
$data, $a_mail_id);
759 array_push($data_types,
'integer');
761 if($counter > 0)
$in .=
',';
786 $data_types = array();
788 $query =
"UPDATE ". $this->table_mail .
"
790 WHERE user_id = %s ";
791 array_push($data_types,
'text',
'integer');
792 array_push(
$data,
'unread', $this->user_id);
794 $cnt_mail_ids = count($a_mail_ids);
796 if (is_array($a_mail_ids) &&
797 count($a_mail_ids) > 0)
800 $in =
'mail_id IN (';
802 foreach($a_mail_ids as $a_mail_id)
804 array_push(
$data, $a_mail_id);
805 array_push($data_types,
'integer');
807 if($counter > 0)
$in .=
',';
816 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
833 $data_types = array();
835 $query =
"UPDATE ". $this->table_mail .
"
837 WHERE user_id = %s ";
838 array_push($data_types,
'text',
'integer');
839 array_push(
$data, $a_folder_id, $this->user_id);
841 $cnt_mail_ids = count($a_mail_ids);
843 if (is_array($a_mail_ids) &&
844 count($a_mail_ids) > 0)
847 $in =
'mail_id IN (';
849 foreach($a_mail_ids as $a_mail_id)
851 array_push(
$data, $a_mail_id);
852 array_push($data_types,
'integer');
854 if($counter > 0)
$in .=
',';
863 $statement = $ilDB->manipulateF(
$query, $data_types,
$data);
878 foreach ($a_mail_ids as $id)
880 $statement = $ilDB->manipulateF(
"
881 DELETE FROM ". $this->table_mail .
"
884 array(
'integer',
'integer'),
885 array($this->user_id, $id));
887 $this->mfile->deassignAttachmentFromDirectory($id);
904 "mail_id" => $a_row->mail_id,
905 "user_id" => $a_row->user_id,
906 "folder_id" => $a_row->folder_id,
907 "sender_id" => $a_row->sender_id,
908 "attachments" => unserialize(stripslashes($a_row->attachments)),
909 "send_time" => $a_row->send_time,
910 "rcp_to" => $a_row->rcp_to,
911 "rcp_cc" => $a_row->rcp_cc,
912 "rcp_bcc" => $a_row->rcp_bcc,
913 "m_status" => $a_row->m_status,
914 "m_type" => unserialize(stripslashes($a_row->m_type)),
915 "m_email" => $a_row->m_email,
916 "m_subject" => $a_row->m_subject,
917 "m_message" => $a_row->m_message,
918 "import_name" => $a_row->import_name,
919 "use_placeholders"=> $a_row->use_placeholders);
931 $a_draft_id = 0, $a_use_placeholders = 0)
935 $ilDB->update($this->table_mail,
937 'folder_id' => array(
'integer', $a_folder_id),
938 'attachments' => array(
'clob', serialize($a_attachments)),
939 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
940 'rcp_to' => array(
'clob', $a_rcp_to),
941 'rcp_cc' => array(
'clob', $a_rcp_cc),
942 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
943 'm_status' => array(
'text',
'read'),
944 'm_type' => array(
'text', serialize($a_m_type)),
945 'm_email' => array(
'integer', $a_m_email),
946 'm_subject' => array(
'text', $a_m_subject),
947 'm_message' => array(
'clob', $a_m_message),
948 'use_placeholders' => array(
'integer', $a_use_placeholders)
951 'mail_id' => array(
'integer', $a_draft_id)
986 $a_user_id = 0, $a_use_placeholders = 0)
993 if ($a_use_placeholders)
999 $a_use_placeholders =
'0';
1003 if(!$a_user_id) $a_user_id =
'0';
1004 if(!$a_folder_id) $a_folder_id =
'0';
1005 if(!$a_sender_id) $a_sender_id = NULL;
1006 if(!$a_attachments) $a_attachments = NULL;
1007 if(!$a_rcp_to) $a_rcp_to = NULL;
1008 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1009 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1010 if(!$a_status) $a_status = NULL;
1011 if(!$a_m_type) $a_m_type = NULL;
1012 if(!$a_m_email) $a_m_email = NULL;
1013 if(!$a_m_subject) $a_m_subject = NULL;
1014 if(!$a_m_message) $a_m_message = NULL;
1017 $next_id = $ilDB->nextId($this->table_mail);
1019 $ilDB->insert($this->table_mail, array(
1020 'mail_id' => array(
'integer', $next_id),
1021 'user_id' => array(
'integer', $a_user_id),
1022 'folder_id' => array(
'integer', $a_folder_id),
1023 'sender_id' => array(
'integer', $a_sender_id),
1024 'attachments' => array(
'clob', serialize($a_attachments)),
1025 'send_time' => array(
'timestamp', date(
'Y-m-d H:i:s', time())),
1026 'rcp_to' => array(
'clob', $a_rcp_to),
1027 'rcp_cc' => array(
'clob', $a_rcp_cc),
1028 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1029 'm_status' => array(
'text', $a_status),
1030 'm_type' => array(
'text', serialize($a_m_type)),
1031 'm_email' => array(
'integer', $a_m_email),
1032 'm_subject' => array(
'text', $a_m_subject),
1033 'm_message' => array(
'clob', $a_m_message)
1047 switch (
$user->getGender())
1049 case 'f': $gender_salut = $lng->txt(
'salutation_f');
1051 case 'm': $gender_salut = $lng->txt(
'salutation_m');
1055 $a_message = str_replace(
'[MAIL_SALUTATION]', $gender_salut, $a_message);
1056 $a_message = str_replace(
'[LOGIN]',
$user->getLogin(), $a_message);
1057 $a_message = str_replace(
'[FIRST_NAME]',
$user->getFirstname(), $a_message);
1058 $a_message = str_replace(
'[LAST_NAME]',
$user->getLastname(), $a_message);
1059 $a_message = str_replace(
'[ILIAS_URL]', ILIAS_HTTP_PATH.
'/login.php?client_id='.CLIENT_ID, $a_message);
1060 $a_message = str_replace(
'[CLIENT_NAME]', CLIENT_NAME, $a_message);
1080 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)
1084 include_once
'Services/Mail/classes/class.ilMailbox.php';
1085 include_once
'./Services/User/classes/class.ilObjUser.php';
1097 if (!$a_use_placeholders) # No Placeholders
1099 $rcp_ids = $this->
getUserIds(trim($a_rcp_to).
','.trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1101 $as_email = array();
1103 foreach($rcp_ids as $id)
1110 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1111 $tmp_user->getActive() &&
1112 $tmp_user->checkTimeLimit();
1115 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1122 if (!$user_can_read_internal_mails ||
1123 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1129 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1134 $mbox->setUserId($id);
1135 $inbox_id = $mbox->getInboxFolder();
1138 $a_attachments, $a_rcp_to,
1139 $a_rcp_cc,
'',
'unread', $a_type,
1140 0, $a_subject, $a_message, $id, 0);
1143 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1151 if (count($as_email) == 1)
1157 foreach ($as_email as $id)
1163 if(count($to) > 0 || count($bcc) > 0)
1165 $this->
sendMimeMail(implode(
',', $to),
'', implode(
',', $bcc), $a_subject, $a_message, $a_attachments);
1168 else # Use Placeholders
1171 $rcp_ids_replace = $this->
getUserIds(trim($a_rcp_to));
1174 $rcp_ids_no_replace = $this->
getUserIds(trim($a_rcp_cc).
','.trim($a_rcp_bcc));
1176 $as_email = array();
1179 foreach($rcp_ids_replace as $id)
1186 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement() &&
1187 $tmp_user->getActive() &&
1188 $tmp_user->checkTimeLimit();
1191 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1198 if (!$user_can_read_internal_mails ||
1199 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1205 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1210 $mbox->setUserId($id);
1211 $inbox_id = $mbox->getInboxFolder();
1214 $a_attachments, $a_rcp_to,
1215 $a_rcp_cc,
'',
'unread', $a_type,
1216 0, $a_subject, $a_message, $id, 1);
1219 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1223 if (count($as_email))
1225 foreach ($as_email as $id)
1231 $as_email = array();
1234 foreach($rcp_ids_no_replace as $id)
1241 $user_can_read_internal_mails = $tmp_user->hasAcceptedUserAgreement()
1242 && $tmp_user->getActive() && $tmp_user->checkTimeLimit();
1245 if (in_array(
'system', $a_type) && !$user_can_read_internal_mails)
1252 if (!$user_can_read_internal_mails ||
1253 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1259 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1264 $mbox->setUserId($id);
1265 $inbox_id = $mbox->getInboxFolder();
1268 $a_attachments, $a_rcp_to,
1269 $a_rcp_cc,
'',
'unread', $a_type,
1270 0, $a_subject, $a_message, $id, 0);
1273 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1277 if (count($as_email))
1279 foreach ($as_email as $id)
1296 global
$log, $rbacreview;
1302 if (! is_a($tmp_names,
'PEAR_Error'))
1304 for ($i = 0;$i < count($tmp_names); $i++)
1306 if ( substr($tmp_names[$i]->mailbox,0,1) ===
'#' ||
1307 (substr($tmp_names[$i]->mailbox,0,1) ===
'"' &&
1308 substr($tmp_names[$i]->mailbox,1,1) ===
'#' ) )
1310 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.
'@'.$tmp_names[$i]->host);
1311 foreach($role_ids as $role_id)
1313 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1319 else if (strtolower($tmp_names[$i]->host) ==
'ilias')
1353 for ($i = 0;$i < count($tmp_names); $i++)
1355 if (substr($tmp_names[$i],0,1) ==
'#')
1359 include_once(
"./classes/class.ilObjectFactory.php");
1360 include_once(
'./Modules/Group/classes/class.ilObjGroup.php');
1368 foreach ($grp_object->getGroupMemberIds() as $id)
1374 elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1376 foreach($rbacreview->assignedUsers($role_id) as
$usr_id)
1383 else if (!empty($tmp_names[$i]))
1392 return array_unique($ids);
1405 function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1407 $error_message =
'';
1409 $a_m_subject = trim($a_m_subject);
1410 $a_rcp_to = trim($a_rcp_to);
1412 if (empty($a_m_subject))
1414 $error_message .= $error_message ?
"<br>" :
'';
1415 $error_message .= $this->lng->txt(
"mail_add_subject");
1418 if (empty($a_rcp_to))
1420 $error_message .= $error_message ?
"<br>" :
'';
1421 $error_message .= $this->lng->txt(
"mail_add_recipient");
1424 return $error_message;
1435 $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;
1538 if (is_a($tmp_rcp,
'PEAR_Error'))
1540 $colon_pos = strpos($tmp_rcp->message,
':');
1541 $wrong_rcps =
'<br />'.(($colon_pos ===
false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1545 foreach ($tmp_rcp as $rcp)
1548 if (substr($rcp->mailbox,0,1) !=
'#')
1552 if (
$user_id ==
false && $rcp->host ==
'ilias')
1554 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox);
1561 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1563 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1564 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1569 else if (substr($rcp->mailbox, 0, 7) ==
'#il_ml_')
1571 if (!$this->mlists->mailingListExists($rcp->mailbox))
1573 $wrong_rcps .=
"<br />".htmlentities($rcp->mailbox).
1574 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1581 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.
'@'.$rcp->host);
1582 if (count($role_ids) == 0)
1584 $wrong_rcps .=
'<br />'.htmlentities($rcp->mailbox).
1585 ' ('.$this->lng->txt(
'mail_no_recipient_found').
')';
1588 else if (count($role_ids) > 1)
1590 $wrong_rcps .=
'<br/>'.htmlentities($rcp->mailbox).
1591 ' ('.sprintf($this->lng->txt(
'mail_multiple_recipients_found'), implode(
',', $role_ids)).
')';
1601 foreach ($tmp_rcp as $rcp)
1608 if (substr($rcp,0,1) !=
'#')
1614 $wrong_rcps .=
"<br />".htmlentities($rcp);
1621 if(!$rbacsystem->checkAccessOfUser(
$user_id,
"mail_visible", $this->getMailObjectReferenceId()))
1623 $wrong_rcps .=
"<br />".htmlentities($rcp).
1624 " (".$this->lng->txt(
"user_cant_receive_mail").
")";
1629 else if (substr($rcp, 0, 7) ==
'#il_ml_')
1631 if (!$this->mlists->mailingListExists($rcp))
1633 $wrong_rcps .=
"<br />".htmlentities($rcp).
1634 " (".$this->lng->txt(
"mail_no_valid_mailing_list").
")";
1643 else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1645 $wrong_rcps .=
"<br />".htmlentities($rcp).
1646 " (".$this->lng->txt(
"mail_no_valid_group_role").
")";
1678 $a_use_placeholders)
1683 if(!$a_attachments) $a_attachments = NULL;
1684 if(!$a_rcp_to) $a_rcp_to = NULL;
1685 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1686 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1687 if(!$a_m_type) $a_m_type = NULL;
1688 if(!$a_m_email) $a_m_email = NULL;
1689 if(!$a_m_message) $a_m_message = NULL;
1690 if(!$a_use_placeholders) $a_use_placeholders =
'0';
1693 $statement = $ilDB->manipulateF(
'
1694 DELETE FROM '. $this->table_mail_saved .
'
1695 WHERE user_id = %s',
1696 array(
'integer'), array($this->user_id));
1698 $ilDB->insert($this->table_mail_saved, array(
1699 'user_id' => array(
'integer', $a_user_id),
1700 'attachments' => array(
'clob', serialize($a_attachments)),
1701 'rcp_to' => array(
'clob', $a_rcp_to),
1702 'rcp_cc' => array(
'clob', $a_rcp_cc),
1703 'rcp_bcc' => array(
'clob', $a_rcp_bcc),
1704 'm_type' => array(
'text', serialize($a_m_type)),
1705 'm_email' => array(
'integer', $a_m_email),
1706 'm_subject' => array(
'text', $a_m_subject),
1707 'm_message' => array(
'clob', $a_m_message),
1708 'use_placeholders' => array(
'integer', $a_use_placeholders),
1725 $res = $ilDB->queryf(
'
1726 SELECT * FROM '. $this->table_mail_saved .
'
1727 WHERE user_id = %s',
1729 array($this->user_id));
1749 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)
1753 $error_message =
'';
1756 if (in_array(
"system",$a_type))
1759 $a_type = array(
'system');
1764 if (!$this->mfile->checkFilesExist($a_attachment))
1766 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1770 if ($error_message = $this->
checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1772 return $error_message;
1777 $message .= $error_message;
1782 $message .= $error_message;
1787 $message .= $error_message;
1790 if (!empty($message))
1792 return $this->lng->txt(
"mail_following_rcp_not_valid").$message;
1796 if (in_array(
'system',$a_type))
1798 if (!empty($a_attachment))
1800 return $lng->txt(
"mail_no_attach_allowed");
1834 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1835 !$rbacsystem->checkAccess(
'smtp_mail', $this->mail_obj_ref_id))
1837 return $this->lng->txt(
'mail_no_permissions_write_smtp');
1846 $sent_id = $this->
saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1847 $a_m_subject,$a_m_message);
1851 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1853 if (
$error = $this->mfile->saveFiles($sent_id,$a_attachment))
1872 if (in_array(
'system',$a_type))
1874 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))
1876 return $lng->txt(
"mail_send_error");
1880 if (in_array(
'normal',$a_type))
1883 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))
1885 return $lng->txt(
"mail_send_error");
1900 if ($rcpt ==
'')
return $rcpt;
1903 if (!is_array($arrRcpt) || empty($arrRcpt))
return $rcpt;
1905 $new_rcpt = array();
1907 foreach ($arrRcpt as $item)
1911 if (substr($item->mailbox, 0, 7) ==
'#il_ml_')
1913 if ($this->mlists->mailingListExists($item->mailbox))
1915 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1917 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1923 $new_rcpt[] = $item->mailbox.
'@'.$item->host;
1928 if (substr($item, 0, 7) ==
'#il_ml_')
1930 if ($this->mlists->mailingListExists($item))
1932 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1934 $new_rcpt[] = ($entry[
'login'] !=
'' ? $entry[
'login'] : $entry[
'email']);
1940 $new_rcpt[] = $item;
1945 return implode(
',', $new_rcpt);
1961 $a_m_subject,$a_m_message)
1963 include_once
"Services/Mail/classes/class.ilMailbox.php";
1966 $sent_id = $mbox->getSentFolder();
1968 return $this->
sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
1969 $a_rcp_bcc,
'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
1981 include_once
'Services/Mail/classes/class.ilMimeMail.php';
1996 include_once
"Services/Mail/classes/class.ilMimeMail.php";
1998 if($this->user_id != ANONYMOUS_USER_ID)
2004 $no_reply_adress = trim($this->ilias->getSetting(
'mail_external_sender_noreply'));
2005 if(strlen($no_reply_adress))
2007 if(strpos($no_reply_adress,
'@') ===
false)
2008 $no_reply_adress =
'noreply@'.$no_reply_adress;
2011 $no_reply_adress =
'noreply@'.$_SERVER[
'SERVER_NAME'];
2015 ' <'.$no_reply_adress.
'>';
2020 ' <noreply@'.$_SERVER[
'SERVER_NAME'].
'>';
2039 function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments)
2041 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2043 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2045 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2046 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2055 include_once
'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2057 $soap_client =
new ilSoapClient();
2058 $soap_client->setTimeout(1);
2059 $soap_client->setResponseTimeout(1);
2060 $soap_client->enableWSDL(
true);
2061 $soap_client->init();
2063 $attachments = array();
2064 $a_attachments = $a_attachments ? $a_attachments : array();
2065 foreach($a_attachments as $attachment)
2067 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2070 $attachments = implode(
'#:#',$attachments);
2072 if(strlen($attachments))
2073 $attachments =
"#:#".$attachments;
2075 $soap_client->call(
'sendMail',array(
$_COOKIE[
'PHPSESSID'].
'::'.
$_COOKIE[
'ilClientId'],
2089 include_once
"Services/Mail/classes/class.ilMimeMail.php";
2092 $mmail->autoCheck(
false);
2093 $mmail->From($sender);
2094 $mmail->To($a_rcp_to);
2096 $mmail->Subject($a_m_subject);
2097 $mmail->Body($a_m_message);
2101 $mmail->Cc($a_rcp_cc);
2106 $mmail->Bcc($a_rcp_bcc);
2109 if (is_array($a_attachments))
2111 foreach ($a_attachments as $attachment)
2113 $mmail->Attach($this->mfile->getAbsolutePath($attachment));
2128 $sender = $umail->getEmail();
2150 $ilDB->update($this->table_mail_saved,
2153 'attachments' => array(
'clob', serialize($a_attachments))
2157 'user_id' => array(
'integer', $this->user_id)
2171 return $this->mail_data[
"attachments"] ? $this->mail_data[
"attachments"] : array();
2191 if (strlen(trim($a_recipients)) > 0)
2193 require_once
'Mail/RFC822.php';
2194 $parser = &
new Mail_RFC822();
2195 return $parser->parseAddressList($a_recipients,
"ilias",
false,
true);
2202 $a_recipients = trim($a_recipients);
2205 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2206 $a_recipients = preg_replace(
"/;/",
",",$a_recipients);
2209 foreach(explode(
',',$a_recipients) as $tmp_rec)
2213 $rcps[] = trim($tmp_rec);
2216 return is_array($rcps) ? $rcps : array();
2227 if (! is_a($tmp_rcp,
'PEAR_Error'))
2229 foreach ($tmp_rcp as $to)
2242 if ($to->host !=
'ilias' && substr($to->mailbox,0,1) !=
'#')
2261 if (strpos($to,
'@'))
2295 if (! is_a($tmp_rcp,
'PEAR_Error'))
2297 foreach ($tmp_rcp as $to)
2299 if(substr($to->mailbox,0,1) !=
'#' && $to->host !=
'ilias')
2307 $rcp[] = $to->mailbox.
'@'.$to->host;
2311 return implode(
',',$rcp);
2329 return implode(
',',$rcp ? $rcp : array());
2335 $inst_name = $this->ilias->getSetting(
"inst_name") ? $this->ilias->getSetting(
"inst_name") :
"ILIAS 3";
2337 $message = $inst_name.
" To:".$rcp_to.
"\n";
2341 $message .=
"Cc: ".$rcp_cc;
2345 $message .= $a_m_message;
2352 if (preg_match(
"/@all/",$a_rcp_to))
2356 $a_rcp_to = preg_replace(
"/@all/",implode(
',',$all),$a_rcp_to);
2371 $new_name = array();
2376 foreach($tmp_names as
$name)
2378 if(strpos($name,
"#") === 0)
2380 $new_name[] =
$name;
2388 $new_name[] = preg_replace(
"/@/",
"�#�",$name);
2392 $new_name[] =
$name;
2396 case "resubstitute":
2397 if(stristr($name,
"�#�"))
2399 $new_name[] = preg_replace(
"/�#�/",
"@",$name);
2403 $new_name[] =
$name;
2408 return implode(
",",$new_name);
2431 require_once
'./Services/User/classes/class.ilObjUser.php';
2434 $login = $usr_obj->getLogin();
2435 $firstname = $usr_obj->getFirstname();
2436 $lastname = $usr_obj->getLastname();
2463 if ($ilias->getSetting(
'pear_mail_enable') ==
true)
2468 $is_pear_mail_installed = @include_once
'Mail/RFC822.php';
2469 if ($is_pear_mail_installed) {
2475 $log->write(
"WARNING: ilMail::_userPearMail disabled Pear Mail support, because include 'Mail/RFC822.php' failed.");
2476 $ilias->setSetting(
'pear_mail_enable',
false);
2496 include_once(
'./Services/Language/classes/class.ilLanguageFactory.php');
2499 $lang->loadLanguageModule(
'mail');
2500 return sprintf(
$lang->txt(
'mail_auto_generated_info'),
2501 $ilSetting->get(
'inst_name',
'ILIAS 4'),
2502 ILIAS_HTTP_PATH.
"\n\n");
2528 if(null === $a_flag) {
2547 global $ilClientIniFile;
2549 $signature =
"\n\n* * * * *\n";
2550 $signature .= $ilClientIniFile->readVariable(
'client',
'name').
"\n";
2551 if(strlen(
$desc = $ilClientIniFile->readVariable(
'client',
'description')))
2553 $signature .=
$desc.
"\n";
2555 $signature .= ILIAS_HTTP_PATH;
2558 if(is_array($clientdirs) && count($clientdirs) > 1)
2560 $signature .=
'/?client_id='.CLIENT_ID;
2573 static $prefix = null;
2575 return $prefix == null ? $ilSetting->get(
'mail_subject_prefix',
'') : $prefix;
2587 $lang = $a_language ? $a_language :
$lng;
2590 $gender = $gender ? $gender :
'n';
2593 if(!strlen(
$name[
'firstname']))
2595 return $lang->txt(
'mail_salutation_anonymous').
',';
2598 return $lang->txt(
'mail_salutation_'.$gender).
' '.
2600 (
$name[
'firstname'] ?
$name[
'firstname'].
' ' :
'').
2601 $name[
'lastname'].
',';