OSDN Git Service

ADD: aboide SMTP server timeout #13312
authorTakuya Ono <takuya-o@users.sourceforge.jp>
Sun, 17 Aug 2008 17:34:32 +0000 (17:34 +0000)
committerTakuya Ono <takuya-o@users.sourceforge.jp>
Sun, 17 Aug 2008 17:34:32 +0000 (17:34 +0000)
ADD: pershaly support multiple sending #13311

src/org/jent/checksmtp/Processer.java

index 8905ab5..1f6c28e 100644 (file)
@@ -33,15 +33,41 @@ public class Processer implements Runnable, ResultNotify {
   private final int R221ServiceClosing = 221;
   private final int R451RequestedActionAbort = 451;
   private final int R502CommandNotImplemented = 502;
-
+  
+  //private final int R500SyntexErrorInCommand = 500;
+  //private final int R501SyntaxErrorInArguments = 501;
+  //private final int R503BadSequenceOfCommands = 503:
+  //private final int R504CommandParameterNotImplemented = 504:
+  //private final int R211SystemStatusRepl = 211;
+  //private final int R214HelpMessage = 214;
+  //private final int R220ServiceReady = 220;
+  //private final int R421ClosingTransmissionChannel = 421;
+  //private final int R250RequestedActionCompleted = 250;
+  //private final int R251UserNotLocal = 251;
+  //private final int R252CannotVRFYuser = 252;
+  //private final int R450RequestedMailActionNotTaken = 450;
+  //private final int R550RequestedActionNotTaken = 550;
+  //private final int R551UserNotLocal = 551;
+  //private final int R452RequestedActionNotTaken = 452;
+  //private final int R552RequestedMailActionAborted = 552;
+  //private final int R553RequestedActionNotTaken = 553;
+  //private final int R554TransactionFailed = 554;
+  
   //SMTP command
   private final String COMMAND_RCPT_TO = "RCPT TO:"; // NOI18N
   private final String COMMAND_DATA = "DATA"; // NOI18N
   private final String COMMAND_RESET = "RSET"; // NOI18N
   private final String COMMAND_TURN = "TURN"; // NOI18N
 
-  //private final String COMMAND_NOOP = "NOOP";
+  private final String COMMAND_NOOP = "NOOP";
   //private final String COMAMND_QUIT = "QUIT";
+  
+  //private final String COMMAND_EXHELLO = "EHLO";
+  //private final String COMMAND_HELLO = "HELO";
+  //private final String COMMAND_MAIL = "MAIL FROM:";
+  //private final String COMMAND_VERIFY = "VRFY";
+  //private final String COMMAND_EXPAND = "EXPN";
+  //private final String COMMAND_HELP = "HELP";
   public Processer(Socket client) {
       this.client = client;
   }
@@ -126,9 +152,23 @@ public class Processer implements Runnable, ResultNotify {
   }
 
   private int getCode(String s) {
-      return Integer.parseInt(s.substring(0, 3));
+    int code = 0;
+    try {
+      code = Integer.parseInt(s.substring(0, 3));
+    } catch (NumberFormatException nfEx) {
+      code = -1;  //Unexpected: SMTP CODE is allway 3digits.
+    }
+    return code;
   }
 
+  private boolean isCompliteCode(int code) {
+    return code >=200 && code<=299 ;
+  }
+  
+  private boolean isErrorCode(int code) {
+    return code>=400 && code<=599;
+  }  
+  
   private boolean isContinue(String s) {
       if ('-' == s.charAt(3)) {
           return true;
@@ -234,24 +274,39 @@ public class Processer implements Runnable, ResultNotify {
               }
 
               //checkout toList
+              result = RESULT_UNKNOWN; //refresh RESULT flag.
               new ToListUI(this, toList);
 
               while (result == RESULT_UNKNOWN) {
                 try {
                     synchronized (this) {
-                        wait();
+                        wait(4000); //TODO: Configurable NOOP time
+                        //Dummy SMTP server access while ToListUI dialog wait.
+                        serverWriter.println(COMMAND_NOOP);
+                        String serverReply = serverReader.readLine();
+                        System.out.println(COMMAND_NOOP + ":ANSER is " + serverReply);
+                        //Server MUST retrun "250 OK" by NOOP command.
+                        if ( isErrorCode(getCode(serverReply)) ) {
+                          System.err.println("Fatal Error. Server return error code by NOOP command.");
+                          //Ignore Fatal Error.
+                        }
                     }
                 } catch (InterruptedException e) {
                     System.err.println("Confirm dialog wait interrupted");
                     e.printStackTrace();
                 }
               }
-
+              toList = new ArrayList(); //refresh TO address list.
+              
               if (result != RESULT_OK ) {
                 System.out.println("CANCEL sending mail.");
                 serverWriter.println(COMMAND_RESET);
                 line = serverReader.readLine(); //Server MUST retrun "250 OK"
                 System.out.println(COMMAND_RESET + ":ANSER is " + line);
+                if ( isErrorCode(getCode(line)) ) {
+                  System.err.println("Fatal Error. Server return error code by RESET command.");
+                  //Ignore Fatal Error.
+                }
                 clientWriter.println(R451RequestedActionAbort);
 
                 continue; //I think Client QUIT or Retry.