Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample 10.3 POP3 code moving from Indy 9 on D7
#4
(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote: When I add TIdMessageParts, TIdText, and TIdAttachment to the uses clause, Delphi 10.3 flags them as unknown identifiers. 

Please re-read my previous reply again more carefully.  I did not say to add TIdMessageParts, TIdText, and TIdAttachment to the uses clause, I said to add IdMessageParts, IdText, and IdAttachment instead.  Indy's unit names do not begin with T, class types do.  There is a difference between a unit name and a class name.  You should know this, as it is basic Delphi 101 kind of stuff.

(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote: Sorry, I did not include all the code..... just the parts Delphi 10.3 complained about.  Here is the actual code:

I see a few issues with that code.

(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote:
Code:
Header := EmailMsg.Headers.Text;
Jdx := Pos('Message-ID', Header);
Order_ID := Copy(Header, Jdx + 13, 100);

Use the TIdMessage.MsgId property instead of parsing the TIdMessage.Headers.Text manually:

Code:
Order_ID := EmailMsg.MsgId;

(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote:
Code:
for Jdx := 0 to Pred(EmailMsg.MessageParts.Count) do

Depending on the actual format of the email, technically the proper way to handle MIME-encoded emails is to process the parts in reverse order, as they are supposed to be ordered from least complex to most complex, and also take MIME nesting levels into account by looking at their ParentPart and ContentType properties.  Loop through the MessageParts from back to front handling only the items whose ParentPart is -1.  If you discover an item whose ContentType is "multipart/..." and you want to dig into its child parts, then loop through the MessageParts again from back to front looking for child items whose ParentPart is the parent item's Index.  And so on, recursively, as needed.

(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote:
Code:
if (EmailMsg.MessageParts.Items[Jdx] is TIdAttachment) then
begin //general attachment

For instance, you can also take the attachment's ParentPart property into account to ignore attachments that are not really meant for the user, for instance those that are embedded media used inside of HTML emails, eg:

Code:
if (EmailMsg.MessageParts.Items[Jdx] is TIdAttachment) then
begin //general attachment
 ParentIdx := EmailMsg.MessageParts.Items[Jdx].ParentPart;
 if ParentIdx <> -1 then
   ParentContentType := EmailMsg.MessageParts.Items[ParentIdx].ContentType
 else
   ParentContentType  := EmailMsg.ContentType;
 //if not IsHeaderMediaType(ParentContentType, 'multipart/mixed') then
 if IsHeaderMediaType(ParentContentType, 'multipart/related') then
     Continue;
 ...
end
else
...

(02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote:
Code:
if EmailMsg.MessageParts.Items[Jdx] is TIdText then
begin
 Parse[Jdx] := EMailMsg.TIdText(EmailMsg.MessageParts.Items[Jdx]).Body;

EMailMsg.TIdText(...) is wrong syntax, EMailMsg.TIdText should be just TIdText by itself:

Code:
Parse[Jdx] := TIdText(EmailMsg.MessageParts.Items[Jdx]).Body;

Also, not all TIdText objects are text content meant for the user, either.  "multipart/..." items use TIdText, too.  You need to pay attention to the ContentType when looking for text to process, eg:

Code:
if EmailMsg.MessageParts.Items[Jdx] is TIdText then
begin
 if IsHeaderMediaType(EmailMsg.MessageParts.Items[Jdx].ContentType, 'text/plain') then
 begin
   Parse[Jdx] := TIdText(EmailMsg.MessageParts.Items[Jdx]).Body;
   ...
 end
 else if IsHeaderMediaType(EmailMsg.MessageParts.Items[Jdx].ContentType, 'text/html') then
 begin
   ...
 end;
end;

Reply


Messages In This Thread
RE: Sample 10.3 POP3 code moving from Indy 9 on D7 - by rlebeau - 03-01-2019, 07:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)