Bug 61687

Summary: Crypto plugin mangles text by adding additional newline character
Product: [Unmaintained] kopete Reporter: Till Gerken <till.gerken>
Component: Cryptography PluginAssignee: Kopete Developers <kopete-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: luke-jr+kdebugs, mart
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Till Gerken 2003-07-26 11:26:32 UTC
Version:           0.6.90cvs >= 20030713 (using KDE 3.1.9)
Compiler:          gcc version 3.3.1 20030626 (Debian prerelease)
OS:          Linux (i686) release 2.4.20-pre11

The crypto plugin appends a newline to every text it sends, so on the other end messages appear as with an additional blank line appended. (this might be related to 58636 also)

Also, it escapes text: quotes (") end up as \".

Umlauts don't appear correctly as well.

This all happens with the Jabber plugin which can only send messages as plainText(), could it be that the crypto plugin attempts to encode as RichText?
Comment 1 Till Gerken 2003-07-26 11:27:06 UTC
Re-assign since wizard does not support component selection. 
Comment 2 Olivier Goffart 2003-07-28 17:24:46 UTC
The quote problem is fixed, but i don't think i will be able to fix the newline problem. 
 
It seems gpg add it itself when encrypting.  
 
I would like to use the same way as kmail to encrypt/decrypt. maybe when i will do this, 
that will fix the problem 
 
Comment 3 wjl 2003-08-19 03:38:23 UTC
it's easy to fix the newline problem: 
 
BEFORE you encrypt the message, ALWAYS add a newline, whether the message 
originally had one or not. gpg will now not add a newline since the message 
already ends with one. 
 
AFTER you decrypt, just always remove the last newline. 
 
 
Comment 4 Olivier Goffart 2003-08-19 08:45:38 UTC
Subject: Re: [Kopete-devel]  Crypto plugin mangles text

Le Mardi 19 Ao
Comment 5 Jason Keirstead 2003-11-05 00:59:52 UTC
CVS commit by brunes: 

One more fix

This should fix bug #61687 according to wjl@icecavern.net 

Oliver: The only reason it was not noticeable Kopete -> Kopete was because
of the table that the plugin wraps the messages in.

CCMAIl:61687-done@bugs.kde.org


  M +2 -1      kgpginterface.cpp   1.23


--- kdenetwork/kopete/plugins/cryptography/kgpginterface.cpp  #1.22:1.23
@@ -61,5 +61,5 @@ QString KgpgInterface::KgpgEncryptText(Q
         
         QCString gpgcmd = "echo ";
-        gpgcmd += KShellProcess::quote(text).utf8();
+        gpgcmd += KShellProcess::quote( text + QString::fromLatin1("\n") ).utf8();
         gpgcmd += " | gpg --no-secmem-warning --no-tty ";
         gpgcmd += Options.local8Bit();
@@ -131,4 +131,5 @@ QString KgpgInterface::KgpgDecryptText(Q
                 pclose(fp);
                 password = QCString();
+                encResult = encResult.left( encResult.length() - 1 );
         }
         
Comment 6 Jason Keirstead 2003-11-05 02:59:43 UTC
Re-opening this I resolved it incorrectly
Comment 7 jstuart 2004-02-17 03:32:12 UTC
Jason, status on this bug?  Will this be fixed soon or should be it be closed?
Comment 8 Till Gerken 2004-07-23 13:14:06 UTC
This problem still exists in 3.3 beta 2. The text sent and received via Jabber is exactly the same as with other clients, so the newline is inside the encrypted text.
Comment 9 Richard Smith 2004-07-31 01:04:30 UTC
Am I right in thinking from the comments above that the only way to fix this would be to use a non-canonical (possibly hown-brewed) version of gpg? If so, this is a WONTFIX. It seems very unlikely to me that you can't turn off the newline-adding behaviour of gpg (think of binary files). Perhaps some investigation of command line options is in order?
Comment 10 Till Gerken 2004-07-31 09:24:42 UTC
No one must be able to fix it with a standard GPG binary. For some reason the crypto plugin adds a newline character into the crypted messages, either because the call to GPG is not perfect or because the message gets mangled before.
Comment 11 Mart Kelder 2004-08-08 16:38:52 UTC
If the bug is in the encryption, it could be caused by the command "echo" (kgpginterface.cpp:63). Maybe this should be "echo -n".

There are a few other sentences which mangels text. For example: "<b>foo</b>" becomes "foo" (boldface), which is false with the jabber protocol. Also, "<foo>" becomes "", which should be untouched either.

I think it must be clear before a message is decrypted if the message contains RichText or not (the format() function in KopeteMessage?). Elsewise, the decrypted message should be send back to the protocol to determe if it is RichText or not. 
Comment 12 Till Gerken 2004-08-08 17:35:50 UTC
As for the RichText issues, please open a separate bug report. The Jabber plugin does not announce RichText capabilities and only reads/writes plaintext messages to the message managers, so the bug is most likely in libkopete.

As for the encryption, you might be right. I don't know if GPG expects the input to end with a newline though. We'll have to check.
Comment 13 Mart Kelder 2004-08-10 09:48:22 UTC
I tried that change, and one contact claims the newline disappeared.
Comment 14 Matt Rogers 2004-12-02 01:55:29 UTC
*** Bug 94251 has been marked as a duplicate of this bug. ***
Comment 15 Olivier Goffart 2005-02-02 13:32:49 UTC
CVS commit by ogoffart: 

Fix Bug 61687: Crypto plugin mangles text by adding additional newline character

the fix is so simple :-/   i could have thought to that before

BUG: 61687


  M +1 -1      kgpginterface.cpp   1.26


--- kdenetwork/kopete/plugins/cryptography/kgpginterface.cpp  #1.25:1.26
@@ -60,5 +60,5 @@ QString KgpgInterface::KgpgEncryptText(Q
         dests+=" --recipient "+userIDs;
         
-        QCString gpgcmd = "echo ";
+        QCString gpgcmd = "echo -n ";
         gpgcmd += KShellProcess::quote( text ).utf8();
         gpgcmd += " | gpg --no-secmem-warning --no-tty ";