'Scan bytes from the file.
@type bytes: L{int}
@param bytes: The number of bytes to read from the file.
@rtype: L{bytes}
@return: Each portion of the header as it is scanned.  Then, full lines
of the message body as they are scanned.  When more than one line
of the header and/or body has been scanned, the result is the
concatenation of the lines.  When the scan results in no full
lines, the empty string is returned.'

def read(self, bytes):

    if self.done:
        return ''
    data = self.f.read(bytes)
    if (not data):
        return data
    if self.headers:
        (df, sz) = (data.find('\r\n\r\n'), 4)
        if (df == (-1)):
            (df, sz) = (data.find('\n\n'), 2)
        if (df != (-1)):
            df += sz
            val = data[:df]
            data = data[df:]
            self.linecount = 1
            self.headers = 0
    else:
        val = ''
    if (self.linecount > 0):
        dsplit = (self.buf + data).split('\n')
        self.buf = dsplit[(-1)]
        for ln in dsplit[:(-1)]:
            if (self.linecount > self.n):
                self.done = 1
                return val
            val += (ln + '\n')
            self.linecount += 1
        return val
    else:
        return data
