19 declare(strict_types=1);
38 'markMailsRead' =>
'',
39 'markMailsUnread' =>
'',
46 'd_drafts' =>
'drafts',
61 $this->
lng = $DIC->language();
62 $this->db = $DIC->database();
64 $this->usrId = $a_user_id;
65 $this->table_mail_obj_data =
'mail_obj_data';
66 $this->table_tree =
'mail_tree';
68 $this->mtree =
new ilTree($this->usrId);
69 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
74 if (is_object($this->
lng)) {
75 $this->
lng->loadLanguageModule(
"mail");
78 'moveMails' => $this->
lng->txt(
'mail_move_to'),
79 'markMailsRead' => $this->
lng->txt(
'mail_mark_read'),
80 'markMailsUnread' => $this->
lng->txt(
'mail_mark_unread'),
81 'deleteMails' => $this->
lng->txt(
'delete'),
88 $res = $this->db->queryF(
89 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
91 [$this->usrId,
'root']
94 $row = $this->db->fetchAssoc(
$res);
96 return (
int) $row[
'obj_id'];
101 $res = $this->db->queryF(
102 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
104 [$this->usrId,
'inbox']
107 $row = $this->db->fetchAssoc(
$res);
109 return (
int) $row[
'obj_id'];
114 $res = $this->db->queryF(
115 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
117 [$this->usrId,
'drafts']
120 $row = $this->db->fetchAssoc(
$res);
122 return (
int) $row[
'obj_id'];
127 $res = $this->db->queryF(
128 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
130 [$this->usrId,
'trash']
133 $row = $this->db->fetchAssoc(
$res);
135 return (
int) $row[
'obj_id'];
140 $res = $this->db->queryF(
141 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
143 [$this->usrId,
'sent']
146 $row = $this->db->fetchAssoc(
$res);
148 return (
int) $row[
'obj_id'];
165 $rootFolderId = $this->db->nextId($this->table_mail_obj_data);
166 $this->db->manipulateF(
167 'INSERT INTO ' . $this->table_mail_obj_data .
168 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
169 [
'integer',
'integer',
'text',
'text'],
170 [$rootFolderId, $this->usrId,
'a_root',
'root']
172 $this->mtree->addTree($this->usrId, $rootFolderId);
174 foreach ($this->defaultFolders as
$key => $folder) {
175 $last_id = $this->db->nextId($this->table_mail_obj_data);
176 $this->db->manipulateF(
177 'INSERT INTO ' . $this->table_mail_obj_data .
178 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
179 [
'integer',
'integer',
'text',
'text'],
180 [$last_id, $this->usrId,
$key, $folder]
182 $this->mtree->insertNode($last_id, $rootFolderId);
192 $nextId = $this->db->nextId($this->table_mail_obj_data);
193 $this->db->manipulateF(
194 'INSERT INTO ' . $this->table_mail_obj_data .
195 ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
196 [
'integer',
'integer',
'text',
'text'],
197 [$nextId, $this->usrId, $name,
'user_folder']
199 $this->mtree->insertNode($nextId, $parentFolderId);
210 $this->db->manipulateF(
211 'UPDATE ' . $this->table_mail_obj_data .
' SET title = %s WHERE obj_id = %s AND user_id = %s',
212 [
'text',
'integer',
'integer'],
213 [$name, $folderId, $this->usrId]
221 $res = $this->db->queryF(
222 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
224 [$this->usrId, $name]
226 $row = $this->db->fetchAssoc(
$res);
228 return is_array($row) && $row[
'obj_id'] > 0;
236 $query = $this->db->queryF(
237 'SELECT obj_id, title FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
238 [
'integer',
'integer'],
239 [$folderId, $this->usrId]
241 $row = $this->db->fetchAssoc(
$query);
243 if (!is_array($row) || array_key_exists($row[
'title'], $this->defaultFolders)) {
247 $mailer =
new ilMail($this->usrId);
249 $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folderId));
250 $this->mtree->deleteTree($this->mtree->getNodeData($folderId));
252 foreach ($subtree as $node) {
253 $nodeId = (
int) $node[
'obj_id'];
255 $mails = $mailer->getMailsOfFolder($nodeId);
258 foreach ($mails as $mail) {
259 $mailIds[] = (
int) $mail[
'mail_id'];
262 $mailer->deleteMails($mailIds);
264 $this->db->manipulateF(
265 'DELETE FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
266 [
'integer',
'integer'],
267 [$nodeId, $this->usrId]
279 $res = $this->db->queryF(
280 'SELECT * FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND obj_id = %s',
281 [
'integer',
'integer'],
282 [$this->usrId, $folderId]
284 $row = $this->db->fetchAssoc(
$res);
286 if (is_array($row)) {
288 'obj_id' => (
int) $row[
'obj_id'],
289 'title' => (
string) $row[
'title'],
290 'type' => (string) $row[
'm_type'],
299 $res = $this->db->queryF(
300 'SELECT * FROM ' . $this->table_tree .
' WHERE child = %s AND tree = %s',
301 [
'integer',
'integer'],
302 [$folderId, $this->usrId]
304 $row = $this->db->fetchAssoc(
$res);
306 return is_array($row) ? (
int) $row[
'parent'] : 0;
313 foreach ($this->defaultFolders as
$key => $value) {
314 $res = $this->db->queryF(
315 'SELECT obj_id, m_type FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
319 $row = $this->db->fetchAssoc(
$res);
323 'type' => (string) $row[
'm_type'],
324 'obj_id' => (
int) $row[
'obj_id'],
329 'SELECT * FROM ' . $this->table_tree .
', ' . $this->table_mail_obj_data,
330 'WHERE ' . $this->table_mail_obj_data .
'.obj_id = ' . $this->table_tree .
'.child',
331 'AND ' . $this->table_tree .
'.depth > %s',
332 'AND ' . $this->table_tree .
'.tree = %s',
333 'ORDER BY ' . $this->table_tree .
'.lft, ' . $this->table_mail_obj_data .
'.title',
335 $res = $this->db->queryF(
337 [
'integer',
'integer'],
340 while ($row = $this->db->fetchAssoc(
$res)) {
342 'title' => (string) $row[
'title'],
343 'type' => (
string) $row[
'm_type'],
344 'obj_id' => (
int) $row[
'child'],
361 public function delete():
void 363 $this->db->manipulateF(
364 'DELETE FROM mail_obj_data WHERE user_id = %s',
369 $this->db->manipulateF(
370 'DELETE FROM mail_options WHERE user_id = %s',
375 $this->db->manipulateF(
376 'DELETE FROM mail_saved WHERE user_id = %s',
381 $this->db->manipulateF(
382 'DELETE FROM mail_tree WHERE tree = %s',
390 $fdm->onUserDelete();
393 $this->db->manipulateF(
394 'DELETE FROM mail WHERE user_id = %s',
406 $this->db->manipulateF(
407 'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
408 [
'integer',
'text',
'integer'],
409 [0, $nameToShow, $this->usrId]
417 return $folderData !== null && (
int) $folderData[
'obj_id'] === $folderId;
getActions(int $folderId)
addFolder(int $parentFolderId, string $name)
This class handles all operations on files (attachments) in directory ilias_data/mail.
updateMailsOfDeletedUser(string $nameToShow)
Update existing mails.
__construct(int $a_user_id)
Mail Box class Base class for creating and handling mail boxes.
createDefaultFolder()
Creates all default folders for a user.
getParentFolderId(int $folderId)
renameFolder(int $folderId, string $name)
getFolderData(int $folderId)
deleteFolder(int $folderId)
array string $table_mail_obj_data
folderNameExists(string $name)
isOwnedFolder(int $folderId)