/**
  *
  */
 public function import($csv)
 {
     // convert to UTF-8
     $head = substr($csv, 0, 4096);
     $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1');
     // fallback to Latin-1?
     $charset = rcube_charset::detect($head, RCMAIL_CHARSET);
     $csv = rcube_charset::convert($csv, $charset);
     $head = '';
     $this->map = array();
     // Parse file
     foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) {
         $line = trim($line);
         if (empty($line)) {
             continue;
         }
         $elements = rcube_utils::explode_quoted_string(',', $line);
         if (empty($elements)) {
             continue;
         }
         // Parse header
         if (empty($this->map)) {
             $this->parse_header($elements);
             if (empty($this->map)) {
                 break;
             }
         } else {
             $this->csv_to_vcard($elements);
         }
     }
 }
Example #2
0
 /**
  * Parse CSV file line
  */
 protected function parse_line($line)
 {
     $line = trim($line);
     if (empty($line)) {
         return null;
     }
     $fields = rcube_utils::explode_quoted_string(',', $line);
     // remove quotes if needed
     if (!empty($fields)) {
         foreach ($fields as $idx => $value) {
             if (($len = strlen($value)) > 1 && $value[0] == '"' && $value[$len - 1] == '"') {
                 // remove surrounding quotes
                 $value = substr($value, 1, -1);
                 // replace doubled quotes inside the string with single quote
                 $value = str_replace('""', '"', $value);
                 $fields[$idx] = $value;
             }
         }
     }
     return $fields;
 }
Example #3
0
 /**
  * Try to fix invalid email addresses
  */
 public static function fix_email($email)
 {
     $parts = rcube_utils::explode_quoted_string('@', $email);
     foreach ($parts as $idx => $part) {
         // remove redundant quoting (#1490040)
         if ($part[0] == '"' && preg_match('/^"([a-zA-Z0-9._+=-]+)"$/', $part, $m)) {
             $parts[$idx] = $m[1];
         }
     }
     return implode('@', $parts);
 }
Example #4
0
 /**
  * Check rcube_utils::explode_quoted_string() compat. with explode()
  */
 function test_explode_quoted_string_compat()
 {
     $data = array('', 'a,b,c', 'a', ',', ',a');
     foreach ($data as $text) {
         $result = rcube_utils::explode_quoted_string(',', $text);
         $this->assertSame(explode(',', $text), $result);
     }
 }
 /**
  * Take a set of recipients and parse them, returning an array of
  * bare addresses (forward paths) that can be passed to sendmail
  * or an smtp server with the rcpt to: command.
  *
  * @param mixed Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid.
  *
  * @return array An array of forward paths (bare addresses).
  * @access private
  */
 private function _parse_rfc822($recipients)
 {
     // if we're passed an array, assume addresses are valid and implode them before parsing.
     if (is_array($recipients)) {
         $recipients = implode(', ', $recipients);
     }
     $addresses = array();
     $recipients = rcube_utils::explode_quoted_string(',', $recipients);
     reset($recipients);
     while (list($k, $recipient) = each($recipients)) {
         $a = rcube_utils::explode_quoted_string(' ', $recipient);
         while (list($k2, $word) = each($a)) {
             if (strpos($word, "@") > 0 && $word[strlen($word) - 1] != '"') {
                 $word = preg_replace('/^<|>$/', '', trim($word));
                 if (in_array($word, $addresses) === false) {
                     array_push($addresses, $word);
                 }
             }
         }
     }
     return $addresses;
 }
