![]() |
Sample 10.3 POP3 code moving from Indy 9 on D7 - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Indy (https://www.atozed.com/forums/forum-8.html) +--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html) +--- Thread: Sample 10.3 POP3 code moving from Indy 9 on D7 (/thread-974.html) |
Sample 10.3 POP3 code moving from Indy 9 on D7 - jackmason@mindspring.com - 02-27-2019 Converted our D7 & Indy 9 application to Studio 10.3 & Indy 10 with one exception: POP3 email processing. Under Indy 9, our code worked as we wished. Moving to Indy 10 apparently requires an additional module which we have yet to identify. The following identifiers become 'undeclared idenitifier": [ if (EmailMsg.MessageParts.Items[Jdx] is TIdAttachment) then if EmailMsg.MessageParts.Items[Jdx] is TIdText then pnlAttachments.visible := true; li := lvMessageParts.Items.Add; li.ImageIndex := 8; li.Caption := TIdAttachment(Msg.MessageParts.Items[Jdx]).Filename; li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[Jdx]).ContentType); ] We greatly appreciate the Indy Project it has been a great assistance to us since the release of Indy9. Jack RE: Sample 10.3 POP3 code moving from Indy 9 on D7 - rlebeau - 02-28-2019 Which identifiers is the compiler complaining about exactly? Please be more specific. Is it complaining about TIdAttachment and TIdText, by chance? If so, you need to add the IdAttachment and IdText units to your uses clause. In Indy 9, everything was in the IdMessage unit. In Indy 10, things like TIdMessageParts, TIdText, TIdAttachment, etc have been broken out into their own units. Also, your code is a little confusing, as an item in the TIdMessage.MessageParts collection can't be both a TIdAttachment and a TIdText at the same time, and type-casting a TIdText to a TIdAttachment is wrong. I think you are missing some begin..end blocks in this code, or maybe the TIdText check doesn't belong at all. RE: Sample 10.3 POP3 code moving from Indy 9 on D7 - jackmason@mindspring.com - 02-28-2019 When I add TIdMessageParts, TIdText, and TIdAttachment to the uses clause, Delphi 10.3 flags them as unknown identifiers. Sorry, I did not include all the code..... just the parts Delphi 10.3 complained about. Here is the actual code: Code: EmailCount := Pop3.CheckMessages; // How many emails are waiting RE: Sample 10.3 POP3 code moving from Indy 9 on D7 - rlebeau - 03-01-2019 (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: 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: 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: 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 (02-28-2019, 04:40 PM)jackmason@mindspring.com Wrote: 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 RE: Sample 10.3 POP3 code moving from Indy 9 on D7 - jackmason@mindspring.com - 03-01-2019 ![]() Thank you very much. I should have known that and been paying more attention to your first response. However, in my defense, your subsequent responses provide valuable information I needed. Thank you again, very much!! ![]() |