datawookie / emayili

An R package for sending email messages.
https://datawookie.github.io/emayili/
179 stars 27 forks source link

[FEAT]: Comma-separated display name #115

Closed 2ndmax closed 2 years ago

2ndmax commented 2 years ago

Description

Hello, in my company the display name of an e-mail address is comma-separated, e.g. 'Smith, Quentin test@domain.com'. When I provide a display name in that format, the emayili functions seem to treat that comma as a separator for multiple addresses or display names.

I understand that addresses can be provides in multiple formats, e.g. as separate strings, vectors or a single comma-separated string. This last option, however, seems to prevent me from formatting the display name that way. At least so far I did not find a way to circumvent that behavior. I would be great if I could :-)

Input: emayili::as.address("Smith, Quentin <test@domain.com>")

Output Now: [1] "Smith" [2] "Quentin <test@domain.com>"

Output Could Be: [1] "Smith, Quentin <test@domain.com>"

Lastly: Thank you for your work, I like using emayili :-)

datawookie commented 2 years ago

Hi @2ndmax,

No problem. I've added an additional argument to the as.address() function.

# Display name as "First Last".
> as.address("Quentin Smith <test@domain.com>")
[1] "Quentin Smith <test@domain.com>"
# Display name as "Last, First".
> as.address("Smith, Quentin <test@domain.com>", split = FALSE)
[1] "Smith, Quentin <test@domain.com>"

This update is only available on GitHub for the moment. Would you mind please testing and letting me know if this resolves your issue?

remotes::install_github("datawookie/emayili")

Thanks, Andrew.

2ndmax commented 2 years ago

Hi @datawookie

Thank you for your kind reply. It works for the as.address() function as I would expect it.

I would additionally recommend to make this splitting argument available for the higher level functions to(), cc() and bcc(), so they can pass this argument to as.address(). Right now an address object can be created using as.address(), but if this is passed on to to(), cc() or bcc(), this address object will be processed again, split and treated as two addresses. That corrupts the e-mail headers.

emayili::envelope() |> emayili::cc("Quentin Smith <test@domain.com>") |> print()

emayili::envelope() |> emayili::cc("Smith, Quentin <test@domain.com>") |> print()

output

Could become:

emayili::envelope() |> emayili::cc("Smith, Quentin <test@domain.com>", split = FALSE)

Thanks and have a nice day.

Maik.

datawookie commented 2 years ago

Hi @2ndmax,

Aha! Good point.

I've implemented the required changes and pushed them to GitHub. I'd appreciate it if you did some testing and let me know how well it works for you.

Thanks, Andrew.

2ndmax commented 2 years ago

Yes, that works wonderful - thank you! :-)

However - I encountered some behavior in another function, that was different before. The combination of address() and to() leads to a break in the headers that should not be there. That happens even if I do not provide any special character in the display name.

The address() function itself seems to produce the same output as before - so far I do not know what change might have caused that... sorry if my request led to some unexpected side effects...

Version 0.7.0:

v07

Version 0.7.4:

v74

datawookie commented 2 years ago

Hi @2ndmax, thanks for spotting that. I've implemented a fix, which is available on the address branch. Would you mind testing, please? Thanks, Andrew.

You can install as follows:

remotes::install_github("datawookie/emayili", ref = "address")

Similar code to your screenshots:

envelope() %>%
     to(address(display = "Quentin Smith", email = "test@domain.com")) %>%
     cc(address(display = "Smith, Quentin", email = "test@domain.com")) %>%
     print()

envelope() |>
     to("Quentin Smith <test@domain.com>") |>
     cc("Smith, Quentin  <test@domain.com>", split = FALSE) |>
     print()
2ndmax commented 2 years ago

Hello @datawookie, I tested it and it works fine.

Thank you for implementing this. That makes things a little easier for me :-)

Thanks, Maik

datawookie commented 2 years ago

Hi @2ndmax, I've made some changes to how I handle display names in the 'Last, First' order. Can you please test the latest version on the master branch to ensure that it still satisfies the issues raised here? Thanks, Andrew.

FYI: I'm using the approach that I used to handle non-ASCII characters to provide a neater solution to this problem.

2ndmax commented 2 years ago

Sure, @datawookie.

I pulled the master branch and both comma separation and UTF-8 encoding work fine.

If you need additional testing, please let me know.

datawookie commented 2 years ago

Wonderful. Thanks, @2ndmax, I've really enjoyed collaborating with you on these new features.

2ndmax commented 2 years ago

And thank you for taking on these challenges :-)