[dev] iCalendar fixups

John Morrissey jwm at horde.net
Mon Mar 10 12:52:53 PST 2003


The attached patch fixes a few minor iCalendar-related things:

* Outlook likes to put raw "\n" sequences in event descriptions and also
  likes to escape commas (',' -> '\,').
* Data::iCalendar was using Data::getNewline() to determine the newline
  character for exports; RFC 2425 says this should always be \r\n.
* Data::iCalendar::export() was appendling the newline character twice;
  _quoteAndFold() already appends it.
* 'Response' was misspelled in imp's itip viewer.
* Substitute <br /> for newlines in the description field in imp's itip
  viewer, so the description looks better than a single text block.

john
-- 
John Morrissey          _o            /\         ----  __o
jwm at horde.net        _-< \_          /  \       ----  <  \,
www.horde.net/    __(_)/_(_)________/    \_______(_) /_(_)__
-------------- next part --------------
Index: lib/iCalendar.php
===================================================================
RCS file: /repository/horde/lib/iCalendar.php,v
retrieving revision 1.12
diff -u -u -r1.12 iCalendar.php
--- lib/iCalendar.php	10 Feb 2003 17:06:14 -0000	1.12
+++ lib/iCalendar.php	9 Mar 2003 16:52:05 -0000
@@ -228,6 +228,12 @@
                 }
 
                 switch ($tag) {
+                    case 'DESCRIPTION':
+                        $value = preg_replace('/\\\\,/', ',', $value);
+                        $value = preg_replace('/\\\\n/', "\n", $value);
+                        $this->setAttribute($tag, $value, $params);
+                        break;
+
                     // Date fields
                     case 'DTSTAMP':
                     case 'COMPLETED':
Index: lib/Data/icalendar.php
===================================================================
RCS file: /repository/horde/lib/Data/icalendar.php,v
retrieving revision 1.15
diff -u -u -r1.15 icalendar.php
--- lib/Data/icalendar.php	14 Jan 2003 21:00:41 -0000	1.15
+++ lib/Data/icalendar.php	9 Mar 2003 16:52:05 -0000
@@ -85,7 +85,9 @@
     {
         global $prefs;
 
-        $newline = $this->getNewline();
+        /* According to RFC 2425, we should always use CRLF-terminated
+           lines. */
+        $newline = "\r\n";
         $DST = date('I');
         $TZNAME = date('T');
         $TZID = $prefs->getValue('timezone');
@@ -95,19 +97,19 @@
         // $TZOffsetFrom = ($DST) ? $TZOFFSET-100 : $TZOFFSET;
         // $TZOffsetTo   = ($DST) ? $TZOFFSET : $TZOFFSET-100;
 
-        $file = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Horde.org//Kronolith Generated\nMETHOD:REQUEST\n";
+        $file = "BEGIN:VCALENDAR${newline}VERSION:2.0${newline}PRODID:-//Horde.org//Kronolith Generated${newline}METHOD:REQUEST${newline}";
         foreach ($data as $row) {
-            $file .= "BEGIN:VEVENT\n";
+            $file .= "BEGIN:VEVENT$newline";
             foreach ($row as $key => $val) {
                 if (!empty($val)) {
                     // Basic encoding. Newlines for now; more work
                     // here to make this RFC-compliant.
-                    $file .= $key . ':' .  $this->_quoteAndFold($val) . $newline;
+                    $file .= $key . ':' .  $this->_quoteAndFold($val);
                 }
             }
-            $file .= "END:VEVENT\n";
+            $file .= "END:VEVENT$newline";
         }
-        $file .= "END:VCALENDAR\n";
+        $file .= "END:VCALENDAR$newline";
 
         return $file;
     }
Index: imp/lib/MIME/Viewer/itip.php
===================================================================
RCS file: /repository/imp/lib/MIME/Viewer/itip.php,v
retrieving revision 1.5
diff -u -u -r1.5 itip.php
--- imp/lib/MIME/Viewer/itip.php	21 Feb 2003 03:16:02 -0000	1.5
+++ imp/lib/MIME/Viewer/itip.php	9 Mar 2003 16:52:05 -0000
@@ -332,7 +332,7 @@
                     if (!empty($replyto) && ($replyto != $barefrom)) {
                         $msg_headers->addHeader('Reply-to', $replyto);
                     }
-                    $msg_headers->addHeader('Subject', _("Free/Busy Request Responce"));
+                    $msg_headers->addHeader('Subject', _("Free/Busy Request Response"));
                     $msg_headers->addMIMEHeaders($mime);
 
                     // Send the reply
@@ -636,7 +636,7 @@
 
         $desc = $vevent->getAttribute('DESCRIPTION');
         if (!is_a($desc, 'PEAR_Error')) {
-            $html .= sprintf('<tr><td colspan="2" class="item"><b>%s:</b>&nbsp;%s</td></tr>', _("Description"), $desc);
+            $html .= sprintf('<tr><td colspan="2" class="item"><b>%s:</b><br />%s</td></tr>', _("Description"), preg_replace('/\\n/', '<br />', $desc));
         }
 
         $loc = $vevent->getAttribute('LOCATION');
@@ -685,7 +685,7 @@
                     }
                 }
 
-                $status = _("Awaiting Responce");
+                $status = _("Awaiting Response");
                 if (array_key_exists('PARTSTAT', $params[$key])) {
                     $status = $this->_partstatToString($params[$key]['PARTSTAT'], $status);
                 }


More information about the dev mailing list