[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete/plugins/otr
From:       Michael Zanetti <michael_zanetti () gmx ! net>
Date:       2010-05-24 16:37:58
Message-ID: 20100524163758.784E6AC8BE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1130163 by mzanetti:

fix handling of xml tags in tagged plaintext messages.
This, however breaks opportunistic mode when rich text 
formatting is enabled. Currently there seems to be no 
way to support both at the same time. The current
solutions seems to be most useful one.

BUG: 233330


 M  +1 -1      otrlchatinterface.cpp  
 M  +45 -6     otrplugin.cpp  


--- trunk/KDE/kdenetwork/kopete/plugins/otr/otrlchatinterface.cpp #1130162:1130163
@@ -559,7 +559,7 @@
 			err = otrl_message_fragment_and_send(&ui_ops, chatSession, context, newMessage,
 			OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &fragment);
 
-			kDebug(14318) << "fragment left to be sent by kopete: " << fragment;
+//			kDebug(14318) << "fragment left to be sent by kopete: " << fragment;
 
 			if( err != 0){
 				*msg = i18n("Encryption error");
--- trunk/KDE/kdenetwork/kopete/plugins/otr/otrplugin.cpp #1130162:1130163
@@ -153,17 +153,34 @@
 void OTRPlugin::slotOutgoingMessage( Kopete::Message& msg )
 {
 	if( msg.direction() == Kopete::Message::Outbound ){
-//        kDebug(14318) << "Outgoing message: Plain: " << msg.plainBody() << \
                "escapedBody:" << msg.escapedBody() << "parsedBody:" << \
                msg.parsedBody();
-		QString msgBody = msg.escapedBody();
-		QString cacheBody = msg.escapedBody();
 		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();
+            cacheBody = msgBody;
+        } else {
+            msgBody = msg.escapedBody();
+            cacheBody = msgBody;
+        }
+        kDebug(14318) << "Outgoing message before processing:" << msgBody;
+
 		int encryptionState = otrlChatInterface->encryptMessage( &msgBody, accountId, \
msg.manager()->account()->protocol()->displayName(), contact->contactId(), \
msg.manager() ); +        
 		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."));
+            
 		} else if(encryptionState == 0){
-//            kDebug(14318) << "Encrypted successfully";
+            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() ){
@@ -172,12 +189,34 @@
 				messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
 			}
 		} else if(encryptionState == 1){
-//            kDebug(14318) << "Tagged plaintext!";
+            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();  }
 	}
-}
 
 void  OTRPlugin::slotEnableOtr( Kopete::ChatSession *session, bool enable ){
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic