Skip to content

Commit 1df5b8b

Browse files
authored
Merge pull request #491 from barbushin/develop
Release 3.1.0
2 parents 9c1469c + bd5fbc5 commit 1df5b8b

25 files changed

+4539
-798
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.yml]
12+
indent_size = 2
13+
14+
[composer.json]
15+
indent_style = space

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ vendor/
33
composer.lock
44
*.phar
55
.php_cs.cache
6+
coverage/
7+
psalm/cache/
68

79
#################
810
## Eclipse
@@ -159,6 +161,7 @@ pip-log.txt
159161
# Unit test / coverage reports
160162
.coverage
161163
.tox
164+
clover.xml
162165

163166
#Translations
164167
*.mo

.php_cs.dist

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ return PhpCsFixer\Config::create()
88
'syntax' => 'short'
99
],
1010
'ordered_imports' => true,
11-
'no_superfluous_phpdoc_tags' => true
11+
'phpdoc_to_comment' => false,
12+
'no_superfluous_phpdoc_tags' => true,
13+
'ordered_class_elements' => true,
14+
'global_namespace_import' => [
15+
'import_classes' => true,
16+
'import_constants' => true,
17+
'import_functions' => false,
18+
],
19+
'native_function_invocation' => true,
1220
])
1321
->setRiskyAllowed(true)
1422
->setFinder(
1523
PhpCsFixer\Finder::create()
1624
->in(__DIR__.'/src')
1725
->in(__DIR__.'/tests')
26+
->in(__DIR__.'/examples')
1827
)
1928
;
20-

.travis.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,57 @@ env:
33
- CC_TEST_REPORTER_ID=4eed0d135b9e1a1668a68e5e29cc71faf872937d13c42efa4faf42dad5ed3375
44

55
language: php
6+
67
php:
78
- 5.6
89
- 7.0
910
- 7.1
1011
- 7.2
1112
- 7.3
12-
- 7.4snapshot
13+
14+
env:
15+
- phpunitflags="--stop-on-failure --exclude-group=live"
16+
17+
matrix:
18+
fast_finish: true
19+
include:
20+
- php: 5.6
21+
dist: xenial
22+
env:
23+
- lint="php-cs-fixer"
24+
- phpunitflags="do not run"
25+
- php: 7.4
26+
dist: bionic
27+
env:
28+
- analysis=yes
29+
- phpunitflags="do not run"
30+
- php: 7.4
31+
dist: bionic
32+
env:
33+
- lint=no
34+
- coverage=yes
35+
- phpunitflags="--stop-on-failure --coverage-clover=clover.xml"
36+
37+
cache:
38+
directories:
39+
- ./vendor
40+
- ./psalm/cache
1341

