common

package
v0.0.0-...-b8bfe6e Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMailboxNotAllowed is returned when a mailbox operation is not allowed
	ErrMailboxNotAllowed = errors.New("mailbox operation not allowed")
	// ErrNotAllowed is returned when an operation is not allowed
	ErrNotAllowed = errors.New("operation not allowed")
)

Functions

func ConvertToIMAPMessage

func ConvertToIMAPMessage(entity *message.Entity) *imap.Message

Helper function to convert message.Entity to imap.Message

func ExtractRecipients

func ExtractRecipients(headers *mail.Header) []string

ExtractRecipients extracts and cleans recipient addresses from To and Cc headers

func GenerateMessageID

func GenerateMessageID(domain string) string

generateMessageID generates a unique message ID

func IsSignatureValid

func IsSignatureValid(header *mail.Header, body []byte) bool

IsSignatureValid checks if the S/MIME signature of the message is valid. It writes the body to a temporary file and calls verifySMIMEWithOpenSSL.

func IsTransportEnvelope

func IsTransportEnvelope(msg *message.Entity) bool

IsTransportEnvelope checks if the message is a PEC transport envelope

func LoadSMIMECredentials

func LoadSMIMECredentials(certPath, keyPath string) (*x509.Certificate, interface{}, error)

func ParseEmailFromSession

func ParseEmailFromSession(s Session) (*mail.Header, []byte, error)

func ParseEmailMessage

func ParseEmailMessage(rawMessage []byte) (*mail.Reader, error)

ParseEmailMessage parses a raw email message and returns a *mail.Reader.

func StartIMAPWithSTARTTLS

func StartIMAPWithSTARTTLS(addr string, backend *IMAPBackend) error

Modify your existing StartIMAP function to clarify it uses STARTTLS

func StartIMAPWithTLS

func StartIMAPWithTLS(addr string, backend *IMAPBackend) error

Add this new function to support direct TLS connections

func StartSMTP

func StartSMTP(addr string, domain string, backend *Backend) error

StartSMTP starts the SMTP server with the given configuration

Types

type Backend

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

The Backend implements SMTP server methods.

func NewBackend

func NewBackend(signer *Signer, store pec_storage.MessageStore, handler func(*Session) error, domain string) *Backend

func (*Backend) NewSession

func (bkd *Backend) NewSession(c *smtp.Conn) (smtp.Session, error)

NewSession is called after client greeting (EHLO, HELO).

type Config

