Board index » delphi » Error loading from stream

Error loading from stream


2008-07-09 03:38:00 PM
delphi256
Hi,
I am using this code to load a message (formerly saved by using Indy9 btw)
into an idMessage component:
idMessage.clear;
ms := TEDBBlobStream.Create(dm.MessagesTableMessage, bmread);
try
ms.position := 0;
idMessage.LoadFromStream(ms,false);
ShowMessage(idMessage.Body.Text); <---------------- Error or empty
finally
ms.Free;
end;
When executing the code I get an empty result in most cases, in some cases
this error is raised: "Max line length exceeded."
Saving the same message to file as .eml from the database and loading it
into idMessage always works fine.
What could be wrong here? (Delphi2007 last Indy snapshot)
Here you find an eml-file that produces the error when loaded from
stream: www.beckersoft.de/temp/sample.eml
Thanks. Uli
 
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
ms := TEDBBlobStream.Create(dm.MessagesTableMessage, bmread);
You should use the CreateBlobStream() method instead:
ms :=
dm.MessagesTableMessage.DataSet.CreateBlobStream(dm.MessagesTableMessage,
bmRead);
Quote
When executing the code I get an empty result in most cases
What does the actual blob data look like? Most likely, the data is being
stored in the TIdMessage.MessageParts collection instead.
Quote
in some cases this error is raised: "Max line length exceeded."
By default, the maximum length that individual lines of text can be is 16384
characters. TIdTCPConnection in Indy 9, and TIdIOHandler in Indy 10, have a
MaxLineLength that you can set to increase that value if needed.
Quote
Saving the same message to file as .eml from the database and
loading it into idMessage always works fine.
TIdMessage.LoadFromFile() calls LoadFromStream() internally, so the same
logic is invoked either way.
Quote
Here you find an eml-file that produces the error when loaded from
stream: www.beckersoft.de/temp/sample.eml
That is not a valid .eml file
Gambit
 

Re:Error loading from stream

Remy,
thanks for your help.
<<
You should use the CreateBlobStream() method instead:
Quote
>
I did, and there are no empty results any more. But the error (Max line
length exceeded) is the same.
I tried to debug it and found the reason for the error here:
function TIdIOHandler.ReadLnRFC(var VMsgEnd: Boolean; const ALineTerminator:
string;
const ADelim: String = '.'; const AEncoding: TIdEncoding = en7Bit):
string;
begin
Result := ReadLn(ALineTerminator, AEncoding);
<------------------------------------------ Error
// Do not use ATerminator since always ends with . (standard)
if Result = ADelim then
begin
VMsgEnd := True;
Exit;
end;
if TextStartsWith(Result, '.') then begin {do not localize}
Delete(Result, 1, 1);
end;
VMsgEnd := False;
end;
<<
What does the actual blob data look like? Most likely, the data is being
stored in the TIdMessage.MessageParts collection instead.
Quote
>
It's exactly the content of the eml-file.
I found out that the error only occurs if there is a file-attachment in the
message.
<<
By default, the maximum length that individual lines of text can be is 16384
characters. TIdTCPConnection in Indy 9, and TIdIOHandler in Indy 10, have a
MaxLineLength that you can set to increase that value if needed.
Quote
>
I checked the blob-content. Actually there are no long lines in it.
<<
stream: www.beckersoft.de/temp/sample.eml
That is not a valid .eml file
Quote
>
It was saved by using an indy9 idMessage component. Outlook Express has no
problems to open it.
Regards Uli
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
I tried to debug it and found the reason for the error here:
You did not show the call stack leading up to ReadLnRFC().
Quote
I found out that the error only occurs if there is a file-attachment
in the message.
<snip>
I checked the blob-content. Actually there are no long lines in it.
Then it is likely calling ReadLn() on a block of binary data, not textual
data.
You did not show the actual .eml data like I asked for. It is very
important to see all of the message headers and such.
Quote
>stream: www.beckersoft.de/temp/sample.eml
>That is not a valid .eml file

