Skip to content

Commit 8841733

Browse files
authored
Merge pull request #208 from mordak/zero-copy
Convert ZeroCopy to ouroboros.
2 parents b656618 + 57834a1 commit 8841733

File tree

10 files changed

+458
-440
lines changed

10 files changed

+458
-440
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "imap"
3-
version = "3.0.0-alpha.4"
3+
version = "3.0.0-alpha.5"
44
authors = ["Jon Gjengset <jon@thesquareplanet.com>",
55
"Matt McCoy <mattnenterprise@yahoo.com>"]
66
documentation = "https://docs.rs/imap/"
@@ -27,6 +27,7 @@ nom = { version = "6.0", default-features = false }
2727
base64 = "0.13"
2828
chrono = { version = "0.4", default-features = false, features = ["std"]}
2929
lazy_static = "1.4"
30+
ouroboros = "0.9.5"
3031

3132
[dev-dependencies]
3233
lettre = "0.9"

examples/gmail_oauth2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() {
4242

4343
match imap_session.fetch("2", "body[text]") {
4444
Ok(msgs) => {
45-
for msg in &msgs {
45+
for msg in msgs.iter() {
4646
print!("{:?}", msg);
4747
}
4848
}

src/client.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -565,39 +565,39 @@ impl<T: Read + Write> Session<T> {
565565
/// - `RFC822.HEADER`: Functionally equivalent to `BODY.PEEK[HEADER]`.
566566
/// - `RFC822.SIZE`: The [RFC-2822](https://tools.ietf.org/html/rfc2822) size of the message.
567567
/// - `UID`: The unique identifier for the message.
568-
pub fn fetch<S1, S2>(&mut self, sequence_set: S1, query: S2) -> ZeroCopyResult<Vec<Fetch>>
568+
pub fn fetch<S1, S2>(&mut self, sequence_set: S1, query: S2) -> Result<Fetches>
569569
where
570570
S1: AsRef<str>,
571571
S2: AsRef<str>,
572572
{
573573
if sequence_set.as_ref().is_empty() {
574-
parse_fetches(vec![], &mut self.unsolicited_responses_tx)
574+
Fetches::parse(vec![], &mut self.unsolicited_responses_tx)
575575
} else {
576576
self.run_command_and_read_response(&format!(
577577
"FETCH {} {}",
578578
validate_sequence_set(sequence_set.as_ref())?,
579579
validate_str_noquote(query.as_ref())?
580580
))
581-
.and_then(|lines| parse_fetches(lines, &mut self.unsolicited_responses_tx))
581+
.and_then(|lines| Fetches::parse(lines, &mut self.unsolicited_responses_tx))
582582
}
583583
}
584584

585585
/// Equivalent to [`Session::fetch`], except that all identifiers in `uid_set` are
586586
/// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8).
587-
pub fn uid_fetch<S1, S2>(&mut self, uid_set: S1, query: S2) -> ZeroCopyResult<Vec<Fetch>>
587+
pub fn uid_fetch<S1, S2>(&mut self, uid_set: S1, query: S2) -> Result<Fetches>
588588
where
589589
S1: AsRef<str>,
590590
S2: AsRef<str>,
591591
{
592592
if uid_set.as_ref().is_empty() {
593-
parse_fetches(vec![], &mut self.unsolicited_responses_tx)
593+
Fetches::parse(vec![], &mut self.unsolicited_responses_tx)
594594
} else {
595595
self.run_command_and_read_response(&format!(
596596
"UID FETCH {} {}",
597597
validate_sequence_set(uid_set.as_ref())?,
598598
validate_str_noquote(query.as_ref())?
599599
))
600-
.and_then(|lines| parse_fetches(lines, &mut self.unsolicited_responses_tx))
600+
.and_then(|lines| Fetches::parse(lines, &mut self.unsolicited_responses_tx))
601601
}
602602
}
603603

@@ -728,9 +728,9 @@ impl<T: Read + Write> Session<T> {
728728
/// The [`CAPABILITY` command](https://tools.ietf.org/html/rfc3501#section-6.1.1) requests a
729729
/// listing of capabilities that the server supports. The server will include "IMAP4rev1" as
730730
/// one of the listed capabilities. See [`Capabilities`] for further details.
731-
pub fn capabilities(&mut self) -> ZeroCopyResult<Capabilities> {
731+
pub fn capabilities(&mut self) -> Result<Capabilities> {
732732
self.run_command_and_read_response("CAPABILITY")
733-
.and_then(|lines| parse_capabilities(lines, &mut self.unsolicited_responses_tx))
733+
.and_then(|lines| Capabilities::parse(lines, &mut self.unsolicited_responses_tx))
734734
}
735735

736736
/// The [`EXPUNGE` command](https://tools.ietf.org/html/rfc3501#section-6.4.3) permanently
@@ -845,7 +845,7 @@ impl<T: Read + Write> Session<T> {
845845
/// Ok(())
846846
/// }
847847
/// ```
848-
pub fn store<S1, S2>(&mut self, sequence_set: S1, query: S2) -> ZeroCopyResult<Vec<Fetch>>
848+
pub fn store<S1, S2>(&mut self, sequence_set: S1, query: S2) -> Result<Fetches>
849849
where
850850
S1: AsRef<str>,
851851
S2: AsRef<str>,
@@ -855,12 +855,12 @@ impl<T: Read + Write> Session<T> {
855855
sequence_set.as_ref(),
856856
query.as_ref()
857857
))
858-
.and_then(|lines| parse_fetches(lines, &mut self.unsolicited_responses_tx))
858+
.and_then(|lines| Fetches::parse(lines, &mut self.unsolicited_responses_tx))
859859
}
860860

861861
/// Equivalent to [`Session::store`], except that all identifiers in `sequence_set` are
862862
/// [`Uid`]s. See also the [`UID` command](https://tools.ietf.org/html/rfc3501#section-6.4.8).
863-
pub fn uid_store<S1, S2>(&mut self, uid_set: S1, query: S2) -> ZeroCopyResult<Vec<Fetch>>
863+
pub fn uid_store<S1, S2>(&mut self, uid_set: S1, query: S2) -> Result<Fetches>
864864
where
865865
S1: AsRef<str>,
866866
S2: AsRef<str>,
@@ -870,7 +870,7 @@ impl<T: Read + Write> Session<T> {
870870
uid_set.as_ref(),
871871
query.as_ref()
872872
))
873-
.and_then(|lines| parse_fetches(lines, &mut self.unsolicited_responses_tx))
873+
.and_then(|lines| Fetches::parse(lines, &mut self.unsolicited_responses_tx))
874874
}
875875

876876
/// The [`COPY` command](https://tools.ietf.org/html/rfc3501#section-6.4.7) copies the
@@ -999,13 +999,13 @@ impl<T: Read + Write> Session<T> {
999999
&mut self,
10001000
reference_name: Option<&str>,
10011001
mailbox_pattern: Option<&str>,
1002-
) -> ZeroCopyResult<Vec<Name>> {
1002+
) -> Result<Names> {
10031003
self.run_command_and_read_response(&format!(
10041004
"LIST {} {}",
10051005
quote!(reference_name.unwrap_or("")),
10061006
mailbox_pattern.unwrap_or("\"\"")
10071007
))
1008-
.and_then(|lines| parse_names(lines, &mut self.unsolicited_responses_tx))
1008+
.and_then(|lines| Names::parse(lines, &mut self.unsolicited_responses_tx))
10091009
}
10101010

10111011
/// The [`LSUB` command](https://tools.ietf.org/html/rfc3501#section-6.3.9) returns a subset of
@@ -1027,13 +1027,13 @@ impl<T: Read + Write> Session<T> {
10271027
&mut self,
10281028
reference_name: Option<&str>,
10291029
mailbox_pattern: Option<&str>,
1030-
) -> ZeroCopyResult<Vec<Name>> {
1030+
) -> Result<Names> {
10311031
self.run_command_and_read_response(&format!(
10321032
"LSUB {} {}",
10331033
quote!(reference_name.unwrap_or("")),
10341034
mailbox_pattern.unwrap_or("")
10351035
))
1036-
.and_then(|lines| parse_names(lines, &mut self.unsolicited_responses_tx))
1036+
.and_then(|lines| Names::parse(lines, &mut self.unsolicited_responses_tx))
10371037
}
10381038

10391039
/// The [`STATUS` command](https://tools.ietf.org/html/rfc3501#section-6.3.10) requests the

0 commit comments

Comments
 (0)