Handle htmlspecialchars() differences between PHP < 5.4 vs >= 5.4
[awl.git] / inc / Multipart.php
blobedd5e8c4436cfe47c6738bfd2061cffeceed8015
1 <?php
3 require_once('AWLUtilities.php');
5 class SinglePart {
6 private $content;
7 private $type;
8 private $otherHeaders;
9 private $disposition;
10 private $id;
12 public static $crlf = "\r\n";
14 function __construct( $content, $type='text/plain', $otherHeaders=array() ) {
15 $this->content = $content;
16 $this->type = $type;
17 $this->otherHeaders = $otherHeaders;
20 function render() {
21 $result = 'Content-Type: '.$this->type.self::$crlf;
22 $encoded = false;
23 foreach( $this->otherHeaders AS $header => $value ) {
24 $result .= $header.': '.$value.self::$crlf;
25 if ( $header == 'Content-Transfer-Encoding' ) $encoded = true;
28 if ( $encoded )
29 return $result . self::$crlf . $content;
31 return $result . 'Content-Transfer-Encoding: base64' . self::$crlf
32 . self::$crlf
33 . base64_encode($content);
38 class Multipart {
40 private $parts; // Always good for a giggle :-)
41 private $boundary;
43 function __construct() {
44 $this->parts = array();
45 $this->boundary = uuid();
48 function addPart() {
49 $args = func_get_args();
50 if ( is_string($args[0]) ) {
51 $newPart = new SinglePart( $args[0], (isset($args[1])?$args[1]:'text/plain'), (isset($args[2])?$args[2]:array()));
53 else
54 $newPart = $args[0];
56 $this->parts[] = $newPart;
58 return $newPart;
62 function getMimeHeaders() {
63 return 'MIME-Version: 1.0' . SinglePart::$crlf
64 .'Content-Type: multipart/mixed; boundary='.$this->boundary . SinglePart::$crlf ;
67 function getMimeParts() {
68 $result = '--' . $this->boundary . SinglePart::$crlf;
69 foreach( $this->parts AS $part ) {
70 $result .= $part->render() . SinglePart::$crlf . '--' . $this->boundary;
72 $result .= '--' . SinglePart::$crlf;
73 return $result;