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,14 @@ public function __construct(ImapDriver $driver, $structure, $mailId, Mailbox $ma
8491 }
8592 }
8693
94+ /**
95+ * @return array
96+ */
97+ public function getRawStructure ()
98+ {
99+ return $ this ->rawStructure ;
100+ }
101+
87102 /**
88103 * @return string
89104 */
@@ -133,6 +148,13 @@ public function getAttachments()
133148 return $ this ->attachments ;
134149 }
135150
151+ /** @return MimePart[] */
152+ public function getParts (): array
153+ {
154+ $ this ->driver ->switchMailbox ($ this ->mailbox ->getName ());
155+ return $ this ->messageParts ;
156+ }
157+
136158 protected function addStructurePart ($ structure , $ partId )
137159 {
138160 $ type = $ structure ->type ;
@@ -151,13 +173,24 @@ protected function addStructurePart($structure, $partId)
151173 }
152174 }
153175
176+ $ this ->messageParts [] = new MimePart (
177+ $ this ->driver ,
178+ $ this ->id ,
179+ $ partId ,
180+ self ::$ typeTable [$ type ]. '/ ' . $ subtype ,
181+ $ parameters ['filename ' ] ?? $ parameters ['name ' ] ?? '' ,
182+ $ encoding
183+ );
184+
185+
154186 if (isset ($ parameters ['filename ' ]) || isset ($ parameters ['name ' ])) {
155187 $ this ->attachmentsIds [] = array (
156188 'id ' => $ partId ,
157189 'encoding ' => $ encoding ,
158190 'name ' => isset ($ parameters ['filename ' ]) ? $ parameters ['filename ' ] : $ parameters ['name ' ],
159191 'type ' => self ::$ typeTable [$ type ]. '/ ' . $ subtype ,
160192 );
193+
161194 } else if ($ type === self ::TYPE_TEXT ) {
162195 if ($ subtype === 'HTML ' ) {
163196 $ this ->htmlBodyIds [] = array ('id ' => $ partId , 'encoding ' => $ encoding );
0 commit comments