data

package
v0.0.0-...-fd1ad92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const InternalDate = "02-Jan-2006 15:04:05 +0700"

Date format used in INTERNALDATE fetch parameter

View Source
const RFC822Date = "Mon, 2 Jan 2006 15:04:05 +0700"

RFC822 date format used by IMAP in go date format

Variables

This section is empty.

Functions

func Encrypt_Password

func Encrypt_Password(password string, salt []byte) string

func FormatDate

func FormatDate(date time.Time) string

func MIMEHeaderToString

func MIMEHeaderToString(header textproto.MIMEHeader) string

MIMEHeaderToString converts a textproto.MIMEHeader into its string representation.

func MimeBodyDecode

func MimeBodyDecode(str string, charset string, encoding string) string

func MimeHeaderDecode

func MimeHeaderDecode(str string) string

Decode strings in Mime header format eg. =?ISO-2022-JP?B?GyRCIVo9dztSOWJAOCVBJWMbKEI=?=

func ParseMIME

func ParseMIME(MIMEBody *MIMEBody, reader io.Reader, boundary string, message *Message) error

func Partbuf

func Partbuf(reader io.Reader) (int64, []byte, error)

func SplitParams

func SplitParams(params string) []string

SplitParams splits parameters in IMAP arguments so that they're easily readable.

func Validate_Password

func Validate_Password(hashed string, input_password string) bool

func WriteMIMEHeader

func WriteMIMEHeader(writer io.Writer, header textproto.MIMEHeader) (n int, err error)

WriteMIMEHeader writes the MIME header out in the standard format. This should eventually be superseded by textproto.MIMEHeader.Write(w) once it is implemented in the go standard library.

Types

type Attachment

type Attachment struct {
	Boundary         string
	Id               string
	Body             string
	FileName         string
	ContentType      string
	Charset          string
	MIMEVersion      string
	TransferEncoding string
	Size             int
}

func (*Attachment) SaveToFile

func (at *Attachment) SaveToFile() error

type ComposeForm

type ComposeForm struct {
	To      string
	Cc      string
	Subject string
	Message string

	Errors map[string]string
}

func (*ComposeForm) Validate

func (f *ComposeForm) Validate() bool

type Content

type Content struct {
	Headers  map[string][]string
	TextBody string
	HtmlBody string
	Size     int
	Body     string
}

func ContentFromString

func ContentFromString(data string) *Content

type ContentQuery

type ContentQuery struct {
	Size int
}

type DataStore

type DataStore struct {
	Config         config.DataStoreConfig
	Domain         string
	Storage        interface{}
	SaveMailChan   chan *config.SMTPMessage
	NotifyMailChan chan interface{}
}

func NewDataStore

func NewDataStore() *DataStore

DefaultDataStore creates a new DataStore object.

func (*DataStore) CheckGreyHost

func (ds *DataStore) CheckGreyHost(h string) bool

Check if host address is in greylist h -> hostname client ip

func (*DataStore) CheckGreyMail

func (ds *DataStore) CheckGreyMail(t, m, d, h string) bool

Check if email address is in greylist t -> type (from/to) m -> local mailbox d -> domain h -> client IP

func (*DataStore) Login

func (ds *DataStore) Login(u string, p string) (*User, error)

Check if host address is in greylist h -> hostname client ip

func (*DataStore) MessageSetBySequenceNumber

func (ds *DataStore) MessageSetBySequenceNumber(username string, set SequenceSet) Messages

func (*DataStore) MessageSetByUID

func (ds *DataStore) MessageSetByUID(username string, set SequenceSet) Messages

func (*DataStore) MessageSetFlags

func (ds *DataStore) MessageSetFlags(username string, seq string)

func (*DataStore) NextId

func (ds *DataStore) NextId(table string) int

func (*DataStore) Pop3GetDele

func (ds *DataStore) Pop3GetDele(username string, sequence int) error

func (*DataStore) Pop3GetList

func (ds *DataStore) Pop3GetList(username string) (Messages, error)

func (*DataStore) Pop3GetRetr

func (ds *DataStore) Pop3GetRetr(username string, sequence int) (Message, error)

func (*DataStore) Pop3GetStat

func (ds *DataStore) Pop3GetStat(username string) (int, int, error)

func (*DataStore) Pop3GetUidl

func (ds *DataStore) Pop3GetUidl(username string) (Messages, error)

func (*DataStore) Recent

func (ds *DataStore) Recent(username string) int

func (*DataStore) RemoveRecent

func (ds *DataStore) RemoveRecent(m Message)

