1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 07:36:44 +02:00

IMAP: Delete message

Also support mailboxes with spaces
This commit is contained in:
Jakub Vrana
2025-03-18 12:35:36 +01:00
parent 753642630b
commit 693dc5b8a7

View File

@@ -4,7 +4,8 @@
* - list messages in each mailbox - limit and offset works but there's no search and order * - list messages in each mailbox - limit and offset works but there's no search and order
* - for each message, there's subject, from, to, date and some flags * - for each message, there's subject, from, to, date and some flags
* - editing the message shows some other information * - editing the message shows some other information
* - inserting, deleting or updating the message does nothing * - deleting marks the message for deletion but doesn't expunge the mailbox
* - inserting or updating the message does nothing
*/ */
namespace Adminer; namespace Adminer;
@@ -36,30 +37,33 @@ if (isset($_GET["imap"])) {
} }
function query($query, $unbuffered = false) { function query($query, $unbuffered = false) {
if (!preg_match('~^SELECT (.+)\sFROM (\w+)(?:\sWHERE uid = (\d+))?.*?(?:\sLIMIT (\d+)(?:\sOFFSET (\d+))?)?~s', $query, $match)) { if (preg_match('~DELETE FROM "(.+?)"~', $query)) {
return false; preg_match_all('~"uid" = (\d+)~', $query, $matches);
} imap_delete($this->imap, implode(",", $matches[1]), FT_UID);
list(, $columns, $table, $uid, $limit, $offset) = $match; } elseif (preg_match('~^SELECT (.+)\sFROM "(.+?)"(?:\sWHERE "uid" = (\d+))?.*?(?:\sLIMIT (\d+)(?:\sOFFSET (\d+))?)?~s', $query, $match)) {
if ($uid) { list(, $columns, $table, $uid, $limit, $offset) = $match;
$return = array((array) imap_fetchstructure($this->imap, $uid, FT_UID)); if ($uid) {
} else { $return = array((array) imap_fetchstructure($this->imap, $uid, FT_UID));
imap_reopen($this->imap, "$this->mailbox$table"); } else {
$check = imap_check($this->imap); imap_reopen($this->imap, "$this->mailbox$table");
$range = ($offset + 1) . ":" . ($limit ? min($check->Nmsgs, $offset + $limit) : $check->Nmsgs); $check = imap_check($this->imap);
$return = array(); $range = ($offset + 1) . ":" . ($limit ? min($check->Nmsgs, $offset + $limit) : $check->Nmsgs);
$fields = fields($table); $return = array();
$columns = ($columns == "*" ? $fields : array_flip(explode(", ", $columns))); $fields = fields($table);
$empty = array_fill_keys(array_keys($fields), null); $columns = ($columns == "*" ? $fields : array_flip(explode(", ", $columns)));
foreach (imap_fetch_overview($this->imap, $range) as $row) { $empty = array_fill_keys(array_keys($fields), null);
// imap_utf8 doesn't work with some strings foreach (imap_fetch_overview($this->imap, $range) as $row) {
$row->subject = iconv_mime_decode($row->subject, 2, "utf-8"); // imap_utf8 doesn't work with some strings
$row->from = iconv_mime_decode($row->from, 2, "utf-8"); $row->subject = iconv_mime_decode($row->subject, 2, "utf-8");
$row->to = iconv_mime_decode($row->to, 2, "utf-8"); $row->from = iconv_mime_decode($row->from, 2, "utf-8");
$row->udate = gmdate("Y-m-d H:i:s", $row->udate); $row->to = iconv_mime_decode($row->to, 2, "utf-8");
$return[] = array_intersect_key(array_merge($empty, (array) $row), $columns); $row->udate = gmdate("Y-m-d H:i:s", $row->udate);
$return[] = array_intersect_key(array_merge($empty, (array) $row), $columns);
}
} }
return new Result($return);
} }
return new Result($return); return false;
} }
function quote($string) { function quote($string) {
@@ -181,7 +185,7 @@ if (isset($_GET["imap"])) {
} }
function idf_escape($idf) { function idf_escape($idf) {
return $idf; //! maybe {} return '"' . str_replace('"', '""', $idf) . '"';
} }
function table($idf) { function table($idf) {