diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-05-11 00:10:38 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-05-16 11:12:11 +0200 |
commit | cd68adc4630ed834eeac33f09ef58891c18c2dee (patch) | |
tree | 29576448a388af981538147f835badc317cd32c1 /worker/maildir | |
parent | 6e038c7fd510563efc35780e293e25e34ffe3077 (diff) | |
download | aerc-cd68adc4630ed834eeac33f09ef58891c18c2dee.tar.gz |
maildir: fix sorting by size
Retrieve message size not only in the MessageInfo but also in the
MessageHeaders function. The MessageHeaders function is used for an
memory-optimized maildir sorting. This fixes sorting by size in the
maildir backend.
Fixes: f04d83e8 ("messageinfo: report message sizes")
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/maildir')
-rw-r--r-- | worker/maildir/message.go | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/worker/maildir/message.go b/worker/maildir/message.go index 0b653fa6..778673a2 100644 --- a/worker/maildir/message.go +++ b/worker/maildir/message.go @@ -78,21 +78,39 @@ func (m Message) MessageInfo() (*models.MessageInfo, error) { if err != nil { return nil, err } - // if size retrieval fails, just return info and log error - if name, err := m.dir.Filename(m.key); err != nil { - log.Errorf("failed to obtain filename: %v", err) - } else { - if info.Size, err = lib.FileSize(name); err != nil { - log.Errorf("failed to obtain file size: %v", err) - } + info.Size, err = m.Size() + if err != nil { + // don't care if size retrieval fails + log.Debugf("message size: %v", err) } return info, nil } +func (m Message) Size() (uint32, error) { + name, err := m.dir.Filename(m.key) + if err != nil { + return 0, fmt.Errorf("failed to get filename: %w", err) + } + size, err := lib.FileSize(name) + if err != nil { + return 0, fmt.Errorf("failed to get filesize: %w", err) + } + return size, nil +} + // MessageHeaders populates a models.MessageInfo struct for the message with // minimal information, used for sorting and threading. func (m Message) MessageHeaders() (*models.MessageInfo, error) { - return lib.MessageHeaders(m) + info, err := lib.MessageHeaders(m) + if err != nil { + return nil, err + } + info.Size, err = m.Size() + if err != nil { + // don't care if size retrieval fails + log.Debugf("message size failed: %v", err) + } + return info, nil } // NewBodyPartReader creates a new io.Reader for the requested body part(s) of |