65 $this->tpl = $DIC->ui()->mainTemplate();
66 $this->ctrl = $DIC->ctrl();
67 $this->lng = $DIC->language();
68 $this->
user = $DIC->user();
69 $this->tabs = $DIC->tabs();
70 $this->toolbar = $DIC->toolbar();
71 $this->rbacsystem = $DIC->rbac()->system();
77 if (null === $bodyPurifier) {
80 $this->purifier = $bodyPurifier;
82 if (isset(
$_POST[
'mobj_id']) && (
int)
$_POST[
'mobj_id']) {
83 $_GET[
'mobj_id'] = $_POST[
'mobj_id'];
86 if (!(
int)
$_GET[
'mobj_id']) {
87 $_GET[
'mobj_id'] = $this->mbox->getInboxFolder();
89 $_GET[
'mobj_id'] = (int) $_GET[
'mobj_id'];
91 $this->ctrl->saveParameter($this,
'mobj_id');
96 $forward_class = $this->ctrl->getNextClass($this);
97 switch ($forward_class) {
98 case 'ilmailfoldergui':
102 case 'ilmailattachmentgui':
103 $this->ctrl->setReturn($this,
"returnFromAttachments");
107 case 'ilmailsearchgui':
108 $this->ctrl->setReturn($this,
"searchResults");
112 case 'ilmailsearchcoursesgui':
113 $this->ctrl->setReturn($this,
"searchResults");
117 case 'ilmailinglistsgui':
118 $this->ctrl->setReturn($this,
'searchResults');
122 case 'ilmailsearchgroupsgui':
123 $this->ctrl->setReturn($this,
"searchResults");
128 if (!($cmd = $this->ctrl->getCmd())) {
143 $decodedFiles = array();
145 foreach ($files as $value) {
146 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' . urldecode($value))) {
147 $decodedFiles[] = urldecode($value);
151 return $decodedFiles;
160 $sanitizedMessage = $mailBody->getContent();
164 $mailer = $this->umail
168 $mailer->setSaveInSentbox(
true);
170 if (
$errors = $mailer->enqueue(
177 (
int)
$_POST[
'use_placeholders']
180 $_POST[
'attachments'] = $files;
183 $mailer->savePostData($this->
user->getId(), array(),
"",
"",
"",
"",
"",
"",
"",
"");
185 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
188 ilUtil::sendSuccess($this->lng->txt(
'mail_message_send'),
true);
191 $this->ctrl->redirectByClass(
'ilmailgui');
200 if (!
$_POST[
'm_subject']) {
201 $_POST[
'm_subject'] = $this->lng->txt(
'mail_no_subject');
204 $draftFolderId = $this->mbox->getDraftsFolder();
207 if (
$errors = $this->umail->validateRecipients(
212 $_POST[
'attachments'] = $files;
222 $draftId = $this->umail->getNewDraftId($this->
user->getId(), $draftFolderId);
225 $this->umail->updateDraft(
235 (
int)
$_POST[
'use_placeholders'],
245 $this->ctrl->redirectByClass([
'ilmailgui',
'ilmailfoldergui']);
253 $this->tpl->setTitle($this->lng->txt(
"mail"));
257 if (isset(
$_POST[
'attachments']) && is_array(
$_POST[
'attachments'])) {
258 foreach (
$_POST[
'attachments'] as $value) {
259 $files[] = urldecode($value);
264 $this->umail->savePostData(
265 $this->
user->getId(),
273 (bool) (
$_POST[
'use_placeholders'] ??
false),
280 $form->setId(
'search_rcp');
281 $form->setTitle($this->lng->txt(
'search_recipients'));
282 $form->setFormAction($this->ctrl->getFormAction($this,
'search'));
284 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
286 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
287 $inp->setDataSource($dsDataLink);
289 $searchQuery = trim((
string)
ilSession::get(
'mail_search_search'));
290 if ($searchQuery !==
'') {
293 $form->addItem($inp);
295 $form->addCommandButton(
'search', $this->lng->txt(
"search"));
296 $form->addCommandButton(
'cancelSearch', $this->lng->txt(
"cancel"));
298 $this->tpl->setContent($form->getHtml());
299 $this->tpl->printToStdout();
310 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
313 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'ref',
'mail');
314 $this->ctrl->redirectByClass(
'ilmailsearchcoursesgui');
324 $this->ctrl->setParameterByClass(
'ilmailsearchgroupsgui',
'ref',
'mail');
325 $this->ctrl->redirectByClass(
'ilmailsearchgroupsgui');
331 if (strlen(trim(
$_SESSION[
"mail_search_search"])) == 0) {
335 if (strlen(trim(
$_SESSION[
"mail_search_search"])) < 3) {
336 $this->lng->loadLanguageModule(
'search');
340 $this->ctrl->setParameterByClass(
343 urlencode(
$_SESSION[
"mail_search_search"])
345 $this->ctrl->redirectByClass(
"ilmailsearchgui");
360 if (isset(
$_POST[
'attachments']) && is_array(
$_POST[
'attachments'])) {
361 foreach (
$_POST[
'attachments'] as $value) {
362 $files[] = urldecode($value);
367 $this->umail->savePostData(
368 $this->
user->getId(),
373 (bool) (
$_POST[
"m_email"] ??
false),
376 (bool) (
$_POST[
"use_placeholders"] ??
false),
381 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
386 $_GET[
"type"] =
"attach";
392 $_GET[
"type"] =
"search_res";
398 $_GET[
"type"] =
"new";
404 $_GET[
"type"] =
"role";
410 $_GET[
"type"] =
"reply";
416 $_GET[
"type"] =
"attach";
425 if (!isset(
$_GET[
'template_id'])) {
430 $template = $this->templateService->loadTemplateForId((
int)
$_GET[
'template_id']);
434 'm_subject' => $template->getSubject(),
435 'm_message' => $template->getMessage() . $this->umail->appendSignature(),
444 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
445 $this->tpl->setTitle($this->lng->txt(
"mail"));
447 $this->lng->loadLanguageModule(
"crs");
450 $this->tabs->setBackTarget($this->lng->txt(
'back'), $this->ctrl->getLinkTarget($this,
'cancelMail'));
454 $mailData[
"rcp_to"] =
'';
455 $mailData[
"rcp_cc"] =
'';
456 $mailData[
"rcp_cc"] =
'';
457 $mailData[
"rcp_bcc"] =
'';
458 $mailData[
"attachments"] = [];
460 switch (
$_GET[
"type"]) {
465 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
466 $mailData[
"m_subject"] = $this->umail->formatReplySubject();
467 $mailData[
"m_message"] = $this->umail->formatReplyMessage();
468 $mailData[
"m_message"] = $this->umail->prependSignature();
470 $mailData[
"attachments"] = array();
472 $mailData[
"rcp_cc"] =
'';
473 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
478 $mailData = $this->umail->getSavedData();
487 if (
$_SESSION[
"mail_search_results_to"]) {
488 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
490 if (
$_SESSION[
"mail_search_results_cc"]) {
491 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
493 if (
$_SESSION[
"mail_search_results_bcc"]) {
494 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
497 unset(
$_SESSION[
"mail_search_results_to"]);
498 unset(
$_SESSION[
"mail_search_results_cc"]);
499 unset(
$_SESSION[
"mail_search_results_bcc"]);
504 $mailData = $this->umail->getSavedData();
509 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
510 if (isset($mailData[
'm_subject']) && $mailData[
'm_subject'] === $this->lng->txt(
'mail_no_subject')) {
511 $mailData[
'm_subject'] =
'';
518 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
519 $mailData[
"rcp_to"] = $mailData[
"rcp_cc"] = $mailData[
"rcp_bcc"] =
'';
520 $mailData[
"m_subject"] = $this->umail->formatForwardSubject();
521 $mailData[
"m_message"] = $this->umail->prependSignature();
522 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"])) {
523 if ($error = $this->mfile->adoptAttachments($mailData[
"attachments"],
$_GET[
"mail_id"])) {
530 if (isset(
$_GET[
'rcp_to'])) {
534 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
536 if (isset(
$_GET[
'rcp_cc'])) {
540 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
542 if (isset(
$_GET[
'rcp_bcc'])) {
546 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
548 $mailData[
'm_message'] =
'';
550 $mailData[
'm_message'] = $sig;
551 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
553 $mailData[
'm_message'] .= $this->umail->appendSignature();
562 if (is_array(
$_POST[
'roles'])) {
565 } elseif (is_array(
$_SESSION[
'mail_roles'])) {
569 $mailData[
'm_message'] =
'';
571 $mailData[
'm_message'] = $sig;
572 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
575 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
576 $_POST[
"additional_message_text"] =
"";
581 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
589 foreach ($mailData as $key => $value) {
590 if (is_string($value)) {
599 $form_gui->setTitle($this->lng->txt(
'compose'));
600 $form_gui->setId(
'mail_compose_form');
601 $form_gui->setName(
'mail_compose_form');
602 $form_gui->setFormAction($this->ctrl->getFormAction($this,
'sendMessage'));
604 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
608 $btn->setForm(
'form_' . $form_gui->getName())
609 ->setName(
'searchUsers')
610 ->setCaption(
'search_recipients');
611 $this->toolbar->addStickyItem($btn);
615 ->setName(
'searchCoursesTo')
616 ->setForm(
'form_' . $form_gui->getName())
617 ->setCaption(
'mail_my_courses');
618 $this->toolbar->addButtonInstance($btn);
622 ->setName(
'searchGroupsTo')
623 ->setForm(
'form_' . $form_gui->getName())
624 ->setCaption(
'mail_my_groups');
625 $this->toolbar->addButtonInstance($btn);
630 ->setName(
'searchMailingListsTo')
631 ->setForm(
'form_' . $form_gui->getName())
632 ->setCaption(
'mail_my_mailing_lists');
633 $this->toolbar->addButtonInstance($btn);
636 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
639 $inp->setRequired(
true);
641 $inp->setValue($mailData[
"rcp_to"]);
642 $inp->setDataSource($dsDataLink,
",");
643 $inp->setMaxLength(null);
644 $form_gui->addItem($inp);
648 $inp->setValue($mailData[
"rcp_cc"]);
649 $inp->setDataSource($dsDataLink,
",");
650 $inp->setMaxLength(null);
651 $form_gui->addItem($inp);
653 $inp =
new ilTextInputGUI($this->lng->txt(
'mail_bcc'),
'rcp_bcc');
655 $inp->setValue($mailData[
"rcp_bcc"]);
656 $inp->setDataSource($dsDataLink,
",");
657 $inp->setMaxLength(null);
658 $form_gui->addItem($inp);
660 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
662 $inp->setRequired(
true);
663 $inp->setValue($mailData[
"m_subject"]);
664 $form_gui->addItem($inp);
668 if (isset($mailData[
"attachments"]) && is_array($mailData[
"attachments"])) {
669 foreach ($mailData[
"attachments"] as
$data) {
670 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
"_" .
$data)) {
672 $form_gui->addItem($hidden);
673 $size = filesize($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
"_" .
$data);
675 $att->addItem($label);
676 $hidden->setValue(urlencode($data));
680 $form_gui->addItem($att);
685 $mailData[
'use_placeholders'] =
true;
690 $templates = $this->templateService->loadTemplatesForContextId(
$context->getId());
691 if (count($templates) > 0) {
695 $this->lng->txt(
'mail_template_client'),
697 $this->ctrl->getLinkTarget($this,
'getTemplateDataById',
'',
true,
false),
698 array(
'm_subject' =>
false,
'm_message' =>
true)
701 foreach ($templates as $template) {
702 $options[$template->getTplId()] = $template->
getTitle();
704 if (!isset($mailData[
'template_id']) && $template->isDefault()) {
705 $template_chb->setValue($template->getTplId());
706 $form_gui->getItemByPostVar(
'm_subject')->setValue($template->getSubject());
707 $mailData[
"m_message"] = $template->getMessage() . $this->umail->appendSignature();
710 if (isset($mailData[
'template_id'])) {
711 $template_chb->setValue((
int) $mailData[
'template_id']);
715 $template_chb->setInfo($this->lng->txt(
'mail_template_client_info'));
716 $template_chb->setOptions(array(
'' => $this->lng->txt(
'please_choose')) + $options);
717 $form_gui->addItem($template_chb);
721 '%s has been called with invalid context id: %s.',
732 $inp->
setValue($mailData[
"m_message"]);
733 $inp->setRequired(
false);
736 $form_gui->addItem($inp);
738 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'mail_serial_letter_placeholders'),
'use_placeholders');
740 if (isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders']) {
741 $chb->setChecked(
true);
745 $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
747 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
749 $placeholders->setAdviseText($this->lng->txt(
'placeholders_advise'));
751 foreach (
$context->getPlaceholders() as $key => $value) {
752 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
754 $chb->addSubItem($placeholders);
755 $form_gui->addItem($chb);
757 $form_gui->addCommandButton(
'sendMessage', $this->lng->txt(
'send_mail'));
758 $form_gui->addCommandButton(
'saveDraft', $this->lng->txt(
'save_message'));
760 $form_gui->addCommandButton(
'cancelMail', $this->lng->txt(
'cancel'));
763 $this->tpl->parseCurrentBlock();
765 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
767 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
768 $this->tpl->printToStdout();
774 if (isset(
$_GET[
"term"]) && is_string(
$_GET[
"term"])) {
775 $search =
$_GET[
"term"];
777 if (isset(
$_POST[
"term"]) && is_string(
$_POST[
"term"])) {
781 $search = trim($search);
785 require_once
'Services/Utilities/classes/class.ilStr.php';
793 $quoted = str_replace(
'%',
'\%', $quoted);
794 $quoted = str_replace(
'_',
'\_', $quoted);
818 if (is_array(
$_POST[
'attachments'])) {
819 foreach (
$_POST[
'attachments'] as $value) {
820 $files[] = urldecode($value);
824 $this->umail->savePostData(
825 $this->
user->getId(),
846 $this->ctrl->setParameterByClass(
'ilmailinglistsgui',
'ref',
'mail');
847 $this->ctrl->redirectByClass(
'ilmailinglistsgui');
856 $formattedErrors = $formatter->format($errors);
858 if (strlen($formattedErrors) > 0) {
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
static getInstanceByGlobalUser()
static getTemplateContextById($a_id)
Class ilMailTemplateService.
static get($a_var)
Get a value.
setValue($a_value)
Set Value.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Mail Box class Base class for creating and handling mail boxes.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a text area property in a property form.
static getLogger($a_component_id)
Get component logger.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
static redirect($a_script)