Charles I have since fixed the code I sent (it was full of bugs). I
agree that the <CRLF>.<CRLF> should be stripped but I was trying to
ascertain if the lack of the first <CRLF> was causing the hang problems
(on NT). 

I have rewritten the class below (and fixed bugs) to keep the first
<CRLF> and strip the .<CRLF>. I tested with this code (Netscape 4.7, 6,
MSOutlook clients, clients and server on NT4) and it has fixed the
server hanging. But not the pop hanging prob. Note I have added a hook
for max message size, needed to limit message sizes for some users I
think that we will need this in the future. 

It appears the pop hanging or refusing logon problem is causes by
..private.StreamStore files not been deleted this is the old NT chestnut
with having problems of deleting files. Strange it only has problems
deleting the streamed files. Anyway I will look at it, in the past I
have moved the files to another dir to be deleted by a background thread
that cleans up files, this removes the files from the dir that can cause
probs.

cheers pb...

p.s. if you want this submitted as a patch in the diff format please let
me know.



<code filename="CharTerminatedInputStream3.java"> 
/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights
reserved.        *
 *
-------------------------------------------------------------------------
*
 * This software is published under the terms of the Apache Software
License *
 * version 1.1, a copy of which has been included  with this
distribution in *
 * the LICENSE
file.                                                         *

*****************************************************************************/

package org.apache.james.util;

import java.io.InputStream;
import java.io.IOException;
import java.util.Stack;

/**
 * <p> Note this version appends <CRLF> to the end of the stream
 * <br> added hook for max message size, needed to limit message sizes 
 * for some users 
 *
 * @version 1.0.0, 23/11/2000
 * @author  Federico Barbieri <[EMAIL PROTECTED]>
 * @author  Peter Blakeley <[EMAIL PROTECTED]>
 */
public class CharTerminatedInputStream3 
        extends InputStream {

    private final static int[] INT_ARRAY_CRLF = { (int)'\r' , (int)'\n'
};    
    
    private InputStream in;
    private int match[];

    private int maxSize = -1;
    private int bytesRead = 0;
    private int read;
    
    private int pos = 0;
    private boolean endFound = false;
    private boolean flushRewind = false;
    private int[] buff;
    private Stack rewind = new Stack();
                
    public CharTerminatedInputStream3(InputStream in, char[] terminator)
{
        this(in, terminator, -1);
    }

    public CharTerminatedInputStream3(InputStream in, char[] terminator,
int maxSize) {
        match = new int[terminator.length];
        for (int i = 0; i < terminator.length; i++) {
            match[i] = (int)terminator[i];
        }
        this.in = in;
        this.maxSize = maxSize;
    }

    public int read() 
            throws IOException {

        if(endFound) {
            if(pos < buff.length) {
                read = buff[pos];
                pos++;
            }else{
                read = -1;
            }
            // System.err.println("FOUND: read=="+read);
            return read;
        }

        if(flushRewind) {
            if(rewind.size() > 0) {
                read = ((Integer)rewind.pop()).intValue();
                // System.err.println("FLUSH: read=="+read);
            }else{
                flushRewind = false;
                read = in.read(); 
                bytesRead++;
            }
        }else{
            read = in.read(); 
            bytesRead++;
        }

        // check to see if max message size is exceeded
        if(maxSize > -1 && bytesRead > maxSize) {
            throw new java.io.IOException(
                "Message too large! exceeds maxSize of "+maxSize);
        }

        
        if(read == match[0]) {
            buff = new int[match.length];
            pos = 0;
            buff[pos] = read;
            pos++;
            endFound = true;
            flushRewind = false;
            // System.err.print("read=="+read+" ");
            for(; pos < match.length; pos++) {
                // get bytes from last rewind
                if(rewind.size() > 0) {
                    read = ((Integer)rewind.pop()).intValue();
                    // System.err.print("rw"+read+"
");                    
                }else{
                    read = in.read(); 
                    bytesRead++;
                    // System.err.print(read+" ");                    
                }
                buff[pos] = read;                

                if(buff[pos] != match[pos]) {
                    // no match
                    endFound = false;
                    flushRewind = true;
                }
            }
            pos = 0;
            if(flushRewind) {
                read = buff[0];
                rewind.clear();
                // #Note Stack LIFO so loop backwards through buff
                for(int i = (buff.length-1); i > 0; i--) {
                    rewind.push(new Integer((int)buff[i]));
                }
                // System.err.println("");                
            }
            if(endFound) {
                                
                // create <CRLF> to append to the end of the message
                buff = INT_ARRAY_CRLF;
            }
        }

        // System.err.println("return read=="+read);
        return read;
    }
}
</code>


Charles Benett wrote:
> 
> Peter,
> Thanks for the bug report.
> I'm a bit in the dark about this, because I can't reproduce it. Possible
> because I don't have NT clients only Win95 and Linux.
> 
> I think that CharTerminatedInputStream should consume the <CRLF>.<CRLF>:
> it is used for receiving emails over SMTP.
> 
> The pop3handler, which uses, I believe, InternetPrintWriter, appears to
> add <CRLF>.<CRLF> to the end of a message, so the hanging remains
> inexplicable.
> 
> Is anyone else finding this?
> 
> Charles
>




------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives:  <http://www.mail-archive.com/james%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to