rstudio / blastula

Easily send great-looking HTML email messages from R
https://pkgs.rstudio.com/blastula
Other
546 stars 84 forks source link

non-UTF-8 subject in smtp_send() results in malformed email subject #241

Closed shrektan closed 1 year ago

shrektan commented 3 years ago

On Windows, if the subject argument of smtp_send() is not UTF-8 encoded, the received email's subject will become garbage letters.

However, after I add enc2utf8() on the subject value, the received email becomes expected.

Example

smtp_send(subject = "中文")  # I have to provide `enc2utf8("中文")` as a workaround

The malformed subject

image

Use enc2utf8()

image

chuxinyuan commented 2 years ago

我这边即使是用了enc2utf8()函数依然会给出警告信息:

Warning message:
In sprintf("=?utf-8?B?%s?=", base64enc::base64encode(charToRaw(str)),  :
  one argument not used by format '=?utf-8?B?%s?='
xfun::session_info("blastula")
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.3 LTS
#> 
#> Locale:
#>   LC_CTYPE=zh_CN.UTF-8       LC_NUMERIC=C              
#>   LC_TIME=zh_CN.UTF-8        LC_COLLATE=zh_CN.UTF-8    
#>   LC_MONETARY=zh_CN.UTF-8    LC_MESSAGES=zh_CN.UTF-8   
#>   LC_PAPER=zh_CN.UTF-8       LC_NAME=C                 
#>   LC_ADDRESS=C               LC_TELEPHONE=C            
#>   LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C       
#> 
#> Package version:
#>   askpass_1.1      base64enc_0.1.3  blastula_0.3.2   cli_3.1.0       
#>   commonmark_1.7   crayon_1.4.2     curl_4.3.2       digest_0.6.28   
#>   dplyr_1.0.7      ellipsis_0.3.2   evaluate_0.14    fansi_0.5.0     
#>   fastmap_1.1.0    fs_1.5.0         generics_0.1.1   getPass_0.2.2   
#>   glue_1.5.0       graphics_4.1.2   grDevices_4.1.2  here_1.0.1      
#>   highr_0.9        htmltools_0.5.2  httr_1.4.2       jquerylib_0.1.4 
#>   jsonlite_1.7.2   knitr_1.36       lifecycle_1.0.1  magrittr_2.0.1  
#>   methods_4.1.2    mime_0.12        openssl_1.4.5    pillar_1.6.4    
#>   pkgconfig_2.0.3  purrr_0.3.4      R6_2.5.1         rlang_0.4.12    
#>   rmarkdown_2.11   rprojroot_2.0.2  rstudioapi_0.13  stats_4.1.2     
#>   stringi_1.7.5    stringr_1.4.0    sys_3.4          tibble_3.1.6    
#>   tidyselect_1.1.1 tinytex_0.35     tools_4.1.2      utf8_1.2.2      
#>   utils_4.1.2      uuid_1.0.3       vctrs_0.3.8      xfun_0.28       
#>   yaml_2.2.1

Created on 2021-12-20 by the reprex package (v2.0.1)

shrektan commented 2 years ago

Your issue should have nothing to do with mine, as you are using Ubuntu where the native encoding is UTF-8, unlike Windows.

chuxinyuan commented 2 years ago

Your issue should have nothing to do with mine, as you are using Ubuntu where the native encoding is UTF-8, unlike Windows.

因为我用的双系统,我要保证在Win和Ubuntu下都能运行,所以还是保留了enc2utf8()以防万一。我现在对mine.R里面的一行代码感到困惑:

str <- sprintf("=?utf-8?B?%s?=", base64enc::base64encode(charToRaw(str)), 0)

每次都是这行代码报警示信息。

chuxinyuan commented 2 years ago

这个问题很久都没人解决了。

chuxinyuan commented 10 months ago
The email message was sent successfully.
Warning message:
In sprintf("=?utf-8?B?%s?=", base64enc::base64encode(charToRaw(str)),  :
  one argument not used by format '=?utf-8?B?%s?='

@rich-iannone @shrektan I don't know how to eliminate this prompt.