commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / ezc / Mail / src / parts / multiparts / multipart_related.php
1 <?php
2 /**
3 * File containing the ezcMailMultipartRelated class
4 *
5 * @package Mail
6 * @version 1.7beta1
7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
9 */
10
11 /**
12 * ezcMailMultipartRelated is intended for mail parts consisting of
13 * several inter-related body parts.
14 *
15 * A typical example is an HTML mail with embedded images.
16 * When you want to refer to a related part you can use content id's
17 * (cid). Set the 'Content-ID' header of the related part to a valid
18 * unique url-addr-spec (specified by RFC 822) and refer to it through
19 * the form cid:unique-string.
20 *
21 * Example:
22 * This example shows how you can use ezcMailMultipartRelated to create an
23 * HTML mail with an inline image.
24 * <code>
25 * $mail = new ezcMail();
26 * $mail->from = new ezcMailAddress( 'sender@example.com', 'Adrian Ripburger' );
27 * $mail->addTo( new ezcMailAddress( 'receiver@example.com', 'Maureen Corley' ) );
28 * $mail->subject = "Example of an HTML email with attachments";
29 * $htmlText = new ezcMailText( "<html>Image <img src='cid:image@12345' /></html>" );
30 * $htmlText->subType = 'html';
31 * $image = new ezcMailFile( "path_to_my_image.jpg" );
32 * $image->contentId = 'image@12345';
33 * $mail->body = new ezcMailMultipartRelated( $htmlText, $image );
34 * </code>
35 *
36 * @package Mail
37 * @version 1.7beta1
38 */
39 class ezcMailMultipartRelated extends ezcMailMultipart
40 {
41 /**
42 * Constructs a new ezcMailMultipartRelated.
43 *
44 * The constructor accepts an arbitrary number of ezcMailParts or arrays with ezcMailparts.
45 * Parts are added in the order provided and the first part will be recognized
46 * as the main body. Parameters of the wrong type are ignored.
47 *
48 * @param ezcMailPart|array(ezcMailPart) $...
49 */
50 public function __construct()
51 {
52 $args = func_get_args();
53 parent::__construct( $args );
54 }
55
56 /**
57 * Sets the main part $part of this alternative multipart.
58 *
59 * @param ezcMailPart $part
60 */
61 public function setMainPart( ezcMailPart $part )
62 {
63 $this->parts[0] = $part;
64 }
65
66 /**
67 * Adds $part to the list of parts and returns the Content-ID of the part.
68 *
69 * @param ezcMailPart $part
70 * @return string
71 */
72 public function addRelatedPart( ezcMailPart $part )
73 {
74 // it doesn't have a Content-ID, we must set one.
75 $contentId = '';
76 if ( $part->getHeader( 'Content-ID' ) == '' )
77 {
78 if ( $part instanceof ezcMailFile )
79 {
80 $part->contentId = ezcMailTools::generateContentId( basename( $part->fileName ) );
81 }
82 else
83 {
84 $part->setHeader( 'Content-ID', ezcMailTools::generateContentId( 'part' ) );
85 }
86 }
87 $contentId = trim( $part->getHeader( 'Content-ID' ), '<>' );
88
89 // Set the content ID property of the ezcMailFile if one was found
90 if ( $part instanceof ezcMailFile )
91 {
92 $part->contentId = $contentId;
93 }
94
95 if ( count( $this->parts ) > 0 )
96 {
97 $this->parts[] = $part;
98 }
99 else
100 {
101 $this->parts[1] = $part;
102 }
103 return $contentId;
104 }
105
106 /**
107 * Returns the main part of this multipart or null if there is no such part.
108 *
109 * @return array(ezcMailPart)
110 */
111 public function getMainPart()
112 {
113 if ( isset( $this->parts[0] ) )
114 {
115 return $this->parts[0];
116 }
117 return null;
118 }
119
120 /**
121 * Returns the mail parts associated with this multipart.
122 *
123 * @return array(ezcMailPart)
124 */
125 public function getRelatedParts()
126 {
127 if ( is_null( $this->getMainPart() ) )
128 {
129 return array_slice( $this->parts, 0 );
130 }
131 return array_slice( $this->parts, 1 );
132 }
133
134 /**
135 * Returns the part associated with the passed Content-ID.
136 *
137 * @param string $cid
138 * @return ezcMailPart
139 */
140 public function getRelatedPartByID( $cid )
141 {
142 $parts = $this->getRelatedParts();
143 foreach ( $parts as $part )
144 {
145 if ( ( $part->getHeader( 'Content-ID' ) !== '' ) &&
146 ( $part->getHeader( 'Content-ID' ) == "<$cid>" ) )
147 {
148 return $part;
149 }
150 }
151 return false;
152 }
153
154 /**
155 * Returns "related".
156 *
157 * @return string
158 */
159 public function multipartType()
160 {
161 return "related";
162 }
163
164 /**
165 * Substitutes links in all ezcMailText parts with the subType HTML in this multipart/alternative.
166 *
167 * This method will perform substitution of CID's and absolute and relative links as specified by
168 * RFC 2557 for links that resolve to files. Links to other message parts must be resolved when
169 * displaying the message.
170 *
171 * - provide methods for substitution of these as well (inclusive listing of which they are)
172 * @todo Move to separate class.
173 */
174 private function resolveHtmlLinks()
175 {
176 // 1. Check that the main part is a html part
177 // 2. Go through the related parts and build up a structure of available
178 // CIDS and locations
179 // 3. Substitute in this message.
180 }
181 }
182 ?>