[Kde-pim] Review Request: Remove all the signature blocks.
Jaime Torres
jtamate at gmail.com
Fri Mar 27 17:15:18 GMT 2009
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.kde.org/r/403/
-----------------------------------------------------------
(Updated 2009-03-27 10:15:18.605706)
Review request for KDE PIM.
Changes
-------
Another posibility. This time only allowing > and spaces before --\s$, as RFC 3676 says.
i--, -----, and other things are not Signature Blocks delimiters.
Summary
-------
Remove all the signature blocks.
The algorithm is:
Look for the prefixes before the "-- " marks (i.e. the text before it in the line).
foreach line, if the line contains "-- ", start to delete lines until the prefix changes.
(it should also work with c code if the -- is not followed by a space).
This addresses bug 72316.
https://bugs.kde.org/show_bug.cgi?id=72316
Diffs (updated)
-----
/trunk/KDE/kdepim/kmail/kmmessage.cpp 945537
Diff: http://reviewboard.kde.org/r/403/diff
Testing (updated)
-------
#include <QtCore/QtCore>
#include <iostream>
#include <cassert>
using namespace std;
/*
remove the Signature Blocks (SB) from prefix+"-- (end of line)" until a
line that
* does not starts with prefix or
* starts with prefix+(any substring of prefix)
@param msg. The message to remove the SB.
@param clearSigned. Before a message is signed all trailing whitespace is
removed. Therefore the signature separator loses the trailing space.
*/
static QString stripSignature ( const QString & msg, bool clearSigned ) {
// Following RFC 3676, only > before --
// I prefer to not delete a SB instead of delete good mail content.
QRegExp SBDelimiterSearch = clearSigned ?
QRegExp( "(^|\n)[> ]*--\\s?\n" ) : QRegExp( "(^|\n)[> ]*-- \n" );
// The regular expresion to look for prefix change
QRegExp CommonReplySearch = QRegExp( "[>]" );
QString res = msg;
QString prefix; // the current prefix
QString line; // the line to check if is part of the SB
int posDeletingStart = -1;
int posNewLine = -1;
int posSignatureBlock = -1;
// While there are SB delimiters
while ( (posDeletingStart = res.indexOf( SBDelimiterSearch )) >= 0 )
{
// Look back for the line begining
posSignatureBlock = res.indexOf( '-', posDeletingStart );
// The prefix before "-- "$
if (res[posDeletingStart]=='\n') ++posDeletingStart;
prefix = res.mid( posDeletingStart, posSignatureBlock - posDeletingStart );
posNewLine = res.indexOf( '\n', posSignatureBlock ) + 1;
// now go to the end of the SB
while ( posNewLine < res.size() && posNewLine > 0 )
{
// check when the SB ends
line = res.mid( posNewLine, res.indexOf( '\n', posNewLine ) - posNewLine );
// * does not starts with prefix or
// * starts with prefix+(any substring of prefix)
if ( (prefix.isEmpty() && line.indexOf( CommonReplySearch ) < 0) ||
(!prefix.isEmpty() && line.startsWith( prefix ) &&
!prefix.contains( line.mid( prefix.size(), 1 ) )) )
{
posNewLine = res.indexOf( '\n', posNewLine ) + 1;
}
else
break; // end of the SB
}
// remove the SB or truncate when is the last SB
if ( posNewLine > 0 )
res.remove( posDeletingStart, posNewLine - posDeletingStart );
else
res.truncate( posDeletingStart );
}
return res;
}
int
main ( int argc, const char *argv[] )
{
QStringList tests;
tests << "text1\n-- \nSignature Block1\nSignature Block1\n\n"
"> text2\n> -- \n> Signature Block 2\n> Signature Block 2\n"
">> text3 -- not a signature block\n>> text3\n"
">>> text4\n> -- \n> Signature Block 4\n> Signature Block 4\n"
">>-------------\n>>-- text5 --\n>>-------------------\n"
">>-- \n>> Signature Block 5\n"
"text6\n-- \nSignature Block 6";
tests << "text1\n"
"> text2\n"
">> text3 -- not a signature block\n>> text3\n"
">>> text4\n"
">>-------------\n>>-- text5 --\n>>-------------------\n"
"text6\n";
tests << "text1\n"
"> text2\n"
">> text3 -- not a signature block\n>> text3\n"
">>> text4\n"
">>-------------\n>>-- text5 --\n>>-------------------\n"
"text6\n";
tests << "text1\n-- \nSignature Block1\nSignature Block1\n\n"
">text2\n>-- \n>Signature Block 2\n>Signature Block 2\n"
"> >text3\n> >text3\n> >-- \n>>Not Signature Block 3\n"
"> > Not Signature Block 3\n"
">text4\n>-- \n>Signature Block 4\n>Signature Block 4\n"
"text5\n-- \nSignature Block 5";
tests << "text1\n"
">text2\n"
">>Not Signature Block 3\n> > Not Signature Block 3\n"
">text4\n"
"text5\n";
tests << "text1\n"
">text2\n"
">>Not Signature Block 3\n> > Not Signature Block 3\n"
">text4\n"
"text5\n";
tests << "Text 1\n-- \nFirst sign\n\n\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n>> --\n"
">> Not Signature Block 2\n\n> Adios\n"
"\n>> Texto 3\n\n>> --\n>> Not Signature block 3\n";
tests << "Text 1\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n>> --\n"
">> Not Signature Block 2\n\n> Adios\n"
"\n>> Texto 3\n\n>> --\n>> Not Signature block 3\n";
tests << "Text 1\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n\n> Adios\n"
"\n>> Texto 3\n\n";
tests << "-- \n-- ACME, Inc\n-- Joe User\n-- PHB\n-- Tel.: 555 1234\n--";
tests << "";
tests << "";
tests << "Text 1\n\n\n\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n"
">> Not Signature Block 2\n\n> Adios\n"
"\n>> Texto 3\n\n>> --\n>> Not Signature block 3\n";
tests << "Text 1\n\n\n\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n"
">> Not Signature Block 2\n\n> Adios\n"
"\n>> Texto 3\n\n>> --\n>> Not Signature block 3\n";
tests << "Text 1\n\n\n\n> From: bla\n"
"> Texto 2\n\n> Aqui algo de texto.\n\n"
">> Not Signature Block 2\n\n> Adios\n"
"\n>> Texto 3\n\n";
tests << "Without Signature Blocks";
tests << "Without Signature Blocks";
tests << "Without Signature Blocks";
QString t1, t2, t3;
for ( int i = 0; i < 100; i++ )
{
t1.append( tests[9] );
t2.append( tests[10] );
t3.append( tests[11] );
}
tests << t1 << t2 << t3;
QTime time = QTime::currentTime();
for ( int j = 0; j < 200; j++ )
{
for ( int i = 0; i < 7; i++ )
{
QString res = stripSignature( tests[i * 3], j%2 );
// cout << "result:\n*" << res.toStdString() << "*" << endl << "expected:\n*" << tests[i*3+1+(j%2)].toStdString() << "*" <<endl;
assert( res == tests[i * 3 + 1 + (j%2)] );
}
}
cout << time.elapsed() << endl;
}
Thanks,
Jaime
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list