Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/jabber/jabber.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -70,5 +70,5 @@
 	
 	s = set_add( &acc->set, "server", NULL, set_eval_account, acc );
-	s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
+	s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY | SET_NULL_OK;
 	
 	s = set_add( &acc->set, "ssl", "false", set_eval_bool, acc );
Index: protocols/jabber/jabber_util.c
===================================================================
--- protocols/jabber/jabber_util.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/jabber/jabber_util.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -37,8 +37,8 @@
 		/* Priority is a signed 8-bit integer, according to RFC 3921. */
 		if( i < -128 || i > 127 )
-			return NULL;
+			return SET_INVALID;
 	}
 	else
-		return NULL;
+		return SET_INVALID;
 	
 	/* Only run this stuff if the account is online ATM,
Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/msn/msn.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -113,5 +113,4 @@
 {
 	struct msn_switchboard *sb;
-	struct msn_data *md = ic->proto_data;
 	
 	if( ( sb = msn_sb_by_handle( ic, who ) ) )
@@ -122,5 +121,4 @@
 	{
 		struct msn_message *m;
-		char buf[1024];
 		
 		/* Create a message. We have to arrange a usable switchboard, and send the message later. */
@@ -129,38 +127,5 @@
 		m->text = g_strdup( message );
 		
-		/* FIXME: *CHECK* the reliability of using spare sb's! */
-		if( ( sb = msn_sb_spare( ic ) ) )
-		{
-			debug( "Trying to use a spare switchboard to message %s", who );
-			
-			sb->who = g_strdup( who );
-			g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
-			if( msn_sb_write( sb, buf, strlen( buf ) ) )
-			{
-				/* He/She should join the switchboard soon, let's queue the message. */
-				sb->msgq = g_slist_append( sb->msgq, m );
-				return( 1 );
-			}
-		}
-		
-		debug( "Creating a new switchboard to message %s", who );
-		
-		/* If we reach this line, there was no spare switchboard, so let's make one. */
-		g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
-		if( !msn_write( ic, buf, strlen( buf ) ) )
-		{
-			g_free( m->who );
-			g_free( m->text );
-			g_free( m );
-			
-			return( 0 );
-		}
-		
-		/* And queue the message to md. We'll pick it up when the switchboard comes up. */
-		md->msgq = g_slist_append( md->msgq, m );
-		
-		/* FIXME: If the switchboard creation fails, the message will not be sent. */
-		
-		return( 1 );
+		return msn_sb_write_msg( ic, m );
 	}
 	
@@ -252,6 +217,4 @@
 {
 	struct msn_switchboard *sb;
-	struct msn_data *md = ic->proto_data;
-	char buf[1024];
 	
 	if( ( sb = msn_sb_by_handle( ic, who ) ) )
@@ -263,20 +226,4 @@
 	{
 		struct msn_message *m;
-		
-		if( ( sb = msn_sb_spare( ic ) ) )
-		{
-			debug( "Trying to reuse an existing switchboard as a groupchat with %s", who );
-			g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
-			if( msn_sb_write( sb, buf, strlen( buf ) ) )
-				return msn_sb_to_chat( sb );
-		}
-		
-		/* If the stuff above failed for some reason: */
-		debug( "Creating a new switchboard to groupchat with %s", who );
-		
-		/* Request a new switchboard. */
-		g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
-		if( !msn_write( ic, buf, strlen( buf ) ) )
-			return( 0 );
 		
 		/* Create a magic message. This is quite hackish, but who cares? :-P */
@@ -285,8 +232,6 @@
 		m->text = g_strdup( GROUPCHAT_SWITCHBOARD_MESSAGE );
 		
-		/* Queue the magic message and cross your fingers. */
-		md->msgq = g_slist_append( md->msgq, m );
-		
-		/* FIXME: Can I try to return something here already? */
+		msn_sb_write_msg( ic, m );
+
 		return NULL;
 	}
Index: protocols/msn/msn.h
===================================================================
--- protocols/msn/msn.h	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/msn/msn.h	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -23,4 +23,7 @@
   Suite 330, Boston, MA  02111-1307  USA
 */
+
+#ifndef _MSN_H
+#define _MSN_H
 
 /* Some hackish magicstrings to make special-purpose messages/switchboards.
@@ -176,2 +179,5 @@
 void msn_sb_destroy( struct msn_switchboard *sb );
 gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond );
+int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m );
+
+#endif //_MSN_H
Index: protocols/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/msn/ns.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -278,23 +278,9 @@
 		if( num_parts == 5 )
 		{
-			int i, groupcount;
-			
-			groupcount = atoi( cmd[4] );
-			if( groupcount > 0 )
-			{
-				/* valgrind says this is leaking memory, I'm guessing
-				   that this happens during server redirects. */
-				if( md->grouplist )
-				{
-					for( i = 0; i < md->groupcount; i ++ )
-						g_free( md->grouplist[i] );
-					g_free( md->grouplist );
-				}
-				
-				md->groupcount = groupcount;
+			md->buddycount = atoi( cmd[3] );
+			md->groupcount = atoi( cmd[4] );
+			if( md->groupcount > 0 )
 				md->grouplist = g_new0( char *, md->groupcount );
-			}
-			
-			md->buddycount = atoi( cmd[3] );
+			
 			if( !*cmd[3] || md->buddycount == 0 )
 				msn_logged_in( ic );
