• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Mime/Part.php

00001 <?php
00025 require_once 'Zend/Mime.php';
00026 
00035 class Zend_Mime_Part {
00036 
00037     public $type = Zend_Mime::TYPE_OCTETSTREAM;
00038     public $encoding = Zend_Mime::ENCODING_8BIT;
00039     public $id;
00040     public $disposition;
00041     public $filename;
00042     public $description;
00043     public $charset;
00044     public $boundary;
00045     public $location;
00046     public $language;
00047     protected $_content;
00048     protected $_isStream = false;
00049 
00050 
00058     public function __construct($content)
00059     {
00060         $this->_content = $content;
00061         if (is_resource($content)) {
00062             $this->_isStream = true;
00063         }
00064     }
00065 
00080     public function isStream()
00081     {
00082       return $this->_isStream;
00083     }
00084 
00092     public function getEncodedStream()
00093     {
00094         if (!$this->_isStream) {
00095             require_once 'Zend/Mime/Exception.php';
00096             throw new Zend_Mime_Exception('Attempt to get a stream from a string part');
00097         }
00098 
00099         //stream_filter_remove(); // ??? is that right?
00100         switch ($this->encoding) {
00101             case Zend_Mime::ENCODING_QUOTEDPRINTABLE:
00102                 $filter = stream_filter_append(
00103                     $this->_content,
00104                     'convert.quoted-printable-encode',
00105                     STREAM_FILTER_READ,
00106                     array(
00107                         'line-length'      => 76,
00108                         'line-break-chars' => Zend_Mime::LINEEND
00109                     )
00110                 );
00111                 if (!is_resource($filter)) {
00112                     require_once 'Zend/Mime/Exception.php';
00113                     throw new Zend_Mime_Exception('Failed to append quoted-printable filter');
00114                 }
00115                 break;
00116             case Zend_Mime::ENCODING_BASE64:
00117                 $filter = stream_filter_append(
00118                     $this->_content,
00119                     'convert.base64-encode',
00120                     STREAM_FILTER_READ,
00121                     array(
00122                         'line-length'      => 76,
00123                         'line-break-chars' => Zend_Mime::LINEEND
00124                     )
00125                 );
00126                 if (!is_resource($filter)) {
00127                     require_once 'Zend/Mime/Exception.php';
00128                     throw new Zend_Mime_Exception('Failed to append base64 filter');
00129                 }
00130                 break;
00131             default:
00132         }
00133         return $this->_content;
00134     }
00135 
00141     public function getContent($EOL = Zend_Mime::LINEEND)
00142     {
00143         if ($this->_isStream) {
00144             return stream_get_contents($this->getEncodedStream());
00145         } else {
00146             return Zend_Mime::encode($this->_content, $this->encoding, $EOL);
00147         }
00148     }
00149 
00156     public function getHeadersArray($EOL = Zend_Mime::LINEEND)
00157     {
00158         $headers = array();
00159 
00160         $contentType = $this->type;
00161         if ($this->charset) {
00162             $contentType .= '; charset=' . $this->charset;
00163         }
00164 
00165         if ($this->boundary) {
00166             $contentType .= ';' . $EOL
00167                           . " boundary=\"" . $this->boundary . '"';
00168         }
00169 
00170         $headers[] = array('Content-Type', $contentType);
00171 
00172         if ($this->encoding) {
00173             $headers[] = array('Content-Transfer-Encoding', $this->encoding);
00174         }
00175 
00176         if ($this->id) {
00177             $headers[]  = array('Content-ID', '<' . $this->id . '>');
00178         }
00179 
00180         if ($this->disposition) {
00181             $disposition = $this->disposition;
00182             if ($this->filename) {
00183                 $disposition .= '; filename="' . $this->filename . '"';
00184             }
00185             $headers[] = array('Content-Disposition', $disposition);
00186         }
00187 
00188         if ($this->description) {
00189             $headers[] = array('Content-Description', $this->description);
00190         }
00191 
00192         if ($this->location) {
00193             $headers[] = array('Content-Location', $this->location);
00194         }
00195 
00196         if ($this->language){
00197             $headers[] = array('Content-Language', $this->language);
00198         }
00199 
00200         return $headers;
00201     }
00202 
00208     public function getHeaders($EOL = Zend_Mime::LINEEND)
00209     {
00210         $res = '';
00211         foreach ($this->getHeadersArray($EOL) as $header) {
00212             $res .= $header[0] . ': ' . $header[1] . $EOL;
00213         }
00214 
00215         return $res;
00216     }
00217 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2