Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The IMAP server replied to the 'FETCH' command with a 'BAD' response: Error in IMAP command FETCH: Invalid messageset (0.000 + 0.041 + 0.040 secs). #572

Closed
DanieleD74 opened this issue Oct 19, 2017 · 6 comments
Labels
compatibility Compatibility with existing software

Comments

@DanieleD74
Copy link

To help me debug your issue, please explain:

  • What were you trying to do?
  • What happened?
  • What did you expect to happen?
  • Step-by-step reproduction instructions and/or a simple test case.

If you got an exception, please include the exception Message and StackTrace.

Please also INCLUDE A PROTOCOL LOG (scrubbed of any authentication data), especially
if you got an exception such as Syntax error in XYZ. Unexpected token: ....
If you do not include the protocol log, you will make me VERY UNHAPPY.

Without a protocol log, I CANNOT fix the issue. I will simply close the bug report.

To get a protocol log, follow one of the following code snippets:

// log to a file called 'imap.log'
var client = new ImapClient (new ProtocolLogger ("imap.log"));
// log to a file called 'pop3.log'
var client = new Pop3Client (new ProtocolLogger ("pop3.log"));
// log to a file called 'smtp.log'
var client = new SmtpClient (new ProtocolLogger ("smtp.log"));

Note: if the protocol log contains sensitive information, feel free to email it to me at
jestedfa@microsoft.com instead of including it in the GitHub issue.

@DanieleD74 DanieleD74 changed the title Hi The IMAP server replied to the 'FETCH' command with a 'BAD' response: Error in IMAP command FETCH: Invalid messageset (0.000 + 0.041 + 0.040 secs). Oct 19, 2017
@DanieleD74
Copy link
Author

DanieleD74 commented Oct 19, 2017

Hello
First of all congratulations, good bookshop.
I'm using mimekit for the first time to develop an IMAP client and I'm having trouble with this call
infoMessage = cltIMAP.Inbox.Fetch ({iUId}, MessageSummaryItems.All)
I always get the error in the subject

