emailjs / emailjs-imap-client

Low-level JS IMAP client for all your IMAP needs.
MIT License
557 stars 123 forks source link

listMessages not working when messages are unread #154

Closed awb99 closed 7 years ago

awb99 commented 7 years ago

I am using listMessages to go through all message in my inbox. This worked when all messages were unread. Now I have had the code execute once and set all messages to read; now I occur bugs

async function page (pagesize, number) {
    var start = pagesize * (number-1) + 1;
    var end = start + pagesize -1;
    var range = `${start}:${end}`;
    //var range = '1:1';
    logger.info("Getting Messages " + range);

    var messages = [];
    try {
         await client.listMessages('INBOX', range , ['uid', 'flags', 'envelope','bodystructure', 'body[]']);
    } catch (err) {
        logger.error("Error getting Messages: " + err);
        return messages;
    }
}

Now I have mostly unread messages, and here comes the error:

[2017-10-10 00:17:49.741] [INFO] messageImport - Getting Messages 1:10
[DEBUG][2017-10-09T22:17:49.746Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Fetching messages 1:10 from INBOX ...
[DEBUG][2017-10-09T22:17:49.748Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Opening INBOX ...
[DEBUG][2017-10-09T22:17:49.749Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] C: W4.p SELECT "INBOX"
[DEBUG][2017-10-09T22:17:49.790Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
[DEBUG][2017-10-09T22:17:49.791Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft "\\*")] Flags permitted.
[DEBUG][2017-10-09T22:17:49.791Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * 9903 EXISTS
[DEBUG][2017-10-09T22:17:49.792Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * 0 RECENT
[DEBUG][2017-10-09T22:17:49.792Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * OK [UNSEEN 9902] First unseen.
[DEBUG][2017-10-09T22:17:49.792Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * OK [UIDVALIDITY 1459521503] UIDs valid
[DEBUG][2017-10-09T22:17:49.792Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * OK [UIDNEXT 9919] Predicted next UID
[DEBUG][2017-10-09T22:17:49.793Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * OK [HIGHESTMODSEQ 11159] Highest
[DEBUG][2017-10-09T22:17:49.793Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: W4.p OK [READ-WRITE] Select completed (0.000 + 0.000 secs).
[DEBUG][2017-10-09T22:17:49.793Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] C: W3 UID FETCH 1:10 (UID FLAGS ENVELOPE BODYSTRUCTURE BODY[])
[DEBUG][2017-10-09T22:17:49.794Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Entering state: 4
[DEBUG][2017-10-09T22:17:49.830Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: W3 OK Fetch completed (0.001 + 0.000 secs).
[2017-10-10 00:17:49.832] [INFO] messageImport - Received 0 emails in page 1.
[DEBUG][2017-10-09T22:17:49.833Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Entering state: 5
[DEBUG][2017-10-09T22:17:49.834Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Logging out...
[DEBUG][2017-10-09T22:17:49.834Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] C: W5 LOGOUT
[DEBUG][2017-10-09T22:17:49.874Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: * BYE Logging out
[DEBUG][2017-10-09T22:17:49.874Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: W5 OK Logout completed (0.000 + 0.000 secs).

The Messages 1-10 that I try to read, they are all read, and it appears that listMessages first searches for ALL messages (FLAGS (\Answered \Flagged \Deleted \Seen \Draft)); and then it does not return any.

If I want to list all messages, then this messages should either show up completely in the query; or message 1-10 should return the first 10 unread messages.

I believe that I have found out a bug.

awb99 commented 7 years ago

I should add, that after all pages are parsed, not one email is received. Even though there are unseen emails in the mailbox. This is the last page that I got; and I believe that this emails should be unseen (I have verified that there are unseen emails via webmail)

´´´ [2017-10-10 13:37:29.035] [INFO] messageImport - Getting Messages 9931:9940 [DEBUG][2017-10-10T11:37:29.035Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Fetching messages 9931:9940 from INBOX ... [DEBUG][2017-10-10T11:37:29.036Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] Idle terminated [DEBUG][2017-10-10T11:37:29.070Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: W6 OK Idle completed (0.001 + 4.011 + 4.011 secs). [DEBUG][2017-10-10T11:37:29.070Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] C: W7 UID FETCH 9931:9940 (UID FLAGS ENVELOPE BODYSTRUCTURE BODY[]) [DEBUG][2017-10-10T11:37:29.164Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9916 FETCH (UID 9931 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 23B string )" (("Zitytrip Apartements" NIL "info" "zitytrip.com")) (("Zitytrip Apartements" NIL "info" "zitytrip.com")) ((NIL NIL "info" "zitytrip.com")) ((NIL NIL "xchen.123549" "guest.booking.com")) NIL NIL NIL "( 51B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "quoted-printable" 1344 65 NIL NIL NIL NIL) ("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 2842 110 NIL NIL NIL NIL) "alternative" ("boundary" "( 49B string )") NIL NIL NIL) BODY[] "( 6178B literal )") [DEBUG][2017-10-10T11:37:29.171Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9917 FETCH (UID 9932 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 23B string )" (("Zitytrip Apartements" NIL "info" "zitytrip.com")) (("Zitytrip Apartements" NIL "info" "zitytrip.com")) ((NIL NIL "info" "zitytrip.com")) ((NIL NIL "ovodol.286999" "guest.booking.com")) NIL NIL NIL "( 51B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "quoted-printable" 1344 65 NIL NIL NIL NIL) ("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 2842 110 NIL NIL NIL NIL) "alternative" ("boundary" "( 49B string )") NIL NIL NIL) BODY[] "( 6179B literal )") [DEBUG][2017-10-10T11:37:29.201Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9918 FETCH (UID 9933 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 32B string )" (("( 48B string )" NIL "tomamanka96" "mail.ru")) (("( 48B string )" NIL "tomamanka96" "mail.ru")) (("( 48B string )" NIL "tomamanka96" "mail.ru")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 37B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "base64" 772 10 NIL NIL NIL NIL) ("text" "html" ("charset" "utf-8") NIL NIL "base64" 838 11 NIL NIL NIL NIL) "alternative" ("boundary" "( 49B string )") NIL NIL NIL) BODY[] "( 5332B literal )") [DEBUG][2017-10-10T11:37:29.236Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9919 FETCH (UID 9934 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 27B string )" (("michael raouf" NIL "michael_raouf373" "hotmail.com")) (("michael raouf" NIL "michael_raouf373" "hotmail.com")) (("michael raouf" NIL "michael_raouf373" "hotmail.com")) (("Reinhard Schaden" NIL "info" "zitytrip.com")) NIL NIL "( 68B string )" "( 80B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "base64" 1688 22 NIL NIL NIL NIL) ("text" "html" ("charset" "utf-8") "( 60B string )" NIL "base64" 5654 73 NIL NIL NIL NIL) "alternative" ("boundary" "( 61B string )") NIL ("en-US") NIL) BODY[] "( 15202B literal )") [DEBUG][2017-10-10T11:37:29.247Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9920 FETCH (UID 9935 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 40B string )" (("Manhart Filomena" NIL "F.Manhart" "eder-gmbh.de")) (("Manhart Filomena" NIL "F.Manhart" "eder-gmbh.de")) (("Manhart Filomena" NIL "F.Manhart" "eder-gmbh.de")) (("info@zitytrip.com" NIL "info" "zitytrip.com")) NIL NIL NIL "( 67B string )") BODYSTRUCTURE ((("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 1870 45 NIL NIL NIL NIL) ("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 6370 138 NIL NIL NIL NIL) "alternative" ("boundary" "( 61B string )") NIL NIL NIL) ("image" "jpeg" ("name" "image001.jpg") "( 32B string )" "image001.jpg" "base64" 8212 NIL ("inline" ("filename" "image001.jpg" "size" "6000" "creation-date" "( 29B string )" "modification-date" "( 29B string )")) NIL NIL) "related" ("boundary" "( 61B string )" "type" "( 21B string )") NIL ("de-DE") NIL) BODY[] "( 19594B literal )") [DEBUG][2017-10-10T11:37:29.409Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9921 FETCH (UID 9936 FLAGS (\Seen) ENVELOPE ("( 37B string )" "( 39B string )" (("Booking.com" NIL "no-reply" "booking.com")) (("Booking.com" NIL "no-reply" "booking.com")) ((NIL NIL "no-reply" "booking.com")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 69B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "quoted-printable" 2140 42 NIL NIL NIL NIL) ("text" "html" ("charset" "utf-8") NIL NIL "quoted-printable" 56965 1108 NIL NIL NIL NIL) "alternative" ("boundary" "( 42B string )") NIL NIL NIL) BODY[] "( 63044B literal )") [DEBUG][2017-10-10T11:37:29.411Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9922 FETCH (UID 9937 FLAGS (\Seen) ENVELOPE ("( 38B string )" "( 51B string )" (("( 28B string )" NIL "customer.service" "booking.com")) (("( 28B string )" NIL "customer.service" "booking.com")) ((NIL NIL "2037477093" "my.booking.com")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 66B string )") BODYSTRUCTURE (((("text" "plain" ("charset" "utf-8") NIL NIL "quoted-printable" 1098 35 NIL ("inline" NIL) NIL NIL) "related" ("boundary" "( 30B string )") NIL NIL NIL) "alternative" ("boundary" "( 30B string )") NIL NIL NIL) "mixed" ("boundary" "( 30B string )") NIL NIL NIL) BODY[] "( 5744B literal )") [DEBUG][2017-10-10T11:37:29.743Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9923 FETCH (UID 9938 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 105B literal )" (("( 64B string )" NIL "noreply" "booking.com")) (("( 64B string )" NIL "noreply" "booking.com")) ((NIL NIL "( 62B string )" "mchat.booking.com")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 51B string )") BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "base64" 3072 40 NIL NIL NIL NIL) (("text" "html" ("charset" "utf-8") NIL NIL "base64" 23630 303 NIL NIL NIL NIL) ("image" "png" NIL "( 86B string )" NIL "base64" 572 NIL NIL NIL NIL) ("image" "png" NIL "( 86B string )" NIL "base64" 21356 NIL NIL NIL NIL) ("image" "png" NIL "( 86B string )" NIL "base64" 93376 NIL NIL NIL NIL) ("image" "png" NIL "( 86B string )" NIL "base64" 9500 NIL NIL NIL NIL) ("image" "png" NIL "( 86B string )" NIL "base64" 12424 NIL NIL NIL NIL) "related" ("boundary" "( 31B string )") NIL NIL NIL) "alternative" ("boundary" "( 31B string )") NIL NIL NIL) BODY[] "( 168776B literal )") [DEBUG][2017-10-10T11:37:29.752Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9924 FETCH (UID 9939 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 117B literal )" (("( 49B string )" NIL "smatsu.144223" "guest.booking.com")) (("( 49B string )" NIL "smatsu.144223" "guest.booking.com")) (("( 49B string )" NIL "smatsu.144223" "guest.booking.com")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 53B string )") BODYSTRUCTURE ((("text" "html" ("charset" "utf-8") NIL NIL "base64" 16692 214 NIL ("inline" NIL) NIL NIL) "alternative" ("boundary" "( 30B string )") NIL NIL NIL) "mixed" ("boundary" "( 30B string )" "charset" "utf-8") NIL NIL NIL) BODY[] "( 21189B literal )") [DEBUG][2017-10-10T11:37:29.784Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: 9925 FETCH (UID 9940 FLAGS (\Seen) ENVELOPE ("( 31B string )" "( 125B literal )" (("( 46B string )" NIL "dminae.285457" "guest.booking.com")) (("( 46B string )" NIL "dminae.285457" "guest.booking.com")) (("( 46B string )" NIL "dminae.285457" "guest.booking.com")) ((NIL NIL "info" "zitytrip.com")) NIL NIL NIL "( 52B string )") BODYSTRUCTURE ((("text" "html" ("charset" "utf-8") NIL NIL "base64" 17174 221 NIL ("inline" NIL) NIL NIL) "alternative" ("boundary" "( 29B string )") NIL NIL NIL) "mixed" ("boundary" "( 29B string )" "charset" "utf-8") NIL NIL NIL) BODY[] "( 21450B literal )") [DEBUG][2017-10-10T11:37:29.784Z][1][wp1180003-zitytrip][wp1180003.mail.server-he.de] S: W7 OK Fetch completed (0.080 + 0.424 secs). [2017-10-10 13:37:29.792] [INFO] messageImport - Received 0 emails in page 994. ´´´

awb99 commented 7 years ago

This was my error. Solved.