Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 4230221725b0cd0f6a9b84f726759d20ff9f0e62)
+++ protocols/msn/msn.c	(revision a8305126a38eb977c51046dd4ec3ac258a20a98f)
@@ -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 4230221725b0cd0f6a9b84f726759d20ff9f0e62)
+++ protocols/msn/msn.h	(revision a8305126a38eb977c51046dd4ec3ac258a20a98f)
@@ -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/sb.c
===================================================================
--- protocols/msn/sb.c	(revision 4230221725b0cd0f6a9b84f726759d20ff9f0e62)
+++ protocols/msn/sb.c	(revision a8305126a38eb977c51046dd4ec3ac258a20a98f)
@@ -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 );
