2017 © Pedro Peláez
 

cakephp-plugin cakephp-datasource-imap

Imap datasource plugin for CakePHP

image

shahariaazam/cakephp-datasource-imap

Imap datasource plugin for CakePHP

  • Thursday, August 28, 2014
  • by shahariaazam
  • Repository
  • 2 Watchers
  • 5 Stars
  • 2,995 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 3 Versions
  • 21 % Grown

The README.md

CakePHP IMAP Custom Datasource

Custom datasource for CakePHP (2.x) to interact with your mail server with IMAP functionality., (*1)

Put the ImapSource.php datasource in your app/Model/Datasource directory and just setup like the following., (*2)

<?php
//app/Model/CustomEmail.php

class CustomEmail extends AppModel
{
    // Important:
    public $useDbConfig = 'myCustomEmail';
    public $useTable = false;

    // Whatever:
    public $displayField = 'subject';
    public $limit = 10;

    // Semi-important:
    // You want to use the datasource schema, and still be able to set
    // $useTable to false. So we override Cake's schema with that exception:
    function schema($field = false)
    {
        if (!is_array($this->_schema) || $field === true) {
            $db =& ConnectionManager::getDataSource($this->useDbConfig);
            $db->cacheSources = ($this->cacheSources && $db->cacheSources);
            $this->_schema = $db->describe($this, $field);
        }
        if (is_string($field)) {
            if (isset($this->_schema[$field])) {
                return $this->_schema[$field];
            } else {
                return null;
            }
        }
        return $this->_schema;
    }
}

Now you need to define credentials in your app/Config/Database.php with the following code., (*3)

<?php
//app/Config/Database.php

    public $myCustomEmail = array(
        'datasource' => 'ImapSource',
        'server' => 'YourIMAPServerHost',
        'username' => 'IMAPServerUsername',
        'password' => 'yourIMAPPassword',
        'port' => 'IMAPServerPort',
        'ssl' => true,
        'encoding' => 'UTF-8',
        'error_handler' => 'php',
        'auto_mark_as' => array(
            'Seen',
            // 'Answered',
            // 'Flagged',
            // 'Deleted',
            // 'Draft',
        ),
    );

Now from your controller just access your email like below:, (*4)

<?php
// app/Controller/MailsController.php

//your controller codes ...
public function index()
{
  $this->loadModel('CustomEmail');
  $emails = $this->CustomEmail->find('first');
  var_dump($emails); die();
}

Now you will get the email. See the debug output. If you have any question please feel free to mail me at shaharia.azam@gmail.com, (*5)

The Versions

28/08 2014

dev-master

9999999-dev https://github.com/shahariaazam/cakephp-datasource-imap

Imap datasource plugin for CakePHP

  Sources   Download

MIT

The Requires

 

plugin cakephp imap datasource

28/08 2014

2.0

2.0.0.0 https://github.com/shahariaazam/cakephp-datasource-imap

Imap datasource plugin for CakePHP

  Sources   Download

MIT

The Requires

 

plugin cakephp imap datasource

28/08 2014

1.0.0

1.0.0.0 https://github.com/shahariaazam/cakephp-datasource-imap

Imap datasource plugin for CakePHP

  Sources   Download

MIT

The Requires

 

plugin cakephp imap datasource