19 declare(strict_types=1);
65 $this->template_service = $template_service ?? $DIC->mail()->textTemplates();
66 $this->tpl = $DIC->ui()->mainTemplate();
67 $this->
ctrl = $DIC->ctrl();
68 $this->
lng = $DIC->language();
69 $this->
user = $DIC->user();
70 $this->
tabs = $DIC->tabs();
71 $this->
toolbar = $DIC->toolbar();
72 $this->
http = $DIC->http();
78 $this->ui_factory = $DIC->ui()->factory();
90 if ($mail_obj_id === 0) {
91 $mail_obj_id = $this->mbox->getInboxFolder();
94 $this->
ctrl->setParameter($this,
'mobj_id', $mail_obj_id);
99 if ($this->
http->wrapper()->query()->has($name)) {
100 return $this->
http->wrapper()->query()->retrieve(
111 if ($this->
http->wrapper()->post()->has($name)) {
112 return $this->
http->wrapper()->post()->retrieve(
123 $forward_class = $this->
ctrl->getNextClass($this) ??
'';
124 switch (strtolower($forward_class)) {
125 case strtolower(ilMailAttachmentGUI::class):
126 $this->
ctrl->setReturn($this,
'returnFromAttachments');
129 $this->
ctrl->forwardCommand($gui);
132 case strtolower(ilMailSearchGUI::class):
133 $this->
ctrl->setReturn($this,
'searchResults');
137 case strtolower(ilMailSearchCoursesGUI::class):
138 $this->
ctrl->setReturn($this,
'searchResults');
142 case strtolower(ilMailingListsGUI::class):
143 $this->
ctrl->setReturn($this,
'searchResults');
147 case strtolower(ilMailSearchGroupsGUI::class):
148 $this->
ctrl->setReturn($this,
'searchResults');
153 if (!($cmd = $this->
ctrl->getCmd())) {
169 foreach ($files as $value) {
170 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' . urldecode($value))) {
171 $decoded_files[] = urldecode($value);
175 return $decoded_files;
184 $sanitized_message = $mail_body->getContent();
193 $mailer = $this->umail
197 $mailer->setSaveInSentbox(
true);
199 $mailer->autoresponder()->enableAutoresponder();
201 if ($errors = $mailer->enqueue(
210 $this->request_attachments = $files;
213 $mailer->autoresponder()->disableAutoresponder();
215 $mailer->persistToStage(
216 $this->
user->getId(),
225 $this->
ctrl->setParameterByClass(ilMailGUI::class,
'type',
'message_sent');
228 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_message_send'),
true);
231 $this->
ctrl->redirectByClass(ilMailGUI::class);
234 $mailer->autoresponder()->disableAutoresponder();
241 $draft_folder_id = $this->mbox->getDraftsFolder();
245 $this->
refinery->kindlyTo()->listOf(
246 $this->
refinery->custom()->transformation($this->
refinery->kindlyTo()->string())
255 if ($errors = $this->umail->validateRecipients(
260 $this->request_attachments = $files;
270 $draft_id = $this->umail->getNewDraftId($draft_folder_id);
273 $this->umail->updateDraft(
289 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_saved'),
true);
294 $this->
ctrl->redirectByClass([ilMailGUI::class, ilMailFolderGUI::class]);
302 $this->tpl->setTitle($this->
lng->txt(
'mail'));
307 $this->
refinery->kindlyTo()->listOf(
308 $this->
refinery->custom()->transformation(
function ($elm):
string {
309 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
311 return urldecode($attachment);
318 $this->umail->persistToStage(
319 $this->
user->getId(),
333 $form->setId(
'search_rcp');
334 $form->setTitle($this->
lng->txt(
'search_recipients'));
335 $form->setFormAction($this->
ctrl->getFormAction($this,
'search'));
339 $data_source_url = $this->
ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
340 $inp->setDataSource($data_source_url);
342 $search_query = trim((
string)
ilSession::get(
'mail_search_search'));
343 if ($search_query !==
'') {
346 $form->addItem($inp);
348 $form->addCommandButton(
'search', $this->
lng->txt(
'search'));
349 $form->addCommandButton(
'cancelSearch', $this->
lng->txt(
'cancel'));
351 $this->tpl->setContent($form->getHTML());
352 $this->tpl->printToStdout();
360 $this->
ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
363 $this->
ctrl->setParameterByClass(ilMailSearchCoursesGUI::class,
'ref',
'mail');
364 $this->
ctrl->redirectByClass(ilMailSearchCoursesGUI::class);
371 $this->
ctrl->setParameterByClass(ilMailSearchGroupsGUI::class,
'ref',
'mail');
372 $this->
ctrl->redirectByClass(ilMailSearchGroupsGUI::class);
378 'mail_search_search',
383 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_insert_query'));
385 } elseif (strlen(trim(
ilSession::get(
'mail_search_search') ??
'')) < 3) {
386 $this->
lng->loadLanguageModule(
'search');
387 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'search_minimum_three'));
390 $this->
ctrl->setParameterByClass(
391 ilMailSearchGUI::class,
395 $this->
ctrl->redirectByClass(ilMailSearchGUI::class);
409 $this->
refinery->kindlyTo()->listOf(
410 $this->
refinery->custom()->transformation(
function ($elm):
string {
411 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
413 return urldecode($attachment);
420 $this->umail->persistToStage(
421 $this->
user->getId(),
433 $this->
ctrl->redirectByClass(ilMailAttachmentGUI::class);
438 $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
444 $this->mail_form_type = self::MAIL_FORM_TYPE_SEARCH_RESULT;
450 $this->mail_form_type = self::MAIL_FORM_TYPE_NEW;
456 $this->mail_form_type = self::MAIL_FORM_TYPE_ROLE;
462 $this->mail_form_type = self::MAIL_FORM_TYPE_REPLY;
468 $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
474 if (!$this->
http->wrapper()->query()->has(
'template_id')) {
475 $this->
http->close();
479 $template = $this->template_service->loadTemplateForId(
480 $this->
http->wrapper()->query()->retrieve(
'template_id', $this->
refinery->kindlyTo()->int())
484 $this->
http->saveResponse(
485 $this->
http->response()
486 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
487 ->withBody(Streams::ofString(json_encode([
488 'm_subject' => $template->getSubject(),
489 'm_message' => $this->umail->appendSignature($template->getMessage()),
490 ], JSON_THROW_ON_ERROR)))
495 $this->
http->sendResponse();
496 $this->
http->close();
501 $this->tpl->addBlockFile(
505 'components/ILIAS/Mail' 507 $this->tpl->setTitle($this->
lng->txt(
'mail'));
509 $this->
lng->loadLanguageModule(
'crs');
512 $this->
tabs->setBackTarget(
513 $this->
lng->txt(
'back'),
514 $this->
ctrl->getLinkTarget($this,
'cancelMail')
519 $mail_data[
'rcp_to'] =
'';
520 $mail_data[
'rcp_cc'] =
'';
521 $mail_data[
'rcp_bcc'] =
'';
522 $mail_data[
'attachments'] = [];
526 if ($this->mail_form_type !==
'') {
531 case self::MAIL_FORM_TYPE_REPLY:
532 $mail_data = $this->umail->getMail($mail_id);
534 $mail_data[
'm_subject'] = $this->umail->formatReplySubject($mail_data[
'm_subject'] ??
'');
535 $mail_data[
'm_message'] = $this->umail->prependSignature(
536 $this->umail->formatReplyMessage($mail_data[
'm_message'] ??
'')
538 $mail_data[
'attachments'] = [];
539 $mail_data[
'rcp_cc'] =
'';
540 $mail_data[
'rcp_to'] = $this->umail->formatReplyRecipient();
543 case self::MAIL_FORM_TYPE_SEARCH_RESULT:
544 $mail_data = $this->umail->retrieveFromStage();
547 $mail_data = $this->umail->appendSearchResult(
548 $this->
refinery->kindlyTo()->listOf(
549 $this->
refinery->kindlyTo()->string()
555 $mail_data = $this->umail->appendSearchResult(
556 $this->
refinery->kindlyTo()->listOf(
557 $this->
refinery->kindlyTo()->string()
563 $mail_data = $this->umail->appendSearchResult(
564 $this->
refinery->kindlyTo()->listOf(
565 $this->
refinery->kindlyTo()->string()
576 case self::MAIL_FORM_TYPE_ATTACH:
577 $mail_data = $this->umail->retrieveFromStage();
580 case self::MAIL_FORM_TYPE_DRAFT:
582 $mail_data = $this->umail->getMail($mail_id);
587 case self::MAIL_FORM_TYPE_FORWARD:
588 $mail_data = $this->umail->getMail($mail_id);
589 $mail_data[
'rcp_to'] = $mail_data[
'rcp_cc'] = $mail_data[
'rcp_bcc'] =
'';
590 $mail_data[
'm_subject'] = $this->umail->formatForwardSubject($mail_data[
'm_subject'] ??
'');
591 $mail_data[
'm_message'] = $this->umail->prependSignature($mail_data[
'm_message'] ??
'');
592 if (is_array($mail_data[
'attachments']) && count($mail_data[
'attachments']) && $error = $this->mfile->adoptAttachments(
593 $mail_data[
'attachments'],
596 $this->tpl->setOnScreenMessage(
'info', $error);
600 case self::MAIL_FORM_TYPE_NEW:
606 $mail_data[
'rcp_to'] = $to;
612 $mail_data[
'rcp_cc'] = $cc;
618 $mail_data[
'rcp_bcc'] = $bcc;
620 $mail_data[
'm_message'] =
'';
622 $mail_data[
'm_message'] = $sig;
623 $mail_data[
'm_message'] .= chr(13)
628 $mail_data[
'm_message'] .= $this->umail->appendSignature(
'');
635 case self::MAIL_FORM_TYPE_ROLE:
637 if ($this->
http->wrapper()->post()->has(
'roles')) {
638 $roles = $this->
http->wrapper()->post()->retrieve(
643 $roles = $this->
refinery->kindlyTo()->listOf(
644 $this->
refinery->kindlyTo()->string()
653 $mail_data[
'm_message'] =
'';
655 $mail_data[
'm_message'] = $sig;
656 $mail_data[
'm_message'] .= chr(13)
662 $additional_msg_text =
'';
663 if ($this->
http->wrapper()->post()->has(
'additional_message_text')) {
665 'additional_message_text',
666 $this->
refinery->kindlyTo()->string()
670 $mail_data[
'm_message'] .= $additional_msg_text
673 . $this->umail->appendSignature(
'');
677 case self::MAIL_FORM_TYPE_ADDRESS:
679 if ($this->
http->wrapper()->query()->has(
'rcp')) {
680 $rcp = $this->
http->wrapper()->query()->retrieve(
'rcp', $this->
refinery->kindlyTo()->string());
682 $mail_data[
'rcp_to'] = urldecode((
string) $rcp);
686 $mail_data = $this->
http->request()->getParsedBody();
687 foreach ($mail_data as $key => $value) {
688 if (is_string($value)) {
694 if ($this->request_attachments) {
701 $form_gui->setTitle($this->
lng->txt(
'compose'));
702 $form_gui->setId(
'mail_compose_form');
703 $form_gui->setName(
'mail_compose_form');
704 $form_gui->setFormAction($this->
ctrl->getFormAction($this,
'sendMessage'));
706 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
708 $mail_form =
'form_' . $form_gui->getName();
710 $btn = $this->ui_factory->button()
711 ->standard($this->
lng->txt(
'search_recipients'),
'#')
713 document.getElementById('$id').addEventListener('click', function() { 714 const frm = document.getElementById('$mail_form'), 715 action = new URL(frm.action), 716 action_params = new URLSearchParams(action.search); 718 action_params.delete('cmd'); 719 action_params.append('cmd', 'searchUsers'); 721 action.search = action_params.toString(); 723 frm.action = action.href; 728 $this->
toolbar->addStickyItem($btn);
730 $btn = $this->ui_factory->button()
731 ->standard($this->
lng->txt(
'mail_my_courses'),
'#')
733 document.getElementById('$id').addEventListener('click', function() { 734 const frm = document.getElementById('$mail_form'), 735 action = new URL(frm.action), 736 action_params = new URLSearchParams(action.search); 738 action_params.delete('cmd'); 739 action_params.append('cmd', 'searchCoursesTo'); 741 action.search = action_params.toString(); 743 frm.action = action.href; 748 $this->
toolbar->addComponent($btn);
750 $btn = $this->ui_factory->button()
751 ->standard($this->
lng->txt(
'mail_my_groups'),
'#')
753 document.getElementById('$id').addEventListener('click', function() { 754 const frm = document.getElementById('$mail_form'), 755 action = new URL(frm.action), 756 action_params = new URLSearchParams(action.search); 758 action_params.delete('cmd'); 759 action_params.append('cmd', 'searchGroupsTo'); 761 action.search = action_params.toString(); 763 frm.action = action.href; 768 $this->
toolbar->addComponent($btn);
771 $btn = $this->ui_factory->button()
772 ->standard($this->
lng->txt(
'mail_my_mailing_lists'),
'#')
774 document.getElementById('$id').addEventListener('click', function() { 775 const frm = document.getElementById('$mail_form'), 776 action = new URL(frm.action), 777 action_params = new URLSearchParams(action.search); 779 action_params.delete('cmd'); 780 action_params.append('cmd', 'searchMailingListsTo'); 782 action.search = action_params.toString(); 784 frm.action = action.href; 789 $this->
toolbar->addComponent($btn);
792 $data_source_url = $this->
ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
795 $inp->setMaxLength(
null);
796 $inp->setRequired(
true);
798 $inp->setValue((
string) ($mail_data[
'rcp_to'] ??
''));
799 $inp->setDataSource($data_source_url,
',');
800 $form_gui->addItem($inp);
803 $inp->setMaxLength(
null);
805 $inp->setValue((
string) ($mail_data[
'rcp_cc'] ??
''));
806 $inp->setDataSource($data_source_url,
',');
807 $form_gui->addItem($inp);
810 $inp->setMaxLength(
null);
812 $inp->setValue($mail_data[
'rcp_bcc'] ??
'');
813 $inp->setDataSource($data_source_url,
',');
814 $form_gui->addItem($inp);
818 $inp->setRequired(
true);
819 $inp->setValue((
string) ($mail_data[
'm_subject'] ??
''));
820 $form_gui->addItem($inp);
824 isset($mail_data[
'attachments']) && is_array($mail_data[
'attachments']) ?
830 if (isset($mail_data[
'attachments']) && is_array($mail_data[
'attachments'])) {
831 foreach ($mail_data[
'attachments'] as
$data) {
832 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' .
$data)) {
834 $form_gui->addItem($hidden);
835 $size = filesize($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' .
$data);
837 $att->addItem($label);
838 $hidden->setValue(urlencode((
string) $data));
842 $form_gui->addItem($att);
848 $mail_data[
'use_placeholders'] =
true;
853 $templates = $this->template_service->loadTemplatesForContextId(
$context->getId());
854 if ($templates !== []) {
858 $this->
lng->txt(
'mail_template_client'),
860 $this->
ctrl->getLinkTarget($this,
'getTemplateDataById',
'',
true),
861 [
'm_subject' =>
false,
'm_message' =>
true]
864 foreach ($templates as $template) {
865 $options[$template->getTplId()] = $template->
getTitle();
867 if (!isset($mail_data[
'template_id']) && $template->isDefault()) {
868 $template_chb->setValue((
string) $template->getTplId());
869 $form_gui->getItemByPostVar(
'm_subject')->setValue($template->getSubject());
870 $mail_data[
'm_message'] = $template->getMessage() . $this->umail->appendSignature(
871 $mail_data[
'm_message']
875 if (isset($mail_data[
'template_id'])) {
876 $template_chb->setValue((
string) ((
int) $mail_data[
'template_id']));
880 $template_chb->setInfo($this->
lng->txt(
'mail_template_client_info'));
881 $template_chb->setOptions([
'' => $this->
lng->txt(
'please_choose')] + $options);
882 $form_gui->addItem($template_chb);
886 '%s has been called with invalid context id: %s.',
894 $inp->
setValue((
string) ($mail_data[
'm_message'] ??
''));
895 $inp->setRequired(
false);
898 $form_gui->addItem($inp);
901 $this->
lng->txt(
'mail_serial_letter_placeholders'),
905 $chb->setChecked(isset($mail_data[
'use_placeholders']) && $mail_data[
'use_placeholders']);
908 $this->
lng->txt(
'mail_form_placeholders_label'),
914 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
916 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
918 foreach (
$context->getPlaceholders() as $key => $value) {
919 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
921 $chb->addSubItem($placeholders);
922 $form_gui->addItem($chb);
924 $form_gui->addCommandButton(
'sendMessage', $this->
lng->txt(
'send_mail'));
925 $form_gui->addCommandButton(
'saveDraft', $this->
lng->txt(
'save_message'));
927 $form_gui->addCommandButton(
'cancelMail', $this->
lng->txt(
'cancel'));
930 $this->tpl->parseCurrentBlock();
932 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
934 $this->tpl->addJavaScript(
'assets/js/ilMailComposeFunctions.js');
935 $this->tpl->printToStdout();
942 $this->
refinery->kindlyTo()->string(),
945 $this->
refinery->kindlyTo()->string(),
953 $this->
http->saveResponse(
954 $this->
http->response()
955 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
956 ->withBody(Streams::ofString(json_encode($result, JSON_THROW_ON_ERROR)))
959 $this->
http->sendResponse();
960 $this->
http->close();
965 $quoted = str_replace([
'%',
'_'], [
'\%',
'\_'], $quoted);
970 $this->
http->saveResponse(
971 $this->
http->response()
972 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
973 ->withBody(Streams::ofString(json_encode($result, JSON_THROW_ON_ERROR)))
975 $this->
http->sendResponse();
976 $this->
http->close();
992 $this->
refinery->kindlyTo()->listOf(
993 $this->
refinery->custom()->transformation(
function ($elm):
string {
994 $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
996 return urldecode($attachment);
1002 $this->umail->persistToStage(
1003 $this->
user->getId(),
1020 $this->
ctrl->setParameterByClass(ilMailingListsGUI::class,
'ref',
'mail');
1021 $this->
ctrl->redirectByClass(ilMailingListsGUI::class);
1030 $formatted_errors = $formatter->format($errors);
1032 if ($formatted_errors !==
'') {
1033 $this->tpl->setOnScreenMessage(
'failure', $formatted_errors);
static get(string $a_var)
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...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
withOnLoadCode(Closure $binder)
static getTemplateContextById(string $a_id)
setValue(string $a_value)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static strLen(string $a_string)
static http()
Fetches the global http state from ILIAS.
static securePlainString(string $a_str)
This is how the factory for UI elements looks.
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)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
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.
static getInstanceByGlobalUser(?ilObjUser $user=null)