Produced by Araxis Merge on 12/13/2018 10:35:27 AM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\fw\mail | SynchronousMailService.java | Fri Dec 7 17:36:18 2018 UTC |
| 2 | v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\fw\mail | SynchronousMailService.java | Wed Dec 12 19:46:45 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 560 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /********* ********** ********** ********** ********** ********** ********* | |
| 2 | * Copyrii ght 2004 V HA. All ri ghts reser ved | |
| 3 | ********* ********** ********** ********** ********** ********** *********/ | |
| 4 | // Package | |
| 5 | package go v.va.med.f w.mail; | |
| 6 | ||
| 7 | // Java cl asses | |
| 8 | import jav a.io.Input Stream; | |
| 9 | import jav a.util.Pro perties; | |
| 10 | ||
| 11 | import jav ax.mail.Me ssagingExc eption; | |
| 12 | import jav ax.mail.in ternet.Mim eMessage; | |
| 13 | ||
| 14 | ||
| 15 | import org .apache.co mmons.lang .Validate; | |
| 16 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 17 | import org .springfra mework.bea ns.factory .annotatio n.Value; | |
| 18 | import org .springfra mework.cor e.io.Resou rce; | |
| 19 | import org .springfra mework.mai l.MailExce ption; | |
| 20 | import org .springfra mework.mai l.SimpleMa ilMessage; | |
| 21 | import org .springfra mework.mai l.javamail .JavaMailS ender; | |
| 22 | import org .springfra mework.mai l.javamail .JavaMailS enderImpl; | |
| 23 | import org .springfra mework.mai l.javamail .MimeMailM essage; | |
| 24 | import org .springfra mework.mai l.javamail .MimeMessa geHelper; | |
| 25 | import org .springfra mework.mai l.javamail .MimeMessa gePreparat or; | |
| 26 | import org .springfra mework.ste reotype.Se rvice; | |
| 27 | ||
| 28 | import gov .va.med.fw .service.A bstractCom ponent; | |
| 29 | import gov .va.med.fw .util.Stri ngUtils; | |
| 30 | ||
| 31 | /** | |
| 32 | * Provide s methods to send e- mail messa ges sychro nously. Re fer to a j unit test | |
| 33 | * MailSer viceTest c lass for s ample usag es of this class </b r> | |
| 34 | * | |
| 35 | * | |
| 36 | * Project : Framewor k</br> Cre ated on: 1 1:24:21 AM </br> | |
| 37 | * | |
| 38 | * @author DN S
|
|
| 39 | */ | |
| 40 | @Service | |
| 41 | public cla ss Synchro nousMailSe rvice exte nds Abstra ctComponen t implemen ts MailSer vice { | |
| 42 | ||
| 43 | /* * | |
| 44 | * An instan ce of seri alVersionU ID | |
| 45 | * / | |
| 46 | pr ivate stat ic final l ong serial VersionUID = -261327 0897112223 669L; | |
| 47 | ||
| 48 | /* * | |
| 49 | * An instan ce of mail Sender | |
| 50 | * / | |
| 51 | pr ivate Java MailSender mailSende r = null; | |
| 52 | ||
| 53 | @V alue("${em ailHost}") | |
| 54 | pr ivate Stri ng emailHo st; | |
| 55 | ||
| 56 | @V alue("${em ailSender} ") | |
| 57 | pr ivate Stri ng emailSe nder; | |
| 58 | ||
| 59 | ||
| 60 | /* * | |
| 61 | * A default construct or | |
| 62 | * / | |
| 63 | pu blic Synch ronousMail Service() { | |
| 64 | supe r(); | |
| 65 | } | |
| 66 | ||
| 67 | /* * | |
| 68 | * @see gov. va.med.fw. service.Ab stractComp onent#afte rPropertie sSet() | |
| 69 | * / | |
| 70 | pu blic void afterPrope rtiesSet() throws Ex ception { | |
| 71 | supe r.afterPro pertiesSet (); | |
| 72 | // T he host pr operty nee ds to be s et, and it cannot be set with Autowiring , as the p roperty | |
| 73 | // o nly exists in the im plementati on. | |
| 74 | Java MailSender Impl mailS enderImpl = new Java MailSender Impl(); | |
| 75 | Prop erties pro ps = new P roperties( ); | |
| 76 | prop s.put("mai l.smtp.hos t", emailH ost); // SMTP Host | |
| 77 | prop s.put("mai l.smtp.sta rttls.enab le", "true "); | |
| 78 | prop s.put("mai l.smtp.por t", "25"); | |
| 79 | prop s.put("mai l.smtp.fro m", emailS ender); | |
| 80 | ||
| 81 | mail SenderImpl .setJavaMa ilProperti es(props); | |
| 82 | mail Sender = m ailSenderI mpl; | |
| 83 | } | |
| 84 | ||
| 85 | /* * | |
| 86 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#creat eMimeMessa ge() | |
| 87 | * / | |
| 88 | pu blic MimeM essage cre ateMimeMes sage() { | |
| 89 | retu rn mailSen der.create MimeMessag e(); | |
| 90 | } | |
| 91 | ||
| 92 | /* * | |
| 93 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#creat eMimeMessa ge(java.io .InputStre am) | |
| 94 | * / | |
| 95 | pu blic MimeM essage cre ateMimeMes sage(Input Stream con tentStream ) throws M ailExcepti on { | |
| 96 | retu rn mailSen der.create MimeMessag e(contentS tream); | |
| 97 | } | |
| 98 | ||
| 99 | /* * | |
| 100 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#send( javax.mail .internet. MimeMessag e) | |
| 101 | * / | |
| 102 | pu blic void send(MimeM essage mim eMessage) throws Mai lException { | |
| 103 | mail Sender.sen d(mimeMess age); | |
| 104 | } | |
| 105 | ||
| 106 | /* * | |
| 107 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#send( javax.mail .internet. MimeMessag e[]) | |
| 108 | * / | |
| 109 | pu blic void send(MimeM essage[] m imeMessage s) throws MailExcept ion { | |
| 110 | mail Sender.sen d(mimeMess ages); | |
| 111 | } | |
| 112 | ||
| 113 | /* * | |
| 114 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#send( org.spring framework. mail.javam ail.MimeMe ssagePrepa rator) | |
| 115 | * / | |
| 116 | pu blic void send(MimeM essagePrep arator mim eMessagePr eparator) throws Mai lException { | |
| 117 | mail Sender.sen d(mimeMess agePrepara tor); | |
| 118 | } | |
| 119 | ||
| 120 | /* * | |
| 121 | * @see org. springfram ework.mail .javamail. JavaMailSe nder#send( org.spring framework. mail.javam ail.MimeMe ssagePrepa rator[]) | |
| 122 | * / | |
| 123 | pu blic void send(MimeM essagePrep arator[] m imeMessage Preparator s) throws MailExcept ion { | |
| 124 | mail Sender.sen d(mimeMess agePrepara tors); | |
| 125 | } | |
| 126 | ||
| 127 | /* * | |
| 128 | * @see org. springfram ework.mail .MailSende r#send(org .springfra mework.mai l.SimpleMa ilMessage) | |
| 129 | * / | |
| 130 | pu blic void send(Simpl eMailMessa ge simpleM essage) th rows MailE xception { | |
| 131 | mail Sender.sen d(simpleMe ssage); | |
| 132 | } | |
| 133 | ||
| 134 | /* * | |
| 135 | * @see org. springfram ework.mail .MailSende r#send(org .springfra mework.mai l.SimpleMa ilMessage[ ]) | |
| 136 | * / | |
| 137 | pu blic void send(Simpl eMailMessa ge[] simpl eMessages) throws Ma ilExceptio n { | |
| 138 | mail Sender.sen d(simpleMe ssages); | |
| 139 | } | |
| 140 | ||
| 141 | /* * | |
| 142 | * @see gov. va.med.fw. mail.MailS ervice#sen d(java.lan g.String, | |
| 143 | * org. springfram ework.mail .SimpleMai lMessage) | |
| 144 | * / | |
| 145 | pu blic void send(Strin g text, fi nal Simple MailMessag e template ) throws M ailExcepti on { | |
| 146 | ||
| 147 | // C heck for v alid input arguments | |
| 148 | Vali date.notNu ll(templat e, "A mess age templa te must no t be null" ); | |
| 149 | ||
| 150 | fina l String f ormattedTe xt = prese rveCarriag eReturns(t ext); | |
| 151 | ||
| 152 | // P repare a m essage wit h an attac hed report | |
| 153 | Mime MessagePre parator pr eparator = new MimeM essagePrep arator() { | |
| 154 | public void prep are(MimeMe ssage mime Message) t hrows Mess agingExcep tion { | |
| 155 | MimeMess ageHelper helper = n ew MimeMes sageHelper (mimeMessa ge, true, "UTF-8"); | |
| 156 | MimeMail Message me ssage = ne w MimeMail Message(he lper); | |
| 157 | ||
| 158 | // Copy all messag e properti es from a template t o a messag e | |
| 159 | template .copyTo(me ssage); | |
| 160 | ||
| 161 | // Set a message c ontent | |
| 162 | message. setText(fo rmattedTex t); | |
| 163 | } | |
| 164 | }; | |
| 165 | ||
| 166 | mail Sender.sen d(preparat or); | |
| 167 | } | |
| 168 | ||
| 169 | /* * | |
| 170 | * @see gov. va.med.fw. mail.MailS ervice#sen d(java.lan g.String, | |
| 171 | * java .lang.Stri ng, org.sp ringframew ork.mail.S impleMailM essage) | |
| 172 | * / | |
| 173 | pu blic void send(Strin g text, St ring attac hment, Sim pleMailMes sage templ ate) | |
| 174 | throws MailExcep tion { | |
| 175 | ||
| 176 | // C heck for v alid input arguments | |
| 177 | Vali date.notNu ll(attachm ent, "A me ssage atta chment mus t not be n ull"); | |
| 178 | ||
| 179 | Reso urce resou rce = this .getApplic ationConte xt().getRe source(att achment); | |
| 180 | this .send(pres erveCarria geReturns( text), res ource, tem plate); | |
| 181 | } | |
| 182 | ||
| 183 | /* * | |
| 184 | * @see gov. va.med.fw. mail.MailS ervice#sen d(java.lan g.String, | |
| 185 | * org. springfram ework.core .io.Resour ce, | |
| 186 | * org. springfram ework.mail .SimpleMai lMessage) | |
| 187 | * / | |
| 188 | pu blic void send(Strin g text, fi nal Resour ce resourc e, final S impleMailM essage tem plate) | |
| 189 | throws MailExcep tion { | |
| 190 | ||
| 191 | // C heck for v alid input arguments | |
| 192 | Vali date.notNu ll(resourc e, "A mess age attach ment must not be nul l"); | |
| 193 | Vali date.notNu ll(templat e, "A mess age templa te must no t be null" ); | |
| 194 | ||
| 195 | fina l String f ormattedTe xt = prese rveCarriag eReturns(t ext); | |
| 196 | ||
| 197 | // P repare a m essage wit h an attac hed report | |
| 198 | Mime MessagePre parator pr eparator = new MimeM essagePrep arator() { | |
| 199 | public void prep are(MimeMe ssage mime Message) t hrows Mess agingExcep tion { | |
| 200 | MimeMess ageHelper helper = n ew MimeMes sageHelper (mimeMessa ge, true, "UTF-8"); | |
| 201 | MimeMail Message me ssage = ne w MimeMail Message(he lper); | |
| 202 | template .copyTo(me ssage); | |
| 203 | ||
| 204 | // Attac h a messag e's attach ment | |
| 205 | if (reso urce.exist s()) { | |
| 206 | helper.add Attachment (resource. getFilenam e(), resou rce); | |
| 207 | } | |
| 208 | ||
| 209 | // Set a message t ext | |
| 210 | message. setText(fo rmattedTex t); | |
| 211 | } | |
| 212 | }; | |
| 213 | ||
| 214 | // S end a mess age | |
| 215 | mail Sender.sen d(preparat or); | |
| 216 | } | |
| 217 | ||
| 218 | /* * | |
| 219 | * @see gov. va.med.fw. mail.MailS ervice#sen d(java.lan g.String, | |
| 220 | * org. springfram ework.core .io.Resour ce, | |
| 221 | * org. springfram ework.mail .SimpleMai lMessage) | |
| 222 | * / | |
| 223 | pu blic void send(Strin g text, fi nal Resour ce resourc e, final S impleMailM essage tem plate, | |
| 224 | final String nam e) throws MailExcept ion { | |
| 225 | ||
| 226 | // C heck for v alid input arguments | |
| 227 | Vali date.notNu ll(resourc e, "A mess age attach ment must not be nul l"); | |
| 228 | Vali date.notNu ll(templat e, "A mess age templa te must no t be null" ); | |
| 229 | ||
| 230 | fina l String f ormattedTe xt = prese rveCarriag eReturns(t ext); | |
| 231 | ||
| 232 | // P repare a m essage wit h an attac hed report | |
| 233 | Mime MessagePre parator pr eparator = new MimeM essagePrep arator() { | |
| 234 | public void prep are(MimeMe ssage mime Message) t hrows Mess agingExcep tion { | |
| 235 | MimeMess ageHelper helper = n ew MimeMes sageHelper (mimeMessa ge, true, "UTF-8"); | |
| 236 | MimeMail Message me ssage = ne w MimeMail Message(he lper); | |
| 237 | template .copyTo(me ssage); | |
| 238 | ||
| 239 | // Attac h a messag e's attach ment | |
| 240 | if (reso urce.exist s()) { | |
| 241 | helper.add Attachment (name, res ource); | |
| 242 | } | |
| 243 | ||
| 244 | // Set a message t ext | |
| 245 | message. setText(fo rmattedTex t); | |
| 246 | } | |
| 247 | }; | |
| 248 | ||
| 249 | // S end a mess age | |
| 250 | mail Sender.sen d(preparat or); | |
| 251 | } | |
| 252 | ||
| 253 | /* * | |
| 254 | * @param ma ilSender | |
| 255 | * The mail Sender to set. | |
| 256 | * / | |
| 257 | pu blic void setMailSen der(JavaMa ilSender m ailSender) { | |
| 258 | this .mailSende r = mailSe nder; | |
| 259 | } | |
| 260 | ||
| 261 | /* * | |
| 262 | * Adds a ta b characte r before e ach carria ge return which will cause | |
| 263 | * Microsoft Outlook t o not "rem ove extra line break s". Also, convert "\ r\n" | |
| 264 | * into "\n" since onl y "\n" is needed in e-mail mes sages to k eep carria ge | |
| 265 | * return fo rmatting i n tact. Ot herwise, e xtra carri age return s might re sult | |
| 266 | * when the tab charac ter is ins erted as w ell (i.e. we don't w ant \r\t\n ). | |
| 267 | * | |
| 268 | * @param te xt | |
| 269 | * the raw text. | |
| 270 | * @return t he raw tex t with tab s added. | |
| 271 | * / | |
| 272 | pu blic stati c String p reserveCar riageRetur ns(String text) { | |
| 273 | if ( StringUtil s.isNotEmp ty(text)) { | |
| 274 | text = text.repl aceAll("\r \n", "\n") ; // stand ardizes li ne | |
| 275 | // sep arators | |
| 276 | return text.repl aceAll("\n ", "\t\n") ; | |
| 277 | } el se { | |
| 278 | return text; | |
| 279 | } | |
| 280 | } | |
| 281 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.