Index: pidgin-2.6.6/libpurple/protocols/oscar/clientlogin.c
===================================================================
--- pidgin-2.6.6.orig/libpurple/protocols/oscar/clientlogin.c
+++ pidgin-2.6.6/libpurple/protocols/oscar/clientlogin.c
@@ -42,8 +42,36 @@
 #include "cipher.h"
 #include "core.h"
 
-#define URL_CLIENT_LOGIN "https://api.screenname.aol.com/auth/clientLogin"
-#define URL_START_OSCAR_SESSION "https://api.oscar.aol.com/aim/startOSCARSession"
+#define AIM_LOGIN_HOST "api.screenname.aol.com"
+#define ICQ_LOGIN_HOST "api.login.icq.net"
+
+#define AIM_API_HOST "api.oscar.aol.com"
+#define ICQ_API_HOST "api.icq.net"
+
+#define CLIENT_LOGIN_PAGE "/auth/clientLogin"
+#define START_OSCAR_SESSION_PAGE "/aim/startOSCARSession"
+
+#define HTTPS_FORMAT_URL(host, page) "https://" host page
+
+static const gchar *client_login_urls[] = {
+	HTTPS_FORMAT_URL(AIM_LOGIN_HOST, CLIENT_LOGIN_PAGE),
+	HTTPS_FORMAT_URL(ICQ_LOGIN_HOST, CLIENT_LOGIN_PAGE),
+};
+
+static const gchar *start_oscar_session_urls[] = {
+	HTTPS_FORMAT_URL(AIM_API_HOST, START_OSCAR_SESSION_PAGE),
+	HTTPS_FORMAT_URL(ICQ_API_HOST, START_OSCAR_SESSION_PAGE),
+};
+
+static const gchar *get_client_login_url(OscarData *od)
+{
+	return client_login_urls[od->icq ? 1 : 0];
+}
+
+static const gchar *get_start_oscar_session_url(OscarData *od)
+{
+	return start_oscar_session_urls[od->icq ? 1 : 0];
+}
 
 /*
  * Using clientLogin requires a developer ID.  This key is for libpurple.
@@ -65,10 +93,22 @@ static const char *get_client_key(OscarD
 static gchar *generate_error_message(xmlnode *resp, const char *url)
 {
 	xmlnode *text;
+	xmlnode *status_code_node;
+	gchar *status_code;
+	gboolean have_error_code = TRUE;
 	gchar *err = NULL;
 	gchar *details = NULL;
 
-	if (resp && (text = xmlnode_get_child(resp, "statusText"))) {
+	status_code_node = xmlnode_get_child(resp, "statusCode");
+	if (status_code_node) {
+		/* We can get 200 OK here if the server omitted something we think it shouldn't have (see #12783).
+		 * No point in showing the "Ok" string to the user.
+		 */
+		if ((status_code = xmlnode_get_data_unescaped(status_code_node)) && strcmp(status_code, "200") == 0) {
+			have_error_code = FALSE;
+		}
+	}
+	if (have_error_code && resp && (text = xmlnode_get_child(resp, "statusText"))) {
 		details = xmlnode_get_data(text);
 	}
 
@@ -125,13 +165,12 @@ static gchar *generate_signature(const c
 
 static gboolean parse_start_oscar_session_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **host, unsigned short *port, char **cookie, char **tls_certname)
 {
+	OscarData *od = purple_connection_get_protocol_data(gc);
 	xmlnode *response_node, *tmp_node, *data_node;
 	xmlnode *host_node = NULL, *port_node = NULL, *cookie_node = NULL, *tls_node = NULL;
-	gboolean use_tls;
 	char *tmp;
 	guint code;
-
-	use_tls = purple_account_get_bool(purple_connection_get_account(gc), "use_ssl", OSCAR_DEFAULT_USE_SSL);
+	const gchar *encryption_type = purple_account_get_string(purple_connection_get_account(gc), "encryption", OSCAR_DEFAULT_ENCRYPTION);
 
 	/* Parse the response as XML */
 	response_node = xmlnode_from_str(response, response_len);
@@ -142,7 +181,7 @@ static gboolean parse_start_oscar_sessio
 				"response as XML: %s\n", response);
 		/* Note to translators: %s in this string is a URL */
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -156,7 +195,6 @@ static gboolean parse_start_oscar_sessio
 		host_node = xmlnode_get_child(data_node, "host");
 		port_node = xmlnode_get_child(data_node, "port");
 		cookie_node = xmlnode_get_child(data_node, "cookie");
