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: Sergey Poznyakoff
Subject: Re: How do I create a message from RFC822 data!
Date: Thu, 15 Nov 2001 11:07:55 +0200

Unfortunately, this can't be based on mh internals. All mh_.* calls
expect that the message owner (or, better said, message data) is
struct _mh_message, which in turn requires that the internal pool
of mh messages be initialized properly, etc.. They are the internal
implementations that are expected to be called only from corresponding
upper layer functions.

The similar problem appeared in writing implementation of imap4 append
command: there it was necessary to read a message from a memory stream.
The approach was to create a "/dev/null" mailbox, attach a stream to
it and force it do a scan. In your case, this would look like:

int
main (int argc, char **argv)
{
//  mailer_t mailer = 0;
  mailbox_t tmp;
  message_t msg = 0;
  stream_t  in = 0;
  stream_t  out = 0;

  size_t count = 0;
  off_t  offset = 0;
  char buf[BUFSIZ];

  {
    list_t bookie;
    registrar_get_list (&bookie);
    list_append (bookie, path_record);
  }
  
  C( mailbox_create (&tmp, "/dev/null") )
  C( mailbox_open (tmp, MU_STREAM_READ) )
  C( stdio_stream_create (&in) )
  C( stream_open (in, (char*) stdin, 0, MU_STREAM_READ) )

  mailbox_set_stream (tmp, in);

  mailbox_messages_count (tmp, &count);
  if (count == 0)
    {
      perror ("mailbox_messages_count");
      exit (1);
    }
  
  mailbox_get_message (tmp, 1, &msg);
  
  /* try and print the message */
  message_get_stream (msg, &out);
  ...

There is a problem, though: mailbox scan functions rely on the ability
to get the size of the stream, which is impossible with stdin. If it
is acceptable to create a temporary file, the problem can easily be
overcome.

Regards,
Sergey





reply via email to

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