bugfixes
[org.ibex.mail.git] / src / org / ibex / mail / protocol / Connection.java
index fe61ff6..d1cca88 100644 (file)
@@ -50,14 +50,20 @@ public abstract class Connection {
         InetSocketAddress remote = (InetSocketAddress)conn.getRemoteSocketAddress();
         Log.info(this, "connection from "+remote.getHostName()+":"+remote.getPort()+" ("+remote.getAddress()+")");
         conversation = new PrintWriter(new OutputStreamWriter(new FileOutputStream(convdir + File.separatorChar + cid + ".txt")));
-        boolean ret = handleRequest();
-        Log.setThreadAnnotation("");
-        conversation.close();
+       boolean ret = false;
+       try {
+           ret = handleRequest();
+           Log.setThreadAnnotation("");
+       } finally {
+           conversation.close();
+       }
         return ret;
     }
 
     protected void println(String s) throws IOException {
+       if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); } 
         conversation.println("S: " + s);
+       conversation.flush();
         pw.print(s);
         pw.print("\r\n");
         pw.flush();
@@ -66,13 +72,16 @@ public abstract class Connection {
     protected String readln() throws IOException {
         String line = lr.readLine();
         conversation.println("C: " + line);
+       conversation.flush();
         return line;
     }
     public char getc() throws IOException {
         int ret = r.read();
         if (ret == -1) throw new EOFException();
-        if (ret == '\n') { if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); } }
+        if (ret == '\n') {
+           if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); } }
         else if (ret != '\r') inbound.append((char)ret);
+       conversation.flush();
         return (char)ret;
     }
     public  char peekc() throws IOException {