Exemplo n.º 1
0
 /**
  * Performs the test.
  *
  * @return \Jyxo\Beholder\Result
  */
 public function run()
 {
     // The http extension is required
     if (!extension_loaded('http')) {
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension http missing');
     }
     $http = new \HttpRequest($this->url, \HttpRequest::METH_GET, array('connecttimeout' => 5, 'timeout' => 10, 'useragent' => 'JyxoBeholder'));
     try {
         $http->send();
         if (200 !== $http->getResponseCode()) {
             throw new \Exception(sprintf('Http error: %s', $http->getResponseCode()));
         }
         if (isset($this->tests['body'])) {
             $body = $http->getResponseBody();
             if (!preg_match($this->tests['body'], $body)) {
                 $body = trim(strip_tags($body));
                 throw new \Exception(sprintf('Invalid body: %s', \Jyxo\String::cut($body, 16)));
             }
         }
         // OK
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS);
     } catch (\HttpException $e) {
         $inner = $e;
         while (null !== $inner->innerException) {
             $inner = $inner->innerException;
         }
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $inner->getMessage());
     } catch (\Exception $e) {
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * Encodes a string using the quoted-printable encoding.
  *
  * @param string $string Input string
  * @param integer $lineLength Line length
  * @param string $lineEnd Line ending
  * @return string
  */
 private static function encodeQuotedPrintable($string, $lineLength, $lineEnd)
 {
     $encoded = \Jyxo\String::fixLineEnding(trim($string), $lineEnd);
     // Replaces all high ASCII characters, control codes and '='
     $encoded = preg_replace_callback('~([\\000-\\010\\013\\014\\016-\\037\\075\\177-\\377])~', function ($matches) {
         return '=' . sprintf('%02X', ord($matches[1]));
     }, $encoded);
     // Replaces tabs and spaces if on line ends
     $encoded = preg_replace_callback('~([\\011\\040])' . $lineEnd . '~', function ($matches) use($lineEnd) {
         return '=' . sprintf('%02X', ord($matches[1])) . $lineEnd;
     }, $encoded);
     $output = '';
     $lines = explode($lineEnd, $encoded);
     // Release from memory
     unset($encoded);
     foreach ($lines as $line) {
         // Line length is less than maximum
         if (strlen($line) <= $lineLength) {
             $output .= $line . $lineEnd;
             continue;
         }
         do {
             $partLength = strlen($line);
             if ($partLength > $lineLength) {
                 $partLength = $lineLength;
             }
             // Cannot break a line in the middle of a character
             $pos = strrpos(substr($line, 0, $partLength), '=');
             if (false !== $pos && $pos >= $partLength - 2) {
                 $partLength = $pos;
             }
             // If the last char is a break, move one character backwards
             if ($partLength > 0 && ' ' == $line[$partLength - 1]) {
                 $partLength--;
             }
             // Saves string parts, trims the string and continues
             $output .= substr($line, 0, $partLength);
             $line = substr($line, $partLength);
             // We are in the middle of a line
             if (!empty($line)) {
                 $output .= '=';
             }
             $output .= $lineEnd;
         } while (!empty($line));
     }
     return $output;
 }
Exemplo n.º 3
0
 /**
  * Adds all attachments to the email.
  *
  * @return string
  */
 private function attachAll()
 {
     $mime = array();
     foreach ($this->email->attachments as $attachment) {
         $encoding = !empty($attachment->encoding) ? $attachment->encoding : Encoding::BASE64;
         $name = $this->changeCharset($this->clearHeaderValue($attachment->name));
         $mime[] = '--' . $this->boundary[1] . self::LINE_END;
         $mime[] = 'Content-Type: ' . $this->clearHeaderValue($attachment->mimeType) . ';' . self::LINE_END;
         $mime[] = ' name="' . $this->encodeHeader($name) . '"' . self::LINE_END;
         $mime[] = 'Content-Transfer-Encoding: ' . $encoding . self::LINE_END;
         if ($attachment->isInline()) {
             $mime[] = 'Content-ID: <' . $this->clearHeaderValue($attachment->cid) . '>' . self::LINE_END;
         }
         $mime[] = 'Content-Disposition: ' . $attachment->disposition . ';' . self::LINE_END;
         $mime[] = ' filename="' . $this->encodeHeader($name) . '"' . self::LINE_END . self::LINE_END;
         // Just fix line endings in case of encoded attachments, encode otherwise
         $mime[] = !empty($attachment->encoding) ? \Jyxo\String::fixLineEnding($attachment->content, self::LINE_END) : $this->encodeString($attachment->content, $encoding);
         $mime[] = self::LINE_END . self::LINE_END;
     }
     $mime[] = '--' . $this->boundary[1] . '--' . self::LINE_END;
     return implode('', $mime);
 }