Skip to content

Commit 7e0f08b

Browse files
committed
wip
1 parent 677e0df commit 7e0f08b

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

imap-codec/examples/client.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use imap_codec::{fragmentizer::Fragmentizer, GreetingCodec};
1+
use imap_codec::{fragmentizer::Fragmentizer, GreetingCodec, ResponseCodec};
22

33
#[path = "common/common.rs"]
44
mod common;
@@ -32,10 +32,7 @@ fn main() {
3232

3333
loop {
3434
// Progress next message.
35-
fragmentizer.progress();
36-
37-
// Does the Fragmentizer need more bytes?
38-
if fragmentizer.is_message_complete() {
35+
let Some(_fragment_info) = fragmentizer.progress() else {
3936
// Read more bytes ...
4037
read_more(&mut buffer, Role::Server);
4138

@@ -45,6 +42,10 @@ fn main() {
4542

4643
// ... and try again.
4744
continue;
45+
};
46+
47+
if !fragmentizer.is_message_complete() {
48+
continue;
4849
}
4950

5051
// The Fragmentizer detected a complete message.
@@ -64,7 +65,7 @@ fn main() {
6465
};
6566
}
6667
State::Response => {
67-
match fragmentizer.decode_message(&GreetingCodec::default()) {
68+
match fragmentizer.decode_message(&ResponseCodec::default()) {
6869
Ok(response) => {
6970
// Do something with the response.
7071
println!("{:#?}", response);

imap-codec/examples/server.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use imap_codec::{
2-
decode::{CommandDecodeError, Decoder},
3-
fragmentizer::{FragmentInfo, Fragmentizer},
2+
fragmentizer::{FragmentInfo, Fragmentizer, LiteralAnnouncement},
43
CommandCodec,
54
};
65

76
#[path = "common/common.rs"]
87
mod common;
98

109
use common::{read_more, COLOR_SERVER, RESET};
10+
use imap_types::core::LiteralMode;
1111

1212
use crate::common::Role;
1313

@@ -35,14 +35,27 @@ fn main() {
3535

3636
loop {
3737
// Progress next message.
38-
let fragment_info = fragmentizer.progress();
38+
let Some(fragment_info) = fragmentizer.progress() else {
39+
// Read more bytes ...
40+
read_more(&mut buffer, Role::Client);
41+
42+
// ... and pass the bytes to the Fragmentizer ...
43+
fragmentizer.enqueue_bytes(&buffer);
44+
buffer.clear();
45+
46+
// ... and try again.
47+
continue;
48+
};
3949

4050
// The Fragmentizer detected a line that announces a literal.
4151
// A command continuation request is expected.
42-
if let Some(FragmentInfo::Line {
43-
announcement: Some(_),
52+
if let FragmentInfo::Line {
53+
announcement: Some(LiteralAnnouncement {
54+
mode: LiteralMode::Sync,
55+
..
56+
}),
4457
..
45-
}) = fragment_info
58+
} = fragment_info
4659
{
4760
// Simulate a command continuation request ...
4861
println!("S: {COLOR_SERVER}+ {RESET}");
@@ -51,16 +64,7 @@ fn main() {
5164
continue;
5265
}
5366

54-
// Does the Fragmentizer need more bytes?
55-
if fragmentizer.is_message_complete() {
56-
// Read more bytes ...
57-
read_more(&mut buffer, Role::Server);
58-
59-
// ... and pass the bytes to the Fragmentizer ...
60-
fragmentizer.enqueue_bytes(&buffer);
61-
buffer.clear();
62-
63-
// ... and try again.
67+
if !fragmentizer.is_message_complete() {
6468
continue;
6569
}
6670

0 commit comments

Comments
 (0)