message

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
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

func GetPath(section Section, msgID, file string) (string, error)

GetPath will return the actual path based on the section, messageID and file inside the message

func IncomingPathExists

func IncomingPathExists(msgID, file string) bool

IncomingPathExists returns true when the upload path for the given message/file exists

func MoveMessage

func MoveMessage(srcSection Section, targetSection Section, msgID string) error

MoveMessage moves a message from a section to another section. Highly unoptimized.

func ProcessQueuePathExists

func ProcessQueuePathExists(msgID, file string) bool

ProcessQueuePathExists returns true when the processing path for the given message/file exists

func RemoveMessage

func RemoveMessage(section Section, msgID string) error

RemoveMessage removes a complete message (header, catalog, blocks etc)

func SignClientHeader

func SignClientHeader(header *Header, privKey bmcrypto.PrivKey) error

SignClientHeader will add a client signature to a message header. This can be used to proof the origin of the message

func SignServerHeader

func SignServerHeader(header *Header) error

SignServerHeader will add a server signature to a message header. This can be used to proof the origin of the message

func StoreAttachment

func StoreAttachment(msgID, attachmentID string, r io.Reader) error

StoreAttachment stores a message attachment to disk

func StoreBlock

func StoreBlock(msgID, blockID string, r io.Reader) error

StoreBlock stores a message block to disk

func StoreCatalog

func StoreCatalog(msgID string, r io.Reader) error

StoreCatalog stores a catalog to disk

func StoreHeader

func StoreHeader(msgID string, header *Header) error

StoreHeader stores a message header to disk

func StoreLocalMessage

func StoreLocalMessage(envelope *Envelope) (string, error)

StoreLocalMessage will store a message locally

func StoreRetryInfo

func StoreRetryInfo(section Section, msgID string, info RetryInfo) error

StoreRetryInfo saves the retry information back to disk

func VerifyClientHeader

func VerifyClientHeader(header Header) bool

VerifyClientHeader will verify a client signature from a message header. This can be used to proof the origin of the message

func VerifyServerHeader

func VerifyServerHeader(header Header) bool

VerifyServerHeader will verify a server signature from a message header. This can be used to proof the origin of the message

func ZlibCompress

func ZlibCompress(r io.Reader) io.Reader

ZlibCompress compresses a stream through zlib compression

func ZlibDecompress

func ZlibDecompress(r io.Reader) (io.Reader, error)

ZlibDecompress will return a reader that automatically decompresses the stream

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

func (a *Addressing) AddRecipient(addr *address.Address, h *hash.Hash, key *bmcrypto.PubKey)

AddRecipient will add recipient information to the addressing

func (*Addressing) AddSender

func (a *Addressing) AddSender(addr *address.Address, h *hash.Hash, name string, key bmcrypto.PrivKey, host string)

AddSender will add sender 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

func GenerateBlocks(b []string) ([]Block, error)

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) AddBlock

func (c *Catalog) AddBlock(entry Block) error

AddBlock adds a block to a catalog

func (*Catalog) AddFlags

func (c *Catalog) AddFlags(flags ...string)

AddFlags adds extra flags to the message

func (*Catalog) AddLabels

func (c *Catalog) AddLabels(labels ...string)

AddLabels adds extra labels to the message

func (*Catalog) GetBlock

func (c *Catalog) GetBlock(blockType string) (*BlockType, error)

GetBlock returns the specified block from the catalog

func (*Catalog) GetFirstBlock

func (c *Catalog) GetFirstBlock() *BlockType

GetFirstBlock returns the first block found in the message

func (*Catalog) HasBlock

func (c *Catalog) HasBlock(blockType string) bool

HasBlock returns true when the catalog has the given block type presents

func (*Catalog) SetToAddress

func (c *Catalog) SetToAddress(addr address.Address)

SetToAddress sets the address of the recipient

type ChecksumList

type ChecksumList map[string]string

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

func NewEnvelope() (*Envelope, error)

NewEnvelope creates a new (open) envelope which is used for holding a complete message

func (*Envelope) AddCatalog

func (e *Envelope) AddCatalog(cat *Catalog) error

AddCatalog will add a catalog to the envelope

func (*Envelope) AddHeader

func (e *Envelope) AddHeader(hdr *Header) error

AddHeader will add a header to the envelope

func (*Envelope) CloseAndEncrypt

func (e *Envelope) CloseAndEncrypt(senderPrivKey *bmcrypto.PrivKey, recipientPubKey *bmcrypto.PubKey) error

CloseAndEncrypt will close an envelope, and make sure all settings are set correctly for sending the message

type FileType

type FileType struct {
	ID   string
	Path string
}

FileType is a simple message-id => path combination

func GetFiles

func GetFiles(section Section, msgID string) ([]FileType, error)

GetFiles returns all blocks and attachments for the given message ID

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 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

func GetMessageHeader

func GetMessageHeader(section Section, msgID string) (*Header, error)

GetMessageHeader Returns a marshalled 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

func GetRetryInfo(section Section, msgID string) (*RetryInfo, error)

GetRetryInfo will return information found in the message .retry.json file

func GetRetryInfoFromQueue

func GetRetryInfoFromQueue() ([]RetryInfo, error)

GetRetryInfoFromQueue retrieves a list of retry infos as found in the retry queue

func NewRetryInfo

func NewRetryInfo(msgID string) *RetryInfo

NewRetryInfo returns a new retry info structure

type Section

type Section int

Section of the path we want to

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"
)

Jump to

Keyboard shortcuts

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