email

package
v0.0.0-...-ddd0786 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2016 License: ISC Imports: 30 Imported by: 0

Documentation

Overview

Package email provides functionality for implementing the IMAP and SMTP servers for bmclient. It allows Bitmessage to act like email. It provides for message folders that are compatible with IMAP and for coverting between the e-mail format and Bitmessage objects.

Index

Constants

View Source
const (
	// InboxFolderName is the default name for the inbox folder.
	// The IMAP protocol requires that a folder named Inbox, case insensitive,
	// exist. So this can't be changed.
	InboxFolderName = "Inbox"

	// OutboxFolderName is the default name for the out folder.
	// Messages in the out folder are waiting for pow to be completed or public
	// key of the recipient so that they can be sent.
	OutboxFolderName = "Outbox"

	// LimboFolderName is the default name for folder containing messages
	// that are out in the network, but have not been received yet (no ack).
	LimboFolderName = "Limbo"

	// SentFolderName is the default name for the sent folder.
	SentFolderName = "Sent"

	// TrashFolderName is the default name for the trash folder.
	TrashFolderName = "Trash"

	// DraftsFolderName is the default name for the drafts folder.
	DraftsFolderName = "Drafts"

	// CommandsFolderName is the default name for the folder containing
	// responses to sent commands.
	CommandsFolderName = "Commands"
)

Variables

