Skip to content

Commit

Permalink
Merge pull request #491 from barbushin/develop
Browse files Browse the repository at this point in the history
Release 3.1.0
  • Loading branch information
Sebbo94BY authored Apr 10, 2020
2 parents 9c1469c + bd5fbc5 commit 1df5b8b
Show file tree
Hide file tree
Showing 25 changed files with 4,539 additions and 798 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_size = 2

[composer.json]
indent_style = space
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ vendor/
composer.lock
*.phar
.php_cs.cache
coverage/
psalm/cache/

#################
## Eclipse
Expand Down Expand Up @@ -159,6 +161,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
clover.xml

#Translations
*.mo
Expand Down
12 changes: 10 additions & 2 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ return PhpCsFixer\Config::create()
'syntax' => 'short'
],
'ordered_imports' => true,
'no_superfluous_phpdoc_tags' => true
'phpdoc_to_comment' => false,
'no_superfluous_phpdoc_tags' => true,
'ordered_class_elements' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => false,
],
'native_function_invocation' => true,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->in(__DIR__.'/examples')
)
;

50 changes: 41 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,57 @@ env:
- CC_TEST_REPORTER_ID=4eed0d135b9e1a1668a68e5e29cc71faf872937d13c42efa4faf42dad5ed3375

language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4snapshot

env:
- phpunitflags="--stop-on-failure --exclude-group=live"

matrix:
fast_finish: true
include:
- php: 5.6
dist: xenial
env:
- lint="php-cs-fixer"
- phpunitflags="do not run"
- php: 7.4
dist: bionic
env:
- analysis=yes
- phpunitflags="do not run"
- php: 7.4
dist: bionic
env:
- lint=no
- coverage=yes
- phpunitflags="--stop-on-failure --coverage-clover=clover.xml"

cache:
directories:
- ./vendor
- ./psalm/cache

