imapflow icon indicating copy to clipboard operation
imapflow copied to clipboard

`fetch` with sequence string `1:*` seems to fail if mailbox is empty

Open Remscar opened this issue 7 months ago • 2 comments

When using .fetch like this:

const inboxMessages = client.fetch("1:*", {
      uid: true,
      source: true,
      envelope: true,
      bodyParts: ["text"],
      bodyStructure: true,
    });

It works just fine if the mailbox has messages in it, but if there are no messages then an error is thrown.

With logging enabled i see this:

{"level":20,"time":1720587672327,"pid":162128,"hostname":"ICEBOX","component":"imap-connection","cid":"ocwf3bbytwuujaqasmuw","src":"s","msg":"8 FETCH 1:* (UID BODYSTRUCTURE ENVELOPE BODY.PEEK[] MODSEQ BODY.PEEK[TEXT])","cid":"ocwf3bbytwuujaqasmuw"}
{"level":20,"time":1720587672331,"pid":162128,"hostname":"ICEBOX","component":"imap-connection","cid":"ocwf3bbytwuujaqasmuw","src":"s","msg":"8 BAD Error in IMAP command FETCH: Invalid messageset (0.001 + 0.000 secs).","cid":"ocwf3bbytwuujaqasmuw"}
{"level":40,"time":1720587672332,"pid":162128,"hostname":"ICEBOX","component":"imap-connection","cid":"ocwf3bbytwuujaqasmuw","err":{"type":"Error","message":"Command failed","stack":"Error: Command failed\n    at ImapFlow.reader (xxxxxxxxx\\node_modules\\imapflow\\lib\\imap-flow.js:571:35)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","response":{"tag":"8","command":"BAD","attributes":[{"type":"TEXT","value":"Error in IMAP command FETCH: Invalid messageset (0.001 + 0.000 secs)."}]},"responseStatus":"BAD","responseText":"Error in IMAP command FETCH: Invalid messageset (0.001 + 0.000 secs)."},"cid":"ocwf3bbytwuujaqasmuw","msg":"Command failed"}

8 BAD Error in IMAP command FETCH: Invalid messageset (0.001 + 0.000 secs). seems important.

I know i could use .status to see if there are any messages, but is there another way around this?

Remscar avatar Jul 10 '24 05:07 Remscar