Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: TIdPOP3 with Google Mail error 'malformed command'


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Feb 12, 2018 11:12 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Boba ½°

Posts: 73
Registered: 12/19/03
TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 5:59 PM
Dear All;
when using TIdPOP3 component to read emails on gmail, I get an exception "malformed command *****************"
thrown by IdPOP3->Connect() method after the socket gets connected and the work ends. It is Indy 10 and VCL12.
TIA
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 7, 2018 7:27 PM   in response to: Boba ½° in response to: Boba ½°
Boba ½° wrote:

when using TIdPOP3 component to read emails on gmail

Why not TIdIMAP4?

I get an exception "malformed command *****************" thrown by
IdPOP3->Connect() method after the socket gets connected and the
work ends.

What is the EXACT command that is being complaining about? Connect()
can potentially send multiple commands (CAPA, STLS, APOP, USER, PASS,
AUTH).

Are you using SSL/TLS? What do you have the UseTLS and Port property
set to?

--
Remy Lebeau (TeamB)
Boba ½°

Posts: 73
Registered: 12/19/03
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 10:42 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Why not TIdIMAP4?
IMAP has already been done (no new questions yet)
What is the EXACT command that is being complaining about? Connect()
can potentially send multiple commands (CAPA, STLS, APOP, USER, PASS,
AUTH).
I do not have any wire listeners yet.
Are you using SSL/TLS? What do you have the UseTLS and Port property
set to?
'some of the relevant properties of VCL components:
with IdSSLIOHandlerSocketOpenSSL
.Destination=pop.gmail.com:995
.Host=pop.gmail.com
.Port=995
with .SSLOptions
.Method=sslvTLSv1
.Mode=sslmUnassigned
with IdPOP3
.AuthType=patUserPass
.AutoLogin=True
.Host=pop.gmail.com
.IOHandler=IdSSLIOHandlerSocketOpenSSL
.Port=995
.UseTLS=utUseImplicitTLS

'ssleay32 version 1.0.2.14
'the event log shows:
IdSSLIOHandlerSocketOpenSSLStatus> Resolving hostname pop.gmail.com.
IdSSLIOHandlerSocketOpenSSLStatus> Connecting to 173.194.70.108.
IdSSLIOHandlerSocketOpenSSLStatusInfo SSL status: "before/connect initialization"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "before/connect initialization"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 write client hello A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read server hello A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read server certificate A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read server key exchange A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read server done A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 write client key exchange A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 write change cipher spec A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 write finished A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 flush data"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read server session ticket A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSLv3 read finished A"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSL negotiation finished successfully"
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSL negotiation finished successfully"
IdSSLIOHandlerSocketOpenSSLStatusInfo> Cipher: name = ECDHE-RSA-AES128-SHA; description = ECDHE-RSA-AES128-SHA SSLv3 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA1
; bits = 128; version = TLSv1/SSLv3;
IdPOP3Status> Connected.
IdPOP3Connected
IdPOP3WorkBegin> 0
IdPOP3Work> READ 6
...............................
IdPOP3Work> READ 106
IdPOP3WorkEnd>
IdPOP3Status> Disconnecting.
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSL negotiation finished successfully"
IdPOP3Disconnected>
IdPOP3Status> Disconnected.
'and then this exception
malformed command w142mb665842711pfs
Can you guess from the above log info what is wrong?
How do I catch TId Exception properly? so it tells me what COMMAND causes it. TIA.
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 11:19 AM   in response to: Boba ½° in response to: Boba ½°
Boba ½° wrote:

I do not have any wire listeners yet.

To capture TIdPOP3's POP3 traffic, you can assign one of Indy's
TIdLog... components to the TIdPOP3.Intercept property.

IdPOP3Status> Connected.
IdPOP3Connected
IdPOP3WorkBegin> 0
IdPOP3Work> READ 6
...............................
IdPOP3Work> READ 106
IdPOP3WorkEnd>
IdPOP3Status> Disconnecting.
IdSSLIOHandlerSocketOpenSSLStatusInfo> SSL status: "SSL negotiation
finished successfully"
IdPOP3Disconnected>
IdPOP3Status> Disconnected.
'and then this exception
malformed command w142mb665842711pfs

