mguessan / davmail

DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
http://davmail.sourceforge.net
GNU General Public License v2.0
576 stars 85 forks source link

Davmail can not handle username with back slash #324

Closed xtang2010 closed 8 months ago

xtang2010 commented 9 months ago

Env: Windows 11 Davmail: 6.2.0 (I also looked source in 6.2.1, as the relevant part is the same, I suspect same behavior)

My organization changed login username format to "domain\username", this caused a lot of problem lately.

Some clients on mobile phone seems working fine, some seems not, here is the list of phones that I have tried.

After some debug, it turns out this part of code in parseCredentials() (in java/davmail/imap/ImapConnection.java) cause the problem.

        int backslashindex = userName.indexOf('\\');
        if (backslashindex > 0) {
            userName = userName.substring(0, backslashindex) + userName.substring(backslashindex + 1);
        } 

iPhone seems automatically sending "domain\\username" (even though there is only one backslash in username), while other client sending exactly username.

I am not sure what the protocol says, but after I change the code to something below, it works for all clients (with username set to "domain\client")

        if (userName.contains("\\\\")) {
            userName = userName.replaceAll("\\\\", "\\");
        }
mguessan commented 9 months ago

Well technically DavMail can handle username with a back slash, it just is not aware that iOS randomly decided to escape this backslash ;-)

Anyway I don't see any reason for regression with the proposed patch, will merge it as is

esabol commented 8 months ago

@xtang2010: You closed the issue prematurely. There's been no commit yet. I think this issue should be reopened.