コード例 #1
0
ファイル: mbox.c プロジェクト: ssvlab/esbmc-gpu
/* Open the file.  For MU_STREAM_READ, the code tries mmap() first and fall
   back to normal file.  */
static int
mbox_open (mu_mailbox_t mailbox, int flags)
{
  mbox_data_t mud = mailbox->data;
  int status = 0;

  if (mud == NULL)
    return EINVAL;

  mailbox->flags = flags;

  /* Get a stream.  */
  if (mailbox->stream == NULL)
    {
      /* We do not try to mmap for CREAT or APPEND, it is not supported.  */
      status = (flags & MU_STREAM_CREAT)
	|| (mailbox->flags & MU_STREAM_APPEND);

      /* Try to mmap () the file first.  */
      if (status == 0)
	{
	  status = mu_mapfile_stream_create (&mailbox->stream, mud->name, mailbox->flags);
	  if (status == 0)
	    {
	      status = mu_stream_open (mailbox->stream);
	    }
	}

      /* Fall back to normal file if mmap() failed.  */
      if (status != 0)
	{
	  status = mu_file_stream_create (&mailbox->stream, mud->name, mailbox->flags);
	  if (status != 0)
	    return status;
	  status = mu_stream_open (mailbox->stream);
	}
      /* All failed, bail out.  */
      if (status != 0)
	{
	  mu_stream_destroy (&mailbox->stream, NULL);
	  return status;
	}
      /* Even on top of normal FILE *, lets agressively cache.  But this
	 may not be suitable for system tight on memory.  */
      mu_stream_setbufsiz (mailbox->stream, BUFSIZ);
    }
  else
    {
      status = mu_stream_open (mailbox->stream);
      if (status != 0)
	return status;
    }

  MU_DEBUG2 (mailbox->debug, MU_DEBUG_TRACE1, "mbox_open (%s, 0x%x)\n",
	     mud->name, mailbox->flags);

  if (mailbox->locker == NULL)
    status = mu_locker_create (&(mailbox->locker), mud->name, 0);
  return status;
}
コード例 #2
0
ファイル: vacation.c プロジェクト: aleeehaider825/hachi-roku
/* Generate and send the reply message */
static int
vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
		char *text, char *to, char *from)
{
  mu_mime_t mime = NULL;
  mu_message_t newmsg;
  mu_header_t newhdr;
  mu_address_t to_addr = NULL, from_addr = NULL;
  char *value;
  mu_mailer_t mailer;
  int rc;

  if (mu_sieve_tag_lookup (tags, "file", NULL))
    {
      mu_stream_t instr;
      
      rc = mu_mapfile_stream_create (&instr, text, MU_STREAM_READ);
      if (rc)
	{
	  mu_sieve_error (mach,
			  _("%lu: cannot open message file %s: %s"),
			  (unsigned long) mu_sieve_get_message_num (mach),
			  text,
			  mu_strerror (rc));
	  return -1;
	}
      rc = mu_stream_to_message (instr, &newmsg);
      mu_stream_unref (instr);
      if (rc)
	{
	  mu_sieve_error (mach,
			  _("%lu: cannot read message from file %s: %s"),
			  (unsigned long) mu_sieve_get_message_num (mach),
			  text,
			  mu_strerror (rc));
	  return -1;
	} 
    }
  else
    {
      if (build_mime (mach, tags, &mime, msg, text))
	return -1;
      mu_mime_get_message (mime, &newmsg);
      mu_message_unref (newmsg);
      mu_message_get_header (newmsg, &newhdr);
    }
  
  rc = mu_address_create (&to_addr, to);
  if (rc)
    {
      mu_sieve_error (mach,
		      _("%lu: cannot create recipient address <%s>: %s"),
		      (unsigned long) mu_sieve_get_message_num (mach),
		      from, mu_strerror (rc));
    }
  else
    {
      mu_header_set_value (newhdr, MU_HEADER_TO, to, 0);
      
      vacation_subject (mach, tags, msg, newhdr);
      
      if (from)
        {
          if (mu_address_create (&from_addr, from))
	    from_addr = NULL;
        }
      else
        {
          from_addr = NULL;
        }
      
      if (mu_rfc2822_in_reply_to (msg, &value) == 0)
        {
          mu_header_set_value (newhdr, MU_HEADER_IN_REPLY_TO, value, 1);
          free (value);
        }
      
      if (mu_rfc2822_references (msg, &value) == 0)
        {
          mu_header_set_value (newhdr, MU_HEADER_REFERENCES, value, 1);
          free (value);
        }
      
      mailer = mu_sieve_get_mailer (mach);
      if (mailer)
	{
	  rc = mu_mailer_send_message (mailer, newmsg, from_addr, to_addr);
	}
      else
	rc = MU_ERR_FAILURE;
    }
  mu_address_destroy (&to_addr);
  mu_address_destroy (&from_addr);
  mu_mime_destroy (&mime);
  return rc;
}