~ubuntu-branches/ubuntu/utopic/kopete/utopic-proposed

« back to all changes in this revision

Viewing changes to plugins/otr/otrplugin.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2013-11-23 17:46:40 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20131123174640-gz1zjv1xqh81bi2h
Tags: 4:4.11.80-0ubuntu1
* New upstream beta release
* Bump build dependency to libotr5-dev
* Update symbols
* Update install files
* Drop new_linphone.diff, not required anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************
2
 
 * Copyright <2007>  <Michael Zanetti> <michael_zanetti@gmx.net>         *
 
2
 * Copyright <2007 - 2013>  <Michael Zanetti> <mzanetti@kde.org>         *
3
3
 *                                                                       *
4
4
 * This program is free software; you can redistribute it and/or         *
5
5
 * modify it under the terms of the GNU General Public License as        *
153
153
void OTRPlugin::slotOutgoingMessage( Kopete::Message& msg )
154
154
{
155
155
        if( msg.direction() == Kopete::Message::Outbound ){
156
 
                QString accountId = msg.manager()->account()->accountId();
157
 
                Kopete::Contact *contact = msg.to().first();
158
 
 
159
 
                QString msgBody;
160
 
                QString cacheBody;
161
 
                bool plaintext = msg.format() == Qt::PlainText;
162
 
                kDebug(14318) << "Message format is" << (plaintext ? "plaintext" : "richtext");
163
 
                if(plaintext){
164
 
                        msgBody = msg.plainBody().replace('<', "&lt;");
165
 
                        cacheBody = msgBody;
166
 
                } else {
167
 
                        msgBody = msg.escapedBody();
168
 
                        cacheBody = msgBody;
169
 
                }
170
 
                kDebug(14318) << "Outgoing message before processing:" << msgBody << "escaped" << Kopete::Message::escape(msgBody);
171
 
 
172
 
                int encryptionState = otrlChatInterface->encryptMessage( &msgBody, accountId, msg.manager()->account()->protocol()->displayName(), contact->contactId(), msg.manager() );
 
156
 
 
157
        QString cacheBody;
 
158
        if(msg.format() == Qt::PlainText){
 
159
                cacheBody = msg.plainBody().replace('<', "&lt;");
 
160
        } else {
 
161
                cacheBody = msg.escapedBody();
 
162
        }
 
163
 
 
164
        otrlChatInterface->encryptMessage( msg );
173
165
        
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."));
178
 
 
179
 
                } else if(encryptionState == 0){
180
 
                        kDebug(14318) << "Encrypted successfully";
181
 
 
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 );
188
 
                        } else {
189
 
                                messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
190
 
                        }
191
 
                } else if(encryptionState == 1){
192
 
                        kDebug(14318) << "Tagged plaintext!";
193
 
            
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.
199
 
               
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).
204
 
                        */
205
 
                        if(plaintext){
206
 
                                msg.setPlainBody(msgBody);
207
 
                        } else {
208
 
                                msg.setHtmlBody(msgBody);
209
 
                        }
210
 
            
211
 
                        messageCache.insert( msgBody, cacheBody );
212
 
                } /* else {
213
 
                        Don't touch msg If encryptionState is something else than above!!!
214
 
                } */
215
 
 
216
 
 
217
 
                kDebug(14318) << "Outgoing message after processing:" << msgBody << msg.format();
 
166
        if( !msg.plainBody().isEmpty() ){
 
167
                messageCache.insert( msg.plainBody(), cacheBody );
 
168
        } else {
 
169
                messageCache.insert( "!OTR:MsgDelByOTR", cacheBody );
 
170
        }
 
171
 
 
172
        kDebug(14318) << "Outgoing message after processing:" << msg.plainBody() << msg.format();
218
173
        }
219
174
}
220
175
 
287
242
                return;
288
243
        }
289
244
 
 
245
 
290
246
        Kopete::Message msg = event->message();
291
247
//      Kopete::ChatSession *session = msg.manager();
292
248
        QMap<QString, QString> messageCache = plugin->getMessageCache();
293
249
 
294
 
        if( msg.direction() == Kopete::Message::Inbound ){
295
 
                if( msg.type() == Kopete::Message::TypeFileTransferRequest )
 
250
    kDebug(14318) << "OtrMessageHandler::handleMessage:" << msg.plainBody();
 
251
 
 
252
    if( msg.direction() == Kopete::Message::Inbound){
 
253
        if( msg.type() == Kopete::Message::TypeFileTransferRequest )
296
254
                {
297
255
                        // file transfers aren't encrypted. Proceed with next plugin
298
256
                        MessageHandler::handleMessage( event );
299
257
                        return;
300
258
                }
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();
309
263
                        return;