Completed
Push — master ( 4995a3...c888a3 )
by Malte
01:44
created

LegacyProtocol   F

Complexity

Total Complexity 64

Size/Duplication

Total Lines 505
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 64
eloc 120
c 1
b 0
f 1
dl 0
loc 505
rs 3.28

39 Methods

Rating   Name   Duplication   Size   Complexity  
A getUid() 0 10 3
A __destruct() 0 2 1
A store() 0 14 4
A overview() 0 2 1
A copyMessage() 0 2 1
A getCapabilities() 0 2 1
A getAddress() 0 14 4
A folders() 0 14 3
A __construct() 0 2 1
A connected() 0 2 1
A authenticate() 0 2 1
A getMessageNumber() 0 2 1
A appendMessage() 0 9 3
A login() 0 24 5
A headers() 0 3 1
A selectFolder() 0 3 1
A content() 0 3 1
A connect() 0 7 3
A logout() 0 5 2
A flags() 0 12 6
A examineFolder() 0 12 2
A createFolder() 0 2 1
A moveMessage() 0 2 1
A subscribeFolder() 0 2 1
A getQuotaRoot() 0 2 1
A getProtocol() 0 2 1
A expunge() 0 2 1
A noop() 0 2 1
A disableDebug() 0 2 1
A getQuota() 0 2 1
A deleteFolder() 0 2 1
A setProtocol() 0 3 1
A idle() 0 2 1
A done() 0 2 1
A search() 0 2 1
A renameFolder() 0 2 1
A decodeFolderName() 0 3 1
A enableDebug() 0 2 1
A unsubscribeFolder() 0 2 1

How to fix   Complexity   

Complex Class

Complex classes like LegacyProtocol often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LegacyProtocol, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*
3
* File: LegacyProtocol.php
4
* Category: Protocol
5
* Author: M.Goldenbaum
6
* Created: 16.09.20 18:27
7
* Updated: -
8
*
9
* Description:
10
*  -
11
*/
12
13
namespace Webklex\PHPIMAP\Connection\Protocols;
14
15
use Webklex\PHPIMAP\ClientManager;
16
use Webklex\PHPIMAP\Exceptions\AuthFailedException;
17
use Webklex\PHPIMAP\Exceptions\MethodNotSupportedException;
18
use Webklex\PHPIMAP\Exceptions\RuntimeException;
19
use Webklex\PHPIMAP\IMAP;
20
21
/**
22
 * Class LegacyProtocol
23
 *
24
 * @package Webklex\PHPIMAP\Connection\Protocols
25
 */
