@@ -30,6 +30,9 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | + /** |
|
| 34 | + * @param boolean $clear |
|
| 35 | + */ |
|
| 33 | 36 | protected function flags( $flags, $clear ) { |
| 34 | 37 | $cb = [$this->imap(), $clear ? 'clearflag' : 'setflag']; |
| 35 | 38 | |
@@ -74,6 +77,9 @@ discard block |
||
| 74 | 77 | return $this->headers; |
| 75 | 78 | } |
| 76 | 79 | |
| 80 | + /** |
|
| 81 | + * @param string $name |
|
| 82 | + */ |
|
| 77 | 83 | public function header( $name ) { |
| 78 | 84 | $headers = $this->headers(); |
| 79 | 85 | return @$headers[ strtolower($name) ]; |
@@ -20,33 +20,33 @@ discard block |
||
| 20 | 20 | // protected $HTMLBody; |
| 21 | 21 | // protected $attachments = []; // Array<IMAPMessageAttachment> |
| 22 | 22 | |
| 23 | - public function __construct( IMAPMailbox $mailbox, $msgNumber, $unseen = null ) { |
|
| 23 | + public function __construct(IMAPMailbox $mailbox, $msgNumber, $unseen = null) { |
|
| 24 | 24 | $this->mailbox = $mailbox; |
| 25 | 25 | $this->msgNumber = $msgNumber; |
| 26 | 26 | $this->unseen = $unseen; |
| 27 | 27 | |
| 28 | - if ( $unseen === null ) { |
|
| 29 | - $this->unseen = (bool) trim($this->header('unseen')); |
|
| 28 | + if ($unseen === null) { |
|
| 29 | + $this->unseen = (bool)trim($this->header('unseen')); |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - protected function flags( $flags, $clear ) { |
|
| 33 | + protected function flags($flags, $clear) { |
|
| 34 | 34 | $cb = [$this->mailbox()->imap(), $clear ? 'clearflag' : 'setflag']; |
| 35 | 35 | |
| 36 | 36 | $feedback = []; |
| 37 | - foreach ( (array)$flags AS $flag ) { |
|
| 38 | - $flag = '\\' . ucfirst($flag); |
|
| 37 | + foreach ((array)$flags AS $flag) { |
|
| 38 | + $flag = '\\'.ucfirst($flag); |
|
| 39 | 39 | $feedback[] = call_user_func($cb, $this->msgNumber, $flag); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return is_array($flags) ? $feedback : $feedback[0]; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function flag( $flags ) { |
|
| 45 | + public function flag($flags) { |
|
| 46 | 46 | return $this->flags($flags, false); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function unflag( $flags ) { |
|
| 49 | + public function unflag($flags) { |
|
| 50 | 50 | return $this->flags($flags, true); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function subject() { |
| 58 | - if ( empty($this->subject) ) { |
|
| 58 | + if (empty($this->subject)) { |
|
| 59 | 59 | $subject = $this->mailbox()->imap()->utf8($this->header('subject')); |
| 60 | 60 | $this->subject = trim($subject); |
| 61 | 61 | } |
@@ -64,27 +64,27 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function headers() { |
| 67 | - if ( empty($this->headers) ) { |
|
| 67 | + if (empty($this->headers)) { |
|
| 68 | 68 | $headers = $this->mailbox()->imap()->headerinfo($this->msgNumber); |
| 69 | - foreach ( $headers as $name => $value ) { |
|
| 70 | - $this->headers[ strtolower($name) ] = $value; |
|
| 69 | + foreach ($headers as $name => $value) { |
|
| 70 | + $this->headers[strtolower($name)] = $value; |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return $this->headers; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function header( $name ) { |
|
| 77 | + public function header($name) { |
|
| 78 | 78 | $headers = $this->headers(); |
| 79 | - return @$headers[ strtolower($name) ]; |
|
| 79 | + return @$headers[strtolower($name)]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function createMessagePart( $structure, $section ) { |
|
| 82 | + public function createMessagePart($structure, $section) { |
|
| 83 | 83 | return new IMAPMessagePart($this, $structure, $section); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | public function parts() { |
| 87 | - if ( empty($this->parts) ) { |
|
| 87 | + if (empty($this->parts)) { |
|
| 88 | 88 | $structure = $this->structure(); |
| 89 | 89 | |
| 90 | 90 | // Possibilities: |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | // - CALENDAR |
| 99 | 99 | // - JPEG |
| 100 | 100 | |
| 101 | - if ( empty($structure->parts) ) { |
|
| 101 | + if (empty($structure->parts)) { |
|
| 102 | 102 | $this->parts[] = $this->createMessagePart( |
| 103 | 103 | $structure, |
| 104 | 104 | [1] |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public function structure() { |
| 121 | - if ( empty($this->structure) ) { |
|
| 121 | + if (empty($this->structure)) { |
|
| 122 | 122 | $this->structure = $this->mailbox()->imap()->fetchstructure($this->msgNumber); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function subtype() { |
| 129 | - if ( empty($this->subtype) ) { |
|
| 129 | + if (empty($this->subtype)) { |
|
| 130 | 130 | $structure = $this->structure(); |
| 131 | 131 | $this->subtype = @$structure->subtype ?: ''; |
| 132 | 132 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function content() { |
| 142 | - if ( count($this->parts()) == 1 ) { |
|
| 142 | + if (count($this->parts()) == 1) { |
|
| 143 | 143 | return $this->part(0)->content(); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -152,16 +152,16 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | public function simpleStructure() { |
| 154 | 154 | $parts = []; |
| 155 | - foreach ( $this->allParts(true) as $part ) { |
|
| 155 | + foreach ($this->allParts(true) as $part) { |
|
| 156 | 156 | $name = ''; |
| 157 | 157 | |
| 158 | - $name .= implode('.', $part->section()) . '. '; |
|
| 159 | - if ( $part->parts() ) { |
|
| 158 | + $name .= implode('.', $part->section()).'. '; |
|
| 159 | + if ($part->parts()) { |
|
| 160 | 160 | $name .= '*'; |
| 161 | 161 | } |
| 162 | 162 | $name .= $part->subtype(); |
| 163 | - if ( $bytes = $part->parameter('bytes') ) { |
|
| 164 | - $name .= ' (' . $bytes . ')'; |
|
| 163 | + if ($bytes = $part->parameter('bytes')) { |
|
| 164 | + $name .= ' ('.$bytes.')'; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $parts[] = $name; |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | protected $parts = []; // Array<rdx\imap\IMAPMessagePart> |
| 9 | 9 | protected $parameters = []; |
| 10 | 10 | |
| 11 | - public function allParts( $withContainers = false ) { |
|
| 11 | + public function allParts($withContainers = false) { |
|
| 12 | 12 | $parts = []; |
| 13 | 13 | $iterate = function($message) use (&$iterate, &$parts, $withContainers) { |
| 14 | - foreach ( $message->parts() as $part ) { |
|
| 15 | - if ( $part->parts() ) { |
|
| 16 | - if ( $withContainers ) { |
|
| 14 | + foreach ($message->parts() as $part) { |
|
| 15 | + if ($part->parts()) { |
|
| 16 | + if ($withContainers) { |
|
| 17 | 17 | $parts[] = $part; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -29,61 +29,61 @@ discard block |
||
| 29 | 29 | return $parts; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function part( $index ) { |
|
| 32 | + public function part($index) { |
|
| 33 | 33 | $parts = $this->parts(); |
| 34 | 34 | return @$parts[$index]; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function parameters() { |
| 38 | - if ( empty($this->parameters) ) { |
|
| 38 | + if (empty($this->parameters)) { |
|
| 39 | 39 | $structure = $this->structure(); |
| 40 | 40 | |
| 41 | 41 | $this->parameters['bytes'] = @$structure->bytes; |
| 42 | 42 | |
| 43 | - foreach ((array) @$structure->parameters as $param) { |
|
| 44 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 43 | + foreach ((array)@$structure->parameters as $param) { |
|
| 44 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 45 | 45 | } |
| 46 | - foreach ((array) @$structure->dparameters as $param) { |
|
| 47 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 46 | + foreach ((array)@$structure->dparameters as $param) { |
|
| 47 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return $this->parameters; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function parameter( $name ) { |
|
| 54 | + public function parameter($name) { |
|
| 55 | 55 | $parameters = $this->parameters(); |
| 56 | - return @$parameters[ strtolower($name) ]; |
|
| 56 | + return @$parameters[strtolower($name)]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function subtypePart( $subtypes, $recursive ) { |
|
| 60 | - $subtypes = (array) $subtypes; |
|
| 59 | + public function subtypePart($subtypes, $recursive) { |
|
| 60 | + $subtypes = (array)$subtypes; |
|
| 61 | 61 | $method = [$this, $recursive ? 'allParts' : 'parts']; |
| 62 | 62 | $parts = call_user_func($method); |
| 63 | 63 | array_unshift($parts, $this); |
| 64 | 64 | |
| 65 | - foreach ( $parts as $part ) { |
|
| 66 | - if ( in_array($part->subtype(), $subtypes) ) { |
|
| 65 | + foreach ($parts as $part) { |
|
| 66 | + if (in_array($part->subtype(), $subtypes)) { |
|
| 67 | 67 | return $part; |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function subtypeContent( $subtypes, $recursive ) { |
|
| 73 | - if ( $part = $this->subtypePart($subtypes, $recursive) ) { |
|
| 72 | + public function subtypeContent($subtypes, $recursive) { |
|
| 73 | + if ($part = $this->subtypePart($subtypes, $recursive)) { |
|
| 74 | 74 | return $part->content(); |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function text( $recursive = false ) { |
|
| 78 | + public function text($recursive = false) { |
|
| 79 | 79 | return $this->subtypeContent($this->mailbox()->getTextSubtypes(), $recursive); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function html( $recursive = false ) { |
|
| 82 | + public function html($recursive = false) { |
|
| 83 | 83 | return $this->subtypeContent($this->mailbox()->getHtmlSubtypes(), $recursive); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function deliveryStatus( $recursive = true ) { |
|
| 86 | + public function deliveryStatus($recursive = true) { |
|
| 87 | 87 | return $this->subtypeContent('DELIVERY-STATUS', $recursive); |
| 88 | 88 | } |
| 89 | 89 | |