Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision c775a58faa7d5905b06e2f8900db7337082d5165)
+++ protocols/msn/msn.c	(revision 76c89dc7e58c9d4806e83c04ab4005faa84e2703)
@@ -108,4 +108,6 @@
 		}
 		
+		g_free( md->profile_rid );
+		
 		g_tree_destroy( md->domaintree );
 		md->domaintree = NULL;
@@ -322,19 +324,13 @@
 	struct msn_data *md = ic->proto_data;
 	
-	if( strlen( value ) > 129 )
-	{
-		imcb_log( ic, "Maximum name length exceeded" );
-		return NULL;
-	}
-	
-	if( md->flags & MSN_GOT_PROFILE_DN )
-		imcb_log( ic, "Warning: Persistent name changes for this account have to be done "
-		              "in the profile. BitlBee doesn't currently support this." );
-	
 	if( md->flags & MSN_EMAIL_UNVERIFIED )
 		imcb_log( ic, "Warning: Your e-mail address is unverified. MSN doesn't allow "
 		              "changing your display name until your e-mail address is verified." );
 	
-	msn_soap_addressbook_set_display_name( ic, value );
+	if( md->flags & MSN_GOT_PROFILE_DN )
+		msn_soap_profile_set_dn( ic, value );
+	else
+		msn_soap_addressbook_set_display_name( ic, value );
+	
 	return msn_ns_set_display_name( ic, value ) ? value : NULL;
 }
@@ -363,5 +359,5 @@
 	
 	ret->name = "msn";
-    ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
+	ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
 	ret->login = msn_login;
 	ret->init = msn_init;
Index: protocols/msn/msn.h
===================================================================
--- protocols/msn/msn.h	(revision c775a58faa7d5905b06e2f8900db7337082d5165)
+++ protocols/msn/msn.h	(revision 76c89dc7e58c9d4806e83c04ab4005faa84e2703)
@@ -119,4 +119,5 @@
 	const struct msn_away_state *away_state;
 	GSList *groups;
+	char *profile_rid;
 	
 	/* Mostly used for sending the ADL command; since MSNP13 the client
Index: protocols/msn/soap.c
===================================================================
--- protocols/msn/soap.c	(revision c775a58faa7d5905b06e2f8900db7337082d5165)
+++ protocols/msn/soap.c	(revision 76c89dc7e58c9d4806e83c04ab4005faa84e2703)
@@ -398,5 +398,8 @@
 	
 	if( md->soapq )
+	{
+		md->flags &= ~MSN_REAUTHING; 
 		return msn_soapq_flush( ic, TRUE );
+	}
 	
 	if( sd->secret == NULL )
@@ -1072,6 +1075,18 @@
 }
 
+static xt_status msn_soap_profile_get_rid( struct xt_node *node, gpointer data )
+{
+	struct msn_soap_req_data *soap_req = data;
+	struct msn_data *md = soap_req->ic->proto_data;
+	
+	g_free( md->profile_rid );
+	md->profile_rid = g_strdup( node->text );
+	
+	return XT_HANDLED;
+}
+
 static const struct xt_handler_entry msn_soap_profile_get_parser[] = {
 	{ "ExpressionProfile", "GetProfileResult", msn_soap_profile_get_result },
+	{ "ResourceID",        "GetProfileResult", msn_soap_profile_get_rid },
 	{ NULL,               NULL,     NULL                        }
 };
@@ -1101,2 +1116,39 @@
 	                       msn_soap_profile_get_free_data );
 }
+
+/* Update profile (display name). */
+static int msn_soap_profile_set_dn_build_request( struct msn_soap_req_data *soap_req )
+{
+	struct msn_data *md = soap_req->ic->proto_data;
+	
+	soap_req->url = g_strdup( SOAP_STORAGE_URL );
+	soap_req->action = g_strdup( SOAP_PROFILE_SET_DN_ACTION );
+	soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_SET_DN_PAYLOAD,
+		md->tokens[3], md->profile_rid, (char*) soap_req->data );
+	
+	return 1;
+}
+
+static const struct xt_handler_entry msn_soap_profile_set_dn_parser[] = {
+	{ NULL,               NULL,     NULL                        }
+};
+
+static int msn_soap_profile_set_dn_handle_response( struct msn_soap_req_data *soap_req )
+{
+	return MSN_SOAP_OK;
+}
+
+static int msn_soap_profile_set_dn_free_data( struct msn_soap_req_data *soap_req )
+{
+	g_free( soap_req->data );
+	return 0;
+}
+
+int msn_soap_profile_set_dn( struct im_connection *ic, const char *dn )
+{
+	return msn_soap_start( ic, g_strdup( dn ),
+	                       msn_soap_profile_set_dn_build_request,
+	                       msn_soap_profile_set_dn_parser,
+	                       msn_soap_profile_set_dn_handle_response,
+	                       msn_soap_profile_set_dn_free_data );
+}
Index: protocols/msn/soap.h
===================================================================
--- protocols/msn/soap.h	(revision c775a58faa7d5905b06e2f8900db7337082d5165)
+++ protocols/msn/soap.h	(revision 76c89dc7e58c9d4806e83c04ab4005faa84e2703)
@@ -303,4 +303,5 @@
 #define SOAP_STORAGE_URL "https://storage.msn.com/storageservice/SchematizedStore.asmx"
 #define SOAP_PROFILE_GET_ACTION "http://www.msn.com/webservices/storage/w10/GetProfile"
+#define SOAP_PROFILE_SET_DN_ACTION "http://www.msn.com/webservices/storage/w10/UpdateProfile"
 
 #define SOAP_PROFILE_GET_PAYLOAD \
@@ -345,6 +346,33 @@
 "</soap:Envelope>"
 
+#define SOAP_PROFILE_SET_DN_PAYLOAD \
+"<?xml version=\"1.0\" encoding=\"utf-8\"?>" \
+"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
+  "<soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
+    "<StorageApplicationHeader xmlns=\"http://www.msn.com/webservices/storage/w10\">" \
+      "<ApplicationID>Messenger Client 9.0</ApplicationID>" \
+      "<Scenario>Initial</Scenario>" \
+    "</StorageApplicationHeader>" \
+    "<StorageUserHeader xmlns=\"http://www.msn.com/webservices/storage/w10\">" \
+      "<Puid>0</Puid>" \
+      "<TicketToken>%s</TicketToken>" \
+    "</StorageUserHeader>" \
+  "</soap:Header>" \
+  "<soap:Body xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \
+    "<UpdateProfile xmlns=\"http://www.msn.com/webservices/storage/w10\">" \
+      "<profile>" \
+        "<ResourceID>%s</ResourceID>" \
+        "<ExpressionProfile>" \
+          "<FreeText>Update</FreeText>" \
+          "<DisplayName>%s</DisplayName>" \
+          "<Flags>0</Flags>" \
+        "</ExpressionProfile>" \
+      "</profile>" \
+    "</UpdateProfile>" \
+  "</soap:Body>" \
+"</soap:Envelope>"
+
 int msn_soap_profile_get( struct im_connection *ic, const char *cid );
-
+int msn_soap_profile_set_dn( struct im_connection *ic, const char *dn );
 
 #endif /* __SOAP_H__ */