Below is the log I have cleared the mail data as it is that of a customer
Connected to imap://imap.istruzione.it:143/?starttls=when-available
S: * OK [CAPABILITY IMAP4 IMAP4REV1 STARTTLS] perdition ready on mvlsmtp003.sidi.mpi.it 0002ed12
C: A00000000 STARTTLS
S: A00000000 OK Begin TLS negotiation now
C: A00000001 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4REV1
S: A00000001 OK CAPABILITY
C: A00000002 LOGIN bla bla bla
S: * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE NOTIFY SPECIAL-USE QUOTA
S: A00000002 OK bla bla bla
C: A00000003 NAMESPACE
S: * NAMESPACE (("INBOX." ".")) NIL NIL
S: A00000003 OK Namespace completed (0.000 + 0.041 + 0.040 secs).
C: A00000004 LIST "" "INBOX"
S: * LIST (\HasChildren) "." INBOX
S: A00000004 OK List completed (0.000 + 0.040 + 0.039 secs).
C: A00000005 LIST (SPECIAL-USE) "" "*"
S: * LIST (\UnMarked \Sent) "." INBOX.Sent
S: * LIST (\UnMarked \Trash) "." INBOX.Trash
S: * LIST (\UnMarked \Drafts) "." INBOX.Drafts
S: * LIST (\Marked \Junk) "." INBOX.Spam
S: A00000005 OK List completed (0.000 + 0.041 + 0.040 secs).
C: A00000006 EXAMINE INBOX (CONDSTORE)
S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
S: * OK [PERMANENTFLAGS ()] Read-only mailbox.
S: * 340 EXISTS
S: * 0 RECENT
S: * OK [UIDVALIDITY 1283844956] UIDs valid
S: * OK [UIDNEXT 79402] Predicted next UID
S: * OK [HIGHESTMODSEQ 31742] Highest
S: A00000006 OK [READ-ONLY] Examine completed (0.000 + 0.040 + 0.039 secs).
C: A00000007 UID SEARCH RETURN () ALL
S: * ESEARCH (TAG "A00000007") UID ALL 78269,78272,78278,78282:78283,78288,78292,78295,78305,78307:78308,78315,78329:78332,78350:78351,78354:78355,78359:78361,78367:78368,78373:78377,78380,78383,78389:78391,78393,78395,78397:78398,78403,78407,78409,78415,78422,78435,78438:78439,78442,78448,78456,78459,78463:78464,78476,78479,78507,78510,78516:78518,78530:78531,78533:78537,78540:78541,78544:78547,78555:78556,78558,78560:78561,78565:78566,78571,78575,78578,78584,78588,78592,78594:78595,78600:78601,78603,78608,78610:78611,78615,78634,78636,78642,78649,78654,78661:78662,78667,78670:78673,78677,78686:78690,78692,78703,78710,78717,78727,78732:78736,78738,78742:78743,78745,78747,78749:78750,78756:78757,78759:78761,78763,78769,78771,78777:78779,78781,78784,78788,78792:78793,78798,78802:78803,78807,78815,78826,78831,78842,78849:78850,78852,78858:78860,78868,78870:78872,78874:78875,78878,78882,78886,78888,78890:78892,78900,78903,78910,78912,78916:78917,78923,78929,78942,78945,78947,78952:78954,78958:78959,78961:78963,78968:78970,78973:78974,78976:78977,78982:78983,78985:78986,78991,78993,78997:78998,79001,79018:79021,79025:79026,79028:79029,79033,79035,79042,79053,79055,79060:79061,79069,79071,79079,79086,79095,79097:79099,79104:79106,79111,79113:79114,79116:79118,79120:79121,79126:79127,79132,79137:79138,79140,79144:79147,79153,79156,79159,79172,79177:79178,79191:79194,79196:79197,79199,79201,79203,79207,79209,79219,79223:79224,79227:79228,79234:79235,79237,79243:79244,79246:79248,79250:79251,79254,79258,79260,79268,79270,79273,79276,79280,79296:79298,79300,79303:79306,79309:79311,79313:79314,79316:79318,79326,79328:79329,79334,79344,79346,79349:79352,79354:79355,79361,79363,79379,79381,79383:79384,79388:79401
S: A00000007 OK Search completed (0.001 + 0.041 secs).
C: A00000008 UID FETCH 78269 (BODY.PEEK[])
S: * 1 FETCH (UID 78269 BODY[] {1653050}
S: Return-Path: bla bla bla
S: Delivered-To: bla bla bla
S: Received: from mx.pubblica.istruzione.it (mvlmx002.sidi.mpi.it [bla bla bla])
S: by mvlmbox008-vip.sidi.mpi.it (Mailbox Server) with ESMTP id ECE3922DAF
S: for ; Thu, 5 Oct 2017 10:05:16 +0200 (CEST)
S: Received: from localhost (unknown [127.0.0.1])
S: by mvlmx002.sidi.mpi.it (Mail Service) with ESMTP id 0C55C2083C
S: for ; Thu, 5 Oct 2017 10:05:15 +0200 (CEST)
S: X-Virus-Scanned: Content Filter at istruzione.it
S: Received: from mx.pubblica.istruzione.it ([127.0.0.1])
S: by localhost (mvlmx002.sidi.mpi.it [127.0.0.1]) (amavisd-new, port 10024)
S: with ESMTP id 59YjPt-0YoAJ for ;
S: Thu, 5 Oct 2017 10:05:14 +0200 (CEST)
S: Received: from ALM_MPC_VE_01 (unknown [bla bla bla])
S: by mvlmx002.sidi.mpi.it (Mail Service) with ESMTP id 67BBF207BA
S: for ; Thu, 5 Oct 2017 10:05:14 +0200 (CEST)
S: Received: from localhost (localhost [127.0.0.1])
S: by ALM_MPC_VE_01 (Postfix) with ESMTP id 0116E1180F8
S: for ; Thu, 5 Oct 2017 10:05:10 +0200 (CEST)
S: X-MTA-CheckPoint: {59D5E765-0-1F28790A-755B07B6}
S: Received: from mvlsymx03.sidi.mpi.it (unknown [bla bla bla])
S: by ALM_MPC_VE_01 (Postfix) with ESMTP id A96471180FE
S: for ; Thu, 5 Oct 2017 10:05:09 +0200 (CEST)
S: X-AuditID: ac10be3f-693ff70000000df2-c0-59d5e7a33863
S: Received: from bla bla bla (bla bla bla [81.88.228.147])
S: by mvlsymx03.sidi.mpi.it (mx.pubblica.istruzione.it ESMTP Service) with SMTP id 75.F9.03570.3A7E5D95; Thu, 5 Oct 2017 10:04:56 +0200 (CEST)
S: Received: (qmail 10417 invoked from network); 5 Oct 2017 08:03:13 -0000
S: Received: from hidden (HELO bla bla bla) ()
S: by vm-mail.bla bla bla with SMTP; 5 Oct 2017 08:03:13 -0000
S: Received: from localhost (localhost [127.0.0.1])
S: by zcs01.bla bla bla (Postfix) with ESMTP id EDADA81361;
S: Thu, 5 Oct 2017 10:03:13 +0200 (CEST)
S: Received: from zcs01.bla bla bla ([127.0.0.1])
S: by localhost (zcs01.bla bla bla [127.0.0.1]) (amavisd-new, port 10032)
S: with ESMTP id ia5OpALWn3FU; Thu, 5 Oct 2017 10:03:12 +0200 (CEST)
S: Received: from localhost (localhost [127.0.0.1])
S: by zcs01.bla bla bla (Postfix) with ESMTP id DAF0B8142C;
S: Thu, 5 Oct 2017 10:03:09 +0200 (CEST)
S: X-Virus-Scanned: amavisd-new at zcs01.bla bla bla
S: Received: from zcs01.bla bla bla ([127.0.0.1])
S: by localhost (zcs01.bla bla bla [127.0.0.1]) (amavisd-new, port 10026)
S: with ESMTP id 5U_IsFPpcj13; Thu, 5 Oct 2017 10:03:09 +0200 (CEST)
S: Received: from [10.4.81.7] (unknown [192.168.4.1])
S: by zcs01.bla bla bla (Postfix) with ESMTP id 0007D8084F;
S: Thu, 5 Oct 2017 10:03:04 +0200 (CEST)
S: To: bla bla bla
S: From: bla bla bla
S: Subject: bla bla bla
S: Message-ID: <0327b1a6-2baf-c228-e4db-a373e2e9dcb8@bla bla bla >
S: Disposition-Notification-To: bla bla bla
S:
S: Date: Thu, 5 Oct 2017 09:59:54 +0200
S: User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101
S: Thunderbird/52.3.0
S: MIME-Version: 1.0
S: Content-Type: multipart/mixed;
S: boundary="------------3F0A69BAF25EF3604855D30F"
S: X-WatchGuard-Spam-ID: str=0001.0A0B0204.59D5E7A3.01CD,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0
S: X-WatchGuard-Spam-Score: 0, clean; 0, virus threat unknown
S: X-WatchGuard-Mail-Client-IP: bla bla bla
S: X-WatchGuard-Mail-From: bla bla bla
S: X-WatchGuard-Mail-Recipients: bla bla bla
S: X-WatchGuard-AntiVirus: part scanned. clean action=allow
S: X-Brightmail-Tracker: bla bla bla
S:
S: This is a multi-part message in MIME format.
S: --------------3F0A69BAF25EF3604855D30F
S: Content-Type: multipart/alternative;
S: boundary="------------010D4830028F0D8F4B2898CD"
S:
S:
S: --------------010D4830028F0D8F4B2898CD
S: Content-Type: text/plain; charset=iso-8859-15; format=flowed
S: Content-Transfer-Encoding: quoted-printable
S: X-WatchGuard-AntiVirus: part scanned. clean action=allow
S: bla bla bla
S:
S:
S: --------------010D4830028F0D8F4B2898CD
S: Content-Type: text/html; charset=iso-8859-15
S: Content-Transfer-Encoding: quoted-printable
S: X-WatchGuard-AntiVirus: part scanned. clean action=allow
S:
S: bla bla bla
S:
S: --------------010D4830028F0D8F4B2898CD--
S:
S: --------------3F0A69BAF25EF3604855D30F
S: Content-Type: image/jpeg;
S: name="bla bla bla.jpg"
S: Content-Transfer-Encoding: base64
S: Content-Disposition: attachment;
S: filename="bla bla bla.jpg"
S: X-WatchGuard-AntiVirus: scanned bla bla bla.jpg'. clean action=allow
S:
S: bla bla bla
S: --------------3F0A69BAF25EF3604855D30F--
S: )
S: A00000008 OK Fetch completed (0.003 + 0.233 secs).
C: A00000009 FETCH 78270 ALL
S: A00000009 BAD Error in IMAP command FETCH: Invalid messageset (0.000 + 0.040 + 0.039 secs).

