Skip to main content

Module changes

Module changes 

Source
Expand description

JMAP Mailbox/changes coroutine (RFC 8621 §2.7): wraps the generic JmapChanges 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::mailbox::changes::{JmapMailboxChanges, JmapMailboxChangesOptions},
};
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 =
    JmapMailboxChanges::new(&session, &auth, "s1", JmapMailboxChangesOptions::default())
        .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!("new state {}", out.new_state);

Structs§

JmapMailboxChanges
I/O-free coroutine for the JMAP Mailbox/changes method.
JmapMailboxChangesOptions
Options for JmapMailboxChanges::new.

Enums§

JmapMailboxChangesError
Failure causes during a JMAP Mailbox/changes flow.