$OpenBSD: patch-plugins_otr_otrplugin_cpp,v 1.1.1.1 2013/12/08 18:39:44 zhuk Exp $
Support for libotr-4.0, from upstream.
--- plugins/otr/otrplugin.cpp.orig	Fri Jun 28 22:08:21 2013
+++ plugins/otr/otrplugin.cpp	Sat Oct  5 05:10:45 2013
@@ -1,5 +1,5 @@
 /*************************************************************************
- * Copyright <2007>  <Michael Zanetti> <michael_zanetti@gmx.net>         *
+ * Copyright <2007 - 2013>  <Michael Zanetti> <mzanetti@kde.org>         *
  *                                                                       *
  * This program is free software; you can redistribute it and/or         *
  * modify it under the terms of the GNU General Public License as        *
@@ -153,68 +153,23 @@ void OTRPlugin::slotNewChatSessionWindow( Kopete::Chat
 void OTRPlugin::slotOutgoingMessage( Kopete::Message& msg )
 {
 	if( msg.direction() == Kopete::Message::Outbound ){
-		QString accountId = msg.manager()->account()->accountId();
-		Kopete::Contact *contact = msg.to().first();
 
-		QString msgBody;
-		QString cacheBody;
-		bool plaintext = msg.format() == Qt::PlainText;
-		kDebug(14318) << "Message format is" << (plaintext ? "plaintext" : "richtext");
-		if(plaintext){
-			msgBody = msg.plainBody().replace('<', "&lt;");
-			cacheBody = msgBody;
-		} else {
-			msgBody = msg.escapedBody();
-			cacheBody = msgBody;
-		}
-		kDebug(14318) << "Outgoing message before processing:" << msgBody << "escaped" << Kopete::Message::escape(msgBody);
+	QString cacheBody;
+	if(msg.format() == Qt::PlainText){
+		cacheBody = msg.plainBody().replace('<', "&lt;");
+	} else {
+		cacheBody = msg.escapedBody();
+	}
 
-		int encryptionState = otrlChatInterface->encryptMessage( &msgBody, accountId, msg.manager()->account()->protocol()->displayName(), contact->contactId(), msg.manager() );
+	otrlChatInterface->encryptMessage( msg );
         
-		if(encryptionState == -1){
-			// Failure. Shouldn't happen. However, if it does DON'T
-			// send the message out in plaintext. overwrite with something else...
-			msg.setPlainBody(i18n("An error occurred while encrypting the message."));
+	if( !msg.plainBody().isEmpty() ){
+		messageCache.insert( msg.plainBody(), cacheBody );
+	} else {
+		messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
+	}
 
-		} else if(encryptionState == 0){
-			kDebug(14318) << "Encrypted successfully";
-
-			// Always set plaintext if the message has been encrypted.
-			// The parser wouldn't understand anything after encryption anyways...
-			msg.setPlainBody( msgBody );
-			msg.setType(Kopete::Message::TypeNormal);
-			if( !msg.plainBody().isEmpty() ){
-				messageCache.insert( msgBody, cacheBody );
-			} else {
-				messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
-			}
-		} else if(encryptionState == 1){
-			kDebug(14318) << "Tagged plaintext!";
-            
-			/* Here we have a problem... libotr tags messages with whitespaces to
-			   be recognized by other clients. Those whitespaces are discarded
-			   if we use setHtmlBody() and breaks opportunistic mode.
-			   If we use setPlainBody() for messages containing tags, those tags
-			   are escaped and will be visible in the other sides chatwindow.
-               
-			   This approach should always send out correct messages but will
-			   break opportunistic mode if the user enables RTF formatting.
-			   Sorry folks. No way to deal with this currently (Would need changes
-			   in the rich text handling in libkopete).
-			*/
-			if(plaintext){
-				msg.setPlainBody(msgBody);
-			} else {
-				msg.setHtmlBody(msgBody);
-			}
-            
-			messageCache.insert( msgBody, cacheBody );
-		} /* else {
-			Don't touch msg If encryptionState is something else than above!!!
-		} */
-
-
-		kDebug(14318) << "Outgoing message after processing:" << msgBody << msg.format();
+	kDebug(14318) << "Outgoing message after processing:" << msg.plainBody() << msg.format();
 	}
 }
 
@@ -287,23 +242,22 @@ void OtrMessageHandler::handleMessage( Kopete::Message
 		return;
 	}
 
+
 	Kopete::Message msg = event->message();
 //	Kopete::ChatSession *session = msg.manager();
 	QMap<QString, QString> messageCache = plugin->getMessageCache();
 
-	if( msg.direction() == Kopete::Message::Inbound ){
-		if( msg.type() == Kopete::Message::TypeFileTransferRequest )
+    kDebug(14318) << "OtrMessageHandler::handleMessage:" << msg.plainBody();
+
+    if( msg.direction() == Kopete::Message::Inbound){
+        if( msg.type() == Kopete::Message::TypeFileTransferRequest )
 		{
 			// file transfers aren't encrypted. Proceed with next plugin
 			MessageHandler::handleMessage( event );
 			return;
 		}
-		QString body = msg.plainBody();
-		QString accountId = msg.manager()->account()->accountId();
-		QString contactId = msg.from()->contactId();
-		int retValue = OtrlChatInterface::self()->decryptMessage( &body, accountId, msg.manager()->account()->protocol()->displayName(), contactId, msg.manager() );
-		msg.setHtmlBody( body );
-		if( (retValue == 2) | OtrlChatInterface::self()->shouldDiscard( msg.plainBody() ) ){
+        int retValue = OtrlChatInterface::self()->decryptMessage( msg );
+        if( (retValue == 2) | OtrlChatInterface::self()->shouldDiscard( msg.plainBody() ) ){
 			// internal OTR message
 			event->discard();
 			return;
