Skip to content

Allows users to submit rfc822 formatted email addresses #577

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

Closed
mbernier opened this issue Oct 19, 2017 · 8 comments
Closed

Allows users to submit rfc822 formatted email addresses #577

mbernier opened this issue Oct 19, 2017 · 8 comments
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: twilio enhancement feature request on Twilio's roadmap

Comments

@mbernier
Copy link
Contributor

Issue Summary

Similar to: sendgrid/sendgrid-python#348

Where the user can submit email addresses as:
[email protected]
or
example example <[email protected]>

@brandon93s
Copy link
Contributor

Looks like there is already an implementation in MailHelper that is available to consumers, but not called automatically anywhere.

The constructor for EmailAddress could be updated to call this method, adding support:

/// <summary>
/// Initializes a new instance of the <see cref="EmailAddress"/> class.
/// </summary>
/// <param name="email">The email address of the sender or recipient.</param>
/// <param name="name">The name of the sender or recipient.</param>
public EmailAddress(string email, string name = null)
{
    if (name == null)
    {
        var address = MailHelper.StringToEmailAddress(email);
        this.Email = address.Email;
        this.Name = address.Name;
    }
    else
    {
        this.Email = email;
        this.Name = name;
    }
}

Thoughts?

@thinkingserious thinkingserious added status: help wanted requesting help from the community difficulty: medium fix is medium in difficulty up-for-grabs type: twilio enhancement feature request on Twilio's roadmap labels Mar 1, 2018
@Niladri24dutta
Copy link
Contributor

@thinkingserious I can submit a PR with the change suggested above regarding MailHelper.StringToEmailAddress. Let me know if it's fine.

@thinkingserious
Copy link
Contributor

That would be great, thanks @Niladri24dutta!

@thinkingserious thinkingserious added status: work in progress Twilio or the community is in the process of implementing and removed help wanted status: help wanted requesting help from the community labels Apr 5, 2018
@Niladri24dutta
Copy link
Contributor

Niladri24dutta commented Apr 16, 2018

@thinkingserious just an observation regarding the above approach , MailHelper.StringToEmailAddress calls the EmailAddress class constructor internally . If we use the MailHelper.StringToEmailAddress method in the constructor of EmailAddress class then it may create 2 issues -

  • there will be a cyclic dependency
  • The constructor of EmailAddress class will be called infinite times if the name is null and the email address is matched with RFC2822 format.

To overcome this have created a new overload of the EmailAddress class constructor which accepts a email address and a boolean flag to denote whether email address is in RFC2822 format like below

public EmailAddress(string email, bool isRFC2822Address)

Let me know your view on this before I proceed.

Here is my working branch

https://github.com/Niladri24dutta/sendgrid-csharp/tree/RFC822CompliantEmailSupport

@thinkingserious
Copy link
Contributor

How about factoring out this part:

var email = match.Groups[EmailGroup].Value.Trim();
var name = match.Groups[NameGroup].Value.Trim();

Then you could just call the factored method internally without the cyclic dependency.

With Best Regards,

Elmer

@Niladri24dutta
Copy link
Contributor

Niladri24dutta commented Apr 17, 2018

@thinkingserious Then,do we need to create a new helper method in MailHelper class to include the above code you mentioned or should we refactor the existing StringToEmailAddress method. Because I can see when the email id is not matched then also the EmailAddress class constructor is called as seen below -

var match = Rfc2822Regex.Match(rfc2822Email);
    if (!match.Success)
    {
        return new EmailAddress(rfc2822Email);
     }

https://github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/Helpers/Mail/MailHelper.cs#L139

However,we can change the return type of the StringToEmailAddress to return a Dictionary<string> which can contain the email and name as key value pair.

@thinkingserious
Copy link
Contributor

I think you can encapsulate that check into a utility function, for example, maybe isRfc2822Email(email). We should try to not change StringToEmailAddress's function signature to avoid any breakage. Unless you want to overload the function.

@thinkingserious
Copy link
Contributor

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

4 participants