153
153
void OTRPlugin::slotOutgoingMessage( Kopete::Message& msg )
155
155
if( msg.direction() == Kopete::Message::Outbound ){
156
QString accountId = msg.manager()->account()->accountId();
157
Kopete::Contact *contact = msg.to().first();
161
bool plaintext = msg.format() == Qt::PlainText;
162
kDebug(14318) << "Message format is" << (plaintext ? "plaintext" : "richtext");
164
msgBody = msg.plainBody().replace('<', "<");
167
msgBody = msg.escapedBody();
170
kDebug(14318) << "Outgoing message before processing:" << msgBody << "escaped" << Kopete::Message::escape(msgBody);
172
int encryptionState = otrlChatInterface->encryptMessage( &msgBody, accountId, msg.manager()->account()->protocol()->displayName(), contact->contactId(), msg.manager() );
158
if(msg.format() == Qt::PlainText){
159
cacheBody = msg.plainBody().replace('<', "<");
161
cacheBody = msg.escapedBody();
164
otrlChatInterface->encryptMessage( msg );
174
if(encryptionState == -1){
175
// Failure. Shouldn't happen. However, if it does DON'T
176
// send the message out in plaintext. overwrite with something else...
177
msg.setPlainBody(i18n("An error occurred while encrypting the message."));
179
} else if(encryptionState == 0){
180
kDebug(14318) << "Encrypted successfully";
182
// Always set plaintext if the message has been encrypted.
183
// The parser wouldn't understand anything after encryption anyways...
184
msg.setPlainBody( msgBody );
185
msg.setType(Kopete::Message::TypeNormal);
186
if( !msg.plainBody().isEmpty() ){
187
messageCache.insert( msgBody, cacheBody );
189
messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
191
} else if(encryptionState == 1){
192
kDebug(14318) << "Tagged plaintext!";
194
/* Here we have a problem... libotr tags messages with whitespaces to
195
be recognized by other clients. Those whitespaces are discarded
196
if we use setHtmlBody() and breaks opportunistic mode.
197
If we use setPlainBody() for messages containing tags, those tags
198
are escaped and will be visible in the other sides chatwindow.
200
This approach should always send out correct messages but will
201
break opportunistic mode if the user enables RTF formatting.
202
Sorry folks. No way to deal with this currently (Would need changes
203
in the rich text handling in libkopete).
206
msg.setPlainBody(msgBody);
208
msg.setHtmlBody(msgBody);
211
messageCache.insert( msgBody, cacheBody );
213
Don't touch msg If encryptionState is something else than above!!!
217
kDebug(14318) << "Outgoing message after processing:" << msgBody << msg.format();
166
if( !msg.plainBody().isEmpty() ){
167
messageCache.insert( msg.plainBody(), cacheBody );
169
messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
172
kDebug(14318) << "Outgoing message after processing:" << msg.plainBody() << msg.format();
290
246
Kopete::Message msg = event->message();
291
247
// Kopete::ChatSession *session = msg.manager();
292
248
QMap<QString, QString> messageCache = plugin->getMessageCache();
294
if( msg.direction() == Kopete::Message::Inbound ){
295
if( msg.type() == Kopete::Message::TypeFileTransferRequest )
250
kDebug(14318) << "OtrMessageHandler::handleMessage:" << msg.plainBody();
252
if( msg.direction() == Kopete::Message::Inbound){
253
if( msg.type() == Kopete::Message::TypeFileTransferRequest )
297
255
// file transfers aren't encrypted. Proceed with next plugin
298
256
MessageHandler::handleMessage( event );
301
QString body = msg.plainBody();
302
QString accountId = msg.manager()->account()->accountId();
303
QString contactId = msg.from()->contactId();
304
int retValue = OtrlChatInterface::self()->decryptMessage( &body, accountId, msg.manager()->account()->protocol()->displayName(), contactId, msg.manager() );
305
msg.setHtmlBody( body );
306
if( (retValue == 2) | OtrlChatInterface::self()->shouldDiscard( msg.plainBody() ) ){
259
int retValue = OtrlChatInterface::self()->decryptMessage( msg );
260
if( (retValue == 2) | OtrlChatInterface::self()->shouldDiscard( msg.plainBody() ) ){
307
261
// internal OTR message
308
262
event->discard();