lib/3rdParty/composer/webklex/php-imap/src/Connection/Protocols/ProtocolInterface.php
raw symbols SCIP| 1 | <?php |
| 2 | /* |
| 3 | * File: ImapProtocol.php |
| 4 | * Category: Protocol |
| 5 | * Author: M.Goldenbaum |
| 6 | * Created: 16.09.20 18:27 |
| 7 | * Updated: - |
| 8 | * |
| 9 | * Description: |
| 10 | * - |
| 11 | */ |
| 12 | |
| 13 | namespace Webklex\PHPIMAP\Connection\Protocols; |
| 14 | |
| 15 | use ErrorException; |
| 16 | use Webklex\PHPIMAP\Exceptions\AuthFailedException; |
| 17 | use Webklex\PHPIMAP\Exceptions\ConnectionFailedException; |
| 18 | use Webklex\PHPIMAP\Exceptions\ImapBadRequestException; |
| 19 | use Webklex\PHPIMAP\Exceptions\ImapServerErrorException; |
| 20 | use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException; |
| 21 | use Webklex\PHPIMAP\Exceptions\MessageNotFoundException; |
| 22 | use Webklex\PHPIMAP\Exceptions\RuntimeException; |
| 23 | use Webklex\PHPIMAP\IMAP; |
| 24 | |
| 25 | /** |
| 26 | * Interface ProtocolInterface |
| 27 | * |
| 28 | * @package Webklex\PHPIMAP\Connection\Protocols |
| 29 | */ |
| 30 | interface ProtocolInterface { |
| 31 | |
| 32 | /** |
| 33 | * Public destructor |
| 34 | * |
| 35 | * @throws ImapBadRequestException |
| 36 | * @throws ImapServerErrorException |
| 37 | * @throws RuntimeException |
| 38 | */ |
| 39 | public function __destruct(); |
| 40 | |
| 41 | /** |
| 42 | * Open a new connection / session |
| 43 | * @param string $host hostname or IP address of IMAP server |
| 44 | * @param int|null $port of service server |
| 45 | * |
| 46 | * @throws ErrorException |
| 47 | * @throws ConnectionFailedException |
| 48 | * @throws RuntimeException |
| 49 | */ |
| 50 | public function connect(string $host, ?int $port = null); |
| 51 | |
| 52 | /** |
| 53 | * Login to a new session. |
| 54 | * |
| 55 | * @param string $user username |
| 56 | * @param string $password password |
| 57 | * |
| 58 | * @return Response |
| 59 | * |
| 60 | * @throws AuthFailedException |
| 61 | * @throws ImapBadRequestException |
| 62 | * @throws ImapServerErrorException |
| 63 | */ |
| 64 | public function login(string $user, string $password): Response; |
| 65 | |
| 66 | /** |
| 67 | * Authenticate your current session. |
| 68 | * @param string $user username |
| 69 | * @param string $token access token |
| 70 | * |
| 71 | * @return Response |
| 72 | * @throws AuthFailedException |
| 73 | */ |
| 74 | public function authenticate(string $user, string $token): Response; |
| 75 | |
| 76 | /** |
| 77 | * Logout of the current server session |
| 78 | * |
| 79 | * @return Response |
| 80 | * |
| 81 | * @throws ImapBadRequestException |
| 82 | * @throws ImapServerErrorException |
| 83 | * @throws RuntimeException |
| 84 | */ |
| 85 | public function logout(): Response; |
| 86 | |
| 87 | /** |
| 88 | * Check if the current session is connected |
| 89 | * |
| 90 | * @return bool |
| 91 | */ |
| 92 | public function connected(): bool; |
| 93 | |
| 94 | /** |
| 95 | * Get an array of available capabilities |
| 96 | * |
| 97 | * @return Response containing a list of capabilities |
| 98 | * @throws RuntimeException |
| 99 | */ |
| 100 | public function getCapabilities(): Response; |
| 101 | |
| 102 | /** |
| 103 | * Change the current folder |
| 104 | * @param string $folder change to this folder |
| 105 | * |
| 106 | * @return Response see examineOrSelect() |
| 107 | * @throws RuntimeException |
| 108 | */ |
| 109 | public function selectFolder(string $folder = 'INBOX'): Response; |
| 110 | |
| 111 | /** |
| 112 | * Examine a given folder |
| 113 | * @param string $folder |
| 114 | * |
| 115 | * @return Response |
| 116 | * @throws RuntimeException |
| 117 | */ |
| 118 | public function examineFolder(string $folder = 'INBOX'): Response; |
| 119 | |
| 120 | /** |
| 121 | * Get the status of a given folder |
| 122 | * |
| 123 | * @return Response list of STATUS items |
| 124 | * |
| 125 | * @throws ImapBadRequestException |
| 126 | * @throws ImapServerErrorException |
| 127 | * @throws RuntimeException |
| 128 | */ |
| 129 | public function folderStatus(string $folder = 'INBOX', $arguments = ['MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY']): Response; |
| 130 | |
| 131 | /** |
| 132 | * Fetch message contents |
| 133 | * @param int|array $uids |
| 134 | * @param string $rfc |
| 135 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 136 | * message numbers instead. |
| 137 | * |
| 138 | * @return Response |
| 139 | * @throws RuntimeException |
| 140 | */ |
| 141 | public function content(int|array $uids, string $rfc = "RFC822", int|string $uid = IMAP::ST_UID): Response; |
| 142 | |
| 143 | /** |
| 144 | * Fetch message headers |
| 145 | * @param int|array $uids |
| 146 | * @param string $rfc |
| 147 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 148 | * message numbers instead. |
| 149 | * |
| 150 | * @return Response |
| 151 | * @throws RuntimeException |
| 152 | */ |
| 153 | public function headers(int|array $uids, string $rfc = "RFC822", int|string $uid = IMAP::ST_UID): Response; |
| 154 | |
| 155 | /** |
| 156 | * Fetch message flags |
| 157 | * @param int|array $uids |
| 158 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 159 | * message numbers instead. |
| 160 | * |
| 161 | * @return Response |
| 162 | * @throws RuntimeException |
| 163 | */ |
| 164 | public function flags(int|array $uids, int|string $uid = IMAP::ST_UID): Response; |
| 165 | |
| 166 | /** |
| 167 | * Fetch message sizes |
| 168 | * @param int|array $uids |
| 169 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 170 | * message numbers instead. |
| 171 | * |
| 172 | * @return Response |
| 173 | * @throws RuntimeException |
| 174 | */ |
| 175 | public function sizes(int|array $uids, int|string $uid = IMAP::ST_UID): Response; |
| 176 | |
| 177 | /** |
| 178 | * Get uid for a given id |
| 179 | * @param int|null $id message number |
| 180 | * |
| 181 | * @return Response containing a message number for given message or all messages as array |
| 182 | * @throws MessageNotFoundException |
| 183 | */ |
| 184 | public function getUid(?int $id = null): Response; |
| 185 | |
| 186 | /** |
| 187 | * Get a message number for a uid |
| 188 | * @param string $id uid |
| 189 | * |
| 190 | * @return Response containing the message number |
| 191 | * @throws MessageNotFoundException |
| 192 | */ |
| 193 | public function getMessageNumber(string $id): Response; |
| 194 | |
| 195 | /** |
| 196 | * Get a list of available folders |
| 197 | * @param string $reference mailbox reference for list |
| 198 | * @param string $folder mailbox / folder name match with wildcards |
| 199 | * |
| 200 | * @return Response containing mailboxes that matched $folder as array(globalName => array('delim' => .., 'flags' => ..)) |
| 201 | * @throws RuntimeException |
| 202 | */ |
| 203 | public function folders(string $reference = '', string $folder = '*'): Response; |
| 204 | |
| 205 | /** |
| 206 | * Set message flags |
| 207 | * @param array|string $flags flags to set, add or remove |
| 208 | * @param int $from message for items or start message if $to !== null |
| 209 | * @param int|null $to if null only one message ($from) is fetched, else it's the |
| 210 | * last message, INF means last message available |
| 211 | * @param string|null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given |
| 212 | * @param bool $silent if false the return values are the new flags for the wanted messages |
| 213 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 214 | * message numbers instead. |
| 215 | * @param string|null $item command used to store a flag |
| 216 | * |
| 217 | * @return Response containing the new flags if $silent is false, else true or false depending on success |
| 218 | * @throws RuntimeException |
| 219 | */ |
| 220 | public function store(array|string $flags, int $from, ?int $to = null, ?string $mode = null, bool $silent = true, int|string $uid = IMAP::ST_UID, ?string $item = null): Response; |
| 221 | |
| 222 | /** |
| 223 | * Append a new message to given folder |
| 224 | * @param string $folder name of target folder |
| 225 | * @param string $message full message content |
| 226 | * @param array|null $flags flags for new message |
| 227 | * @param string|null $date date for new message |
| 228 | * |
| 229 | * @return Response |
| 230 | * @throws RuntimeException |
| 231 | */ |
| 232 | public function appendMessage(string $folder, string $message, ?array $flags = null, ?string $date = null): Response; |
| 233 | |
| 234 | /** |
| 235 | * Copy message set from current folder to other folder |
| 236 | * |
| 237 | * @param string $folder destination folder |
| 238 | * @param $from |
| 239 | * @param int|null $to if null only one message ($from) is fetched, else it's the |
| 240 | * last message, INF means last message available |
| 241 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 242 | * message numbers instead. |
| 243 | * |
| 244 | * @return Response |
| 245 | * @throws RuntimeException |
| 246 | */ |
| 247 | public function copyMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response; |
| 248 | |
| 249 | /** |
| 250 | * Copy multiple messages to the target folder |
| 251 | * @param array<string> $messages List of message identifiers |
| 252 | * @param string $folder Destination folder |
| 253 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 254 | * message numbers instead. |
| 255 | * |
| 256 | * @return Response Tokens if operation successful, false if an error occurred |
| 257 | * @throws RuntimeException |
| 258 | */ |
| 259 | public function copyManyMessages(array $messages, string $folder, int|string $uid = IMAP::ST_UID): Response; |
| 260 | |
| 261 | /** |
| 262 | * Move a message set from current folder to another folder |
| 263 | * @param string $folder destination folder |
| 264 | * @param $from |
| 265 | * @param int|null $to if null only one message ($from) is fetched, else it's the |
| 266 | * last message, INF means last message available |
| 267 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 268 | * message numbers instead. |
| 269 | * |
| 270 | * @return Response |
| 271 | */ |
| 272 | public function moveMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response; |
| 273 | |
| 274 | /** |
| 275 | * Move multiple messages to the target folder |
| 276 | * |
| 277 | * @param array<string> $messages List of message identifiers |
| 278 | * @param string $folder Destination folder |
| 279 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 280 | * message numbers instead. |
| 281 | * |
| 282 | * @return Response Tokens if operation successful, false if an error occurred |
| 283 | * @throws RuntimeException |
| 284 | */ |
| 285 | public function moveManyMessages(array $messages, string $folder, int|string $uid = IMAP::ST_UID): Response; |
| 286 | |
| 287 | /** |
| 288 | * Exchange identification information |
| 289 | * Ref.: https://datatracker.ietf.org/doc/html/rfc2971 |
| 290 | * |
| 291 | * @param null $ids |
| 292 | * @return Response |
| 293 | * |
| 294 | * @throws RuntimeException |
| 295 | */ |
| 296 | public function ID($ids = null): Response; |
| 297 | |
| 298 | /** |
| 299 | * Create a new folder |
| 300 | * |
| 301 | * @param string $folder folder name |
| 302 | * @return Response |
| 303 | * @throws RuntimeException |
| 304 | */ |
| 305 | public function createFolder(string $folder): Response; |
| 306 | |
| 307 | /** |
| 308 | * Rename an existing folder |
| 309 | * |
| 310 | * @param string $old old name |
| 311 | * @param string $new new name |
| 312 | * @return Response |
| 313 | * @throws RuntimeException |
| 314 | */ |
| 315 | public function renameFolder(string $old, string $new): Response; |
| 316 | |
| 317 | /** |
| 318 | * Delete a folder |
| 319 | * |
| 320 | * @param string $folder folder name |
| 321 | * @return Response |
| 322 | * |
| 323 | * @throws ImapBadRequestException |
| 324 | * @throws ImapServerErrorException |
| 325 | * @throws RuntimeException |
| 326 | */ |
| 327 | public function deleteFolder(string $folder): Response; |
| 328 | |
| 329 | /** |
| 330 | * Subscribe to a folder |
| 331 | * |
| 332 | * @param string $folder folder name |
| 333 | * @return Response |
| 334 | * |
| 335 | * @throws ImapBadRequestException |
| 336 | * @throws ImapServerErrorException |
| 337 | * @throws RuntimeException |
| 338 | */ |
| 339 | public function subscribeFolder(string $folder): Response; |
| 340 | |
| 341 | /** |
| 342 | * Unsubscribe from a folder |
| 343 | * |
| 344 | * @param string $folder folder name |
| 345 | * @return Response |
| 346 | * |
| 347 | * @throws ImapBadRequestException |
| 348 | * @throws ImapServerErrorException |
| 349 | * @throws RuntimeException |
| 350 | */ |
| 351 | public function unsubscribeFolder(string $folder): Response; |
| 352 | |
| 353 | /** |
| 354 | * Send idle command |
| 355 | * |
| 356 | * @throws RuntimeException |
| 357 | */ |
| 358 | public function idle(); |
| 359 | |
| 360 | /** |
| 361 | * Send done command |
| 362 | * @throws RuntimeException |
| 363 | */ |
| 364 | public function done(); |
| 365 | |
| 366 | /** |
| 367 | * Apply session saved changes to the server |
| 368 | * |
| 369 | * @return Response |
| 370 | * |
| 371 | * @throws ImapBadRequestException |
| 372 | * @throws ImapServerErrorException |
| 373 | * @throws RuntimeException |
| 374 | */ |
| 375 | public function expunge(): Response; |
| 376 | |
| 377 | /** |
| 378 | * Retrieve the quota level settings, and usage statics per mailbox |
| 379 | * @param $username |
| 380 | * |
| 381 | * @return Response |
| 382 | * @throws RuntimeException |
| 383 | */ |
| 384 | public function getQuota($username): Response; |
| 385 | |
| 386 | /** |
| 387 | * Retrieve the quota settings per user |
| 388 | * |
| 389 | * @param string $quota_root |
| 390 | * |
| 391 | * @return Response |
| 392 | * @throws ConnectionFailedException |
| 393 | */ |
| 394 | public function getQuotaRoot(string $quota_root = 'INBOX'): Response; |
| 395 | |
| 396 | /** |
| 397 | * Send noop command |
| 398 | * |
| 399 | * @return Response |
| 400 | * |
| 401 | * @throws ImapBadRequestException |
| 402 | * @throws ImapServerErrorException |
| 403 | * @throws RuntimeException |
| 404 | */ |
| 405 | public function noop(): Response; |
| 406 | |
| 407 | /** |
| 408 | * Do a search request |
| 409 | * |
| 410 | * @param array $params |
| 411 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 412 | * message numbers instead. |
| 413 | * |
| 414 | * @return Response containing the message ids |
| 415 | * @throws RuntimeException |
| 416 | */ |
| 417 | public function search(array $params, int|string $uid = IMAP::ST_UID): Response; |
| 418 | |
| 419 | /** |
| 420 | * Get a message overview |
| 421 | * @param string $sequence uid sequence |
| 422 | * @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use |
| 423 | * message numbers instead. |
| 424 | * |
| 425 | * @return Response |
| 426 | * @throws RuntimeException |
| 427 | * @throws MessageNotFoundException |
| 428 | * @throws InvalidMessageDateException |
| 429 | */ |
| 430 | public function overview(string $sequence, int|string $uid = IMAP::ST_UID): Response; |
| 431 | |
| 432 | /** |
| 433 | * Enable the debug mode |
| 434 | */ |
| 435 | public function enableDebug(); |
| 436 | |
| 437 | /** |
| 438 | * Disable the debug mode |
| 439 | */ |
| 440 | public function disableDebug(); |
| 441 | |
| 442 | /** |
| 443 | * Enable uid caching |
| 444 | */ |
| 445 | public function enableUidCache(); |
| 446 | |
| 447 | /** |
| 448 | * Disable uid caching |
| 449 | */ |
| 450 | public function disableUidCache(); |
| 451 | |
| 452 | /** |
| 453 | * Set the uid cache of current active folder |
| 454 | * |
| 455 | * @param array|null $uids |
| 456 | */ |
| 457 | public function setUidCache(?array $uids); |
| 458 | } |