Skip to content

Commit

Permalink
handle RecipientsNotFoundError for calendar event cancellations, #2975
Browse files Browse the repository at this point in the history
  • Loading branch information
vaf-hub committed Apr 27, 2021
1 parent 2a2f088 commit 5d56ed1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/calendar/CalendarUpdateDistributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {CalendarEventAttendee} from "../api/entities/tutanota/CalendarEvent
import {createCalendarEventAttendee} from "../api/entities/tutanota/CalendarEventAttendee"
import {isTutanotaMailAddress} from "../api/common/RecipientInfo"
import {createMailAddress} from "../api/entities/tutanota/MailAddress"
import {RecipientsNotFoundError} from "../api/common/error/RecipientsNotFoundError"

export interface CalendarUpdateDistributor {
sendInvite(existingEvent: CalendarEvent, sendMailModel: SendMailModel): Promise<void>;
Expand Down Expand Up @@ -72,6 +73,21 @@ export class CalendarMailDistributor implements CalendarUpdateDistributor {
body: makeInviteEmailBody(sender, event, message),
event,
sender
}).catch(RecipientsNotFoundError, e => {
// we want to delete the event even if the recipient is not an existing tutanota address
// and just exclude them from sending out updates but leave the event untouched for other recipients
const invalidRecipients = e.message.split("\n")
let hasRemovedRecipient = false
invalidRecipients.forEach(invalidRecipient => {
const recipientInfo = sendMailModel.bccRecipients().find(r => r.mailAddress === invalidRecipient)
if (recipientInfo) {
hasRemovedRecipient = sendMailModel.removeRecipient(recipientInfo, "bcc", false) || hasRemovedRecipient
}
})
// only try sending again if we successfully removed a recipient and there are still other recipients
if (hasRemovedRecipient && sendMailModel.allRecipients().length) {
return this.sendCancellation(event, sendMailModel)
}
})
}

Expand Down
9 changes: 7 additions & 2 deletions src/mail/editor/SendMailModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ApprovalStatus,
ConversationType,
MailFolderType,
MailMethod,
MAX_ATTACHMENT_SIZE,
OperationType,
ReplyType
Expand Down Expand Up @@ -751,8 +752,12 @@ export class SendMailModel {
// catch all of the badness
.catch(RecipientNotResolvedError, () => {throw new UserError("tooManyAttempts_msg")})
.catch(RecipientsNotFoundError, (e) => {
let invalidRecipients = e.message
throw new UserError(() => lang.get("invalidRecipients_msg") + "\n" + invalidRecipients)
if (mailMethod === MailMethod.ICAL_CANCEL) {
//in case of calendar event cancellation we willremove invalid recipients and then delete the event without sending updates
throw e
} else {
throw new UserError(() => lang.get("invalidRecipients_msg") + "\n" + e.message)
}
})
.catch(TooManyRequestsError, () => {throw new UserError(tooManyRequestsError)})
.catch(AccessBlockedError, e => {
Expand Down

0 comments on commit 5d56ed1

Please sign in to comment.