aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-03-15 12:21:24 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-03-15 12:21:24 +0800
commitd365f590272614905f8d3e6445370645a61ad80c (patch)
tree9a2fa3c5eed45473e01813bd5d70a7cae1d0a834 /camel
parent8391885d18e36b4f6608abd0c2c23bb9d1130828 (diff)
downloadgsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar.gz
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar.bz2
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar.lz
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar.xz
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.tar.zst
gsoc2013-evolution-d365f590272614905f8d3e6445370645a61ad80c.zip
Update for using CamelTcpStreams and also for using SSL.
2001-03-14 Jeffrey Stedfast <fejj@ximian.com> * providers/smtp/camel-smtp-transport.c (smtp_connect): Update for using CamelTcpStreams and also for using SSL. * providers/smtp/libcamelsmtp.urls: defined "ssmtp" * providers/smtp/camel-smtp-provider.c: Defined the Secure SMTP provider. (camel_provider_module_init): Register the Secure SMTP provider. svn path=/trunk/; revision=8728
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog3
-rw-r--r--camel/camel-tcp-stream-ssl.h3
-rw-r--r--camel/providers/smtp/camel-smtp-transport.c66
3 files changed, 52 insertions, 20 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index ab97ed1919..ee281db3bd 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,8 @@
2001-03-14 Jeffrey Stedfast <fejj@ximian.com>
+ * providers/smtp/camel-smtp-transport.c (smtp_connect): Update for
+ using CamelTcpStreams and also for using SSL.
+
* providers/smtp/libcamelsmtp.urls: defined "ssmtp"
* providers/smtp/camel-smtp-provider.c: Defined the Secure SMTP
diff --git a/camel/camel-tcp-stream-ssl.h b/camel/camel-tcp-stream-ssl.h
index 883e1cda2a..c0ad2f8a43 100644
--- a/camel/camel-tcp-stream-ssl.h
+++ b/camel/camel-tcp-stream-ssl.h
@@ -35,7 +35,8 @@ extern "C" {
#ifdef HAVE_NSS
#include <camel/camel-tcp-stream.h>
#include <camel/camel-service.h>
-#include <nspr.h>
+#include <mozilla/nspr.h>
+#include <mozilla/prnetdb.h>
#define CAMEL_TCP_STREAM_SSL_TYPE (camel_tcp_stream_ssl_get_type ())
#define CAMEL_TCP_STREAM_SSL(obj) (CAMEL_CHECK_CAST((obj), CAMEL_TCP_STREAM_SSL_TYPE, CamelTcpStreamSSL))
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index 0d2c75398c..c3a5f2ac79 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -45,7 +45,11 @@
#include "camel-multipart.h"
#include "camel-mime-part.h"
#include "camel-stream-buffer.h"
-#include "camel-stream-fs.h"
+#include "camel-tcp-stream.h"
+#include "camel-tcp-stream-raw.h"
+#ifdef HAVE_NSS
+#include "camel-tcp-stream-ssl.h"
+#endif
#include "camel-session.h"
#include "camel-exception.h"
#include "camel-sasl.h"
@@ -201,11 +205,12 @@ static gboolean
smtp_connect (CamelService *service, CamelException *ex)
{
CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service);
- gchar *pass = NULL, *respbuf = NULL;
+ CamelStream *tcp_stream;
+ gchar *respbuf = NULL;
+ gboolean use_ssl = FALSE;
struct hostent *h;
- struct sockaddr_in sin;
guint32 addrlen;
- gint fd;
+ int port, ret;
if (!service_class->connect (service, ex))
return FALSE;
@@ -219,30 +224,53 @@ smtp_connect (CamelService *service, CamelException *ex)
transport->authtypes = NULL;
CAMEL_TRANSPORT (transport)->supports_8bit = FALSE;
- sin.sin_family = h->h_addrtype;
- sin.sin_port = htons (service->url->port ? service->url->port : SMTP_PORT);
- memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr));
+ port = service->url->port ? service->url->port : SMTP_PORT;
- fd = socket (h->h_addrtype, SOCK_STREAM, 0);
- if (fd == -1 || connect (fd, (struct sockaddr *)&sin, sizeof (sin)) == -1) {
+#ifdef HAVE_NSS
+ if (!g_strcasecmp (service->url->protocol, "ssmtp")) {
+ use_ssl = TRUE;
+ port = service->url->port ? service->url->port : 465;
+ tcp_stream = camel_tcp_stream_ssl_new (service, service->url->host);
+ } else {
+ tcp_stream = camel_tcp_stream_raw_new ();
+ }
+#else
+ tcp_stream = camel_tcp_stream_raw_new ();
+#endif /* HAVE_NSS */
+
+ ret = camel_tcp_stream_connect (CAMEL_TCP_STREAM (tcp_stream), h, port);
+ if (ret == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
_("Could not connect to %s (port %d): %s"),
- service->url->host,
- service->url->port ? service->url->port : SMTP_PORT,
- strerror (errno));
- if (fd > -1)
- close (fd);
- g_free (pass);
+ service->url->host, port,
+ g_strerror (errno));
+
return FALSE;
}
/* get the localaddr - needed later by smtp_helo */
addrlen = sizeof (transport->localaddr);
- getsockname (fd, (struct sockaddr*)&transport->localaddr, &addrlen);
+#ifdef HAVE_NSS
+ if (use_ssl) {
+ PRNetAddr addr;
+ char hname[1024];
+
+ PR_GetSockName (CAMEL_TCP_STREAM_SSL (tcp_stream)->sockfd, &addr);
+ memset (hname, 0, sizeof (hname));
+ PR_NetAddrToString (&addr, hname, 1023);
+
+ inet_aton (hname, (struct in_addr *)&transport->localaddr.sin_addr);
+ } else {
+ getsockname (CAMEL_TCP_STREAM_RAW (tcp_stream)->sockfd,
+ (struct sockaddr *)&transport->localaddr, &addrlen);
+ }
+#else
+ getsockname (CAMEL_TCP_STREAM_RAW (tcp_stream)->sockfd,
+ (struct sockaddr *)&transport->localaddr, &addrlen);
+#endif /* HAVE_NSS */
- transport->ostream = camel_stream_fs_new_with_fd (fd);
- transport->istream = camel_stream_buffer_new (transport->ostream,
- CAMEL_STREAM_BUFFER_READ);
+ transport->ostream = tcp_stream;
+ transport->istream = camel_stream_buffer_new (tcp_stream, CAMEL_STREAM_BUFFER_READ);
/* Read the greeting, note whether the server is ESMTP or not. */
do {