message

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package message contains set of tools to convert message between Proton API and IMAP format.

Index

Constants

View Source
const (
	BackgroundPriority = 1 << iota
	ForegroundPriority
)
View Source
const (
	AppleMailJunkFlag      = "$Junk"
	ThunderbirdJunkFlag    = "Junk"
	ThunderbirdNonJunkFlag = "NonJunk"
)

Various client specific flags.

Variables

View Source
var (
	ErrDecryptionFailed = errors.New("message could not be decrypted")
	ErrNoSuchKeyRing    = errors.New("the keyring to decrypt this message could not be found")
)

Functions

func AttachPublicKey

func AttachPublicKey(p *parser.Parser, key, keyName string)

func BuildEncrypted

func BuildEncrypted(m *pmapi.Message, readers []io.Reader, kr *crypto.KeyRing) ([]byte, error)

BuildEncrypted is used for importing encrypted message.

func BuildMIMEBody

func BuildMIMEBody(p *parser.Parser) (mimeBody string, err error)

BuildMIMEBody builds mime body from the parser returned by NewParser.

func EncryptRFC822

func EncryptRFC822(kr *crypto.KeyRing, r io.Reader) ([]byte, error)

func GetEnvelope

func GetEnvelope(msg *pmapi.Message, header textproto.MIMEHeader) *imap.Envelope

GetEnvelope will prepare envelope from pmapi message and cached header.

func GetFlags

func GetFlags(m *pmapi.Message) (flags []string)

GetFlags returns imap flags from pmapi message attributes.

func HeaderLines

func HeaderLines(header []byte) [][]byte

HeaderLines returns each line in the given header.

func Parse

func Parse(r io.Reader) (m *pmapi.Message, mimeBody, plainBody string, attReaders []io.Reader, err error)

Parse parses RAW message.

func ParserWithParser

func ParserWithParser(p *parser.Parser) (m *pmapi.Message, plainBody string, attReaders []io.Reader, err error)

ParserWithParser parses message from Parser without building MIME body.

func SanitizeMessageDate

func SanitizeMessageDate(msgTime int64) time.Time

SanitizeMessageDate will return time from msgTime timestamp. If timestamp is not after epoch the RFC822 publish day will be used. No message should realistically be older than RFC822 itself.

func WriteHeader

func WriteHeader(w io.Writer, h textproto.MIMEHeader) (err error)

Types

type Base64Sanitizer added in v0.4.0

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

func NewBase64Sanitizer added in v0.4.0

func NewBase64Sanitizer(r io.Reader) (*Base64Sanitizer, error)

func (*Base64Sanitizer) Read added in v0.4.0

func (c *Base64Sanitizer) Read(b []byte) (int, error)

type BodyStructure

type BodyStructure map[string]*SectionInfo

BodyStructure is used to parse an email into MIME sections and then generate body structure for IMAP server.

func DeserializeBodyStructure

func DeserializeBodyStructure(raw []byte) (*BodyStructure, error)

DeserializeBodyStructure will create new structure from msgpack bytes.

func NewBodyStructure

func NewBodyStructure(reader io.Reader) (structure *BodyStructure, err error)

func (*BodyStructure) GetMailHeader

func (bs *BodyStructure) GetMailHeader() (header textproto.MIMEHeader, err error)

GetMailHeader returns the main header of mail.

func (*BodyStructure) GetMailHeaderBytes

func (bs *BodyStructure) GetMailHeaderBytes() (header []byte, err error)

GetMailHeaderBytes returns the bytes with main mail header. Warning: It can contain extra lines.

func (*BodyStructure) GetSection

func (bs *BodyStructure) GetSection(wholeMail io.ReadSeeker, sectionPath []int) (section []byte, err error)

GetSection returns bytes of section including MIME header.

func (*BodyStructure) GetSectionContent

func (bs *BodyStructure) GetSectionContent(wholeMail io.ReadSeeker, sectionPath []int) (section []byte, err error)

