fix(mailparser): Deutsche Wochentagsabkürzungen im Date-Header parsen
PMG mit German-Locale erzeugt "So, 24 Aug 2025 00:05:17 +0200" statt "Sun, ..." — Go's net/mail und alle bisherigen Fallbacks scheitern daran. Fix: Wochentag-Präfix (≤3 Zeichen vor dem ersten Komma) abschneiden und erneut mit den numerischen Offset-Formaten parsen. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -136,6 +136,30 @@ func Parse(raw []byte) (*ParsedMail, error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !parsed {
|
||||||
|
// Some MTAs (e.g. PMG with German locale) use localised weekday names:
|
||||||
|
// "So, 24 Aug 2025 00:05:17 +0200" instead of "Sun, 24 Aug 2025...".
|
||||||
|
// Strip the "Weekday, " prefix (≤3 chars before the first comma) and retry.
|
||||||
|
if commaIdx := strings.Index(raw, ","); commaIdx > 0 && commaIdx <= 3 {
|
||||||
|
noWeekday := strings.TrimSpace(raw[commaIdx+1:])
|
||||||
|
for _, layout := range []string{
|
||||||
|
"2 Jan 2006 15:04:05 -0700",
|
||||||
|
"02 Jan 2006 15:04:05 -0700",
|
||||||
|
"2 Jan 2006 15:04:05 -07:00",
|
||||||
|
"02 Jan 2006 15:04:05 -07:00",
|
||||||
|
"2 Jan 2006 15:04:05 MST",
|
||||||
|
"02 Jan 2006 15:04:05 MST",
|
||||||
|
"2 Jan 2006 15:04 -0700",
|
||||||
|
"02 Jan 2006 15:04 -0700",
|
||||||
|
} {
|
||||||
|
if t, err := time.Parse(layout, noWeekday); err == nil {
|
||||||
|
pm.Date = t
|
||||||
|
parsed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if !parsed {
|
if !parsed {
|
||||||
// Leave pm.Date as zero — storage will use DB DEFAULT NOW()
|
// Leave pm.Date as zero — storage will use DB DEFAULT NOW()
|
||||||
pm.Date = time.Time{}
|
pm.Date = time.Time{}
|
||||||
|
|||||||
Reference in New Issue
Block a user