If OTR is disabled and we are over a plaintext session, dont process any message delivery events.

cusax-fix
George Politis 16 years ago
parent b9e59faee1
commit 19aa0a3b24

@ -5,6 +5,8 @@
*/
package net.java.sip.communicator.plugin.otr;
import net.java.otr4j.*;
import net.java.otr4j.session.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -21,6 +23,17 @@ public class OtrTransformLayer
*/
public MessageDeliveredEvent messageDelivered(MessageDeliveredEvent evt)
{
Contact contact = evt.getDestinationContact();
OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact);
SessionStatus sessionStatus =
OtrActivator.scOtrEngine.getSessionStatus(contact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
&& sessionStatus == SessionStatus.PLAINTEXT)
return evt;
if (OtrActivator.scOtrEngine.isMessageUIDInjected(evt
.getSourceMessage().getMessageUID()))
// If this is a message otr4j injected earlier, don't display it,
@ -46,13 +59,23 @@ public MessageDeliveryFailedEvent messageDeliveryFailed(
public MessageDeliveredEvent messageDeliveryPending(
MessageDeliveredEvent evt)
{
Contact contact = evt.getDestinationContact();
OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact);
SessionStatus sessionStatus =
OtrActivator.scOtrEngine.getSessionStatus(contact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
&& sessionStatus == SessionStatus.PLAINTEXT)
return evt;
// If this is a message otr4j injected earlier, return the event as is.
if (OtrActivator.scOtrEngine.isMessageUIDInjected(evt
.getSourceMessage().getMessageUID()))
return evt;
// Process the outgoing message.
Contact contact = evt.getDestinationContact();
String msgContent = evt.getSourceMessage().getContent();
String processedMessageContent =
OtrActivator.scOtrEngine.transformSending(contact, msgContent);
@ -65,10 +88,9 @@ public MessageDeliveredEvent messageDeliveryPending(
return evt;
// Forge a new message based on the new contents.
OperationSetBasicInstantMessaging imOpSet
= contact
.getProtocolProvider()
.getOperationSet(OperationSetBasicInstantMessaging.class);
OperationSetBasicInstantMessaging imOpSet =
contact.getProtocolProvider().getOperationSet(
OperationSetBasicInstantMessaging.class);
Message processedMessage =
imOpSet.createMessage(processedMessageContent);
@ -85,8 +107,18 @@ public MessageDeliveredEvent messageDeliveryPending(
*/
public MessageReceivedEvent messageReceived(MessageReceivedEvent evt)
{
// Process the incoming message.
Contact contact = evt.getSourceContact();
OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(contact);
SessionStatus sessionStatus =
OtrActivator.scOtrEngine.getSessionStatus(contact);
// If OTR is disabled and we are not over an encrypted session, don't
// process anything.
if (!policy.getEnableManual()
&& sessionStatus == SessionStatus.PLAINTEXT)
return evt;
// Process the incoming message.
String msgContent = evt.getSourceMessage().getContent();
String processedMessageContent =
@ -100,10 +132,9 @@ public MessageReceivedEvent messageReceived(MessageReceivedEvent evt)
return evt;
// Forge a new message based on the new contents.
OperationSetBasicInstantMessaging imOpSet
= contact
.getProtocolProvider()
.getOperationSet(OperationSetBasicInstantMessaging.class);
OperationSetBasicInstantMessaging imOpSet =
contact.getProtocolProvider().getOperationSet(
OperationSetBasicInstantMessaging.class);
Message processedMessage =
imOpSet.createMessage(processedMessageContent);

Loading…
Cancel
Save