ANSI C mbox library?

J

Jonathan Pritchard

Does anyone know of a library to read/write mbox format (used to store
emails e.g. in Thunderbird) in ANSI C (cross platform is key)?

Is there a more appropriate place to ask this?
 
A

Adam Shea

Does anyone know of a library to read/write mbox format (used to
store emails e.g. in Thunderbird) in ANSI C (cross platform is key)?

Is there a more appropriate place to ask this?

I know it's a bit OT, but if I remember correctly, the mbox format is
relatively simple to use with the stdio functions. It's just a text
file with messages ended with a . by itself. Just do some google on
the format and you should be able to parse it with no problem.

cura,
Adam Shea.
 
S

Stephen Sprunk

Jonathan Pritchard said:
Does anyone know of a library to read/write mbox format (used to store
emails e.g. in Thunderbird) in ANSI C (cross platform is key)?

Is there a more appropriate place to ask this?

Use stdio.h.

mbox format is simple text, delimited (at least on unix systems) by a
line that starts with "From " -- note the space and lack of colon.
There is absolutely nothing else special about the file.

S
 
R

Richard Bos

Stephen Sprunk said:
Use stdio.h.

mbox format is simple text, delimited (at least on unix systems) by a
line that starts with "From " -- note the space and lack of colon.
There is absolutely nothing else special about the file.

That's dangerous.

From the above specification, it would appear that this not one message.

Richard
 
R

Richard Tobin

Does anyone know of a library to read/write mbox format (used to store
emails e.g. in Thunderbird) in ANSI C (cross platform is key)?
[/QUOTE]
Use stdio.h.

mbox format is simple text, delimited (at least on unix systems) by a
line that starts with "From " -- note the space and lack of colon.
There is absolutely nothing else special about the file.

True, but presumably the OP is looking for a library in standard C
that separates the messages, parses the message headers and so on.

Probably the "mail" program on any free unix system includes such
functions, though whether they are nicely packaged as a library is
another matter.

-- Richard
 
J

Jonathan Pritchard

Use stdio.h.

mbox format is simple text, delimited (at least on unix systems) by a
line that starts with "From " -- note the space and lack of colon.
There is absolutely nothing else special about the file.

True, but presumably the OP is looking for a library in standard C
that separates the messages, parses the message headers and so on.

Probably the "mail" program on any free unix system includes such
functions, though whether they are nicely packaged as a library is
another matter.

-- Richard[/QUOTE]

First off, thank-you for the replies.

I have looked at the specification, and even then it is quite simple. I
know that each message has an ID, and that the messages are seperated by
a new line (however, there are newlines inside the message content, so
would need to search for From:... as well).

I've been googling for mbox and mbox library and mbox.c etc. and it may
be that KMail's library is written in C, I could use that perhaps.

Just wandering if anyone knew of one, that I hadn't found.

Thanks again.
 
C

Chris F.A. Johnson

First off, thank-you for the replies.

I have looked at the specification, and even then it is quite simple. I
know that each message has an ID, and that the messages are seperated by
a new line (however, there are newlines inside the message content, so
would need to search for From:... as well).

No, you need to search for "From " at the beginning of a line
following a blank line. You should also check that the rest of the
line is correct for the From line (the date format is very
specific).
I've been googling for mbox and mbox library and mbox.c etc. and it may
be that KMail's library is written in C, I could use that perhaps.

Just wandering if anyone knew of one, that I hadn't found.

Look at the source code for formail (part of the procmail package).
 
J

jmcgill

Richard said:
That's dangerous.

From the above specification, it would appear that this not one message.

Richard

That is a problem in many mail systems. Because of this issue, it is
not uncommon for mailers to insert a character before a line beginning
with "From" if it follows an empty line in an email body.

It's a nuisance, but it's hardly "dangerous", and it is well-specified.

http://www.qmail.org/man/man5/mbox.html
 
S

Stephen Sprunk

Richard Bos said:
That's dangerous.

From the above specification, it would appear that this not one
message.

No, it means that your message cannot be stored in an mbox file without
modification. sendmail, procmail, and various other programs will
prepend a ">" before any lines in the message itself that start with
"From " while storing it into the mbox file.

I've gotten so used to this that when I start a sentence with "From", I
put a space before it so that the readers don't end up seeing ">From"
and mistake what I wrote for a quote. The '>' is _not_ to be removed
when the message is extracted, which you might expect, in case it _was_
part of a quote.

S
 
J

Jonathan Pritchard

Chris said:
No, you need to search for "From " at the beginning of a line
following a blank line. You should also check that the rest of the
line is correct for the From line (the date format is very
specific).


Look at the source code for formail (part of the procmail package).

Yes, that is what I meant. That I would have to not only identify the
newline, but probably the from too. Thanks for the pointer. Now I have
to learn how to write a library.
 
R

Richard Bos

Stephen Sprunk said:
No, it means that your message cannot be stored in an mbox file without
modification. sendmail, procmail, and various other programs will
prepend a ">" before any lines in the message itself that start with
"From " while storing it into the mbox file.

I've gotten so used to this that when I start a sentence with "From", I
put a space before it so that the readers don't end up seeing ">From"
and mistake what I wrote for a quote. The '>' is _not_ to be removed
when the message is extracted, which you might expect, in case it _was_
part of a quote.

A stunningly creative solution to a stunningly creative problem.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top