Produced by Araxis Merge on 9/25/2018 2:13:12 PM Central Daylight 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 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\net\smtp | SmtpClient.java | Mon Jan 22 14:46:54 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\net\smtp | SmtpClient.java | Wed Sep 12 17:45:01 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 580 |
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 | * Copyrig ht (c) 199 5, 2017, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package su n.net.smtp ; | |
27 | ||
28 | import jav a.util.Str ingTokeniz er; | |
29 | import jav a.io.*; | |
30 | import jav a.net.*; | |
31 | import sun .net.Trans ferProtoco lClient; | |
32 | ||
33 | /** | |
34 | * This cl ass implem ents the S MTP client . | |
35 | * You can send a pi ece of mai l by creat ing a new SmtpClient , calling | |
36 | * the "to " method t o add dest inations, calling "f rom" to na me the | |
37 | * sender, calling s tartMessag e to retur n a stream to which you write | |
38 | * the mes sage (with RFC733 he aders) and then you finally cl ose the Sm tp | |
39 | * Client. | |
40 | * | |
41 | * @author Jame s Gosling | |
42 | */ | |
43 | ||
44 | public cla ss SmtpCli ent extend s Transfer ProtocolCl ient { | |
45 | ||
46 | private st atic int D EFAULT_SMT P_PORT
|
|
47 | String mailhost; | |
48 | SmtpPr intStream message; | |
49 | ||
50 | /** | |
51 | * iss ue the QUI T command to the SMT P server a nd close t he connect ion. | |
52 | */ | |
53 | public void clos eServer() throws IOE xception { | |
54 | if (serverIs Open()) { | |
55 | closeMes sage(); | |
56 | issueCom mand("QUIT \r\n", 221 ); | |
57 | super.cl oseServer( ); | |
58 | } | |
59 | } | |
60 | ||
61 | void i ssueComman d(String c md, int ex pect) thro ws IOExcep tion { | |
62 | se ndServer(c md); | |
63 | in t reply; | |
64 | wh ile ((repl y = readSe rverRespon se()) != e xpect) | |
65 | if (repl y != 220) { | |
66 | thro w new Smtp ProtocolEx ception(ge tResponseS tring()); | |
67 | } | |
68 | } | |
69 | ||
70 | privat e void toC anonical(S tring s) t hrows IOEx ception { | |
71 | if (s.starts With("<")) | |
72 | issueCom mand("rcpt to: " + s + "\r\n", 250); | |
73 | el se | |
74 | issueCom mand("rcpt to: <" + s + ">\r\n ", 250); | |
75 | } | |
76 | ||
77 | public void to(S tring s) t hrows IOEx ception { | |
78 | if (s.indexO f('\n') != -1) { | |
79 | throw ne w IOExcept ion("Illeg al SMTP co mmand", | |
80 | new Illega lArgumentE xception(" Illegal ca rriage ret urn")); | |
81 | } | |
82 | in t st = 0; | |
83 | in t limit = s.length() ; | |
84 | in t pos = 0; | |
85 | in t lastnons p = 0; | |
86 | in t parendep th = 0; | |
87 | bo olean igno re = false ; | |
88 | wh ile (pos < limit) { | |
89 | int c = s.charAt(p os); | |
90 | if (pare ndepth > 0 ) { | |
91 | if ( c == '(') | |
92 | parendepth ++; | |
93 | else if (c == ')') | |
94 | parendepth --; | |
95 | if ( parendepth == 0) | |
96 | if (lastno nsp > st) | |
97 | ignore = true; | |
98 | else | |
99 | st = p os + 1; | |
100 | } else i f (c == '( ') | |
101 | pare ndepth++; | |
102 | else if (c == '<') | |
103 | st = lastnonsp = pos + 1 ; | |
104 | else if (c == '>') | |
105 | igno re = true; | |
106 | else if (c == ',') { | |
107 | if ( lastnonsp > st) | |
108 | toCanonica l(s.substr ing(st, la stnonsp)); | |
109 | st = pos + 1; | |
110 | igno re = false ; | |
111 | } else { | |
112 | if ( c > ' ' && !ignore) | |
113 | lastnonsp = pos + 1; | |
114 | else if (st == pos) | |
115 | st++; | |
116 | } | |
117 | pos++; | |
118 | } | |
119 | if (lastnons p > st) | |
120 | toCanoni cal(s.subs tring(st, lastnonsp) ); | |
121 | } | |
122 | ||
123 | public void from (String s) throws IO Exception { | |
124 | if (s.indexO f('\n') != -1) { | |
125 | throw ne w IOExcept ion("Illeg al SMTP co mmand", | |
126 | new Illega lArgumentE xception(" Illegal ca rriage ret urn")); | |
127 | } | |
128 | if (s.starts With("<")) { | |
129 | issueCom mand("mail from: " + s + "\r\n ", 250); | |
130 | } else { | |
131 | issueCom mand("mail from: <" + s + ">\r \n", 250); | |
132 | } | |
133 | } | |
134 | ||
135 | /** op en a SMTP connection to host < i>host</i> . */ | |
136 | privat e void ope nServer(St ring host) throws IO Exception { | |
137 | ma ilhost = h ost; | |
138 | op enServer(m ailhost, D EFAULT_SMT P_PORT); | |
139 | is sueCommand ("helo "+I netAddress .getLocalH ost().getH ostName()+ "\r\n", 25 0); | |
140 | } | |
141 | ||
142 | public PrintStre am startMe ssage() th rows IOExc eption { | |
143 | is sueCommand ("data\r\n ", 354); | |
144 | tr y { | |
145 | message = new Smtp PrintStrea m(serverOu tput, this ); | |
146 | } catch (Uns upportedEn codingExce ption e) { | |
147 | throw ne w Internal Error(enco ding+" enc oding not found", e) ; | |
148 | } | |
149 | re turn messa ge; | |
150 | } | |
151 | ||
152 | void c loseMessag e() throws IOExcepti on { | |
153 | if (message != null) | |
154 | message. close(); | |
155 | } | |
156 | ||
157 | /** Ne w SMTP cli ent connec ted to hos t <i>host< /i>. */ | |
158 | public SmtpClien t (String host) thro ws IOExcep tion { | |
159 | su per(); | |
160 | if (host != null) { | |
161 | try { | |
162 | open Server(hos t); | |
163 | mail host = hos t; | |
164 | retu rn; | |
165 | } catch( Exception e) { | |
166 | } | |
167 | } | |
168 | tr y { | |
169 | String s ; | |
170 | mailhost = java.se curity.Acc essControl ler.doPriv ileged( | |
171 | new sun.se curity.act ion.GetPro pertyActio n("mail.ho st")); | |
172 | if (mail host != nu ll) { | |
173 | open Server(mai lhost); | |
174 | retu rn; | |
175 | } | |
176 | } catch(Exce ption e) { | |
177 | } | |
178 | tr y { | |
179 | mailhost = "localh ost"; | |
180 | openServ er(mailhos t); | |
181 | } catch(Exce ption e) { | |
182 | mailhost = "mailho st"; | |
183 | openServ er(mailhos t); | |
184 | } | |
185 | } | |
186 | ||
187 | /** Cr eate an un initialize d SMTP cli ent. */ | |
188 | public SmtpClien t () throw s IOExcept ion { | |
189 | th is(null); | |
190 | } | |
191 | ||
192 | public SmtpClien t(int to) throws IOE xception { | |
193 | su per(); | |
194 | se tConnectTi meout(to); | |
195 | tr y { | |
196 | String s ; | |
197 | mailhost = java.se curity.Acc essControl ler.doPriv ileged( | |
198 | new sun.se curity.act ion.GetPro pertyActio n("mail.ho st")); | |
199 | if (mail host != nu ll) { | |
200 | open Server(mai lhost); | |
201 | retu rn; | |
202 | } | |
203 | } catch(Exce ption e) { | |
204 | } | |
205 | tr y { | |
206 | mailhost = "localh ost"; | |
207 | openServ er(mailhos t); | |
208 | } catch(Exce ption e) { | |
209 | mailhost = "mailho st"; | |
210 | openServ er(mailhos t); | |
211 | } | |
212 | } | |
213 | ||
214 | public String ge tMailHost( ) { | |
215 | re turn mailh ost; | |
216 | } | |
217 | ||
218 | String getEncodi ng () { | |
219 | re turn encod ing; | |
220 | } | |
221 | } | |
222 | ||
223 | class Smtp PrintStrea m extends java.io.Pr intStream { | |
224 | privat e SmtpClie nt target; | |
225 | privat e int last c = '\n'; | |
226 | ||
227 | SmtpPr intStream (OutputStr eam fos, S mtpClient cl) throws Unsupport edEncoding Exception { | |
228 | su per(fos, f alse, cl.g etEncoding ()); | |
229 | ta rget = cl; | |
230 | } | |
231 | ||
232 | public void clos e() { | |
233 | if (target = = null) | |
234 | return; | |
235 | if (lastc != '\n') { | |
236 | write('\ n'); | |
237 | } | |
238 | tr y { | |
239 | target.i ssueComman d(".\r\n", 250); | |
240 | target.m essage = n ull; | |
241 | out = nu ll; | |
242 | target = null; | |
243 | } catch (IOE xception e ) { | |
244 | } | |
245 | } | |
246 | ||
247 | public void writ e(int b) { | |
248 | tr y { | |
249 | // quote a dot at the beginn ing of a l ine | |
250 | if (last c == '\n' && b == '. ') { | |
251 | out. write('.') ; | |
252 | } | |
253 | ||
254 | // trans late NL to CRLF | |
255 | if (b == '\n' && l astc != '\ r') { | |
256 | out. write('\r' ); | |
257 | } | |
258 | out.writ e(b); | |
259 | lastc = b; | |
260 | } catch (IOE xception e ) { | |
261 | } | |
262 | } | |
263 | ||
264 | public void writ e(byte b[] , int off, int len) { | |
265 | tr y { | |
266 | int lc = lastc; | |
267 | while (- -len >= 0) { | |
268 | int c = b[off+ +]; | |
269 | ||
270 | // q uote a dot at the be ginning of a line | |
271 | if ( lc == '\n' && c == ' .') | |
272 | out.write( '.'); | |
273 | ||
274 | // t ranslate N L to CRLF | |
275 | if ( c == '\n' && lc != ' \r') { | |
276 | out.write( '\r'); | |
277 | } | |
278 | out. write(c); | |
279 | lc = c; | |
280 | } | |
281 | lastc = lc; | |
282 | } catch (IOE xception e ) { | |
283 | } | |
284 | } | |
285 | public void prin t(String s ) { | |
286 | in t len = s. length(); | |
287 | fo r (int i = 0; i < le n; i++) { | |
288 | write(s. charAt(i)) ; | |
289 | } | |
290 | } | |
291 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.