• Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well.

IMAP Library for PHP

Latest release on Packagist Latest prerelease on Packagist Software License Total Downloads Hits Discord Snyk

Description

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well. You can enable the php-imap module in order to handle edge cases, improve message decoding quality and is required if you want to use legacy protocols such as pop3.

Official documentation: php-imap.com

Laravel wrapper: webklex/laravel-imap

Discord: discord.gg/rd4cN9h6

Table of Contents

Documentations

Compatibility

Version PHP 5.6 PHP 7 PHP 8
v5.x / / X
v4.x / X X
v3.x / X /
v2.x X X /
v1.x X / /

Basic usage example

This is a basic example, which will echo out all Mails within all imap folders and will move every message into INBOX.read. Please be aware that this should not be tested in real life and is only meant to give an impression on how things work.

use Webklex\PHPIMAP\ClientManager;

require_once "vendor/autoload.php";

$cm = new ClientManager('path/to/config/imap.php');

/** @var \Webklex\PHPIMAP\Client $client */
$client = $cm->account('account_identifier');

//Connect to the IMAP Server
$client->connect();

//Get all Mailboxes
/** @var \Webklex\PHPIMAP\Support\FolderCollection $folders */
$folders = $client->getFolders();

//Loop through every Mailbox
/** @var \Webklex\PHPIMAP\Folder $folder */
foreach($folders as $folder){

    //Get all Messages of the current Mailbox $folder
    /** @var \Webklex\PHPIMAP\Support\MessageCollection $messages */
    $messages = $folder->messages()->all()->get();
    
    /** @var \Webklex\PHPIMAP\Message $message */
    foreach($messages as $message){
        echo $message->getSubject().'<br />';
        echo 'Attachments: '.$message->getAttachments()->count().'<br />';
        echo $message->getHTMLBody();
        
        //Move the current Message to 'INBOX.read'
        if($message->move('INBOX.read') == true){
            echo 'Message has been moved';
        }else{
            echo 'Message could not be moved';
        }
    }
}

Sponsors

Feline

Testing

To run the tests, please execute the following command:

composer test

Quick-Test / Static Test

To disable all test which require a live mailbox, please copy the phpunit.xml.dist to phpunit.xml and adjust the configuration:

<php>
    <env name="LIVE_MAILBOX" value="false"/>
</php>

Full-Test / Live Mailbox Test

To run all tests, you need to provide a valid imap configuration.

To provide a valid imap configuration, please copy the phpunit.xml.dist to phpunit.xml and adjust the configuration:

<php>
    <env name="LIVE_MAILBOX" value="true"/>
    <env name="LIVE_MAILBOX_DEBUG" value="true"/>
    <env name="LIVE_MAILBOX_HOST" value="mail.example.local"/>
    <env name="LIVE_MAILBOX_PORT" value="993"/>
    <env name="LIVE_MAILBOX_VALIDATE_CERT" value="false"/>
    <env name="LIVE_MAILBOX_QUOTA_SUPPORT" value="true"/>
    <env name="LIVE_MAILBOX_ENCRYPTION" value="ssl"/>
    <env name="LIVE_MAILBOX_USERNAME" value="[email protected]"/>
    <env name="LIVE_MAILBOX_PASSWORD" value="foobar"/>
</php>

The test account should not contain any important data, as it will be deleted during the test. Furthermore, the test account should be able to create new folders, move messages and should not be used by any other application during the test.

It's recommended to use a dedicated test account for this purpose. You can use the provided Dockerfile to create an imap server used for testing purposes.

Build the docker image:

cd .github/docker

docker build -t php-imap-server .

Run the docker image:

docker run --name imap-server -p 993:993 --rm -d php-imap-server

Stop the docker image:

docker stop imap-server

Known issues

Error Solution
Kerberos error: No credentials cache file found (try running kinit) (...) Uncomment "DISABLE_AUTHENTICATOR" inside your config and use the legacy-imap protocol

Support

If you encounter any problems or if you find a bug, please don't hesitate to create a new issue. However, please be aware that it might take some time to get an answer. Off-topic, rude or abusive issues will be deleted without any notice.

