示例#1
0
int
mu_url_set_port (mu_url_t url, unsigned port)
{
  char *copy;
  
  if (!url)
    return EINVAL;
  if (port)
    {
      char nbuf[128];
      snprintf (nbuf, sizeof nbuf, "%u", port);
      copy = strdup (nbuf);
      if (!copy)
	return ENOMEM;
      url->flags |= MU_URL_PORT;
    }
  else
    {
      copy = NULL;
      url->flags &= ~MU_URL_PORT;
    }
  url->_get_port = NULL;
  url->_get_portstr = NULL;
  free (url->portstr);
  url->port = port;
  url->portstr = copy;
  mu_url_invalidate (url);
  return 0;
}
示例#2
0
int
mu_url_set_path (mu_url_t url, const char *path)
{
  char *copy;
  
  if (!url)
    return EINVAL;
  if (path)
    {
      copy = strdup (path);
      if (!copy)
	return ENOMEM;
      url->flags |= MU_URL_PATH;
    }
  else
    {
      url->flags &= ~MU_URL_PATH;
      copy = NULL;
    }
  free (url->path);
  url->path = copy;
  url->_get_path = NULL;
  mu_url_invalidate (url);
  return 0;
}
示例#3
0
int
mu_url_set_service (mu_url_t url, const char *str)
{
  unsigned port;
  char *copy;
  
  if (!url)
    return EINVAL;
  if (str)
    {
      unsigned long n;
      char *p;
      
      n = strtoul (str, &p, 10);
      if (*p)
	{
	  /* FIXME: 1. This assumes MU_URL_PARSE_PORTSRV. */
	  /* FIXME: 2. Another proto? */
	  struct servent *sp = getservbyname (str, "tcp");
	  if (!sp)
	    return MU_ERR_TCP_NO_PORT;
	  port = ntohs (sp->s_port);
	}
      else if (n > USHRT_MAX)
	return ERANGE;

      copy = strdup (str);
      if (!copy)
	return ENOMEM;
      url->flags |= MU_URL_PORT;
    }
  else
    {
      copy = NULL;
      port = 0;
      url->flags &= ~MU_URL_PORT;
    }
  url->_get_port = NULL;
  url->_get_portstr = NULL;
  free (url->portstr);
  url->port = port;
  url->portstr = copy;
  mu_url_invalidate (url);
  return 0;
}
示例#4
0
int
mutool_send (int argc, char **argv)
{
  int index;
  char *infile;
  mu_stream_t instr;
  mu_message_t msg;
  size_t count;
  mu_url_t urlhint, url;
  mu_mailer_t mailer;
  
  MU_ASSERT (mu_address_create_null (&rcpt_addr));
  mu_register_all_mailer_formats ();
  
  if (argp_parse (&send_argp, argc, argv, 0, &index, NULL))
    return 1;

  argc -= index;
  argv += index;

  if (argc < 1)
    {
      mu_error (_("not enough arguments"));
      return 1;
    }

  infile = argv[1];
  if (infile)
    MU_ASSERT (mu_file_stream_create (&instr, infile,
				      MU_STREAM_READ|MU_STREAM_SEEK));
  else
    MU_ASSERT (mu_stdio_stream_create (&instr, MU_STDIN_FD,
				       MU_STREAM_READ|MU_STREAM_SEEK));

  MU_ASSERT (mu_stream_to_message (instr, &msg));
  mu_stream_unref (instr);

  mu_address_get_count (rcpt_addr, &count);
  if (count == 0)
    read_recipients = 1;

  if (read_recipients)
    {
      int rc;
      mu_header_t header;
      const char *value;

      MU_ASSERT (mu_message_get_header (msg, &header));
	  
      rc = mu_header_sget_value (header, MU_HEADER_TO, &value);
      if (rc == 0)
	send_address_add (&rcpt_addr, value);
      else if (rc != MU_ERR_NOENT)
	{
	  mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value",
			   MU_HEADER_TO, rc);
	  exit (1);
	}
      
      rc = mu_header_sget_value (header, MU_HEADER_CC, &value);
      if (rc == 0)
	send_address_add (&rcpt_addr, value);
      else if (rc != MU_ERR_NOENT)
	{
	  mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value",
			   MU_HEADER_CC, rc);
	  exit (1);
	}

      rc = mu_header_sget_value (header, MU_HEADER_BCC, &value);
      if (rc == 0)
	send_address_add (&rcpt_addr, value);
      else if (rc != MU_ERR_NOENT)
	{
	  mu_diag_funcall (MU_DIAG_ERROR, "mu_header_sget_value",
			   MU_HEADER_BCC, rc);
	  exit (1);
	}
    }

  mu_address_get_count (rcpt_addr, &count);
  if (count == 0)
    {
      mu_error (_("no recipients"));
      exit (1);
    }
  
  MU_ASSERT (mu_url_create (&urlhint, "smtp://"));
  MU_ASSERT (mu_url_create_hint (&url, argv[0], MU_URL_PARSE_DEFAULT,
				 urlhint));
  mu_url_invalidate (url);
  MU_ASSERT (mu_mailer_create_from_url (&mailer, url));
  MU_ASSERT (mu_mailer_open (mailer, MU_STREAM_RDWR));
  MU_ASSERT (mu_mailer_send_message (mailer, msg, from_addr, rcpt_addr));
  mu_mailer_close (mailer);
  mu_mailer_destroy (&mailer);
  return 0;
}