PHP code example of mail-map / laramail-map

1. Go to this page and download the library: Download mail-map/laramail-map library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mail-map / laramail-map example snippets


// config/app.php
'providers' => [
    // ... other providers
    LaraMailMap\LaraMailMapServiceProvider::class,
],

// app/MailMaps/GithubMailMap.php


namespace App\MailMaps;

use LaraMailMap\LaraMailMap;

class GithubMailMap extends LaraMailMap
{
}

// app/Models/Imap/GithubEmail.php


namespace App\Models\Imap;

use MailMap\Mail;

class GithubEmail extends Mail
{
    // Find the github user's username who sent the message.
    // 'Unknown' if it wasn't found
    public function findSenderUser()
    {
        return $this->header('X-GitHub-Sender', 'Unknown');
    }
}


// app/Providers/MailMapProvider.php


namespace App\Providers;

use App\MailMaps\GithubMailMap;
use App\Models\Imap\GithubEmail;
use Illuminate\Support\ServiceProvider;
use MailMap\MailFactory;

class MailMapProvider extends ServiceProvider
{
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(GithubMailMap::class, function () {
            $config = config('mailmap'); // connection information
            $mailbox = config('mailmap.mailboxes.github'); // name of the mailbox for this MailMap
            $factory = new MailFactory(GithubEmail::class); // This will generate our GithubEmail "models"

            return new GithubMailMap($config, $mailbox, $factory);
        });
    }
}

'mailboxes' => [
    'inbox' => 'INBOX',
    'github' => 'Github'
],

// app/Http/Controllers/MyController.php


namespace App\Https\Controllers;

use App\MailMaps\GithubMailMap;
use Carbon\Carbon;

class MyController
{
    public function githubMessages(GithubMailMap $githubMap, Carbon $since, $limit = 10)
    {
        $messages = $githubMap->queryMailbox(function ($query) use ($since, $limit) {
            return $query->since($since->format('d-M-Y'))->limit($limit);
        });

        return view('show.my.github.emails', compact('messages'));
    }
}