Re: reading and store emails from a file

Giganews Newsgroups
Subject: Re: reading and store emails from a file
Posted by:  Remy Lebeau (TeamB) (
Date: Mon, 19 Jan 2004

"Stan" <an.…> wrote in message

> I can do  msg.savetostream to save multiple emails
> to a file, but how do I read the emails back?

As long as each message is separated by a "." on its own line, then you
should be able to just keep calling ProcessMessage() for each message in the

>  vMsgClient.ProcessMessage(Msg, vStream, true);

What exactly are you storing in the file anyway?  Are you really only
storing headers, or are you storing full messages instead?  Why are you
specifying True for the HeadersOnly parameter?  If you are storing multiple
full messages into the same file/stream, then that is going to mess up your
reading unless you seek the stream manually after calling ProcessMessage().

There is another alternative you could consider - Windows has a concept of
"compund files", which is basically a way to have multiple data blocks
stored in a file in a structured manner.  With that, you could store
multiple data blocks in a single file,. where each data block represents
individual TIdMessage contents.  Every data block is represented by an
IStream interface in the file.  The VCL has a TStreamAdapter class for
mapping TStream to IStream and vice versa, so you could still use
TIdMessage's SaveToStream() and LoadFromStream() methods when needed.




In response to

reading and store emails from a file posted by Stan on Sat, 17 Jan 2004