Board index » delphi » Malformed email or Indy bug?

Malformed email or Indy bug?


2003-08-25 08:32:53 PM
delphi132
Hello,
I am writing a service to check emails periodically. Unfortunately,
there are some emails that always cause problems. The latest is the
email following (all email adresses taken out). It is a message one of
our clients has sent us to clarify where the other messaes come from.
Note that the attachments probably have been messages by a virus. This
message has been scanned and passed our Antivirus, so it is not harmful
as is.
The problem I have is to save the attachments to disk. What I do is
TIdAttachment(Msg.MessageParts.Items[j]).SaveToFile(att);
with att being a full path and filename (no duplicates can exist).
I get an exception " Error saving attachment." and the filename states
to be "age/rfc822" - part of the content-type.
Is this email conform the standards, and what do I need to add to my
code to consider attachments without a filename?
****
X-UIDL-JANA-SERVER: 1061643518.4331
Return-path: <emailadr>
Envelope-to: emailadr
Delivery-date: Sat, 23 Aug 2003 14:58:38 +0200
Received: from [194.65.5.200] (helo=fep01-svc.mail.telepac.pt)
by mxng03.kundenserver.de with esmtp (Exim 3.35 #1)
id 19qXyV-0006qA-00
for emailadr; Sat, 23 Aug 2003 14:58:35 +0200
Received: from Principal ([213.13.22.247]) by fep01-svc.mail.telepac.pt
(InterMail vM.5.01.04.13 201-253-122-122-113-20020313) with
SMTP
id
<20030823125833.UXYN28255.fep01-svc.mail.telepac.pt@Principal>
for <emailadr>;
Sat, 23 Aug 2003 13:58:33 +0100
From: "J.Ramalho" <emailadr>
To: "Nuno Ricardo Blochberger" <emailadr>
Subject: E-mails estranhos
Date: Sat, 23 Aug 2003 13:58:40 +0100
Message-ID: <NGBBIEJOGLJCEAGAINCDMEPECNAA.emailadr>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0003_01C3697E.A84C3BF0"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
This is a multi-part message in MIME format.
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
J??a segunda vez que recebo este tipo de e-mails.
São enviados desde 'eurosolution-se.com' e o anti-virus não os refere.
Sabe o que ?isto ???
cumprimentos
Jos?Ramalho
emailadr
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=28218.?=
=?iso-8859-1?Q?241.68.19:8080=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?_dO_z_l_hKqBc8ILx__cuSya4__1_Zq4VS6BI_A_yT__UA0XOYM82Z1B_i?=
=?iso-8859-1?Q?B9iI1tT_hL_TcAp1e_AIc8_v=FFFFFFCCabcdefghijklmnopqrstuvqxy?=
=?iso-8859-1?Q?zABCDEFGHIJKLMNOP_._?=
Date: Sat, 23 Aug 2003 13:31:19 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at
08:31:19
---------------------------------------------------------------------------
body: jrvNLY5YMuuFY8h
dO z
l hKqBc8ILx cuSya4 1 Zq4VS6BI
A yT
UA0XOYM82Z1B iB9iI1tT
hL TcAp1e AIc8 vÿFFFFCCabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOP
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=28218.?=
=?iso-8859-1?Q?241.68.19:8080=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?_dO_z_l_hKqBc8ILx__cuSya4__1_Zq4VS6BI_A_yT__UA0XOYM82Z1B_i?=
=?iso-8859-1?Q?B9iI1tT_hL_TcAp1e_AIc8_v=FFFFFFCCabcdefghijklmnopqrstuvqxy?=
=?iso-8859-1?Q?zABCDEFGHIJKLMNOP_._?=
Date: Sat, 23 Aug 2003 13:31:12 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at
08:31:12
---------------------------------------------------------------------------
body: jrvNLY5YMuuFY8h
dO z
l hKqBc8ILx cuSya4 1 Zq4VS6BI
A yT
UA0XOYM82Z1B iB9iI1tT
hL TcAp1e AIc8 vÿFFFFCCabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOP
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=28200.?=
=?iso-8859-1?Q?204.183.199:8081=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?HnYR_jWq2m_83__n_f_kYYs08hhIjla_eDrH_Sqn17eM_N8Xd7yBmlI9Y_?=
=?iso-8859-1?Q?_LOH_E__zAfF_vWI_h__v_H388=FFFFFFCCabcdefghijklmnopqrstuvq?=
=?iso-8859-1?Q?xyzABC_._?=
Date: Sat, 23 Aug 2003 13:30:55 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at 08:30:55
---------------------------------------------------------------------------
body: k H xACOkl
4HyAHnYR jWq2m 83 n f
kYYs08hhIjla eDrH
Sqn17eM N8Xd7yBmlI9Y
LOH E zAfF
vWI
h
v H388ÿFFFFCCabcdefghijklmnopqrstuvqxyzABC
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=28200.?=
=?iso-8859-1?Q?204.183.199:8081=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?HnYR_jWq2m_83__n_f_kYYs08hhIjla_eDrH_Sqn17eM_N8Xd7yBmlI9Y_?=
=?iso-8859-1?Q?_LOH_E__zAfF_vWI_h__v_H388=FFFFFFCCabcdefghijklmnopqrstuvq?=
=?iso-8859-1?Q?xyzABC_._?=
Date: Sat, 23 Aug 2003 13:30:51 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at 08:30:51
---------------------------------------------------------------------------
body: k H xACOkl
4HyAHnYR jWq2m 83 n f
kYYs08hhIjla eDrH
Sqn17eM N8Xd7yBmlI9Y
LOH E zAfF
vWI
h
v H388ÿFFFFCCabcdefghijklmnopqrstuvqxyzABC
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=2861.1?=
=?iso-8859-1?Q?1.72.218:6588=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?EjYbJ9_4G_MRVtqtCLi_btqIPLb1_O0n8x_EI_q97QAtW_6XZXcaV_g3L9?=
=?iso-8859-1?Q?HrqSTVfGB_yyz_Hr3lnX0fz=FFFFFFCCabcdefghijklmnopqrstuvqxyz?=
=?iso-8859-1?Q?ABC_._?=
Date: Sat, 23 Aug 2003 13:30:39 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at 08:30:39
---------------------------------------------------------------------------
body: U7z N
dFR MVMXEo8xEjYbJ9
4G
MRVtqtCLi btqIPLb1 O0n8x
EI
q97QAtW 6XZXcaV
g3L9HrqSTVfGB yyz Hr3lnX0fzÿFFFFCCabcdefghijklmnopqrstuvqxyzABC
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
From: <XXXX@XXXXX.COM>
To: <XXXX@XXXXX.COM>
Subject:
=?iso-8859-1?Q?www.eurosolution-se.com/cgi-sys/formmail.pl_=28213.?=
=?iso-8859-1?Q?229.58.218:80=29__bcc:XXXX@XXXXX.COM?=
=?iso-8859-1?Q?kuMNz_aYb78_vBW_Ms_Hs_q2hdRTEWx_Txdc8UzY__f_i__fZKxqa_q_3_?=
=?iso-8859-1?Q?f_1o28R_NPooG_PK68PrGq7=FFFFFFCCabcdefghijklmnopqrstuvqxyz?=
=?iso-8859-1?Q?ABCDEFGHIJKLMNOP_._?=
Date: Sat, 23 Aug 2003 13:30:37 +0100
Message-ID: <XXXX@XXXXX.COM>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: NMS FormMail 3.09c1
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200
X-POP3-Rcpt: XXXX@XXXXX.COM
Below is the result of your feedback form. It was submitted by
(XXXX@XXXXX.COM) on Saturday, August 23, 2003 at
08:30:37
---------------------------------------------------------------------------
body: Ong
oytlhDhJ m5 VekuMNz
aYb78 vBW
Ms Hs q2hdRTEWx Txdc8UzY f i fZKxqa q 3
f 1o28R
NPooG PK68PrGq7ÿFFFFCCabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOP
---------------------------------------------------------------------------
------=_NextPart_000_0003_01C3697E.A84C3BF0--
****
--
Dipl. Inform. (FH) Sabine Dinis Blochberger
Op3racional
s.blochberger @ op3racional.de
www.op3racional.de (portuguese, english, german, dutch)
 
 

Re:Malformed email or Indy bug?

Sabine Dinis Blochberger wrote on Mon, 25 Aug 2003 13:32:53 +0100:
Follow-up:
To not lose any data, I'd like to store the full email (with the
attachments in the body). How could I do this?
Right now it is handled like this:
****
if (Msg.MessageParts.Count <>0) OR
(Pos('multipart/', Msg.ContentType) <>0) then
begin
// try to fix the quoted-printable bug
with Msg.MessageParts do
if (Count = 1) and
(Items[0] is TidText) and
(Items[0].ContentType = '') then
Items[0].ContentType := Msg.ContentType;
// this is a multipart mime message
// msg.body is invalid
for j := 0 to Msg.MessageParts.Count - 1 do
begin
if (Msg.MessageParts.Items[j] is TIdAttachment) then
begin
// handle attachments
// take out some special characters
fName :=
GenerateSaveFileName(TIdAttachment(Msg.MessageParts.Items[j]).Filename);
att := attachmentPath + '\' + fName;
att := GenerateUniqueFileName(att);
try
TIdAttachment(Msg.MessageParts.Items[j]).SaveToFile(att);
attList := attList + ExtractFileName(att) + Chr(13);
except on e:Exception do
WriteToLog('EMAIL: exception in domessages: '+e.Message+'
while saving to '+att+' of msg nr. '+inttostr(i));
end; {end try}
end else
// handle body text
if Msg.MessageParts.Items[j] is TIdText then
if Pos('text/plain', Msg.MessageParts[j].ContentType)>0 then
// it is a text part...
for k := 0 to
TIdText(Msg.MessageParts.Items[j]).Body.Count-1 do // save body text
mensagem := mensagem +
TIdText(Msg.MessageParts.Items[j]).Body.Strings[k]+ Chr(13)+Chr(10)
else if Pos('text/html', Msg.MessageParts[j].ContentType)>0
then
// it is a HTML part
for k := 0 to
TIdText(Msg.MessageParts.Items[j]).Body.Count-1 do // save body text
mensagemHTML := mensagemHTML +
TIdText(Msg.MessageParts.Items[j]).Body.Strings[k]+ Chr(13)+Chr(10);
end; { end for }
end else { end if }
begin
// this is a text/* message
// idMessage.Body contains the entire body
for j := 0 to Msg.Body.Count-1 do // save body text
mensagem := mensagem + Msg.Body.Strings[j] + Chr(13)+Chr(10);
end;
****
--
Dipl. Inform. (FH) Sabine Dinis Blochberger
Op3racional
s.blochberger @ op3racional.de
www.op3racional.de (portuguese, english, german, dutch)
 

Re:Malformed email or Indy bug?

Hi!
Try this for saving the whole email:
IdPop31.RetrieveRow(i, IdMEssage1)
IdMessage1.SaveToFile()
Good luck...
 

Re:Malformed email or Indy bug?

"Kirilov" <XXXX@XXXXX.COM>writes:
Quote

Hi!
Try this for saving the whole email:
IdPop31.RetrieveRow(i, IdMEssage1)
IdMessage1.SaveToFile()

Good luck...
because SaveToStream has free vStream.
 

Re:Malformed email or Indy bug?

Kirilov wrote on 26 Aug 2003 14:22:06 -0700:
Quote

Hi!
Try this for saving the whole email:
IdPop31.RetrieveRow(i, IdMEssage1)
IdMessage1.SaveToFile()

Good luck...
Thank you! Here is the working code-snippet adapted to my needs:
****
try
TIdAttachment(Msg.MessageParts.Items[j]).SaveToFile(att);
attList := attList + ExtractFileName(att) + Chr(13);
except on e:Exception do
begin
WriteToLog('EMAIL: exception in domessages: '+
e.Message+' while saving to '+att+' of msg nr. '+inttostr(i));
RawMsg := TStringList.Create;
RawMsg.Clear;
Pop3.RetrieveRaw(i, RawMsg);
rawStr := RawMsg.Text;
RawMsg.Free;
RawMsg := nil;
end; end; {end try}
****
A bit of a crummy solution, because it will retrieve the raw message for
each attachment, but it seems to be only a small performance penalty.
--
Dipl. Inform. (FH) Sabine Dinis Blochberger
Op3racional
s.blochberger @ op3racional.de
www.op3racional.de (portuguese, english, german, dutch)