These are chat archives for IndySockets/Indy

Apr 2018
Ludwig Behm
Apr 19 2018 08:28
Something like this should break it:
TIdText *t = new TIdText(pMessage->MessageParts, NULL);
t->ContentType = "text/plain";
t->Body->Text = "Test";
TIdText *h = new TIdText(pMessage->MessageParts, NULL);
h->ContentType = "text/html";
h->Body->Text = "Test";
TIdText *a = new TIdText(pMessage->MessageParts, NULL);
a->ContentType = "multipart/alternative";
a->ParentPart = -1;
t->ParentPart = a->Index;
h->ParentPart = a->Index;
Ludwig Behm
Apr 19 2018 08:36
I intended to build up the message parts as they are needed. If someone just sets the text/plain content no message part is needed. If HTML is added, the text/plain is converted and both parts are appended to the alternative part. Same with related if a graphic is added earlier or later.
Just tried to reduce some copying.
Remy Lebeau
Apr 19 2018 16:39
@lbehm that is definately the wrong way to prepare a multipart email. You need to add the "multipart/alternative" part first, then add the "text/plain" and "text/html" parts after it and link their ParentPart to the previous "multipart/alternative" part. In short, ParentPart should always refer to an earlier part, never to a later part. If you want to convert an email from one layout to another, you basically need to start fresh with a new message and make sure you add parts to it in the correct order, copying data from old parts to new parts as needed. This will be much easier once IndySockets/Indy#139 is implemented, as you will be able to just move parts around from one collection to another. But for now, you have to do thing manually to make it work correctly. I suppose a possible workaround would be to update TIdMessage to scan the MessageParts for items with ParentPart=-1, then rescan for ParentPart=0, =1, etc. But that is a lot more work, especially for how it currently tracks and pops used MIME boundaries. Easier to just make sure the parts in the right order to begin with
Ludwig Behm
Apr 19 2018 17:06
@rlebeau No problem. As I mentioned I switched to using TIdMessageBuilderHtmlwhich is working fine.
But maybe an exception would be nice to prevent that loop?
Remy Lebeau
Apr 19 2018 17:32
@lbehm perhaps. It is easy enough to detect if the while loop runs out of MIME boundaries to send, indicating a malformed email. Raising an exception while sending an email would cause communication issues for NNTP and SMTP at least, so I would have to update them to close the socket if TIdMessage fails to encode. That would be a minor change, thoguh
Remy Lebeau
Apr 19 2018 17:45
@lbehm I just added IndySockets/Indy#209 for you