Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 1febf5c93b231942cd9cac8ac6a5a0d830c581cc)
+++ protocols/msn/msn.c	(revision 46dca11bfad72bb9365b85b433f1e812733f31ec)
@@ -90,19 +90,5 @@
 			msn_sb_destroy( md->switchboards->data );
 		
-		if( md->msgq )
-		{
-			struct msn_message *m;
-			
-			for( l = md->msgq; l; l = l->next )
-			{
-				m = l->data;
-			
-				imcb_log( ic, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
-				g_free( m->who );
-				g_free( m->text );
-				g_free( m );
-			}
-			g_slist_free( md->msgq );
-		}
+		msn_msgq_purge( ic, &md->msgq );
 		
 		while( md->groupcount > 0 )
Index: protocols/msn/msn.h
===================================================================
--- protocols/msn/msn.h	(revision 1febf5c93b231942cd9cac8ac6a5a0d830c581cc)
+++ protocols/msn/msn.h	(revision 46dca11bfad72bb9365b85b433f1e812733f31ec)
@@ -158,4 +158,5 @@
 int msn_handler( struct msn_handler_data *h );
 char *msn_http_encode( const char *input );
+void msn_msgq_purge( struct im_connection *ic, GSList **list );
 
 /* tables.c */
Index: protocols/msn/msn_util.c
===================================================================
--- protocols/msn/msn_util.c	(revision 1febf5c93b231942cd9cac8ac6a5a0d830c581cc)
+++ protocols/msn/msn_util.c	(revision 46dca11bfad72bb9365b85b433f1e812733f31ec)
@@ -339,2 +339,36 @@
 	return ret;
 }
+
+void msn_msgq_purge( struct im_connection *ic, GSList **list )
+{
+	struct msn_message *m;
+	GString *ret;
+	GSList *l;
+	
+	l = *list;
+	if( l == NULL )
+		return;
+	
+	m = l->data;
+	ret = g_string_sized_new( 1024 );
+	g_string_printf( ret, "WARNING: Cleaning up MSN (switchboard) connection with unsent "
+	                      "messages to %s:", m->who ? m->who : "unknown recipient" );
+	
+	while( l )
+	{
+		m = l->data;
+		
+		g_string_append_printf( ret, "\n%s", m->text );
+		
+		g_free( m->who );
+		g_free( m->text );
+		g_free( m );
+		
+		l = l->next;
+	}
+	g_slist_free( *list );
+	*list = NULL;
+	
+	imcb_log( ic, ret->str );
+	g_string_free( ret, TRUE );
+}
Index: protocols/msn/sb.c
===================================================================
--- protocols/msn/sb.c	(revision 1febf5c93b231942cd9cac8ac6a5a0d830c581cc)
+++ protocols/msn/sb.c	(revision 46dca11bfad72bb9365b85b433f1e812733f31ec)
@@ -128,5 +128,5 @@
 		if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 )
 		{
-			buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 );
+			buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 + 1 );
 			i = strlen( MSN_MESSAGE_HEADERS );
 			
@@ -207,23 +207,5 @@
 	debug( "Destroying switchboard: %s", sb->who ? sb->who : sb->key ? sb->key : "" );
 	
-	if( sb->msgq )
-	{
-		struct msn_message *m;
-		GSList *l;
-		
-		for( l = sb->msgq; l; l = l->next )
-		{
-			m = l->data;
-
-			g_free( m->who );
-			g_free( m->text );
-			g_free( m );
-		}
-		g_slist_free( sb->msgq );
-		
-		imcb_log( ic, "Warning: Closing down MSN switchboard connection with "
-		                   "unsent message to %s, you'll have to resend it.",
-		                   sb->who ? sb->who : "(unknown)" );
-	}
+	msn_msgq_purge( ic, &sb->msgq );
 	
 	if( sb->key ) g_free( sb->key );
@@ -266,5 +248,5 @@
 	if( source != sb->fd )
 	{
-		debug( "ERROR %d while connecting to switchboard server", 1 );
+		debug( "Error %d while connecting to switchboard server", 1 );
 		msn_sb_destroy( sb );
 		return FALSE;
@@ -287,5 +269,5 @@
 		sb->inp = b_input_add( sb->fd, GAIM_INPUT_READ, msn_sb_callback, sb );
 	else
-		debug( "ERROR %d while connecting to switchboard server", 2 );
+		debug( "Error %d while connecting to switchboard server", 2 );
 	
 	return FALSE;
@@ -298,5 +280,5 @@
 	if( msn_handler( sb->handler ) == -1 )
 	{
-		debug( "ERROR: Switchboard died" );
+		debug( "Error: Switchboard died" );
 		msn_sb_destroy( sb );
 		
@@ -555,7 +537,4 @@
 			if( sb->who )
 			{
-				struct msn_message *m;
-				GSList *l;
-				
 				/* Apparently some invitation failed. We might want to use this
 				   board later, so keep it as a spare. */
@@ -564,13 +543,5 @@
 				
 				/* Also clear the msgq, otherwise someone else might get them. */
-				for( l = sb->msgq; l; l = l->next )
-				{
-					m = l->data;
-					g_free( m->who );
-					g_free( m->text );
-					g_free( m );
-				}
-				g_slist_free( sb->msgq );
-				sb->msgq = NULL;
+				msn_msgq_purge( ic, &sb->msgq );
 			}
 			
