Update of /cvsroot/mahogany/M/src/classes
In directory usw-pr-cvs1:/tmp/cvs-serv1808/src/classes

Modified Files:
        ComposeTemplate.cpp 
Log Message:
discard text after the last signature found, not the first one when quoting and also 
don't use RE if possible (bug 582)

Index: ComposeTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ComposeTemplate.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -b -u -2 -r1.29 -r1.30
--- ComposeTemplate.cpp 16 Mar 2002 23:38:48 -0000      1.29
+++ ComposeTemplate.cpp 28 Apr 2002 22:49:55 -0000      1.30
@@ -1396,5 +1396,5 @@
    // should we quote the empty lines?
    //
-   // this option is ignore when we're inserting text verbatim (hence without
+   // this option is ignored when we're inserting text verbatim (hence without
    // reply prefix) and not quoting it
    bool quoteEmpty = !prefix.empty() &&
@@ -1427,4 +1427,7 @@
 
 #if wxUSE_REGEX
+   // will we use the RE?
+   bool useRE;
+
    // a RE to detect the start of the signature
    wxRegEx reSig;
@@ -1433,4 +1436,13 @@
       String sig = READ_CONFIG(m_profile, MP_REPLY_SIG_SEPARATOR);
 
+      if ( sig == GetStringDefault(MP_REPLY_SIG_SEPARATOR) )
+      {
+         // use faster manual code
+         useRE = false;
+      }
+      else // use the user-supplied RE
+      {
+         useRE = true;
+
       // we implicitly anchor the RE at start/end of line
       //
@@ -1451,4 +1463,5 @@
       }
    }
+   }
 #endif // wxUSE_REGEX
 
@@ -1459,4 +1472,7 @@
    String lineCur;
 
+   // the last detected signature start
+   int posSig = -1;
+
    for ( const char *cptr = text.c_str(); ; cptr++ )
    {
@@ -1466,20 +1482,47 @@
          if ( detectSig )
          {
+            bool isSig = false;
+
 #if wxUSE_REGEX
-            if ( reSig.Matches(cptr) )
-               break;
-#else // !wxUSE_REGEX
+            if ( useRE )
+            {
+               isSig = reSig.Matches(cptr);
+            }
+            else
+#endif // wxUSE_REGEX
+            {
             // hard coded detection for standard signature separator "--"
+               // and the mailing list trailer "____...___"
             if ( cptr[0] == '-' && cptr[1] == '-' )
             {
-               // there may be an optional space after "--"
+                  // there may be an optional space after "--" (in fact the
+                  // space should be there but some people don't put it)
                const char *p = cptr + 2;
                if ( IsEndOfLine(p) || (*p == ' ' && IsEndOfLine(p + 1)) )
                {
-                  // the rest is the sig - skip
-                  break;
+                     // looks like the start of the sig
+                     isSig = true;
+                  }
+               }
+               else if ( cptr[0] == '_' )
+               {
+                  const char *p = cptr + 1;
+                  while ( *p == '_' )
+                     p++;
+
+                  // consider that there should be at least 5 underscores...
+                  if ( IsEndOfLine(p) && p - cptr >= 5 )
+                  {
+                     // looks like the mailing list trailer
+                     isSig = true;
                }
             }
-#endif // wxUSE_REGEX/!wxUSE_REGEX
+            }
+
+            if ( isSig )
+            {
+               // remember that the sig apparently starts here
+               posSig = value->length();
+            }
          }
 
@@ -1559,4 +1602,13 @@
          }
       }
+   }
+
+   // if we had a sig, truncate it now: we have to do it like this because
+   // otherwise we risk discarding a too big part of the message, e.g. if it
+   // contains a quoted message with a sig inside it so we want to discard
+   // everything after the last sig detected
+   if ( posSig != -1 )
+   {
+      value->erase(posSig);
    }
 }


_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to