type Config struct {
	Domain     string `json:"domain"`
	SMTPServer string `json:"smtp_server"`
	IMAPServer string `json:"imap_server"`
	CertFile   string `json:"cert_file"`
	KeyFile    string `json:"key_file"`
	APIServer  string `json:"api_server"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

type IMAPBackend

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

IMAPBackend implements the IMAP server backend

func NewIMAPBackend

func NewIMAPBackend(store pec_storage.MessageStore, cert *x509.Certificate, key interface{}) *IMAPBackend

func (*IMAPBackend) Login

func (b *IMAPBackend) Login(connInfo *imap.ConnInfo, username, password string) (backend.User, error)

type IMAPMailbox

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

IMAPMailbox represents a mailbox (folder)

func (*IMAPMailbox) Check

func (m *IMAPMailbox) Check() error

func (*IMAPMailbox) CopyMessages

func (m *IMAPMailbox) CopyMessages(uid bool, seqSet *imap.SeqSet, destName string) error

func (*IMAPMailbox) CreateMessage

func (m *IMAPMailbox) CreateMessage(flags []string, date time.Time, body imap.Literal) error

func (*IMAPMailbox) Expunge

func (m *IMAPMailbox) Expunge() error

func (*IMAPMailbox) Info

func (m *IMAPMailbox) Info() (*imap.MailboxInfo, error)

func (*IMAPMailbox) ListMessages

func (m *IMAPMailbox) ListMessages(uid bool, seqSet *imap.SeqSet, items []imap.FetchItem, ch chan<- *imap.Message) error

func (*IMAPMailbox) ListenUpdates

func (m *IMAPMailbox) ListenUpdates() <-chan backend.Update

Implement ListenUpdates for IDLE support

func (*IMAPMailbox) Name

func (m *IMAPMailbox) Name() string

func (*IMAPMailbox) NotifyUpdate

func (m *IMAPMailbox) NotifyUpdate()

Add NotifyUpdate to trigger notifications

func (*IMAPMailbox) SearchMessages

func (m *IMAPMailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([]uint32, error)

func (*IMAPMailbox) SetSubscribed

func (m *IMAPMailbox) SetSubscribed(subscribed bool) error

func (*IMAPMailbox) Status

func (m *IMAPMailbox) Status(items []imap.StatusItem) (*imap.MailboxStatus, error)

func (*IMAPMailbox) StopListenUpdates

func (m *IMAPMailbox) StopListenUpdates(ch <-chan backend.Update)

Implement StopListeningUpdates to clean up

func (*IMAPMailbox) UpdateMessagesFlags

func (m *IMAPMailbox) UpdateMessagesFlags(uid bool, seqSet *imap.SeqSet, operation imap.FlagsOp, flags []string) error

type IMAPUser

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

IMAPUser represents an authenticated user

func (*IMAPUser) CreateMailbox

func (u *IMAPUser) CreateMailbox(name string) error

CreateMailbox creates a new mailbox

func (*IMAPUser) DeleteMailbox

func (u *IMAPUser) DeleteMailbox(name string) error

func (*IMAPUser) GetMailbox

func (u *IMAPUser) GetMailbox(name string) (backend.Mailbox, error)

func (*IMAPUser) ListMailboxes

func (u *IMAPUser) ListMailboxes(subscribed bool) ([]backend.Mailbox, error)

func (*IMAPUser) Logout

func (u *IMAPUser) Logout() error

func (*IMAPUser) RenameMailbox

func (u *IMAPUser) RenameMailbox(existingName, newName string) error

func (*IMAPUser) Username

func (u *IMAPUser) Username() string

type Session

type Session struct {
	From string
	To   []string

	Store pec_storage.MessageStore

	Domain string
	// contains filtered or unexported fields
}

A Session is returned after successful login.

func (*Session) Auth

func (s *Session) Auth(mech string) (sasl.Server, error)

Auth is the handler for supported authenticators.

func (*Session) AuthMechanisms

func (s *Session) AuthMechanisms() []string

AuthMechanisms returns a slice of available auth mechanisms; only PLAIN is supported in this example.

func (*Session) Data

func (s *Session) Data(r io.Reader) error

func (*Session) GetData

func (s *Session) GetData() ([]byte, error)

func (*Session) GetFrom

func (s *Session) GetFrom() (string, error)

func (*Session) GetHandler

func (s *Session) GetHandler() func(*Session) error

func (*Session) GetSigner

func (s *Session) GetSigner() *Signer

func (*Session) GetStore

func (s *Session) GetStore() pec_storage.MessageStore

func (*Session) GetTo

func (s *Session) GetTo() ([]string, error)

func (*Session) Logout

func (s *Session) Logout() error

func (*Session) Mail

func (s *Session) Mail(from string, opts *smtp.MailOptions) error

func (*Session) Rcpt

func (s *Session) Rcpt(to string, opts *smtp.RcptOptions) error

func (*Session) Reset

func (s *Session) Reset()

type Signer

type Signer struct {
	Cert   *x509.Certificate
	Key    interface{}
	Domain string
}

Use your existing Signer struct

func (*Signer) CreateSignedMimeMessage

func (s *Signer) CreateSignedMimeMessage(emailContent []byte) ([]byte, error)

Create a complete S/MIME signed email message from email bytes

func (*Signer) CreateSignedMimeMessageEntity

func (s *Signer) CreateSignedMimeMessageEntity(emailContent []byte) (*message.Entity, error)

func (*Signer) SignEmail

func (s *Signer) SignEmail(emailContent []byte) ([]byte, error)

S/MIME signing using go.mozilla.org/pkcs7

Jump to

Keyboard shortcuts

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