@@ -9,6 +9,12 @@ discard block |
||
9 | 9 | |
10 | 10 | protected $resource; // imap_open() resource |
11 | 11 | |
12 | + /** |
|
13 | + * @param string $server |
|
14 | + * @param string $username |
|
15 | + * @param string $password |
|
16 | + * @param string $mailbox |
|
17 | + */ |
|
12 | 18 | public function open( $server, $username, $password, $mailbox, array $flags ) { |
13 | 19 | if ( !empty($flags) ) { |
14 | 20 | $server .= '/' . implode('/', $flags); |
@@ -34,6 +40,9 @@ discard block |
||
34 | 40 | return imap_utf8($string); |
35 | 41 | } |
36 | 42 | |
43 | + /** |
|
44 | + * @param integer $msgNumber |
|
45 | + */ |
|
37 | 46 | public function headerinfo( $msgNumber ) { |
38 | 47 | return $this->iteratorToLowercaseArray(imap_headerinfo($this->resource, $msgNumber)); |
39 | 48 | } |
@@ -46,10 +55,17 @@ discard block |
||
46 | 55 | return imap_setflag_full($this->resource, $msgNumber, $flag); |
47 | 56 | } |
48 | 57 | |
58 | + /** |
|
59 | + * @param integer $msgNumber |
|
60 | + */ |
|
49 | 61 | public function fetchstructure( $msgNumber ) { |
50 | 62 | return imap_fetchstructure($this->resource, $msgNumber); |
51 | 63 | } |
52 | 64 | |
65 | + /** |
|
66 | + * @param integer $msgNumber |
|
67 | + * @param string $section |
|
68 | + */ |
|
53 | 69 | public function fetchbody( $msgNumber, $section ) { |
54 | 70 | return quoted_printable_decode(imap_fetchbody($this->resource, $msgNumber, $section, FT_PEEK)); |
55 | 71 | } |
@@ -58,6 +74,9 @@ discard block |
||
58 | 74 | return imap_expunge($this->resource); |
59 | 75 | } |
60 | 76 | |
77 | + /** |
|
78 | + * @param integer $msgNumber |
|
79 | + */ |
|
61 | 80 | public function delete( $msgNumber ) { |
62 | 81 | return imap_delete($this->resource, $msgNumber); |
63 | 82 | } |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | |
10 | 10 | protected $resource; // imap_open() resource |
11 | 11 | |
12 | - public function open( $server, $username, $password, $mailbox, array $flags ) { |
|
13 | - if ( !empty($flags) ) { |
|
14 | - $server .= '/' . implode('/', $flags); |
|
12 | + public function open($server, $username, $password, $mailbox, array $flags) { |
|
13 | + if (!empty($flags)) { |
|
14 | + $server .= '/'.implode('/', $flags); |
|
15 | 15 | } |
16 | 16 | |
17 | - $mailbox = '{' . $server . '}' . $mailbox; |
|
17 | + $mailbox = '{'.$server.'}'.$mailbox; |
|
18 | 18 | $this->resource = @imap_open($mailbox, $username, $password); |
19 | - if ( !$this->resource ) { |
|
19 | + if (!$this->resource) { |
|
20 | 20 | $error = imap_last_error(); |
21 | 21 | imap_errors(); |
22 | 22 | imap_alerts(); |
@@ -30,27 +30,27 @@ discard block |
||
30 | 30 | return imap_headers($this->resource); |
31 | 31 | } |
32 | 32 | |
33 | - public function utf8( $string ) { |
|
33 | + public function utf8($string) { |
|
34 | 34 | return imap_utf8($string); |
35 | 35 | } |
36 | 36 | |
37 | - public function headerinfo( $msgNumber ) { |
|
37 | + public function headerinfo($msgNumber) { |
|
38 | 38 | return $this->iteratorToLowercaseArray(imap_headerinfo($this->resource, $msgNumber)); |
39 | 39 | } |
40 | 40 | |
41 | - public function unflag( $msgNumber, $flag ) { |
|
41 | + public function unflag($msgNumber, $flag) { |
|
42 | 42 | return imap_clearflag_full($this->resource, $msgNumber, $flag); |
43 | 43 | } |
44 | 44 | |
45 | - public function flag( $msgNumber, $flag ) { |
|
45 | + public function flag($msgNumber, $flag) { |
|
46 | 46 | return imap_setflag_full($this->resource, $msgNumber, $flag); |
47 | 47 | } |
48 | 48 | |
49 | - public function fetchstructure( $msgNumber ) { |
|
49 | + public function fetchstructure($msgNumber) { |
|
50 | 50 | return imap_fetchstructure($this->resource, $msgNumber); |
51 | 51 | } |
52 | 52 | |
53 | - public function fetchbody( $msgNumber, $section ) { |
|
53 | + public function fetchbody($msgNumber, $section) { |
|
54 | 54 | return quoted_printable_decode(imap_fetchbody($this->resource, $msgNumber, $section, FT_PEEK)); |
55 | 55 | } |
56 | 56 | |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | return imap_expunge($this->resource); |
59 | 59 | } |
60 | 60 | |
61 | - public function delete( $msgNumber ) { |
|
61 | + public function delete($msgNumber) { |
|
62 | 62 | return imap_delete($this->resource, $msgNumber); |
63 | 63 | } |
64 | 64 | |
65 | 65 | public function mailboxmsginfo() { |
66 | - return (object) $this->iteratorToLowercaseArray(imap_mailboxmsginfo($this->resource)); |
|
66 | + return (object)$this->iteratorToLowercaseArray(imap_mailboxmsginfo($this->resource)); |
|
67 | 67 | } |
68 | 68 | |
69 | - protected function iteratorToLowercaseArray( $iterator ) { |
|
69 | + protected function iteratorToLowercaseArray($iterator) { |
|
70 | 70 | $data = []; |
71 | - foreach ( $iterator as $name => $value ) { |
|
72 | - $data[ strtolower($name) ] = $value; |
|
71 | + foreach ($iterator as $name => $value) { |
|
72 | + $data[strtolower($name)] = $value; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $data; |
@@ -5,7 +5,7 @@ |
||
5 | 5 | interface IMAPTransportInterface { |
6 | 6 | |
7 | 7 | /** |
8 | - * @return rdx\imap\IMAPTransportInterface |
|
8 | + * @return IMAPTransport |
|
9 | 9 | */ |
10 | 10 | public function open( $server, $username, $password, $mailbox, array $flags ); |
11 | 11 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @return rdx\imap\IMAPTransportInterface |
9 | 9 | */ |
10 | - public function open( $server, $username, $password, $mailbox, array $flags ); |
|
10 | + public function open($server, $username, $password, $mailbox, array $flags); |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @return array<string> |
@@ -17,32 +17,32 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public function utf8( $string ); |
|
20 | + public function utf8($string); |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @return array<mixed> |
24 | 24 | */ |
25 | - public function headerinfo( $msgNumber ); |
|
25 | + public function headerinfo($msgNumber); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @return bool |
29 | 29 | */ |
30 | - public function unflag( $msgNumber, $flag ); |
|
30 | + public function unflag($msgNumber, $flag); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function flag( $msgNumber, $flag ); |
|
35 | + public function flag($msgNumber, $flag); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @return object<mixed> |
39 | 39 | */ |
40 | - public function fetchstructure( $msgNumber ); |
|
40 | + public function fetchstructure($msgNumber); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function fetchbody( $msgNumber, $section ); |
|
45 | + public function fetchbody($msgNumber, $section); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @return bool |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @return bool |
54 | 54 | */ |
55 | - public function delete( $msgNumber ); |
|
55 | + public function delete($msgNumber); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return object |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | protected $message; // rdx\imap\IMAPMessage |
14 | 14 | protected $skippedParts = []; // Array<stdClass> |
15 | 15 | |
16 | - public function __construct( IMAPMessage $message, $structure, array $section ) { |
|
16 | + public function __construct(IMAPMessage $message, $structure, array $section) { |
|
17 | 17 | $this->message = $message; |
18 | 18 | $this->structure = $structure; |
19 | 19 | $this->section = $section; |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public function parts() { |
26 | - if ( empty($this->parts) && !empty($this->structure()->parts) ) { |
|
26 | + if (empty($this->parts) && !empty($this->structure()->parts)) { |
|
27 | 27 | $parts = $this->structure()->parts; |
28 | - while ( count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts) ) { |
|
28 | + while (count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts)) { |
|
29 | 29 | $this->skippedParts[] = $parts[0]; |
30 | 30 | $parts = $parts[0]->parts; |
31 | 31 | } |
32 | 32 | |
33 | - foreach ( $parts as $n => $part ) { |
|
33 | + foreach ($parts as $n => $part) { |
|
34 | 34 | $this->parts[] = $this->message()->createMessagePart( |
35 | 35 | $part, |
36 | 36 | array_merge($this->section(), [$n+1]) |
@@ -17,33 +17,33 @@ discard block |
||
17 | 17 | protected $subject = ''; |
18 | 18 | protected $subtype = ''; |
19 | 19 | |
20 | - public function __construct( IMAPMailbox $mailbox, $msgNumber, $unseen = null ) { |
|
20 | + public function __construct(IMAPMailbox $mailbox, $msgNumber, $unseen = null) { |
|
21 | 21 | $this->mailbox = $mailbox; |
22 | 22 | $this->msgNumber = $msgNumber; |
23 | 23 | $this->unseen = $unseen; |
24 | 24 | |
25 | - if ( $unseen === null ) { |
|
26 | - $this->unseen = (bool) trim($this->header('unseen')); |
|
25 | + if ($unseen === null) { |
|
26 | + $this->unseen = (bool)trim($this->header('unseen')); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | - protected function flags( $flags, $clear ) { |
|
30 | + protected function flags($flags, $clear) { |
|
31 | 31 | $cb = [$this->mailbox()->imap(), $clear ? 'unflag' : 'flag']; |
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[] = call_user_func($cb, $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 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | public function subject() { |
55 | - if ( empty($this->subject) ) { |
|
55 | + if (empty($this->subject)) { |
|
56 | 56 | $subject = $this->mailbox()->imap()->utf8($this->header('subject')); |
57 | 57 | $this->subject = trim($subject); |
58 | 58 | } |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | public function headers() { |
64 | - if ( empty($this->headers) ) { |
|
64 | + if (empty($this->headers)) { |
|
65 | 65 | $this->headers = $this->mailbox()->imap()->headerinfo($this->msgNumber); |
66 | 66 | } |
67 | 67 | |
68 | 68 | return $this->headers; |
69 | 69 | } |
70 | 70 | |
71 | - public function header( $name ) { |
|
71 | + public function header($name) { |
|
72 | 72 | $headers = $this->headers(); |
73 | - return @$headers[ strtolower($name) ]; |
|
73 | + return @$headers[strtolower($name)]; |
|
74 | 74 | } |
75 | 75 | |
76 | - public function createMessagePart( $structure, $section ) { |
|
76 | + public function createMessagePart($structure, $section) { |
|
77 | 77 | return new IMAPMessagePart($this, $structure, $section); |
78 | 78 | } |
79 | 79 | |
80 | 80 | public function parts() { |
81 | - if ( empty($this->parts) ) { |
|
81 | + if (empty($this->parts)) { |
|
82 | 82 | $structure = $this->structure(); |
83 | 83 | |
84 | 84 | // Possibilities: |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | // - CALENDAR |
93 | 93 | // - JPEG |
94 | 94 | |
95 | - if ( empty($structure->parts) ) { |
|
95 | + if (empty($structure->parts)) { |
|
96 | 96 | $this->parts[] = $this->createMessagePart( |
97 | 97 | $structure, |
98 | 98 | [1] |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | public function structure() { |
115 | - if ( empty($this->structure) ) { |
|
115 | + if (empty($this->structure)) { |
|
116 | 116 | $this->structure = $this->mailbox()->imap()->fetchstructure($this->msgNumber); |
117 | 117 | } |
118 | 118 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | |
122 | 122 | public function subtype() { |
123 | - if ( empty($this->subtype) ) { |
|
123 | + if (empty($this->subtype)) { |
|
124 | 124 | $structure = $this->structure(); |
125 | 125 | $this->subtype = @$structure->subtype ?: ''; |
126 | 126 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | public function content() { |
136 | - if ( count($this->parts()) == 1 ) { |
|
136 | + if (count($this->parts()) == 1) { |
|
137 | 137 | return $this->part(0)->content(); |
138 | 138 | } |
139 | 139 | |
@@ -146,16 +146,16 @@ discard block |
||
146 | 146 | |
147 | 147 | public function simpleStructure() { |
148 | 148 | $parts = []; |
149 | - foreach ( $this->allParts(true) as $part ) { |
|
149 | + foreach ($this->allParts(true) as $part) { |
|
150 | 150 | $name = ''; |
151 | 151 | |
152 | - $name .= implode('.', $part->section()) . '. '; |
|
153 | - if ( $part->parts() ) { |
|
152 | + $name .= implode('.', $part->section()).'. '; |
|
153 | + if ($part->parts()) { |
|
154 | 154 | $name .= '*'; |
155 | 155 | } |
156 | 156 | $name .= $part->subtype(); |
157 | - if ( $bytes = $part->parameter('bytes') ) { |
|
158 | - $name .= ' (' . $bytes . ')'; |
|
157 | + if ($bytes = $part->parameter('bytes')) { |
|
158 | + $name .= ' ('.$bytes.')'; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $parts[] = $name; |