Subject: [Imap-uw] c-client and smtp

From: Mike Schmidt <[email-masked]>
Date: Tue, 17 May 2005 09:28:06 -0400

Hi,

Does anyone know how I can set  X-headers when using  c-client's smtp 
functions? I've looked through the code, but can't seem to quite figure 
it out. Where are the X-headers, anyway? in the Envelope, Body?  I am 
starting to implement smtp via c-client, but I nned to set some private 
headers.

Another question:  Where and when is the Message-Id generated in 
c-client? If I send through the c-client smtp functions, how do I get 
the message-Id back to my code, so that I can store the message complete 
in the sent mailbox? (which I plan to do with the imap append function)

Thanks very much for any help you may be able to provide.

Mike
_______________________________________________
Imap-uw mailing list
[email-masked]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw

---

From: Mark Crispin <[email-masked]>
Date: Tue, 17 May 2005 18:28:58 -0700 (Pacific Daylight Time)

On Tue, 17 May 2005, Mike Schmidt wrote:
> functions?

The default rfc822_output() routine, called by the SMTP routines does not 
offer any means to write X-headers.  There is a kludge by which you can do 
it, but it would be wrong to do it that way.

Instead, you need to write an rfc822out_t routine, which you arm by 
SET_RFC822OUTPUT, that does something like:

my_rfc822_output (char *t,ENVELOPE *env,BODY *body,soutr_t f,void *s,
 		  long ok8bit)
{
   if (ok8bit) rfc822_encode_body_8bit (env,body);
   else rfc822_encode_body_7bit (env,body);
   my_rfc822_header (t,env,body);
   return (*f) (s,t) && (body ? rfc822_output_body (body,f,s) : T);
}

The significant thing here is that you call a routine (which you also 
write) called my_rfc822_header() instead of the c-client rfc822_header().

rfc822_header() is really a sample routine, and not something that you 
should use in production; among other things, it doesn't check for buffer 
overflows.  Your routine should do so.  You do, however, need to look at 
rfc822_header() to see what sorts of things that you need to do in your 
routine.

> Where are the X-headers, anyway? in the Envelope, Body?

X-headers are not registered headers, and thus do not appear in the 
ENVELOPE or the BODY.  If you need them, you have to fetch them as header 
strings via mail_fetch_header() with the "lines" argument set to have the 
name(s) of the particular X-header fields that you want.

> Another question:  Where and when is the Message-Id generated in c-client?

It isn't.  That is the job of your application when building the ENVELOPE 
structure.

> If 
> I send through the c-client smtp functions, how do I get the message-Id back 
> to my code, so that I can store the message complete in the sent mailbox? 
> (which I plan to do with the imap append function)

As noted above, your application sets env->message_id itself.

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.
_______________________________________________
Imap-uw mailing list
[email-masked]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw

---

From: Mike Schmidt <[email-masked]>
Date: Wed, 18 May 2005 10:22:56 -0400

Hi, Mark

Thanks for the information. I have examined the functions you mentioned, 
and it makes much more sense to me now in light of your answer. The 
reality is that I already have the email I wish to send completely 
formatted as an RFC822 message by the time I am ready to send it. It is 
currently produced by Microsoft MIME functions. I don't have the 
Message-Id yet, but that can be done. So it should be reletively easy 
for me to produce an output routine that just takes the entire message 
and throws it into the pipe via rfc822_output without taking it all 
apart. These are signed and encrypted messages anyway, thus a single 
S/MIME block, already encoded in Base64.  (after creating an envelope so 
that the smtp transaction can get started the regular way).

BTW, in case this is of interest to you, I have c-client running in 
Windows XP with a small OO interface, compiled in C++, and it works very 
well. I have made absolutely no changes to the code as distributed.

Do you have any suggestions as to open source code that generates the 
message-Id? Or specific well-known algorithms? I suppose this is a 
roll-your-own situation. I have read about the various algorithms used 
to produce message-id headers, but didn't see anything that could be 
interpreted as a standard.

There is one thing, though, that I have a question about: In the 
messages as they are currently produced, the headers are not in any 
specific order. I use the c-client mail_append_full to import them into 
the sent mailbox, and they are accepted without problems, x_headers and 
all by mail_append_full. Can I feed this same message to smtp, or do I 
need to re-order the headers? (like, put From first)?.  The SMTP server 
is SendMail, latest version, if that makes any difference.

This is a sample message:
=======================================
X-Mailer: TT-eXpress secure mailer
Date: Tue, 10 May 2005 22:26:59 -0400
Thread-Topic: test124-8
X-header-a: -1
thread-index: AcVV0Og7UpWTdVYaTIanYtqNLH8v+g==
X-header-b: 0
X-header-c: 0
Message-ID: <000d01c555d0$e8615aa0$7528eccd@mercury>
X-header-d: 4
Content-Transfer-Encoding: base64
From: <[email-masked]>
Content-Disposition: attachment;
    filename="smime.p7m"
To: <[email-masked]>
Subject: test124-8
MIME-Version: 1.0
Content-Type: 
application/pkcs7-mime;smime-type=signed-data;name="smime.p7m";
    boundary="----=_NextPart_000_0004_01C555AF.61372990";
    name="smime.p7m"
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441

MIIMmgYJKoZIhvcNAQcCoIIMizCCDIcCAQExCzAJBgUrDgMCGgUAMIIEsQYJKoZIhvcNAQcBoIIE
ogSCBJ5YLVRUWC1kZXN0cnVjdC10aW1lOiAxODAwDQpYLU1haWxlcjogVFQtZVhwcmVzcyBzZWN1
.....
============================================================================

Thank you again, Mark.

Mike

Mark Crispin wrote:

> The default rfc822_output() routine, called by the SMTP routines does 
> not offer any means to write X-headers.  There is a kludge by which 
> you can do it, but it would be wrong to do it that way.
>
> should use in production; among other things, it doesn't check for 
> buffer overflows.  Your routine should do so.  You do, however, need 
> to look at rfc822_header() to see what sorts of things that you need 
> to do in your routine.
>
> ENVELOPE or the BODY.  If you need them, you have to fetch them as 
> header strings via mail_fetch_header() with the "lines" argument set 
> to have the name(s) of the particular X-header fields that you want.
>
>> c-client?
> It isn't.  That is the job of your application when building the 
> ENVELOPE structure.
>
>> If I send through the c-client smtp functions, how do I get the 
>> message-Id back to my code, so that I can store the message complete

---

From: Mark Crispin <[email-masked]>
Date: Wed, 18 May 2005 07:35:59 -0700 (PDT)

On Wed, 18 May 2005, Mike Schmidt wrote:
> roll-your-own situation.

It is a roll-your-own.  As long as the result complies with the syntax for 
Message-ID and will not be duplicated in another message, you can use 
pretty much anything you want.

It is fairly conventional to have the DNS name of the composing system 
appear to the right of the "@" in the Message-ID, but this is not 
required.  Ignore anyone who says it is required; such individuals are 
misinformed and are likely to pass on other misinformation.

Typically, the left side of the "@" contains the time of day in some form 
(e.g. number of seconds since January 1, 1970) along with some other 
values.  UNIX process ID, results from whatever random number generator 
exists on your system, etc.

> There is one thing, though, that I have a question about: In the messages as 
> they are currently produced, the headers are not in any specific order.

With the exception of Received: headers, which are always prepended to the 
header by the MTA, and ReSent-??? headers which obviously are in a block 
for each resending, there are no requirements for any header ordering. 
Neither of these apply to you.

Good luck!

-- Mark --