@@ -679,7 +665,4 @@
 					imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
 				}
-				
-				g_free( inbox );
-				g_free( folders );
 			}
 			else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
Index: protocols/msn/sb.c
===================================================================
--- protocols/msn/sb.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/msn/sb.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -44,4 +44,46 @@
 		return( 0 );
 	}
+	
+	return( 1 );
+}
+
+int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m )
+{
+	struct msn_data *md = ic->proto_data;
+	struct msn_switchboard *sb;
+	char buf[1024];
+
+	/* FIXME: *CHECK* the reliability of using spare sb's! */
+	if( ( sb = msn_sb_spare( ic ) ) )
+	{
+		debug( "Trying to use a spare switchboard to message %s", m->who );
+		
+		sb->who = g_strdup( m->who );
+		g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who );
+		if( msn_sb_write( sb, buf, strlen( buf ) ) )
+		{
+			/* He/She should join the switchboard soon, let's queue the message. */
+			sb->msgq = g_slist_append( sb->msgq, m );
+			return( 1 );
+		}
+	}
+	
+	debug( "Creating a new switchboard to message %s", m->who );
+	
+	/* If we reach this line, there was no spare switchboard, so let's make one. */
+	g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
+	if( !msn_write( ic, buf, strlen( buf ) ) )
+	{
+		g_free( m->who );
+		g_free( m->text );
+		g_free( m );
+		
+		return( 0 );
+	}
+	
+	/* And queue the message to md. We'll pick it up when the switchboard comes up. */
+	md->msgq = g_slist_append( md->msgq, m );
+	
+	/* FIXME: If the switchboard creation fails, the message will not be sent. */
 	
 	return( 1 );
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/nogaim.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -267,4 +267,8 @@
 	   protocols. */
 	imc_set_away( ic, u->away );
+	
+	/* Apparently we're connected successfully, so reset the
+	   exponential backoff timer. */
+	ic->acc->auto_reconnect_delay = 0;
 }
 
@@ -290,4 +294,5 @@
 	user_t *t, *u;
 	account_t *a;
+	int delay;
 	
 	/* Nested calls might happen sometimes, this is probably the best
@@ -329,8 +334,7 @@
 	}
 	else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
-	         set_getbool( &a->set, "auto_reconnect" ) )
-	{
-		int delay = set_getint( &irc->set, "auto_reconnect_delay" );
-		
+	         set_getbool( &a->set, "auto_reconnect" ) &&
+	         ( delay = account_reconnect_delay( a ) ) > 0 )
+	{
 		imcb_log( ic, "Reconnecting in %d seconds..", delay );
 		a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );
Index: protocols/yahoo/libyahoo2.c
===================================================================
--- protocols/yahoo/libyahoo2.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/yahoo/libyahoo2.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -69,4 +69,6 @@
 #ifdef __MINGW32__
 # include <winsock2.h>
+# define write(a,b,c) send(a,b,c,0)
+# define read(a,b,c)  recv(a,b,c,0)
 #endif
 
Index: protocols/yahoo/yahoo.c
===================================================================
--- protocols/yahoo/yahoo.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/yahoo/yahoo.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -666,7 +666,4 @@
 	
 	imcb_error( ic, "%s", err );
-	
-	if( fatal )
-		imc_logout( ic, TRUE );
 }
 
Index: protocols/yahoo/yahoo_httplib.c
===================================================================
--- protocols/yahoo/yahoo_httplib.c	(revision 6738a676c7a3895988de4bd9eacfe8fa0ef73cc3)
+++ protocols/yahoo/yahoo_httplib.c	(revision 823de9d44f262ea2364ac8ec6a1e18e0f7dab658)
@@ -51,4 +51,6 @@
 #ifdef __MINGW32__
 # include <winsock2.h>
+# define write(a,b,c) send(a,b,c,0)
+# define read(a,b,c)  recv(a,b,c,0)
 # define snprintf _snprintf
 #endif
