Skip to main content

jmap_calendars_types/
capability.rs

1//! Capability types for the JMAP Calendars extension.
2//!
3//! Normative reference: draft-ietf-jmap-calendars-33 §1.5.
4//!
5//! The Calendars extension defines three capability URIs.  Each has both a
6//! session-level capability (value in the JMAP Session `capabilities` map)
7//! and an account-level capability (value in the account's
8//! `accountCapabilities` map).  Session-level values are empty objects for
9//! all Calendars capabilities.
10
11use jmap_jscalendar_types::Duration;
12use jmap_types::UTCDate;
13use serde::{Deserialize, Serialize};
14
15/// Capability URI for core JMAP Calendars support
16/// (draft-ietf-jmap-calendars-33 §1.5.1).
17pub const JMAP_CALENDARS_URI: &str = "urn:ietf:params:jmap:calendars";
18
19/// Capability URI for Principal availability queries
20/// (draft-ietf-jmap-calendars-33 §1.5.2).
21pub const JMAP_PRINCIPALS_AVAILABILITY_URI: &str = "urn:ietf:params:jmap:principals:availability";
22
23/// Capability URI for the CalendarEvent/parse method
24/// (draft-ietf-jmap-calendars-33 §1.5.3).
25pub const JMAP_CALENDARS_PARSE_URI: &str = "urn:ietf:params:jmap:calendars:parse";
26
27/// Session-level Calendars capability (draft-ietf-jmap-calendars-33 §1.5.1).
28///
29/// The value of `capabilities["urn:ietf:params:jmap:calendars"]` in the JMAP
30/// Session object.  The spec mandates that this is an empty object `{}`.
31#[non_exhaustive]
32#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
33pub struct CalendarsCapability {}
34
35/// Account-level Calendars capability (draft-ietf-jmap-calendars-33 §1.5.1).
36///
37/// The value of `accountCapabilities["urn:ietf:params:jmap:calendars"]` for a
38/// given account.  Describes server capabilities and account-level permissions
39/// for the Calendars extension.
40#[non_exhaustive]
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase")]
43pub struct CalendarsAccountCapability {
44    /// Maximum number of calendars a single event may belong to, or `null`
45    /// for no limit.
46    pub max_calendars_per_event: Option<u64>,
47
48    /// Earliest UTC date-time value the server accepts for any CalendarEvent
49    /// date property.
50    pub min_date_time: UTCDate,
51
52    /// Latest UTC date-time value the server accepts for any CalendarEvent
53    /// date property.
54    pub max_date_time: UTCDate,
55
56    /// Maximum duration the user may query over when asking the server to
57    /// expand recurrences (draft-ietf-jmap-calendars-33 §1.5.1:
58    /// "maxExpandedQueryDuration: Duration").
59    pub max_expanded_query_duration: Duration,
60
61    /// Maximum number of participants a single event may have, or `null`
62    /// for no limit.
63    pub max_participants_per_event: Option<u64>,
64
65    /// If `true`, the user may create a calendar in this account.
66    pub may_create_calendar: bool,
67}
68
69/// Session-level capability for the Principal availability extension
70/// (draft-ietf-jmap-calendars-33 §1.5.2).
71///
72/// Value is an empty object `{}` at the session level.
73#[non_exhaustive]
74#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
75pub struct PrincipalsAvailabilityCapability {}
76
77/// Account-level capability for the Principal availability extension
78/// (draft-ietf-jmap-calendars-33 §1.5.2).
79#[non_exhaustive]
80#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct PrincipalsAvailabilityAccountCapability {
83    /// Maximum duration over which the server will calculate availability in
84    /// a single `Principal/getAvailability` call
85    /// (draft-ietf-jmap-calendars-33 §1.5.2: "maxAvailabilityDuration: Duration").
86    pub max_availability_duration: Duration,
87}
88
89/// Session-level capability for the CalendarEvent/parse method
90/// (draft-ietf-jmap-calendars-33 §1.5.3).
91///
92/// Value is an empty object `{}` at both session and account level.
93#[non_exhaustive]
94#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
95pub struct CalendarsParseCapability {}
96
97/// The value of `Principal.capabilities["urn:ietf:params:jmap:calendars"]`
98/// on a JMAP Principals object (draft-ietf-jmap-calendars-33 §2.1).
99///
100/// This is distinct from the session-level [`CalendarsCapability`].  Where
101/// [`CalendarsCapability`] appears in the JMAP Session `capabilities` map,
102/// `PrincipalCalendarsCapability` appears inside a *Principal* object's own
103/// `capabilities` map and describes that principal's calendar presence.
104///
105/// ## Field semantics
106///
107/// - `account_id` — the JMAP account id that contains this principal's
108///   calendar data, or `null` if the principal has no calendar account
109///   accessible to the requesting user.
110/// - `may_get_availability` — the requesting user may call
111///   `Principal/getAvailability` for this principal.
112/// - `may_share_with` — the requesting user may add this principal to the
113///   `shareWith` of their own Calendar objects.
114/// - `calendar_address` — the iTIP scheduling address for this principal
115///   (e.g. `"mailto:alice@example.com"`), or `null` if the principal may
116///   not be added as a participant to an event.
117#[non_exhaustive]
118#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120pub struct PrincipalCalendarsCapability {
121    /// Id of the account containing this principal's calendar data,
122    /// or `null` if no accessible calendar account exists.
123    ///
124    /// Required-and-nullable: always present on the wire, as `null` or an Id.
125    /// Do NOT add `skip_serializing_if` to this field: draft-ietf-jmap-calendars
126    /// §2.1 types `accountId` as `Id|null`, so omitting it on `None` is a
127    /// wire-protocol break, not a clean-up. The regression test
128    /// `principal_calendars_capability_account_id_null_serializes` (in
129    /// `tests/types_test.rs`) pins the current behavior. Precedent:
130    /// `CalendarAlert.recurrence_id`, bd:JMAP-1rwf.7.
131    pub account_id: Option<jmap_types::Id>,
132
133    /// The requesting user may call `Principal/getAvailability` for this
134    /// principal.
135    pub may_get_availability: bool,
136
137    /// The requesting user may add this principal to the `shareWith` property
138    /// of their own Calendar objects.
139    pub may_share_with: bool,
140
141    /// iTIP scheduling address for this principal, or `null` when it may
142    /// not be added as a participant (draft-ietf-jmap-calendars-33 §2.1:
143    /// "`calendarAddress`: String|null ... otherwise, this is null").
144    ///
145    /// Required-and-nullable: always present on the wire, as `null` or a
146    /// String.
147    pub calendar_address: Option<String>,
148}