aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorQuentin <quentin@dufour.io>2024-01-19 14:04:03 +0000
committerQuentin <quentin@dufour.io>2024-01-19 14:04:03 +0000
commit0f227e44e4996e54d2e55ed5c7a07f5458c4db4f (patch)
tree7f6c4fec623d0d99d3f09e752a360ca0f806429e /tests
parent55e26d24a08519ded6a6898453dcd6db287f45c8 (diff)
parent23aa313e11f344da07143d60ce446b5f23d5f362 (diff)
downloadaerogramme-0f227e44e4996e54d2e55ed5c7a07f5458c4db4f.tar.gz
aerogramme-0f227e44e4996e54d2e55ed5c7a07f5458c4db4f.zip
Merge pull request 'Implement IDLE' (#72) from feat/idle into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/aerogramme/pulls/72
Diffstat (limited to 'tests')
-rw-r--r--tests/behavior.rs112
-rw-r--r--tests/common/fragments.rs31
2 files changed, 114 insertions, 29 deletions
diff --git a/tests/behavior.rs b/tests/behavior.rs
index 205f5e1..2e3c610 100644
--- a/tests/behavior.rs
+++ b/tests/behavior.rs
@@ -1,8 +1,8 @@
use anyhow::Context;
mod common;
-use crate::common::fragments::*;
use crate::common::constants::*;
+use crate::common::fragments::*;
fn main() {
rfc3501_imap4rev1_base();
@@ -11,6 +11,7 @@ fn main() {
rfc6851_imapext_move();
rfc7888_imapext_literal();
rfc4551_imapext_condstore();
+ rfc2177_imapext_idle();
println!("โœ… SUCCESS ๐ŸŒŸ๐Ÿš€๐Ÿฅณ๐Ÿ™๐Ÿฅน");
}
@@ -21,29 +22,40 @@ fn rfc3501_imap4rev1_base() {
capability(imap_socket, Extension::None).context("check server capabilities")?;
login(imap_socket, Account::Alice).context("login test")?;
create_mailbox(imap_socket, Mailbox::Archive).context("created mailbox archive")?;
- // UNSUBSCRIBE IS NOT IMPLEMENTED YET
- //unsubscribe_mailbox(imap_socket).context("unsubscribe from archive")?;
- let select_res = select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
+ let select_res =
+ select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
assert!(select_res.contains("* 0 EXISTS"));
check(imap_socket).context("check must run")?;
- status(imap_socket, Mailbox::Archive, StatusKind::UidNext).context("status of archive from inbox")?;
+ status(imap_socket, Mailbox::Archive, StatusKind::UidNext)
+ .context("status of archive from inbox")?;
lmtp_handshake(lmtp_socket).context("handshake lmtp done")?;
lmtp_deliver_email(lmtp_socket, Email::Multipart).context("mail delivered successfully")?;
noop_exists(imap_socket, 1).context("noop loop must detect a new email")?;
- let srv_msg = fetch(imap_socket, Selection::FirstId, FetchKind::Rfc822, FetchMod::None)
- .context("fetch rfc822 message, should be our first message")?;
+ let srv_msg = fetch(
+ imap_socket,
+ Selection::FirstId,
+ FetchKind::Rfc822,
+ FetchMod::None,
+ )
+ .context("fetch rfc822 message, should be our first message")?;
let orig_email = std::str::from_utf8(EMAIL1)?;
assert!(srv_msg.contains(orig_email));
-
+
copy(imap_socket, Selection::FirstId, Mailbox::Archive)
.context("copy message to the archive mailbox")?;
append_email(imap_socket, Email::Basic).context("insert email in INBOX")?;
noop_exists(imap_socket, 2).context("noop loop must detect a new email")?;
search(imap_socket, SearchKind::Text("OoOoO")).expect("search should return something");
- store(imap_socket, Selection::FirstId, Flag::Deleted, StoreAction::AddFlags, StoreMod::None)
- .context("should add delete flag to the email")?;
+ store(
+ imap_socket,
+ Selection::FirstId,
+ Flag::Deleted,
+ StoreAction::AddFlags,
+ StoreMod::None,
+ )
+ .context("should add delete flag to the email")?;
expunge(imap_socket).context("expunge emails")?;
rename_mailbox(imap_socket, Mailbox::Archive, Mailbox::Drafts)
.context("Archive mailbox is renamed Drafts")?;
@@ -63,19 +75,32 @@ fn rfc3691_imapext_unselect() {
capability(imap_socket, Extension::Unselect).context("check server capabilities")?;
login(imap_socket, Account::Alice).context("login test")?;
- let select_res = select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
+ let select_res =
+ select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
assert!(select_res.contains("* 0 EXISTS"));
noop_exists(imap_socket, 1).context("noop loop must detect a new email")?;
- store(imap_socket, Selection::FirstId, Flag::Deleted, StoreAction::AddFlags, StoreMod::None)
- .context("add delete flags to the email")?;
+ store(
+ imap_socket,
+ Selection::FirstId,
+ Flag::Deleted,
+ StoreAction::AddFlags,
+ StoreMod::None,
+ )
+ .context("add delete flags to the email")?;
unselect(imap_socket)
.context("unselect inbox while preserving email with the \\Delete flag")?;
- let select_res = select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox again")?;
+ let select_res =
+ select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox again")?;
assert!(select_res.contains("* 1 EXISTS"));
- let srv_msg = fetch(imap_socket, Selection::FirstId, FetchKind::Rfc822, FetchMod::None)
- .context("message is still present")?;
+ let srv_msg = fetch(
+ imap_socket,
+ Selection::FirstId,
+ FetchKind::Rfc822,
+ FetchMod::None,
+ )
+ .context("message is still present")?;
let orig_email = std::str::from_utf8(EMAIL2)?;
assert!(srv_msg.contains(orig_email));
@@ -111,7 +136,8 @@ fn rfc6851_imapext_move() {
capability(imap_socket, Extension::Move).context("check server capabilities")?;
login(imap_socket, Account::Alice).context("login test")?;
create_mailbox(imap_socket, Mailbox::Archive).context("created mailbox archive")?;
- let select_res = select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
+ let select_res =
+ select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
assert!(select_res.contains("* 0 EXISTS"));
lmtp_handshake(lmtp_socket).context("handshake lmtp done")?;
@@ -123,15 +149,17 @@ fn rfc6851_imapext_move() {
unselect(imap_socket)
.context("unselect inbox while preserving email with the \\Delete flag")?;
- let select_res = select(imap_socket, Mailbox::Archive, SelectMod::None).context("select archive")?;
+ let select_res =
+ select(imap_socket, Mailbox::Archive, SelectMod::None).context("select archive")?;
assert!(select_res.contains("* 1 EXISTS"));
let srv_msg = fetch(
- imap_socket,
- Selection::FirstId,
- FetchKind::Rfc822,
+ imap_socket,
+ Selection::FirstId,
+ FetchKind::Rfc822,
FetchMod::None,
- ).context("check mail exists")?;
+ )
+ .context("check mail exists")?;
let orig_email = std::str::from_utf8(EMAIL2)?;
assert!(srv_msg.contains(orig_email));
@@ -166,7 +194,8 @@ fn rfc4551_imapext_condstore() {
login(imap_socket, Account::Alice).context("login test")?;
// RFC 3.1.8. CONDSTORE Parameter to SELECT and EXAMINE
- let select_res = select(imap_socket, Mailbox::Inbox, SelectMod::Condstore).context("select inbox")?;
+ let select_res =
+ select(imap_socket, Mailbox::Inbox, SelectMod::Condstore).context("select inbox")?;
// RFC 3.1.2 New OK Untagged Responses for SELECT and EXAMINE
assert!(select_res.contains("[HIGHESTMODSEQ 1]"));
@@ -175,14 +204,25 @@ fn rfc4551_imapext_condstore() {
lmtp_deliver_email(lmtp_socket, Email::Basic).context("mail delivered successfully")?;
lmtp_deliver_email(lmtp_socket, Email::Multipart).context("mail delivered successfully")?;
noop_exists(imap_socket, 2).context("noop loop must detect a new email")?;
- let store_res = store(imap_socket, Selection::All, Flag::Important, StoreAction::AddFlags, StoreMod::UnchangedSince(1))?;
+ let store_res = store(
+ imap_socket,
+ Selection::All,
+ Flag::Important,
+ StoreAction::AddFlags,
+ StoreMod::UnchangedSince(1),
+ )?;
assert!(store_res.contains("[MODIFIED 2]"));
assert!(store_res.contains("* 1 FETCH (FLAGS (\\Important) MODSEQ (3))"));
assert!(!store_res.contains("* 2 FETCH"));
assert_eq!(store_res.lines().count(), 2);
// RFC 3.1.4. FETCH and UID FETCH Commands
- let fetch_res = fetch(imap_socket, Selection::All, FetchKind::Rfc822Size, FetchMod::ChangedSince(2))?;
+ let fetch_res = fetch(
+ imap_socket,
+ Selection::All,
+ FetchKind::Rfc822Size,
+ FetchMod::ChangedSince(2),
+ )?;
assert!(fetch_res.contains("* 1 FETCH (RFC822.SIZE 84 MODSEQ (3))"));
assert!(!fetch_res.contains("* 2 FETCH"));
assert_eq!(store_res.lines().count(), 2);
@@ -200,3 +240,25 @@ fn rfc4551_imapext_condstore() {
})
.expect("test fully run");
}
+
+
+fn rfc2177_imapext_idle() {
+ println!("๐Ÿงช rfc2177_imapext_idle");
+ common::aerogramme_provider_daemon_dev(|imap_socket, lmtp_socket| {
+ // Test setup
+ connect(imap_socket).context("server says hello")?;
+ capability(imap_socket, Extension::Idle).context("check server capabilities")?;
+ login(imap_socket, Account::Alice).context("login test")?;
+ select(imap_socket, Mailbox::Inbox, SelectMod::None).context("select inbox")?;
+
+ // Check that new messages from LMTP are correctly detected during idling
+ start_idle(imap_socket).context("can't start idling")?;
+ lmtp_handshake(lmtp_socket).context("handshake lmtp done")?;
+ lmtp_deliver_email(lmtp_socket, Email::Basic).context("mail delivered successfully")?;
+ let srv_msg = stop_idle(imap_socket).context("stop idling")?;
+ assert!(srv_msg.contains("* 1 EXISTS"));
+
+ Ok(())
+ })
+ .expect("test fully run");
+}
diff --git a/tests/common/fragments.rs b/tests/common/fragments.rs
index f9ad87e..7f7967a 100644
--- a/tests/common/fragments.rs
+++ b/tests/common/fragments.rs
@@ -36,6 +36,7 @@ pub enum Extension {
Move,
Condstore,
LiteralPlus,
+ Idle,
}
pub enum Enable {
@@ -114,6 +115,7 @@ pub fn capability(imap: &mut TcpStream, ext: Extension) -> Result<()> {
Extension::Move => Some("MOVE"),
Extension::Condstore => Some("CONDSTORE"),
Extension::LiteralPlus => Some("LITERAL+"),
+ Extension::Idle => Some("IDLE"),
};
let mut buffer: [u8; 6000] = [0; 6000];
@@ -286,7 +288,12 @@ pub fn noop_exists(imap: &mut TcpStream, must_exists: u32) -> Result<()> {
}
}
-pub fn fetch(imap: &mut TcpStream, selection: Selection, kind: FetchKind, modifier: FetchMod) -> Result<String> {
+pub fn fetch(
+ imap: &mut TcpStream,
+ selection: Selection,
+ kind: FetchKind,
+ modifier: FetchMod,
+) -> Result<String> {
let mut buffer: [u8; 65535] = [0; 65535];
let sel_str = match selection {
@@ -363,11 +370,11 @@ pub fn search(imap: &mut TcpStream, sk: SearchKind) -> Result<String> {
}
pub fn store(
- imap: &mut TcpStream,
- sel: Selection,
+ imap: &mut TcpStream,
+ sel: Selection,
flag: Flag,
action: StoreAction,
- modifier: StoreMod
+ modifier: StoreMod,
) -> Result<String> {
let mut buffer: [u8; 6000] = [0; 6000];
@@ -491,6 +498,22 @@ pub fn enable(imap: &mut TcpStream, ask: Enable, done: Option<Enable>) -> Result
Ok(())
}
+pub fn start_idle(imap: &mut TcpStream) -> Result<()> {
+ let mut buffer: [u8; 1500] = [0; 1500];
+ imap.write(&b"98 IDLE\r\n"[..])?;
+ let read = read_lines(imap, &mut buffer, None)?;
+ assert_eq!(read[0], b'+');
+ Ok(())
+}
+
+pub fn stop_idle(imap: &mut TcpStream) -> Result<String> {
+ let mut buffer: [u8; 16536] = [0; 16536];
+ imap.write(&b"DONE\r\n"[..])?;
+ let read = read_lines(imap, &mut buffer, Some(&b"98 OK"[..]))?;
+ let srv_msg = std::str::from_utf8(read)?;
+ Ok(srv_msg.to_string())
+}
+
pub fn logout(imap: &mut TcpStream) -> Result<()> {
imap.write(&b"99 logout\r\n"[..])?;
let mut buffer: [u8; 1500] = [0; 1500];