Skip to content

Commit 22e9fe5

Browse files
committed
Fix UNSEEN and LSUB
All tests now pass
1 parent 6a50307 commit 22e9fe5

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ path = "src/lib.rs"
2828
native-tls = "0.1"
2929
regex = "0.2"
3030
bufstream = "0.1"
31-
imap-proto = "0.1"
31+
#imap-proto = "0.1"
32+
imap-proto = { git = "https://github.com/djc/imap-proto.git" }
3233
nom = "3.2.1"
3334

3435
[dev-dependencies]

src/client.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ impl<T: Read + Write> Client<T> {
447447

448448
/// The APPEND command adds a mail to a mailbox.
449449
pub fn append(&mut self, folder: &str, content: &[u8]) -> Result<()> {
450-
try!(self.run_command(&format!("APPEND \"{}\" {{{}}}", folder, content.len())));
450+
try!(self.run_command(
451+
&format!("APPEND \"{}\" {{{}}}", folder, content.len())
452+
));
451453
let mut v = Vec::new();
452454
try!(self.readline(&mut v));
453455
if !v.starts_with(b"+") {
@@ -499,10 +501,20 @@ impl<T: Read + Write> Client<T> {
499501
let line = &data[line_start..];
500502

501503
match parse_response(line) {
502-
IResult::Done(_, Response::Done(tag, status, _, expl)) => {
504+
IResult::Done(
505+
_,
506+
Response::Done {
507+
tag,
508+
status,
509+
information,
510+
..
511+
},
512+
) => {
503513
assert_eq!(tag.as_bytes(), match_tag.as_bytes());
504514
Some(match status {
505-
Status::Bad | Status::No => Err((status, expl.map(|s| s.to_string()))),
515+
Status::Bad | Status::No => {
516+
Err((status, information.map(|s| s.to_string())))
517+
}
506518
Status::Ok => Ok(()),
507519
status => Err((status, None)),
508520
})
@@ -822,6 +834,7 @@ mod tests {
822834
recent: 1,
823835
unseen: Some(1),
824836
permanent_flags: vec![
837+
"\\*".to_string(),
825838
"\\Answered".to_string(),
826839
"\\Flagged".to_string(),
827840
"\\Deleted".to_string(),

src/parse.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ pub fn parse_names(lines: Vec<u8>) -> ZeroCopyResult<Vec<Name>> {
5555
use imap_proto::MailboxDatum;
5656
let f = |resp| match resp {
5757
// https://github.com/djc/imap-proto/issues/4
58-
Response::MailboxData(MailboxDatum::List(attrs, delim, name)) => MapOrNot::Map(Name {
59-
attributes: attrs,
60-
delimiter: delim,
61-
name: name,
58+
Response::MailboxData(MailboxDatum::List {
59+
flags,
60+
delimiter,
61+
name,
62+
}) |
63+
Response::MailboxData(MailboxDatum::SubList {
64+
flags,
65+
delimiter,
66+
name,
67+
}) => MapOrNot::Map(Name {
68+
attributes: flags,
69+
delimiter,
70+
name,
6271
}),
6372
resp => MapOrNot::Not(resp),
6473
};
@@ -128,7 +137,7 @@ pub fn parse_mailbox(mut lines: &[u8]) -> Result<Mailbox> {
128137

129138
loop {
130139
match imap_proto::parse_response(lines) {
131-
IResult::Done(rest, Response::Data(status, rcode, _)) => {
140+
IResult::Done(rest, Response::Data { status, code, .. }) => {
132141
lines = rest;
133142

134143
if let imap_proto::Status::Ok = status {
@@ -138,20 +147,21 @@ pub fn parse_mailbox(mut lines: &[u8]) -> Result<Mailbox> {
138147
}
139148

140149
use imap_proto::ResponseCode;
141-
match rcode {
150+
match code {
142151
Some(ResponseCode::UidValidity(uid)) => {
143152
mailbox.uid_validity = Some(uid);
144153
}
145154
Some(ResponseCode::UidNext(unext)) => {
146155
mailbox.uid_next = Some(unext);
147156
}
157+
Some(ResponseCode::Unseen(n)) => {
158+
mailbox.unseen = Some(n);
159+
}
148160
Some(ResponseCode::PermanentFlags(flags)) => {
149161
mailbox
150162
.permanent_flags
151163
.extend(flags.into_iter().map(|s| s.to_string()));
152164
}
153-
// TODO: UNSEEN
154-
// https://github.com/djc/imap-proto/issues/2
155165
_ => {}
156166
}
157167
}
@@ -171,7 +181,7 @@ pub fn parse_mailbox(mut lines: &[u8]) -> Result<Mailbox> {
171181
.flags
172182
.extend(flags.into_iter().map(|s| s.to_string()));
173183
}
174-
MailboxDatum::List(..) => {}
184+
MailboxDatum::SubList { .. } | MailboxDatum::List { .. } => {}
175185
}
176186
}
177187
IResult::Done(_, resp) => {

0 commit comments

Comments
 (0)