package Ġcc . ch ord flower . template . basic . application Ċ Ċ import Ġcc . ch ord flower . template . basic . application . config . Configuration Ċ import Ġcc . ch ord flower . template . basic . application . events . Event Ċ import Ġcc . ch ord flower . template . basic . application . utils . Context Objects Ċ import Ġio . v avr . control . Option Ċ import Ġio . vertx . core . Vert x Ċ import Ġio . vertx . ext . mail . Mail Client Ċ import Ġio . vertx . ext . mail . Mail Config Ċ import Ġio . vertx . ext . mail . Start TLS Options Ċ import Ġorg . green robot . event bus . EventBus Ċ import Ġorg . green robot . event bus . Subscribe Ċ import Ġorg . green robot . event bus . Thread Mode Ċ import Ġorg . slf 4 j . Logger Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġjavax . annotation . Post Construct Ċ import Ġjavax . annotation . Pre Destroy Ċ import Ġjavax . enterprise . context . Application Scoped Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Named Ċ Ċ @ Application Scoped Ċ @ Named Ċ class ĠMail Listener Ġ@ Inject Ġconstructor ( private Ġval Ġevent Bus : ĠEvent Bus , Ġprivate Ġval Ġvert x : ĠVert x ) Ġ{ ĊĊĠ Ġprivate Ġval Ġlogger Ġ: ĠLogger Ġ= ĠLoggerFactory . getLogger ( Mail Listener :: class . java ) ĊĊĠ Ġ@ Post Construct ĊĠ Ġfun Ġinit () Ġ{ ĊĠĠĠ Ġthis . event Bus . register ( this ) ĊĠ Ġ} ĊĊĠ Ġinternal Ġvar Ġmail Client Creator Ġ: ĠFunction 2 < Vert x , ĠMail Config , ĠMail Client > Ġ= ĠMail Client :: create ĊĊĠ Ġ@ Suppress (" UNUSED _ PARAMETER ") ĊĠ Ġ@ Subscribe ( thread Mode Ġ= ĠThread Mode . POST ING ) ĊĠ Ġfun Ġregister Mail Client ( Ġevent Ġ: ĠEvent . Logger Configured Event ) Ġ{ ĊĠĠĠ Ġlogger . info (" Creating Ġmail Ġclient ") ĊĠĠĠ Ġval Ġconf Ġ= ĠOption . of ( this . vertx . or Create Context . get < Configuration >( Context Objects . CONFIGURATION . key )). getOrElse Throw ( Ġ:: IllegalArgumentException Ġ) ĊĠĠĠ Ġval Ġmail Config Ġ= ĠMail Config () ĊĠĠĠ Ġmail Config . hostname Ġ= Ġconf . mail . address ĊĠĠĠ Ġmail Config . port Ġ= Ġconf . mail . port . toInt () ĊĠĠĠ Ġmail Config . start tls Ġ= Ġif (! conf . mail . secure ) ĠStart TLS Options . DISABLED Ġelse ĠStart TLS Options . REQUIRED ĊĠĠĠ Ġif ( conf . mail . username . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġmail Config . username Ġ= Ġconf . mail . username ĊĠĠĠ Ġ} ĊĠĠĠ Ġif ( conf . mail . password . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġmail Config . password Ġ= Ġconf . mail . password ĊĠĠĠ Ġ} ĊĠĠĠ Ġthis . vertx . or Create Context . put ( Context Objects . MAIL . key , Ġthis . mail Client Creator ( vertx , Ġmail Config )) ĊĠĠĠ Ġlogger . info (" Mail Ġclient Ġcreated ") ĊĠ Ġ} ĊĊĠ Ġ@ Pre Destroy ĊĠ Ġfun Ġdestroy () Ġ{ ĊĠĠĠ Ġthis . event Bus . unregister ( this ) ĊĠ Ġ} Ċ Ċ } Ċ