Subject: Creating ENVELOPE and BODY from a string

From: Akmal Khodjanov <[email-masked]>
Date: Wed, 3 Nov 2004 00:51:48 +0500

Hello list,

I'm really a newbie in c-client. Could somebody instruct me if I'm
doing something wrong here. The contents of the envelope is getting
parsed just fine, but the body contents are empty.

char *msg;        // I'm placing the message into this string
char *bodystring; // that's where the body string actually is after cutting off the header part
int hdrLength;    // the length of the header, calculated when I was cutting off the header part

ENVELOPE *env = NIL;
BODY *body = NIL;
STRING str;
INIT(&str, mail_string, const_cast<char *>(bodystring), strlen(bodystring));
rfc822_parse_msg(&env, &body, const_cast<char *>(msg), hdrLength, &str, "", 0);

Thanks a lot in advance, any help is appreciated.

-- 
Best regards,
 Akmal
-----------------------------------
"I have a quantum car. Every time I look at the speedometer I get lost..."

-- 
------------------------------------------------------------------
 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: Tue, 2 Nov 2004 12:20:50 -0800 (Pacific Standard Time)

Your call looks right, although the "host" argument should not be an empty 
string; if you don't want to specify a localhost pass a NIL argument to 
default to the internal BADHOST.

When you say "the body contents are empty" what do you mean?  At the very 
least you should have a TEXT/PLAIN body passed back.

Also, why are you calling rfc822_parse_msg()?  This is a very low-level 
routine in c-client.  For most purposes, you would use the higher level 
mail_fetch_structure() instead.  If you use the low-level routines, you 
may be causing yourself a lot more work than is necessary.

-- Mark --

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

---

From: Akmal Khodjanov <[email-masked]>
Date: Wed, 3 Nov 2004 02:00:07 +0500

Dear Mark,

Thanks for such operative respond.

For example I'm passing to rfc822_parse_msg this:
// start
From: Akmal Khodjanov <[email-masked]>
Subject: Testing message
To: [email-masked]
Message-ID: <[email-masked]>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Disposition: INLINE

Hello there,

this is a test.
-akmal.
// end

after rfc822_parse_msg when I try to ouput the envelope and body
contents I get this:
// start
Date: Wed, 3 Nov 2004 01:50:12 +0500 (West Asia Standard Time)
From: Akmal Khodjanov <[email-masked]>
Sender: Akmal Khodjanov <[email-masked]>
Reply-To: Akmal Khodjanov <[email-masked]>
Subject: Testing message
To: [email-masked]
Message-ID: <[email-masked]>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Disposition: INLINE

// end

As you see, in the second output I don't have body part, and can't figure
out why.

The reason why I wanted to use rfc822_parse_msg is to create c-client
envelope and body from plain text file where email message could be
saved, say in *.msg format. If there is any other option of doing this
please let me know.

Thanks.

-akmal.

-- 
Best regards,
 Akmal
-----------------------------------
"I do not feel obliged to believe that the same God who has endowed
us with sense, reason, and intellect has intended us to forgo their use."
≈ Galileo Galilei.
.......................................................

Wednesday, November 3, 2004, 1:20:50 AM, you wrote:

MC> Your call looks right, although the "host" argument should not be an empty
MC> string; if you don't want to specify a localhost pass a NIL argument to
MC> default to the internal BADHOST.

MC> When you say "the body contents are empty" what do you mean?  At the very
MC> least you should have a TEXT/PLAIN body passed back.

MC> Also, why are you calling rfc822_parse_msg()?  This is a very low-level
MC> routine in c-client.  For most purposes, you would use the higher level
MC> mail_fetch_structure() instead.  If you use the low-level routines, you
MC> may be causing yourself a lot more work than is necessary.

MC> -- Mark --

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

---

From: Mark Crispin <[email-masked]>
Date: Tue, 2 Nov 2004 14:18:42 -0800 (Pacific Standard Time)

> after rfc822_parse_msg when I try to ouput the envelope and body

What do you mean by "body contents"?

If you are talking about body->contents.text, that is not something that 
is set by rfc822_parse_msg().  In fact, that is not something that you 
should *ever* access in your application; it is strictly internal to 
c-client.

That's why I suggest that you use the higher-level routines.  If the 
message is truly in a non-mailbox form, you are better off writing a 
driver for it than calling rfc822_parse_msg() directly.  Perhaps you can 
start by hacking the phile driver using the message loading capability 
from the mh driver.

The proper use of rfc822_parse_msg() is very complicated, and only a 
careful study of mail.c will show you this.  Fortunately, mail.c will do 
the work for you, if you have a driver.

-- Mark --

---

From: Mark Crispin <[email-masked]>
Date: Tue, 2 Nov 2004 14:24:17 -0800 (Pacific Standard Time)

On Tue, 2 Nov 2004, Mark Crispin wrote:
> If you are talking about body->contents.text, that is not something that is 
> set by rfc822_parse_msg().  In fact, that is not something that you should 
> *ever* access in your application; it is strictly internal to c-client.

If you really insist upon using rfc822_parse_msg(), you use 
body->contents.offset which is the offset into the stringstruct that you 
passed as the argument to rfc822_parse_msg(), along with the 
body->size.octets.

body->contents.text is currently only used by the IMAP driver and by the 
sending modules (SMTP and NNTP send).

-- Mark --