Documentation ¶
Overview ¶
Package db manages the queuing/persistance for the postmaster
Index ¶
- Constants
- Variables
- func DisableOkq()
- func GenerateEmailID(recipient string, flags int64, uid string, env string) string
- func MarkAsBounced(id string, reason string) error
- func MarkAsDelivered(id string) error
- func MarkAsDropped(id string, reason string) error
- func MarkAsOpened(id string) error
- func MarkAsSpamReported(id string) error
- func StoreEmailBounce(email string) error
- func StoreEmailFlags(email string, flags int64) error
- func StoreEmailSpam(email string) error
- func StoreSendJob(jobContents string) error
- func StoreStatsJob(jobContents string) error
- func VerifyEmailAllowed(email string, flags int64) bool
- type EmailDoc
- type StatDoc
- type StatsJob
Constants ¶
const ( Sent int = 1 << iota Delivered SpamReported Bounced Dropped Opened )
Variables ¶
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 ¶
GenerateEmailID generates a uniqueID and stores a record of an intended email this is used in okq.go and in tests
func MarkAsBounced ¶
func MarkAsDelivered ¶
func MarkAsDropped ¶
func MarkAsOpened ¶
func MarkAsSpamReported ¶
func StoreEmailBounce ¶
StoreEmailBounce stores a new time when the email bounced
func StoreEmailFlags ¶
StoreEmailFlags updates the email with new flags restrictions
func StoreEmailSpam ¶
StoreEmailSpam stores a new time when the email was spammed
func StoreSendJob ¶
StoreSendJob creates a new Mail job with jobContents and sends it to okq
func StoreStatsJob ¶
StoreStatsJob creates a new statsJob with jobContents and sends it to okq
func VerifyEmailAllowed ¶
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
GetLastUniqueID gets the last StatDoc for the given recipient and uniqueID
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