@@ -20,6 +20,10 @@ discard block |
||
| 20 | 20 | public $HTMLBody; |
| 21 | 21 | public $attachments = array(); // typeof Array<IMAPMessageAttachment> |
| 22 | 22 | |
| 23 | + /** |
|
| 24 | + * @param integer $msgNumber |
|
| 25 | + * @param boolean $unseen |
|
| 26 | + */ |
|
| 23 | 27 | public function __construct( IMAPMailbox $mailbox, $msgNumber, $header, $unseen ) { |
| 24 | 28 | $this->mailbox = $mailbox; |
| 25 | 29 | $this->msgNumber = $msgNumber; |
@@ -27,6 +31,9 @@ discard block |
||
| 27 | 31 | $this->unseen = $unseen; |
| 28 | 32 | } |
| 29 | 33 | |
| 34 | + /** |
|
| 35 | + * @param boolean $clear |
|
| 36 | + */ |
|
| 30 | 37 | protected function flags( $flags, $clear ) { |
| 31 | 38 | $cb = $clear ? 'imap_clearflag_full' : 'imap_setflag_full'; |
| 32 | 39 | |
@@ -128,6 +135,9 @@ discard block |
||
| 128 | 135 | return $parts; |
| 129 | 136 | } |
| 130 | 137 | |
| 138 | + /** |
|
| 139 | + * @param integer $index |
|
| 140 | + */ |
|
| 131 | 141 | public function part( $index ) { |
| 132 | 142 | $parts = $this->parts(); |
| 133 | 143 | return @$parts[$index]; |
@@ -20,30 +20,30 @@ discard block |
||
| 20 | 20 | public $HTMLBody; |
| 21 | 21 | public $attachments = array(); // 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 = array(); |
| 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 ( !$this->subject ) { |
|
| 56 | + if (!$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 ( !$this->headers ) { |
|
| 68 | + if (!$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 ( !$this->parts ) { |
|
| 76 | + if (!$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 ( !$this->structure ) { |
|
| 137 | + if (!$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 | $parts = $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 ( !$this->parameters ) { |
|
| 153 | + if (!$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; |
@@ -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 | } |
@@ -104,6 +104,9 @@ |
||
| 104 | 104 | return $this->decode($body); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | + /** |
|
| 108 | + * @param string $content |
|
| 109 | + */ |
|
| 107 | 110 | public function decode( $content ) { |
| 108 | 111 | return quoted_printable_decode($content); |
| 109 | 112 | } |
@@ -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 ( !$this->parameters ) { |
|
| 76 | + if (!$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 | |
@@ -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 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | foreach ($messages as $message) { |
| 20 | 20 | echo "\n\n"; |
| 21 | - echo '[' . $message->msgNumber . '] [' . date('Y-m-d H:i:s', $message->utc()) . '] ' . $message->subject() . "\n"; |
|
| 21 | + echo '['.$message->msgNumber.'] ['.date('Y-m-d H:i:s', $message->utc()).'] '.$message->subject()."\n"; |
|
| 22 | 22 | |
| 23 | 23 | echo "\n"; |
| 24 | 24 | // print_r($message->headers()); |
@@ -20,29 +20,29 @@ discard block |
||
| 20 | 20 | $headers = imap_headers($mbox); |
| 21 | 21 | print_r($headers); |
| 22 | 22 | |
| 23 | -foreach ( $headers AS $hd ) { |
|
| 24 | - if ( preg_match('/(\d+)\)/', $hd, $match) ) { |
|
| 23 | +foreach ($headers AS $hd) { |
|
| 24 | + if (preg_match('/(\d+)\)/', $hd, $match)) { |
|
| 25 | 25 | $msgNum = $match[1]; |
| 26 | 26 | |
| 27 | 27 | $hd = imap_headerinfo($mbox, $msgNum); |
| 28 | 28 | $new = !!trim($hd->Unseen); |
| 29 | 29 | |
| 30 | - if ( $new ) { |
|
| 30 | + if ($new) { |
|
| 31 | 31 | |
| 32 | 32 | // subject -- should contain #code# |
| 33 | 33 | $title = get_plain_text_subject($mbox, $msgNum, $hd); |
| 34 | 34 | $code = preg_match('/#(\d+)#$/', $title, $match) ? (int)$match[1] : 0; |
| 35 | -echo $title . "\n"; |
|
| 35 | +echo $title."\n"; |
|
| 36 | 36 | |
| 37 | 37 | // body -- get only last part (no conversation history) |
| 38 | 38 | $attachments = array(); |
| 39 | 39 | $full_body = get_plain_text_body($mbox, $msgNum, $attachments); |
| 40 | 40 | $body = get_last_body_part($full_body); |
| 41 | - if ( $attachments ) { |
|
| 42 | - $body .= "\n\n== Attachments:\n* " . implode("\n* ", $attachments); |
|
| 41 | + if ($attachments) { |
|
| 42 | + $body .= "\n\n== Attachments:\n* ".implode("\n* ", $attachments); |
|
| 43 | 43 | } |
| 44 | 44 | #echo $full_body . "\n===================================================\n"; |
| 45 | -echo $body . "\n\n===================================================\n===================================================\n===================================================\n"; |
|
| 45 | +echo $body."\n\n===================================================\n===================================================\n===================================================\n"; |
|
| 46 | 46 | |
| 47 | 47 | flush(); |
| 48 | 48 | } |
@@ -55,49 +55,49 @@ discard block |
||
| 55 | 55 | imap_close($mbox, CL_EXPUNGE); |
| 56 | 56 | |
| 57 | 57 | |
| 58 | -function get_last_body_part( $body ) { |
|
| 58 | +function get_last_body_part($body) { |
|
| 59 | 59 | $lines = preg_split('/(\r\n|\r|\n)/', $body); |
| 60 | 60 | |
| 61 | 61 | $body = ''; |
| 62 | - foreach ( $lines AS $line ) { |
|
| 63 | - if ( '>' == substr($line, 0, 1) || '-----' == substr($line, 0, 5) || '_____' == substr($line, 0, 5) ) { |
|
| 62 | + foreach ($lines AS $line) { |
|
| 63 | + if ('>' == substr($line, 0, 1) || '-----' == substr($line, 0, 5) || '_____' == substr($line, 0, 5)) { |
|
| 64 | 64 | break; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $body .= $line . "\r\n"; |
|
| 67 | + $body .= $line."\r\n"; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | return trim($body); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -function get_plain_text_subject( $mbox, $msgNum, $headers = null ) { |
|
| 73 | +function get_plain_text_subject($mbox, $msgNum, $headers = null) { |
|
| 74 | 74 | $headers or $headers = imap_headerinfo($mbox, $msgNum); |
| 75 | 75 | |
| 76 | 76 | $subjectParts = imap_mime_header_decode($headers->Subject); |
| 77 | 77 | $subject = ''; |
| 78 | - foreach ( $subjectParts AS $p ) { |
|
| 78 | + foreach ($subjectParts AS $p) { |
|
| 79 | 79 | $subject .= $p->text; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return trim($subject); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -function get_plain_text_body( $mbox, $msgNum, &$attachments = array() ) { |
|
| 85 | +function get_plain_text_body($mbox, $msgNum, &$attachments = array()) { |
|
| 86 | 86 | $structure = imap_fetchstructure($mbox, $msgNum); |
| 87 | 87 | |
| 88 | 88 | // only plain text |
| 89 | - if ( 'PLAIN' == $structure->subtype ) { |
|
| 89 | + if ('PLAIN' == $structure->subtype) { |
|
| 90 | 90 | return trim(imap_qprint(imap_body($mbox, $msgNum))); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( isset($structure->parts) ) { |
|
| 93 | + if (isset($structure->parts)) { |
|
| 94 | 94 | // get attachments |
| 95 | - foreach ( $structure->parts AS $partNum => $part ) { |
|
| 96 | - if ( in_array($part->subtype, array('JPEG', 'PNG', 'GIF')) ) { |
|
| 95 | + foreach ($structure->parts AS $partNum => $part) { |
|
| 96 | + if (in_array($part->subtype, array('JPEG', 'PNG', 'GIF'))) { |
|
| 97 | 97 | // oeh an image |
| 98 | - $name = 'image-from-email-'.$msgNum.'.' . strtolower($part->subtype); |
|
| 99 | - foreach ( $part->parameters AS $param ) { |
|
| 100 | - if ( 'NAME' == $param->attribute ) { |
|
| 98 | + $name = 'image-from-email-'.$msgNum.'.'.strtolower($part->subtype); |
|
| 99 | + foreach ($part->parameters AS $param) { |
|
| 100 | + if ('NAME' == $param->attribute) { |
|
| 101 | 101 | $name = $param->value; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -107,15 +107,15 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // multipart (probably) -- look for plain text part |
| 110 | - foreach ( $structure->parts AS $partNum => $part ) { |
|
| 111 | - if ( 'PLAIN' == $part->subtype ) { |
|
| 110 | + foreach ($structure->parts AS $partNum => $part) { |
|
| 111 | + if ('PLAIN' == $part->subtype) { |
|
| 112 | 112 | $body = imap_fetchbody($mbox, $msgNum, (string)($partNum+1)); |
| 113 | 113 | |
| 114 | 114 | return trim($body); |
| 115 | 115 | } |
| 116 | - else if ( 'ALTERNATIVE' == $part->subtype && isset($part->parts) ) { |
|
| 117 | - foreach ( $part->parts AS $subPartNum => $subPart ) { |
|
| 118 | - if ( 'PLAIN' == $subPart->subtype ) { |
|
| 116 | + else if ('ALTERNATIVE' == $part->subtype && isset($part->parts)) { |
|
| 117 | + foreach ($part->parts AS $subPartNum => $subPart) { |
|
| 118 | + if ('PLAIN' == $subPart->subtype) { |
|
| 119 | 119 | $body = imap_fetchbody($mbox, $msgNum, ($partNum+1).'.'.($subPartNum+1)); |
| 120 | 120 | |
| 121 | 121 | return trim($body); |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -spl_autoload_register(function( $class ) { |
|
| 3 | +spl_autoload_register(function($class) { |
|
| 4 | 4 | $ns = explode('\\', $class); |
| 5 | 5 | $lib = array_splice($ns, 0, 2); |
| 6 | - if ( $lib == array('rdx', 'imap') ) { |
|
| 7 | - if ( file_exists($file = __DIR__ . '/src/' . implode('/', $ns) . '.php') ) { |
|
| 6 | + if ($lib == array('rdx', 'imap')) { |
|
| 7 | + if (file_exists($file = __DIR__.'/src/'.implode('/', $ns).'.php')) { |
|
| 8 | 8 | include $file; |
| 9 | 9 | } |
| 10 | 10 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | protected $imap; // IMAP resource |
| 13 | 13 | |
| 14 | - public function __construct( $server, $username, $password, $mailbox = 'INBOX', $flags = array() ) { |
|
| 14 | + public function __construct($server, $username, $password, $mailbox = 'INBOX', $flags = array()) { |
|
| 15 | 15 | $this->server = $server; |
| 16 | 16 | $this->username = $username; |
| 17 | 17 | $this->password = $password; |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function connect() { |
| 25 | - if ( !$this->imap ) { |
|
| 25 | + if (!$this->imap) { |
|
| 26 | 26 | $server = $this->server; |
| 27 | - if ( $this->flags ) { |
|
| 28 | - $server .= '/' . implode('/', $this->flags); |
|
| 27 | + if ($this->flags) { |
|
| 28 | + $server .= '/'.implode('/', $this->flags); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $mailbox = '{'.$server.'}'.$this->mailbox; |
@@ -39,19 +39,19 @@ discard block |
||
| 39 | 39 | return $this->imap; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function headers( $newestFirst = true ) { |
|
| 42 | + public function headers($newestFirst = true) { |
|
| 43 | 43 | $this->connect(); |
| 44 | 44 | |
| 45 | 45 | $headers = imap_headers($this->imap()); |
| 46 | 46 | |
| 47 | - if ( $newestFirst ) { |
|
| 47 | + if ($newestFirst) { |
|
| 48 | 48 | $headers = array_reverse($headers); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return $headers; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function messages( array $options = [] ) { |
|
| 54 | + public function messages(array $options = []) { |
|
| 55 | 55 | $options += array( |
| 56 | 56 | 'offset' => 0, |
| 57 | 57 | 'limit' => 0, |
@@ -63,21 +63,21 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $messages = array(); |
| 65 | 65 | $eligibles = 0; |
| 66 | - foreach ( $headers AS $n => $header ) { |
|
| 67 | - if ( preg_match('/(U?)\s+(\d+)\)/', $header, $match) ) { |
|
| 66 | + foreach ($headers AS $n => $header) { |
|
| 67 | + if (preg_match('/(U?)\s+(\d+)\)/', $header, $match)) { |
|
| 68 | 68 | $unseen = (bool)trim($match[1]); |
| 69 | 69 | $msgNum = (int)$match[2]; |
| 70 | 70 | |
| 71 | 71 | $eligible = $options['seen'] === null || $unseen != $options['seen']; |
| 72 | - if ( $eligible ) { |
|
| 72 | + if ($eligible) { |
|
| 73 | 73 | $eligibles++; |
| 74 | 74 | |
| 75 | - if ( $eligibles > $options['offset'] ) { |
|
| 75 | + if ($eligibles > $options['offset']) { |
|
| 76 | 76 | $messages[] = new IMAPMessage($this, $msgNum, $header, $unseen); |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( $options['limit'] && isset($messages[$options['limit']-1]) ) { |
|
| 80 | + if ($options['limit'] && isset($messages[$options['limit']-1])) { |
|
| 81 | 81 | break; |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -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 | |