[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [trojita] src: Add support for Mailman's non-standard signature delimiter
From:       Jan_Kundrát <jkt () flaska ! net>
Date:       2013-01-31 21:17:43
Message-ID: 20130131211743.3227CA60C8 () git ! kde ! org
[Download RAW message or body]

Git commit 1580ccf27893b439bae6b3c32ae31beb49ad76f4 by Jan Kundrát.
Committed on 31/01/2013 at 22:15.
Pushed by jkt into branch 'master'.

Add support for Mailman's non-standard signature delimiter

There's a perfectly valid standard for how a signature separator shall look
like, but nope, Mailman just *has* to use something very special.

Let's just follow notmuch's example here and match even this garbage. On the
other hand, let's play it a bit safer and put a minimal length limit so that we
don't match "innocent" stuff like "__" etc.

M  +10   -2    src/Composer/PlainTextFormatter.cpp
M  +2    -0    src/Composer/PlainTextFormatter.h
M  +1    -1    src/Gui/MessageView.cpp

http://commits.kde.org/trojita/1580ccf27893b439bae6b3c32ae31beb49ad76f4

diff --git a/src/Composer/PlainTextFormatter.cpp \
b/src/Composer/PlainTextFormatter.cpp index bfeb5f8..b588037 100644
--- a/src/Composer/PlainTextFormatter.cpp
+++ b/src/Composer/PlainTextFormatter.cpp
@@ -175,6 +175,14 @@ void closeQuotesUpTo(QStringList &markup, QStack<QPair<int, int> \
> &controlStack  }
 }
 
+/** @short Returna a regular expression which matches the signature separators */
+QRegExp signatureSeparator()
+{
+    // "-- " is the standards-compliant signature separator.
+    // "Line of underscores" is non-standard garbage which Mailman happily \
generates. Yes, it's nasty and ugly. +    return QRegExp(QLatin1String("-- \
|_{45,}")); +}
+
 QStringList plainTextToHtml(const QString &plaintext, const FlowedFormat flowed)
 {
     static QRegExp quotemarks("^>[>\\s]*");
@@ -194,7 +202,7 @@ QStringList plainTextToHtml(const QString &plaintext, const \
FlowedFormat flowed)  }
 
         // Special marker for the signature separator
-        if (line == QLatin1String("-- ")) {
+        if (signatureSeparator().exactMatch(line)) {
             lineBuffer << qMakePair(SIGNATURE_SEPARATOR, line);
             signatureSeparatorSeen = true;
             continue;
@@ -261,7 +269,7 @@ QStringList plainTextToHtml(const QString &plaintext, const \
FlowedFormat flowed)  // The first signature separator
             signatureSeparatorSeen = true;
             closeQuotesUpTo(markup, controlStack, quoteLevel, 0);
-            markup << QLatin1String("<span class=\"signature\">-- ");
+            markup << QLatin1String("<span class=\"signature\">") + \
helperHtmlifySingleLine(it->second);  continue;
         }
 
diff --git a/src/Composer/PlainTextFormatter.h b/src/Composer/PlainTextFormatter.h
index 2a7980b..db09299 100644
--- a/src/Composer/PlainTextFormatter.h
+++ b/src/Composer/PlainTextFormatter.h
@@ -36,6 +36,8 @@ typedef enum {
 
 QStringList plainTextToHtml(const QString &plaintext, const FlowedFormat flowed);
 
+QRegExp signatureSeparator();
+
 }
 }
 
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 2a60921..5aee4bd 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -359,7 +359,7 @@ QString MessageView::quoteText() const
         QStringList quote;
         QStringList lines = w->quoteMe().split('\n');
         for (QStringList::iterator line = lines.begin(); line != lines.end(); \
                ++line) {
-            if (*line == QLatin1String("-- ")) {
+            if (Composer::Util::signatureSeparator().exactMatch(*line)) {
                 // This is the signature separator, we should not include anything \
below that in the quote  break;
             }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic