33
44use crate :: models;
55
6+ use diesel:: Connection ;
67use futures:: Future ;
78use melib;
89use melib:: backends:: imap:: {
@@ -20,9 +21,12 @@ use std::time::{Duration, SystemTime};
2021
2122use std:: pin:: Pin ;
2223
24+ type ConnectionMutexType = Arc < FutureMutex < ImapConnection > > ;
25+
2326#[ derive( Debug ) ]
2427pub struct ImapBackend {
25- pub connection : Arc < FutureMutex < ImapConnection > > ,
28+ pub connection : ConnectionMutexType ,
29+ pub messages_fetch_connection : ConnectionMutexType ,
2630 pub server_conf : ImapServerConf ,
2731}
2832
@@ -235,6 +239,11 @@ pub fn create_connection(server_conf: &ImapServerConf, event_consumer: BackendEv
235239
236240pub type ResultFuture < T > = Result < Pin < Box < dyn Future < Output = Result < T , MeliError > > + Send + ' static > > , MeliError > ;
237241
242+ pub enum ConnectionType {
243+ Backend ,
244+ MessagesFetch ,
245+ }
246+
238247impl ImapBackend {
239248 pub fn new (
240249 server_hostname : String ,
@@ -245,7 +254,6 @@ impl ImapBackend {
245254 use_tls : bool ,
246255 use_starttls : bool ,
247256 danger_accept_invalid_certs : bool ,
248- event_consumer : BackendEventConsumer ,
249257 ) -> Result < Box < ImapBackend > , MeliError > {
250258 let server_conf = ImapServerConf {
251259 server_hostname,
@@ -266,13 +274,24 @@ impl ImapBackend {
266274 } ;
267275
268276 Ok ( Box :: new ( ImapBackend {
269- connection : Arc :: new ( FutureMutex :: new ( create_connection ( & server_conf, event_consumer) ) ) ,
277+ connection : Arc :: new ( FutureMutex :: new ( create_connection (
278+ & server_conf,
279+ BackendEventConsumer :: new ( Arc :: new ( |_, _| { } ) ) ,
280+ ) ) ) ,
281+ messages_fetch_connection : Arc :: new ( FutureMutex :: new ( create_connection (
282+ & server_conf,
283+ BackendEventConsumer :: new ( Arc :: new ( |_, _| { } ) ) ,
284+ ) ) ) ,
270285 server_conf,
271286 } ) )
272287 }
273288
274- pub fn is_online ( & self ) -> ResultFuture < ( ) > {
275- let connection = self . connection . clone ( ) ;
289+ pub fn is_online ( & self , connection_type : ConnectionType ) -> ResultFuture < ( ) > {
290+ let connection = match connection_type {
291+ ConnectionType :: Backend => self . connection . clone ( ) ,
292+ ConnectionType :: MessagesFetch => self . messages_fetch_connection . clone ( ) ,
293+ } ;
294+
276295 let timeout_dur = self . server_conf . timeout ;
277296 Ok ( Box :: pin ( async move {
278297 match timeout ( timeout_dur, connection. lock ( ) ) . await {
@@ -373,7 +392,7 @@ impl ImapBackend {
373392 }
374393
375394 pub fn fetch_message_content ( & self , imap_path : & String , uid : i64 ) -> ResultFuture < String > {
376- let connection_clone = self . connection . clone ( ) ;
395+ let connection_clone = self . messages_fetch_connection . clone ( ) ;
377396 let timeout_dur = self . server_conf . timeout ;
378397 let imap_path_clone = imap_path. clone ( ) ;
379398
0 commit comments