func (*DataStore) SaveMail

func (ds *DataStore) SaveMail()

func (*DataStore) SaveSpamIP

func (ds *DataStore) SaveSpamIP(ip string, email string)

func (*DataStore) StorageConnect

func (ds *DataStore) StorageConnect()

func (*DataStore) StorageDisconnect

func (ds *DataStore) StorageDisconnect()

func (*DataStore) Total

func (ds *DataStore) Total(username string) int

func (*DataStore) TotalErr

func (ds *DataStore) TotalErr(username string) (int, error)

func (*DataStore) Unread

func (ds *DataStore) Unread(username string) int

func (*DataStore) UnreadCount

func (ds *DataStore) UnreadCount(username string) int

type GreyHost

type GreyHost struct {
	Id        bson.ObjectId `bson:"_id"`
	CreatedBy string
	Hostname  string
	CreatedAt time.Time
	IsActive  bool
}

type GreyMail

type GreyMail struct {
	Id        bson.ObjectId `bson:"_id"`
	CreatedBy string
	Type      string
	Email     string
	Local     string
	Domain    string
	CreatedAt time.Time
	IsActive  bool
}

type ListQuery

type ListQuery struct {
	Id       string
	Sequence int
	Content  ContentQuery
}

type LoginForm

type LoginForm struct {
	Username string
	Password string
	Token    string

	Errors map[string]string
}

func (*LoginForm) Validate

func (f *LoginForm) Validate() bool

type MIMEBody

type MIMEBody struct {
	Parts []*MIMEPart
}

type MIMEPart

type MIMEPart struct {
	Boundary         string
	Headers          map[string][]string
	Body             string
	FileName         string
	ContentType      string
	Charset          string
	MIMEVersion      string
	TransferEncoding string
	Disposition      string
	Size             int
	Lines            int
}

type Message

type Message struct {
	Id          string
	Sequence    int
	Subject     string
	From        *Path
	To          []*Path
	Created     time.Time
	Attachments []*Attachment
	Ip          string
	Content     *Content
	MIME        *MIMEBody
	Starred     bool
	Unread      bool
	Recent      bool
	Deleted     bool
}

func ParseSMTPMessage

func ParseSMTPMessage(mongo *MongoDB, m *config.SMTPMessage, hostname string, mimeParser bool) *Message

TODO support nested MIME content

type Messages

type Messages []Message

type MongoDB

type MongoDB struct {
	Config    config.DataStoreConfig
	Session   *mgo.Session
	Messages  *mgo.Collection
	Users     *mgo.Collection
	Hosts     *mgo.Collection
	Emails    *mgo.Collection
	Mailboxes *mgo.Collection
	Spamdb    *mgo.Collection
	Sequences *mgo.Collection
}

func CreateMongoDB

func CreateMongoDB(c config.DataStoreConfig) *MongoDB

func (*MongoDB) Close

func (mongo *MongoDB) Close()

func (*MongoDB) DeleteAll

func (mongo *MongoDB) DeleteAll() error

func (*MongoDB) DeleteOne

func (mongo *MongoDB) DeleteOne(id string) error

func (*MongoDB) IsGreyHost

func (mongo *MongoDB) IsGreyHost(hostname string) (int, error)

func (*MongoDB) IsGreyMail

func (mongo *MongoDB) IsGreyMail(email, t string) (int, error)

func (*MongoDB) List

func (mongo *MongoDB) List(username, domain string, start int, limit int) (*Messages, error)

func (*MongoDB) Load

func (mongo *MongoDB) Load(id string) (*Message, error)

func (*MongoDB) LoadAttachment

func (mongo *MongoDB) LoadAttachment(id string) (*Message, error)

func (*MongoDB) Login

func (mongo *MongoDB) Login(username, password string) (*User, error)

Login validates and returns a user object if they exist in the database.

func (*MongoDB) MessageByUID

func (mongo *MongoDB) MessageByUID(username, domain string, uid uint32) (Message, error)

func (*MongoDB) MessageSetBySequenceNumber

func (mongo *MongoDB) MessageSetBySequenceNumber(username, domain string, set SequenceSet) Messages

func (*MongoDB) MessageSetByUID

func (mongo *MongoDB) MessageSetByUID(username, domain string, set SequenceSet) Messages

func (*MongoDB) MessageSetFlags

func (mongo *MongoDB) MessageSetFlags(username, domain, seq string)

func (*MongoDB) NextId

func (mongo *MongoDB) NextId(username string) int

func (*MongoDB) Pop3GetDele

