bertjohnson / OpaqueMail

.NET email library and proxy supporting IMAP, POP3, and SMTP with S/MIME and PGP.

Home Page:https://opaquemail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with UniqueCommandTag

butch0r opened this issue · comments

You have a Problem with the UniqueCommandTag(). Here you only add 1 to a number.
So then in ReadDataAsync(string commandTag, string previousCommand, int timeout = 0)
there is one IF-Statment (if (responseParts[0] == commandTag || (...)) that asks, if the first part is equal to the commandTag. If so you can't get the complete mail.
E.g.:
CommangTag = 4
response = "4 or 5 times"
responseParts[0] = "4"

I solved this problem like this:

        public string UniqueCommandTag()
        {
            return (++CommandTagCounter).ToString() + "~#~OPAQUE-MAIL~#~";
        }

I hope you understand this.

Best regards

Butch0r

Hi Butch0r, I'm not sure if what you reported is an issue or not.

IMAP requires that every command is prefixed with a unique tag. The server then precedes certain responses with the command tag (echoing it back). See section 2.2.1 of the RFC3501 IMAP spec.

Message contents are guaranteed to come after the command tag is specified. So even if a message contains the string "1234567890", the "4" in that substring would always match after the command tag.

Can you confirm whether you've observed problems with tag mismatches or whether this is a preventative measure? Thanks for your help.

Hi Bert,

the problem appears on switching the response.part[1] in the default case.

// If not a known response, return it verbatim. default: if (**responseParts[0] == commandTag** || (responseParts[0] == "+" && responseBuilder.Length == 0)) return responseLine.Substring(responseLine.IndexOf(" ") + 1); else responseBuilder.Append(responseLine + "\r\n"); break;

if at the start of any line int the mail content is an number that matches the command tag, it will remove this number from the content.

i hope this helps.

If I read this correctly, you're concerned that a numeric command tag can incorrectly match up with text in an email's contents. Because command tags are always going to be matched prior to an email's contents by IndexOf(), I'm confident that can't happen.

Please reopen this issue if you're able to produce an error. Thanks.