db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package db manages the queuing/persistance for the postmaster

Index

Constants

View Source
const (
	Sent int = 1 << iota
	Delivered
	SpamReported
	Bounced
	Dropped
	Opened
)

Variables

View Source
var (

	//MongoDisabledErr is returned when we need mongo but don't have it
	MongoDisabledErr = errors.New("mongo disabled")
)

Functions

func DisableOkq added in v0.4.0

func DisableOkq()

DisableOkq turns off using okq for job storing this should ONLY be called during testing

func GenerateEmailID

func GenerateEmailID(recipient string, flags int64, uid string, env string) string

GenerateEmailID generates a uniqueID and stores a record of an intended email this is used in okq.go and in tests

func MarkAsBounced

func MarkAsBounced(id string, reason string) error

func MarkAsDelivered

func MarkAsDelivered(id string) error

func MarkAsDropped

func MarkAsDropped(id string, reason string) error

func MarkAsOpened

func MarkAsOpened(id string) error

func MarkAsSpamReported

func MarkAsSpamReported(id string) error

func StoreEmailBounce

func StoreEmailBounce(email string) error

StoreEmailBounce stores a new time when the email bounced

func StoreEmailFlags

func StoreEmailFlags(email string, flags int64) error

StoreEmailFlags updates the email with new flags restrictions

func StoreEmailSpam

func StoreEmailSpam(email string) error

StoreEmailSpam stores a new time when the email was spammed

func StoreSendJob

func StoreSendJob(jobContents string) error

StoreSendJob creates a new Mail job with jobContents and sends it to okq

func StoreStatsJob

func StoreStatsJob(jobContents string) error

StoreStatsJob creates a new statsJob with jobContents and sends it to okq

func VerifyEmailAllowed

func VerifyEmailAllowed(email string, flags int64) bool

VerifyEmailAllowed verifies that we're allowed to send an email with flags to recipient

Types

type EmailDoc

type EmailDoc struct {
	Email       string      `bson:"_id"`
	UnsubFlags  int64       `bson:"f"`
	Bounces     []time.Time `bson:"b"` //also includes *some* drops
	SpamReports []time.Time `bson:"s"`
	TSUpdated   time.Time   `bson:"ts"`
}

EmailDoc represents a doc of the email's preferences, bounces, spams

type StatDoc

type StatDoc struct {
	// ID is a unique identifier for this doc not to be confused by the
	// user-supplied uniqueID field
	ID bson.ObjectId `json:"-" bson:"_id,omitempty"`

	// Recipient is the email address of the recipient
	Recipient string `json:"recipient" bson:"r"`

	// EmailFlags were the originally flags sent when sending the email
	EmailFlags int64 `json:"emailFlags" bson:"ef"`

	// StateFlags represent the current state of the email
	StateFlags int64 `json:"stateFlags" bson:"s"`

	// UniqueID was the original uniqueID sent to us in rpc.Enqueue
	UniqueID string `json:"uniqueID" bson:"uid"`

	// SentEnvironment was the original environment when sent
	SentEnvironment string `json:"sentEnv" bson:"se"`

	// TSCreated is the time that the email was sent
	TSCreated timeutil.Timestamp `json:"tsCreated" bson:"tc"`

	// TSUpdated is the last time this doc was updated
	TSUpdated timeutil.Timestamp `json:"tsUpdated" bson:"ts"`

	// Error is the reason for why the email errored
	Error string `json:"error" bson:"err,omitempty"`
}

A StatDoc represents an email that was sent

func GetLastUniqueID added in v0.2.0

func GetLastUniqueID(recipient, uid string) (*StatDoc, error)

GetLastUniqueID gets the last StatDoc for the given recipient and uniqueID

func GetStats

func GetStats(id string) (*StatDoc, error)

this is mostly for testing purposes

type StatsJob

type StatsJob struct {
	//Email address of the intended recipient
	Email string `json:"email" validate:"email,nonzero"`

	Timestamp timeutil.Timestamp `json:"timestamp,omitempty"`

	//Type is one of: bounce, deferred, delivered, dropped, processed
	Type string `json:"event" validate:"nonzero"`

	//json flag must match db.uniqueArgStatID in okq.go
	StatsID string `json:"pmStatsID" validate:"nonzero"`

	//json flag must match db.uniqueArgEnvID in okq.go
	SentEnvironment string `json:"pmEnvID" validate:"nonzero"`

	// this is the previous json key name before we changed it to pmStatusID
	OldStatsID string `json:"stats_id"`

	// Reason is miscellaneous data for why it bounced, dropped, etc
	Reason string `json:"reason,omitempty" validate:"max=1024"`
}

A StatsJob encompasses a okq job in response to a webhook event and is used to update the StatDoc for a specific email identified by StatsID

Jump to

Keyboard shortcuts

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