mmail

package
v0.0.0-...-cda5684 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailTypeHTML = iota
	EmailTypeText
)

Emails content type

View Source
const MailBox = "INBOX"

MailBox default mail box

Variables

View Source
var ErrEmptyUID = errors.New("Empty UID stored or invalid UIDVALIDITY")

ErrEmptyUID error when is empty UID stored or invalid UIDVALIDITY

View Source
var ErrUIDValidityZero = errors.New("uidvalidity need to be greater than zero")

ErrUIDValidityZero error when UIDVALIDITY is zero

Functions

func Start

func Start(config *model.Config) error

Start server

Types

type Attachment

type Attachment struct {
	Filename string
	Content  []byte
}

Attachment filename and content

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log implements Logger interface

func NewLog

func NewLog(prefix string, debug bool) *Log

NewLog creates a new Logger

func (*Log) Debug

func (l *Log) Debug(args ...interface{})

Debug calls Println with tag DEBG

func (*Log) Debugf

func (l *Log) Debugf(format string, v ...interface{})

Debugf calls Printf with tag DEBG

func (*Log) Error

func (l *Log) Error(args ...interface{})

Error calls Println with tag EROR

func (*Log) Errorf

func (l *Log) Errorf(format string, v ...interface{})

Errorf calls Printf with tag EROR

func (*Log) Info

func (l *Log) Info(args ...interface{})

Info calls Println with tag INFO

func (*Log) Infof

func (l *Log) Infof(format string, v ...interface{})

Infof calls Printf with tag INFO

func (*Log) Write

func (l *Log) Write(p []byte) (n int, err error)

type Logger

type Logger interface {
	Info(args ...interface{})
	Debug(args ...interface{})
	Error(args ...interface{})
	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Write(p []byte) (n int, err error)
}

Logger default interface logger with info/debug/error

type MailHandler

type MailHandler func(mailReader io.Reader) error

MailHandler function called to handle mail message

type MailMessage

type MailMessage struct {
	From        string
	Subject     string
	EmailText   string
	EmailBody   string
	EmailType   int
	Attachments []*Attachment
}

MailMessage mail message with fields used in mattermail

func ReadMailMessage

func ReadMailMessage(r io.Reader) (*MailMessage, error)

ReadMailMessage convert net/mail in MailMessage

type MailProvider

type MailProvider interface {
	// CheckNewMessage gets new email from server
	CheckNewMessage(handler MailHandler) error

	// WaitNewMessage waits for a new message (idle or time.Sleep)
	WaitNewMessage(timeout int) error

	// Terminate mail connection
	Terminate() error
}

MailProvider interface to abstract email connection

type MailProviderImap

type MailProviderImap struct {
	// contains filtered or unexported fields
}

MailProviderImap implements MailProvider using imap

func NewMailProviderImap

func NewMailProviderImap(cfg *model.Email, log Logger, cache UIDCache, debug bool) *MailProviderImap

NewMailProviderImap creates a new MailProviderImap implementing MailProvider

func (*MailProviderImap) CheckNewMessage

func (m *MailProviderImap) CheckNewMessage(handler MailHandler) error

CheckNewMessage gets new email from server

func (*MailProviderImap) Terminate

func (m *MailProviderImap) Terminate() error

Terminate imap connection

func (*MailProviderImap) WaitNewMessage

func (m *MailProviderImap) WaitNewMessage(timeout int) error

WaitNewMessage waits for a new message (idle or time.Sleep)

type MatterMail

type MatterMail struct {
	// contains filtered or unexported fields
}

MatterMail struct with configurations, loggers and Mattemost user

func NewMatterMail

func NewMatterMail(cfg *model.Profile, log Logger, mailProvider MailProvider, mmProvider MattermostProvider) *MatterMail

NewMatterMail creates a new MatterMail instance

func (*MatterMail) Listen

func (m *MatterMail) Listen()

Listen starts MatterMail server

func (*MatterMail) PostMailMessage

func (m *MatterMail) PostMailMessage(msg *MailMessage) error

