@@ -150,10 +150,7 @@ public boolean deleteMessage(final int messageId) throws IOException {
150150 * @throws IOException If a network I/O error occurs in the process of sending the list command.
151151 */
152152 public POP3MessageInfo listMessage (final int messageId ) throws IOException {
153- if (getState () != TRANSACTION_STATE ) {
154- return null ;
155- }
156- if (sendCommand (POP3Command .LIST , Integer .toString (messageId )) != POP3Reply .OK ) {
153+ if (getState () != TRANSACTION_STATE || sendCommand (POP3Command .LIST , Integer .toString (messageId )) != POP3Reply .OK ) {
157154 return null ;
158155 }
159156 return parseStatus (lastReplyLine .substring (3 ));
@@ -169,10 +166,7 @@ public POP3MessageInfo listMessage(final int messageId) throws IOException {
169166 * @throws IOException If a network I/O error occurs in the process of sending the list command.
170167 */
171168 public POP3MessageInfo [] listMessages () throws IOException {
172- if (getState () != TRANSACTION_STATE ) {
173- return null ;
174- }
175- if (sendCommand (POP3Command .LIST ) != POP3Reply .OK ) {
169+ if (getState () != TRANSACTION_STATE || sendCommand (POP3Command .LIST ) != POP3Reply .OK ) {
176170 return null ;
177171 }
178172 getAdditionalReply ();
@@ -199,10 +193,7 @@ public POP3MessageInfo[] listMessages() throws IOException {
199193 * @throws IOException If a network I/O error occurs in the process of sending the list unique identifier command.
200194 */
201195 public POP3MessageInfo listUniqueIdentifier (final int messageId ) throws IOException {
202- if (getState () != TRANSACTION_STATE ) {
203- return null ;
204- }
205- if (sendCommand (POP3Command .UIDL , Integer .toString (messageId )) != POP3Reply .OK ) {
196+ if (getState () != TRANSACTION_STATE || sendCommand (POP3Command .UIDL , Integer .toString (messageId )) != POP3Reply .OK ) {
206197 return null ;
207198 }
208199 return parseUID (lastReplyLine .substring (3 ));
@@ -218,10 +209,7 @@ public POP3MessageInfo listUniqueIdentifier(final int messageId) throws IOExcept
218209 * @throws IOException If a network I/O error occurs in the process of sending the list unique identifier command.
219210 */
220211 public POP3MessageInfo [] listUniqueIdentifiers () throws IOException {
221- if (getState () != TRANSACTION_STATE ) {
222- return null ;
223- }
224- if (sendCommand (POP3Command .UIDL ) != POP3Reply .OK ) {
212+ if (getState () != TRANSACTION_STATE || sendCommand (POP3Command .UIDL ) != POP3Reply .OK ) {
225213 return null ;
226214 }
227215 getAdditionalReply ();
@@ -248,20 +236,11 @@ public POP3MessageInfo[] listUniqueIdentifiers() throws IOException {
248236 * @throws IOException If a network I/O error occurs in the process of logging in.
249237 */
250238 public boolean login (final String user , final String password ) throws IOException {
251- if (getState () != AUTHORIZATION_STATE ) {
252- return false ;
253- }
254-
255- if (sendCommand (POP3Command .USER , user ) != POP3Reply .OK ) {
239+ if (getState () != AUTHORIZATION_STATE || sendCommand (POP3Command .USER , user ) != POP3Reply .OK
240+ || sendCommand (POP3Command .PASS , password ) != POP3Reply .OK ) {
256241 return false ;
257242 }
258-
259- if (sendCommand (POP3Command .PASS , password ) != POP3Reply .OK ) {
260- return false ;
261- }
262-
263243 setState (TRANSACTION_STATE );
264-
265244 return true ;
266245 }
267246
@@ -291,35 +270,28 @@ public boolean login(final String user, String timestamp, final String secret) t
291270 final StringBuilder buffer ;
292271 final StringBuilder digestBuffer ;
293272 final MessageDigest md5 ;
294-
295273 if (getState () != AUTHORIZATION_STATE ) {
296274 return false ;
297275 }
298-
299276 md5 = MessageDigest .getInstance ("MD5" );
300277 timestamp += secret ;
301278 digest = md5 .digest (timestamp .getBytes (getCharset ()));
302279 digestBuffer = new StringBuilder (128 );
303-
304280 for (i = 0 ; i < digest .length ; i ++) {
305281 final int digit = digest [i ] & 0xff ;
306282 if (digit <= 15 ) { // Add leading zero if necessary (NET-351)
307283 digestBuffer .append ("0" );
308284 }
309285 digestBuffer .append (Integer .toHexString (digit ));
310286 }
311-
312287 buffer = new StringBuilder (256 );
313288 buffer .append (user );
314289 buffer .append (' ' );
315290 buffer .append (digestBuffer .toString ());
316-
317291 if (sendCommand (POP3Command .APOP , buffer .toString ()) != POP3Reply .OK ) {
318292 return false ;
319293 }
320-
321294 setState (TRANSACTION_STATE );
322-
323295 return true ;
324296 }
325297
@@ -384,13 +356,9 @@ public boolean reset() throws IOException {
384356 * @throws IOException If a network I/O error occurs in the process of sending the retrieve message command.
385357 */
386358 public Reader retrieveMessage (final int messageId ) throws IOException {
387- if (getState () != TRANSACTION_STATE ) {
359+ if (getState () != TRANSACTION_STATE || sendCommand ( POP3Command . RETR , Integer . toString ( messageId )) != POP3Reply . OK ) {
388360 return null ;
389361 }
390- if (sendCommand (POP3Command .RETR , Integer .toString (messageId )) != POP3Reply .OK ) {
391- return null ;
392- }
393-
394362 return new DotTerminatedMessageReader (reader );
395363 }
396364
@@ -412,13 +380,10 @@ public Reader retrieveMessage(final int messageId) throws IOException {
412380 * @throws IOException If a network I/O error occurs in the process of sending the top command.
413381 */
414382 public Reader retrieveMessageTop (final int messageId , final int numLines ) throws IOException {
415- if (numLines < 0 || getState () != TRANSACTION_STATE ) {
416- return null ;
417- }
418- if (sendCommand (POP3Command .TOP , Integer .toString (messageId ) + " " + Integer .toString (numLines )) != POP3Reply .OK ) {
383+ if (numLines < 0 || getState () != TRANSACTION_STATE
384+ || sendCommand (POP3Command .TOP , Integer .toString (messageId ) + " " + Integer .toString (numLines )) != POP3Reply .OK ) {
419385 return null ;
420386 }
421-
422387 return new DotTerminatedMessageReader (reader );
423388 }
424389
@@ -432,10 +397,7 @@ public Reader retrieveMessageTop(final int messageId, final int numLines) throws
432397 * @throws IOException If a network I/O error occurs in the process of sending the status command.
433398 */
434399 public POP3MessageInfo status () throws IOException {
435- if (getState () != TRANSACTION_STATE ) {
436- return null ;
437- }
438- if (sendCommand (POP3Command .STAT ) != POP3Reply .OK ) {
400+ if (getState () != TRANSACTION_STATE || sendCommand (POP3Command .STAT ) != POP3Reply .OK ) {
439401 return null ;
440402 }
441403 return parseStatus (lastReplyLine .substring (3 ));
0 commit comments