This sequence implies that you are doing something in your code to make
TIdPOP3 try to communicate with POP3 before it is actually ready to do
so. The SSL/TLS handshake is clearly not fully complete, so a portion
of it is being sent to the server at the wrong stage, causing the
server to treat it as a malformed command, which TIdPOP3 reacts to by
closing the connection.

Please show your actual code. Are you using the OnConnected event to
issue commands? If you are, you shouldn't be. It is triggered as soon
as the TCP connection is established, before the SSL/TLS handshake is
performed. Don't issue any POP3 commands until after the Connect()
method exits first.

How do I catch TId Exception properly?

Use a try/catch block, like any other exception.

so it tells me what COMMAND causes it.

The raised exception won't tell you which command failed. It will only
tell you the server's response.

--
Remy Lebeau (TeamB)
Boba ½°

Posts: 73
Registered: 12/19/03
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 5:42 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
To capture TIdPOP3's POP3 traffic, you can assign one of Indy's
TIdLog... components to the TIdPOP3.Intercept property.
//this is the log file contents:
Stat Connected.
Recv 2/8/2018 6:56:55 PM: +OK Gpop ready for requests from NNN.NNN.NNN.NNN z8mb235611285opg<EOL>
Sent 2/8/2018 6:56:55 PM: CAPA<EOL>
Recv 2/8/2018 6:56:55 PM: +OK Capability list follows<EOL>USER<EOL>RESP-CODES<EOL>EXPIRE 0<EOL>LOGIN-DELAY 300<EOL>TOP<EOL>UIDL<EOL>X-GOOGLE-RICO<EOL>SASL PLAIN XOAUTH2 OAUTHBEARER<EOL>.<EOL>
Sent 2/8/2018 6:56:55 PM: USER xxxx@xxxxxxxx.com<EOL>
Recv 2/8/2018 6:56:55 PM: +OK send PASS<EOL>
Sent 2/8/2018 6:56:55 PM: PASS <EOL>
Recv 2/8/2018 6:56:55 PM: -ERR malformed command z6mb245413260oof<EOL>
Stat Disconnected.
{/code}
so it's the wrong password client gave me. I wish I knew about logging feature of TIdPOP3.
<div class="jive-quote">This sequence implies that you are doing something in your code to make
TIdPOP3 try to communicate with POP3 before it is actually ready to do
so.  The SSL/TLS handshake is clearly not fully complete, so a portion
of it is being sent to the server at the wrong stage, causing the
server to treat it as a malformed command, which TIdPOP3 reacts to by
closing the connection.
 
Please show your actual code.  Are you using the OnConnected event to
issue commands?  If you are, you shouldn't be.  It is triggered as soon
as the TCP connection is established, before the SSL/TLS handshake is
performed.  Don't issue any POP3 commands until after the Connect()
method exits first.</div>

void __fastcall TFormMain::BtnDnldEmlsClick(TObject *){
try{
IdPOP3->Connect();
MemoLog->Lines->Add("---connected---");//not logged
nMsgs = IdPOP3->CheckMessages();
...
}catch(Exception &e){
MemoLog->Lines->Add(e.Message);//"malformed command ...."
}
}//TFormMain::BtnDnldEmlsClick
{/code}

Remy, thank you very much for your prompt reply; you just made my week better...
Best regards,
Boba TC
Remy Lebeau (Te...


Posts: 9,229
Registered: 12/23/01
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 11:12 AM   in response to: Boba ½° in response to: Boba ½°
Boba ½° wrote:

USER xxxx at xxxxxxxx dot com
+OK send PASS
PASS
-ERR malformed command z6mb245413260oof

so it's the wrong password client gave me.

Not just a wrong password, but it looks like a blank password is being
sent. Did you assign anything to the TIdPOP3.Password property?

I wish I knew about logging feature of TIdPOP3.

It is not just TIdPOP3, all of Indy's TCP components support intercepts.

--
Remy Lebeau (TeamB)
Boba ½°

Posts: 73
Registered: 12/19/03
Re: TIdPOP3 with Google Mail error 'malformed command'  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 5:44 PM   in response to: Boba ½° in response to: Boba ½°
Tons of thanks go to Remy.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02