1442
before_script:
43+
- if [[ "$coverage" != "yes" ]]; then phpenv config-rm xdebug.ini; fi
1544
- composer install --no-interaction
16-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17-
- chmod +x ./cc-test-reporter
18-
- ./cc-test-reporter before-build
19-
- curl https://cs.symfony.com/download/php-cs-fixer-v2.phar -o php-cs-fixer.phar
20-
- chmod +x php-cs-fixer.phar
45+
- if [[ "$coverage" = "yes" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; fi
46+
- if [[ "$coverage" = "yes" ]]; then chmod +x ./cc-test-reporter; fi
47+
- if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter before-build; fi
48+
- if [[ "$analysis" = "yes" ]]; then composer require --dev paragonie/hidden-string; fi
49+
- if [[ "$analysis" = "yes" ]]; then composer require --dev --update-with-dependencies "phpunit/phpunit:<9" vimeo/psalm psalm/plugin-phpunit maglnet/composer-require-checker:^2.0; fi
2150

2251
script:
23-
- vendor/bin/phpunit
24-
- ./php-cs-fixer.phar fix --allow-risky=yes --no-interaction --dry-run --diff -v
52+
- if [[ "$lint" != "no" ]]; then vendor/bin/parallel-lint .php_cs.dist src tests examples; fi
53+
- if [[ "$phpunitflags" != "do not run" ]]; then vendor/bin/phpunit $phpunitflags; fi
54+
- if [[ "$analysis" = "yes" ]]; then vendor/bin/composer-require-checker check ./composer.json; fi
55+
- if [[ "$analysis" = "yes" ]]; then vendor/bin/psalm --show-info=false --shepherd --diff --diff-methods; fi
56+
- if [[ "$lint" = "php-cs-fixer" ]]; then vendor/bin/php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run --diff-format=udiff -v; fi
2557

2658
after_script:
27-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
59+
- if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT -t clover; fi

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Supported PHP Version](https://img.shields.io/packagist/php-v/php-imap/php-imap/3.0.8.svg)](README.md)
88
[![Maintainability](https://api.codeclimate.com/v1/badges/02f72a4fd695cb7e2976/maintainability)](https://codeclimate.com/github/barbushin/php-imap/maintainability)
99
[![Coverage](https://api.codeclimate.com/v1/badges/02f72a4fd695cb7e2976/test_coverage)](https://codeclimate.com/github/barbushin/php-imap/test_coverage)
10+
[![Type Coverage](https://shepherd.dev/github/barbushin/php-imap/coverage.svg)](https://shepherd.dev/github/barbushin/php-imap)
1011

1112
Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open source library to connect to a mailbox by POP3, IMAP and NNTP using the PHP IMAP extension. This library allows you to fetch emails from your email server. Extend the functionality or create powerful web applications to handle your incoming emails.
1213

@@ -18,7 +19,7 @@ Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open
1819
* Mark emails as seen/unseen
1920
* Delete emails
2021
* Manage mailbox folders
21-
22+
2223
### Requirements
2324

2425
* PHP 5.6, 7.0, 7.1, 7.2, 7.3 or 7.4
@@ -102,13 +103,13 @@ print_r($mail->getAttachments());
102103
Method imap() allows to call any imap function in a context of the the instance:
103104

104105
```php
105-
// Call imap_check();
106-
// http://php.net/manual/en/function.imap-check.php
107-
$info = $mailbox->imap('check'); //
108-
106+
// Call imap_check();
107+
// http://php.net/manual/en/function.imap-check.php
108+
$info = $mailbox->imap('check'); //
109+
109110
// Show current time for the mailbox
110-
$currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown';
111-
111+
$currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown';
112+
112113
echo $currentServerTime;
113114
```
114115

@@ -118,19 +119,19 @@ Some request require much time and resources:
118119
// If you don't need to grab attachments you can significantly increase performance of your application
119120
$mailbox->setAttachmentsIgnore(true);
120121

121-
// get the list of folders/mailboxes
122-
$folders = $mailbox->getMailboxes('*');
123-
124-
// loop through mailboxs
125-
foreach($folders as $folder) {
126-
127-
// switch to particular mailbox
128-
$mailbox->switchMailbox($folder['fullpath']);
129-
130-
// search in particular mailbox
131-
$mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"');
132-
}
133-
122+
// get the list of folders/mailboxes
123+
$folders = $mailbox->getMailboxes('*');
124+
125+
// loop through mailboxs
126+
foreach($folders as $folder) {
127+
128+
// switch to particular mailbox
129+
$mailbox->switchMailbox($folder['fullpath']);
130+
131+
// search in particular mailbox
132+
$mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"');
133+
}
134+
134135
print_r($mails_ids);
135136
```
136137

composer.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,38 @@
1919
"email": "[email protected]"
2020
}
2121
],
22+
"config": {
23+
"sort-packages": true
24+
},
2225
"require": {
2326
"php": ">=5.6",
27+
"ext-fileinfo": "*",
28+
"ext-iconv": "*",
2429
"ext-imap": "*",
25-
"ext-mbstring": "*",
26-
"ext-iconv": "*"
30+
"ext-mbstring": "*"
2731
},
2832
"require-dev": {
29-
"phpunit/phpunit": "^5.7",
30-
"squizlabs/php_codesniffer": "^3.4"
33+
"friendsofphp/php-cs-fixer": "^2.16",
34+
"jakub-onderka/php-parallel-lint": "^1.0",
35+
"paragonie/random_compat": "^1",
36+
"phpunit/phpunit": "^5.7"
37+
},
38+
"scripts": {
39+
"tests": [
40+
"parallel-lint .php_cs.dist src tests examples",
41+
"phpunit",
42+
"composer-require-checker check ./composer.json",
43+
"psalm --show-info=false",
44+
"php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run --diff-format=udiff -v"
45+
]
46+
},
47+
"suggest": {
48+
"ext-fileinfo": "To facilitate IncomingMailAttachment::getMimeType() auto-detection"
49+
},
50+
"autoload-dev": {
51+
"psr-4": {
52+
"PhpImap\\": "tests/unit"
53+
}
3154
},
3255
"autoload": {
3356
"psr-4": {

coverage/.gitkeep

Whitespace-only changes.
Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<?php
22

3-
/**
4-
* Example: Get and parse all emails which match the subject "part of the subject" with saving their attachments.
5-
*
6-
* @author Sebastian Krätzig <[email protected]>
7-
*/
8-
9-
require_once __DIR__ . '/../vendor/autoload.php';
10-
use PhpImap\Mailbox;
3+
/**
4+
* Example: Get and parse all emails which match the subject "part of the subject" with saving their attachments.
5+
*
6+
* @author Sebastian Krätzig <[email protected]>
7+
*/
8+
require_once __DIR__.'/../vendor/autoload.php';
119
use PhpImap\Exceptions\ConnectionException;
10+
use PhpImap\Mailbox;
1211

1312
$mailbox = new Mailbox(
1413
'{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
1514
'[email protected]', // Username for the before configured mailbox
1615
'*********', // Password for the before configured username
1716
__DIR__, // Directory, where attachments will be saved (optional)
18-
'US-ASCII' // Server encoding (optional)
17+
'US-ASCII' // Server encoding (optional)
1918
);
2019

2120
try {
2221
$mail_ids = $mailbox->searchMailbox('SUBJECT "part of the subject"');
23-
} catch(ConnectionException $ex) {
24-
die("IMAP connection failed: " . $ex->getMessage());
22+
} catch (ConnectionException $ex) {
23+
die('IMAP connection failed: '.$ex->getMessage());
2524
} catch (Exception $ex) {
26-
die("An error occured: " . $ex->getMessage());
25+
die('An error occured: '.$ex->getMessage());
2726
}
2827

2928
foreach ($mail_ids as $mail_id) {
@@ -34,39 +33,39 @@
3433
false // Do NOT mark emails as seen (optional)
3534
);
3635

37-
echo "from-name: " . (isset($email->fromName)) ? $email->fromName : $email->fromAddress . "\n";
38-
echo "from-email: " . $email->fromAddress . "\n";
39-
echo "to: " . $email->to . "\n";
40-
echo "subject: " . $email->subject . "\n";
41-
echo "message_id: " . $email->messageId . "\n";
42-
43-
echo "mail has attachments? ";
36+
echo 'from-name: '.(string) (isset($email->fromName) ? $email->fromName : $email->fromAddress)."\n";
37+
echo 'from-email: '.(string) $email->fromAddress."\n";
38+
echo 'to: '.(string) $email->toString."\n";
39+
echo 'subject: '.(string) $email->subject."\n";
40+
echo 'message_id: '.(string) $email->messageId."\n";
41+
42+
echo 'mail has attachments? ';
4443
if ($email->hasAttachments()) {
4544
echo "Yes\n";
4645
} else {
4746
echo "No\n";
4847
}
49-
48+
5049
if (!empty($email->getAttachments())) {
51-
echo count($email->getAttachments()) . " attachements\n";
50+
echo \count($email->getAttachments())." attachements\n";
5251
}
5352
if ($email->textHtml) {
54-
echo "Message HTML:\n" . $email->textHtml;
53+
echo "Message HTML:\n".$email->textHtml;
5554
} else {
56-
echo "Message Plain:\n" . $email->textPlain;
55+
echo "Message Plain:\n".$email->textPlain;
5756
}
58-
57+
5958
if (!empty($email->autoSubmitted)) {
6059
// Mark email as "read" / "seen"
6160
$mailbox->markMailAsRead($mail_id);
62-
echo "+------ IGNORING: Auto-Reply ------+\n";
61+
echo "+------ IGNORING: Auto-Reply ------+\n";
6362
}
64-
63+
6564
if (!empty($email_content->precedence)) {
6665
// Mark email as "read" / "seen"
6766
$mailbox->markMailAsRead($mail_id);
6867
echo "+------ IGNORING: Non-Delivery Report/Receipt ------+\n";
69-
}
68+
}
7069
}
7170

72-
$mailbox->disconnect();
71+
$mailbox->disconnect();

0 commit comments

Comments
 (0)