eventsource/
eventsource.rs1#[cfg(feature = "async")]
17use futures_util::StreamExt;
18#[cfg(feature = "async")]
19use jmap_client::{client::Client, DataType};
20
21#[cfg(feature = "async")]
22async fn event_source() {
23 let client = Client::new()
25 .credentials(("john@example.org", "secret"))
26 .connect("https://jmap.example.org")
27 .await
28 .unwrap();
29
30 let mut stream = client
32 .event_source(
33 [
34 DataType::Email,
35 DataType::EmailDelivery,
36 DataType::Mailbox,
37 DataType::EmailSubmission,
38 DataType::Identity,
39 ]
40 .into(),
41 false,
42 60.into(),
43 None,
44 )
45 .await
46 .unwrap();
47
48 while let Some(event) = stream.next().await {
50 use jmap_client::event_source::PushNotification;
51
52 match event.unwrap() {
53 PushNotification::StateChange(changes) => {
54 println!("-> Change id: {:?}", changes.id());
55 for account_id in changes.changed_accounts() {
56 println!(" Account {} has changes:", account_id);
57 if let Some(account_changes) = changes.changes(account_id) {
58 for (type_state, state_id) in account_changes {
59 println!(" Type {:?} has a new state {}.", type_state, state_id);
60 }
61 }
62 }
63 }
64 PushNotification::CalendarAlert(calendar_alert) => {
65 println!(
66 "-> Calendar alert received for event {} (alert id {}).",
67 calendar_alert.calendar_event_id, calendar_alert.alert_id
68 );
69 }
70 }
71 }
72}
73
74fn main() {
75 #[cfg(feature = "async")]
76 let _c = event_source();
77}