aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog96
-rw-r--r--camel/camel-filter-driver.c2
-rw-r--r--camel/camel-folder-search.c1
-rw-r--r--camel/camel-movemail.c3
-rw-r--r--camel/camel-sasl-digest-md5.c1
-rw-r--r--camel/camel-sasl-gssapi.c1
-rw-r--r--camel/camel-service.c6
-rw-r--r--camel/camel-tcp-stream-ssl.c1
-rw-r--r--camel/camel-vee-folder.c1
-rw-r--r--camel/camel-vee-store.c1
-rw-r--r--camel/providers/imap/camel-imap-store.c171
-rw-r--r--camel/providers/imapp/camel-imapp-store.c1
-rw-r--r--camel/providers/local/camel-local-folder.c2
-rw-r--r--camel/providers/local/camel-maildir-folder.c1
-rw-r--r--camel/providers/local/camel-mbox-folder.c1
-rw-r--r--camel/providers/local/camel-mbox-store.c1
-rw-r--r--camel/providers/local/camel-mh-folder.c1
-rw-r--r--camel/providers/local/camel-spool-folder.c2
-rw-r--r--camel/providers/local/camel-spool-store.c1
-rw-r--r--camel/providers/nntp/camel-nntp-folder.c1
-rw-r--r--camel/providers/nntp/camel-nntp-store.c131
-rw-r--r--camel/providers/pop3/camel-pop3-store.c162
-rw-r--r--camel/providers/smtp/camel-smtp-transport.c167
-rw-r--r--camel/providers/smtp/camel-smtp-transport.h8
-rw-r--r--camel/tests/data/messages/.cvsignore1
25 files changed, 391 insertions, 373 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 3f75ad95c9..e677210378 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -42,22 +42,6 @@
EAI_AGAIN, it doesn't appear to mean the same as EAGAIN does with
system calls (i guess 'no shit sherlock' really).
-2004-10-04 JP Rosevear <jpr@novell.com>
-
- * providers/imap4/camel-imap4-provider.c: include camel-i18n.h
-
-2004-10-01 Jeffrey Stedfast <fejj@novell.com>
-
- * providers/imap4/camel-imap4-folder.c (imap4_sync): If we aren't
- online, we're done. nothing to do.
- (imap4_refresh_info): Same.
- (imap4_append_message): Same but set an exception.
- (imap4_transfer_messages_to): Same.
-
- * camel-service.c (camel_getaddrinfo): Avoid assigning a value to
- the member of a const struct (which newer gcc's apparently break
- over) by casting to non-const.
-
2004-09-28 Not Zed <NotZed@Ximian.com>
** See bug #66509.
@@ -101,7 +85,7 @@
* camel-vee-store.c:
* camel-vee-folder.c: move the unmatched
folder onto the camel-vee-store object. Removede the global
- unmatched folder and associated locks/etc, fixed all the code up
+ unmatched folder and associated locks/etc, fixed all the code up
to work with the new unmatched folder, if present.
2004-09-27 Not Zed <NotZed@Ximian.com>
@@ -127,24 +111,6 @@
(spool_get_meta_path): implement, this needs to work differnetly
to the parent classes implementations :-/.
-2004-09-22 Jeffrey Stedfast <fejj@novell.com>
-
- * providers/imap/camel-imap-store.c (connect_to_server): Instead
- of doing a host-lookup ourselves, get it passed in to us as an
- argument. Also simplified a bit (try_starttls is no longer an
- option).
- (connect_to_server_wrapper): Simplified (we no longer have
- fallback cases for SSL stuff). Also, perform host lookup here.
-
- * providers/imap4/camel-imap4-store.c: Same changes as above.
-
- * providers/pop3/camel-pop3-store.c: Same.
-
- * providers/smtp/camel-smtp-transport.c: Same. Other changes
- include making the code consistant with the other providers.
-
- * providers/nntp/camel-nntp-store.c: Same as pop/imap.
-
2004-09-21 Not Zed <NotZed@Ximian.com>
** See bug #63521.
@@ -229,12 +195,6 @@
* camel-http-stream.c: turn off debug.
-2004-09-08 Hannah & Fazlu <hannah_lins@yahoo.co.in>
-
- Fixes Bug#61088
-
- * camel/camel-smime-context.c: Change of strings.
-
2004-09-15 Not Zed <NotZed@Ximian.com>
** See bug #0xffff.
@@ -555,60 +515,6 @@
CAMEL_GROUPWISE_CFLAGS.
(libcamelgroupwise_la_LIBADD): use CAMEL_GROUPWISE_LIBS.
-2004-09-07 Not Zed <NotZed@Ximian.com>
-
- * providers/groupwise/camel-groupwise-provider.c: put the options
- in their own section.
-
-2004-09-06 Not Zed <NotZed@Ximian.com>
-
- * camel-search-private.c (utf8_get): remove this, and make the
- code use camel_utf8_getc instead. Quite a bit faster esp if
- optimising with inlines.
-
- * camel-object.c (check_magic_fail): change the check_magic code
- to mostly run from a macro, its worth it.
-
-2004-09-04 Not Zed <NotZed@Ximian.com>
-
- * providers/local/camel-mbox-summary.c (message_info_new): fix
- cast issue.
-
- * providers/pop3/camel-pop3-engine.c (get_capabilities): remove
- some unused variables.
-
- * camel-object.h: remove camel-i18n.h, fixed all c files where
- appropriate.
-
-2004-08-25 Not Zed <NotZed@Ximian.com>
-
- * camel-list-utils.[ch]: Copied e_dlist* stuff to here, part of
- removing e-util dependency on camel.
-
-2004-08-05 Not Zed <NotZed@Ximian.com>
-
- * providers/local/camel-local-provider.c: same.
-
- * providers/imap/camel-imap-provider.c: put the extra stuff into a
- 'general' section.
-
- * providers/imapp/camel-imapp-provider.c: same.
-
- * providers/pop3/camel-pop3-provider.c: make sure each section
- start has a name.
-
-2004-08-03 Not Zed <NotZed@Ximian.com>
-
- * camel-url.c (camel_url_set_param): when clearing a param, use
- remove_data instead of set_data_full. craptatious glib at it
- again.
-
- * providers/nntp/camel-nntp-provider.c: turn on ssl option.
-
-2004-07-07 Not Zed <NotZed@Ximian.com>
-
- * camel-folder.c: removed filter-rule.h ugh.
-
2004-07-02 Christian Neumair <chris@gnome-de.org>
* camel-smime-context.c: s/Can't/Cannot/.
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index dfb88b84ed..cd26c3c390 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -44,8 +44,8 @@
#include "camel-stream-fs.h"
#include "camel-stream-mem.h"
#include "camel-mime-message.h"
+
#include "camel-debug.h"
-#include "camel-i18n.h"
#include "e-util/e-sexp.h"
#include "e-util/e-memory.h"
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index b7578ba887..9dde9dd848 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -45,7 +45,6 @@
#include "camel-stream-mem.h"
#include "e-util/e-memory.h"
#include "camel-search-private.h"
-#include "camel-i18n.h"
#define d(x)
#define r(x)
diff --git a/camel/camel-movemail.c b/camel/camel-movemail.c
index 619d3dc33a..9684bf25e6 100644
--- a/camel/camel-movemail.c
+++ b/camel/camel-movemail.c
@@ -42,11 +42,12 @@
#include "camel-movemail.h"
#include "camel-exception.h"
+
#include "camel-mime-parser.h"
#include "camel-mime-filter.h"
#include "camel-mime-filter-from.h"
+
#include "camel-lock-client.h"
-#include "camel-i18n.h"
#define d(x)
diff --git a/camel/camel-sasl-digest-md5.c b/camel/camel-sasl-digest-md5.c
index b526ff47e7..91bbcda705 100644
--- a/camel/camel-sasl-digest-md5.c
+++ b/camel/camel-sasl-digest-md5.c
@@ -37,7 +37,6 @@
#include "camel-charset-map.h"
#include "camel-mime-utils.h"
#include "camel-sasl-digest-md5.h"
-#include "camel-i18n.h"
#define d(x)
diff --git a/camel/camel-sasl-gssapi.c b/camel/camel-sasl-gssapi.c
index 29724078b1..1efbefee16 100644
--- a/camel/camel-sasl-gssapi.c
+++ b/camel/camel-sasl-gssapi.c
@@ -204,6 +204,7 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
gss_buffer_desc inbuf, outbuf;
GByteArray *challenge = NULL;
gss_buffer_t input_token;
+ struct hostent *h;
int conf_state;
gss_qop_t qop;
gss_OID mech;
diff --git a/camel/camel-service.c b/camel/camel-service.c
index b916d5c05a..a4e27259f2 100644
--- a/camel/camel-service.c
+++ b/camel/camel-service.c
@@ -38,6 +38,7 @@
#include <sys/poll.h>
#include "e-util/e-msgport.h"
+
#include "e-util/e-host-utils.h"
#include "camel-service.h"
@@ -45,7 +46,6 @@
#include "camel-exception.h"
#include "camel-operation.h"
#include "camel-private.h"
-#include "camel-i18n.h"
#define d(x)
#define w(x)
@@ -896,7 +896,7 @@ camel_getaddrinfo(const char *name, const char *service, const struct addrinfo *
else
memcpy (&myhints, hints, sizeof (myhints));
- myhints.ai_family = AF_INET;
+ myhints.ai_faimily = AF_INET;
hints = &myhints;
#endif
@@ -917,7 +917,7 @@ camel_getaddrinfo(const char *name, const char *service, const struct addrinfo *
cs_freeinfo(msg);
} else
res = NULL;
-
+
camel_operation_end(NULL);
return res;
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index 19c534beff..39bf89d468 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -61,7 +61,6 @@
#include "camel-session.h"
#include "camel-certdb.h"
#include "camel-operation.h"
-#include "camel-i18n.h"
/* from md5-utils.h */
void md5_get_digest (const char *buffer, int buffer_size, unsigned char digest[16]);
diff --git a/camel/camel-vee-folder.c b/camel/camel-vee-folder.c
index 34211a48aa..d7c29eefb4 100644
--- a/camel/camel-vee-folder.c
+++ b/camel/camel-vee-folder.c
@@ -38,7 +38,6 @@
#include "camel-vee-store.h" /* for open flags */
#include "camel-private.h"
#include "camel-debug.h"
-#include "camel-i18n.h"
#include "e-util/md5-utils.h"
diff --git a/camel/camel-vee-store.c b/camel/camel-vee-store.c
index 90c6ee1f95..b562ad4a60 100644
--- a/camel/camel-vee-store.c
+++ b/camel/camel-vee-store.c
@@ -27,7 +27,6 @@
#include "camel-vee-folder.h"
#include "camel-private.h"
-#include "camel-i18n.h"
#include <string.h>
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index bc89bae55b..c0c0bcc8a2 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -24,6 +24,7 @@
*
*/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -58,10 +59,11 @@
#include "camel-sasl.h"
#include "camel-utf8.h"
#include "camel-string-utils.h"
+
#include "camel-imap-private.h"
#include "camel-private.h"
+
#include "camel-debug.h"
-#include "camel-i18n.h"
#define d(x)
@@ -503,52 +505,76 @@ imap_get_capability (CamelService *service, CamelException *ex)
}
enum {
- MODE_CLEAR,
- MODE_SSL,
- MODE_TLS,
+ USE_SSL_NEVER,
+ USE_SSL_ALWAYS,
+ USE_SSL_WHEN_POSSIBLE
};
#define SSL_PORT_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3)
#define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
static gboolean
-connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex)
+connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelException *ex)
{
CamelImapStore *store = (CamelImapStore *) service;
CamelImapResponse *response;
CamelStream *tcp_stream;
CamelSockOptData sockopt;
gboolean force_imap4 = FALSE;
- int clean_quit, ret;
+ int clean_quit;
+ int ret;
char *buf;
+ struct addrinfo *ai, hints = { 0 };
+ char *serv;
+
+ /* FIXME: this connect stuff is duplicated everywhere */
+
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "imap";
- if (ssl_mode != MODE_CLEAR) {
+ if (ssl_mode != USE_SSL_NEVER) {
#ifdef HAVE_SSL
- if (ssl_mode == MODE_TLS) {
- tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, STARTTLS_FLAGS);
+ if (try_starttls) {
+ tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
} else {
+ if (service->url->port == 0)
+ serv = "imaps";
tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
}
#else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host, _("SSL unavailable"));
+ if (!try_starttls && service->url->port == 0)
+ serv = "imaps";
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
+ _("SSL unavailable"));
return FALSE;
#endif /* HAVE_SSL */
} else {
tcp_stream = camel_tcp_stream_raw_new ();
}
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ai == NULL) {
+ camel_object_unref(tcp_stream);
+ return FALSE;
+ }
- if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1) {
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
+ if (ret == -1) {
if (errno == EINTR)
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
_("Connection cancelled"));
else
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host,
- g_strerror (errno));
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv, g_strerror (errno));
camel_object_unref (tcp_stream);
@@ -643,18 +669,32 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
store->server_level = IMAP_LEVEL_IMAP4;
}
- if (ssl_mode != MODE_TLS) {
- /* we're done */
- return TRUE;
+#ifdef HAVE_SSL
+ if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
+ if (store->capabilities & IMAP_CAPABILITY_STARTTLS)
+ goto starttls;
+ } else if (ssl_mode == USE_SSL_ALWAYS) {
+ if (try_starttls) {
+ if (store->capabilities & IMAP_CAPABILITY_STARTTLS) {
+ /* attempt to toggle STARTTLS mode */
+ goto starttls;
+ } else {
+ /* server doesn't support STARTTLS, abort */
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to connect to IMAP server %s in secure mode: %s"),
+ service->url->host, _("SSL/TLS extension not supported."));
+ /* we have the possibility of quitting cleanly here */
+ clean_quit = TRUE;
+ goto exception;
+ }
+ }
}
+#endif /* HAVE_SSL */
- if (!(store->capabilities & IMAP_CAPABILITY_STARTTLS)) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to IMAP server %s in secure mode: %s"),
- service->url->host, _("STARTTLS not supported"));
-
- goto exception;
- }
+ return TRUE;
+
+#ifdef HAVE_SSL
+ starttls:
/* as soon as we send a STARTTLS command, all hope is lost of a clean QUIT if problems arise */
clean_quit = FALSE;
@@ -719,6 +759,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
store->connected = FALSE;
return FALSE;
+#endif /* HAVE_SSL */
}
static gboolean
@@ -866,54 +907,60 @@ connect_to_server_process (CamelService *service, const char *cmd, CamelExceptio
static struct {
char *value;
- char *serv;
int mode;
} ssl_options[] = {
- { "", "imaps", MODE_SSL }, /* really old (1.x) */
- { "always", "imaps", MODE_SSL },
- { "when-possible", "imap", MODE_TLS },
- { "never", "imap", MODE_CLEAR },
- { NULL, "imap", MODE_CLEAR },
+ { "", USE_SSL_ALWAYS },
+ { "always", USE_SSL_ALWAYS },
+ { "when-possible", USE_SSL_WHEN_POSSIBLE },
+ { "never", USE_SSL_NEVER },
+ { NULL, USE_SSL_NEVER },
};
static gboolean
connect_to_server_wrapper (CamelService *service, CamelException *ex)
{
- const char *command, *ssl_mode;
- struct addrinfo hints, *ai;
- int mode, ret, i;
- char *serv;
-
- if ((command = camel_url_get_param (service->url, "command")))
+ const char *command;
+#ifdef HAVE_SSL
+ const char *use_ssl;
+ int i, ssl_mode;
+#endif
+ command = camel_url_get_param (service->url, "command");
+ if (command)
return connect_to_server_process (service, command, ex);
-
- if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
+
+#ifdef HAVE_SSL
+ use_ssl = camel_url_get_param (service->url, "use_ssl");
+ if (use_ssl) {
for (i = 0; ssl_options[i].value; i++)
- if (!strcmp (ssl_options[i].value, ssl_mode))
+ if (!strcmp (ssl_options[i].value, use_ssl))
break;
- mode = ssl_options[i].mode;
- serv = ssl_options[i].serv;
+ ssl_mode = ssl_options[i].mode;
+ } else
+ ssl_mode = USE_SSL_NEVER;
+
+ if (ssl_mode == USE_SSL_ALWAYS) {
+ /* First try the ssl port */
+ if (!connect_to_server (service, ssl_mode, FALSE, ex)) {
+ if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) {
+ /* The ssl port seems to be unavailable, lets try STARTTLS */
+ camel_exception_clear (ex);
+ return connect_to_server (service, ssl_mode, TRUE, ex);
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ } else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
+ /* If the server supports STARTTLS, use it */
+ return connect_to_server (service, ssl_mode, TRUE, ex);
} else {
- mode = MODE_CLEAR;
- serv = "imap";
+ /* User doesn't care about SSL */
+ return connect_to_server (service, ssl_mode, FALSE, ex);
}
-
- if (service->url->port) {
- serv = g_alloca (16);
- sprintf (serv, "%d", service->url->port);
- }
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = PF_UNSPEC;
- if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex)))
- return FALSE;
-
- ret = connect_to_server (service, ai, mode, ex);
-
- camel_freeaddrinfo (ai);
-
- return ret;
+#else
+ return connect_to_server (service, USE_SSL_NEVER, FALSE, ex);
+#endif
}
extern CamelServiceAuthType camel_imap_password_authtype;
diff --git a/camel/providers/imapp/camel-imapp-store.c b/camel/providers/imapp/camel-imapp-store.c
index 00ba0d00ce..2176c91cc6 100644
--- a/camel/providers/imapp/camel-imapp-store.c
+++ b/camel/providers/imapp/camel-imapp-store.c
@@ -48,7 +48,6 @@
#ifdef HAVE_SSL
#include "camel/camel-tcp-stream-ssl.h"
#endif
-#include "camel/camel-i18n.h"
#include "camel-imapp-store-summary.h"
#include "camel-imapp-store.h"
diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c
index 70673d9687..b86d23221a 100644
--- a/camel/providers/local/camel-local-folder.c
+++ b/camel/providers/local/camel-local-folder.c
@@ -20,6 +20,7 @@
*
*/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -47,7 +48,6 @@
#include "camel-stream-filter.h"
#include "camel-mime-filter-from.h"
#include "camel-exception.h"
-#include "camel-i18n.h"
#include "camel-local-private.h"
diff --git a/camel/providers/local/camel-maildir-folder.c b/camel/providers/local/camel-maildir-folder.c
index 669e636527..ba42b75f28 100644
--- a/camel/providers/local/camel-maildir-folder.c
+++ b/camel/providers/local/camel-maildir-folder.c
@@ -39,7 +39,6 @@
#include "camel-data-wrapper.h"
#include "camel-mime-message.h"
#include "camel-exception.h"
-#include "camel-i18n.h"
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
diff --git a/camel/providers/local/camel-mbox-folder.c b/camel/providers/local/camel-mbox-folder.c
index b4926b9b04..fa8f0b645d 100644
--- a/camel/providers/local/camel-mbox-folder.c
+++ b/camel/providers/local/camel-mbox-folder.c
@@ -42,7 +42,6 @@
#include "camel-stream-filter.h"
#include "camel-mime-filter-from.h"
#include "camel-exception.h"
-#include "camel-i18n.h"
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c
index f98c87a8ea..1277407dbb 100644
--- a/camel/providers/local/camel-mbox-store.c
+++ b/camel/providers/local/camel-mbox-store.c
@@ -37,7 +37,6 @@
#include "camel-text-index.h"
#include "camel-exception.h"
#include "camel-url.h"
-#include "camel-i18n.h"
#define d(x)
diff --git a/camel/providers/local/camel-mh-folder.c b/camel/providers/local/camel-mh-folder.c
index fd054933c5..78456b6daf 100644
--- a/camel/providers/local/camel-mh-folder.c
+++ b/camel/providers/local/camel-mh-folder.c
@@ -39,7 +39,6 @@
#include "camel-data-wrapper.h"
#include "camel-mime-message.h"
#include "camel-exception.h"
-#include "camel-i18n.h"
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c
index b9cb643189..6a1bbf798a 100644
--- a/camel/providers/local/camel-spool-folder.c
+++ b/camel/providers/local/camel-spool-folder.c
@@ -44,8 +44,8 @@
#include "camel-session.h"
#include "camel-file-utils.h"
#include "camel-lock-client.h"
+
#include "camel-local-private.h"
-#include "camel-i18n.h"
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c
index 3dc21886c8..2e3d9ea777 100644
--- a/camel/providers/local/camel-spool-store.c
+++ b/camel/providers/local/camel-spool-store.c
@@ -41,7 +41,6 @@
#include "camel-exception.h"
#include "camel-url.h"
#include "camel-private.h"
-#include "camel-i18n.h"
#define d(x)
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index 7f06555b43..ffb1b29742 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -49,7 +49,6 @@
#include "camel/camel-multipart.h"
#include "camel/camel-mime-part.h"
#include "camel/camel-stream-buffer.h"
-#include "camel/camel-i18n.h"
#include "camel/camel-private.h"
#include "camel-nntp-summary.h"
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 1d4f43cc52..5813a965ff 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -52,7 +52,6 @@
#include "camel-nntp-folder.h"
#include "camel-nntp-private.h"
#include "camel-nntp-resp-codes.h"
-#include "camel-i18n.h"
#define w(x)
extern int camel_verbose_debug;
@@ -82,6 +81,12 @@ nntp_can_work_offline(CamelDiscoStore *store)
return TRUE;
}
+enum {
+ USE_SSL_NEVER,
+ USE_SSL_ALWAYS,
+ USE_SSL_WHEN_POSSIBLE
+};
+
static struct {
const char *name;
int type;
@@ -148,17 +153,8 @@ xover_setup(CamelNNTPStore *store, CamelException *ex)
return ret;
}
-enum {
- MODE_CLEAR,
- MODE_SSL,
- MODE_TLS,
-};
-
-#define SSL_PORT_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3)
-#define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
-
static gboolean
-connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex)
+connect_to_server (CamelService *service, int ssl_mode, CamelException *ex)
{
CamelNNTPStore *store = (CamelNNTPStore *) service;
CamelDiscoStore *disco_store = (CamelDiscoStore*) service;
@@ -168,6 +164,8 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
unsigned int len;
int ret;
char *path;
+ struct addrinfo *ai, hints = { 0 };
+ char *serv;
CAMEL_SERVICE_LOCK(store, connect_lock);
@@ -184,34 +182,42 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
camel_data_cache_set_expire_age (store->cache, 60*60*24*14);
camel_data_cache_set_expire_access (store->cache, 60*60*24*5);
}
+
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "nntp";
- if (ssl_mode != MODE_CLEAR) {
#ifdef HAVE_SSL
- if (ssl_mode == MODE_TLS) {
- tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, STARTTLS_FLAGS);
- } else {
- tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
- }
-#else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host, _("SSL unavailable"));
-
- goto fail;
-#endif /* HAVE_SSL */
+ if (ssl_mode != USE_SSL_NEVER) {
+ if (service->url->port == 0)
+ serv = "nntps";
+ tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3);
} else {
tcp_stream = camel_tcp_stream_raw_new ();
}
+#else
+ tcp_stream = camel_tcp_stream_raw_new ();
+#endif /* HAVE_SSL */
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ai == NULL) {
+ camel_object_unref(tcp_stream);
+ goto fail;
+ }
- if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1) {
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
+ if (ret == -1) {
if (errno == EINTR)
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
_("Connection cancelled"));
else
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host,
- g_strerror (errno));
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv, g_strerror (errno));
camel_object_unref (tcp_stream);
@@ -273,51 +279,54 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
static struct {
char *value;
- char *serv;
int mode;
} ssl_options[] = {
- { "", "nntps", MODE_SSL }, /* really old (1.x) */
- { "always", "nntps", MODE_SSL },
- { "when-possible", "nntp", MODE_TLS },
- { "never", "nntp", MODE_CLEAR },
- { NULL, "nntp", MODE_CLEAR },
+ { "", USE_SSL_ALWAYS },
+ { "always", USE_SSL_ALWAYS },
+ { "when-possible", USE_SSL_WHEN_POSSIBLE },
+ { "never", USE_SSL_NEVER },
+ { NULL, USE_SSL_NEVER },
};
static gboolean
nntp_connect_online (CamelService *service, CamelException *ex)
{
- struct addrinfo hints, *ai;
- const char *ssl_mode;
- int mode, ret, i;
- char *serv;
+#ifdef HAVE_SSL
+ const char *use_ssl;
+ int i, ssl_mode;
- if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
+ use_ssl = camel_url_get_param (service->url, "use_ssl");
+ if (use_ssl) {
for (i = 0; ssl_options[i].value; i++)
- if (!strcmp (ssl_options[i].value, ssl_mode))
+ if (!strcmp (ssl_options[i].value, use_ssl))
break;
- mode = ssl_options[i].mode;
- serv = ssl_options[i].serv;
+ ssl_mode = ssl_options[i].mode;
+ } else
+ ssl_mode = USE_SSL_NEVER;
+
+ if (ssl_mode == USE_SSL_ALWAYS) {
+ /* Connect via SSL */
+ return connect_to_server (service, ssl_mode, ex);
+ } else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
+ /* If the server supports SSL, use it */
+ if (!connect_to_server (service, ssl_mode, ex)) {
+ if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) {
+ /* The ssl port seems to be unavailable, fall back to plain NNTP */
+ camel_exception_clear (ex);
+ return connect_to_server (service, USE_SSL_NEVER, ex);
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
} else {
- mode = MODE_CLEAR;
- serv = "nntp";
- }
-
- if (service->url->port) {
- serv = g_alloca (16);
- sprintf (serv, "%d", service->url->port);
+ /* User doesn't care about SSL */
+ return connect_to_server (service, ssl_mode, ex);
}
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = PF_UNSPEC;
- if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex)))
- return FALSE;
-
- ret = connect_to_server (service, ai, mode, ex);
-
- camel_freeaddrinfo (ai);
-
- return ret;
+#else
+ return connect_to_server (service, USE_SSL_NEVER, ex);
+#endif
}
static gboolean
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 1c7b9d025d..52d3d1a831 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -54,7 +54,6 @@
#ifdef HAVE_SSL
#include "camel-tcp-stream-ssl.h"
#endif
-#include "camel-i18n.h"
/* Specified in RFC 1939 */
#define POP3_PORT 110
@@ -135,16 +134,16 @@ finalize (CamelObject *object)
}
enum {
- MODE_CLEAR,
- MODE_SSL,
- MODE_TLS,
+ USE_SSL_NEVER,
+ USE_SSL_ALWAYS,
+ USE_SSL_WHEN_POSSIBLE
};
#define SSL_PORT_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3)
#define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
static gboolean
-connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex)
+connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelException *ex)
{
CamelPOP3Store *store = CAMEL_POP3_STORE (service);
CamelStream *tcp_stream;
@@ -152,34 +151,56 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
guint32 flags = 0;
int clean_quit;
int ret;
-
- if (ssl_mode != MODE_CLEAR) {
+ struct addrinfo *ai, hints = { 0 };
+ char *serv;
+
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "pop3";
+
+ if (ssl_mode != USE_SSL_NEVER) {
#ifdef HAVE_SSL
- if (ssl_mode == MODE_TLS) {
- tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, STARTTLS_FLAGS);
+ if (try_starttls) {
+ tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
} else {
+ if (service->url->port == 0)
+ serv = "pop3s";
tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
}
#else
+ if (!try_starttls && service->url->port == 0)
+ serv = "pop3s";
+
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host, _("SSL unavailable"));
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
+ _("SSL unavailable"));
return FALSE;
#endif /* HAVE_SSL */
} else {
tcp_stream = camel_tcp_stream_raw_new ();
}
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ai == NULL) {
+ camel_object_unref(tcp_stream);
+ return FALSE;
+ }
- if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1) {
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
+ if (ret == -1) {
if (errno == EINTR)
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
_("Connection cancelled"));
else
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host,
- g_strerror (errno));
+ _("Could not connect to POP server %s (port %s): %s"),
+ service->url->host, serv, g_strerror (errno));
camel_object_unref (tcp_stream);
@@ -197,24 +218,41 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to read a valid greeting from POP server %s"),
- service->url->host);
-
+ _("Failed to read a valid greeting from POP server %s (port %s)"),
+ service->url->host, serv);
return FALSE;
}
- if (ssl_mode != MODE_TLS) {
- camel_object_unref (tcp_stream);
- return TRUE;
+#ifdef HAVE_SSL
+ if (store->engine) {
+ if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
+ if (store->engine->capa & CAMEL_POP3_CAP_STLS)
+ goto starttls;
+ } else if (ssl_mode == USE_SSL_ALWAYS) {
+ if (try_starttls) {
+ if (store->engine->capa & CAMEL_POP3_CAP_STLS) {
+ /* attempt to toggle STARTTLS mode */
+ goto starttls;
+ } else {
+ /* server doesn't support STARTTLS, abort */
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to connect to POP server %s in secure mode: %s"),
+ service->url->host, _("SSL/TLS extension not supported."));
+ /* we have the possibility of quitting cleanly here */
+ clean_quit = TRUE;
+ goto stls_exception;
+ }
+ }
+ }
}
+#endif /* HAVE_SSL */
- if (!(store->engine->capa & CAMEL_POP3_CAP_STLS)) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to POP server %s in secure mode: %s"),
- service->url->host, _("STLS not supported"));
- goto stls_exception;
- }
+ camel_object_unref (tcp_stream);
+
+ return store->engine != NULL;
+#ifdef HAVE_SSL
+ starttls:
/* as soon as we send a STLS command, all hope is lost of a clean QUIT if problems arise */
clean_quit = FALSE;
@@ -264,55 +302,59 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
store->engine = NULL;
return FALSE;
+#endif /* HAVE_SSL */
}
static struct {
char *value;
- char *serv;
int mode;
} ssl_options[] = {
- { "", "pop3s", MODE_SSL }, /* really old (1.x) */
- { "always", "pop3s", MODE_SSL },
- { "when-possible", "pop3", MODE_TLS },
- { "never", "pop3", MODE_CLEAR },
- { NULL, "pop3", MODE_CLEAR },
+ { "", USE_SSL_ALWAYS },
+ { "always", USE_SSL_ALWAYS },
+ { "when-possible", USE_SSL_WHEN_POSSIBLE },
+ { "never", USE_SSL_NEVER },
+ { NULL, USE_SSL_NEVER },
};
static gboolean
connect_to_server_wrapper (CamelService *service, CamelException *ex)
{
- struct addrinfo hints, *ai;
- const char *ssl_mode;
- int mode, ret, i;
- char *serv;
+#ifdef HAVE_SSL
+ const char *use_ssl;
+ int i, ssl_mode;
- if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
+ use_ssl = camel_url_get_param (service->url, "use_ssl");
+ if (use_ssl) {
for (i = 0; ssl_options[i].value; i++)
- if (!strcmp (ssl_options[i].value, ssl_mode))
+ if (!strcmp (ssl_options[i].value, use_ssl))
break;
- mode = ssl_options[i].mode;
- serv = ssl_options[i].serv;
+ ssl_mode = ssl_options[i].mode;
+ } else
+ ssl_mode = USE_SSL_NEVER;
+
+ if (ssl_mode == USE_SSL_ALWAYS) {
+ /* First try the ssl port */
+ if (!connect_to_server (service, ssl_mode, FALSE, ex)) {
+ if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) {
+ /* The ssl port seems to be unavailable, lets try STARTTLS */
+ camel_exception_clear (ex);
+ return connect_to_server (service, ssl_mode, TRUE, ex);
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ } else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
+ /* If the server supports STARTTLS, use it */
+ return connect_to_server (service, ssl_mode, TRUE, ex);
} else {
- mode = MODE_CLEAR;
- serv = "pop3";
+ /* User doesn't care about SSL */
+ return connect_to_server (service, ssl_mode, FALSE, ex);
}
-
- if (service->url->port) {
- serv = g_alloca (16);
- sprintf (serv, "%d", service->url->port);
- }
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = PF_UNSPEC;
- if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex)))
- return FALSE;
-
- ret = connect_to_server (service, ai, mode, ex);
-
- camel_freeaddrinfo (ai);
-
- return ret;
+#else
+ return connect_to_server (service, USE_SSL_NEVER, FALSE, ex);
+#endif
}
extern CamelServiceAuthType camel_pop3_password_authtype;
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index a6e555badf..fc313ed4d2 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -55,7 +55,7 @@
#include "camel-session.h"
#include "camel-exception.h"
#include "camel-sasl.h"
-#include "camel-i18n.h"
+
extern int camel_verbose_debug;
#define d(x) (camel_verbose_debug ? (x) : 0)
@@ -145,7 +145,18 @@ smtp_construct (CamelService *service, CamelSession *session,
CamelProvider *provider, CamelURL *url,
CamelException *ex)
{
+ CamelSmtpTransport *smtp_transport = CAMEL_SMTP_TRANSPORT (service);
+ const char *use_ssl;
+
CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
+
+ if ((use_ssl = camel_url_get_param (url, "use_ssl"))) {
+ /* Note: previous versions would use "" to toggle use_ssl to 'on' */
+ if (!*use_ssl || !strcmp (use_ssl, "always"))
+ smtp_transport->flags |= CAMEL_SMTP_TRANSPORT_USE_SSL_ALWAYS;
+ else if (!strcmp (use_ssl, "when-possible"))
+ smtp_transport->flags |= CAMEL_SMTP_TRANSPORT_USE_SSL_WHEN_POSSIBLE;
+ }
}
static const char *
@@ -217,56 +228,70 @@ smtp_error_string (int error)
}
}
-enum {
- MODE_CLEAR,
- MODE_SSL,
- MODE_TLS,
-};
-
#define SSL_PORT_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3)
#define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
static gboolean
-connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex)
+connect_to_server (CamelService *service, int try_starttls, CamelException *ex)
{
CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service);
CamelStream *tcp_stream;
char *respbuf = NULL;
int ret;
+ struct addrinfo *ai, hints = { 0 };
+ char *serv;
if (!CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex))
return FALSE;
/* set some smtp transport defaults */
- transport->flags = 0;
+ transport->flags &= CAMEL_SMTP_TRANSPORT_USE_SSL; /* reset all but ssl flags */
transport->authtypes = NULL;
+
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "smtp";
- if (ssl_mode != MODE_CLEAR) {
+ if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL) {
#ifdef HAVE_SSL
- if (ssl_mode == MODE_TLS) {
- tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, STARTTLS_FLAGS);
+ if (try_starttls) {
+ tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
} else {
+ if (service->url->port == 0)
+ serv = "smtps";
tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
}
#else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host, _("SSL unavailable"));
+ if (!try_starttls && service->url->port == 0)
+ serv = "smtps";
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
+ _("SSL unavailable"));
+
return FALSE;
#endif /* HAVE_SSL */
} else {
tcp_stream = camel_tcp_stream_raw_new ();
}
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ai == NULL) {
+ camel_object_unref(tcp_stream);
+ return FALSE;
+ }
- if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1) {
- if (errno == EINTR)
- camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
- _("Connection cancelled"));
- else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host, g_strerror (errno));
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
+ if (ret == -1) {
+ camel_exception_setv (ex, errno == EINTR ? CAMEL_EXCEPTION_USER_CANCEL : CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
+ g_strerror (errno));
camel_object_unref (tcp_stream);
@@ -310,19 +335,30 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
/* clear any EHLO/HELO exception and assume that any SMTP errors encountered were non-fatal */
camel_exception_clear (ex);
- if (ssl_mode != MODE_TLS) {
- /* we're done */
- return TRUE;
+#ifdef HAVE_SSL
+ if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL_WHEN_POSSIBLE) {
+ /* try_starttls is always TRUE here */
+ if (transport->flags & CAMEL_SMTP_TRANSPORT_STARTTLS)
+ goto starttls;
+ } else if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL_ALWAYS) {
+ if (try_starttls) {
+ if (transport->flags & CAMEL_SMTP_TRANSPORT_STARTTLS) {
+ goto starttls;
+ } else {
+ /* server doesn't support STARTTLS, abort */
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to connect to SMTP server %s in secure mode: %s"),
+ service->url->host, _("server does not appear to support SSL"));
+ goto exception_cleanup;
+ }
+ }
}
+#endif /* HAVE_SSL */
- if (!(transport->flags & CAMEL_SMTP_TRANSPORT_STARTTLS)) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to SMTP server %s in secure mode: %s"),
- service->url->host, _("STARTTLS not supported"));
-
- goto exception_cleanup;
- }
+ return TRUE;
+#ifdef HAVE_SSL
+ starttls:
d(fprintf (stderr, "sending : STARTTLS\r\n"));
if (camel_stream_write (tcp_stream, "STARTTLS\r\n", 10) == -1) {
camel_exception_setv (ex, errno == EINTR ? CAMEL_EXCEPTION_USER_CANCEL : CAMEL_EXCEPTION_SYSTEM,
@@ -372,55 +408,38 @@ connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, Cam
transport->connected = FALSE;
return FALSE;
+#endif /* HAVE_SSL */
}
-static struct {
- char *value;
- char *serv;
- int mode;
-} ssl_options[] = {
- { "", "smtps", MODE_SSL }, /* really old (1.x) */
- { "always", "smtps", MODE_SSL },
- { "when-possible", "smtp", MODE_TLS },
- { "never", "smtp", MODE_CLEAR },
- { NULL, "smtp", MODE_CLEAR },
-};
-
static gboolean
connect_to_server_wrapper (CamelService *service, CamelException *ex)
{
- struct addrinfo hints, *ai;
- const char *ssl_mode;
- int mode, ret, i;
- char *serv;
+#ifdef HAVE_SSL
+ CamelSmtpTransport *transport = (CamelSmtpTransport *) service;
- if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
- for (i = 0; ssl_options[i].value; i++)
- if (!strcmp (ssl_options[i].value, ssl_mode))
- break;
- mode = ssl_options[i].mode;
- serv = ssl_options[i].serv;
+ if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL_ALWAYS) {
+ /* First try connecting to the SSL port */
+ if (!connect_to_server (service, FALSE, ex)) {
+ if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) {
+ /* Seems the SSL port is unavailable, lets try STARTTLS */
+ camel_exception_clear (ex);
+ return connect_to_server (service, TRUE, ex);
+ } else {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ } else if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL_WHEN_POSSIBLE) {
+ /* If the server supports STARTTLS, use it */
+ return connect_to_server (service, TRUE, ex);
} else {
- mode = MODE_CLEAR;
- serv = "smtp";
+ /* User doesn't care about SSL */
+ return connect_to_server (service, FALSE, ex);
}
-
- if (service->url->port) {
- serv = g_alloca (16);
- sprintf (serv, "%d", service->url->port);
- }
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = PF_UNSPEC;
- if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex)))
- return FALSE;
-
- ret = connect_to_server (service, ai, mode, ex);
-
- camel_freeaddrinfo (ai);
-
- return ret;
+#else
+ return connect_to_server (service, FALSE, ex);
+#endif
}
static gboolean
diff --git a/camel/providers/smtp/camel-smtp-transport.h b/camel/providers/smtp/camel-smtp-transport.h
index 7b5ad88f12..87fcafb58b 100644
--- a/camel/providers/smtp/camel-smtp-transport.h
+++ b/camel/providers/smtp/camel-smtp-transport.h
@@ -43,7 +43,13 @@ extern "C" {
#define CAMEL_SMTP_TRANSPORT_ENHANCEDSTATUSCODES (1 << 2)
#define CAMEL_SMTP_TRANSPORT_STARTTLS (1 << 3)
-#define CAMEL_SMTP_TRANSPORT_AUTH_EQUAL (1 << 4) /* set if we are using authtypes from a broken AUTH= */
+#define CAMEL_SMTP_TRANSPORT_USE_SSL_ALWAYS (1 << 4)
+#define CAMEL_SMTP_TRANSPORT_USE_SSL_WHEN_POSSIBLE (1 << 5)
+
+#define CAMEL_SMTP_TRANSPORT_USE_SSL (CAMEL_SMTP_TRANSPORT_USE_SSL_ALWAYS | \
+ CAMEL_SMTP_TRANSPORT_USE_SSL_WHEN_POSSIBLE)
+
+#define CAMEL_SMTP_TRANSPORT_AUTH_EQUAL (1 << 6) /* set if we are using authtypes from a broken AUTH= */
typedef struct {
CamelTransport parent_object;
diff --git a/camel/tests/data/messages/.cvsignore b/camel/tests/data/messages/.cvsignore
deleted file mode 100644
index e358dd1903..0000000000
--- a/camel/tests/data/messages/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-*.msg