Skip to content

Commit 3d84fc6

Browse files
authored
Pass principal name to delivery hook (#6)
1 parent 323d315 commit 3d84fc6

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

crates/email/src/hooks/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Message {
3434
#[derive(Serialize, Deserialize, Debug, Clone)]
3535
pub struct Request {
3636
pub user_id: String,
37-
pub user_id_num: u32,
37+
pub principal_name: String,
3838
#[serde(skip_serializing_if = "Option::is_none")]
3939
pub envelope: Option<Envelope>,
4040
#[serde(skip_serializing_if = "Option::is_none")]
@@ -79,10 +79,10 @@ pub enum Modification {
7979
}
8080

8181
impl Request {
82-
pub fn new(user_id: String, user_id_num: u32) -> Self {
82+
pub fn new(user_id: String, principal_name: String) -> Self {
8383
Self {
8484
user_id,
85-
user_id_num,
85+
principal_name,
8686
envelope: None,
8787
message: None,
8888
}

crates/email/src/message/delivery_hooks.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,28 @@ pub async fn try_delivery_hook(
6868
})
6969
.collect();
7070

71+
let principal = match server
72+
.directory()
73+
.query(directory::QueryParams::id(user_id))
74+
.await
75+
{
76+
Ok(principal) => match principal {
77+
Some(principal) => principal,
78+
None => {
79+
return Err(
80+
trc::EventType::MessageIngest(trc::MessageIngestEvent::Error).ctx(
81+
trc::Key::Reason,
82+
"User principal not found for delivery hook",
83+
),
84+
);
85+
}
86+
},
87+
Err(err) => return Err(err),
88+
};
89+
7190
let request = hooks::Request::new(
7291
jmap_proto::types::id::Id::from(user_id).as_string(),
73-
user_id,
92+
principal.name,
7493
)
7594
.with_envelope(envelope)
7695
.with_message(hooks::Message {

0 commit comments

Comments
 (0)