diff options
author | Marin <m.dzhigarov@gmail.com> | 2014-01-06 09:39:27 +0200 |
---|---|---|
committer | Marin <m.dzhigarov@gmail.com> | 2014-01-06 10:29:06 +0200 |
commit | d51c519a6d099d073c7d8d4be308acf5e6be7211 (patch) | |
tree | 4f9ca94873b9d296c3c267d7dbb3dfbadd2f463c /src/net/java/sip | |
parent | 9dc6b6ef1d4d5d2b9c0c73cd4335844649b462ca (diff) | |
download | jitsi-d51c519a6d099d073c7d8d4be308acf5e6be7211.zip jitsi-d51c519a6d099d073c7d8d4be308acf5e6be7211.tar.gz jitsi-d51c519a6d099d073c7d8d4be308acf5e6be7211.tar.bz2 |
Fixes HTML being shown in OTR messages
Diffstat (limited to 'src/net/java/sip')
5 files changed, 44 insertions, 13 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java index 0eb6620..84cb59f 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -152,19 +152,21 @@ public class OperationSetBasicInstantMessagingJabberImpl } /** - * Create a Message instance with the specified UID and a default - * (text/plain) content type and encoding. + * Create a Message instance with the specified UID, content type + * and a default encoding. * This method can be useful when message correction is required. One can * construct the corrected message to have the same UID as the message * before correction. * * @param messageText the string content of the message. + * @param contentType the MIME-type for <tt>content</tt> * @param messageUID the unique identifier of this message. * @return Message the newly created message */ - public Message createMessageWithUID(String messageText, String messageUID) + public Message createMessageWithUID( + String messageText, String contentType, String messageUID) { - return new MessageJabberImpl(messageText, DEFAULT_MIME_TYPE, + return new MessageJabberImpl(messageText, contentType, DEFAULT_MIME_ENCODING, null, messageUID); } 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 =
+ "<a href=\"http://en.wikipedia.org/wiki/Off-the-Record_Messaging\">";
+ 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);
diff --git a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java index ec94e08..fe4f90f 100644 --- a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java @@ -108,17 +108,19 @@ public abstract class AbstractOperationSetBasicInstantMessaging } /** - * Create a Message instance with the specified UID and a default - * (text/plain) content type and encoding. + * Create a Message instance with the specified UID, content type + * and a default encoding. * This method can be useful when message correction is required. One can * construct the corrected message to have the same UID as the message * before correction. * * @param messageText the string content of the message. + * @param contentType the MIME-type for <tt>content</tt> * @param messageUID the unique identifier of this message. * @return Message the newly created message */ - public Message createMessageWithUID(String messageText, String messageUID) + public Message createMessageWithUID( + String messageText, String contentType, String messageUID) { return createMessage(messageText); } diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java index 7b34e34..e04cd15 100644 --- a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java @@ -54,17 +54,19 @@ public interface OperationSetBasicInstantMessaging public Message createMessage(String messageText); /** - * Create a Message instance with the specified UID and a default - * (text/plain) content type and encoding. + * Create a Message instance with the specified UID, content type + * and a default encoding. * This method can be useful when message correction is required. One can * construct the corrected message to have the same UID as the message * before correction. * * @param messageText the string content of the message. + * @param contentType the MIME-type for <tt>content</tt> * @param messageUID the unique identifier of this message. * @return Message the newly created message */ - public Message createMessageWithUID(String messageText, String messageUID); + public Message createMessageWithUID( + String messageText, String contentType, String messageUID); /** * Sends the <tt>message</tt> to the destination indicated by the |