Version: v0.0.0-...-dee8dd0 Latest Latest

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

Go to latest
Published: Mar 29, 2017 License: ISC Imports: 14 Imported by: 6




View Source
const (
	// DateFormat is the format for encoding dates.
	DateFormat = "Mon Jan 2 15:04:05 -0700 MST 2006"

	// Broadcast is the email address used to send broadcasts.
	Broadcast = "broadcast@bm.addr"


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

	// ErrGetPubKeySent is the error returned by GenerateObject when a
	// a message could not be written as an object because the necessary
	// PubKey was missing. However, a GetPubKey request was successfully
	// sent, so we should receive it eventually.
	ErrGetPubKeySent = fmt.Errorf("GetPubKey request sent")

	// ErrAckMissing is the error returned by GenerateObject when a
	// message could not be written as an object because an ack is required
	// but missing. Therefore it is necessary to generate the ack and
	// do POW on it before proceeding.
	ErrAckMissing = fmt.Errorf("Ack missing")

	// BitmessageRegex is the regex of a Bitmessage address.
	BitmessageRegex = regexp.MustCompile(fmt.Sprintf("^%s$", bmAddrPattern))

	// CommandRegex is used for detecting an email intended as a
	// command to bmagent.
	CommandRegex = regexp.MustCompile(commandRegexString)
View Source
var (
	IMAPLog btclog.Logger
	SMTPLog btclog.Logger

Loggers initialized with no output filters. This means the package will not perform any logging by default until the caller requests it.


func BmToEmail

func BmToEmail(bmAddr string) string

BmToEmail converts a Bitmessage address to an e-mail address.

func DisableLog

func DisableLog()

DisableLog disables all library log output.

func GetContentType

func GetContentType(contentType string) (content, subtype string, param map[string]string, err error)

GetContentType takes a string representing the a Content-Type email header value and parses it into a set of values.

According to, the proper format for Content-Type is given by

Content-Type := type "/" subtype *[";" parameter]

type :=   "application"     / "audio"
          / "image"           / "message"
          / "multipart"  / "text"
          / "video"           / x-token

x-token := <The two characters "X-" followed, with no
           intervening white space, by any token>

subtype := token

parameter := attribute "=" value

attribute := token

value := token / quoted-string

token := 1*<any CHAR except SPACE, CTLs, or tspecials>

tspecials :=  "(" / ")" / "<" / ">" / "@"  ; Must be in
           /  "," / ";" / ":" / "\" / <">  ; quoted-string,
           /  "/" / "[" / "]" / "?" / "."  ; to use within
           /  "="                        ; parameter values

func GetSMTPBody

func GetSMTPBody(email *data.Content) (string, error)

GetSMTPBody return the body of an e-mail to be delivered through SMTP.

func ToBm

func ToBm(emailAddr string) (string, error)

ToBm extracts a Bitmessage address from an e-mail address.

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.

func ValidateEmail

func ValidateEmail(to string) bool

ValidateEmail validates an email TO header entry.


type Bmail

type Bmail struct {
	From       string
	To         string
	OfChannel  bool // Whether the message was sent to/received from a channel.
	Expiration time.Time
	Ack        []byte
	Content    format.Encoding
	ImapData   *ImapData
	State      *MessageState

Bmail represents an email compatible with a bitmessage format (msg or broadcast). If To is empty, then it is a broadcast.

func BroadcastRead

func BroadcastRead(msg *cipher.Broadcast) (*Bmail, error)

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

func MsgRead

func MsgRead(msg *cipher.Message, toAddress string, ofChan bool) (*Bmail, error)

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

func NewBitmessageDraftFromSMTP

func NewBitmessageDraftFromSMTP(smtp *data.Content) (*Bmail, 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) (*Bmail, error)

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

func (*Bmail) ToEmail

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

ToEmail converts a Bitmessage into an IMAPEmail.

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 {

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

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

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

Mailbox represent a mailbox compatible with both IMAP and Bitmessage.

type MessageState

type MessageState struct {
	// Whether a pubkey request is pending for this message.
	PubkeyRequestOutstanding bool
	// 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL