| Total Complexity | 118 |
| Total Lines | 781 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Message often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Message, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class Message { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Client instance |
||
| 27 | * |
||
| 28 | * @var Client |
||
| 29 | */ |
||
| 30 | private $client = Client::class; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * U ID |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | public $uid = ''; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Fetch body options |
||
| 41 | * |
||
| 42 | * @var integer |
||
| 43 | */ |
||
| 44 | public $fetch_options = null; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Fetch body options |
||
| 48 | * |
||
| 49 | * @var bool |
||
| 50 | */ |
||
| 51 | public $fetch_body = null; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Fetch attachments options |
||
| 55 | * |
||
| 56 | * @var bool |
||
| 57 | */ |
||
| 58 | public $fetch_attachment = null; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var int $msglist |
||
| 62 | */ |
||
| 63 | public $msglist = 1; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var string $header |
||
| 67 | */ |
||
| 68 | public $header = null; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var null|object $header_info |
||
| 72 | */ |
||
| 73 | public $header_info = null; |
||
| 74 | |||
| 75 | /** @var null|object $raw_body */ |
||
| 76 | public $raw_body = null; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Message header components |
||
| 80 | * |
||
| 81 | * @var string $message_id |
||
| 82 | * @var mixed $message_no |
||
| 83 | * @var string $subject |
||
| 84 | * @var mixed $date |
||
| 85 | * @var array $from |
||
| 86 | * @var array $to |
||
| 87 | * @var array $cc |
||
| 88 | * @var array $bcc |
||
| 89 | * @var array $reply_to |
||
| 90 | * @var string $in_reply_to |
||
| 91 | * @var array $sender |
||
| 92 | */ |
||
| 93 | public $message_id = ''; |
||
| 94 | public $message_no = null; |
||
| 95 | public $subject = ''; |
||
| 96 | public $date = null; |
||
| 97 | public $from = []; |
||
| 98 | public $to = []; |
||
| 99 | public $cc = []; |
||
| 100 | public $bcc = []; |
||
| 101 | public $reply_to = []; |
||
| 102 | public $in_reply_to = ''; |
||
| 103 | public $sender = []; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Message body components |
||
| 107 | * |
||
| 108 | * @var array $bodies |
||
| 109 | * @var AttachmentCollection|array $attachments |
||
| 110 | */ |
||
| 111 | public $bodies = []; |
||
| 112 | public $attachments = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Message const |
||
| 116 | * |
||
| 117 | * @const integer TYPE_TEXT |
||
| 118 | * @const integer TYPE_MULTIPART |
||
| 119 | * |
||
| 120 | * @const integer ENC_7BIT |
||
| 121 | * @const integer ENC_8BIT |
||
| 122 | * @const integer ENC_BINARY |
||
| 123 | * @const integer ENC_BASE64 |
||
| 124 | * @const integer ENC_QUOTED_PRINTABLE |
||
| 125 | * @const integer ENC_OTHER |
||
| 126 | */ |
||
| 127 | const TYPE_TEXT = 0; |
||
| 128 | const TYPE_MULTIPART = 1; |
||
| 129 | |||
| 130 | const ENC_7BIT = 0; |
||
| 131 | const ENC_8BIT = 1; |
||
| 132 | const ENC_BINARY = 2; |
||
| 133 | const ENC_BASE64 = 3; |
||
| 134 | const ENC_QUOTED_PRINTABLE = 4; |
||
| 135 | const ENC_OTHER = 5; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Message constructor. |
||
| 139 | * |
||
| 140 | * @param integer $uid |
||
| 141 | * @param integer|null $msglist |
||
| 142 | * @param Client $client |
||
| 143 | * @param integer|null $fetch_options |
||
| 144 | * @param boolean $fetch_body |
||
| 145 | * @param boolean $fetch_attachment |
||
| 146 | */ |
||
| 147 | public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_attachment = false) { |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Copy the current Messages to a mailbox |
||
| 167 | * |
||
| 168 | * @param $mailbox |
||
| 169 | * @param int $options |
||
| 170 | * |
||
| 171 | * @return bool |
||
| 172 | */ |
||
| 173 | public function copy($mailbox, $options = 0) { |
||
| 174 | return imap_mail_copy($this->client->getConnection(), $this->msglist, $mailbox, $options); |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Move the current Messages to a mailbox |
||
| 179 | * |
||
| 180 | * @param $mailbox |
||
| 181 | * @param int $options |
||
| 182 | * |
||
| 183 | * @return bool |
||
| 184 | */ |
||
| 185 | public function move($mailbox, $options = 0) { |
||
| 186 | return imap_mail_move($this->client->getConnection(), $this->msglist, $mailbox, $options); |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Check if the Message has a text body |
||
| 191 | * |
||
| 192 | * @return bool |
||
| 193 | */ |
||
| 194 | public function hasTextBody() { |
||
| 195 | return isset($this->bodies['text']); |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get the Message text body |
||
| 200 | * |
||
| 201 | * @return mixed |
||
| 202 | */ |
||
| 203 | public function getTextBody() { |
||
| 204 | if (!isset($this->bodies['text'])) { |
||
| 205 | return false; |
||
| 206 | } |
||
| 207 | |||
| 208 | return $this->bodies['text']->content; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Check if the Message has a html body |
||
| 213 | * |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | public function hasHTMLBody() { |
||
| 217 | return isset($this->bodies['html']); |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Get the Message html body |
||
| 222 | * |
||
| 223 | * @var bool $replaceImages |
||
| 224 | * |
||
| 225 | * @return mixed |
||
| 226 | */ |
||
| 227 | public function getHTMLBody($replaceImages = false) { |
||
| 228 | if (!isset($this->bodies['html'])) { |
||
| 229 | return false; |
||
| 230 | } |
||
| 231 | |||
| 232 | $body = $this->bodies['html']->content; |
||
| 233 | if ($replaceImages) { |
||
| 234 | $this->attachments->each(function($oAttachment) use(&$body){ |
||
| 235 | if ($oAttachment->id && isset($oAttachment->img_src)) { |
||
| 236 | $body = str_replace('cid:'.$oAttachment->id, $oAttachment->img_src, $body); |
||
| 237 | } |
||
| 238 | }); |
||
| 239 | } |
||
| 240 | |||
| 241 | return $body; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Parse all defined headers |
||
| 246 | * |
||
| 247 | * @return void |
||
| 248 | */ |
||
| 249 | private function parseHeader() { |
||
| 250 | $this->header = $header = imap_fetchheader($this->client->getConnection(), $this->uid, $this->fetch_options); |
||
|
|
|||
| 251 | if ($this->header) { |
||
| 252 | $header = imap_rfc822_parse_headers($this->header); |
||
| 253 | } |
||
| 254 | |||
| 255 | if (property_exists($header, 'subject')) { |
||
| 256 | $this->subject = imap_utf8($header->subject); |
||
| 257 | } |
||
| 258 | if (property_exists($header, 'date')) { |
||
| 259 | $date = $header->date; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Exception handling for invalid dates |
||
| 263 | * Will be extended in the future |
||
| 264 | * |
||
| 265 | * Currently known invalid formats: |
||
| 266 | * ^ Datetime ^ Problem ^ Cause |
||
| 267 | * | Mon, 20 Nov 2017 20:31:31 +0800 (GMT+8:00) | Double timezone specification | A Windows feature |
||
| 268 | * | | and invalid timezone (max 6 char) | |
||
| 269 | * | 04 Jan 2018 10:12:47 UT | Missing letter "C" | Unknown |
||
| 270 | * |
||
| 271 | * Please report any new invalid timestamps to [#45](https://github.com/Webklex/laravel-imap/issues/45) |
||
| 272 | */ |
||
| 273 | try { |
||
| 274 | $this->date = Carbon::parse($date); |
||
| 275 | } catch(\Exception $e) { |
||
| 276 | switch (true) { |
||
| 277 | case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ \+[0-9]{4}\ \([A-Z]{2,3}\+[0-9]{1,2}\:[0-9]{1,2})\)+$/i', $date) > 0: |
||
| 278 | $array = explode('(', $date); |
||
| 279 | $array = array_reverse($array); |
||
| 280 | $date = trim(array_pop($array)); |
||
| 281 | break; |
||
| 282 | case preg_match('/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ UT)+$/i', $date) > 0: |
||
| 283 | $date .= 'C'; |
||
| 284 | break; |
||
| 285 | } |
||
| 286 | $this->date = Carbon::parse($date); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | if (property_exists($header, 'from')) { |
||
| 291 | $this->from = $this->parseAddresses($header->from); |
||
| 292 | } |
||
| 293 | if (property_exists($header, 'to')) { |
||
| 294 | $this->to = $this->parseAddresses($header->to); |
||
| 295 | } |
||
| 296 | if (property_exists($header, 'cc')) { |
||
| 297 | $this->cc = $this->parseAddresses($header->cc); |
||
| 298 | } |
||
| 299 | if (property_exists($header, 'bcc')) { |
||
| 300 | $this->bcc = $this->parseAddresses($header->bcc); |
||
| 301 | } |
||
| 302 | |||
| 303 | if (property_exists($header, 'reply_to')) { |
||
| 304 | $this->reply_to = $this->parseAddresses($header->reply_to); |
||
| 305 | } |
||
| 306 | if (property_exists($header, 'in_reply_to')) { |
||
| 307 | $this->in_reply_to = str_replace(['<', '>'], '', $header->in_reply_to); |
||
| 308 | } |
||
| 309 | if (property_exists($header, 'sender')) { |
||
| 310 | $this->sender = $this->parseAddresses($header->sender); |
||
| 311 | } |
||
| 312 | |||
| 313 | if (property_exists($header, 'message_id')) { |
||
| 314 | $this->message_id = str_replace(['<', '>'], '', $header->message_id); |
||
| 315 | } |
||
| 316 | if (property_exists($header, 'Msgno')) { |
||
| 317 | $this->message_no = ($this->fetch_options == FT_UID) ? trim($header->Msgno) : imap_msgno($this->client->getConnection(), trim($header->Msgno)); |
||
| 318 | } else{ |
||
| 319 | $this->message_no = imap_msgno($this->client->getConnection(), $this->getUid()); |
||
| 320 | } |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Get the current Message header info |
||
| 325 | * |
||
| 326 | * @return object |
||
| 327 | */ |
||
| 328 | public function getHeaderInfo() { |
||
| 329 | if ($this->header_info == null) { |
||
| 330 | $this->header_info = |
||
| 331 | $this->header_info = imap_headerinfo($this->client->getConnection(), $this->getMessageNo()); ; |
||
| 332 | } |
||
| 333 | |||
| 334 | return $this->header_info; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Parse Addresses |
||
| 339 | * |
||
| 340 | * @param $list |
||
| 341 | * |
||
| 342 | * @return array |
||
| 343 | */ |
||
| 344 | private function parseAddresses($list) { |
||
| 345 | $addresses = []; |
||
| 346 | |||
| 347 | foreach ($list as $item) { |
||
| 348 | $address = (object) $item; |
||
| 349 | |||
| 350 | if (!property_exists($address, 'mailbox')) { |
||
| 351 | $address->mailbox = false; |
||
| 352 | } |
||
| 353 | if (!property_exists($address, 'host')) { |
||
| 354 | $address->host = false; |
||
| 355 | } |
||
| 356 | if (!property_exists($address, 'personal')) { |
||
| 357 | $address->personal = false; |
||
| 358 | } |
||
| 359 | |||
| 360 | $address->personal = imap_utf8($address->personal); |
||
| 361 | |||
| 362 | $address->mail = ($address->mailbox && $address->host) ? $address->mailbox.'@'.$address->host : false; |
||
| 363 | $address->full = ($address->personal) ? $address->personal.' <'.$address->mail.'>' : $address->mail; |
||
| 364 | |||
| 365 | $addresses[] = $address; |
||
| 366 | } |
||
| 367 | |||
| 368 | return $addresses; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Parse the Message body |
||
| 373 | * |
||
| 374 | * @return $this |
||
| 375 | */ |
||
| 376 | public function parseBody() { |
||
| 377 | $structure = imap_fetchstructure($this->client->getConnection(), $this->uid, $this->fetch_options); |
||
| 378 | |||
| 379 | $this->fetchStructure($structure); |
||
| 380 | |||
| 381 | return $this; |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Fetch the Message structure |
||
| 386 | * |
||
| 387 | * @param $structure |
||
| 388 | * @param mixed $partNumber |
||
| 389 | */ |
||
| 390 | private function fetchStructure($structure, $partNumber = null) { |
||
| 391 | if ($structure->type == self::TYPE_TEXT && |
||
| 392 | ($structure->ifdisposition == 0 || |
||
| 393 | ($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber == null) |
||
| 394 | ) |
||
| 395 | ) { |
||
| 396 | if ($structure->subtype == "PLAIN") { |
||
| 397 | if (!$partNumber) { |
||
| 398 | $partNumber = 1; |
||
| 399 | } |
||
| 400 | |||
| 401 | $encoding = $this->getEncoding($structure); |
||
| 402 | |||
| 403 | $content = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options); |
||
| 404 | $content = $this->decodeString($content, $structure->encoding); |
||
| 405 | $content = $this->convertEncoding($content, $encoding); |
||
| 406 | |||
| 407 | $body = new \stdClass; |
||
| 408 | $body->type = "text"; |
||
| 409 | $body->content = $content; |
||
| 410 | |||
| 411 | $this->bodies['text'] = $body; |
||
| 412 | |||
| 413 | $this->fetchAttachment($structure, $partNumber); |
||
| 414 | |||
| 415 | } elseif ($structure->subtype == "HTML") { |
||
| 416 | if (!$partNumber) { |
||
| 417 | $partNumber = 1; |
||
| 418 | } |
||
| 419 | |||
| 420 | $encoding = $this->getEncoding($structure); |
||
| 421 | |||
| 422 | $content = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options); |
||
| 423 | $content = $this->decodeString($content, $structure->encoding); |
||
| 424 | $content = $this->convertEncoding($content, $encoding); |
||
| 425 | |||
| 426 | $body = new \stdClass; |
||
| 427 | $body->type = "html"; |
||
| 428 | $body->content = $content; |
||
| 429 | |||
| 430 | $this->bodies['html'] = $body; |
||
| 431 | } |
||
| 432 | } elseif ($structure->type == self::TYPE_MULTIPART) { |
||
| 433 | foreach ($structure->parts as $index => $subStruct) { |
||
| 434 | $prefix = ""; |
||
| 435 | if ($partNumber) { |
||
| 436 | $prefix = $partNumber."."; |
||
| 437 | } |
||
| 438 | $this->fetchStructure($subStruct, $prefix.($index + 1)); |
||
| 439 | } |
||
| 440 | } else { |
||
| 441 | if ($this->getFetchAttachmentOption() === true) { |
||
| 442 | $this->fetchAttachment($structure, $partNumber); |
||
| 443 | } |
||
| 444 | } |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Fetch the Message attachment |
||
| 449 | * |
||
| 450 | * @param object $structure |
||
| 451 | * @param mixed $partNumber |
||
| 452 | */ |
||
| 453 | protected function fetchAttachment($structure, $partNumber) { |
||
| 454 | |||
| 455 | $oAttachment = new Attachment($this, $structure, $partNumber); |
||
| 456 | |||
| 457 | if ($oAttachment->getName() != null) { |
||
| 458 | if ($oAttachment->getId() != null) { |
||
| 459 | $this->attachments->put($oAttachment->getId(), $oAttachment); |
||
| 460 | } else { |
||
| 461 | $this->attachments->push($oAttachment); |
||
| 462 | } |
||
| 463 | } |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Fail proof setter for $fetch_option |
||
| 468 | * |
||
| 469 | * @param $option |
||
| 470 | * |
||
| 471 | * @return $this |
||
| 472 | */ |
||
| 473 | public function setFetchOption($option) { |
||
| 474 | if (is_long($option) == true) { |
||
| 475 | $this->fetch_options = $option; |
||
| 476 | } elseif (is_null($option) == true) { |
||
| 477 | $config = config('imap.options.fetch', FT_UID); |
||
| 478 | $this->fetch_options = is_long($config) ? $config : 1; |
||
| 479 | } |
||
| 480 | |||
| 481 | return $this; |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Fail proof setter for $fetch_body |
||
| 486 | * |
||
| 487 | * @param $option |
||
| 488 | * |
||
| 489 | * @return $this |
||
| 490 | */ |
||
| 491 | public function setFetchBodyOption($option) { |
||
| 492 | if (is_bool($option) == true) { |
||
| 493 | $this->fetch_body = $option; |
||
| 494 | } elseif (is_null($option) == true) { |
||
| 495 | $config = config('imap.options.fetch_body', true); |
||
| 496 | $this->fetch_body = is_bool($config) ? $config : true; |
||
| 497 | } |
||
| 498 | |||
| 499 | return $this; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Fail proof setter for $fetch_attachment |
||
| 504 | * |
||
| 505 | * @param $option |
||
| 506 | * |
||
| 507 | * @return $this |
||
| 508 | */ |
||
| 509 | public function setFetchAttachmentOption($option) { |
||
| 510 | if (is_bool($option) == true) { |
||
| 511 | $this->fetch_attachment = $option; |
||
| 512 | } elseif (is_null($option) == true) { |
||
| 513 | $config = config('imap.options.fetch_attachment', true); |
||
| 514 | $this->fetch_attachment = is_bool($config) ? $config : true; |
||
| 515 | } |
||
| 516 | |||
| 517 | return $this; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Decode a given string |
||
| 522 | * |
||
| 523 | * @param $string |
||
| 524 | * @param $encoding |
||
| 525 | * |
||
| 526 | * @return string |
||
| 527 | */ |
||
| 528 | public function decodeString($string, $encoding) { |
||
| 529 | switch ($encoding) { |
||
| 530 | case self::ENC_7BIT: |
||
| 531 | return $string; |
||
| 532 | case self::ENC_8BIT: |
||
| 533 | return quoted_printable_decode(imap_8bit($string)); |
||
| 534 | case self::ENC_BINARY: |
||
| 535 | return imap_binary($string); |
||
| 536 | case self::ENC_BASE64: |
||
| 537 | return imap_base64($string); |
||
| 538 | case self::ENC_QUOTED_PRINTABLE: |
||
| 539 | return quoted_printable_decode($string); |
||
| 540 | case self::ENC_OTHER: |
||
| 541 | return $string; |
||
| 542 | default: |
||
| 543 | return $string; |
||
| 544 | } |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Convert the encoding |
||
| 549 | * |
||
| 550 | * @param $str |
||
| 551 | * @param string $from |
||
| 552 | * @param string $to |
||
| 553 | * |
||
| 554 | * @return mixed|string |
||
| 555 | */ |
||
| 556 | private function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") { |
||
| 557 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
||
| 558 | return iconv($from, $to.'//IGNORE', $str); |
||
| 559 | } else { |
||
| 560 | if (!$from) { |
||
| 561 | return mb_convert_encoding($str, $to); |
||
| 562 | } |
||
| 563 | return mb_convert_encoding($str, $to, $from); |
||
| 564 | } |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Get the encoding of a given abject |
||
| 569 | * |
||
| 570 | * @param object $structure |
||
| 571 | * |
||
| 572 | * @return null|string |
||
| 573 | */ |
||
| 574 | private function getEncoding($structure) { |
||
| 575 | if (property_exists($structure, 'parameters')) { |
||
| 576 | foreach ($structure->parameters as $parameter) { |
||
| 577 | if (strtolower($parameter->attribute) == "charset") { |
||
| 578 | return strtoupper($parameter->value); |
||
| 579 | } |
||
| 580 | } |
||
| 581 | } |
||
| 582 | return null; |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Move the Message into an other Folder |
||
| 587 | * |
||
| 588 | * @param string $mailbox |
||
| 589 | * |
||
| 590 | * @return bool |
||
| 591 | */ |
||
| 592 | public function moveToFolder($mailbox = 'INBOX') { |
||
| 593 | $this->client->createFolder($mailbox); |
||
| 594 | |||
| 595 | if (imap_mail_move($this->client->getConnection(), $this->msglist, $mailbox) == true) { |
||
| 596 | return true; |
||
| 597 | } |
||
| 598 | return false; |
||
| 599 | } |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Delete the current Message |
||
| 603 | * |
||
| 604 | * @return bool |
||
| 605 | */ |
||
| 606 | public function delete() { |
||
| 607 | $status = imap_delete($this->client->getConnection(), $this->uid, $this->fetch_options); |
||
| 608 | $this->client->expunge(); |
||
| 609 | |||
| 610 | return $status; |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Restore a deleted Message |
||
| 615 | * |
||
| 616 | * @return bool |
||
| 617 | */ |
||
| 618 | public function restore() { |
||
| 619 | return imap_undelete($this->client->getConnection(), $this->message_no); |
||
| 620 | } |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Get all message attachments. |
||
| 624 | * |
||
| 625 | * @return AttachmentCollection |
||
| 626 | */ |
||
| 627 | public function getAttachments() { |
||
| 628 | return $this->attachments; |
||
| 629 | } |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Checks if there are any attachments present |
||
| 633 | * |
||
| 634 | * @return boolean |
||
| 635 | */ |
||
| 636 | public function hasAttachments() { |
||
| 637 | return $this->attachments->isEmpty() === false; |
||
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Set a given flag |
||
| 642 | * @param string|array $flag |
||
| 643 | * |
||
| 644 | * @return bool |
||
| 645 | */ |
||
| 646 | public function setFlag($flag) { |
||
| 647 | $flag = "\\".trim(is_array($flag) ? implode(" \\", $flag) : $flag); |
||
| 648 | return imap_setflag_full($this->client->getConnection(), $this->getUid(), $flag, SE_UID); |
||
| 649 | } |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Unset a given flag |
||
| 653 | * @param string|array $flag |
||
| 654 | * |
||
| 655 | * @return bool |
||
| 656 | */ |
||
| 657 | public function unsetFlag($flag) { |
||
| 658 | $flag = "\\".trim(is_array($flag) ? implode(" \\", $flag) : $flag); |
||
| 659 | return imap_clearflag_full($this->client->getConnection(), $this->getUid(), "\\$flag", SE_UID); |
||
| 660 | } |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @return null|object|string |
||
| 664 | */ |
||
| 665 | public function getRawBody() { |
||
| 671 | } |
||
| 672 | |||
| 673 | /** |
||
| 674 | * @return string |
||
| 675 | */ |
||
| 676 | public function getHeader() { |
||
| 677 | return $this->header; |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * @return Client |
||
| 682 | */ |
||
| 683 | public function getClient() { |
||
| 684 | return $this->client; |
||
| 685 | } |
||
| 686 | |||
| 687 | /** |
||
| 688 | * @return string |
||
| 689 | */ |
||
| 690 | public function getUid() { |
||
| 691 | return $this->uid; |
||
| 692 | } |
||
| 693 | |||
| 694 | /** |
||
| 695 | * @return integer |
||
| 696 | */ |
||
| 697 | public function getFetchOptions() { |
||
| 698 | return $this->fetch_options; |
||
| 699 | } |
||
| 700 | |||
| 701 | /** |
||
| 702 | * @return boolean |
||
| 703 | */ |
||
| 704 | public function getFetchBodyOption() { |
||
| 705 | return $this->fetch_body; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * @return boolean |
||
| 710 | */ |
||
| 711 | public function getFetchAttachmentOption() { |
||
| 712 | return $this->fetch_attachment; |
||
| 713 | } |
||
| 714 | |||
| 715 | /** |
||
| 716 | * @return int |
||
| 717 | */ |
||
| 718 | public function getMsglist() { |
||
| 719 | return $this->msglist; |
||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @return mixed |
||
| 724 | */ |
||
| 725 | public function getMessageId() { |
||
| 726 | return $this->message_id; |
||
| 727 | } |
||
| 728 | |||
| 729 | /** |
||
| 730 | * @return int |
||
| 731 | */ |
||
| 732 | public function getMessageNo() { |
||
| 733 | return $this->message_no; |
||
| 734 | } |
||
| 735 | |||
| 736 | /** |
||
| 737 | * @return string |
||
| 738 | */ |
||
| 739 | public function getSubject() { |
||
| 740 | return $this->subject; |
||
| 741 | } |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @return null |
||
| 745 | */ |
||
| 746 | public function getDate() { |
||
| 747 | return $this->date; |
||
| 748 | } |
||
| 749 | |||
| 750 | /** |
||
| 751 | * @return array |
||
| 752 | */ |
||
| 753 | public function getFrom() { |
||
| 754 | return $this->from; |
||
| 755 | } |
||
| 756 | |||
| 757 | /** |
||
| 758 | * @return array |
||
| 759 | */ |
||
| 760 | public function getTo() { |
||
| 761 | return $this->to; |
||
| 762 | } |
||
| 763 | |||
| 764 | /** |
||
| 765 | * @return array |
||
| 766 | */ |
||
| 767 | public function getCc() { |
||
| 768 | return $this->cc; |
||
| 769 | } |
||
| 770 | |||
| 771 | /** |
||
| 772 | * @return array |
||
| 773 | */ |
||
| 774 | public function getBcc() { |
||
| 775 | return $this->bcc; |
||
| 776 | } |
||
| 777 | |||
| 778 | /** |
||
| 779 | * @return array |
||
| 780 | */ |
||
| 781 | public function getReplyTo() { |
||
| 782 | return $this->reply_to; |
||
| 783 | } |
||
| 784 | |||
| 785 | /** |
||
| 786 | * @return string |
||
| 787 | */ |
||
| 788 | public function getInReplyTo() { |
||
| 790 | } |
||
| 791 | |||
| 792 | /** |
||
| 793 | * @return array |
||
| 794 | */ |
||
| 795 | public function getSender() { |
||
| 796 | return $this->sender; |
||
| 797 | } |
||
| 798 | |||
| 799 | /** |
||
| 800 | * @return mixed |
||
| 801 | */ |
||
| 802 | public function getBodies() { |
||
| 803 | return $this->bodies; |
||
| 804 | } |
||
| 805 | } |
||
| 806 |