-		tls_node = xmlnode_get_child(data_node, "tlsCertName");
 	}
 
 	/* Make sure we have a status code */
@@ -165,7 +203,7 @@ static gboolean parse_start_oscar_sessio
 		purple_debug_error("oscar", "startOSCARSession response was "
 				"missing statusCode: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -177,10 +215,23 @@ static gboolean parse_start_oscar_sessio
 	code = atoi(tmp);
 	if (code != 200)
 	{
+		xmlnode *status_detail_node;
+		guint status_detail = 0;
+
+		status_detail_node = xmlnode_get_child(response_node,
+		                                       "statusDetailCode");
+		if (status_detail_node) {
+			gchar *data = xmlnode_get_data(status_detail_node);
+			if (data) {
+				status_detail = atoi(data);
+				g_free(data);
+			}
+		}
+
 		purple_debug_error("oscar", "startOSCARSession response statusCode "
 				"was %s: %s\n", tmp, response);
 
-		if (code == 401 || code == 607)
+		if ((code == 401 && status_detail != 1014) || code == 607)
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_OTHER_ERROR,
 					_("You have been connecting and disconnecting too "
@@ -190,7 +241,7 @@ static gboolean parse_start_oscar_sessio
 		else {
 			char *msg;
 			msg = generate_error_message(response_node,
-					URL_START_OSCAR_SESSION);
+					get_start_oscar_session_url(od));
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
 			g_free(msg);
@@ -203,15 +254,13 @@ static gboolean parse_start_oscar_sessio
 	g_free(tmp);
 
 	/* Make sure we have everything else */
-	if (data_node == NULL || host_node == NULL ||
-		port_node == NULL || cookie_node == NULL ||
-		(use_tls && tls_node == NULL))
+	if (data_node == NULL || host_node == NULL || port_node == NULL || cookie_node == NULL)
 	{
 		char *msg;
 		purple_debug_error("oscar", "startOSCARSession response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -219,22 +268,37 @@ static gboolean parse_start_oscar_sessio
 		return FALSE;
 	}
 
+	if (strcmp(encryption_type, OSCAR_NO_ENCRYPTION) != 0) {
+		tls_node = xmlnode_get_child(data_node, "tlsCertName");
+		if (tls_node != NULL) {
+			*tls_certname = xmlnode_get_data_unescaped(tls_node);
+		} else {
+			if (strcmp(encryption_type, OSCAR_OPPORTUNISTIC_ENCRYPTION) == 0) {
+				purple_debug_warning("oscar", "We haven't received a tlsCertName to use. We will not do SSL to BOS.\n");
+			} else {
+				purple_debug_error("oscar", "startOSCARSession was missing tlsCertName: %s\n", response);
+				purple_connection_error_reason(
+					gc,
+					PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
+					_("You required encryption in your account settings, but one of the servers doesn't support it."));
+				xmlnode_free(response_node);
+				return FALSE;
+			}
+		}
+	}
+
 	/* Extract data from the XML */
 	*host = xmlnode_get_data_unescaped(host_node);
 	tmp = xmlnode_get_data_unescaped(port_node);
 	*cookie = xmlnode_get_data_unescaped(cookie_node);
 
-	if (use_tls)
-		*tls_certname = xmlnode_get_data_unescaped(tls_node);
-
-	if (*host == NULL || **host == '\0' || tmp == NULL || *tmp == '\0' || *cookie == NULL || **cookie == '\0' ||
-			(use_tls && (*tls_certname == NULL || **tls_certname == '\0')))
+	if (*host == NULL || **host == '\0' || tmp == NULL || *tmp == '\0' || *cookie == NULL || **cookie == '\0')
 	{
 		char *msg;
 		purple_debug_error("oscar", "startOSCARSession response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_START_OSCAR_SESSION);
+				get_start_oscar_session_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -259,7 +323,7 @@ static void start_oscar_session_cb(Purpl
 	char *tls_certname = NULL;
 	unsigned short port;
 	guint8 *cookiedata;
-	gsize cookiedata_len;
+	gsize cookiedata_len = 0;
 
 	od = user_data;
 	gc = od->gc;
@@ -271,7 +335,8 @@ static void start_oscar_session_cb(Purpl
 		/* Note to translators: The first %s is a URL, the second is an
 		   error message. */
 		tmp = g_strdup_printf(_("Error requesting %s: %s"),
-				URL_START_OSCAR_SESSION, error_message);
+				get_start_oscar_session_url(od), error_message ?
+				error_message : _("The server returned an empty response"));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
 		g_free(tmp);
@@ -293,7 +358,8 @@ static void start_oscar_session_cb(Purpl
 static void send_start_oscar_session(OscarData *od, const char *token, const char *session_key, time_t hosttime)
 {
 	char *query_string, *signature, *url;
-	gboolean use_tls = purple_account_get_bool(purple_connection_get_account(od->gc), "use_ssl", OSCAR_DEFAULT_USE_SSL);
+	PurpleAccount *account = purple_connection_get_account(od->gc);
+	const gchar *encryption_type = purple_account_get_string(account, "encryption", OSCAR_DEFAULT_ENCRYPTION);
 
 	/*
 	 * Construct the GET parameters.  0x00000611 is the distid given to
@@ -306,18 +372,20 @@ static void send_start_oscar_session(Osc
 			"&ts=%" PURPLE_TIME_T_MODIFIER
 			"&useTLS=%d",
 			purple_url_encode(token),
-			oscar_get_ui_info_int(od->icq ? "prpl-icq-distid"
-					: "prpl-aim-distid", 0x00000611),
-			get_client_key(od), hosttime, use_tls);
-	signature = generate_signature("GET", URL_START_OSCAR_SESSION,
+			oscar_get_ui_info_int(od->icq ? "prpl-icq-distid" : "prpl-aim-distid", 0x00000611),
+			get_client_key(od),
+			hosttime,
+			strcmp(encryption_type, OSCAR_NO_ENCRYPTION) != 0 ? 1 : 0);
+	signature = generate_signature("GET", get_start_oscar_session_url(od),
 			query_string, session_key);
-	url = g_strdup_printf(URL_START_OSCAR_SESSION "?%s&sig_sha256=%s",
+	url = g_strdup_printf("%s?%s&sig_sha256=%s", get_start_oscar_session_url(od),
 			query_string, signature);
 	g_free(query_string);
 	g_free(signature);
 
 	/* Make the request */
-	od->url_data = purple_util_fetch_url(url, TRUE, NULL, FALSE,
+	od->url_data = purple_util_fetch_url_request_len_with_account(account,
+			url, TRUE, NULL, FALSE, NULL, FALSE, -1,
 			start_oscar_session_cb, od);
 	g_free(url);
 }
@@ -349,6 +417,7 @@ static void send_start_oscar_session(Osc
  */
 static gboolean parse_client_login_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **token, char **secret, time_t *hosttime)
 {
+	OscarData *od = purple_connection_get_protocol_data(gc);
 	xmlnode *response_node, *tmp_node, *data_node;
 	xmlnode *secret_node = NULL, *hosttime_node = NULL, *token_node = NULL, *tokena_node = NULL;
 	char *tmp;
@@ -361,7 +430,7 @@ static gboolean parse_client_login_respo
 		purple_debug_error("oscar", "clientLogin could not parse "
 				"response as XML: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -385,7 +454,7 @@ static gboolean parse_client_login_respo
 		purple_debug_error("oscar", "clientLogin response was "
 				"missing statusCode: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -410,6 +479,9 @@ static gboolean parse_client_login_respo
 				"was %d (%d): %s\n", status_code, status_detail_code, response);
 
 		if (status_code == 330 && status_detail_code == 3011) {
+			PurpleAccount *account = purple_connection_get_account(gc);
+			if (!purple_account_get_remember_password(account))
+				purple_account_set_password(account, NULL);
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
 					_("Incorrect password"));
@@ -425,7 +497,7 @@ static gboolean parse_client_login_respo
 		} else {
 			char *msg;
 			msg = generate_error_message(response_node,
-					URL_CLIENT_LOGIN);
+					get_client_login_url(od));
 			purple_connection_error_reason(gc,
 					PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
 			g_free(msg);
@@ -444,7 +516,7 @@ static gboolean parse_client_login_respo
 		purple_debug_error("oscar", "clientLogin response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -462,7 +534,7 @@ static gboolean parse_client_login_respo
 		purple_debug_error("oscar", "clientLogin response was missing "
 				"something: %s\n", response);
 		msg = generate_error_message(response_node,
-				URL_CLIENT_LOGIN);
+				get_client_login_url(od));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
 		g_free(msg);
@@ -498,7 +570,8 @@ static void client_login_cb(PurpleUtilFe
 	if (error_message != NULL || len == 0) {
 		gchar *tmp;
 		tmp = g_strdup_printf(_("Error requesting %s: %s"),
-				URL_CLIENT_LOGIN, error_message);
+				get_client_login_url(od), error_message ?
+				error_message : _("The server returned an empty response"));
 		purple_connection_error_reason(gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
 		g_free(tmp);
@@ -573,8 +646,9 @@ void send_client_login(OscarData *od, co
 	g_string_free(body, TRUE);
 
 	/* Send the POST request  */
-	od->url_data = purple_util_fetch_url_request(URL_CLIENT_LOGIN,
-			TRUE, NULL, FALSE, request->str, FALSE,
+	od->url_data = purple_util_fetch_url_request_len_with_account(
+			purple_connection_get_account(gc), get_client_login_url(od),
+			TRUE, NULL, FALSE, request->str, FALSE, -1,
 			client_login_cb, od);
 	g_string_free(request, TRUE);
 }
Index: pidgin-2.6.6/libpurple/protocols/oscar/libaim.c
===================================================================
--- pidgin-2.6.6.orig/libpurple/protocols/oscar/libaim.c
+++ pidgin-2.6.6/libpurple/protocols/oscar/libaim.c
@@ -140,7 +140,7 @@ static PurplePluginInfo info =
 static void
 init_plugin(PurplePlugin *plugin)
 {
-	oscar_init(plugin);
+	oscar_init(plugin,FALSE);
 }
 
 PURPLE_INIT_PLUGIN(aim, init_plugin, info);
Index: pidgin-2.6.6/libpurple/protocols/oscar/libicq.c
===================================================================
--- pidgin-2.6.6.orig/libpurple/protocols/oscar/libicq.c
+++ pidgin-2.6.6/libpurple/protocols/oscar/libicq.c
@@ -153,7 +153,7 @@ init_plugin(PurplePlugin *plugin)
 {
 	PurpleAccountOption *option;
 
-	oscar_init(plugin);
+	oscar_init(plugin,TRUE);
 
 	option = purple_account_option_string_new(_("Encoding"), "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
Index: pidgin-2.6.6/libpurple/protocols/oscar/oscar.c
===================================================================
--- pidgin-2.6.6.orig/libpurple/protocols/oscar/oscar.c
+++ pidgin-2.6.6/libpurple/protocols/oscar/oscar.c
@@ -1457,17 +1457,49 @@ recent_buddies_pref_cb(const char *name,
 		aim_ssi_setpresence(od, presence | AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES);
 }
 
+static const gchar *login_servers[] = {
+	AIM_DEFAULT_LOGIN_SERVER,
+	AIM_DEFAULT_SSL_LOGIN_SERVER,
+	ICQ_DEFAULT_LOGIN_SERVER,
+	ICQ_DEFAULT_SSL_LOGIN_SERVER,
+};
+
+static const gchar *
+get_login_server(gboolean is_icq, gboolean use_ssl)
+{
+	return login_servers[(is_icq ? 2 : 0) + (use_ssl ? 1 : 0)];
+}
+
+static gint
+compare_handlers(gconstpointer a, gconstpointer b)
+{
+	guint aa = GPOINTER_TO_UINT(a);
+	guint bb = GPOINTER_TO_UINT(b);
+	guint family1 = aa >> 16;
+	guint family2 = bb >> 16;
+	guint subtype1 = aa & 0xFFFF;
+	guint subtype2 = bb & 0xFFFF;
+	if (family1 != family2) {
+		return family1 - family2;
+	}
+	return subtype1 - subtype2;
+}
+
 void
 oscar_login(PurpleAccount *account)
 {
 	PurpleConnection *gc;
 	OscarData *od;
+	const gchar *encryption_type;
+	GList *handlers;
+	GList *sorted_handlers;
+	GList *cur;
+	GString *msg = g_string_new("");
 
 	gc = purple_account_get_connection(account);
 	od = oscar_data_new();
 	od->gc = gc;
 	purple_connection_set_protocol_data(gc, od);
-
 	oscar_data_addhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, purple_connerr, 0);
 	oscar_data_addhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, flap_connection_established, 0);
 
@@ -1532,6 +1564,23 @@ oscar_login(PurpleAccount *account)
 	oscar_data_addhandler(od, SNAC_FAMILY_USERLOOKUP, SNAC_SUBTYPE_USERLOOKUP_ERROR, purple_parse_searcherror, 0);
 	oscar_data_addhandler(od, SNAC_FAMILY_USERLOOKUP, 0x0003, purple_parse_searchreply, 0);
 
+	g_string_append(msg, "Registered handlers: ");
+#if GLIB_CHECK_VERSION(2,14,0)
+	handlers = g_hash_table_get_keys(od->handlerlist);
+#else
+	handlers = NULL;
+	g_hash_table_foreach(od->handlerlist, hash_table_get_list_of_keys, &handlers);
+#endif /* GLIB < 2.14.0 */
+	sorted_handlers = g_list_sort(g_list_copy(handlers), compare_handlers);
+	for (cur = sorted_handlers; cur; cur = cur->next) {
+		guint x = GPOINTER_TO_UINT(cur->data);
+		g_string_append_printf(msg, "%04x/%04x, ", x >> 16, x & 0xFFFF);
+	}
+	g_list_free(sorted_handlers);
+	g_list_free(handlers);
+	purple_debug_misc("oscar", "%s\n", msg->str);
+	g_string_free(msg, TRUE);
+
 	purple_debug_misc("oscar", "oscar_login: gc = %p\n", gc);
 
 	if (!oscar_util_valid_name(purple_account_get_username(account))) {
@@ -1542,15 +1591,24 @@ oscar_login(PurpleAccount *account)
 		return;
 	}
 
+	gc->flags |= PURPLE_CONNECTION_HTML;
 	if (oscar_util_valid_name_icq((purple_account_get_username(account)))) {
 		od->icq = TRUE;
 	} else {
-		gc->flags |= PURPLE_CONNECTION_HTML;
 		gc->flags |= PURPLE_CONNECTION_AUTO_RESP;
 	}
 
 	od->default_port = purple_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT);
-	od->use_ssl = purple_account_get_bool(account, "use_ssl", OSCAR_DEFAULT_USE_SSL);
+
+	encryption_type = purple_account_get_string(account, "encryption", OSCAR_DEFAULT_ENCRYPTION);
+	if (!purple_ssl_is_supported() && strcmp(encryption_type, OSCAR_REQUIRE_ENCRYPTION) == 0) {
+		purple_connection_error_reason(
+			gc,
+			PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
+			_("You required encryption in your account settings, but encryption is not supported by your system."));
+		return;
+	}
+	od->use_ssl = purple_ssl_is_supported() && strcmp(encryption_type, OSCAR_NO_ENCRYPTION) != 0;
 
 	/* Connect to core Purple signals */
 	purple_prefs_connect_callback(gc, "/purple/away/idle_reporting", idle_reporting_pref_cb, gc);
@@ -1575,13 +1633,7 @@ oscar_login(PurpleAccount *account)
 		newconn = flap_connection_new(od, SNAC_FAMILY_AUTH);
 
 		if (od->use_ssl) {
-			if (!purple_ssl_is_supported()) {
-				purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
-						_("SSL support unavailable"));
-				return;
-			}
-
-			server = purple_account_get_string(account, "server", OSCAR_DEFAULT_SSL_LOGIN_SERVER);
+			server = purple_account_get_string(account, "server", get_login_server(od->icq, TRUE));
 
 			/*
 			 * If the account's server is what the oscar prpl has offered as
@@ -1590,27 +1642,27 @@ oscar_login(PurpleAccount *account)
 			 * do what we know is best for them and change the setting out
 			 * from under them to the SSL login server.
 			 */
-			if (!strcmp(server, OSCAR_DEFAULT_LOGIN_SERVER) || !strcmp(server, OSCAR_OLD_LOGIN_SERVER)) {
+			if (!strcmp(server, get_login_server(od->icq, FALSE)) || !strcmp(server, AIM_ALT_LOGIN_SERVER)) {
 				purple_debug_info("oscar", "Account uses SSL, so changing server to default SSL server\n");
-				purple_account_set_string(account, "server", OSCAR_DEFAULT_SSL_LOGIN_SERVER);
-				server = OSCAR_DEFAULT_SSL_LOGIN_SERVER;
+				purple_account_set_string(account, "server", get_login_server(od->icq, TRUE));
+				server = get_login_server(od->icq, TRUE);
 			}
 
 			newconn->gsc = purple_ssl_connect(account, server,
 					purple_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT),
 					ssl_connection_established_cb, ssl_connection_error_cb, newconn);
 		} else {
-			server = purple_account_get_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER);
+			server = purple_account_get_string(account, "server", get_login_server(od->icq, FALSE));
 
 			/*
 			 * See the comment above. We do the reverse here. If they don't want
 			 * SSL but their server is set to OSCAR_DEFAULT_SSL_LOGIN_SERVER,
 			 * set it back to the default.
 			 */
-			if (!strcmp(server, OSCAR_DEFAULT_SSL_LOGIN_SERVER)) {
+			if (!strcmp(server, get_login_server(od->icq, TRUE))) {
 				purple_debug_info("oscar", "Account does not use SSL, so changing server back to non-SSL\n");
-				purple_account_set_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER);
-				server = OSCAR_DEFAULT_LOGIN_SERVER;
+				purple_account_set_string(account, "server", get_login_server(od->icq, FALSE));
+				server = get_login_server(od->icq, FALSE);
 			}
 
 			newconn->connect_data = purple_proxy_connect(NULL, account, server,
@@ -1626,7 +1678,6 @@ oscar_login(PurpleAccount *account)
 	}
 
 	purple_connection_update_progress(gc, _("Connecting"), 0, OSCAR_CONNECT_STEPS);
-	ck[0] = 0x5a;
 }
 
 void
@@ -7193,20 +7244,39 @@ static gboolean oscar_uri_handler(const
 	return FALSE;
 }
 
-void oscar_init(PurplePlugin *plugin)
+void oscar_init(PurplePlugin *plugin, gboolean is_icq)
 {
 	PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
 	PurpleAccountOption *option;
 	static gboolean init = FALSE;
+	static const gchar *encryption_keys[] = {
+		N_("Use encryption if available"),
+		N_("Require encryption"),
+		N_("Don't use encryption"),
+		NULL
+	};
+	static const gchar *encryption_values[] = {
+		OSCAR_OPPORTUNISTIC_ENCRYPTION,
+		OSCAR_REQUIRE_ENCRYPTION,
+		OSCAR_NO_ENCRYPTION,
+		NULL
+	};
+	GList *encryption_options = NULL;
+	int i;
 
-	option = purple_account_option_string_new(_("Server"), "server", OSCAR_DEFAULT_LOGIN_SERVER);
+	option = purple_account_option_string_new(_("Server"), "server", get_login_server(is_icq, TRUE));
 	prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option);
 
 	option = purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT);
 	prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option);
 
-	option = purple_account_option_bool_new(_("Use SSL"), "use_ssl",
-			OSCAR_DEFAULT_USE_SSL);
+	for (i = 0; encryption_keys[i]; i++) {
+		PurpleKeyValuePair *kvp = g_new0(PurpleKeyValuePair, 1);
+		kvp->key = g_strdup(_(encryption_keys[i]));
+		kvp->value = g_strdup(encryption_values[i]);
+		encryption_options = g_list_append(encryption_options, kvp);
+	}
+	option = purple_account_option_list_new(_("Connection security"), "encryption", encryption_options);
 	prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option);
 
 	option = purple_account_option_bool_new(_("Use clientLogin"), "use_clientlogin",
@@ -7240,4 +7310,3 @@ void oscar_init(PurplePlugin *plugin)
 	purple_signal_connect(purple_get_core(), "uri-handler", &init,
 		PURPLE_CALLBACK(oscar_uri_handler), NULL);
 }
-
Index: pidgin-2.6.6/libpurple/protocols/oscar/oscarcommon.h
===================================================================
--- pidgin-2.6.6.orig/libpurple/protocols/oscar/oscarcommon.h
+++ pidgin-2.6.6/libpurple/protocols/oscar/oscarcommon.h
@@ -30,11 +30,20 @@
 #include "prpl.h"
 #include "version.h"
 #include "notify.h"
+#include "status.h"
+
+#define AIM_DEFAULT_LOGIN_SERVER "login.oscar.aol.com"
+#define AIM_ALT_LOGIN_SERVER "login.messaging.aol.com"
+#define AIM_DEFAULT_SSL_LOGIN_SERVER "slogin.oscar.aol.com"
+#define ICQ_DEFAULT_LOGIN_SERVER "login.icq.com"
+#define ICQ_DEFAULT_SSL_LOGIN_SERVER "slogin.icq.com"
 
-#define OSCAR_DEFAULT_LOGIN_SERVER "login.messaging.aol.com"
 #define OSCAR_DEFAULT_LOGIN_PORT 5190
-#define OSCAR_DEFAULT_SSL_LOGIN_SERVER "slogin.oscar.aol.com"
-#define OSCAR_OLD_LOGIN_SERVER "login.oscar.aol.com"
+
+#define OSCAR_OPPORTUNISTIC_ENCRYPTION "opportunistic_encryption"
+#define OSCAR_REQUIRE_ENCRYPTION "require_encryption"
+#define OSCAR_NO_ENCRYPTION "no_encryption"
+
 #ifndef _WIN32
 #define OSCAR_DEFAULT_CUSTOM_ENCODING "ISO-8859-1"
 #else
@@ -45,8 +54,8 @@
 #define OSCAR_DEFAULT_WEB_AWARE FALSE
 #define OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY FALSE
 #define OSCAR_DEFAULT_ALLOW_MULTIPLE_LOGINS TRUE
-#define OSCAR_DEFAULT_USE_SSL TRUE
 #define OSCAR_DEFAULT_USE_CLIENTLOGIN TRUE
+#define OSCAR_DEFAULT_ENCRYPTION OSCAR_OPPORTUNISTIC_ENCRYPTION
 
 #ifdef _WIN32
 const char *oscar_get_locale_charset(void);
@@ -95,4 +104,4 @@ PurpleXfer *oscar_new_xfer(PurpleConnect
 gboolean oscar_offline_message(const PurpleBuddy *buddy);
 void oscar_format_username(PurpleConnection *gc, const char *nick);
 GList *oscar_actions(PurplePlugin *plugin, gpointer context);
-void oscar_init(PurplePlugin *plugin);
+void oscar_init(PurplePlugin *plugin, gboolean is_icq);
