@@ -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 ( $this->flags ) { |
|
| 27 | - $server .= '/' . implode('/', $this->flags); |
|
| 26 | + if ($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,19 +38,19 @@ 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 messages( array $options = [] ) { |
|
| 53 | + public function messages(array $options = []) { |
|
| 54 | 54 | $options += [ |
| 55 | 55 | 'offset' => 0, |
| 56 | 56 | 'limit' => 0, |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $messages = []; |
| 64 | 64 | $eligibles = 0; |
| 65 | - foreach ( $headers AS $n => $header ) { |
|
| 66 | - if ( preg_match('/(U?)\s+(\d+)\)/', $header, $match) ) { |
|
| 65 | + foreach ($headers AS $n => $header) { |
|
| 66 | + if (preg_match('/(U?)\s+(\d+)\)/', $header, $match)) { |
|
| 67 | 67 | $unseen = (bool)trim($match[1]); |
| 68 | 68 | $msgNum = (int)$match[2]; |
| 69 | 69 | |
| 70 | 70 | $eligible = $options['seen'] === null || $unseen != $options['seen']; |
| 71 | - if ( $eligible ) { |
|
| 71 | + if ($eligible) { |
|
| 72 | 72 | $eligibles++; |
| 73 | 73 | |
| 74 | - if ( $eligibles > $options['offset'] ) { |
|
| 74 | + if ($eligibles > $options['offset']) { |
|
| 75 | 75 | $messages[] = new IMAPMessage($this, $msgNum, $header, $unseen); |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ( $options['limit'] && isset($messages[$options['limit']-1]) ) { |
|
| 79 | + if ($options['limit'] && isset($messages[$options['limit']-1])) { |
|
| 80 | 80 | break; |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -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 | |
@@ -20,30 +20,30 @@ discard block |
||
| 20 | 20 | public $HTMLBody; |
| 21 | 21 | public $attachments = []; // typeof Array<IMAPMessageAttachment> |
| 22 | 22 | |
| 23 | - public function __construct( IMAPMailbox $mailbox, $msgNumber, $header, $unseen ) { |
|
| 23 | + public function __construct(IMAPMailbox $mailbox, $msgNumber, $header, $unseen) { |
|
| 24 | 24 | $this->mailbox = $mailbox; |
| 25 | 25 | $this->msgNumber = $msgNumber; |
| 26 | 26 | $this->header = $header; |
| 27 | 27 | $this->unseen = $unseen; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - protected function flags( $flags, $clear ) { |
|
| 30 | + protected function flags($flags, $clear) { |
|
| 31 | 31 | $cb = $clear ? 'imap_clearflag_full' : 'imap_setflag_full'; |
| 32 | 32 | |
| 33 | 33 | $feedback = []; |
| 34 | - foreach ( (array)$flags AS $flag ) { |
|
| 35 | - $flag = '\\' . ucfirst($flag); |
|
| 34 | + foreach ((array)$flags AS $flag) { |
|
| 35 | + $flag = '\\'.ucfirst($flag); |
|
| 36 | 36 | $feedback[] = $cb($this->mailbox->imap(), (string)$this->msgNumber, $flag); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | return is_array($flags) ? $feedback : $feedback[0]; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function flag( $flags ) { |
|
| 42 | + public function flag($flags) { |
|
| 43 | 43 | return $this->flags($flags, false); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function unflag( $flags ) { |
|
| 46 | + public function unflag($flags) { |
|
| 47 | 47 | return $this->flags($flags, true); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function subject() { |
| 56 | - if ( empty($this->subject) ) { |
|
| 56 | + if (empty($this->subject)) { |
|
| 57 | 57 | $headers = $this->headers(); |
| 58 | 58 | |
| 59 | 59 | $subject = imap_utf8($headers->Subject); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public function headers() { |
| 68 | - if ( empty($this->headers) ) { |
|
| 68 | + if (empty($this->headers)) { |
|
| 69 | 69 | $this->headers = imap_headerinfo($this->mailbox->imap(), $this->msgNumber); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function parts() { |
| 76 | - if ( empty($this->parts) ) { |
|
| 76 | + if (empty($this->parts)) { |
|
| 77 | 77 | $structure = $this->structure(); |
| 78 | 78 | |
| 79 | 79 | // Possibilities: |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | // - HTML |
| 87 | 87 | // - CALENDAR |
| 88 | 88 | |
| 89 | - if ( empty($structure->parts) ) { |
|
| 89 | + if (empty($structure->parts)) { |
|
| 90 | 90 | $this->parts[] = new IMAPMessagePart( |
| 91 | 91 | $this, |
| 92 | 92 | $structure, |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | return $this->parts; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function allParts( $withContainers = false ) { |
|
| 110 | + public function allParts($withContainers = false) { |
|
| 111 | 111 | $parts = []; |
| 112 | 112 | $iterate = function($message) use (&$iterate, &$parts, $withContainers) { |
| 113 | - foreach ( $message->parts() as $part ) { |
|
| 114 | - if ( $part->parts() ) { |
|
| 115 | - if ( $withContainers ) { |
|
| 113 | + foreach ($message->parts() as $part) { |
|
| 114 | + if ($part->parts()) { |
|
| 115 | + if ($withContainers) { |
|
| 116 | 116 | $parts[] = $part; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -128,13 +128,13 @@ discard block |
||
| 128 | 128 | return $parts; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function part( $index ) { |
|
| 131 | + public function part($index) { |
|
| 132 | 132 | $parts = $this->parts(); |
| 133 | 133 | return @$parts[$index]; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function structure() { |
| 137 | - if ( empty($this->structure) ) { |
|
| 137 | + if (empty($this->structure)) { |
|
| 138 | 138 | $this->structure = imap_fetchstructure($this->mailbox->imap(), $this->msgNumber); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | public function content() { |
| 145 | - if ( count($this->parts()) == 1 ) { |
|
| 145 | + if (count($this->parts()) == 1) { |
|
| 146 | 146 | return $this->part(0)->content(); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -150,16 +150,16 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | public function parameters() { |
| 153 | - if ( empty($this->parameters) ) { |
|
| 153 | + if (empty($this->parameters)) { |
|
| 154 | 154 | $structure = $this->structure(); |
| 155 | 155 | |
| 156 | 156 | $this->parameters['bytes'] = @$structure->bytes; |
| 157 | 157 | |
| 158 | - foreach ((array) @$structure->parameters as $param) { |
|
| 159 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 158 | + foreach ((array)@$structure->parameters as $param) { |
|
| 159 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 160 | 160 | } |
| 161 | - foreach ((array) @$structure->dparameters as $param) { |
|
| 162 | - $this->parameters[ strtolower($param->attribute) ] = $param->value; |
|
| 161 | + foreach ((array)@$structure->dparameters as $param) { |
|
| 162 | + $this->parameters[strtolower($param->attribute)] = $param->value; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -168,16 +168,16 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | public function simpleStructure() { |
| 170 | 170 | $parts = []; |
| 171 | - foreach ( $this->allParts(true) as $part ) { |
|
| 171 | + foreach ($this->allParts(true) as $part) { |
|
| 172 | 172 | $name = ''; |
| 173 | 173 | |
| 174 | - $name .= implode('.', $part->section) . '. '; |
|
| 175 | - if ( $part->parts() ) { |
|
| 174 | + $name .= implode('.', $part->section).'. '; |
|
| 175 | + if ($part->parts()) { |
|
| 176 | 176 | $name .= '*'; |
| 177 | 177 | } |
| 178 | 178 | $name .= $part->subtype; |
| 179 | - if ( $bytes = $part->parameter('bytes') ) { |
|
| 180 | - $name .= ' (' . $bytes . ')'; |
|
| 179 | + if ($bytes = $part->parameter('bytes')) { |
|
| 180 | + $name .= ' ('.$bytes.')'; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | $parts[] = $name; |