Revision: 1666
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1666&view=rev
Author:   cimorrison
Date:     2010-12-03 16:46:12 +0000 (Fri, 03 Dec 2010)

Log Message:
-----------
Implemented "folding"

Modified Paths:
--------------
    mrbs/branches/ics_attachments/web/functions_ical.inc

Modified: mrbs/branches/ics_attachments/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_ical.inc        2010-12-03 
16:12:52 UTC (rev 1665)
+++ mrbs/branches/ics_attachments/web/functions_ical.inc        2010-12-03 
16:46:12 UTC (rev 1666)
@@ -5,6 +5,42 @@
 
 define ('RFC5545_FORMAT', 'Ymd\THis');  // Format for expressing iCalendar 
dates
 
+// "Folds" lines longer than 75 octets
+//
+// "Lines of text SHOULD NOT be longer than 75 octets, excluding the line
+// break.  Long content lines SHOULD be split into a multiple line
+// representations using a line "folding" technique.  That is, a long
+// line can be split between any two characters by inserting a CRLF
+// immediately followed by a single linear white-space character (i.e.,
+// SPACE or HTAB).  Any sequence of CRLF followed immediately by a
+// single linear white-space character is ignored (i.e., removed) when
+// processing the content type."  (RFC 5545)
+function ical_fold($str)
+{
+  $result = '';
+  $col = 0;
+  for ($i=0; $i<strlen($str); $i++)
+  {
+    // If we've reached a CRLF reset the column counter 
+    // to the beginning of the line
+    if (($str[$i] == "\r")  && 
+        (($i+1) < strlen($str)) &&
+        ($str[$i+1] == "\n"))
+    {
+      $col = -2;  // -2 because we'll then be at 0 after the \r\n
+    }
+    // Otherwise if we've already had 75 characters, insert
+    // a CRLF followed by a space (and so the column counter will be 1)
+    elseif ($col >= 75)
+    {
+      $result .= "\r\n ";
+      $col = 1;
+    }
+    $result .= $str[$i];
+    $col++;
+  }
+  return $result;
+}
 
 // Escape text for use in an iCalendar object
 function ical_escape_text($str)
@@ -138,7 +174,8 @@
   
   $result = implode($eol, $results);
   $result .= $eol;  // Has to end with a CRLF
-
+  
+  $result = ical_fold($result);
   return $result;
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to