@@ -502,7 +502,6 @@ impl MailBackend for JmapType {
502502 . read ( )
503503 . unwrap ( )
504504 . iter ( )
505- . filter ( |( _, f) | f. is_subscribed )
506505 . map ( |( & h, f) | ( h, BackendMailbox :: clone ( f) as Mailbox ) )
507506 . collect ( ) ;
508507
@@ -769,7 +768,6 @@ impl MailBackend for JmapType {
769768 . read ( )
770769 . unwrap ( )
771770 . iter ( )
772- . filter ( |( _, f) | f. is_subscribed )
773771 . map ( |( & h, f) | ( h, BackendMailbox :: clone ( f) as Mailbox ) )
774772 . collect ( ) ;
775773 let id = new_mailboxes
@@ -784,12 +782,82 @@ impl MailBackend for JmapType {
784782
785783 fn delete_mailbox (
786784 & mut self ,
787- _mailbox_hash : MailboxHash ,
785+ mailbox_hash : MailboxHash ,
788786 ) -> ResultFuture < HashMap < MailboxHash , Mailbox > > {
789- Err (
790- Error :: new ( "Deleting a mailbox is currently unimplemented for the JMAP backend." )
791- . set_kind ( ErrorKind :: NotImplemented ) ,
792- )
787+ let mailbox_id: Id < mailbox:: MailboxObject > = {
788+ let mailboxes_lck = self . store . mailboxes . read ( ) . unwrap ( ) ;
789+ let Some ( id) = mailboxes_lck. get ( & mailbox_hash) . map ( |m| m. id . clone ( ) ) else {
790+ return Err (
791+ Error :: new ( format ! ( "Mailbox with hash {} not found" , mailbox_hash) )
792+ . set_kind ( ErrorKind :: NotFound ) ,
793+ ) ;
794+ } ;
795+ id
796+ } ;
797+ let store = self . store . clone ( ) ;
798+ let connection = self . connection . clone ( ) ;
799+ Ok ( Box :: pin ( async move {
800+ let mut conn = connection. lock ( ) . await ;
801+ let mail_account_id = conn. session_guard ( ) . await ?. mail_account_id ( ) ;
802+ let mailbox_state = store. mailbox_state . lock ( ) . await . clone ( ) ;
803+
804+ let mailbox_set_call = mailbox:: MailboxSet :: new (
805+ Set :: < mailbox:: MailboxObject > :: new ( mailbox_state)
806+ . account_id ( mail_account_id)
807+ . destroy ( Some ( vec ! [ mailbox_id. into( ) ] ) ) ,
808+ ) ;
809+
810+ let mut req = Request :: new ( conn. request_no . clone ( ) ) ;
811+ let _prev_seq = req. add_call ( & mailbox_set_call) . await ;
812+
813+ let res_text = conn
814+ . post_async ( None , serde_json:: to_string ( & req) ?)
815+ . await ?
816+ . text ( )
817+ . await ?;
818+
819+ let mut v: MethodResponse = match deserialize_from_str ( & res_text) {
820+ Err ( err) => {
821+ _ = store. online_status . set ( None , Err ( err. clone ( ) ) ) . await ;
822+ return Err ( err) ;
823+ }
824+ Ok ( s) => s,
825+ } ;
826+ store. online_status . update_timestamp ( None ) . await ;
827+ let SetResponse {
828+ not_destroyed,
829+ new_state,
830+ ..
831+ } = SetResponse :: < mailbox:: MailboxObject > :: try_from ( v. method_responses . remove ( 0 ) ) ?;
832+ * store. mailbox_state . lock ( ) . await = Some ( new_state) ;
833+ if let Some ( ids) = not_destroyed {
834+ if !ids. is_empty ( ) {
835+ return Err ( Error :: new ( format ! (
836+ "Could not delete mailbox: {}" ,
837+ ids. iter( )
838+ . map( |err| err. to_string( ) )
839+ . collect:: <Vec <String >>( )
840+ . join( "," )
841+ ) ) ) ;
842+ }
843+ }
844+ conn. add_refresh_event ( RefreshEvent {
845+ account_hash : store. account_hash ,
846+ mailbox_hash,
847+ kind : RefreshEventKind :: MailboxDelete ( mailbox_hash) ,
848+ } ) ;
849+ let new_mailboxes = protocol:: get_mailboxes ( & mut conn, None ) . await ?;
850+ * store. mailboxes . write ( ) . unwrap ( ) = new_mailboxes;
851+
852+ let new_mailboxes: HashMap < MailboxHash , Mailbox > = store
853+ . mailboxes
854+ . read ( )
855+ . unwrap ( )
856+ . iter ( )
857+ . map ( |( & h, f) | ( h, BackendMailbox :: clone ( f) as Mailbox ) )
858+ . collect ( ) ;
859+ Ok ( new_mailboxes)
860+ } ) )
793861 }
794862
795863 fn set_mailbox_subscription (
0 commit comments