GetSectionContent returns bytes of section content (excluding MIME header).

func (*BodyStructure) GetSectionHeader

func (bs *BodyStructure) GetSectionHeader(sectionPath []int) (textproto.MIMEHeader, error)

GetSectionHeader returns the mime header of specified section.

func (*BodyStructure) GetSectionHeaderBytes

func (bs *BodyStructure) GetSectionHeaderBytes(sectionPath []int) ([]byte, error)

GetSectionHeaderBytes returns raw header bytes of specified section.

func (*BodyStructure) IMAPBodyStructure

func (bs *BodyStructure) IMAPBodyStructure(currentPart []int) (imapBS *imap.BodyStructure, err error)

IMAPBodyStructure will prepare imap bodystructure recurently for given part. Use empty path to create whole email structure.

func (*BodyStructure) Parse

func (bs *BodyStructure) Parse(r io.Reader) error

Parse will read the mail and create all body structures.

func (*BodyStructure) Serialize

func (bs *BodyStructure) Serialize() ([]byte, error)

Serialize will write msgpack bytes.

type Builder

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

func NewBuilder

func NewBuilder(fetchWorkers, attachmentWorkers int) *Builder

NewBuilder creates a new builder which manages the given number of fetch/attach/build workers.

  • fetchWorkers: the number of workers which fetch messages from API
  • attachWorkers: the number of workers which fetch attachments from API.

The returned builder is ready to handle jobs -- see (*Builder).NewJob for more information.

Call (*Builder).Done to shut down the builder and stop all workers.

func (*Builder) Done

func (builder *Builder) Done()

func (*Builder) NewJob

func (builder *Builder) NewJob(ctx context.Context, fetcher Fetcher, messageID string, prio int) (*Job, pool.DoneFunc)

func (*Builder) NewJobWithOptions

func (builder *Builder) NewJobWithOptions(ctx context.Context, fetcher Fetcher, messageID string, opts JobOptions, prio int) (*Job, pool.DoneFunc)

type Fetcher

type Fetcher interface {
	GetMessage(context.Context, string) (*pmapi.Message, error)
	GetAttachment(context.Context, string) (io.ReadCloser, error)
	KeyRingForAddressID(string) (*crypto.KeyRing, error)
}

type Job

type Job struct {
	*pool.Job
	// contains filtered or unexported fields
}

func (*Job) GetResult

func (job *Job) GetResult() ([]byte, error)

type JobOptions

type JobOptions struct {
	IgnoreDecryptionErrors bool // Whether to ignore decryption errors and create a "custom message" instead.
	SanitizeDate           bool // Whether to replace all dates before 1970 with RFC822's birthdate.
	AddInternalID          bool // Whether to include MessageID as X-Pm-Internal-Id.
	AddExternalID          bool // Whether to include ExternalID as X-Pm-External-Id.
	AddMessageDate         bool // Whether to include message time as X-Pm-Date.
	AddMessageIDReference  bool // Whether to include the MessageID in References.
}

type QuotedPrintableSanitizer added in v0.4.0

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

func NewQuotedPrintableSanitizer added in v0.4.0

func NewQuotedPrintableSanitizer(r io.Reader) (*QuotedPrintableSanitizer, error)

func (*QuotedPrintableSanitizer) Read added in v0.4.0

func (c *QuotedPrintableSanitizer) Read(b []byte) (int, error)

type SectionInfo

type SectionInfo struct {
	Header                    []byte
	Start, BSize, Size, Lines int
	// contains filtered or unexported fields
}

SectionInfo is used to hold data about parts of each section.

func (*SectionInfo) GetMIMEHeader

func (si *SectionInfo) GetMIMEHeader() (textproto.MIMEHeader, error)

GetMIMEHeader parses bytes and return MIME header.

func (*SectionInfo) Read

func (si *SectionInfo) Read(p []byte) (n int, err error)

Read will also count the final size of section.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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