smiley22 / S22.Imap

A free, easy-to-use and well-documented .NET library component for communicating with IMAP servers
http://smiley22.github.com/S22.Imap/Documentation/
MIT License
210 stars 112 forks source link

Problem with folder's name #112

Open maxsmal opened 9 years ago

maxsmal commented 9 years ago

Hi, Torben Könke. I'm use your library for my email-client. But i have problem with MoveMessage() function. I create folder "мимими" (i'm from Russia, it's russian letters), and try to move message to this folder. Code: var imap = new S22.Imap.ImapClient(host,port,login,pass, AuthMethod.Login); imap.MoveMessage(248, "мимими", "INBOX"); // letter with uid=248 in INBOX folder is exist. But i get error: Необработанное исключение типа "S22.Imap.BadServerResponseException" в S22.Imap.dll Дополнительные сведения: xm004 NO Invalid mailbox name: ???????????? I think, that problem is encoded. How to solve this?

jstedfast commented 9 years ago

It looks like Util.cs has UTF7Encode() and UTF7Decode() methods that can be used to properly encode the folder names, so you could probably without too much effort fix up S22.Imap to use that everywhere it passes along folder names.

For example, in your particular case, you would need to change the following code in ImapClient.cs in the CopyMessages() method (MoveMessages calls CopyMessages):

https://github.com/smiley22/S22.Imap/blob/master/ImapClient.cs#L1630

The code currently does this:

string response = SendCommandGetResponse(tag + "UID COPY " + set + " " +
                    destination.QuoteString());

What you'll need to do is to call Util.UTF7Encode (destination).QuoteString () instead. You'll probably also want to fix up all of the other places the code doesn't encode the folder names because they'll have similar problems that you are having with MoveMessages().

Alternatively, you might want to check out MailKit which already does this properly.

Hope that helps.

jstedfast commented 9 years ago

I decided to send Torben a pull request with a fix for this issue since it was so obvious and trivial to fix.

It turns out most of the code properly encodes the folder name before using it, the only place that was missing it that I could find was the CopyMessages() method.

I'd still recommend using MailKit though ;-)

maxsmal commented 9 years ago

jstedfast, thanks for your comments. I already use MailKit for this situation.

jstedfast commented 9 years ago

Awesome :-)