Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 7281ad13e9dadb1369590617eb06265b084a1726)
+++ protocols/msn/msn.c	(revision bc676acb5f316f0688ab9f99dd2b73315a6ad50c)
@@ -232,11 +232,7 @@
 {
 	struct msn_switchboard *sb = msn_sb_by_chat( c );
-	char buf[1024];
 	
 	if( sb )
-	{
-		g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
-		msn_sb_write( sb, buf, strlen( buf ) );
-	}
+		msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, who );
 }
 
@@ -246,5 +242,5 @@
 	
 	if( sb )
-		msn_sb_write( sb, "OUT\r\n", 5 );
+		msn_sb_write( sb, "OUT\r\n" );
 }
 
Index: protocols/msn/msn.h
===================================================================
--- protocols/msn/msn.h	(revision 7281ad13e9dadb1369590617eb06265b084a1726)
+++ protocols/msn/msn.h	(revision bc676acb5f316f0688ab9f99dd2b73315a6ad50c)
@@ -53,8 +53,13 @@
 */
 
+/* <= BitlBee 3.0.5
 #define MSNP11_PROD_KEY "ILTXC!4IXB5FB*PX"
 #define MSNP11_PROD_ID  "PROD0119GSJUC$18"
-#define MSNP_VER        "MSNP15"
-#define MSNP_BUILD      "8.5.1288"
+*/
+
+#define MSNP11_PROD_KEY "C1BX{V4W}Q3*10SM"
+#define MSNP11_PROD_ID  "PROD0120PW!CCV9@"
+#define MSNP_VER        "MSNP18"
+#define MSNP_BUILD      "14.0.8117.416"
 
 #define MSN_SB_NEW         -24062002
@@ -222,5 +227,5 @@
 
 /* ns.c */
-int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... );
+int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ) G_GNUC_PRINTF( 3, 4 );
 gboolean msn_ns_connect( struct im_connection *ic, struct msn_handler_data *handler, const char *host, int port );
 void msn_ns_close( struct msn_handler_data *handler );
@@ -228,4 +233,6 @@
 void msn_auth_got_contact_list( struct im_connection *ic );
 int msn_ns_finish_login( struct im_connection *ic );
+int msn_ns_sendmessage( struct im_connection *ic, struct bee_user *bu, const char *text );
+void msn_ns_oim_send_queue( struct im_connection *ic, GSList **msgq );
 
 /* msn_util.c */
@@ -250,5 +257,5 @@
 
 /* sb.c */
-int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... );
+int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... ) G_GNUC_PRINTF( 2, 3 );;
 struct msn_switchboard *msn_sb_create( struct im_connection *ic, char *host, int port, char *key, int session );
 struct msn_switchboard *msn_sb_by_handle( struct im_connection *ic, char *handle );
Index: protocols/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision 7281ad13e9dadb1369590617eb06265b084a1726)
+++ protocols/msn/ns.c	(revision bc676acb5f316f0688ab9f99dd2b73315a6ad50c)
@@ -757,5 +757,5 @@
 	if( token )
 	{
-		msn_ns_write( ic, -1, "USR %d SSO S %s %s\r\n", ++md->trId, md->tokens[0], token );
+		msn_ns_write( ic, -1, "USR %d SSO S %s %s {7535ef7c-ff92-11e1-8069-50e5493b06de}\r\n", ++md->trId, md->tokens[0], token );
 	}
 	else
@@ -886,2 +886,50 @@
 	return 1;
 }
+
+int msn_ns_sendmessage( struct im_connection *ic, bee_user_t *bu, const char *text )
+{
+	struct msn_data *md = ic->proto_data;
+	char *buf;
+	
+	if( strncmp( text, "\r\r\r", 3 ) == 0 )
+		/* Err. Shouldn't happen but I guess it can. Don't send others
+		   any of the "SHAKE THAT THING" messages. :-D */
+		return 1;
+	
+	buf = g_strdup_printf( "%s%s", MSN_MESSAGE_HEADERS, text );
+	
+	if( msn_ns_write( ic, -1, "UUM %d %s %d %d %zd\r\n%s",
+	                          ++md->trId, bu->handle,
+	                          1, /* type == MSN offline message */
+	                          1, /* type == IM (not nudge/typing) */
+	                          strlen( buf ), buf ) )
+		return 1;
+	else
+		return 0;
+}
+
+void msn_ns_oim_send_queue( struct im_connection *ic, GSList **msgq )
+{
+	GSList *l;
+	
+	for( l = *msgq; l; l = l->next )
+	{
+		struct msn_message *m = l->data;
+		bee_user_t *bu = bee_user_by_handle( ic->bee, ic, m->who );
+		
+		if( bu )
+			if( !msn_ns_sendmessage( ic, bu, m->text ) )
+				return;
+	}
+	
+	while( *msgq != NULL )
+	{
+		struct msn_message *m = (*msgq)->data;
+		
+		g_free( m->who );
+		g_free( m->text );
+		g_free( m );
+		
+		*msgq = g_slist_remove( *msgq, m );
+	}
+}
Index: protocols/msn/sb.c
===================================================================
--- protocols/msn/sb.c	(revision 7281ad13e9dadb1369590617eb06265b084a1726)
+++ protocols/msn/sb.c	(revision bc676acb5f316f0688ab9f99dd2b73315a6ad50c)
@@ -629,10 +629,7 @@
 		/* If the person is offline, send an offline message instead,
 		   and don't report an error. */
-		/* TODO: Support for OIMs that works. (#874) */
-		/*
 		if( num == 217 )
-			msn_soap_oim_send_queue( ic, &sb->msgq );
+			msn_ns_oim_send_queue( ic, &sb->msgq );
 		else
-		*/
 			imcb_error( ic, "Error reported by switchboard server: %s", err->text );
 		
