when reading maildirs for imports, use the file mtime as fallback for "received" time

more useful than the time.Time zero file in case the maildir filename isn't
properly formed with a timestamp. this is not too uncommon when people
reconstruct maildirs from other sources of message files to then import the
maildir.

based on message from abdul h
This commit is contained in:
Mechiel Lukkien 2024-04-02 19:43:45 +02:00
parent 96e3e5e33e
commit 6d38a1e9a4
No known key found for this signature in database

View file

@ -306,11 +306,14 @@ func (mr *MaildirReader) Next() (*Message, *os.File, string, error) {
return nil, nil, p, fmt.Errorf("writing message: %v", err)
}
// Take received time from filename.
// Take received time from filename, falling back to mtime for maildirs
// reconstructed some other sources of message files.
var received time.Time
t := strings.SplitN(filepath.Base(sf.Name()), ".", 2)
if v, err := strconv.ParseInt(t[0], 10, 64); err == nil {
received = time.Unix(v, 0)
} else if fi, err := sf.Stat(); err == nil {
received = fi.ModTime()
}
// Parse flags. See https://cr.yp.to/proto/maildir.html.