@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | $structure, |
| 93 | 93 | [1] |
| 94 | 94 | ); |
| 95 | - } |
|
| 96 | - else { |
|
| 95 | + } else { |
|
| 97 | 96 | foreach ($structure->parts as $n => $part) { |
| 98 | 97 | $this->parts[] = new IMAPMessagePart( |
| 99 | 98 | $this, |
@@ -117,8 +116,7 @@ discard block |
||
| 117 | 116 | } |
| 118 | 117 | |
| 119 | 118 | $iterate($part); |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | $parts[] = $part; |
| 123 | 121 | } |
| 124 | 122 | } |
@@ -19,33 +19,33 @@ discard block |
||
| 19 | 19 | protected $HTMLBody; |
| 20 | 20 | protected $attachments = []; // typeof Array<IMAPMessageAttachment> |
| 21 | 21 | |
| 22 | - public function __construct( IMAPMailbox $mailbox, $msgNumber, $unseen = null ) { |
|
| 22 | + public function __construct(IMAPMailbox $mailbox, $msgNumber, $unseen = null) { |
|
| 23 | 23 | $this->mailbox = $mailbox; |
| 24 | 24 | $this->msgNumber = $msgNumber; |
| 25 | 25 | $this->unseen = $unseen; |
| 26 | 26 | |
| 27 | - if ( $unseen === null ) { |
|
| 28 | - $this->unseen = (bool) trim($this->header('unseen')); |
|
| 27 | + if ($unseen === null) { |
|
| 28 | + $this->unseen = (bool)trim($this->header('unseen')); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - protected function flags( $flags, $clear ) { |
|
| 32 | + protected function flags($flags, $clear) { |
|
| 33 | 33 | $cb = $clear ? 'imap_clearflag_full' : 'imap_setflag_full'; |
| 34 | 34 | |
| 35 | 35 | $feedback = []; |
| 36 | - foreach ( (array)$flags AS $flag ) { |
|
| 37 | - $flag = '\\' . ucfirst($flag); |
|
| 36 | + foreach ((array)$flags AS $flag) { |
|
| 37 | + $flag = '\\'.ucfirst($flag); |
|
| 38 | 38 | $feedback[] = $cb($this->mailbox()->imap(), (string)$this->msgNumber, $flag); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return is_array($flags) ? $feedback : $feedback[0]; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function flag( $flags ) { |
|
| 44 | + public function flag($flags) { |
|
| 45 | 45 | return $this->flags($flags, false); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function unflag( $flags ) { |
|
| 48 | + public function unflag($flags) { |
|
| 49 | 49 | return $this->flags($flags, true); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function subject() { |
| 57 | - if ( empty($this->subject) ) { |
|
| 57 | + if (empty($this->subject)) { |
|
| 58 | 58 | $subject = imap_utf8($this->header('subject')); |
| 59 | 59 | $this->subject = trim($subject); |
| 60 | 60 | } |
@@ -63,23 +63,23 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function headers() { |
| 66 | - if ( empty($this->headers) ) { |
|
| 66 | + if (empty($this->headers)) { |
|
| 67 | 67 | $headers = imap_headerinfo($this->mailbox()->imap(), $this->msgNumber); |
| 68 | - foreach ( $headers as $name => $value ) { |
|
| 69 | - $this->headers[ strtolower($name) ] = $value; |
|
| 68 | + foreach ($headers as $name => $value) { |
|
| 69 | + $this->headers[strtolower($name)] = $value; |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return $this->headers; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public function header( $name ) { |
|
| 76 | + public function header($name) { |
|
| 77 | 77 | $headers = $this->headers(); |
| 78 | - return @$headers[ strtolower($name) ]; |
|
| 78 | + return @$headers[strtolower($name)]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function parts() { |
| 82 | - if ( empty($this->parts) ) { |
|
| 82 | + if (empty($this->parts)) { |
|
| 83 | 83 | $structure = $this->structure(); |
| 84 | 84 | |
| 85 | 85 | // Possibilities: |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | // - CALENDAR |
| 94 | 94 | // - JPEG |
| 95 | 95 | |
| 96 | - if ( empty($structure->parts) ) { |
|
| 96 | + if (empty($structure->parts)) { |
|
| 97 | 97 | $this->parts[] = new IMAPMessagePart( |
| 98 | 98 | $this, |
| 99 | 99 | $structure, |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | return $this->parts; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - public function allParts( $withContainers = false ) { |
|
| 117 | + public function allParts($withContainers = false) { |
|
| 118 | 118 | $parts = []; |
| 119 | 119 | $iterate = function($message) use (&$iterate, &$parts, $withContainers) { |
| 120 | - foreach ( $message->parts() as $part ) { |
|
| 121 | - if ( $part->parts() ) { |
|
| 122 | - if ( $withContainers ) { |
|
| 120 | + foreach ($message->parts() as $part) { |
|
| 121 | + if ($part->parts()) { |
|
| 122 | + if ($withContainers) { |
|
| 123 | 123 | $parts[] = $part; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | return $parts; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function part( $index ) { |
|
| 138 | + public function part($index) { |
|
| 139 | 139 | $parts = $this->parts(); |
| 140 | 140 | return @$parts[$index]; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | public function structure() { |
| 144 | - if ( empty($this->structure) ) { |
|
| 144 | + if (empty($this->structure)) { |
|
| 145 | 145 | $this->structure = imap_fetchstructure($this->mailbox()->imap(), $this->msgNumber); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public function content() { |
| 152 | - if ( count($this->parts()) == 1 ) { |
|
| 152 | + if (count($this->parts()) == 1) { |
|
| 153 | 153 | return $this->part(0)->content(); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | public function parameters() { |
| 160 | - if ( empty($this->parameters) ) { |
|
| 160 | + if (empty($this->parameters)) { |
|
| 161 | 161 | $structure = $this->structure(); |
| 162 | 162 | |
| 163 | 163 | $this->parameters['bytes'] = @$structure->bytes; |
| 164 | 164 | |
| 165 | - foreach ((array) @$structure->parameters as $param) { |
|
| 166 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 165 | + foreach ((array)@$structure->parameters as $param) { |
|
| 166 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 167 | 167 | } |
| 168 | - foreach ((array) @$structure->dparameters as $param) { |
|
| 169 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 168 | + foreach ((array)@$structure->dparameters as $param) { |
|
| 169 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
@@ -175,16 +175,16 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | public function simpleStructure() { |
| 177 | 177 | $parts = []; |
| 178 | - foreach ( $this->allParts(true) as $part ) { |
|
| 178 | + foreach ($this->allParts(true) as $part) { |
|
| 179 | 179 | $name = ''; |
| 180 | 180 | |
| 181 | - $name .= implode('.', $part->section()) . '. '; |
|
| 182 | - if ( $part->parts() ) { |
|
| 181 | + $name .= implode('.', $part->section()).'. '; |
|
| 182 | + if ($part->parts()) { |
|
| 183 | 183 | $name .= '*'; |
| 184 | 184 | } |
| 185 | 185 | $name .= $part->subtype(); |
| 186 | - if ( $bytes = $part->parameter('bytes') ) { |
|
| 187 | - $name .= ' (' . $bytes . ')'; |
|
| 186 | + if ($bytes = $part->parameter('bytes')) { |
|
| 187 | + $name .= ' ('.$bytes.')'; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $parts[] = $name; |
@@ -52,8 +52,7 @@ |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $iterate($part); |
| 55 | - } |
|
| 56 | - else { |
|
| 55 | + } else { |
|
| 57 | 56 | $parts[] = $part; |
| 58 | 57 | } |
| 59 | 58 | } |
@@ -14,21 +14,21 @@ discard block |
||
| 14 | 14 | public $structure; // typeof stdClass |
| 15 | 15 | public $skippedParts = []; // Array<stdClass> |
| 16 | 16 | |
| 17 | - public function __construct( IMAPMessage $message, $structure, array $section ) { |
|
| 17 | + public function __construct(IMAPMessage $message, $structure, array $section) { |
|
| 18 | 18 | $this->message = $message; |
| 19 | 19 | $this->structure = $structure; |
| 20 | 20 | $this->section = $section; |
| 21 | 21 | $this->subtype = strtoupper($structure->subtype); |
| 22 | 22 | |
| 23 | - if ( !empty($structure->parts) ) { |
|
| 23 | + if (!empty($structure->parts)) { |
|
| 24 | 24 | $parts = $structure->parts; |
| 25 | 25 | |
| 26 | - while ( count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts) ) { |
|
| 26 | + while (count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts)) { |
|
| 27 | 27 | $this->skippedParts[] = $parts[0]; |
| 28 | 28 | $parts = $parts[0]->parts; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - foreach ( $parts as $n => $part ) { |
|
| 31 | + foreach ($parts as $n => $part) { |
|
| 32 | 32 | $this->parts[] = new IMAPMessagePart( |
| 33 | 33 | $this->message, |
| 34 | 34 | $part, |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | return $this->parts; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function allParts( $withContainers = false ) { |
|
| 45 | + public function allParts($withContainers = false) { |
|
| 46 | 46 | $parts = []; |
| 47 | 47 | $iterate = function($message) use (&$iterate, &$parts, $withContainers) { |
| 48 | - foreach ( $message->parts() as $part ) { |
|
| 49 | - if ( $part->parts() ) { |
|
| 50 | - if ( $withContainers ) { |
|
| 48 | + foreach ($message->parts() as $part) { |
|
| 49 | + if ($part->parts()) { |
|
| 50 | + if ($withContainers) { |
|
| 51 | 51 | $parts[] = $part; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | return $parts; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function part( $index ) { |
|
| 66 | + public function part($index) { |
|
| 67 | 67 | $parts = $this->parts(); |
| 68 | 68 | return @$parts[$index]; |
| 69 | 69 | } |
@@ -73,25 +73,25 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function parameters() { |
| 76 | - if ( empty($this->parameters) ) { |
|
| 76 | + if (empty($this->parameters)) { |
|
| 77 | 77 | $structure = $this->structure(); |
| 78 | 78 | |
| 79 | 79 | $this->parameters['bytes'] = @$structure->bytes; |
| 80 | 80 | |
| 81 | - foreach ((array) @$structure->parameters as $param) { |
|
| 82 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 81 | + foreach ((array)@$structure->parameters as $param) { |
|
| 82 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 83 | 83 | } |
| 84 | - foreach ((array) @$structure->dparameters as $param) { |
|
| 85 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 84 | + foreach ((array)@$structure->dparameters as $param) { |
|
| 85 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return $this->parameters; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function parameter( $name ) { |
|
| 92 | + public function parameter($name) { |
|
| 93 | 93 | $parameters = $this->parameters(); |
| 94 | - return @$parameters[ strtolower($name) ]; |
|
| 94 | + return @$parameters[strtolower($name)]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function content() { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | return $this->decode($body); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function decode( $content ) { |
|
| 107 | + public function decode($content) { |
|
| 108 | 108 | return quoted_printable_decode($content); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | public function structure(); |
| 7 | 7 | public function parts(); |
| 8 | 8 | public function allParts(); |
| 9 | - public function part( $index ); |
|
| 9 | + public function part($index); |
|
| 10 | 10 | public function content(); |
| 11 | 11 | public function parameters(); |
| 12 | 12 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | protected $imap; // imap_open() resource |
| 14 | 14 | |
| 15 | - public function __construct( $server, $username, $password, $mailbox = null, $flags = [] ) { |
|
| 15 | + public function __construct($server, $username, $password, $mailbox = null, $flags = []) { |
|
| 16 | 16 | $this->server = $server; |
| 17 | 17 | $this->username = $username; |
| 18 | 18 | $this->password = $password; |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function connect() { |
| 24 | - if ( !$this->imap ) { |
|
| 24 | + if (!$this->imap) { |
|
| 25 | 25 | $server = $this->server; |
| 26 | - if ( !empty($this->flags) ) { |
|
| 27 | - $server .= '/' . implode('/', $this->flags); |
|
| 26 | + if (!empty($this->flags)) { |
|
| 27 | + $server .= '/'.implode('/', $this->flags); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - $mailbox = '{' . $server . '}' . $this->mailbox; |
|
| 30 | + $mailbox = '{'.$server.'}'.$this->mailbox; |
|
| 31 | 31 | $this->imap = imap_open($mailbox, $this->username, $this->password); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -38,25 +38,25 @@ discard block |
||
| 38 | 38 | return $this->imap; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function headers( $newestFirst = true ) { |
|
| 41 | + public function headers($newestFirst = true) { |
|
| 42 | 42 | $this->connect(); |
| 43 | 43 | |
| 44 | 44 | $headers = imap_headers($this->imap()); |
| 45 | 45 | |
| 46 | - if ( $newestFirst ) { |
|
| 46 | + if ($newestFirst) { |
|
| 47 | 47 | $headers = array_reverse($headers); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | return $headers; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function message( $msgNum ) { |
|
| 53 | + public function message($msgNum) { |
|
| 54 | 54 | $this->connect(); |
| 55 | 55 | |
| 56 | 56 | return new IMAPMessage($this, $msgNum); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function messages( array $options = [] ) { |
|
| 59 | + public function messages(array $options = []) { |
|
| 60 | 60 | $options += [ |
| 61 | 61 | 'offset' => 0, |
| 62 | 62 | 'limit' => 0, |
@@ -68,21 +68,21 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | $messages = []; |
| 70 | 70 | $eligibles = 0; |
| 71 | - foreach ( $headers AS $n => $header ) { |
|
| 72 | - if ( preg_match('/([UN]?)\s+(\d+)\)/', $header, $match) ) { |
|
| 73 | - $unseen = (bool) trim($match[1]); |
|
| 74 | - $msgNum = (int) $match[2]; |
|
| 71 | + foreach ($headers AS $n => $header) { |
|
| 72 | + if (preg_match('/([UN]?)\s+(\d+)\)/', $header, $match)) { |
|
| 73 | + $unseen = (bool)trim($match[1]); |
|
| 74 | + $msgNum = (int)$match[2]; |
|
| 75 | 75 | |
| 76 | 76 | $eligible = $options['seen'] === null || $unseen != $options['seen']; |
| 77 | - if ( $eligible ) { |
|
| 77 | + if ($eligible) { |
|
| 78 | 78 | $eligibles++; |
| 79 | 79 | |
| 80 | - if ( $eligibles > $options['offset'] ) { |
|
| 80 | + if ($eligibles > $options['offset']) { |
|
| 81 | 81 | $messages[] = new IMAPMessage($this, $msgNum, $unseen); |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( $options['limit'] && isset($messages[$options['limit']-1]) ) { |
|
| 85 | + if ($options['limit'] && isset($messages[$options['limit']-1])) { |
|
| 86 | 86 | break; |
| 87 | 87 | } |
| 88 | 88 | } |