import java.util.regex.Pattern;
-public class Processer implements Runnable {
+public class Processer implements Runnable, ResultNotify {
private Socket client;
//Conform status.
BufferedReader clientReader;
PrintWriter clientWriter;
+ Socket server = null;
+
try {
//Connect to SMTP Server host
String servername = ApplicationProperties.getSmtpServerHost();
int serverport = ApplicationProperties.getSmtpServerPort();
//Connection to true SMTP server.
- Socket server = new Socket(servername, serverport);
+ server = new Socket(servername, serverport);
serverInput = server.getInputStream();
serverOutput = server.getOutputStream();
clientInput = client.getInputStream();
//forServerThread.start();
////Use this ThreadforClientThread.run();
server.close();
+ server = null;
client.close();
+ client = null;
} catch (IOException e) {
System.err.println("Execption occurred in Processer.");
+ //TODO: Display error Dialog.
e.printStackTrace();
+ } finally {
+ //for failsafe Socket close.
+ if (server != null) {
+ try {
+ server.close();
+ } catch (IOException ioEx ) {
+ //IGNORE close Exception
+ }
+ }
+ if (client != null) {
+ try {
+ client.close();
+ } catch (IOException ioEx ) {
+ //IGNORE close Exception
+ }
+ }
+ //LDAP Connection close.
+ LDAPSearch.close();
}
}
while (true) {
line = clientReader.readLine();
+ if (line == null) {
+ //Finish client stream.
+ System.err.println("Client disconnected.");
+ break; //force disconnect.
+ }
+
if (isRcptTo(line)) {
//stored To: address.
toList.add(formatToAddress(line));
}
//checkout toList
- new ToListDialog(this, toList);
+ new ToListUI(this, toList);
while (result == RESULT_UNKNOWN) {
try {
}
}
- if (result == RESULT_NG) {
+ if (result != RESULT_OK ) {
System.out.println("CANCEL sending mail.");
serverWriter.println(COMMAND_RESET);
line = serverReader.readLine(); //Server MUST retrun "250 OK"
break; // client read while(true);
}
+ if (line == null ) {
+ break;
+ }
serverWriter.println(line);
System.out.println(line);
}