Code Monkey home page Code Monkey logo

Comments (18)

smiley22 avatar smiley22 commented on July 20, 2024

ah I see, I think we can also get away with just tweaking the regex to make the quotes an optional part. something like this should work:

"\* LIST ((.*))\s+"(.+)"\s+"?([^\"]+)"

Hm so mailbox names can contain quote characters as part of their names? That is really annoying...I guess the {7} is the number of bytes following that * LIST response line. I don't remember reading anything about this in RFC 3501 though, will do some testing and see how other servers deal with this!

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

BTW about half of the servers I tested with wouldn't allow quote characters in mailbox names and the other half handled them correctly or escaped them, so I guess it's a problem with the IMAP implementation of the exchange server.

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

That's Microsoft. Not the first time when their product doesn't meet standards...
Actually it's a MS Exchange Server 2010 and the client is MS Outlook 2010. Today I tested in via telnet with pure IMAP commands, so it handles double quotes on its way:

* OK The Microsoft Exchange IMAP4 service is ready.
> capability
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+
$ OK CAPABILITY completed.
> login znagy xxxxxxx
$ OK LOGIN completed.
> create hello
$ OK CREATE completed.
> rename hello hell"oh
$ OK RENAME completed.
> list "" hell*
* LIST (\HasNoChildren) "/" {7}
hell"oh
$ OK LIST completed.
> logout
* BYE Microsoft Exchange Server 2010 IMAP4 server signing off.

If you like me to send more various examples,I'll do it later. But actually it's not important for me (either). I think the main aim is a working lib along standards. (Maybe it's worth to create a MS Exchange specific todo list for the time when nothing else to do..:)

Anyway, the regex fix works fine!

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Yup no idea why they do it like this, but I submitted another patch to deal with it. That'll hopefully take care of it!

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

Almost good,but it removes the double quote from the beginning or ending in case of eg:

* LIST (\Marked \HasNoChildren) "/" {11}
Say "Hello"
* LIST (\HasNoChildren) "/" {14}
"Hello" - said
* LIST (\HasNoChildren) "/" {11}
Why "MC" A?

Say "Hello" ==> Say "Hello
"Hello" - sad ==> Hello" - said
Why "MC" A? is OK :)

I said that's not important... but if you want it ;)

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Fixed

On Mon, Oct 8, 2012 at 2:21 PM, greatz [email protected] wrote:

Almost good,but it removes the double quote from the beginning or ending
in case of eg:

  • LIST (\Marked \HasNoChildren) "/" {11}
    Say "Hello"
  • LIST (\HasNoChildren) "/" {14}
    "Hello" - said
  • LIST (\HasNoChildren) "/" {11}
    Why "MC" A?

Say "Hello" ==> Say "Hello
"Hello" - sad ==> Hello" - said
Why "MC" A? is OK :)

I said that's not important... but if you want it ;)


Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-9223886.

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

Sorry for my annoying test cases:

Bug#1: character '-' (hyphen) lost:

["Hello" - said] ==> ["Hello"  said]

Bug#2: [Why "Mc" A?] and ["Hello" Okay] parsing OK, but problem with selection:

IMAP> A007 SELECT "Why \"Mc\" A?"
A007 BAD Command Argument Error. 12

IMAP> A007 SELECT "\"Hello\" Okay"
A007 BAD Command Argument Error. 12

Hm, currently I have no idea for bug#2...

Meanwhile the [Say "Hello"] is fine:

IMAP> A005 SELECT "Say \"Hello\""
* 15 EXISTS
* 0 RECENT

but [Say "Hello" mate] makes us crazy again:

IMAP> A007 SELECT "Say \"Hello\" mate"
A007 BAD Command Argument Error. 12

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Haha no worries, glad to have your help in bug-fixing =) Will have a look at it and try to cook something up!

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Hyphen was swallowed by UTF7Encode, so that is taken care of...I couldn't reproduce bug#2 though, I just ran a couple of tests and it all seemed to work.

JustA"Test
Selecting as "JustA\"Test"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402195] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

Say "Hello"
Selecting as "Say \"Hello\""
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402197] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

"Hello" said
Selecting as "\"Hello\" said"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402198] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

書き言葉と話し
Selecting as "&ZvgwTYoAhEkwaIpxMFc-"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402199] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

"Hello" - said
Selecting as "\"Hello\" - said"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402200] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

Why "Mc" A?
Selecting as "Why \"Mc\" A?"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402201] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

"Hello" Okay
Selecting as "\"Hello\" Okay"
* OK [CLOSED] Previous mailbox closed.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1348402202] UIDs valid
* OK [UIDNEXT 1] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

It's a mystery. Most of the examples cause "BAD Command Argument Error. 12" error on MS Exchange.

A001 CREATE "JustA\"Test"
A001 OK CREATE completed.

A002 CREATE "Say \"Hello\""
A002 OK CREATE completed.

A003 CREATE "\"Hello\" said"
A003 BAD Command Argument Error. 12

