1package imapserver
2
3import (
4 "net"
5)
6
7// prefixConn is a net.Conn with a buffer from which the first reads are satisfied.
8// used for STARTTLS where already did a buffered read of initial TLS data.
9type prefixConn struct {
10 prefix []byte
11 net.Conn
12}
13
14func (c *prefixConn) Read(buf []byte) (int, error) {
15 if len(c.prefix) > 0 {
16 n := len(buf)
17 if n > len(c.prefix) {
18 n = len(c.prefix)
19 }
20 copy(buf[:n], c.prefix[:n])
21 c.prefix = c.prefix[n:]
22 if len(c.prefix) == 0 {
23 c.prefix = nil
24 }
25 return n, nil
26 }
27 return c.Conn.Read(buf)
28}
29