@@ -199,7 +199,6 @@ fn validate_identity_value(
199199 identity : & mut ParticipantIdentity ,
200200 allowed_emails : & AHashSet < String > ,
201201) -> Result < ( ) , SetError < ParticipantIdentityProperty > > {
202- let mut changed_address = None ;
203202 for ( property, value) in update. into_expanded_object ( ) {
204203 let Key :: Property ( property) = property else {
205204 return Err ( SetError :: invalid_properties ( )
@@ -213,7 +212,27 @@ fn validate_identity_value(
213212 }
214213 ( ParticipantIdentityProperty :: CalendarAddress , Value :: Str ( value) ) => {
215214 if identity. calendar_address != value {
216- changed_address = Some ( value) ;
215+ let email = if let Some ( email) = value. strip_prefix ( "mailto:" ) {
216+ sanitize_email ( email)
217+ } else {
218+ sanitize_email ( & value)
219+ } ;
220+
221+ if let Some ( email) = email {
222+ if allowed_emails. iter ( ) . any ( |e| e == & email) {
223+ identity. calendar_address = format ! ( "mailto:{email}" ) ;
224+ } else {
225+ return Err ( SetError :: invalid_properties ( )
226+ . with_property ( ParticipantIdentityProperty :: CalendarAddress )
227+ . with_description (
228+ "Calendar address not configured for this account." . to_string ( ) ,
229+ ) ) ;
230+ }
231+ } else {
232+ return Err ( SetError :: invalid_properties ( )
233+ . with_property ( ParticipantIdentityProperty :: CalendarAddress )
234+ . with_description ( "Invalid or missing calendar address." . to_string ( ) ) ) ;
235+ }
217236 }
218237 }
219238 ( property, _) => {
@@ -223,34 +242,10 @@ fn validate_identity_value(
223242 }
224243 }
225244 }
245+
226246 // Validate email address
227247 if !identity. calendar_address . is_empty ( ) {
228- if let Some ( new_address) = changed_address {
229- let email = if let Some ( email) = new_address. strip_prefix ( "mailto:" ) {
230- sanitize_email ( email)
231- } else {
232- sanitize_email ( & new_address)
233- } ;
234-
235- if let Some ( email) = email {
236- if allowed_emails. iter ( ) . any ( |e| e == & email) {
237- identity. calendar_address = format ! ( "mailto:{email}" ) ;
238- Ok ( ( ) )
239- } else {
240- Err ( SetError :: invalid_properties ( )
241- . with_property ( ParticipantIdentityProperty :: CalendarAddress )
242- . with_description (
243- "Calendar address not configured for this account." . to_string ( ) ,
244- ) )
245- }
246- } else {
247- Err ( SetError :: invalid_properties ( )
248- . with_property ( ParticipantIdentityProperty :: CalendarAddress )
249- . with_description ( "Invalid or missing calendar address." . to_string ( ) ) )
250- }
251- } else {
252- Ok ( ( ) )
253- }
248+ Ok ( ( ) )
254249 } else {
255250 Err ( SetError :: invalid_properties ( )
256251 . with_property ( ParticipantIdentityProperty :: CalendarAddress )
0 commit comments