【问题标题】:Pascal Synapse error handling帕斯卡突触错误处理
【发布时间】:2013-07-19 14:30:15
【问题描述】:

我有一些使用Synapse IMAPSend 库单元的Lazarus/FreePascal 编写的代码。我尝试通过 SSL (IMAPS) 登录 IMAP 服务器,但调用 Login 失败。

我已经尝试检查异常 - 没有抛出任何异常。

Wireshark 只显示与相应服务器和端口的 TCP 三向握手。

这是代码

function GetImapResponse(host, port, user, pass:String): String;
var
  response: String = '';
  imap: TIMAPSend;
  no_unseen: integer;
begin
  imap := TIMAPSend.create;
  try
    imap.TargetHost := host;  //'10.0.0.16';
    imap.TargetPort := port;  //'993';
    imap.UserName := user;    //'red';
    imap.Password := pass;    //'********';
    imap.AutoTLS := false;
    imap.FullSSL := true;
    response := response + 'IMAP login to '+user+'@'+host+':'+port+' ... ';
    if imap.Login then
    begin
      response := response + 'Logged in OK. ';
      // How many unseen?
      no_unseen := imap.StatusFolder('INBOX','UNSEEN');
      Form1.Label2.Caption := IntToStr(no_unseen);
      response := 'INBOX contains ' +  IntToStr(no_unseen) + ' unseen messages. ';
    end
    else
    begin
      response := response + 'IMAP Login failed. ';
    end;
  except
    on E: Exception do
    begin
      response := response + 'Exception: ' + E.Message;
      showMessage(response);
    end;
  end;
  {
  finally
    imap.free;
    response := response + 'Finally. ';
  end;
  }
  Result := response;
end;               

这是这个函数的字符串结果

IMAP login to red@10.0.0.16:993 ... IMAP Login failed. 

问题:有没有办法查看 IMAPSend 认为发生的事情的一些细节?


更新 1

SimaWB's answer plus cmets by Arioch 'The所示

  mySynaDebug := TsynaDebug.Create;
  imap.Sock.OnStatus := @MySynaDebug.HookStatus;
  imap.Sock.OnMonitor := @MySynaDebug.HookMonitor; 

生成了一个 projectname.slog 文件,其中包含

20130722-103643.605 0011F230HR_SocketClose: 
20130722-103643.609 0011F230HR_ResolvingBegin: 10.0.0.16:993
20130722-103643.620 0011F230HR_ResolvingEnd: 10.0.0.16:993
20130722-103643.623 0011F230HR_SocketCreate: IPv4
20130722-103643.628 0011F230HR_Connect: 10.0.0.16:993
20130722-103643.631 0011F230HR_Error: 10091,SSL/TLS support is not compiled!

所以我正在前进:-)

我的项目文件夹中确实有 libssl32.dlllibeay32.dll,但会检查我是否有正确的版本,并且对鸡内脏做了正确的事情。


更新 2:

我使用的是 64 位版本的 Lazarus。 OpenSSL DLL 是 Synapse 的 ssl_openssl 单元动态加载的 32 位 DLL。我安装了 32 位版本的 Lazarus/FPC,现在我的 IMAP/SSL 客户端程序可以按预期编译和工作。

目前的 64 位 Lazarus/FPC 二进制发行版 (v1.0.10/2.6.2) 似乎无法交叉编译到 i386(我认为这可能有所帮助)。

【问题讨论】:

  • synapse 自带资源。在imap.Login 上按 F7(Trace Into)并像调试程序的所有其他部分一样对其进行调试。
  • FYI 严格来说,如果 没有扩展类型,则 -> x86 不起作用。最初 x86_64 已扩展已弃用,因此它算作“没有它”。 PowerPC64->PowerPC32 没问题,不是一般的 64->32 问题。
  • 我正在使用 Delphi 10 Seattle 构建 32 位应用程序,但我得到“10091,SSL/TLS 支持未编译!”信息。有人用最新版本的 Delphi 测试过吗?

标签: delphi exception-handling freepascal lazarus


【解决方案1】:

您尝试过 synadbg 单元的 Synapse 吗?

imap := TIMAPSend.create;
imap.Sock.OnStatus := TSynaDebug.HookStatus;
imap.Sock.OnMonitor := TSynaDebug.HookMonitor;

然后应用程序创建一个扩展名为“.slog”的日志文件。也许您可以在日志文件中找到更多详细信息。

【讨论】:

  • 这看起来很有用,但编译器抱怨 Error: Wrong number of parameters specified for call to "HookStatus" 所以它认为我在调用而不是(比如说)分配对过程的引用.我找不到这种用法的任何例子。 :-(
  • 那么@imap.Sock.OnStatus := @TSynaDebug.HookStatus;imap.Sock.OnStatus := @TSynaDebug.HookStatus; ?
  • @Arioch'The:我想不出一个不会因为unit1.pas(95,26) Error: Incompatible types: got "<class method type of procedure(TObject,THookSocketReason,const AnsiString) of object;Register>" expected "<procedure variable type of procedure(TObject,THookSocketReason,const AnsiString) of object;Register>"而失败的方法
  • 那么这意味着你应该创建一个 TSynaDBG 类型的对象并采用对象的方法,而不是类的方法
  • @RedGrittyBrick:可能与版本差异有关。 ararat.cz/synapse/doku.php/public:howto:debugsocket
【解决方案2】:

在 64 位 Ubuntu 上的 .slog 文件中的相同错误已通过“sudo apt-get install libssl-dev”修复,并在使用部分包含“ssl_openssl”。

【讨论】:

    【解决方案3】:

    问题出在这里:imap.AutoTLS := false; imap.FullSSL := true;尝试将true设置为false,将false设置为true... 端口应该是 587

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多