[sync] Support for importing recurring Outlook events [PATCH]
Todd Pytel
tppytel at sophrosune.org
Tue Aug 8 23:44:15 PDT 2006
The following diff should allow importing of recurring events from the
Sync4J Outlook connector. No support for exceptions yet, but all of the
standard SIF-format RecurrenceTypes are implemented.
While I'm looking at it, are there specific recurrence bugs involved
with http://bugs.horde.org/ticket/?id=3885 ? I didn't test absolutely
every permutation of recurrence parameters, but I tried a lot of things
and they seemed to work correctly.
--- SyncML/Device/Sync4j.php.orig 2006-08-08 15:06:58.000000000 -0500
+++ SyncML/Device/Sync4j.php 2006-08-09 01:15:57.000000000 -0500
@@ -62,6 +62,15 @@
$contentType = 'text/x-vtodo';
break;
}
+
+ // Always remove client UID. UID will be seperately passed in
+ // XML.
+ $content = preg_replace('/(\r\n|\r|\n)UID:.*?(\r\n|\r|\n)/',
'\1', $content, 1);
+
+ // Ensure valid newline termination.
+ if (substr($content, -1) != "\n" && substr($content, -1) !=
"\r") {
+ $content .= "\r\n";
+ }
if (DEBUGLOG_ICALENDARDATA) {
$fp = @fopen('/tmp/sync/log.txt', 'a');
@@ -315,9 +324,53 @@
$vEvent->setAttribute('LOCATION', $a['Location']);
+ if ($a['IsRecurring'] == 1) {
+
+ $typearray = array('DAILY','WEEKLY','MONTHLY','MONTHLY',
+ 'NOTUSED','MONTHLY','MONTHLY');
+ $recurtype = $a['RecurrenceType'];
+
+ $rule = "FREQ=" . $typearray[$recurtype] . ";";
+ $rule .= "INTERVAL=" . $a['Interval'];
+
+ if ($recurtype == 1 || $recurtype == 3 || $recurtype == 6)
{
+ $rule .= ";BYDAY=";
+ if ($recurtype == 3 || $recurtype == 6) {
+ $rule .= $a['Instance'];
+ }
+ $rule .= $this->maskToString($a['DayOfWeekMask']);
+ }
+
+ if ($a['NoEndDate'] == 0) {
+ $rule .= ';UNTIL=' . $a['PatternEndDate'];
+ }
+
+ $vEvent->setAttribute('RRULE', $rule);
+ }
+
return $vEvent->exportvCalendar();
}
+ // Converts a SIF DayOfWeekMask to a string of days, used above
+
+ function maskToString($mask)
+ {
+ $days = array('SU','MO','TU','WE','TH','FR','SA');
+
+ $result = "";
+ $i = 0;
+ for ($i=0; $mask > 0; $i++) {
+ if ($mask % 2 != 0) {
+ $result .= $days[$i] . ",";
+ $mask--;
+ }
+ $mask /= 2;
+ }
+
+ $result = substr_replace($result, "", -1);
+ return $result;
+ }
+
function sif2vtodo($sif)
{
$a = SyncML_Device_sync4j::sif2array($sif);
More information about the sync
mailing list