This is a write up of two bugs, one in Docuware's Connect to Mail, and the other in the Dovecot IMAP server as supplied by Redhat Enterprise Linux 6 and 7. These bugs together cause Docuware Connect to Mail to be unable to connect to RHEL6 and RHEL7.

When setting up a new IMAP service, you get the error "Not able to establish connection. Please verify your input!". No underlying error is given to the end user, and nothing is logged.

By manually creating a connection in the Docuware database, you find the underlying error is as follows:

<exception>DocuWare.ConnectToMail.Communication.Exception.CommunicationClientException: Could not establish connection to mail server ---&gt; System.Exception: Connection to IMAP server timed out after 60000ms 
at DocuWare.ConnectToMail.Communication.Clients.Components.DWImap.EstablishServerConnection(ConnectionServerContainer conServer, List`1&amp; externalLog) 
at DocuWare.ConnectToMail.Communication.Clients.Components.DWImap.EstablishClientConnection(ConnectionServerContainer conServer, ConnectionUserContainer conUser, List`1&amp; externalLog) 
at DocuWare.ConnectToMail.Communication.DwCommunicationClient.EstablishConnection(List`1&amp; externalLog) 
--- End of inner exception stack trace --- 
at DocuWare.ConnectToMail.Communication.DwCommunicationClient.EstablishConnection(List`1&amp; externalLog) 
at DocuWare.ConnectToMail.Communication.DwCommunicationClient.EstablishConnection() 
at DocuWare.BPS.C2Mail.Implementation.ProcessImplementation.EstablishConnectionToMailProvider() 
at DocuWare.BPS.C2Mail.Implementation.ProcessImplementation.Run()</exception> 

First, the Docuware bug:

When an IMAP connection is diconnected by the server side and enters a broken state, the exception thrown is not caught by Docuware, and Docuware returns this broken IMAP object to it's connection pool.

When Docuware needs this connection it retrieves the connection from the pool, and attempts to use that connection. The connection, being disconnected by the server, returns the exception above, and no successful connection is possible.

To fix this, Docuware needs to ensure that all exceptions returned by the Limilabs IMAP client are caught and the IMAP object cleanly destroyed.

Limilabs shed light on the internal workings of their library here:

Second, the Redhat Enterpise Linux bug:

When a secure IMAP connection is made to Dovecot as supplied by Redhat Enterprise Linux, and the Limilabs IMAP clients requests a graceful logout, dovecot logs out but does not flush the logout confirmation before closing the TCP connection. The Limilabs IMAP client does not see the BYE command, and returns an exception, with the expectation that the IMAP connection be destroyed. Docuware returns this broken connection to it's pool and attempts to reuse the connection, resulting in failure.


The workaround is to apply the patches to dovecot as documented in the following two bug reports, one for RHEL6 and one for RHEL7. This causes the connection to be closed properly, and thus we avoid the Docuware bug above: