Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/internal/model/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"ivpn.net/email/api/internal/utils"
)

var (
ErrExtractOriginalFrom = fmt.Errorf("error extracting original From from bounce")
)

type Msg struct {
From string
FromName string
Expand Down Expand Up @@ -69,7 +73,8 @@ func ParseMsg(data []byte) (Msg, error) {
msgType = FailBounce
fromAddress, err = ExtractOriginalFrom(processedData)
if err != nil {
return Msg{}, fmt.Errorf("extract original from bounce: %w", err)
log.Println("error extracting original From from bounce:", err)
return Msg{}, ErrExtractOriginalFrom
}
}

Expand Down
8 changes: 4 additions & 4 deletions api/internal/service/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
var (
ErrGetAlias = errors.New("Unable to retrieve alias by ID.")
ErrGetAliases = errors.New("Unable to retrieve aliases.")
ErrGetAliasByName = errors.New("Unable to retrieve alias by name.")
ErrGetAliasByName = errors.New("alias not found:")
ErrDisabledAlias = errors.New("alias disabled:")
ErrPostAlias = errors.New("Unable to create alias. Please try again.")
ErrPostAliasLimit = errors.New("You’ve reached the maximum number of allowed aliases.")
ErrUpdateAlias = errors.New("Unable to update alias. Please try again.")
Expand Down Expand Up @@ -81,8 +82,7 @@ func (s *Service) GetAllAliases(ctx context.Context, userID string) ([]model.Ali
func (s *Service) GetAliasByName(name string) (model.Alias, error) {
alias, err := s.Store.GetAliasByName(name)
if err != nil {
log.Printf("error fetching alias %s: %s", name, err.Error())
return model.Alias{}, ErrGetAliasByName
return model.Alias{Name: name}, ErrGetAliasByName
}

return alias, nil
Expand Down Expand Up @@ -193,7 +193,7 @@ func (s *Service) FindAlias(email string) (model.Alias, error) {
name, _ := model.ParseReplyTo(email)
alias, err := s.GetAliasByName(name)
if err != nil {
return model.Alias{}, err
return model.Alias{Name: name}, err
}

return alias, nil
Expand Down
19 changes: 12 additions & 7 deletions api/internal/service/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

var (
ErrInactiveSubscription = errors.New("Subscription is inactive.")
ErrDisabledAlias = errors.New("This alias is disabled.")
ErrNoRecipients = errors.New("No recipients found.")
ErrNoVerifiedRecipients = errors.New("Sender is not a verified address.")
ErrInactiveRecipient = errors.New("The recipient is inactive.")
Expand All @@ -22,24 +21,30 @@ var (
func (s *Service) ProcessMessage(data []byte) error {
msg, err := model.ParseMsg(data)
if err != nil {
log.Println("error parsing message", err)
if errors.Is(err, model.ErrExtractOriginalFrom) {
// Fail silently so bounce messages are not kept in postfix queue
return nil
}

log.Println("error parsing message:", err)
return err
}

// Bounce
if msg.Type == model.FailBounce {
alias, err := s.FindAlias(msg.From)
if err != nil {
log.Println("error processing bounce", err)
return err
log.Println("error processing bounce:", err, alias.Name)
// Fail silently so bounce messages are not kept in postfix queue
return nil
}

err = s.ProcessBounceLog(alias.UserID, alias.ID, data, msg)
if err != nil {
log.Println("error processing bounce", err)
return err
log.Println("error processing bounce:", err, alias.Name)
}

// Fail silently so bounce messages are not kept in postfix queue
return nil
}

Expand All @@ -58,7 +63,7 @@ func (s *Service) ProcessMessage(data []byte) error {
for _, to := range msg.To {
recipients, alias, relayType, err := s.FindRecipients(msg.From, to, msg.Type)
if err != nil {
log.Println("error processing message", err)
log.Println("error processing message:", err, alias.Name)

// Handle ErrNoVerifiedRecipients
if errors.Is(err, ErrNoVerifiedRecipients) {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/service/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (s *Service) FindRecipients(from string, to string, msgType model.MessageTy
name, replyTo := model.ParseReplyTo(to)
alias, err := s.GetAliasByName(name)
if err != nil {
return []model.Recipient{}, model.Alias{}, 0, err
return []model.Recipient{}, model.Alias{Name: name}, 0, err
}

// Handle disabled alias
Expand Down
Loading