@@ -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 ' ];
@@ -1138,7 +1141,7 @@ class Hm_Handler_imap_message_action extends Hm_Handler_Module {
11381141 public function process () {
11391142 list ($ success , $ form ) = $ this ->process_form (array ('action_type ' , 'message_ids ' ));
11401143 if ($ success ) {
1141- if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' ))) {
1144+ if (in_array ($ form ['action_type ' ], array ('delete ' , 'read ' , 'unread ' , 'flag ' , 'unflag ' , 'archive ' , 'junk ' , ' restore ' ))) {
11421145 $ ids = process_imap_message_ids ($ form ['message_ids ' ]);
11431146 $ errs = 0 ;
11441147 $ msgs = 0 ;
@@ -1196,6 +1199,9 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
11961199 $ moved = array ();
11971200 $ folder_name = hex2bin ($ folder );
11981201 $ special_folder = $ this ->get_special_folder ($ action_type , $ specials , $ server_details );
1202+ if ($ action_type == "restore " && !$ special_folder ) {
1203+ $ special_folder = 'INBOX ' ;
1204+ }
11991205
12001206 if ($ special_folder && $ special_folder != $ folder_name ) {
12011207 if ($ this ->user_config ->get ('original_folder_setting ' , false )) {
@@ -1225,7 +1231,7 @@ private function perform_action($mailbox, $action_type, $uids, $folder, $special
12251231 }
12261232
12271233 $ folderNotFoundError = false ;
1228- if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' ) {
1234+ if (!$ special_folder && $ action_type != 'read ' && $ action_type != 'unread ' && $ action_type != 'flag ' && $ action_type != 'unflag ' && $ action_type != ' restore ' ) {
12291235 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 ' );
12301236 $ folderNotFoundError = true ;
12311237 }
@@ -1254,6 +1260,8 @@ private function get_special_folder($action_type, $specials, $server_details) {
12541260 $ folder = $ specials ['archive ' ];
12551261 } elseif ($ action_type == 'junk ' && array_key_exists ('junk ' , $ specials )) {
12561262 $ folder = $ specials ['junk ' ];
1263+ } elseif ($ action_type == 'restore ' ) {
1264+ $ folder = $ specials ['inbox ' ];
12571265 }
12581266 return $ folder ;
12591267 }
@@ -1996,6 +2004,7 @@ public function process() {
19962004 $ this ->session ->set (sprintf ('reply_details_imap_%s_%s_%s ' , $ form ['imap_server_id ' ], $ form ['folder ' ], $ form ['imap_msg_uid ' ]),
19972005 array ('ts ' => time (), 'msg_struct ' => $ msg_struct_current , 'msg_text ' => ($ save_reply_text ? $ msg_text : '' ), 'msg_headers ' => $ msg_headers ));
19982006 }
2007+ $ this ->out ('is_trash_folder ' , is_imap_trash_folder ($ this , $ form ['imap_server_id ' ], hex2bin ($ form ['folder ' ])));
19992008 }
20002009 }
20012010 }
@@ -2177,3 +2186,51 @@ function process_ceo_amount_limit_callback($val) { return $val; }
21772186 process_site_setting ('ceo_rate_limit ' , $ this , 'process_ceo_amount_limit_callback ' );
21782187 }
21792188}
2189+
2190+ /**
2191+ * Restore a message from trash to inbox
2192+ * @subpackage imap/handler
2193+ */
2194+ class Hm_Handler_imap_restore_message extends Hm_Handler_Module {
2195+ public function process () {
2196+ list ($ success , $ form ) = $ this ->process_form (array ('imap_msg_uid ' , 'imap_server_id ' , 'folder ' ));
2197+
2198+ if (!$ success ) {
2199+ return ;
2200+ }
2201+
2202+ $ restore_result = false ;
2203+ $ inbox_folder = 'INBOX ' ;
2204+ $ form_folder = hex2bin ($ form ['folder ' ]);
2205+ $ errors = 0 ;
2206+ $ status = false ;
2207+ $ mailbox = Hm_IMAP_List::get_connected_mailbox ($ form ['imap_server_id ' ], $ this ->cache );
2208+ if ($ mailbox && $ mailbox ->authed ()) {
2209+ $ inbox_exists = count ($ mailbox ->get_folder_status ($ inbox_folder ));
2210+ if (!$ inbox_exists ) {
2211+ Hm_Msgs::add ('INBOX folder does not exist ' , 'danger ' );
2212+ $ errors ++;
2213+ }
2214+
2215+ if (!$ errors ) {
2216+ $ result = $ mailbox ->message_action ($ form_folder , 'MOVE ' , array ($ form ['imap_msg_uid ' ]), $ inbox_folder );
2217+ $ status = $ result ['status ' ] ?? false ;
2218+ }
2219+
2220+ $ this ->out ('folder_status ' , array ('imap_ ' .$ form ['imap_server_id ' ].'_ ' .$ form ['folder ' ] => $ mailbox ->get_folder_state ()));
2221+ } else {
2222+ Hm_Msgs::add ('Unable to connect to IMAP server ' , 'danger ' );
2223+ $ errors ++;
2224+ }
2225+
2226+ if ($ status ) {
2227+ $ restore_result = true ;
2228+ Hm_Msgs::add ('Message restored to inbox ' );
2229+ } else {
2230+ Hm_Msgs::add ('An error occurred restoring the message ' , 'danger ' );
2231+ }
2232+
2233+ $ this ->save_hm_msgs ();
2234+ $ this ->out ('restore_result ' , $ restore_result );
2235+ }
2236+ }
0 commit comments