Esempio n. 1
0
int
mu_message_get_envelope (mu_message_t msg, mu_envelope_t *penvelope)
{
  if (msg == NULL)
    return EINVAL;
  if (penvelope == NULL)
    return MU_ERR_OUT_PTR_NULL;

  if (msg->envelope == NULL)
    {
      mu_envelope_t envelope;
      int status = mu_envelope_create (&envelope, msg);
      if (status != 0)
	return status;
      mu_envelope_set_sender (envelope, message_envelope_sender, msg);
      mu_envelope_set_date (envelope, message_envelope_date, msg);
      msg->envelope = envelope;
    }
  *penvelope = msg->envelope;
  return 0;
}
Esempio n. 2
0
static int
new_message (mu_mailbox_t mailbox, mbox_message_t mum, mu_message_t *pmsg)
{
  int status;
  mu_message_t msg;

  /* Get an empty message struct.  */
  status = mu_message_create (&msg, mum);
  if (status != 0)
    return status;

  /* Set the header.  */
  {
    mu_header_t header = NULL;
    status = mu_header_create (&header, NULL, 0, msg);
    if (status != 0)
      {
	mu_message_destroy (&msg, mum);
	return status;
      }
    mu_header_set_fill (header, mbox_header_fill, msg);
    mu_message_set_header (msg, header, mum);
  }

  /* Set the attribute.  */
  {
    mu_attribute_t attribute;
    status = mu_attribute_create (&attribute, msg);
    if (status != 0)
      {
	mu_message_destroy (&msg, mum);
	return status;
      }
    mu_attribute_set_get_flags (attribute, mbox_get_attr_flags, msg);
    mu_attribute_set_set_flags (attribute, mbox_set_attr_flags, msg);
    mu_attribute_set_unset_flags (attribute, mbox_unset_attr_flags, msg);
    mu_message_set_attribute (msg, attribute, mum);
  }

  /* Prepare the body.  */
  {
    mu_body_t body = NULL;
    mu_stream_t stream = NULL;
    if ((status = mu_body_create (&body, msg)) != 0
	|| (status = mu_stream_create (&stream,
				       mailbox->flags | MU_STREAM_SEEKABLE,
				       body)) != 0)
      {
	mu_body_destroy (&body, msg);
	mu_stream_destroy (&stream, body);
	mu_message_destroy (&msg, mum);
	return status;
      }
    mu_stream_set_read (stream, mbox_body_read, body);
    mu_stream_set_readline (stream, mbox_body_readline, body);
    mu_stream_set_get_transport2 (stream, mbox_get_body_transport, body);
    mu_stream_set_size (stream, mbox_stream_size, body);
    mu_body_set_stream (body, stream, msg);
    mu_body_set_size (body, mbox_body_size, msg);
    mu_body_set_lines (body, mbox_body_lines, msg);
    mu_message_set_body (msg, body, mum);
  }

  /* Set the envelope.  */
  {
    mu_envelope_t envelope= NULL;
    status = mu_envelope_create (&envelope, msg);
    if (status != 0)
      {
	mu_message_destroy (&msg, mum);
	return status;
      }
    mu_envelope_set_sender (envelope, mbox_envelope_sender, msg);
    mu_envelope_set_date (envelope, mbox_envelope_date, msg);
    mu_message_set_envelope (msg, envelope, mum);
  }

  /* Set the UID.  */
  mu_message_set_uid (msg, mbox_message_uid, mum);
  mu_message_set_qid (msg, mbox_message_qid, mum);
  
  /* Attach the message to the mailbox mbox data.  */
  mum->message = msg;
  mu_message_set_mailbox (msg, mailbox, mum);

  *pmsg = msg;
  
  return 0;
}