Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/jabber/jabber.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -531,4 +531,5 @@
 	
 	ret->name = "jabber";
+    ret->mms = 0;                        /* no limit */
 	ret->login = jabber_login;
 	ret->init = jabber_init;
Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/msn/msn.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -307,4 +307,5 @@
 	
 	ret->name = "msn";
+    ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
 	ret->login = msn_login;
 	ret->init = msn_init;
Index: protocols/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/msn/ns.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -271,23 +271,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 );
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/nogaim.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -725,6 +725,8 @@
 	}
 	
-	/* early if-clause for show_offline even if there is some redundant code here because this isn't LISP but C ;) */
-	if( set_getbool( &ic->irc->set, "show_offline" ) && set_getbool( &ic->irc->set, "away_devoice" ) )
+	/* LISPy... */
+	if( ( u->online ) &&						/* Don't touch offline people */
+	    ( ( u->online != oo ) ||					/* Do joining people */
+	      ( ( u->online == oo ) && ( oa == !u->away ) ) ) )		/* Do people changing state */
 	{
 		char *from;
@@ -740,40 +742,28 @@
 		}
 
-		/* if we use show_offline, we op online users, voice away users, and devoice/deop offline users */
-		if( flags & OPT_LOGGED_IN )
-		{
-			/* user is "online" (either really online or away) */
-			irc_write( ic->irc, ":%s MODE %s %cv%co %s %s", from, ic->irc->channel,
-			                                          u->away?'+':'-', u->away?'-':'+', u->nick, u->nick );
-		}
-		else
-		{
-			/* user is offline */
-			irc_write( ic->irc, ":%s MODE %s -vo %s %s", from, ic->irc->channel, u->nick, u->nick );
-		}
-	}
-	else
-	{ 
-		/* LISPy... */
-		if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&		/* Don't do a thing when user doesn't want it */
-		    ( u->online ) &&						/* Don't touch offline people */
-		    ( ( ( u->online != oo ) && !u->away ) ||			/* Voice joining people */
-		      ( ( u->online == oo ) && ( oa == !u->away ) ) ) )		/* (De)voice people changing state */
-		{
-			char *from;
-
-			if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
-			{
-				from = g_strdup( ic->irc->myhost );
-			}
-			else
-			{
-				from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
-				                                    ic->irc->myhost );
-			}
+		if(!strcmp(set_getstr(&ic->irc->set, "voice_buddies"), "online")) {
+			irc_write( ic->irc, ":%s MODE %s +v %s", from, ic->irc->channel, u->nick );
+		}
+		if(!strcmp(set_getstr(&ic->irc->set, "halfop_buddies"), "online")) {
+			irc_write( ic->irc, ":%s MODE %s +h %s", from, ic->irc->channel, u->nick );
+		}
+		if(!strcmp(set_getstr(&ic->irc->set, "op_buddies"), "online")) {
+			irc_write( ic->irc, ":%s MODE %s +o %s", from, ic->irc->channel, u->nick );
+		}
+
+		if(!strcmp(set_getstr(&ic->irc->set, "voice_buddies"), "notaway")) {
 			irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
-			                                          u->away?'-':'+', u->nick );
-			g_free( from );
-		}
+		 	                                         u->away?'-':'+', u->nick );
+		}
+		if(!strcmp(set_getstr(&ic->irc->set, "halfop_buddies"), "notaway")) {
+			irc_write( ic->irc, ":%s MODE %s %ch %s", from, ic->irc->channel,
+		 	                                         u->away?'-':'+', u->nick );
+		}
+		if(!strcmp(set_getstr(&ic->irc->set, "op_buddies"), "notaway")) {
+			irc_write( ic->irc, ":%s MODE %s %co %s", from, ic->irc->channel,
+		 	                                         u->away?'-':'+', u->nick );
+		}
+
+		g_free( from );
 	}
 }
@@ -784,7 +774,13 @@
 	char *wrapped, *ts = NULL;
 	user_t *u;
-	
+
+	/* pass the message through OTR */
+	msg = otr_handle_message(ic, handle, msg);
+	if(!msg) {
+		/* this was an internal OTR protocol message */
+		return;
+	}
+
 	u = user_findhandle( ic, handle );
-	
 	if( !u )
 	{
@@ -796,4 +792,5 @@
 				imcb_log( ic, "Ignoring message from unknown handle %s", handle );
 			
+			g_free(msg);
 			return;
 		}
@@ -829,6 +826,6 @@
 	{
 		char *new = g_strconcat( ts, msg, NULL );
-		g_free( ts );
-		ts = msg = new;
+		g_free( msg );
+		msg = new;
 	}
 	
