karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3, IMAP protocols. It is based on the standard C++ 17 and Boost library.
Other
381 stars 102 forks source link

send imap quoted string #134

Closed yjm6560 closed 1 year ago

yjm6560 commented 1 year ago

hi. i had searched imap c++ library, and this library is very helpful. but i found a point which could be improved.

imap quoted string in LOGIN command

string can be quoted string like following pictures in rfc3501 grammar.

image image

And userid and password containing " or \ In LOGIN command must be quoted string not plain string. if not, imap server can't parse the imap request. To be more specific, if password contains imap reserved character like (, ), {, }, imap server can't distinguish whether it is imap reserved character or part of password string. and if password contains space, server would be confused. So it will be safer to make userid and password into imap quoted string.

the way to convert plain string to imap quoted string is simple. Just put \ in front of quoted-special characters(" and \ ), and cover it with dquote("). e.g.

// AS-IS : imap server can't parse it
1 LOGIN userid" passwd\
// TO-BE
1 LOGIN "userid\"" "passwd\\"

Please feel free to tell me if I made a mistake. thank you.

yjm6560 commented 1 year ago

i will post other points which can be improved in a few days, if you don't mind..

karastojko commented 1 year ago

Thank you for the valuable suggestions. Let me play a little bit with the code, and I will apply the changes.

yjm6560 commented 1 year ago

Also, I think it would be good to consider using imap quoted string in the imap commands which uses the mailbox name. same problem can be occurred in mailbox name.

karastojko commented 1 year ago

Login now uses the quoted string on login. I will check the same for the mailbox name.

karastojko commented 1 year ago

Quoted string for the folder names are also added. Tested with various commands like creating and renaming a folder, looks fine.

Seems that Zoho is not happy with a folder which contains the double quote in the name, but that's not part of this bug.

yjm6560 commented 1 year ago

67e077e commit seems that you removed DQUOTE surrounding folder name. i thought same way with c524e5f should be applied to folder name.

did you test folder name like test("aaa"), test)], test"aaa?? it is good to create those folders in Web and test mailio::imap::select. i haven't tested after 67e077e commit but i think it may not work well..

karastojko commented 1 year ago

I think you are right, the last change was not good, I'll have to do it in a better way.

karastojko commented 1 year ago

Let's see if this time is better.

yjm6560 commented 1 year ago

Let's see if this time is better.

it seems to work well! there would be no work with imap quoted string if #136 is done!

There may be people who converts id,passwd and folder name to imap quoted string themselves. Therefore, it would be good to write it down in the release note that they don't have to do it themselves.