PostMailMessage MailMessage in Mattermost

func (*MatterMail) PostNetMail

func (m *MatterMail) PostNetMail(mailReader io.Reader) error

PostNetMail read net/mail.Message and post in Mattermost

type MattermostProvider

type MattermostProvider interface {
	// Login log in Mattermost
	Login() error

	// Logout terminate connection with Mattermost
	Logout() error

	// GetChannelID gets channel id by channel name return empty string if not exists
	GetChannelID(channelName string) string

	// PostMessage posts a message in Mattermost
	PostMessage(message, channelID string, attachments []*Attachment) error
}

MattermostProvider interface to abstract Mattermost functions

func NewMattermostProvider

func NewMattermostProvider(cfg *model.Mattermost, log Logger) MattermostProvider

NewMattermostProvider creates a new instance of Mattermost

type MattermostProviderV3

type MattermostProviderV3 struct {
	// contains filtered or unexported fields
}

MattermostProviderV3 default implementation of MattermostProvider

func NewMattermostProviderV3

func NewMattermostProviderV3(cfg *model.Mattermost, log Logger) *MattermostProviderV3

NewMattermostProviderV3 creates a new instance of Mattermost api V3

func (*MattermostProviderV3) GetChannelID

func (m *MattermostProviderV3) GetChannelID(channelName string) string

GetChannelID gets channel id by channel name return empty string if not exists

func (*MattermostProviderV3) Login

func (m *MattermostProviderV3) Login() error

Login log in Mattermost

func (*MattermostProviderV3) Logout

func (m *MattermostProviderV3) Logout() (err error)

Logout terminate connection with Mattermost

func (*MattermostProviderV3) PostMessage

func (m *MattermostProviderV3) PostMessage(message, channelID string, attachments []*Attachment) error

PostMessage posts a message in Mattermost

type MattermostProviderV4

type MattermostProviderV4 struct {
	// contains filtered or unexported fields
}

MattermostProviderV4 default implementation of MattermostProvider

func NewMattermostProviderV4

func NewMattermostProviderV4(cfg *model.Mattermost, log Logger) *MattermostProviderV4

NewMattermostProviderV4 creates a new instance of Mattermost api V4

func (*MattermostProviderV4) GetChannelID

func (m *MattermostProviderV4) GetChannelID(channelName string) string

GetChannelID gets channel id by channel name return empty string if not exists

func (*MattermostProviderV4) Login

func (m *MattermostProviderV4) Login() error

Login log in Mattermost

func (*MattermostProviderV4) Logout

func (m *MattermostProviderV4) Logout() (err error)

Logout terminate connection with Mattermost

func (*MattermostProviderV4) PostMessage

func (m *MattermostProviderV4) PostMessage(message, channelID string, attachments []*Attachment) error

PostMessage posts a message in Mattermost

type UIDCache

type UIDCache interface {
	// GetNextUID returns the next uid for the uidvalidity, if empty or is an invalid uidvalidity returns ErrEmptyUID
	GetNextUID(uidvalidity uint32) (uint32, error)

	// SaveNextUID stores the uid and uidvalidity
	SaveNextUID(uidvalidity, uid uint32) error
}

UIDCache is a cache of uid for account + mailbox

type UIDCacheFile

type UIDCacheFile struct {
	// contains filtered or unexported fields
}

UIDCacheFile implements UIDCache using filesystem to store

func NewUIDCacheFile

func NewUIDCacheFile(directory, account, mailbox string) *UIDCacheFile

NewUIDCacheFile return a new UIDCacheFile

func (*UIDCacheFile) GetNextUID

func (u *UIDCacheFile) GetNextUID(uidvalidity uint32) (uint32, error)

GetNextUID returns the next uid for the uidvalidity, if empty or is an invalid uidvalidity returns ErrEmptyUID

func (*UIDCacheFile) SaveNextUID

func (u *UIDCacheFile) SaveNextUID(uidvalidity, uid uint32) error

SaveNextUID stores the uid and uidvalidity

Jump to

Keyboard shortcuts

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