Ejemplo n.º 1
0
/*
 * Format a MIME message to an allocated character buffer.  Caller
 * is responsible for freeing this buffer.
 */
char *mime_format (MIME *m)
{
  DBUF *b;

  b = dbuf_alloc ();
  mime_format_part (m, b);
  return (dbuf_extract (b));
}
Ejemplo n.º 2
0
/*
 * Build and return the mime payload container
 */
MIME *ebxml_getpayload (XML *xml, QUEUEROW *r)
{
  int l, mapi;
  XML *exml;
  MIME *msg;
  char *b,			/* buffer for payload		*/
       *type,
       *unc = NULL,		/* encryption info		*/
       *pw = NULL,
       dn[DNSZ],
       *organization,
       pid[MAX_PATH],
       buf[MAX_PATH],
       fname[MAX_PATH];

  debug ("getpayload container...\n");
  if ((mapi = ebxml_pid (xml, r, pid)) < 0)
    return (NULL);
  ppathf (fname, cfg_map (xml, mapi, "Processed"), "%s",
    queue_field_get (r, "PAYLOADFILE"));

  /* invoke the filter if given					*/
  b = cfg_map (xml, mapi, "Filter");
  if (*b)
  {
    char *emsg;
    DBUF *rbuf = dbuf_alloc ();

    debug ("filter read %s with %s\n", fname, b);
    if (filter_run (b, fname, NULL, NULL, rbuf, &emsg, cfg_timeout (xml)))
    {
      error ("Can't filter %s - %s\n", fname, strerror (errno));
      dbuf_free (rbuf);
      return (NULL);
    }
    if (*emsg)
      warn ("filter %s returned %s\n", b, emsg);
    free (emsg);
    l = dbuf_size (rbuf);
    b = dbuf_extract (rbuf);
  }
  else
  {
    debug ("reading data from %s\n", fname);
    if ((b = readfile (fname, &l)) == NULL)
    {
      error ("Can't read %s - %s\n", fname, strerror (errno));
      return (NULL);
    }
  }

  organization = cfg_org (xml);
  type = cfg_map (xml, mapi, "Encryption.Type");
  if ((type != NULL) && *type)	/* encrypted			*/
  {
    unc = cfg_map (xml, mapi, "Encryption.Unc");
    pw = cfg_map (xml, mapi, "Encryption.Password");
    strcpy (dn, cfg_map (xml, mapi, "Encryption.Id"));
  }

  msg = payload_create (b, l, fname, organization, unc, dn, pw);

  free (b);
  if (msg == NULL)
    error ("Can't create payload container for %s\n", fname);
  return (msg);
}