From d51c519a6d099d073c7d8d4be308acf5e6be7211 Mon Sep 17 00:00:00 2001 From: Marin Date: Mon, 6 Jan 2014 09:39:27 +0200 Subject: Fixes HTML being shown in OTR messages --- .../communicator/plugin/otr/OtrTransformLayer.java | 10 ++++++++-- .../communicator/plugin/otr/ScOtrEngineImpl.java | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/net/java/sip/communicator/plugin/otr') diff --git a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java index 44e0f0e..5ba5a53 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java @@ -94,7 +94,11 @@ public class OtrTransformLayer contact.getProtocolProvider().getOperationSet( OperationSetBasicInstantMessaging.class); Message processedMessage = - imOpSet.createMessage(processedMessageContent); + imOpSet.createMessage( + processedMessageContent, + evt.getSourceMessage().getContentType(), + evt.getSourceMessage().getEncoding(), + evt.getSourceMessage().getSubject()); // Create a new event and return. MessageDeliveredEvent processedEvent = @@ -140,7 +144,9 @@ public class OtrTransformLayer OperationSetBasicInstantMessaging.class); Message processedMessage = imOpSet.createMessageWithUID( - processedMessageContent, evt.getSourceMessage().getMessageUID()); + processedMessageContent, + evt.getSourceMessage().getContentType(), + evt.getSourceMessage().getMessageUID()); // Create a new event and return. MessageReceivedEvent processedEvent = diff --git a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java index 5e00234..b7fb849 100644 --- a/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java +++ b/src/net/java/sip/communicator/plugin/otr/ScOtrEngineImpl.java @@ -62,7 +62,26 @@ public class ScOtrEngineImpl .getProtocolProvider() .getOperationSet( OperationSetBasicInstantMessaging.class); - Message message = imOpSet.createMessage(messageText); + + // This is a dirty way of detecting whether the injected message + // contains HTML markup. If this is the case then we should create + // the message with the appropriate content type so that the remote + // party can properly display the HTML. + // When otr4j injects QueryMessages it calls + // OtrEngineHost.getFallbackMessage() which is currently the only + // host method that uses HTML so we can simply check if the injected + // message contains the string that getFallbackMessage() returns. + String otrHtmlFallbackMessage = + ""; + String contentType = + messageText.contains(otrHtmlFallbackMessage) + ? imOpSet.HTML_MIME_TYPE : imOpSet.DEFAULT_MIME_TYPE; + + Message message = + imOpSet.createMessage( messageText, + contentType, + imOpSet.DEFAULT_MIME_ENCODING, + null); injectedMessageUIDs.add(message.getMessageUID()); imOpSet.sendInstantMessage(contact, message); -- cgit v1.1