26
class LegacyProtocol extends Protocol implements ProtocolInterface {
27
28
    protected $protocol = "imap";
29
    protected $host = null;
30
    protected $port = null;
31
    protected $encryption = null;
32
33
    /**
34
     * Imap constructor.
35
     * @param bool $cert_validation set to false to skip SSL certificate validation
36
     */
37
    public function __construct($cert_validation = true) {
38
        $this->setCertValidation($cert_validation);
39
    }
40
41
    /**
42
     * Public destructor
43
     */
44
    public function __destruct() {
45
        $this->logout();
46
    }
47
48
    /**
49
     * Save the information for a nw connection
50
     * @param string $host
51
     * @param null $port
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $port is correct as it would always require null to be passed?
Loading history...
52
     * @param bool $encryption
53
     */
54
    public function connect($host, $port = null, $encryption = false) {
55
        if ($port === null) {
0 ignored issues
show
introduced by
The condition $port === null is always true.
Loading history...
56
            $port = $encryption == "ssl" ? 995 : 110;
57
        }
58
        $this->host = $host;
59
        $this->port = $port;
60
        $this->encryption = $encryption;
61
    }
62
63
    /**
64
     * Login to a new session.
65
     * @param string $user username
66
     * @param string $password password
67
     *
68
     * @return bool
69
     * @throws AuthFailedException
70
     */
71
    public function login($user, $password) {
72
        try {
73
            $this->stream = \imap_open(
74
                $this->getAddress(),
75
                $user,
76
                $password,
77
                IMAP::OP_READONLY,
78
                $attempts = 3,
79
                ClientManager::get('options.open')
80
            );
81
        } catch (\ErrorException $e) {
82
            $errors = \imap_errors();
83
            $message = $e->getMessage().'. '.implode("; ", (is_array($errors) ? $errors : array()));
0 ignored issues
show
introduced by
The condition is_array($errors) is always true.
Loading history...
84
85
            throw new AuthFailedException($message);
86
        }
87
88
        if(!$this->stream) {
89
            $errors = \imap_errors();
90
            $message = implode("; ", (is_array($errors) ? $errors : array()));
0 ignored issues
show
introduced by
The condition is_array($errors) is always true.
Loading history...
91
            throw new AuthFailedException($message);
92
        }
93
94
        return !$this->stream;
95
    }
96
97
    /**
98
     * Authenticate your current session.
99
     * @param string $user username
100
     * @param string $token access token
101
     *
102
     * @return bool
103
     * @throws AuthFailedException
104
     */
105
    public function authenticate($user, $token) {
106
        return $this->login($user, $token);
107
    }
108
109
    /**
110
     * Get full address of mailbox.
111
     *
112
     * @return string
113
     */
114
    protected function getAddress() {
115
        $address = "{".$this->host.":".$this->port."/".$this->protocol;
116
        if (!$this->cert_validation) {
117
            $address .= '/novalidate-cert';
118
        }
119
        if (in_array($this->encryption,['tls', 'notls', 'ssl'])) {
120
            $address .= '/'.$this->encryption;
121
        } elseif ($this->encryption === "starttls") {
122
            $address .= '/tls';
123
        }
124
125
        $address .= '}';
126
127
        return $address;
128
    }
129
130
    /**
131
     * Logout of the current session
132
     *
133
     * @return bool success
134
     */
135
    public function logout() {
136
        if ($this->stream) {
137
            return \imap_close($this->stream, IMAP::CL_EXPUNGE);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type true; however, parameter $imap_stream of imap_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
            return \imap_close(/** @scrutinizer ignore-type */ $this->stream, IMAP::CL_EXPUNGE);
Loading history...
138
        }
139
        return false;
140
    }
141
142
    /**
143
     * Check if the current session is connected
144
     *
145
     * @return bool
146
     */
147
    public function connected(){
148
        return !$this->stream;
149
    }
150
151
    /**
152
     * Get an array of available capabilities
153
     *
154
     * @throws MethodNotSupportedException
155
     */
156
    public function getCapabilities() {
157
        throw new MethodNotSupportedException();
158
    }
159
160
    /**
161
     * Change the current folder
162
     * @param string $folder change to this folder
163
     *
164
     * @return bool|array see examineOrselect()
165
     * @throws RuntimeException
166
     */
167
    public function selectFolder($folder = 'INBOX') {
168
        \imap_reopen($this->stream, $folder, IMAP::OP_READONLY, 3);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_reopen() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

168
        \imap_reopen(/** @scrutinizer ignore-type */ $this->stream, $folder, IMAP::OP_READONLY, 3);
Loading history...
169
        return $this->examineFolder($folder);
170
    }
171
172
    /**
173
     * Examine a given folder
174
     * @param string $folder examine this folder
175
     *
176
     * @return bool|array see examineOrselect()
177
     * @throws RuntimeException
178
     */
179
    public function examineFolder($folder = 'INBOX') {
180
        if (strpos($folder, ".") === 0) {
181
            throw new RuntimeException("Segmentation fault prevented. Folders starts with an illegal char '.'.");
182
        }
183
        $folder = $this->getAddress().$folder;
184
        $status = \imap_status($this->stream, $folder, IMAP::SA_ALL);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_status() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

184
        $status = \imap_status(/** @scrutinizer ignore-type */ $this->stream, $folder, IMAP::SA_ALL);
Loading history...
185
        return [
186
            "flags" => [],
187
            "exists" => $status->messages,
188
            "recent" => $status->recent,
189
            "unseen" => $status->unseen,
190
            "uidnext" => $status->uidnext,
191
        ];
192
    }
193
194
    /**
195
     * Fetch message content
196
     * @param array|int $uids
197
     * @param string $rfc
198
     *
199
     * @return array
200
     */
201
    public function content($uids, $rfc = "RFC822") {
202
        $content = \imap_fetchbody($this->stream, $uids[0], "", IMAP::FT_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_fetchbody() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

202
        $content = \imap_fetchbody(/** @scrutinizer ignore-type */ $this->stream, $uids[0], "", IMAP::FT_UID);
Loading history...
203
        return [$uids[0] => $content];
204
    }
205
206
    /**
207
     * Fetch message headers
208
     * @param array|int $uids
209
     * @param string $rfc
210
     *
211
     * @return array
212
     */
213
    public function headers($uids, $rfc = "RFC822"){
214
        $headers = \imap_fetchheader($this->stream, $uids[0], IMAP::FT_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_fetchheader() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

214
        $headers = \imap_fetchheader(/** @scrutinizer ignore-type */ $this->stream, $uids[0], IMAP::FT_UID);
Loading history...
215
        return [$uids[0] => $headers];
216
    }
217
218
    /**
219
     * Fetch message flags
220
     * @param array|int $uids
221
     *
222
     * @return array
223
     */
224
    public function flags($uids){
225
        $flags = \imap_fetch_overview($this->stream, $uids[0], IMAP::FT_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_fetch_overview() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

225
        $flags = \imap_fetch_overview(/** @scrutinizer ignore-type */ $this->stream, $uids[0], IMAP::FT_UID);
Loading history...
226
        $result = [];
227
        if (is_array($flags) && isset($flags[0])) {
228
            $flags = (array) $flags[0];
229
            foreach($flags as $flag => $value) {
230
                if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false){
231
                    $result[] = "\\".ucfirst($flag);
232
                }
233
            }
234
        }
235
        return [$uids[0] => $result];
236
    }
237
238
    /**
239
     * Get uid for a given id
240
     * @param int|null $id message number
241
     *
242
     * @return array|string message number for given message or all messages as array
243
     */
244
    public function getUid($id = null) {
245
        if ($id === null) {
246
            $overview = $this->overview("1:*");
247
            $uids = [];
248
            foreach($overview as $set){
249
                $uids[$set->msgno] = $set->uid;
250
            }
251
            return $uids;
252
        }
253
        return \imap_uid($this->stream, $id);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_uid() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

253
        return \imap_uid(/** @scrutinizer ignore-type */ $this->stream, $id);
Loading history...
254
    }
255
256
    /**
257
     * Get a message number for a uid
258
     * @param string $id uid
259
     *
260
     * @return int message number
261
     */
262
    public function getMessageNumber($id) {
263
        return \imap_msgno($this->stream, $id);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_msgno() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

263
        return \imap_msgno(/** @scrutinizer ignore-type */ $this->stream, $id);
Loading history...
Bug introduced by
$id of type string is incompatible with the type integer expected by parameter $uid of imap_msgno(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

263
        return \imap_msgno($this->stream, /** @scrutinizer ignore-type */ $id);
Loading history...
264
    }
265
266
    /**
267
     * Get a message number for a uid
268
     * @param string $sequence uid sequence
269
     *
270
     * @return array
271
     */
272
    public function overview($sequence) {
273
        return \imap_fetch_overview($this->stream, $sequence);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_fetch_overview() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

273
        return \imap_fetch_overview(/** @scrutinizer ignore-type */ $this->stream, $sequence);
Loading history...
274
    }
275
276
    /**
277
     * Get a list of available folders
278
     * @param string $reference mailbox reference for list
279
     * @param string $folder mailbox name match with wildcards
280
     *
281
     * @return array folders that matched $folder as array(name => array('delimiter' => .., 'flags' => ..))
282
     * @throws RuntimeException
283
     */
284
    public function folders($reference = '', $folder = '*') {
285
        $result = [];
286
287
        $items = \imap_getmailboxes($this->stream, $this->getAddress(), $reference.$folder);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_getmailboxes() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

287
        $items = \imap_getmailboxes(/** @scrutinizer ignore-type */ $this->stream, $this->getAddress(), $reference.$folder);
Loading history...
288
        if(is_array($items)){
0 ignored issues
show
introduced by
The condition is_array($items) is always true.
Loading history...
289
            foreach ($items as $item) {
290
                $name = $this->decodeFolderName($item->name);
291
                $result[$name] = ['delimiter' => $item->delimiter, 'flags' => []];
292
            }
293
        }else{
294
            throw new RuntimeException(\imap_last_error());
295
        }
296
297
        return $result;
298
    }
299
300
    /**
301
     * Manage flags
302
     * @param array $flags flags to set, add or remove - see $mode
303
     * @param int $from message for items or start message if $to !== null
304
     * @param int|null $to if null only one message ($from) is fetched, else it's the
305
     *                             last message, INF means last message available
306
     * @param string|null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given
307
     * @param bool $silent if false the return values are the new flags for the wanted messages
308
     *
309
     * @return bool|array new flags if $silent is false, else true or false depending on success
310
     */
311
    public function store(array $flags, $from, $to = null, $mode = null, $silent = true) {
312
        $flag = "\\".trim(is_array($flags) ? implode(" \\", $flags) : $flags);
0 ignored issues
show
introduced by
The condition is_array($flags) is always true.
Loading history...
313
314
        if ($mode == "+"){
315
            $status = \imap_setflag_full($this->stream, $from, $flag, IMAP::SE_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_setflag_full() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

315
            $status = \imap_setflag_full(/** @scrutinizer ignore-type */ $this->stream, $from, $flag, IMAP::SE_UID);
Loading history...
316
        }else{
317
            $status = \imap_clearflag_full($this->stream, $from, $flag, IMAP::SE_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_clearflag_full() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

317
            $status = \imap_clearflag_full(/** @scrutinizer ignore-type */ $this->stream, $from, $flag, IMAP::SE_UID);
Loading history...
318
        }
319
320
        if ($silent === true) {
321
            return $status;
322
        }
323
324
        return $this->flags($from);
325
    }
326
327
    /**
328
     * Append a new message to given folder
329
     * @param string $folder name of target folder
330
     * @param string $message full message content
331
     * @param array $flags flags for new message
332
     * @param string $date date for new message
333
     *
334
     * @return bool success
335
     */
336
    public function appendMessage($folder, $message, $flags = null, $date = null) {
337
        if ($date != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $date of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
338
            if ($date instanceof \Carbon\Carbon){
0 ignored issues
show
introduced by
$date is never a sub-type of Carbon\Carbon.
Loading history...
339
                $date = $date->format('d-M-Y H:i:s O');
340
            }
341
            return \imap_append($this->stream, $folder, $message, $flags, $date);
0 ignored issues
show
Bug introduced by
It seems like $flags can also be of type array; however, parameter $options of imap_append() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

341
            return \imap_append($this->stream, $folder, $message, /** @scrutinizer ignore-type */ $flags, $date);
Loading history...
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_append() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

341
            return \imap_append(/** @scrutinizer ignore-type */ $this->stream, $folder, $message, $flags, $date);
Loading history...
342
        }
343
344
        return \imap_append($this->stream, $folder, $message, $flags);
345
    }
346
347
    /**
348
     * Copy message set from current folder to other folder
349
     * @param string $folder destination folder
350
     * @param $from
351
     * @param int|null $to if null only one message ($from) is fetched, else it's the
352
     *                         last message, INF means last message available
353
     *
354
     * @return bool success
355
     */
356
    public function copyMessage($folder, $from, $to = null) {
357
        return \imap_mail_copy($this->stream, $from, $folder, IMAP::CP_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_mail_copy() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

357
        return \imap_mail_copy(/** @scrutinizer ignore-type */ $this->stream, $from, $folder, IMAP::CP_UID);
Loading history...
358
    }
359
360
    /**
361
     * Move a message set from current folder to an other folder
362
     * @param string $folder destination folder
363
     * @param $from
364
     * @param int|null $to if null only one message ($from) is fetched, else it's the
365
     *                         last message, INF means last message available
366
     *
367
     * @return bool success
368
     */
369
    public function moveMessage($folder, $from, $to = null) {
370
        return \imap_mail_move($this->stream, $from, $folder, IMAP::CP_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_mail_move() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

370
        return \imap_mail_move(/** @scrutinizer ignore-type */ $this->stream, $from, $folder, IMAP::CP_UID);
Loading history...
371
    }
372
373
    /**
374
     * Create a new folder (and parent folders if needed)
375
     * @param string $folder folder name
376
     *
377
     * @return bool success
378
     */
379
    public function createFolder($folder) {
380
        return \imap_createmailbox($this->stream, $folder);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_createmailbox() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

380
        return \imap_createmailbox(/** @scrutinizer ignore-type */ $this->stream, $folder);
Loading history...
381
    }
382
383
    /**
384
     * Rename an existing folder
385
     * @param string $old old name
386
     * @param string $new new name
387
     *
388
     * @return bool success
389
     */
390
    public function renameFolder($old, $new) {
391
        return \imap_renamemailbox($this->stream, $old, $new);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_renamemailbox() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

391
        return \imap_renamemailbox(/** @scrutinizer ignore-type */ $this->stream, $old, $new);
Loading history...
392
    }
393
394
    /**
395
     * Delete a folder
396
     * @param string $folder folder name
397
     *
398
     * @return bool success
399
     */
400
    public function deleteFolder($folder) {
401
        return \imap_deletemailbox($this->stream, $folder);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_deletemailbox() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

401
        return \imap_deletemailbox(/** @scrutinizer ignore-type */ $this->stream, $folder);
Loading history...
402
    }
403
404
    /**
405
     * Subscribe to a folder
406
     * @param string $folder folder name
407
     *
408
     * @throws MethodNotSupportedException
409
     */
410
    public function subscribeFolder($folder) {
411
        throw new MethodNotSupportedException();
412
    }
413
414
    /**
415
     * Unsubscribe from a folder
416
     * @param string $folder folder name
417
     *
418
     * @throws MethodNotSupportedException
419
     */
420
    public function unsubscribeFolder($folder) {
0 ignored issues
show
Unused Code introduced by
The parameter $folder is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

420
    public function unsubscribeFolder(/** @scrutinizer ignore-unused */ $folder) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
421
        throw new MethodNotSupportedException();
422
    }
423
424
    /**
425
     * Apply session saved changes to the server
426
     *
427
     * @return bool success
428
     */
429
    public function expunge() {
430
        return \imap_expunge($this->stream);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_expunge() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

430
        return \imap_expunge(/** @scrutinizer ignore-type */ $this->stream);
Loading history...
431
    }
432
433
    /**
434
     * Send noop command
435
     *
436
     * @throws MethodNotSupportedException
437
     */
438
    public function noop() {
439
        throw new MethodNotSupportedException();
440
    }
441
442
    /**
443
     * Send idle command
444
     *
445
     * @throws MethodNotSupportedException
446
     */
447
    public function idle() {
448
        throw new MethodNotSupportedException();
449
    }
450
451
    /**
452
     * Send done command
453
     *
454
     * @throws MethodNotSupportedException
455
     */
456
    public function done() {
457
        throw new MethodNotSupportedException();
458
    }
459
460
    /**
461
     * Search for matching messages
462
     *
463
     * @param array $params
464
     * @return array message ids
465
     */
466
    public function search(array $params) {
467
        return \imap_search($this->stream, $params[0], IMAP::SE_UID);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_search() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

467
        return \imap_search(/** @scrutinizer ignore-type */ $this->stream, $params[0], IMAP::SE_UID);
Loading history...
468
    }
469
470
    /**
471
     * Enable the debug mode
472
     */
473
    public function enableDebug(){
474
        $this->debug = true;
475
    }
476
477
    /**
478
     * Disable the debug mode
479
     */
480
    public function disableDebug(){
481
        $this->debug = false;
482
    }
483
484
    /**
485
     * Decode name.
486
     * It converts UTF7-IMAP encoding to UTF-8.
487
     *
488
     * @param $name
489
     *
490
     * @return mixed|string
491
     */
492
    protected function decodeFolderName($name) {
493
        preg_match('#\{(.*)\}(.*)#', $name, $preg);
494
        return mb_convert_encoding($preg[2], "UTF-8", "UTF7-IMAP");
495
    }
496
497
    /**
498
     * @return string
499
     */
500
    public function getProtocol() {
501
        return $this->protocol;
502
    }
503
504
    /**
505
     * Retrieve the quota level settings, and usage statics per mailbox
506
     * @param $username
507
     *
508
     * @return array
509
     */
510
    public function getQuota($username) {
511
        return \imap_get_quota($this->stream, 'user.'.$username);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_get_quota() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

511
        return \imap_get_quota(/** @scrutinizer ignore-type */ $this->stream, 'user.'.$username);
Loading history...
512
    }
513
514
    /**
515
     * Retrieve the quota settings per user
516
     * @param string $quota_root
517
     *
518
     * @return array
519
     */
520
    public function getQuotaRoot($quota_root = 'INBOX') {
521
        return \imap_get_quotaroot($this->stream, $quota_root);
0 ignored issues
show
Bug introduced by
It seems like $this->stream can also be of type boolean; however, parameter $imap_stream of imap_get_quotaroot() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

521
        return \imap_get_quotaroot(/** @scrutinizer ignore-type */ $this->stream, $quota_root);
Loading history...
522
    }
523
524
    /**
525
     * @param string $protocol
526
     * @return LegacyProtocol
527
     */
528
    public function setProtocol($protocol) {
529
        $this->protocol = $protocol;
530
        return $this;
531
    }
532
}