Public Member Functions | |
__construct ($body= '', $params=array()) | |
Constructor. | |
encode () | |
Encodes and returns the email. | |
addSubPart ($body, $params) | |
Adds a subpart to current mime part and returns a reference to it. | |
Private Member Functions | |
getEncodedData ($data, $encoding) | |
Returns encoded data based upon encoding passed to it. | |
quotedPrintableEncode ($input, $line_max=76) | |
Encodes data to quoted-printable standard. | |
Private Attributes | |
$encoding | |
$subparts | |
$encoded | |
$headers | |
$body |
Definition at line 74 of file mimePart.php.
Mail_MIMEPart::__construct | ( | $ | body = '' , |
|
$ | params = array() | |||
) |
Constructor.
Sets up the object.
$body | - The body of the mime part if any. | |
$params | - An associative array of parameters: content_type - The content type for this part eg multipart/mixed encoding - The encoding to use, 7bit, 8bit, base64, or quoted-printable cid - Content ID to apply disposition - Content disposition, inline or attachment dfilename - Optional filename parameter for content disposition description - Content description charset - Character set to use public |
Definition at line 122 of file mimePart.php.
References $body, and $headers.
00123 { 00124 if (!defined('MAIL_MIMEPART_CRLF')) { 00125 define('MAIL_MIMEPART_CRLF', defined('MAIL_MIME_CRLF') ? MAIL_MIME_CRLF : "\r\n", true); 00126 } 00127 00128 foreach ($params as $key => $value) { 00129 switch ($key) { 00130 case 'content_type': 00131 $headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : ''); 00132 break; 00133 00134 case 'encoding': 00135 $this->encoding = $value; 00136 $headers['Content-Transfer-Encoding'] = $value; 00137 break; 00138 00139 case 'cid': 00140 $headers['Content-ID'] = '<' . $value . '>'; 00141 break; 00142 00143 case 'disposition': 00144 $headers['Content-Disposition'] = $value . (isset($dfilename) ? '; filename="' . $dfilename . '"' : ''); 00145 break; 00146 00147 case 'dfilename': 00148 if (isset($headers['Content-Disposition'])) { 00149 $headers['Content-Disposition'] .= '; filename="' . $value . '"'; 00150 } else { 00151 $dfilename = $value; 00152 } 00153 break; 00154 00155 case 'description': 00156 $headers['Content-Description'] = $value; 00157 break; 00158 00159 case 'charset': 00160 if (isset($headers['Content-Type'])) { 00161 $headers['Content-Type'] .= '; charset="' . $value . '"'; 00162 } else { 00163 $charset = $value; 00164 } 00165 break; 00166 } 00167 } 00168 00169 // Default content-type 00170 if (!isset($headers['Content-Type'])) { 00171 $headers['Content-Type'] = 'text/plain'; 00172 } 00173 00174 // Default encoding 00175 if (!isset($this->encoding)) { 00176 $this->encoding = '7bit'; 00177 } 00178 00179 // Assign stuff to member variables 00180 $this->encoded = array(); 00181 $this->headers = $headers; 00182 $this->body = $body; 00183 }
Mail_MIMEPart::addSubPart | ( | $ | body, | |
$ | params | |||
) |
Adds a subpart to current mime part and returns a reference to it.
$body | The body of the subpart, if any. | |
$params | The parameters for the subpart, same as the $params argument for constructor. |
Definition at line 234 of file mimePart.php.
References $body.
00235 { 00236 $this->subparts[] = new Mail_MIMEPart($body, $params); 00237 00238 return $this->subparts[count($this->subparts) - 1]; 00239 }
Mail_MIMEPart::encode | ( | ) |
Encodes and returns the email.
Also stores it in the encoded member variable
Definition at line 193 of file mimePart.php.
References $encoded, $headers, $subparts, and getEncodedData().
00194 { 00195 $encoded =& $this->encoded; 00196 00197 if (!empty($this->subparts)) { 00198 srand((double)microtime()*1000000); 00199 $boundary = '=_' . md5(uniqid(rand()) . microtime()); 00200 $this->headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"'; 00201 00202 // Add body parts to $subparts 00203 for ($i = 0; $i < count($this->subparts); $i++) { 00204 $headers = array(); 00205 $tmp = $this->subparts[$i]->encode(); 00206 foreach ($tmp['headers'] as $key => $value) { 00207 $headers[] = $key . ': ' . $value; 00208 } 00209 $subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body']; 00210 } 00211 00212 $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF . 00213 implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) . 00214 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF; 00215 } else { 00216 $encoded['body'] = $this->getEncodedData($this->body, $this->encoding) . MAIL_MIMEPART_CRLF; 00217 } 00218 00219 // Add headers to $encoded 00220 $encoded['headers'] =& $this->headers; 00221 00222 return $encoded; 00223 }
Mail_MIMEPart::getEncodedData | ( | $ | data, | |
$ | encoding | |||
) | [private] |
Returns encoded data based upon encoding passed to it.
$data | The data to encode. | |
$encoding | The encoding type to use, 7bit, base64, or quoted-printable. |
Definition at line 248 of file mimePart.php.
References $encoding, and quotedPrintableEncode().
Referenced by encode().
00249 { 00250 switch ($encoding) { 00251 case '8bit': 00252 case '7bit': 00253 return $data; 00254 break; 00255 00256 case 'quoted-printable': 00257 return $this->quotedPrintableEncode($data); 00258 break; 00259 00260 case 'base64': 00261 return rtrim(chunk_split(base64_encode($data), 76, MAIL_MIMEPART_CRLF)); 00262 break; 00263 00264 default: 00265 return $data; 00266 } 00267 }
Mail_MIMEPart::quotedPrintableEncode | ( | $ | input, | |
$ | line_max = 76 | |||
) | [private] |
Encodes data to quoted-printable standard.
$input | The data to encode | |
$line_max | Optional max line length. Should not be more than 76 chars |
Definition at line 276 of file mimePart.php.
Referenced by getEncodedData().
00277 { 00278 $lines = preg_split("/\r?\n/", $input); 00279 $eol = MAIL_MIMEPART_CRLF; 00280 $escape = '='; 00281 $output = ''; 00282 00283 while(list(, $line) = each($lines)){ 00284 00285 $linlen = strlen($line); 00286 $newline = ''; 00287 00288 for ($i = 0; $i < $linlen; $i++) { 00289 $char = substr($line, $i, 1); 00290 $dec = ord($char); 00291 00292 if (($dec == 32) AND ($i == ($linlen - 1))){ // convert space at eol only 00293 $char = '=20'; 00294 00295 } elseif($dec == 9) { 00296 ; // Do nothing if a tab. 00297 } elseif(($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) { 00298 $char = $escape . strtoupper(sprintf('%02s', dechex($dec))); 00299 } 00300 00301 if ((strlen($newline) + strlen($char)) >= $line_max) { // MAIL_MIMEPART_CRLF is not counted 00302 $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay 00303 $newline = ''; 00304 } 00305 $newline .= $char; 00306 } // end of for 00307 $output .= $newline . $eol; 00308 } 00309 $output = substr($output, 0, -1 * strlen($eol)); // Don't want last crlf 00310 return $output; 00311 }
Mail_MIMEPart::$body [private] |
Mail_MIMEPart::$encoded [private] |
Mail_MIMEPart::$encoding [private] |
Mail_MIMEPart::$headers [private] |
Mail_MIMEPart::$subparts [private] |