Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): stop an unmapped mailbox zone blocking Outlook discovery (#9621)

gbirman5a4d56aa13be
diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.md
index a95fc7ef6b..24e8a9a813 100644
--- a/crates/calendar_events/AGENTS.md
+++ b/crates/calendar_events/AGENTS.md
@@ -370,7 +370,13 @@ reminder dispatch, team availability, and provider/Postgres persistence.
page membership stays so later tombstones resolve. The round still finishes
as a clean sync. The warning `skipping an Outlook event Macro cannot read`
and the `calendar.outlook_sync` span carry `calendar_id`,
- `provider_event_id` and `rejected_field`.
+ `provider_event_id` and `rejected_field`. Discovery does not fail on a
+ mailbox time zone Macro cannot map to IANA either: `OutlookDiscovery`
+ stores the account's calendars with no `time_zone`, which every reader
+ treats as unknown, as it does a Google calendar's zone it cannot read
+ (reminders and automatic declines anchor all-day dates at UTC, team
+ availability reports the zone missing). The warning `ignoring an Outlook
+ mailbox time zone Macro cannot map` and the span carry `unmapped_time_zone`.
- A sync of a `ready`, already synced account stays `ready`, on Google as on
Outlook, including after a re-grant that kept calendar access, whose sync tokens
survive. Any other state is catching up and marks it `syncing`: a first import,
diff --git a/crates/calendar_events/src/domain/outlook.rs b/crates/calendar_events/src/domain/outlook.rs
index a3071ff2ed..54d4c1a266 100644
--- a/crates/calendar_events/src/domain/outlook.rs
+++ b/crates/calendar_events/src/domain/outlook.rs
@@ -44,6 +44,17 @@ pub struct OutlookCalendar {
pub online_meeting_providers: Vec<String>,
}
+/// Every calendar one Outlook account can see.
+pub struct OutlookDiscovery {
+ /// The account's calendars, each in the mailbox's time zone.
+ pub calendars: Vec<OutlookCalendar>,
+ /// The mailbox time zone Microsoft named when Macro cannot map it to an
+ /// IANA zone. The calendars then carry no time zone rather than failing
+ /// discovery, and every reader treats it as unknown, as it does a Google
+ /// calendar zone it cannot read.
+ pub unmapped_time_zone: Option<String>,
+}
+
/// One page of event identities. Its cursor is staged with its child work.
pub struct OutlookCalendarPage {
/// (Provider occurrence/single ID, normalized master/single ID).
@@ -102,7 +113,7 @@ pub trait OutlookCalendarReader: Send + Sync + 'static {
&self,
token: &str,
binding: CalendarGrantBinding,
- ) -> impl Future<Output = Result<Vec<OutlookCalendar>, CalendarProviderError>> + Send;
+ ) -> impl Future<Output = Result<OutlookDiscovery, CalendarProviderError>> + Send;
/// Fetch one provider page without advancing any checkpoint.
fn calendar_page(
&self,
@@ -229,6 +240,7 @@ impl<
provider_event_id = tracing::field::Empty,
outcome = tracing::field::Empty,
rejected_field = tracing::field::Empty,
+ unmapped_time_zone = tracing::field::Empty,
error_kind = tracing::field::Empty,
),
err(level = tracing::Level::DEBUG)
@@ -327,9 +339,17 @@ impl<
.map_err(storage_error)?;
} else {
span.record("step", "discover");
- let calendars = self.provider.calendars(&token, lease.binding).await?;
+ let discovery = self.provider.calendars(&token, lease.binding).await?;
+ if let Some(zone) = &discovery.unmapped_time_zone {
+ span.record("unmapped_time_zone", zone.as_str());
+ tracing::warn!(
+ account_id = %lease.account_id,
+ unmapped_time_zone = %zone,
+ "ignoring an Outlook mailbox time zone Macro cannot map"
+ );
+ }
self.repository
- .commit_outlook_calendars(lease, calendars)
+ .commit_outlook_calendars(lease, discovery.calendars)
.await
.map_err(storage_error)?;
}
diff --git a/crates/email_api_client/AGENTS.md b/crates/email_api_client/AGENTS.md
index 4d02b4492b..cc53396d2b 100644
--- a/crates/email_api_client/AGENTS.md
+++ b/crates/email_api_client/AGENTS.md
@@ -112,7 +112,16 @@ Outlook (Microsoft Graph) outbound adapters.
log that one event. Give a new check a `Rejected`, not `invalid()`. Graph names UTC `tzone://Microsoft/Utc` on meetings Exchange
imported from another system's invitation, which `zones::zone` maps; a
series end date in a legacy custom zone (`tzone://Microsoft/Custom`) is
- read in the zone the event's time is kept in.
+ read in the zone the event's time is kept in. Calendar discovery reads the
+ mailbox's `mailboxSettings.timeZone` (Windows or IANA) through the same
+ table; a name it cannot map leaves the calendars without a zone and is
+ reported as `OutlookDiscovery::unmapped_time_zone` rather than failing the
+ account. `zones.rs` is CLDR's `windowsZones.xml` (territory `001`, in file
+ order) with its `LICENSE` beside it; regenerate both from a new CLDR
+ release when Windows adds zones. Keep out a zone whose IANA rules the
+ bundled chrono-tz lacks: Outlook writes send local times computed with
+ them, so stale rules move an event. British Columbia, Alberta and Manitoba
+ Standard Time are held out that way until current tz data ships.
- Same-mailbox Outlook replies use `createReply`. When Graph refuses it with
400 `ErrorInvalidOperation`, `create_draft` creates a standalone draft that
carries the same correlation and RFC reply headers.
diff --git a/crates/email_api_client/src/outbound/outlook/calendar.rs b/crates/email_api_client/src/outbound/outlook/calendar.rs
index 5595d7f21b..97a3e42756 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar.rs
+++ b/crates/email_api_client/src/outbound/outlook/calendar.rs
@@ -336,20 +336,19 @@ impl OutlookCalendarReader for OutlookApiClientRepository {
&self,
token: &str,
binding: CalendarGrantBinding,
- ) -> Result<Vec<OutlookCalendar>, CalendarProviderError> {
+ ) -> Result<OutlookDiscovery, CalendarProviderError> {
let api = self.for_mailbox(access(binding));
let token = AccessToken::new(token.to_owned());
let settings = api
.calendar_get(&token, api.calendar_endpoint(&["me", "mailboxSettings"])?)
.await?;
- let zone = zones::zone(settings["timeZone"].as_str().unwrap_or("UTC"))
- .ok_or_else(invalid)?
- .name()
- .to_owned();
+ let named = settings["timeZone"].as_str().unwrap_or("UTC");
+ let zone = zones::zone(named).map(|zone| zone.name().to_owned());
+ let unmapped_time_zone = zone.is_none().then(|| named.to_owned());
let (calendars, _) = api
.calendar_pages(&token, api.calendar_endpoint(&["me", "calendars"])?)
.await?;
- calendars
+ let calendars = calendars
.into_iter()
.map(|c| {
Ok(OutlookCalendar {
@@ -357,7 +356,7 @@ impl OutlookCalendarReader for OutlookApiClientRepository {
provider_calendar_id: string(&c, "id")?.into(),
name: c["name"].as_str().unwrap_or("Calendar").into(),
description: None,
- time_zone: Some(zone.clone()),
+ time_zone: zone.clone(),
color: c["hexColor"]
.as_str()
.filter(|c| !c.is_empty())
@@ -385,7 +384,11 @@ impl OutlookCalendarReader for OutlookApiClientRepository {
.collect(),
})
})
- .collect()
+ .collect::<Result<_, CalendarProviderError>>()?;
+ Ok(OutlookDiscovery {
+ calendars,
+ unmapped_time_zone,
+ })
}
async fn calendar_page(
&self,
diff --git a/crates/email_api_client/src/outbound/outlook/calendar/CLDR-LICENSE.txt b/crates/email_api_client/src/outbound/outlook/calendar/CLDR-LICENSE.txt
index 861b74f3c8..b4132054a5 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar/CLDR-LICENSE.txt
+++ b/crates/email_api_client/src/outbound/outlook/calendar/CLDR-LICENSE.txt
@@ -1,8 +1,26 @@
-UNICODE LICENSE V3
-
COPYRIGHT AND PERMISSION NOTICE
-Copyright © 2004-2025 Unicode, Inc.
+Copyright © 2001–2026 Unicode, Inc.
+
+Unicode Technical Standard #35, Unicode Locale Data Markup Language
+(LDML) made available in this repository is protected by copyright, and
+permission must be obtained from Unicode, Inc. prior to any
+reproduction, modification, or other use not permitted by the Unicode
+Terms of Use <https://www.unicode.org/copyright.html>. Specifically, you
+may make copies of this publication and may annotate and translate it
+solely for personal or internal business purposes and not for public
+distribution, provided that any such permitted copies and modifications
+fully reproduce all copyright and other legal notices contained in the
+original. You may not make copies of or modifications to this
+publication for public distribution, or incorporate it in whole or in
+part into any product or publication without the express written
+permission of Unicode. Notwithstanding the foregoing, you may within
+this repository provide comments and propose changes to this standard
+and may make copies/forks solely for such purposes provided that you
+reproduce this copyright notice and these terms of use in any such
+copy/fork.
+
+All other content in this repo is released under UNICODE LICENSE V3
NOTICE TO USER: Carefully read the following legal agreement. BY
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
diff --git a/crates/email_api_client/src/outbound/outlook/calendar/test.rs b/crates/email_api_client/src/outbound/outlook/calendar/test.rs
index 8d46bd4a14..6c65557bc3 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar/test.rs
+++ b/crates/email_api_client/src/outbound/outlook/calendar/test.rs
@@ -35,6 +35,46 @@ pub(super) fn target() -> ProviderCalendarTarget {
pub(super) fn event(id: &str) -> Value {
json!({"id":id,"@odata.etag":"W/\"1\"","iCalUId":format!("{id}@outlook"),"subject":"Meeting","type":"singleInstance","createdDateTime":"2026-01-01T10:00:00Z","lastModifiedDateTime":"2026-10-01T10:00:00Z","originalStartTimeZone":"Pacific Standard Time","start":{"dateTime":"2026-11-02T17:00:00.0000000","timeZone":"UTC"},"end":{"dateTime":"2026-11-02T18:00:00.0000000","timeZone":"UTC"},"isAllDay":false,"attendees":[]})
}
+/// `GET /me/mailboxSettings` as Graph documents it, with `time_zone` as the
+/// mailbox's zone, or without one when it is `None`. Its working hours keep a
+/// zone of their own.
+pub(super) fn mailbox_settings(time_zone: Option<&str>) -> Value {
+ let mut settings = json!({
+ "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings",
+ "archiveFolder":"AAMkAGI2TGuLAAA=",
+ "automaticRepliesSetting":{
+ "status":"disabled","externalAudience":"all",
+ "scheduledStartDateTime":{"dateTime":"2026-11-04T08:00:00.0000000","timeZone":"UTC"},
+ "scheduledEndDateTime":{"dateTime":"2026-11-05T08:00:00.0000000","timeZone":"UTC"},
+ "internalReplyMessage":"","externalReplyMessage":""
+ },
+ "timeZone":time_zone,
+ "language":{"locale":"en-US","displayName":"English (United States)"},
+ "workingHours":{
+ "daysOfWeek":["monday","tuesday","wednesday","thursday","friday"],
+ "startTime":"08:00:00.0000000","endTime":"17:00:00.0000000",
+ "timeZone":{"name":"Pacific Standard Time"}
+ },
+ "userPurpose":{"value":"user"},
+ "dateFormat":"MM/dd/yyyy","timeFormat":"hh:mm tt",
+ "delegateMeetingMessageDeliveryOptions":"sendToDelegateOnly"
+ });
+ if time_zone.is_none() {
+ settings.as_object_mut().unwrap().remove("timeZone");
+ }
+ settings
+}
+/// The mailbox's default calendar, as `GET /me/calendars` lists it.
+pub(super) fn default_calendar(id: &str) -> Value {
+ json!({
+ "id":id,"name":"Calendar","color":"auto","hexColor":"","isDefaultCalendar":true,
+ "changeKey":"nfZyf7VcrEKLNoU37KWlkQAAA0x0+w==","canShare":true,"canViewPrivateItems":true,
+ "isSharedWithMe":false,"canEdit":true,
+ "allowedOnlineMeetingProviders":["teamsForBusiness"],"defaultOnlineMeetingProvider":"teamsForBusiness",
+ "isTallyingResponses":true,"isRemovable":false,
+ "owner":{"name":"Olivia","address":"[email protected]"}
+ })
+}
pub(super) async fn setup() -> (MockServer, OutlookApiClientRepository) {
let server = MockServer::start().await;
let api = OutlookApiClientRepository::for_test(&format!("{}/v1.0/", server.uri()));
@@ -125,6 +165,68 @@ async fn secondary_calendars_use_complete_v1_views_and_follow_every_page() {
assert!(last.delta.is_none());
}
+/// Discover the calendars of a mailbox whose settings name `time_zone`.
+async fn discover(time_zone: Option<&str>) -> OutlookDiscovery {
+ let (server, api) = setup().await;
+ Mock::given(method("GET"))
+ .and(path("/v1.0/me/mailboxSettings"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(mailbox_settings(time_zone)))
+ .mount(&server)
+ .await;
+ Mock::given(method("GET"))
+ .and(path("/v1.0/me/calendars"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({
+ "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#me/calendars",
+ "value":[default_calendar("AAMkCalendar")],
+ })))
+ .mount(&server)
+ .await;
+ match api.calendars("token", target().binding.unwrap()).await {
+ Ok(discovery) => discovery,
+ Err(_) => panic!("a mailbox in {time_zone:?} fails discovery"),
+ }
+}
+
+#[tokio::test]
+async fn calendars_carry_the_iana_zone_of_the_mailbox() {
+ for (named, iana) in [
+ (Some("Pacific Standard Time"), "America/Los_Angeles"),
+ (Some("America/Los_Angeles"), "America/Los_Angeles"),
+ (None, "Etc/UTC"),
+ ] {
+ let discovery = discover(named).await;
+ assert_eq!(
+ discovery.calendars[0].calendar.time_zone.as_deref(),
+ Some(iana),
+ "{named:?}"
+ );
+ assert_eq!(discovery.unmapped_time_zone, None, "{named:?}");
+ }
+}
+
+#[tokio::test]
+async fn a_mailbox_time_zone_macro_cannot_map_leaves_its_calendars_without_one() {
+ for named in [
+ "tzone://Microsoft/Custom",
+ "Atlantis Standard Time",
+ "",
+ // In CLDR 49, but held out until Macro's tz data has its 2026 rules.
+ "British Columbia Standard Time",
+ ] {
+ let discovery = discover(Some(named)).await;
+ assert_eq!(discovery.calendars.len(), 1, "{named:?}");
+ assert_eq!(
+ discovery.calendars[0].calendar.time_zone, None,
+ "{named:?} is unknown, not UTC"
+ );
+ assert_eq!(
+ discovery.unmapped_time_zone.as_deref(),
+ Some(named),
+ "{named:?}"
+ );
+ }
+}
+
#[test]
fn windows_zones_and_moved_exceptions_preserve_the_original_occurrence() {
let mut master = event("master");
diff --git a/crates/email_api_client/src/outbound/outlook/calendar/test/mutations.rs b/crates/email_api_client/src/outbound/outlook/calendar/test/mutations.rs
index 47470985ba..7c2e367718 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar/test/mutations.rs
+++ b/crates/email_api_client/src/outbound/outlook/calendar/test/mutations.rs
@@ -76,10 +76,13 @@ impl Respond for GraphEvent {
}
}
-pub(super) async fn connected_mailbox(
+/// A connected Outlook inbox with calendar access whose Graph mailbox
+/// answers with `settings` and `calendars`, before its calendars are
+/// discovered.
+pub(super) async fn linked_mailbox(
pool: &PgPool,
server: &MockServer,
- api: &OutlookApiClientRepository,
+ settings: Value,
calendars: Value,
) -> PgCalendarRepository {
let macro_user_id = Uuid::now_v7();
@@ -120,9 +123,7 @@ pub(super) async fn connected_mailbox(
.unwrap();
Mock::given(method("GET"))
.and(path("/v1.0/me/mailboxSettings"))
- .respond_with(
- ResponseTemplate::new(200).set_body_json(json!({"timeZone":"Pacific Standard Time"})),
- )
+ .respond_with(ResponseTemplate::new(200).set_body_json(settings))
.mount(server)
.await;
Mock::given(method("GET"))
@@ -130,7 +131,22 @@ pub(super) async fn connected_mailbox(
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"value":calendars})))
.mount(server)
.await;
- let repo = PgCalendarRepository::new(pool.clone());
+ PgCalendarRepository::new(pool.clone())
+}
+
+pub(super) async fn connected_mailbox(
+ pool: &PgPool,
+ server: &MockServer,
+ api: &OutlookApiClientRepository,
+ calendars: Value,
+) -> PgCalendarRepository {
+ let repo = linked_mailbox(
+ pool,
+ server,
+ mailbox_settings(Some("Pacific Standard Time")),
+ calendars,
+ )
+ .await;
let discovery = repo
.claim_outlook_calendar(
Uuid::now_v7(),
@@ -140,7 +156,7 @@ pub(super) async fn connected_mailbox(
.unwrap()
.unwrap();
let discovered = api.calendars(TOKEN, discovery.binding).await.unwrap();
- repo.commit_outlook_calendars(&discovery, discovered)
+ repo.commit_outlook_calendars(&discovery, discovered.calendars)
.await
.unwrap();
repo
diff --git a/crates/email_api_client/src/outbound/outlook/calendar/test/sync.rs b/crates/email_api_client/src/outbound/outlook/calendar/test/sync.rs
index 2e2ad6241e..cd11fe35cb 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar/test/sync.rs
+++ b/crates/email_api_client/src/outbound/outlook/calendar/test/sync.rs
@@ -1,4 +1,4 @@
-use super::mutations::{IssuedToken, NoOpenClients, OWNER, connected_mailbox};
+use super::mutations::{IssuedToken, NoOpenClients, OWNER, connected_mailbox, linked_mailbox};
use super::*;
use calendar_events::outbound::pg::PgCalendarRepository;
use macro_db_migrator::MACRO_DB_MIGRATIONS;
@@ -221,3 +221,30 @@ async fn a_stored_event_that_turns_unreadable_leaves_the_calendar(pool: PgPool)
"a later tombstone for it still resolves"
);
}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn a_mailbox_in_a_time_zone_macro_cannot_map_still_discovers_and_syncs(pool: PgPool) {
+ let (server, api) = setup().await;
+ let repo = linked_mailbox(
+ &pool,
+ &server,
+ mailbox_settings(Some("tzone://Microsoft/Custom")),
+ json!([default_calendar("AAMkCalendar")]),
+ )
+ .await;
+ let sync = OutlookCalendarSync::new(repo, api, IssuedToken, NoOpenClients);
+ serve_delta(&server, None, &[single("AAMkReadable")], "complete").await;
+ serve_event(&server, upcoming("AAMkReadable")).await;
+ // Discovery, then the calendar's page, its event and the finish.
+ sync_until_idle(&sync).await;
+
+ assert_synced(&pool).await;
+ assert_eq!(imported(&pool).await, vec!["AAMkReadable"]);
+ let time_zone = sqlx::query_scalar!(
+ "SELECT time_zone FROM calendars WHERE provider_calendar_id = 'AAMkCalendar'"
+ )
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert_eq!(time_zone, None, "the calendar's zone is unknown, not UTC");
+}
diff --git a/crates/email_api_client/src/outbound/outlook/calendar/zones.rs b/crates/email_api_client/src/outbound/outlook/calendar/zones.rs
index efabf1e9fa..e03bc247ac 100644
--- a/crates/email_api_client/src/outbound/outlook/calendar/zones.rs
+++ b/crates/email_api_client/src/outbound/outlook/calendar/zones.rs
@@ -1,6 +1,7 @@
-//! Windows to IANA global mappings from Unicode CLDR 48.
-//! Source: https://github.com/unicode-org/cldr/blob/release-48/common/supplemental/windowsZones.xml
-//! License: CLDR-LICENSE.txt in this directory. Generated territory="001" entries.
+//! Windows to IANA global mappings from Unicode CLDR 49.
+//! Source: https://github.com/unicode-org/cldr/blob/release-49/common/supplemental/windowsZones.xml
+//! License: CLDR-LICENSE.txt in this directory. Generated territory="001" entries;
+//! three are held out, as the comment in the table explains.
use chrono_tz::Tz;
/// Graph's own name for UTC, which it gives meetings Exchange imported from
@@ -23,6 +24,10 @@ pub(super) fn zone(name: &str) -> Option<Tz> {
"US Mountain Standard Time" => "America/Phoenix",
"Mountain Standard Time (Mexico)" => "America/Mazatlan",
"Mountain Standard Time" => "America/Denver",
+ // British Columbia, Alberta and Manitoba Standard Time (America/Vancouver,
+ // America/Edmonton, America/Winnipeg) are held out: chrono-tz's bundled
+ // tzdata (2025b) predates their 2026 changes, so mapping them would make
+ // Outlook writes land an hour off. Add them when current tz data ships.
"Yukon Standard Time" => "America/Whitehorse",
"Central America Standard Time" => "America/Guatemala",
"Central Standard Time" => "America/Chicago",