Search code examples
delphiimapindy

Indy IMAP doesn't allow special characters for the password


I am connecting to an Exchange server using the Indy TIdIMAP4 component (version 10.6.0). This works fine when there are just simple characters in the password as IMAP4rev1 doesn't seem to allow anything else than US-ASCII. Though if the password contains special characters like the German umlauts, spaces, etc. the authentication via IMAPConnection.Connect fails, i.e. it throws an exception saying "LOGIN failed".

I assume this is caused by a bug in the TIdIMAP4 component regarding SASL, though I'm not sure about that.

If that bug is unrelated, is there a property that can be set or a function that can be called to allow authenticating? If that bug is causing these authentication problems, is there a workaround for it?

And how would the actual connection code look like then?

Sebastian


Solution

  • The SASL is broken in TIdIMAP4 issue was already addressed in 10.6.0, via an internal PerformSASLLogin_IMAP() function in IdIMAP4.pas. For the time being, TIdIMAP4 now uses its own internal SASL implementation instead of using Indy's normal SASL implementation. So that is not the issue.

    The IMAP LOGIN command does not allow Unicode, period. SASL does allow Unicode, but Indy does not implement support for Unicode in SASL at this time.

    You could try patching IdIMAP4.pas manually, by changing these lines:

    // lines 1368 and 1378 in PerformSASLLogin_IMAP()
    AClient.IOHandler.WriteLn(AEncoder.Encode(S));
    

    To this instead:

    AClient.IOHandler.WriteLn(AEncoder.Encode(S, IndyTextEncoding_UTF8));
    

    But that may or may not work depending on the particular SASL used and if it actually supports UTF-8 or not.

    I have opened up a new ticket in Indy's issue trackers to support Unicode in SASL in a future release.