[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/kdepim/enterprise4/kdepimlibs
From: Thomas McGuire <mcguire () kde ! org>
Date: 2009-12-26 23:19:15
Message-ID: 1261869555.183807.14664.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1066388 by tmcguire:
Backport the bidi spoofing from trunk to the enterprise4 branch:
r1066360, r1066375 and r1066378
M +5 -3 kmime/kmime_header_parsing.cpp
M +15 -0 kmime/kmime_util.cpp
M +8 -0 kmime/kmime_util.h
M +29 -0 kmime/tests/kmime_message_test.cpp
M +1 -0 kmime/tests/kmime_message_test.h
M +7 -6 kpimutils/email.cpp
--- branches/kdepim/enterprise4/kdepimlibs/kmime/kmime_header_parsing.cpp #1066387:1066388
@@ -134,14 +134,14 @@
void Mailbox::setName( const QString &name )
{
- mDisplayName = name;
+ mDisplayName = removeBidiControlChars( name );
}
void Mailbox::setNameFrom7Bit( const QByteArray &name,
const QByteArray &defaultCharset )
{
QByteArray cs;
- mDisplayName = decodeRFC2047String( name, cs, defaultCharset, false );
+ setName( decodeRFC2047String( name, cs, defaultCharset, false ) );
}
bool Mailbox::hasAddress() const
@@ -1189,7 +1189,9 @@
return false;
}
- result.displayName = maybeDisplayName;
+ // KDE5 TODO: Don't expose displayName as public, but rather add setter for it that
+ // automatically calls removeBidiControlChars
+ result.displayName = removeBidiControlChars( maybeDisplayName );
// get obs-mbox-list (may contain empty entries):
scursor++;
--- branches/kdepim/enterprise4/kdepimlibs/kmime/kmime_util.cpp #1066387:1066388
@@ -31,6 +31,7 @@
#include <klocale.h>
#include <kcharsets.h>
#include <kcodecs.h>
+#include <kdebug.h>
#include <QtCore/QList>
#include <QtCore/QString>
@@ -487,4 +488,18 @@
}
}
+QString removeBidiControlChars( const QString &input )
+{
+ const int LRO = 0x202D;
+ const int RLO = 0x202E;
+ const int LRE = 0x202A;
+ const int RLE = 0x202B;
+ QString result = input;
+ result.remove( LRO );
+ result.remove( RLO );
+ result.remove( LRE );
+ result.remove( RLE );
+ return result;
+}
+
} // namespace KMime
--- branches/kdepim/enterprise4/kdepimlibs/kmime/kmime_util.h #1066387:1066388
@@ -229,6 +229,14 @@
*/
KMIME_EXPORT extern void addQuotes( QByteArray &str, bool forceQuotes );
+/**
+ * Similar to the above function. Instead of trying to balance the Bidi chars, it outright
+ * removes them from the string.
+ *
+ * Reason: KHTML seems to ignore the PDF character, so adding them doesn't fix things :(
+ */
+KMIME_EXPORT QString removeBidiControlChars( const QString &input );
+
} // namespace KMime
#endif /* __KMIME_UTIL_H__ */
--- branches/kdepim/enterprise4/kdepimlibs/kmime/tests/kmime_message_test.cpp #1066387:1066388
@@ -172,3 +172,32 @@
QCOMPARE( body, QString::fromAscii( msg2.body() ) );
}
+void MessageTest::testBidiSpoofing()
+{
+ const QString RLO( QChar( 0x202E ) );
+ const QString PDF( QChar( 0x202C ) );
+
+ const QByteArray senderAndRLO =
+ encodeRFC2047String( "\"Sender" + RLO + "\" <sender@test.org>", "utf-8" );
+
+ // The display name of the "From" has an RLO, make sure the KMime parser balances it
+ QByteArray data =
+ "From: " + senderAndRLO + "\n"
+ "\n"
+ "Body";
+
+ KMime::Message msg;
+ msg.setContent( data );
+ msg.parse();
+
+ // Test adjusted for taking into account that KMIME now removes bidi control chars
+ // instead of adding PDF chars, because of broken KHTML.
+ //const QString expectedDisplayName = "\"Sender" + RLO + PDF + "\"";
+ const QString expectedDisplayName = "\"Sender\"";
+ const QString expectedMailbox = expectedDisplayName + " <sender@test.org>";
+ QCOMPARE( msg.from()->addresses().count(), 1 );
+ QCOMPARE( msg.from()->asUnicodeString(), expectedMailbox );
+ QCOMPARE( msg.from()->displayNames().first(), expectedDisplayName );
+ QCOMPARE( msg.from()->mailboxes().first().name(), expectedDisplayName );
+ QCOMPARE( msg.from()->mailboxes().first().address().data(), "sender@test.org" );
+}
--- branches/kdepim/enterprise4/kdepimlibs/kmime/tests/kmime_message_test.h #1066387:1066388
@@ -30,6 +30,7 @@
void testBrunosMultiAssembleBug();
void testWillsAndTillsCrash();
void missingHeadersTest();
+ void testBidiSpoofing();
};
--- branches/kdepim/enterprise4/kdepimlibs/kpimutils/email.cpp #1066387:1066388
@@ -896,19 +896,20 @@
const QString &addrSpec,
const QString &comment )
{
- if ( displayName.isEmpty() && comment.isEmpty() ) {
+ const QString realDisplayName = KMime::removeBidiControlChars( displayName );
+ if ( realDisplayName.isEmpty() && comment.isEmpty() ) {
return addrSpec;
} else if ( comment.isEmpty() ) {
- if ( !displayName.startsWith('\"') ) {
- return quoteNameIfNecessary( displayName ) + " <" + addrSpec + '>';
+ if ( !realDisplayName.startsWith('\"') ) {
+ return quoteNameIfNecessary( realDisplayName ) + " <" + addrSpec + '>';
} else {
- return displayName + " <" + addrSpec + '>';
+ return realDisplayName + " <" + addrSpec + '>';
}
- } else if ( displayName.isEmpty() ) {
+ } else if ( realDisplayName.isEmpty() ) {
QString commentStr = comment;
return quoteNameIfNecessary( commentStr ) + " <" + addrSpec + '>';
} else {
- return displayName + " (" + comment + ") <" + addrSpec + '>';
+ return realDisplayName + " (" + comment + ") <" + addrSpec + '>';
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic