Expand description
JMAP Thread/get coroutine (RFC 8621 §3.3): wraps the generic JmapGet
with the JMAP-Mail capability set.
§Example
use std::{
io::{Read, Write},
net::TcpStream,
};
use io_jmap::{
coroutine::{JmapCoroutine, JmapCoroutineState, JmapYield},
rfc8620::session::JmapSession,
rfc8621::thread::get::JmapThreadGet,
};
use secrecy::SecretString;
// Ready stream needed (TCP-connected, TLS-negociated)
let mut stream = TcpStream::connect("api.example.com:443").unwrap();
let mut buf = [0u8; 4096];
let session: JmapSession = serde_json::from_str(r#"{
"username": "",
"accounts": {},
"primaryAccounts": {"urn:ietf:params:jmap:mail": "a1"},
"capabilities": {},
"apiUrl": "https://api.example.com/jmap/",
"downloadUrl": "",
"uploadUrl": "",
"eventSourceUrl": "",
"state": ""
}"#).unwrap();
let auth = SecretString::from("Bearer xyz");
let mut coroutine = JmapThreadGet::new(&session, &auth, vec!["t1".into()]).unwrap();
let mut arg = None;
let out = loop {
match coroutine.resume(arg.take()) {
JmapCoroutineState::Yielded(JmapYield::WantsWrite(bytes)) => {
stream.write_all(&bytes).unwrap();
}
JmapCoroutineState::Yielded(JmapYield::WantsRead) => {
let n = stream.read(&mut buf).unwrap();
arg = Some(&buf[..n]);
}
JmapCoroutineState::Complete(Ok(out)) => break out,
JmapCoroutineState::Complete(Err(err)) => panic!("{err}"),
}
};
println!("{} threads", out.threads.len());Structs§
- Jmap
Thread Get - I/O-free coroutine for the JMAP
Thread/getmethod. - Jmap
Thread GetOutput - Successful terminal output of
JmapThreadGet.
Enums§
- Jmap
Thread GetError - Failure causes during a JMAP
Thread/getflow.