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
- Variables
- func DisableLog()
- func InitializeUser(u *store.UserData, keys *keymgr.Manager, GenKeys int16) error
- func NewDrafts(mbox store.Folder, addresses map[string]string) (*mailbox, error)
- func NewMailbox(mbox store.Folder, addresses map[string]string) (*mailbox, error)
- func UseIMAPLogger(logger btclog.Logger)
- func UseSMTPLogger(logger btclog.Logger)
- type Bitmessage
- func BroadcastRead(msg *wire.MsgBroadcast) (*Bitmessage, error)
- func DecodeBitmessage(data []byte) (*Bitmessage, error)
- func MsgRead(msg *wire.MsgMsg, toAddress string, ofChan bool) (*Bitmessage, error)
- func NewBitmessageDraftFromSMTP(smtp *data.Content) (*Bitmessage, error)
- func NewBitmessageFromSMTP(smtp *data.Content) (*Bitmessage, error)
- type BitmessageStore
- type IMAPConfig
- type IMAPEmail
- func (e *IMAPEmail) AddFlags(newFlags types.Flags) mailstore.Message
- func (e *IMAPEmail) Body() string
- func (e *IMAPEmail) Flags() types.Flags
- func (e *IMAPEmail) Header() textproto.MIMEHeader
- func (e *IMAPEmail) InternalDate() time.Time
- func (e *IMAPEmail) Keywords() []string
- func (e *IMAPEmail) OverwriteFlags(newFlags types.Flags) mailstore.Message
- func (e *IMAPEmail) RemoveFlags(newFlags types.Flags) mailstore.Message
- func (e *IMAPEmail) Save() (mailstore.Message, error)
- func (e *IMAPEmail) SequenceNumber() uint32
- func (e *IMAPEmail) SetBody(body string) mailstore.Message
- func (e *IMAPEmail) SetHeaders(headers textproto.MIMEHeader) mailstore.Message
- func (e *IMAPEmail) Size() uint32
- func (e *IMAPEmail) UID() uint32
- type ImapData
- type Mailbox
- type MessageSequence
- type MessageState
- type SMTPConfig
- type SMTPServer
- type ServerOps
- type User
- func (u *User) DeliverAckReply()
- func (u *User) DeliverFromBMNet(bm *Bitmessage) error
- func (u *User) DeliverFromSMTP(bmsg *Bitmessage) error
- func (u *User) DeliverPow(index uint64, obj *wire.MsgObject) error
- func (u *User) DeliverPowAck()
- func (u *User) DeliverPublicKey(bmaddr string, public *identity.Public) error
- func (u *User) GenerateKeys(n uint16) error
- func (u *User) MailboxByName(name string) (mailstore.Mailbox, error)
- func (u *User) Mailboxes() []mailstore.Mailbox
- func (u *User) NewMailbox(name string) (Mailbox, error)
Constants ¶
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 ¶
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 InitializeUser ¶
InitializeStore initializes the store by creating the default mailboxes and inserting the welcome message.
func NewMailbox ¶
NewMailbox returns a new mailbox.
func UseIMAPLogger ¶
UseIMAPLogger uses a specified Logger to output logging info for the IMAP server.
func UseSMTPLogger ¶
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 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 ¶
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 ¶
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 ¶
AddFlags writes the flags for this message and return the updated 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 ¶
InternalDate return the date the email was received by the server (This is not the date on the envelope of the email).
func (*IMAPEmail) OverwriteFlags ¶
OverwriteFlags overwrites the flags for this message and return the updated message.
func (*IMAPEmail) RemoveFlags ¶
RemoveFlags writes the flags for this message and return the updated message.
func (*IMAPEmail) SequenceNumber ¶
SequenceNumber returns the sequence number of the email.
func (*IMAPEmail) SetHeaders ¶
func (e *IMAPEmail) SetHeaders(headers textproto.MIMEHeader) mailstore.Message
SetHeaders sets the headers of a message.
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 ¶
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.
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 (*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 ¶
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 ¶
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 ¶
Generate keys creates n new keys for the user and sends him a message about them.
func (*User) MailboxByName ¶
MailboxByName returns a mailbox by its name. It is part of the IMAPMailbox interface.