@@ -555,6 +555,8 @@ public function process() {
555555 if (array_key_exists (strtolower ($ folder ), $ spcial_folders )) {
556556 $ this ->out ('core_msg_control_folder ' , $ spcial_folders [strtolower ($ folder )]);
557557 }
558+
559+ $ this ->out ('is_trash_folder ' , is_imap_trash_folder ($ this , $ parts [1 ], $ folder ));
558560 if (!empty ($ details )) {
559561 if (array_key_exists ('folder_label ' , $ this ->request ->get )) {
560562 $ folder = $ this ->request ->get ['folder_label ' ];
@@ -1133,13 +1135,14 @@ class Hm_Handler_imap_message_action extends Hm_Handler_Module {
11331135 public function process () {
11341136 list ($ success , $ form ) = $ this ->process_form (array ('action_type ' , 'message_ids ' ));
11351137 if ($ success ) {
1136- if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' ))) {
1138+ if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' , ' restore ' ))) {
11371139 $ ids = process_imap_message_ids ($ form ['message_ids ' ]);
11381140 $ errs = 0 ;
11391141 $ msgs = 0 ;
11401142 $ moved = array ();
11411143 $ status = array ();
11421144 foreach ($ ids as $ server => $ folders ) {
1145+ // die($server);
11431146 $ specials = get_special_folders ($ this , $ server );
11441147 $ mailbox = Hm_IMAP_List::get_connected_mailbox ($ server , $ this ->cache );
11451148 if ($ mailbox && $ mailbox ->authed ()) {
@@ -1157,6 +1160,7 @@ public function process() {
11571160 }
11581161 }
11591162 }
1163+ // die(var_dump($errs));
11601164 if ($ errs > 0 ) {
11611165 Hm_Msgs::add (sprintf ('An error occurred trying to %s some messages! ' , $ form ['action_type ' ], $ server ), 'danger ' );
11621166 }
@@ -1191,6 +1195,11 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
11911195 $ moved = array ();
11921196 $ folder_name = hex2bin ($ folder );
11931197 $ special_folder = $ this ->get_special_folder ($ action_type , $ specials , $ server_details );
1198+ if ($ action_type == "restore " && !$ special_folder ) {
1199+ $ special_folder = 'INBOX ' ;
1200+ }
1201+
1202+ // die(var_dump($specials));
11941203
11951204 if ($ special_folder && $ special_folder != $ folder_name ) {
11961205 if ($ this ->user_config ->get ('original_folder_setting ' , false )) {
@@ -1207,20 +1216,26 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
12071216 }
12081217 }
12091218 } else {
1210- if (!$ mailbox ->message_action ($ folder_name , mb_strtoupper ($ action_type ), $ uids )['status ' ]) {
1219+
1220+ $ status = $ mailbox ->message_action ($ folder_name , mb_strtoupper ($ action_type ), $ uids )['status ' ];
1221+ // var_dump("xxxxxxxxxx", $status, "---------");
1222+ if (!$ status ) {
12111223 $ error = true ;
1224+
12121225 } else {
1226+ // var_dump("xxxx ok xxxxxx $action_type - $folder_name");
12131227 foreach ($ uids as $ uid ) {
12141228 $ moved [] = sprintf ("imap_%s_%s_%s " , $ server_details ['id ' ], $ uid , $ folder );
12151229 }
12161230 if ($ action_type == 'delete ' ) {
12171231 $ mailbox ->message_action ($ folder_name , 'EXPUNGE ' , $ uids );
1218- }
1232+ }
12191233 }
12201234 }
1235+ // die(var_dump($special_folder, $folder_name, $folder, $action_type, "xxxxxxx"));
12211236
12221237 $ folderNotFoundError = false ;
1223- if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' ) {
1238+ if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' && $ action_type != ' restore ' ) {
12241239 Hm_Msgs::add (sprintf ('No %s folder configured for %s. Please go to <a href="?page=folders&imap_server_id=%s">Folders seetting</a> and configure one ' , $ action_type , $ server_details ['name ' ], $ server_details ['id ' ]), empty ($ moved ) ? 'danger ' : 'warning ' );
12251240 $ folderNotFoundError = true ;
12261241 }
@@ -1249,6 +1264,8 @@ private function get_special_folder($action_type, $specials, $server_details) {
12491264 $ folder = $ specials ['archive ' ];
12501265 } elseif ($ action_type == 'junk ' && array_key_exists ('junk ' , $ specials )) {
12511266 $ folder = $ specials ['junk ' ];
1267+ } elseif ($ action_type == 'restore ' ) {
1268+ $ folder = $ specials ['inbox ' ];
12521269 }
12531270 return $ folder ;
12541271 }
@@ -1983,6 +2000,8 @@ public function process() {
19832000 $ this ->session ->set (sprintf ('reply_details_imap_%s_%s_%s ' , $ form ['imap_server_id ' ], $ form ['folder ' ], $ form ['imap_msg_uid ' ]),
19842001 array ('ts ' => time (), 'msg_struct ' => $ msg_struct_current , 'msg_text ' => ($ save_reply_text ? $ msg_text : '' ), 'msg_headers ' => $ msg_headers ));
19852002 }
2003+
2004+ $ this ->out ('is_trash_folder ' , is_imap_trash_folder ($ this , $ form ['imap_server_id ' ], hex2bin ($ form ['folder ' ])));
19862005 }
19872006 }
19882007 }
@@ -2164,3 +2183,51 @@ function process_ceo_amount_limit_callback($val) { return $val; }
21642183 process_site_setting ('ceo_rate_limit ' , $ this , 'process_ceo_amount_limit_callback ' );
21652184 }
21662185}
2186+
2187+ /**
2188+ * Restore a message from trash to inbox
2189+ * @subpackage imap/handler
2190+ */
2191+ class Hm_Handler_imap_restore_message extends Hm_Handler_Module {
2192+ public function process () {
2193+ list ($ success , $ form ) = $ this ->process_form (array ('imap_msg_uid ' , 'imap_server_id ' , 'folder ' ));
2194+
2195+ if (!$ success ) {
2196+ return ;
2197+ }
2198+
2199+ $ restore_result = false ;
2200+ $ inbox_folder = 'INBOX ' ;
2201+ $ form_folder = hex2bin ($ form ['folder ' ]);
2202+ $ errors = 0 ;
2203+ $ status = false ;
2204+ $ mailbox = Hm_IMAP_List::get_connected_mailbox ($ form ['imap_server_id ' ], $ this ->cache );
2205+ if ($ mailbox && $ mailbox ->authed ()) {
2206+ $ inbox_exists = count ($ mailbox ->get_folder_status ($ inbox_folder ));
2207+ if (!$ inbox_exists ) {
2208+ Hm_Msgs::add ('INBOX folder does not exist ' , 'danger ' );
2209+ $ errors ++;
2210+ }
2211+
2212+ if (!$ errors ) {
2213+ $ result = $ mailbox ->message_action ($ form_folder , 'MOVE ' , array ($ form ['imap_msg_uid ' ]), $ inbox_folder );
2214+ $ status = $ result ['status ' ] ?? false ;
2215+ }
2216+
2217+ $ this ->out ('folder_status ' , array ('imap_ ' .$ form ['imap_server_id ' ].'_ ' .$ form ['folder ' ] => $ mailbox ->get_folder_state ()));
2218+ } else {
2219+ Hm_Msgs::add ('Unable to connect to IMAP server ' , 'danger ' );
2220+ $ errors ++;
2221+ }
2222+
2223+ if ($ status ) {
2224+ $ restore_result = true ;
2225+ Hm_Msgs::add ('Message restored to inbox ' );
2226+ } else {
2227+ Hm_Msgs::add ('An error occurred restoring the message ' , 'danger ' );
2228+ }
2229+
2230+ $ this ->save_hm_msgs ();
2231+ $ this ->out ('restore_result ' , $ restore_result );
2232+ }
2233+ }
0 commit comments