Files
zeekayandHanzo Dev 15909c7b79 Rename Go module path to github.com/hanzoai/mail
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).

Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.

Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.

The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 23:16:19 -07:00

71 lines
2.1 KiB
Go

package smtpserver
import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"io"
"log/slog"
"os"
"github.com/mjl-/bstore"
"github.com/hanzoai/mail/message"
"github.com/hanzoai/mail/mlog"
"github.com/hanzoai/mail/moxio"
"github.com/hanzoai/mail/store"
)
// rejectPresent returns whether the message is already present in the rejects mailbox.
func rejectPresent(log mlog.Log, acc *store.Account, rejectsMailbox string, m *store.Message, f *os.File) (present bool, msgID string, hash []byte, rerr error) {
if p, err := message.Parse(log.Logger, false, store.FileMsgReader(m.MsgPrefix, f)); err != nil {
log.Infox("parsing reject message for message-id", err)
} else if header, err := p.Header(); err != nil {
log.Infox("parsing reject message header for message-id", err)
} else {
msgID, _, err = message.MessageIDCanonical(header.Get("Message-Id"))
if err != nil {
log.Debugx("parsing message-id for reject", err, slog.String("messageid", header.Get("Message-Id")))
}
}
// We must not read MsgPrefix, it will likely change for subsequent deliveries.
h := sha256.New()
if _, err := io.Copy(h, &moxio.AtReader{R: f}); err != nil {
log.Infox("copying reject message to hash", err)
} else {
hash = h.Sum(nil)
}
if msgID == "" && len(hash) == 0 {
return false, "", nil, fmt.Errorf("no message-id or hash for determining reject message presence")
}
var exists bool
var err error
acc.WithRLock(func() {
err = acc.DB.Read(context.TODO(), func(tx *bstore.Tx) error {
mb, err := acc.MailboxFind(tx, rejectsMailbox)
if err != nil {
return fmt.Errorf("looking for rejects mailbox: %w", err)
} else if mb == nil {
return nil
}
q := bstore.QueryTx[store.Message](tx)
q.FilterNonzero(store.Message{MailboxID: mb.ID})
q.FilterEqual("Expunged", false)
q.FilterFn(func(m store.Message) bool {
return msgID != "" && m.MessageID == msgID || len(hash) > 0 && bytes.Equal(m.MessageHash, hash)
})
exists, err = q.Exists()
return err
})
})
if err != nil {
return false, "", nil, fmt.Errorf("querying for presence of reject message: %w", err)
}
return exists, msgID, hash, nil
}