func (mongo *MongoDB) Pop3GetDele(username string, domain string, sequence int) error

func (*MongoDB) Pop3GetList

func (mongo *MongoDB) Pop3GetList(username string, domain string) (Messages, error)

func (*MongoDB) Pop3GetRetr

func (mongo *MongoDB) Pop3GetRetr(username string, domain string, sequence int) (Message, error)

func (*MongoDB) Pop3GetStat

func (mongo *MongoDB) Pop3GetStat(username, domain string) (int, int, error)

func (*MongoDB) Pop3GetUidl

func (mongo *MongoDB) Pop3GetUidl(username string, domain string) (Messages, error)

func (*MongoDB) Recent

func (mongo *MongoDB) Recent(username, domain string) int

func (*MongoDB) RemoveRecent

func (mongo *MongoDB) RemoveRecent(m Message)

func (*MongoDB) Store

func (mongo *MongoDB) Store(m *Message) (string, error)

func (*MongoDB) StoreGreyHost

func (mongo *MongoDB) StoreGreyHost(h *GreyHost) (string, error)

func (*MongoDB) StoreGreyMail

func (mongo *MongoDB) StoreGreyMail(m *GreyMail) (string, error)

func (*MongoDB) StoreSpamIp

func (mongo *MongoDB) StoreSpamIp(s SpamIP) (string, error)

func (*MongoDB) Total

func (mongo *MongoDB) Total(username, domain string) int

func (*MongoDB) TotalErr

func (mongo *MongoDB) TotalErr(username, domain string) (int, error)

func (*MongoDB) Unread

func (mongo *MongoDB) Unread(username, domain string) int

func (*MongoDB) UnreadCount

func (mongo *MongoDB) UnreadCount(username, domain string) int

type Path

type Path struct {
	Relays  []string
	Mailbox string
	Domain  string
	Params  string
}

func PathFromString

func PathFromString(path string) *Path

type SequenceNumber

type SequenceNumber string

SequenceNumber represents a single message identifier. Could be UID or sequence number. See RFC3501 section 9.

func (SequenceNumber) IsValue

func (s SequenceNumber) IsValue() bool

IsValue returns true if the sequence number is a numeral value and not nil or *.

func (SequenceNumber) Last

func (s SequenceNumber) Last() bool

Last returns true if this sequence number indicates the *last* sequence number or UID available in this mailbox. If false, this sequence number contains an integer value.

func (SequenceNumber) Nil

func (s SequenceNumber) Nil() bool

Nil returns true if no sequence number was specified.

func (SequenceNumber) Value

func (s SequenceNumber) Value() (uint32, error)

Value returns the integer value of the sequence number, if any is set. If Nil or Last is true (ie, this sequence number is not an integer value) then this returns 0 and an error.

type SequenceRange

type SequenceRange struct {
	Min SequenceNumber
	Max SequenceNumber
}

SequenceRange represents a range of identifiers. eg in IMAP: 5:9 or 15:*

func InterpretMessageRange

func InterpretMessageRange(imapMessageRange string) (seqRange SequenceRange, err error)

InterpretMessageRange creates a SequenceRange from the given string in the IMAP format.

type SequenceSet

type SequenceSet []SequenceRange

SequenceSet represents set of sequence ranges. eg in IMAP: 1,3,5:9,18:*

func InterpretSequenceSet

func InterpretSequenceSet(imapSequenceSet string) (seqSet SequenceSet, err error)

InterpretSequenceSet creates a SequenceSet from the given string in the IMAP format.

type Sequences

type Sequences struct {
	Table string
	Value int
}

type SpamIP

type SpamIP struct {
	Id        bson.ObjectId `bson:"_id"`
	Hostname  string
	IPAddress string
	Type      string
	Email     string
	CreatedAt time.Time
	IsActive  bool
}

type StatQuery

type StatQuery struct {
	Id    string
	Count int
	Total int
}

type UidlQuery

type UidlQuery struct {
	Id       string
	Sequence int
	Uid      string
}

type User

type User struct {
	Id            bson.ObjectId `bson:"_id"`
	Firstname     string
	Lastname      string
	Email         string
	Username      string
	Password      string
	Avatar        string
	Website       string
	Location      string
	Tagline       string
	Bio           string
	JoinedAt      time.Time
	IsSuperuser   bool
	IsActive      bool
	ValidateCode  string
	ResetCode     string
	LastLoginTime time.Time
	LastLoginIp   string
	LoginCount    int64
}

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword takes a plaintext password and hashes it with bcrypt and sets the password field to the hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL