Implement some IMAP extensions #50
3 changed files with 26 additions and 2 deletions
|
@ -8,6 +8,7 @@ fn main() {
|
||||||
rfc3691_imapext_unselect();
|
rfc3691_imapext_unselect();
|
||||||
rfc5161_imapext_enable();
|
rfc5161_imapext_enable();
|
||||||
rfc6851_imapext_move();
|
rfc6851_imapext_move();
|
||||||
|
rfc7888_imapext_literal();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rfc3501_imap4rev1_base() {
|
fn rfc3501_imap4rev1_base() {
|
||||||
|
@ -105,3 +106,15 @@ fn rfc6851_imapext_move() {
|
||||||
})
|
})
|
||||||
.expect("test fully run");
|
.expect("test fully run");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rfc7888_imapext_literal() {
|
||||||
|
println!("rfc7888_imapext_literal");
|
||||||
|
common::aerogramme_provider_daemon_dev(|imap_socket, _lmtp_socket| {
|
||||||
|
connect(imap_socket).context("server says hello")?;
|
||||||
|
|
||||||
|
capability(imap_socket, Extension::LiteralPlus).context("check server capabilities")?;
|
||||||
|
login_with_literal(imap_socket, Account::Alice).context("use literal to connect Alice")?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}).expect("test fully run");
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ pub enum Extension {
|
||||||
Unselect,
|
Unselect,
|
||||||
Move,
|
Move,
|
||||||
CondStore,
|
CondStore,
|
||||||
|
LiteralPlus,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Enable {
|
pub enum Enable {
|
||||||
|
@ -72,9 +73,10 @@ pub fn capability(imap: &mut TcpStream, ext: Extension) -> Result<()> {
|
||||||
Extension::Unselect => Some("UNSELECT"),
|
Extension::Unselect => Some("UNSELECT"),
|
||||||
Extension::Move => Some("MOVE"),
|
Extension::Move => Some("MOVE"),
|
||||||
Extension::CondStore => Some("CONDSTORE"),
|
Extension::CondStore => Some("CONDSTORE"),
|
||||||
|
Extension::LiteralPlus => Some("LITERAL+"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buffer: [u8; 1500] = [0; 1500];
|
let mut buffer: [u8; 6000] = [0; 6000];
|
||||||
let read = read_lines(imap, &mut buffer, Some(&b"5 OK"[..]))?;
|
let read = read_lines(imap, &mut buffer, Some(&b"5 OK"[..]))?;
|
||||||
let srv_msg = std::str::from_utf8(read)?;
|
let srv_msg = std::str::from_utf8(read)?;
|
||||||
assert!(srv_msg.contains("IMAP4REV1"));
|
assert!(srv_msg.contains("IMAP4REV1"));
|
||||||
|
@ -97,6 +99,15 @@ pub fn login(imap: &mut TcpStream, account: Account) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn login_with_literal(imap: &mut TcpStream, account: Account) -> Result<()> {
|
||||||
|
let mut buffer: [u8; 1500] = [0; 1500];
|
||||||
|
|
||||||
|
assert!(matches!(account, Account::Alice));
|
||||||
|
imap.write(&b"10 login {5+}\r\nalice {7+}\r\nhunter2\r\n"[..])?;
|
||||||
|
let _read = read_lines(imap, &mut buffer, Some(&b"10 OK"[..]))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_mailbox(imap: &mut TcpStream, mbx: Mailbox) -> Result<()> {
|
pub fn create_mailbox(imap: &mut TcpStream, mbx: Mailbox) -> Result<()> {
|
||||||
let mut buffer: [u8; 1500] = [0; 1500];
|
let mut buffer: [u8; 1500] = [0; 1500];
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub fn read_lines<'a, F: Read>(
|
||||||
None => true,
|
None => true,
|
||||||
Some(mark) => buffer[..nbytes].windows(mark.len()).any(|w| w == mark),
|
Some(mark) => buffer[..nbytes].windows(mark.len()).any(|w| w == mark),
|
||||||
};
|
};
|
||||||
if pre_condition && &buffer[nbytes - 2..nbytes] == &b"\r\n"[..] {
|
if pre_condition && nbytes >= 2 && &buffer[nbytes - 2..nbytes] == &b"\r\n"[..] {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue