summaryrefslogtreecommitdiff
path: root/Postman/Postman-Mail/Zend-1.12.10/Mail/Part
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-10-15 06:46:12 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-10-15 06:46:12 +0000
commitca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6 (patch)
tree40ff112761d82af1d8c1c89d30ede8206502e17b /Postman/Postman-Mail/Zend-1.12.10/Mail/Part
parent8812fbf61bde539d1599e239044595ccb8a2c3a5 (diff)
downloadPost-SMTP-ca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6.zip
release
Diffstat (limited to 'Postman/Postman-Mail/Zend-1.12.10/Mail/Part')
-rw-r--r--Postman/Postman-Mail/Zend-1.12.10/Mail/Part/File.php198
-rw-r--r--Postman/Postman-Mail/Zend-1.12.10/Mail/Part/Interface.php136
2 files changed, 334 insertions, 0 deletions
diff --git a/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/File.php b/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/File.php
new file mode 100644
index 0000000..dbe34c2
--- /dev/null
+++ b/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/File.php
@@ -0,0 +1,198 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Postman_Zend_Mail
+ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id$
+ */
+
+
+/**
+ * @see Postman_Zend_Mime_Decode
+ */
+require_once 'Zend/Mime/Decode.php';
+
+/**
+ * @see Postman_Zend_Mail_Part
+ */
+require_once 'Zend/Mail/Part.php';
+
+
+/**
+ * @category Zend
+ * @package Postman_Zend_Mail
+ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Postman_Zend_Mail_Part_File extends Postman_Zend_Mail_Part
+{
+ protected $_contentPos = array();
+ protected $_partPos = array();
+ protected $_fh;
+
+ /**
+ * Public constructor
+ *
+ * This handler supports the following params:
+ * - file filename or open file handler with message content (required)
+ * - startPos start position of message or part in file (default: current position)
+ * - endPos end position of message or part in file (default: end of file)
+ *
+ * @param array $params full message with or without headers
+ * @throws Postman_Zend_Mail_Exception
+ */
+ public function __construct(array $params)
+ {
+ if (empty($params['file'])) {
+ /**
+ * @see Postman_Zend_Mail_Exception
+ */
+ require_once 'Zend/Mail/Exception.php';
+ throw new Postman_Zend_Mail_Exception('no file given in params');
+ }
+
+ if (!is_resource($params['file'])) {
+ $this->_fh = fopen($params['file'], 'r');
+ } else {
+ $this->_fh = $params['file'];
+ }
+ if (!$this->_fh) {
+ /**
+ * @see Postman_Zend_Mail_Exception
+ */
+ require_once 'Zend/Mail/Exception.php';
+ throw new Postman_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;
+ }
+
+ Postman_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 Postman_Zend_Mail_Exception
+ */
+ require_once 'Zend/Mail/Exception.php';
+ throw new Postman_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 Postman_Zend_Mail_Exception
+ */
+ require_once 'Zend/Mail/Exception.php';
+ throw new Postman_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 Postman_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 Postman_Zend_Mail_Part wanted part
+ * @throws Postman_Zend_Mail_Exception
+ */
+ public function getPart($num)
+ {
+ --$num;
+ if (!isset($this->_partPos[$num])) {
+ /**
+ * @see Postman_Zend_Mail_Exception
+ */
+ require_once 'Zend/Mail/Exception.php';
+ throw new Postman_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/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/Interface.php b/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/Interface.php
new file mode 100644
index 0000000..ac9656f
--- /dev/null
+++ b/Postman/Postman-Mail/Zend-1.12.10/Mail/Part/Interface.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Postman_Zend_Mail
+ * @subpackage Storage
+ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id$
+ */
+
+
+/**
+ * @category Zend
+ * @package Postman_Zend_Mail
+ * @subpackage Storage
+ * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+interface Postman_Zend_Mail_Part_Interface extends RecursiveIterator
+{
+ /**
+ * Check if part is a multipart message
+ *
+ * @return bool if part is multipart
+ */
+ public function isMultipart();
+
+
+ /**
+ * Body of part
+ *
+ * If part is multipart the raw content of this part with all sub parts is returned
+ *
+ * @return string body
+ * @throws Postman_Zend_Mail_Exception
+ */
+ public function getContent();
+
+ /**
+ * Return size of part
+ *
+ * @return int size
+ */
+ public function getSize();
+
+ /**
+ * Get part of multipart message
+ *
+ * @param int $num number of part starting with 1 for first part
+ * @return Postman_Zend_Mail_Part wanted part
+ * @throws Postman_Zend_Mail_Exception
+ */
+ public function getPart($num);
+
+ /**
+ * Count parts of a multipart part
+ *
+ * @return int number of sub-parts
+ */
+ public function countParts();
+
+
+ /**
+ * Get all headers
+ *
+ * The returned headers are as saved internally. All names are lowercased. The value is a string or an array
+ * if a header with the same name occurs more than once.
+ *
+ * @return array headers as array(name => 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 Postman_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 Postman_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 Postman_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 Postman_Zend_Exception, Postman_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 Postman_Zend_Mail_Part::getHeader($name, 'string')
+ *
+ * @see Postman_Zend_Mail_Part::getHeader()
+ *
+ * @param string $name header name
+ * @return string value of header
+ * @throws Postman_Zend_Mail_Exception
+ */
+ public function __get($name);
+
+ /**
+ * magic method to get content of part
+ *
+ * @return string content
+ */
+ public function __toString();
+}