Esempio n. 1
0
 /**
  * Sends one or more iTip messages through email.
  *
  * @param string $originator Originator Email
  * @param array $recipients Array of email addresses
  * @param VObject\Component $vObject
  * @param string $principal Principal Url of the originator
  * @return void
  */
 public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal)
 {
     foreach ($recipients as $recipient) {
         $to = $recipient;
         $replyTo = $originator;
         $subject = 'SabreDAV iTIP message';
         switch (strtoupper($vObject->METHOD)) {
             case 'REPLY':
                 $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
                 break;
             case 'REQUEST':
                 $subject = 'Invitation for: ' . $vObject->VEVENT->SUMMARY;
                 break;
             case 'CANCEL':
                 $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
                 break;
         }
         $headers = array();
         $headers[] = 'Reply-To: ' . $replyTo;
         $headers[] = 'From: ' . $this->senderEmail;
         $headers[] = 'Content-Type: text/calendar; method=' . (string) $vObject->method . '; charset=utf-8';
         if (DAV\Server::$exposeVersion) {
             $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY;
         }
         $vcalBody = $vObject->serialize();
         $this->mail($to, $subject, $vcalBody, $headers);
     }
 }
Esempio n. 2
0
 /**
  * Reads a property or component from a line.
  *
  * @return void
  */
 protected function readProperty($line)
 {
     if ($this->options & self::OPTION_FORGIVING) {
         $propNameToken = 'A-Z0-9\\-\\._\\/';
     } else {
         $propNameToken = 'A-Z0-9\\-\\.';
     }
     $paramNameToken = 'A-Z0-9\\-';
     $safeChar = '^";:,';
     $qSafeChar = '^"';
     $regex = "/\n            ^(?P<name> [{$propNameToken}]+ ) (?=[;:])        # property name\n            |\n            (?<=:)(?P<propValue> .*)\$                      # property value\n            |\n            ;(?P<paramName> [{$paramNameToken}]+) (?=[=;:])  # parameter name\n            |\n            (=|,)(?P<paramValue>                           # parameter value\n                (?: [{$safeChar}]*) |\n                \"(?: [{$qSafeChar}]+)\"\n            ) (?=[;:,])\n            /xi";
     //echo $regex, "\n"; die();
     preg_match_all($regex, $line, $matches, PREG_SET_ORDER);
     $property = array('name' => null, 'parameters' => array(), 'value' => null);
     $lastParam = null;
     /**
      * Looping through all the tokens.
      *
      * Note that we are looping through them in reverse order, because if a
      * sub-pattern matched, the subsequent named patterns will not show up
      * in the result.
      */
     foreach ($matches as $match) {
         if (isset($match['paramValue'])) {
             if ($match['paramValue'] && $match['paramValue'][0] === '"') {
                 $value = substr($match['paramValue'], 1, -1);
             } else {
                 $value = $match['paramValue'];
             }
             $value = $this->unescapeParam($value);
             if (is_null($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam] = $value;
             } elseif (is_array($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam][] = $value;
             } else {
                 $property['parameters'][$lastParam] = array($property['parameters'][$lastParam], $value);
             }
             continue;
         }
         if (isset($match['paramName'])) {
             $lastParam = strtoupper($match['paramName']);
             if (!isset($property['parameters'][$lastParam])) {
                 $property['parameters'][$lastParam] = null;
             }
             continue;
         }
         if (isset($match['propValue'])) {
             $property['value'] = $match['propValue'];
             continue;
         }
         if (isset($match['name']) && $match['name']) {
             $property['name'] = strtoupper($match['name']);
             continue;
         }
         // @codeCoverageIgnoreStart
         throw new \LogicException('This code should not be reachable');
         // @codeCoverageIgnoreEnd
     }
     if (is_null($property['value']) || !$property['name']) {
         if ($this->options & self::OPTION_IGNORE_INVALID_LINES) {
             return false;
         }
         throw new ParseException('Invalid Mimedir file. Line starting at ' . $this->startLine . ' did not follow iCalendar/vCard conventions');
     }
     // vCard 2.1 states that parameters may appear without a name, and only
     // a value. We can deduce the value based on it's name.
     //
     // Our parser will get those as parameters without a value instead, so
     // we're filtering these parameters out first.
     $namedParameters = array();
     $namelessParameters = array();
     foreach ($property['parameters'] as $name => $value) {
         if (!is_null($value)) {
             $namedParameters[$name] = $value;
         } else {
             $namelessParameters[] = $name;
         }
     }
     $propObj = $this->root->createProperty($property['name'], null, $namedParameters);
     foreach ($namelessParameters as $namelessParameter) {
         $propObj->add(null, $namelessParameter);
     }
     if (strtoupper($propObj['ENCODING']) === 'QUOTED-PRINTABLE') {
         $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue());
     } else {
         $propObj->setRawMimeDirValue($property['value']);
     }
     return $propObj;
 }
Esempio n. 3
0
 /**
  * Repairs a VObject file
  *
  * @param Component $vObj
  * @return int
  */
 protected function repair($vObj)
 {
     $returnCode = 0;
     switch ($vObj->name) {
         case 'VCALENDAR':
             $this->log("iCalendar: " . (string) $vObj->VERSION);
             break;
         case 'VCARD':
             $this->log("vCard: " . (string) $vObj->VERSION);
             break;
     }
     $warnings = $vObj->validate(Node::REPAIR);
     if (!count($warnings)) {
         $this->log("  No warnings!");
     } else {
         foreach ($warnings as $warn) {
             $returnCode = 2;
             $this->log("  " . $warn['message']);
         }
     }
     fwrite($this->stdout, $vObj->serialize());
     return $returnCode;
 }