These are chat archives for IndySockets/Indy

1st
Oct 2018
code4tips
@code4tips
Oct 01 2018 00:49

@czhower Fixed this part as follows:

   1 - Removed all the text from Responses 
    2-  In the Command Handlers add ASender.Reply.SetReply(200, '[success]') 
    3 - In the client use  
                                a) Memo1.Lines.Add(intToStr(Client.LastCmdResult.NumericCode));
                                b) for I := 0 to Client.LastCmdResult.Text.Count -1 do Memo1.Lines.Add(Client.LastCmdResult.Text[i]);

No more '.' (periods). Thanks

Marcos Douglas B. Santos
@mdbs99
Oct 01 2018 01:43
Hello. How can I differentiate attachments among those that are only images on body than those that are really attachment files?
Marcos Douglas B. Santos
@mdbs99
Oct 01 2018 12:36
@rlebeau just a feedback about my issue with ZEOS+Indy, I've solved as explained here - thanks
mezen
@mezen
Oct 01 2018 13:04
Maybe the sender set the content-disposition (https://www.iana.org/assignments/cont-disp/cont-disp.xhtml) for the attachment "inline" or "attachment"
Remy Lebeau
@rlebeau
Oct 01 2018 16:27
@mdbs99 what @mezen said. Also, most of the time, non-body attachments are at the top-level of the email (ParentPart = -1), though that is not guaranteed. Usually non-body attachments are inside a multipart/mixed MIME part (also not guaranteed). Body-related attachments should be in a multipart/related MIME part along with the body that refers to them.
code4tips
@code4tips
Oct 01 2018 17:12
Hi, for IDCompressorZlib.DeflateStream and InflateStream is there any way to track progress?
Remy Lebeau
@rlebeau
Oct 01 2018 17:24
@code4tips not directly. The only way is to wrap the input and/or output stream(s) with one(s) that override the Read()/Write() methods to track howw many bytes are being processed (for instance, Indy's TIdEventStream)
code4tips
@code4tips
Oct 01 2018 17:31
I have Indy 10.6.2, and cannot resolve TIdEventStream - was it renamed? Or is there a newer version, also someone posted a workaround on GitHub, looks like you have to patch the ZLib.pas https://github.com/madler/zlib/blob/master/contrib/delphi/ZLib.pas.
Remy Lebeau
@rlebeau
Oct 01 2018 17:32
@code4tips No, it was not renamed. It is in the IdGlobal unit
@code4tips that is Borland's code, not Indy's. Certainly, if you use the ZLib API directly, you can track progress. But your question wasn't about ZLib itself, it was about Indy's IdCompressorZLib wrapper, which doesn't expose progress (because it is not meant to be used directly, it is used by TIdHTTP)
code4tips
@code4tips
Oct 01 2018 17:34
IdCompressorZlib is what I am using. Found the TTidEventSTream. Thanks.
Marcos Douglas B. Santos
@mdbs99
Oct 01 2018 21:24

@rlebeau @mezen

Body-related attachments should be in a multipart/related MIME part along with the body that refers to them.

So, if I want to get all attachments but not body-related ones, I guess I need to test like this:

       // ...
        else if part.PartType = mptAttachment then
        begin
          // get attachment, if it's NOT body-related
          if not IsHeaderMediaType(part.ContentType, 'multipart/related') then
            mail.AddAttachment(TIdAttachment(part));
        end;

Am I right?

Remy Lebeau
@rlebeau
Oct 01 2018 21:46
@mdbs99 if you are going to do ContentType checking like that, you need to check the PARENT'S type, not the attachment's type, more like this instead:
else if part.PartType = mptAttachment then
begin
  if (
    (part.ParentPart = -1) and not IsHeaderMediaType(mail.ContentType, 'multipart/related')
    )
    or (
    (part.ParentPart <> -1) and not IsHeaderMediaType(mail.MessageParts[part.ParentPart].ContentType, 'multipart/related')
    ) then
    mail.AddAttachment(TIdAttachment(part));
end;
@mdbs99 or this, which is cleaner:
var
  ct: string;
...
else if part.PartType = mptAttachment then
begin
  if part.ParentPart = -1 then
    ct := mail.ContentType
  else
    ct := mail.MessageParts[part.ParentPart].ContentType;
  if not IsHeaderMediaType(ct, 'multipart/related') then
    mail.AddAttachment(TIdAttachment(part));
end;