olafmersmann / sendmailR

Simple SMTP client implementation for R.
14 stars 11 forks source link

Setting the MIME type in mime_part() for files does not work #9

Closed innir closed 1 year ago

innir commented 1 year ago

Hi,

while the method mime_part.character() has a parameter type it is not passed down to .file_attachment() in https://github.com/olafmersmann/sendmailR/blob/main/R/mime_part.R#L210:

> attachment <- sendmailR::mime_part("/etc/group", "group", type = "text/plain") 
> attachment$headers$`Content-Type`
[1] "application/octet-stream"

vs.

> attachment2 <- sendmailR:::.file_attachment("/etc/group", "group", type = "text/plain")
> attachment2$headers$`Content-Type`
[1] "text/plain"

I didn't open a PR because it's not completely obvious how to handle this. One idea would be to use the package mime to guess the MIME type of the file.

olafmersmann commented 1 year ago

That looks like a bug to me. I think the most straight forward way would be:

  1. Check if a mime type is given, if yes do as the user wishes.
  2. Check for the mime package and if available use it to guess the mime type.
  3. Default to the safe bet of application/octet-stream.

I don't want an explicit dependency on mime because I know of users who work in environments where it is hard to bring in additional dependencies.

Feel free to submit a PR, I can't promise when I will get around to implementing anything :/

innir commented 1 year ago

I didn't include checking if mime is installed or not, I guess it's easier if users just provide the MIME type guessed by mime directly.