PHP code example of secit-pl / imap-bundle

1. Go to this page and download the library: Download secit-pl/imap-bundle 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/ */

    

secit-pl / imap-bundle example snippets




namespace App\Controller;

use SecIT\ImapBundle\ConnectionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class IndexController extends AbstractController
{
    public function index(
        ConnectionInterface $exampleConnection,
        ConnectionInterface $secondConnection,
        ConnectionInterface $connection3Connection,
    ) {
        $mailbox = $exampleConnection->getMailbox(); // instance of PhpImap\Mailbox
        $isConnectable = $secondConnection->testConnection();
        $connectionName = $connection3Connection->getName(); // connection3

        ...
    }

    ...
}




namespace App\Controller;

use SecIT\ImapBundle\ConnectionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Target;

class IndexController extends AbstractController
{
    public function index(
        #[Target('exampleConnection')] 
        ConnectionInterface $example,
        #[Target('secondConnection')] 
        ConnectionInterface $customName,
        #[Target('connection3Connection')] 
        ConnectionInterface $connection,
    ) {
        $mailbox = $exampleConnection->getMailbox(); // instance of PhpImap\Mailbox
        $isConnectable = $secondConnection->testConnection();
        $connectionName = $connection3Connection->getName(); // connection3

        ...
    }

    ...
}




namespace App\Controller;

use SecIT\ImapBundle\ConnectionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;

class IndexController extends AbstractController
{
    public function index(
        #[TaggedIterator('secit.imap.connection')]
        iterable $connections,
    ) {
        foreach ($connections as $connection) {
            $mailbox = $connection->getMailbox();
        }

        ...
    }

    ...
}


$mailbox = $exampleConnection->getMailbox();
$mailbox->getMailboxInfo();

// testing with a boolean response
$isConnectable = $exampleConnection->testConnection();
var_dump($isConnectable);

// testing with a full error message
try {
    $isConnectable = $exampleConnection->testConnection(true);
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

public function index(Imap $imap)
{
    $mailbox = $imap->get('example_connection')->getConnection();
}


use SecIT\ImapBundle\Connection\ConnectionInterface;

public function index(ConnectionInterface $exampleConnection)
{
    $mailbox = $exampleConnection->getMailbox();
}


use SecIT\ImapBundle\ConnectionInterface;
use Symfony\Component\DependencyInjection\Attribute\Target;

public function index(
    #[Target('exampleConnection')] 
    ConnectionInterface $customName,
) {
    $mailbox = $customName->getMailbox();
}
bash
php bin/console secit:imap:validate-connections