@@ -555,6 +555,9 @@ 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 ));
560+
558561 if (!empty ($ details )) {
559562 if (array_key_exists ('folder_label ' , $ this ->request ->get )) {
560563 $ folder = $ this ->request ->get ['folder_label ' ];
@@ -1133,7 +1136,7 @@ class Hm_Handler_imap_message_action extends Hm_Handler_Module {
11331136 public function process () {
11341137 list ($ success , $ form ) = $ this ->process_form (array ('action_type ' , 'message_ids ' ));
11351138 if ($ success ) {
1136- if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' ))) {
1139+ if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' , ' restore ' ))) {
11371140 $ ids = process_imap_message_ids ($ form ['message_ids ' ]);
11381141 $ errs = 0 ;
11391142 $ msgs = 0 ;
@@ -1191,6 +1194,9 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
11911194 $ moved = array ();
11921195 $ folder_name = hex2bin ($ folder );
11931196 $ special_folder = $ this ->get_special_folder ($ action_type , $ specials , $ server_details );
1197+ if ($ action_type == "restore " && !$ special_folder ) {
1198+ $ special_folder = 'INBOX ' ;
1199+ }
11941200
11951201 if ($ special_folder && $ special_folder != $ folder_name ) {
11961202 if ($ this ->user_config ->get ('original_folder_setting ' , false )) {
@@ -1220,7 +1226,7 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
12201226 }
12211227
12221228 $ folderNotFoundError = false ;
1223- if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' ) {
1229+ if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' && $ action_type != ' restore ' ) {
12241230 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 ' );
12251231 $ folderNotFoundError = true ;
12261232 }
@@ -1249,6 +1255,8 @@ private function get_special_folder($action_type, $specials, $server_details) {
12491255 $ folder = $ specials ['archive ' ];
12501256 } elseif ($ action_type == 'junk ' && array_key_exists ('junk ' , $ specials )) {
12511257 $ folder = $ specials ['junk ' ];
1258+ } elseif ($ action_type == 'restore ' ) {
1259+ $ folder = $ specials ['inbox ' ];
12521260 }
12531261 return $ folder ;
12541262 }
@@ -1983,6 +1991,7 @@ public function process() {
19831991 $ this ->session ->set (sprintf ('reply_details_imap_%s_%s_%s ' , $ form ['imap_server_id ' ], $ form ['folder ' ], $ form ['imap_msg_uid ' ]),
19841992 array ('ts ' => time (), 'msg_struct ' => $ msg_struct_current , 'msg_text ' => ($ save_reply_text ? $ msg_text : '' ), 'msg_headers ' => $ msg_headers ));
19851993 }
1994+ $ this ->out ('is_trash_folder ' , is_imap_trash_folder ($ this , $ form ['imap_server_id ' ], hex2bin ($ form ['folder ' ])));
19861995 }
19871996 }
19881997 }
@@ -2164,3 +2173,51 @@ function process_ceo_amount_limit_callback($val) { return $val; }
21642173 process_site_setting ('ceo_rate_limit ' , $ this , 'process_ceo_amount_limit_callback ' );
21652174 }
21662175}
2176+
2177+ /**
2178+ * Restore a message from trash to inbox
2179+ * @subpackage imap/handler
2180+ */
2181+ class Hm_Handler_imap_restore_message extends Hm_Handler_Module {
2182+ public function process () {
2183+ list ($ success , $ form ) = $ this ->process_form (array ('imap_msg_uid ' , 'imap_server_id ' , 'folder ' ));
2184+
2185+ if (!$ success ) {
2186+ return ;
2187+ }
2188+
2189+ $ restore_result = false ;
2190+ $ inbox_folder = 'INBOX ' ;
2191+ $ form_folder = hex2bin ($ form ['folder ' ]);
2192+ $ errors = 0 ;
2193+ $ status = false ;
2194+ $ mailbox = Hm_IMAP_List::get_connected_mailbox ($ form ['imap_server_id ' ], $ this ->cache );
2195+ if ($ mailbox && $ mailbox ->authed ()) {
2196+ $ inbox_exists = count ($ mailbox ->get_folder_status ($ inbox_folder ));
2197+ if (!$ inbox_exists ) {
2198+ Hm_Msgs::add ('INBOX folder does not exist ' , 'danger ' );
2199+ $ errors ++;
2200+ }
2201+
2202+ if (!$ errors ) {
2203+ $ result = $ mailbox ->message_action ($ form_folder , 'MOVE ' , array ($ form ['imap_msg_uid ' ]), $ inbox_folder );
2204+ $ status = $ result ['status ' ] ?? false ;
2205+ }
2206+
2207+ $ this ->out ('folder_status ' , array ('imap_ ' .$ form ['imap_server_id ' ].'_ ' .$ form ['folder ' ] => $ mailbox ->get_folder_state ()));
2208+ } else {
2209+ Hm_Msgs::add ('Unable to connect to IMAP server ' , 'danger ' );
2210+ $ errors ++;
2211+ }
2212+
2213+ if ($ status ) {
2214+ $ restore_result = true ;
2215+ Hm_Msgs::add ('Message restored to inbox ' );
2216+ } else {
2217+ Hm_Msgs::add ('An error occurred restoring the message ' , 'danger ' );
2218+ }
2219+
2220+ $ this ->save_hm_msgs ();
2221+ $ this ->out ('restore_result ' , $ restore_result );
2222+ }
2223+ }
0 commit comments