A004 CREATE "&ZvgwTYoAhEkwaIpxMFc-"
A004 OK CREATE completed.

A005 CREATE "\"Hello\" - said"
A005 BAD Command Argument Error. 12

A006 CREATE "Why \"Mc\" A?"
A006 BAD Command Argument Error. 12

Back to the {n} formula in string, I just found that's part of the rfc3501, called "literal" string: http://tools.ietf.org/html/rfc3501#section-4.3

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Yea I came across this the other day too when extending the search method to support non-ascii characters. Have you tried sending the mailbox name as a "literal" to the server i.e.

--> CREATE {11}
<-- + Go ahead....
-->"Why "Mc" A?"

But even if that works, I'm a bit hesitant to add workarounds to all mailbox methods just to address this. Especially since it only seems to be a problem with Exchange Server. I guess I'll make a post to the IMAP mailing list, maybe someone there can shed some light on this.

EDIT: It seems the protocol allows servers to return arbitrary strings as literals. Pretty annoying, but other than with the Exchange Server I have never observed this...

This doc has some info on it under 3.4.2, but it also says client and server both must be able to handle backslash escaped double-quote characters: http://tools.ietf.org/html/rfc2683

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

To address the literal problem, the GetResponse method could be modified to just take care of them automatically.

        /// <summary>
        /// Waits for a response from the server. This method blocks
        /// until a response has been received.
        /// </summary>
        /// <param name="resolveLiterals">Set to true to resolve possible literals
        /// returned by the server (Refer to RFC 3501 Section 4.3 for details).</param>
        /// <returns>A response string from the server</returns>
        private string GetResponse(bool resolveLiterals = true) {
            const int Newline = 10, CarriageReturn = 13;
            using (var mem = new MemoryStream()) {
                lock (readLock) {
                    while (true) {
                        byte b = (byte)stream.ReadByte();
                        if (b == CarriageReturn)
                            continue;
                        if (b == Newline) {
                            string s = Encoding.ASCII.GetString(mem.ToArray());
                            if (resolveLiterals)
                                s = Regex.Replace(s, @"{\d+}$", _ => GetResponse(false));
                            return s;
                        } else
                            mem.WriteByte(b);
                    }
                }
            }
        }

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

There's an interesing document describing to which degree MS Exchange Server supports IMAP4rev1 and where it deviates from the standard.

It states what we've already observerd ("If a mailbox name contains the backslash character (""), then Microsoft® Exchange Server returns the mailbox name as a literal preceded by a field.") but unfortunately has nothing on the SELECT command.

http://download.microsoft.com/download/9/1/D/91D015B5-C439-40E7-94F3-CBFCF2B04D49/[MS-STANXIMAP].pdf

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

What about the option/flag like "bool handleDqInStringAsLiteral" for MS Exchange Servers? :)

It can be set automated after connection:

* OK The Microsoft Exchange IMAP4 service is ready.

or when getting capabilities:

* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+

Additionally, what if ListMailboxes() returns with an array of a new class type for mailbox (with bool IsLiteral and string LiteralName properties, that can be extended with status info and so on... :) instead of string array? :)

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Yea something like that. Could also store the associated flags then and the XLIST stuff. Ah well I'll do some experimenting and see if I can come up with something=)

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

I just ran these on an Exchange 2003 server via telnet and then again via S22.Imap.dll and they all worked

> CREATE "\"Hello\" said"
< xm026 OK CREATE completed.
> CREATE "\"Hello\" - said"
< xm027 OK CREATE completed.
> CREATE "Why \"Mc\" A?"
< xm028 OK CREATE completed.

> LIST "" "*"
< * LIST (\HasNoChildren) "/" INBOX
< * LIST (\HasNoChildren) "/" ""Hello" said"
< * LIST (\HasNoChildren) "/" ""Hello" - said"
< * LIST (\HasNoChildren) "/" "Why "Mc" A?"
< xm029 OK LIST completed.

from s22.imap.

nagyzo avatar nagyzo commented on July 20, 2024

Hi, I'm back again :)

I repeated the test on MS Excange 2010. Finally, it seems that the use of literal string as input is the solution for CREATE command on the this server.

< * OK The Microsoft Exchange IMAP4 service is ready.

> A001 CREATE "\"Hello\" said"
< A001 BAD Command Error. 12

> A002 CREATE "\"Hello\" - said"
< A002 BAD Command Error. 12

> A003 CREATE {11}
< + Ready for additional command text.
> Why "Mc" A?
< A003 OK CREATE completed.

> A004 CREATE {17}
< + Ready for additional command text.
> "Hell'oh!" - said
< A004 OK CREATE completed.

> A005 CAPABILITY
< * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+
< A005 OK CAPABILITY completed.

> A006 LOGOUT
< * BYE Microsoft Exchange Server 2010 IMAP4 server signing off.

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

How do you send those commands to the server? I'm wondering because when I logged into an Exchange 2003 server using telnet the other day, I could create all those mailboxes just fine. I just can't seem to reproduce the "BAD Command Error. 12"...

from s22.imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.