11use std:: cmp;
2- use std:: iter:: { self , once } ;
2+ use std:: iter;
33use std:: num:: NonZeroUsize ;
44use std:: sync:: atomic:: Ordering ;
55
@@ -214,21 +214,25 @@ impl SchedulerState {
214214 /// Indicate that the network likely has come back.
215215 pub ( crate ) async fn maybe_network ( & self ) {
216216 let inner = self . inner . read ( ) . await ;
217- let ( inbox , oboxes) = match * inner {
217+ let ( inboxes , oboxes) = match * inner {
218218 InnerSchedulerState :: Started ( ref scheduler) => {
219219 scheduler. maybe_network ( ) ;
220- let inbox = scheduler. inbox . conn_state . state . connectivity . clone ( ) ;
220+ let inboxes = scheduler
221+ . inboxes
222+ . iter ( )
223+ . map ( |b| b. conn_state . state . connectivity . clone ( ) )
224+ . collect :: < Vec < _ > > ( ) ;
221225 let oboxes = scheduler
222226 . oboxes
223227 . iter ( )
224228 . map ( |b| b. conn_state . state . connectivity . clone ( ) )
225229 . collect :: < Vec < _ > > ( ) ;
226- ( inbox , oboxes)
230+ ( inboxes , oboxes)
227231 }
228232 _ => return ,
229233 } ;
230234 drop ( inner) ;
231- connectivity:: idle_interrupted ( inbox , oboxes) ;
235+ connectivity:: idle_interrupted ( inboxes , oboxes) ;
232236 }
233237
234238 /// Indicate that the network likely is lost.
@@ -333,7 +337,8 @@ struct SchedBox {
333337/// Job and connection scheduler.
334338#[ derive( Debug ) ]
335339pub ( crate ) struct Scheduler {
336- inbox : SchedBox ,
340+ /// Inboxes, one per transport.
341+ inboxes : Vec < SchedBox > ,
337342 /// Optional boxes -- mvbox.
338343 oboxes : Vec < SchedBox > ,
339344 smtp : SmtpConnectionState ,
@@ -860,38 +865,40 @@ impl Scheduler {
860865 let ( ephemeral_interrupt_send, ephemeral_interrupt_recv) = channel:: bounded ( 1 ) ;
861866 let ( location_interrupt_send, location_interrupt_recv) = channel:: bounded ( 1 ) ;
862867
868+ let mut inboxes = Vec :: new ( ) ;
863869 let mut oboxes = Vec :: new ( ) ;
864870 let mut start_recvs = Vec :: new ( ) ;
865871
866- let ( transport_id, configured_login_param) = ConfiguredLoginParam :: load ( ctx)
867- . await ?
868- . context ( "Not configured" ) ?;
869- let ( conn_state, inbox_handlers) =
870- ImapConnectionState :: new ( ctx, transport_id, configured_login_param. clone ( ) ) . await ?;
871- let ( inbox_start_send, inbox_start_recv) = oneshot:: channel ( ) ;
872- let handle = {
873- let ctx = ctx. clone ( ) ;
874- task:: spawn ( inbox_loop ( ctx, inbox_start_send, inbox_handlers) )
875- } ;
876- let inbox = SchedBox {
877- meaning : FolderMeaning :: Inbox ,
878- conn_state,
879- handle,
880- } ;
881- start_recvs. push ( inbox_start_recv) ;
882-
883- if ctx. should_watch_mvbox ( ) . await ? {
884- let ( conn_state, handlers) = ImapConnectionState :: new ( ctx, transport_id, configured_login_param) . await ?;
885- let ( start_send, start_recv) = oneshot:: channel ( ) ;
886- let ctx = ctx. clone ( ) ;
887- let meaning = FolderMeaning :: Mvbox ;
888- let handle = task:: spawn ( simple_imap_loop ( ctx, start_send, handlers, meaning) ) ;
889- oboxes. push ( SchedBox {
890- meaning,
872+ for ( transport_id, configured_login_param) in ConfiguredLoginParam :: load_all ( ctx) . await ? {
873+ let ( conn_state, inbox_handlers) =
874+ ImapConnectionState :: new ( ctx, transport_id, configured_login_param. clone ( ) ) . await ?;
875+ let ( inbox_start_send, inbox_start_recv) = oneshot:: channel ( ) ;
876+ let handle = {
877+ let ctx = ctx. clone ( ) ;
878+ task:: spawn ( inbox_loop ( ctx, inbox_start_send, inbox_handlers) )
879+ } ;
880+ let inbox = SchedBox {
881+ meaning : FolderMeaning :: Inbox ,
891882 conn_state,
892883 handle,
893- } ) ;
894- start_recvs. push ( start_recv) ;
884+ } ;
885+ inboxes. push ( inbox) ;
886+ start_recvs. push ( inbox_start_recv) ;
887+
888+ if ctx. should_watch_mvbox ( ) . await ? {
889+ let ( conn_state, handlers) =
890+ ImapConnectionState :: new ( ctx, transport_id, configured_login_param) . await ?;
891+ let ( start_send, start_recv) = oneshot:: channel ( ) ;
892+ let ctx = ctx. clone ( ) ;
893+ let meaning = FolderMeaning :: Mvbox ;
894+ let handle = task:: spawn ( simple_imap_loop ( ctx, start_send, handlers, meaning) ) ;
895+ oboxes. push ( SchedBox {
896+ meaning,
897+ conn_state,
898+ handle,
899+ } ) ;
900+ start_recvs. push ( start_recv) ;
901+ }
895902 }
896903
897904 let smtp_handle = {
@@ -917,7 +924,7 @@ impl Scheduler {
917924 let recently_seen_loop = RecentlySeenLoop :: new ( ctx. clone ( ) ) ;
918925
919926 let res = Self {
920- inbox ,
927+ inboxes ,
921928 oboxes,
922929 smtp,
923930 smtp_handle,
@@ -937,8 +944,8 @@ impl Scheduler {
937944 Ok ( res)
938945 }
939946
940- fn boxes ( & self ) -> iter:: Chain < iter :: Once < & SchedBox > , std:: slice:: Iter < ' _ , SchedBox > > {
941- once ( & self . inbox ) . chain ( self . oboxes . iter ( ) )
947+ fn boxes ( & self ) -> iter:: Chain < std :: slice :: Iter < ' _ , SchedBox > , std:: slice:: Iter < ' _ , SchedBox > > {
948+ self . inboxes . iter ( ) . chain ( self . oboxes . iter ( ) )
942949 }
943950
944951 fn maybe_network ( & self ) {
@@ -956,7 +963,9 @@ impl Scheduler {
956963 }
957964
958965 fn interrupt_inbox ( & self ) {
959- self . inbox . conn_state . interrupt ( ) ;
966+ for b in & self . inboxes {
967+ b. conn_state . interrupt ( ) ;
968+ }
960969 }
961970
962971 fn interrupt_oboxes ( & self ) {
@@ -996,7 +1005,7 @@ impl Scheduler {
9961005 let timeout_duration = std:: time:: Duration :: from_secs ( 30 ) ;
9971006
9981007 let tracker = TaskTracker :: new ( ) ;
999- for b in once ( self . inbox ) . chain ( self . oboxes ) {
1008+ for b in self . inboxes . into_iter ( ) . chain ( self . oboxes . into_iter ( ) ) {
10001009 let context = context. clone ( ) ;
10011010 tracker. spawn ( async move {
10021011 tokio:: time:: timeout ( timeout_duration, b. handle )
0 commit comments