Archived Forum Post

Index of archived forum posts

Question:

Error messages when logging into some Imap accounts

May 29 '17 at 17:27

Hi,

I've got really very odd problem: one customer of mine has a lot of accounts which he wants to archive into my application. In the current version I log into the Imap accounts synchronously and everything works fine. For an upcoming version I'm changing to use asynchronous tasks. Where some but not all accounts give error messages like the one below. He gave me the login details for one account and when I try to log in everything works. The simplified code is below as well as the error from the plugin.

Any ideas what might cause this problem?

Xojo 2017r1, Mac OS 10.11. Chilkat 9.5.0.66 .

Mit freundlichen Grüßen/Regards

Beatrix Willius

http://www.mothsoftware.com Mail Archiver X: The email archiving solution for professionals

Code:

CkoImap.Port = Port
CkoImap.AuthMethod = "LOGIN"

if doSSL then CkoImap.Ssl = True call CkoImap.StartTls end if

'connect to server dim CkoConnectTask as Chilkat.Task = CkoImap.ConnectAsync(ServerName) call CkoConnectTask.Run While not CkoConnectTask.Finished CkoConnectTask.SleepMs(10) Wend

if not CkoConnectTask.TaskSuccess then globals.theErrorLog.LogItem(CurrentMethodName + " connect task didn't finish") Return "loginfailed" end if

dim theResult as Boolean = CkoConnectTask.GetResultBool if not theResult then globals.theErrorLog.LogItem "connection failed: " + getLastError if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "loginfailed" end if

'login with user and password 'theResult = CkoImap.Login(UserName, Password) dim CkoLoginTask as Chilkat.Task = CkoImap.LoginAsync(UserName, Password) call CkoLoginTask.Run While not CkoLoginTask.Finished CkoLoginTask.SleepMs(10) Wend

if not CkoLoginTask.TaskSuccess then globals.theErrorLog.LogItem(CurrentMethodName + " login task didn't finish") Return "loginfailed" end if

theResult = CkoLoginTask.GetResultBool if theResult then ImapInfoOkay = True if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "success" else globals.theErrorLog.LogItem "login failed: " + getLastError ImapInfoOkay = False if Verbose then globals.theErrorLog.LogItem getVerboseLog Return "loginfailed" end if

Error:

connection failed: ChilkatLog:
  Connect_Imap(141ms):
    DllDate: Jan 24 2017
    ChilkatVersion: 9.5.0.66
    UnlockPrefix: BEATRX.xxxx
    Architecture: Little Endian; 32-bit
    Language: MAC OS X C/C++
    VerboseLogging: 1
    Component successfully unlocked using purchased unlock code.
    connectInner(141ms):
      connectToImapServer(141ms):
        hostname: mail.venlogic.com
        port: 143
        socket2Connect(71ms):
          connect2(71ms):
            hostname: mail.xxx.com
            port: 143
            ssl: 0
            connectSocket(71ms):
              domainOrIpAddress: mail.xxx.com
              port: 143
              connectTimeoutMs: 30000
              connect_ipv6_or_ipv4(71ms):
                Single-threaded domain to IP address resolution
                connecting to IPV4 address...
                ipAddress: 70.32.86.149
                createSocket:
                  Setting SO_SNDBUF size
                  sendBufSize: 262144
                  Setting SO_RCVBUF size
                  recvBufSize: 4194304
                --createSocket
                connect(70ms):
                  Waiting for the connect to complete...
                  myIP: 192.168.10.3
                  myPort: 52599
                  socket connect successful.
                --connect
              --connect_ipv6_or_ipv4
            --connectSocket
          --connect2
        --socket2Connect
        Turning on TCP_NODELAY.
        socketOptions:
          SO_SNDBUF: 262332
          SO_RCVBUF: 4194536
          TCP_NODELAY: 4
          SO_KEEPALIVE: 8
        --socketOptions
        ConnectionType: Unencrypted TCP/IP
        numBytesRequested: 2048
        Connection closed by peer.
        passiveClose:
          error on socket shutdown.
          socketErrno: 57
          socketError: Socket is not connected
        --passiveClose
        nReceived: 0
        getImapResponseLine: Socket connection closed.
        Failed to get greeting.
      --connectToImapServer
      connect failed.
    --connectInner
    Failed.
  --Connect_Imap
--ChilkatLog

2017-05-13, 10:19:05 PM

Connecting to IMAP server at mail.xxx.com:143

----ERROR---- Failed to get command response on socket ----ERROR----


Answer

This section of code is suspect:

if doSSL then
CkoImap.Ssl = True
call CkoImap.StartTls
end if

StartTls is a property, not a method, so I would expect it to be like this:

if doSSL then
CkoImap.Ssl = True
CkoImap.StartTls = True
end if

However.. Ssl and StartTLS should never BOTH be True. The Ssl indicates that the connection is implicit SSL/TLS (typically port 993). Implicit TLS performs the TLS handshake immediately upon connecting.

The StartTls property indicates that a regular TCP connection is initially established (port 143 is typical). Then, prior to authentication, the IMAP client issues a "STARTTLS" command to convert the connection to TLS. Chilkat does this automatically when the StarTls property = True. For this particular server, you would want Ssl = False, but StartTls = True.

The behavior you see is that Chilkat is doing implicit TLS (because Ssl = True). The connection to port 143 is etablished, and Chilkat immediately begins the TLS handshake, but the IMAP server is not expecting it. The binary TLS handshake bytes being sent by Chilkat are unintelligible to the IMAP server, and it disconnects..


Answer

Thanks for the answer.

This particular code is not executed because the connection is on port 143 so DoSSL should be false. I also don't understand why this works in version 4.1 of my app but not for 4.2 which uses the same settings for SSL.

Obviously I need to read up on SSL. What is the correct code? Do I need to do testing what the different servers expect? Should I simply take out the line

CkoImap.StartTls = True

?

Mit freundlichen Grüßen/Regards

Beatrix Willius

http://www.mothsoftware.com Mail Archiver X: The email archiving solution for professionals


Answer

Any news on this? I know the problem doesn't make sense. But this is what we see.

Regards

Beatrix Willius


Answer

Port 143 is the non-SSL/TLS port for IMAP. Whereas port 993 is the implicit SSL/TLS port for IMAP.

If TLS is to be used, and the initial connection is to port 143, then you would want these settings:

if doSSL then
CkoImap.Ssl = False
CkoImap.StartTls = True
end if

If you connect to port 143, then the initial connection is non-encrypted. The StartTls property indicates to send the STARTTLS command immediately after connecting to negotiate the TLS connection. This is called "explicit TLS". Implicit TLS is when the TLS handshake occurs implicitly right after the connection is established.