Revision: 1737
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1737&view=rev
Author:   cimorrison
Date:     2011-01-06 08:49:07 +0000 (Thu, 06 Jan 2011)

Log Message:
-----------
Added a CN parameter to the ORGANIZER and ATTENDEE properties, extracting the 
common name from the email address where possible.

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

Modified: mrbs/branches/ics_attachments/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_ical.inc        2011-01-05 
17:31:04 UTC (rev 1736)
+++ mrbs/branches/ics_attachments/web/functions_ical.inc        2011-01-06 
08:49:07 UTC (rev 1737)
@@ -96,6 +96,7 @@
   return $str;
 }
 
+
 // Create an iCalendar Recurrence Rule
 function create_rrule($data)
 {
@@ -236,15 +237,33 @@
   */
   
   // ORGANIZER
+  // The organizer is the booking creator if we've got an email address for 
him/her.
+  // Otherwise we'll make the 'from' address the organizer.   In both cases 
we'll try
+  // and extract the common name from the email address.
   $organizer_email = get_email_address($data['create_by']);
-  if (!empty($organizer_email))
+  if (empty($organizer_email))
   {
-    $results[] = "ORGANIZER;CN=\"" . 
ical_escape_quoted_string($data['create_by']) . "\":mailto:$organizer_email";;
+    $organizer = parse_address($addresses['from']);
+    if (empty($organizer['common_name']))
+    {
+      $organizer['common_name'] = $organizer['address'];
+    }
   }
-  elseif (!empty($addresses['from']))
+  else
   {
-    $results[] = "ORGANIZER:mailto:"; . $addresses['from'];
+    $organizer = parse_address($organizer_email);
+    if (empty($organizer['common_name']))
+    {
+      // If the email address doesn't have a common name
+      // then we can use the creator's username
+      $organizer['common_name'] = $data['create_by'];
+    }
   }
+  if (!empty($organizer['address']))
+  {
+    $results[] = "ORGANIZER;CN=\"" . 
ical_escape_quoted_string($organizer['common_name']) . "\":mailto:"; . 
$organizer['address'];
+  }
+  
   // Put the people on the "to" list as required participants and those on the 
cc
   // list as non particpants.   In theory the email client can then decide 
whether
   // to enter the booking automaticaly on the user's calendar - although at the
@@ -281,7 +300,11 @@
               $role = "NON-PARTICIPANT";
               break;
           }
-          $results[] = "ATTENDEE;ROLE=$role:mailto:"; . trim($attendee);
+          // Use the common name if there is one
+          $attendee = parse_address($attendee);
+          $results[] = "ATTENDEE;" .
+                       ((!empty($attendee['common_name'])) ? "CN=\"" . 
ical_escape_quoted_string($attendee['common_name']) . "\";" : "") .
+                       "ROLE=$role:mailto:"; . $attendee['address'];
         }
       }
     }

Modified: mrbs/branches/ics_attachments/web/functions_mail.inc
===================================================================
--- mrbs/branches/ics_attachments/web/functions_mail.inc        2011-01-05 
17:31:04 UTC (rev 1736)
+++ mrbs/branches/ics_attachments/web/functions_mail.inc        2011-01-06 
08:49:07 UTC (rev 1737)
@@ -177,6 +177,37 @@
   return convertToMailCharset($string);
 }
 
+
+// Splits an email address of the form 'common_name <address>',
+// '"common_name" <address>' or just 'address' into a common name and an 
address.
+// Returns the result as an array index by 'common_name' and 'address'.
+function parse_address($email_address)
+{
+  if (strpos($email_address, '<') === FALSE)
+  {
+    $cn = '';
+    $addr = $email_address;
+  }
+  else
+  {
+    list($cn, $addr) = explode('<', $email_address, 2);
+  
+    $cn = trim($cn);
+    $cn = trim($cn, '"');
+    $cn = trim($cn);
+  
+    $addr = trim($addr);
+    $addr = rtrim($addr, '>');
+    $addr = trim($addr);
+  }
+  
+  $result = array();
+  $result['common_name'] = $cn;
+  $result['address'] = $addr; 
+  return $result;
+}
+
+
 // get_address_list($array)
 //
 // Takes an array of email addresses and returns a comma separated


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

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to