From c53d8d026021f97075fb2f4940ba22793c38fb6e Mon Sep 17 00:00:00 2001 From: davehauenstein Date: Wed, 15 Apr 2009 22:06:42 +0000 Subject: added toolbar; functionality includes refresh button to get back to original page, print article, email a link to the article with a personal note git-svn-id: http://arc90labs-readability.googlecode.com/svn/trunk@31 d4e419ec-0920-11de-bbfd-a7c1bc4c261e --- lib/Zend/Mail/Part/File.php | 198 +++++++++++++++++++++++++++++++++++++++ lib/Zend/Mail/Part/Interface.php | 136 +++++++++++++++++++++++++++ 2 files changed, 334 insertions(+) create mode 100644 lib/Zend/Mail/Part/File.php create mode 100644 lib/Zend/Mail/Part/Interface.php (limited to 'lib/Zend/Mail/Part') diff --git a/lib/Zend/Mail/Part/File.php b/lib/Zend/Mail/Part/File.php new file mode 100644 index 0000000..6ff5147 --- /dev/null +++ b/lib/Zend/Mail/Part/File.php @@ -0,0 +1,198 @@ +_fh = fopen($params['file'], 'r'); + } else { + $this->_fh = $params['file']; + } + if (!$this->_fh) { + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('could not open file'); + } + if (isset($params['startPos'])) { + fseek($this->_fh, $params['startPos']); + } + $header = ''; + $endPos = isset($params['endPos']) ? $params['endPos'] : null; + while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) { + $header .= $line; + } + + Zend_Mime_Decode::splitMessage($header, $this->_headers, $null); + + $this->_contentPos[0] = ftell($this->_fh); + if ($endPos !== null) { + $this->_contentPos[1] = $endPos; + } else { + fseek($this->_fh, 0, SEEK_END); + $this->_contentPos[1] = ftell($this->_fh); + } + if (!$this->isMultipart()) { + return; + } + + $boundary = $this->getHeaderField('content-type', 'boundary'); + if (!$boundary) { + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('no boundary found in content type to split message'); + } + + $part = array(); + $pos = $this->_contentPos[0]; + fseek($this->_fh, $pos); + while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) { + $line = fgets($this->_fh); + if ($line === false) { + if (feof($this->_fh)) { + break; + } + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('error reading file'); + } + + $lastPos = $pos; + $pos = ftell($this->_fh); + $line = trim($line); + + if ($line == '--' . $boundary) { + if ($part) { + // not first part + $part[1] = $lastPos; + $this->_partPos[] = $part; + } + $part = array($pos); + } else if ($line == '--' . $boundary . '--') { + $part[1] = $lastPos; + $this->_partPos[] = $part; + break; + } + } + $this->_countParts = count($this->_partPos); + + } + + + /** + * Body of part + * + * If part is multipart the raw content of this part with all sub parts is returned + * + * @return string body + * @throws Zend_Mail_Exception + */ + public function getContent($stream = null) + { + fseek($this->_fh, $this->_contentPos[0]); + if ($stream !== null) { + return stream_copy_to_stream($this->_fh, $stream, $this->_contentPos[1] - $this->_contentPos[0]); + } + $length = $this->_contentPos[1] - $this->_contentPos[0]; + return $length < 1 ? '' : fread($this->_fh, $length); + } + + /** + * Return size of part + * + * Quite simple implemented currently (not decoding). Handle with care. + * + * @return int size + */ + public function getSize() { + return $this->_contentPos[1] - $this->_contentPos[0]; + } + + /** + * Get part of multipart message + * + * @param int $num number of part starting with 1 for first part + * @return Zend_Mail_Part wanted part + * @throws Zend_Mail_Exception + */ + public function getPart($num) + { + --$num; + if (!isset($this->_partPos[$num])) { + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('part not found'); + } + + return new self(array('file' => $this->_fh, 'startPos' => $this->_partPos[$num][0], + 'endPos' => $this->_partPos[$num][1])); + } +} diff --git a/lib/Zend/Mail/Part/Interface.php b/lib/Zend/Mail/Part/Interface.php new file mode 100644 index 0000000..d1a22f1 --- /dev/null +++ b/lib/Zend/Mail/Part/Interface.php @@ -0,0 +1,136 @@ + value) + */ + public function getHeaders(); + + /** + * Get a header in specificed format + * + * Internally headers that occur more than once are saved as array, all other as string. If $format + * is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim). + * + * @param string $name name of header, matches case-insensitive, but camel-case is replaced with dashes + * @param string $format change type of return value to 'string' or 'array' + * @return string|array value of header in wanted or internal format + * @throws Zend_Mail_Exception + */ + public function getHeader($name, $format = null); + + /** + * Get a specific field from a header like content type or all fields as array + * + * If the header occurs more than once, only the value from the first header + * is returned. + * + * Throws a Zend_Mail_Exception if the requested header does not exist. If + * the specific header field does not exist, returns null. + * + * @param string $name name of header, like in getHeader() + * @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned + * @param string $firstName key name for the first part + * @return string|array wanted part or all parts as array($firstName => firstPart, partname => value) + * @throws Zend_Exception, Zend_Mail_Exception + */ + public function getHeaderField($name, $wantedPart = 0, $firstName = 0); + + + /** + * Getter for mail headers - name is matched in lowercase + * + * This getter is short for Zend_Mail_Part::getHeader($name, 'string') + * + * @see Zend_Mail_Part::getHeader() + * + * @param string $name header name + * @return string value of header + * @throws Zend_Mail_Exception + */ + public function __get($name); + + /** + * magic method to get content of part + * + * @return string content + */ + public function __toString(); +} \ No newline at end of file -- cgit v1.2.3