Subject: MIME parsing of non-unix-mailbox streams

From: Daniele Arena <[email-masked]>
Date: Fri, 14 Jul 2000 17:31:18 +0200 (CEST)

Hello everybody.

This list has been quiet for a while, so I thought I could send in a
stupid question, just to make it alive a bit.:-)

I am writing a fairly basic MIME parser using the c-client library (I am -
for the moment - using IMAP 4.7b).

It just does the following (well, in a simplified way):

get the stream with mail_open()
get the headers with mail_fetchheader_full()
get the body with mail_fetchstructure()
get body information with a routine very similar to display_body() of mtest.c
get the contents with a simplified case(body->type)
	If text/plain: use mail_fetchtext()
	If (some types of) multipart: use mail_fetch_mime()
  {I do not have to support all body types for this MIME parser.
   Some are just rejected.}

The problem is: this works pretty well with files which are in a so-called
"unix" mailbox format, i.e. they have as their first line

>From [email-masked] Mon Jul  3 14:56:07 2000 +0200

But I overlooked the fact that the files I'm actually going to process do
not have that line. They are just plain rfc822(+MIME) messages. And if my
parser is run on a file which does not contain that line, the status()
call (just after mail_open()) returns "This is a phile mailbox" and no
MIME parts are extracted: the whole message is seen as a single big MIME
part. Not to speak about the mail headers returned: they are definitely
wrong. So basically, the parser does not work at all.

One solution could be to dump the original message (I only have to process
one message at a time) into a temporary file, adding a dummy "From..."
first line, and escaping the lines starting with "From" in the body of the
message (so that the parser doesn't think that there is more than one
message in the file); then process that file. But this solution does not
seem very clean to me.

Would this solution work? Can anyone of you suggest a better solution to
that? Or do I have to rewrite the whole thing in a completely different
way?:-(

Thanks in advance!

				Cheers,

					Daniele.

--------------------------------------------------------------------------
Daniele Arena			RIPE Network Coordination Centre
phone  : +31 20 535 4444	Singel 258
fax    : +31 20 535 4445	1016AB Amsterdam
e-mail : [email-masked]	The Netherlands

-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------