Skip to content

Commit

Permalink
Added snooze functionnality to imap
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Jul 3, 2023
1 parent 6c1c758 commit 21bd58e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ function parse_snooze_header($snooze_header)
{
$snooze_header = str_replace('X-Snoozed: ', '', $snooze_header);
$result = [];
foreach (explode(';', str_replace("\r\n", " ", $snooze_header)) as $kv)
foreach (explode(';', $snooze_header) as $kv)
{
$kv = trim($kv);
$spacePos = strpos($kv, ' ');
Expand Down
21 changes: 13 additions & 8 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function process() {
}
}
elseif (count($moved) == 0) {
Hm_Msgs::add('ERR Unable to move/copy selected messages');
Hm_Msgs::add('ERRUnable to move/copy selected messages');
}
if ($form['imap_move_action'] == 'move' && $form['imap_move_page'] == 'message') {
$msgs = Hm_Msgs::get();
Expand Down Expand Up @@ -942,7 +942,7 @@ public function process() {
if ($form['imap_snooze_until'] != 'unsnooze') {
$at = date('D, d M Y H:i:s O');
$until = get_snooze_date($form['imap_snooze_until']);
$snooze_tag = "X-Snoozed: at $at;\n \tuntil $until";
$snooze_tag = "X-Snoozed: at $at; until $until";
}
$ids = explode(',', $form['imap_snooze_ids']);
foreach ($ids as $msg_part) {
Expand Down Expand Up @@ -987,16 +987,21 @@ public function process() {
$imap = Hm_IMAP_List::connect($server_id, $cache);
if (imap_authed($imap)) {
$folder = 'Snoozed';
if (!count($imap->get_mailbox_status($folder))) {
continue;
}
$ret = $imap->get_mailbox_page($folder, 'DATE', false, 'ALL');
foreach ($ret[1] as $msg) {
$msg_headers = $imap->get_message_headers($msg['uid']);
try {
$snooze_headers = parse_snooze_header($msg_headers['X-Snoozed']);
if (new DateTime($snooze_headers['until']) <= new DateTime()) {
snooze_message($imap, $msg['uid'], $folder, null);
if (isset($msg_headers['X-Snoozed'])) {
try {
$snooze_headers = parse_snooze_header($msg_headers['X-Snoozed']);
if (new DateTime($snooze_headers['until']) <= new DateTime()) {
snooze_message($imap, $msg['uid'], $folder, null);
}
} catch (Exception $e) {
Hm_Debug::add(sprintf('ERR Cannot unsnooze message: %s', $msg_headers['subject']));
}
} catch (Exception $e) {
Hm_Debug::add(sprintf('ERR Cannot unsnooze message: %s', $msg_headers['subject']));
}
}
}
Expand Down

0 comments on commit 21bd58e

Please sign in to comment.