1
1
use std:: collections:: HashSet ;
2
2
3
+ use async_std:: channel;
3
4
use async_std:: io;
4
5
use async_std:: prelude:: * ;
5
6
use async_std:: stream:: Stream ;
6
- use async_std:: sync;
7
7
use imap_proto:: { self , MailboxDatum , RequestId , Response } ;
8
8
9
9
use crate :: error:: { Error , Result } ;
@@ -12,7 +12,7 @@ use crate::types::*;
12
12
13
13
pub ( crate ) fn parse_names < ' a , T : Stream < Item = io:: Result < ResponseData > > + Unpin + Send > (
14
14
stream : & ' a mut T ,
15
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
15
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
16
16
command_tag : RequestId ,
17
17
) -> impl Stream < Item = Result < Name > > + ' a + Send + Unpin {
18
18
use futures:: { FutureExt , StreamExt } ;
@@ -58,7 +58,7 @@ fn filter_sync(res: &io::Result<ResponseData>, command_tag: &RequestId) -> bool
58
58
59
59
pub ( crate ) fn parse_fetches < ' a , T : Stream < Item = io:: Result < ResponseData > > + Unpin + Send > (
60
60
stream : & ' a mut T ,
61
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
61
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
62
62
command_tag : RequestId ,
63
63
) -> impl Stream < Item = Result < Fetch > > + ' a + Send + Unpin {
64
64
use futures:: { FutureExt , StreamExt } ;
@@ -87,7 +87,7 @@ pub(crate) fn parse_fetches<'a, T: Stream<Item = io::Result<ResponseData>> + Unp
87
87
88
88
pub ( crate ) fn parse_expunge < ' a , T : Stream < Item = io:: Result < ResponseData > > + Unpin + Send > (
89
89
stream : & ' a mut T ,
90
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
90
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
91
91
command_tag : RequestId ,
92
92
) -> impl Stream < Item = Result < u32 > > + ' a + Send {
93
93
use futures:: StreamExt ;
@@ -115,7 +115,7 @@ pub(crate) fn parse_expunge<'a, T: Stream<Item = io::Result<ResponseData>> + Unp
115
115
116
116
pub ( crate ) async fn parse_capabilities < ' a , T : Stream < Item = io:: Result < ResponseData > > + Unpin > (
117
117
stream : & ' a mut T ,
118
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
118
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
119
119
command_tag : RequestId ,
120
120
) -> Result < Capabilities > {
121
121
let mut caps: HashSet < Capability > = HashSet :: new ( ) ;
@@ -143,7 +143,7 @@ pub(crate) async fn parse_capabilities<'a, T: Stream<Item = io::Result<ResponseD
143
143
144
144
pub ( crate ) async fn parse_noop < T : Stream < Item = io:: Result < ResponseData > > + Unpin > (
145
145
stream : & mut T ,
146
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
146
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
147
147
command_tag : RequestId ,
148
148
) -> Result < ( ) > {
149
149
while let Some ( resp) = stream
@@ -160,7 +160,7 @@ pub(crate) async fn parse_noop<T: Stream<Item = io::Result<ResponseData>> + Unpi
160
160
161
161
pub ( crate ) async fn parse_mailbox < T : Stream < Item = io:: Result < ResponseData > > + Unpin > (
162
162
stream : & mut T ,
163
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
163
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
164
164
command_tag : RequestId ,
165
165
) -> Result < Mailbox > {
166
166
let mut mailbox = Mailbox :: default ( ) ;
@@ -252,7 +252,7 @@ pub(crate) async fn parse_mailbox<T: Stream<Item = io::Result<ResponseData>> + U
252
252
253
253
pub ( crate ) async fn parse_ids < T : Stream < Item = io:: Result < ResponseData > > + Unpin > (
254
254
stream : & mut T ,
255
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
255
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
256
256
command_tag : RequestId ,
257
257
) -> Result < HashSet < u32 > > {
258
258
let mut ids: HashSet < u32 > = HashSet :: new ( ) ;
@@ -282,7 +282,7 @@ pub(crate) async fn parse_ids<T: Stream<Item = io::Result<ResponseData>> + Unpin
282
282
// (see Section 7 of RFC 3501):
283
283
pub ( crate ) async fn handle_unilateral (
284
284
res : ResponseData ,
285
- unsolicited : sync :: Sender < UnsolicitedResponse > ,
285
+ unsolicited : channel :: Sender < UnsolicitedResponse > ,
286
286
) {
287
287
// ignore these if they are not being consumed
288
288
if unsolicited. is_full ( ) {
@@ -291,7 +291,7 @@ pub(crate) async fn handle_unilateral(
291
291
292
292
match res. parsed ( ) {
293
293
Response :: MailboxData ( MailboxDatum :: Status { mailbox, status } ) => {
294
- unsolicited
294
+ let _ = unsolicited
295
295
. send ( UnsolicitedResponse :: Status {
296
296
mailbox : ( * mailbox) . into ( ) ,
297
297
attributes : status
@@ -307,19 +307,23 @@ pub(crate) async fn handle_unilateral(
307
307
} )
308
308
. collect ( ) ,
309
309
} )
310
- . await ;
310
+ . await ; //TODO: decide what to do with result
311
311
}
312
312
Response :: MailboxData ( MailboxDatum :: Recent ( n) ) => {
313
- unsolicited. send ( UnsolicitedResponse :: Recent ( * n) ) . await ;
313
+ //TODO: decide what to do with result
314
+ let _ = unsolicited. send ( UnsolicitedResponse :: Recent ( * n) ) . await ;
314
315
}
315
316
Response :: MailboxData ( MailboxDatum :: Exists ( n) ) => {
316
- unsolicited. send ( UnsolicitedResponse :: Exists ( * n) ) . await ;
317
+ //TODO: decide what to do with result
318
+ let _ = unsolicited. send ( UnsolicitedResponse :: Exists ( * n) ) . await ;
317
319
}
318
320
Response :: Expunge ( n) => {
319
- unsolicited. send ( UnsolicitedResponse :: Expunge ( * n) ) . await ;
321
+ //TODO: decide what to do with result
322
+ let _ = unsolicited. send ( UnsolicitedResponse :: Expunge ( * n) ) . await ;
320
323
}
321
324
_ => {
322
- unsolicited. send ( UnsolicitedResponse :: Other ( res) ) . await ;
325
+ //TODO: decide what to do with result
326
+ let _ = unsolicited. send ( UnsolicitedResponse :: Other ( res) ) . await ;
323
327
}
324
328
}
325
329
}
@@ -350,7 +354,7 @@ mod tests {
350
354
input_stream ( & [ "* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r \n " ] ) ;
351
355
352
356
let mut stream = async_std:: stream:: from_iter ( responses) ;
353
- let ( send, recv) = sync :: channel ( 10 ) ;
357
+ let ( send, recv) = channel :: bounded ( 10 ) ;
354
358
let id = RequestId ( "A0001" . into ( ) ) ;
355
359
let capabilities = parse_capabilities ( & mut stream, send, id) . await . unwrap ( ) ;
356
360
// shouldn't be any unexpected responses parsed
@@ -368,7 +372,7 @@ mod tests {
368
372
let responses = input_stream ( & [ "* CAPABILITY IMAP4REV1 STARTTLS\r \n " ] ) ;
369
373
let mut stream = async_std:: stream:: from_iter ( responses) ;
370
374
371
- let ( send, recv) = sync :: channel ( 10 ) ;
375
+ let ( send, recv) = channel :: bounded ( 10 ) ;
372
376
let id = RequestId ( "A0001" . into ( ) ) ;
373
377
let capabilities = parse_capabilities ( & mut stream, send, id) . await . unwrap ( ) ;
374
378
@@ -383,7 +387,7 @@ mod tests {
383
387
#[ async_std:: test]
384
388
#[ should_panic]
385
389
async fn parse_capability_invalid_test ( ) {
386
- let ( send, recv) = sync :: channel ( 10 ) ;
390
+ let ( send, recv) = channel :: bounded ( 10 ) ;
387
391
let responses = input_stream ( & [ "* JUNK IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r \n " ] ) ;
388
392
let mut stream = async_std:: stream:: from_iter ( responses) ;
389
393
@@ -396,7 +400,7 @@ mod tests {
396
400
397
401
#[ async_std:: test]
398
402
async fn parse_names_test ( ) {
399
- let ( send, recv) = sync :: channel ( 10 ) ;
403
+ let ( send, recv) = channel :: bounded ( 10 ) ;
400
404
let responses = input_stream ( & [ "* LIST (\\ HasNoChildren) \" .\" \" INBOX\" \r \n " ] ) ;
401
405
let mut stream = async_std:: stream:: from_iter ( responses) ;
402
406
@@ -417,7 +421,7 @@ mod tests {
417
421
418
422
#[ async_std:: test]
419
423
async fn parse_fetches_empty ( ) {
420
- let ( send, recv) = sync :: channel ( 10 ) ;
424
+ let ( send, recv) = channel :: bounded ( 10 ) ;
421
425
let responses = input_stream ( & [ ] ) ;
422
426
let mut stream = async_std:: stream:: from_iter ( responses) ;
423
427
let id = RequestId ( "a" . into ( ) ) ;
@@ -432,7 +436,7 @@ mod tests {
432
436
433
437
#[ async_std:: test]
434
438
async fn parse_fetches_test ( ) {
435
- let ( send, recv) = sync :: channel ( 10 ) ;
439
+ let ( send, recv) = channel :: bounded ( 10 ) ;
436
440
let responses = input_stream ( & [
437
441
"* 24 FETCH (FLAGS (\\ Seen) UID 4827943)\r \n " ,
438
442
"* 25 FETCH (FLAGS (\\ Seen))\r \n " ,
@@ -462,7 +466,7 @@ mod tests {
462
466
#[ async_std:: test]
463
467
async fn parse_fetches_w_unilateral ( ) {
464
468
// https://github.com/mattnenterprise/rust-imap/issues/81
465
- let ( send, recv) = sync :: channel ( 10 ) ;
469
+ let ( send, recv) = channel :: bounded ( 10 ) ;
466
470
let responses = input_stream ( & [ "* 37 FETCH (UID 74)\r \n " , "* 1 RECENT\r \n " ] ) ;
467
471
let mut stream = async_std:: stream:: from_iter ( responses) ;
468
472
let id = RequestId ( "a" . into ( ) ) ;
@@ -480,7 +484,7 @@ mod tests {
480
484
481
485
#[ async_std:: test]
482
486
async fn parse_names_w_unilateral ( ) {
483
- let ( send, recv) = sync :: channel ( 10 ) ;
487
+ let ( send, recv) = channel :: bounded ( 10 ) ;
484
488
let responses = input_stream ( & [
485
489
"* LIST (\\ HasNoChildren) \" .\" \" INBOX\" \r \n " ,
486
490
"* 4 EXPUNGE\r \n " ,
@@ -506,7 +510,7 @@ mod tests {
506
510
507
511
#[ async_std:: test]
508
512
async fn parse_capabilities_w_unilateral ( ) {
509
- let ( send, recv) = sync :: channel ( 10 ) ;
513
+ let ( send, recv) = channel :: bounded ( 10 ) ;
510
514
let responses = input_stream ( & [
511
515
"* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r \n " ,
512
516
"* STATUS dev.github (MESSAGES 10 UIDNEXT 11 UIDVALIDITY 1408806928 UNSEEN 0)\r \n " ,
@@ -541,7 +545,7 @@ mod tests {
541
545
542
546
#[ async_std:: test]
543
547
async fn parse_ids_w_unilateral ( ) {
544
- let ( send, recv) = sync :: channel ( 10 ) ;
548
+ let ( send, recv) = channel :: bounded ( 10 ) ;
545
549
let responses = input_stream ( & [
546
550
"* SEARCH 23 42 4711\r \n " ,
547
551
"* 1 RECENT\r \n " ,
@@ -571,7 +575,7 @@ mod tests {
571
575
572
576
#[ async_std:: test]
573
577
async fn parse_ids_test ( ) {
574
- let ( send, recv) = sync :: channel ( 10 ) ;
578
+ let ( send, recv) = channel :: bounded ( 10 ) ;
575
579
let responses = input_stream ( & [
576
580
"* SEARCH 1600 1698 1739 1781 1795 1885 1891 1892 1893 1898 1899 1901 1911 1926 1932 1933 1993 1994 2007 2032 2033 2041 2053 2062 2063 2065 2066 2072 2078 2079 2082 2084 2095 2100 2101 2102 2103 2104 2107 2116 2120 2135 2138 2154 2163 2168 2172 2189 2193 2198 2199 2205 2212 2213 2221 2227 2267 2275 2276 2295 2300 2328 2330 2332 2333 2334\r \n " ,
577
581
"* SEARCH 2335 2336 2337 2338 2339 2341 2342 2347 2349 2350 2358 2359 2362 2369 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2390 2392 2397 2400 2401 2403 2405 2409 2411 2414 2417 2419 2420 2424 2426 2428 2439 2454 2456 2467 2468 2469 2490 2515 2519 2520 2521\r \n " ,
@@ -604,7 +608,7 @@ mod tests {
604
608
605
609
#[ async_std:: test]
606
610
async fn parse_ids_search ( ) {
607
- let ( send, recv) = sync :: channel ( 10 ) ;
611
+ let ( send, recv) = channel :: bounded ( 10 ) ;
608
612
let responses = input_stream ( & [ "* SEARCH\r \n " ] ) ;
609
613
let mut stream = async_std:: stream:: from_iter ( responses) ;
610
614
0 commit comments