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

List:       kde-pim
Subject:    Re: [Kde-pim] Review Request: Remove all the signature blocks.
From:       "Thomas McGuire" <mcguire () kde ! org>
Date:       2009-03-30 18:13:04
Message-ID: 20090330181304.14981.97602 () localhost
[Download RAW message or body]


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.kde.org/r/403/#review737
-----------------------------------------------------------


FYI: Added unit tests for this in r947004, see \
http://websvn.kde.org/?view=rev&revision=947004

- Thomas


On 2009-03-28 11:09:40, Jaime Torres wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.kde.org/r/403/
> -----------------------------------------------------------
> 
> (Updated 2009-03-28 11:09:40)
> 
> 
> Review request for KDE PIM.
> 
> 
> 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
> -----
> 
> /trunk/KDE/kdepim/kmail/kmmessage.cpp 945537 
> 
> Diff: http://reviewboard.kde.org/r/403/diff
> 
> 
> Testing
> -------
> 
> #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.
> const QRegExp sbDelimiterSearch = clearSigned ?
> QRegExp( "(^|\n)[> ]*--\\s?\n" ) : QRegExp( "(^|\n)[> ]*-- \n" );
> // The regular expresion to look for prefix change
> const QRegExp commonReplySearch = QRegExp( "[ ]*>" );
> 
> QString res = msg;
> int posDeletingStart = 1; // to start looking at 0
> 
> // While there are SB delimiters (start looking just before the deleted SB)
> while ( ( posDeletingStart = res.indexOf( sbDelimiterSearch , posDeletingStart -1 ) \
> ) >= 0 ) {
> QString prefix; // the current prefix
> QString line; // the line to check if is part of the SB
> int posNewLine = -1;
> int posSignatureBlock = -1;
> // Look for the SB 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 )
> {
> // handle the undefined case for mid ( x , -n ) where n>1
> int nextPosNewLine = res.indexOf( '\n', posNewLine );
> if ( nextPosNewLine < 0 ) nextPosNewLine = posNewLine - 1;
> line = res.mid( posNewLine, nextPosNewLine - posNewLine );
> 
> // check when the SB ends:
> // * 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 ) &&
> line.mid( prefix.size() ).indexOf( commonReplySearch ) < 0 ) )
> {
> 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>>\n>> Signature Block 5\n"
> "text6\n-- \nSignature Block 6\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"
> "> 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"
> "> >text3\n> >text3\n"
> ">>Not Signature Block 3\n> > Not Signature Block 3\n"
> ">text4\n"
> "text5\n";
> tests << "text1\n"
> ">text2\n"
> "> >text3\n> >text3\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@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


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

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