@@ -836,4 +833,5 @@
 	irc_msgfrom( irc, u->nick, wrapped );
 	g_free( wrapped );
+	g_free( msg );
 	g_free( ts );
 }
@@ -1112,59 +1110,4 @@
 /* Misc. BitlBee stuff which shouldn't really be here */
 
-char *set_eval_away_devoice( set_t *set, char *value )
-{
-	irc_t *irc = set->data;
-	int st;
-	
-	if( !is_bool( value ) )
-		return SET_INVALID;
-	
-	st = bool2int( value );
-	
-	/* Horror.... */
-	
-	if( st != set_getbool( &irc->set, "away_devoice" ) )
-	{
-		char list[80] = "";
-		user_t *u = irc->users;
-		int i = 0, count = 0;
-		char pm;
-		char v[80];
-		
-		if( st )
-			pm = '+';
-		else
-			pm = '-';
-		
-		while( u )
-		{
-			if( u->ic && u->online && !u->away )
-			{
-				if( ( strlen( list ) + strlen( u->nick ) ) >= 79 )
-				{
-					for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0;
-					irc_write( irc, ":%s MODE %s %c%s%s",
-					           irc->myhost,
-		        			   irc->channel, pm, v, list );
-					
-					*list = 0;
-					count = 0;
-				}
-				
-				sprintf( list + strlen( list ), " %s", u->nick );
-				count ++;
-			}
-			u = u->next;
-		}
-		
-		/* $v = 'v' x $i */
-		for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0;
-		irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost,
-		                                            irc->channel, pm, v, list );
-	}
-	
-	return value;
-}
-
 char *set_eval_timezone( set_t *set, char *value )
 {
@@ -1269,8 +1212,9 @@
 		msg = buf;
 	}
-	
-	st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
-	g_free( buf );
-	
+
+	/* if compiled without otr support, this just calls the prpl buddy_msg */
+	st = otr_send_message(ic, handle, msg, flags);
+	
+	g_free(buf);
 	return st;
 }
Index: protocols/nogaim.h
===================================================================
--- protocols/nogaim.h	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/nogaim.h	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -59,4 +59,5 @@
 #define OPT_TYPING      0x00000100 /* Some pieces of code make assumptions */
 #define OPT_THINKING    0x00000200 /* about these values... Stupid me! */
+#define OPT_NOOTR	0x00001000 /* protocol not suitable for OTR */
 
 /* ok. now the fun begins. first we create a connection structure */
@@ -132,4 +133,8 @@
 	 * - The user sees this name ie. when imcb_log() is used. */
 	const char *name;
+	/* Maximum Message Size of this protocol.
+	 * - Introduced for OTR, in order to fragment large protocol messages.
+	 * - 0 means "unlimited". */
+	unsigned int mms;
 
 	/* Added this one to be able to add per-account settings, don't think
@@ -326,5 +331,4 @@
 /* Misc. stuff */
 char *set_eval_timezone( set_t *set, char *value );
-char *set_eval_away_devoice( set_t *set, char *value );
 gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond );
 void cancel_auto_reconnect( struct account *a );
Index: protocols/oscar/oscar.c
===================================================================
--- protocols/oscar/oscar.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/oscar/oscar.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -2554,4 +2554,5 @@
 	struct prpl *ret = g_new0(struct prpl, 1);
 	ret->name = "oscar";
+    ret->mms = 2343;       /* this guess taken from libotr UPGRADING file */
 	ret->away_states = oscar_away_states;
 	ret->init = oscar_init;
Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/twitter/twitter.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -376,4 +376,5 @@
 	struct prpl *ret = g_new0(struct prpl, 1);
 	
+	ret->options = OPT_NOOTR;
 	ret->name = "twitter";
 	ret->login = twitter_login;
Index: protocols/yahoo/libyahoo2.c
===================================================================
--- protocols/yahoo/libyahoo2.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/yahoo/libyahoo2.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -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 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/yahoo/yahoo.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -355,4 +355,5 @@
 	struct prpl *ret = g_new0(struct prpl, 1);
 	ret->name = "yahoo";
+    ret->mms = 832;           /* this guess taken from libotr UPGRADING file */
 	ret->init = byahoo_init;
 	
Index: protocols/yahoo/yahoo_httplib.c
===================================================================
--- protocols/yahoo/yahoo_httplib.c	(revision 8203da9d2f792252d2144e5e9063391a3ceebfe9)
+++ protocols/yahoo/yahoo_httplib.c	(revision eb6df6a280c458546ebc57126e63a828674b4cd8)
@@ -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
