19 declare(strict_types=1);
37 'markMailsRead' =>
'',
38 'markMailsUnread' =>
'',
45 'd_drafts' =>
'drafts',
60 $this->
lng = $DIC->language();
61 $this->db = $DIC->database();
62 $this->table_mail_obj_data =
'mail_obj_data';
63 $this->table_tree =
'mail_tree';
65 $this->mtree =
new ilTree($this->usrId);
66 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
71 if (is_object($this->
lng)) {
72 $this->
lng->loadLanguageModule(
"mail");
75 'moveMails' => $this->
lng->txt(
'mail_move_to'),
76 'markMailsRead' => $this->
lng->txt(
'mail_mark_read'),
77 'markMailsUnread' => $this->
lng->txt(
'mail_mark_unread'),
78 'deleteMails' => $this->
lng->txt(
'delete'),
85 $res = $this->db->queryF(
86 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
88 [$this->usrId,
'root']
91 $row = $this->db->fetchAssoc(
$res);
93 return (
int) $row[
'obj_id'];
98 $res = $this->db->queryF(
99 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
101 [$this->usrId,
'inbox']
104 $row = $this->db->fetchAssoc(
$res);
106 return (
int) $row[
'obj_id'];
111 $res = $this->db->queryF(
112 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
114 [$this->usrId,
'drafts']
117 $row = $this->db->fetchAssoc(
$res);
119 return (
int) $row[
'obj_id'];
124 $res = $this->db->queryF(
125 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
127 [$this->usrId,
'trash']
130 $row = $this->db->fetchAssoc(
$res);
132 return (
int) $row[
'obj_id'];
137 $res = $this->db->queryF(
138 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND m_type = %s',
140 [$this->usrId,
'sent']
143 $row = $this->db->fetchAssoc(
$res);
145 return (
int) $row[
'obj_id'];
161 $rootFolderId = $this->db->nextId($this->table_mail_obj_data);
162 $this->db->manipulateF(
163 'INSERT INTO ' . $this->table_mail_obj_data .
164 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
165 [
'integer',
'integer',
'text',
'text'],
166 [$rootFolderId, $this->usrId,
'a_root',
'root']
168 $this->mtree->addTree($this->usrId, $rootFolderId);
170 foreach ($this->defaultFolders as
$key => $folder) {
171 $last_id = $this->db->nextId($this->table_mail_obj_data);
172 $this->db->manipulateF(
173 'INSERT INTO ' . $this->table_mail_obj_data .
174 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
175 [
'integer',
'integer',
'text',
'text'],
176 [$last_id, $this->usrId,
$key, $folder]
178 $this->mtree->insertNode($last_id, $rootFolderId);
188 $nextId = $this->db->nextId($this->table_mail_obj_data);
189 $this->db->manipulateF(
190 'INSERT INTO ' . $this->table_mail_obj_data .
191 ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
192 [
'integer',
'integer',
'text',
'text'],
193 [$nextId, $this->usrId, $name,
'user_folder']
195 $this->mtree->insertNode($nextId, $parentFolderId);
206 $this->db->manipulateF(
207 'UPDATE ' . $this->table_mail_obj_data .
' SET title = %s WHERE obj_id = %s AND user_id = %s',
208 [
'text',
'integer',
'integer'],
209 [$name, $folderId, $this->usrId]
217 $res = $this->db->queryF(
218 'SELECT obj_id FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
220 [$this->usrId, $name]
222 $row = $this->db->fetchAssoc(
$res);
224 return is_array($row) && $row[
'obj_id'] > 0;
232 $query = $this->db->queryF(
233 'SELECT obj_id, title FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
234 [
'integer',
'integer'],
235 [$folderId, $this->usrId]
237 $row = $this->db->fetchAssoc($query);
239 if (!is_array($row) || array_key_exists($row[
'title'], $this->defaultFolders)) {
243 $mailer =
new ilMail($this->usrId);
245 $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folderId));
246 $this->mtree->deleteTree($this->mtree->getNodeData($folderId));
248 foreach ($subtree as $node) {
249 $nodeId = (
int) $node[
'obj_id'];
251 $mails = $mailer->getMailsOfFolder($nodeId);
254 foreach ($mails as $mail) {
255 $mailIds[] = (
int) $mail[
'mail_id'];
258 $mailer->deleteMails($mailIds);
260 $this->db->manipulateF(
261 'DELETE FROM ' . $this->table_mail_obj_data .
' WHERE obj_id = %s AND user_id = %s',
262 [
'integer',
'integer'],
263 [$nodeId, $this->usrId]
275 $res = $this->db->queryF(
276 'SELECT * FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND obj_id = %s',
277 [
'integer',
'integer'],
278 [$this->usrId, $folderId]
280 $row = $this->db->fetchAssoc(
$res);
282 if (is_array($row)) {
284 'obj_id' => (
int) $row[
'obj_id'],
285 'title' => (
string) $row[
'title'],
286 'type' => (string) $row[
'm_type'],
295 $res = $this->db->queryF(
296 'SELECT * FROM ' . $this->table_tree .
' WHERE child = %s AND tree = %s',
297 [
'integer',
'integer'],
298 [$folderId, $this->usrId]
300 $row = $this->db->fetchAssoc(
$res);
302 return is_array($row) ? (
int) $row[
'parent'] : 0;
309 foreach (array_keys($this->defaultFolders) as
$key) {
310 $res = $this->db->queryF(
311 'SELECT obj_id, m_type FROM ' . $this->table_mail_obj_data .
' WHERE user_id = %s AND title = %s',
315 $row = $this->db->fetchAssoc(
$res);
319 'type' => (string) $row[
'm_type'],
320 'obj_id' => (
int) $row[
'obj_id'],
324 $query = implode(
' ', [
325 'SELECT * FROM ' . $this->table_tree .
', ' . $this->table_mail_obj_data,
326 'WHERE ' . $this->table_mail_obj_data .
'.obj_id = ' . $this->table_tree .
'.child',
327 'AND ' . $this->table_tree .
'.depth > %s',
328 'AND ' . $this->table_tree .
'.tree = %s',
329 'ORDER BY ' . $this->table_tree .
'.lft, ' . $this->table_mail_obj_data .
'.title',
331 $res = $this->db->queryF(
333 [
'integer',
'integer'],
336 while ($row = $this->db->fetchAssoc(
$res)) {
338 'title' => (string) $row[
'title'],
339 'type' => (
string) $row[
'm_type'],
340 'obj_id' => (
int) $row[
'child'],
349 $this->usrId = $usrId;
357 public function delete():
void 359 $this->db->manipulateF(
360 'DELETE FROM mail_obj_data WHERE user_id = %s',
365 $this->db->manipulateF(
366 'DELETE FROM mail_options WHERE user_id = %s',
371 $this->db->manipulateF(
372 'DELETE FROM mail_saved WHERE user_id = %s',
377 $this->db->manipulateF(
378 'DELETE FROM mail_tree WHERE tree = %s',
383 $this->db->manipulateF(
384 'DELETE FROM mail_auto_responder WHERE sender_id = %s OR receiver_id = %s',
385 [
'integer',
'integer'],
386 [$this->usrId, $this->usrId]
392 $fdm->onUserDelete();
395 $this->db->manipulateF(
396 'DELETE FROM mail WHERE user_id = %s',
408 $this->db->manipulateF(
409 'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
410 [
'integer',
'text',
'integer'],
411 [0, $nameToShow, $this->usrId]
419 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.
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)
__construct(protected int $usrId)
deleteFolder(int $folderId)
array string $table_mail_obj_data
folderNameExists(string $name)
isOwnedFolder(int $folderId)