TIdText a Boundary

Giganews Newsgroups
Subject: TIdText a Boundary
Posted by:  FrantiĊĦek FILIP (f.fil…@ha-soft.cz)
Date: Fri, 9 Mar 2007

Hello,
I'm performing digital signature on email with CryptoAPI. When email is
created just from one part, everything works correctly. The problem
occurs when
there are more parts (for example TIdText + TIdText). For digital
signature, there has to be created just one data block (here is code):

var
SMTP:      TIdSMTP;
Message1:  TIdMessage;

with TidText.Create(Message1.MessageParts) do
begin
ContentType := 'multipart/mixed';
end;

with TidText.Create(Message1.MessageParts) do
begin
ContentType := 'text/plain';
CharSet    := 'iso-8859-2';
ContentTransfer := '7bit';
Body.Text  := 'My data!!';
ParentPart := 0;
end;

with TidText.Create(Message1.MessageParts) do
begin
ContentType := 'text/plain';
CharSet    := 'iso-8859-2';
ContentTransfer := '7bit';
Body.Text  := 'My data 2!!';
ParentPart := 0;
end;

When the email is created, I call my signature function, which saves
email into the stream. There is removing redundant code, and the rest of
data is correctly signed:

Message1.ContentType := 'multipart/signed;' + '
protocol="application/x-pkcs7-signature";' + ' micalg=SHA1';

with TIdAttachmentMemory.Create(Message1.MessageParts) do
begin
ContentType := 'application/x-pkcs7-signature';
FileName    := 'smime.p7s';
DataString := <<< sign
end;

Next step is sending email with SMTP.Send(Message1). Here is the
problem, because there is performed creation of email and property
Boundary is chnaged
in first TIdText. Then, this mail isn't valid, because its HASH has
changed.

The question is, how can I avoid change Boundary after its saving to
stream? Or how have I to set Boundary for problematic TIdText?

I know to set global Boundary, but generated email has added random
char to TIdText.Boundary.

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat    << GLobalni Boundary
Content-Type: multipart/mixed;
        boundary="TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat0"  <<<<< Added 0
at the end, how is it possible to set?

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat0
Content-Type: text/plain ; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

My data!!

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat0
Content-Type: text/plain ; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

My data2!!

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat0--

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat
Content-Type: application/x-pkcs7-signature;
        name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="smime.p7s"

.....

--TwO=_gVmwsmLmxagg26P5eY8yzeEvA4oat--

Thanks for any help

Franta

--

Replies