Documentation ¶
Overview ¶
Package imapserver implements an IMAP server.
Index ¶
- Constants
- Variables
- func MatchList(name string, delim rune, reference, pattern string) bool
- type Conn
- type ExpungeWriter
- type FetchResponseWriter
- func (w *FetchResponseWriter) Close() error
- func (w *FetchResponseWriter) WriteBinarySection(section *imap.FetchItemBinarySection, size int64) io.WriteCloser
- func (w *FetchResponseWriter) WriteBinarySectionSize(section *imap.FetchItemBinarySection, size uint32)
- func (w *FetchResponseWriter) WriteBodySection(section *imap.FetchItemBodySection, size int64) io.WriteCloser
- func (w *FetchResponseWriter) WriteBodyStructure(bs imap.BodyStructure)
- func (w *FetchResponseWriter) WriteEnvelope(envelope *imap.Envelope)
- func (w *FetchResponseWriter) WriteFlags(flags []imap.Flag)
- func (w *FetchResponseWriter) WriteInternalDate(t time.Time)
- func (w *FetchResponseWriter) WriteRFC822Size(size int64)
- func (w *FetchResponseWriter) WriteUID(uid imap.UID)
- type FetchWriter
- type GreetingData
- type ListWriter
- type Logger
- type MailboxTracker
- func (t *MailboxTracker) NewSession() *SessionTracker
- func (t *MailboxTracker) QueueExpunge(seqNum uint32)
- func (t *MailboxTracker) QueueMailboxFlags(flags []imap.Flag)
- func (t *MailboxTracker) QueueMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag, source *SessionTracker)
- func (t *MailboxTracker) QueueNumMessages(n uint32)
- type MoveWriter
- type NumKind
- type Options
- type Server
- type Session
- type SessionIMAP4rev2
- type SessionMove
- type SessionNamespace
- type SessionSASL
- type SessionTracker
- type SessionUnauthenticate
- type UpdateWriter
Constants ¶
const ( NumKindSeq = NumKind(imapwire.NumKindSeq) NumKindUID = NumKind(imapwire.NumKindUID) )
Variables ¶
var ErrAuthFailed = errAuthFailed
ErrAuthFailed is returned by Session.Login on authentication failure.
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn represents an IMAP connection to the server.
type ExpungeWriter ¶
type ExpungeWriter struct {
// contains filtered or unexported fields
}
ExpungeWriter writes EXPUNGE updates.
func (*ExpungeWriter) WriteExpunge ¶
func (w *ExpungeWriter) WriteExpunge(seqNum uint32) error
WriteExpunge notifies the client that the message with the provided sequence number has been deleted.
type FetchResponseWriter ¶
type FetchResponseWriter struct {
// contains filtered or unexported fields
}
FetchResponseWriter writes a single FETCH response for a message.
func (*FetchResponseWriter) Close ¶
func (w *FetchResponseWriter) Close() error
Close closes the FETCH message writer.
func (*FetchResponseWriter) WriteBinarySection ¶
func (w *FetchResponseWriter) WriteBinarySection(section *imap.FetchItemBinarySection, size int64) io.WriteCloser
WriteBinarySection writes a binary section.
The returned io.WriteCloser must be closed before writing any more message data items.
func (*FetchResponseWriter) WriteBinarySectionSize ¶
func (w *FetchResponseWriter) WriteBinarySectionSize(section *imap.FetchItemBinarySection, size uint32)
WriteBinarySectionSize writes a binary section size.
func (*FetchResponseWriter) WriteBodySection ¶
func (w *FetchResponseWriter) WriteBodySection(section *imap.FetchItemBodySection, size int64) io.WriteCloser
WriteBodySection writes a body section.
The returned io.WriteCloser must be closed before writing any more message data items.
func (*FetchResponseWriter) WriteBodyStructure ¶
func (w *FetchResponseWriter) WriteBodyStructure(bs imap.BodyStructure)
WriteBodyStructure writes the message's body structure (either BODYSTRUCTURE or BODY).
func (*FetchResponseWriter) WriteEnvelope ¶
func (w *FetchResponseWriter) WriteEnvelope(envelope *imap.Envelope)
WriteEnvelope writes the message's envelope.
func (*FetchResponseWriter) WriteFlags ¶
func (w *FetchResponseWriter) WriteFlags(flags []imap.Flag)
WriteFlags writes the message's flags.
func (*FetchResponseWriter) WriteInternalDate ¶
func (w *FetchResponseWriter) WriteInternalDate(t time.Time)
WriteInternalDate writes the message's internal date.
func (*FetchResponseWriter) WriteRFC822Size ¶
func (w *FetchResponseWriter) WriteRFC822Size(size int64)
WriteRFC822Size writes the message's full size.
func (*FetchResponseWriter) WriteUID ¶
func (w *FetchResponseWriter) WriteUID(uid imap.UID)
WriteUID writes the message's UID.
type FetchWriter ¶
type FetchWriter struct {
// contains filtered or unexported fields
}
FetchWriter writes FETCH responses.
func (*FetchWriter) CreateMessage ¶
func (cmd *FetchWriter) CreateMessage(seqNum uint32) *FetchResponseWriter
CreateMessage writes a FETCH response for a message.
FetchResponseWriter.Close must be called.
type GreetingData ¶
type GreetingData struct {
PreAuth bool
}
GreetingData is the data associated with an IMAP greeting.
type ListWriter ¶
type ListWriter struct {
// contains filtered or unexported fields
}
ListWriter writes LIST responses.
func (*ListWriter) WriteList ¶
func (w *ListWriter) WriteList(data *imap.ListData) error
WriteList writes a single LIST response for a mailbox.
type Logger ¶
type Logger interface {
Printf(format string, args ...interface{})
}
Logger is a facility to log error messages.
type MailboxTracker ¶
type MailboxTracker struct {
// contains filtered or unexported fields
}
MailboxTracker tracks the state of a mailbox.
A mailbox can have multiple sessions listening for updates. Each session has its own view of the mailbox, because IMAP clients asynchronously receive mailbox updates.
func NewMailboxTracker ¶
func NewMailboxTracker(numMessages uint32) *MailboxTracker
NewMailboxTracker creates a new mailbox tracker.
func (*MailboxTracker) NewSession ¶
func (t *MailboxTracker) NewSession() *SessionTracker
NewSession creates a new session tracker for the mailbox.
The caller must call SessionTracker.Close once they are done with the session.
func (*MailboxTracker) QueueExpunge ¶
func (t *MailboxTracker) QueueExpunge(seqNum uint32)
QueueExpunge queues a new EXPUNGE update.
func (*MailboxTracker) QueueMailboxFlags ¶
func (t *MailboxTracker) QueueMailboxFlags(flags []imap.Flag)
QueueMailboxFlags queues a new FLAGS update.
func (*MailboxTracker) QueueMessageFlags ¶
func (t *MailboxTracker) QueueMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag, source *SessionTracker)
QueueMessageFlags queues a new FETCH FLAGS update.
If source is not nil, the update won't be dispatched to it.
func (*MailboxTracker) QueueNumMessages ¶
func (t *MailboxTracker) QueueNumMessages(n uint32)
QueueNumMessages queues a new EXISTS update.
type MoveWriter ¶
type MoveWriter struct {
// contains filtered or unexported fields
}
MoveWriter writes responses for the MOVE command.
Servers must first call WriteCopyData once, then call WriteExpunge any number of times.
func (*MoveWriter) WriteCopyData ¶
func (w *MoveWriter) WriteCopyData(data *imap.CopyData) error
WriteCopyData writes the untagged COPYUID response for a MOVE command.
func (*MoveWriter) WriteExpunge ¶
func (w *MoveWriter) WriteExpunge(seqNum uint32) error
WriteExpunge writes an EXPUNGE response for a MOVE command.
type NumKind ¶
type NumKind int
NumKind describes how a number should be interpreted: either as a sequence number, either as a UID.
type Options ¶
type Options struct { // NewSession is called when a client connects. NewSession func(*Conn) (Session, *GreetingData, error) // Supported capabilities. If nil, only IMAP4rev1 is advertised. This set // must contain at least IMAP4rev1 or IMAP4rev2. // // The following capabilities are part of IMAP4rev2 and need to be // explicitly enabled by IMAP4rev1-only servers: // // - NAMESPACE // - UIDPLUS // - ESEARCH // - LIST-EXTENDED // - LIST-STATUS // - MOVE // - STATUS=SIZE Caps imap.CapSet // Logger is a logger to print error messages. If nil, log.Default is used. Logger Logger // TLSConfig is a TLS configuration for STARTTLS. If nil, STARTTLS is // disabled. TLSConfig *tls.Config // InsecureAuth allows clients to authenticate without TLS. In this mode, // the server is susceptible to man-in-the-middle attacks. InsecureAuth bool // Raw ingress and egress data will be written to this writer, if any. // Note, this may include sensitive information such as credentials used // during authentication. DebugWriter io.Writer }
Options contains server options.
The only required field is NewSession.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an IMAP server.
func (*Server) Close ¶
Close immediately closes all active listeners and connections.
Close returns any error returned from closing the server's underlying listeners.
Once Close has been called on a server, it may not be reused; future calls to methods such as Serve will return an error.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve.
If addr is empty, ":143" is used.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address addr and then calls Serve to handle incoming TLS connections.
The TLS configuration set in Options.TLSConfig is used. If addr is empty, ":993" is used.
type Session ¶
type Session interface { Close() error // Not authenticated state Login(username, password string) error // Authenticated state Select(mailbox string, options *imap.SelectOptions) (*imap.SelectData, error) Create(mailbox string, options *imap.CreateOptions) error Delete(mailbox string) error Rename(mailbox, newName string) error Subscribe(mailbox string) error Unsubscribe(mailbox string) error List(w *ListWriter, ref string, patterns []string, options *imap.ListOptions) error Status(mailbox string, options *imap.StatusOptions) (*imap.StatusData, error) Append(mailbox string, r imap.LiteralReader, options *imap.AppendOptions) (*imap.AppendData, error) Poll(w *UpdateWriter, allowExpunge bool) error Idle(w *UpdateWriter, stop <-chan struct{}) error // Selected state Unselect() error Expunge(w *ExpungeWriter, uids *imap.UIDSet) error Search(kind NumKind, criteria *imap.SearchCriteria, options *imap.SearchOptions) (*imap.SearchData, error) Fetch(w *FetchWriter, numSet imap.NumSet, options *imap.FetchOptions) error Store(w *FetchWriter, numSet imap.NumSet, flags *imap.StoreFlags, options *imap.StoreOptions) error Copy(numSet imap.NumSet, dest string) (*imap.CopyData, error) }
Session is an IMAP session.
type SessionIMAP4rev2 ¶
type SessionIMAP4rev2 interface { Session SessionNamespace SessionMove }
SessionIMAP4rev2 is an IMAP session which supports IMAP4rev2.
type SessionMove ¶
type SessionMove interface { Session // Selected state Move(w *MoveWriter, numSet imap.NumSet, dest string) error }
SessionMove is an IMAP session which supports MOVE.
type SessionNamespace ¶
type SessionNamespace interface { Session // Authenticated state Namespace() (*imap.NamespaceData, error) }
SessionNamespace is an IMAP session which supports NAMESPACE.
type SessionSASL ¶
type SessionSASL interface { Session AuthenticateMechanisms() []string Authenticate(mech string) (sasl.Server, error) }
SessionSASL is an IMAP session which supports its own set of SASL authentication mechanisms.
type SessionTracker ¶
type SessionTracker struct {
// contains filtered or unexported fields
}
SessionTracker tracks the state of a mailbox for an IMAP client.
func (*SessionTracker) DecodeSeqNum ¶
func (t *SessionTracker) DecodeSeqNum(seqNum uint32) uint32
DecodeSeqNum converts a message sequence number from the client view to the server view.
Zero is returned if the message doesn't exist from the server point-of-view.
func (*SessionTracker) EncodeSeqNum ¶
func (t *SessionTracker) EncodeSeqNum(seqNum uint32) uint32
EncodeSeqNum converts a message sequence number from the server view to the client view.
Zero is returned if the message doesn't exist from the client point-of-view.
func (*SessionTracker) Idle ¶
func (t *SessionTracker) Idle(w *UpdateWriter, stop <-chan struct{}) error
Idle continuously writes mailbox updates.
When the stop channel is closed, it returns.
Idle cannot be invoked concurrently from two separate goroutines.
func (*SessionTracker) Poll ¶
func (t *SessionTracker) Poll(w *UpdateWriter, allowExpunge bool) error
Poll dequeues pending mailbox updates for this session.
type SessionUnauthenticate ¶
SessionUnauthenticate is an IMAP session which supports UNAUTHENTICATE.
type UpdateWriter ¶
type UpdateWriter struct {
// contains filtered or unexported fields
}
UpdateWriter writes status updates.
func (*UpdateWriter) WriteExpunge ¶
func (w *UpdateWriter) WriteExpunge(seqNum uint32) error
WriteExpunge writes an EXPUNGE response.
func (*UpdateWriter) WriteMailboxFlags ¶
func (w *UpdateWriter) WriteMailboxFlags(flags []imap.Flag) error
WriteMailboxFlags writes a FLAGS response.
func (*UpdateWriter) WriteMessageFlags ¶
func (w *UpdateWriter) WriteMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag) error
WriteMessageFlags writes a FETCH response with FLAGS.
func (*UpdateWriter) WriteNumMessages ¶
func (w *UpdateWriter) WriteNumMessages(n uint32) error
WriteNumMessages writes an EXISTS response.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package imapmemserver implements an in-memory IMAP server.
|
Package imapmemserver implements an in-memory IMAP server. |