What could be the problem?
Thank you

@jstedfast
Copy link
Owner

That command should have worked, but your IMAP server seems finicky. It might not like a single message UID in the FETCH request.

I've just committed a fix to make it encode as 78270:78270 so that it's a set.

@jstedfast jstedfast added the compatibility Compatibility with existing software label Oct 19, 2017
@jstedfast
Copy link
Owner

FWIW, normally you don't Fetch() for a single message, you normally do it for a batch of messages to be more efficient.

I probably won't get a chance to make a new nuget release for a week or so, so this fix won't show up for a little while yet.

@jstedfast
Copy link
Owner

I had to revert my fix for this due to the fact that it breaks expected behavior.

Syntax as defined by rfc3501:

fetch           = "FETCH" SP sequence-set SP ("ALL" / "FULL" / "FAST" /
                  fetch-att / "(" fetch-att *(SP fetch-att) ")")

sequence-set    = (seq-number / seq-range) *("," sequence-set)

So the fact that MailKit is encoding the FETCH command as:

A00000009 FETCH 78270 ALL

is perfectly valid syntax that your IMAP server is not properly handling.

@jstedfast
Copy link
Owner

That said, this will work for you in the next release:

var uid = new UniqueId (78270);
var uids = new UniqueIdRange (uid, uid);
var str = uids.ToString ();  // this will now be "78270:78270"

@DanieleD74
Copy link
Author

DanieleD74 commented Nov 3, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with existing software
Projects
None yet
Development

No branches or pull requests

2 participants