Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: IdIMAP4->Connected() returns true before it is connected



Permlink Replies: 2 - Last Post: May 11, 2017 5:30 PM Last Post By: Asger Joergensen Threads: [ Previous | Next ]
Asger Joergensen

Posts: 370
Registered: 11/18/08
IdIMAP4->Connected() returns true before it is connected
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 11, 2017 6:19 AM
Hi

I have a strange problem, I have dropped a TIdIMAP4, a TIdPOP3 and
a TIdSSLIOHandlerSocketOpenSSL on my mail setup form, I chose to
setup a POP3 account and I test-run the setup.
In the FormClose event i run this code:

   bool imapConnected = IdIMAP4->Connected();
   if( imapConnected )
      IdIMAP4->Disconnect();
 
 
   bool pop3Connected = IdPOP3->Connected();
   if( pop3Connected )
      IdPOP3->Disconnect();


the strange thing is that imapConnected is true, which leads to
IdIMAP4->Disconnect(); being called and the program freezes.

It seem to be because I have the same TIdSSLIOHandlerSocketOpenSSL
assigned to both pop and imap, after setting the IOHandler right
before I set UseSSL and setting the other to 0 the IdIMAP4->Connected()
no longer return true.

Is this a known problem or maybe it just have to be this way ?

Thanks in advance
Best regards
Asger
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: IdIMAP4->Connected() returns true before it is connected
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 11, 2017 12:29 PM   in response to: Asger Joergensen in response to: Asger Joergensen
Asger wrote:

In the FormClose event i run this code:

bool imapConnected = IdIMAP4->Connected();
if( imapConnected )
IdIMAP4->Disconnect();
 
bool pop3Connected = IdPOP3->Connected();
if( pop3Connected )
IdPOP3->Disconnect();

You don't need to call Connected() before calling Disconnect(). Just call
Disconnect() unconditionally. Or don't call it at all, the component destructor
will close the socket anyway.

the strange thing is that imapConnected is true, which leads to
IdIMAP4->Disconnect(); being called and the program freezes.

It seem to be because I have the same TIdSSLIOHandlerSocketOpenSSL
assigned to both pop and imap

You can't share an IOHandler like that, unless you make ABSOLUTELY SURE that
only one TCP component at a time is actively using it. Otherwise, give each
component its own IOHandler instead.

Internally, the TIdTCPConnection::Connected() method checks the TIdIOHandler::Connected
property. So it makes perfect sense that if you are sharing the IOHandler,
and you connect TIdPOP3 to a POP3 server, and then call TIdIMAP4::Connected(),
it will return true (the IOHandler is actually connected to something, it
just doesn't know what). Then calling TIdIMAP4::Disconnect() would send
an IMAP "LOGOUT" command to the server, but since you are connected to a
POP3 server, a failure response will be sent back since "LOGOUT" is not a
valid POP3 command, and since the POP3 protocol is very different than the
IMAP protocol then TIdIMAP4:::Disconnect() can't detect the end of the response
and thus freezes.

This is another situation where setting the ReadTimeout property would solve
the freezing problem.

after setting the IOHandler right before I set UseSSL and setting
the other to 0 the IdIMAP4->Connected() no longer return true.

If you mean you are setting the TIdIMAP4::IOHandler to NULL while the TIdPOP3
is connected, then yes, TIdIMAP4::Connected() would return false.

--
Remy Lebeau (TeamB)
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: IdIMAP4->Connected() returns true before it is connected
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 11, 2017 5:30 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy

Thank you very much for explaining.

Best regards
Asger
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02