/**
     * _getMailBoxListData
     *
     * @access	public
     * @static
     * @return	array	Array of mails
     * 
     */
    public static function _getMailBoxListData()
    {
        global $ilDB;
        // initialize array
        $mails = array('cnt' => 0, 'cnt_unread' => 0, 'set' => array());
        // count query
        $queryCount = 'SELECT COUNT(mail_id) cnt FROM mail ' . 'LEFT JOIN usr_data ON usr_id = sender_id ' . 'WHERE user_id = %s ' . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) ' . 'AND folder_id = %s ' . 'UNION ALL ' . 'SELECT COUNT(mail_id) cnt FROM mail ' . 'LEFT JOIN usr_data ON usr_id = sender_id ' . 'WHERE user_id = %s ' . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) ' . 'AND folder_id = %s ' . 'AND m_status = %s';
        $res = $ilDB->queryf($queryCount, array('integer', 'integer', 'integer', 'integer', 'text'), array(self::$userId, self::$folderId, self::$userId, self::$folderId, 'unread'));
        $counter = 0;
        while ($cnt_row = $ilDB->fetchAssoc($res)) {
            if ($counter == 0) {
                $mails['cnt'] = $cnt_row['cnt'];
            } else {
                if ($counter == 1) {
                    $mails['cnt_unread'] = $cnt_row['cnt'];
                } else {
                    break;
                }
            }
            ++$counter;
        }
        $sortColumn = '';
        if (self::$orderColumn == 'rcp_to' && $ilDB->getDBType() == 'oracle') {
            $sortColumn = ", CAST(rcp_to AS VARCHAR2(4000)) SORTCOL";
        }
        if (self::$orderColumn == 'from') {
            // Because of the user id of automatically generated mails and ordering issues we have to do some magic
            $firstname = '
				,(CASE
					WHEN (usr_id = ' . ANONYMOUS_USER_ID . ') THEN firstname 
					ELSE ' . $ilDB->quote(ilMail::_getIliasMailerName(), 'text') . '
				END) fname
			';
        }
        // item query
        $query = 'SELECT mail.*' . $sortColumn . ' ' . $firstname . ' FROM mail ' . 'LEFT JOIN usr_data ON usr_id = sender_id ' . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) ' . 'WHERE user_id = %s ' . 'AND folder_id = %s';
        // order direction
        $orderDirection = '';
        if (in_array(strtolower(self::$orderDirection), array('desc', 'asc'))) {
            $orderDirection = self::$orderDirection;
        } else {
            $orderDirection = 'ASC';
        }
        // order column
        if (self::$orderColumn == 'rcp_to' && $ilDB->getDBType() == 'oracle') {
            $query .= ' ORDER BY SORTCOL ' . $orderDirection;
        } else {
            if (self::$orderColumn == 'from') {
                $query .= ' ORDER BY ' . ' fname ' . $orderDirection . ', ' . ' lastname ' . $orderDirection . ', ' . ' login ' . $orderDirection . ', ' . ' import_name ' . $orderDirection;
            } else {
                if (strlen(self::$orderColumn)) {
                    if (!in_array(strtolower(self::$orderColumn), array('m_subject', 'send_time', 'rcp_to')) && !$ilDB->tableColumnExists('mail', strtolower(self::$orderColumn))) {
                        // @todo: Performance problem...
                        self::$orderColumn = 'send_time';
                    }
                    $query .= ' ORDER BY ' . strtolower(self::$orderColumn) . ' ' . $orderDirection;
                } else {
                    $query .= ' ORDER BY send_time DESC';
                }
            }
        }
        $ilDB->setLimit(self::$limit, self::$offset);
        $res = $ilDB->queryF($query, array('integer', 'integer'), array(self::$userId, self::$folderId));
        while ($row = $ilDB->fetchAssoc($res)) {
            $row['attachments'] = unserialize(stripslashes($row['attachments']));
            $row['m_type'] = unserialize(stripslashes($row['m_type']));
            $mails['set'][] = $row;
        }
        return $mails;
    }
 /**
  * get flat bookmark list for personal desktop
  */
 public function fillRow($mail)
 {
     global $ilCtrl, $lng;
     $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
     if ($this->getCurrentDetailLevel() > 2) {
         $this->tpl->touchBlock('usr_image_space');
         if ($user && $user->getId() != ANONYMOUS_USER_ID) {
             $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
             $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
             $this->tpl->setVariable('ALT_SENDER', $user->getPublicName());
         } else {
             if (!$user) {
                 $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
                 $this->tpl->setCurrentBlock('image_container');
                 $this->tpl->touchBlock('image_container');
                 $this->tpl->parseCurrentBlock();
             } else {
                 $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
                 $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIcon.png'));
                 $this->tpl->setVariable('ALT_SENDER', ilMail::_getIliasMailerName());
             }
         }
         $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
     } else {
         if ($user && $user->getId() != ANONYMOUS_USER_ID) {
             $this->tpl->setVariable('PUBLIC_NAME_SHORT', $user->getPublicName());
         } else {
             if (!$user) {
                 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
             } else {
                 $this->tpl->setVariable('PUBLIC_NAME_SHORT', ilMail::_getIliasMailerName());
             }
         }
     }
     $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
     $ilCtrl->setParameter($this, 'mobj_id', $this->inbox);
     $ilCtrl->setParameter($this, 'mail_id', $mail['mail_id']);
     $ilCtrl->setParameter($this, 'mail_mode', $this->mail_mode);
     $this->tpl->setVariable('NEW_MAIL_LINK_READ', $ilCtrl->getLinkTarget($this, 'showMail'));
     $ilCtrl->clearParameters($this);
 }
 /**
  * fetchTableData
  * @access	protected
  * @return	ilMailFolderTableGUI
  *
  */
 protected function fetchTableData()
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     // table title
     if ($this->_folderNode['m_type'] == 'user_folder') {
         $txt_folder = $this->_folderNode['title'];
         $img_folder = 'icon_user_folder.png';
     } else {
         $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
         $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
     }
     try {
         if ($this->isLuceneSearchEnabled()) {
             include_once 'Services/Mail/classes/class.ilMailLuceneQueryParser.php';
             $query_parser = new ilMailLuceneQueryParser($this->filter['mail_filter']);
             $query_parser->setFields(array('title' => (bool) $this->filter['mail_filter_subject'], 'content' => (bool) $this->filter['mail_filter_body'], 'mattachment' => (bool) $this->filter['mail_filter_attach'], 'msender' => (bool) $this->filter['mail_filter_sender'], 'mrcp' => (bool) $this->filter['mail_filter_recipients']));
             $query_parser->parse();
             require_once 'Services/Mail/classes/class.ilMailLuceneSearcher.php';
             require_once 'Services/Mail/classes/class.ilMailSearchResult.php';
             $result = new ilMailSearchResult();
             $searcher = new ilMailLuceneSearcher($query_parser, $result);
             $searcher->search($ilUser->getId(), $this->_currentFolderId);
             if (!$result->getIds()) {
                 throw new ilException('mail_search_empty_result');
             }
             ilMailBoxQuery::$filtered_ids = $result->getIds();
             ilMailBoxQuery::$filter = array();
         } else {
             ilMailBoxQuery::$filter = (array) $this->filter;
         }
         $this->determineOffsetAndOrder();
         ilMailBoxQuery::$folderId = $this->_currentFolderId;
         ilMailBoxQuery::$userId = $ilUser->getId();
         ilMailBoxQuery::$limit = $this->getLimit();
         ilMailBoxQuery::$offset = $this->getOffset();
         ilMailBoxQuery::$orderDirection = $this->getOrderDirection();
         ilMailBoxQuery::$orderColumn = $this->getOrderField();
         $data = ilMailBoxQuery::_getMailBoxListData();
         if (!count($data['set']) && $this->getOffset() > 0) {
             $this->resetOffset();
             ilMailBoxQuery::$limit = $this->getLimit();
             ilMailBoxQuery::$offset = $this->getOffset();
             $data = ilMailBoxQuery::_getMailBoxListData();
         }
     } catch (Exception $e) {
         $this->setTitleData($txt_folder, 0, 0, $img_folder);
         if ('mail_search_empty_result' == $e->getMessage()) {
             $data['set'] = array();
             $data['cnt'] = 0;
         } else {
             throw $e;
         }
     }
     if (!$this->isDraftFolder() && !$this->isSentFolder()) {
         $user_ids = array();
         foreach ($data['set'] as $mail) {
             if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
                 $user_ids[$mail['sender_id']] = $mail['sender_id'];
             }
         }
         ilMailUserCache::preloadUserObjects($user_ids);
     }
     $counter = 0;
     foreach ($data['set'] as $key => $mail) {
         ++$counter;
         if (is_array($this->getSelectedItems()) && in_array($mail['mail_id'], $this->getSelectedItems())) {
             $mail['checked'] = ' checked="checked" ';
         }
         if ($this->isDraftFolder() || $this->isSentFolder()) {
             $mail['rcp_to'] = $mail['mail_login'] = $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']);
         } else {
             if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
                 $mail['img_sender'] = ilUtil::getImagePath('HeaderIconAvatar.svg');
                 $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = ilMail::_getIliasMailerName();
             } else {
                 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
                 if ($user) {
                     $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
                     $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = $user->getPublicName();
                 } else {
                     $mail['from'] = $mail['mail_login'] = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
                 }
             }
         }
         if ($this->isDraftFolder()) {
             $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
             $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
             $link_mark_as_read = $this->ctrl->getLinkTargetByClass('ilmailformgui');
             $this->ctrl->clearParametersByClass('ilmailformgui');
         } else {
             $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
             $link_mark_as_read = $this->ctrl->getLinkTarget($this->_parentObject, 'showMail');
             $this->ctrl->clearParameters($this->_parentObject);
         }
         $css_class = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
         if ($this->isLuceneSearchEnabled()) {
             $search_result = array();
             foreach ($result->getFields($mail['mail_id']) as $content) {
                 if ('title' == $content[0]) {
                     $mail['msr_subject_link_read'] = $link_mark_as_read;
                     $mail['msr_subject_mailclass'] = $css_class;
                     $mail['msr_subject'] = $content[1];
                 } else {
                     $search_result[] = $content[1];
                 }
             }
             $mail['msr_data'] = implode('', array_map(function ($value) {
                 return '<p>' . $value . '</p>';
             }, $search_result));
             if (!$mail['msr_subject']) {
                 $mail['msr_subject_link_read'] = $link_mark_as_read;
                 $mail['msr_subject_mailclass'] = $css_class;
                 $mail['msr_subject'] = htmlspecialchars($mail['m_subject']);
             }
         } else {
             $mail['mail_link_read'] = $link_mark_as_read;
             $mail['mailclass'] = $css_class;
             $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
         }
         $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
         $data['set'][$key] = $mail;
     }
     $this->setData($data['set']);
     $this->setMaxCount($data['cnt']);
     $this->setNumerOfMails($data['cnt']);
     $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
     return $this;
 }
 /**
  * Get Mail HTML for Personal Desktop Mail Display
  */
 public function getPDMailHTML($a_mail_id, $a_mobj_id)
 {
     global $lng, $rbacsystem, $ilias;
     $lng->loadLanguageModule('mail');
     //get the mail from user
     $umail = new ilMail($_SESSION['AccountId']);
     // catch hack attempts
     if (!$rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
         $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->WARNING);
     }
     $umail->markRead(array($a_mail_id));
     $mail_data = $umail->getMail($a_mail_id);
     $tpl = new ilTemplate('tpl.pd_mail.html', true, true, 'Services/Mail');
     // attachments
     if ($mail_data['attachments']) {
         foreach ($mail_data['attachments'] as $file) {
             $tpl->setCurrentBlock('a_row');
             $tpl->setVariable('HREF_DOWNLOAD', 'ilias.php?baseClass=ilMailGUI&amp;type=deliverFile&amp;mail_id=' . $_GET['mail_id'] . '&amp;filename=' . md5($file));
             $tpl->setVariable('FILE_NAME', $file);
             $tpl->setVariable('TXT_DOWNLOAD', $lng->txt('download'));
             $tpl->parseCurrentBlock();
         }
         $tpl->setCurrentBlock('attachment');
         $tpl->setVariable('TXT_ATTACHMENT', $lng->txt('attachments'));
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable('TXT_FROM', $lng->txt('from'));
     /**
      * @var $sender ilObjUser
      */
     $sender = ilObjectFactory::getInstanceByObjId($mail_data['sender_id'], false);
     if ($sender && $sender->getId() != ANONYMOUS_USER_ID) {
         $tpl->setCurrentBlock('pers_image');
         $tpl->setVariable('IMG_SENDER', $sender->getPersonalPicturePath('xsmall'));
         $tpl->setVariable('ALT_SENDER', $sender->getPublicName());
         $tpl->parseCurrentBlock();
         $tpl->setVariable('PUBLIC_NAME', $sender->getPublicName());
     } else {
         if (!$sender) {
             $tpl->setVariable('PUBLIC_NAME', $mail_data['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
         } else {
             $tpl->setCurrentBlock('pers_image');
             $tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.png'));
             $tpl->setVariable('ALT_SENDER', ilMail::_getIliasMailerName());
             $tpl->parseCurrentBlock();
             $tpl->setVariable('PUBLIC_NAME', ilMail::_getIliasMailerName());
         }
     }
     $tpl->setVariable('TXT_TO', $lng->txt('mail_to'));
     $tpl->setVariable('TO', $umail->formatNamesForOutput($mail_data['rcp_to']));
     if ($mail_data['rcp_cc']) {
         $tpl->setCurrentBlock('cc');
         $tpl->setVariable('TXT_CC', $lng->txt('cc'));
         $tpl->setVariable('CC', $umail->formatNamesForOutput($mail_data['rcp_cc']));
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable('TXT_SUBJECT', $lng->txt('subject'));
     $tpl->setVariable('SUBJECT', htmlspecialchars($mail_data['m_subject']));
     $tpl->setVariable('TXT_DATE', $lng->txt('date'));
     $tpl->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($mail_data['send_time'], IL_CAL_DATETIME)));
     $tpl->setVariable('TXT_MESSAGE', $lng->txt('message'));
     // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
     $tpl->setVariable('MAIL_MESSAGE', nl2br(ilUtil::makeClickable(htmlspecialchars(ilUtil::securePlainString($mail_data['m_message'])))));
     return $tpl->get();
 }
 /**
  * Print mail
  */
 public function printMail()
 {
     /**
      * @var $tpl ilTemplate
      */
     global $tpl;
     $tplprint = new ilTemplate('tpl.mail_print.html', true, true, 'Services/Mail');
     $tplprint->setVariable('JSPATH', $tpl->tplPath);
     $mailData = $this->umail->getMail((int) $_GET['mail_id']);
     /**
      * @var $sender ilObjUser
      */
     $sender = ilObjectFactory::getInstanceByObjId($mailData['sender_id'], false);
     $tplprint->setVariable('TXT_FROM', $this->lng->txt('from'));
     if ($sender && $sender->getId() && $sender->getId() != ANONYMOUS_USER_ID) {
         $tplprint->setVariable('FROM', $sender->getPublicName());
     } else {
         if (!$sender || !$sender->getId()) {
             $tplprint->setVariable('FROM', $mailData['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
         } else {
             $tplprint->setVariable('FROM', ilMail::_getIliasMailerName());
         }
     }
     $tplprint->setVariable('TXT_TO', $this->lng->txt('mail_to'));
     $tplprint->setVariable('TO', $mailData['rcp_to']);
     if ($mailData['rcp_cc']) {
         $tplprint->setCurrentBlock('cc');
         $tplprint->setVariable('TXT_CC', $this->lng->txt('cc'));
         $tplprint->setVariable('CC', $mailData['rcp_cc']);
         $tplprint->parseCurrentBlock();
     }
     if ($mailData['rcp_bcc']) {
         $tplprint->setCurrentBlock('bcc');
         $tplprint->setVariable('TXT_BCC', $this->lng->txt('bc'));
         $tplprint->setVariable('BCC', $mailData['rcp_bcc']);
         $tplprint->parseCurrentBlock();
     }
     $tplprint->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
     $tplprint->setVariable('SUBJECT', htmlspecialchars($mailData['m_subject']));
     $tplprint->setVariable('TXT_DATE', $this->lng->txt('date'));
     $tplprint->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'], IL_CAL_DATETIME)));
     $tplprint->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
     $tplprint->setVariable('MAIL_MESSAGE', nl2br(htmlspecialchars($mailData['m_message'])));
     $tplprint->show();
 }
    public function send()
    {
        global $ilDB, $lng, $ilSetting;
        $is_message_enabled = $ilSetting->get("mail_notification_message");
        $res = $ilDB->queryF('SELECT mail.* FROM mail_options
						INNER JOIN mail ON mail.user_id = mail_options.user_id
						INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
						WHERE cronjob_notification = %s
						AND send_time >= %s
						AND m_status = %s', array('integer', 'timestamp', 'text'), array(1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'unread'));
        $users = array();
        $user_id = 0;
        while ($row = $ilDB->fetchAssoc($res)) {
            if ($user_id == 0 || $row['user_id'] != $user_id) {
                $user_id = $row['user_id'];
            }
            $users[$user_id][] = $row;
        }
        foreach ($users as $user_id => $mail_data) {
            $this->initLanguage($user_id);
            $user_lang = $this->getLanguage() ? $this->getLanguage() : $lng;
            $this->initMail();
            $this->setRecipients($user_id);
            $this->setSubject($this->getLanguageText('mail_notification_subject'));
            $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
            $this->appendBody("\n\n");
            if (count($mail_data) == 1) {
                $this->appendBody(sprintf($user_lang->txt('mail_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
            } else {
                $this->appendBody(sprintf($user_lang->txt('mails_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
            }
            $this->appendBody("\n\n");
            $counter = 1;
            foreach ($mail_data as $mail) {
                $this->appendBody("----------------------------------------------------------------------------------------------");
                $this->appendBody("\n\n");
                $this->appendBody('#' . $counter . "\n\n");
                $this->appendBody($user_lang->txt('date') . ": " . $mail['send_time']);
                $this->appendBody("\n");
                if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
                    $sender = ilMail::_getIliasMailerName();
                } else {
                    $sender = ilObjUser::_lookupLogin($mail['sender_id']);
                }
                $this->appendBody($user_lang->txt('sender') . ": " . $sender);
                $this->appendBody("\n");
                $this->appendBody($user_lang->txt('subject') . ": " . $mail['m_subject']);
                $this->appendBody("\n\n");
                if ($is_message_enabled == true) {
                    $this->appendBody($user_lang->txt('message') . ": " . $mail['m_message']);
                    $this->appendBody("\n\n");
                }
                ++$counter;
            }
            $this->appendBody("----------------------------------------------------------------------------------------------");
            $this->appendBody("\n\n");
            $this->appendBody($user_lang->txt('follow_link_to_read_mails') . " ");
            $this->appendBody("\n");
            $mailbox_link = ilUtil::_getHttpPath();
            $mailbox_link .= "/goto.php?target=mail&client_id=" . CLIENT_ID;
            $this->appendBody($mailbox_link);
            $this->appendBody("\n\n");
            $this->appendBody(ilMail::_getAutoGeneratedMessageString($this->getLanguage()));
            $this->appendBody(ilMail::_getInstallationSignature());
            $mmail = new ilMimeMail();
            $mmail->autoCheck(false);
            $mmail->From(ilMail::getIliasMailerAddress());
            $mmail->To(ilObjUser::_lookupEmail($user_id));
            $mmail->Subject($this->getSubject());
            $mmail->Body($this->getBody());
            $mmail->Send();
        }
    }
 /**
  * fetchTableData
  * @access	protected
  * @return	ilMailFolderTableGUI
  *
  */
 protected function fetchTableData()
 {
     global $ilUser;
     $this->determineOffsetAndOrder();
     require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
     ilMailBoxQuery::$folderId = $this->_currentFolderId;
     ilMailBoxQuery::$userId = $ilUser->getId();
     ilMailBoxQuery::$limit = $this->getLimit();
     ilMailBoxQuery::$offset = $this->getOffset();
     ilMailBoxQuery::$orderDirection = $this->getOrderDirection();
     ilMailBoxQuery::$orderColumn = $this->getOrderField();
     $data = ilMailBoxQuery::_getMailBoxListData();
     if (!count($data['set']) && $this->getOffset() > 0) {
         $this->resetOffset();
         ilMailBoxQuery::$limit = $this->getLimit();
         ilMailBoxQuery::$offset = $this->getOffset();
         $data = ilMailBoxQuery::_getMailBoxListData();
     }
     if (!$this->isDraftFolder() && !$this->isSentFolder()) {
         $user_ids = array();
         foreach ($data['set'] as $mail) {
             if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
                 $user_ids[$mail['sender_id']] = $mail['sender_id'];
             }
         }
         ilMailUserCache::preloadUserObjects($user_ids);
     }
     $counter = 0;
     foreach ($data['set'] as $key => $mail) {
         ++$counter;
         if (is_array($this->getSelectedItems()) && in_array($mail['mail_id'], $this->getSelectedItems())) {
             $mail['checked'] = ' checked="checked" ';
         }
         if ($this->isDraftFolder() || $this->isSentFolder()) {
             $mail['rcp_to'] = $mail['mail_login'] = $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']);
         } else {
             if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
                 $mail['img_sender'] = ilUtil::getImagePath('HeaderIcon.png');
                 $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = ilMail::_getIliasMailerName();
             } else {
                 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
                 if ($user) {
                     $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
                     $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = $user->getPublicName();
                 } else {
                     $mail['from'] = $mail['mail_login'] = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
                 }
             }
         }
         $mail['mailclass'] = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
         if ($this->isDraftFolder()) {
             $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
             $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
             $mail['mail_link_read'] = $this->ctrl->getLinkTargetByClass('ilmailformgui');
             $this->ctrl->clearParametersByClass('ilmailformgui');
         } else {
             $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
             $mail['mail_link_read'] = $this->ctrl->getLinkTarget($this->_parentObject, 'showMail');
             $this->ctrl->clearParameters($this->_parentObject);
         }
         $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
         $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
         $data['set'][$key] = $mail;
     }
     $this->setData($data['set']);
     $this->setMaxCount($data['cnt']);
     $this->setNumerOfMails($data['cnt']);
     // table title
     $txt_folder = '';
     $img_folder = '';
     if ($this->_folderNode['m_type'] == 'user_folder') {
         $txt_folder = $this->_folderNode['title'];
         $img_folder = 'icon_user_folder.png';
     } else {
         $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
         $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
     }
     $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
     return $this;
 }