Subject: message/rfc822 attachments include headers in both header and body?

From: Charles Dorner <[email-masked]>
Date: Thu, 02 Dec 2004 15:25:12 -0800

I'm trying to determine if I'm making a mistake in formating or if this 
is normal behavior.

Create an e-mail, add a part, take the forwarded e-mail, put the text in 
part->body with type TYPEMESSAGE and subtype "rfc822".  send the message.

When it is recieved, c-client returns the headers in calls to both 
mail_fetch_header and mail_fetch_body when given the section number for 
the embedded message.  Is this supposed to happen or is there a problem 
in the message that I need to reformat part of it?

Thanks,

Charles

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

---

From: Mark Crispin <[email-masked]>
Date: Thu, 2 Dec 2004 15:55:45 -0800 (Pacific Standard Time)

On Thu, 2 Dec 2004, Charles Dorner wrote:
> mail_fetch_header and mail_fetch_body when given the section number for the 
> embedded message.  Is this supposed to happen or is there a problem in the 
> message that I need to reformat part of it?

Do they return the same data?

Or does mail_fetch_header() return just the header and mail_fetch_body() 
returns the entire message?

Remember that these are not null-terminated strings; they are size-count 
strings.

I suspect that the answers to the above questions are "no" and "yes" 
respectively.  You should check that, just to be sure.  If that is the 
case, can you then guess how to get the text of the message and the first 
body part?

If you're still stumped, let me know and I'll carry you through the next 
step.

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.

---

From: Charles Dorner <[email-masked]>
Date: Thu, 02 Dec 2004 16:23:51 -0800

On both questions, you guessed correctly; I was more focused on why the 
body was the header+body together.  As long as this is the appropriate 
behavior from c-client, everything is jolly.  I had previously 
implemented the obvious hack to just count the header and remove that 
prefix from the body.  However, I wanted to verify that there wasn't 
more of a problem with section numbers, message format, or something 
else lurking in the shadows.  Thanks!

Charles

Mark Crispin wrote on 12/2/2004 3:55 PM:

>> mail_fetch_header and mail_fetch_body when given the section number 
>> for the embedded message.  Is this supposed to happen or is there a 
>> problem in the message that I need to reformat part of it?
>
>
> Or does mail_fetch_header() return just the header and 
> mail_fetch_body() returns the entire message?
>
> Remember that these are not null-terminated strings; they are 
> size-count strings.
>
> case, can you then guess how to get the text of the message and the 
> first body part?
>
> If you're still stumped, let me know and I'll carry you through the 
> next step.
>
> -- Mark --
>

---

From: Mark Crispin <[email-masked]>
Date: Thu, 2 Dec 2004 16:27:55 -0800 (Pacific Standard Time)

On Thu, 2 Dec 2004, Charles Dorner wrote:
> On both questions, you guessed correctly; I was more focused on why the body 
> was the header+body together.  As long as this is the appropriate behavior 
> from c-client, everything is jolly.  I had previously implemented the obvious 
> hack to just count the header and remove that prefix from the body.  However, 
> I wanted to verify that there wasn't more of a problem with section numbers, 
> message format, or something else lurking in the shadows.  Thanks!

You don't need to count the header; you can get the message text directly.

mail_fetch_text() will fetch the raw message text (without the header).

To get the first body part of the message text (as in a encapsulated MIME 
message), you need to add ".1" to the section specifier.

Are you starting to see how it works?

-- Mark --

---

From: Charles Dorner <[email-masked]>
Date: Thu, 02 Dec 2004 16:46:19 -0800

>
>
> To get the first body part of the message text (as in a encapsulated 
> MIME message), you need to add ".1" to the section specifier.
>

Strange, I thought section numbers worked differently.  So then, 
assuming that an e-mail has a single embedded message, I would want 
section 2 for mail_fetch_header and section 2.1 for mail_fetch_body?

---

From: Mark Crispin <[email-masked]>
Date: Thu, 2 Dec 2004 16:58:55 -0800 (Pacific Standard Time)

On Thu, 2 Dec 2004, Charles Dorner wrote:
> Strange, I thought section numbers worked differently.  So then, assuming 
> that an e-mail has a single embedded message, I would want section 2 for 
> mail_fetch_header and section 2.1 for mail_fetch_body?

If an email consists solely of a single embedded message, it would be 
section 1 instead of section 2.  Presumably, if you are using section 2, 
you have an email with a primary text content and an embedded message as 
an attachment, e.g.
 	MULTIPART/MIXED
 	 TEXT/PLAIN		"primary text content"
 	 MESSAGE/RFC822		"embedded message"

In that case, then the following is true:

mail_fetch_body() returns the entire body part
 	section 1	=> primary text content
 	section 2	=> entire embedded message
 	section 2.1	=> first MIME part of embedded message
 	section 2.2	=> second MIME part of embedded message
 		etc.

mail_fetch_header() returns the header of messages only
 	null section	=> top level header
 	section 2	=> header of embedded message

mail_fetch_text() returns the text of messages only
 	null section	=> top level text
 	section 2	=> embedded message text

Note that you can not call mail_fetch_header() or mail_fetch() text on 
section 1, nor can you call it on sections 2.1 or 2.2 unless those are 
also MESSAGE/RFC822 parts.

Is it starting to make sense yet?

The learning curve for how section numbers work *is* steep.  The good news 
is that, when you finally understand the theory of section numbers, it'll 
be light a light bulb turning on in your head and then you can't imagine 
how it could be any other way.

I thrashed through all of this when I developed it, and went through 
several different theories before I finally ended up with this one.

If you are familiar with IMAP (RFC 3501), c-client section numbers are 
similar to IMAP section numbers, only in c-client they are always numeric.

mail_fetch_body()		=> <section>
mail_fetch_header()		=> [<section>.]HEADER
mail_fetch_text()		=> [<section>.]TEXT
mail_fetch_mime()		=> <section>.MIME

In other words, mail_fetch_header() of section 2 is IMAP section 2.HEADER 
and mail_fetch_text() of section 2 is IMAP section 2.TEXT ...

-- Mark --