[whups] Email wordwrap patch

Mike Baptiste mike@msbnetworks.net
Tue Nov 12 01:28:33 2002


Below is a patch which changes how comments are formatted in 
notification emails.  The current code strips out all line feeds and 
outputs the comment in 80 char chunks.  While this made for a compact 
email, it really scrambled stuff like code snippets, data lists, etc

So instead of packing the comment down, we just wrap any long lines 
using wordwrap.

I realize this is a change vs a bug fix.  If there are folks that prefer 
compressed comments, maybe we can make it an option.  One thing I did 
notice is the current code didn't replace the linefeeds with spaces so 
words got joined together that had linefeeds between them. This would be 
fixed by adding a space to $result in the while (pos) loop I think.

Anyway, here is the patch

Index: Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.26
diff -c -r1.26 Driver.php
*** Driver.php	28 Oct 2002 22:23:44 -0000	1.26
--- Driver.php	12 Nov 2002 01:07:41 -0000
***************
*** 254,287 ****

       function _splitMessage($message)
       {
!         $set = split("[ \t]+", $message);
!         $len = 0;
!         $result = '';
!
!         foreach ($set as $substr) {
!             while (($pos = strpos($substr, "\n")) !== false) {
!                 $result .= substr($substr, 0, $pos);
!                 $len = 0;
!                 $substr = substr($substr, $pos + 1);
!             }
!
!             $slen = strlen($substr);
!
!             if (!$slen) {
!                 continue;
!             }
!
!             $len += $slen + 1;
!
!             if ($len > 80) {
!                 $len = $slen;
!                 $result .= "\n" . $substr . ' ';
!             } else {
!                 $result .= $substr . ' ';
!             }
!         }
!
!         return $result;
       }

   }
--- 254,260 ----

       function _splitMessage($message)
       {
!           return wordwrap($message, 80, "\n", 1);
       }

   }

-- 
Mike Baptiste - MSB Networks - mike@msbnetworks.net
Download my GnuPG key at http://msbnetworks.net/msbnet.gpg



More information about the whups mailing list