@@ -51,8 +51,11 @@ async function sendArticle ({ article, feedTitle, feedUrl, toAddresses }) {
5151 const domainsAllowedImagesAttached = process . env . DOMAINS_ALLOWED_ATTACHED_IMAGES || [ ] ;
5252 const isDomainAllowedForImages = domainsAllowedImagesAttached . includes ( new URL ( article . link ) . host ) ;
5353
54+ const usersAllowAttachmentsInEmail = toAddresses . filter ( recipient => recipient . allowAttachmentsInEmail ) ;
55+ const usersNotAllowAttachmentsInEmail = toAddresses . filter ( recipient => ! recipient . allowAttachmentsInEmail ) ;
56+
5457 let thumbnailBase64 ;
55- if ( isDomainAllowedForImages && thumbnail ) {
58+ if ( isDomainAllowedForImages && thumbnail && usersAllowAttachmentsInEmail . length ) {
5659 try {
5760 thumbnailBase64 = await imageToBase64 ( thumbnail ) ;
5861 } catch ( error ) {
@@ -78,7 +81,7 @@ async function sendArticle ({ article, feedTitle, feedUrl, toAddresses }) {
7881
7982 const mailOptions = {
8083 from : process . env . GMAIL_USER ,
81- bcc : toAddresses . filter ( recipient => recipient . allowAttachmentsInEmail ) . map ( recipient => recipient . address ) ,
84+ bcc : usersAllowAttachmentsInEmail . map ( recipient => recipient . address ) ,
8285 subject : `${ feedTitle } ⟫ ${ title } ` ,
8386 html : await ejs . renderFile ( path . join ( __dirname , '../templates' , 'article.ejs' ) , ejsData ) ,
8487 attachments : [ ]
@@ -93,21 +96,16 @@ async function sendArticle ({ article, feedTitle, feedUrl, toAddresses }) {
9396
9497 const promises = [ ] ;
9598
96- const usersAllowAttachmentsInEmail = toAddresses . filter ( recipient => recipient . allowAttachmentsInEmail ) ;
97- const usersNotAllowAttachmentsInEmail = toAddresses . filter ( recipient => ! recipient . allowAttachmentsInEmail ) ;
98-
9999 if ( usersAllowAttachmentsInEmail . length && isDomainAllowedForImages ) {
100100 promises . push ( transporter . sendMail ( mailOptions ) ) ;
101101 }
102102
103103 if ( usersNotAllowAttachmentsInEmail . length ) {
104104 ejsData . imageUrl = thumbnail ;
105105 promises . push ( transporter . sendMail ( {
106- mailOptions : {
107- ...mailOptions ,
108- bcc : usersNotAllowAttachmentsInEmail . map ( recipient => recipient . address ) ,
109- attachments : [ ]
110- }
106+ ...mailOptions ,
107+ bcc : usersNotAllowAttachmentsInEmail . map ( recipient => recipient . address ) ,
108+ attachments : [ ]
111109 } )
112110 ) ;
113111 }
0 commit comments