bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I create a message from RFC822 data!


From: Alain Magloire
Subject: Re: How do I create a message from RFC822 data!
Date: Thu, 15 Nov 2001 00:37:29 -0500 (EST)

> 
> Can somebody point me the right way?
> 
> What i need to be able to do is something like:
> 
> message_create();
> 
> s = stdio_stream_create(stdin)/open();
> 
> message_attach_to_stream(s);
> 
> h = message_get_header(); // Causing the headers to be read from the stream.
> 
> Manipulate the headers in-memory (add message-id, date, etc.).
> 
> mailer_send(msg)
>   which will
>      readline from message
>      writeline to wherever
> 
> The important thing is that the message data was never loaded into
> memory all at once.
> 
> Do I need to create a special kind of folder for this, or can I do it
> with a message_t?

Ok, it should be as easy as doing this:
{
   message_t msg;
   header_t header;
   char buffer[512];
   off_t off = 0;
   size_t n = 0;

   message_create (mesg, NULL, 0);
   file_stream_crete (&stream, "/home/user/mh/mesg_1");
   message_set_stream (mesg, stream, NULL);
   message_get_header (mesg, &header);

   header_get_stream (header, &stream);
   while (stream_readline (stream, buffer, sizeof buffer, off, &n) == 0
          && n > 0) {
     printf ("%s", buffer);
     off += n;
   }
   message_destroy (&mesg, NULL);
} 

But unfortunately I just realize that I did not use the new stream attached
I got this wrong, consider this as a bug, I'll correct it later,
during the week.  My computer quota is finish.

> I want to learn more about these things internals, but a pointer in the
> right direction so I don't flail around too much would be handy.

Well what should have happen is that when you do the first
message.c:message_get_{header,body}:  The code should have:

 - Check if msg->header is already set if yes return it.

 - else if msg->header == NULL check if a stream exist
   if yes, implement a header_t that use the stream
   assuming that it is rfc822 i.e. \n terminated.

 - if msg->header == NULL and  msg->stream == NULL return an empty header.

The same algo goes for body.  But execpt of an empty header
it create a tempory file as a place holder.

What will work however until I fix this is to let
the message_t object create temporary file for you
The same technique is use by the mime.c code:
{
  stream_t file_stream;
  message_t mesg;
  stream mesg_stream;
  off_t off = 0;
  size_t n = 0;

  file_stream_create (*file_stream, "/home/alain/mh/msg3");
  message_create (&mesg, NULL)
  message_get_stream (mesg, &mesg_stream);

  /* Copy the file ".../msg3" to the mesg(message_t).  */
   while (stream_read (stream, buffer, sizeof buffer, off, &n) == 0
          && n > 0) {
     stream_write (mesg_stream, buffer, n, off, NULL);
     off += n;
   }

  /* Now, msg contain a parse rfc822 object.
     And you look at /tmp/muxxxx  you will see the body.
     May need to stream_flush () first to see it since
     FILE * use buffering.  */
}

Later.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]