Beispiel #1
0
int mailsmtp_ssl_connect_with_callback(mailsmtp * session,
    const char * server, uint16_t port,
    void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
  int s;
  mailstream * stream;

#if HAVE_CFNETWORK
  if (callback == NULL) {
    return mailsmtp_cfssl_connect(session, server, port);
  }
#endif
  
  if (port == 0) {
    port = mail_get_service_port(SERVICE_NAME_SMTPS, SERVICE_TYPE_TCP);
    if (port == 0)
      port = DEFAULT_SMTPS_PORT;
  }

  /* Connection */

  s = mail_tcp_connect(server, port);
  if (s == -1)
    return MAILSMTP_ERROR_CONNECTION_REFUSED;

  stream = mailstream_ssl_open(s);
  if (stream == NULL) {
    close(s);
    return MAILSMTP_ERROR_SSL;
  }

  return mailsmtp_connect(session, stream);
}
Beispiel #2
0
int mailsmtp_socket_connect(mailsmtp * session,
    const char * server, uint16_t port)
{
  int s;
  mailstream * stream;

#if HAVE_CFNETWORK
  return mailsmtp_cfsocket_connect(session, server, port);
#endif
  
  if (port == 0) {
    port = mail_get_service_port(SERVICE_NAME_SMTP, SERVICE_TYPE_TCP);
    if (port == 0)
      port = DEFAULT_SMTP_PORT;
  }

  /* Connection */

  s = mail_tcp_connect(server, port);
  if (s == -1)
    return MAILSMTP_ERROR_CONNECTION_REFUSED;

  stream = mailstream_socket_open(s);
  if (stream == NULL) {
#ifdef WIN32
	closesocket(s);
#else
    close(s);
#endif
    return MAILSMTP_ERROR_MEMORY;
  }

  return mailsmtp_connect(session, stream);
}
Beispiel #3
0
static int mailsmtp_cfsocket_connect(mailsmtp * session,
                                     const char * server, uint16_t port)
{
  mailstream * stream;
  
  stream = mailstream_cfstream_open_timeout(server, port, session->smtp_timeout);
  if (stream == NULL) {
    return MAILSMTP_ERROR_CONNECTION_REFUSED;
  }
  
  return mailsmtp_connect(session, stream);
}
Beispiel #4
0
static int mailsmtp_cfssl_connect(mailsmtp * session,
                                  const char * server, uint16_t port)
{
  mailstream * stream;
  int r;
  
  stream = mailstream_cfstream_open(server, port);
  if (stream == NULL) {
    return MAILSMTP_ERROR_CONNECTION_REFUSED;
  }
  mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION);
  r = mailstream_cfstream_set_ssl_enabled(stream, 1);
  if (r < 0) {
    mailstream_close(stream);
    return MAILSMTP_ERROR_SSL;
  }
  
  return mailsmtp_connect(session, stream);
}