package mailstore

import "mailgoserver/internal/db"

// ResolveRecipient looks up a local mailbox for addr — its primary email first, then
// any active alias — so mail sent to an alias lands in the owning mailbox's INBOX.
func (s *Store) ResolveRecipient(addr string) (*db.Mailbox, error) {
	mbox, err := s.DB.GetMailboxByEmail(addr)
	if err != nil || mbox != nil {
		return mbox, err
	}
	alias, err := s.DB.GetAliasByEmail(addr)
	if err != nil || alias == nil {
		return nil, err
	}
	return s.DB.GetMailboxByID(alias.MailboxID)
}
