1- const nodemailer = require ( "nodemailer" )
2- const core = require ( "@actions/core" )
3- const glob = require ( "@actions/glob" )
4- const fs = require ( "fs" )
5- const showdown = require ( "showdown" )
6- const path = require ( "path" )
1+ const nodemailer = require ( "nodemailer" ) ;
2+ const core = require ( "@actions/core" ) ;
3+ const glob = require ( "@actions/glob" ) ;
4+ const fs = require ( "fs" ) ;
5+ const showdown = require ( "showdown" ) ;
6+ const path = require ( "path" ) ;
77
88function getText ( textOrFile , convertMarkdown ) {
9- let text = textOrFile
9+ let text = textOrFile ;
1010
1111 // Read text from file
1212 if ( textOrFile . startsWith ( "file://" ) ) {
13- const file = textOrFile . replace ( "file://" , "" )
14- text = fs . readFileSync ( file , "utf8" )
13+ const file = textOrFile . replace ( "file://" , "" ) ;
14+ text = fs . readFileSync ( file , "utf8" ) ;
1515 }
1616
1717 // Convert Markdown to HTML
1818 if ( convertMarkdown ) {
19- const converter = new showdown . Converter ( { tables : true } )
20- text = converter . makeHtml ( text )
19+ const converter = new showdown . Converter ( { tables : true } ) ;
20+ text = converter . makeHtml ( text ) ;
2121 }
2222
23- return text
23+ return text ;
2424}
2525
2626function getFrom ( from , username ) {
2727 if ( from . match ( / .+ < .+ @ .+ > / ) ) {
28- return from
28+ return from ;
2929 }
3030
31- return `"${ from } " <${ username } >`
31+ return `"${ from } " <${ username } >` ;
3232}
3333
3434async function getAttachments ( attachments ) {
35- const globber = await glob . create ( attachments . split ( ',' ) . join ( '\n' ) )
36- const files = await globber . glob ( )
37- return files . map ( f => ( { filename : path . basename ( f ) , path : f , cid : f . replace ( / ^ .* [ \\ \/ ] / , '' ) } ) )
35+ const globber = await glob . create ( attachments . split ( "," ) . join ( "\n" ) ) ;
36+ const files = await globber . glob ( ) ;
37+ return files . map ( ( f ) => ( {
38+ filename : path . basename ( f ) ,
39+ path : f ,
40+ cid : f . replace ( / ^ .* [ \\ \/ ] / , "" ) ,
41+ } ) ) ;
3842}
3943
4044function sleep ( ms ) {
4145 return new Promise ( ( resolve ) => {
42- setTimeout ( resolve , ms ) ;
46+ setTimeout ( resolve , ms ) ;
4347 } ) ;
4448}
4549
4650async function main ( ) {
4751 try {
48- let serverAddress = core . getInput ( "server_address" )
49- let serverPort = core . getInput ( "server_port" )
50- let secure = core . getInput ( "secure" )
51- let username = core . getInput ( "username" )
52- let password = core . getInput ( "password" )
52+ let serverAddress = core . getInput ( "server_address" ) ;
53+ let serverPort = core . getInput ( "server_port" ) ;
54+ let secure = core . getInput ( "secure" ) ;
55+ let username = core . getInput ( "username" ) ;
56+ let password = core . getInput ( "password" ) ;
5357
5458 if ( ! secure ) {
55- secure = serverPort === "465" ? "true" : "false"
59+ secure = serverPort === "465" ? "true" : "false" ;
5660 }
5761
58- const connectionUrl = core . getInput ( "connection_url" )
62+ const connectionUrl = core . getInput ( "connection_url" ) ;
5963 if ( connectionUrl ) {
60- const url = new URL ( connectionUrl )
64+ const url = new URL ( connectionUrl ) ;
6165 switch ( url . protocol ) {
6266 default :
63- throw new Error ( `Unsupported connection protocol '${ url . protocol } '` )
67+ throw new Error (
68+ `Unsupported connection protocol '${ url . protocol } '`
69+ ) ;
6470 case "smtp:" :
65- serverPort = "25"
66- secure = "false"
67- break
71+ serverPort = "25" ;
72+ secure = "false" ;
73+ break ;
6874 case "smtp+starttls:" :
69- serverPort = "465"
70- secure = "true"
71- break
75+ serverPort = "465" ;
76+ secure = "true" ;
77+ break ;
7278 }
7379 if ( url . hostname ) {
74- serverAddress = url . hostname
80+ serverAddress = url . hostname ;
7581 }
7682 if ( url . port ) {
77- serverPort = url . port
83+ serverPort = url . port ;
7884 }
7985 if ( url . username ) {
80- username = unescape ( url . username )
86+ username = unescape ( url . username ) ;
8187 }
8288 if ( url . password ) {
83- password = unescape ( url . password )
89+ password = unescape ( url . password ) ;
8490 }
8591 }
8692
87- const subject = core . getInput ( "subject" , { required : true } )
88- const from = core . getInput ( "from" , { required : true } )
89- const to = core . getInput ( "to" , { required : false } )
90- const body = core . getInput ( "body" , { required : false } )
91- const htmlBody = core . getInput ( "html_body" , { required : false } )
92- const cc = core . getInput ( "cc" , { required : false } )
93- const bcc = core . getInput ( "bcc" , { required : false } )
94- const replyTo = core . getInput ( "reply_to" , { required : false } )
95- const inReplyTo = core . getInput ( "in_reply_to" , { required : false } )
96- const attachments = core . getInput ( "attachments" , { required : false } )
97- const convertMarkdown = core . getInput ( "convert_markdown" , { required : false } )
98- const ignoreCert = core . getInput ( "ignore_cert" , { required : false } )
99- const priority = core . getInput ( "priority" , { required : false } )
100- const nodemailerlog = core . getInput ( "nodemailerlog" , { required : false } )
101- const nodemailerdebug = core . getInput ( "nodemailerdebug" , { required : false } )
102- const envelopeFrom = core . getInput ( "envelope_from" , { required : false } )
103- const envelopeTo = core . getInput ( "envelope_to" , { required : false } )
93+ const subject = core . getInput ( "subject" , { required : true } ) ;
94+ const from = core . getInput ( "from" , { required : true } ) ;
95+ const to = core . getInput ( "to" , { required : false } ) ;
96+ const body = core . getInput ( "body" , { required : false } ) ;
97+ const htmlBody = core . getInput ( "html_body" , { required : false } ) ;
98+ const cc = core . getInput ( "cc" , { required : false } ) ;
99+ const bcc = core . getInput ( "bcc" , { required : false } ) ;
100+ const replyTo = core . getInput ( "reply_to" , { required : false } ) ;
101+ const inReplyTo = core . getInput ( "in_reply_to" , { required : false } ) ;
102+ const attachments = core . getInput ( "attachments" , { required : false } ) ;
103+ const convertMarkdown = core . getInput ( "convert_markdown" , {
104+ required : false ,
105+ } ) ;
106+ const ignoreCert = core . getInput ( "ignore_cert" , { required : false } ) ;
107+ const priority = core . getInput ( "priority" , { required : false } ) ;
108+ const nodemailerlog = core . getInput ( "nodemailerlog" , {
109+ required : false ,
110+ } ) ;
111+ const nodemailerdebug = core . getInput ( "nodemailerdebug" , {
112+ required : false ,
113+ } ) ;
114+ const envelopeFrom = core . getInput ( "envelope_from" , {
115+ required : false ,
116+ } ) ;
117+ const envelopeTo = core . getInput ( "envelope_to" , { required : false } ) ;
104118
105119 // if neither to, cc or bcc is provided, throw error
106120 if ( ! to && ! cc && ! bcc ) {
107- throw new Error ( "At least one of 'to', 'cc' or 'bcc' must be specified" )
121+ throw new Error (
122+ "At least one of 'to', 'cc' or 'bcc' must be specified"
123+ ) ;
108124 }
109-
125+
110126 if ( ! serverAddress ) {
111- throw new Error ( "Server address must be specified" )
127+ throw new Error ( "Server address must be specified" ) ;
112128 }
113129
114130 const transport = nodemailer . createTransport ( {
115131 host : serverAddress ,
116- auth : username && password ? {
117- user : username ,
118- pass : password
119- } : undefined ,
132+ auth :
133+ username && password
134+ ? {
135+ user : username ,
136+ pass : password ,
137+ }
138+ : undefined ,
120139 port : serverPort ,
121140 secure : secure === "true" ,
122- tls : ignoreCert == "true" ? {
123- rejectUnauthorized : false
124- } : undefined ,
141+ tls :
142+ ignoreCert == "true"
143+ ? {
144+ rejectUnauthorized : false ,
145+ }
146+ : undefined ,
125147 logger : nodemailerdebug == "true" ? true : nodemailerlog ,
126148 debug : nodemailerdebug ,
127- } )
149+ } ) ;
128150
129151 var i = 1 ;
130152 while ( true ) {
@@ -139,22 +161,29 @@ async function main() {
139161 inReplyTo : inReplyTo ? inReplyTo : undefined ,
140162 references : inReplyTo ? inReplyTo : undefined ,
141163 text : body ? getText ( body , false ) : undefined ,
142- html : htmlBody ? getText ( htmlBody , convertMarkdown ) : undefined ,
164+ html : htmlBody
165+ ? getText ( htmlBody , convertMarkdown )
166+ : undefined ,
143167 priority : priority ? priority : undefined ,
144- attachments : attachments ? ( await getAttachments ( attachments ) ) : undefined ,
145- envelope : ( envelopeFrom || envelopeTo ) ? {
146- from : envelopeFrom ? envelopeFrom : undefined ,
147- to : envelopeTo ? envelopeTo : undefined
148- } : undefined
168+ attachments : attachments
169+ ? await getAttachments ( attachments )
170+ : undefined ,
171+ envelope :
172+ envelopeFrom || envelopeTo
173+ ? {
174+ from : envelopeFrom ? envelopeFrom : undefined ,
175+ to : envelopeTo ? envelopeTo : undefined ,
176+ }
177+ : undefined ,
149178 } ) ;
150179 break ;
151180 } catch ( error ) {
152181 if ( ! error . message . includes ( "Try again later," ) ) {
153- core . setFailed ( error . message )
182+ core . setFailed ( error . message ) ;
154183 break ;
155184 }
156185 if ( i > 10 ) {
157- core . setFailed ( error . message )
186+ core . setFailed ( error . message ) ;
158187 break ;
159188 }
160189 console . log ( "Received: " + error . message ) ;
@@ -168,8 +197,8 @@ async function main() {
168197 }
169198 }
170199 } catch ( error ) {
171- core . setFailed ( error . message )
200+ core . setFailed ( error . message ) ;
172201 }
173202}
174203
175- main ( )
204+ main ( ) ;
0 commit comments