19 declare(strict_types=1);
64 $this->templateService = $templateService ?? $DIC[
'mail.texttemplates.service'];
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->
http = $DIC->http();
88 if (0 === $requestMailObjId) {
89 $requestMailObjId = $this->mbox->getInboxFolder();
92 $this->
ctrl->setParameter($this,
'mobj_id', $requestMailObjId);
97 if ($this->
http->wrapper()->query()->has($name)) {
98 return $this->
http->wrapper()->query()->retrieve(
109 if ($this->
http->wrapper()->post()->has($name)) {
110 return $this->
http->wrapper()->post()->retrieve(
121 $forward_class = $this->
ctrl->getNextClass($this);
122 switch (strtolower($forward_class)) {
123 case strtolower(ilMailAttachmentGUI::class):
124 $this->
ctrl->setReturn($this,
'returnFromAttachments');
128 case strtolower(ilMailSearchGUI::class):
129 $this->
ctrl->setReturn($this,
'searchResults');
133 case strtolower(ilMailSearchCoursesGUI::class):
134 $this->
ctrl->setReturn($this,
'searchResults');
138 case strtolower(ilMailingListsGUI::class):
139 $this->
ctrl->setReturn($this,
'searchResults');
143 case strtolower(ilMailSearchGroupsGUI::class):
144 $this->
ctrl->setReturn($this,
'searchResults');
149 if (!($cmd = $this->
ctrl->getCmd())) {
166 foreach ($files as $value) {
167 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' . urldecode($value))) {
168 $decodedFiles[] = urldecode($value);
172 return $decodedFiles;
181 $sanitizedMessage = $mailBody->getContent();
190 $mailer = $this->umail
194 $mailer->setSaveInSentbox(
true);
196 if (
$errors = $mailer->enqueue(
205 $this->requestAttachments = $files;
208 $mailer->persistToStage(
209 $this->
user->getId(),
218 $this->
ctrl->setParameterByClass(ilMailGUI::class,
'type',
'message_sent');
221 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_message_send'),
true);
224 $this->
ctrl->redirectByClass(ilMailGUI::class);
233 $draftFolderId = $this->mbox->getDraftsFolder();
237 $this->
refinery->kindlyTo()->listOf(
238 $this->
refinery->custom()->transformation($this->
refinery->kindlyTo()->string())
247 if (
$errors = $this->umail->validateRecipients(
252 $this->requestAttachments = $files;
262 $draftId = $this->umail->getNewDraftId($draftFolderId);
265 $this->umail->updateDraft(
281 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_saved'),
true);
286 $this->
ctrl->redirectByClass([ilMailGUI::class, ilMailFolderGUI::class]);
294 $this->tpl->setTitle($this->
lng->txt(
'mail'));
299 $this->
refinery->kindlyTo()->listOf(
300 $this->
refinery->custom()->transformation(
function ($elm):
string {
301 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
303 return urldecode($attachment);
310 $this->umail->persistToStage(
311 $this->
user->getId(),
325 $form->setId(
'search_rcp');
326 $form->setTitle($this->
lng->txt(
'search_recipients'));
327 $form->setFormAction($this->
ctrl->getFormAction($this,
'search'));
331 $dsDataLink = $this->
ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
332 $inp->setDataSource($dsDataLink);
334 $searchQuery = trim((
string)
ilSession::get(
'mail_search_search'));
335 if ($searchQuery !==
'') {
338 $form->addItem($inp);
340 $form->addCommandButton(
'search', $this->
lng->txt(
'search'));
341 $form->addCommandButton(
'cancelSearch', $this->
lng->txt(
'cancel'));
343 $this->tpl->setContent($form->getHTML());
344 $this->tpl->printToStdout();
352 $this->
ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
355 $this->
ctrl->setParameterByClass(ilMailSearchCoursesGUI::class,
'ref',
'mail');
356 $this->
ctrl->redirectByClass(ilMailSearchCoursesGUI::class);
363 $this->
ctrl->setParameterByClass(ilMailSearchGroupsGUI::class,
'ref',
'mail');
364 $this->
ctrl->redirectByClass(ilMailSearchGroupsGUI::class);
370 'mail_search_search',
375 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"mail_insert_query"));
377 } elseif (strlen(trim(
ilSession::get(
'mail_search_search'))) < 3) {
378 $this->
lng->loadLanguageModule(
'search');
379 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'search_minimum_three'));
382 $this->
ctrl->setParameterByClass(
383 ilMailSearchGUI::class,
387 $this->
ctrl->redirectByClass(ilMailSearchGUI::class);
401 $this->
refinery->kindlyTo()->listOf(
402 $this->
refinery->custom()->transformation(
function ($elm):
string {
403 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
405 return urldecode($attachment);
412 $this->umail->persistToStage(
413 $this->
user->getId(),
425 $this->
ctrl->redirectByClass(ilMailAttachmentGUI::class);
430 $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
436 $this->mail_form_type = self::MAIL_FORM_TYPE_SEARCH_RESULT;
442 $this->mail_form_type = self::MAIL_FORM_TYPE_NEW;
448 $this->mail_form_type = self::MAIL_FORM_TYPE_ROLE;
454 $this->mail_form_type = self::MAIL_FORM_TYPE_REPLY;
460 $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
466 if (!$this->
http->wrapper()->query()->has(
'template_id')) {
467 $this->
http->close();
471 $template = $this->templateService->loadTemplateForId(
472 $this->
http->wrapper()->query()->retrieve(
'template_id', $this->
refinery->kindlyTo()->int())
476 $this->
http->saveResponse(
477 $this->
http->response()
478 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
479 ->withBody(Streams::ofString(json_encode([
480 'm_subject' => $template->getSubject(),
481 'm_message' => $this->umail->appendSignature($template->getMessage()),
482 ], JSON_THROW_ON_ERROR)))
487 $this->
http->sendResponse();
488 $this->
http->close();
493 $this->tpl->addBlockFile(
499 $this->tpl->setTitle($this->
lng->txt(
'mail'));
501 $this->
lng->loadLanguageModule(
'crs');
504 $this->
tabs->setBackTarget(
505 $this->
lng->txt(
'back'),
506 $this->
ctrl->getLinkTarget($this,
'cancelMail')
511 $mailData[
'rcp_to'] =
'';
512 $mailData[
'rcp_cc'] =
'';
513 $mailData[
'rcp_bcc'] =
'';
514 $mailData[
'attachments'] = [];
518 if ($this->mail_form_type !==
'') {
523 case self::MAIL_FORM_TYPE_REPLY:
524 $mailData = $this->umail->getMail($mailId);
526 $mailData[
'm_subject'] = $this->umail->formatReplySubject($mailData[
'm_subject'] ??
'');
527 $mailData[
'm_message'] = $this->umail->prependSignature(
528 $this->umail->formatReplyMessage($mailData[
'm_message'] ??
'')
530 $mailData[
'attachments'] = [];
531 $mailData[
'rcp_cc'] =
'';
532 $mailData[
'rcp_to'] = $this->umail->formatReplyRecipient();
535 case self::MAIL_FORM_TYPE_SEARCH_RESULT:
536 $mailData = $this->umail->retrieveFromStage();
539 $mailData = $this->umail->appendSearchResult(
540 $this->
refinery->kindlyTo()->listOf(
541 $this->
refinery->kindlyTo()->string()
547 $mailData = $this->umail->appendSearchResult(
548 $this->
refinery->kindlyTo()->listOf(
549 $this->
refinery->kindlyTo()->string()
555 $mailData = $this->umail->appendSearchResult(
556 $this->
refinery->kindlyTo()->listOf(
557 $this->
refinery->kindlyTo()->string()
568 case self::MAIL_FORM_TYPE_ATTACH:
569 $mailData = $this->umail->retrieveFromStage();
572 case self::MAIL_FORM_TYPE_DRAFT:
574 $mailData = $this->umail->getMail($mailId);
579 case self::MAIL_FORM_TYPE_FORWARD:
580 $mailData = $this->umail->getMail($mailId);
581 $mailData[
'rcp_to'] = $mailData[
'rcp_cc'] = $mailData[
'rcp_bcc'] =
'';
582 $mailData[
'm_subject'] = $this->umail->formatForwardSubject($mailData[
'm_subject'] ??
'');
583 $mailData[
'm_message'] = $this->umail->prependSignature($mailData[
'm_message'] ??
'');
584 if (is_array($mailData[
'attachments']) && count($mailData[
'attachments']) && $error = $this->mfile->adoptAttachments(
585 $mailData[
'attachments'],
588 $this->tpl->setOnScreenMessage(
'info', $error);
592 case self::MAIL_FORM_TYPE_NEW:
598 $mailData[
'rcp_to'] = $to;
604 $mailData[
'rcp_cc'] = $cc;
610 $mailData[
'rcp_bcc'] = $bcc;
612 $mailData[
'm_message'] =
'';
614 $mailData[
'm_message'] = $sig;
615 $mailData[
'm_message'] .= chr(13)
620 $mailData[
'm_message'] .= $this->umail->appendSignature(
'');
627 case self::MAIL_FORM_TYPE_ROLE:
629 if ($this->
http->wrapper()->post()->has(
'roles')) {
630 $roles = $this->
http->wrapper()->post()->retrieve(
635 $roles = $this->
refinery->kindlyTo()->listOf(
636 $this->
refinery->kindlyTo()->string()
645 $mailData[
'm_message'] =
'';
647 $mailData[
'm_message'] = $sig;
648 $mailData[
'm_message'] .= chr(13)
654 $additionalMessageText =
'';
655 if ($this->
http->wrapper()->post()->has(
'additional_message_text')) {
657 'additional_message_text',
658 $this->
refinery->kindlyTo()->string()
662 $mailData[
'm_message'] .= $additionalMessageText
665 . $this->umail->appendSignature(
'');
669 case self::MAIL_FORM_TYPE_ADDRESS:
671 if ($this->
http->wrapper()->query()->has(
'rcp')) {
672 $rcp = $this->
http->wrapper()->query()->retrieve(
'rcp', $this->
refinery->kindlyTo()->string());
674 $mailData[
'rcp_to'] = urldecode($rcp);
678 $mailData = $this->
http->request()->getParsedBody();
679 foreach ($mailData as
$key => $value) {
680 if (is_string($value)) {
686 if ($this->requestAttachments) {
693 $form_gui->setTitle($this->
lng->txt(
'compose'));
694 $form_gui->setId(
'mail_compose_form');
695 $form_gui->setName(
'mail_compose_form');
696 $form_gui->setFormAction($this->
ctrl->getFormAction($this,
'sendMessage'));
698 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
702 $btn->setForm(
'form_' . $form_gui->getName())
703 ->setName(
'searchUsers')
704 ->setCaption(
'search_recipients');
705 $this->
toolbar->addStickyItem($btn);
709 ->setName(
'searchCoursesTo')
710 ->setForm(
'form_' . $form_gui->getName())
711 ->setCaption(
'mail_my_courses');
712 $this->
toolbar->addButtonInstance($btn);
716 ->setName(
'searchGroupsTo')
717 ->setForm(
'form_' . $form_gui->getName())
718 ->setCaption(
'mail_my_groups');
719 $this->
toolbar->addButtonInstance($btn);
724 ->setName(
'searchMailingListsTo')
725 ->setForm(
'form_' . $form_gui->getName())
726 ->setCaption(
'mail_my_mailing_lists');
727 $this->
toolbar->addButtonInstance($btn);
730 $dsDataLink = $this->
ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
733 $inp->setMaxLength(null);
734 $inp->setRequired(
true);
736 $inp->setValue((
string) ($mailData[
'rcp_to'] ??
''));
737 $inp->setDataSource($dsDataLink,
',');
738 $form_gui->addItem($inp);
741 $inp->setMaxLength(null);
743 $inp->setValue((
string) ($mailData[
'rcp_cc'] ??
''));
744 $inp->setDataSource($dsDataLink,
',');
745 $form_gui->addItem($inp);
748 $inp->setMaxLength(null);
750 $inp->setValue($mailData[
'rcp_bcc'] ??
'');
751 $inp->setDataSource($dsDataLink,
',');
752 $form_gui->addItem($inp);
756 $inp->setRequired(
true);
757 $inp->setValue((
string) ($mailData[
'm_subject'] ??
''));
758 $form_gui->addItem($inp);
762 isset($mailData[
'attachments']) && is_array($mailData[
'attachments']) ?
767 if (isset($mailData[
'attachments']) && is_array($mailData[
'attachments'])) {
768 foreach ($mailData[
'attachments'] as
$data) {
769 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' .
$data)) {
771 $form_gui->addItem($hidden);
772 $size = filesize($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' .
$data);
774 $att->addItem($label);
775 $hidden->setValue(urlencode($data));
779 $form_gui->addItem($att);
785 $mailData[
'use_placeholders'] =
true;
790 $templates = $this->templateService->loadTemplatesForContextId(
$context->getId());
791 if (count($templates) > 0) {
795 $this->
lng->txt(
'mail_template_client'),
797 $this->
ctrl->getLinkTarget($this,
'getTemplateDataById',
'',
true),
798 [
'm_subject' =>
false,
'm_message' =>
true]
801 foreach ($templates as $template) {
802 $options[$template->getTplId()] = $template->
getTitle();
804 if (!isset($mailData[
'template_id']) && $template->isDefault()) {
805 $template_chb->setValue((
string) $template->getTplId());
806 $form_gui->getItemByPostVar(
'm_subject')->setValue($template->getSubject());
807 $mailData[
'm_message'] = $template->getMessage() . $this->umail->appendSignature(
808 $mailData[
'm_message']
812 if (isset($mailData[
'template_id'])) {
813 $template_chb->setValue((
string) ((
int) $mailData[
'template_id']));
817 $template_chb->setInfo($this->
lng->txt(
'mail_template_client_info'));
818 $template_chb->setOptions([
'' => $this->
lng->txt(
'please_choose')] + $options);
819 $form_gui->addItem($template_chb);
823 '%s has been called with invalid context id: %s.',
831 $inp->
setValue((
string) ($mailData[
'm_message'] ??
''));
832 $inp->setRequired(
false);
835 $form_gui->addItem($inp);
838 $this->
lng->txt(
'mail_serial_letter_placeholders'),
842 $chb->setChecked(isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders']);
847 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
849 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
851 foreach (
$context->getPlaceholders() as
$key => $value) {
852 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
854 $chb->addSubItem($placeholders);
855 $form_gui->addItem($chb);
857 $form_gui->addCommandButton(
'sendMessage', $this->
lng->txt(
'send_mail'));
858 $form_gui->addCommandButton(
'saveDraft', $this->
lng->txt(
'save_message'));
860 $form_gui->addCommandButton(
'cancelMail', $this->
lng->txt(
'cancel'));
863 $this->tpl->parseCurrentBlock();
865 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
867 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
868 $this->tpl->printToStdout();
875 $this->
refinery->kindlyTo()->string(),
878 $this->
refinery->kindlyTo()->string(),
886 $this->
http->saveResponse(
887 $this->
http->response()
888 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
889 ->withBody(Streams::ofString(json_encode($result, JSON_THROW_ON_ERROR)))
892 $this->
http->sendResponse();
893 $this->
http->close();
898 $quoted = str_replace([
'%',
'_'], [
'\%',
'\_'], $quoted);
903 $this->
http->saveResponse(
904 $this->
http->response()
905 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
906 ->withBody(Streams::ofString(json_encode($result, JSON_THROW_ON_ERROR)))
908 $this->
http->sendResponse();
909 $this->
http->close();
925 $this->
refinery->kindlyTo()->listOf(
926 $this->
refinery->custom()->transformation(
function ($elm):
string {
927 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
929 return urldecode($attachment);
935 $this->umail->persistToStage(
936 $this->
user->getId(),
953 $this->
ctrl->setParameterByClass(ilMailingListsGUI::class,
'ref',
'mail');
954 $this->
ctrl->redirectByClass(ilMailingListsGUI::class);
963 $formattedErrors = $formatter->format($errors);
965 if ($formattedErrors !==
'') {
966 $this->tpl->setOnScreenMessage(
'failure', $formattedErrors);
Interface GlobalHttpState.
static get(string $a_var)
static getInstanceByGlobalUser()
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class handles all operations on files (attachments) in directory ilias_data/mail.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Class ilMailTemplateService.
static getTemplateContextById(string $a_id)
setValue(string $a_value)
static strLen(string $a_string)
static http()
Fetches the global http state from ILIAS.
static securePlainString(string $a_str)
Mail Box class Base class for creating and handling mail boxes.
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
static redirect(string $a_script)
This class represents a text area property in a property form.
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.