If you need commercial support, feel free to send me a mail at [email protected].

A little notice

If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read
and people are more likely to comment and help :)

```php

echo 'your php code...';

```

will turn into:

echo 'your php code...'; 

Features & pull requests

Everyone can contribute to this project. Every pull request will be considered, but it can also happen to be declined.
To prevent unnecessary work, please consider to create a feature issue
first, if you're planning to do bigger changes. Of course, you can also create a new feature issue if you're just wishing a feature ;)

Change log

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
PHP
560
star
2

laravel-pdfmerger

A FPDI PDF Wrapper for Laravel which includes the "merge" functionality
PHP
66
star
3

laravel-git-hook

Automatic git deployment for Laravel
PHP
17
star
4

tbm

Fetch all your bookmarked tweets and make them accessible through a webinterface.
CSS
16
star
5

altip

Convert an IP into Alternative / Obfuscated versions of itself
Go
14
star
6

gogeoip

GoGeoIP - a lightweight web api providing ip intelligence written in GO. This software provides an api to get as many information as possible for a given IP address or the current visitor. This includes network, system, location and user information.
Go
12
star
7

romb

Rust
7
star
8

PostfixADM

PostfixADM is a modern postfix management tool. It is designed to work with almost any setup that is based on postfix, dovecot and mysql.
PHP
6
star
9

python_amazon_price_tracker

Python Amazon Price Tracker
Python
4
star
10

gohits

An easy way to track your page or project views ("hits") of any GitHub or online project.
Go
3
star
11

php-geoip

PHP-GeoIP provides you with the ability to gather open source ip intelligence by using the open api provided by https://github.com/Webklex/gogeoip.
PHP
2
star
12

gogeoip-gui

Example GUI for webklex/gogeoip
HTML
2
star
13

wappalyzer

Cli app based upon https://github.com/projectdiscovery/wappalyzergo
Go
2
star
14

laravel_imap_example

This is an example application to showcase the integration of `webklex/laravel-imap`.
PHP
2
star
15

thunderbird-spam-score-column

A simple Mozilla Thunderbird add-on that adds a sortable column to display the contents of SpamAssassin's X-Spam-Score header.
JavaScript
2
star
16

translator

This is a translator package provides everything you need to get started with a quiet fast CSV file based translation service.
PHP
2
star
17

ESP8266AutoConnect

With this library an ESP8266 can automatically connect to an open wifi network which has a working internet connection. This library should not be considered save since it is a bad thing to have your iot autoconnect to everything it can get a hold of. However I developed it for a personal use case where exactly that was required. So here we go :)
C++
2
star
18

iban

This is a simple class to calculate the iban of a given account number, bank sort code and country code.
PHP
2
star
19

apache-add-site

This script is designed to setup any local development website witch one easy command. It creates if it doesn't exists an apache2 site config file, does the required hosts entry, adds the site to the apache configuration (a2ensite) and reloads the whole configuration. So you can get started within seconds.
Shell
2
star
20

juck

This program attempts to harvest as much information as possible from javascript source maps. Works with both, local files and urls.
Go
1
star
21

twitter-bot

Feed your Twitter account with lots of stuff - all you need is a RSS feed
PHP
1
star
22

hd

Check a single or many targets how they behave if an altered host header is supplied.
Go
1
star
23

laravel-geoip

Laravel-GeoIP provides you with the ability to gather open source ip intelligence by using the open api provided by https://github.com/Webklex/gogeoip
PHP
1
star
24

helpers

This is a helpers package that provides some built in helpers, and also provides an Artisan generator to quickly create your own custom helpers.
PHP
1
star
25

tcpc

A simple, single threaded and minimalistic port checker.
Rust
1
star
26

php-imap-documentation

php-imap and laravel-imap documentation
1
star
27

composer-info

Access the current details of your composer.lock file.
PHP
1
star
28

sstb

This bot will monitor all user orders for a given number of markets and will automatically create counter orders whenever one of these monitored orders gets fulfilled.
Go
1
star
29

2fam

Generate a 2fa code for a given secret.
Shell
1
star