Documentation ¶
Index ¶
- Constants
- func GetPath(section Section, msgID, file string) (string, error)
- func IncomingPathExists(msgID, file string) bool
- func MoveMessage(srcSection Section, targetSection Section, msgID string) error
- func ProcessQueuePathExists(msgID, file string) bool
- func RemoveMessage(section Section, msgID string) error
- func SignClientHeader(header *Header, privKey bmcrypto.PrivKey) error
- func SignServerHeader(header *Header) error
- func StoreAttachment(msgID, attachmentID string, r io.Reader) error
- func StoreBlock(msgID, blockID string, r io.Reader) error
- func StoreCatalog(msgID string, r io.Reader) error
- func StoreHeader(msgID string, header *Header) error
- func StoreLocalMessage(envelope *Envelope) (string, error)
- func StoreRetryInfo(section Section, msgID string, info RetryInfo) error
- func VerifyClientHeader(header Header) bool
- func VerifyServerHeader(header Header) bool
- func ZlibCompress(r io.Reader) io.Reader
- func ZlibDecompress(r io.Reader) (io.Reader, error)
- type Addressing
- type Attachment
- type AttachmentType
- type AuthorizedByType
- type Block
- type BlockType
- type Catalog
- func (c *Catalog) AddAttachment(entry Attachment) error
- func (c *Catalog) AddBlock(entry Block) error
- func (c *Catalog) AddFlags(flags ...string)
- func (c *Catalog) AddLabels(labels ...string)
- func (c *Catalog) GetBlock(blockType string) (*BlockType, error)
- func (c *Catalog) GetFirstBlock() *BlockType
- func (c *Catalog) HasBlock(blockType string) bool
- func (c *Catalog) SetToAddress(addr address.Address)
- type ChecksumList
- type DecryptedMessage
- type EncryptedMessage
- type Envelope
- type FileType
- type Flags
- type Header
- type List
- type RetryInfo
- type Section
- type SignedByType
Constants ¶
const ( // SectionIncoming uploading message SectionIncoming = iota // SectionProcessing processes a message SectionProcessing // SectionRetry messages that have to be retried at a later stadium SectionRetry )
Variables ¶
This section is empty.
Functions ¶
func GetPath ¶
GetPath will return the actual path based on the section, messageID and file inside the message
func IncomingPathExists ¶
IncomingPathExists returns true when the upload path for the given message/file exists
func MoveMessage ¶
MoveMessage moves a message from a section to another section. Highly unoptimized.
func ProcessQueuePathExists ¶
ProcessQueuePathExists returns true when the processing path for the given message/file exists
func RemoveMessage ¶
RemoveMessage removes a complete message (header, catalog, blocks etc)
func SignClientHeader ¶
SignClientHeader will add a client signature to a message header. This can be used to proof the origin of the message
func SignServerHeader ¶
SignServerHeader will add a server signature to a message header. This can be used to proof the origin of the message
func StoreAttachment ¶
StoreAttachment stores a message attachment to disk
func StoreBlock ¶
StoreBlock stores a message block to disk
func StoreCatalog ¶
StoreCatalog stores a catalog to disk
func StoreHeader ¶
StoreHeader stores a message header to disk
func StoreLocalMessage ¶
StoreLocalMessage will store a message locally
func StoreRetryInfo ¶
StoreRetryInfo saves the retry information back to disk
func VerifyClientHeader ¶
VerifyClientHeader will verify a client signature from a message header. This can be used to proof the origin of the message
func VerifyServerHeader ¶
VerifyServerHeader will verify a server signature from a message header. This can be used to proof the origin of the message
func ZlibCompress ¶
ZlibCompress compresses a stream through zlib compression
Types ¶
type Addressing ¶
type Addressing struct { Sender struct { Address *address.Address // BitMaelum Address Hash *hash.Hash // Optional address hash if the address is unknown (for instance, server messages). If the address is set, this field is ignored Name string // Additional name (if known) PrivKey *bmcrypto.PrivKey // Private key of the sender Host string // Host address of the sender mail server } Recipient struct { Address *address.Address // BitMaelum Address Hash *hash.Hash // Optional address hash if the address is unknown (for instance, server messages). If the address is set, this field is ignored PubKey *bmcrypto.PubKey // Public key } AuthorizedBy struct { PubKey *bmcrypto.PubKey // Public key of the authorized user Signature string // signature of the signed public key by the sender.address } Type SignedByType // Type of the addressing }
Addressing is the configuration for an envelope (@TODO: bad naming)
func NewAddressing ¶
func NewAddressing(signType SignedByType) Addressing
NewAddressing sets up a new addressing struct that can be used for composing and sending a message. Use the fluent builder methods to populate the sender and the receiver
func (*Addressing) AddRecipient ¶
AddRecipient will add recipient information to the addressing
type Attachment ¶
type Attachment struct { Path string // LOCAL path of the attachment. Needed for things like os.Stat() Reader io.ReadSeeker // Reader to the attachment file, also needs to seek, as we need to reset after a mimetype check }
Attachment represents an attachment and reader
func GenerateAttachments ¶
func GenerateAttachments(a []string) ([]Attachment, error)
GenerateAttachments creates message attachments that we can add to a catalog
type AttachmentType ¶
type AttachmentType struct { ID string `json:"id"` // Attachment identifier UUID MimeType string `json:"mimetype"` // Mimetype FileName string `json:"filename"` // Filename Size uint64 `json:"size"` // Size of the attachment in bytes Compression string `json:"compression"` // Compression used Checksum ChecksumList `json:"checksum"` // Checksums of the data Reader io.Reader `json:"-"` // Reader to the attachment data Key []byte `json:"key"` // Key for decryption IV []byte `json:"iv"` // IV for decryption }
AttachmentType represents a message attachment as used inside a catalog
type AuthorizedByType ¶
type AuthorizedByType struct { PublicKey *bmcrypto.PubKey `json:"public_key"` // Public key of the authorized sender Signature string `json:"signature"` // Signature signed by the origin address }
AuthorizedByType holds info about the authorized sender in case the message is send and signed by an authorized sender instead of the origin sender
type Block ¶
type Block struct { Type string // Type of the block (text, html, default, mobile etc) Size uint64 // Size of the block Reader io.Reader // Reader to the block data }
Block represents a block and reader
func GenerateBlocks ¶
GenerateBlocks generates blocks that can be added to a catalog
type BlockType ¶
type BlockType struct { ID string `json:"id"` // BLock identifier UUID Type string `json:"type"` // Type of the block. Can be anything message readers can parse. Size uint64 `json:"size"` // Size of the block in bytes Encoding string `json:"encoding"` // Encoding of the block in case it's encoded Compression string `json:"compression"` // Compression used Checksum ChecksumList `json:"checksum"` // Checksums of the block Reader io.Reader `json:"-"` // Reader of the block data Key []byte `json:"key"` // Key for decryption IV []byte `json:"iv"` // IV for decryption }
BlockType represents a message block as used inside a catalog
type Catalog ¶
type Catalog struct { From struct { Address string `json:"address"` // BitMaelum address of the sender Name string `json:"name"` // Name of the sender Organisation string `json:"organisation"` // Organisation of the sender ProofOfWork *proofofwork.ProofOfWork `json:"proof_of_work"` // Sender's proof of work PublicKey *bmcrypto.PubKey `json:"public_key"` // Public key of the sender } `json:"from"` To struct { Address string `json:"address"` // Address of the recipient } `json:"to"` CreatedAt time.Time `json:"created_at"` // Timestamp when the message was created ThreadID string `json:"thread_id"` // Thread ID (and parent ID) in case this message was send in a thread Subject string `json:"subject"` // Subject of the message Flags []string `json:"flags"` // Flags of the message Labels []string `json:"labels"` // Labels for this message Blocks []BlockType `json:"blocks"` // Message block info Attachments []AttachmentType `json:"attachments"` // Message attachment info }
Catalog is the structure that represents a message catalog. This will hold all information about the actual message, blocks and attachments.
func NewCatalog ¶
func NewCatalog(addr Addressing, subject string) *Catalog
NewCatalog initialises a new catalog. This catalog has to be filled with more info, blocks and attachments
func (*Catalog) AddAttachment ¶
func (c *Catalog) AddAttachment(entry Attachment) error
AddAttachment adds an attachment to a catalog
func (*Catalog) GetFirstBlock ¶
GetFirstBlock returns the first block found in the message
func (*Catalog) SetToAddress ¶
SetToAddress sets the address of the recipient
type ChecksumList ¶
ChecksumList is a list of key/value pairs of checksums. ie: ["sha1"] = "123456abcde"
func CalculateChecksums ¶
func CalculateChecksums(r io.Reader) (ChecksumList, error)
CalculateChecksums calculates a number of hashes for the given reader in one go. Taken from http://marcio.io/2015/07/calculating-multiple-file-hashes-in-a-single-pass/
type DecryptedMessage ¶
type DecryptedMessage struct { ID string // Optional message ID (not part of the message) Header *Header // Message header (same as in the encrypted message) Catalog *Catalog // Decrypted catalog }
DecryptedMessage is a message that is fully decrypted and can be read
type EncryptedMessage ¶
type EncryptedMessage struct { ID string // Optional message ID (not part of the message) Header *Header // Message header Catalog []byte // Encrypted catalog GenerateBlockReader func(messageID, blockID string) io.Reader // Generator for block readers GenerateAttachmentReader func(messageID, attachmentID string) io.Reader // generator for attachment readers }
EncryptedMessage is an encrypted message.
func (*EncryptedMessage) Decrypt ¶
func (em *EncryptedMessage) Decrypt(privKey bmcrypto.PrivKey) (*DecryptedMessage, error)
Decrypt will decrypt the current encrypted message with the given public key and return a decrypted copy
type Envelope ¶
type Envelope struct { Header *Header // The message header EncryptedCatalog []byte // The catalog in encrypted bytes BlockReaders map[string]*io.Reader // Readers for the blocks AttachmentReaders map[string]*io.Reader // Readers for the attachments // contains filtered or unexported fields }
Envelope is a simple structure that will keep a header and catalog together.
func Compose ¶
func Compose(addressing Addressing, subject string, b, a []string) (*Envelope, error)
Compose will create a new message and places it inside an envelope. This can be used for actual sending the message
func NewEnvelope ¶
NewEnvelope creates a new (open) envelope which is used for holding a complete message
func (*Envelope) AddCatalog ¶
AddCatalog will add a catalog to the envelope
type Flags ¶
type Flags struct {
Flags []string `json:"flags"`
}
Flags represents the .flags.json file which holds all current flags for the given mailbox/message
type Header ¶
type Header struct { // Information on the sender of the message From struct { Addr hash.Hash `json:"address"` // Address hash of the sender SignedBy SignedByType `json:"signed_by"` // Who has signed this message (the originator, or an authorized sender?) } `json:"from"` // Information on the recipient of the message To struct { Addr hash.Hash `json:"address"` // Address hash of the recipient Fingerprint string `json:"fingerprint,omitempty"` // The fingerprint used for encrypting to this user } `json:"to"` // Information about the catalog of this message Catalog struct { Size uint64 `json:"size"` // Size of the catalog file Checksum ChecksumList `json:"checksum"` // Checksum of the catalog file Crypto string `json:"crypto,omitempty"` // Crypto used (not used in newer releases) TransactionID string `json:"txid,omitempty"` // Transaction ID (if used) for encryption EncryptedKey []byte `json:"encrypted_key"` // The actual encrypted key, only to be decrypted by the private key of the recipient } `json:"catalog"` AuthorizedBy *AuthorizedByType `json:"authorized_by,omitempty"` // Using a pointer type since this section can be completely omitted // Signatures on the message header Signatures struct { Server string `json:"server"` // Signature of the server AND client section, as signed by the private key of the server. Filled in when sending the message Client string `json:"client"` // Signature of the client section, as signed by the private key of the client. Filled in by the client sending the message } `json:"signatures"` }
Header represents a message header
type List ¶
type List struct { ID string `json:"id"` Dt string `json:"datetime"` Flags []string `json:"flags"` }
List is a message list
type RetryInfo ¶
type RetryInfo struct { RetryAt time.Time `json:"retry_at"` // Retry processing again on or after this time LastRetriedAt time.Time `json:"last_retried_at"` // Last time the message was processed/retried Retries int `json:"retries"` // Number of retries already done MsgID string `json:"message_id"` // Actual message ID (redundant since it's always inside the message directory) }
RetryInfo is a structure that holds information about when a message has been retried or when it needs to be retried
func GetRetryInfo ¶
GetRetryInfo will return information found in the message .retry.json file
func GetRetryInfoFromQueue ¶
GetRetryInfoFromQueue retrieves a list of retry infos as found in the retry queue
func NewRetryInfo ¶
NewRetryInfo returns a new retry info structure
type SignedByType ¶
type SignedByType string
SignedByType is a type that tells us how a message is signed
const ( // SignedByTypeOrigin signed by origin address / private key SignedByTypeOrigin SignedByType = "origin" // SignedByTypeAuthorized signed by an authorized private key (info stored in authorizedPublicKey) SignedByTypeAuthorized SignedByType = "authorized" // SignedByTypeServer signed by the server (postmaster) SignedByTypeServer SignedByType = "server" )