It was saved by using an indy9 idMessage component.
Outlook Express has no problems to open it.
The data I see at that URL is an HTML webpage, not an .eml file.
Gambit
 

Re:Error loading from stream

Remy,
Quote
You did not show the call stack leading up to ReadLnRFC().
I'll check that out.
Quote
stream: www.beckersoft.de/temp/sample.eml
The data I see at that URL is an HTML webpage, not an .eml file.
That's weird. I just clicked on the link and was able to download the .eml
file.
Here a new try:
www.beckersoft.de/temp/test.zip
Regards Uli
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
That's weird. I just clicked on the link and was able to
download the .eml file.
Here a new try:

www.beckersoft.de/temp/test.zip
Better.
I see nothing in that message that can cause a "Max line length exceeded"
exception to be raised. Are you sure the DB blob is not stripping out CRLF
characters, by chance?
Gambit
 

Re:Error loading from stream

Remy,
Quote
I see nothing in that message that can cause a "Max line length exceeded"
exception to be raised. Are you sure the DB blob is not stripping out
CRLF characters, by chance?
I don't know how to check that, here is the (quite simple) code (I am using
ElevateDB):
procedure TForm1.Button6Click(Sender: TObject);
var
MyStream: TStream;
begin
memoRawMessage.lines.text := dm.MessagesTableMessage.value;
MyStream :=
dm.MessagesTable.CreateBlobStream(dm.MessagesTableMessage,bmread);
try
MyStream.position := 0;
try
idMessage.LoadFromStream(MyStream);
ShowMessage(idMessage.headers.text);
except
ShowMessage('Error');
end;
finally
MyStream.free;
end;
end;
Regards Uli
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
I don't know how to check that
View the raw blob data. Or save it to a file.
Gambit
 

Re:Error loading from stream

Quote
View the raw blob data. Or save it to a file.
I saved the stream to a listbox. No rows in there longer than 77 chars.
Regards Uli
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
I saved the stream to a listbox. No rows in there longer than 77 chars.
I'd rather you save it to a file. Then you can view the actual link breaks.
Loading it into a ListBox loses that information.
Gambit
 

Re:Error loading from stream

Quote
I'd rather you save it to a file. Then you can view the actual link
breaks. Loading it into a ListBox loses that information.
Sorry, I don't want to waste your time, but:TStream has no saveToFile
method. Since I am not familiar with streams I don't know how to do that.
Uli
 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
TStream has no saveToFile method.
Instantiate a separate TFileStream object and then pass the blob stream to
its CopyFrom() method, ie:
procedure TForm1.Button6Click(Sender: TObject);
var
BStream, FStream: TStream;
begin
BStream :=
dm.MessagesTable.CreateBlobStream(dm.MessagesTableMessage, bmRead);
try
FStream := TFileStream.Create('c:\blob.data', fmCreate);
try
FStream.CopyFrom(BStream, 0);
finally
FStream.Free;
end;
finally
BStream.Free;
end;
end;
Gambit
 

Re:Error loading from stream

Quote
Instantiate a separate TFileStream object and then pass the blob stream to
its CopyFrom() method, ie:
Thanks for your patience.
Here the saved blob-stream:
www.beckersoft.de/temp/blob.zip
Would you please have a look on it?
Thanks and regards Uli
 

Re:Error loading from stream

Remy,
could you already have a look on the saved stream?
Thank you.
Uli
"Uli Becker" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
>Instantiate a separate TFileStream object and then pass the blob stream
>to its CopyFrom() method, ie:

Thanks for your patience.

Here the saved blob-stream:

www.beckersoft.de/temp/blob.zip

Would you please have a look on it?

Thanks and regards Uli

 

Re:Error loading from stream

"Uli Becker" <XXXX@XXXXX.COM>writes
Quote
Here the saved blob-stream:

www.beckersoft.de/temp/blob.zip

Would you please have a look on it?
Your data is using CR for all of its line breaks instead of using LF or
CRLF, as required by not only Indy but also the RFC standards for email
messages in general. That is why you are getting the "Max line length
exceeded" error. You need to fix your data.
Gambit