Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email.Azure: Deconstructing email addresses that include a display name (Lombiq Technologies: OCORE-204) #16889

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

BenedekFarkas
Copy link
Member

Fixes #16888

@BenedekFarkas BenedekFarkas self-assigned this Oct 15, 2024
@@ -224,4 +226,33 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary<string, ILi

return emailMessage;
}

private static EmailAddress ToAzureEmailAddress(string emailWithDisplayName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name should be a verb, why didn't you add this code to ParseEmailAddressWithDisplayName?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name should be a verb

Yeah, I initially intended it to be an extension method, I'll fix that.

why didn't you add this code to ParseEmailAddressWithDisplayName?

ParseEmailAddressWithDisplayName is used separately too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing can we create a virtual method so subclasses can implement how to get the display name

Copy link
Member Author

@BenedekFarkas BenedekFarkas Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is laser-focused on this scenario, so I don't see any reason to override it without overriding the whole email sending logic. But then you can handle email addresses however you want.

@BenedekFarkas BenedekFarkas changed the title Email.Azure: Deconstructing email addresses that include a display name Email.Azure: Deconstructing email addresses that include a display name (Lombiq Technologies: OCORE-204) Oct 15, 2024

private static (string DisplayName, string EmailAddress) TryCreateMailAddressOrFail(string email)
{
if (MailAddress.TryCreate(email, out var mailAddress))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use IEmailAddressValidator instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the deconstructed email address (i.e. the display name and the address itself separately), not just validation.

@@ -187,13 +188,14 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary<string, ILi
}

var emailMessage = new EmailMessage(
message.From,
// For compatibility with configuration for other providers that allow a sender with display name.
CreateMailAddressOrFail(message.From).EmailAddress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can throw an exception. If there is a way it can throw then we should catch it and return the error message since this code here supports error messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, right. It doesn't need to be an exception here, just need to add an error message that will be surfaced.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated error handling.

Copy link
Member

@sebastienros sebastienros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change error message handling if that makes sense or merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure email provider can't handle display names in email addresses
4 participants