From bf3a8482abcad2ab8bbaf10ea039bb70ce070400 Mon Sep 17 00:00:00 2001 From: jmunro Date: Thu, 28 Feb 2002 23:15:27 +0000 Subject: [PATCH] fix for bug #512056, update filters when renaming/deleting folders git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2524 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 63e9dafa..f3082dbf 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -184,6 +184,7 @@ function sqimap_mailbox_delete ($imap_stream, $mailbox) $read_ary = sqimap_run_command($imap_stream, "DELETE \"$mailbox\"", TRUE, $response, $message); sqimap_unsubscribe ($imap_stream, $mailbox); + filter_check($mailbox, 'delete'); } /*********************************************************************** @@ -200,15 +201,47 @@ function sqimap_mailbox_is_subscribed($imap_stream, $folder) { return false; } +/* fix filters when renaming/deleting folders */ + +function filter_check ($old_folder, $action, $new_folder = 'INBOX') { + global $plugins, $data_dir, $username; + $filters = array(); + $count = count($plugins); + for ($i=0;$i<$count;$i++) { + if ($plugins[$i] == 'filters') { + require_once("../plugins/filters/filters.php"); + $filters = load_filters(); + break; + } + } + if (empty($filters)) { + return; + } + $filter_count = count($filters); + $p=0; + for ($i=0;$i<$filter_count;$i++) { + if ($old_folder == $filters[$i]['folder']) { + if ($action == 'rename') { + $filters[$i]['folder'] = $new_folder; + setPref($data_dir, $username, "filter".$i, $filters[$i]['where'].",".$filters[$i]['what'].",".$new_folder); + } + elseif ($action == 'delete') { + remove_filter($p); + $p = $p-1; + } + } + $p++; + } +} + + /* Renames a mailbox */ function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) { if ( $old_name <> $new_name ) { - global $delimiter, $imap_server_type; - if ( substr( $old_name, -1 ) == $delimiter ) { $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 ); $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 ); @@ -222,6 +255,7 @@ function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) { TRUE, $response, $message); sqimap_unsubscribe($imap_stream, $old_name.$postfix); sqimap_subscribe($imap_stream, $new_name.$postfix); + filter_check($old_name, 'rename', $new_name); $l = strlen( $old_name ) + 1; $p = 'unformatted'; foreach ( $boxesall as $box ) { @@ -234,6 +268,7 @@ function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) { } sqimap_unsubscribe($imap_stream, $box[$p]); sqimap_subscribe($imap_stream, $new_sub); + filter_check($box[$p], 'rename', $new_sub); } } } -- 2.25.1