Skip to content

Commit a452388

Browse files
Auto-tag DMARC reports and scam emails as spam on ingest
upsertInbound now checks each new message against spam heuristics: - DMARC reports: from contains "dmarc" or subject starts with "Report domain:" - Scam emails: subject matches fake domain-renewal patterns (Avis de coupure, Non-paiement, Renouvellement de, Régulariser, suspension, facture impayée, etc.) Tagged messages get the "spam" tag via ensureTagRow + ensureTag, so they appear in the spam tag view and can be filtered/bulk-deleted. Retroactively tagged 45 of 58 existing admin@intrane.fr messages as spam. 13 legitimate emails remain untagged. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent c692326 commit a452388

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

sync.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,41 @@ func upsertInbound(p *Poche, mailboxID string, doc map[string]any) (created bool
231231
_ = json.Unmarshal(raw, &wrap)
232232
localID, _ := wrap["_id"].(string)
233233
_ = upsertAttachments(p, localID, doc)
234+
if localID != "" && isSpam(from, subj) {
235+
_ = ensureTagRow(p, "spam")
236+
_ = ensureTag(p, localID, "spam")
237+
}
234238
return true, nil
235239
}
236240

241+
// isSpam detects DMARC reports and fake domain-renewal scam emails.
242+
// DMARC: from address contains "dmarc" or subject starts with "Report domain:".
243+
// Spam: subject matches common scam patterns (fake renewal, fake invoice, etc.).
244+
func isSpam(from, subject string) bool {
245+
f := strings.ToLower(from)
246+
s := strings.ToLower(subject)
247+
if strings.Contains(f, "dmarc") || strings.HasPrefix(s, "report domain:") {
248+
return true
249+
}
250+
scamPatterns := []string{
251+
"avis de coupure",
252+
"non-paiement du renouvellement",
253+
"renouvellement de",
254+
"régulariser votre domaine",
255+
"risque de suspension",
256+
"suspension immédiate",
257+
"facture impayée",
258+
"interruption de service",
259+
"dernier rappel avant expiration",
260+
}
261+
for _, p := range scamPatterns {
262+
if strings.Contains(s, p) {
263+
return true
264+
}
265+
}
266+
return false
267+
}
268+
237269
func findByResendID(p *Poche, resendID string) (string, error) {
238270
data, err := p.List("messages", "resend_id="+resendID, 1, 0, "", false)
239271
if err != nil {

0 commit comments

Comments
 (0)