-1

Can someone help me translate a line from this code to C++ Builder:

http://blog.onkeysoft.com/2011/04/20/how-to-prepare-a-connection-to-pop3-server-with-indy-tidpop3/

I was doing good until this line:

 POP3Client.SASLMechanisms.Add.SASL := tidsasl(con_sasl_anonymous);

Additional question - is there a "good" order of SASL mechanisms to try out - from most secure to least secure? In other words, what would be a good order of them? I would try with SHA1 first, then MD5 then... something here... and PlainText as last one.

4
  • POP3Client>SASLMechanisms>Add>SASL = (TIdSASL*)con_sasl_anonymous;
    – TLama
    Mar 30, 2013 at 21:29
  • That doesn't work because Add(TIdSASListEntry *) is a function - it expects TIdSASListEntry * as parameter so there may be something wrong with above code?
    – Coder12345
    Mar 30, 2013 at 21:34
  • 1
    Is Add really a method with parameter ? I don't know, just looking at the Add method of TCollection class, it doesn't expect any parameter (maybe Indy has the TIdSASLEntries based on a different class, I don't know). Anyway, that code is unsafe since adding of that collection item may fail and you may access not existing object. Safer is to have a variable where you'll store the added collection item. It might be this way.
    – TLama
    Mar 30, 2013 at 21:59
  • Yes, you are right... (TIdSASLListEntry*) is return parameter from Add() function which doesn't require parameters! Can't believe I didn't notice that. Now everything works! Thanks!
    – Coder12345
    Mar 30, 2013 at 22:06

1 Answer 1

3

For future googlers - thanks to TLama:

TIdSASLListEntry *se = POP3Client->SASLMechanisms->Add();
se->SASL = (TIdSASL*)con_sasl_anonymous;

Or if you prefer C++ style casts:

TIdSASLListEntry *se = POP3Client->SASLMechanisms->Add();
se->SASL = static_cast<TIdSASL*>(con_sasl_anonymous);
1
  • 1
    Assuming con_sasl_anonymous is a TIdSASLAnonymous component, then you don't need the type-cast at all (the original DElphi code did not need to type-cast, either): se->SASL = con_sasl_anonymous; Apr 1, 2013 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.