fix(mail): apply search limit and propagate body read error
- Cap search results to limit (keep most-recent UIDs) - Propagate io.ReadAll errors from body reads in fetchByUIDSet Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -83,7 +83,10 @@ func (c *Client) fetchByUIDSet(folder string, set *imap.SeqSet, full bool) ([]Me
|
|||||||
if r == nil {
|
if r == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
raw, _ := io.ReadAll(r)
|
raw, err := io.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("uid %d: read body: %w", m.Uid, err)
|
||||||
|
}
|
||||||
parsed, err := ParseMessage(m.Uid, raw)
|
parsed, err := ParseMessage(m.Uid, raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -187,6 +190,9 @@ func (c *Client) Search(folder string, sc SearchCriteria, limit int) ([]Header,
|
|||||||
if len(uids) == 0 {
|
if len(uids) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
if limit > 0 && len(uids) > limit {
|
||||||
|
uids = uids[len(uids)-limit:] // keep highest (most recent) UIDs
|
||||||
|
}
|
||||||
return c.FetchHeaders(folder, uids)
|
return c.FetchHeaders(folder, uids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user