before_script:
- if [[ "$coverage" != "yes" ]]; then phpenv config-rm xdebug.ini; fi
- composer install --no-interaction
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- curl https://cs.symfony.com/download/php-cs-fixer-v2.phar -o php-cs-fixer.phar
- chmod +x php-cs-fixer.phar
- if [[ "$coverage" = "yes" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; fi
- if [[ "$coverage" = "yes" ]]; then chmod +x ./cc-test-reporter; fi
- if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter before-build; fi
- if [[ "$analysis" = "yes" ]]; then composer require --dev paragonie/hidden-string; fi
- 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

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

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
- if [[ "$coverage" = "yes" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT -t clover; fi
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Supported PHP Version](https://img.shields.io/packagist/php-v/php-imap/php-imap/3.0.8.svg)](README.md)
[![Maintainability](https://api.codeclimate.com/v1/badges/02f72a4fd695cb7e2976/maintainability)](https://codeclimate.com/github/barbushin/php-imap/maintainability)
[![Coverage](https://api.codeclimate.com/v1/badges/02f72a4fd695cb7e2976/test_coverage)](https://codeclimate.com/github/barbushin/php-imap/test_coverage)
[![Type Coverage](https://shepherd.dev/github/barbushin/php-imap/coverage.svg)](https://shepherd.dev/github/barbushin/php-imap)

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.

Expand All @@ -18,7 +19,7 @@ Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open
* Mark emails as seen/unseen
* Delete emails
* Manage mailbox folders

### Requirements

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

```php
// Call imap_check();
// http://php.net/manual/en/function.imap-check.php
$info = $mailbox->imap('check'); //
// Call imap_check();
// http://php.net/manual/en/function.imap-check.php
$info = $mailbox->imap('check'); //

// Show current time for the mailbox
$currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown';
$currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown';

echo $currentServerTime;
```

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

// get the list of folders/mailboxes
$folders = $mailbox->getMailboxes('*');
// loop through mailboxs
foreach($folders as $folder) {
// switch to particular mailbox
$mailbox->switchMailbox($folder['fullpath']);
// search in particular mailbox
$mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"');
}
// get the list of folders/mailboxes
$folders = $mailbox->getMailboxes('*');

// loop through mailboxs
foreach($folders as $folder) {

// switch to particular mailbox
$mailbox->switchMailbox($folder['fullpath']);

// search in particular mailbox
$mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"');
}

print_r($mails_ids);
```

Expand Down
31 changes: 27 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,38 @@
"email": "[email protected]"
}
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=5.6",
"ext-fileinfo": "*",
"ext-iconv": "*",
"ext-imap": "*",
"ext-mbstring": "*",
"ext-iconv": "*"
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.4"
"friendsofphp/php-cs-fixer": "^2.16",
"jakub-onderka/php-parallel-lint": "^1.0",
"paragonie/random_compat": "^1",
"phpunit/phpunit": "^5.7"
},
"scripts": {
"tests": [
"parallel-lint .php_cs.dist src tests examples",
"phpunit",
"composer-require-checker check ./composer.json",
"psalm --show-info=false",
"php-cs-fixer fix --allow-risky=yes --no-interaction --dry-run --diff-format=udiff -v"
]
},
"suggest": {
"ext-fileinfo": "To facilitate IncomingMailAttachment::getMimeType() auto-detection"
},
"autoload-dev": {
"psr-4": {
"PhpImap\\": "tests/unit"
}
},
"autoload": {
"psr-4": {
Expand Down
Empty file added coverage/.gitkeep
Empty file.
55 changes: 27 additions & 28 deletions examples/get_and_parse_all_emails_with_matching_subject.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?php

/**
* Example: Get and parse all emails which match the subject "part of the subject" with saving their attachments.
*
* @author Sebastian Krätzig <[email protected]>
*/

require_once __DIR__ . '/../vendor/autoload.php';
use PhpImap\Mailbox;
/**
* Example: Get and parse all emails which match the subject "part of the subject" with saving their attachments.
*
* @author Sebastian Krätzig <[email protected]>
*/
require_once __DIR__.'/../vendor/autoload.php';
use PhpImap\Exceptions\ConnectionException;
use PhpImap\Mailbox;

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

try {
$mail_ids = $mailbox->searchMailbox('SUBJECT "part of the subject"');
} catch(ConnectionException $ex) {
die("IMAP connection failed: " . $ex->getMessage());
} catch (ConnectionException $ex) {
die('IMAP connection failed: '.$ex->getMessage());
} catch (Exception $ex) {
die("An error occured: " . $ex->getMessage());
die('An error occured: '.$ex->getMessage());
}

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

echo "from-name: " . (isset($email->fromName)) ? $email->fromName : $email->fromAddress . "\n";
echo "from-email: " . $email->fromAddress . "\n";
echo "to: " . $email->to . "\n";
echo "subject: " . $email->subject . "\n";
echo "message_id: " . $email->messageId . "\n";
echo "mail has attachments? ";
echo 'from-name: '.(string) (isset($email->fromName) ? $email->fromName : $email->fromAddress)."\n";
echo 'from-email: '.(string) $email->fromAddress."\n";
echo 'to: '.(string) $email->toString."\n";
echo 'subject: '.(string) $email->subject."\n";
echo 'message_id: '.(string) $email->messageId."\n";

echo 'mail has attachments? ';
if ($email->hasAttachments()) {
echo "Yes\n";
} else {
echo "No\n";
}

if (!empty($email->getAttachments())) {
echo count($email->getAttachments()) . " attachements\n";
echo \count($email->getAttachments())." attachements\n";
}
if ($email->textHtml) {
echo "Message HTML:\n" . $email->textHtml;
echo "Message HTML:\n".$email->textHtml;
} else {
echo "Message Plain:\n" . $email->textPlain;
echo "Message Plain:\n".$email->textPlain;
}

if (!empty($email->autoSubmitted)) {
// Mark email as "read" / "seen"
$mailbox->markMailAsRead($mail_id);
echo "+------ IGNORING: Auto-Reply ------+\n";
echo "+------ IGNORING: Auto-Reply ------+\n";
}

if (!empty($email_content->precedence)) {
// Mark email as "read" / "seen"
$mailbox->markMailAsRead($mail_id);
echo "+------ IGNORING: Non-Delivery Report/Receipt ------+\n";
}
}
}

$mailbox->disconnect();
$mailbox->disconnect();
Loading

0 comments on commit 1df5b8b

Please sign in to comment.