mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
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:
parent
96e3e5e33e
commit
6d38a1e9a4
1 changed files with 4 additions and 1 deletions
|
@ -306,11 +306,14 @@ func (mr *MaildirReader) Next() (*Message, *os.File, string, error) {
|
||||||
return nil, nil, p, fmt.Errorf("writing message: %v", err)
|
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
|
var received time.Time
|
||||||
t := strings.SplitN(filepath.Base(sf.Name()), ".", 2)
|
t := strings.SplitN(filepath.Base(sf.Name()), ".", 2)
|
||||||
if v, err := strconv.ParseInt(t[0], 10, 64); err == nil {
|
if v, err := strconv.ParseInt(t[0], 10, 64); err == nil {
|
||||||
received = time.Unix(v, 0)
|
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.
|
// Parse flags. See https://cr.yp.to/proto/maildir.html.
|
||||||
|
|
Loading…
Reference in a new issue