View Source
var (
	// ErrInvalidEmail is the error returned by EmailToBM when the e-mail
	// address is invalid and a valid Bitmessage address cannot be extracted
	// from it.
	ErrInvalidEmail = errors.New(
		fmt.Sprintf("From address must be of the form %s.",
			emailRegexString))
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output.

func InitializeUser

func InitializeUser(u *store.UserData, keys *keymgr.Manager, GenKeys int16) error

InitializeStore initializes the store by creating the default mailboxes and inserting the welcome message.

func NewDrafts

func NewDrafts(mbox store.Folder, addresses map[string]string) (*mailbox, error)

NewDrafts returns a new Drafts folder.

func NewMailbox

func NewMailbox(mbox store.Folder, addresses map[string]string) (*mailbox, error)

NewMailbox returns a new mailbox.

func UseIMAPLogger

func UseIMAPLogger(logger btclog.Logger)

UseIMAPLogger uses a specified Logger to output logging info for the IMAP server.

func UseSMTPLogger

func UseSMTPLogger(logger btclog.Logger)

UseSMTPLogger uses a specified Logger to output logging info for the SMTP server.

Types

type Bitmessage

type Bitmessage struct {
	From       string
	To         string
	OfChannel  bool // Whether the message was sent to/received from a channel.
	Expiration time.Time
	Ack        []byte
	Message    format.Encoding
	ImapData   *ImapData
	// contains filtered or unexported fields
}

Bitmessage represents a message compatible with a bitmessage format (msg or broadcast). If To is empty, then it is a broadcast.

func BroadcastRead

func BroadcastRead(msg *wire.MsgBroadcast) (*Bitmessage, error)

BroadcastRead creates a Bitmessage object from an unencrypted wire.MsgBroadcast.

func DecodeBitmessage

func DecodeBitmessage(data []byte) (*Bitmessage, error)

DecodeBitmessage takes the protobuf encoding of a Bitmessage and converts it back to a Bitmessage.

func MsgRead

func MsgRead(msg *wire.MsgMsg, toAddress string, ofChan bool) (*Bitmessage, error)

MsgRead creates a Bitmessage object from an unencrypted wire.MsgMsg.

func NewBitmessageDraftFromSMTP

func NewBitmessageDraftFromSMTP(smtp *data.Content) (*Bitmessage, error)

NewBitmessageDraftFromSMTP takes an SMTP e-mail and turns it into a Bitmessage, but is less strict than NewBitmessageFromSMTP in how it checks the email.

func NewBitmessageFromSMTP

func NewBitmessageFromSMTP(smtp *data.Content) (*Bitmessage, error)

NewBitmessageFromSMTP takes an SMTP e-mail and turns it into a Bitmessage.

func (*Bitmessage) GenerateObject

func (m *Bitmessage) GenerateObject(s ServerOps) (object *wire.MsgObject,
	nonceTrials, extraBytes uint64, genErr error)

GenerateObject generates the wire.MsgObject form of the message.

func (*Bitmessage) Serialize

func (m *Bitmessage) Serialize() ([]byte, error)

Serialize encodes the message in a protobuf format.

func (*Bitmessage) SubmitPow

func (m *Bitmessage) SubmitPow(s ServerOps) error

SubmitPow attempts to submit a message for pow.

func (*Bitmessage) ToEmail

func (m *Bitmessage) ToEmail() (*IMAPEmail, error)

ToEmail converts a Bitmessage into an IMAPEmail.

type BitmessageStore

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

BitmessageStore implements mailstore.Mailstore.

func NewBitmessageStore

func NewBitmessageStore(user *User, cfg *IMAPConfig) *BitmessageStore

NewBitmessageStore creates a new bitmessage store.

func (*BitmessageStore) Authenticate

func (s *BitmessageStore) Authenticate(username string, password string) (mailstore.User, error)

Authenticate is part of the mailstore.Mailstore interface. It takes a username and password and returns a mailstore.User if the credentials are valid.

type IMAPConfig

type IMAPConfig struct {
	Username   string
	Password   string
	RequireTLS bool
}

IMAPConfig contains configuration options for the IMAP server.

type IMAPEmail

type IMAPEmail struct {
	ImapSequenceNumber uint32
	ImapUID            uint64
	ImapFlags          types.Flags
	Date               time.Time
	Mailbox            Mailbox
	Content            *data.Content
}

IMAPEmail is a representaton of an email that is compatible with the IMAP protocol and is an implementation of mailstore.Message. An email according IMAP is associated with a particular mailbox and therefore includes things like a uid and sequence number.

func (*IMAPEmail) AddFlags

func (e *IMAPEmail) AddFlags(newFlags types.Flags) mailstore.Message

AddFlags writes the flags for this message and return the updated message.

func (*IMAPEmail) Body

func (e *IMAPEmail) Body() string

Body returns the body of the email.

func (*IMAPEmail) Flags

func (e *IMAPEmail) Flags() types.Flags

Flags returns the flags for this message.

func (*IMAPEmail) Header

func (e *IMAPEmail) Header() textproto.MIMEHeader

Header returns the message's MIME headers as a map in a format compatible with imap-server.

func (*IMAPEmail) InternalDate

func (e *IMAPEmail) InternalDate() time.Time

InternalDate return the date the email was received by the server (This is not the date on the envelope of the email).

func (*IMAPEmail) Keywords

func (e *IMAPEmail) Keywords() []string

Keywords returns the list of custom keywords/flags for this message.

func (*IMAPEmail) OverwriteFlags

func (e *IMAPEmail) OverwriteFlags(newFlags types.Flags) mailstore.Message

OverwriteFlags overwrites the flags for this message and return the updated message.

func (*IMAPEmail) RemoveFlags

func (e *IMAPEmail) RemoveFlags(newFlags types.Flags) mailstore.Message

RemoveFlags writes the flags for this message and return the updated message.

func (*IMAPEmail) Save

func (e *IMAPEmail) Save() (mailstore.Message, error)

Save saves any changes to the message.

func (*IMAPEmail) SequenceNumber

func (e *IMAPEmail) SequenceNumber() uint32

SequenceNumber returns the sequence number of the email.

func (*IMAPEmail) SetBody

func (e *IMAPEmail) SetBody(body string) mailstore.Message

SetBody sets the body of the message.

func (*IMAPEmail) SetHeaders

func (e *IMAPEmail) SetHeaders(headers textproto.MIMEHeader) mailstore.Message

SetHeaders sets the headers of a message.

func (*IMAPEmail) Size

func (e *IMAPEmail) Size() uint32

Size returns the RFC822 size of the message.

func (*IMAPEmail) UID

func (e *IMAPEmail) UID() uint32

UID return the unique id of the email.

type ImapData

type ImapData struct {
	UID            uint64
	SequenceNumber uint32
	Flags          types.Flags
	TimeReceived   time.Time
	Mailbox        Mailbox
}

ImapData provides a Bitmessage with extra information to make it compatible with imap.

type Mailbox

type Mailbox interface {
	mailstore.Mailbox

	// Save saves an IMAP email in the Mailbox.
	Save(email *IMAPEmail) error

	// AddNew adds a new Bitmessage to the Mailbox.
	AddNew(bmsg *Bitmessage, flags types.Flags) error

	// DeleteBitmessageByUID deletes a bitmessage by uid.
	DeleteBitmessageByUID(id uint64) error
}

type MessageSequence

type MessageSequence []uint64

MessageSequence represents a sequence of uids contained in this mailbox. It implements sort.Interface.

func (MessageSequence) GetSequenceNumber

func (uids MessageSequence) GetSequenceNumber(uid uint64) uint32

GetSequenceNumber gets the lowest sequence number containing a value higher than or equal to the given uid.

func (MessageSequence) Len

func (uids MessageSequence) Len() int

func (MessageSequence) Less

func (uids MessageSequence) Less(i, j int) bool

func (MessageSequence) Swap

func (uids MessageSequence) Swap(i, j int)

type MessageState

type MessageState struct {
	// Whether a pubkey request is pending for this message.
	PubkeyRequestOutstanding bool
	// The index of a pow computation for this message.
	PowIndex uint64
	// The index of a pow computation for the message ack.
	AckPowIndex uint64
	// The number of times that the message was sent.
	SendTries uint32
	// The last send attempt for the message.
	LastSend time.Time
	// Whether an ack is expected for this message.
	AckExpected bool
	// Whether an ack has been received.
	AckReceived bool
	// Whether the message was received over the bitmessage network.
	Received bool
}

MessageState contains the state of the message as maintained by bmclient.

type SMTPConfig

type SMTPConfig struct {
	RequireTLS bool
	Username   string
	Password   string
}

SMTPConfig contains configuration options for the SMTP server.

type SMTPServer

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

SMTPServer provides an SMTP server for handling communications with SMTP clients.

func NewSMTPServer

func NewSMTPServer(cfg *SMTPConfig, user *User) *SMTPServer

NewSMTPServer returns a new smtp server.

func (*SMTPServer) Serve

func (serv *SMTPServer) Serve(l net.Listener) error

Serve serves SMTP requests on the given listener.

type ServerOps

type ServerOps interface {
	// GetOrRequestPublicID attempts to retreive a public identity for the given
	// address. If the function returns nil with no error, that means that a
	// pubkey request was successfully queued for proof-of-work.
	GetOrRequestPublicID(string) (*identity.Public, error)

	// GetPrivateID queries the key manager for the right private key for the
	// given address.
	GetPrivateID(string) *keymgr.PrivateID

	// GetObjectExpiry returns the time duration after which an object of the
	// given type will expire on the network. It's used for POW calculations.
	GetObjectExpiry(wire.ObjectType) time.Duration

	// RunPow submits some data to have the pow calculated and submitted to the network.
	RunPow(uint64, []byte) (uint64, error)

	// Mailboxes returns the set of mailboxes in the store.
	Folders() []store.Folder
}

ServerOps is used for doing operations best performed by the server and its components. This includes requesting public and private identities from the server and accessing some config options.

type User

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

User implements the mailstore.User interface and represents a collection of imap folders belonging to a single user.

func NewUser

func NewUser(username string, server ServerOps, keys *keymgr.Manager) (*User, error)

NewUser creates a User object from the store.

func (*User) DeliverAckReply

func (u *User) DeliverAckReply()

DeliverAckReply takes a message ack and marks a message as having been received by the recipient.

func (*User) DeliverFromBMNet

func (u *User) DeliverFromBMNet(bm *Bitmessage) error

DeliverFromBMNet adds a message received from bmd into the appropriate folder.

func (*User) DeliverFromSMTP

func (u *User) DeliverFromSMTP(bmsg *Bitmessage) error

DeliverFromSMTP adds a message received via SMTP to the POW queue, if needed, and the outbox.

func (*User) DeliverPow

func (u *User) DeliverPow(index uint64, obj *wire.MsgObject) error

DeliverPow delivers an object that has had pow done on it.

func (*User) DeliverPowAck

func (u *User) DeliverPowAck()

DeliverPowAck delivers an ack message that was generated by the pow queue.

func (*User) DeliverPublicKey

func (u *User) DeliverPublicKey(bmaddr string, public *identity.Public) error

DeliverPublicKey takes a public key and attempts to match it with a message. If a matching message is found, the message is encoded to the wire format and sent to the pow queue.

func (*User) GenerateKeys

func (u *User) GenerateKeys(n uint16) error

Generate keys creates n new keys for the user and sends him a message about them.

func (*User) MailboxByName

func (u *User) MailboxByName(name string) (mailstore.Mailbox, error)

MailboxByName returns a mailbox by its name. It is part of the IMAPMailbox interface.

func (*User) Mailboxes

func (u *User) Mailboxes() []mailstore.Mailbox

Mailboxes returns all the mailboxes. It is part of the IMAPMailbox interface.

func (*User) NewMailbox

func (u *User) NewMailbox(name string) (Mailbox, error)

NewMailbox adds a new mailbox.

Jump to

Keyboard shortcuts

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