Complete example/simple.rs, tests that fail for APPEND

This commit is contained in:
Alex 2022-08-30 16:53:17 +02:00
parent ce339cf89b
commit f15069fe64
Signed by: lx
GPG key ID: 0E496D15096376BE
4 changed files with 69 additions and 7 deletions

View file

@ -1,21 +1,41 @@
use miette::{IntoDiagnostic, Result};
use imap_codec::types::command::CommandBody;
use tracing::info;
use boitalettres::proto::{Request, Response};
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
use boitalettres::server::Server;
async fn handle_req(_req: Request) -> Result<Response> {
async fn handle_req(req: Request) -> Result<Response> {
use imap_codec::types::response::{Capability, Data as ImapData};
use boitalettres::proto::res::{body::Data, Status};
info!("Handling request: {:?}", req);
match req.command.body {
CommandBody::Noop => Ok(Response::ok("NOOP done")?),
CommandBody::Capability => {
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
let body: Vec<Data> = vec![
Status::ok("Yeah")?.into(),
ImapData::Capability(capabilities).into(),
];
Ok(Response::ok("Done")?.with_body(body))
Ok(Response::ok("CAPABILITY done")?.with_body(body))
}
CommandBody::Login { .. } => Ok(Response::ok("Faking successfull LOGIN")?),
CommandBody::Append { .. } => Ok(Response::ok("Faking successfull APPEND")?),
CommandBody::Logout { .. } => {
let body: Vec<Data> = vec![Status::bye("Logging out")?.into()];
Ok(Response::ok("LOGOUT completed")?
.with_body(body)
.close(true))
}
_ => Ok(Response::no("unavailable command")?),
}
}
#[tokio::main]

18
scripts/test_imap.py Normal file → Executable file
View file

@ -2,6 +2,24 @@
from imaplib import IMAP4
conn = IMAP4('127.0.0.1', port=4567)
print("Connected")
conn.noop()
print("NOOP done")
conn.login("lx", "plop")
print("Logged in")
print("Testing APPEND (this uses continuation style)")
conn.append("INBOX", [], None,
b"""From: alex@adnab.me
To: lx@deuxfleurs.fr
Subject: Hello, world!
Test
.
""")
print("Append done")
conn.logout()
print("Logged out")

23
scripts/test_imap.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
# APPEND example from RFC9051
nc localhost 4567 <<EOF
A CAPABILITY
B LOGIN lx plop
C APPEND saved-messages (\\Seen) {297+}
Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
From: Fred Foobar <foobar@example.com>
Subject: afternoon meeting
To: mooch@example.com
Message-Id: <B27397-0100000@example.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Hello Joe, do you think we can meet at 3:30 tomorrow?
D NOOP
E LOGOUT
EOF
echo "^ expected output: responses to A B C D and E, last one is E OK LOGOUT completed"

View file

@ -0,0 +1 @@