mirror of
https://github.com/mjl-/mox.git
synced 2024-12-25 16:03:48 +03:00
28 lines
545 B
Go
28 lines
545 B
Go
package imapserver
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// prefixConn is a net.Conn with a buffer from which the first reads are satisfied.
|
|
// used for STARTTLS where already did a buffered read of initial TLS data.
|
|
type prefixConn struct {
|
|
prefix []byte
|
|
net.Conn
|
|
}
|
|
|
|
func (c *prefixConn) Read(buf []byte) (int, error) {
|
|
if len(c.prefix) > 0 {
|
|
n := len(buf)
|
|
if n > len(c.prefix) {
|
|
n = len(c.prefix)
|
|
}
|
|
copy(buf[:n], c.prefix[:n])
|
|
c.prefix = c.prefix[n:]
|
|
if len(c.prefix) == 0 {
|
|
c.prefix = nil
|
|
}
|
|
return n, nil
|
|
}
|
|
return c.Conn.Read(buf)
|
|
}
|