19 declare(strict_types=1);
    67         $this->templateService = $templateService ?? $DIC->mail()->textTemplates();
    68         $this->tpl = $DIC->ui()->mainTemplate();
    69         $this->
ctrl = $DIC->ctrl();
    70         $this->
lng = $DIC->language();
    71         $this->
user = $DIC->user();
    72         $this->
tabs = $DIC->tabs();
    73         $this->
toolbar = $DIC->toolbar();
    74         $this->
http = $DIC->http();
    80         $this->ui_factory = $DIC->ui()->factory();
    92         if (0 === $requestMailObjId) {
    93             $requestMailObjId = $this->mbox->getInboxFolder();
    96         $this->
ctrl->setParameter($this, 
'mobj_id', $requestMailObjId);
   101         if ($this->
http->wrapper()->query()->has($name)) {
   102             return $this->
http->wrapper()->query()->retrieve(
   113         if ($this->
http->wrapper()->post()->has($name)) {
   114             return $this->
http->wrapper()->post()->retrieve(
   125         $forward_class = $this->
ctrl->getNextClass($this);
   126         switch (strtolower($forward_class)) {
   127             case strtolower(ilMailAttachmentGUI::class):
   128                 $this->
ctrl->setReturn($this, 
'returnFromAttachments');
   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())) {
   170         foreach ($files as $value) {
   171             if (is_file($this->mfile->getMailPath() . 
'/' . $this->
user->getId() . 
'_' . urldecode($value))) {
   172                 $decodedFiles[] = urldecode($value);
   176         return $decodedFiles;
   185         $sanitizedMessage = $mailBody->getContent();
   194         $mailer = $this->umail
   198         $mailer->setSaveInSentbox(
true);
   200         $mailer->autoresponder()->enableAutoresponder();
   202         if ($errors = $mailer->enqueue(
   211             $this->requestAttachments = $files;
   214             $mailer->autoresponder()->disableAutoresponder();
   216             $mailer->persistToStage(
   217                 $this->
user->getId(),
   226             $this->
ctrl->setParameterByClass(ilMailGUI::class, 
'type', 
'message_sent');
   229                 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_message_send'), 
true);
   232                 $this->
ctrl->redirectByClass(ilMailGUI::class);
   235         $mailer->autoresponder()->disableAutoresponder();
   242         $draftFolderId = $this->mbox->getDraftsFolder();
   246             $this->
refinery->kindlyTo()->listOf(
   247                 $this->
refinery->custom()->transformation($this->
refinery->kindlyTo()->string())
   256         if ($errors = $this->umail->validateRecipients(
   261             $this->requestAttachments = $files;
   271             $draftId = $this->umail->getNewDraftId($draftFolderId);
   274         $this->umail->updateDraft(
   290         $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_saved'), 
true);
   295             $this->
ctrl->redirectByClass([ilMailGUI::class, ilMailFolderGUI::class]);
   303         $this->tpl->setTitle($this->
lng->txt(
'mail'));
   308                 $this->
refinery->kindlyTo()->listOf(
   309                     $this->
refinery->custom()->transformation(
function ($elm): 
string {
   310                         $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
   312                         return urldecode($attachment);
   319             $this->umail->persistToStage(
   320                 $this->
user->getId(),
   334         $form->setId(
'search_rcp');
   335         $form->setTitle($this->
lng->txt(
'search_recipients'));
   336         $form->setFormAction($this->
ctrl->getFormAction($this, 
'search'));
   340         $dsDataLink = $this->
ctrl->getLinkTarget($this, 
'lookupRecipientAsync', 
'', 
true);
   341         $inp->setDataSource($dsDataLink);
   343         $searchQuery = trim((
string) 
ilSession::get(
'mail_search_search'));
   344         if ($searchQuery !== 
'') {
   347         $form->addItem($inp);
   349         $form->addCommandButton(
'search', $this->
lng->txt(
'search'));
   350         $form->addCommandButton(
'cancelSearch', $this->
lng->txt(
'cancel'));
   352         $this->tpl->setContent($form->getHTML());
   353         $this->tpl->printToStdout();
   361             $this->
ctrl->setParameterByClass(
'ilmailsearchcoursesgui', 
'cmd', 
'showMembers');
   364         $this->
ctrl->setParameterByClass(ilMailSearchCoursesGUI::class, 
'ref', 
'mail');
   365         $this->
ctrl->redirectByClass(ilMailSearchCoursesGUI::class);
   372         $this->
ctrl->setParameterByClass(ilMailSearchGroupsGUI::class, 
'ref', 
'mail');
   373         $this->
ctrl->redirectByClass(ilMailSearchGroupsGUI::class);
   379             'mail_search_search',
   384             $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"mail_insert_query"));
   386         } elseif (strlen(trim(
ilSession::get(
'mail_search_search'))) < 3) {
   387             $this->
lng->loadLanguageModule(
'search');
   388             $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'search_minimum_three'));
   391             $this->
ctrl->setParameterByClass(
   392                 ilMailSearchGUI::class,
   396             $this->
ctrl->redirectByClass(ilMailSearchGUI::class);
   410             $this->
refinery->kindlyTo()->listOf(
   411                 $this->
refinery->custom()->transformation(
function ($elm): 
string {
   412                     $attachment = $this->
refinery->kindlyTo()->string()->transform($elm);
   414                     return urldecode($attachment);
   421         $this->umail->persistToStage(
   422             $this->
user->getId(),
   434         $this->
ctrl->redirectByClass(ilMailAttachmentGUI::class);
   439         $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
   445         $this->mail_form_type = self::MAIL_FORM_TYPE_SEARCH_RESULT;
   451         $this->mail_form_type = self::MAIL_FORM_TYPE_NEW;
   457         $this->mail_form_type = self::MAIL_FORM_TYPE_ROLE;
   463         $this->mail_form_type = self::MAIL_FORM_TYPE_REPLY;
   469         $this->mail_form_type = self::MAIL_FORM_TYPE_ATTACH;
   475         if (!$this->
http->wrapper()->query()->has(
'template_id')) {
   476             $this->
http->close();
   480             $template = $this->templateService->loadTemplateForId(
   481                 $this->
http->wrapper()->query()->retrieve(
'template_id', $this->
refinery->kindlyTo()->int())
   485             $this->
http->saveResponse(
   486                 $this->
http->response()
   487                     ->withHeader(ResponseHeader::CONTENT_TYPE, 
'application/json')
   488                     ->withBody(Streams::ofString(json_encode([
   489                         'm_subject' => $template->getSubject(),
   490                         'm_message' => $this->umail->appendSignature($template->getMessage()),
   491                     ], JSON_THROW_ON_ERROR)))
   496         $this->
http->sendResponse();
   497         $this->
http->close();
   502         $this->tpl->addBlockFile(
   508         $this->tpl->setTitle($this->
lng->txt(
'mail'));
   510         $this->
lng->loadLanguageModule(
'crs');
   513             $this->
tabs->setBackTarget(
   514                 $this->
lng->txt(
'back'),
   515                 $this->
ctrl->getLinkTarget($this, 
'cancelMail')
   520         $mailData[
'rcp_to'] = 
'';
   521         $mailData[
'rcp_cc'] = 
'';
   522         $mailData[
'rcp_bcc'] = 
'';
   523         $mailData[
'attachments'] = [];
   527         if ($this->mail_form_type !== 
'') {
   532             case self::MAIL_FORM_TYPE_REPLY:
   533                 $mailData = $this->umail->getMail($mailId);
   535                 $mailData[
'm_subject'] = $this->umail->formatReplySubject($mailData[
'm_subject'] ?? 
'');
   536                 $mailData[
'm_message'] = $this->umail->prependSignature(
   537                     $this->umail->formatReplyMessage($mailData[
'm_message'] ?? 
'')
   539                 $mailData[
'attachments'] = [];
   540                 $mailData[
'rcp_cc'] = 
'';
   541                 $mailData[
'rcp_to'] = $this->umail->formatReplyRecipient();
   544             case self::MAIL_FORM_TYPE_SEARCH_RESULT:
   545                 $mailData = $this->umail->retrieveFromStage();
   548                     $mailData = $this->umail->appendSearchResult(
   549                         $this->
refinery->kindlyTo()->listOf(
   550                             $this->
refinery->kindlyTo()->string()
   556                     $mailData = $this->umail->appendSearchResult(
   557                         $this->
refinery->kindlyTo()->listOf(
   558                             $this->
refinery->kindlyTo()->string()
   564                     $mailData = $this->umail->appendSearchResult(
   565                         $this->
refinery->kindlyTo()->listOf(
   566                             $this->
refinery->kindlyTo()->string()
   577             case self::MAIL_FORM_TYPE_ATTACH:
   578                 $mailData = $this->umail->retrieveFromStage();
   581             case self::MAIL_FORM_TYPE_DRAFT:
   583                 $mailData = $this->umail->getMail($mailId);
   588             case self::MAIL_FORM_TYPE_FORWARD:
   589                 $mailData = $this->umail->getMail($mailId);
   590                 $mailData[
'rcp_to'] = $mailData[
'rcp_cc'] = $mailData[
'rcp_bcc'] = 
'';
   591                 $mailData[
'm_subject'] = $this->umail->formatForwardSubject($mailData[
'm_subject'] ?? 
'');
   592                 $mailData[
'm_message'] = $this->umail->prependSignature($mailData[
'm_message'] ?? 
'');
   593                 if (is_array($mailData[
'attachments']) && count($mailData[
'attachments']) && $error = $this->mfile->adoptAttachments(
   594                     $mailData[
'attachments'],
   597                     $this->tpl->setOnScreenMessage(
'info', $error);
   601             case self::MAIL_FORM_TYPE_NEW:
   607                 $mailData[
'rcp_to'] = $to;
   613                 $mailData[
'rcp_cc'] = $cc;
   619                 $mailData[
'rcp_bcc'] = $bcc;
   621                 $mailData[
'm_message'] = 
'';
   623                     $mailData[
'm_message'] = $sig;
   624                     $mailData[
'm_message'] .= chr(13)
   629                 $mailData[
'm_message'] .= $this->umail->appendSignature(
'');
   636             case self::MAIL_FORM_TYPE_ROLE:
   638                 if ($this->
http->wrapper()->post()->has(
'roles')) {
   639                     $roles = $this->
http->wrapper()->post()->retrieve(
   644                     $roles = $this->
refinery->kindlyTo()->listOf(
   645                         $this->
refinery->kindlyTo()->string()
   654                 $mailData[
'm_message'] = 
'';
   656                     $mailData[
'm_message'] = $sig;
   657                     $mailData[
'm_message'] .= chr(13)
   663                 $additionalMessageText = 
'';
   664                 if ($this->
http->wrapper()->post()->has(
'additional_message_text')) {
   666                         'additional_message_text',
   667                         $this->
refinery->kindlyTo()->string()
   671                 $mailData[
'm_message'] .= $additionalMessageText
   674                     . $this->umail->appendSignature(
'');
   678             case self::MAIL_FORM_TYPE_ADDRESS:
   680                 if ($this->
http->wrapper()->query()->has(
'rcp')) {
   681                     $rcp = $this->
http->wrapper()->query()->retrieve(
'rcp', $this->
refinery->kindlyTo()->string());
   683                 $mailData[
'rcp_to'] = urldecode($rcp);
   687                 $mailData = $this->
http->request()->getParsedBody();
   688                 foreach ($mailData as 
$key => $value) {
   689                     if (is_string($value)) {
   695                 if ($this->requestAttachments) {
   702         $form_gui->setTitle($this->
lng->txt(
'compose'));
   703         $form_gui->setId(
'mail_compose_form');
   704         $form_gui->setName(
'mail_compose_form');
   705         $form_gui->setFormAction($this->
ctrl->getFormAction($this, 
'sendMessage'));
   707         $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
   709         $mail_form = 
'form_' . $form_gui->getName();
   711         $btn = $this->ui_factory->button()
   712                                 ->standard($this->
lng->txt(
'search_recipients'), 
'#')
   714                 document.getElementById('$id').addEventListener('click', function() {   715                     const frm = document.getElementById('$mail_form'),   716                         action = new URL(frm.action),   717                         action_params = new URLSearchParams(action.search);   719                     action_params.delete('cmd');   720                     action_params.append('cmd', 'searchUsers');   722                     action.search = action_params.toString();   724                     frm.action = action.href;   729         $this->
toolbar->addStickyItem($btn);
   731         $btn = $this->ui_factory->button()
   732                                 ->standard($this->
lng->txt(
'mail_my_courses'), 
'#')
   734                 document.getElementById('$id').addEventListener('click', function() {   735                     const frm = document.getElementById('$mail_form'),   736                         action = new URL(frm.action),   737                         action_params = new URLSearchParams(action.search);   739                     action_params.delete('cmd');   740                     action_params.append('cmd', 'searchCoursesTo');   742                     action.search = action_params.toString();   744                     frm.action = action.href;   749         $this->
toolbar->addComponent($btn);
   751         $btn = $this->ui_factory->button()
   752                                 ->standard($this->
lng->txt(
'mail_my_groups'), 
'#')
   754                 document.getElementById('$id').addEventListener('click', function() {   755                     const frm = document.getElementById('$mail_form'),   756                         action = new URL(frm.action),   757                         action_params = new URLSearchParams(action.search);   759                     action_params.delete('cmd');   760                     action_params.append('cmd', 'searchGroupsTo');   762                     action.search = action_params.toString();   764                     frm.action = action.href;   769         $this->
toolbar->addComponent($btn);
   772             $btn = $this->ui_factory->button()
   773                                     ->standard($this->
lng->txt(
'mail_my_mailing_lists'), 
'#')
   775                 document.getElementById('$id').addEventListener('click', function() {   776                     const frm = document.getElementById('$mail_form'),   777                         action = new URL(frm.action),   778                         action_params = new URLSearchParams(action.search);   780                     action_params.delete('cmd');   781                     action_params.append('cmd', 'searchMailingListsTo');   783                     action.search = action_params.toString();   785                     frm.action = action.href;   790             $this->
toolbar->addComponent($btn);
   793         $dsDataLink = $this->
ctrl->getLinkTarget($this, 
'lookupRecipientAsync', 
'', 
true);
   796         $inp->setMaxLength(null);
   797         $inp->setRequired(
true);
   799         $inp->setValue((
string) ($mailData[
'rcp_to'] ?? 
''));
   800         $inp->setDataSource($dsDataLink, 
',');
   801         $form_gui->addItem($inp);
   804         $inp->setMaxLength(null);
   806         $inp->setValue((
string) ($mailData[
'rcp_cc'] ?? 
''));
   807         $inp->setDataSource($dsDataLink, 
',');
   808         $form_gui->addItem($inp);
   811         $inp->setMaxLength(null);
   813         $inp->setValue($mailData[
'rcp_bcc'] ?? 
'');
   814         $inp->setDataSource($dsDataLink, 
',');
   815         $form_gui->addItem($inp);
   819         $inp->setRequired(
true);
   820         $inp->setValue((
string) ($mailData[
'm_subject'] ?? 
''));
   821         $form_gui->addItem($inp);
   825                 isset($mailData[
'attachments']) && is_array($mailData[
'attachments']) ?
   831         if (isset($mailData[
'attachments']) && is_array($mailData[
'attachments'])) {
   832             foreach ($mailData[
'attachments'] as 
$data) {
   833                 if (is_file($this->mfile->getMailPath() . 
'/' . $this->
user->getId() . 
'_' . 
$data)) {
   835                     $form_gui->addItem($hidden);
   836                     $size = filesize($this->mfile->getMailPath() . 
'/' . $this->
user->getId() . 
'_' . 
$data);
   838                     $att->addItem($label);
   839                     $hidden->setValue(urlencode($data));
   843         $form_gui->addItem($att);
   849             $mailData[
'use_placeholders'] = 
true;
   854                 $templates = $this->templateService->loadTemplatesForContextId(
$context->getId());
   855                 if ($templates !== []) {
   859                         $this->
lng->txt(
'mail_template_client'),
   861                         $this->
ctrl->getLinkTarget($this, 
'getTemplateDataById', 
'', 
true),
   862                         [
'm_subject' => 
false, 
'm_message' => 
true]
   865                     foreach ($templates as $template) {
   866                         $options[$template->getTplId()] = $template->
getTitle();
   868                         if (!isset($mailData[
'template_id']) && $template->isDefault()) {
   869                             $template_chb->setValue((
string) $template->getTplId());
   870                             $form_gui->getItemByPostVar(
'm_subject')->setValue($template->getSubject());
   871                             $mailData[
'm_message'] = $template->getMessage() . $this->umail->appendSignature(
   872                                 $mailData[
'm_message']
   876                     if (isset($mailData[
'template_id'])) {
   877                         $template_chb->setValue((
string) ((
int) $mailData[
'template_id']));
   881                     $template_chb->setInfo($this->
lng->txt(
'mail_template_client_info'));
   882                     $template_chb->setOptions([
'' => $this->
lng->txt(
'please_choose')] + $options);
   883                     $form_gui->addItem($template_chb);
   887                     '%s has been called with invalid context id: %s.',
   895         $inp->
setValue((
string) ($mailData[
'm_message'] ?? 
''));
   896         $inp->setRequired(
false);
   899         $form_gui->addItem($inp);
   902             $this->
lng->txt(
'mail_serial_letter_placeholders'),
   906         $chb->setChecked(isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders']);
   909             $this->
lng->txt(
'mail_form_placeholders_label'),
   915             $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'), 
'<br />'));
   917             $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(
'Services/Mail/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         $formattedErrors = $formatter->format($errors);
  1032         if ($formattedErrors !== 
'') {
  1033             $this->tpl->setOnScreenMessage(
'failure', $formattedErrors);
 
Interface GlobalHttpState. 
 
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...
 
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="")
 
withOnLoadCode(Closure $binder)
 
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)
 
static getInstanceByGlobalUser(ilObjUser $user=null)
 
This class represents a text area property in a property form. 
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
static clear(string $a_var)
 
static set(string $a_var, $a_val)
Set a value.