77
88namespace Sazanof \PhpImapSockets \Models ;
99
10+ use ReflectionException ;
1011use Sazanof \PhpImapSockets \Collections \BodyStructureCollection ;
1112use Sazanof \PhpImapSockets \Collections \Collection ;
1213use Sazanof \PhpImapSockets \Collections \MailboxCollection ;
1314use Sazanof \PhpImapSockets \Commands \ExamineCommand ;
1415use Sazanof \PhpImapSockets \Commands \FetchCommand ;
1516use Sazanof \PhpImapSockets \Commands \SearchCommand ;
1617use Sazanof \PhpImapSockets \Connection ;
18+ use Sazanof \PhpImapSockets \Exceptions \MailboxOperationException ;
19+ use Sazanof \PhpImapSockets \Exceptions \NoResultsException ;
1720use Sazanof \PhpImapSockets \Query \FetchQuery ;
1821use Sazanof \PhpImapSockets \Query \SearchQuery ;
1922use Sazanof \PhpImapSockets \Response \ExamineResponse ;
@@ -106,9 +109,7 @@ public function parseLine(string $line)
106109
107110 public function examine ()
108111 {
109- $ response = new ExamineResponse (
110- $ this ->getConnection ()->command (ExamineCommand::class, [$ this ->getOriginalPath ()])
111- );
112+ $ response = $ this ->getConnection ()->examine ($ this ->getOriginalPath ());
112113 $ this ->uidvalidity = $ response ->uidvalidiry ;
113114 $ this ->uidnext = $ response ->uidnext ;
114115 $ this ->unseen = $ response ->unseen ;
@@ -124,24 +125,82 @@ public function select()
124125 return $ this ;
125126 }
126127
127- public function search (SearchQuery $ query )
128+ /**
129+ * @param string $folder
130+ * @param bool $insideCurrent
131+ * @return bool
132+ * @throws MailboxOperationException
133+ * @throws ReflectionException
134+ */
135+ public function create (string $ folder , bool $ insideCurrent = false ): bool
136+ {
137+ $ name = $ insideCurrent ? $ this ->getPath () . $ this ->getDelimiter () . $ folder : $ folder ;
138+ return $ this ->getConnection ()->createMailbox ($ name );
139+ }
140+
141+ /**
142+ * @param string $folder
143+ * @param bool $insideCurrent
144+ * @return bool
145+ * @throws ReflectionException
146+ * @throws MailboxOperationException
147+ */
148+ public function delete (string $ folder , bool $ insideCurrent = false ): bool
149+ {
150+ $ name = $ insideCurrent ? $ this ->getPath () . $ this ->getDelimiter () . $ folder : $ folder ;
151+ return $ this ->getConnection ()->deleteMailbox ($ name );
152+ }
153+
154+ /**
155+ * @param string $currentName
156+ * @param string $newName
157+ * @return bool
158+ * @throws MailboxOperationException
159+ * @throws ReflectionException
160+ */
161+ public function rename (string $ currentName , string $ newName ): bool
162+ {
163+ return $ this ->getConnection ()->renameMailbox ($ currentName , $ newName );
164+ }
165+
166+ /**
167+ * @param SearchQuery $query
168+ * @return SearchResponse
169+ * @throws ReflectionException
170+ * @throws NoResultsException
171+ */
172+ public function search (SearchQuery $ query ): SearchResponse
128173 {
129174 return new SearchResponse (
130175 $ this ->connection ->command (SearchCommand::class, [$ query ])
131176 );
132177 }
133178
134- public function fetch (array $ nums , FetchQuery $ query )
179+ /**
180+ * @param array $nums
181+ * @param FetchQuery $query
182+ * @return Response
183+ * @throws ReflectionException
184+ */
185+ public function fetch (array $ nums , FetchQuery $ query ): Response
135186 {
136187 return $ this ->connection ->command (FetchCommand::class, [$ nums , $ query ]);
137188 }
138189
190+ /**
191+ * @param array $nums
192+ * @return BodyStructureCollection
193+ * @throws ReflectionException
194+ */
139195 public function getBodyStructure (array $ nums ): BodyStructureCollection
140196 {
141197 $ query = new FetchQuery ();
142198 return $ this ->connection ->command (FetchCommand::class, [$ nums , $ query ->bodystructure ()])->asCollection (BodyStructureCollection::class);
143199 }
144200
201+ /**
202+ * @return bool
203+ */
145204 public function hasChildren ()
146205 {
147206 return !empty (array_intersect (self ::SPECIAL_ATTRIBUTES ['haschildren ' ], $ this ->attributes ->toArray ()));
0 commit comments