88use greeny \MailLibrary \Attachment ;
99use greeny \MailLibrary \Drivers \ImapDriver ;
1010use greeny \MailLibrary \Mailbox ;
11+ use greeny \MailLibrary \MimePart ;
1112
1213class ImapStructure implements IStructure {
1314 const TYPE_TEXT = 0 ;
@@ -37,6 +38,8 @@ class ImapStructure implements IStructure {
3738 self ::TYPE_OTHER => 'other ' ,
3839 );
3940
41+ private $ messageParts = [];
42+
4043 /** @var \greeny\MailLibrary\Drivers\ImapDriver */
4144 protected $ driver ;
4245
@@ -64,6 +67,9 @@ class ImapStructure implements IStructure {
6467 /** @var Mailbox */
6568 protected $ mailbox ;
6669
70+ /** @var array */
71+ private $ rawStructure = [];
72+
6773 /**
6874 * @param ImapDriver $driver
6975 * @param object $structure
@@ -72,6 +78,7 @@ class ImapStructure implements IStructure {
7278 */
7379 public function __construct (ImapDriver $ driver , $ structure , $ mailId , Mailbox $ mailbox )
7480 {
81+ $ this ->rawStructure = $ structure ;
7582 $ this ->driver = $ driver ;
7683 $ this ->id = $ mailId ;
7784 $ this ->mailbox = $ mailbox ;
@@ -84,6 +91,15 @@ public function __construct(ImapDriver $driver, $structure, $mailId, Mailbox $ma
8491 }
8592 }
8693
94+ /**
95+ * @return array
96+ * @internal use only with caution, format can change without warning
97+ */
98+ public function getRawStructure ()
99+ {
100+ return $ this ->rawStructure ;
101+ }
102+
87103 /**
88104 * @return string
89105 */
@@ -100,9 +116,9 @@ public function getHtmlBody()
100116 if ($ this ->htmlBody === NULL ) {
101117 $ this ->driver ->switchMailbox ($ this ->mailbox ->getName ());
102118 return $ this ->htmlBody = $ this ->driver ->getBody ($ this ->id , $ this ->htmlBodyIds );
103- } else {
104- return $ this ->htmlBody ;
105119 }
120+
121+ return $ this ->htmlBody ;
106122 }
107123
108124 /**
@@ -113,9 +129,9 @@ public function getTextBody()
113129 if ($ this ->textBody === NULL ) {
114130 $ this ->driver ->switchMailbox ($ this ->mailbox ->getName ());
115131 return $ this ->textBody = $ this ->driver ->getBody ($ this ->id , $ this ->textBodyIds );
116- } else {
117- return $ this ->textBody ;
118132 }
133+
134+ return $ this ->textBody ;
119135 }
120136
121137 /**
@@ -133,6 +149,21 @@ public function getAttachments()
133149 return $ this ->attachments ;
134150 }
135151
152+ /**
153+ * @return MimePart[]
154+ */
155+ public function getMimeParts ()
156+ {
157+ $ this ->driver ->switchMailbox ($ this ->mailbox ->getName ());
158+ return $ this ->messageParts ;
159+ }
160+
161+ /** @deprecated use getMimeParts() instead */
162+ public function getParts () {
163+ \trigger_error (\E_USER_DEPRECATED , 'use getMimeParts() instead ' );
164+ return $ this ->getMimeParts ();
165+ }
166+
136167 protected function addStructurePart ($ structure , $ partId )
137168 {
138169 $ type = $ structure ->type ;
@@ -151,13 +182,27 @@ protected function addStructurePart($structure, $partId)
151182 }
152183 }
153184
185+ /** @noinspection NestedTernaryOperatorInspection Yep, will fix this when we switch to PHP7 level; see ?? operator */
186+ $ this ->messageParts [] = new MimePart (
187+ $ this ->driver ,
188+ $ this ->id ,
189+ $ partId ,
190+ self ::$ typeTable [$ type ]. '/ ' . $ subtype ,
191+ (empty ($ parameters ['filename ' ]) ? $ parameters ['filename ' ] : (
192+ empty ($ parameters ['name ' ]) ? $ parameters ['name ' ] : ''
193+ )),
194+ $ encoding
195+ );
196+
197+
154198 if (isset ($ parameters ['filename ' ]) || isset ($ parameters ['name ' ])) {
155199 $ this ->attachmentsIds [] = array (
156200 'id ' => $ partId ,
157201 'encoding ' => $ encoding ,
158202 'name ' => isset ($ parameters ['filename ' ]) ? $ parameters ['filename ' ] : $ parameters ['name ' ],
159203 'type ' => self ::$ typeTable [$ type ]. '/ ' . $ subtype ,
160204 );
205+
161206 } else if ($ type === self ::TYPE_TEXT ) {
162207 if ($ subtype === 'HTML ' ) {
163208 $ this ->htmlBodyIds [] = array ('id ' => $ partId , 'encoding ' => $ encoding );
0 commit comments