Example #6
0
function rcube_explode_quoted_string($delimiter, $string)
{
    return rcube_utils::explode_quoted_string($delimiter, $string);
}
Example #7
0
 /**
  * Take a set of recipients and parse them, returning an array of
  * bare addresses (forward paths) that can be passed to sendmail
  * or an smtp server with the rcpt to: command.
  *
  * @param mixed Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid.
  *
  * @return array An array of forward paths (bare addresses).
  */
 private function _parse_rfc822($recipients)
 {
     // if we're passed an array, assume addresses are valid and implode them before parsing.
     if (is_array($recipients)) {
         $recipients = implode(', ', $recipients);
     }
     $addresses = array();
     $recipients = preg_replace('/[\\s\\t]*\\r?\\n/', '', $recipients);
     $recipients = rcube_utils::explode_quoted_string(',', $recipients);
     reset($recipients);
     foreach ($recipients as $recipient) {
         $a = rcube_utils::explode_quoted_string(' ', $recipient);
         foreach ($a as $word) {
             $word = trim($word);
             $len = strlen($word);
             if ($len && strpos($word, "@") > 0 && $word[$len - 1] != '"') {
                 $word = preg_replace('/^<|>$/', '', $word);
                 if (!in_array($word, $addresses)) {
                     array_push($addresses, $word);
                 }
             }
         }
     }
     return $addresses;
 }
 /**
  * Convert sql record into a rcube style event object
  */
 private function _read_postprocess($event)
 {
     $free_busy_map = array_flip($this->free_busy_map);
     $sensitivity_map = array_flip($this->sensitivity_map);
     $event['id'] = $event['event_id'];
     if ($event['allday'] = intval($event['all_day'])) {
         $event['start'] = new DateTime($event['start']);
         $event['end'] = new DateTime($event['end']);
     } else {
         $tz = $event['tzname'] ? $event['tzname'] : 'UTC';
         $event['start'] = new DateTime($event['start'], new DateTimezone($tz));
         $event['end'] = new DateTime($event['end'], new DateTimezone($tz));
     }
     $event['created'] = new DateTime($event['created']);
     $event['created']->setTimezone(new DateTimezone('UTC'));
     $event['changed'] = new DateTime($event['changed']);
     $event['changed']->setTimezone(new DateTimezone('UTC'));
     $event['free_busy'] = $free_busy_map[$event['free_busy']];
     $event['sensitivity'] = $sensitivity_map[$event['sensitivity']];
     $event['calendar'] = $event['calendar_id'];
     $event['recurrence_id'] = intval($event['recurrence_id']);
     // parse recurrence rule
     if ($event['recurrence'] && preg_match_all('/([A-Z]+)=([^;]+);?/', $event['recurrence'], $m, PREG_SET_ORDER)) {
         $event['recurrence'] = array();
         foreach ($m as $rr) {
             if (is_numeric($rr[2])) {
                 $rr[2] = intval($rr[2]);
             } else {
                 if ($rr[1] == 'UNTIL') {
                     $rr[2] = date_create($rr[2]);
                 } else {
                     if ($rr[1] == 'RDATE') {
                         $rr[2] = array_map('date_create', explode(',', $rr[2]));
                     } else {
                         if ($rr[1] == 'EXDATE') {
                             $rr[2] = array_map('date_create', explode(',', $rr[2]));
                         }
                     }
                 }
             }
             $event['recurrence'][$rr[1]] = $rr[2];
         }
     }
     if ($event['exception']) {
         $event['recurrence_date'] = new DateTime($event['exception'], $this->cal->timezone);
     }
     if ($event['_attachments'] > 0) {
         $event['attachments'] = (array) $this->list_attachments($event);
     }
     // decode serialized event attendees
     if ($event['attendees']) {
         $attendees = array();
         foreach (explode("\n", $event['attendees']) as $line) {
             $att = array();
             foreach (rcube_utils::explode_quoted_string(';', $line) as $prop) {
                 list($key, $value) = explode("=", $prop);
                 $att[strtolower($key)] = stripslashes(trim($value, '""'));
             }
             $attendees[] = $att;
         }
         $event['attendees'] = $attendees;
     }
     unset($event['event_id'], $event['calendar_id'], $event['all_day'], $event['_attachments']);
     return $event;
 }
 /**
  * Helper method to decode the attendees list from string
  */
 private function unserialize_attendees($s_attendees)
 {
     $attendees = array();
     // decode json serialized string
     if ($s_attendees[0] == '[') {
         $attendees = json_decode($s_attendees, true);
     } else {
         foreach (explode("\n", $s_attendees) as $line) {
             $att = array();
             foreach (rcube_utils::explode_quoted_string(';', $line) as $prop) {
                 list($key, $value) = explode("=", $prop);
                 $att[strtolower($key)] = stripslashes(trim($value, '""'));
             }
             $attendees[] = $att;
         }
     }
     return $attendees;
 }
Example #10
0
function rcube_explode_quoted_string($delimiter, $string)
{
    _deprecation_warning(__FUNCTION__);
    return rcube_utils::explode_quoted_string($delimiter, $string);
}